From 5882d060d2d8a19ff94d7f6ed9e562a1ac09ae48 Mon Sep 17 00:00:00 2001 From: Brandon Cheng Date: Mon, 26 May 2025 15:15:24 -0400 Subject: [PATCH 01/10] test: remove newly redundant test This test is now redundant with the one below since both will now check that the catalog is updated. This tests previously checked different aspects of not updating before updates were supported. --- pkg-manager/core/test/catalogs.ts | 31 ------------------------------- 1 file changed, 31 deletions(-) diff --git a/pkg-manager/core/test/catalogs.ts b/pkg-manager/core/test/catalogs.ts index 8f7076ea7fc..e79fde6831d 100644 --- a/pkg-manager/core/test/catalogs.ts +++ b/pkg-manager/core/test/catalogs.ts @@ -1346,37 +1346,6 @@ describe('update', () => { // is-positive since public packages can release new versions and break the // tests here. - test('update does not modify catalog: protocol', async () => { - const { options, projects } = preparePackagesAndReturnObjects([{ - name: 'project1', - dependencies: { - '@pnpm.e2e/foo': 'catalog:', - }, - }]) - - const { updatedManifest } = await addDependenciesToPackage( - projects['project1' as ProjectId], - ['@pnpm.e2e/foo'], - { - ...options, - dir: path.join(options.lockfileDir, 'project1'), - lockfileOnly: true, - allowNew: false, - update: true, - catalogs: { - default: { '@pnpm.e2e/foo': '^1.0.0' }, - }, - }) - - // Expecting the manifest to remain unchanged. - expect(updatedManifest).toEqual({ - name: 'project1', - dependencies: { - '@pnpm.e2e/foo': 'catalog:', - }, - }) - }) - test('update does not upgrade cataloged dependency', async () => { const { options, projects, readLockfile } = preparePackagesAndReturnObjects([{ name: 'project1', From 88e6b7ca10ba96fe9182e512e4d1a4f3a2efb720 Mon Sep 17 00:00:00 2001 From: Brandon Cheng Date: Sun, 16 Mar 2025 18:05:51 -0400 Subject: [PATCH 02/10] test: change catalog pnpm update tests to check for version changes --- pkg-manager/core/test/catalogs.ts | 56 ++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 19 deletions(-) diff --git a/pkg-manager/core/test/catalogs.ts b/pkg-manager/core/test/catalogs.ts index e79fde6831d..96c6409249c 100644 --- a/pkg-manager/core/test/catalogs.ts +++ b/pkg-manager/core/test/catalogs.ts @@ -1325,11 +1325,6 @@ describe('add', () => { }) }) -// The 'pnpm update' command should eventually support updates of dependencies -// in the catalog. This is a more involved feature since pnpm-workspace.yaml -// needs to be edited. Until the catalog update feature is implemented, ensure -// pnpm update does not touch or rewrite dependencies using the catalog -// protocol. describe('update', () => { // Many of the update tests use @pnpm.e2e/foo, which has the following // versions currently published to the https://github.com/pnpm/registry-mock @@ -1346,7 +1341,7 @@ describe('update', () => { // is-positive since public packages can release new versions and break the // tests here. - test('update does not upgrade cataloged dependency', async () => { + test('update works on cataloged dependency', async () => { const { options, projects, readLockfile } = preparePackagesAndReturnObjects([{ name: 'project1', dependencies: { @@ -1354,6 +1349,8 @@ describe('update', () => { }, }]) + // Start by using 1.0.0 as the specifier. We'll then change this to ^1.0.0 + // and to test pnpm properly updates from 1.0.0 to 1.3.0. const catalogs = { default: { '@pnpm.e2e/foo': '1.0.0' }, } @@ -1365,17 +1362,18 @@ describe('update', () => { await mutateModules(installProjects(projects), mutateOpts) - // Updating the catalog from 1.0.0 to ^1.0.0. This should still lock to the - // existing 1.0.0 version despite version 1.3.0 existing. + // Changing the catalog from 1.0.0 to ^1.0.0. This should still lock to the + // existing 1.0.0 version despite version 1.3.0 available on the registry. catalogs.default['@pnpm.e2e/foo'] = '^1.0.0' await mutateModules(installProjects(projects), mutateOpts) + // Sanity check that the @pnpm.e2e/foo dependency is installed on the older + // requested version. expect(readLockfile().catalogs.default).toEqual({ '@pnpm.e2e/foo': { specifier: '^1.0.0', version: '1.0.0' }, }) - // Expecting the manifest to remain unchanged after running an update. - const { updatedManifest } = await addDependenciesToPackage( + const { updatedCatalogs, updatedManifest } = await addDependenciesToPackage( projects['project1' as ProjectId], ['@pnpm.e2e/foo'], { @@ -1384,21 +1382,34 @@ describe('update', () => { update: true, }) + // Expecting the manifest to remain unchanged after running an update. The + // change should be reflected in the returned updatedCatalogs object + // instead. expect(updatedManifest).toEqual({ name: 'project1', dependencies: { '@pnpm.e2e/foo': 'catalog:', }, }) - - // The lockfile should only contain 1.0.0 and not 1.3.0 (or a later version). - expect(readLockfile()).toMatchObject({ - catalogs: { default: { '@pnpm.e2e/foo': { specifier: '^1.0.0', version: '1.0.0' } } }, - packages: { '@pnpm.e2e/foo@1.0.0': expect.any(Object) }, + expect(updatedCatalogs).toEqual({ + default: { + '@pnpm.e2e/foo': '^1.3.0', + }, }) + + // The lockfile should also contain the updated ^1.3.0 reference. + expect(readLockfile()).toEqual(expect.objectContaining({ + catalogs: { default: { '@pnpm.e2e/foo': { specifier: '^1.3.0', version: '1.3.0' } } }, + packages: { '@pnpm.e2e/foo@1.3.0': expect.objectContaining({}) }, + })) + + // Ensure the old 1.0.0 version is no longer used. + expect(Object.keys(readLockfile().snapshots)).toEqual(['@pnpm.e2e/foo@1.3.0']) }) - test('update latest does not modify catalog: protocol', async () => { + test('update --latest works on cataloged dependency', async () => { + await addDistTag({ package: '@pnpm.e2e/foo', version: '100.1.0', distTag: 'latest' }) + const { options, projects, readLockfile } = preparePackagesAndReturnObjects([{ name: 'project1', dependencies: { @@ -1424,7 +1435,7 @@ describe('update', () => { '@pnpm.e2e/foo': { specifier: '1.0.0', version: '1.0.0' }, }) - const { updatedManifest } = await addDependenciesToPackage( + const { updatedCatalogs, updatedManifest } = await addDependenciesToPackage( projects['project1' as ProjectId], ['@pnpm.e2e/foo'], { @@ -1435,15 +1446,22 @@ describe('update', () => { updateToLatest: true, }) - // Expecting the manifest to remain unchanged. + // Expecting the manifest to remain unchanged after running an update. The + // change should be reflected in the returned updatedCatalogs object + // instead. expect(updatedManifest).toEqual({ name: 'project1', dependencies: { '@pnpm.e2e/foo': 'catalog:', }, }) + expect(updatedCatalogs).toEqual({ + default: { + '@pnpm.e2e/foo': '100.1.0', + }, + }) - expect(Object.keys(readLockfile().snapshots)).toEqual(['@pnpm.e2e/foo@1.0.0']) + expect(Object.keys(readLockfile().snapshots)).toEqual(['@pnpm.e2e/foo@100.1.0']) }) }) From 723699240c1fdf0f52b7a1534d6ab15f6581a820 Mon Sep 17 00:00:00 2001 From: Brandon Cheng Date: Mon, 26 May 2025 13:11:06 -0400 Subject: [PATCH 03/10] test: ensure only matching dependencies are updated --- pkg-manager/core/test/catalogs.ts | 89 +++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) diff --git a/pkg-manager/core/test/catalogs.ts b/pkg-manager/core/test/catalogs.ts index 96c6409249c..48245090846 100644 --- a/pkg-manager/core/test/catalogs.ts +++ b/pkg-manager/core/test/catalogs.ts @@ -1463,6 +1463,95 @@ describe('update', () => { expect(Object.keys(readLockfile().snapshots)).toEqual(['@pnpm.e2e/foo@100.1.0']) }) + + // This test will update @pnpm.e2e/bar, but make sure @pnpm.e2e/foo is + // untouched. On the registry-mock, the versions for @pnpm.e2e/bar are: + // + // - 100.0.0 + // - 100.1.0 + test('update only affects matching filter', async () => { + const { options, projects, readLockfile } = preparePackagesAndReturnObjects([{ + name: 'project1', + dependencies: { + '@pnpm.e2e/foo': 'catalog:', + '@pnpm.e2e/bar': 'catalog:', + }, + }]) + + // Start by using 1.0.0 as the specifier. We'll then change this to ^1.0.0. + const catalogs = { + default: { + '@pnpm.e2e/foo': '1.0.0', + '@pnpm.e2e/bar': '100.0.0', + }, + } + const mutateOpts = { + ...options, + lockfileOnly: true, + catalogs, + } + + await mutateModules(installProjects(projects), mutateOpts) + + // Adding ^ to the catalog config entries. This allows the update process to + // consider newer versions to update to for this test. + catalogs.default['@pnpm.e2e/foo'] = '^1.0.0' + catalogs.default['@pnpm.e2e/bar'] = '^100.0.0' + await mutateModules(installProjects(projects), mutateOpts) + + // Sanity check dependencies are still installed on older requested version + // and not accidentally updated due to adding ^ above. + expect(readLockfile().catalogs.default).toEqual({ + '@pnpm.e2e/foo': { specifier: '^1.0.0', version: '1.0.0' }, + '@pnpm.e2e/bar': { specifier: '^100.0.0', version: '100.0.0' }, + }) + + const { updatedCatalogs, updatedManifest } = await addDependenciesToPackage( + projects['project1' as ProjectId], + ['@pnpm.e2e/bar'], + { + ...mutateOpts, + dir: path.join(options.lockfileDir, 'project1'), + update: true, + updateMatching: (pkgName) => pkgName === '@pnpm.e2e/bar', + }) + + // Expecting the manifest to remain unchanged after running an update. The + // change should be reflected in the returned updatedCatalogs object + // instead. + expect(updatedManifest).toEqual({ + name: 'project1', + dependencies: { + '@pnpm.e2e/foo': 'catalog:', + '@pnpm.e2e/bar': 'catalog:', + }, + }) + expect(updatedCatalogs).toEqual({ + default: { + '@pnpm.e2e/bar': '^100.1.0', + }, + }) + + // The lockfile should also contain the updated ^100.1.0 reference. + expect(readLockfile()).toEqual(expect.objectContaining({ + catalogs: { + default: { + '@pnpm.e2e/foo': { specifier: '^1.0.0', version: '1.0.0' }, + '@pnpm.e2e/bar': { specifier: '^100.1.0', version: '100.1.0' }, + }, + }, + packages: { + '@pnpm.e2e/foo@1.0.0': expect.objectContaining({}), + '@pnpm.e2e/bar@100.1.0': expect.objectContaining({}), + }, + })) + + // Ensure the old 1.0.0 version is no longer used. + expect(Object.keys(readLockfile().snapshots)).toEqual([ + '@pnpm.e2e/bar@100.1.0', + '@pnpm.e2e/foo@1.0.0', + ]) + }) }) test('catalogs work in overrides', async () => { From a720280d846807f7f1c5cb9cdb3c083ea2870bf9 Mon Sep 17 00:00:00 2001 From: Brandon Cheng Date: Sat, 7 Jun 2025 13:12:30 -0400 Subject: [PATCH 04/10] test: add test for updates to named catalog --- pkg-manager/core/test/catalogs.ts | 66 +++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/pkg-manager/core/test/catalogs.ts b/pkg-manager/core/test/catalogs.ts index 48245090846..815d14ef21a 100644 --- a/pkg-manager/core/test/catalogs.ts +++ b/pkg-manager/core/test/catalogs.ts @@ -1407,6 +1407,72 @@ describe('update', () => { expect(Object.keys(readLockfile().snapshots)).toEqual(['@pnpm.e2e/foo@1.3.0']) }) + test('update works on named catalog', async () => { + const { options, projects, readLockfile } = preparePackagesAndReturnObjects([{ + name: 'project1', + dependencies: { + '@pnpm.e2e/foo': 'catalog:foo', + }, + }]) + + // Start by using 1.0.0 as the specifier. We'll then change this to ^1.0.0 + // and to test pnpm properly updates from 1.0.0 to 1.3.0. + const catalogs = { + foo: { '@pnpm.e2e/foo': '1.0.0' }, + } + const mutateOpts = { + ...options, + lockfileOnly: true, + catalogs, + } + + await mutateModules(installProjects(projects), mutateOpts) + + // Changing the catalog from 1.0.0 to ^1.0.0. This should still lock to the + // existing 1.0.0 version despite version 1.3.0 available on the registry. + catalogs.foo['@pnpm.e2e/foo'] = '^1.0.0' + await mutateModules(installProjects(projects), mutateOpts) + + // Sanity check that the @pnpm.e2e/foo dependency is installed on the older + // requested version. + expect(readLockfile().catalogs.foo).toEqual({ + '@pnpm.e2e/foo': { specifier: '^1.0.0', version: '1.0.0' }, + }) + + const { updatedCatalogs, updatedManifest } = await addDependenciesToPackage( + projects['project1' as ProjectId], + ['@pnpm.e2e/foo'], + { + ...mutateOpts, + dir: path.join(options.lockfileDir, 'project1'), + update: true, + }) + + // Expecting the manifest to remain unchanged after running an update. The + // change should be reflected in the returned updatedCatalogs object + // instead. + expect(updatedManifest).toEqual({ + name: 'project1', + dependencies: { + '@pnpm.e2e/foo': 'catalog:foo', + }, + }) + expect(updatedCatalogs).toEqual({ + foo: { + '@pnpm.e2e/foo': '^1.3.0', + }, + }) + + // The lockfile should also contain the updated ^1.3.0 reference. + expect(readLockfile()).toEqual(expect.objectContaining({ + catalogs: { foo: { '@pnpm.e2e/foo': { specifier: '^1.3.0', version: '1.3.0' } } }, + packages: { '@pnpm.e2e/foo@1.3.0': expect.objectContaining({}) }, + })) + + // Ensure the old 1.0.0 version is no longer used. + expect(Object.keys(readLockfile().snapshots)).toEqual(['@pnpm.e2e/foo@1.3.0']) + }) + test('update --latest works on cataloged dependency', async () => { await addDistTag({ package: '@pnpm.e2e/foo', version: '100.1.0', distTag: 'latest' }) From d5136492a6203e41c7f14115b1ae0ce29e2b5d18 Mon Sep 17 00:00:00 2001 From: Brandon Cheng Date: Sun, 1 Jun 2025 03:15:04 -0400 Subject: [PATCH 05/10] feat: update lockfile snapshots when pnpm update changes catalogs --- .../src/getCatalogSnapshots.ts | 14 ++++++++++++-- pkg-manager/resolve-dependencies/src/index.ts | 4 +++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/pkg-manager/resolve-dependencies/src/getCatalogSnapshots.ts b/pkg-manager/resolve-dependencies/src/getCatalogSnapshots.ts index 8ca0a1f5dc7..4d70a90388d 100644 --- a/pkg-manager/resolve-dependencies/src/getCatalogSnapshots.ts +++ b/pkg-manager/resolve-dependencies/src/getCatalogSnapshots.ts @@ -1,14 +1,24 @@ +import { type Catalogs } from '@pnpm/catalogs.types' import { type CatalogSnapshots } from '@pnpm/lockfile.types' import { type ResolvedDirectDependency } from './resolveDependencyTree' -export function getCatalogSnapshots (resolvedDirectDeps: readonly ResolvedDirectDependency[]): CatalogSnapshots { +export function getCatalogSnapshots ( + resolvedDirectDeps: readonly ResolvedDirectDependency[], + updatedCatalogs?: Catalogs +): CatalogSnapshots { const catalogSnapshots: CatalogSnapshots = {} const catalogedDeps = resolvedDirectDeps.filter(isCatalogedDep) for (const dep of catalogedDeps) { const snapshotForSingleCatalog = (catalogSnapshots[dep.catalogLookup.catalogName] ??= {}) + const updatedSpecifier = updatedCatalogs?.[dep.catalogLookup.catalogName]?.[dep.alias] + snapshotForSingleCatalog[dep.alias] = { - specifier: dep.catalogLookup.specifier, + // The "updated specifier" will be present when pnpm add/update is ran and + // bare specifiers need to be added in the pnpm-workspace.yaml file. When + // this happens, the updated specifier should be saved to lockfile instead + // of the original specifier before the update. + specifier: updatedSpecifier ?? dep.catalogLookup.specifier, version: dep.version, } } diff --git a/pkg-manager/resolve-dependencies/src/index.ts b/pkg-manager/resolve-dependencies/src/index.ts index 3999a50009e..4c045f52615 100644 --- a/pkg-manager/resolve-dependencies/src/index.ts +++ b/pkg-manager/resolve-dependencies/src/index.ts @@ -322,7 +322,9 @@ export async function resolveDependencies ( } } - newLockfile.catalogs = getCatalogSnapshots(Object.values(resolvedImporters).flatMap(({ directDependencies }) => directDependencies)) + newLockfile.catalogs = getCatalogSnapshots( + Object.values(resolvedImporters).flatMap(({ directDependencies }) => directDependencies), + updatedCatalogs) // waiting till package requests are finished async function waitTillAllFetchingsFinish (): Promise { From 22b312354aab7097ffe35e8fadae4f53ecc9cc75 Mon Sep 17 00:00:00 2001 From: Brandon Cheng Date: Mon, 26 May 2025 15:24:58 -0400 Subject: [PATCH 06/10] feat: enable pnpm update on dependencies using catalog protocol --- .changeset/fancy-files-wish.md | 6 ++++ .../src/resolveDependencies.ts | 30 +++---------------- 2 files changed, 10 insertions(+), 26 deletions(-) create mode 100644 .changeset/fancy-files-wish.md diff --git a/.changeset/fancy-files-wish.md b/.changeset/fancy-files-wish.md new file mode 100644 index 00000000000..e1ff186cfb3 --- /dev/null +++ b/.changeset/fancy-files-wish.md @@ -0,0 +1,6 @@ +--- +"@pnpm/resolve-dependencies": minor +pnpm: minor +--- + +The `pnpm update` command now supports updating `catalog:` protocol dependencies and writes new specifiers to `pnpm-workspace.yaml`. diff --git a/pkg-manager/resolve-dependencies/src/resolveDependencies.ts b/pkg-manager/resolve-dependencies/src/resolveDependencies.ts index 64f5e862ef4..ef7b0ee61ba 100644 --- a/pkg-manager/resolve-dependencies/src/resolveDependencies.ts +++ b/pkg-manager/resolve-dependencies/src/resolveDependencies.ts @@ -559,16 +559,8 @@ async function resolveDependenciesOfImporterDependency ( // snapshot to ensure all projects using the same cataloged dependency get the // same version. if (catalogLookup != null) { - const existingVersion = getCatalogExistingVersionFromSnapshot(catalogLookup, ctx.wantedLockfile, extendedWantedDep.wantedDependency) - - // If there's an existing version, always use it to prevent "pnpm update" - // from updating the catalog protocol. A future change will remove this - // condition to support updating specifiers in pnpm-workspace.yaml - // functionality. - extendedWantedDep.wantedDependency.bareSpecifier = existingVersion != null - ? replaceVersionInBareSpecifier(catalogLookup.specifier, existingVersion) - : catalogLookup.specifier - extendedWantedDep.preferredVersion = existingVersion + extendedWantedDep.wantedDependency.bareSpecifier = catalogLookup.specifier + extendedWantedDep.preferredVersion = getCatalogExistingVersionFromSnapshot(catalogLookup, ctx.wantedLockfile, extendedWantedDep.wantedDependency) } const result = await resolveDependenciesOfDependency( @@ -578,12 +570,6 @@ async function resolveDependenciesOfImporterDependency ( ...importer.options, parentPkgAliases: importer.parentPkgAliases, pickLowestVersion: pickLowestVersion && !importer.updatePackageManifest, - // Cataloged dependencies cannot be upgraded yet since they require - // updating the pnpm-workspace.yaml file. This will be handled in a future - // version of pnpm. - updateToLatest: catalogLookup != null - ? false - : importer.options.updateToLatest, pinnedVersion: importer.pinnedVersion, }, extendedWantedDep @@ -881,16 +867,8 @@ async function resolveDependenciesOfDependency ( // as an importer separately, and we can rely on that process keeping the // importers lockfile catalog snapshots up to date. if (catalogLookup != null) { - const existingVersion = getCatalogExistingVersionFromSnapshot(catalogLookup, ctx.wantedLockfile, extendedWantedDep.wantedDependency) - - // If there's an existing version, always use it to prevent "pnpm update" - // from updating the catalog protocol. A future change will remove this - // condition to support updating specifiers in pnpm-workspace.yaml - // functionality. - extendedWantedDep.wantedDependency.bareSpecifier = existingVersion != null - ? replaceVersionInBareSpecifier(catalogLookup.specifier, existingVersion) - : catalogLookup.specifier - extendedWantedDep.preferredVersion = existingVersion + extendedWantedDep.wantedDependency.bareSpecifier = catalogLookup.specifier + extendedWantedDep.preferredVersion = getCatalogExistingVersionFromSnapshot(catalogLookup, ctx.wantedLockfile, extendedWantedDep.wantedDependency) } } From d504f25033ed4421ae500d6908be973f944c0721 Mon Sep 17 00:00:00 2001 From: Brandon Cheng Date: Fri, 6 Jun 2025 17:03:34 -0400 Subject: [PATCH 07/10] fix: mention pnpm update when adding an existing catalog entry Restoring the message from: https://github.com/pnpm/pnpm/pull/9484#discussion_r2080906840 --- pkg-manager/resolve-dependencies/src/resolveDependencyTree.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg-manager/resolve-dependencies/src/resolveDependencyTree.ts b/pkg-manager/resolve-dependencies/src/resolveDependencyTree.ts index 0f873e641da..5e001c64795 100644 --- a/pkg-manager/resolve-dependencies/src/resolveDependencyTree.ts +++ b/pkg-manager/resolve-dependencies/src/resolveDependencyTree.ts @@ -242,7 +242,7 @@ export async function resolveDependencyTree ( if (existingCatalog != null) { if (existingCatalog !== normalizedBareSpecifier) { globalWarn( - `Skip adding ${alias} to catalogs.${saveCatalogName} because it already exists as ${existingCatalog}` + `Skip adding ${alias} to the default catalog because it already exists as ${existingCatalog}. Please use \`pnpm update\` to update the catalogs.` ) } } else if (saveCatalogName != null && normalizedBareSpecifier != null && version != null) { From 8c637c7ebc64f2f0b37d19027fd698065b89f6c0 Mon Sep 17 00:00:00 2001 From: khai96_ Date: Sun, 8 Jun 2025 01:08:16 +0700 Subject: [PATCH 08/10] style: test code should be immediately obvious --- pkg-manager/core/test/catalogs.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/pkg-manager/core/test/catalogs.ts b/pkg-manager/core/test/catalogs.ts index 815d14ef21a..2d7c9ba2099 100644 --- a/pkg-manager/core/test/catalogs.ts +++ b/pkg-manager/core/test/catalogs.ts @@ -1349,22 +1349,21 @@ describe('update', () => { }, }]) - // Start by using 1.0.0 as the specifier. We'll then change this to ^1.0.0 - // and to test pnpm properly updates from 1.0.0 to 1.3.0. - const catalogs = { - default: { '@pnpm.e2e/foo': '1.0.0' }, - } const mutateOpts = { ...options, lockfileOnly: true, - catalogs, + catalogs: { + // Start by using 1.0.0 as the specifier. We'll then change this to ^1.0.0 + // and to test pnpm properly updates from 1.0.0 to 1.3.0. + default: { '@pnpm.e2e/foo': '1.0.0' }, + }, } await mutateModules(installProjects(projects), mutateOpts) // Changing the catalog from 1.0.0 to ^1.0.0. This should still lock to the // existing 1.0.0 version despite version 1.3.0 available on the registry. - catalogs.default['@pnpm.e2e/foo'] = '^1.0.0' + mutateOpts.catalogs.default['@pnpm.e2e/foo'] = '^1.0.0' await mutateModules(installProjects(projects), mutateOpts) // Sanity check that the @pnpm.e2e/foo dependency is installed on the older From 62be9f2f5af72010a9e2b487b2447e16043b25b8 Mon Sep 17 00:00:00 2001 From: khai96_ Date: Sun, 8 Jun 2025 01:27:58 +0700 Subject: [PATCH 09/10] style: test code should be immediately obvious --- pkg-manager/core/test/catalogs.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/pkg-manager/core/test/catalogs.ts b/pkg-manager/core/test/catalogs.ts index 2d7c9ba2099..8798af6513e 100644 --- a/pkg-manager/core/test/catalogs.ts +++ b/pkg-manager/core/test/catalogs.ts @@ -1414,22 +1414,21 @@ describe('update', () => { }, }]) - // Start by using 1.0.0 as the specifier. We'll then change this to ^1.0.0 - // and to test pnpm properly updates from 1.0.0 to 1.3.0. - const catalogs = { - foo: { '@pnpm.e2e/foo': '1.0.0' }, - } const mutateOpts = { ...options, lockfileOnly: true, - catalogs, + catalogs: { + // Start by using 1.0.0 as the specifier. We'll then change this to ^1.0.0 + // and to test pnpm properly updates from 1.0.0 to 1.3.0. + foo: { '@pnpm.e2e/foo': '1.0.0' }, + }, } await mutateModules(installProjects(projects), mutateOpts) // Changing the catalog from 1.0.0 to ^1.0.0. This should still lock to the // existing 1.0.0 version despite version 1.3.0 available on the registry. - catalogs.foo['@pnpm.e2e/foo'] = '^1.0.0' + mutateOpts.catalogs.foo['@pnpm.e2e/foo'] = '^1.0.0' await mutateModules(installProjects(projects), mutateOpts) // Sanity check that the @pnpm.e2e/foo dependency is installed on the older From 9bcce999e91456b6366167908571602e1057a17f Mon Sep 17 00:00:00 2001 From: khai96_ Date: Sun, 8 Jun 2025 01:45:11 +0700 Subject: [PATCH 10/10] style: test code should be immediately obvious --- pkg-manager/core/test/catalogs.ts | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/pkg-manager/core/test/catalogs.ts b/pkg-manager/core/test/catalogs.ts index 8798af6513e..e9d59b0b196 100644 --- a/pkg-manager/core/test/catalogs.ts +++ b/pkg-manager/core/test/catalogs.ts @@ -1542,25 +1542,27 @@ describe('update', () => { }, }]) - // Start by using 1.0.0 as the specifier. We'll then change this to ^1.0.0. - const catalogs = { - default: { - '@pnpm.e2e/foo': '1.0.0', - '@pnpm.e2e/bar': '100.0.0', - }, - } const mutateOpts = { ...options, lockfileOnly: true, - catalogs, + catalogs: { + default: { + // Start by using 1.0.0 as the specifier. We'll then change this to ^1.0.0. + '@pnpm.e2e/foo': '1.0.0', + // Start by using 100.0.0 as the specifier. We'll then change this to ^100.0.0. + '@pnpm.e2e/bar': '100.0.0', + }, + }, } await mutateModules(installProjects(projects), mutateOpts) // Adding ^ to the catalog config entries. This allows the update process to // consider newer versions to update to for this test. - catalogs.default['@pnpm.e2e/foo'] = '^1.0.0' - catalogs.default['@pnpm.e2e/bar'] = '^100.0.0' + mutateOpts.catalogs.default = { + '@pnpm.e2e/foo': '^1.0.0', + '@pnpm.e2e/bar': '^100.0.0', + } await mutateModules(installProjects(projects), mutateOpts) // Sanity check dependencies are still installed on older requested version