Skip to content

install: replace a tarball or git folder when its name moves to the registry - #46153

Closed
robobun wants to merge 3 commits into
mainfrom
robobun/a6d3d1e4/registry-folder-tag
Closed

robobun wants to merge 3 commits into
mainfrom
robobun/a6d3d1e4/registry-folder-tag

Conversation

@robobun

@robobun robobun commented Oct 20, 2026 •

Copy link
Copy Markdown
Collaborator

Related to #28964

Problem

Fix

  • The install replaces a registry folder with a .bun-tag, when the lockfile had a tarball or git package of that name.
  • bun prune and the removal of nested copies keep the copy below such a folder and warn. They also check a tarball folder's .bun-tag.
  • Verified: test/cli/install/bun-prune.test.ts (26 new cases, 22 fail on main) and 27 more install suites (Notes).
  • Self-reviewed: 28 concerns raised, 25 addressed. Not taken: a by-place keep, a shared verifier, a registry stamp.

Background

  • Bun writes .bun-tag (integrity or commit) into tarball and git folders, not into registry packages.
  • Considered: a record of what the last install laid. It also covers file: folders and links, and needs a maintainer's decision.

Downsides

  • Not fixed: file: folders, links, tarball folders from Bun 1.4.3 (copy deleted, 1.4.2 keeps it), and bun.lock changes outside the install.
  • New: bun remove --offline exits 1 if the registry package is not cached.
  • openat: 65 to 71 when bun prune checks 6 folders, 43 to 44 in bun add beside a same-name tarball. .text: +1,280 bytes.
Notes

Origin

A fuzz run of install flows found this. No user reported it. #28964 is a user's report of the same class for a link: dependency.

Example

The root depends on a tarball dep-c@1.0.1. p depends on the registry dep-c@^1.0.0, so p has its own copy at node_modules/p/node_modules/dep-c. Run bun remove dep-c. bun.lock then has one dep-c, the registry package, at the root.

  • main: node_modules/dep-c is still the tarball, the copy below p is deleted, and p loads the tarball. bun install --frozen-lockfile prints Checked 2 installs across 3 packages (no changes) and exits 0.
  • This PR: node_modules/dep-c is the registry package and the copy below p is removed, as after a first install.

Where the change is (source: +115, -45 in 6 files)

  • Install: one more term at the needs_install test in src/install/PackageInstaller.rs. had_other_source asks the lockfile from before clean for a tarball or git package of the name (Lockfile::packages_named). PackageInstall::has_other_bun_tag reads the folder's .bun-tag and, if there is one, the .bun-tag of the cache entry that the install copies.
  • read_bun_tag is the one reader of the folder's .bun-tag. verify_bun_tag uses it too.
  • Removal: the registry arm of HoistedTree::installed in src/install/prune.rs answers the new Installed::OtherSource for a folder with a .bun-tag. The tarball arm compares the folder's .bun-tag with the integrity in bun.lock through tarball_tag_matches, which the installer and the isolated linker already use. other_source_above asks the registry question for the pass that removes what Bun 1.4.3 laid (remove_from_older_places).
  • Refactor only: the memo of verified_installed is one Vec<Cell<Option<Installed>>>, because a fourth answer does not fit the three bit sets.
  • install_with_manager.rs gives the removal's existing condition a name (changes_places) and passes the lockfile from before clean to the hoisted install under it.

Rules

  • Install. The folder of a registry package is installed again when all of these are true: package.json differs from bun.lock, or the command is bun update, bun dedupe or bun audit fix. The lockfile from before clean has a tarball or git package of that name. The folder has a .bun-tag, or one that cannot be opened. The cache entry of the registry package does not have the same .bun-tag.
  • The last rule is for a registry package that ships the file, or whose patch adds it: the install does not replace that folder again and again.
  • The installer knows no tag format. An empty tag (--no-verify), a tarball with the registry's own bytes, and a tag that gains a second line all count.
  • Removal, registry package: a folder with a .bun-tag is another source. bun prune does not read the cache.
  • Removal, tarball package: the folder must have the name and a .bun-tag that equals the integrity in bun.lock. An empty tag counts, because bun install --no-verify leaves one. Before, the name alone was enough, and bun prune deleted a workspace's tarball copy below a registry folder of that name.
  • A file: folder is still accepted on its name, as on main.

