forked from remix-run/remix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
33 lines (27 loc) · 1.08 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import tsConfigPaths from "tsconfig-paths";
import { writeConfigDefaults } from "./write-config-defaults";
export function createMatchPath(tsconfigPath: string | undefined) {
// There is no tsconfig to match paths against.
if (!tsconfigPath) {
return undefined;
}
// When passing a absolute path, loadConfig assumes that the path contains
// a tsconfig file.
// Ref.: https://github.com/dividab/tsconfig-paths/blob/v4.0.0/src/__tests__/config-loader.test.ts#L74
let configLoaderResult = tsConfigPaths.loadConfig(tsconfigPath);
if (configLoaderResult.resultType === "failed") {
if (configLoaderResult.message === "Missing baseUrl in compilerOptions") {
throw new Error(
`🚨 Oops! No baseUrl found, please set compilerOptions.baseUrl in your tsconfig or jsconfig`
);
}
return undefined;
}
writeConfigDefaults(configLoaderResult.configFileAbsolutePath);
return tsConfigPaths.createMatchPath(
configLoaderResult.absoluteBaseUrl,
configLoaderResult.paths,
configLoaderResult.mainFields,
configLoaderResult.addMatchAll
);
}