Skip to content

Conversation

@robobun
Copy link
Collaborator

@robobun robobun commented Jan 26, 2026

Summary

This PR adds a --preview flag to bun patch and bun patch-commit commands that allows users to see what a patch will contain before committing to it.

  • Prints the patch diff to stdout without saving the patch file
  • Does not modify package.json
  • Works with both bun patch --preview <path> and bun patch-commit --preview <path>

Motivation

When creating patches for dependencies (e.g., porting upstream bug fixes), users often want to create minimal patches. Currently, the only way to see the patch content is to run bun patch --commit, which saves the patch file and modifies package.json. If the patch needs adjustment, users must:

  1. Undo everything (revert bun.lock and package.json, delete the .patch file)
  2. Reinstall node_modules
  3. Run bun patch again and reapply changes
  4. Run bun patch --commit again

With --preview, users can iterate on their changes and preview the diff multiple times without any side effects.

Usage

# Preview what a patch will look like
bun patch --preview node_modules/package

# Or with patch-commit
bun patch-commit --preview node_modules/package

Test plan

  • Added tests for --preview flag
  • Verified preview prints diff to stdout
  • Verified preview does not create patches directory
  • Verified preview does not modify package.json
  • Verified "No changes detected" message works in preview mode
  • Verified existing --commit functionality still works

Closes #26463

🤖 Generated with Claude Code

Adds a `--preview` flag to `bun patch` and `bun patch-commit` commands that
prints the patch diff to stdout without saving the patch file or modifying
package.json.

This allows users to preview what a patch will contain before committing to
it, making it easier to create minimal patches when porting bug fixes from
upstream repositories.

Usage:
  bun patch --preview node_modules/package
  bun patch-commit --preview node_modules/package

Closes #26463

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@robobun
Copy link
Collaborator Author

robobun commented Jan 26, 2026

Updated 5:00 PM PT - Jan 26th, 2026

❌ Your commit 76163e20 has 3 failures in Build #35895 (All Failures):


🧪   To try this PR locally:

bunx bun-pr 26466

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

bun-26466 --bun

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 27, 2026

Walkthrough

The pull request adds a --preview flag to bun patch and bun patch-commit commands, enabling users to view the generated patch diff without modifying files or saving patch entries. When preview mode is active, the patch contents are printed to stdout and the operation exits before any filesystem changes occur.

Changes

Cohort / File(s) Summary
CLI and Options Parsing
src/install/PackageManager/CommandLineArguments.zig, src/install/PackageManager/PackageManagerOptions.zig
Introduces --preview flag to patch command arguments and wires it through the PatchOpts data structure. Adds preview: bool = false field to the commit variant of patch_features, updates CLI parsing to populate the preview boolean, and extends public parameter sets to recognize the new option in help text and argument parsing.
Patch Implementation
src/install/PackageManager/patchPackage.zig
Adds preview mode logic to doPatchCommit that prints generated patch contents to stdout and exits early, bypassing patch file creation and filesystem modifications while preserving error handling for stdout operations.
Test Coverage
test/cli/install/bun-patch.test.ts
Adds comprehensive test suite validating that bun patch --preview and bun patch-commit --preview print diffs without creating patch files, modifying patches directory, or updating package.json.patchedDependencies, including scenarios for modified and unmodified packages.

Suggested reviewers

  • zackradisic
  • pfgithub
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: adding a --preview flag to patch commands that shows diffs without saving.
Description check ✅ Passed The description covers both required sections (What does this PR do and How did you verify) with comprehensive details about the feature, motivation, usage, and test verification.
Linked Issues check ✅ Passed The PR fully implements the feature requested in #26463: a --preview flag that prints diffs without modifying state, supporting both patch and patch-commit commands with comprehensive test coverage.
Out of Scope Changes check ✅ Passed All changes are directly related to implementing the --preview flag feature for patch commands as specified in the linked issue, with no unrelated modifications.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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

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.

add option to preview diff using bun patch

2 participants