Skip to content

Commit 27a9888

Browse files
committed
perf: use extension resolutions only for parent typescript files
1 parent 045a5cf commit 27a9888

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/jiti.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,17 @@ export default function createJITI(
175175
for (const ext of _additionalExts) {
176176
resolved =
177177
tryResolve(id + ext, options) ||
178-
// TODO: Only do this for imports within a typescript parent module
179-
tryResolve(id.replace(/\.(c|m)?j(sx?)$/, ".$1t$2"), options) ||
180178
tryResolve(id + "/index" + ext, options);
181179
if (resolved) {
182180
return resolved;
183181
}
182+
// Try resolving .ts files with .js extension
183+
if (parentModule?.filename.endsWith(".ts")) {
184+
resolved = tryResolve(id.replace(/\.(c|m)?j(sx?)$/, ".$1t$2"), options);
185+
if (resolved) {
186+
return resolved;
187+
}
188+
}
184189
}
185190
throw err;
186191
};

0 commit comments

Comments
 (0)