Skip to content

Commit 4433bdf

Browse files
authored
feat: resolve declaration files (e.g. .d.ts) as a last resort (#1023)
It seems that some users are using declaration files as shared header files and there is nothing else to resolve. During normal transpilation, any such imports would get removed and the declaration file would not be part of the dist bundle. Since we transpile on the runner, it would be nice to have the file available there even though it's not technically even required. More importantly however this change makes the parser not complain about missing dependencies if it encounters imports that can only be resolved to a declaration file.
1 parent 18857dc commit 4433bdf

File tree

1 file changed

+11
-3
lines changed
  • packages/cli/src/services/check-parser/package-files

1 file changed

+11
-3
lines changed

packages/cli/src/services/check-parser/package-files/extension.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,20 @@ type CoreExtensionMapping = {
99
}
1010

1111
/**
12+
* Unlike TypeScript's native lookup order, our lookup order prefers
13+
* implementation files to declaration files.
14+
*
15+
* Why include declaration files at all? Some of our users use manually
16+
* created declaration files as essentially shared header files without a
17+
* corresponding implementation file, and the declaration is the only thing
18+
* we'll be able to find. Otherwise we'd complain about a missing dependency.
19+
*
1220
* @see https://www.typescriptlang.org/docs/handbook/modules/reference.html#file-extension-substitution
1321
*/
1422
export const tsCoreExtensionLookupOrder: CoreExtensionMapping = {
15-
'.js': ['.ts', '.tsx', '.js', '.jsx'],
16-
'.mjs': ['.mts', '.mjs'],
17-
'.cjs': ['.cts', '.cjs'],
23+
'.js': ['.ts', '.tsx', '.js', '.jsx', '.d.ts'],
24+
'.mjs': ['.mts', '.mjs', '.d.mts'],
25+
'.cjs': ['.cts', '.cjs', '.d.cts'],
1826
'.json': ['.json'],
1927
}
2028

0 commit comments

Comments
 (0)