File size: 1,175 Bytes
4a5ef51 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | #!/usr/bin/env node
/**
* Start Expo Metro without prompting when the default port is busy.
* Picks the next free port (8081, 8082, …) and passes --port to expo start.
*/
import {spawn} from "node:child_process"
import path from "node:path"
import {fileURLToPath} from "node:url"
import {resolveMetroPort} from "./resolve-metro-port.mjs"
const scriptDir = path.dirname(fileURLToPath(import.meta.url))
const projectRoot = path.resolve(scriptDir, "..")
const preferred = Number(process.env.RCT_METRO_PORT || process.env.EXPO_DEV_SERVER_PORT || 8081)
const port = await resolveMetroPort(preferred)
if (port !== preferred) {
console.log(`Port ${preferred} is in use; using ${port} instead.`)
}
process.env.RCT_METRO_PORT = String(port)
process.env.EXPO_DEV_SERVER_PORT = String(port)
const expoArgs = ["expo", "start", "--dev-client", "--port", String(port), ...process.argv.slice(2)]
const child = spawn("bunx", expoArgs, {
cwd: projectRoot,
env: process.env,
stdio: "inherit",
})
child.on("exit", (code, signal) => {
if (signal) {
process.kill(process.pid, signal)
return
}
process.exit(code ?? 0)
})
|