fix: it should be possible to override direct deps (#3289)

This commit is contained in:
Zoltan Kochan
2021-03-29 11:35:57 +03:00
committed by GitHub
parent c3b20c8052
commit 945dc9f562
3 changed files with 15 additions and 5 deletions

View File

@@ -0,0 +1,5 @@
---
"supi": patch
---
`pnpm.overrides` should work on direct dependencies as well.

View File

@@ -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) {

View File

@@ -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',