forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup-wasm.mjs
32 lines (28 loc) · 851 Bytes
/
setup-wasm.mjs
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
import path from 'path'
import fs from 'fs'
;(async function () {
try {
let wasmDir = path.join(process.cwd(), 'crates/wasm')
let wasmTarget = 'nodejs'
// CI restores artifact at pkg-${wasmTarget}
// This only runs locally
let folderName = fs.existsSync(path.join(wasmDir, 'pkg'))
? 'pkg'
: `pkg-${wasmTarget}`
let wasmPkg = JSON.parse(
fs.readFileSync(path.join(wasmDir, `${folderName}/package.json`))
)
wasmPkg.name = `@next/swc-wasm-${wasmTarget}`
fs.writeFileSync(
path.join(wasmDir, `${folderName}/package.json`),
JSON.stringify(wasmPkg, null, 2)
)
fs.cpSync(
path.join(wasmDir, folderName),
path.join(process.cwd(), `node_modules/@next/swc-wasm-${wasmTarget}`),
{ force: true, recursive: true }
)
} catch (e) {
console.error(e)
}
})()