Skip to content

Commit

Permalink
fix(tsLookup): extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
jjangga0214 committed Aug 20, 2021
1 parent c443ca3 commit a6740c2
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand All @@ -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
Expand Down

0 comments on commit a6740c2

Please sign in to comment.