Skip to content

Commit

Permalink
feat: try adding local pre-release package in workspaces (#5733)
Browse files Browse the repository at this point in the history
close #5316
  • Loading branch information
await-ovo committed Dec 2, 2022
1 parent dd83e59 commit f3bfa2a
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changeset/tricky-bulldogs-eat.md
@@ -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.
4 changes: 3 additions & 1 deletion resolving/npm-resolver/src/index.ts
Expand Up @@ -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':
Expand Down
37 changes: 37 additions & 0 deletions resolving/npm-resolver/test/index.ts
Expand Up @@ -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')
Expand Down

0 comments on commit f3bfa2a

Please sign in to comment.