Created
May 25, 2021 18:32
list global npm packages that are not linked
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
const { exec } = require("child_process") | |
exec('npm ls --global --json', (err, stdout, stderr) => { | |
if (err) throw err | |
const deps = JSON.parse(stdout).dependencies | |
// dependencies hash looks like: | |
// "linked-pkg": { "version": "1.0.0", "resolved": "file:..." }, | |
// "global-pkg": { "version": "1.0.0" }, ... | |
// so we skip any package that has a "resolved" property | |
const output = Object.keys(deps).reduce((total, key) => { | |
return deps[key].resolved ? total : `${total}${key}\n` | |
}, '') | |
process.stdout.write(output) | |
process.stderr.write(stderr) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment