* Recursively rewrites .ts imports to .js in all JavaScript files. * Required because Node.js cannot resolve .ts extensions at runtime.
(dir: string)
| 8 | * Required because Node.js cannot resolve .ts extensions at runtime. |
| 9 | */ |
| 10 | function rewriteTsImportsInDir(dir: string): void { |
| 11 | const entries = readdirSync(dir, { withFileTypes: true }); |
| 12 | for (const entry of entries) { |
| 13 | const fullPath = join(dir, entry.name); |
| 14 | if (entry.isDirectory()) { |
| 15 | rewriteTsImportsInDir(fullPath); |
| 16 | } else if (entry.name.endsWith('.js')) { |
| 17 | let content = readFileSync(fullPath, 'utf-8'); |
| 18 | // Rewrite: import ... from "./path.ts" or import ... from "../path.ts" |
| 19 | // Also handles: export ... from "./path.ts" |
| 20 | const rewritten = content.replace( |
| 21 | /((?:import|export)[^'"]*['"])([^'"]+)(\.ts)(['"])/g, |
| 22 | '$1$2.js$4', |
| 23 | ); |
| 24 | if (rewritten !== content) { |
| 25 | writeFileSync(fullPath, rewritten, 'utf-8'); |
| 26 | } |
| 27 | } |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | export default defineConfig({ |
| 32 | // Include all TypeScript files for unbundled output |
no test coverage detected