npm / cli

the package manager for JavaScript
https://docs.npmjs.com/cli/
Other
8.46k stars 3.15k forks source link

[BUG] --scr and some other npm config variables not allowed #6618

Open emilh91 opened 1 year ago

emilh91 commented 1 year ago

Is there an existing issue for this?

This issue exists in the latest npm version

Current Behavior

emil@Emils-MBP:~/Desktop/npm-run-flag-test$ npm start --scr=foo

> npm-run-flag-test@1.0.0 start
> env | grep npm_config_s | sort

npm ERR! code ENOENT
npm ERR! syscall spawn foo
npm ERR! path /Users/emil/Desktop/npm-run-flag-test
npm ERR! errno -2
npm ERR! enoent spawn foo ENOENT
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent 

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/emil/.npm/_logs/2023-06-30T14_37_13_384Z-debug-0.log

The above output can also be seen when using --scri, --scrip, and --script too.

Expected Behavior

emil@Emils-MBP:~/Desktop/npm-run-flag-test$ npm start --scripty=foo

> npm-run-flag-test@1.0.0 start
> env | grep npm_config_s | sort

npm_config_scripty=foo
npm_lifecycle_script=env | grep npm_config_s | sort

I would expect the above output, but with scr|scri|scrip|script in lieu of scripty.

Steps To Reproduce

On npm 8 (and 9)...

With the following package.json...

{
  "name": "npm-run-flag-test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "env | grep npm_config_s | sort"
  },
  "author": "",
  "license": "ISC"
}

Running any of the following:

... Yields the above error

Environment

emilh91 commented 1 year ago

I discovered this issue when I was migrating some code from Node 14 (and npm 6) to Node 16 (and npm 8). I checked to see if it was fixed in Node 18 (and npm 9), but the issue is still present in the latest npm it seems. I have since moved to simply using --file (instead of --script and after trying --scr) and that seems to work for now. But I wanted to flag this in case it was not intentional, since I did not see this documented.