Package Exports
- parse-npm-script
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (parse-npm-script) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
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 = require('path')
const util = require('util')
const parse = require('./lib')
/* path to your package.json file */
const packagePath = path.join(__dirname, 'tests/fixtures/one.json')
async function runParser() {
const parsed = await parse(packagePath, 'npm run build')
console.log(util.inspect(parsed, {
showHidden: false,
depth: null
}))
}
runParser()
/* 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
{
"name": "parse-npm-script",
"scripts": {
"foo": "echo foo",
"cleanup": "echo cleanup",
"prebuild": "echo a && npm run foo",
"build": "echo b && npm run cleanup",
"postbuild": "echo c"
},
"author": "David Wells",
"license": "MIT"
}
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'
}