From 1deec533ad94837f1ca0bc877e74122b2586eb83 Mon Sep 17 00:00:00 2001 From: CrescentLeaf Date: Sat, 13 Sep 2025 12:28:02 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20Android=20=E4=B8=8A=E5=BC=B7=E5=88=B6?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=20@rollup/wasm-node?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/checkIsAndroidAndBuild.ts | 36 ++++++++++++++++++++++++++++++++ client/deno.jsonc | 6 ++++-- client/fix-build-on-android.sh | 3 +++ 3 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 client/checkIsAndroidAndBuild.ts create mode 100644 client/fix-build-on-android.sh diff --git a/client/checkIsAndroidAndBuild.ts b/client/checkIsAndroidAndBuild.ts new file mode 100644 index 0000000..16ef194 --- /dev/null +++ b/client/checkIsAndroidAndBuild.ts @@ -0,0 +1,36 @@ +import process from 'node:process' +import child_process from 'node:child_process' +import fs from 'node:fs/promises' + +function spawn(exec: string, args: string[]) { + child_process.spawnSync(exec, args, { + stdio: [process.stdin, process.stdout, process.stderr] + }) +} + +function runBuild() { + const args = [ + "run", + "-A", + "--node-modules-dir", + ] + let i = 0 + for (const arg of process.argv) { + if (i > 1) + args.push(arg) + i++ + } + + spawn('deno', args) +} + +if (process.platform == 'android') { + try { + await fs.stat('./node_modules/.deno/rollup@4.50.1/node_modules/rollup/') + } catch (e) { + spawn('deno', ['install', '--node-modules-dir=auto']) + } + spawn('sh', ["fix-build-on-android.sh"]) +} + +runBuild() diff --git a/client/deno.jsonc b/client/deno.jsonc index 5db2267..9cfa912 100644 --- a/client/deno.jsonc +++ b/client/deno.jsonc @@ -1,7 +1,7 @@ { "tasks": { - "build": "deno run -A --node-modules-dir npm:vite build", - "build-watch": "deno run -A --node-modules-dir npm:vite --watch build" + "build": "deno run --allow-run --allow-env --allow-read checkIsAndroidAndBuild.ts npm:vite build", + "build-watch": "deno run --allow-run --allow-env --allow-read checkIsAndroidAndBuild.ts npm:vite --watch build" }, "compilerOptions": { "lib": ["ES2022", "DOM", "DOM.Iterable"], @@ -17,6 +17,8 @@ "react": "npm:react@18.3.1", "react-dom": "npm:react-dom@18.3.1", "vite": "npm:vite@7.0.6", + + "rollup": "npm:@rollup/wasm-node@4.48.0", "chalk": "npm:chalk@5.4.1", diff --git a/client/fix-build-on-android.sh b/client/fix-build-on-android.sh new file mode 100644 index 0000000..f52fa7d --- /dev/null +++ b/client/fix-build-on-android.sh @@ -0,0 +1,3 @@ +rm -r ./node_modules/.deno/rollup@4.50.1/node_modules/rollup/ +cp -r ./node_modules/.deno/@rollup+wasm-node@4.48.0/node_modules/@rollup/wasm-node/ node_modules/.deno/rollup@4.50.1/node_modules/rollup/ +echo Replaced rollup with @rollup/wasm-node successfully