Skip to content

Commit

Permalink
feat: resolve declaration files (e.g. .d.ts) as a last resort
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sorccu committed Feb 20, 2025
1 parent 18857dc commit e594205
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions packages/cli/src/services/check-parser/package-files/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,20 @@ type CoreExtensionMapping = {
}

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

Expand Down

0 comments on commit e594205

Please sign in to comment.