diff --git a/.changeset/dirty-cups-live.md b/.changeset/dirty-cups-live.md new file mode 100644 index 0000000000..35e7dc3b5f --- /dev/null +++ b/.changeset/dirty-cups-live.md @@ -0,0 +1,5 @@ +--- +"pkgs-graph": patch +--- + +fix: when set workspace protocol the pkgs in workspace without version not ignore diff --git a/.changeset/mean-lamps-march.md b/.changeset/mean-lamps-march.md new file mode 100644 index 0000000000..b4f99f180b --- /dev/null +++ b/.changeset/mean-lamps-march.md @@ -0,0 +1,5 @@ +--- +"pnpm": patch +--- + +When sorting workspace projects, don't ignore the manifests of those that don't have a version field [#3933](https://github.com/pnpm/pnpm/issues/3933). diff --git a/packages/pkgs-graph/src/index.ts b/packages/pkgs-graph/src/index.ts index f232c66b46..32134a4aaa 100644 --- a/packages/pkgs-graph/src/index.ts +++ b/packages/pkgs-graph/src/index.ts @@ -91,6 +91,10 @@ export default function (pkgs: Array, opts?: { unmatched.push({ pkgName: depName, range: rawSpec }) return '' } + if (isWorkspaceSpec && versions.length === 0) { + const matchedPkg = pkgs.find(pkg => pkg.manifest.name === depName) + return matchedPkg!.dir + } if (versions.includes(rawSpec)) { const matchedPkg = pkgs.find(pkg => pkg.manifest.name === depName && pkg.manifest.version === rawSpec) return matchedPkg!.dir diff --git a/packages/pkgs-graph/test/index.ts b/packages/pkgs-graph/test/index.ts index 4bd9302579..b4c734472b 100644 --- a/packages/pkgs-graph/test/index.ts +++ b/packages/pkgs-graph/test/index.ts @@ -669,3 +669,51 @@ test('* matches prerelease versions', () => { }, }) }) + +// fix: https://github.com/pnpm/pnpm/issues/3933 +test('successfully create a package graph even when a workspace package has no version', async () => { + const result = createPkgGraph([ + { + dir: BAR1_PATH, + manifest: { + dependencies: { + foo: 'workspace:*', + }, + name: 'bar', + version: '1.0.0', + }, + }, + { + dir: FOO1_PATH, + manifest: { + name: 'foo', + }, + }, + ]) + + expect(result.unmatched).toStrictEqual([]) + expect(result.graph).toStrictEqual({ + [BAR1_PATH]: { + dependencies: [FOO1_PATH], + package: { + dir: BAR1_PATH, + manifest: { + dependencies: { + foo: 'workspace:*', + }, + name: 'bar', + version: '1.0.0', + }, + }, + }, + [FOO1_PATH]: { + dependencies: [], + package: { + dir: FOO1_PATH, + manifest: { + name: 'foo', + }, + }, + }, + }) +})