From 845ad47049848c492a50a9cf04fbe3a67bbc8431 Mon Sep 17 00:00:00 2001 From: UnschooledGamer <76094069+UnschooledGamer@users.noreply.github.com> Date: Fri, 5 Jun 2026 21:51:58 +0530 Subject: [PATCH 1/5] fix(dev:android): make Windows dev spawns reliable in android dev npm script --- utils/scripts/dev.js | 62 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 53 insertions(+), 9 deletions(-) diff --git a/utils/scripts/dev.js b/utils/scripts/dev.js index e6a1239e7..8fc149a58 100644 --- a/utils/scripts/dev.js +++ b/utils/scripts/dev.js @@ -28,6 +28,7 @@ const ROOT = path.resolve(__dirname, "../.."); const WWW = path.join(ROOT, "www"); const PLUGINS = path.join(ROOT, "src", "plugins"); const PLATFORM_WWW = path.join(ROOT, "platforms", "android", "platform_www"); +const CORDOVA_BIN = path.join(ROOT, "node_modules", "cordova", "bin", "cordova"); const MIME = { ".html": "text/html", ".js": "application/javascript", @@ -95,10 +96,40 @@ function log(label, msg) { console.log(` ${c}[${label}]${reset} ${msg}`); } +function resolveSpawnCommand(command) { + if (process.platform !== "win32") return command; + const lower = command.toLowerCase(); + if (lower.endsWith(".cmd") || lower.endsWith(".exe")) return command; + if (lower === "cordova" || lower === "npx" || lower === "npm") { + return `${command}.cmd`; + } + return command; +} + +function buildSpawnEnv(extra = {}) { + const merged = { ...process.env, ...extra }; + const sanitized = {}; + + for (const [key, value] of Object.entries(merged)) { + if (!key || key.startsWith("=") || value === undefined) continue; + sanitized[key] = String(value); + } + + return sanitized; +} + function spawnAsync(command, args, options) { return new Promise((resolve, reject) => { - const mergedOptions = { stdio: "inherit", ...options }; - const proc = spawn(command, args, mergedOptions); + const mergedOptions = { + stdio: "inherit", + ...options, + env: options?.env ? buildSpawnEnv(options.env) : options?.env, + }; + const useLocalCordova = + command === "cordova" && fs.existsSync(CORDOVA_BIN); + const proc = useLocalCordova + ? spawn(process.execPath, [CORDOVA_BIN, ...args], mergedOptions) + : spawn(resolveSpawnCommand(command), args, mergedOptions); proc.on("close", (code) => { if (code === 0) resolve(); else reject(new Error(`${command} exited with code ${code}`)); @@ -251,10 +282,16 @@ async function launchApp(target, platform, emulator) { const args = ["run", platform]; if (emulator) args.push("--emulator"); if (target) args.push("--target", target); - const proc = spawn("cordova", args, { + const useLocalCordova = fs.existsSync(CORDOVA_BIN); + const proc = useLocalCordova + ? spawn(process.execPath, [CORDOVA_BIN, ...args], { + cwd: ROOT, + stdio: "inherit", + }) + : spawn(resolveSpawnCommand("cordova"), args, { cwd: ROOT, stdio: "inherit", - }); + }); proc.on("close", (code) => { if (code === 0) resolve(); @@ -271,15 +308,22 @@ async function launchApp(target, platform, emulator) { function startRspackWatch(host, port, proto, onCompiled) { log("info", "Starting rspack --watch..."); - const env = { - ...process.env, + const env = buildSpawnEnv({ DEV_MODE: "true", DEV_HOST: host, DEV_PORT: String(port), DEV_PROTO: proto, - }; - - const proc = spawn("npx", ["rspack", "--watch", "--mode", "development"], { + }); + const rspackBin = path.join( + ROOT, + "node_modules", + "@rspack", + "cli", + "bin", + "rspack.js", + ); + + const proc = spawn(process.execPath, [rspackBin, "--watch", "--mode", "development"], { cwd: ROOT, env, stdio: "pipe", From 3449e44111b6d7abca99b3ac3de813980ebe3685 Mon Sep 17 00:00:00 2001 From: UnschooledGamer <76094069+UnschooledGamer@users.noreply.github.com> Date: Fri, 5 Jun 2026 21:53:43 +0530 Subject: [PATCH 2/5] chore: fmt --- utils/scripts/dev.js | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/utils/scripts/dev.js b/utils/scripts/dev.js index 8fc149a58..dda569426 100644 --- a/utils/scripts/dev.js +++ b/utils/scripts/dev.js @@ -28,7 +28,13 @@ const ROOT = path.resolve(__dirname, "../.."); const WWW = path.join(ROOT, "www"); const PLUGINS = path.join(ROOT, "src", "plugins"); const PLATFORM_WWW = path.join(ROOT, "platforms", "android", "platform_www"); -const CORDOVA_BIN = path.join(ROOT, "node_modules", "cordova", "bin", "cordova"); +const CORDOVA_BIN = path.join( + ROOT, + "node_modules", + "cordova", + "bin", + "cordova", +); const MIME = { ".html": "text/html", ".js": "application/javascript", @@ -125,8 +131,7 @@ function spawnAsync(command, args, options) { ...options, env: options?.env ? buildSpawnEnv(options.env) : options?.env, }; - const useLocalCordova = - command === "cordova" && fs.existsSync(CORDOVA_BIN); + const useLocalCordova = command === "cordova" && fs.existsSync(CORDOVA_BIN); const proc = useLocalCordova ? spawn(process.execPath, [CORDOVA_BIN, ...args], mergedOptions) : spawn(resolveSpawnCommand(command), args, mergedOptions); @@ -289,9 +294,9 @@ async function launchApp(target, platform, emulator) { stdio: "inherit", }) : spawn(resolveSpawnCommand("cordova"), args, { - cwd: ROOT, - stdio: "inherit", - }); + cwd: ROOT, + stdio: "inherit", + }); proc.on("close", (code) => { if (code === 0) resolve(); @@ -323,11 +328,15 @@ function startRspackWatch(host, port, proto, onCompiled) { "rspack.js", ); - const proc = spawn(process.execPath, [rspackBin, "--watch", "--mode", "development"], { - cwd: ROOT, - env, - stdio: "pipe", - }); + const proc = spawn( + process.execPath, + [rspackBin, "--watch", "--mode", "development"], + { + cwd: ROOT, + env, + stdio: "pipe", + }, + ); let firstCompile = true; From 52ec868d059efc5fb7cf59cda6098c1eeedbb8f7 Mon Sep 17 00:00:00 2001 From: UnschooledGamer <76094069+UnschooledGamer@users.noreply.github.com> Date: Fri, 5 Jun 2026 22:00:18 +0530 Subject: [PATCH 3/5] fix(dev:android): guard rspack path and add npx fallback --- utils/scripts/dev.js | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/utils/scripts/dev.js b/utils/scripts/dev.js index dda569426..17cf4579c 100644 --- a/utils/scripts/dev.js +++ b/utils/scripts/dev.js @@ -328,15 +328,26 @@ function startRspackWatch(host, port, proto, onCompiled) { "rspack.js", ); - const proc = spawn( - process.execPath, - [rspackBin, "--watch", "--mode", "development"], - { - cwd: ROOT, - env, - stdio: "pipe", - }, - ); + const useLocalRspack = fs.existsSync(rspackBin); + if (!useLocalRspack) { + log("warn", "Local rspack CLI not found, falling back to npx rspack"); + } + + const proc = useLocalRspack + ? spawn(process.execPath, [rspackBin, "--watch", "--mode", "development"], { + cwd: ROOT, + env, + stdio: "pipe", + }) + : spawn( + resolveSpawnCommand("npx"), + ["rspack", "--watch", "--mode", "development"], + { + cwd: ROOT, + env, + stdio: "pipe", + }, + ); let firstCompile = true; @@ -357,6 +368,8 @@ function startRspackWatch(host, port, proto, onCompiled) { proc.on("error", (err) => { log("warn", `rspack error: ${err.message}`); + log("warn", "rspack watcher failed to start; exiting dev mode"); + process.exit(1); }); proc.on("close", (code) => { From 958f2a1484c3fd17c682ef15359fc5a85e3e781f Mon Sep 17 00:00:00 2001 From: Emmanuel Lobo <76094069+UnschooledGamer@users.noreply.github.com> Date: Fri, 5 Jun 2026 22:01:51 +0530 Subject: [PATCH 4/5] Update utils/scripts/dev.js Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> --- utils/scripts/dev.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/scripts/dev.js b/utils/scripts/dev.js index 17cf4579c..3d12ab4c8 100644 --- a/utils/scripts/dev.js +++ b/utils/scripts/dev.js @@ -288,10 +288,10 @@ async function launchApp(target, platform, emulator) { if (emulator) args.push("--emulator"); if (target) args.push("--target", target); const useLocalCordova = fs.existsSync(CORDOVA_BIN); - const proc = useLocalCordova - ? spawn(process.execPath, [CORDOVA_BIN, ...args], { + : spawn(resolveSpawnCommand("cordova"), args, { cwd: ROOT, stdio: "inherit", + }); }) : spawn(resolveSpawnCommand("cordova"), args, { cwd: ROOT, From 0c783098f48388d417654b4f9e70945c267e36e9 Mon Sep 17 00:00:00 2001 From: UnschooledGamer <76094069+UnschooledGamer@users.noreply.github.com> Date: Fri, 5 Jun 2026 22:05:41 +0530 Subject: [PATCH 5/5] chore: revert & fmt greptile suggestion --- utils/scripts/dev.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/scripts/dev.js b/utils/scripts/dev.js index 3d12ab4c8..17cf4579c 100644 --- a/utils/scripts/dev.js +++ b/utils/scripts/dev.js @@ -288,10 +288,10 @@ async function launchApp(target, platform, emulator) { if (emulator) args.push("--emulator"); if (target) args.push("--target", target); const useLocalCordova = fs.existsSync(CORDOVA_BIN); - : spawn(resolveSpawnCommand("cordova"), args, { + const proc = useLocalCordova + ? spawn(process.execPath, [CORDOVA_BIN, ...args], { cwd: ROOT, stdio: "inherit", - }); }) : spawn(resolveSpawnCommand("cordova"), args, { cwd: ROOT,