Skip to content

Commit

Permalink
feat: Prioritize .ts extensions in Cjs too
Browse files Browse the repository at this point in the history
  • Loading branch information
Septh committed Sep 26, 2024
1 parent 475778b commit dee5fb3
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions source/cjs-hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,12 @@ export function install_cjs_hooks(defaultType: NodeJS.ModuleType) {
const { _resolveFilename } = Module
Module._resolveFilename = function _resolveFilenamePatch(request, ...otherArgs) {
try {
return _resolveFilename.call(undefined, request, ...otherArgs)
// Let's try first with the .ts extension...
return _resolveFilename.call(Module, request.replace(jsExtRx, '.$1ts'), ...otherArgs)
}
catch {
return _resolveFilename.call(undefined, request.replace(jsExtRx, '.$1ts'), ...otherArgs)
// Otherwise, go as-is.
return _resolveFilename.call(Module, request, ...otherArgs)
}
}

Expand Down

0 comments on commit dee5fb3

Please sign in to comment.