From 16a80b81033b82d0873748b13ca8a672399afbff Mon Sep 17 00:00:00 2001 From: arthur791004 Date: Wed, 13 May 2026 22:57:06 +0800 Subject: [PATCH] fix(unix): don't rewrite app.asar.unpacked paths a second time MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit helperPath.replace('app.asar', 'app.asar.unpacked') matches the first occurrence. When helperPath already contains 'app.asar.unpacked/...' (e.g. a caller of node-pty that itself lives inside app.asar.unpacked, bypassing Electron's asar shim), the substring 'app.asar' matches the prefix of 'app.asar.unpacked' and we produce 'app.asar.unpacked.unpacked/...' — a path that doesn't exist on disk. posix_spawn then fails with ENOENT and node-pty throws the misleading "posix_spawnp failed.". Skip each rewrite when the unpacked variant is already present. Fixes #923. --- src/unixTerminal.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/unixTerminal.ts b/src/unixTerminal.ts index 2776d501..99a6c5e1 100644 --- a/src/unixTerminal.ts +++ b/src/unixTerminal.ts @@ -16,8 +16,18 @@ const native = loadNativeModule('pty'); const pty: IUnixNative = native.module; let helperPath = native.dir + '/spawn-helper'; helperPath = path.resolve(__dirname, helperPath); -helperPath = helperPath.replace('app.asar', 'app.asar.unpacked'); -helperPath = helperPath.replace('node_modules.asar', 'node_modules.asar.unpacked'); +// String.prototype.replace matches the first occurrence, so when helperPath +// already contains 'app.asar.unpacked' (e.g. a caller of node-pty that +// itself lives in app.asar.unpacked) the substring 'app.asar' matches the +// prefix of 'app.asar.unpacked' and we'd produce 'app.asar.unpacked.unpacked' +// — a path that doesn't exist on disk. Skip each rewrite if the unpacked +// variant is already present. +if (helperPath.indexOf('app.asar.unpacked') === -1) { + helperPath = helperPath.replace('app.asar', 'app.asar.unpacked'); +} +if (helperPath.indexOf('node_modules.asar.unpacked') === -1) { + helperPath = helperPath.replace('node_modules.asar', 'node_modules.asar.unpacked'); +} const DEFAULT_FILE = 'sh'; const DEFAULT_NAME = 'xterm';