diff --git a/src/bin/nps.js b/src/bin/nps.js index 7edc3a1..2792991 100755 --- a/src/bin/nps.js +++ b/src/bin/nps.js @@ -6,7 +6,14 @@ import runPackageScript from '../index' import parse from '../bin-utils/parser' const FAIL_CODE = 1 -const {argv, psConfig} = parse(process.argv.slice(2)) || {} + +const args = process.argv.slice(2) +const indexOfCommand = args.findIndex(arg => !arg.startsWith('-')) +const preCommandFlags = + indexOfCommand === -1 ? args : args.slice(0, indexOfCommand + 1) +const postCommandFlags = args.slice(indexOfCommand + 1) + +const {argv, psConfig} = parse(preCommandFlags) || {} if (argv && psConfig) { runPackageScript({ @@ -18,6 +25,7 @@ if (argv && psConfig) { logLevel: argv.logLevel, prefix: argv.prefix, scripts: argv.scripts, + args: postCommandFlags, }, psConfig.options, ), diff --git a/src/index.js b/src/index.js index 56ab60c..0319bcc 100644 --- a/src/index.js +++ b/src/index.js @@ -56,7 +56,7 @@ function runPackageScript({scriptConfig, options, input}) { ref: 'missing-script', }) } - const command = [script, ...args].join(' ').trim() + const command = [script, ...args, ...(options.args || [])].join(' ').trim() const log = getLogger(getLogLevel(options)) const showScript = options.scripts log.info(