Skip to content

Commit 825536c

Browse files
committed
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>/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
1 parent ef75f6a commit 825536c

1 file changed

Lines changed: 31 additions & 1 deletion

File tree

  • packages/angular/cli/src/commands/update

packages/angular/cli/src/commands/update/cli.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,37 @@ export default class UpdateCommandModule extends CommandModule<UpdateCommandArgs
634634
}
635635
}
636636

637-
const migrations = plan.migrationsToRun;
637+
const migrations = [...plan.migrationsToRun];
638+
639+
// Fallback: check installed packages on disk for migrations that were omitted
640+
// from remote registry metadata (e.g., GitHub Packages strips 'ng-update' from API responses).
641+
const existingMigrationPackages = new Set(migrations.map((m) => m.package));
642+
for (const [packageName, targetVersion] of plan.packagesToUpdate) {
643+
if (existingMigrationPackages.has(packageName)) {
644+
continue;
645+
}
646+
647+
const packageJsonPath = findPackageJson(this.context.root, packageName);
648+
if (packageJsonPath) {
649+
try {
650+
const packageJson = JSON.parse(await fs.readFile(packageJsonPath, 'utf8'));
651+
const ngUpdate = packageJson?.['ng-update'];
652+
if (ngUpdate && typeof ngUpdate === 'object' && typeof ngUpdate.migrations === 'string') {
653+
const installedVersion = plan.packageInfoMap.get(packageName)?.installed.version;
654+
if (installedVersion) {
655+
migrations.push({
656+
package: packageName,
657+
collection: ngUpdate.migrations,
658+
from: installedVersion,
659+
to: targetVersion,
660+
});
661+
}
662+
}
663+
} catch {
664+
// Ignore read/parse errors for optional fallback
665+
}
666+
}
667+
}
638668

639669
if (migrations) {
640670
for (const migration of migrations) {

0 commit comments

Comments
 (0)