Repository navigation
Handle registry-qualified versions and runtimes in pnpm lockfiles #1913
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| # pnpm v10-v12 detector support tracker | ||
|
|
||
| **Status:** Initial research recorded November 18, 2026. Registry-qualified version handling and pnpm-managed runtime skipping are implemented; broader compatibility fixtures are pending. | ||
|
|
||
| **Goal:** Detect resolved npm dependencies from pnpm v10, v11, and v12 standalone projects and workspaces that use lockfile schema `9.0`, including lockfile-recorded config and package-manager dependencies. The opt-in `13.0` schema is out of scope. Preserve existing lockfile v5, v6, and v9 behavior. This is a static scan: do not run pnpm, execute hooks, or resolve missing versions against a registry. | ||
|
|
||
| ## Current baseline | ||
|
|
||
| The [Pnpm detector](pnpm.md) dispatches on **lockfile schema**, not the pnpm CLI major. It recognizes schemas 5, 6, and 9 and searches `pnpm-lock.yaml` and legacy `shrinkwrap.yaml`. It does not read `pnpm-workspace.yaml` directly; workspace detection uses the resolved projects in the lockfile's `importers`. | ||
|
|
||
| The [schema 9 parser](../../src/Microsoft.ComponentDetection.Detectors/pnpm/Pnpm9Detector.cs) builds the graph from `importers` and `snapshots`, including the two-document layout when both documents declare `9.0`. It reads optional roots, but the shared [snapshot model](../../src/Microsoft.ComponentDetection.Detectors/pnpm/Contracts/Package.cs) has no `optionalDependencies` edges. It does not read `resolution` metadata, so nested resolution shapes parse. The [version reader](../../src/Microsoft.ComponentDetection.Detectors/pnpm/ParsingUtilities/PnpmParsingUtilitiesFactory.cs) rejects different version strings across documents before graph parsing. Existing multi-document tests use synthetic examples; recognizing a schema number is not evidence that every CLI release or feature works. | ||
|
|
||
| ## pnpm v10: schema 9.0 with new dependency forms | ||
|
|
||
| The [v10 lockfile writer][v10-writer] still emits [`9.0`][v10-schema] with `importers`, `packages`, and `snapshots`. Keep the schema 9 parser and test the newer entries that can appear inside it. | ||
|
|
||
| | Change | Detector impact | | ||
| | --- | --- | | ||
| | [v10.0][v10-release] switches long peer suffixes and patch/checksum fields to SHA-256, manages the pinned pnpm version by default, and blocks dependency lifecycle scripts by default. | Match full snapshot keys without assuming a hash algorithm. Keep peer and patch context for edges without making it part of the npm component version. Build approval and package-manager switching do not require re-running install logic. | | ||
| | v10.0 changes workspace linking and requires injected workspace packages for the new `deploy` flow. It also drops automatic conversion from lockfile v6. | Cover external dependencies reached through injected workspace packages; preserve the scanner's independent v6 reader. | | ||
| | [Config dependencies][v10-config] are pinned as `version+integrity` in `pnpm-workspace.yaml`. | They can be absent from `pnpm-lock.yaml` and are invisible to the current detector. Decide whether to add a narrow manifest reader for these exact pins; do not treat arbitrary catalog ranges or overrides as installed packages. | | ||
| | [v10.9 adds `jsr:`][v10-year]; [v10.12.1 adds catalog modes][v10-catalogs]. | Verify how JSR and npm aliases resolve in the lockfile. Use the actual locked target for `catalog:` dependencies, not the alias or the catalog range. | | ||
| | [v10.14][v10-runtime] locks Node.js, Deno, and Bun from `devEngines.runtime`; [v10.21][v10-transitive-runtime] also installs Node.js for dependencies' `engines.runtime`. | **Done:** `<name>@runtime:<version>` entries are skipped, including direct and transitive references, and their nested `variations` resolutions parse. | | ||
|
|
||
| ## pnpm v11: schema 9.0 with an environment document | ||
|
|
||
| - The [v11.0.0 constant][v11-schema] remains `9.0`. The [release notes][v11-release] move config-dependency resolutions and integrity out of `pnpm-workspace.yaml` into an optional first YAML document. It also contains resolved pnpm pins (`packageManagerDependencies`), including versions selected from a `devEngines.packageManager` range. The last document contains the project graph. The [v11 writer][v11-env] initializes the environment document with `9.0`; [upstream compatibility tests][v11-env-tests] also use the nonnumeric `env-1.0` marker. Treat that marker as a fixture candidate for a recognized environment shape, not the default v11 output. | ||
| - The [v11.0 release][v11-release] moves general project settings into `pnpm-workspace.yaml`, adds scoped `registries` and per-project `packageConfigs`, replaces the old build-approval settings with `allowBuilds`, and introduces `dedupePeers`, which can shorten nested peer suffixes. [v11.2][v11-optional] includes one level of config-package optional dependencies and records all platform variants. Test both peer forms and optional edges; do not simulate settings, registry access, or build policies. | ||
| - [Named registry support][v11-sources] adds dependency aliases in v11.1, and [v11.20][registry-keys] uses registry-qualified keys (`name@registry:version`). [v11.25][v11-revisions] adds registry revisions, and [v11.26][v11-workspace-catalogs] allows `workspace:` ranges in catalogs. Preserve source distinctions for graph lookup and verify component identity separately. | ||
| - [Upstream runtime examples][runtime-shapes] record entries like `node@runtime:22.0.0` and nest platform variants under `resolution`. **Done:** the parser no longer reads `resolution`, so these entries don't stop the rest of the npm graph from being reported, and runtime entries are skipped. | ||
|
|
||
| ## pnpm v12: schema 9.0 | ||
|
|
||
| [pnpm v12.0][v12-release] switches the CLI to Rust but [retains schema 9.0][v12-schema]. Treat it as another writer to test, not a reason to route on the CLI major. Upstream's [release listing][releases] shows `12.22.0` as the current v12 release as of this research. | ||
|
|
||
| | Change | Detector impact | | ||
| | --- | --- | | ||
| | v12.0 adds registry revisions (`resolution.revision`, with `+rN` pins) and can manage other package managers and runtimes. [v12.13][package-sources] adds `tool:` but still writes `runtime:` in the lockfile. [v12.15][v12-includes] adds `lockfile.integrityTarget: tar` and tar registries. | Verify that revision and integrity metadata do not change npm identity accidentally. **Done:** resolution metadata is not read, and `runtime:` tools, including Yarn 6, are skipped instead of being labeled as npm packages. | | ||
| | [v12.2-v12.3][v12-workspace-catalogs] adds `workspace:` support inside catalogs; [v12.6][v12-local-catalogs] adds `file:` and `link:`. [v12.7][v12-workspaces] can create `pnpm-workspace.yaml` from `package.json` workspace globs. [v12.12][v12-config] supports saving config-dependency ranges, and v12.15 can delegate named settings via `include`. | Test locked external dependencies of linked and injected projects, and use the exact environment resolution for config dependencies. Do not follow includes or infer dependencies from workspace globs when the lockfile already supplies the graph. | | ||
| | [v12.4][v12-polyglot] manages Cargo and Python in the same workspace but retains their separate `Cargo.lock` and `pylock.toml`. | Keep ecosystem attribution separate. Track any missing Cargo/Python coverage with the respective detectors. | | ||
| | [v12.16][v12-registry-keys] consistently uses registry-qualified keys for a registry with a prefix. [v12.18][v12-variants] adds platform variants for npm packages served by pnpr, not just for runtime binaries. | Keep registry-qualified graph keys and export the bare semantic version. **Done:** packages with nested variant resolutions parse and are reported as npm packages. | | ||
|
|
||
| [v12.19][v12-next] also introduced experimental `lockfile.format: v13`. That format remains unsupported. | ||
|
|
||
| ## Implementation and verification | ||
|
|
||
| - [x] Compare release notes and tagged upstream writers with the local dispatch, graph model, and existing tests. | ||
| - [x] Fix the v12 schema 9 regression where a named-registry key such as `sample@my-registry:0.1.12` exported `my-registry:0.1.12` instead of `0.1.12`, which Governance rejected. Retain the full key for direct and transitive lookups and preserve pnpm protocol prefixes that are not [registry aliases][registry-aliases]. | ||
| - [x] Skip pnpm-managed runtimes and tools (`<name>@runtime:<version>`) instead of reporting them as npm packages with an invalid `runtime:` version. Stop reading `resolution` so nested `variations` resolutions from runtimes and pnpr variant packages no longer fail the whole lockfile. | ||
| - [ ] Generate minimal standalone and multi-project fixtures, starting with pnpm `10.31.0`, `11.0.0`, `11.28.13`, `12.0.0`, and `12.22.0`. Record the producer, settings, and expected graph with each fixture; commit the resulting inputs so detector tests can run offline. Include shared and per-project locks (`sharedWorkspaceLockfile: false`). | ||
| - [ ] Extend the existing schema 9 parser where fixtures show gaps: optional transitive edges, aliases, and peer/patch-aware lookups. Cover the v10 manifest-only config pin if in scope. Keep ordinary npm component IDs and direct/dev attribution stable. | ||
| - [ ] Make document selection role-aware: parse the project version from the last document, validate and read a recognized environment document separately, and register config and manager dependencies without joining unrelated snapshot edges across documents. Verify whether to support an environment-only file: the upstream writer can leave the project document empty before the first full install. Reject extra documents and arbitrary mixed schemas. | ||
| - [ ] Add targeted graph assertions to [PnpmDetectorTests](../../test/Microsoft.ComponentDetection.Detectors.Tests/PnpmDetectorTests.cs) and end-to-end inputs under [verification resources](../../test/Microsoft.ComponentDetection.VerificationTests/resources/pnpm). Assert identities, direct/transitive and optional edges, production winning over dev when both are reachable, and no loss of ordinary npm packages in mixed inputs. Retain v5/v6/v9 regressions and bump the `Pnpm` detector result version when output changes. | ||
|
|
||
| **Next implementation slice:** Verify schema 9 compatibility on v10, v11, and default v12 output. Track workspace-only declarations, alternate lockfile paths such as branch lockfiles, and inventory of non-npm tools separately unless the fixture work makes them essential. | ||
|
|
||
| [v10-release]: https://github.com/pnpm/pnpm/releases/tag/v10.0.0 | ||
| [v10-writer]: https://github.com/pnpm/pnpm/blob/v10.31.0/lockfile/fs/src/lockfileFormatConverters.ts | ||
| [v10-schema]: https://github.com/pnpm/pnpm/blob/v10.31.0/packages/constants/src/index.ts | ||
| [v10-config]: https://pnpm.io/10.x/config-dependencies | ||
| [v10-year]: https://pnpm.io/blog/2025/12/29/pnpm-in-2025 | ||
| [v10-catalogs]: https://github.com/pnpm/pnpm/releases/tag/v10.12.1 | ||
| [v10-runtime]: https://pnpm.io/blog/releases/10.14 | ||
| [v10-transitive-runtime]: https://pnpm.io/blog/releases/10.21 | ||
| [v11-release]: https://pnpm.io/blog/releases/11.0 | ||
| [v11-schema]: https://github.com/pnpm/pnpm/blob/v11.0.0/core/constants/src/index.ts | ||
| [v11-env]: https://github.com/pnpm/pnpm/blob/v11.0.0/lockfile/fs/src/envLockfile.ts | ||
| [v11-env-tests]: https://github.com/pnpm/pnpm/blob/v11.0.0/lockfile/fs/test/write.test.ts | ||
| [v11-optional]: https://pnpm.io/blog/releases/11.2 | ||
| [v11-sources]: https://pnpm.io/blog/releases/11.1 | ||
| [registry-keys]: https://pnpm.io/blog/releases/11.20 | ||
| [v11-revisions]: https://pnpm.io/blog/releases/11.25 | ||
| [v11-workspace-catalogs]: https://pnpm.io/blog/releases/11.26 | ||
| [runtime-shapes]: https://github.com/pnpm/pacquet/issues/437 | ||
| [v12-release]: https://github.com/pnpm/pnpm/releases/tag/v12.0.0 | ||
| [v12-schema]: https://github.com/pnpm/pnpm/blob/v12.0.0/pnpm/crates/lockfile/src/lib.rs | ||
| [releases]: https://github.com/pnpm/pnpm/releases | ||
| [v12-workspace-catalogs]: https://pnpm.io/blog/releases/12.2-12.3 | ||
| [v12-polyglot]: https://pnpm.io/blog/releases/12.4 | ||
| [v12-local-catalogs]: https://pnpm.io/blog/releases/12.6 | ||
| [v12-workspaces]: https://pnpm.io/blog/releases/12.7 | ||
| [v12-config]: https://pnpm.io/blog/releases/12.12.0 | ||
| [package-sources]: https://pnpm.io/package-sources | ||
| [v12-includes]: https://pnpm.io/blog/releases/12.15.0 | ||
| [v12-registry-keys]: https://pnpm.io/blog/releases/12.16.0 | ||
| [v12-variants]: https://pnpm.io/blog/releases/12.18.0 | ||
| [v12-next]: https://pnpm.io/blog/releases/12.19.0 | ||
| [registry-aliases]: https://github.com/pnpm/pnpm/blob/v12.22.0/pnpm/crates/deps-path/src/registry_qualified.rs | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,7 +15,7 @@ public class Package | |
| [YamlMember(Alias = "name")] | ||
| public string Name { get; set; } | ||
|
|
||
| [YamlMember(Alias = "resolution")] | ||
| [YamlIgnore] | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why are we ignoring this, even with a breaking change it should only leave it empty, no need to ignore preexisting contracts afaik |
||
| public Dictionary<string, string> Resolution { get; set; } | ||
|
|
||
| [YamlMember(Alias = "version")] | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,8 @@ | ||
| #nullable disable | ||
| namespace Microsoft.ComponentDetection.Detectors.Pnpm; | ||
|
|
||
| using System.Linq; | ||
| using global::NuGet.Versioning; | ||
| using Microsoft.ComponentDetection.Contracts; | ||
| using Microsoft.ComponentDetection.Contracts.TypedComponent; | ||
|
|
||
|
|
@@ -21,7 +23,7 @@ public override DetectedComponent CreateDetectedComponentFromPnpmPath(string pnp | |
| // An example of a dependency path with these: /[email protected]([email protected])([email protected])([email protected]) | ||
| (var fullPackageName, var packageVersion) = this.ExtractNameAndVersionFromPnpmPackagePath(pnpmPackagePath); | ||
|
|
||
| return new DetectedComponent(new NpmComponent(fullPackageName, packageVersion)); | ||
| return new DetectedComponent(new NpmComponent(fullPackageName, GetComponentVersion(packageVersion))); | ||
| } | ||
|
|
||
| public override (string FullPackageName, string PackageVersion) ExtractNameAndVersionFromPnpmPackagePath(string pnpmPackagePath) | ||
|
|
@@ -69,4 +71,27 @@ public override string ReconstructPnpmDependencyPath(string dependencyName, stri | |
| return $"{dependencyName}@{dependencyVersion}"; | ||
| } | ||
| } | ||
|
|
||
| private static string GetComponentVersion(string packageVersion) | ||
| { | ||
| var separator = packageVersion.IndexOf(':'); | ||
| if (separator <= 0 || !char.IsAsciiLetter(packageVersion[0])) | ||
| { | ||
| return packageVersion; | ||
| } | ||
|
|
||
| var prefix = packageVersion[..separator]; | ||
|
|
||
| // These pnpm protocol prefixes cannot be named registry aliases. | ||
| if (prefix is "bitbucket" or "catalog" or "custom" or "file" or "git" or "github" or "gitlab" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. where is this list coming from? This looks a bit brittle and random, but possibly PNPM has a link somewhere about why these protocol prefixes are important. Important to include a link to that doc and a few words for context. If PNPM defines a registry-name grammar that we can implement/reference that would be great to encapsulate and include a link to docs of where that came from. Something like: |
||
| or "http" or "https" or "jsr" or "link" or "npm" or "pkg" or "runtime" or "ssh" or "tool" or "workspace" | ||
| || !prefix.All(c => char.IsAsciiLetterOrDigit(c) || c is '.' or '_' or '-')) | ||
| { | ||
| return packageVersion; | ||
| } | ||
|
|
||
| // Only normalize the exported version; snapshot lookups still use the full key. | ||
| var version = packageVersion[(separator + 1)..]; | ||
| return SemanticVersion.TryParse(version, out _) ? version : packageVersion; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's please remove this markdown file, let's keep our docs human-readable, the pnpm.md should be all we need