Skip to content

Commit 0781279

Browse files
committed
Add resolution branding
1 parent 8a883ae commit 0781279

1 file changed

Lines changed: 26 additions & 22 deletions

File tree

src/compiler/tsbuild.ts

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
namespace ts {
2+
type ResolvedConfigFileName = string & { _isResolvedConfigFileName: never };
3+
24
const minimumDate = new Date(-8640000000000000);
35
const maximumDate = new Date(8640000000000000);
46

@@ -24,7 +26,7 @@ namespace ts {
2426

2527
type Mapper = ReturnType<typeof createDependencyMapper>;
2628
interface DependencyGraph {
27-
buildQueue: string[][];
29+
buildQueue: ResolvedConfigFileName[][];
2830
dependencyMap: Mapper;
2931
}
3032

@@ -296,7 +298,7 @@ namespace ts {
296298

297299
// TODO: Cache invalidation under --watch
298300

299-
function parseConfigFile(configFilePath: string) {
301+
function parseConfigFile(configFilePath: ResolvedConfigFileName) {
300302
const sourceFile = host.getSourceFile(configFilePath, ScriptTarget.JSON) as JsonSourceFile;
301303
if (sourceFile === undefined) {
302304
return undefined;
@@ -401,7 +403,7 @@ namespace ts {
401403
context = createBuildContext(options, reportDiagnostic);
402404
}
403405

404-
function getUpToDateStatusOfFile(configFileName: string): UpToDateStatus {
406+
function getUpToDateStatusOfFile(configFileName: ResolvedConfigFileName): UpToDateStatus {
405407
return getUpToDateStatus(configFileCache.parseConfigFile(configFileName));
406408
}
407409

@@ -500,7 +502,7 @@ namespace ts {
500502
// See if any of its upstream projects are newer than it
501503
if (project.projectReferences) {
502504
for (const ref of project.projectReferences) {
503-
const resolvedRef = resolveProjectReferencePath(host, ref);
505+
const resolvedRef = resolveProjectReferencePath(host, ref) as ResolvedConfigFileName;
504506
const refStatus = getUpToDateStatus(configFileCache.parseConfigFile(resolvedRef));
505507

506508
// If the upstream project is out of date, then so are we (someone shouldn't have asked, though?)
@@ -544,14 +546,14 @@ namespace ts {
544546
}
545547

546548
// TODO: Use the better algorithm
547-
function createDependencyGraph(roots: string[]): DependencyGraph {
549+
function createDependencyGraph(roots: ResolvedConfigFileName[]): DependencyGraph {
548550
// This is a list of list of projects that need to be built.
549551
// The ordering here is "backwards", i.e. the first entry in the array is the last set of projects that need to be built;
550552
// and the last entry is the first set of projects to be built.
551553
// Each subarray is effectively unordered.
552554
// We traverse the reference graph from each root, then "clean" the list by removing
553555
// any entry that is duplicated to its right.
554-
const buildQueue: string[][] = [];
556+
const buildQueue: ResolvedConfigFileName[][] = [];
555557
const dependencyMap = createDependencyMapper();
556558
let buildQueuePosition = 0;
557559
for (const root of roots) {
@@ -560,7 +562,7 @@ namespace ts {
560562
reportDiagnostic(createCompilerDiagnostic(Diagnostics.File_0_does_not_exist, root));
561563
continue;
562564
}
563-
enumerateReferences(normalizePath(root), config);
565+
enumerateReferences(normalizePath(root) as ResolvedConfigFileName, config);
564566
}
565567
removeDuplicatesFromBuildQueue(buildQueue);
566568

@@ -569,7 +571,7 @@ namespace ts {
569571
dependencyMap
570572
};
571573

572-
function enumerateReferences(fileName: string, root: ParsedCommandLine): void {
574+
function enumerateReferences(fileName: ResolvedConfigFileName, root: ParsedCommandLine): void {
573575
const myBuildLevel = buildQueue[buildQueuePosition] = buildQueue[buildQueuePosition] || [];
574576
if (myBuildLevel.indexOf(fileName) < 0) {
575577
myBuildLevel.push(fileName);
@@ -579,11 +581,11 @@ namespace ts {
579581
if (refs === undefined) return;
580582
buildQueuePosition++;
581583
for (const ref of refs) {
582-
const actualPath = resolveProjectReferencePath(host, ref);
584+
const actualPath = resolveProjectReferencePath(host, ref) as ResolvedConfigFileName;
583585
dependencyMap.addReference(fileName, actualPath);
584586
const resolvedRef = configFileCache.parseConfigFile(actualPath);
585587
if (resolvedRef === undefined) continue;
586-
enumerateReferences(normalizePath(actualPath), resolvedRef);
588+
enumerateReferences(normalizePath(actualPath) as ResolvedConfigFileName, resolvedRef);
587589
}
588590
buildQueuePosition--;
589591
}
@@ -607,7 +609,7 @@ namespace ts {
607609
}
608610

609611
// TODO Accept parsedCommandLine instead?
610-
function buildSingleProject(proj: string) {
612+
function buildSingleProject(proj: ResolvedConfigFileName) {
611613
if (context.options.dry) {
612614
reportDiagnostic(createCompilerDiagnostic(Diagnostics.Would_build_project_0, proj));
613615
return;
@@ -713,8 +715,8 @@ namespace ts {
713715
context.projectStatus.setValue(proj.options.configFilePath, { type: UpToDateStatusType.UpToDate, newestDeclarationFileContentChangedTime: priorNewestUpdateTime } as UpToDateStatus);
714716
}
715717

716-
function getFilesToClean(configFileNames: string[]): string[] | undefined {
717-
const resolvedNames: string[] | undefined = resolveProjectNames(configFileNames);
718+
function getFilesToClean(configFileNames: ResolvedConfigFileName[]): string[] | undefined {
719+
const resolvedNames: ResolvedConfigFileName[] | undefined = resolveProjectNames(configFileNames);
718720
if (resolvedNames === undefined) return;
719721

720722
// Get the same graph for cleaning we'd use for building
@@ -736,7 +738,10 @@ namespace ts {
736738
}
737739

738740
function cleanProjects(configFileNames: string[]) {
739-
const filesToDelete = getFilesToClean(configFileNames);
741+
const resolvedNames: ResolvedConfigFileName[] | undefined = resolveProjectNames(configFileNames);
742+
if (resolvedNames === undefined) return;
743+
744+
const filesToDelete = getFilesToClean(resolvedNames);
740745

741746
if (context.options.dry) {
742747
reportDiagnostic(createCompilerDiagnostic(Diagnostics.Would_delete_the_following_files_Colon_0, filesToDelete.map(f => `\r\n * ${f}`).join("")));
@@ -752,18 +757,17 @@ namespace ts {
752757
}
753758
}
754759

755-
// TODO add branding to resolved filenames
756-
function resolveProjectNames(configFileNames: string[]): string[] | undefined {
757-
const resolvedNames: string[] = [];
760+
function resolveProjectNames(configFileNames: string[]): ResolvedConfigFileName[] | undefined {
761+
const resolvedNames: ResolvedConfigFileName[] = [];
758762
for (const name of configFileNames) {
759763
let fullPath = resolvePath(host.getCurrentDirectory(), name);
760764
if (host.fileExists(fullPath)) {
761-
resolvedNames.push(fullPath);
765+
resolvedNames.push(fullPath as ResolvedConfigFileName);
762766
continue;
763767
}
764768
fullPath = combinePaths(fullPath, "tsconfig.json");
765769
if (host.fileExists(fullPath)) {
766-
resolvedNames.push(fullPath);
770+
resolvedNames.push(fullPath as ResolvedConfigFileName);
767771
continue;
768772
}
769773
reportDiagnostic(createCompilerDiagnostic(Diagnostics.File_0_not_found, fullPath));
@@ -773,7 +777,7 @@ namespace ts {
773777
}
774778

775779
function buildProjects(configFileNames: string[]) {
776-
const resolvedNames: string[] | undefined = resolveProjectNames(configFileNames);
780+
const resolvedNames: ResolvedConfigFileName[] | undefined = resolveProjectNames(configFileNames);
777781
if (resolvedNames === undefined) return;
778782

779783
// Establish what needs to be built
@@ -782,7 +786,7 @@ namespace ts {
782786
const queue = graph.buildQueue;
783787
reportBuildQueue(graph);
784788

785-
let next: string;
789+
let next: ResolvedConfigFileName;
786790
while (next = getNext()) {
787791
const proj = configFileCache.parseConfigFile(next);
788792
const status = getUpToDateStatus(proj);
@@ -809,7 +813,7 @@ namespace ts {
809813
}
810814
}
811815

812-
function getNext(): string | undefined {
816+
function getNext(): ResolvedConfigFileName | undefined {
813817
if (queue.length === 0) {
814818
return undefined;
815819
}

0 commit comments

Comments
 (0)