File size: 1,360 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
// This script must be run with tsx
const { NEXT_DIR, execAsyncWithOutput, execFn, exec } = require('./pack-util')
const fs = require('fs')
const path = require('path')
const nextSwcDir = path.join(NEXT_DIR, 'packages/next-swc')
;(async () => {
await execAsyncWithOutput(
'Build wasm bindings',
['pnpm', 'run', 'build-wasm', ...process.argv.slice(2)],
{
cwd: nextSwcDir,
shell: process.platform === 'win32' ? 'powershell.exe' : false,
env: {
CARGO_TERM_COLOR: 'always',
TTY: '1',
...process.env,
},
}
)
execFn(
'Copy generated types to `next/src/build/swc/generated-wasm.d.ts`',
() => writeTypes()
)
})()
function writeTypes() {
const generatedTypesPath = path.join(NEXT_DIR, 'crates/wasm/pkg/wasm.d.ts')
const vendoredTypesPath = path.join(
NEXT_DIR,
'packages/next/src/build/swc/generated-wasm.d.ts'
)
const generatedNotice =
'// DO NOT MANUALLY EDIT THESE TYPES\n// You can regenerate this file by running `pnpm swc-build-wasm` in the root of the repo.\n\n'
const generatedTypes = fs.readFileSync(generatedTypesPath, 'utf8')
const vendoredTypes = generatedNotice + generatedTypes
fs.writeFileSync(vendoredTypesPath, vendoredTypes)
exec('Prettify generated types', [
'pnpm',
'prettier',
'--write',
vendoredTypesPath,
])
}
|