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