From 9e5377a2e3c4431f73985bc9272f5bf09dc6e30d Mon Sep 17 00:00:00 2001 From: Paul Gschwendtner Date: Tue, 14 May 2019 20:59:21 +0200 Subject: [PATCH] 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 --- .../migrations/static-queries/index.ts | 22 +++++++++---------- .../template_strategy/template_strategy.ts | 6 +---- .../migrations/static-queries/transform.ts | 2 +- .../static_queries_migration_template_spec.ts | 2 +- 4 files changed, 14 insertions(+), 18 deletions(-) diff --git a/packages/core/schematics/migrations/static-queries/index.ts b/packages/core/schematics/migrations/static-queries/index.ts index 19bdba3934..505c404bde 100644 --- a/packages/core/schematics/migrations/static-queries/index.ts +++ b/packages/core/schematics/migrations/static-queries/index.ts @@ -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 { 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 []; } diff --git a/packages/core/schematics/migrations/static-queries/strategies/template_strategy/template_strategy.ts b/packages/core/schematics/migrations/static-queries/strategies/template_strategy/template_strategy.ts index f7c0084470..6157ab3b99 100644 --- a/packages/core/schematics/migrations/static-queries/strategies/template_strategy/template_strategy.ts +++ b/packages/core/schematics/migrations/static-queries/strategies/template_strategy/template_strategy.ts @@ -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) { diff --git a/packages/core/schematics/migrations/static-queries/transform.ts b/packages/core/schematics/migrations/static-queries/transform.ts index 139df0afa2..f60875799a 100644 --- a/packages/core/schematics/migrations/static-queries/transform.ts +++ b/packages/core/schematics/migrations/static-queries/transform.ts @@ -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()}}"`; } } diff --git a/packages/core/schematics/test/static_queries_migration_template_spec.ts b/packages/core/schematics/test/static_queries_migration_template_spec.ts index 31483df180..4376b2d97f 100644 --- a/packages/core/schematics/test/static_queries_migration_template_spec.ts +++ b/packages/core/schematics/test/static_queries_migration_template_spec.ts @@ -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/); });