Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

deviceHubNodeArgs.ts

25 lines1007 Bytes

1// expo-device-hub detaches emulators without hiding their Windows console. Closing that
2// console terminates the emulator; keep the workaround scoped to the hub process.
3const WINDOWS_EMULATOR_PRELOAD = `
4import childProcess from "node:child_process";
5import { syncBuiltinESMExports } from "node:module";
6import { basename } from "node:path";
7const spawn = childProcess.spawn;
8childProcess.spawn = function(command, ...args) {
9 if (typeof command === "string" && basename(command).toLowerCase() === "emulator.exe") {
10 const index = Array.isArray(args[0]) ? 1 : 0;
11 args[index] = { ...args[index], detached: false, windowsHide: true };
12 }
13 return Reflect.apply(spawn, this, [command, ...args]);
14};
15syncBuiltinESMExports();
16`;
17​
18export const deviceHubNodeArgs = (entryPath: string, platform: NodeJS.Platform): string[] =>
19 platform === "win32"
20 ? [
21 "--import",
22 `data:text/javascript,${encodeURIComponent(WINDOWS_EMULATOR_PRELOAD)}`,
23 entryPath,
24 ]
25 : [entryPath];