Skip to content

Commit

Permalink
feat: support TS directory imports for ESM (#422)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley committed May 20, 2022
1 parent 60164f9 commit 4c58e78
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/module-loader.ts
Expand Up @@ -13,7 +13,7 @@ const getPackageType = require('get-package-type')
* Defines file extension resolution when source files do not have an extension.
*/
// eslint-disable-next-line camelcase
const s_EXTENSIONS: string[] = ['.js', '.mjs', '.cjs']
const s_EXTENSIONS: string[] = ['.ts', '.js', '.mjs', '.cjs']

/**
* Provides a mechanism to use dynamic import / import() with tsconfig -> module: commonJS as otherwise import() gets
Expand Down Expand Up @@ -110,6 +110,9 @@ export default class ModuleLoader {
case '.js':
return getPackageType.sync(filePath) === 'module'

case '.ts':
return getPackageType.sync(filePath) === 'module'

case '.mjs':
return true

Expand Down Expand Up @@ -155,7 +158,7 @@ export default class ModuleLoader {
// Try all supported extensions.
let foundPath = ModuleLoader.findFile(filePath)
if (!foundPath && isDirectory) {
// Since filePath is a directory, try looking for index.js file.
// Since filePath is a directory, try looking for index file.
foundPath = ModuleLoader.findFile(path.join(filePath, 'index'))
}

Expand Down

0 comments on commit 4c58e78

Please sign in to comment.