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

CLI npm scripts and input .coffee file/s as last argument conflicting with --watch #5455

Open
danielbayley opened this issue Sep 14, 2023 · 2 comments

Comments

@danielbayley
Copy link
Contributor

The CLI doesn’t currently play nice with [p]npm scripts, when calling one from another…

Expected Behavior

In this contrived, simplified example:

// package.json
"scripts": {
  "compile": "coffee --compile *.coffee",
  "watch": "npm run compile -- --watch"
}
npm run watch

should run coffee in watch mode, but this seems to be impossible because of the design of the command line API.

Current Behavior

The above throws a File not found: .../my-project/--watch error.

Possible Solution

Allow the positional *.coffee parameter/s to be anywhere, rather than forcing it to be the last argument, or add some kind of -[-i]nput option.

Context

  • CoffeeScript version: 2.7.0
  • Node.js version: 20.6.1
@GeoffreyBooth
Copy link
Collaborator

Allow the positional *.coffee parameter/s to be anywhere

I don’t think this is possible, because some flags take values. You could argue that when a non-flag argument is passed after a flag that accepts values, treat it as a value else treat it as input, but I think this could be confusing UX. It’s very common to require the input to come last, like how the node command works.

Personally I don’t think this is so bad:

  "compile": "coffee --compile *.coffee",
  "wach": "coffee --watch --compile *.coffee"

If you’re determined for DRYness, maybe something like this would work:

  "coffee": "coffee $COFFEE_ARGS *.coffee",
  "compile": "COFFEE_ARGS=--compile npm run coffee",
  "watch": "COFFEE_ARGS='--compile --watch' npm run coffee"

@danielbayley
Copy link
Contributor Author

danielbayley commented Oct 2, 2023

I don’t think this is possible, because some flags take values.

Maybe I am missing something, but dozens of other cli’s don’t seem to have this problem…
Probably most of them use one of the available argument parsing libraries
Is this ultimately because CoffeeScript has no dependencies?

Personally I don’t think this is so bad:

  "compile": "coffee --compile *.coffee",
  "wach": "coffee --watch --compile *.coffee"

@GeoffreyBooth Sure, that isn’t so terrible. But as mentioned, the contrived example I gave was much simplified 😉

For reference, I also thought of this handy workaround (using pnpm and package.yaml, because—in the spirit of CoffeeScript—who sane wants to write JSON by choice?):

# package.yaml
scripts:
  compile: coffee --compile *.coffee
  watch: $npm_package_scripts_compile --watch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants