diff --git a/packages/logger/src/logger.ts b/packages/logger/src/logger.ts index 0113ab3d..239b1d0a 100644 --- a/packages/logger/src/logger.ts +++ b/packages/logger/src/logger.ts @@ -260,7 +260,6 @@ export class Logger { if (name) { this.nameColor = hashStringToColor(name); } - this.info(`Log level: ${process.env.LOG_LEVEL || "info"}`); if (process.env.LOG_LEVEL) { switch (process.env.LOG_LEVEL) { case "debug": this.level = Level.Debug; break; diff --git a/packages/protocol/src/browser/command.ts b/packages/protocol/src/browser/command.ts index 40521a74..f6ef21a3 100644 --- a/packages/protocol/src/browser/command.ts +++ b/packages/protocol/src/browser/command.ts @@ -1,6 +1,6 @@ import * as events from "events"; import * as stream from "stream"; -import { SendableConnection } from "../common/connection"; +import { ReadWriteConnection } from "../common/connection"; import { ShutdownSessionMessage, ClientMessage, WriteToSessionMessage, ResizeSessionTTYMessage, TTYDimensions as ProtoTTYDimensions, ConnectionOutputMessage, ConnectionCloseMessage } from "../proto"; export interface TTYDimensions { @@ -40,11 +40,14 @@ export class ServerProcess extends events.EventEmitter implements ChildProcess { private _killed: boolean = false; public constructor( - private readonly connection: SendableConnection, + private readonly connection: ReadWriteConnection, private readonly id: number, private readonly hasTty: boolean = false, ) { super(); + this.connection.onMessage((message) => { + this.emit("message", message); + }); if (!this.hasTty) { delete this.resize; @@ -131,7 +134,7 @@ export class ServerSocket extends events.EventEmitter implements Socket { private _connecting: boolean = true; public constructor( - private readonly connection: SendableConnection, + private readonly connection: ReadWriteConnection, private readonly id: number, connectCallback?: () => void, ) { diff --git a/packages/protocol/src/browser/modules/child_process.ts b/packages/protocol/src/browser/modules/child_process.ts index 93d64907..8a4d42ea 100644 --- a/packages/protocol/src/browser/modules/child_process.ts +++ b/packages/protocol/src/browser/modules/child_process.ts @@ -46,7 +46,7 @@ export class CP { public fork = (modulePath: string, args?: ReadonlyArray | cp.ForkOptions, options?: cp.ForkOptions): cp.ChildProcess => { //@ts-ignore - return this.client.fork(modulePath, args, options); + return this.client.fork(options && options.env && options.env.AMD_ENTRYPOINT || modulePath, args, options); } public spawn = (command: string, args?: ReadonlyArray | cp.SpawnOptions, options?: cp.SpawnOptions): cp.ChildProcess => { diff --git a/packages/protocol/src/node/command.ts b/packages/protocol/src/node/command.ts index 7b849e87..128dbb55 100644 --- a/packages/protocol/src/node/command.ts +++ b/packages/protocol/src/node/command.ts @@ -3,7 +3,7 @@ import * as net from "net"; import * as nodePty from "node-pty"; import * as stream from "stream"; import { TextEncoder } from "text-encoding"; -import { NewSessionMessage, ServerMessage, SessionDoneMessage, SessionOutputMessage, ShutdownSessionMessage, IdentifySessionMessage, ClientMessage, NewConnectionMessage, ConnectionEstablishedMessage, NewConnectionFailureMessage, ConnectionCloseMessage, ConnectionOutputMessage } from "../proto"; +import { NewSessionMessage, ServerMessage, SessionDoneMessage, SessionOutputMessage, IdentifySessionMessage, NewConnectionMessage, ConnectionEstablishedMessage, NewConnectionFailureMessage, ConnectionCloseMessage, ConnectionOutputMessage } from "../proto"; import { SendableConnection } from "../common/connection"; import { ServerOptions } from "./server"; @@ -16,7 +16,7 @@ export interface Process { killed?: boolean; on(event: "data", cb: (data: string) => void): void; - on(event: 'exit', listener: (exitCode: number, signal?: number) => void): void; + on(event: "exit", listener: (exitCode: number, signal?: number) => void): void; write(data: string | Uint8Array): void; resize?(cols: number, rows: number): void; kill(signal?: string): void; @@ -170,4 +170,4 @@ export const handleNewConnection = (connection: SendableConnection, newConnectio }); return socket; -} \ No newline at end of file +}; diff --git a/packages/server/src/server.ts b/packages/server/src/server.ts index ae6f23f5..ae19fb7b 100644 --- a/packages/server/src/server.ts +++ b/packages/server/src/server.ts @@ -44,14 +44,33 @@ export const createApp = (registerMiddleware?: (app: express.Application) => voi const server = new Server(connection, options ? { ...options, forkProvider: (message: NewSessionMessage): ChildProcess => { - let proc: ChildProcess; + const command = message.getCommand(); + const childLogger = logger.named(command.split("/").pop()!); + childLogger.debug("Forking...", field("module", command)); + let proc: ChildProcess; if (message.getIsBootstrapFork()) { - proc = forkModule(message.getCommand()); + proc = forkModule(command); } else { throw new Error("No support for non bootstrap-forking yet"); } + proc.stdout.on("data", (message) => { + childLogger.debug("stdout", field("message", message.toString().trim())); + }); + + proc.stderr.on("data", (message) => { + childLogger.debug("stderr", field("message", message.toString().trim())); + }); + + proc.stdin.on("data", (message) => { + childLogger.debug("stdin", field("message", message.toString().trim())); + }); + + proc.on("exit", (exitCode) => { + childLogger.debug(`Exited with ${exitCode}`); + }); + return proc; }, } : undefined); diff --git a/packages/server/src/vscode/sharedProcess.ts b/packages/server/src/vscode/sharedProcess.ts index 19056842..c982f9fd 100644 --- a/packages/server/src/vscode/sharedProcess.ts +++ b/packages/server/src/vscode/sharedProcess.ts @@ -29,7 +29,7 @@ export class SharedProcess { private activeProcess: ChildProcess | undefined; private ipcHandler: StdioIpcHandler | undefined; private readonly onStateEmitter: Emitter; - private readonly logger = logger.named("SHDR PROC"); + private readonly logger = logger.named("SHRD PROC"); public constructor( private readonly userDataDir: string,