Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(@angular/cli): create commits per migration during update #15611

Merged
merged 1 commit into from
Sep 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not: redundant || 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