Skip to content

Ignore invalid unrelated package.json fields in JS detection - #161

Closed
tomdale wants to merge 1 commit into
moonrepo:masterfrom
tomdale:tomdale/fix-js-package-json-version-detection
Closed

Ignore invalid unrelated package.json fields in JS detection#161
tomdale wants to merge 1 commit into
moonrepo:masterfrom
tomdale:tomdale/fix-js-package-json-version-detection

Conversation

@tomdale

@tomdale tomdale commented Jun 26, 2026

Copy link
Copy Markdown

Summary

JavaScript tool version detection reads several package.json fields in priority order, including devEngines, packageManager, Volta, and engines. The detection path parsed the entire manifest through nodejs_package_json::PackageJson before looking at those individual fields, so one malformed version-like field could prevent discovery from reaching an unrelated valid field.

This PR changes detection to parse package.json as raw JSON first, then extract only the candidate strings relevant to the active tool. Node, Bun, and node-depman keep their existing source precedence, and the selected candidate is still parsed through UnresolvedVersionSpec, so malformed authoritative values for the active tool still fail.

The shared extraction covers devEngines object and array forms, engines, packageManager values with Corepack hashes, and Volta including extends. The affected crates no longer depend directly on nodejs_package_json for detection.

Fixes #159.

Verification

  • cargo build -p node_tool -p node_depman_tool -p bun_tool --target wasm32-wasip1
  • cargo test -p node_tool --no-default-features --test versions_test
  • cargo test -p node_depman_tool --no-default-features --test versions_test
  • cargo test -p bun_tool --no-default-features --test versions_test

Parse package.json as raw JSON during JavaScript tool version detection so unrelated malformed version fields do not prevent valid Node, Bun, or package manager fields from being discovered.

Add pnpm coverage for the moonrepo#159 regression and devEngines packageManager arrays.

Fixes moonrepo#159
@milesj

milesj commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Thanks for the contribution, but I'd rather just fix nodejs_package_json.

@milesj

milesj commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

@tomdale Patched here if you want to pull it in milesj/rust-js-ecosystem#30

Edit: actually bumping here #162

@tomdale

tomdale commented Jul 11, 2026

Copy link
Copy Markdown
Author

Thank you!

@tomdale tomdale closed this Jul 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

JavaScript tool version detection can ignore valid fields when another package.json version field is invalid

2 participants