Skip to content

Commit b11ede3

Browse files
committed
feat: resolve .ts/.tsx/.d.ts first, and then fallback to @types/*
1 parent 18eafa2 commit b11ede3

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

index.js

+18-6
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,9 @@ function resolveFile(source, file, config) {
2525
}
2626

2727
let foundTsPath = null;
28-
const extensions = Object.keys(require.extensions).concat(
29-
'.ts',
30-
'.tsx',
31-
'.d.ts',
32-
);
28+
const extensions = Object.keys(require.extensions);
29+
30+
extensions.unshift('.ts', '.tsx', '.d.ts');
3331

3432
// setup tsconfig-paths
3533
const searchStart = config.directory || process.cwd();
@@ -64,6 +62,20 @@ function resolveFile(source, file, config) {
6462
foundNodePath = null;
6563
}
6664

65+
// naive attempt at @types/* resolution,
66+
// iff path is neither absolute nor relative
67+
if (
68+
/\.jsx?$/.test(foundNodePath) &&
69+
!/^@types[\/\\]/.test(source) &&
70+
!path.isAbsolute(source) &&
71+
source[0] !== '.'
72+
) {
73+
const definitely = resolveFile('@types/' + source, file, config);
74+
if (definitely.found) {
75+
return definitely;
76+
}
77+
}
78+
6779
if (foundNodePath) {
6880
log('matched node path:', foundNodePath);
6981

@@ -73,7 +85,7 @@ function resolveFile(source, file, config) {
7385
};
7486
}
7587

76-
log('didnt find', source);
88+
log("didn't find", source);
7789

7890
return {
7991
found: false,

package-lock.json

+7-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)