( channelOrVersion: string, forceReinstall: boolean = false, )
| 481 | } |
| 482 | |
| 483 | async function updateLatest( |
| 484 | channelOrVersion: string, |
| 485 | forceReinstall: boolean = false, |
| 486 | ): Promise<{ |
| 487 | success: boolean |
| 488 | latestVersion: string |
| 489 | lockFailed?: boolean |
| 490 | lockHolderPid?: number |
| 491 | }> { |
| 492 | const startTime = Date.now() |
| 493 | let version = await getLatestVersion(channelOrVersion) |
| 494 | const { executable: executablePath } = getBaseDirectories() |
| 495 | |
| 496 | logForDebugging(`Checking for native installer update to version ${version}`) |
| 497 | |
| 498 | // Check if max version is set (server-side kill switch for auto-updates) |
| 499 | if (!forceReinstall) { |
| 500 | const maxVersion = await getMaxVersion() |
| 501 | if (maxVersion && gt(version, maxVersion)) { |
| 502 | logForDebugging( |
| 503 | `Native installer: maxVersion ${maxVersion} is set, capping update from ${version} to ${maxVersion}`, |
| 504 | ) |
| 505 | // If we're already at or above maxVersion, skip the update entirely |
| 506 | if (gte(MACRO.VERSION, maxVersion)) { |
| 507 | logForDebugging( |
| 508 | `Native installer: current version ${MACRO.VERSION} is already at or above maxVersion ${maxVersion}, skipping update`, |
| 509 | ) |
| 510 | logEvent('ncode_native_update_skipped_max_version', { |
| 511 | latency_ms: Date.now() - startTime, |
| 512 | max_version: |
| 513 | maxVersion as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS, |
| 514 | available_version: |
| 515 | version as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS, |
| 516 | }) |
| 517 | return { success: true, latestVersion: version } |
| 518 | } |
| 519 | version = maxVersion |
| 520 | } |
| 521 | } |
| 522 | |
| 523 | // Early exit: if we're already running this exact version AND both the version binary |
| 524 | // and executable exist and are valid. We need to proceed if the executable doesn't exist, |
| 525 | // is invalid (e.g., empty/corrupted from a failed install), or we're running via npx. |
| 526 | if ( |
| 527 | !forceReinstall && |
| 528 | version === MACRO.VERSION && |
| 529 | (await versionIsAvailable(version)) && |
| 530 | (await isPossibleNcodeBinary(executablePath)) |
| 531 | ) { |
| 532 | logForDebugging(`Found ${version} at ${executablePath}, skipping install`) |
| 533 | logEvent('ncode_native_update_complete', { |
| 534 | latency_ms: Date.now() - startTime, |
| 535 | was_new_install: false, |
| 536 | was_force_reinstall: false, |
| 537 | was_already_running: true, |
| 538 | }) |
| 539 | return { success: true, latestVersion: version } |
| 540 | } |
no test coverage detected