mirror of
https://github.com/pnpm/pnpm.git
synced 2026-04-10 18:18:56 -04:00
fix: it should be possible to override direct deps (#3289)
This commit is contained in:
5
.changeset/hot-windows-count.md
Normal file
5
.changeset/hot-windows-count.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"supi": patch
|
||||
---
|
||||
|
||||
`pnpm.overrides` should work on direct dependencies as well.
|
||||
@@ -141,11 +141,7 @@ export async function mutateModules (
|
||||
|
||||
const installsOnly = projects.every((project) => project.mutation === 'install')
|
||||
opts['forceNewModules'] = installsOnly
|
||||
const ctx = await getContext(projects, opts)
|
||||
const pruneVirtualStore = ctx.modulesFile?.prunedAt && opts.modulesCacheMaxAge > 0
|
||||
? cacheExpired(ctx.modulesFile.prunedAt, opts.modulesCacheMaxAge)
|
||||
: true
|
||||
const rootProjectManifest = ctx.projects.find(({ id }) => id === '.')?.manifest ??
|
||||
const rootProjectManifest = projects.find(({ rootDir }) => rootDir === opts.lockfileDir)?.manifest ??
|
||||
// When running install/update on a subset of projects, the root project might not be included,
|
||||
// so reading its manifest explicitly hear.
|
||||
await safeReadProjectManifestOnly(opts.lockfileDir)
|
||||
@@ -167,6 +163,10 @@ export async function mutateModules (
|
||||
opts.hooks.readPackage = versionsOverrider
|
||||
}
|
||||
}
|
||||
const ctx = await getContext(projects, opts)
|
||||
const pruneVirtualStore = ctx.modulesFile?.prunedAt && opts.modulesCacheMaxAge > 0
|
||||
? cacheExpired(ctx.modulesFile.prunedAt, opts.modulesCacheMaxAge)
|
||||
: true
|
||||
|
||||
for (const { manifest, rootDir } of ctx.projects) {
|
||||
if (!manifest) {
|
||||
|
||||
@@ -39,6 +39,8 @@ test('versions are replaced with versions specified through pnpm.overrides field
|
||||
|
||||
// The lockfile is updated if the overrides are changed
|
||||
manifest.pnpm!.overrides!['bar@^100.0.0'] = '100.0.0'
|
||||
// A direct dependency may be overriden as well
|
||||
manifest.pnpm!.overrides!['foobarqar'] = '1.0.1'
|
||||
await mutateModules([
|
||||
{
|
||||
buildIndex: 0,
|
||||
@@ -52,7 +54,9 @@ test('versions are replaced with versions specified through pnpm.overrides field
|
||||
const lockfile = await project.readLockfile()
|
||||
expect(lockfile.packages).toHaveProperty(['/dep-of-pkg-with-1-dep/101.0.0'])
|
||||
expect(lockfile.packages).toHaveProperty(['/bar/100.0.0'])
|
||||
expect(lockfile.packages).toHaveProperty(['/foobarqar/1.0.1'])
|
||||
expect(lockfile.overrides).toStrictEqual({
|
||||
foobarqar: '1.0.1',
|
||||
'foobarqar>foo': 'npm:qar@100.0.0',
|
||||
'bar@^100.0.0': '100.0.0',
|
||||
'dep-of-pkg-with-1-dep': '101.0.0',
|
||||
@@ -73,6 +77,7 @@ test('versions are replaced with versions specified through pnpm.overrides field
|
||||
{
|
||||
const lockfile = await project.readLockfile()
|
||||
expect(lockfile.overrides).toStrictEqual({
|
||||
foobarqar: '1.0.1',
|
||||
'foobarqar>foo': 'npm:qar@100.0.0',
|
||||
'bar@^100.0.0': '100.0.0',
|
||||
'dep-of-pkg-with-1-dep': '101.0.0',
|
||||
|
||||
Reference in New Issue
Block a user