Skip to content

Commit ac29ecb

Browse files
committed
fix(@angular/cli): use the workspace package manager in catalog update guidance
When `ng update` aborts because a package uses the `catalog:` protocol, the manual migration steps hardcode pnpm and yarn: the install step suggests 'pnpm install' for every package manager except yarn, and the catalog file hint only names pnpm-workspace.yaml and .yarnrc.yml. Bun workspaces also support catalogs, so a bun workspace is told to run 'pnpm install' and to look for files it does not have. Build the install command from the detected package manager and name the catalog location it actually uses: pnpm-workspace.yaml for pnpm, .yarnrc.yml for yarn, and the 'workspaces.catalog' field in the root package.json for bun. The previous generic text is kept as a fallback when the package manager is unknown. The new spec fails without the fix: with `packageManager: 'bun'`, the guidance suggested 'pnpm install' and the pnpm/yarn file names.
1 parent 2c6e8b9 commit ac29ecb

2 files changed

Lines changed: 38 additions & 3 deletions

File tree

‎packages/angular/cli/src/commands/update/update-resolver.ts‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -832,8 +832,16 @@ async function checkCatalogUpdates(
832832
}
833833

834834
if (catalogUpdates.length > 0) {
835-
const packageManagerName = options.packageManager ?? 'your package manager';
836-
const installCmd = packageManagerName === 'yarn' ? 'yarn install' : 'pnpm install';
835+
const packageManagerName = options.packageManager;
836+
const installCmd = packageManagerName ? `${packageManagerName} install` : 'pnpm install';
837+
const catalogLocations: Record<string, string> = {
838+
pnpm: 'pnpm-workspace.yaml',
839+
yarn: '.yarnrc.yml',
840+
bun: `the 'workspaces.catalog' field in the root package.json`,
841+
};
842+
const catalogLocation =
843+
(packageManagerName && catalogLocations[packageManagerName]) ||
844+
'e.g., pnpm-workspace.yaml or .yarnrc.yml';
837845

838846
const updatesList = catalogUpdates
839847
.map((pkg) => ` - ${pkg.name} (${pkg.specifier}) -> Target version: ${pkg.target}`)
@@ -853,7 +861,7 @@ async function checkCatalogUpdates(
853861
`Because catalogs are shared across the monorepo, 'ng update' cannot modify them directly.\n` +
854862
`Please perform the following steps to update:\n` +
855863
` 1. Manually update the versions for these packages in your catalog configuration file ` +
856-
`(e.g., pnpm-workspace.yaml or .yarnrc.yml).\n` +
864+
`(${catalogLocation}).\n` +
857865
` 2. Run '${installCmd}' to install the updated versions.\n` +
858866
` 3. Run the following command(s) from the workspace root to execute the migration schematics:\n` +
859867
`${migrationCommands}`,

‎packages/angular/cli/src/commands/update/update-resolver_spec.ts‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,33 @@ Please perform the following steps to update:
544544
).toBeRejectedWithError(new RegExp(expectedError));
545545
});
546546

547+
it('uses the workspace package manager in the catalog update guidance', async () => {
548+
createMockWorkspace(
549+
{
550+
name: 'blah',
551+
dependencies: {
552+
'@angular/core': 'catalog:',
553+
},
554+
},
555+
{
556+
'@angular/core': { version: '5.1.0' },
557+
},
558+
);
559+
560+
const expectedError =
561+
` 1\\. Manually update the versions for these packages in your catalog configuration ` +
562+
`file \\(the 'workspaces\\.catalog' field in the root package\\.json\\)\\.\n` +
563+
` 2\\. Run 'bun install' to install the updated versions\\.`;
564+
565+
await expectAsync(
566+
resolvePlan({
567+
packages: ['@angular/core'],
568+
workspaceRoot: tempRoot,
569+
packageManager: 'bun',
570+
}),
571+
).toBeRejectedWithError(new RegExp(expectedError));
572+
});
573+
547574
it('rejects updates for catalog packages specified with a version suffix', async () => {
548575
createMockWorkspace(
549576
{

0 commit comments

Comments
 (0)