Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: forward cli args #233

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/bin/nps.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -18,6 +25,7 @@ if (argv && psConfig) {
logLevel: argv.logLevel,
prefix: argv.prefix,
scripts: argv.scripts,
args: postCommandFlags,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

another alternative to this new flag would be to just concatenate all the args as space separated strings to argv._[0].

It would be the same functionality either way, since we can run a maximum of one script from the cli now.

},
psConfig.options,
),
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down