Skip to content

Commit 2c24678

Browse files
committedJul 9, 2024
Set moduleResolution: bundler if not set and don't share it (resolves #719)
1 parent 3201c07 commit 2c24678

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed
 

‎packages/knip/src/PrincipalFactory.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type ts from 'typescript';
1+
import ts from 'typescript';
22
import { ProjectPrincipal } from './ProjectPrincipal.js';
33
import type { AsyncCompilers, SyncCompilers } from './compilers/types.js';
44
import { debugLog } from './util/debug.js';
@@ -64,6 +64,7 @@ export class PrincipalFactory {
6464
const workspacePaths = compilerOptions?.paths ? Object.keys(compilerOptions.paths) : [];
6565
const principal = Array.from(this.principals).find(principal => {
6666
if (compilerOptions.pathsBasePath && principal.principal.compilerOptions.pathsBasePath) return false;
67+
if (compilerOptions.moduleResolution !== principal.principal.compilerOptions.moduleResolution) return false;
6768
if (compilerOptions.baseUrl === principal.principal.compilerOptions.baseUrl) {
6869
return workspacePaths.every(p => !principal.pathKeys.has(p));
6970
}
@@ -81,6 +82,7 @@ export class PrincipalFactory {
8182
) {
8283
const { pathsBasePath, paths } = compilerOptions;
8384
if (pathsBasePath) principal.principal.compilerOptions.pathsBasePath = pathsBasePath;
85+
principal.principal.compilerOptions.moduleResolution ??= ts.ModuleResolutionKind.Bundler;
8486
for (const p of Object.keys(paths ?? {})) principal.pathKeys.add(p);
8587
principal.principal.addPaths(paths);
8688
principal.principal.addCompilers(compilers);

0 commit comments

Comments
 (0)
Please sign in to comment.