refactor(core): improve messages for static-query migrations (#30458)

Slightly improves the messages for the static-query migration in order
to make the terminal output less verbose but more helpful. Unfortunately
we are limited in what we can print due to the devkit not providing much
utilities for printing good messages from a migration schematic.

PR Close #30458
This commit is contained in:
Paul Gschwendtner 2019-05-14 20:59:21 +02:00 committed by Alex Rickabaugh
parent 0cdf5980e2
commit 9e5377a2e3
4 changed files with 14 additions and 18 deletions

View File

@ -53,7 +53,6 @@ async function runMigration(tree: Tree, context: SchematicContext) {
logger.info('In preparation for Ivy, developers can now explicitly specify the');
logger.info('timing of their queries. Read more about this here:');
logger.info('https://github.com/angular/angular/pull/28810');
logger.info('');
if (!buildPaths.length && !testPaths.length) {
throw new SchematicsException(
@ -92,6 +91,7 @@ async function runMigration(tree: Tree, context: SchematicContext) {
}
if (failures.length) {
logger.info('');
logger.info('Some queries could not be migrated automatically. Please go');
logger.info('through those manually and apply the appropriate timing:');
failures.forEach(failure => logger.warn(`${failure}`));
@ -153,7 +153,7 @@ function analyzeProject(
*/
async function runStaticQueryMigration(
tree: Tree, project: AnalyzedProject, selectedStrategy: SELECTED_STRATEGY,
logger: logging.LoggerApi) {
logger: logging.LoggerApi): Promise<string[]> {
const {sourceFiles, typeChecker, host, queryVisitor, tsconfigPath, basePath} = project;
const printer = ts.createPrinter();
const failureMessages: string[] = [];
@ -190,22 +190,22 @@ async function runStaticQueryMigration(
try {
strategy.setup();
} catch (e) {
// In case the strategy could not be set up properly, we just exit the
// migration. We don't want to throw an exception as this could mean
// that other migrations are interrupted.
logger.warn(
`Could not setup migration strategy for "${project.tsconfigPath}". The ` +
`following error has been reported:`);
if (selectedStrategy === SELECTED_STRATEGY.TEMPLATE) {
logger.warn(
`The template migration strategy uses the Angular compiler ` +
`internally and therefore projects that no longer build successfully after ` +
`the update cannot use the template migration strategy. Please ensure ` +
`there are no AOT compilation errors.`);
`there are no AOT compilation errors.\n`);
}
logger.error(e.toString());
// In case the strategy could not be set up properly, we just exit the
// migration. We don't want to throw an exception as this could mean
// that other migrations are interrupted.
logger.warn(
`Could not setup migration strategy for "${project.tsconfigPath}". The ` +
`following error has been reported:\n`);
logger.error(`${e.toString()}\n`);
logger.info(
'Migration can be rerun with: "ng update @angular/core --from 7 --to 8 --migrate-only"');
'Migration can be rerun with: "ng update @angular/core --from 7 --to 8 --migrate-only"\n');
return [];
}

View File

@ -179,11 +179,7 @@ export class QueryTemplateStrategy implements TimingStrategy {
}
private _createDiagnosticsError(diagnostics: (ts.Diagnostic|Diagnostic)[]) {
return new Error(
`Could not create Angular AOT compiler to determine query timing.\n` +
`The following diagnostics were detected:\n` +
`${diagnostics.map(d => d.messageText).join(`\n `)}\n` +
`Please make sure that there is no AOT compilation failure.`);
return new Error(`${diagnostics.map(d => d.messageText).join(`\n `)}`);
}
private _getViewQueryUniqueKey(filePath: string, className: string, propName: string) {

View File

@ -72,7 +72,7 @@ export function getTransformedQueryCallExpr(
// we create a transformation failure message that shows developers that they need
// to set the query timing manually to the determined query timing.
if (timing !== null) {
failureMessage = 'Cannot update query declaration to explicit timing. Please manually ' +
failureMessage = 'Cannot update query to set explicit timing. Please manually ' +
`set the query timing to: "{static: ${(timing === QueryTiming.STATIC).toString()}}"`;
}
}

View File

@ -602,7 +602,7 @@ describe('static-queries migration with template strategy', () => {
.toContain(`@ViewChild('myRef', /* TODO: add static flag */ myOptionsVar) query: any;`);
expect(warnOutput.length).toBe(1);
expect(warnOutput[0])
.toMatch(/^⮑ {3}index.ts@8:11: Cannot update query declaration to explicit timing./);
.toMatch(/^⮑ {3}index.ts@8:11: Cannot update query to set explicit timing./);
expect(warnOutput[0]).toMatch(/Please manually set the query timing to.*static: true/);
});