Passing arbitrary flags through to Node
Is there/can there be a way to pass arguments on to Node (for instance to set Node's debug port). For instance if I had rejoice -c manifest.js -p . -- --debug-brk=5959 as the target of a run script, everything after -- would be passed directly to Node.
I posted a work-around on StackOverflow, but having a cleaner syntax[1] would be nicer.
[1] Reaching into node_modules/.bin feels wrong and possibly brittle, and it side-steps one of the major benefits to using run scripts in the first place.
Have you checked out the yargs library?
node index.js --id 'ID ARG' --otherFlag 'other stuff'
const argv = require('yargs')
.usage('$0 --id default --otherFlag other')
.option('id', {
alias: 'id',
describe: 'flag description',
demandOption: true,
type: 'string'
})
.option('otherFlag', {
alias: 'other',
describe: 'second flag description',
demandOption: true,
type: 'string'
})
.argv
console.log('ID:', argv.id);
console.log('OTHER:', argv.otherFlag);
Not sure if that's exactly what you're looking for or not.
I'm not trying to parse command line flags myself, and I am not using a wrapper script around rejoice.
Just to clarify why I'm asking. Currently my package.json scripts include:
"start": "rejoice -c manifest.js -p ."
"debug": "node --debug-brk=5959 node_modules/.bin/rejoice -c manifest.js -p ."
Please note the disparity between start and debug. What I'm asking for would allow me to have this instead:
"start": "rejoice -c manifest.js -p ."
"debug": "rejoice -c manifest.js -p . -- --debug-brk=5959"
Everything after -- would be passed through directly to the underlying Node process.
Ah, sorry, misunderstood the end goal. I'm not sure about how to get there, sorry. :\
Hopefully someone else can lend their insight
I think what you have is perfectly valid and I have done this approach as well in the past. I am open to suggestions but I would stick with just calling node, passing the args and then calling rejoice just as you have done.