Skip to content

Commit 5696384

Browse files
committed
Handle prepend output to be emitted in downstream project even if declaration file doesnt change
1 parent 0319f10 commit 5696384

File tree

2 files changed

+89
-14
lines changed

2 files changed

+89
-14
lines changed

src/compiler/tsbuild.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ namespace ts {
1313

1414
interface DependencyGraph {
1515
buildQueue: ResolvedConfigFileName[];
16-
referencingProjectsMap: ConfigFileMap<ConfigFileMap<true>>;
16+
/** value in config File map is true if project is referenced using prepend */
17+
referencingProjectsMap: ConfigFileMap<ConfigFileMap<boolean>>;
1718
}
1819

1920
export interface BuildOptions {
@@ -907,17 +908,16 @@ namespace ts {
907908
}
908909

909910
const buildResult = buildSingleProject(resolved);
910-
// If declaration output changed then only queue in build for downstream projects
911-
if (!(buildResult & BuildResultFlags.DeclarationOutputUnchanged)) {
912-
const dependencyGraph = getGlobalDependencyGraph();
913-
const referencingProjects = dependencyGraph.referencingProjectsMap.getValue(resolved);
914-
if (!referencingProjects) return;
915-
// Always use build order to queue projects
916-
for (const project of dependencyGraph.buildQueue) {
917-
// Can skip circular references
918-
if (referencingProjects.hasKey(project)) {
919-
addProjToQueue(project);
920-
}
911+
const dependencyGraph = getGlobalDependencyGraph();
912+
const referencingProjects = dependencyGraph.referencingProjectsMap.getValue(resolved);
913+
if (!referencingProjects) return;
914+
// Always use build order to queue projects
915+
for (const project of dependencyGraph.buildQueue) {
916+
const prepend = referencingProjects.getValue(project);
917+
// If the project is referenced with prepend, always build downstream projectm,
918+
// otherwise queue it only if declaration output changed
919+
if (prepend || (prepend !== undefined && !(buildResult & BuildResultFlags.DeclarationOutputUnchanged))) {
920+
addProjToQueue(project);
921921
}
922922
}
923923
}
@@ -927,7 +927,7 @@ namespace ts {
927927
const permanentMarks = createFileMap<true>(toPath);
928928
const circularityReportStack: string[] = [];
929929
const buildOrder: ResolvedConfigFileName[] = [];
930-
const referencingProjectsMap = createFileMap<ConfigFileMap<true>>(toPath);
930+
const referencingProjectsMap = createFileMap<ConfigFileMap<boolean>>(toPath);
931931
for (const root of roots) {
932932
visit(root);
933933
}
@@ -958,7 +958,7 @@ namespace ts {
958958
visit(resolvedRefPath, inCircularContext || ref.circular);
959959
// Get projects referencing resolvedRefPath and add projPath to it
960960
const referencingProjects = getOrCreateValueFromConfigFileMap(referencingProjectsMap, resolvedRefPath, () => createFileMap(toPath));
961-
referencingProjects.setValue(projPath, true);
961+
referencingProjects.setValue(projPath, !!ref.prepend);
962962
}
963963
}
964964

src/testRunner/unittests/tsbuildWatchMode.ts

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,81 @@ export class someClass2 { }`);
276276
verifyWatches(host);
277277
});
278278

279+
it("when referenced using prepend, builds referencing project even for non local change", () => {
280+
const coreTsConfig: File = {
281+
path: core[0].path,
282+
content: JSON.stringify({
283+
compilerOptions: { composite: true, declaration: true, outFile: "index.js" }
284+
})
285+
};
286+
const coreIndex: File = {
287+
path: core[1].path,
288+
content: `function foo() { return 10; }`
289+
};
290+
const logicTsConfig: File = {
291+
path: logic[0].path,
292+
content: JSON.stringify({
293+
compilerOptions: { composite: true, declaration: true, outFile: "index.js" },
294+
references: [{ path: "../core", prepend: true }]
295+
})
296+
};
297+
const logicIndex: File = {
298+
path: logic[1].path,
299+
content: `function bar() { return foo() + 1 };`
300+
};
301+
302+
const projectFiles = [coreTsConfig, coreIndex, logicTsConfig, logicIndex];
303+
const host = createWatchedSystem([libFile, ...projectFiles], { currentDirectory: projectsLocation });
304+
createSolutionBuilderWithWatch(host, [`${project}/${SubProject.logic}`]);
305+
verifyWatches();
306+
checkOutputErrorsInitial(host, emptyArray);
307+
const outputFileStamps = getOutputFileStamps();
308+
for (const stamp of outputFileStamps) {
309+
assert.isDefined(stamp[1], `${stamp[0]} expected to be present`);
310+
}
311+
312+
// Make non local change
313+
verifyChangeInCore(`${coreIndex.content}
314+
function myFunc() { return 10; }`);
315+
316+
// Make local change to function bar
317+
verifyChangeInCore(`${coreIndex.content}
318+
function myFunc() { return 100; }`);
319+
320+
function verifyChangeInCore(content: string) {
321+
const outputFileStamps = getOutputFileStamps();
322+
host.writeFile(coreIndex.path, content);
323+
324+
host.checkTimeoutQueueLengthAndRun(1); // Builds core
325+
const changedCore = getOutputFileStamps();
326+
verifyChangedFiles(changedCore, outputFileStamps, [
327+
...getOutputFileNames(SubProject.core, "index")
328+
]);
329+
host.checkTimeoutQueueLengthAndRun(1); // Builds logic
330+
const changedLogic = getOutputFileStamps();
331+
verifyChangedFiles(changedLogic, changedCore, [
332+
...getOutputFileNames(SubProject.logic, "index")
333+
]);
334+
host.checkTimeoutQueueLength(0);
335+
checkOutputErrorsIncremental(host, emptyArray);
336+
verifyWatches();
337+
}
338+
339+
function getOutputFileStamps(): OutputFileStamp[] {
340+
const result = [
341+
...getOutputStamps(host, SubProject.core, "index"),
342+
...getOutputStamps(host, SubProject.logic, "index"),
343+
];
344+
return result;
345+
}
346+
347+
function verifyWatches() {
348+
checkWatchedFiles(host, projectFiles.map(f => f.path));
349+
checkWatchedDirectories(host, emptyArray, /*recursive*/ false);
350+
checkWatchedDirectories(host, [projectPath(SubProject.core), projectPath(SubProject.logic)], /*recursive*/ true);
351+
}
352+
});
353+
279354
// TODO: write tests reporting errors but that will have more involved work since file
280355
});
281356
}

0 commit comments

Comments
 (0)