diff --git a/index.js b/index.js index 9959fd9..1850e56 100644 --- a/index.js +++ b/index.js @@ -252,8 +252,9 @@ function tsLookup({ dependency, filename, tsConfig, tsConfigPath, noTypeDefiniti const absoluteBaseUrl = path.join(path.dirname(tsConfigPath), compilerOptions.baseUrl) // REF: https://github.com/dividab/tsconfig-paths#creatematchpath const tsMatchPath = createMatchPath(absoluteBaseUrl, compilerOptions.paths) + const extensions = ['.ts', '.tsx', '.d.ts', '.js', '.jsx', '.json', '.node'] // REF: https://github.com/dividab/tsconfig-paths#creatematchpath - const resolvedTsAliasPath = tsMatchPath(dependency) // Get absolute path by ts path mapping. `undefined` if non-existent + const resolvedTsAliasPath = tsMatchPath(dependency, undefined, undefined, extensions) // Get absolute path by ts path mapping. `undefined` if non-existent if (resolvedTsAliasPath) { const stat = (() => { try { @@ -266,8 +267,8 @@ function tsLookup({ dependency, filename, tsConfig, tsConfigPath, noTypeDefiniti if (stat) { if (stat.isDirectory()) { // When directory is imported, index file is resolved - for (const indexFile of ['index.ts', 'index.tsx', 'index.js', 'index.jsx']) { - const filename = path.join(resolvedTsAliasPath, indexFile) + for (const ext of extensions) { + const filename = path.join(resolvedTsAliasPath, 'index' + ext) if (fs.existsSync(filename)) { result = filename break; @@ -279,7 +280,7 @@ function tsLookup({ dependency, filename, tsConfig, tsConfigPath, noTypeDefiniti } } else { // For cases a file extension is omitted when being imported - for (const ext of ['.ts', '.tsx', '.js', '.jsx']) { + for (const ext of extensions) { const filenameWithExt = resolvedTsAliasPath + ext if (fs.existsSync(filenameWithExt)) { result = filenameWithExt