feat: try adding local pre-release package in workspaces (#5733)

close #5316
This commit is contained in:
await-ovo
2022-12-03 06:50:53 +08:00
committed by GitHub
parent dd83e5974b
commit f3bfa2aae6
3 changed files with 46 additions and 1 deletions

View File

@@ -0,0 +1,6 @@
---
"@pnpm/npm-resolver": patch
"pnpm": patch
---
`pnpm add` should prefer local projects from the workspace, even if they use prerelease versions.

View File

@@ -291,7 +291,9 @@ function pickMatchingLocalVersionOrNull (
const localVersions = Object.keys(versions)
switch (spec.type) {
case 'tag':
return semver.maxSatisfying(localVersions, '*')
return semver.maxSatisfying(localVersions, '*', {
includePrerelease: true,
})
case 'version':
return versions[spec.fetchSpec] ? spec.fetchSpec : null
case 'range':

View File

@@ -1317,6 +1317,43 @@ test('resolve from local directory when package is not found in the registry and
expect(resolveResult!.manifest!.version).toBe('2.0.0')
})
test('resolve from local directory when package is not found in the registry and local prerelease available', async () => {
nock(registry)
.get('/is-positive')
.reply(404, {})
const cacheDir = tempy.directory()
const resolve = createResolveFromNpm({
cacheDir,
})
const resolveResult = await resolve({ alias: 'is-positive', pref: 'latest' }, {
projectDir: '/home/istvan/src',
registry,
workspacePackages: {
'is-positive': {
'3.0.0-alpha.1.2.3': {
dir: '/home/istvan/src/is-positive',
manifest: {
name: 'is-positive',
version: '3.0.0-alpha.1.2.3',
},
},
},
},
})
expect(resolveResult!.resolvedVia).toBe('local-filesystem')
expect(resolveResult!.id).toBe('link:is-positive')
expect(resolveResult!.latest).toBeFalsy()
expect(resolveResult!.resolution).toStrictEqual({
directory: '/home/istvan/src/is-positive',
type: 'directory',
})
expect(resolveResult!.manifest).toBeTruthy()
expect(resolveResult!.manifest!.name).toBe('is-positive')
expect(resolveResult!.manifest!.version).toBe('3.0.0-alpha.1.2.3')
})
test('resolve from local directory when package is not found in the registry and specific version is requested', async () => {
nock(registry)
.get('/is-positive')