You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When run from a workspace sub-folder, the npm run autocomplete only lists scripts from the workspace root package.json. This is a problem because those aren't the scripts that npm run actually can execute in that context. Trying to run one of the autocompleted script names will fail with "npm ERR! Error: Missing script".
Expected Behavior
It should list scripts from the nearest ancestor package.json, as that is what will actually be executed, not the ones from the root.
Steps To Reproduce
Make a new npm project with at least one workspace
Add a script to the root package.json file
Add a script to the workspace's package.json file
cd to the workspace folder
Type npm run and press Tab
Environment
npm: 10.2.5 (also reproducible on 9.8.1)
Node.js: 20.10.0 (also reproducible on 18.18.2)
OS Name: macOS
System Model Name: Macbook Pro
npm config:
npm ERR! code ENOWORKSPACES
npm ERR! This command does not support workspaces.
The text was updated successfully, but these errors were encountered:
The issue is in the static completion method for the run-script command. It always operates on npm.localPrefix which will be the root package.json for workspace.
Ideally that method could use the workspace directory if it was the pwd, or even parse the args so npm run -w workspace <tab> would find the directory for workspace.
PR makes `npm run` completion to take workspaces into account in case of
cwd is inside workspace dir it will autocompletes from `scripts` section
of nearest workspace's package.
Former behavoiur was to autocomplete everything from workspace root
package, it has no sense since when you are in workspace directory
script which will be suggested in such manner will not work. So there
was a mismatch between the script launch and the autocomplete hint
areas.
## References
Fixes [#7114](#7114)
Is there an existing issue for this?
This issue exists in the latest npm version
Current Behavior
When run from a workspace sub-folder, the
npm run
autocomplete only lists scripts from the workspace root package.json. This is a problem because those aren't the scripts thatnpm run
actually can execute in that context. Trying to run one of the autocompleted script names will fail with "npm ERR! Error: Missing script".Expected Behavior
It should list scripts from the nearest ancestor package.json, as that is what will actually be executed, not the ones from the root.
Steps To Reproduce
cd
to the workspace foldernpm run
and press TabEnvironment
The text was updated successfully, but these errors were encountered: