Add .js extension even in declaration files

This commit is contained in:
Vanilagy
2025-09-29 20:43:40 +02:00
parent 7d747ae6d9
commit b74854d0a0
+8 -3
View File
@@ -13,7 +13,7 @@ const walkDir = (dir: string) => {
if (stat.isDirectory()) { if (stat.isDirectory()) {
files.push(...walkDir(fullPath)); files.push(...walkDir(fullPath));
} else if (item.endsWith('.js')) { } else if (item.endsWith('.js') || item.endsWith('.ts')) {
files.push(fullPath); files.push(fullPath);
} }
} }
@@ -23,8 +23,13 @@ const walkDir = (dir: string) => {
const fixFile = (filePath: string) => { const fixFile = (filePath: string) => {
const content = fs.readFileSync(filePath, 'utf8'); const content = fs.readFileSync(filePath, 'utf8');
const fixed = content.replace( // We only match relative imports
/(\s+from\s+['"])(\.[^'"]*)(['"])/g, // This only matches 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', '$1$2.js$3',
); );