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 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
7 changes: 7 additions & 0 deletions .changeset/tasty-coins-join.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@pnpm/plugin-commands-installation": patch
"@pnpm/resolve-dependencies": patch
"pnpm": patch
---

The update command should not replace dependency versions specified via dist-tags [#5996](https://github.com/pnpm/pnpm/pull/5996).
4 changes: 2 additions & 2 deletions pkg-manager/core/src/install/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ export async function mutateModules (
updateWorkspaceDependencies: opts.update,
nodeExecPath: opts.nodeExecPath,
})
.map((wantedDependency) => ({ ...wantedDependency, updateSpec: true }))
.map((wantedDependency) => ({ ...wantedDependency, updateSpec: true, preserveNonSemverVersionSpec: true }))

if (ctx.wantedLockfile?.importers) {
forgetResolutionsOfPrevWantedDeps(ctx.wantedLockfile.importers[project.id], wantedDependencies)
Expand Down Expand Up @@ -719,7 +719,7 @@ export type ImporterToUpdate = {
pruneDirectDependencies: boolean
removePackages?: string[]
updatePackageManifest: boolean
wantedDependencies: Array<WantedDependency & { isNew?: boolean, updateSpec?: boolean }>
wantedDependencies: Array<WantedDependency & { isNew?: boolean, updateSpec?: boolean, preserveNonSemverVersionSpec?: boolean }>
} & DependenciesMutation

export interface UpdatedProject {
Expand Down
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')
})
1 change: 1 addition & 0 deletions pkg-manager/resolve-dependencies/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export type ImporterToResolve = Importer<{
pinnedVersion?: PinnedVersion
raw: string
updateSpec?: boolean
preserveNonSemverVersionSpec?: boolean
}>
& {
peer?: boolean
Expand Down
12 changes: 9 additions & 3 deletions pkg-manager/resolve-dependencies/src/updateProjectManifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export async function updateProjectManifest (
.filter((rdd, index) => importer.wantedDependencies[index]?.updateSpec)
.map((rdd, index) => {
const wantedDep = importer.wantedDependencies[index]!
return resolvedDirectDepToSpecObject({ ...rdd, isNew: wantedDep.isNew, specRaw: wantedDep.raw }, importer, {
return resolvedDirectDepToSpecObject({ ...rdd, isNew: wantedDep.isNew, specRaw: wantedDep.raw, preserveNonSemverVersionSpec: wantedDep.preserveNonSemverVersionSpec }, importer, {
nodeExecPath: wantedDep.nodeExecPath,
pinnedVersion: wantedDep.pinnedVersion ?? importer.pinnedVersion ?? 'major',
preserveWorkspaceProtocol: opts.preserveWorkspaceProtocol,
Expand Down Expand Up @@ -66,7 +66,8 @@ function resolvedDirectDepToSpecObject (
resolution,
specRaw,
version,
}: ResolvedDirectDependency & { isNew?: Boolean, specRaw: string },
preserveNonSemverVersionSpec,
}: ResolvedDirectDependency & { isNew?: Boolean, specRaw: string, preserveNonSemverVersionSpec?: boolean },
importer: ImporterToResolve,
opts: {
nodeExecPath?: string
Expand Down Expand Up @@ -103,6 +104,7 @@ function resolvedDirectDepToSpecObject (
specRaw,
version,
rolling: shouldUseWorkspaceProtocol && opts.saveWorkspaceProtocol === 'rolling',
preserveNonSemverVersionSpec,
})
}
if (
Expand Down Expand Up @@ -156,6 +158,7 @@ function getPrefPreferSpecifiedExoticSpec (
specRaw: string
pinnedVersion: PinnedVersion
rolling: boolean
preserveNonSemverVersionSpec?: boolean
}
) {
const prefix = getPrefix(opts.alias, opts.name)
Expand All @@ -168,7 +171,10 @@ function getPrefPreferSpecifiedExoticSpec (
}
}
const selector = versionSelectorType(specWithoutName)
if (!selector) {
if (
((selector == null) || (selector.type !== 'version' && selector.type !== 'range')) &&
opts.preserveNonSemverVersionSpec
) {
return opts.specRaw.slice(opts.alias.length + 1)
}
}
Expand Down