From e59420536fd39520ad51c7de3330bc8e95e7378c Mon Sep 17 00:00:00 2001 From: Simo Kinnunen Date: Fri, 21 Feb 2025 02:19:54 +0900 Subject: [PATCH] feat: resolve declaration files (e.g. `.d.ts`) as a last resort 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. --- .../check-parser/package-files/extension.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/cli/src/services/check-parser/package-files/extension.ts b/packages/cli/src/services/check-parser/package-files/extension.ts index d1510f5e..6f28c9a8 100644 --- a/packages/cli/src/services/check-parser/package-files/extension.ts +++ b/packages/cli/src/services/check-parser/package-files/extension.ts @@ -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'], }