feat: show available workspace versions on mismatch (#10466)

This commit is contained in:
Vedant Madane
2026-01-16 22:17:30 +05:30
committed by Zoltan Kochan
parent d75628a612
commit 1df570b468
3 changed files with 10 additions and 2 deletions

View File

@@ -216,6 +216,7 @@
"proxied",
"pwsh",
"quux",
"rcompare",
"redownload",
"refclone",
"reflattened",

View File

@@ -561,9 +561,16 @@ function tryResolveFromWorkspacePackages (
opts.update ? { name: spec.name, fetchSpec: '*', type: 'range' } : spec
)
if (!localVersion) {
const availableVersions = Array.from(workspacePkgsMatchingName.keys()).sort((a, b) => semver.rcompare(a, b))
throw new PnpmError(
'NO_MATCHING_VERSION_INSIDE_WORKSPACE',
`In ${path.relative(process.cwd(), opts.projectDir)}: No matching version found for ${opts.wantedDependency.alias ?? ''}@${opts.wantedDependency.bareSpecifier ?? ''} inside the workspace`
`In ${path.relative(process.cwd(), opts.projectDir)}: No matching version found for ${opts.wantedDependency.alias ?? ''}@${opts.wantedDependency.bareSpecifier ?? ''} inside the workspace` +
(availableVersions.length ? `. Available versions: ${availableVersions.join(', ')}` : ''),
availableVersions.length
? {
hint: `Available workspace versions for "${spec.name}": ${availableVersions.join(', ')}`,
}
: undefined
)
}
return resolveFromLocalPackage(workspacePkgsMatchingName.get(localVersion)!, spec, opts)

View File

@@ -1702,7 +1702,7 @@ test('workspace protocol: resolution fails if there is no matching local package
expect(err).toBeTruthy()
expect(err.code).toBe('ERR_PNPM_NO_MATCHING_VERSION_INSIDE_WORKSPACE')
expect(err.message).toBe(`In ${path.relative(process.cwd(), projectDir)}: No matching version found for is-positive@workspace:^3.0.0 inside the workspace`)
expect(err.message).toBe(`In ${path.relative(process.cwd(), projectDir)}: No matching version found for is-positive@workspace:^3.0.0 inside the workspace. Available versions: 2.0.0`)
})
test('workspace protocol: resolution fails if there are no local packages', async () => {