diff --git a/src/index.ts b/src/index.ts index 9549cda7de..76c883cce3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -97,7 +97,7 @@ async function resolveNpm ( let version: string | undefined switch (spec.type) { case 'version': - version = spec.fetchSpec + version = semver.clean(spec.fetchSpec) as string break case 'tag': version = meta['dist-tags'][spec.fetchSpec] diff --git a/src/parsePref.ts b/src/parsePref.ts index 911ed9d596..117dfdef61 100644 --- a/src/parsePref.ts +++ b/src/parsePref.ts @@ -18,6 +18,7 @@ export default function parsePref (pref: string, alias?: string): RegistryPackag if (!name) { return null } + // TODO: this should also return the clean version of the spec (what semver.valid returns) const type = getVersionSelectorType(pref, true) if (type) { return { diff --git a/test/index.ts b/test/index.ts index 217da5f2ef..de5ede3a09 100644 --- a/test/index.ts +++ b/test/index.ts @@ -50,6 +50,15 @@ test('can resolve aliased scoped dependency', async t => { t.end() }) +test('can resolve package with version prefixed with v', async t => { + metaCache.clear() + const resolveResult = await resolveFromNpm({alias: 'is-positive', pref: 'v1.0.0'}, { + registry, + }) + t.equal(resolveResult!.id, 'localhost+4873/is-positive/1.0.0') + t.end() +}) + test("resolves to latest if it's inside the wanted range. Even if there are newer versions available inside the range", async t => { metaCache.clear() await addDistTag({package: 'pnpm-foo', version: '1.0.0', distTag: 'latest'})