Skip to content

Commit d6ce352

Browse files
fix: change swc update command
1 parent 38d2f96 commit d6ce352

File tree

3 files changed

+52
-24
lines changed

3 files changed

+52
-24
lines changed

.github/workflows/update-swc.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ on:
1010
- cron: '0 0 * * 1' # Every Monday at 00:00 UTC
1111

1212
env:
13-
NODE_VERSION: lts/*
13+
NODE_VERSION: 22
1414

1515
jobs:
1616
update-swc:
@@ -26,6 +26,8 @@ jobs:
2626

2727
- name: Set up Node.js
2828
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
29+
with:
30+
node-version: ${{ env.NODE_VERSION }}
2931

3032
- name: Check if SWC update is required
3133
id: version-check
@@ -48,7 +50,7 @@ jobs:
4850
4951
- name: Update SWC
5052
if: steps.version-check.outputs.UPDATE_REQUIRED == 'true'
51-
run: ./tools/update-swc.sh
53+
run: node --run build:wasm
5254

5355
- name: Create Pull Request with first commit
5456
if: steps.version-check.outputs.UPDATE_REQUIRED == 'true'

deps/swc/bindings/binding_typescript_wasm/scripts/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ set -eux
33

44
export CARGO_PROFILE_RELEASE_LTO="fat"
55
export CARGO_PROFILE_RELEASE_OPT_LEVEL="z"
6-
wasm-pack build --out-name wasm --release --scope=swc --target nodejs
6+
wasm-pack build --out-namsh e wasm --release --scope=swc --target nodejs
77
ls -al ./pkg
88

99
node ./scripts/patch.mjs

tools/build-wasm.js

Lines changed: 47 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
1-
const WASM_BUILDER_CONTAINER =
2-
"ghcr.io/nodejs/wasm-builder@sha256:975f391d907e42a75b8c72eb77c782181e941608687d4d8694c3e9df415a0970"; // v0.0.9
3-
41
const { execSync, execFileSync } = require("node:child_process");
52
const { resolve } = require("node:path");
63

4+
const WASM_BUILDER_CONTAINER =
5+
"ghcr.io/nodejs/wasm-builder@sha256:975f391d907e42a75b8c72eb77c782181e941608687d4d8694c3e9df415a0970"; // v0.0.9
6+
77
const ROOT = resolve(__dirname, "../");
88

9-
let platform = process.env.WASM_PLATFORM;
10-
if (!platform && process.argv[2]) {
11-
platform = execFileSync("docker", [
12-
"info",
13-
"-f",
14-
"{{.OSType}}/{{.Architecture}}",
15-
])
16-
.toString()
17-
.trim();
9+
function getPlatformFromDocker() {
10+
try {
11+
return execFileSync("docker", [
12+
"info",
13+
"-f",
14+
"{{.OSType}}/{{.Architecture}}",
15+
])
16+
.toString()
17+
.trim();
18+
} catch (error) {
19+
console.error(
20+
"Error retrieving platform information from Docker:",
21+
error.message,
22+
);
23+
}
1824
}
1925

20-
if (process.argv[2] === "--docker") {
26+
function runDockerContainer() {
2127
const args = [];
2228
args.push("run");
2329
args.push("--rm");
@@ -43,14 +49,34 @@ if (process.argv[2] === "--docker") {
4349
args.push("./tools/build-wasm.js");
4450
console.log(`> docker ${args}\n\n`);
4551
execFileSync("docker", args, { stdio: "inherit" });
52+
}
53+
54+
let platform = process.env.WASM_PLATFORM;
55+
if (!platform && process.argv[2]) {
56+
platform = getPlatformFromDocker();
57+
}
58+
59+
// If "--docker" is passed, run the Docker container with the specified mounts
60+
if (process.argv[2] === "--docker") {
61+
runDockerContainer();
4662
process.exit(0);
4763
}
4864

49-
execSync(
50-
`cd bindings/binding_typescript_wasm && \
51-
cargo install --locked wasm-pack && \
52-
PATH=/home/node/.cargo/bin:$PATH && \
53-
./scripts/build.sh && \
54-
cp -r pkg/* ../../lib`,
55-
{ stdio: "inherit" },
56-
);
65+
const wasmBindingPath = `${ROOT}/bindings/binding_typescript_wasm`;
66+
67+
const commands = [
68+
`cd ${wasmBindingPath}`,
69+
"cargo install --locked wasm-pack",
70+
"export PATH=/home/node/.cargo/bin:$PATH",
71+
`sh ${wasmBindingPath}/scripts/build.sh`,
72+
`cp -r ${wasmBindingPath}/pkg/* ${ROOT}/lib`,
73+
];
74+
75+
try {
76+
for (const command of commands) {
77+
execSync(command, { stdio: "inherit" });
78+
}
79+
} catch (error) {
80+
console.error("Error executing build command:", error.message);
81+
process.exit(1);
82+
}

0 commit comments

Comments
 (0)