mirror of
https://github.com/vercel/next.js.git
synced 2026-09-20 02:25:18 +08:00
a6375148dc
Written with @bgw. - Transitions to using `tsx` for script execution - Replaces `patch-package` with TypeScript implementation - Implements argument parsing and help message with `yargs` - Uses `execa` for some command execution Test Plan: Run `pnpm pack-next`, `pnpm swc-build-wasm`, `pnpm unpack-next`, and `pnpm sweep` without errors.
53 lines
1.3 KiB
JavaScript
Executable File
53 lines
1.3 KiB
JavaScript
Executable File
// 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,
|
|
])
|
|
}
|