1

Let's say I have the following in a file called print-last-arg.js:

console.log(process.argv[process.argv.length-1])

And the following scripts in my package.json:

"scripts": {
  "print_a": "node print-last-arg.js",
  "print_b": "npm run print_a"
}

When I run npm run print_a -- --foo=bar, I get --foo=bar as expected.

However, npm run print_b -- --foo=bar gives me no output.

How do I pass the CLI arguments from print_b to print_a?

2

1 Answer 1

2

It turns out that you just have to add an extra -- on the end of print_b, which will tell npm to pass whatever arguments print_b got to print_a. So,

"scripts": {
  "print_a": "node print-last-arg.js",
  "print_b": "npm run print_a"
}

becomes

"scripts": {
  "print_a": "node print-last-arg.js",
  "print_b": "npm run print_a -- "
}

Voilà! Now npm run print_b -- --foo=bar prints --foo=bar as expected.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.