UNPKG

5.97 kBSource Map (JSON)View Raw
1{"version":3,"file":"ensureSimulatorAppRunningAsync.js","names":["osascript","data","_interopRequireWildcard","require","_spawnAsync","_interopRequireDefault","_child_process","_util","_internal","_waitForActionAsync","obj","__esModule","default","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","execAsync","promisify","exec","waitForSimulatorAppToStart","waitForActionAsync","interval","action","isSimulatorAppRunningAsync","zeroMeansNo","trim","error","message","includes","ensureSimulatorAppRunningAsync","udid","Logger","global","info","openSimulatorAppAsync","TimeoutError","args","push","join","killAllAsync","spawnAsync"],"sources":["../../../src/apple/utils/ensureSimulatorAppRunningAsync.ts"],"sourcesContent":["import * as osascript from '@expo/osascript';\nimport spawnAsync from '@expo/spawn-async';\nimport { exec } from 'child_process';\nimport { promisify } from 'util';\n\nimport { Logger } from '../../internal';\nimport { TimeoutError, waitForActionAsync } from './waitForActionAsync';\n\nconst execAsync = promisify(exec);\n\nexport async function waitForSimulatorAppToStart(): Promise<boolean> {\n return waitForActionAsync<boolean>({\n interval: 50,\n action: isSimulatorAppRunningAsync,\n });\n}\n\n/**\n * I think the app can be open while no simulators are booted.\n */\nexport async function isSimulatorAppRunningAsync(): Promise<boolean> {\n try {\n const zeroMeansNo = (\n await osascript.execAsync(\n 'tell app \"System Events\" to count processes whose name is \"Simulator\"'\n )\n ).trim();\n if (zeroMeansNo === '0') {\n return false;\n }\n } catch (error: any) {\n if (error.message.includes('Application isn’t running')) {\n return false;\n }\n throw error;\n }\n\n return true;\n}\n\nexport async function ensureSimulatorAppRunningAsync({ udid }: { udid?: string }) {\n // Yes, simulators can be booted even if the app isn't running, obviously we'd never want this.\n if (!(await isSimulatorAppRunningAsync())) {\n Logger.global.info(`\\u203A Opening the iOS simulator, this might take a moment.`);\n\n // In theory this would ensure the correct simulator is booted as well.\n // This isn't theory though, this is Xcode.\n await openSimulatorAppAsync({ udid });\n if (!(await waitForSimulatorAppToStart())) {\n throw new TimeoutError(\n `Simulator app did not open fast enough. Try opening Simulator first, then running your app.`\n );\n }\n }\n}\n\nexport async function openSimulatorAppAsync({ udid }: { udid?: string }) {\n const args = ['open', '-a', 'Simulator'];\n if (udid) {\n // This has no effect if the app is already running.\n args.push('--args', '-CurrentDeviceUDID', udid);\n }\n await execAsync(args.join(' '));\n}\n\nexport async function killAllAsync() {\n return await spawnAsync('killAll', ['Simulator']);\n}\n"],"mappings":";;;;;;;;;;AAAA,SAAAA,UAAA;EAAA,MAAAC,IAAA,GAAAC,uBAAA,CAAAC,OAAA;EAAAH,SAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,YAAA;EAAA,MAAAH,IAAA,GAAAI,sBAAA,CAAAF,OAAA;EAAAC,WAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAK,eAAA;EAAA,MAAAL,IAAA,GAAAE,OAAA;EAAAG,cAAA,YAAAA,CAAA;IAAA,OAAAL,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAM,MAAA;EAAA,MAAAN,IAAA,GAAAE,OAAA;EAAAI,KAAA,YAAAA,CAAA;IAAA,OAAAN,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAO,UAAA;EAAA,MAAAP,IAAA,GAAAE,OAAA;EAAAK,SAAA,YAAAA,CAAA;IAAA,OAAAP,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAQ,oBAAA;EAAA,MAAAR,IAAA,GAAAE,OAAA;EAAAM,mBAAA,YAAAA,CAAA;IAAA,OAAAR,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAAwE,SAAAI,uBAAAK,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GA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