(ts) apply tsconfig-path rewrites to scripts as well, server/calendar.ts was affected

see https://stackoverflow.com/questions/71571684/ts-node-with-tsconfig-paths-wont-work-when-using-esm
This commit is contained in:
Valentyne Stigloher 2024-06-23 00:30:01 +02:00
parent 8bdc4438c1
commit 1ccca9bd98
2 changed files with 16 additions and 1 deletions

15
server/load.js Normal file
View File

@ -0,0 +1,15 @@
import { resolve as resolveTs } from 'ts-node/esm.mjs';
import { loadConfig, createMatchPath } from 'tsconfig-paths';
import { pathToFileURL } from 'url';
const { absoluteBaseUrl, paths } = loadConfig();
const matchPath = createMatchPath(absoluteBaseUrl, paths);
export async function resolve(specifier, ctx, defaultResolve) {
const match = matchPath(specifier);
return match
? resolveTs(pathToFileURL(`${match}`).href, ctx, defaultResolve)
: resolveTs(specifier, ctx, defaultResolve);
}
export { load, transformSource } from 'ts-node/esm.mjs';

View File

@ -1,4 +1,4 @@
import { register } from 'node:module';
import { pathToFileURL } from 'node:url';
register('ts-node/esm', pathToFileURL('./'));
register('./server/load.js', pathToFileURL('./'));