From b74854d0a03a27a6b11503836de17eaef9184a27 Mon Sep 17 00:00:00 2001 From: Vanilagy <1696106+Vanilagy@users.noreply.github.com> Date: Mon, 29 Sep 2025 20:43:40 +0200 Subject: [PATCH] Add .js extension even in declaration files --- scripts/add-import-extensions.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/scripts/add-import-extensions.ts b/scripts/add-import-extensions.ts index d5da4b1..a0d7b11 100644 --- a/scripts/add-import-extensions.ts +++ b/scripts/add-import-extensions.ts @@ -13,7 +13,7 @@ const walkDir = (dir: string) => { if (stat.isDirectory()) { files.push(...walkDir(fullPath)); - } else if (item.endsWith('.js')) { + } else if (item.endsWith('.js') || item.endsWith('.ts')) { files.push(fullPath); } } @@ -23,8 +23,13 @@ const walkDir = (dir: string) => { const fixFile = (filePath: string) => { const content = fs.readFileSync(filePath, 'utf8'); - const fixed = content.replace( - /(\s+from\s+['"])(\.[^'"]*)(['"])/g, // This only matches relative imports + // We only match relative imports + let fixed = content.replace( + /(\s+from\s+['"])(\.[^'"]*)(['"])/g, // This matches static imports + '$1$2.js$3', + ); + fixed = fixed.replace( + /(import\s*\(\s*['"])(\.[^'"]*)(['"]\s*\))/g, // This matches dynamic imports '$1$2.js$3', );