mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-20 14:30:57 +00:00
44 lines
1.2 KiB
TypeScript
44 lines
1.2 KiB
TypeScript
type PathEnvKey = "PATH" | "Path" | "PATHEXT" | "Pathext";
|
|
|
|
const PATH_ENV_KEYS = ["PATH", "Path", "PATHEXT", "Pathext"] as const;
|
|
|
|
export type PlatformPathEnvSnapshot = {
|
|
platformDescriptor: PropertyDescriptor | undefined;
|
|
env: Record<PathEnvKey, string | undefined>;
|
|
};
|
|
|
|
export function setProcessPlatform(platform: NodeJS.Platform): void {
|
|
Object.defineProperty(process, "platform", {
|
|
value: platform,
|
|
configurable: true,
|
|
});
|
|
}
|
|
|
|
export function snapshotPlatformPathEnv(): PlatformPathEnvSnapshot {
|
|
return {
|
|
platformDescriptor: Object.getOwnPropertyDescriptor(process, "platform"),
|
|
env: {
|
|
PATH: process.env.PATH,
|
|
Path: process.env.Path,
|
|
PATHEXT: process.env.PATHEXT,
|
|
Pathext: process.env.Pathext,
|
|
},
|
|
};
|
|
}
|
|
|
|
export function restorePlatformPathEnv(snapshot: PlatformPathEnvSnapshot): void {
|
|
if (snapshot.platformDescriptor) {
|
|
Object.defineProperty(process, "platform", snapshot.platformDescriptor);
|
|
}
|
|
|
|
for (const key of PATH_ENV_KEYS) {
|
|
const value = snapshot.env[key];
|
|
if (value === undefined) {
|
|
delete process.env[key];
|
|
continue;
|
|
}
|
|
process.env[key] = value;
|
|
}
|
|
}
|
|
export { createWindowsCmdShimFixture } from "../../shared/windows-cmd-shim-test-fixtures.js";
|