fix(build): resolve repo root with fileURLToPath so builds work on Windows - #241
Open
redliuziqi wants to merge 1 commit into
Open
fix(build): resolve repo root with fileURLToPath so builds work on Windows#241redliuziqi wants to merge 1 commit into
redliuziqi wants to merge 1 commit into
Conversation
…ndows
`new URL("..", import.meta.url).pathname` returns a URL path, not a
filesystem path. On win32 that is "/C:/..." and path.resolve() treats the
leading slash as relative, producing "C:\C:\..." — so build-bundles.mjs
died on ENOENT reading package.json, blocking build:cli, build:plugin,
prepublishOnly, verify:plugin-sync and the check gate.
fileURLToPath does the documented URL→path conversion and is correct on
every platform. code-hash.cjs already resolves its root correctly via
__dirname; this was the only URL-pathname occurrence in the repo.
Covered by existing tests — on Windows they went 20 pass / 3 fail before
this change and 23 pass / 0 fail after (verify-plugin-sync.test.ts,
build-info.test.ts, code-hash.test.ts). No behavior change on POSIX.
Fixes raysonmeng#240
修复:用 fileURLToPath 解析仓库根目录,使 Windows 上可以正常构建。
URL.pathname 在 win32 返回 "/C:/...",resolve() 会拼成 "C:\C:\...",
导致所有构建目标读取 package.json 时 ENOENT 失败。POSIX 行为不变。
Contributor
|
Thanks for the PR! Before we can merge it, please sign our lightweight Contributor License Agreement — it keeps the project able to offer a future commercial edition alongside the open-source one. Reply here with: I have read the CLA Document and I hereby sign the CLA You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #240
Problem
scripts/build-bundles.mjsresolved the repo root withnew URL("..", import.meta.url).pathname. That returns a URL path, not a filesystem path — on win32 it is/C:/Users/..., andpath.resolve()treats the leading slash as relative, producingC:\C:\Users\....Result on Windows: every build target dies immediately.
This blocks
build:cli,build:plugin,prepublishOnly,verify:plugin-syncand thecheckgate — a Windows contributor cannot build or validate anything.Fix
fileURLToPathperforms the documented URL→path conversion (strips the leading slash, decodes percent-escapes) and is correct on all platforms.scripts/code-hash.cjsalready resolves its root correctly via__dirname; this was the only URL-pathname occurrence in the repo, so the change is one line plus the import.No behavior change on macOS/Linux — there
pathnameand the real path already coincide.Validation
Windows 11, Bun 1.3.14, Node v22.14.0, base
a3e927f(v0.1.30).Three tests already in the suite fail on Windows purely because of this bug, so the fix is locked by existing coverage and no new test is needed:
verify-plugin-sync.test.ts+build-info.test.ts+code-hash.test.tsmasterThe 3 that flip green:
build-bundles commit override (verify-plugin-sync mechanism)(2) andbuild-bundles codeHash stamping(1).Also confirmed on this branch:
Notes for reviewers
bun run build:pluginon this branch does rewriteplugins/agentbridge/server/*.js, but the diff is unrelated rebuild noise: the embedded commit stamp, plus different minifier output because my local Bun is 1.3.14 while the repo pins 1.3.11. Per CONTRIBUTING that pairing belongs to a build on the pinned toolchain, so I reverted them and kept this PR to the script only. Someone on Bun 1.3.11 should do the bundle refresh separately.1485 pass / 33 fail(87 files). The rest are separate environment gaps tracked in Windows support: unblock the POSIX-only assumptions #231:symlinkEPERM (needs Administrator/Developer Mode), Unix file-mode assertions (420/511), POSIX path joins in other scripts, andSIGKILLnaming.src/unit-test/logs-cli.test.tsspawnstail, which does not exist on Windows. That aborts the wholebun test src/unit-testrun rather than failing one test, so reproducing a full count requires excluding that file. Worth its own issue under Windows support: unblock the POSIX-only assumptions #231 —abg logs -fis presumably non-functional on Windows for the same reason.中文说明:
URL.pathname在 win32 返回/C:/...,resolve()会拼成C:\C:\...,导致所有构建目标读取package.json时 ENOENT 失败,Windows 上完全无法构建。改用fileURLToPath修复,POSIX 行为不变。仓库内仅此一处该写法。现有 3 个测试因此 bug 在 Windows 上失败,修复后转为全部通过(20 pass / 3 fail → 23 pass / 0 fail),无需新增测试。未提交 bundle 产物:本地 Bun 版本与仓库锁定版本不一致,重新构建的差异属于无关噪声。