Skip to content

Conversation

@dylan-conway
Copy link
Contributor

@dylan-conway dylan-conway commented Aug 12, 2025

Bun v1.2.19 added support for isolated installs similar to pnpm. This install strategy puts packages in ./node_modules/.bun. For example, [email protected] would exist in ./node_modules/.bun/[email protected]/node_modules/simple-git-hooks

This pr adds detection for .bun in getProjectRootDirectoryFromNodeModules

(oven-sh/bun#21754)

@changeset-bot
Copy link

changeset-bot bot commented Aug 12, 2025

⚠️ No Changeset found

Latest commit: 03523a0

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link

coderabbitai bot commented Aug 12, 2025

Walkthrough

Updated getProjectRootDirectoryFromNodeModules in simple-git-hooks.js to recognize Bun’s .bun installation layout and return the correct project root. Added a unit test in simple-git-hooks.test.js to validate Bun path handling alongside existing pnpm/deno cases. No changes to exported/public declarations.

Changes

Cohort / File(s) Summary
Root path resolution logic
simple-git-hooks.js
Extend project root detection: handle Bun’s .bun path segment (slice path up to .bun), placed before existing .store handling. No API changes.
Unit tests
simple-git-hooks.test.js
Add test covering Bun isolated linker path to ensure correct root resolution (var/my-project from .bun/.../simple-git-hooks).

Sequence Diagram(s)

sequenceDiagram
  participant Caller as Hook/Caller
  participant SGH as simple-git-hooks
  participant FS as Filesystem Path

  Caller->>SGH: getProjectRootDirectoryFromNodeModules(path)
  SGH->>FS: Inspect path segments
  alt Bun layout detected (.bun)
    SGH-->>Caller: Return path up to .bun parent
  else pnpm/deno/other layouts
    SGH-->>Caller: Apply existing rules (.pnpm/.deno/.store/etc.)
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~7 minutes

Poem

I twitch my ears at Bun’s new trail,
Through .bun burrows I will not fail.
Hop-hop, the root is found with glee,
From nested nodes to project tree.
Carrot-commit, tests all run—
A tidy warren, Bun by Bun. 🥕🐇

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

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

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
simple-git-hooks.test.js (1)

76-82: Add a companion Bun test (without trailing /node_modules/simple-git-hooks) for parity with pnpm

You already cover the full Bun path; consider also testing just .../node_modules/.bun/simple-git-hooks@<version> like we do for pnpm. This guards against regressions and asserts the function works when given the package-dir path itself.

Apply this diff to add the extra test:

       it("return correct dir when installed using bun with --linker=isolated", () => {
         expect(
             simpleGitHooks.getProjectRootDirectoryFromNodeModules(
                 `var/my-project/node_modules/.bun/simple-git-hooks@${packageVersion}/node_modules/simple-git-hooks`
             )
         ).toBe('var/my-project');
       })
+      
+      it("return correct dir when installed using bun with --linker=isolated (package dir only)", () => {
+        expect(
+            simpleGitHooks.getProjectRootDirectoryFromNodeModules(
+                `var/my-project/node_modules/.bun/simple-git-hooks@${packageVersion}`
+            )
+        ).toBe("var/my-project");
+      });
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between de65b00 and 03523a0.

📒 Files selected for processing (2)
  • simple-git-hooks.js (1 hunks)
  • simple-git-hooks.test.js (1 hunks)
🔇 Additional comments (1)
simple-git-hooks.js (1)

117-120: Bun isolated linker support: logic and placement look correct

The .bun detection mirrors existing .pnpm/.deno handling and is correctly placed before the .store check. The slice up to indexOfBunDir - 1 resolves the proper project root for paths like .../node_modules/.bun/<pkg>@<ver>/node_modules/<pkg>. LGTM.

@ryoppippi
Copy link

I need this!!

Copy link
Owner

@toplenboren toplenboren left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

@toplenboren toplenboren merged commit 33af460 into toplenboren:master Sep 12, 2025
5 checks passed
@ryoppippi
Copy link

hello @toplenboren could you publish this change?

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.

4 participants