New output, for sign-off

warn: node_modules/dep-c has a .bun-tag but bun.lock expects a registry package; keeping node_modules/p/node_modules/dep-c
note: remove the folder with the .bun-tag and run 'bun install' first

The note above is from bun prune. After an install the note is remove the folder with the .bun-tag and run 'bun install', then 'bun prune'. For a tarball package, bun prune prints the existing is not the version bun.lock expects warning and the existing run 'bun install' first note.

The commands that replace the folder now print what Bun prints for every run that installs a package:

Command main This PR
bun remove dep-c - dep-c, done 1 package installed
bun add dep-c@1.0.1 installed dep-c@1.0.1, done installed dep-c@1.0.1, 1 package installed
edit, then bun install Checked 2 installs across 3 packages (no changes) + dep-c@1.0.1, 1 package installed

print_removed has needed install_summary.success == 0 since #38333, so a bun remove that installs a package prints no - name row.

Source by flow

Hoisted linker. The root has another source of dep-c@1.0.1, and p needs the registry dep-c@1.0.1. Flows: bun remove, bun add, edit and bun install, edit and bun update.

Source at the root Bun 1.4.2 main This PR
git, GitHub, and a tarball URL or local tarball on a tree that this Bun laid old folder stays. The copy stays, except in bun update. old folder stays, copy deleted registry package at the root, tree of a first install
tarball folder that Bun 1.4.3 or older laid (no .bun-tag) as above as above as main
file: folder, link: as above as above as main

So main and this PR delete the dependent's copy in the last two rows, where 1.4.2 keeps it. Two test.todo cases record them.

Measurements

Release builds of main (9634520) and of this PR. Syscalls counted with gdb catchpoints, all threads.

Run openat main openat PR
bun install, no changes 25 25
bun prune, clean tree 27 27
bun add other, no tarball or git package 42 42
bun add other, a tarball dep-c, no registry dep-c 41 41
bun add other, a tarball dep-c and a registry dep-c below p 43 44
bun prune, 5 stray copies of registry packages (6 folders checked) 65 71
bun prune, 10 stray copies (11 folders checked) 100 111
bun prune, a stray copy of a tarball package (2 folders checked) 37 39
  • read, newfstatat, unlinkat and getdents64 are equal in every row. close is equal except in the last row (31 to 32: the .bun-tag of the tarball folder opens). write differs by one between two runs of one binary.
  • The install reads the .bun-tag of a cache entry only for a folder that has a .bun-tag.
  • Allocator calls on the main thread (14 mimalloc entry points, gdb breakpoints): bun install with no changes 364 to 364, bun prune on a clean tree 312 to 310, bun add other 587 to 583.
  • Size (size -A): .text 81,932,069 to 81,933,349 (+1,280). .rodata, .data and .bss are equal.
  • strace, perf, valgrind and bloaty are not installed on this machine.

Tests

  • test/cli/install/bun-prune.test.ts: 26 new cases and 2 test.todo cases. On a debug build of main (9634520), 22 of the 26 fail. The other 4 are guards: a registry package with and without a shipped .bun-tag beside a tarball of its name, a registry package whose patch adds the file, and bun prune over a patched tarball folder.
  • The rows: local tarball (4 flows), a copy of the registry's tarball, tarball URL, git, GitHub, a patched tarball, a .bun-tag that is a directory (tarball and git), a .bun-tag that is a link to itself (not on Windows: a file link needs a privilege there), an empty .bun-tag, bun update through a transitive dependency, bun update after the tarball got other bytes, bun dedupe. Each row of the table also asserts stdout.
  • Seven clauses removed in two builds: the name condition, the three arms of has_other_bun_tag, the empty tag in the tarball arm, and the Dedupe and Update arms of changes_places. Six fail their own case. The Update arm fails none: in the bun update cases here, main's condition is true without it.
  • Debug build of this branch, long timeout, all pass: bun-prune (202 pass, 1 skip, 2 todo), hoist, bun-remove, bun-add, bun-update, bun-update-transitive, bun-install-tarball-integrity, bun-install-patch, bun-patch, bun-dedupe, bun-audit, bun-link, bun-install-staging, bun-workspaces, bun-workspaces-self-contained, overrides, nested-overrides, frozen-lockfile-pruned, frozen-lockfile-outdated, bun-install-offline, lockfile-only, bun-install-backends, bun-lock, catalogs, isolated-install, bun-install, bun-install-registry. In bun-install-git-deps one case hit its own 30 s limit in the full run ("a long chain of links costs no more than as many links to one file"). Alone it passes in 13 s here and in 16 s on main.
  • cargo check for Linux, x86_64-pc-windows-msvc and aarch64-apple-darwin, and cargo clippy on bun_install: no warnings. I could not run Windows or macOS.

