Repository navigation
Lenient package.json parsing, migrate to version_spec, and protocol fixes - #32
Merged
Merged
Conversation
- Fix `dependents_of` returning the package itself instead of its dependents.
- Parse local paths (`../foo`, `~/foo`, `/foo`, `C:\foo`) as `VersionProtocol::Path`
instead of GitHub shorthand, and SCP-like git URLs as `Git`.
- Keep the full GitHub reference, like `#semver:^5.0`.
- Match full versions without an operator in ranges exactly, like npm.
- Match `workspace:^1.0.0` and `workspace:~1.0.0` as ranges in the graph.
- Keep the alias for exact workspace versions (`WorkspaceProtocol::Version { alias, version }`).
- Don't split workspace paths containing `@`, and don't panic on non-ASCII values.
- Support more than 255 workspace packages.
- Detect Bun's `bun.lock` lockfile.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Preserve the order of maps, like `exports` conditions, when parsing leniently, by enabling `serde_json`'s `preserve_order`. - Convert partial hyphen ranges per `||` clause, like `1 - 2 || 3 - 4`. - Deserialize dependencies that aren't strings as `Unknown`, instead of dropping the whole map. - Error for duplicate package names in the graph. - Parse `x` and `X` as wildcards. - Parse hosted git shorthands, like `github:user/repo`, as `Git`. - Ignore build metadata when linking exact versions in the graph. - Support ranges in the workspace protocol (`WorkspaceProtocol::Range`). - Remove the unreachable `RangeMissingStartVersion` and `RangeMissingStopVersion` errors. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Summary
Makes
package.jsonparsing lenient and replaces thesemvercrate withversion_spec. It also fixes several protocol parsing and package graph bugs found in an audit. All of these change the public API, sonodejs_package_jsonandnodejs_package_graphneed a minor version bump.Changes
Lenient parsing
None) instead of failing the wholepackage.json.VersionProtocol::Unknown, including values that aren't strings, so one bad dependency no longer drops its whole map.serde_json'spreserve_orderis now enabled. Lenient parsing goes throughserde_json::Value, which sorted map keys when the crate was built on its own (the graph crate's dependencies enabled the feature, so its tests never noticed). That reorderedexportsconditions, which Node matches in order, along withscriptsandengines.semver→version_specVersionis nowversion_spec::Version. A single requirement isRequirement, and anything compound (>=1 <2,1.2.3 - 2.0.0,^1 || ^2) isVersionProtocol::Range(Range), which mirrorsUnresolvedVersionSpec.version_specparses npm spacing, wildcards, space-separated requirements, hyphen ranges and||itself, soclean_versionis removed. The remaining npm differences are handled in a newprotocols/range.rs:1.2.3 || 2.0.0no longer matches1.2.9).1.2 - 2, are converted for each||clause.>=1 <2), notversion_spec's&&.version_specis optional and enabled by theprotocolsfeature, as is its re-export.Protocol fixes
../foo,./x.tgz,~/x,/x,C:\x) parse as a newVersionProtocol::Pathinstead of being cut down to GitHub shorthand, like../foo/bar→../foo.user/repo#semver:^5.0). Git URLs ingit@host:repoform and the hosted shorthands (github:,gitlab:,bitbucket:,gist:) parse asGit.xandXare wildcards instead of tags.@aren't split.WorkspaceProtocol::Versionkeeps its alias.WorkspaceProtocol::Range).Package graph fixes
dependents_ofreturned the queried package instead of its dependents.workspace:^1.0.0andworkspace:~1.0.0are matched as ranges instead of needing an exact version.Rangedependencies and bare local paths now create edges.Package.indexis ausize).bun.lockis detected, as well asbun.lockb.PackageGraphError::DuplicatePackageNameinstead of silently overwriting each other.Breaking changes
VersionReq→Requirement/Range.VersionProtocol::Rangeholds aRange, and compound requirements are nowRangeinstead ofRequirement.VersionProtocol::PathWorkspaceProtocol::RangePackageGraphError::DuplicatePackageNameWorkspaceProtocol::Versionis nowVersion { alias, version }.Semver→SpecRangeMissingStartVersionandRangeMissingStopVersionare removed (they were unreachable).protocolsfeature.1.2.x→1.2.*, a bare1→~1, and>=1, <2→>=1 <2.preserve_orderalso turns it on for downstream crates.Testing
cargo test --workspace --all-features: 128 tests pass, with regression tests for each fix.cargo clippy --workspace --all-targets --all-features -- -D warningsis clean.nodejs_package_jsonbuilds with no features,protocols,serializeandmiette,protocols.preserve_orderwhen run with-p nodejs_package_json.🤖 Generated with Claude Code