The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(install): repair missing Rolldown bindings
Gilleae9f42accf01
diff --git a/apps/desktop/scripts/ensure-rolldown-binding.mjs b/apps/desktop/scripts/ensure-rolldown-binding.mjsnew file mode 100644index 00000000000..0567b100b2c--- /dev/null+++ b/apps/desktop/scripts/ensure-rolldown-binding.mjs@@ -0,0 +1,80 @@+import { existsSync, readFileSync } from 'node:fs'+import { dirname, join, resolve } from 'node:path'+import { fileURLToPath } from 'node:url'+import { spawnSync } from 'node:child_process'++const appDir = resolve(dirname(fileURLToPath(import.meta.url)), '..')+const rootDir = resolve(appDir, '..', '..')++export function selectRolldownBinding(optionalDependencies, platform, arch) {+ const suffix = `binding-${platform}-${arch}`+ const matches = Object.entries(optionalDependencies ?? {}).filter(([name]) => name.endsWith(suffix))++ return matches.length === 1 ? matches[0] : null+}++function probeRolldown(root) {+ return spawnSync(process.execPath, ['--input-type=module', '--eval', "await import('rolldown')"], {+ cwd: root,+ encoding: 'utf8'+ })+}++function installBinding(root, spec) {+ const npm = process.platform === 'win32' ? 'npm.cmd' : 'npm'+ return spawnSync(npm, ['install', '--no-save', '--package-lock=false', '--include=optional', spec], {+ cwd: root,+ stdio: 'inherit'+ })+}++export function ensureRolldownBinding({+ root = rootDir,+ platform = process.platform,+ arch = process.arch,+ probe = probeRolldown,+ install = installBinding,+ findPackage = rootPath =>+ [+ join(rootPath, 'node_modules', 'rolldown', 'package.json'),+ join(rootPath, 'apps', 'desktop', 'node_modules', 'rolldown', 'package.json')+ ].find(existsSync),+ readPackage = path => JSON.parse(readFileSync(path, 'utf8'))+} = {}) {+ const initial = probe(root)+ if (initial.status === 0) return true++ let rolldownPackage+ try {+ const packagePath = findPackage(root)+ if (!packagePath) throw new Error('package.json was not found')+ rolldownPackage = readPackage(packagePath)+ } catch (error) {+ console.error(`Could not inspect the installed Rolldown package: ${error.message}`)+ return false+ }++ const binding = selectRolldownBinding(rolldownPackage.optionalDependencies, platform, arch)+ if (!binding) {+ console.error(`Rolldown has no unambiguous native binding for ${platform}/${arch}.`)+ return false+ }++ const [name, version] = binding+ console.warn(`Rolldown could not load; repairing ${name}@${version}...`)+ const installed = install(root, `${name}@${version}`)+ if (installed.status !== 0) return false++ const repaired = probe(root)+ if (repaired.status !== 0) {+ const detail = repaired.stderr?.trim() || repaired.stdout?.trim()+ console.error(detail || `Rolldown still cannot load after installing ${name}.`)+ return false+ }++ return true+}++if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {+ process.exitCode = ensureRolldownBinding() ? 0 : 1+}diff --git a/apps/desktop/scripts/ensure-rolldown-binding.test.mjs b/apps/desktop/scripts/ensure-rolldown-binding.test.mjsnew file mode 100644index 00000000000..3d41e0f6ff0--- /dev/null+++ b/apps/desktop/scripts/ensure-rolldown-binding.test.mjs@@ -0,0 +1,75 @@+import assert from 'node:assert/strict'+import test from 'node:test'++import { ensureRolldownBinding, selectRolldownBinding } from './ensure-rolldown-binding.mjs'++const packageMetadata = {+ optionalDependencies: {+ '@rolldown/binding-darwin-arm64': '1.2.1',+ '@rolldown/binding-darwin-x64': '1.2.1',+ '@rolldown/binding-linux-x64-gnu': '1.2.1',+ '@rolldown/binding-linux-x64-musl': '1.2.1'+ }+}++test('selects the exact platform binding from Rolldown metadata', () => {+ assert.deepEqual(selectRolldownBinding(packageMetadata.optionalDependencies, 'darwin', 'arm64'), [+ '@rolldown/binding-darwin-arm64',+ '1.2.1'+ ])+})++test('does nothing when Rolldown already loads', () => {+ let installs = 0+ const ok = ensureRolldownBinding({+ root: '/repo',+ probe: () => ({ status: 0 }),+ install: () => {+ installs += 1+ return { status: 0 }+ }+ })++ assert.equal(ok, true)+ assert.equal(installs, 0)+})++test('installs the missing macOS binding and verifies the repair', () => {+ let probes = 0+ const installs = []+ const ok = ensureRolldownBinding({+ root: '/repo',+ platform: 'darwin',+ arch: 'arm64',+ probe: () => ({ status: probes++ === 0 ? 1 : 0 }),+ install: (_root, spec) => {+ installs.push(spec)+ return { status: 0 }+ },+ findPackage: () => '/repo/node_modules/rolldown/package.json',+ readPackage: () => packageMetadata+ })++ assert.equal(ok, true)+ assert.deepEqual(installs, ['@rolldown/[email protected]'])+ assert.equal(probes, 2)+})++test('fails without guessing when the platform binding is ambiguous', () => {+ let installs = 0+ const ok = ensureRolldownBinding({+ root: '/repo',+ platform: 'linux',+ arch: 'x64',+ probe: () => ({ status: 1 }),+ install: () => {+ installs += 1+ return { status: 0 }+ },+ findPackage: () => '/repo/node_modules/rolldown/package.json',+ readPackage: () => packageMetadata+ })++ assert.equal(ok, false)+ assert.equal(installs, 0)+})diff --git a/scripts/install.ps1 b/scripts/install.ps1index 2f3a865ed32..55eb407a800 100644--- a/scripts/install.ps1+++ b/scripts/install.ps1@@ -4131,11 +4131,15 @@ function Install-Desktop {# is the artifact), but on failure we scan $npmOut for the TLS-trust# signature so corporate-proxy users get the NODE_EXTRA_CA_CERTS hint# instead of an opaque "exit 1" (issue #38016).- & $npmExe ci 2>&1 | ForEach-Object { "$_" } | Tee-Object -Variable npmOut+ & $npmExe ci --include=optional 2>&1 | ForEach-Object { "$_" } | Tee-Object -Variable npmOut$code = $LASTEXITCODEif ($code -ne 0) {Write-Info " npm ci failed (exit $code) -- retrying with npm install..."- & $npmExe install 2>&1 | ForEach-Object { "$_" } | Tee-Object -Variable npmOut+ & $npmExe install --include=optional 2>&1 | ForEach-Object { "$_" } | Tee-Object -Variable npmOut+ $code = $LASTEXITCODE+ }+ if ($code -eq 0) {+ & node apps/desktop/scripts/ensure-rolldown-binding.mjs$code = $LASTEXITCODE}$ErrorActionPreference = $prevEAP@@ -4244,7 +4248,7 @@ function Install-Desktop {$code = $LASTEXITCODE}}- if ($code -ne 0 -and -not $env:ELECTRON_MIRROR) {+ if ($code -ne 0 -and -not $env:ELECTRON_MIRROR -and -not (Test-ElectronDist -InstallDir $InstallDir)) {$mirror = $script:DesktopElectronFallbackMirrorWrite-Warn "Desktop build still failing - the Electron download from GitHub looks blocked."Write-Warn "Re-downloading Electron via a public mirror ($mirror), then rebuilding:"diff --git a/scripts/install.sh b/scripts/install.shindex cd290cac6c1..ae0d9c83b0e 100755--- a/scripts/install.sh+++ b/scripts/install.sh@@ -3566,11 +3566,11 @@ install_desktop() {log_info "Installing desktop workspace dependencies (includes Electron ~150MB, 1-3min)..."local _deps_start _deps_remaining_deps_start=$(date +%s)- if run_with_timeout "$DESKTOP_BUILD_TIMEOUT" bash -c 'cd "$1" && npm ci' _ "$INSTALL_DIR"; then+ if run_with_timeout "$DESKTOP_BUILD_TIMEOUT" bash -c 'cd "$1" && npm ci --include=optional && { [ "$2" != macos ] || node apps/desktop/scripts/ensure-rolldown-binding.mjs; }' _ "$INSTALL_DIR" "$OS"; thenlog_success "Desktop workspace dependencies installed"elif _deps_remaining=$(( DESKTOP_BUILD_TIMEOUT - ($(date +%s) - _deps_start) )); \[ "$_deps_remaining" -lt 30 ] && _deps_remaining=30; \- run_with_timeout "$_deps_remaining" bash -c 'cd "$1" && npm install' _ "$INSTALL_DIR"; then+ run_with_timeout "$_deps_remaining" bash -c 'cd "$1" && npm install --include=optional && { [ "$2" != macos ] || node apps/desktop/scripts/ensure-rolldown-binding.mjs; }' _ "$INSTALL_DIR" "$OS"; thenlog_success "Desktop workspace dependencies installed"elif _electron_pkg_staged_missing_dist "$INSTALL_DIR"; thenlog_warn "Desktop dependency install failed with a missing Electron dist; attempting self-heal..."@@ -3617,7 +3617,7 @@ install_desktop() {fi# (c) GitHub blocked → mirror fallback (#47266).- if [ "$pack_ok" = false ] && [ -z "${ELECTRON_MIRROR:-}" ]; then+ if [ "$pack_ok" = false ] && [ -z "${ELECTRON_MIRROR:-}" ] && ! _electron_dist_ok "$INSTALL_DIR"; thenlog_warn "Desktop build still failing — the Electron download from GitHub looks blocked."log_warn "Re-downloading Electron via a public mirror ($DESKTOP_ELECTRON_FALLBACK_MIRROR), then rebuilding..."log_warn " (set ELECTRON_MIRROR yourself to use a different/trusted mirror)"@@ -3633,9 +3633,11 @@ install_desktop() {# the binary download is blocked/throttled (firewall, proxy, region) and# the mirror fallback above also couldn't reach a host. Try a mirror you# trust and rebuild (@electron/get honors ELECTRON_MIRROR):- log_info "If the log shows Electron download retries, rebuild via a reachable mirror:"- log_info " ELECTRON_MIRROR=<mirror-base-url> \\"- log_info " bash -c 'cd \"$desktop_dir\" && CSC_IDENTITY_AUTO_DISCOVERY=false npm run pack'"+ if ! _electron_dist_ok "$INSTALL_DIR"; then+ log_info "If the log shows Electron download retries, rebuild via a reachable mirror:"+ log_info " ELECTRON_MIRROR=<mirror-base-url> \\"+ log_info " bash -c 'cd \"$desktop_dir\" && CSC_IDENTITY_AUTO_DISCOVERY=false npm run pack'"+ filog_info "Otherwise build manually: cd $desktop_dir && npm run pack"return 1fi