Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement bun unlink {packageName} #18713

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

brainkim
Copy link
Contributor

@brainkim brainkim commented Apr 2, 2025

What does this PR do?

Saw that bun unlink {packageName} was unimplemented and gave it a shot. Fixes #7852.

  • Documentation or TypeScript types (it's okay to leave the rest blank in this case)
  • Code changes

How did you verify your code works?

  • I checked the lifetime of memory allocated to verify it's (1) freed and (2) only freed when it should be
  • I included a test for the new code, or an existing test covers it
  • JSValue used outside of the stack is either wrapped in a JSC.Strong or is JSValueProtect'ed
  • I wrote TypeScript/JavaScript tests and they pass locally (bun-debug test test-file-name.test)

It seemed like manager.updatePackageJSONAndInstallWithManager() in install.zig mostly handles the case of unlinking. I accounted for three cases when writing this code:

  • A new package is linked and unlinked
  • An existing unlinked package is linked and unlinked
  • A package linked with --save is unlinked with --save

The current summary is not that helpful, but I haven’t yet wrapped my head around how the lockfile diffing works. The tricky thing with unlink is that it typically won’t create package.json changes, so I’m unsure how to show the unlinked packages as removed.

@brainkim brainkim force-pushed the brian-unlink-package branch from e33055b to 2b9184f Compare April 2, 2025 02:48
return;
}

if (manager.options.do.install_packages) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The previous minimal bun remove logic triggers on do.write_package_json, but bun unlink defaults to --no-save and I think running removal/unlinking logic on do.install_packages makes more sense.

"",
expect.stringContaining("done"),
"",
]);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could maybe work on the summary output, but the current seems fine for now?

@DonIsaac DonIsaac requested a review from dylan-conway April 3, 2025 01:34
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.

Implement bun unlink {packageName}
1 participant