Last active
March 3, 2021 10:10
-
-
Save nfreear/893ce93d441e1709c72cc49fe0a9522d to your computer and use it in GitHub Desktop.
NPM: outdated filter "wanted" (Node / Javacript utility)
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
/** | |
* 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