From 4c58e782e86dd7ecf91294bac0d2c759b4454596 Mon Sep 17 00:00:00 2001 From: Mike Donnalley Date: Fri, 20 May 2022 10:16:12 -0700 Subject: [PATCH] feat: support TS directory imports for ESM (#422) --- src/module-loader.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/module-loader.ts b/src/module-loader.ts index 9182c9a09..07a23c99b 100644 --- a/src/module-loader.ts +++ b/src/module-loader.ts @@ -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 @@ -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 @@ -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')) }