Skip to content

Commit

Permalink
feat(@angular/cli): create commits per migration during update (#15611)
Browse files Browse the repository at this point in the history
  • Loading branch information
clydin authored and mgechev committed Sep 17, 2019
1 parent 0d0d124 commit ace02f6
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
36 changes: 35 additions & 1 deletion packages/angular/cli/commands/update-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export class UpdateCommand extends Command<UpdateCommandSchema> {
const description = schematic.description as typeof schematic.description & {
version?: string;
};
description.version = coerceVersionNumber(description.version) || undefined;
if (!description.version) {
continue;
}
Expand Down Expand Up @@ -489,8 +490,37 @@ export class UpdateCommand extends Command<UpdateCommandSchema> {
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;
}

Expand Down Expand Up @@ -536,7 +566,11 @@ export class UpdateCommand extends Command<UpdateCommandSchema> {
}
}

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})*/);

Expand Down
21 changes: 20 additions & 1 deletion packages/schematics/update/update/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ function _performUpdate(
infoMap: Map<string, PackageInfo>,
logger: logging.LoggerApi,
migrateOnly: boolean,
migrateExternal: boolean,
): Observable<void> {
const packageJsonContent = tree.read('/package.json');
if (!packageJsonContent) {
Expand Down Expand Up @@ -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.
Expand All @@ -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,
Expand All @@ -316,6 +330,11 @@ function _performUpdate(
installTask,
);
});

if (externalMigrations.length > 0) {
// tslint:disable-next-line: no-any
(global as any).externalMigrations = externalMigrations;
}
}

return of<void>(undefined);
Expand Down Expand Up @@ -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);
}
Expand Down
5 changes: 5 additions & 0 deletions packages/schematics/update/update/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@
"npm",
"yarn"
]
},
"migrateExternal": {
"type": "boolean",
"default": false,
"hidden": true
}
},
"required": [
Expand Down

0 comments on commit ace02f6

Please sign in to comment.