Skip to content

Commit ace02f6

Browse files
clydinmgechev
authored andcommitted
feat(@angular/cli): create commits per migration during update (#15611)
1 parent 0d0d124 commit ace02f6

File tree

3 files changed

+60
-2
lines changed

3 files changed

+60
-2
lines changed

packages/angular/cli/commands/update-impl.ts

+35-1
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ export class UpdateCommand extends Command<UpdateCommandSchema> {
136136
const description = schematic.description as typeof schematic.description & {
137137
version?: string;
138138
};
139+
description.version = coerceVersionNumber(description.version) || undefined;
139140
if (!description.version) {
140141
continue;
141142
}
@@ -489,8 +490,37 @@ export class UpdateCommand extends Command<UpdateCommandSchema> {
489490
force: options.force || false,
490491
packageManager,
491492
packages: packagesToUpdate,
493+
migrateExternal: true,
492494
});
493495

496+
if (success && !options.skipCommits) {
497+
this.createCommit('Angular CLI update\n' + packagesToUpdate.join('\n'), []);
498+
}
499+
500+
// This is a temporary workaround to allow data to be passed back from the update schematic
501+
// tslint:disable-next-line: no-any
502+
const migrations = (global as any).externalMigrations as {
503+
package: string;
504+
collection: string;
505+
from: string;
506+
to: string;
507+
}[];
508+
509+
if (success && migrations) {
510+
for (const migration of migrations) {
511+
const result = await this.executeMigrations(
512+
migration.package,
513+
migration.collection,
514+
new semver.Range('>' + migration.from + ' <=' + migration.to),
515+
!options.skipCommits,
516+
);
517+
518+
if (!result) {
519+
return 0;
520+
}
521+
}
522+
}
523+
494524
return success ? 0 : 1;
495525
}
496526

@@ -536,7 +566,11 @@ export class UpdateCommand extends Command<UpdateCommandSchema> {
536566
}
537567
}
538568

539-
function coerceVersionNumber(version: string): string | null {
569+
function coerceVersionNumber(version: string | undefined): string | null {
570+
if (!version) {
571+
return null;
572+
}
573+
540574
if (!version.match(/^\d{1,30}\.\d{1,30}\.\d{1,30}/)) {
541575
const match = version.match(/^\d{1,30}(\.\d{1,30})*/);
542576

packages/schematics/update/update/index.ts

+20-1
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ function _performUpdate(
228228
infoMap: Map<string, PackageInfo>,
229229
logger: logging.LoggerApi,
230230
migrateOnly: boolean,
231+
migrateExternal: boolean,
231232
): Observable<void> {
232233
const packageJsonContent = tree.read('/package.json');
233234
if (!packageJsonContent) {
@@ -292,6 +293,8 @@ function _performUpdate(
292293
installTask = [context.addTask(new NodePackageInstallTask())];
293294
}
294295

296+
const externalMigrations: {}[] = [];
297+
295298
// Run the migrate schematics with the list of packages to use. The collection contains
296299
// version information and we need to do this post installation. Please note that the
297300
// migration COULD fail and leave side effects on disk.
@@ -307,6 +310,17 @@ function _performUpdate(
307310
: ''
308311
) + target.updateMetadata.migrations;
309312

313+
if (migrateExternal) {
314+
externalMigrations.push({
315+
package: name,
316+
collection,
317+
from: installed.version,
318+
to: target.version,
319+
});
320+
321+
return;
322+
}
323+
310324
context.addTask(new RunSchematicTask('@schematics/update', 'migrate', {
311325
package: name,
312326
collection,
@@ -316,6 +330,11 @@ function _performUpdate(
316330
installTask,
317331
);
318332
});
333+
334+
if (externalMigrations.length > 0) {
335+
// tslint:disable-next-line: no-any
336+
(global as any).externalMigrations = externalMigrations;
337+
}
319338
}
320339

321340
return of<void>(undefined);
@@ -906,7 +925,7 @@ export default function(options: UpdateSchema): Rule {
906925
);
907926
_validateUpdatePackages(infoMap, !!options.force, sublog);
908927

909-
return _performUpdate(tree, context, infoMap, logger, !!options.migrateOnly);
928+
return _performUpdate(tree, context, infoMap, logger, !!options.migrateOnly, !!options.migrateExternal);
910929
} else {
911930
return _usageMessage(options, infoMap, logger);
912931
}

packages/schematics/update/update/schema.json

+5
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@
6666
"npm",
6767
"yarn"
6868
]
69+
},
70+
"migrateExternal": {
71+
"type": "boolean",
72+
"default": false,
73+
"hidden": true
6974
}
7075
},
7176
"required": [

0 commit comments

Comments
 (0)