Skip to content

Commit

Permalink
fix: resolve with index.{ts,mjs}
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Jan 12, 2021
1 parent a72e0f4 commit 2fe1846
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/jiti.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { existsSync, readFileSync, writeFileSync } from 'fs'
import { Module, builtinModules } from 'module'
import { dirname, join, basename } from 'path'
import { dirname, join, basename, extname } from 'path'
import { tmpdir } from 'os'
import { createHash } from 'crypto'
import vm from 'vm'
Expand Down Expand Up @@ -76,7 +76,15 @@ export default function createJITI (_filename: string = process.cwd(), opts: JIT
}

const _resolve = (id: string, options?: { paths?: string[] }) => {
return tryResolve(id + '.ts', options) || tryResolve(id + '.mjs', options) || nativeRequire.resolve(id, options)
if (['.js', '.ts', '.mjs'].includes(extname(id))) {
return nativeRequire.resolve(id, options)
}
return tryResolve(id, options) ||
tryResolve(id + '.ts', options) ||
tryResolve(id + '/index.ts', options) ||
tryResolve(id + '.mjs', options) ||
tryResolve(id + '/index.mjs', options) ||
nativeRequire.resolve(id, options)
}
_resolve.paths = nativeRequire.resolve.paths

Expand Down

0 comments on commit 2fe1846

Please sign in to comment.