Skip to content

fix(install): reload user config after preinstall - #9909

Open
arhxam wants to merge 4 commits into
npm:latestfrom
arhxam:codex/preinstall-reload-user-config
Open

fix(install): reload user config after preinstall#9909
arhxam wants to merge 4 commits into
npm:latestfrom
arhxam:codex/preinstall-reload-user-config

Conversation

@arhxam

@arhxam arhxam commented Aug 22, 2026

Copy link
Copy Markdown

What / Why

npm 12 runs a local root preinstall before Arborist fetches dependencies, but npm install currently freezes its Arborist options before that hook. A credential helper can therefore replace an expired token in the configured user .npmrc, yet the active install still sends the old token and fails; only a second invocation succeeds.

Change

  • Add Config#reload(where) for already-loaded file-backed config layers. Reloading clears removed values, preserves the existing precedence chain, and invalidates flattened options.
  • Reload the user config after a successful local root preinstall and derive Arborist/script-policy options from the refreshed config.
  • Keep installs with arguments, global installs, and --ignore-scripts behavior unchanged.
  • Document the reload API and cover replacement, removal, environment precedence, flattened options, command integration, and the new debug-log event.

Testing

  • node ../../bin/npm-cli.js test -- --no-coverage from workspaces/config
  • node . run test -- test/lib/commands/install.js --no-coverage
  • node . run test
  • Local authenticated-registry reproduction with an expired user token: root preinstall replaced the token, then both the packument and tarball requests used the fresh bearer token and the first npm install completed.

References

Fixes #9853

AI assistance

This change was developed with AI assistance. I reproduced the stale-token behavior against the current latest branch, reviewed the credential/config precedence path, and ran the checks above locally.

@arhxam
arhxam requested review from a team as code owners August 22, 2026 13:15
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

Successfully merging this pull request may close these issues.

[BUG] Root preinstall cannot update registry credentials for the active npm install

1 participant