Skip to content

The agent that grows with you

fix(desktop): name the half-installed get-windows dir and its repair when staging degrades

teknium17ee8f5528d98
diff --git a/apps/desktop/scripts/stage-native-deps.mjs b/apps/desktop/scripts/stage-native-deps.mjs
index 43805a07690..d200facbbbc 100644
--- a/apps/desktop/scripts/stage-native-deps.mjs
+++ b/apps/desktop/scripts/stage-native-deps.mjs
@@ -640,11 +640,46 @@ export function installGetWindowsNativeBinding(
}
}
+/**
+ * A get-windows directory that exists but does not resolve as a package: an
+ * `npm install` interrupted by a running Desktop/gateway holding files open
+ * (TAR_ENTRY_ERROR on Windows) leaves the binding on disk without
+ * package.json, and npm never revisits a directory that already exists, so the
+ * tree stays broken across every later update. Walks the same
+ * `node_modules` ancestors `require.resolve` does (the workspace root hoist or
+ * the app-local copy).
+ */
+export function findHalfInstalledGetWindowsDir(startDir = projectRoot, exists = existsSync) {
+ for (let dir = startDir; ; dir = dirname(dir)) {
+ const candidate = join(dir, 'node_modules', 'get-windows')
+ if (exists(candidate)) return candidate
+ if (dirname(dir) === dir) return null
+ }
+}
+
+/** The warning printed when get-windows cannot be staged; exported for tests. */
+export function missingGetWindowsWarning({ platform, arch, halfInstalledDir }) {
+ const lines = [
+ `[stage-native-deps] get-windows not installed (optional dep skipped for ${platform}-${arch}); ` +
+ 'read_window_below will be unavailable in this build'
+ ]
+ if (halfInstalledDir) {
+ lines.push(
+ `[stage-native-deps] ${halfInstalledDir} exists but is not a loadable package — an ` +
+ 'interrupted npm install left it half-extracted (look for TAR_ENTRY_ERROR in the install log). ' +
+ 'To restore read_window_below: close every Hermes window and gateway, then run ' +
+ '`npm install get-windows --save-exact` in apps/desktop and rebuild with `hermes desktop --force-build`.'
+ )
+ }
+ return lines.join('\n')
+}
+
export function stageGetWindows(
{
platform = process.platform,
arch = process.arch,
- resolveRoot = resolveGetWindowsRoot
+ resolveRoot = resolveGetWindowsRoot,
+ findHalfInstalledDir = findHalfInstalledGetWindowsDir
} = {}
) {
const srcRoot = resolveRoot()
@@ -656,8 +691,7 @@ export function stageGetWindows(
// already fails soft, so we disable only window enumeration instead of failing
// the entire Desktop build (which would strand users on an old version).
console.warn(
- `[stage-native-deps] get-windows not installed (optional dep skipped for ${platform}-${arch}); ` +
- 'read_window_below will be unavailable in this build'
+ missingGetWindowsWarning({ platform, arch, halfInstalledDir: findHalfInstalledDir() })
)
return undefined
}
diff --git a/apps/desktop/scripts/stage-native-deps.test.mjs b/apps/desktop/scripts/stage-native-deps.test.mjs
index 4e74bccc5ed..533b53b3edc 100644
--- a/apps/desktop/scripts/stage-native-deps.test.mjs
+++ b/apps/desktop/scripts/stage-native-deps.test.mjs
@@ -6,6 +6,7 @@ import { pathToFileURL } from 'node:url'
import { test } from 'vitest'
import {
+ findHalfInstalledGetWindowsDir,
installGetWindowsNativeBinding,
stageGetWindows,
stageGetWindowsInto,
@@ -647,33 +648,63 @@ test('darwin staging ships the Swift helper executable and the rewritten windows
// ─── stageGetWindows (optionalDependency gate) ──────────────────────
//
-// get-windows is an optionalDependency: on Linux its node-pre-gyp install
-// script fails because no prebuilt exists. Windows ARM64 has the same package
-// state: its prebuilt URL returns 404 and npm may omit the optional dependency.
-// Staging skips those unsupported targets, but supported native targets remain
-// a hard failure when the package is missing.
-
-test('linux staging skips when get-windows is absent (optional dep skipped by npm)', () => {
- assert.equal(stageGetWindows({ platform: 'linux', resolveRoot: () => null }), undefined)
-})
-
-test('darwin staging fails when get-windows is absent', () => {
- assert.throws(
- () => stageGetWindows({ platform: 'darwin', arch: 'arm64', resolveRoot: () => null }),
- /get-windows is not installed/
- )
+// get-windows is an optionalDependency: npm omits it when its install script
+// fails (no prebuilt for Linux / Windows ARM64) and a Windows in-place update
+// can leave it half-extracted when a running Desktop holds files open
+// (#90829). Either way only read_window_below is lost, so staging degrades
+// with a warning on every platform instead of failing the whole build.
+
+test('staging degrades (never throws) when get-windows is absent on every platform', () => {
+ const warnings = []
+ const origWarn = console.warn
+ console.warn = (msg) => warnings.push(String(msg))
+ try {
+ for (const [platform, arch] of [['linux', 'x64'], ['darwin', 'arm64'], ['win32', 'arm64'], ['win32', 'x64']]) {
+ assert.equal(
+ stageGetWindows({ platform, arch, resolveRoot: () => null, findHalfInstalledDir: () => null }),
+ undefined,
+ `${platform}-${arch} must degrade`
+ )
+ }
+ } finally {
+ console.warn = origWarn
+ }
+ assert.equal(warnings.length, 4)
+ assert.ok(warnings.every((w) => w.includes('read_window_below will be unavailable')))
+ assert.ok(warnings.every((w) => !w.includes('npm install get-windows')), 'no repair hint without a stale dir')
})
-test('win32-arm64 staging skips when get-windows is absent after its optional install fails', () => {
- assert.equal(
- stageGetWindows({ platform: 'win32', arch: 'arm64', resolveRoot: () => null }),
- undefined
- )
-})
+test('a half-installed get-windows dir is found and named in a repair hint', () => {
+ const tmp = fs.mkdtempSync(join(os.tmpdir(), 'half-installed-'))
+ try {
+ // Reporter's state: node_modules/get-windows exists (binding extracted) but
+ // package.json never was, so require.resolve fails while the dir is there.
+ const app = join(tmp, 'apps', 'desktop')
+ const stale = join(tmp, 'node_modules', 'get-windows', 'lib', 'binding')
+ fs.mkdirSync(app, { recursive: true })
+ fs.mkdirSync(stale, { recursive: true })
+ assert.equal(findHalfInstalledGetWindowsDir(app), join(tmp, 'node_modules', 'get-windows'))
+
+ const warnings = []
+ const origWarn = console.warn
+ console.warn = (msg) => warnings.push(String(msg))
+ try {
+ stageGetWindows({
+ platform: 'win32',
+ arch: 'x64',
+ resolveRoot: () => null,
+ findHalfInstalledDir: () => findHalfInstalledGetWindowsDir(app)
+ })
+ } finally {
+ console.warn = origWarn
+ }
+ assert.equal(warnings.length, 1)
+ assert.match(warnings[0], /npm install get-windows --save-exact/)
+ assert.ok(warnings[0].includes(join(tmp, 'node_modules', 'get-windows')))
-test('win32-x64 staging fails when get-windows is absent', () => {
- assert.throws(
- () => stageGetWindows({ platform: 'win32', arch: 'x64', resolveRoot: () => null }),
- /get-windows is not installed/
- )
+ fs.rmSync(join(tmp, 'node_modules'), { recursive: true, force: true })
+ assert.equal(findHalfInstalledGetWindowsDir(app), null)
+ } finally {
+ fs.rmSync(tmp, { recursive: true, force: true })
+ }
})
diff --git a/website/docs/user-guide/desktop.md b/website/docs/user-guide/desktop.md
index 077dad71ff8..5624f2e8e43 100644
--- a/website/docs/user-guide/desktop.md
+++ b/website/docs/user-guide/desktop.md
@@ -603,6 +603,8 @@ ELECTRON_MIRROR=https://npmmirror.com/mirrors/electron/ \
**Other native downloads (e.g. the `get-windows` prebuilt on Windows) that need a mirror:** put the npm keys in `$HERMES_HOME/npmrc` (`%LOCALAPPDATA%\hermes\npmrc` on Windows, `~/.hermes/npmrc` elsewhere) — for example `node_get_windows_binary_host_mirror=https://<mirror>/sindresorhus/get-windows/releases/download/`. Every `npm ci`/`npm run` the updater spawns (desktop, web and TUI builds) points `NPM_CONFIG_USERCONFIG` at that file when it exists, so the config survives `hermes update`; the repo-root `.npmrc` is git-tracked and gets autostashed on every update, and `~/.npmrc` may be missed because the desktop hand-off inherits the GUI's environment. An `NPM_CONFIG_USERCONFIG` you set yourself is never overridden.
+**If `get-windows` is missing or half-installed:** the build no longer fails — it prints `[stage-native-deps] get-windows not installed ... read_window_below will be unavailable in this build` and ships without the `read_window_below` tool. When the package directory exists but is not loadable (a Windows in-place update interrupted by a running Hermes window, `TAR_ENTRY_ERROR` in the install log), the same warning names the directory and the repair: close every Hermes window and gateway, run `npm install get-windows --save-exact` in `apps/desktop`, then `hermes desktop --force-build`.
+
To clear a corrupt cached zip by hand:
```bash