Skip to content

Commit

Permalink
fix(cdk/schematics): avoid throwing an error for empty program (#27060)
Browse files Browse the repository at this point in the history
Fixes that the `ng update` schematics were throwing an error if the tsconfig doesn't match any files.

Fixes #27055.
  • Loading branch information
crisbeto committed May 8, 2023
1 parent a1e7de9 commit 1ce3a3b
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/cdk/schematics/update-tool/utils/parse-tsconfig.ts
Expand Up @@ -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 {}

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 1ce3a3b

Please sign in to comment.