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

fix: update without specify --latest should not update tag version #5996

Merged
merged 6 commits into from
Feb 1, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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/tasty-coins-join.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@pnpm/plugin-commands-installation": patch
"@pnpm/resolve-dependencies": patch
---

Update without specify --latest should not update tag version
30 changes: 30 additions & 0 deletions pkg-manager/plugin-commands-installation/test/update/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,3 +335,33 @@ test('do not update anything if all the dependencies are ignored and trying to u
const lockfileUpdated = await project.readLockfile()
expect(lockfileUpdated.packages['/@pnpm.e2e/foo/100.0.0']).toBeTruthy()
})

test('should not update tag version when --latest not set', async () => {
await addDistTag({ package: '@pnpm.e2e/peer-a', version: '1.0.1', distTag: 'latest' })
await addDistTag({ package: '@pnpm.e2e/peer-c', version: '2.0.0', distTag: 'canary' })
await addDistTag({ package: '@pnpm.e2e/foo', version: '2.0.0', distTag: 'latest' })

prepare({
dependencies: {
'@pnpm.e2e/peer-a': 'latest',
'@pnpm.e2e/peer-c': 'canary',
'@pnpm.e2e/foo': '1.0.0',
},
})

await install.handler({
...DEFAULT_OPTS,
dir: process.cwd(),
})

await update.handler({
...DEFAULT_OPTS,
dir: process.cwd(),
latest: false,
})

const manifest = await loadJsonFile<ProjectManifest>('package.json')
expect(manifest.dependencies?.['@pnpm.e2e/peer-a']).toBe('latest')
expect(manifest.dependencies?.['@pnpm.e2e/peer-c']).toBe('canary')
expect(manifest.dependencies?.['@pnpm.e2e/foo']).toBe('1.0.0')
})
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ function resolvedDirectDepToSpecObject (
specRaw,
version,
rolling: shouldUseWorkspaceProtocol && opts.saveWorkspaceProtocol === 'rolling',
isNew,
})
}
if (
Expand Down Expand Up @@ -156,6 +157,7 @@ function getPrefPreferSpecifiedExoticSpec (
specRaw: string
pinnedVersion: PinnedVersion
rolling: boolean
isNew?: Boolean
}
) {
const prefix = getPrefix(opts.alias, opts.name)
Expand All @@ -168,7 +170,7 @@ function getPrefPreferSpecifiedExoticSpec (
}
}
const selector = versionSelectorType(specWithoutName)
if (!selector) {
if (!((selector != null) && (selector.type === 'version' || selector.type === 'range')) && opts.isNew === undefined) {
zkochan marked this conversation as resolved.
Show resolved Hide resolved
return opts.specRaw.slice(opts.alias.length + 1)
}
}
Expand Down