Limits, in detail

  • file: folder and link:: their folders have no .bun-tag. The old folder stays and the dependent's copy is deleted, without a message. install(hoisted): do not accept a link in the place of a registry package #45749 is open for links.
  • A tarball folder that Bun 1.4.3 or older installed has no .bun-tag. If the switch is the first install with the new Bun, the result is main's. One plain bun install before the switch lays the tag, if the tarball is still there. A git checkout has a tag in every version.
  • bun.lock changed outside the install (git pull, bun install --lockfile-only, bun install --filter that leaves the folder out, bun add <tarball> --no-save and then bun install): bun install reports no changes and keeps the old folder. bun prune and an install that leaves out dependencies keep the dependent's copy and warn.
  • A registry package that ships its own .bun-tag, or whose patch adds one: bun prune and the removal after an install keep a nested copy of it and warn, where main removes the copy. The note's remedy does not clear this. I know no published package with a .bun-tag at its root. The install does not replace such a folder.
  • bun prune does not clean inside the folder of another source, and prints no message for it. Main has this rule for a folder of another version (owners_installed).
  • bun prune keeps a copy below a tarball folder without the right .bun-tag, and asks for bun install. A tarball folder that Bun 1.4.3 laid is such a folder until one bun install.
  • bun remove --offline and bun install --offline exit 1 (error: --offline: "dep-c" is not in the cache) when the registry package is not in the cache. Main keeps the old folder, deletes the dependent's copy and exits 0.
  • bun prune accepts any folder with the right name for a file: folder package, as on main.
  • Registry to registry at the same name and version with other bytes (another registry, a republished version): no tag can tell the two apart. As on 1.4.2, in both linkers.
  • bun patch <path> and bun patch --commit <path> still take a tarball or git folder for the registry package of its name and version.
  • A folder that cannot be renamed aside (a mount point) is linked in place and keeps the old .bun-tag. install: clear a package folder that cannot be renamed aside instead of linking on top of it #45572 is open for that.

Other designs

  • A record, by place, of what the last install laid. npm, pnpm and Yarn keep one in node_modules. It covers file: folders, links, a pulled bun.lock and the registry-to-registry case. It costs one file read and one write per hoisted install, and it is a new file in node_modules. install: consolidate the open package manager pull requests #44968 names a state file per project as the complete fix for another gap (a killed install) and adds none.
  • The same comparison without a file: the places of bun.lock before and after the run. It covers file: folders and links in the run that changes them. A branch with that design exists (robobun/a6d3d1e4/relink-changed-source). A review of it found layouts where it installs a folder again that did not change: two trees that share one folder, a saved tree that differs from the linked one, and --no-save.
  • A stamp in the installed package.json, which the checks already parse. install: name the patch in the hoisted copy of a patched package #44622 builds such a stamp for patches (_bunPatchHash).
  • A .bun-tag for registry packages, written at extraction. Trees and caches from older versions have none.
  • A check of .bun-tag in every registry folder in every install: one more openat per registry package in the run with no changes.

This PR uses the tag that is already on disk, only in the run that changes the source, because that adds no format and no work to an install without a tarball or git package.

Review

The review before this push raised 28 concerns. 15 changed the code or the tests: the name condition in place of a list of tag bytes, the compare with the cache entry, no rule for a tarball with the registry's bytes, no cache lookup in bun prune, the tarball arm, and the new test rows. 10 changed this text. Not taken:

  • A keep, by place, in the removal after the install, so that a file: folder switch keeps the dependent's copy as 1.4.2 does. It is a second mechanism and it leaves the old folder in place. It is handed off as its own change.
  • One verifier that the install and bun prune share for every source kind. The tarball arm now uses the shared tarball_tag_matches. The rest is a larger change.
  • A rule that keeps a tarball with the registry's bytes, as a step to a registry stamp. Another concern asked to remove that rule, and the install now replaces the folder.

