Parse NPM Script
Parse a given npm
script command from package.json
& return information.
- What the
script
lifecycle looks like - How the command really resolves
- & What the final command run is
Useful for parsing dependencies actually used and figuring out wtf is happening in a complex package.json
.
Usage
const path = const util = const parse = /* path to your package.json file */const packagePath = path { const parsed = await console} /* Parsed contents{ command: 'npm run build', steps: [{ name: 'prebuild', raw: 'echo a && npm run foo', parsed: ['echo a', 'echo foo'] }, { name: 'build', raw: 'echo b && npm run cleanup', parsed: ['echo b', 'echo cleanup'] }, { name: 'postbuild', raw: 'echo c', parsed: 'echo c' } ], raw: ['echo a', 'echo foo', 'echo b', 'echo cleanup', 'echo c'], combined: 'echo a && echo foo && echo b && echo cleanup && echo c'}*/
Example:
Parsing a package.json
Will result in this output:
command: 'npm run build' steps: name: 'prebuild' raw: 'echo a && npm run foo' parsed: 'echo a' 'echo foo' name: 'build' raw: 'echo b && npm run cleanup' parsed: 'echo b' 'echo cleanup' name: 'postbuild' raw: 'echo c' parsed: 'echo c' raw: 'echo a' 'echo foo' 'echo b' 'echo cleanup' 'echo c' combined: 'echo a && echo foo && echo b && echo cleanup && echo c'