Skip to content

Commit 901476f

Browse files
authored
Merge pull request #28271 from Microsoft/containerOnlyProgramFiles
Do not add source files to container only project
2 parents deeee77 + 121a350 commit 901476f

File tree

3 files changed

+27
-12
lines changed

3 files changed

+27
-12
lines changed

src/compiler/program.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -694,12 +694,14 @@ namespace ts {
694694
if (!resolvedProjectReferences) {
695695
resolvedProjectReferences = projectReferences.map(parseProjectReferenceConfigFile);
696696
}
697-
for (const parsedRef of resolvedProjectReferences) {
698-
if (parsedRef) {
699-
const out = parsedRef.commandLine.options.outFile || parsedRef.commandLine.options.out;
700-
if (out) {
701-
const dtsOutfile = changeExtension(out, ".d.ts");
702-
processSourceFile(dtsOutfile, /*isDefaultLib*/ false, /*ignoreNoDefaultLib*/ false, /*packageId*/ undefined);
697+
if (rootNames.length) {
698+
for (const parsedRef of resolvedProjectReferences) {
699+
if (parsedRef) {
700+
const out = parsedRef.commandLine.options.outFile || parsedRef.commandLine.options.out;
701+
if (out) {
702+
const dtsOutfile = changeExtension(out, ".d.ts");
703+
processSourceFile(dtsOutfile, /*isDefaultLib*/ false, /*ignoreNoDefaultLib*/ false, /*packageId*/ undefined);
704+
}
703705
}
704706
}
705707
}
@@ -708,7 +710,7 @@ namespace ts {
708710
forEach(rootNames, name => processRootFile(name, /*isDefaultLib*/ false, /*ignoreNoDefaultLib*/ false));
709711

710712
// load type declarations specified via 'types' argument or implicitly from types/ and node_modules/@types folders
711-
const typeReferences: string[] = getAutomaticTypeDirectiveNames(options, host);
713+
const typeReferences: string[] = rootNames.length ? getAutomaticTypeDirectiveNames(options, host) : emptyArray;
712714

713715
if (typeReferences.length) {
714716
// This containingFilename needs to match with the one used in managed-side
@@ -724,7 +726,7 @@ namespace ts {
724726
// - The '--noLib' flag is used.
725727
// - A 'no-default-lib' reference comment is encountered in
726728
// processing the root files.
727-
if (!skipDefaultLib) {
729+
if (rootNames.length && !skipDefaultLib) {
728730
// If '--lib' is not specified, include default library file according to '--target'
729731
// otherwise, using options specified in '--lib' instead of '--target' default library file
730732
const defaultLibraryFileName = getDefaultLibraryFileName();
@@ -1839,7 +1841,7 @@ namespace ts {
18391841
}
18401842

18411843
function getGlobalDiagnostics(): SortedReadonlyArray<Diagnostic> {
1842-
return sortAndDeduplicateDiagnostics(getDiagnosticsProducingTypeChecker().getGlobalDiagnostics().slice());
1844+
return rootNames.length ? sortAndDeduplicateDiagnostics(getDiagnosticsProducingTypeChecker().getGlobalDiagnostics().slice()) : emptyArray as any as SortedReadonlyArray<Diagnostic>;
18431845
}
18441846

18451847
function getConfigFileParsingDiagnostics(): ReadonlyArray<Diagnostic> {

src/testRunner/unittests/tscWatchMode.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,7 +1074,10 @@ namespace ts.tscWatch {
10741074
const host = createWatchedSystem([file1, configFile, libFile]);
10751075
const watch = createWatchOfConfigFile(configFile.path, host);
10761076

1077-
checkProgramActualFiles(watch(), [libFile.path]);
1077+
checkProgramActualFiles(watch(), emptyArray);
1078+
checkOutputErrorsInitial(host, [
1079+
"error TS18003: No inputs were found in config file '/a/b/tsconfig.json'. Specified 'include' paths were '[\"app/*\",\"test/**/*\",\"something\"]' and 'exclude' paths were '[]'.\n"
1080+
]);
10781081
});
10791082

10801083
it("non-existing directories listed in config file input array should be able to handle @types if input file list is empty", () => {
@@ -1100,7 +1103,10 @@ namespace ts.tscWatch {
11001103
const host = createWatchedSystem([f, config, t1, t2], { currentDirectory: getDirectoryPath(f.path) });
11011104
const watch = createWatchOfConfigFile(config.path, host);
11021105

1103-
checkProgramActualFiles(watch(), [t1.path, t2.path]);
1106+
checkProgramActualFiles(watch(), emptyArray);
1107+
checkOutputErrorsInitial(host, [
1108+
"tsconfig.json(1,24): error TS18002: The 'files' list in config file '/a/tsconfig.json' is empty.\n"
1109+
]);
11041110
});
11051111

11061112
it("should support files without extensions", () => {

src/testRunner/unittests/tsserverProjectSystem.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3086,7 +3086,7 @@ namespace ts.projectSystem {
30863086
const configProject = configuredProjectAt(projectService, 0);
30873087
checkProjectActualFiles(configProject, lazyConfiguredProjectsFromExternalProject ?
30883088
emptyArray : // Since no files opened from this project, its not loaded
3089-
[libFile.path, configFile.path]);
3089+
[configFile.path]);
30903090

30913091
host.reloadFS([libFile, site]);
30923092
host.checkTimeoutQueueLengthAndRun(1);
@@ -10575,6 +10575,13 @@ declare class TestLib {
1057510575
}).response;
1057610576
assert.deepEqual(semanticDiagnostics, []);
1057710577
});
10578+
const containerProject = service.configuredProjects.get(containerConfig.path)!;
10579+
checkProjectActualFiles(containerProject, [containerConfig.path]);
10580+
const optionsDiagnostics = session.executeCommandSeq<protocol.CompilerOptionsDiagnosticsRequest>({
10581+
command: protocol.CommandTypes.CompilerOptionsDiagnosticsFull,
10582+
arguments: { projectFileName: containerProject.projectName }
10583+
}).response;
10584+
assert.deepEqual(optionsDiagnostics, []);
1057810585
});
1057910586

1058010587
it("can successfully find references with --out options", () => {

0 commit comments

Comments
 (0)