Skip to content

fix: resolve symlinks in cwd - #85

Merged
lukeed merged 1 commit into
mainfrom
fix/real-cwd
Oct 23, 2026
Merged

lukeed merged 1 commit into
mainfrom
fix/real-cwd

Conversation

@lukeed

@lukeed lukeed commented Oct 22, 2026

Copy link
Copy Markdown
Owner

A build through a symlinked project path wrote different script bytes. bongo build -C /tmp/site on macOS, where /tmp links to /private/tmp, gave //#region ../../private/tmp/site/assets/main.ts. A build from inside the folder gave //#region assets/main.ts. normalize() kept the symlink in argv.cwd, while Rolldown names each module by its real path, so the relative path climbed to / and back. Minified builds have no region comments, so they were not affected.

Changes

  • normalize() sets argv.cwd with fs.real(), which resolves symlinks and keeps a part that does not exist yet. Every path made from argv.cwd now matches the module paths.
  • fs.real() is exported, with docs.
  • bundler.summary() drops its check of realpathSync(root), since each root is now real. The same check for content/ in build.ts stays: it covers a content/ folder that is itself a symlink.

Visible changes

  • Error messages and the size list name the real path. With -C through a symlink, the list shows private/tmp/site/public/, not tmp/site/public/. A build that runs from inside the folder already had real paths, since process.cwd() is real.
  • The memo key includes argv.dest, so the first build through a symlinked path after this change renders every page once.

Benchmark

bun bench/index.ts site --runs 5, 10 pairs, alternating which side runs first. Wall is the median of 5 fresh builds of 10,000 pages.

pair main wall branch wall main user branch user
1 2.18 s 2.18 s 2.96 s 2.95 s
2 2.18 s 2.20 s 2.99 s 2.97 s
3 2.19 s 2.20 s 2.97 s 2.97 s
4 2.17 s 2.17 s 2.97 s 2.96 s
5 2.21 s 2.24 s 2.99 s 2.97 s
6 2.21 s 2.21 s 2.99 s 3.00 s
7 2.19 s 2.19 s 2.99 s 2.98 s
8 2.22 s 2.20 s 2.97 s 2.98 s
9 2.19 s 2.19 s 2.97 s 2.96 s
10 2.20 s 2.21 s 2.97 s 2.98 s

The branch median is higher in 4 pairs, lower in 1, and the same in 5. Its fastest run is lower than main's in 5 pairs and higher in 3. User time is the same within 0.02 s. bench/site has no symlink in its path, so the only added work is one realpath call per build. Every run wrote the same output, sha256 71e146856b298c20.

Test plan

  • bun test (854 pass), bunx tsc -p ., bunx tsc -p build, bun run build
  • New tests fail on main: normalize() resolves a symlinked cwd and keeps a missing part, and a script built through a symlinked cwd has the bytes of a build through the real path
  • Three tests now expect real paths: the minifier argument, the "Refusing to empty" message, and two normalize() paths
  • By hand: bongo build -C /tmp/rc from / writes //#region assets/main.ts, and bongo dev -C /tmp/rc rebuilds on an edit

@lukeed
lukeed merged commit bc1792c into main Oct 23, 2026
4 checks passed
@lukeed
lukeed deleted the fix/real-cwd branch October 23, 2026 00:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant