Loads the macOS operating system context.
()
| 429 | |
| 430 | /** Loads the macOS operating system context. */ |
| 431 | async function getDarwinInfo(): Promise<OsContext> { |
| 432 | // Default values that will be used in case no operating system information |
| 433 | // can be loaded. The default version is computed via heuristics from the |
| 434 | // kernel version, but the build ID is missing. |
| 435 | const darwinInfo: OsContext = { |
| 436 | kernel_version: os.release(), |
| 437 | name: 'Mac OS X', |
| 438 | version: `10.${Number(os.release().split('.')[0]) - 4}`, |
| 439 | }; |
| 440 | |
| 441 | try { |
| 442 | // We try to load the actual macOS version by executing the `sw_vers` tool. |
| 443 | // This tool should be available on every standard macOS installation. In |
| 444 | // case this fails, we stick with the values computed above. |
| 445 | |
| 446 | const output = await new Promise<string>((resolve, reject) => { |
| 447 | execFile('/usr/bin/sw_vers', (error: Error | null, stdout: string) => { |
| 448 | if (error) { |
| 449 | reject(error); |
| 450 | return; |
| 451 | } |
| 452 | resolve(stdout); |
| 453 | }); |
| 454 | }); |
| 455 | |
| 456 | darwinInfo.name = matchFirst(/^ProductName:\s+(.*)$/m, output); |
| 457 | darwinInfo.version = matchFirst(/^ProductVersion:\s+(.*)$/m, output); |
| 458 | darwinInfo.build = matchFirst(/^BuildVersion:\s+(.*)$/m, output); |
| 459 | } catch { |
| 460 | // ignore |
| 461 | } |
| 462 | |
| 463 | return darwinInfo; |
| 464 | } |
| 465 | |
| 466 | /** Returns a distribution identifier to look up version callbacks. */ |
| 467 | function getLinuxDistroId(name: string): string { |
no test coverage detected