fix: make npm version safe to run in parallel across workspaces#9730
Open
alaminrifat wants to merge 4 commits into
Open
fix: make npm version safe to run in parallel across workspaces#9730alaminrifat wants to merge 4 commits into
alaminrifat wants to merge 4 commits into
Conversation
2 tasks
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.
Running
npm versionin parallel across many workspaces (e.g. withxargs -Por ultra-runner) intermittently fails withEJSONPARSE, because one npm process can read apackage.jsonthat another process is writing at that moment.There are two places where this race happens:
workspaces/configloadLocalPrefix): when the cwd is inside a workspace, it callsmapWorkspaces()on the root, which parses every sibling workspace'spackage.json. If any of them is mid-write, config load throws and the whole npm invocation fails before any command runs. This is deterministically reproducible: empty out one workspace'spackage.jsonand run any npm command from inside another workspace.npm versionitself:changeWorkspaces()runssetWorkspaces()(another fullmapWorkspaces()pass over the monorepo) and thenupdateWorkspaces()(an Arborist reify at the root), even when the only selected workspace came implicitly from the cwd.Changes:
lib/commands/version.js: when the workspace is selected implicitly (cwd inside a workspace, no--workspace/--workspacesflags), bump only that workspace — no monorepo traversal, no root reify. Explicit--workspace/--workspacesbehavior is unchanged.workspaces/config/lib/index.js: if the workspace map cannot be read during workspace-root detection, log a warning and fall back to treating the current prefix as a standalone project instead of failing the entire config load.Verification:
npm version patch --no-git-tag-versionrun with 12-way parallelism: 2/40 invocations failed before this change, 0/40 after, with every workspace bumped exactly once.libnpmversioncall, no lockfile creation) and the corrupt-sibling scenario at both the command and config layers.test/lib/commands/version.jsandworkspaces/configsuites pass unchanged.References
Fixes #9412