fix(unix): do not rewrite already-unpacked asar helper paths - #953
Open
fei (feiiiiii5) wants to merge 1 commit into
Open
fix(unix): do not rewrite already-unpacked asar helper paths#953fei (feiiiiii5) wants to merge 1 commit into
fei (feiiiiii5) wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #923. When node-pty is installed under
app.asar.unpacked(the layout Electron apps use for native modules), thehelperPathrewrite insrc/unixTerminal.tsdouble-applies:String.prototype.replacematches the first occurrence, which is theapp.asarprefix insideapp.asar.unpacked, producingapp.asar.unpacked.unpacked/.../spawn-helper. That path does not exist, so on macOS every PTY spawn fails withposix_spawnp failed.(macOS is the only platform that spawns through thespawn-helperbinary).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: extractresolveSpawnHelperPath(nativeDir, moduleDir); skip theapp.asar/node_modules.asarrewrite when the.unpackedvariant is already present.src/unixTerminal.test.ts: 4 regression tests covering packed → unpacked rewrite and already-unpacked (no double rewrite) for bothapp.asarandnode_modules.asar.Verification
'/app/node_modules.asar.unpacked.unpacked/node-pty/build/Release/spawn-helper'(expected.../app.asar.unpacked/...).eslint src/clean.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/bashsucceeds. Captured helper path before fix:.../app.asar.unpacked.unpacked/node_modules/node-pty/build/Release/spawn-helper; after: the correct single-unpacked path.Notes
posix_spawnp failedon macOS 26 in its minimal-mode persistent bash).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.