Skip to content

Commit eb77b53

Browse files
cexbrayatpkozlowski-opensource
authored andcommitted
refactor(migrations): avoid TS error 18003 when no files found (angular#57899)
When running a migration, tsurge creates a TS program from the tsconfig files found. This can result in a 18003 error when no files are found (based on the includes/files of the config). For example, the signal input migration throws in a CLI project that has no spec files: ``` ng g @angular/core:signal-inputs --defaults Tsconfig could not be parsed or is invalid: No inputs were found in config file '/tsconfig.spec.json'. Specified 'include' paths were '["src/**/*.spec.ts","src/**/*.d.ts"]' and 'exclude' paths were '["/out-tsc/spec"]'. ``` A similar issue has already been raised in the CDK migration (see angular/components#27055). This was solved in the CDK (credits to @crisbeto) by ignoring the 18003 error (see 9c1112d408361a47c98dfd470b8e990cbd1753db). This PR does the same in tsurge. PR Close angular#57899
1 parent 101d162 commit eb77b53

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

packages/core/schematics/utils/tsurge/helpers/ngtsc_program.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@ import {
1717
import {NgtscProgram} from '@angular/compiler-cli/src/ngtsc/program';
1818
import {BaseProgramInfo} from '../program_info';
1919

20+
/** Code of the error raised by TypeScript when a tsconfig doesn't match any files. */
21+
const NO_INPUTS_ERROR_CODE = 18003;
22+
2023
/**
2124
* Parses the configuration of the given TypeScript project and creates
22-
* an instance of the Angular compiler for for the project.
25+
* an instance of the Angular compiler for the project.
2326
*/
2427
export function createNgtscProgram(
2528
absoluteTsconfigPath: string,
@@ -33,10 +36,13 @@ export function createNgtscProgram(
3336

3437
const tsconfig = readConfiguration(absoluteTsconfigPath, {}, fs);
3538

36-
if (tsconfig.errors.length > 0) {
39+
// Skip the "No inputs found..." error since we don't want to interrupt the migration if a
40+
// tsconfig doesn't match a file. This will result in an empty `Program` which is still valid.
41+
const errors = tsconfig.errors.filter((diag) => diag.code !== NO_INPUTS_ERROR_CODE);
42+
43+
if (errors.length) {
3744
throw new Error(
38-
`Tsconfig could not be parsed or is invalid:\n\n` +
39-
`${tsconfig.errors.map((e) => e.messageText)}`,
45+
`Tsconfig could not be parsed or is invalid:\n\n` + `${errors.map((e) => e.messageText)}`,
4046
);
4147
}
4248

0 commit comments

Comments
 (0)