Skip to content

Commit 570aece

Browse files
code-asherkylecarbs
authored andcommitted
Get boostrap stuff forking
They don't run yet but seem to be forking correctly now.
1 parent 644e5b4 commit 570aece

File tree

6 files changed

+32
-11
lines changed

6 files changed

+32
-11
lines changed

packages/logger/src/logger.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,6 @@ export class Logger {
260260
if (name) {
261261
this.nameColor = hashStringToColor(name);
262262
}
263-
this.info(`Log level: ${process.env.LOG_LEVEL || "info"}`);
264263
if (process.env.LOG_LEVEL) {
265264
switch (process.env.LOG_LEVEL) {
266265
case "debug": this.level = Level.Debug; break;

packages/protocol/src/browser/command.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as events from "events";
22
import * as stream from "stream";
3-
import { SendableConnection } from "../common/connection";
3+
import { ReadWriteConnection } from "../common/connection";
44
import { ShutdownSessionMessage, ClientMessage, WriteToSessionMessage, ResizeSessionTTYMessage, TTYDimensions as ProtoTTYDimensions, ConnectionOutputMessage, ConnectionCloseMessage } from "../proto";
55

66
export interface TTYDimensions {
@@ -40,11 +40,14 @@ export class ServerProcess extends events.EventEmitter implements ChildProcess {
4040
private _killed: boolean = false;
4141

4242
public constructor(
43-
private readonly connection: SendableConnection,
43+
private readonly connection: ReadWriteConnection,
4444
private readonly id: number,
4545
private readonly hasTty: boolean = false,
4646
) {
4747
super();
48+
this.connection.onMessage((message) => {
49+
this.emit("message", message);
50+
});
4851

4952
if (!this.hasTty) {
5053
delete this.resize;
@@ -131,7 +134,7 @@ export class ServerSocket extends events.EventEmitter implements Socket {
131134
private _connecting: boolean = true;
132135

133136
public constructor(
134-
private readonly connection: SendableConnection,
137+
private readonly connection: ReadWriteConnection,
135138
private readonly id: number,
136139
connectCallback?: () => void,
137140
) {

packages/protocol/src/browser/modules/child_process.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export class CP {
4646

4747
public fork = (modulePath: string, args?: ReadonlyArray<string> | cp.ForkOptions, options?: cp.ForkOptions): cp.ChildProcess => {
4848
//@ts-ignore
49-
return this.client.fork(modulePath, args, options);
49+
return this.client.fork(options && options.env && options.env.AMD_ENTRYPOINT || modulePath, args, options);
5050
}
5151

5252
public spawn = (command: string, args?: ReadonlyArray<string> | cp.SpawnOptions, options?: cp.SpawnOptions): cp.ChildProcess => {

packages/protocol/src/node/command.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as net from "net";
33
import * as nodePty from "node-pty";
44
import * as stream from "stream";
55
import { TextEncoder } from "text-encoding";
6-
import { NewSessionMessage, ServerMessage, SessionDoneMessage, SessionOutputMessage, ShutdownSessionMessage, IdentifySessionMessage, ClientMessage, NewConnectionMessage, ConnectionEstablishedMessage, NewConnectionFailureMessage, ConnectionCloseMessage, ConnectionOutputMessage } from "../proto";
6+
import { NewSessionMessage, ServerMessage, SessionDoneMessage, SessionOutputMessage, IdentifySessionMessage, NewConnectionMessage, ConnectionEstablishedMessage, NewConnectionFailureMessage, ConnectionCloseMessage, ConnectionOutputMessage } from "../proto";
77
import { SendableConnection } from "../common/connection";
88
import { ServerOptions } from "./server";
99

@@ -16,7 +16,7 @@ export interface Process {
1616
killed?: boolean;
1717

1818
on(event: "data", cb: (data: string) => void): void;
19-
on(event: 'exit', listener: (exitCode: number, signal?: number) => void): void;
19+
on(event: "exit", listener: (exitCode: number, signal?: number) => void): void;
2020
write(data: string | Uint8Array): void;
2121
resize?(cols: number, rows: number): void;
2222
kill(signal?: string): void;
@@ -170,4 +170,4 @@ export const handleNewConnection = (connection: SendableConnection, newConnectio
170170
});
171171

172172
return socket;
173-
}
173+
};

packages/server/src/server.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,33 @@ export const createApp = (registerMiddleware?: (app: express.Application) => voi
4444
const server = new Server(connection, options ? {
4545
...options,
4646
forkProvider: (message: NewSessionMessage): ChildProcess => {
47-
let proc: ChildProcess;
47+
const command = message.getCommand();
48+
const childLogger = logger.named(command.split("/").pop()!);
49+
childLogger.debug("Forking...", field("module", command));
4850

51+
let proc: ChildProcess;
4952
if (message.getIsBootstrapFork()) {
50-
proc = forkModule(message.getCommand());
53+
proc = forkModule(command);
5154
} else {
5255
throw new Error("No support for non bootstrap-forking yet");
5356
}
5457

58+
proc.stdout.on("data", (message) => {
59+
childLogger.debug("stdout", field("message", message.toString().trim()));
60+
});
61+
62+
proc.stderr.on("data", (message) => {
63+
childLogger.debug("stderr", field("message", message.toString().trim()));
64+
});
65+
66+
proc.stdin.on("data", (message) => {
67+
childLogger.debug("stdin", field("message", message.toString().trim()));
68+
});
69+
70+
proc.on("exit", (exitCode) => {
71+
childLogger.debug(`Exited with ${exitCode}`);
72+
});
73+
5574
return proc;
5675
},
5776
} : undefined);

packages/server/src/vscode/sharedProcess.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class SharedProcess {
2929
private activeProcess: ChildProcess | undefined;
3030
private ipcHandler: StdioIpcHandler | undefined;
3131
private readonly onStateEmitter: Emitter<SharedProcessEvent>;
32-
private readonly logger = logger.named("SHDR PROC");
32+
private readonly logger = logger.named("SHRD PROC");
3333

3434
public constructor(
3535
private readonly userDataDir: string,

0 commit comments

Comments
 (0)