Skip to content

Commit bd229b5

Browse files
committed
Exclude Json files from Project reference redirects from files to be emitted list
Fixes #30382
1 parent a6f7ec3 commit bd229b5

File tree

14 files changed

+58
-55
lines changed

14 files changed

+58
-55
lines changed

src/compiler/builder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -980,7 +980,7 @@ namespace ts {
980980
backupState: noop,
981981
restoreState: noop,
982982
getProgram: notImplemented,
983-
getProgramOrUndefined: () => undefined,
983+
getProgramOrUndefined: returnUndefined,
984984
releaseProgram: noop,
985985
getCompilerOptions: () => state.compilerOptions,
986986
getSourceFile: notImplemented,

src/compiler/core.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1614,6 +1614,9 @@ namespace ts {
16141614
/** Do nothing and return true */
16151615
export function returnTrue(): true { return true; }
16161616

1617+
/** Do nothing and return undefined */
1618+
export function returnUndefined(): undefined { return undefined; }
1619+
16171620
/** Returns its argument. */
16181621
export function identity<T>(x: T) { return x; }
16191622

src/compiler/emitter.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -680,11 +680,12 @@ namespace ts {
680680
getCompilerOptions: () => config.options,
681681
getCurrentDirectory: () => host.getCurrentDirectory(),
682682
getNewLine: () => host.getNewLine(),
683-
getSourceFile: () => undefined,
684-
getSourceFileByPath: () => undefined,
683+
getSourceFile: returnUndefined,
684+
getSourceFileByPath: returnUndefined,
685685
getSourceFiles: () => sourceFilesForJsEmit,
686686
getLibFileFromReference: notImplemented,
687687
isSourceFileFromExternalLibrary: returnFalse,
688+
getResolvedProjectReferenceToRedirect: returnUndefined,
688689
writeFile: (name, text, writeByteOrderMark) => {
689690
switch (name) {
690691
case jsFilePath:
@@ -721,7 +722,7 @@ namespace ts {
721722
fileExists: f => host.fileExists(f),
722723
directoryExists: host.directoryExists && (f => host.directoryExists!(f)),
723724
useCaseSensitiveFileNames: () => host.useCaseSensitiveFileNames(),
724-
getProgramBuildInfo: () => undefined
725+
getProgramBuildInfo: returnUndefined
725726
};
726727
emitFiles(notImplementedResolver, emitHost, /*targetSourceFile*/ undefined, /*emitOnlyDtsFiles*/ false, getTransformers(config.options));
727728
return outputFiles;

src/compiler/factory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3405,7 +3405,7 @@ namespace ts {
34053405
export const nullTransformationContext: TransformationContext = {
34063406
enableEmitNotification: noop,
34073407
enableSubstitution: noop,
3408-
endLexicalEnvironment: () => undefined,
3408+
endLexicalEnvironment: returnUndefined,
34093409
getCompilerOptions: notImplemented,
34103410
getEmitHost: notImplemented,
34113411
getEmitResolver: notImplemented,

src/compiler/program.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,7 @@ namespace ts {
979979

980980
function getCommonSourceDirectory() {
981981
if (commonSourceDirectory === undefined) {
982-
const emittedFiles = filter(files, file => sourceFileMayBeEmitted(file, options, isSourceFileFromExternalLibrary));
982+
const emittedFiles = filter(files, file => sourceFileMayBeEmitted(file, options, isSourceFileFromExternalLibrary, getResolvedProjectReferenceToRedirect));
983983
if (options.rootDir && checkSourceFilesBelongToPath(emittedFiles, options.rootDir)) {
984984
// If a rootDir is specified use it as the commonSourceDirectory
985985
commonSourceDirectory = getNormalizedAbsolutePath(options.rootDir, currentDirectory);
@@ -1425,6 +1425,7 @@ namespace ts {
14251425
getSourceFiles: program.getSourceFiles,
14261426
getLibFileFromReference: program.getLibFileFromReference,
14271427
isSourceFileFromExternalLibrary,
1428+
getResolvedProjectReferenceToRedirect,
14281429
writeFile: writeFileCallback || (
14291430
(fileName, data, writeByteOrderMark, onError, sourceFiles) => host.writeFile(fileName, data, writeByteOrderMark, onError, sourceFiles)),
14301431
isEmitBlocked,
@@ -2740,13 +2741,14 @@ namespace ts {
27402741

27412742
// List of collected files is complete; validate exhautiveness if this is a project with a file list
27422743
if (options.composite) {
2743-
const sourceFiles = files.filter(f => !f.isDeclarationFile);
2744-
if (rootNames.length < sourceFiles.length) {
2745-
const normalizedRootNames = rootNames.map(r => normalizePath(r).toLowerCase());
2746-
for (const file of sourceFiles.map(f => normalizePath(f.path).toLowerCase())) {
2747-
if (normalizedRootNames.indexOf(file) === -1) {
2748-
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.File_0_is_not_in_project_file_list_Projects_must_list_all_files_or_use_an_include_pattern, file));
2749-
}
2744+
const rootPaths = rootNames.map(r => toPath(r));
2745+
for (const file of files) {
2746+
// Ignore declaration files
2747+
if (file.isDeclarationFile) continue;
2748+
// Ignore json file thats from project reference
2749+
if (isJsonSourceFile(file) && getResolvedProjectReferenceToRedirect(file.fileName)) continue;
2750+
if (rootPaths.indexOf(file.path) === -1) {
2751+
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.File_0_is_not_in_project_file_list_Projects_must_list_all_files_or_use_an_include_pattern, file.fileName));
27502752
}
27512753
}
27522754
}
@@ -3158,7 +3160,7 @@ namespace ts {
31583160
readFile: f => directoryStructureHost.readFile(f),
31593161
useCaseSensitiveFileNames: host.useCaseSensitiveFileNames(),
31603162
getCurrentDirectory: () => host.getCurrentDirectory(),
3161-
onUnRecoverableConfigFileDiagnostic: host.onUnRecoverableConfigFileDiagnostic || (() => undefined),
3163+
onUnRecoverableConfigFileDiagnostic: host.onUnRecoverableConfigFileDiagnostic || returnUndefined,
31623164
trace: host.trace ? (s) => host.trace!(s) : undefined
31633165
};
31643166
}

src/compiler/tsbuild.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ namespace ts {
339339

340340
function createSolutionBuilderHostBase<T extends BuilderProgram>(system: System, createProgram: CreateProgram<T> | undefined, reportDiagnostic?: DiagnosticReporter, reportSolutionBuilderStatus?: DiagnosticReporter) {
341341
const host = createProgramHost(system, createProgram) as SolutionBuilderHostBase<T>;
342-
host.getModifiedTime = system.getModifiedTime ? path => system.getModifiedTime!(path) : () => undefined;
342+
host.getModifiedTime = system.getModifiedTime ? path => system.getModifiedTime!(path) : returnUndefined;
343343
host.setModifiedTime = system.setModifiedTime ? (path, date) => system.setModifiedTime!(path, date) : noop;
344344
host.deleteFile = system.deleteFile ? path => system.deleteFile!(path) : noop;
345345
host.reportDiagnostic = reportDiagnostic || createDiagnosticReporter(system);
@@ -660,15 +660,16 @@ namespace ts {
660660
}
661661
}
662662

663-
// Collect the expected outputs of this project
664-
const outputs = getAllProjectOutputs(project, !host.useCaseSensitiveFileNames());
665-
666-
if (outputs.length === 0) {
663+
// Container if no files are specified in the project
664+
if (!project.fileNames.length && !canJsonReportNoInutFiles(project.raw)) {
667665
return {
668666
type: UpToDateStatusType.ContainerOnly
669667
};
670668
}
671669

670+
// Collect the expected outputs of this project
671+
const outputs = getAllProjectOutputs(project, !host.useCaseSensitiveFileNames());
672+
672673
// Now see if all outputs are newer than the newest input
673674
let oldestOutputFileName = "(none)";
674675
let oldestOutputFileTime = maximumDate;

src/compiler/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5337,6 +5337,7 @@ namespace ts {
53375337
getCurrentDirectory(): string;
53385338

53395339
isSourceFileFromExternalLibrary(file: SourceFile): boolean;
5340+
getResolvedProjectReferenceToRedirect(fileName: string): ResolvedProjectReference | undefined;
53405341
getLibFileFromReference(ref: FileReference): SourceFile | undefined;
53415342

53425343
getCommonSourceDirectory(): string;

src/compiler/utilities.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3422,22 +3422,26 @@ namespace ts {
34223422
export function getSourceFilesToEmit(host: EmitHost, targetSourceFile?: SourceFile): ReadonlyArray<SourceFile> {
34233423
const options = host.getCompilerOptions();
34243424
const isSourceFileFromExternalLibrary = (file: SourceFile) => host.isSourceFileFromExternalLibrary(file);
3425+
const getResolvedProjectReferenceToRedirect = (fileName: string) => host.getResolvedProjectReferenceToRedirect(fileName);
34253426
if (options.outFile || options.out) {
34263427
const moduleKind = getEmitModuleKind(options);
34273428
const moduleEmitEnabled = options.emitDeclarationOnly || moduleKind === ModuleKind.AMD || moduleKind === ModuleKind.System;
34283429
// Can emit only sources that are not declaration file and are either non module code or module with --module or --target es6 specified
34293430
return filter(host.getSourceFiles(), sourceFile =>
3430-
(moduleEmitEnabled || !isExternalModule(sourceFile)) && sourceFileMayBeEmitted(sourceFile, options, isSourceFileFromExternalLibrary));
3431+
(moduleEmitEnabled || !isExternalModule(sourceFile)) && sourceFileMayBeEmitted(sourceFile, options, isSourceFileFromExternalLibrary, getResolvedProjectReferenceToRedirect));
34313432
}
34323433
else {
34333434
const sourceFiles = targetSourceFile === undefined ? host.getSourceFiles() : [targetSourceFile];
3434-
return filter(sourceFiles, sourceFile => sourceFileMayBeEmitted(sourceFile, options, isSourceFileFromExternalLibrary));
3435+
return filter(sourceFiles, sourceFile => sourceFileMayBeEmitted(sourceFile, options, isSourceFileFromExternalLibrary, getResolvedProjectReferenceToRedirect));
34353436
}
34363437
}
34373438

34383439
/** Don't call this for `--outFile`, just for `--outDir` or plain emit. `--outFile` needs additional checks. */
3439-
export function sourceFileMayBeEmitted(sourceFile: SourceFile, options: CompilerOptions, isSourceFileFromExternalLibrary: (file: SourceFile) => boolean) {
3440-
return !(options.noEmitForJsFiles && isSourceFileJS(sourceFile)) && !sourceFile.isDeclarationFile && !isSourceFileFromExternalLibrary(sourceFile);
3440+
export function sourceFileMayBeEmitted(sourceFile: SourceFile, options: CompilerOptions, isSourceFileFromExternalLibrary: (file: SourceFile) => boolean, getResolvedProjectReferenceToRedirect: (fileName: string) => ResolvedProjectReference | undefined) {
3441+
return !(options.noEmitForJsFiles && isSourceFileJS(sourceFile)) &&
3442+
!sourceFile.isDeclarationFile &&
3443+
!isSourceFileFromExternalLibrary(sourceFile) &&
3444+
!(isJsonSourceFile(sourceFile) && getResolvedProjectReferenceToRedirect(sourceFile.fileName));
34413445
}
34423446

34433447
export function getSourceFilePathInNewDir(fileName: string, host: EmitHost, newDirPath: string): string {

src/testRunner/unittests/tsbuild/resolveJsonModule.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -132,22 +132,15 @@ export default hello.hello`);
132132
[Diagnostics.Building_project_0, `/${stringsConfigFile}`],
133133
[Diagnostics.Project_0_is_out_of_date_because_output_file_1_does_not_exist, mainConfigFile, "src/main/index.js"],
134134
[Diagnostics.Building_project_0, `/${mainConfigFile}`],
135-
[Diagnostics.File_0_is_not_in_project_file_list_Projects_must_list_all_files_or_use_an_include_pattern, "/src/strings/foo.json"],
136-
[Diagnostics.Project_0_can_t_be_built_because_its_dependency_1_has_errors, configFile, mainConfigFile],
137-
[Diagnostics.Skipping_build_of_project_0_because_its_dependency_1_has_errors, `/${configFile}`, `/${mainConfigFile}`]
138135
);
139-
assert.isFalse(fs.existsSync(expectedOutput), `Expect file ${expectedOutput} to not exist because of errors`);
136+
assert(fs.existsSync(expectedOutput), `Expect file ${expectedOutput} to exist`);
140137
host.clearDiagnostics();
141138
builder.resetBuildContext();
142139
builder.buildAllProjects();
143140
host.assertDiagnosticMessages(
144141
getExpectedDiagnosticForProjectsInBuild(stringsConfigFile, mainConfigFile, configFile),
145142
[Diagnostics.Project_0_is_up_to_date_because_newest_input_1_is_older_than_oldest_output_2, stringsConfigFile, "src/strings/foo.json", "src/strings/tsconfig.tsbuildinfo"],
146-
[Diagnostics.Project_0_is_out_of_date_because_output_file_1_does_not_exist, mainConfigFile, "src/main/index.js"],
147-
[Diagnostics.Building_project_0, `/${mainConfigFile}`],
148-
[Diagnostics.File_0_is_not_in_project_file_list_Projects_must_list_all_files_or_use_an_include_pattern, "/src/strings/foo.json"],
149-
[Diagnostics.Project_0_can_t_be_built_because_its_dependency_1_has_errors, configFile, mainConfigFile],
150-
[Diagnostics.Skipping_build_of_project_0_because_its_dependency_1_has_errors, `/${configFile}`, `/${mainConfigFile}`]
143+
[Diagnostics.Project_0_is_up_to_date_because_newest_input_1_is_older_than_oldest_output_2, mainConfigFile, "src/main/index.ts", "src/main/index.js"],
151144
);
152145
});
153146
});

src/testRunner/unittests/tsserver/helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ namespace ts.projectSystem {
6464
msg: noop,
6565
startGroup: noop,
6666
endGroup: noop,
67-
getLogFileName: () => undefined,
67+
getLogFileName: returnUndefined,
6868
};
6969

7070
export function createHasErrorMessageLogger() {

0 commit comments

Comments
 (0)