From abcb76d90a24968a3a8770ad793459b744cf7a80 Mon Sep 17 00:00:00 2001 From: redliuziqi <2432362444@qq.com> Date: Thu, 13 Aug 2026 10:00:33 +0800 Subject: [PATCH] fix(build): resolve repo root with fileURLToPath so builds work on Windows MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `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 #240 修复:用 fileURLToPath 解析仓库根目录,使 Windows 上可以正常构建。 URL.pathname 在 win32 返回 "/C:/...",resolve() 会拼成 "C:\C:\...", 导致所有构建目标读取 package.json 时 ENOENT 失败。POSIX 行为不变。 --- scripts/build-bundles.mjs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/build-bundles.mjs b/scripts/build-bundles.mjs index d6dae4af..f307b3dd 100644 --- a/scripts/build-bundles.mjs +++ b/scripts/build-bundles.mjs @@ -4,11 +4,15 @@ import { execFileSync, spawnSync } from "node:child_process"; import { chmodSync, readFileSync } from "node:fs"; import { createRequire } from "node:module"; import { resolve } from "node:path"; +import { fileURLToPath } from "node:url"; const require = createRequire(import.meta.url); const { computeCodeHash } = require("./code-hash.cjs"); -const repoRoot = resolve(new URL("..", import.meta.url).pathname); +// fileURLToPath, not URL.pathname (issue #240): on win32 pathname yields +// "/C:/..." and resolve() then doubles the drive into "C:\C:\...", so every +// build target dies on ENOENT reading package.json. +const repoRoot = resolve(fileURLToPath(new URL("..", import.meta.url))); const pkg = JSON.parse(readFileSync(resolve(repoRoot, "package.json"), "utf-8")); /**