Skip to content

Commit

Permalink
Test error
Browse files Browse the repository at this point in the history
  • Loading branch information
msujew committed Apr 18, 2024
1 parent e0fa281 commit edc63d8
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 9 deletions.
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.48.0",
"node-pty": "1.0.0",
"node-pty": "1.1.0-beta5",
"string-argv": "^0.1.1",
"tslib": "^2.6.2"
},
Expand Down
1 change: 1 addition & 0 deletions packages/process/src/common/process-manager-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export interface IProcessExitEvent {
* Data emitted when a process has been successfully started.
*/
export interface IProcessStartEvent {
readonly pid?: number;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/process/src/node/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ export abstract class Process implements ManagedProcess {
return this.closeEmitter.event;
}

protected emitOnStarted(): void {
this.startEmitter.fire({});
protected emitOnStarted(event?: IProcessStartEvent): void {
this.startEmitter.fire(event ?? {});
}

/**
Expand Down
16 changes: 15 additions & 1 deletion packages/process/src/node/terminal-process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { DevNullStream } from './dev-null-stream';
import { signame } from './utils';
import { PseudoPty } from './pseudo-pty';
import { Writable } from 'stream';
import * as fs from 'fs';

export const TerminalProcessOptions = Symbol('TerminalProcessOptions');
export interface TerminalProcessOptions extends ProcessOptions {
Expand Down Expand Up @@ -144,13 +145,26 @@ export class TerminalProcess extends Process {
* @returns the terminal PTY and a stream by which it may be sent input
*/
private createPseudoTerminal(command: string, options: TerminalProcessOptions, ringBuffer: MultiRingBuffer): { terminal: IPty | undefined, inputStream: Writable } {
// Only test the command file on non-Windows platforms.
// On Windows, calling `spawn` on an invalid file throws an error. On Linux/macOS, it does not.
if (!isWindows) {
try {
const stat = fs.statSync(command);
if (stat.isDirectory()) {
throw new Error('Permission denied');
}
} catch (error) {
throw new Error('File not found: ' + command);
}
}

const terminal = spawn(
command,
(isWindows && options.commandLine) || options.args || [],
options.options || {}
);

process.nextTick(() => this.emitOnStarted());
setImmediate(() => this.emitOnStarted({ pid: terminal.pid }));

// node-pty actually wait for the underlying streams to be closed before emitting exit.
// We should emulate the `exit` and `close` sequence.
Expand Down
4 changes: 3 additions & 1 deletion packages/terminal/src/node/shell-terminal-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ export class ShellTerminalServer extends BaseTerminalServer implements IShellTer
private spawnAsPromised(command: string, args: string[]): Promise<string> {
return new Promise((resolve, reject) => {
let stdout = '';
const child = cp.spawn(command, args);
const child = cp.spawn(command, args, {
shell: true
});
if (child.pid) {
child.stdout.on('data', (data: Buffer) => {
stdout += data.toString();
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8594,10 +8594,10 @@ node-preload@^0.2.1:
dependencies:
process-on-spawn "^1.0.0"

node-pty@1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/node-pty/-/node-pty-1.0.0.tgz#7daafc0aca1c4ca3de15c61330373af4af5861fd"
integrity sha512-wtBMWWS7dFZm/VgqElrTvtfMq4GzJ6+edFI0Y0zyzygUSZMgZdraDUMUhCIvkjhJjme15qWmbyJbtAx4ot4uZA==
node-pty@1.1.0-beta5:
version "1.1.0-beta5"
resolved "https://registry.yarnpkg.com/node-pty/-/node-pty-1.1.0-beta5.tgz#364386b7058a93070234064f13164ec1ef914993"
integrity sha512-j3QdgFHnLY0JWxztrvM3g67RaQLOGvytv+C6mFu0PqD+JILlzqfwuoyqRqVxdZZjoOTUXPfSRj1qPVCaCH+eOw==
dependencies:
nan "^2.17.0"

Expand Down

0 comments on commit edc63d8

Please sign in to comment.