From 3e893ab9c37d9d07904ac4c291633016dda7dd20 Mon Sep 17 00:00:00 2001 From: Paul <82803315+ppauel@users.noreply.github.com> Date: Wed, 29 Apr 2026 14:57:56 +0200 Subject: [PATCH] feat: Add env parameter for BotInstance --- src/instance/BotInstance.ts | 8 ++++++-- src/instance/ManagedInstance.ts | 6 +++--- src/instance/StandaloneInstance.ts | 6 +++--- test/machine.ts | 1 + 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/instance/BotInstance.ts b/src/instance/BotInstance.ts index 404dd6e..0fd0b60 100644 --- a/src/instance/BotInstance.ts +++ b/src/instance/BotInstance.ts @@ -9,13 +9,16 @@ export abstract class BotInstance { private readonly execArgv: string[]; + private readonly env: NodeJS.ProcessEnv; + public readonly clusters: Map = new Map(); protected _shuttingDown = false; - protected constructor(entryPoint: string, execArgv?: string[]) { + protected constructor(entryPoint: string, execArgv?: string[], env?: NodeJS.ProcessEnv) { this.entryPoint = entryPoint; this.execArgv = execArgv ?? []; + this.env = env ?? {}; } protected readonly eventMap: BotInstanceEventListeners = { @@ -44,6 +47,7 @@ export abstract class BotInstance { try { const childProcess = fork(this.entryPoint, { env: { + ...this.env, INSTANCE_ID: instanceID.toString(), CLUSTER_ID: clusterID.toString(), SHARD_LIST: shardList.join(','), @@ -210,4 +214,4 @@ export type BotInstanceEventListeners = { 'SELF_CHECK_SUCCESS': (() => void) | undefined, 'SELF_CHECK_ERROR': ((error: string) => void) | undefined, 'SELF_CHECK_RECEIVED': ((data: { clusterList: number[] }) => void) | undefined, -}; \ No newline at end of file +}; diff --git a/src/instance/ManagedInstance.ts b/src/instance/ManagedInstance.ts index e5edbfa..352382f 100644 --- a/src/instance/ManagedInstance.ts +++ b/src/instance/ManagedInstance.ts @@ -26,8 +26,8 @@ export class ManagedInstance extends BotInstance { private dev: boolean = false; - constructor(entryPoint: string, host: string, port: number, instanceID: number, data: unknown, execArgv?: string[], dev?: boolean) { - super(entryPoint, execArgv); + constructor(entryPoint: string, host: string, port: number, instanceID: number, data: unknown, execArgv?: string[], env?: NodeJS.ProcessEnv, dev?: boolean) { + super(entryPoint, execArgv, env); this.host = host; this.port = port; @@ -307,4 +307,4 @@ export class ManagedInstance extends BotInstance { type: 'INSTANCE_STOP' }); } -} \ No newline at end of file +} diff --git a/src/instance/StandaloneInstance.ts b/src/instance/StandaloneInstance.ts index 80ac4a8..eea8907 100644 --- a/src/instance/StandaloneInstance.ts +++ b/src/instance/StandaloneInstance.ts @@ -10,8 +10,8 @@ export class StandaloneInstance extends BotInstance { public readonly token: string; public readonly intents: GatewayIntentsString[]; - constructor(entryPoint: string, shardsPerCluster: number, totalClusters: number, token: string, intents: GatewayIntentsString[], execArgv?: string[]) { - super(entryPoint, execArgv); + constructor(entryPoint: string, shardsPerCluster: number, totalClusters: number, token: string, intents: GatewayIntentsString[], execArgv?: string[], env?: NodeJS.ProcessEnv) { + super(entryPoint, execArgv, env); this.shardsPerCluster = shardsPerCluster; this.totalClusters = totalClusters; this.token = token; @@ -100,4 +100,4 @@ export class StandaloneInstance extends BotInstance { return Promise.reject(new Error(`Unknown request type: ${message.type}`)); } -} \ No newline at end of file +} diff --git a/test/machine.ts b/test/machine.ts index c87bb46..c33f229 100644 --- a/test/machine.ts +++ b/test/machine.ts @@ -13,6 +13,7 @@ const machine = new ManagedInstance( key: "value", }, ["--import", "tsx"], + process.env, false, );