mirror of
https://github.com/pnpm/pnpm.git
synced 2026-03-31 13:32:18 -04:00
fix: print the actual version in no matching version error
close #1314 PR #2851
This commit is contained in:
5
.changeset/shiny-years-brush.md
Normal file
5
.changeset/shiny-years-brush.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@pnpm/npm-resolver": patch
|
||||
---
|
||||
|
||||
When no matching version is found, report the actually specified version spec in the error message (not the normalized one).
|
||||
@@ -23,7 +23,6 @@ import pickPackage, {
|
||||
PackageMetaCache,
|
||||
PickPackageOptions,
|
||||
} from './pickPackage'
|
||||
import toRaw from './toRaw'
|
||||
import path = require('path')
|
||||
import LRU = require('lru-cache')
|
||||
import normalize = require('normalize-path')
|
||||
@@ -33,8 +32,11 @@ import ssri = require('ssri')
|
||||
|
||||
class NoMatchingVersionError extends PnpmError {
|
||||
public readonly packageMeta: PackageMeta
|
||||
constructor (opts: { spec: RegistryPackageSpec, packageMeta: PackageMeta}) {
|
||||
super('NO_MATCHING_VERSION', `No matching version found for ${toRaw(opts.spec)}`)
|
||||
constructor (opts: { wantedDependency: WantedDependency, packageMeta: PackageMeta}) {
|
||||
const dep = opts.wantedDependency.alias
|
||||
? `${opts.wantedDependency.alias}@${opts.wantedDependency.pref ?? ''}`
|
||||
: opts.wantedDependency.pref!
|
||||
super('NO_MATCHING_VERSION', `No matching version found for ${dep}`)
|
||||
this.packageMeta = opts.packageMeta
|
||||
}
|
||||
}
|
||||
@@ -149,7 +151,7 @@ async function resolveNpm (
|
||||
const resolvedFromLocal = tryResolveFromWorkspacePackages(workspacePackages, spec, opts.projectDir)
|
||||
if (resolvedFromLocal) return resolvedFromLocal
|
||||
}
|
||||
throw new NoMatchingVersionError({ spec, packageMeta: meta })
|
||||
throw new NoMatchingVersionError({ wantedDependency, packageMeta: meta })
|
||||
}
|
||||
|
||||
if (workspacePackages?.[pickedPackage.name] && opts.projectDir) {
|
||||
|
||||
@@ -792,7 +792,7 @@ test('error is thrown when there is no package found for the requested range', a
|
||||
await resolveFromNpm({ alias: 'is-positive', pref: '^1000.0.0' }, { registry })
|
||||
t.fail('installation should have failed')
|
||||
} catch (err) {
|
||||
t.ok(err.message.startsWith('No matching version found for is-positive@>=1000.0.0 <1001.0.0'), 'failed with correct error message')
|
||||
t.ok(err.message.startsWith('No matching version found for is-positive@^1000.0.0'), 'failed with correct error message')
|
||||
t.end()
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user