fix: print the actual version in no matching version error

close #1314
PR #2851
This commit is contained in:
Zoltan Kochan
2020-09-13 15:53:31 +03:00
committed by GitHub
parent 86cd72de33
commit 3633f5e46a
3 changed files with 12 additions and 5 deletions

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

View File

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

View File

@@ -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()
}
})