mirror of
https://github.com/pnpm/pnpm.git
synced 2026-04-10 18:18:56 -04:00
feat: use the versions from overrides when adding deps without specs (#4355)
* feat: use the versions from overrides when adding deps without specs close #4313 * docs: fix changeset
This commit is contained in:
21
.changeset/wicked-sheep-tell.md
Normal file
21
.changeset/wicked-sheep-tell.md
Normal file
@@ -0,0 +1,21 @@
|
||||
---
|
||||
"@pnpm/core": minor
|
||||
"pnpm": minor
|
||||
---
|
||||
|
||||
When adding a new dependency, use the version specifier from the overrides, when present [#4313](https://github.com/pnpm/pnpm/issues/4313).
|
||||
|
||||
Normally, if the latest version of `foo` is `2.0.0`, then `pnpm add foo` installs `foo@^2.0.0`. This behavior changes if `foo` is specified in an override:
|
||||
|
||||
```json
|
||||
{
|
||||
"pnpm": {
|
||||
"overrides": {
|
||||
"foo": "1.0.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
In this case, `pnpm add foo` will add `foo@1.0.0` to the dependency. However, if a version is explicitly specifying, then the specified version will be used and the override will be ignored. So `pnpm add foo@0` will install v0 and it doesn't matter what is in the overrides.
|
||||
|
||||
@@ -443,6 +443,7 @@ export async function mutateModules (
|
||||
optionalDependencies,
|
||||
updateWorkspaceDependencies: opts.update,
|
||||
preferredSpecs,
|
||||
overrides: opts.overrides,
|
||||
})
|
||||
projectsToInstall.push({
|
||||
pruneDirectDependencies: false,
|
||||
|
||||
@@ -13,6 +13,7 @@ export default function parseWantedDependencies (
|
||||
devDependencies: Dependencies
|
||||
optional: boolean
|
||||
optionalDependencies: Dependencies
|
||||
overrides?: Record<string, string>
|
||||
updateWorkspaceDependencies?: boolean
|
||||
preferredSpecs?: Record<string, string>
|
||||
}
|
||||
@@ -56,6 +57,13 @@ export default function parseWantedDependencies (
|
||||
raw: `${rawWantedDependency}@${opts.preferredSpecs[alias]}`,
|
||||
}
|
||||
}
|
||||
if (alias && opts.overrides?.[alias]) {
|
||||
return {
|
||||
...result,
|
||||
pref: opts.overrides[alias],
|
||||
raw: `${alias}@${opts.overrides[alias]}`,
|
||||
}
|
||||
}
|
||||
return {
|
||||
...result,
|
||||
pref: opts.defaultTag,
|
||||
|
||||
@@ -111,3 +111,19 @@ test('versions are replaced with versions specified through overrides option', a
|
||||
)
|
||||
)
|
||||
})
|
||||
|
||||
test('when adding a new dependency that is present in the overrides, use the spec from the override', async () => {
|
||||
prepareEmpty()
|
||||
|
||||
await addDistTag({ package: 'bar', version: '100.0.0', distTag: 'latest' })
|
||||
|
||||
const overrides = {
|
||||
bar: '100.1.0',
|
||||
}
|
||||
const manifest = await addDependenciesToPackage({},
|
||||
['bar'],
|
||||
await testDefaults({ overrides })
|
||||
)
|
||||
|
||||
expect(manifest.dependencies?.bar).toBe(overrides.bar)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user