Skip to content

WIP: allow circular project references #54216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,8 @@ export function createCompilerHostWorker(options: CompilerOptions, setParentNode
realpath,
readDirectory: (path, extensions, include, exclude, depth) => system.readDirectory(path, extensions, include, exclude, depth),
createDirectory: d => system.createDirectory(d),
createHash: maybeBind(system, system.createHash)
createHash: maybeBind(system, system.createHash),
useSourceOfProjectReferenceRedirect: (projectReferences) => projectReferences?.some(x => x.circular) || false,
};
return compilerHost;
}
Expand Down Expand Up @@ -1671,7 +1672,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
let mapFromFileToProjectReferenceRedirects: Map<Path, Path> | undefined;
let mapFromToProjectReferenceRedirectSource: Map<Path, SourceOfProjectReferenceRedirect> | undefined;

const useSourceOfProjectReferenceRedirect = !!host.useSourceOfProjectReferenceRedirect?.() &&
const useSourceOfProjectReferenceRedirect = !!host.useSourceOfProjectReferenceRedirect?.(projectReferences) &&
!options.disableSourceOfProjectReferenceRedirect;
const { onProgramCreateComplete, fileExists, directoryExists } = updateHostForUseSourceOfProjectReferenceRedirect({
compilerHost: host,
Expand Down
3 changes: 3 additions & 0 deletions src/compiler/tsbuildPublic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,9 @@ function createBuildOrder<T extends BuilderProgram>(state: SolutionBuilderState<
const parsed = parseConfigFile(state, configFileName, projPath);
if (parsed && parsed.projectReferences) {
for (const ref of parsed.projectReferences) {
if (ref.circular) {
continue;
}
const resolvedRefPath = resolveProjectName(state, ref.path);
visit(resolvedRefPath, inCircularContext || ref.circular);
}
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7820,7 +7820,7 @@ export interface CompilerHost extends ModuleResolutionHost {
/** @internal */ hasChangedAutomaticTypeDirectiveNames?: HasChangedAutomaticTypeDirectiveNames;
createHash?(data: string): string;
getParsedCommandLine?(fileName: string): ParsedCommandLine | undefined;
/** @internal */ useSourceOfProjectReferenceRedirect?(): boolean;
/** @internal */ useSourceOfProjectReferenceRedirect?(projectReferences: readonly ProjectReference[] | undefined): boolean;

// TODO: later handle this in better way in builder host instead once the api for tsbuild finalizes and doesn't use compilerHost as base
/** @internal */createDirectory?(directory: string): void;
Expand Down
1 change: 1 addition & 0 deletions src/compiler/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,7 @@ export function createCompilerHostFromProgramHost(host: ProgramHost<any>, getCom
createHash: maybeBind(host, host.createHash),
readDirectory: maybeBind(host, host.readDirectory),
storeFilesChangingSignatureDuringEmit: host.storeFilesChangingSignatureDuringEmit,
useSourceOfProjectReferenceRedirect: (projectReferences) => projectReferences?.some(x => x.circular) || false,
};
return compilerHost;
}
Expand Down
20 changes: 20 additions & 0 deletions src/testRunner/unittests/tsbuild/demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,26 @@ describe("unittests:: tsbuild:: on demo project", () => {
]`
)
});

verifyTsc({
scenario: "demo",
subScenario: "in explicit circular branch reports no error",
fs: () => projFs,
commandLineArgs: ["--b", "/src/tsconfig.json", "--verbose"],
modifyFs: fs => replaceText(
fs,
"/src/core/tsconfig.json",
"}",
`},
"references": [
{
"path": "../zoo",
"circular": true
}
]`
)
});

verifyTsc({
scenario: "demo",
subScenario: "in bad-ref branch reports the error about files not in rootDir at the import location",
Expand Down
Loading