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EK,MAAM,kBAAkB,GAAG,KAAK,EAAE,OAAe,EAAE,IAAc,EAAE,EAAE;IAC1E,IAAI,CAAC;QACH,MAAM,IAAA,mBAAI,EAAC,OAAO,EAAE,IAAI,CAAC,CAAA;QACzB,OAAO,IAAI,CAAA;IACb,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAA;IACd,CAAC;AACH,CAAC,CAAA;AAPY,QAAA,kBAAkB,sBAO9B","sourcesContent":["import { DebugLogger, exec, ExtraSpawnOptions, InvalidConfigurationError, log, spawn } from \"builder-util\"\nimport { ExecFileOptions, SpawnOptions } from \"child_process\"\nimport { Lazy } from \"lazy-val\"\nimport * as path from \"path\"\nimport { ParallelsVm } from \"./ParallelsVm\"\nexport class VmManager {\n get pathSep(): string {\n return path.sep\n }\n\n exec(file: string, args: Array, options?: ExecFileOptions, isLogOutIfDebug = true): Promise {\n return exec(file, args, options, isLogOutIfDebug)\n }\n\n spawn(file: string, args: Array, options?: SpawnOptions, extraOptions?: ExtraSpawnOptions): Promise {\n return spawn(file, args, options, extraOptions)\n }\n\n toVmFile(file: string): string {\n return file\n }\n\n readonly powershellCommand = new Lazy(() => {\n return this.exec(\"powershell.exe\", [\"-NoProfile\", \"-NonInteractive\", \"-Command\", `Get-Command pwsh.exe`])\n .then(() => {\n log.info(null, \"identified pwsh.exe\")\n return \"pwsh.exe\"\n })\n .catch(() => {\n log.info(null, \"unable to find pwsh.exe, falling back to powershell.exe\")\n return \"powershell.exe\"\n })\n })\n}\n\nexport async function getWindowsVm(debugLogger: DebugLogger): Promise {\n const parallelsVmModule = await import(\"./ParallelsVm\")\n let vmList: ParallelsVm[] = []\n try {\n vmList = (await parallelsVmModule.parseVmList(debugLogger)).filter(it => [\"win-10\", \"win-11\"].includes(it.os))\n } catch (_error) {\n if ((await isPwshAvailable.value) && (await isWineAvailable.value)) {\n const vmModule = await import(\"./PwshVm\")\n return new vmModule.PwshVmManager()\n }\n }\n if (vmList.length === 0) {\n throw new InvalidConfigurationError(\"Cannot find suitable Parallels Desktop virtual machine (Windows 10 is required) and cannot access `pwsh` and `wine` locally\")\n }\n\n // prefer running or suspended vm\n return new parallelsVmModule.ParallelsVmManager(vmList.find(it => it.state === \"running\") || vmList.find(it => it.state === \"suspended\") || vmList[0])\n}\n\nconst isWineAvailable = new Lazy(async () => {\n return isCommandAvailable(\"wine\", [\"--version\"])\n})\n\nexport const isPwshAvailable = new Lazy(async () => {\n return isCommandAvailable(\"pwsh\", [\"--version\"])\n})\n\nexport const isCommandAvailable = async (command: string, args: string[]) => {\n try {\n await exec(command, args)\n return true\n } catch {\n return false\n }\n}\n"]}