Skip to content

fix(unix): do not rewrite already-unpacked asar helper paths - #953

Open
fei (feiiiiii5) wants to merge 1 commit into
microsoft:mainfrom
feiiiiii5:fix/helperpath-asar-unpacked
Open

fix(unix): do not rewrite already-unpacked asar helper paths#953
fei (feiiiiii5) wants to merge 1 commit into
microsoft:mainfrom
feiiiiii5:fix/helperpath-asar-unpacked

Conversation

@feiiiiii5

Copy link
Copy Markdown

Summary

Fixes #923. When node-pty is installed under app.asar.unpacked (the layout Electron apps use for native modules), the helperPath rewrite in src/unixTerminal.ts double-applies:

helperPath.replace('app.asar', 'app.asar.unpacked');

String.prototype.replace matches the first occurrence, which is the app.asar prefix inside app.asar.unpacked, producing app.asar.unpacked.unpacked/.../spawn-helper. That path does not exist, so on macOS every PTY spawn fails with posix_spawnp failed. (macOS is the only platform that spawns through the spawn-helper binary).

This PR extracts the resolution into resolveSpawnHelperPath() and skips each rewrite when the unpacked variant is already present. It is the same fix as #924 but with the logic factored into a pure, exported function so it can be regression-tested.

Changes

  • src/unixTerminal.ts: extract resolveSpawnHelperPath(nativeDir, moduleDir); skip the app.asar / node_modules.asar rewrite when the .unpacked variant is already present.
  • src/unixTerminal.test.ts: 4 regression tests covering packed → unpacked rewrite and already-unpacked (no double rewrite) for both app.asar and node_modules.asar.

Verification

  • Pre-fix (regression tests fail): with the unguarded rewrite, 2 of 4 new tests fail with the exact bug path:
    '/app/node_modules.asar.unpacked.unpacked/node-pty/build/Release/spawn-helper' (expected .../app.asar.unpacked/...).
  • Post-fix: 4/4 pass; full suite 28 passing on macOS; eslint src/ clean.
  • End-to-end (real runtime): reproduced the failure inside the actual Electron runtime of a packaged app whose node-pty lives under app.asar.unpacked (posix_spawnp failed. for every spawn), then applied this change to that node-pty and confirmed a real PTY spawn of /bin/bash succeeds. Captured helper path before fix: .../app.asar.unpacked.unpacked/node_modules/node-pty/build/Release/spawn-helper; after: the correct single-unpacked path.

Notes

AI disclosure: this PR was developed with AI assistance (code + tests written with DeepSeek, reviewed and verified by a human) and is signed off by the human contributor.

Extract resolveSpawnHelperPath and skip the app.asar / node_modules.asar
rewrite when the unpacked variant is already present. When node-pty is
installed under app.asar.unpacked (e.g. an Electron app that unpacks
native modules), String.prototype.replace matches the 'app.asar' prefix
inside 'app.asar.unpacked' and produces 'app.asar.unpacked.unpacked' —
a path that does not exist, so PTY spawn fails with 'posix_spawnp
failed.' on macOS.

Adds regression tests for both the packed and already-unpacked forms.

Co-authored-by: DeepSeek
Signed-off-by: fei <204683769+feiiiiii5@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

helperPath replace produces 'app.asar.unpacked.unpacked/…' when caller is itself in app.asar.unpacked → posix_spawnp ENOENT

1 participant