From 714ef13e6894ac4f0172598a15db3c08982a5bb6 Mon Sep 17 00:00:00 2001 From: xuzhongpeng Date: Sun, 5 Apr 2026 18:04:12 +0800 Subject: [PATCH] fix: resolve absolute path in dev.ts for cross-directory execution The dev script previously used a relative path "src/entrypoints/cli.tsx" which would fail when executed from outside the project root directory. Changes: - Add path resolution using import.meta.url to locate project root - Use absolute path for cli.tsx entry point - Set cwd option in Bun.spawnSync to ensure correct working directory This allows running "bun run /path/to/scripts/dev.ts" from any directory. Co-Authored-By: Claude Sonnet 4.6 --- scripts/dev.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/scripts/dev.ts b/scripts/dev.ts index 68b4734ba..2cdc67e7e 100644 --- a/scripts/dev.ts +++ b/scripts/dev.ts @@ -4,8 +4,16 @@ * via Bun's -d flag (bunfig.toml [define] doesn't propagate to * dynamically imported modules at runtime). */ +import { join, dirname } from "node:path"; +import { fileURLToPath } from "node:url"; import { getMacroDefines } from "./defines.ts"; +// Resolve project root from this script's location +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); +const projectRoot = join(__dirname, ".."); +const cliPath = join(projectRoot, "src/entrypoints/cli.tsx"); + const defines = getMacroDefines(); const defineArgs = Object.entries(defines).flatMap(([k, v]) => [ @@ -32,8 +40,8 @@ const inspectArgs = process.env.BUN_INSPECT : []; const result = Bun.spawnSync( - ["bun", ...inspectArgs, "run", ...defineArgs, ...featureArgs, "src/entrypoints/cli.tsx", ...process.argv.slice(2)], - { stdio: ["inherit", "inherit", "inherit"] }, + ["bun", ...inspectArgs, "run", ...defineArgs, ...featureArgs, cliPath, ...process.argv.slice(2)], + { stdio: ["inherit", "inherit", "inherit"], cwd: projectRoot }, ); process.exit(result.exitCode ?? 0);