Unverified Commit 3b8e2f68 authored by Maia Teegarden's avatar Maia Teegarden Committed by GitHub

Make setup-wasm script work for local dev (#36355)

* Make setup-wasm script work for local dev

* Use copy instead of move
parent be9491e2
...@@ -63,6 +63,8 @@ yarn prepublish ...@@ -63,6 +63,8 @@ yarn prepublish
By default the latest canary of the next-swc binaries will be installed and used. If you are actively working on Rust code or you need to test out the most recent Rust code that hasn't been published as a canary yet you can [install Rust](https://www.rust-lang.org/tools/install) and run `yarn --cwd packages/next-swc build-native`. By default the latest canary of the next-swc binaries will be installed and used. If you are actively working on Rust code or you need to test out the most recent Rust code that hasn't been published as a canary yet you can [install Rust](https://www.rust-lang.org/tools/install) and run `yarn --cwd packages/next-swc build-native`.
If you want to test out the wasm build locally, you will need to [install wasm-pack](https://rustwasm.github.io/wasm-pack/installer/). Run `yarn --cwd packages/next-swc build-wasm --target <wasm_target>` to build and `node ./scripts/setup-wasm.mjs` to copy it into your `node_modules`. Run next with `NODE_OPTIONS='--no-addons'` to force it to use the wasm binary.
If you need to clean the project for any reason, use `yarn clean`. If you need to clean the project for any reason, use `yarn clean`.
## Testing ## Testing
......
import path from 'path' import path from 'path'
import { readFile, writeFile } from 'fs/promises' import { readFile, writeFile } from 'fs/promises'
import { copy } from 'fs-extra' import { copy, pathExists } from 'fs-extra'
;(async function () { ;(async function () {
let wasmDir = path.join(process.cwd(), 'packages/next-swc/crates/wasm') try {
let wasmTarget = 'nodejs' let wasmDir = path.join(process.cwd(), 'packages/next-swc/crates/wasm')
let wasmPkg = JSON.parse( let wasmTarget = 'nodejs'
await readFile(path.join(wasmDir, `pkg-${wasmTarget}/package.json`))
)
wasmPkg.name = `@next/swc-wasm-${wasmTarget}`
await writeFile( // CI restores artifact at pkg-${wasmTarget}
path.join(wasmDir, `pkg-${wasmTarget}/package.json`), // This only runs locally
JSON.stringify(wasmPkg, null, 2) let folderName = (await pathExists(path.join(wasmDir, 'pkg')))
) ? 'pkg'
: `pkg-${wasmTarget}`
await copy( let wasmPkg = JSON.parse(
path.join(wasmDir, `pkg-${wasmTarget}`), await readFile(path.join(wasmDir, `${folderName}/package.json`))
path.join(process.cwd(), `node_modules/@next/swc-wasm-${wasmTarget}`) )
) wasmPkg.name = `@next/swc-wasm-${wasmTarget}`
await writeFile(
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)
}
})() })()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment