|
| 1 | +import { globSync } from 'fast-glob' |
| 2 | +import { |
| 3 | + existsSync, |
| 4 | + mkdirSync, |
| 5 | + readFileSync, |
| 6 | + rmSync, |
| 7 | + writeFileSync |
| 8 | +} from 'node:fs' |
| 9 | +import path from 'node:path' |
| 10 | +import { fileURLToPath } from 'node:url' |
| 11 | +import { isolatedDeclaration } from 'oxc-transform' |
| 12 | + |
| 13 | +const __dirname = fileURLToPath(new URL('.', import.meta.url)) |
| 14 | + |
| 15 | +if (existsSync(path.resolve(__dirname, '../temp/packages'))) { |
| 16 | + rmSync(path.resolve(__dirname, '../temp/packages'), { recursive: true }) |
| 17 | +} |
| 18 | + |
| 19 | +let errs = '' |
| 20 | +let start = performance.now() |
| 21 | +let count = 0 |
| 22 | + |
| 23 | +const IGNORES = [ |
| 24 | + 'format-explorer', |
| 25 | + 'size-check-core', |
| 26 | + 'size-check-vue-i18n', |
| 27 | + 'size-check-vue-i18n' |
| 28 | +] |
| 29 | + |
| 30 | +for (const file of globSync( |
| 31 | + path.resolve(__dirname, '../packages/*/src/**/*.ts') |
| 32 | +)) { |
| 33 | + for (const ignore of IGNORES) { |
| 34 | + if (file.includes(ignore)) { |
| 35 | + continue |
| 36 | + } |
| 37 | + } |
| 38 | + |
| 39 | + const ts = readFileSync(file, 'utf-8') |
| 40 | + const dts = isolatedDeclaration(file, ts, { |
| 41 | + sourcemap: false, |
| 42 | + stripInternal: true |
| 43 | + }) |
| 44 | + if (dts.errors.length) { |
| 45 | + dts.errors.forEach(err => { |
| 46 | + // temporary workaround for https://github.com/oxc-project/oxc/issues/5668 |
| 47 | + if (!err.message.includes('set value(_: S)')) { |
| 48 | + console.error(err) |
| 49 | + } |
| 50 | + errs += err.message + '\n' |
| 51 | + }) |
| 52 | + } |
| 53 | + |
| 54 | + write(path.join('temp', file.replace(/\.ts$/, '.d.ts')), dts.code) |
| 55 | + count++ |
| 56 | +} |
| 57 | + |
| 58 | +console.log( |
| 59 | + `\n${count} isolated dts files generated in ${(performance.now() - start).toFixed(2)}ms.` |
| 60 | +) |
| 61 | + |
| 62 | +if (errs) { |
| 63 | + write(path.join('temp', 'oxc-iso-decl-errors.txt'), errs) |
| 64 | +} |
| 65 | + |
| 66 | +console.log('bundling dts with rollup-plugin-dts...') |
| 67 | + |
| 68 | +// bundle with rollup-plugin-dts |
| 69 | +// const rollupConfigs = (await import('../rollup.dts.config.js')).default |
| 70 | + |
| 71 | +start = performance.now() |
| 72 | + |
| 73 | +// await Promise.all( |
| 74 | +// rollupConfigs.map(c => |
| 75 | +// rollup(c).then(bundle => { |
| 76 | +// return bundle.write(c.output).then(() => { |
| 77 | +// console.log(pc.gray('built: ') + pc.blue(c.output.file)) |
| 78 | +// }) |
| 79 | +// }), |
| 80 | +// ), |
| 81 | +// ) |
| 82 | + |
| 83 | +console.log( |
| 84 | + `bundled dts generated in ${(performance.now() - start).toFixed(2)}ms.` |
| 85 | +) |
| 86 | + |
| 87 | +function write(file: string, content: string) { |
| 88 | + const dir = path.dirname(file) |
| 89 | + if (!existsSync(dir)) { |
| 90 | + mkdirSync(dir, { recursive: true }) |
| 91 | + } |
| 92 | + writeFileSync(file, content) |
| 93 | +} |
0 commit comments