From 1d2bf324c426ed1ae72b4f6e4ceae4f83c7d403c Mon Sep 17 00:00:00 2001 From: A <258483684+la14-1@users.noreply.github.com> Date: Wed, 11 Mar 2026 14:03:46 -0700 Subject: [PATCH] refactor: replace bun -e with bun eval and require() with ESM imports in shell scripts (#2505) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Per shell-scripts.md rules: always use `bun eval` (not `bun -e`) and ESM-only (never `require()`). Fixed in: - sh/shared/key-request.sh: 3 instances of `bun -e` → `bun eval` - sh/e2e/lib/soak.sh: `bun -e` → `bun eval`; `require("fs")`/`require("path")` → named ESM imports from node:fs and node:path Co-authored-by: spawn-qa-bot Co-authored-by: Claude Sonnet 4.6 Co-authored-by: L <6723574+louisgv@users.noreply.github.com> --- sh/e2e/lib/soak.sh | 13 +++++++------ sh/shared/key-request.sh | 6 +++--- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/sh/e2e/lib/soak.sh b/sh/e2e/lib/soak.sh index 416cd2dd..170a163f 100644 --- a/sh/e2e/lib/soak.sh +++ b/sh/e2e/lib/soak.sh @@ -97,20 +97,21 @@ soak_inject_telegram_config() { log_step "Patching ~/.openclaw/openclaw.json with Telegram bot token..." - # Use bun -e on the remote to JSON-patch the config file + # Use bun eval on the remote to JSON-patch the config file cloud_exec "${app}" "source ~/.spawnrc 2>/dev/null; \ export PATH=\$HOME/.npm-global/bin:\$HOME/.bun/bin:\$HOME/.local/bin:\$PATH; \ _TOKEN=\$(printf '%s' '${encoded_token}' | base64 -d); \ - bun -e ' \ - const fs = require(\"fs\"); \ + bun eval ' \ + import { mkdirSync, readFileSync, writeFileSync } from \"node:fs\"; \ + import { dirname } from \"node:path\"; \ const configPath = process.env.HOME + \"/.openclaw/openclaw.json\"; \ let config = {}; \ - try { config = JSON.parse(fs.readFileSync(configPath, \"utf-8\")); } catch {} \ + try { config = JSON.parse(readFileSync(configPath, \"utf-8\")); } catch {} \ if (!config.channels) config.channels = {}; \ if (!config.channels.telegram) config.channels.telegram = {}; \ config.channels.telegram.botToken = process.env._TOKEN; \ - fs.mkdirSync(require(\"path\").dirname(configPath), { recursive: true }); \ - fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); \ + mkdirSync(dirname(configPath), { recursive: true }); \ + writeFileSync(configPath, JSON.stringify(config, null, 2)); \ console.log(\"Telegram config injected\"); \ '" >/dev/null 2>&1 diff --git a/sh/shared/key-request.sh b/sh/shared/key-request.sh index 2613e0a1..bb415978 100644 --- a/sh/shared/key-request.sh +++ b/sh/shared/key-request.sh @@ -24,7 +24,7 @@ _parse_cloud_auths() { if command -v jq &>/dev/null; then jq -r '.clouds | to_entries[] | select(.value.auth != null and .value.auth != "") | select(.value.key_request != false) | select(.value.auth | test("\\b(login|configure|setup)\\b"; "i") | not) | "\(.key)|\(.value.auth)"' "${manifest_path}" 2>/dev/null else - _MANIFEST="${manifest_path}" bun -e " + _MANIFEST="${manifest_path}" bun eval " import fs from 'fs'; const m = JSON.parse(fs.readFileSync(process.env._MANIFEST, 'utf8')); for (const [key, cloud] of Object.entries(m.clouds || {})) { @@ -63,7 +63,7 @@ _try_load_env_var() { if command -v jq &>/dev/null; then val=$(jq -r --arg v "${var_name}" '(.[$v] // .api_key // .token) // "" | select(. != null)' "${config_file}" 2>/dev/null) else - val=$(_FILE="${config_file}" _VAR="${var_name}" bun -e " + val=$(_FILE="${config_file}" _VAR="${var_name}" bun eval " import fs from 'fs'; const d = JSON.parse(fs.readFileSync(process.env._FILE, 'utf8')); process.stdout.write(d[process.env._VAR] || d.api_key || d.token || ''); @@ -194,7 +194,7 @@ request_missing_cloud_keys() { if command -v jq &>/dev/null; then providers_json=$(printf '%s\n' ${MISSING_KEY_PROVIDERS} | jq -Rn '[inputs | select(. != "")]' 2>/dev/null) || return 0 elif command -v bun &>/dev/null; then - providers_json=$(_PROVIDERS="${MISSING_KEY_PROVIDERS}" bun -e " + providers_json=$(_PROVIDERS="${MISSING_KEY_PROVIDERS}" bun eval " const providers = process.env._PROVIDERS.trim().split(/\s+/).filter(Boolean); process.stdout.write(JSON.stringify(providers)); " 2>/dev/null) || return 0