Skip to content

Commit 865fb63

Browse files
committed
Make env-prefixed npm scripts work on Windows
1 parent e25fa44 commit 865fb63

File tree

2 files changed

+51
-8
lines changed

2 files changed

+51
-8
lines changed

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@
222222
"android:lint:android": "cd apps/android && ./gradlew :app:lintDebug",
223223
"android:run": "cd apps/android && ./gradlew :app:installDebug && adb shell am start -n ai.openclaw.app/.MainActivity",
224224
"android:test": "cd apps/android && ./gradlew :app:testDebugUnitTest",
225-
"android:test:integration": "OPENCLAW_LIVE_TEST=1 OPENCLAW_LIVE_ANDROID_NODE=1 vitest run --config vitest.live.config.ts src/gateway/android-node.capabilities.live.test.ts",
225+
"android:test:integration": "node scripts/with-env.mjs OPENCLAW_LIVE_TEST=1 OPENCLAW_LIVE_ANDROID_NODE=1 -- vitest run --config vitest.live.config.ts src/gateway/android-node.capabilities.live.test.ts",
226226
"build": "pnpm canvas:a2ui:bundle && node scripts/tsdown-build.mjs && node scripts/copy-plugin-sdk-root-alias.mjs && pnpm build:plugin-sdk:dts && node --import tsx scripts/write-plugin-sdk-entry-dts.ts && node --import tsx scripts/canvas-a2ui-copy.ts && node --import tsx scripts/copy-hook-metadata.ts && node --import tsx scripts/copy-export-html-templates.ts && node --import tsx scripts/write-build-info.ts && node --import tsx scripts/write-cli-startup-metadata.ts && node --import tsx scripts/write-cli-compat.ts",
227227
"build:docker": "node scripts/tsdown-build.mjs && node scripts/copy-plugin-sdk-root-alias.mjs && pnpm build:plugin-sdk:dts && node --import tsx scripts/write-plugin-sdk-entry-dts.ts && node --import tsx scripts/canvas-a2ui-copy.ts && node --import tsx scripts/copy-hook-metadata.ts && node --import tsx scripts/copy-export-html-templates.ts && node --import tsx scripts/write-build-info.ts && node --import tsx scripts/write-cli-startup-metadata.ts && node --import tsx scripts/write-cli-compat.ts",
228228
"build:plugin-sdk:dts": "tsc -p tsconfig.plugin-sdk.dts.json",
@@ -257,8 +257,8 @@
257257
"format:docs:check": "git ls-files 'docs/**/*.md' 'docs/**/*.mdx' 'README.md' | xargs oxfmt --check",
258258
"format:fix": "oxfmt --write",
259259
"format:swift": "swiftformat --lint --config .swiftformat apps/macos/Sources apps/ios/Sources apps/shared/OpenClawKit/Sources",
260-
"gateway:dev": "OPENCLAW_SKIP_CHANNELS=1 CLAWDBOT_SKIP_CHANNELS=1 node scripts/run-node.mjs --dev gateway",
261-
"gateway:dev:reset": "OPENCLAW_SKIP_CHANNELS=1 CLAWDBOT_SKIP_CHANNELS=1 node scripts/run-node.mjs --dev gateway --reset",
260+
"gateway:dev": "node scripts/with-env.mjs OPENCLAW_SKIP_CHANNELS=1 CLAWDBOT_SKIP_CHANNELS=1 -- node scripts/run-node.mjs --dev gateway",
261+
"gateway:dev:reset": "node scripts/with-env.mjs OPENCLAW_SKIP_CHANNELS=1 CLAWDBOT_SKIP_CHANNELS=1 -- node scripts/run-node.mjs --dev gateway --reset",
262262
"gateway:watch": "node scripts/watch-node.mjs gateway --force",
263263
"gen:host-env-policy:swift": "node scripts/generate-host-env-security-policy-swift.mjs --write",
264264
"ghsa:patch": "node scripts/ghsa-patch.mjs",
@@ -320,19 +320,19 @@
320320
"test:force": "node --import tsx scripts/test-force.ts",
321321
"test:gateway": "vitest run --config vitest.gateway.config.ts --pool=forks",
322322
"test:install:e2e": "bash scripts/test-install-sh-e2e-docker.sh",
323-
"test:install:e2e:anthropic": "OPENCLAW_E2E_MODELS=anthropic CLAWDBOT_E2E_MODELS=anthropic bash scripts/test-install-sh-e2e-docker.sh",
324-
"test:install:e2e:openai": "OPENCLAW_E2E_MODELS=openai CLAWDBOT_E2E_MODELS=openai bash scripts/test-install-sh-e2e-docker.sh",
323+
"test:install:e2e:anthropic": "node scripts/with-env.mjs OPENCLAW_E2E_MODELS=anthropic CLAWDBOT_E2E_MODELS=anthropic -- bash scripts/test-install-sh-e2e-docker.sh",
324+
"test:install:e2e:openai": "node scripts/with-env.mjs OPENCLAW_E2E_MODELS=openai CLAWDBOT_E2E_MODELS=openai -- bash scripts/test-install-sh-e2e-docker.sh",
325325
"test:install:smoke": "bash scripts/test-install-sh-docker.sh",
326-
"test:live": "OPENCLAW_LIVE_TEST=1 CLAWDBOT_LIVE_TEST=1 vitest run --config vitest.live.config.ts",
327-
"test:macmini": "OPENCLAW_TEST_VM_FORKS=0 OPENCLAW_TEST_PROFILE=serial node scripts/test-parallel.mjs",
326+
"test:live": "node scripts/with-env.mjs OPENCLAW_LIVE_TEST=1 CLAWDBOT_LIVE_TEST=1 -- vitest run --config vitest.live.config.ts",
327+
"test:macmini": "node scripts/with-env.mjs OPENCLAW_TEST_VM_FORKS=0 OPENCLAW_TEST_PROFILE=serial -- node scripts/test-parallel.mjs",
328328
"test:perf:budget": "node scripts/test-perf-budget.mjs",
329329
"test:perf:hotspots": "node scripts/test-hotspots.mjs",
330330
"test:sectriage": "pnpm exec vitest run --config vitest.gateway.config.ts && vitest run --config vitest.unit.config.ts --exclude src/daemon/launchd.integration.test.ts --exclude src/process/exec.test.ts",
331331
"test:ui": "pnpm lint:ui:no-raw-window-open && pnpm --dir ui test",
332332
"test:voicecall:closedloop": "vitest run extensions/voice-call/src/manager.test.ts extensions/voice-call/src/media-stream.test.ts src/plugins/voice-call.plugin.test.ts --maxWorkers=1",
333333
"test:watch": "vitest",
334334
"tui": "node scripts/run-node.mjs tui",
335-
"tui:dev": "OPENCLAW_PROFILE=dev CLAWDBOT_PROFILE=dev node scripts/run-node.mjs --dev tui",
335+
"tui:dev": "node scripts/with-env.mjs OPENCLAW_PROFILE=dev CLAWDBOT_PROFILE=dev -- node scripts/run-node.mjs --dev tui",
336336
"ui:build": "node scripts/ui.js build",
337337
"ui:dev": "node scripts/ui.js dev",
338338
"ui:install": "node scripts/ui.js install"

