From 1ce3a3bbe5e4eb104e1a4e545b04156309565cfc Mon Sep 17 00:00:00 2001 From: Kristiyan Kostadinov Date: Mon, 8 May 2023 11:20:03 +0200 Subject: [PATCH] fix(cdk/schematics): avoid throwing an error for empty program (#27060) Fixes that the `ng update` schematics were throwing an error if the tsconfig doesn't match any files. Fixes #27055. --- .../schematics/update-tool/utils/parse-tsconfig.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/cdk/schematics/update-tool/utils/parse-tsconfig.ts b/src/cdk/schematics/update-tool/utils/parse-tsconfig.ts index 0a386c819ab2..e87b5a72a74c 100644 --- a/src/cdk/schematics/update-tool/utils/parse-tsconfig.ts +++ b/src/cdk/schematics/update-tool/utils/parse-tsconfig.ts @@ -12,6 +12,9 @@ import {FileSystemHost} from './virtual-host'; import {dirname} from 'path'; import {formatDiagnostics} from './diagnostics'; +/** Code of the error raised by TypeScript when a tsconfig doesn't match any files. */ +const NO_INPUTS_ERROR_CODE = 18003; + /** Class capturing a tsconfig parse error. */ export class TsconfigParseError extends Error {} @@ -45,8 +48,12 @@ export function parseTsconfigFile( {}, ); - if (parsed.errors.length) { - throw new TsconfigParseError(formatDiagnostics(parsed.errors, fileSystem)); + // Skip the "No inputs found..." error since we don't want to interrupt the migration if a + // tsconfig doesn't match a file. This will result in an empty `Program` which is still valid. + const errors = parsed.errors.filter(diag => diag.code !== NO_INPUTS_ERROR_CODE); + + if (errors.length) { + throw new TsconfigParseError(formatDiagnostics(errors, fileSystem)); } return parsed;