Repository navigation
Conversation
…below `/` `bun init` took the default package name from `PathName::init(cwd).filename`. When the path has no parent directory component, that is the whole path: `bun init -y` wrote `"name": "/app"` in `/app`, `"name": "/"` in `/`, and `"name": "u:"` in `U:\`. The name now comes from `bun_paths::basename`. It is empty for a root, so the existing `project` fallback applies. `FileSystem::top_level_dir_without_trailing_slash` turned the drive root `C:\` into `C:`, the current directory of drive C. It now keeps a Windows filesystem root, as it already kept `/`. `bun repl` read it for `module.path`, which was `U:` in `U:\`. `Bun__REPL__setupGlobalRequire` adds no second separator to a cwd that ends in one. `module.filename` was `//[repl]` in `/`. `bun patch` strips the separator itself, so the path it prints does not change.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository: oven-sh/bun/.coderabbit.yaml Review profile: ASSERTIVE Plan: Essentials Run ID: 📒 Files selected for processing (7)
Included review availability: Your plan provides up to 10 included reviews per hour; 0 remain after this review. WalkthroughThe changes preserve filesystem roots when removing trailing separators. Package initialization, REPL setup, and workspace patch instructions now use root-safe paths. Windows regression tests cover drive-root behavior. ChangesFilesystem root path handling
Suggested reviewers: Priority: ➖ Normal 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
Comment |
|
Updated 3:43 PM PT - Sep 19th, 2026
✅ @robobun, your commit 297f45751bf62f1688ea6c7bca4c043845106d4f passed in 🧪 To try this PR locally: bunx bun-pr 43489That installs a local version of the PR into your bun-43489 --bun |
|
Status Reproduction:
Fix:
CI (build 118394 on
Later commits (no behavior change):
The red x64-asan lane, checked again on build 118499 (
|
The comment read as a rule for every filesystem root. The basename is empty in `/` and in a drive root. A UNC share root gives the share name.
`bun init` takes the default package name from `bun_paths::basename` and relies on the empty result for `/`, `C:\` and `C:`. Nothing tested that. The functions are pure, so the Windows rules run on every host.
Problem
bun init -ywrites an invalid default package name:"name": "/app"in/app(any directory directly below the POSIX root),"name": "/"in/, and"name": "u:"in the Windows drive rootU:\.src/runtime/cli/init_command.rs:397took the name fromPathName::init(cwd).filename. When the path has no parent directory component,filenameis the whole path. On Windows the cwd came fromFileSystem::top_level_dir_without_trailing_slash()(src/resolver/lib.rs:425), which turnedC:\intoC:.bun replreads the same accessor. InU:\,module.pathisU:. In/,module.filenameis//[repl].Fix
bun inittakes the name frombun_paths::basename(cwd). It is empty for a root, so the existingprojectfallback applies.C:\), as it already kept/.Bun__REPL__setupGlobalRequireadds no second separator to a cwd that ends in one.bun patchstrips the separator itself, so the path it prints does not change.test/cli/init/init.test.ts(Windows) andtest/js/bun/repl/repl.test.tsfail on canary 1.4.3. Both files andtest/cli/install/bun-patch.test.tspass on Linux and Windows x64 debug builds.Background
C:without a separator is a drive-relative path. It names the current directory of drive C, not the rootC:\.top_level_diris the cwd thatFileSystem::initreads once. It has no trailing separator, except for a root.subst U: <dir>makes a directory the root of a new drive, without admin rights. A test cannot write to the root of a real drive.Notes
Values before and after (canary 1.4.3-canary.1+26e7a4b36, then debug builds of this branch)
/initxbun init -yname/initxinitx/bun init -yname/projectU:\(subst)bun init -ynameu:projectU:\(subst)bun replmodule.pathU:U:\/bun replmodule.filename//[repl]/[repl]bun initrows have no test, because a test cannot write to/. I checked them by hand in a container, before and after. Bun 1.2.20 gives the same/initx, so the bug is not new.src/paths/lib.rspin thebasenameresults that the fix depends on (empty for/,C:\andC:,appfor/app). They run in thecargo miri testcheck. They do not runbun init. A test gated on root would be skipped in CI: the Linux lanes I checked (debian 13 x64-asan, alpine 3.23 aarch64) run the tests asbuildkite-agent.npm init -y(npm 11.16.0) writes"name": ""inU:\.projectis the name thatbun initalready uses when the normalized directory name is empty.bun link(src/runtime/cli/link_command.rs:174) reads it afterPackageManager::inithas already stripped the cwd toC:(src/install/PackageManager.rs:1509,:1840). So this change does not reachbun link. In a drive root it still fails ininitwithENOENT, on main and on this branch. install: make bun install work in the root of a Windows drive #43437 fixes that path.bun patch(src/install/PackageManager/patchPackage.rs:977) joined the accessor withplatform::Posixto print a path. WithC:\kept, that join would printC:\/node_modules/... Sobun patchnow strips the separator itself and printsC:/node_modules/.., as before.top_level_dircomes fromgetcwd. So the accessor only strips something in a drive root, or afterprocess.chdir()(VirtualMachine::set_process_cwdappends a separator).windows_filesystem_root, notwithout_trailing_slash_windows_path. The second one also strips\on POSIX, where\can end a directory name.bun installwork in a drive root. Until it lands, thebun installstep at the end ofbun initfails there withENOENT, andbun initstill exits 0. The new init test starts from a package.json that needs no install, so it does not depend on install: make bun install work in the root of a Windows drive #43437 and does not use the network.substDriveintest/harness.tsis the same text as the helper in install: make bun install work in the root of a Windows drive #43437, so the two branches merge without a conflict.test/cli/init/init.test.ts,test/js/bun/repl/repl.test.tsandtest/cli/install/bun-patch.test.tson Linux x64 and Windows x64,test/internal/source-lints/on Linux.cargo test -p bun_paths --libandbun run rust:miri -p bun_pathson Linux (31 tests pass).test/cli/install/bun-link.test.tson Linux: 3 of 4 pass. The fourth compares exact stdout, and a debug build prints a stack trace there (#[cfg(bun_debug)]insrc/install/PackageInstall.rs:221).no test proof · iteration 2 · platform-specific test(s) that do not run on this machine, deferring to CI, which covers all platforms: test/js/bun/repl/repl.test.ts, test/cli/init/init.test.ts