Skip to content

Commit edc63d8

Browse files
committed
Test error
1 parent e0fa281 commit edc63d8

File tree

6 files changed

+26
-9
lines changed

6 files changed

+26
-9
lines changed

packages/process/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "Theia process support.",
55
"dependencies": {
66
"@theia/core": "1.48.0",
7-
"node-pty": "1.0.0",
7+
"node-pty": "1.1.0-beta5",
88
"string-argv": "^0.1.1",
99
"tslib": "^2.6.2"
1010
},

packages/process/src/common/process-manager-types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export interface IProcessExitEvent {
4242
* Data emitted when a process has been successfully started.
4343
*/
4444
export interface IProcessStartEvent {
45+
readonly pid?: number;
4546
}
4647

4748
/**

packages/process/src/node/process.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ export abstract class Process implements ManagedProcess {
123123
return this.closeEmitter.event;
124124
}
125125

126-
protected emitOnStarted(): void {
127-
this.startEmitter.fire({});
126+
protected emitOnStarted(event?: IProcessStartEvent): void {
127+
this.startEmitter.fire(event ?? {});
128128
}
129129

130130
/**

packages/process/src/node/terminal-process.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { DevNullStream } from './dev-null-stream';
2525
import { signame } from './utils';
2626
import { PseudoPty } from './pseudo-pty';
2727
import { Writable } from 'stream';
28+
import * as fs from 'fs';
2829

2930
export const TerminalProcessOptions = Symbol('TerminalProcessOptions');
3031
export interface TerminalProcessOptions extends ProcessOptions {
@@ -144,13 +145,26 @@ export class TerminalProcess extends Process {
144145
* @returns the terminal PTY and a stream by which it may be sent input
145146
*/
146147
private createPseudoTerminal(command: string, options: TerminalProcessOptions, ringBuffer: MultiRingBuffer): { terminal: IPty | undefined, inputStream: Writable } {
148+
// Only test the command file on non-Windows platforms.
149+
// On Windows, calling `spawn` on an invalid file throws an error. On Linux/macOS, it does not.
150+
if (!isWindows) {
151+
try {
152+
const stat = fs.statSync(command);
153+
if (stat.isDirectory()) {
154+
throw new Error('Permission denied');
155+
}
156+
} catch (error) {
157+
throw new Error('File not found: ' + command);
158+
}
159+
}
160+
147161
const terminal = spawn(
148162
command,
149163
(isWindows && options.commandLine) || options.args || [],
150164
options.options || {}
151165
);
152166

153-
process.nextTick(() => this.emitOnStarted());
167+
setImmediate(() => this.emitOnStarted({ pid: terminal.pid }));
154168

155169
// node-pty actually wait for the underlying streams to be closed before emitting exit.
156170
// We should emulate the `exit` and `close` sequence.

packages/terminal/src/node/shell-terminal-server.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ export class ShellTerminalServer extends BaseTerminalServer implements IShellTer
6969
private spawnAsPromised(command: string, args: string[]): Promise<string> {
7070
return new Promise((resolve, reject) => {
7171
let stdout = '';
72-
const child = cp.spawn(command, args);
72+
const child = cp.spawn(command, args, {
73+
shell: true
74+
});
7375
if (child.pid) {
7476
child.stdout.on('data', (data: Buffer) => {
7577
stdout += data.toString();

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8594,10 +8594,10 @@ node-preload@^0.2.1:
85948594
dependencies:
85958595
process-on-spawn "^1.0.0"
85968596

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

0 commit comments

Comments
 (0)