Skip to content

Commit

Permalink
allow custom NODE_OPTIONS and DEBUG on child
Browse files Browse the repository at this point in the history
  • Loading branch information
bwp91 committed Apr 7, 2024
1 parent febf860 commit ec0466b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/bridgeService.ts
Expand Up @@ -15,7 +15,8 @@ import {
Bridge,
Categories,
Characteristic,
CharacteristicEventTypes, CharacteristicWarning,
CharacteristicEventTypes,
CharacteristicWarning,
CharacteristicWarningType,
InterfaceName,
IPAddress,
Expand Down Expand Up @@ -59,6 +60,10 @@ export interface BridgeConfiguration {
model?: string;
disableIpc?: boolean;
firmwareRevision?: string;
env?: {
NODE_OPTIONS?: string;
DEBUG?: string;
};
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down
20 changes: 17 additions & 3 deletions src/childBridgeService.ts
Expand Up @@ -130,6 +130,7 @@ export interface ChildMetadata {
export class ChildBridgeService {
private child?: child_process.ChildProcess;
private args: string[] = [];
private processEnv: child_process.ForkOptions = {};
private shuttingDown = false;
private lastBridgeStatus: ChildBridgeStatus = ChildBridgeStatus.PENDING;
private pairedStatus: boolean | null = null;
Expand Down Expand Up @@ -165,6 +166,7 @@ export class ChildBridgeService {
*/
public start(): void {
this.setProcessFlags();
this.setProcessEnv();
this.startChildProcess();

// set display name
Expand Down Expand Up @@ -202,9 +204,7 @@ export class ChildBridgeService {
private startChildProcess(): void {
this.bridgeStatus = ChildBridgeStatus.PENDING;

this.child = child_process.fork(path.resolve(__dirname, "childBridgeFork.js"), this.args, {
silent: true,
});
this.child = child_process.fork(path.resolve(__dirname, "childBridgeFork.js"), this.args, this.processEnv);

this.child.stdout?.on("data", (data) => {
process.stdout.write(data);
Expand Down Expand Up @@ -332,6 +332,20 @@ export class ChildBridgeService {
}
}

/**
* Set environment variables for the child process
*/
private setProcessEnv(): void {
this.processEnv = {
env: {
...process.env,
DEBUG: `${process.env.DEBUG || ""} ${this.bridgeConfig.env?.DEBUG || ""}`.trim(),
NODE_OPTIONS: `${process.env.NODE_OPTIONS || ""} ${this.bridgeConfig.env?.NODE_OPTIONS || ""}`.trim(),
},
silent: true,
};
}

/**
* Tell the child process to load the given plugin
*/
Expand Down

0 comments on commit ec0466b

Please sign in to comment.