From 3ec4367a8d351289288c73e8f1b02d75e30262f6 Mon Sep 17 00:00:00 2001 From: Alan Agius <17563226+alan-agius4@users.noreply.github.com> Date: Fri, 31 Jul 2026 12:59:31 +0000 Subject: [PATCH 1/3] fix(@angular/cli): discover migrations from installed packages when omitted by registry metadata Private package registries such as GitHub Packages frequently strip out custom non-npm metadata properties (e.g., ng-update or schematics) from their remote API responses. Previously, this caused ng update to skip migration execution during updates from those registries, even though ng update --migrate-only worked correctly. This commit adds a post-installation disk-fallback check in ng update: for any updated packages that were not scheduled for migrations from registry metadata, the CLI inspects node_modules//package.json on disk after installation. If an ng-update.migrations collection is found, it is automatically added to the migration queue and executed. Closes #33717 --- .../angular/cli/src/commands/update/cli.ts | 39 ++++- .../cli/src/commands/update/cli_spec.ts | 133 ++++++++++++++++++ 2 files changed, 171 insertions(+), 1 deletion(-) create mode 100644 packages/angular/cli/src/commands/update/cli_spec.ts diff --git a/packages/angular/cli/src/commands/update/cli.ts b/packages/angular/cli/src/commands/update/cli.ts index b886c287f2ec..3b4ab699f7f3 100644 --- a/packages/angular/cli/src/commands/update/cli.ts +++ b/packages/angular/cli/src/commands/update/cli.ts @@ -634,7 +634,7 @@ export default class UpdateCommandModule extends CommandModule { + const migrations = [...plan.migrationsToRun]; + const existingMigrationPackages = new Set(migrations.map((m) => m.package)); + + for (const [packageName, targetVersion] of plan.packagesToUpdate) { + if (existingMigrationPackages.has(packageName)) { + continue; + } + + const packageJsonPath = findPackageJson(workspaceRoot, packageName); + if (packageJsonPath) { + try { + const packageJson = JSON.parse(await fs.readFile(packageJsonPath, 'utf8')); + const ngUpdate = packageJson?.['ng-update']; + if (ngUpdate && typeof ngUpdate === 'object' && typeof ngUpdate.migrations === 'string') { + const installedVersion = plan.packageInfoMap.get(packageName)?.installed.version; + if (installedVersion) { + migrations.push({ + package: packageName, + collection: ngUpdate.migrations, + from: installedVersion, + to: targetVersion, + }); + } + } + } catch { + // Ignore read/parse errors for optional fallback + } + } + } + + return migrations; +} diff --git a/packages/angular/cli/src/commands/update/cli_spec.ts b/packages/angular/cli/src/commands/update/cli_spec.ts new file mode 100644 index 000000000000..bae00d3dba24 --- /dev/null +++ b/packages/angular/cli/src/commands/update/cli_spec.ts @@ -0,0 +1,133 @@ +/** + * @license + * Copyright Google LLC All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.dev/license + */ + +import assert from 'node:assert'; +import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises'; +import path from 'path'; +import { resolveFallbackMigrations } from './cli'; +import type { PackageVersionInfo, UpdatePlan } from './update-resolver'; + +describe('resolveFallbackMigrations', () => { + let tempRoot: string; + let pkgDir: string; + beforeEach(async () => { + const baseTmpDir = process.env['TEST_TMPDIR']; + assert(baseTmpDir, 'TEST_TMPDIR is not set'); + tempRoot = await mkdtemp(path.join(baseTmpDir, 'angular-cli-update-cli-test-')); + pkgDir = path.join(tempRoot, 'node_modules/@company/library-name'); + await mkdir(pkgDir, { recursive: true }); + }); + + afterEach(async () => { + await rm(tempRoot, { recursive: true, force: true }); + }); + + it('discovers migrations from installed package.json when omitted from plan.migrationsToRun', async () => { + await writeFile( + path.join(pkgDir, 'package.json'), + JSON.stringify({ + name: '@company/library-name', + version: '21.2.0-next.1', + 'ng-update': { + migrations: './schematics/migration.json', + }, + }), + 'utf8', + ); + + const plan: UpdatePlan = { + packagesToUpdate: new Map([['@company/library-name', '21.2.0-next.1']]), + migrationsToRun: [], + packageInfoMap: new Map([ + [ + '@company/library-name', + { + name: '@company/library-name', + npmPackageJson: { + name: '@company/library-name', + versions: ['21.1.0', '21.2.0-next.1'], + 'dist-tags': {}, + }, + installed: { + version: '21.1.0' as unknown as PackageVersionInfo['version'], + packageJson: { name: '@company/library-name', version: '21.1.0' }, + updateMetadata: { packageGroup: {}, requirements: {} }, + }, + packageJsonRange: '^21.1.0', + }, + ], + ]), + registryClient: undefined as unknown as UpdatePlan['registryClient'], + }; + + const migrations = await resolveFallbackMigrations(tempRoot, plan); + + expect(migrations).toEqual([ + { + package: '@company/library-name', + collection: './schematics/migration.json', + from: '21.1.0', + to: '21.2.0-next.1', + }, + ]); + }); + + it('does not duplicate migration if package is already in plan.migrationsToRun', async () => { + await writeFile( + path.join(pkgDir, 'package.json'), + JSON.stringify({ + name: '@company/library-name', + version: '21.2.0-next.1', + 'ng-update': { + migrations: './schematics/migration.json', + }, + }), + 'utf8', + ); + + const plan: UpdatePlan = { + packagesToUpdate: new Map([['@company/library-name', '21.2.0-next.1']]), + migrationsToRun: [ + { + package: '@company/library-name', + collection: './schematics/migration.json', + from: '21.1.0', + to: '21.2.0-next.1', + }, + ], + packageInfoMap: new Map(), + registryClient: undefined as unknown as UpdatePlan['registryClient'], + }; + + const migrations = await resolveFallbackMigrations(tempRoot, plan); + + expect(migrations).toHaveSize(1); + }); + + it('returns unchanged migrations when package has no ng-update field on disk', async () => { + await writeFile( + path.join(pkgDir, 'package.json'), + JSON.stringify({ + name: '@company/library-name', + version: '21.2.0-next.1', + }), + 'utf8', + ); + + const plan: UpdatePlan = { + packagesToUpdate: new Map([['@company/library-name', '21.2.0-next.1']]), + migrationsToRun: [], + packageInfoMap: new Map(), + registryClient: undefined as unknown as UpdatePlan['registryClient'], + }; + + const migrations = await resolveFallbackMigrations(tempRoot, plan); + + expect(migrations).toHaveSize(0); + }); +}); From c957ded49dcfaa2c3e74213426a66d3c3e1248eb Mon Sep 17 00:00:00 2001 From: Alan Agius <17563226+alan-agius4@users.noreply.github.com> Date: Fri, 31 Jul 2026 13:14:13 +0000 Subject: [PATCH 2/3] fix(@angular/cli): always install package during ng add to inspect manifest on disk for schematics Private package registries such as GitHub Packages frequently strip out custom non-npm metadata properties (such as schematics and ng-add) from their remote API responses. Previously, ng add skipped confirming and installing a package if the registry metadata did not report hasSchematics, causing ng add to fail on first run. This commit removes the early skip condition based on registry metadata so ng add always installs the target package to inspect its physical manifest on disk. If no schematics are found after installation, the CLI cleanly removes the temporary dependency. Closes #33060 --- packages/angular/cli/src/commands/add/cli.ts | 23 +++++--------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/packages/angular/cli/src/commands/add/cli.ts b/packages/angular/cli/src/commands/add/cli.ts index 511223eb53b5..bc95f33ff8e7 100644 --- a/packages/angular/cli/src/commands/add/cli.ts +++ b/packages/angular/cli/src/commands/add/cli.ts @@ -224,29 +224,12 @@ export default class AddCommandModule { title: 'Confirming installation', enabled: !skipConfirmation && !options.dryRun, - skip: (context) => { - if (context.hasSchematics) { - return false; - } - - return `The ${color.blue(context.packageIdentifier.toString())} package does not provide \`ng add\` actions.`; - }, task: (context, task) => this.confirmInstallationTask(context, task), rendererOptions: { persistentOutput: true }, }, { title: 'Installing package', skip: (context) => { - if (!context.hasSchematics) { - const builtInSchematic = - BUILT_IN_SCHEMATICS[ - context.packageIdentifier.name as keyof typeof BUILT_IN_SCHEMATICS - ]; - if (builtInSchematic) { - return `Skipping package installation.`; - } - } - if (context.dryRun) { return `Skipping package installation. Would install package ${color.blue( context.packageIdentifier.toString(), @@ -278,6 +261,9 @@ export default class AddCommandModule if (localManifest['ng-add']?.save === false) { shouldCleanUp = true; } + } else { + await this.cleanUpTemporaryDependency(result.collectionName); + shouldCleanUp = false; } } catch {} } @@ -305,6 +291,9 @@ export default class AddCommandModule const builtInSchematic = BUILT_IN_SCHEMATICS[packageName as keyof typeof BUILT_IN_SCHEMATICS]; if (builtInSchematic) { + logger.info( + `The ${color.blue(packageName)} package does not provide \`ng add\` actions.`, + ); logger.info('The Angular CLI will use built-in actions to add it to your project.'); return this.executeSchematic({ From 78a2b68ef369f66d86ef6a98cd40b3e15abb7884 Mon Sep 17 00:00:00 2001 From: Alan Agius <17563226+alan-agius4@users.noreply.github.com> Date: Fri, 31 Jul 2026 17:31:43 +0000 Subject: [PATCH 3/3] fixup! fix(@angular/cli): discover migrations from installed packages when omitted by registry metadata TAG=agy CONV=b92ba928-67b0-4f4b-a79a-ce19e5098641 --- packages/angular/cli/src/commands/update/cli.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/angular/cli/src/commands/update/cli.ts b/packages/angular/cli/src/commands/update/cli.ts index 3b4ab699f7f3..005df998b501 100644 --- a/packages/angular/cli/src/commands/update/cli.ts +++ b/packages/angular/cli/src/commands/update/cli.ts @@ -707,6 +707,15 @@ async function readPackageManifest(manifestPath: string): Promise/package.json` after installation, + * we ensure that any migration collections defined by the package are discovered and queued. + */ export async function resolveFallbackMigrations( workspaceRoot: string, plan: UpdatePlan,