Skip to content

Commit c9b3770

Browse files
committedNov 11, 2023
Make compilerOptions.paths (and configured paths) absolute if no baseUrl
1 parent 465d170 commit c9b3770

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed
 

‎src/PrincipalFactory.ts

+12-6
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,19 @@ export type PrincipalOptions = {
1818
isGitIgnored: GlobbyFilterFunction;
1919
};
2020

21+
const mapToAbsolutePaths = (paths: NonNullable<Paths>, cwd: string): Paths =>
22+
Object.keys(paths).reduce((result, key) => {
23+
result[key] = paths[key].map(entry => toAbsolute(entry, cwd));
24+
return result;
25+
}, {} as NonNullable<Paths>);
26+
2127
const mergePaths = (cwd: string, compilerOptions: ts.CompilerOptions, paths: Paths = {}) => {
22-
const overridePaths = Object.keys(paths).reduce((overridePaths, key) => {
23-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
24-
overridePaths![key] = paths[key].map(entry => toAbsolute(entry, cwd));
25-
return overridePaths;
26-
}, {} as Paths);
27-
compilerOptions.paths = { ...compilerOptions.paths, ...overridePaths };
28+
const compilerPaths =
29+
!compilerOptions.baseUrl && compilerOptions.paths
30+
? mapToAbsolutePaths(compilerOptions.paths, cwd)
31+
: compilerOptions.paths;
32+
const extraPaths = mapToAbsolutePaths(paths, cwd);
33+
compilerOptions.paths = { ...compilerPaths, ...extraPaths };
2834
return compilerOptions;
2935
};
3036

0 commit comments

Comments
 (0)
Please sign in to comment.