(
currentVersion: string,
options: RunUpdatePreflightOptions = {},
)
| 662 | } |
| 663 | |
| 664 | export async function runUpdatePreflight( |
| 665 | currentVersion: string, |
| 666 | options: RunUpdatePreflightOptions = {}, |
| 667 | ): Promise<UpdatePreflightResult> { |
| 668 | const stdout = options.stdout ?? process.stdout; |
| 669 | const stderr = options.stderr ?? process.stderr; |
| 670 | const logger = options.logger ?? log; |
| 671 | const platform = process.platform; |
| 672 | |
| 673 | if (isAutoUpdateDisabledByEnv()) { |
| 674 | return 'continue'; |
| 675 | } |
| 676 | |
| 677 | try { |
| 678 | const isInteractive = |
| 679 | options.isTTY ?? (process.stdin.isTTY && process.stdout.isTTY); |
| 680 | const deviceId = resolveUpdateDeviceId(); |
| 681 | const bypassRollout = isRolloutBypassedByExperimentalEnv(); |
| 682 | let installState = await readUpdateInstallState().catch(() => emptyUpdateInstallState()); |
| 683 | if (isInteractive) { |
| 684 | installState = await showPendingBackgroundInstallNotice( |
| 685 | installState, |
| 686 | currentVersion, |
| 687 | stdout, |
| 688 | options.track, |
| 689 | logger, |
| 690 | ); |
| 691 | } |
| 692 | |
| 693 | const cache = await readUpdateCache().catch(() => null); |
| 694 | const cachedManifest = cache?.manifest ?? null; |
| 695 | const cachedDecision = decidePassiveUpdateTarget( |
| 696 | currentVersion, |
| 697 | cache?.latest ?? null, |
| 698 | cachedManifest, |
| 699 | deviceId, |
| 700 | new Date(), |
| 701 | bypassRollout, |
| 702 | ); |
| 703 | logRolloutDecision('startup-cache', currentVersion, cache?.latest ?? null, cachedManifest, cachedDecision); |
| 704 | const target = cachedDecision.target; |
| 705 | if (target === null) { |
| 706 | refreshAndMaybeInstallInBackground( |
| 707 | currentVersion, |
| 708 | deviceId, |
| 709 | bypassRollout, |
| 710 | isInteractive, |
| 711 | installState, |
| 712 | platform, |
| 713 | options.track, |
| 714 | logger, |
| 715 | ); |
| 716 | return 'continue'; |
| 717 | } |
| 718 | |
| 719 | const source: InstallSource = |
| 720 | !isInteractive |
| 721 | ? 'unsupported' |
no test coverage detected