From d6ce352541b3c2171690e6f839e07c85481b2d23 Mon Sep 17 00:00:00 2001 From: Marco Ippolito Date: Mon, 4 Nov 2024 09:19:32 +0000 Subject: [PATCH] fix: change swc update command --- .github/workflows/update-swc.yml | 6 +- .../binding_typescript_wasm/scripts/build.sh | 2 +- tools/build-wasm.js | 68 +++++++++++++------ 3 files changed, 52 insertions(+), 24 deletions(-) diff --git a/.github/workflows/update-swc.yml b/.github/workflows/update-swc.yml index 86c6df871..8af690a4c 100644 --- a/.github/workflows/update-swc.yml +++ b/.github/workflows/update-swc.yml @@ -10,7 +10,7 @@ on: - cron: '0 0 * * 1' # Every Monday at 00:00 UTC env: - NODE_VERSION: lts/* + NODE_VERSION: 22 jobs: update-swc: @@ -26,6 +26,8 @@ jobs: - name: Set up Node.js uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0 + with: + node-version: ${{ env.NODE_VERSION }} - name: Check if SWC update is required id: version-check @@ -48,7 +50,7 @@ jobs: - name: Update SWC if: steps.version-check.outputs.UPDATE_REQUIRED == 'true' - run: ./tools/update-swc.sh + run: node --run build:wasm - name: Create Pull Request with first commit if: steps.version-check.outputs.UPDATE_REQUIRED == 'true' diff --git a/deps/swc/bindings/binding_typescript_wasm/scripts/build.sh b/deps/swc/bindings/binding_typescript_wasm/scripts/build.sh index fa5cbf507..06f30d3e3 100755 --- a/deps/swc/bindings/binding_typescript_wasm/scripts/build.sh +++ b/deps/swc/bindings/binding_typescript_wasm/scripts/build.sh @@ -3,7 +3,7 @@ set -eux export CARGO_PROFILE_RELEASE_LTO="fat" export CARGO_PROFILE_RELEASE_OPT_LEVEL="z" -wasm-pack build --out-name wasm --release --scope=swc --target nodejs +wasm-pack build --out-namsh e wasm --release --scope=swc --target nodejs ls -al ./pkg node ./scripts/patch.mjs diff --git a/tools/build-wasm.js b/tools/build-wasm.js index 367cd7e6a..6eaa5145f 100644 --- a/tools/build-wasm.js +++ b/tools/build-wasm.js @@ -1,23 +1,29 @@ -const WASM_BUILDER_CONTAINER = - "ghcr.io/nodejs/wasm-builder@sha256:975f391d907e42a75b8c72eb77c782181e941608687d4d8694c3e9df415a0970"; // v0.0.9 - const { execSync, execFileSync } = require("node:child_process"); const { resolve } = require("node:path"); +const WASM_BUILDER_CONTAINER = + "ghcr.io/nodejs/wasm-builder@sha256:975f391d907e42a75b8c72eb77c782181e941608687d4d8694c3e9df415a0970"; // v0.0.9 + const ROOT = resolve(__dirname, "../"); -let platform = process.env.WASM_PLATFORM; -if (!platform && process.argv[2]) { - platform = execFileSync("docker", [ - "info", - "-f", - "{{.OSType}}/{{.Architecture}}", - ]) - .toString() - .trim(); +function getPlatformFromDocker() { + try { + return execFileSync("docker", [ + "info", + "-f", + "{{.OSType}}/{{.Architecture}}", + ]) + .toString() + .trim(); + } catch (error) { + console.error( + "Error retrieving platform information from Docker:", + error.message, + ); + } } -if (process.argv[2] === "--docker") { +function runDockerContainer() { const args = []; args.push("run"); args.push("--rm"); @@ -43,14 +49,34 @@ if (process.argv[2] === "--docker") { args.push("./tools/build-wasm.js"); console.log(`> docker ${args}\n\n`); execFileSync("docker", args, { stdio: "inherit" }); +} + +let platform = process.env.WASM_PLATFORM; +if (!platform && process.argv[2]) { + platform = getPlatformFromDocker(); +} + +// If "--docker" is passed, run the Docker container with the specified mounts +if (process.argv[2] === "--docker") { + runDockerContainer(); process.exit(0); } -execSync( - `cd bindings/binding_typescript_wasm && \ - cargo install --locked wasm-pack && \ - PATH=/home/node/.cargo/bin:$PATH && \ - ./scripts/build.sh && \ - cp -r pkg/* ../../lib`, - { stdio: "inherit" }, -); +const wasmBindingPath = `${ROOT}/bindings/binding_typescript_wasm`; + +const commands = [ + `cd ${wasmBindingPath}`, + "cargo install --locked wasm-pack", + "export PATH=/home/node/.cargo/bin:$PATH", + `sh ${wasmBindingPath}/scripts/build.sh`, + `cp -r ${wasmBindingPath}/pkg/* ${ROOT}/lib`, +]; + +try { + for (const command of commands) { + execSync(command, { stdio: "inherit" }); + } +} catch (error) { + console.error("Error executing build command:", error.message); + process.exit(1); +}