scripts/with-env.mjs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env node
2+
import { spawn } from "node:child_process";
3+
import process from "node:process";
4+
5+
const usage = () => {
6+
console.error("Usage: node scripts/with-env.mjs KEY=value [KEY=value ...] -- command [args...]");
7+
process.exit(1);
8+
};
9+
10+
const argv = process.argv.slice(2);
11+
const separatorIndex = argv.indexOf("--");
12+
13+
if (separatorIndex === -1) {
14+
usage();
15+
}
16+
17+
const envAssignments = argv.slice(0, separatorIndex);
18+
const command = argv[separatorIndex + 1];
19+
const args = argv.slice(separatorIndex + 2);
20+
21+
if (!command) {
22+
usage();
23+
}
24+
25+
const childEnv = { ...process.env };
26+
for (const assignment of envAssignments) {
27+
const equalsIndex = assignment.indexOf("=");
28+
if (equalsIndex <= 0) {
29+
usage();
30+
}
31+
childEnv[assignment.slice(0, equalsIndex)] = assignment.slice(equalsIndex + 1);
32+
}
33+
34+
const child = spawn(command, args, {
35+
cwd: process.cwd(),
36+
env: childEnv,
37+
stdio: "inherit",
38+
shell: process.platform === "win32",
39+
});
40+
41+
child.on("exit", (code, signal) => {
42+
process.exit(signal ? 1 : (code ?? 1));
43+
});

0 commit comments

Comments
 (0)