17553c5e25
The PR follows #56536 and #56491, replacing `fs-extra` usages inside the `scripts/` folder. Note that the `copy` and `move` haven't been replaced yet. Currently, there is no better recursive copy (lightweight, promise-based, Node.js built-in `copyFile` API-based, support the `filter` option) library alternative available on npm, and Node.js built-in `fs.rename` doesn't support `overwrite`. The PR also replaces many async fs API usage with their sync versions. cc @wbinnssmith
33 lines
894 B
JavaScript
33 lines
894 B
JavaScript
import path from 'path'
|
|
import fs from 'fs'
|
|
import { copy } from 'fs-extra'
|
|
;(async function () {
|
|
try {
|
|
let wasmDir = path.join(process.cwd(), 'packages/next-swc/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)
|
|
)
|
|
|
|
await copy(
|
|
path.join(wasmDir, `${folderName}`),
|
|
path.join(process.cwd(), `node_modules/@next/swc-wasm-${wasmTarget}`),
|
|
{ overwrite: true }
|
|
)
|
|
} catch (e) {
|
|
console.error(e)
|
|
}
|
|
})()
|