|
| 1 | +#!/usr/bin/env node |
| 2 | + |
| 3 | +const fs = require('fs'); |
| 4 | +const path = require('path'); |
| 5 | + |
| 6 | +function fixImportsInFile(filePath) { |
| 7 | + let content = fs.readFileSync(filePath, 'utf8'); |
| 8 | + |
| 9 | + // Fix relative imports to include .js extension |
| 10 | + content = content.replace( |
| 11 | + /from ['"](\.\/[^'"]*?)['"]/g, |
| 12 | + (match, importPath) => { |
| 13 | + if (!importPath.endsWith('.js')) { |
| 14 | + return `from '${importPath}.js'`; |
| 15 | + } |
| 16 | + return match; |
| 17 | + } |
| 18 | + ); |
| 19 | + |
| 20 | + // Fix relative imports with ../ |
| 21 | + content = content.replace( |
| 22 | + /from ['"](\.\.\/[^'"]*?)['"]/g, |
| 23 | + (match, importPath) => { |
| 24 | + if (!importPath.endsWith('.js')) { |
| 25 | + return `from '${importPath}.js'`; |
| 26 | + } |
| 27 | + return match; |
| 28 | + } |
| 29 | + ); |
| 30 | + |
| 31 | + fs.writeFileSync(filePath, content); |
| 32 | +} |
| 33 | + |
| 34 | +function processDirectory(dir) { |
| 35 | + const files = fs.readdirSync(dir); |
| 36 | + |
| 37 | + for (const file of files) { |
| 38 | + const filePath = path.join(dir, file); |
| 39 | + const stat = fs.statSync(filePath); |
| 40 | + |
| 41 | + if (stat.isDirectory()) { |
| 42 | + processDirectory(filePath); |
| 43 | + } else if (file.endsWith('.js')) { |
| 44 | + fixImportsInFile(filePath); |
| 45 | + } |
| 46 | + } |
| 47 | +} |
| 48 | + |
| 49 | +// Process the lib directory |
| 50 | +const libDir = path.join(__dirname, '..', 'lib'); |
| 51 | +if (fs.existsSync(libDir)) { |
| 52 | + processDirectory(libDir); |
| 53 | + console.log('✅ Fixed import extensions in compiled files'); |
| 54 | +} else { |
| 55 | + console.log('❌ lib directory not found'); |
| 56 | +} |
0 commit comments