Skip to content

Instantly share code, notes, and snippets.

@nfreear
Last active March 3, 2021 10:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nfreear/893ce93d441e1709c72cc49fe0a9522d to your computer and use it in GitHub Desktop.
Save nfreear/893ce93d441e1709c72cc49fe0a9522d to your computer and use it in GitHub Desktop.
NPM: outdated filter "wanted" (Node / Javacript utility)
/**
* NPM-Outdated-filter-wanted.js
*
* @author NDF, 02-Mar-2021.
*/
const exec = require('child_process').exec;
exec('npm outdated --json', (err, stdout, stderr) => {
if (err instanceof Error && !stdout) {
console.error(err);
throw err;
}
const outdated = JSON.parse(stdout);
const wanted = [];
const ignored = [];
Object.entries(outdated).map(item => {
const [ name, mod ] = item;
if (mod.current == mod.wanted) {
ignored.push([ name, mod.current, mod.wanted, mod.latest ]);
} else {
wanted.push([ name, mod.current, mod.wanted ]); // Was: ...Object.values(mod)
}
});
console.log('Wanted:', wanted, '\n');
console.log('Ignored:', ignored);
});
// https://zaiste.net/posts/nodejs-child-process-spawn-exec-fork-async-await/
/* const util = require('util');
const exec = util.promisify(require('child_process').exec);
async function main() {
const { stdout, stderr } = await exec('npm outdated --json');
if (stderr) {
console.error(`error: ${stderr}`);
}
console.log(`result: ${stdout}`);
}
main(); */
// End.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment