fix script argument regression, add process.argv.lsc #1014
Conversation
In commit 03c6e6a, removing the code that mutated process.argv also removed a side effect that prevented all arguments to lsc from being handled as scripts to compile and run. This caused a regression when running `lsc script-file.ls arg1 arg2` that would result in a crash when no `arg1.ls` file could be found. The regression is fixed by reintroducing the side effect to remove all but the first positional argument from the array containing the scripts to compile and run, but only when lsc is running scripts--batch compilation commands involving multiple input files should remain unaffected. This commit also adds a `process.argv.lsc` property, present only when a script is being interpreted by lsc, which is an array holding the name of the script being invoked along with any extra arguments not consumed by lsc. The intent here is to provide a way to get script arguments that's simpler and more reliable than picking through process.argv and skipping over elements like node, the lsc compiler itself, and any CLI options being provided to either.
Crickets and thumbs up, so I'm issuing final call for comments on this. Will merge on or after Friday, March 23 if nobody has anything to say. |
Passing
|
@corwin-of-amber, that's an interesting point. Part of why I wanted to add the |
Sounds to me like |
In commit 03c6e6a, removing the code that mutated process.argv also removed a side effect that prevented all arguments to lsc from being handled as scripts to compile and run. This caused a regression when running
lsc script-file.ls arg1 arg2
that would result in a crash when noarg1.ls
file could be found.The regression is fixed by reintroducing the side effect to remove all but the first positional argument from the array containing the scripts to compile and run, but only when lsc is running scripts—batch compilation commands involving multiple input files should remain unaffected.
This commit also adds a
process.argv.lsc
property, present only when a script is being interpreted by lsc, which is an array holding the name of the script being invoked along with any extra arguments not consumed by lsc. The intent here is to provide a way to get script arguments that's simpler and more reliable than picking through process.argv and skipping over elements like node, the lsc compiler itself, and any CLI options being provided to either.Fixes #1013. This is both a bug fix and an experimental feature (the
process.argv.lsc
part), so I would like to hear some feedback on whether this mild alternative to the originalprocess.argv
mutation that I nuked back in #959 is reasonable—if not, it wouldn't be hard to remove that part and just make this the bug fix.