diff --git a/src/options.ts b/src/options.ts index d05a1bc7..8026172c 100644 --- a/src/options.ts +++ b/src/options.ts @@ -16,6 +16,8 @@ export function resolveJitiOptions(userOptions: JitiOptions): JitiOptions { ".cjs", ".ts", ".tsx", + ".mts", + ".cts", ]), alias: _jsonEnv>("JITI_ALIAS", {}), nativeModules: _jsonEnv("JITI_NATIVE_MODULES", []), diff --git a/src/require.ts b/src/require.ts index df3ec3fd..c8836fea 100644 --- a/src/require.ts +++ b/src/require.ts @@ -82,7 +82,13 @@ export function jitiRequire( // Unknown format if (ext && !ctx.opts.extensions!.includes(ext)) { - debug(ctx, "[unknown]", filename); + debug( + ctx, + "[native]", + "[unknown]", + opts.async ? "[import]" : "[require]", + filename, + ); return nativeImportOrRequire(ctx, id, opts.async); } diff --git a/src/resolve.ts b/src/resolve.ts index 9cbbe03e..3c640140 100644 --- a/src/resolve.ts +++ b/src/resolve.ts @@ -56,7 +56,10 @@ export function jitiResolve( return resolved; } // Try resolving .ts files with .js extension - if (TS_EXT_RE.test(ctx.parentModule?.filename || "")) { + if ( + TS_EXT_RE.test(ctx.filename) || + TS_EXT_RE.test(ctx.parentModule?.filename || "") + ) { resolved = tryNativeRequireResolve( ctx, id.replace(JS_EXT_RE, ".$1t$2"), diff --git a/src/utils.ts b/src/utils.ts index 9bb3d0c1..d35ec01a 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -65,6 +65,7 @@ const debugMap = { "[native]": cyan("[native]"), "[transpile]": yellow("[transpile]"), "[fallback]": red("[fallback]"), + "[unknown]": red("[unknown]"), "[hit]": green("[hit]"), "[miss]": yellow("[miss]"), }; diff --git a/test/register-test.mjs b/test/register-test.mjs index 876764be..87844ae2 100644 --- a/test/register-test.mjs +++ b/test/register-test.mjs @@ -9,9 +9,6 @@ const fixturesDir = fileURLToPath(new URL("fixtures", import.meta.url)); const fixtures = await readdir(fixturesDir); for (const fixture of fixtures) { - if (fixture === "typescript") { - continue; // .mts support - } test("fixtures/" + fixture + " (ESM)", async () => { const promise = import(`./fixtures/${fixture}`); const shouldReject =