Skip to content

Commit

Permalink
feat: allow resolving .ts files with .js extension (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
Akryum authored Mar 15, 2023
1 parent a9aa709 commit 045a5cf
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
5 changes: 2 additions & 3 deletions src/jiti.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,6 @@ export default function createJITI(
}

// Try native require resolve
if ((opts.extensions as string[]).includes(extname(id))) {
return nativeRequire.resolve(id, options);
}
try {
return nativeRequire.resolve(id, options);
} catch (error) {
Expand All @@ -178,6 +175,8 @@ export default function createJITI(
for (const ext of _additionalExts) {
resolved =
tryResolve(id + ext, options) ||
// TODO: Only do this for imports within a typescript parent module
tryResolve(id.replace(/\.(c|m)?j(sx?)$/, ".$1t$2"), options) ||
tryResolve(id + "/index" + ext, options);
if (resolved) {
return resolved;
Expand Down
2 changes: 1 addition & 1 deletion test/__snapshots__/fixtures.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Vitest Snapshot v1
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`fixtures > async > stdout 1`] = `"works"`;

Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/typescript/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import test, { FeedService } from "./test";
import Clazz from "./decorators";
import { test as satisfiesTest } from "./satisfies";
import { test as satisfiesTest } from "./satisfies.js";

export type { Test } from "./types";

Expand Down

0 comments on commit 045a5cf

Please sign in to comment.