Repository navigation
Conversation
…LockOnly is set When `npm exec`/`npx` or `npm init <initializer>` needs a package that is not installed, libnpmexec installs it to the npx cache and then runs its bin. If `dryRun` or `packageLockOnly` is set, Arborist skips that install, so the bin is missing and the command fails, even though the user never asked for the exec itself to be a dry run. This happens without anyone passing those flags to `npx` directly: lifecycle scripts inherit the parent command's config as `npm_config_*` environment variables, so a `prepublishOnly` script that runs `npx some-tool` fails under `npm publish --dry-run`, because it sees `npm_config_dry_run=true`. npm#4843 fixed this for `packageLockOnly` in `npm exec` only, by overriding it in `lib/commands/exec.js`. `npm init <initializer>` calls libnpmexec too, and still had the bug for both flags, and `npm exec` still had it for `dryRun`. This moves that override into libnpmexec, where the npx cache's Arborist is created, and extends it to `dryRun`, so every caller gets it. The existing `npm exec` `packageLockOnly` test still passes, and there are new tests in libnpmexec for both flags and in `npm exec` for `dry-run`.
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.
When
npm exec/npxornpm init <initializer>needs a package that is not installed, libnpmexec installs it to the npx cache and then runs its bin. IfdryRunorpackageLockOnlyis set, Arborist skips that install, so the bin is missing and the command fails, even though the user never asked for the exec itself to be a dry run.This happens without anyone passing those flags to
npxdirectly: lifecycle scripts inherit the parent command's config asnpm_config_*environment variables, so aprepublishOnlyscript that runsnpx some-toolfails undernpm publish --dry-run, because it seesnpm_config_dry_run=true.#4843 fixed this for
packageLockOnlyinnpm execonly, by overriding it inlib/commands/exec.js.npm init <initializer>calls libnpmexec too, and still had the bug for both flags, andnpm execstill had it fordryRun. This moves that override into libnpmexec, where the npx cache's Arborist is created, and extends it todryRun, so every caller gets it. The existingnpm execpackageLockOnlytest still passes, and there are new tests in libnpmexec for both flags and innpm execfordry-run.