Skip to content

Commit

Permalink
Update node-pty to 1.1.0-beta27 (#14677)
Browse files Browse the repository at this point in the history
Fixes #14026

Contributed on behalf of STMicroelectronics

Signed-off-by: Thomas Mäder <[email protected]>
  • Loading branch information
tsmaeder authored Jan 6, 2025
1 parent 3207cc0 commit 202ab63
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 44 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [windows-2019, ubuntu-22.04, macos-14]
node: [18.x, 20.x]
os: [windows-2022, ubuntu-22.04, macos-14]
node: [20.x, 22.x]

runs-on: ${{ matrix.os }}
timeout-minutes: 60
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export class NativeWebpackPlugin {
const dllFile = require.resolve('node-pty/build/Release/winpty.dll');
const targetDllFile = path.join(targetDirectory, 'winpty.dll');
await this.copyExecutable(dllFile, targetDllFile);
} else {
} else if (process.platform === 'darwin') {
const sourceFile = require.resolve('node-pty/build/Release/spawn-helper');
const targetFile = path.join(targetDirectory, 'spawn-helper');
await this.copyExecutable(sourceFile, targetFile);
Expand Down
7 changes: 6 additions & 1 deletion packages/core/src/browser/test/jsdom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ export function enableJSDOM(): () => void {
});
(global as any)['document'] = dom.window.document;
(global as any)['window'] = dom.window;
(global as any)['navigator'] = { userAgent: 'node.js', platform: 'Mac' };
try {
(global as any)['navigator'] = { userAgent: 'node.js', platform: 'Mac' };

} catch (e) {
// node 21+ already has a navigator object
}

const toCleanup: string[] = [];
Object.getOwnPropertyNames((dom.window as any)).forEach(property => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ export class TestWebSocketChannelSetup {
path: string
}) {
const address = (server.address() as AddressInfo);
const url = `ws://${address.address}:${address.port}${servicesPath}`;
let url;
if (address.family === 'IPv6') {
url = `ws://[${address.address}]:${address.port}${servicesPath}`;
} else {
url = `ws://${address.address}:${address.port}${servicesPath}`;
}
this.connectionProvider = this.createConnectionProvider(url);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/process/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Theia process support.",
"dependencies": {
"@theia/core": "1.57.0",
"node-pty": "0.11.0-beta24",
"node-pty": "1.1.0-beta27",
"string-argv": "^0.1.1",
"tslib": "^2.6.2"
},
Expand Down
6 changes: 2 additions & 4 deletions packages/process/src/node/raw-process.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { RawProcessFactory } from './raw-process';
import * as temp from 'temp';
import * as fs from 'fs';
import * as path from 'path';
import { isWindows } from '@theia/core';
import { IProcessStartEvent, ProcessErrorEvent } from './process';

/* Allow to create temporary files, but delete them when we're done. */
Expand Down Expand Up @@ -80,10 +79,9 @@ describe('RawProcess', function (): void {
proc.onExit(reject);
});

// On Windows, we get 'UNKNOWN'.
const expectedCode = isWindows ? 'UNKNOWN' : 'EACCES';
// do not check the exact error code as this seems to change between nodejs version

expect(error.code).eq(expectedCode);
expect(error).to.exist;
});