Related open PRs


no test proof · iteration 0 · platform-specific test(s) that do not run on this machine, deferring to CI, which covers all platforms: test/cli/install/bun-prune.test.ts

@robobun

robobun commented Oct 20, 2026

Copy link
Copy Markdown
Collaborator Author

Status

Reproduced on main with a release build and the hoisted linker:

  1. package.json has "dependencies": { "dep-c": "file:./dep-c-1.0.1.tgz", "p": "1.0.0" }. The registry has dep-c@1.0.1, and p depends on dep-c@^1.0.0.
  2. Run bun install. node_modules/dep-c is the tarball. node_modules/p/node_modules/dep-c is the registry package.
  3. Run bun remove dep-c.

On main, node_modules/dep-c is still the tarball and node_modules/p/node_modules/dep-c is deleted. bun install --frozen-lockfile then prints Checked 2 installs across 3 packages (no changes) and exits 0.

With this PR, node_modules/dep-c is the registry package after step 3.

PR: #46153

@robobun

robobun commented Oct 20, 2026 •

Copy link
Copy Markdown
Collaborator Author
Updated 6:56 AM PT - Oct 22nd, 2026

✅ @robobun, your commit fea0ca180b0d30e57ab0450b00e02da99ab7f2f4 passed in Build #130905! 🎉


🧪   To try this PR locally:

bunx bun-pr 46153

That installs a local version of the PR into your bun-46153 executable, so you can run:

bun-46153 --bun

@coderabbitai

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
📥 Commits

Reviewing files that changed from the base of the PR and between eb4ad72 and fea0ca1.

📒 Files selected for processing: 6
  • src/install/PackageInstall.rs
  • src/install/PackageInstaller.rs
  • src/install/PackageManager/install_with_manager.rs
  • src/install/hoisted_install.rs
  • src/install/prune.rs
  • test/cli/install/bun-prune.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.

Walkthrough

Installation now uses prior lockfile source information and .bun-tag comparisons when verifying packages. Pruning validates package names, versions, and tags, then preserves and reports packages classified as OtherSource. Tests cover source transitions, tag cases, and nested package copies.

Changes

Package tag validation

Layer / File(s) Summary
Use prior source and tag state during installation
src/install/PackageInstall.rs, src/install/PackageInstaller.rs, src/install/PackageManager/install_with_manager.rs, src/install/hoisted_install.rs, src/install/PackageManager/security_scanner.rs, test/cli/install/bun-prune.test.ts
Hoisted installation passes the pre-clean lockfile to PackageInstaller. For NPM verification, the installer checks whether the prior lockfile used a Git or tarball source and compares destination and cache .bun-tag values. Tests cover source transitions and install, update, remove, and dedupe flows.
Classify and preserve tagged packages during pruning
src/install/prune.rs, test/cli/install/bun-prune.test.ts
Pruning validates package names and versions, checks tags, and caches each verification result. It retains and reports packages classified as OtherSource, including qualifying ancestor copies. Tests cover tag validation and nested copies.

Suggested reviewers: jarred-sumner

Priority: ➖ Normal

Merge Risk: 🔵 Low · up to fea0c

Mergeable with awareness that pruning a registry package that ships its own tag may leave a nested copy and show an unnecessary removal warning.

Pre-merge checks: Passed 4
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: replacing an installed tarball or Git folder when the package now resolves to the registry.
Description check Passed The description is detailed and covers the problem, fix, verification, test results, limitations, and design decisions. It does not use the exact template headings, but it provides the required inform…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description is detailed and covers the problem, fix, verification, test results, limitations, and design decisions. It does not use the exact template headings, but it provides the required information and is substantially complete.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing blocking. The comments below are optional suggestions. There is no need to push a fix for them before merging.

Beyond the inline findings, I also checked the isolated linker for the same name+version conflation: its store keys (fmt_store_key in src/install/isolated_install/Store.rs) include the full resolution (tarball URL, git commit), so a tarball and a registry package of the same version land in separate store entries and that path is not affected. The None passed from security_scanner.rs and the "unreadable .bun-tag counts as other" branch in PackageInstall::has_bun_tag were also examined and ruled out as regressions on the paths they gate.

Extended reasoning...

