Skip to content

Commit 8800cc2

Browse files
authored
Merge pull request #30288 from Microsoft/nonModuleNonPrepend
Add output declaration files from referenced project into program if module: none
2 parents 1463b32 + 927c10a commit 8800cc2

File tree

2 files changed

+52
-6
lines changed

2 files changed

+52
-6
lines changed

src/compiler/program.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -825,11 +825,16 @@ namespace ts {
825825
}
826826
if (rootNames.length) {
827827
for (const parsedRef of resolvedProjectReferences) {
828-
if (parsedRef) {
829-
const out = parsedRef.commandLine.options.outFile || parsedRef.commandLine.options.out;
830-
if (out) {
831-
const dtsOutfile = changeExtension(out, ".d.ts");
832-
processSourceFile(dtsOutfile, /*isDefaultLib*/ false, /*ignoreNoDefaultLib*/ false, /*packageId*/ undefined);
828+
if (!parsedRef) continue;
829+
const out = parsedRef.commandLine.options.outFile || parsedRef.commandLine.options.out;
830+
if (out) {
831+
processSourceFile(changeExtension(out, ".d.ts"), /*isDefaultLib*/ false, /*ignoreNoDefaultLib*/ false, /*packageId*/ undefined);
832+
}
833+
else if (getEmitModuleKind(parsedRef.commandLine.options) === ModuleKind.None) {
834+
for (const fileName of parsedRef.commandLine.fileNames) {
835+
if (!fileExtensionIs(fileName, Extension.Dts) && hasTSFileExtension(fileName)) {
836+
processSourceFile(getOutputDeclarationFileName(fileName, parsedRef.commandLine), /*isDefaultLib*/ false, /*ignoreNoDefaultLib*/ false, /*packageId*/ undefined);
837+
}
833838
}
834839
}
835840
}

src/testRunner/unittests/tsbuild/outFile.ts

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,6 @@ namespace ts {
436436
changeCompilerVersion(host);
437437
builder.buildAllProjects();
438438
host.assertDiagnosticMessages(
439-
// TODO:: This should build all instead
440439
getExpectedDiagnosticForProjectsInBuild(relSources[project.first][source.config], relSources[project.second][source.config], relSources[project.third][source.config]),
441440
[Diagnostics.Project_0_is_out_of_date_because_output_for_it_was_generated_with_version_1_that_differs_with_current_version_2, relSources[project.first][source.config], fakes.version, version],
442441
[Diagnostics.Building_project_0, sources[project.first][source.config]],
@@ -843,5 +842,47 @@ ${internal} enum internalEnum { a, b, c }`);
843842
});
844843
});
845844
});
845+
846+
it("non module projects without prepend", () => {
847+
const fs = outFileFs.shadow();
848+
// No prepend
849+
replaceText(fs, sources[project.third][source.config], `{ "path": "../first", "prepend": true }`, `{ "path": "../first" }`);
850+
replaceText(fs, sources[project.third][source.config], `{ "path": "../second", "prepend": true }`, `{ "path": "../second" }`);
851+
852+
// Non Modules
853+
replaceText(fs, sources[project.first][source.config], `"composite": true,`, `"composite": true, "module": "none",`);
854+
replaceText(fs, sources[project.second][source.config], `"composite": true,`, `"composite": true, "module": "none",`);
855+
replaceText(fs, sources[project.third][source.config], `"composite": true,`, `"composite": true, "module": "none",`);
856+
857+
// Own file emit
858+
replaceText(fs, sources[project.first][source.config], `"outFile": "./bin/first-output.js",`, "");
859+
replaceText(fs, sources[project.second][source.config], `"outFile": "../2/second-output.js",`, "");
860+
replaceText(fs, sources[project.third][source.config], `"outFile": "./thirdjs/output/third-output.js",`, "");
861+
862+
const host = new fakes.SolutionBuilderHost(fs);
863+
const builder = createSolutionBuilder(host);
864+
builder.buildAllProjects();
865+
host.assertDiagnosticMessages(
866+
getExpectedDiagnosticForProjectsInBuild(relSources[project.first][source.config], relSources[project.second][source.config], relSources[project.third][source.config]),
867+
[Diagnostics.Project_0_is_out_of_date_because_output_file_1_does_not_exist, relSources[project.first][source.config], "src/first/first_PART1.js"],
868+
[Diagnostics.Building_project_0, sources[project.first][source.config]],
869+
[Diagnostics.Project_0_is_out_of_date_because_output_file_1_does_not_exist, relSources[project.second][source.config], "src/second/second_part1.js"],
870+
[Diagnostics.Building_project_0, sources[project.second][source.config]],
871+
[Diagnostics.Project_0_is_out_of_date_because_output_file_1_does_not_exist, relSources[project.third][source.config], "src/third/third_part1.js"],
872+
[Diagnostics.Building_project_0, sources[project.third][source.config]]
873+
);
874+
const expectedOutputFiles = flatMap(sources, ([config, ts]) => [
875+
removeFileExtension(config) + Extension.TsBuildInfo,
876+
...flatMap(ts, f => [
877+
removeFileExtension(f) + Extension.Js,
878+
removeFileExtension(f) + Extension.Js + ".map",
879+
removeFileExtension(f) + Extension.Dts,
880+
removeFileExtension(f) + Extension.Dts + ".map",
881+
])
882+
]);
883+
for (const output of expectedOutputFiles) {
884+
assert(fs.existsSync(output), `Expect file ${output} to exist`);
885+
}
886+
});
846887
});
847888
}

0 commit comments

Comments
 (0)