From d39e17d1c0b05a254fe768da3de4cd42fa468ea0 Mon Sep 17 00:00:00 2001 From: Charles Lyding <19598772+clydin@users.noreply.github.com> Date: Mon, 16 Sep 2019 21:29:52 -0400 Subject: [PATCH] feat(@angular/cli): create commits per migration during update --- packages/angular/cli/commands/update-impl.ts | 36 ++++++++++++++++++- packages/schematics/update/update/index.ts | 21 ++++++++++- packages/schematics/update/update/schema.json | 5 +++ 3 files changed, 60 insertions(+), 2 deletions(-) diff --git a/packages/angular/cli/commands/update-impl.ts b/packages/angular/cli/commands/update-impl.ts index 0a39875769e2..1be15926ca06 100644 --- a/packages/angular/cli/commands/update-impl.ts +++ b/packages/angular/cli/commands/update-impl.ts @@ -136,6 +136,7 @@ export class UpdateCommand extends Command { const description = schematic.description as typeof schematic.description & { version?: string; }; + description.version = coerceVersionNumber(description.version) || undefined; if (!description.version) { continue; } @@ -489,8 +490,37 @@ export class UpdateCommand extends Command { force: options.force || false, packageManager, packages: packagesToUpdate, + migrateExternal: true, }); + if (success && !options.skipCommits) { + this.createCommit('Angular CLI update\n' + packagesToUpdate.join('\n'), []); + } + + // This is a temporary workaround to allow data to be passed back from the update schematic + // tslint:disable-next-line: no-any + const migrations = (global as any).externalMigrations as { + package: string; + collection: string; + from: string; + to: string; + }[]; + + if (success && migrations) { + for (const migration of migrations) { + const result = await this.executeMigrations( + migration.package, + migration.collection, + new semver.Range('>' + migration.from + ' <=' + migration.to), + !options.skipCommits, + ); + + if (!result) { + return 0; + } + } + } + return success ? 0 : 1; } @@ -536,7 +566,11 @@ export class UpdateCommand extends Command { } } -function coerceVersionNumber(version: string): string | null { +function coerceVersionNumber(version: string | undefined): string | null { + if (!version) { + return null; + } + if (!version.match(/^\d{1,30}\.\d{1,30}\.\d{1,30}/)) { const match = version.match(/^\d{1,30}(\.\d{1,30})*/); diff --git a/packages/schematics/update/update/index.ts b/packages/schematics/update/update/index.ts index 1ae274078470..cf05b19b7671 100644 --- a/packages/schematics/update/update/index.ts +++ b/packages/schematics/update/update/index.ts @@ -228,6 +228,7 @@ function _performUpdate( infoMap: Map, logger: logging.LoggerApi, migrateOnly: boolean, + migrateExternal: boolean, ): Observable { const packageJsonContent = tree.read('/package.json'); if (!packageJsonContent) { @@ -292,6 +293,8 @@ function _performUpdate( installTask = [context.addTask(new NodePackageInstallTask())]; } + const externalMigrations: {}[] = []; + // Run the migrate schematics with the list of packages to use. The collection contains // version information and we need to do this post installation. Please note that the // migration COULD fail and leave side effects on disk. @@ -307,6 +310,17 @@ function _performUpdate( : '' ) + target.updateMetadata.migrations; + if (migrateExternal) { + externalMigrations.push({ + package: name, + collection, + from: installed.version, + to: target.version, + }); + + return; + } + context.addTask(new RunSchematicTask('@schematics/update', 'migrate', { package: name, collection, @@ -316,6 +330,11 @@ function _performUpdate( installTask, ); }); + + if (externalMigrations.length > 0) { + // tslint:disable-next-line: no-any + (global as any).externalMigrations = externalMigrations; + } } return of(undefined); @@ -906,7 +925,7 @@ export default function(options: UpdateSchema): Rule { ); _validateUpdatePackages(infoMap, !!options.force, sublog); - return _performUpdate(tree, context, infoMap, logger, !!options.migrateOnly); + return _performUpdate(tree, context, infoMap, logger, !!options.migrateOnly, !!options.migrateExternal); } else { return _usageMessage(options, infoMap, logger); } diff --git a/packages/schematics/update/update/schema.json b/packages/schematics/update/update/schema.json index 2385abbde97b..4b849b8a5316 100644 --- a/packages/schematics/update/update/schema.json +++ b/packages/schematics/update/update/schema.json @@ -66,6 +66,11 @@ "npm", "yarn" ] + }, + "migrateExternal": { + "type": "boolean", + "default": false, + "hidden": true } }, "required": [