mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-19 10:41:56 -05:00
Report error if overwriting buildInfo of another project reference
This commit is contained in:
@@ -4016,6 +4016,10 @@
|
||||
"category": "Message",
|
||||
"code": 6376
|
||||
},
|
||||
"Cannot write file '{0}' because it will overwrite '.tsbuildinfo' of referenced project '{1}'": {
|
||||
"category": "Error",
|
||||
"code": 6377
|
||||
},
|
||||
|
||||
"The expected type comes from property '{0}' which is declared here on type '{1}'": {
|
||||
"category": "Message",
|
||||
|
||||
@@ -186,6 +186,10 @@ namespace ts {
|
||||
if (!buildInfoPath || targetSourceFile || emitSkipped) return;
|
||||
const program = host.getProgramBuildInfo();
|
||||
if (!bundle && !program) return;
|
||||
if (host.isEmitBlocked(buildInfoPath) || compilerOptions.noEmit) {
|
||||
emitSkipped = true;
|
||||
return;
|
||||
}
|
||||
writeFile(host, emitterDiagnostics, buildInfoPath, getBuildInfoText({ bundle, program }), /*writeByteOrderMark*/ false);
|
||||
}
|
||||
|
||||
|
||||
@@ -2941,6 +2941,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
function verifyProjectReferences() {
|
||||
const buildInfoPath = !options.noEmit && !options.suppressOutputPathCheck ? getOutputPathForBuildInfo(options, projectReferences) : undefined;
|
||||
forEachProjectReference(projectReferences, resolvedProjectReferences, (resolvedRef, index, parent) => {
|
||||
const ref = (parent ? parent.commandLine.projectReferences : projectReferences)![index];
|
||||
const parentFile = parent && parent.sourceFile as JsonSourceFile;
|
||||
@@ -2967,6 +2968,11 @@ namespace ts {
|
||||
createDiagnosticForReference(parentFile, index, Diagnostics.Cannot_prepend_project_0_because_it_does_not_have_outFile_set, ref.path);
|
||||
}
|
||||
}
|
||||
const refBuildInfoPath = getOutputPathForBuildInfo(options, resolvedRef.commandLine.projectReferences);
|
||||
if (refBuildInfoPath && refBuildInfoPath === buildInfoPath) {
|
||||
createDiagnosticForReference(parentFile, index, Diagnostics.Cannot_write_file_0_because_it_will_overwrite_tsbuildinfo_of_referenced_project_1, buildInfoPath, ref.path);
|
||||
hasEmitBlockingDiagnostics.set(toPath(buildInfoPath), true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -478,6 +478,32 @@ namespace ts {
|
||||
);
|
||||
});
|
||||
|
||||
it("verify that if multiple projects write tsbuildinfo to same location, reports error", () => {
|
||||
const fs = outFileFs.shadow();
|
||||
const host = new fakes.SolutionBuilderHost(fs);
|
||||
replaceText(fs, sources[project.first][source.config], "./bin/first-output.js", "../bin/first-output.js");
|
||||
replaceText(fs, sources[project.second][source.config], "../2/second-output.js", "../bin/second-output.js");
|
||||
replaceText(fs, sources[project.third][source.config], "./thirdjs/output/third-output.js", "../bin/third-output.js");
|
||||
const builder = createSolutionBuilder(host);
|
||||
builder.buildAllProjects();
|
||||
host.assertDiagnosticMessages(
|
||||
getExpectedDiagnosticForProjectsInBuild(relSources[project.first][source.config], relSources[project.second][source.config], relSources[project.third][source.config]),
|
||||
[Diagnostics.Project_0_is_out_of_date_because_output_file_1_does_not_exist, relSources[project.first][source.config], "src/bin/first-output.js"],
|
||||
[Diagnostics.Building_project_0, sources[project.first][source.config]],
|
||||
[Diagnostics.Project_0_is_out_of_date_because_output_file_1_does_not_exist, relSources[project.second][source.config], "src/bin/second-output.js"],
|
||||
[Diagnostics.Building_project_0, sources[project.second][source.config]],
|
||||
[Diagnostics.Project_0_is_out_of_date_because_output_file_1_does_not_exist, relSources[project.third][source.config], "src/bin/third-output.js"],
|
||||
[Diagnostics.Building_project_0, sources[project.third][source.config]],
|
||||
[Diagnostics.Cannot_write_file_0_because_it_will_overwrite_tsbuildinfo_of_referenced_project_1, "/src/bin/.tsbuildinfo", "/src/first"],
|
||||
[Diagnostics.Cannot_write_file_0_because_it_will_overwrite_tsbuildinfo_of_referenced_project_1, "/src/bin/.tsbuildinfo", "/src/second"]
|
||||
);
|
||||
// Verify they exist
|
||||
for (const output of ["/src/bin/first-output.js", "/src/bin/second-output.js"]) {
|
||||
assert(fs.existsSync(output), `Expect file ${output} to exist`);
|
||||
}
|
||||
assert.isFalse(fs.existsSync("/src/bin/third-output.js"), `Expect file "/src/bin/third-output.js" to not exist`);
|
||||
});
|
||||
|
||||
// Prologues
|
||||
function enableStrict(fs: vfs.FileSystem, path: string) {
|
||||
replaceText(fs, path, `"strict": false`, `"strict": true`);
|
||||
|
||||
Reference in New Issue
Block a user