fix: resolve node-pty binaries from unpacked asar in Copilot shim

This commit is contained in:
deepak1556
2026-07-02 21:48:06 +09:00
parent e7654a9d63
commit 4e5cfda64f
2 changed files with 29 additions and 5 deletions
@@ -52,11 +52,19 @@ async function _ensureNodePtyShim(extensionPath: string, vscodeAppRoot: string,
}
export async function resolveNodePtySourcePath(vscodeAppRoot: string, logService: ILogService): Promise<string> {
const nodePtyRoot = path.join(vscodeAppRoot, 'node_modules', 'node-pty');
const candidatePaths = [
path.join(nodePtyRoot, 'build', 'Release'),
path.join(nodePtyRoot, 'prebuilds', process.platform + '-' + process.arch),
];
// In a packaged build VS Code's `node_modules` is bundled into a
// `node_modules.asar` archive and native binaries are extracted alongside it
// into `node_modules.asar.unpacked`. Check both roots so the shim works in
// development (plain `node_modules`) and in a packaged install
// (`node_modules.asar.unpacked`).
const nodeModulesRoots = ['node_modules', 'node_modules.asar.unpacked'];
const candidatePaths = nodeModulesRoots.flatMap(root => {
const nodePtyRoot = path.join(vscodeAppRoot, root, 'node-pty');
return [
path.join(nodePtyRoot, 'build', 'Release'),
path.join(nodePtyRoot, 'prebuilds', process.platform + '-' + process.arch),
];
});
for (const candidatePath of candidatePaths) {
if (await isDirectory(candidatePath)) {
@@ -38,6 +38,22 @@ describe('nodePtyShim', () => {
await expect(resolveNodePtySourcePath(testDir, logService)).resolves.toBe(prebuildDir);
});
it('resolves node-pty from node_modules.asar.unpacked in a packaged build', async () => {
const unpackedBuildDir = join(testDir, 'node_modules.asar.unpacked', 'node-pty', 'build', 'Release');
await mkdir(unpackedBuildDir, { recursive: true });
await expect(resolveNodePtySourcePath(testDir, logService)).resolves.toBe(unpackedBuildDir);
});
it('prefers plain node_modules over node_modules.asar.unpacked', async () => {
const buildDir = join(testDir, 'node_modules', 'node-pty', 'build', 'Release');
const unpackedBuildDir = join(testDir, 'node_modules.asar.unpacked', 'node-pty', 'build', 'Release');
await mkdir(buildDir, { recursive: true });
await mkdir(unpackedBuildDir, { recursive: true });
await expect(resolveNodePtySourcePath(testDir, logService)).resolves.toBe(buildDir);
});
it('throws when node-pty binaries are missing', async () => {
await expect(resolveNodePtySourcePath(testDir, logService)).rejects.toThrow('Unable to find node-pty binaries');
});