The change adds .bun-tag-based detection to the hoisted installer and bun prune so a tarball/git folder is not accepted as the registry package of the same name and version, plus a memo refactor in prune.rs and a new non-creating cache opener; it touches no auth, crypto or injection surface. Six verified findings are posted inline (false warnings when the cache entry is gone, nested extraneous entries no longer pruned under an OtherSource folder, empty-tag reinstall loops, and pre-existing gaps for the no-diff pull and file: cases), so a human should weigh those before merging.

Additional findings (outside the current diff — GitHub can't attach inline comments there):

  • 🟡 src/install/prune.rs — Users running bun prune with a stale tarball or git folder now silently keep every extraneous entry under that folder's nested node_modules, where the base branch removed them. At src/install/prune.rs:1381 is_installed returns false for the new Installed::OtherSource verdict, so scan_folder keeps everything, and only removable sets kept_other_source, so no warn and no note are printed. The same silent keep applies to the folder's whole subtree through owners_installed at src/install/prune.rs:1402. Fix: when is_installed or owners_installed see OtherSource, set kept_other_source and emit the same warn/note that removable prints, so prune never degrades to a silent no-op for the population this PR targets.

    Why this was flagged

    The trigger is a hoisted project whose node_modules/dep-c is a tarball or git checkout with the same name and version as the registry dep-c that bun.lock now expects, and whose node_modules/dep-c/node_modules holds entries bun.lock does not list; the user runs bun prune. On the base branch installed at the old src/install/prune.rs Npm arm returned Matches on name+version, so is_installed was true and those nested entries were pruned. After the change src/install/prune.rs:1155-1158 returns Installed::OtherSource, is_installed at src/install/prune.rs:1065-1070 compares it to Matches and returns false, and the closure at src/install/prune.rs:1381 keeps every entry. kept_other_source is only set inside removable at src/install/prune.rs:1036-1038, which this path never calls for the tarball folder itself because it is an expected entry, so the user sees exit 0, no warn: and no note: while prune has skipped the subtree. The PR text claims prune keeps and warns; here it keeps and stays silent.

    Verification: In src/install/prune.rs, the Npm arm of installed (lines 1149-1158) returns Installed::OtherSource. is_installed (lines 1065-1070) compares the verdict == Installed::Matches, so it is false for OtherSource. At lines 1375-1386 !is_installed short-circuits, so removable is never reached. Only removable (lines 1035-1053) sets kept_other_source and prints the warn, so nothing is printed.

  • 🟡 src/install/PackageManager/install_with_manager.rs — nit, pre-existing: after this change bun remove dep-c in the tarball-to-registry case prints 1 package installed and no - dep-c line, while main prints - dep-c and 1 package removed. The replacement of node_modules/dep-c makes install_summary.success 1, and print_removed at src/install/PackageManager/install_with_manager.rs:1285-1287 requires install_summary.success == 0. Fix: for Subcommand::Remove, print the removed rows whenever requests_removed_from_lockfile > 0, independent of how many packages the same run installed, and keep the installed count line after them.

    Why this was flagged

    The root depends on a tarball dep-c@ 1.0.1 and p depends on the registry dep-c@^1.0.0; the user runs bun remove dep-c. With this PR has_other_tag at src/install/PackageInstaller.rs:2019-2021 makes the installer replace node_modules/dep-c, so install_summary.success is 1. print_removed at src/install/PackageManager/install_with_manager.rs:1285-1287 is Remove && summary.remove > 0 && install_summary.success == 0, so print_removed_rows is skipped and the else if this.summary.remove > 0 branch at line 1305 is never reached; the summary says 1 package installed. On main the folder is skipped, success is 0, and the user sees - dep-c and 1 package removed. The PR description lists this output for sign-off; the condition is pre-existing code, but this change is what newly routes a plain bun remove through it in this scenario, so a user who asked to remove a package is told one was installed.

    Verification: Trigger: bun remove <name> where the removed dependency was a tarball/git package and another package needs the registry package. src/install/PackageManager/install_with_manager.rs:1285-1287 requires install_summary.success == 0; on the base nothing is reinstalled, so print_removed_rows prints - dep-c. The new test at test/cli/install/bun-prune.test.ts:4338-4368 does not assert stdout.

Comment thread src/install/prune.rs Resolved
Comment thread src/install/PackageInstaller.rs Resolved
Comment thread src/install/PackageInstaller.rs Resolved
@robobun

robobun commented Oct 21, 2026

Copy link
Copy Markdown
Collaborator Author

Replies to the two findings outside the diff. The four inline threads have their own replies.

Entries inside a folder of another source (is_installed and owners_installed in src/install/prune.rs). No change. This is the existing rule for a folder that is not the package bun.lock expects: bun prune does not clean inside it, because its contents were installed for another package (see the comment on owners_installed). On main the rule applies to a folder of another version, and bun prune prints no message for it. I checked that on a debug build of main: a stray entry below a folder of another version stays, and the output is nothing to prune. A folder of another source now gets the same answer. The entries there are the nested dependencies of the tarball or git package, and that package needs them while its folder is in place. The warning is for a copy that bun.lock no longer places and that bun prune keeps.

bun remove prints 1 package installed (print_install_summary). No change in this PR. print_removed needs install_summary.success == 0 since #38333, so every bun remove that installs a package prints the installed count and no - name row. A change to that rule changes the output of those removals too. The PR notes list the new output for sign-off. One correction: on main this flow prints - dep-c and done, not 1 package removed, because the name dep-c stays in bun.lock.

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review found no issues

No high-confidence issues detected in this change.

A tarball or git dependency can have the name and version of a registry
package. The hoisted linker compares only the name and version in
package.json, so when the name moved to the registry (`bun remove`,
`bun add`, a package.json edit) it kept the old folder and reported no
changes. The same run deleted the registry copy that a dependent had in
its own node_modules, and the dependent loaded the old files. `bun
update` has done this since #38333. `bun remove`, `bun add` and `bun
install` do it since #44968.

The install now replaces the folder when its `.bun-tag` is the tag of a
tarball or git package that the loaded bun.lock has for that name. It
checks this in a run with a package.json change and in `bun update`,
`bun dedupe` and `bun audit fix`.

`bun prune` and the passes that remove nested copies after an install
keep the copy below a folder whose `.bun-tag` is not the registry
package's own, and print a warning and a note. A tag is the package's
own when it is the integrity of the package, or when the package's
cache entry has the same file: the package ships it, or a patch adds
it.

This change does not cover a `file:` folder, a `link:` dependency
(#28964), or a tarball folder that Bun 1.4.3 or older installed, which
has no `.bun-tag`. When bun.lock changed outside the install, `bun
install` still keeps the old folder, and `bun prune` then keeps the
copy and warns.
A tarball package gets two entries in `other_tags`: its integrity and the
empty tag that `--no-verify` leaves. A tarball package with no integrity
in bun.lock got the empty tag twice. The list is now free of duplicates.
The installer listed the `.bun-tag` bytes of the tarball and git packages
of the loaded bun.lock and compared the folder's tag with them. `bun
update` can give a loaded tarball row a new integrity before the install
runs, so the list missed the folder's tag and the old folder stayed.

The installer now asks the lockfile from before `clean` if the name has
a tarball or a git package. If it has one, a folder with a `.bun-tag`
is installed again, unless the cache entry of the registry package has
the same `.bun-tag`. A tarball with the bytes of the registry's tarball
is replaced too.

`bun prune` and the removal of nested copies take every `.bun-tag` in
the folder of a registry package for another source. They no longer
read the cache. For a tarball package they now compare the folder's
`.bun-tag` with the integrity in bun.lock, as the installer does.
Before, `bun prune` deleted a tarball copy below a registry folder of
the same name.
@robobun
robobun force-pushed the robobun/a6d3d1e4/registry-folder-tag branch from eb4ad72 to fea0ca1 Compare October 22, 2026 12:27
@robobun robobun changed the title install: do not accept a tarball or git folder as the registry package install: replace a tarball or git folder when its name moves to the registry Oct 22, 2026

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Findings marked 🟡 are optional suggestions and need no follow-up push.

Comment thread src/install/prune.rs
Comment on lines +1150 to +1153
let tag = sys::File::read_from(package.fd(), BUN_TAG);
if !tag.is_err_and(|err| err.get_errno() == E::ENOENT) {
return Installed::OtherSource;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Users of a registry package whose published files include a .bun-tag now get a permanent warning from bun prune and from installs that remove collapsed copies, and the stale nested copy is never removed. prune.rs:1150-1153 answers Installed::OtherSource for any readable or unreadable .bun-tag in a registry folder, while the install side (has_other_bun_tag, PackageInstall.rs:1282-1294) treats a tag equal to the cache entry's own .bun-tag as the package's own and keeps the folder, so the printed note cannot clear it. Fix: make prune and the removal passes use the same own-tag rule as the install (a tag equal to the cache entry's .bun-tag, or the patched entry's, is not OtherSource), with a missing cache entry falling back to Matches.

Why this was flagged

A registry package tagged@ 1.0.0 whose tarball contains a .bun-tag is hoisted to node_modules/tagged, and a dependent has a collapsed copy at node_modules/dependent/node_modules/tagged. The user runs bun prune, or any bun add/bun remove/bun update that reaches plan_and_remove_collapsed_copies. removable (prune.rs:1024) calls installed; prune.rs:1150-1153 reads .bun-tag, it is not ENOENT, and returns Installed::OtherSource without consulting the cache entry. removable at prune.rs:1033-1050 keeps the copy and warns has a .bun-tag but bun.lock expects a registry package; keeping ...; the note at prune.rs:1381 or prune.rs:1744 says to remove the folder and run 'bun install'. Doing so reinstalls the same package from the cache, which has_other_bun_tag at PackageInstall.rs:1291 accepts because the cache entry has the identical .bun-tag, so the next prune warns again: the warning is permanent and the copy is never removed. On the base branch the Npm arm compared only name and version, so the copy was removed with no output.

Verification: In src/install/prune.rs the Npm arm of installed at lines 1150-1153 reads BUN_TAG and returns Installed::OtherSource unless the read fails with ENOENT. On the base branch the Npm arm compared name and version only, so the copy was removed with no output. src/install/PackageInstall.rs:1282-1294 has_other_bun_tag treats a tag equal to the cache entry's .bun-tag as the package's own.

Comment on lines +1286 to +1292
Ok(tag) => {
let own = path::resolve_path::join_z::<path::platform::Posix>(&[
self.cache_dir_subpath.as_bytes(),
BUN_TAG,
]);
!sys::File::read_from(self.cache_dir, own).is_ok_and(|own| own == tag.bytes)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 nit (optional): a .bun-tag that opens but cannot be read is not treated as another package's tag, so the directory case is decided by the cache entry instead of the read error. src/install/PackageInstall.rs:1286 takes the Ok(tag) arm with empty tag.bytes and ignores tag.err (read_small_file at src/install/PackageInstaller.rs:323-329 wraps a read failure such as EISDIR in Ok), so the folder is kept whenever the cache entry's .bun-tag is empty. Fix: treat tag.err.is_some() like the Err(_) arm (return true), so every unreadable tag counts as another package, matching prune.rs:1151 which uses read_from and already does.

Why this was flagged

On Linux and macOS open(O_RDONLY) on a directory succeeds and the read fails with EISDIR. read_small_file (src/install/PackageInstaller.rs:320-329) returns Ok(ReadToEndResult { bytes: Vec::new(), err: Some(EISDIR) }) for a node_modules/<name>/.bun-tag that is a directory. has_other_bun_tag (src/install/PackageInstall.rs:1283-1293) only maps open errors to true; the Ok(tag) arm at :1286 never looks at tag.err and compares the empty bytes with the cache entry's .bun-tag at :1291. For a registry package whose cache entry has an empty .bun-tag the empty bytes compare equal and needs_install at src/install/PackageInstaller.rs:2038-2040 stays false, so the foreign folder is kept. The prune side at src/install/prune.rs:1150-1153 uses sys::File::read_from, which returns Err on a read failure, so the two checks disagree on the same folder. The base branch had no such check; the inconsistency is new.

Verification: nit. node_modules/<name>/.bun-tag opens but cannot be read while the cache entry ships an empty .bun-tag. read_small_file (src/install/PackageInstaller.rs:320-329) wraps a read failure as Ok; the Ok(tag) arm at src/install/PackageInstall.rs:1286 never inspects tag.err, so the folder is kept, unlike src/install/prune.rs:1150-1153 which returns OtherSource.

@robobun

robobun commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator Author

Closing as stale: this PR conflicts with main, and its last commit is from 2026-10-22.

The branch stays, so the work is not lost. To pick it up again, rebase the branch on main and reopen this PR.

@robobun robobun closed this Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants