Skip to content

Commit c8cdb81

Browse files
committed
Always create dependency graph and build order
1 parent 5029a61 commit c8cdb81

File tree

3 files changed

+15
-56
lines changed

3 files changed

+15
-56
lines changed

src/compiler/diagnosticMessages.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3838,10 +3838,6 @@
38383838
"category": "Error",
38393839
"code": 6370
38403840
},
3841-
"Skipping clean because not all projects could be located": {
3842-
"category": "Error",
3843-
"code": 6371
3844-
},
38453841

38463842
"The expected type comes from property '{0}' which is declared here on type '{1}'": {
38473843
"category": "Message",

src/compiler/tsbuild.ts

Lines changed: 15 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ namespace ts {
341341

342342
/*@internal*/ resolveProjectName(name: string): ResolvedConfigFileName;
343343
/*@internal*/ getUpToDateStatusOfFile(configFileName: ResolvedConfigFileName): UpToDateStatus;
344-
/*@internal*/ getBuildGraph(configFileNames: ReadonlyArray<string>): DependencyGraph | undefined;
344+
/*@internal*/ getBuildGraph(configFileNames: ReadonlyArray<string>): DependencyGraph;
345345

346346
/*@internal*/ invalidateProject(configFileName: string, reloadLevel?: ConfigFileProgramReloadLevel): void;
347347
/*@internal*/ buildInvalidatedProject(): void;
@@ -404,7 +404,7 @@ namespace ts {
404404
/** Map from config file name to up-to-date status */
405405
const projectStatus = createFileMap<UpToDateStatus>(toPath);
406406
const missingRoots = createMap<true>();
407-
let globalDependencyGraph: DependencyGraph | false | undefined;
407+
let globalDependencyGraph: DependencyGraph | undefined;
408408

409409
// Watch state
410410
// TODO(shkamat): this should be really be diagnostics but thats for later time
@@ -504,12 +504,7 @@ namespace ts {
504504
}
505505

506506
function startWatching() {
507-
const graph = getGlobalDependencyGraph()!;
508-
if (!graph.buildQueue) {
509-
// Everything is broken - we don't even know what to watch. Give up.
510-
return;
511-
}
512-
507+
const graph = getGlobalDependencyGraph();
513508
for (const resolved of graph.buildQueue) {
514509
const cfg = parseConfigFile(resolved);
515510
if (cfg) {
@@ -627,10 +622,7 @@ namespace ts {
627622
}
628623

629624
function getGlobalDependencyGraph() {
630-
if (globalDependencyGraph === undefined) {
631-
globalDependencyGraph = getBuildGraph(rootNames) || false;
632-
}
633-
return globalDependencyGraph || undefined;
625+
return globalDependencyGraph || (globalDependencyGraph = getBuildGraph(rootNames));
634626
}
635627

636628
function getUpToDateStatus(project: ParsedCommandLine | undefined): UpToDateStatus {
@@ -826,10 +818,7 @@ namespace ts {
826818

827819
if (addProjToQueue(resolved, reloadLevel)) {
828820
// TODO: instead of adding the dependent project to queue right away postpone this
829-
const dependencyGraph = getGlobalDependencyGraph();
830-
if (dependencyGraph) {
831-
queueBuildForDownstreamReferences(resolved, dependencyGraph);
832-
}
821+
queueBuildForDownstreamReferences(resolved, getGlobalDependencyGraph());
833822
}
834823
}
835824

@@ -950,49 +939,36 @@ namespace ts {
950939
buildSingleProject(resolved);
951940
}
952941

953-
function createDependencyGraph(roots: ResolvedConfigFileName[]): DependencyGraph | undefined {
954-
const temporaryMarks: { [path: string]: true } = {};
955-
const permanentMarks: { [path: string]: true } = {};
942+
function createDependencyGraph(roots: ResolvedConfigFileName[]): DependencyGraph {
943+
const temporaryMarks = createFileMap<true>(toPath);
944+
const permanentMarks = createFileMap<true>(toPath);
956945
const circularityReportStack: string[] = [];
957946
const buildOrder: ResolvedConfigFileName[] = [];
958947
const graph = createDependencyMapper(toPath);
959-
960-
let hadError = false;
961-
962948
for (const root of roots) {
963949
visit(root);
964950
}
965951

966-
if (hadError) {
967-
return undefined;
968-
}
969-
970952
return {
971953
buildQueue: buildOrder,
972-
dependencyMap: graph
954+
dependencyMap: graph,
973955
};
974956

975957
function visit(projPath: ResolvedConfigFileName, inCircularContext = false) {
976958
// Already visited
977-
if (permanentMarks[projPath]) return;
959+
if (permanentMarks.hasKey(projPath)) return;
978960
// Circular
979-
if (temporaryMarks[projPath]) {
961+
if (temporaryMarks.hasKey(projPath)) {
980962
if (!inCircularContext) {
981-
hadError = true;
982-
// TODO(shkamat): Account for this error
983963
reportStatus(Diagnostics.Project_references_may_not_form_a_circular_graph_Cycle_detected_Colon_0, circularityReportStack.join("\r\n"));
984964
return;
985965
}
986966
}
987967

988-
temporaryMarks[projPath] = true;
968+
temporaryMarks.setValue(projPath, true);
989969
circularityReportStack.push(projPath);
990970
const parsed = parseConfigFile(projPath);
991-
if (parsed === undefined) {
992-
hadError = true;
993-
return;
994-
}
995-
if (parsed.projectReferences) {
971+
if (parsed && parsed.projectReferences) {
996972
for (const ref of parsed.projectReferences) {
997973
const resolvedRefPath = resolveProjectName(ref.path);
998974
visit(resolvedRefPath, inCircularContext || ref.circular);
@@ -1001,7 +977,7 @@ namespace ts {
1001977
}
1002978

1003979
circularityReportStack.pop();
1004-
permanentMarks[projPath] = true;
980+
permanentMarks.setValue(projPath, true);
1005981
buildOrder.push(projPath);
1006982
}
1007983
}
@@ -1135,11 +1111,9 @@ namespace ts {
11351111
projectStatus.setValue(proj.options.configFilePath as ResolvedConfigFilePath, { type: UpToDateStatusType.UpToDate, newestDeclarationFileContentChangedTime: priorNewestUpdateTime } as UpToDateStatus);
11361112
}
11371113

1138-
function getFilesToClean(): string[] | undefined {
1114+
function getFilesToClean(): string[] {
11391115
// Get the same graph for cleaning we'd use for building
11401116
const graph = getGlobalDependencyGraph();
1141-
if (graph === undefined) return undefined;
1142-
11431117
const filesToDelete: string[] = [];
11441118
for (const proj of graph.buildQueue) {
11451119
const parsed = parseConfigFile(proj);
@@ -1159,11 +1133,6 @@ namespace ts {
11591133

11601134
function cleanAllProjects() {
11611135
const filesToDelete = getFilesToClean();
1162-
if (filesToDelete === undefined) {
1163-
reportStatus(Diagnostics.Skipping_clean_because_not_all_projects_could_be_located);
1164-
return ExitStatus.DiagnosticsPresent_OutputsSkipped;
1165-
}
1166-
11671136
if (options.dry) {
11681137
reportStatus(Diagnostics.A_non_dry_build_would_delete_the_following_files_Colon_0, filesToDelete.map(f => `\r\n * ${f}`).join(""));
11691138
return ExitStatus.Success;
@@ -1187,11 +1156,6 @@ namespace ts {
11871156
function buildAllProjects(): ExitStatus {
11881157
if (options.watch) { reportWatchStatus(Diagnostics.Starting_compilation_in_watch_mode); }
11891158
const graph = getGlobalDependencyGraph();
1190-
if (graph === undefined) {
1191-
reportErrorSummary();
1192-
return ExitStatus.DiagnosticsPresent_OutputsSkipped;
1193-
}
1194-
11951159
const queue = graph.buildQueue;
11961160
reportBuildQueue(graph);
11971161
let anyFailed = false;

src/testRunner/unittests/tsbuild.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,6 @@ namespace ts {
377377

378378
const projFileNames = rootNames.map(getProjectFileName);
379379
const graph = builder.getBuildGraph(projFileNames);
380-
if (graph === undefined) throw new Error("Graph shouldn't be undefined");
381380

382381
assert.sameMembers(graph.buildQueue, expectedBuildSet.map(getProjectFileName));
383382

0 commit comments

Comments
 (0)