it('test start event', function (): Promise<IProcessStartEvent> {
Expand Down
22 changes: 10 additions & 12 deletions packages/process/src/node/terminal-process.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,17 @@ describe('TerminalProcess', function (): void {
this.timeout(20_000);

it('test error on non existent path', async function (): Promise<void> {
const error = await new Promise<ProcessErrorEvent>((resolve, reject) => {
const error = await new Promise<ProcessErrorEvent | IProcessExitEvent>((resolve, reject) => {
const proc = terminalProcessFactory({ command: '/non-existent' });
proc.onStart(reject);
proc.onError(resolve);
proc.onExit(reject);
proc.onExit(resolve);
});

expect(error.code).eq('ENOENT');
if (isWindows) {
expect(error.code).eq('ENOENT');
} else {
expect(error.code).eq(1);
}
});

it('test implicit .exe (Windows only)', async function (): Promise<void> {
Expand All @@ -66,20 +69,15 @@ describe('TerminalProcess', function (): void {
});

it('test error on trying to execute a directory', async function (): Promise<void> {
const error = await new Promise<ProcessErrorEvent>((resolve, reject) => {
const error = await new Promise<ProcessErrorEvent | IProcessExitEvent>((resolve, reject) => {
const proc = terminalProcessFactory({ command: __dirname });
proc.onStart(reject);
proc.onError(resolve);
proc.onExit(reject);
proc.onExit(resolve);
});

if (isWindows) {
// On Windows, node-pty returns us a "File not found" message, so we can't really differentiate this case
// from trying to execute a non-existent file. node's child_process.spawn also returns ENOENT, so it's
// probably the best we can get.
expect(error.code).eq('ENOENT');
} else {
expect(error.code).eq('EACCES');
expect(error.code).eq(1);
}
});

Expand Down
4 changes: 4 additions & 0 deletions packages/process/src/node/terminal-process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ export class TerminalProcess extends Process {
// node-pty actually wait for the underlying streams to be closed before emitting exit.
// We should emulate the `exit` and `close` sequence.
terminal.onExit(({ exitCode, signal }) => {
// see https://github.com/microsoft/node-pty/issues/751
if (exitCode === undefined) {
exitCode = 0;
}
// Make sure to only pass either code or signal as !undefined, not
// both.
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,7 @@ describe('ripgrep-search-in-workspace-server', function (): void {
});

if (isWindows) {
expect(errorString).contains('An error happened while searching (UNKNOWN).');
expect(errorString).contains('An error happened while searching');
} else {
expect(errorString).contains('could not execute the ripgrep (rg) binary');
}
Expand Down
12 changes: 3 additions & 9 deletions packages/task/src/node/task-server.slow-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import * as https from 'https';
import { isWindows, isOSX } from '@theia/core/lib/common/os';
import { FileUri } from '@theia/core/lib/node';
import { terminalsPath } from '@theia/terminal/lib/common/terminal-protocol';
import { expectThrowsAsync } from '@theia/core/lib/common/test/expect';
import { TestWebSocketChannelSetup } from '@theia/core/lib/node/messaging/test/test-web-socket-channel';
import { expect } from 'chai';
import URI from '@theia/core/lib/common/uri';
Expand Down Expand Up @@ -199,7 +198,7 @@ describe('Task server / back-end', function (): void {
// possible on what node's child_process module does.
if (isWindows) {
// On Windows, node-pty just reports an exit code of 0.
expect(exitStatus).equals(0);
expect(exitStatus).equals(1);
} else {
// On Linux/macOS, node-pty sends SIGHUP by default, for some reason.
expect(exitStatus).equals('SIGHUP');
Expand All @@ -218,8 +217,8 @@ describe('Task server / back-end', function (): void {
// currently. Ideally, its behavior should be aligned as much as
// possible on what node's child_process module does.
if (isWindows) {
// On Windows, node-pty just reports an exit code of 0.
expect(exitStatus).equals(0);
// On Windows, node-pty just reports an exit code of 1.
expect(exitStatus).equals(1);
} else {
// On Linux/macOS, node-pty sends SIGHUP by default, for some reason.
expect(exitStatus).equals('SIGHUP');
Expand Down Expand Up @@ -251,11 +250,6 @@ describe('Task server / back-end', function (): void {
}
});

it('task using raw process can handle command that does not exist', async function (): Promise<void> {
const p = taskServer.run(createProcessTaskConfig2('process', bogusCommand, []), wsRoot);
await expectThrowsAsync(p, 'ENOENT');
});

it('getTasks(ctx) returns tasks according to created context', async function (): Promise<void> {
const context1 = 'aContext';
const context2 = 'anotherContext';
Expand Down
5 changes: 0 additions & 5 deletions packages/terminal/src/node/terminal-server.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,4 @@ describe('TerminalServer', function (): void {
const createResult = await terminalServer.create({ command: process.execPath, 'args': args });
expect(createResult).to.be.greaterThan(-1);
});

it('test terminal create from non-existent path', async function (): Promise<void> {
const createError = await terminalServer.create({ command: '/non-existent' });
expect(createError).eq(-1);
});
});
14 changes: 7 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9185,7 +9185,7 @@ mute-stream@^1.0.0, mute-stream@~1.0.0:
resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-1.0.0.tgz#e31bd9fe62f0aed23520aa4324ea6671531e013e"
integrity sha512-avsJQhyd+680gKXyG/sQc0nXaC6rBkPOfyHYcFb9+hdkqQkR9bdnkJ0AMZhke0oesPqIO+mFFJ+IdBc7mst4IA==

[email protected], nan@^2.14.0, nan@^2.17.0, nan@^2.18.0, nan@^2.19.0:
[email protected], nan@^2.14.0, nan@^2.18.0, nan@^2.19.0:
version "2.20.0"
resolved "https://registry.yarnpkg.com/nan/-/nan-2.20.0.tgz#08c5ea813dd54ed16e5bd6505bf42af4f7838ca3"
integrity sha512-bk3gXBZDGILuuo/6sKtr0DQmSThYHLtNCdSdXk9YkxD/jK6X2vmCyyXBBxyqZ4XcnzTyYEAThfX3DCEnLf6igw==
Expand Down Expand Up @@ -9272,7 +9272,7 @@ node-addon-api@^4.3.0:
resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-4.3.0.tgz#52a1a0b475193e0928e98e0426a0d1254782b77f"
integrity sha512-73sE9+3UaLYYFmDsFZnqCInzPyh3MqIwZO9cw58yIqAZhONrrabrYyYe3TuIqtIiOuTXVhsGau8hcrhhwSsDIQ==

node-addon-api@^7.0.0:
node-addon-api@^7.0.0, node-addon-api@^7.1.0:
version "7.1.1"
resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-7.1.1.tgz#1aba6693b0f255258a049d621329329322aad558"
integrity sha512-5m3bsyrjFWE1xf7nz7YXdN4udnVtXK6/Yfgn5qnahL6bCkf2yKt4k3nuTKAtT4r3IG8JNR2ncsIMdZuAzJjHQQ==
Expand Down Expand Up @@ -9356,12 +9356,12 @@ node-preload@^0.2.1:
dependencies:
process-on-spawn "^1.0.0"

node-pty@0.11.0-beta24:
version "0.11.0-beta24"
resolved "https://registry.yarnpkg.com/node-pty/-/node-pty-0.11.0-beta24.tgz#084841017187656edaf14b459946c4a1d7cf8392"
integrity sha512-CzItw3hitX+wnpw9dHA/A+kcbV7ETNKrsyQJ+s0ZGzsu70+CSGuIGPLPfMnAc17vOrQktxjyRQfaqij75GVJFw==
node-pty@1.1.0-beta27:
version "1.1.0-beta27"
resolved "https://registry.yarnpkg.com/node-pty/-/node-pty-1.1.0-beta27.tgz#08a76876d345a03dd181f0b81fa7eb26e31b39b3"
integrity sha512-r0nRVgunspo/cBmf/eR+ultBrclxqldaL6FhiTLEmC4VcyKJxhluRK5d8EtbHYPLt8DqPKMnCakJDxreQynpnw==
dependencies:
nan "^2.17.0"
node-addon-api "^7.1.0"

node-releases@^2.0.18:
version "2.0.18"
Expand Down

0 comments on commit 202ab63

Please sign in to comment.