diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 3285599697..724c04b736 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -48,7 +48,7 @@ namespace ts { } if (includeBuildInfo) { const buildInfoPath = getOutputPathForBuildInfo(host.getCompilerOptions(), host.getProjectReferences()); - return action({ buildInfoPath }, /*sourceFileOrBundle*/ undefined); + if (buildInfoPath) return action({ buildInfoPath }, /*sourceFileOrBundle*/ undefined); } } } diff --git a/src/compiler/tsbuild.ts b/src/compiler/tsbuild.ts index 09f7c042fc..141008e049 100644 --- a/src/compiler/tsbuild.ts +++ b/src/compiler/tsbuild.ts @@ -1487,7 +1487,10 @@ namespace ts { for (const inputFile of project.fileNames) { outputs.push(...getOutputFileNames(inputFile, project)); } - if (!ignoreBuildInfo) outputs.push(Debug.assertDefined(getOutputPathForBuildInfo(project.options, project.projectReferences))); + if (!ignoreBuildInfo) { + const buildInfoPath = getOutputPathForBuildInfo(project.options, project.projectReferences); + if (buildInfoPath) outputs.push(buildInfoPath); + } return outputs; } } diff --git a/src/testRunner/unittests/tsbuild/sample.ts b/src/testRunner/unittests/tsbuild/sample.ts index 9db347745e..51ccd64d30 100644 --- a/src/testRunner/unittests/tsbuild/sample.ts +++ b/src/testRunner/unittests/tsbuild/sample.ts @@ -65,6 +65,22 @@ namespace ts { assert(fs.existsSync(output), `Expect file ${output} to exist`); } }); + + it("builds correctly when project is not composite or doesnt have any references", () => { + const fs = projFs.shadow(); + replaceText(fs, "/src/core/tsconfig.json", `"composite": true,`, ""); + const host = new fakes.SolutionBuilderHost(fs); + const builder = createSolutionBuilder(host, ["/src/core"], { verbose: true }); + builder.buildAllProjects(); + host.assertDiagnosticMessages( + getExpectedDiagnosticForProjectsInBuild("src/core/tsconfig.json"), + [Diagnostics.Project_0_is_out_of_date_because_output_file_1_does_not_exist, "src/core/tsconfig.json", "src/core/anotherModule.js"], + [Diagnostics.Building_project_0, "/src/core/tsconfig.json"] + ); + for (const output of ["/src/core/index.js", "/src/core/index.d.ts", "/src/core/index.d.ts.map"]) { + assert(fs.existsSync(output), `Expect file ${output} to exist`); + } + }); }); describe("dry builds", () => {