forked from oddsdk/causal-islands-workshop-2023
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtsnode-loader.js
26 lines (22 loc) · 814 Bytes
/
tsnode-loader.js
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
/** Load ESM modules with path mappings
* ts-node/esm does not currently support path mappings. This custom
* loader takes care of that. Tracking discussion and loader source code
* from https://github.com/TypeStrong/ts-node/discussions/1450
*/
import {
resolve as resolveTs,
getFormat,
load,
transformSource,
} from "ts-node/esm";
import * as tsConfigPaths from "tsconfig-paths"
export { getFormat, load, transformSource };
const { absoluteBaseUrl, paths } = tsConfigPaths.loadConfig()
const matchPath = tsConfigPaths.createMatchPath(absoluteBaseUrl, paths)
export function resolve(specifier, context, defaultResolver) {
const mappedSpecifier = matchPath(specifier)
if (mappedSpecifier) {
specifier = `${mappedSpecifier}.js`
}
return resolveTs(specifier, context, defaultResolver);
}