fix: pkg deps don't ignore the workspace project without set version (#4112)

close #3933
This commit is contained in:
zoomdong
2021-12-13 00:08:00 +08:00
committed by GitHub
parent b363f9fbfd
commit f82cc7f774
4 changed files with 62 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
---
"pkgs-graph": patch
---
fix: when set workspace protocol the pkgs in workspace without version not ignore

View File

@@ -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).

View File

@@ -91,6 +91,10 @@ export default function <T> (pkgs: Array<Package & T>, 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

View File

@@ -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',
},
},
},
})
})