Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Dec 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/tricky-bulldogs-eat.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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