mirror of
https://github.com/pnpm/pnpm.git
synced 2026-02-15 09:33:45 -05:00
fix: should not replace workspace:* when update (#5764)
close #5317 close #5303 close #5312 close #5726
This commit is contained in:
8
.changeset/old-islands-perform.md
Normal file
8
.changeset/old-islands-perform.md
Normal file
@@ -0,0 +1,8 @@
|
||||
---
|
||||
"@pnpm/core": patch
|
||||
"@pnpm/plugin-commands-installation": patch
|
||||
"@pnpm/resolve-dependencies": patch
|
||||
"pnpm": patch
|
||||
---
|
||||
|
||||
`pnpm update` should not replace `workspace:*`, `workspace:~`, and `workspace:^` with `workspace:<version>` [#5764](https://github.com/pnpm/pnpm/pull/5764).
|
||||
@@ -538,7 +538,7 @@ export async function mutateModules (
|
||||
projectsToInstall.push({
|
||||
pruneDirectDependencies: false,
|
||||
...project,
|
||||
wantedDependencies: wantedDeps.map(wantedDep => ({ ...wantedDep, isNew: true, updateSpec: true, nodeExecPath: opts.nodeExecPath })),
|
||||
wantedDependencies: wantedDeps.map(wantedDep => ({ ...wantedDep, isNew: !currentPrefs[wantedDep.alias], updateSpec: true, nodeExecPath: opts.nodeExecPath })),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ export function parseWantedDependencies (
|
||||
dev: Boolean(opts.dev || alias && !!opts.devDependencies[alias]),
|
||||
optional: Boolean(opts.optional || alias && !!opts.optionalDependencies[alias]),
|
||||
pinnedVersion,
|
||||
raw: rawWantedDependency,
|
||||
raw: alias && opts.currentPrefs?.[alias]?.startsWith('workspace:') ? `${alias}@${opts.currentPrefs[alias]}` : rawWantedDependency,
|
||||
}
|
||||
if (pref) {
|
||||
return {
|
||||
|
||||
@@ -946,6 +946,8 @@ test('update workspace range', async () => {
|
||||
dep4: 'workspace:1',
|
||||
dep5: 'workspace:1.0',
|
||||
dep6: 'workspace:*',
|
||||
dep7: 'workspace:^',
|
||||
dep8: 'workspace:~',
|
||||
},
|
||||
},
|
||||
rootDir: path.resolve('project-1'),
|
||||
@@ -963,6 +965,8 @@ test('update workspace range', async () => {
|
||||
dep4: 'workspace:1',
|
||||
dep5: 'workspace:1.0',
|
||||
dep6: 'workspace:*',
|
||||
dep7: 'workspace:^',
|
||||
dep8: 'workspace:~',
|
||||
},
|
||||
},
|
||||
rootDir: path.resolve('project-2'),
|
||||
@@ -1024,6 +1028,24 @@ test('update workspace range', async () => {
|
||||
},
|
||||
},
|
||||
},
|
||||
dep7: {
|
||||
'2.0.0': {
|
||||
dir: '',
|
||||
manifest: {
|
||||
name: 'dep7',
|
||||
version: '2.0.0',
|
||||
},
|
||||
},
|
||||
},
|
||||
dep8: {
|
||||
'2.0.0': {
|
||||
dir: '',
|
||||
manifest: {
|
||||
name: 'dep8',
|
||||
version: '2.0.0',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}))
|
||||
|
||||
@@ -1033,7 +1055,9 @@ test('update workspace range', async () => {
|
||||
dep3: 'workspace:^2.0.0',
|
||||
dep4: 'workspace:^2.0.0',
|
||||
dep5: 'workspace:~2.0.0',
|
||||
dep6: 'workspace:2.0.0',
|
||||
dep6: 'workspace:*',
|
||||
dep7: 'workspace:^',
|
||||
dep8: 'workspace:~',
|
||||
}
|
||||
expect(updatedImporters[0].manifest.dependencies).toStrictEqual(expected)
|
||||
expect(updatedImporters[1].manifest.dependencies).toStrictEqual(expected)
|
||||
|
||||
@@ -27,7 +27,7 @@ export function createWorkspaceSpecs (specs: string[], workspacePackages: Worksp
|
||||
const parsed = parseWantedDependency(spec)
|
||||
if (!parsed.alias) throw new PnpmError('NO_PKG_NAME_IN_SPEC', `Cannot update/install from workspace through "${spec}"`)
|
||||
if (!workspacePackages[parsed.alias]) throw new PnpmError('WORKSPACE_PACKAGE_NOT_FOUND', `"${parsed.alias}" not found in the workspace`)
|
||||
if (!parsed.pref) return `${parsed.alias}@workspace:*`
|
||||
if (!parsed.pref) return `${parsed.alias}@workspace:>=0.0.0`
|
||||
if (parsed.pref.startsWith('workspace:')) return spec
|
||||
return `${parsed.alias}@workspace:${parsed.pref}`
|
||||
})
|
||||
|
||||
@@ -72,7 +72,7 @@ test('updateToWorkspacePackagesFromManifest()', () => {
|
||||
})
|
||||
|
||||
test('createWorkspaceSpecs', () => {
|
||||
expect(createWorkspaceSpecs(['bar', 'foo@2', 'qar@workspace:3'], WORKSPACE_PACKAGES)).toStrictEqual(['bar@workspace:*', 'foo@workspace:2', 'qar@workspace:3'])
|
||||
expect(createWorkspaceSpecs(['bar', 'foo@2', 'qar@workspace:3'], WORKSPACE_PACKAGES)).toStrictEqual(['bar@workspace:>=0.0.0', 'foo@workspace:2', 'qar@workspace:3'])
|
||||
let err!: PnpmError
|
||||
try {
|
||||
createWorkspaceSpecs(['express'], WORKSPACE_PACKAGES)
|
||||
|
||||
@@ -83,7 +83,7 @@ function getWantedDependenciesFromGivenSet (
|
||||
nodeExecPath: opts.nodeExecPath ?? opts.dependenciesMeta[alias]?.node,
|
||||
pinnedVersion: whichVersionIsPinned(pref),
|
||||
pref: updatedPref,
|
||||
raw: `${alias}@${updatedPref}`,
|
||||
raw: `${alias}@${pref}`,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ function resolvedDirectDepToSpecObject (
|
||||
nodeExecPath: opts.nodeExecPath,
|
||||
peer: importer['peer'],
|
||||
pref,
|
||||
saveType: (isNew === true) ? importer['targetDependenciesField'] : undefined,
|
||||
saveType: importer['targetDependenciesField'],
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,12 +159,23 @@ function getPrefPreferSpecifiedExoticSpec (
|
||||
}
|
||||
) {
|
||||
const prefix = getPrefix(opts.alias, opts.name)
|
||||
if (opts.specRaw?.startsWith(`${opts.alias}@${prefix}`) && opts.specRaw !== `${opts.alias}@workspace:*`) {
|
||||
const specWithoutName = opts.specRaw.slice(`${opts.alias}@${prefix}`.length)
|
||||
if (opts.specRaw?.startsWith(`${opts.alias}@${prefix}`)) {
|
||||
let specWithoutName = opts.specRaw.slice(`${opts.alias}@${prefix}`.length)
|
||||
if (specWithoutName.startsWith('workspace:')) {
|
||||
specWithoutName = specWithoutName.slice(10)
|
||||
if (specWithoutName === '*' || specWithoutName === '^' || specWithoutName === '~') {
|
||||
return specWithoutName
|
||||
}
|
||||
}
|
||||
const selector = versionSelectorType(specWithoutName)
|
||||
if (!((selector != null) && (selector.type === 'version' || selector.type === 'range'))) {
|
||||
if (!selector) {
|
||||
return opts.specRaw.slice(opts.alias.length + 1)
|
||||
}
|
||||
}
|
||||
// A prerelease version is always added as an exact version
|
||||
if (semver.parse(opts.version)?.prerelease.length) {
|
||||
return `${prefix}${opts.version}`
|
||||
}
|
||||
|
||||
return `${prefix}${createVersionSpec(opts.version, { pinnedVersion: opts.pinnedVersion, rolling: opts.rolling })}`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user