Skip to content

Commit f4923a4

Browse files
committed
allow circular project references
1 parent 72037a9 commit f4923a4

File tree

6 files changed

+587
-3
lines changed

6 files changed

+587
-3
lines changed

src/compiler/program.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,8 @@ export function createCompilerHostWorker(options: CompilerOptions, setParentNode
500500
realpath,
501501
readDirectory: (path, extensions, include, exclude, depth) => system.readDirectory(path, extensions, include, exclude, depth),
502502
createDirectory: d => system.createDirectory(d),
503-
createHash: maybeBind(system, system.createHash)
503+
createHash: maybeBind(system, system.createHash),
504+
useSourceOfProjectReferenceRedirect: (projectReferences) => projectReferences?.some(x => x.circular) || false,
504505
};
505506
return compilerHost;
506507
}
@@ -1671,7 +1672,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
16711672
let mapFromFileToProjectReferenceRedirects: Map<Path, Path> | undefined;
16721673
let mapFromToProjectReferenceRedirectSource: Map<Path, SourceOfProjectReferenceRedirect> | undefined;
16731674

1674-
const useSourceOfProjectReferenceRedirect = !!host.useSourceOfProjectReferenceRedirect?.() &&
1675+
const useSourceOfProjectReferenceRedirect = !!host.useSourceOfProjectReferenceRedirect?.(projectReferences) &&
16751676
!options.disableSourceOfProjectReferenceRedirect;
16761677
const { onProgramCreateComplete, fileExists, directoryExists } = updateHostForUseSourceOfProjectReferenceRedirect({
16771678
compilerHost: host,

src/compiler/tsbuildPublic.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,9 @@ function createBuildOrder<T extends BuilderProgram>(state: SolutionBuilderState<
631631
const parsed = parseConfigFile(state, configFileName, projPath);
632632
if (parsed && parsed.projectReferences) {
633633
for (const ref of parsed.projectReferences) {
634+
if (ref.circular) {
635+
continue;
636+
}
634637
const resolvedRefPath = resolveProjectName(state, ref.path);
635638
visit(resolvedRefPath, inCircularContext || ref.circular);
636639
}

src/compiler/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7820,7 +7820,7 @@ export interface CompilerHost extends ModuleResolutionHost {
78207820
/** @internal */ hasChangedAutomaticTypeDirectiveNames?: HasChangedAutomaticTypeDirectiveNames;
78217821
createHash?(data: string): string;
78227822
getParsedCommandLine?(fileName: string): ParsedCommandLine | undefined;
7823-
/** @internal */ useSourceOfProjectReferenceRedirect?(): boolean;
7823+
/** @internal */ useSourceOfProjectReferenceRedirect?(projectReferences: readonly ProjectReference[] | undefined): boolean;
78247824

78257825
// TODO: later handle this in better way in builder host instead once the api for tsbuild finalizes and doesn't use compilerHost as base
78267826
/** @internal */createDirectory?(directory: string): void;

src/compiler/watch.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,7 @@ export function createCompilerHostFromProgramHost(host: ProgramHost<any>, getCom
767767
createHash: maybeBind(host, host.createHash),
768768
readDirectory: maybeBind(host, host.readDirectory),
769769
storeFilesChangingSignatureDuringEmit: host.storeFilesChangingSignatureDuringEmit,
770+
useSourceOfProjectReferenceRedirect: (projectReferences) => projectReferences?.some(x => x.circular) || false,
770771
};
771772
return compilerHost;
772773
}

src/testRunner/unittests/tsbuild/demo.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,26 @@ describe("unittests:: tsbuild:: on demo project", () => {
4242
]`
4343
)
4444
});
45+
46+
verifyTsc({
47+
scenario: "demo",
48+
subScenario: "in explicit circular branch reports no error",
49+
fs: () => projFs,
50+
commandLineArgs: ["--b", "/src/tsconfig.json", "--verbose"],
51+
modifyFs: fs => replaceText(
52+
fs,
53+
"/src/core/tsconfig.json",
54+
"}",
55+
`},
56+
"references": [
57+
{
58+
"path": "../zoo",
59+
"circular": true
60+
}
61+
]`
62+
)
63+
});
64+
4565
verifyTsc({
4666
scenario: "demo",
4767
subScenario: "in bad-ref branch reports the error about files not in rootDir at the import location",

0 commit comments

Comments
 (0)