Skip to content

Commit e85b0d3

Browse files
fix(packages): no longer match versionless packages (#10056)
### Description Previously we had matched version constraints on workspace packages that didn't have versions. This did not match actual package manager implementations. To give a concrete example: ``` [0 olszewski@macbookpro] /tmp/pnpm-prune-test $ tree . ├── node_modules ├── package.json ├── packages │ ├── a │ │ ├── node_modules │ │ │ └── b -> ../../../node_modules/.pnpm/[email protected]/node_modules/b │ │ └── package.json │ └── b │ └── package.json ├── pnpm-lock.yaml └── pnpm-workspace.yaml [0 olszewski@macbookpro] /tmp/pnpm-prune-test $ cat packages/a/package.json {"name": "a", "dependencies": {"b": "2.0.1"}} [0 olszewski@macbookpro] /tmp/pnpm-prune-test $ cat packages/b/package.json {"name": "b"} [0 olszewski@macbookpro] /tmp/pnpm-prune-test $ cat pnpm-lock.yaml lockfileVersion: '6.0' settings: autoInstallPeers: true excludeLinksFromLockfile: false importers: .: {} packages/a: dependencies: b: specifier: 2.0.1 version: 2.0.1 packages/b: {} packages: /[email protected]: resolution: {integrity: sha512-JBWAj6f91ocNLbdg1jCGrxHXSWbQDsxgqVmKeO0TellEcq9LCvJ97iWG6p3otCt/v08/hHrWwAB9vNYS9y70IQ==} engines: {node: '>= 0.8.0'} dev: false ``` As you can see `a` is using a `b` from the NPM registry and not the workspace package `b` that does not have a version. ### Testing Instructions Added red -> green unit test I spot checked and all of the following would not match a versionless workspace dependency when provided a constraint: - npm 8,9,10 - yarn 1, 3, 4 - pnpm 8, 9, 10
1 parent bee59c1 commit e85b0d3

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

crates/turborepo-repository/src/package_graph/dep_splitter.rs

+6
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@ impl<'a> DependencyVersion<'a> {
170170
false
171171
}
172172
_ if self.version == "*" => true,
173+
_ if package_version.is_empty() => {
174+
// The workspace version of this package does not contain a version, no version
175+
// based constraints will match it so it must be external.
176+
false
177+
}
173178
_ => {
174179
// If we got this far, then we need to check the workspace package version to
175180
// see it satisfies the dependencies range to determine whether
@@ -234,6 +239,7 @@ mod test {
234239
#[test_case("1.2.3", Some("foo"), "workspace:@scope/foo@^", Some("@scope/foo"), true ; "handles pnpm alias caret")]
235240
#[test_case("1.2.3", None, "1.2.3", None, false ; "no workspace linking")]
236241
#[test_case("1.2.3", None, "workspace:1.2.3", Some("@scope/foo"), false ; "no workspace linking with protocol")]
242+
#[test_case("", None, "1.2.3", None, true ; "no workspace package version")]
237243
fn test_matches_workspace_package(
238244
package_version: &str,
239245
dependency_name: Option<&str>,

0 commit comments

Comments
 (0)