Skip to content

Commit

Permalink
perf: use extension resolutions only for parent typescript files
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Mar 15, 2023
1 parent 045a5cf commit 27a9888
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/jiti.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,17 @@ 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;
}
// Try resolving .ts files with .js extension
if (parentModule?.filename.endsWith(".ts")) {

This comment has been minimized.

Copy link
@Akryum

Akryum Mar 15, 2023

Contributor

Would this work for .cts and .mts files?

This comment has been minimized.

Copy link
@pi0

pi0 Mar 15, 2023

Author Member

Good point! Will add a hotfix on top + fixture update.

resolved = tryResolve(id.replace(/\.(c|m)?j(sx?)$/, ".$1t$2"), options);
if (resolved) {
return resolved;
}
}
}
throw err;
};
Expand Down

0 comments on commit 27a9888

Please sign in to comment.