From 48426852b0c1d5541a3e7369dc2b343e33856968 Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Thu, 17 Nov 2022 13:43:01 +0000 Subject: [PATCH] fix(@schematics/angular): show warning when a TS Config is not found during migrations Prior to this change an error was shown when a non existing tsconfig was referenced in the angular.json. This causes the update to fail. Closes #24264 (cherry picked from commit 5a123a61eab913b8856341d30196de5c0210d4cd) --- .../update-15/update-typescript-target.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/packages/schematics/angular/migrations/update-15/update-typescript-target.ts b/packages/schematics/angular/migrations/update-15/update-typescript-target.ts index 008bf26e893d..faef903ca83c 100644 --- a/packages/schematics/angular/migrations/update-15/update-typescript-target.ts +++ b/packages/schematics/angular/migrations/update-15/update-typescript-target.ts @@ -13,7 +13,7 @@ import { getWorkspace } from '../../utility/workspace'; import { Builders } from '../../utility/workspace-models'; export default function (): Rule { - return async (host) => { + return async (host, context) => { // Workspace level tsconfig updateTarget(host, 'tsconfig.json'); @@ -21,15 +21,25 @@ export default function (): Rule { // Find all tsconfig which are refereces used by builders for (const [, project] of workspace.projects) { - for (const [, target] of project.targets) { + for (const [targetName, target] of project.targets) { // Update all other known CLI builders that use a tsconfig const tsConfigs = [target.options || {}, ...Object.values(target.configurations || {})] .filter((opt) => typeof opt?.tsConfig === 'string') .map((opt) => (opt as { tsConfig: string }).tsConfig); - const uniqueTsConfigs = [...new Set(tsConfigs)]; + const uniqueTsConfigs = new Set(tsConfigs); + for (const tsConfig of uniqueTsConfigs) { + if (host.exists(tsConfig)) { + continue; + } - if (uniqueTsConfigs.length < 1) { + uniqueTsConfigs.delete(tsConfig); + context.logger.warn( + `'${tsConfig}' referenced in the '${targetName}' target does not exist.`, + ); + } + + if (!uniqueTsConfigs.size) { continue; }