fix(install): repeat specs in global allow-scripts suggestion - #9840
Open
Ashish-CodeJourney wants to merge 1 commit into
Open
fix(install): repeat specs in global allow-scripts suggestion#9840Ashish-CodeJourney wants to merge 1 commit into
Ashish-CodeJourney wants to merge 1 commit into
Conversation
The blocked-install-scripts warning suggested `npm install -g --allow-scripts=<pkg>`, which has no install targets, so the command falls back to installing the current directory and fails with ENOENT reading package.json for anyone not sitting in a project. Build the suggestion from the command that was actually run and its positional specs, so `npm install -g esbuild` now suggests `npm install -g esbuild --allow-scripts=esbuild`. Commands invoked without specs (`npm update -g`) keep the bare form, which works. Fixes: npm#9835
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The blocked-install-scripts warning suggested
npm install -g --allow-scripts=<pkg>, which has no install targets, so the command falls back to installing the current directory and fails with ENOENT reading package.json for anyone not sitting in a project.Build the suggestion from the command that was actually run and its positional specs, so
npm install -g esbuildnow suggestsnpm install -g esbuild --allow-scripts=esbuild. Commands invoked without specs (npm update -g) keep the bare form, which works.Fixes: #9835
What / Why
Global installs have no project
package.json, sonpm install-scripts approvecannot be used. The warning instead points at--allow-scripts, but the command it prints is not runnable:npm install -gwith no positional specs installs the current directory, which a global installer is generally not sitting in, so the suggested remediation dead-ends on ENOENT.How
remediationLines()inlib/utils/reify-output.jsno longer hardcodesnpm install -g. It now calls a newglobalAllowScripts()helper, added next to the existingconfigSetAllowScripts()inlib/utils/allow-scripts-remediation.js, which rebuilds the command fromnpm.commandand the positional specs innpm.argv:Commands invoked without positional specs (e.g.
npm update -g) keep the barenpm update -g --allow-scripts=...form, which needs nopackage.jsonand already works.The same non-working example was documented in
npm install-scriptsandnpm approve-scripts; both are corrected.Tests
Two tests added to
test/lib/utils/reify-output.js, written failing first:lib/utils/reify-output.jsandlib/utils/allow-scripts-remediation.jsremain at 100% coverage.test/lib/utils/*,test/lib/commands/install*,update,cianddocsall pass.References
Fixes #9835