#!/usr/bin/env node /** * `react-native run-android`, minus one inherited setting that stops it from * opening Metro on Windows. * * Why this exists: run-android opens Metro by running `cmd.exe /C * launchPackager.bat` in a new window, and the first thing that script does is * `call .packager.bat` — a bare name, resolved from the current directory. * Tools started from inside VS Code (Claude Code among them) carry * `NoDefaultCurrentDirectoryInExePath=1`, which tells cmd not to look in the * current directory. The call then fails, the project paths it would have set * stay empty, Metro dies with `Cannot find module 'D:\cli.js'`, and because the * window gets no stdin its closing `pause` returns at once. The Metro window * flashes and is gone, and the app has no bundle to load. * * The setting is dropped for this command only. Everything else passes * through, so this takes the same flags as the CLI: * * npm run android * npm run android -- --mode release */ const { spawnSync } = require('child_process'); const env = {}; for (const [key, value] of Object.entries(process.env)) { // Windows variable names are case-insensitive. if (key.toLowerCase() !== 'nodefaultcurrentdirectoryinexepath') { env[key] = value; } } const cli = require.resolve('react-native/cli.js'); const result = spawnSync( process.execPath, [cli, 'run-android', ...process.argv.slice(2)], { stdio: 'inherit', env }, ); if (result.error) { console.error(result.error); } process.exit(result.status ?? 1);