mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-19 09:58:38 +00:00
refactor(supervisor): share env normalization
This commit is contained in:
@@ -2,6 +2,7 @@ import type { ChildProcessWithoutNullStreams, SpawnOptions } from "node:child_pr
|
|||||||
import type { ManagedRunStdin } from "../types.js";
|
import type { ManagedRunStdin } from "../types.js";
|
||||||
import { killProcessTree } from "../../kill-tree.js";
|
import { killProcessTree } from "../../kill-tree.js";
|
||||||
import { spawnWithFallback } from "../../spawn-utils.js";
|
import { spawnWithFallback } from "../../spawn-utils.js";
|
||||||
|
import { toStringEnv } from "./env.js";
|
||||||
|
|
||||||
function resolveCommand(command: string): string {
|
function resolveCommand(command: string): string {
|
||||||
if (process.platform !== "win32") {
|
if (process.platform !== "win32") {
|
||||||
@@ -18,20 +19,6 @@ function resolveCommand(command: string): string {
|
|||||||
return command;
|
return command;
|
||||||
}
|
}
|
||||||
|
|
||||||
function toStringEnv(env?: NodeJS.ProcessEnv): Record<string, string> {
|
|
||||||
if (!env) {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
const out: Record<string, string> = {};
|
|
||||||
for (const [key, value] of Object.entries(env)) {
|
|
||||||
if (value === undefined) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
out[key] = String(value);
|
|
||||||
}
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
export type ChildAdapter = {
|
export type ChildAdapter = {
|
||||||
pid?: number;
|
pid?: number;
|
||||||
stdin?: ManagedRunStdin;
|
stdin?: ManagedRunStdin;
|
||||||
|
|||||||
13
src/process/supervisor/adapters/env.ts
Normal file
13
src/process/supervisor/adapters/env.ts
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
export function toStringEnv(env?: NodeJS.ProcessEnv): Record<string, string> {
|
||||||
|
if (!env) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
const out: Record<string, string> = {};
|
||||||
|
for (const [key, value] of Object.entries(env)) {
|
||||||
|
if (value === undefined) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
out[key] = String(value);
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import type { ManagedRunStdin } from "../types.js";
|
import type { ManagedRunStdin } from "../types.js";
|
||||||
import { killProcessTree } from "../../kill-tree.js";
|
import { killProcessTree } from "../../kill-tree.js";
|
||||||
|
import { toStringEnv } from "./env.js";
|
||||||
|
|
||||||
type PtyExitEvent = { exitCode: number; signal?: number };
|
type PtyExitEvent = { exitCode: number; signal?: number };
|
||||||
type PtyDisposable = { dispose: () => void };
|
type PtyDisposable = { dispose: () => void };
|
||||||
@@ -29,20 +30,6 @@ type PtyModule = {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
function toStringEnv(env?: NodeJS.ProcessEnv): Record<string, string> {
|
|
||||||
if (!env) {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
const out: Record<string, string> = {};
|
|
||||||
for (const [key, value] of Object.entries(env)) {
|
|
||||||
if (value === undefined) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
out[key] = String(value);
|
|
||||||
}
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
export type PtyAdapter = {
|
export type PtyAdapter = {
|
||||||
pid?: number;
|
pid?: number;
|
||||||
stdin?: ManagedRunStdin;
|
stdin?: ManagedRunStdin;
|
||||||
|
|||||||
Reference in New Issue
Block a user