Skip to content

Conversation

@johnlindquist
Copy link
Owner

@johnlindquist johnlindquist commented Jul 8, 2025

Summary

  • Remove template package.json, tsconfig.json, and .gitignore files
  • Update init command to run bun init -y to generate project config
  • Add proper error handling for when Bun is not installed
  • Install @types/node dependency after project initialization

Motivation

This approach is cleaner as it lets Bun generate the appropriate configuration files instead of maintaining static template copies. This ensures users always get the latest Bun configuration defaults.

Changes

  • Removed templates/hooks/package.json, templates/hooks/tsconfig.json, and templates/hooks/.gitignore
  • Modified src/commands/init.ts to:
    • Add runBunInit() method that runs bun init -y
    • Update generateHookFiles() to call runBunInit() before copying template files
    • Rename runBunInstall() to installDependencies() and install @types/node specifically
    • Add better error handling when Bun is not installed

Testing

The init command works correctly when tested locally, creating a proper TypeScript project with Bun's defaults.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Improved initialization process now sets up a TypeScript project automatically in the hooks directory.
    • Enhanced error messages if Bun is not installed, including detailed installation instructions.
  • Bug Fixes

    • More robust error handling during project initialization and dependency installation.
  • Chores

    • Removed redundant configuration files from the hooks template, relying on automated project setup instead.
    • Updated CI workflow to include Bun runtime setup alongside Node.js.

- Remove template package.json, tsconfig.json, and .gitignore files
- Update init command to run `bun init -y` to generate project config
- Add proper error handling for when Bun is not installed
- Install @types/node dependency after project initialization

This approach is cleaner as it lets Bun generate the appropriate configuration
files instead of maintaining static template copies.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@coderabbitai
Copy link

coderabbitai bot commented Jul 8, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

The initialization process for hooks was refactored to use bun init -y for project setup instead of copying template configuration files. Dependency installation now specifically adds @types/node with improved error handling for missing Bun installations. Template files package.json, tsconfig.json, and .gitignore were removed from the repository.

Changes

Files/Groups Change Summary
src/commands/init.ts Refactored initialization: added runBunInit, renamed and updated dependency install logic, improved error handling for Bun presence, removed config file copying.
templates/hooks/.gitignore Deleted: .gitignore file for hooks template removed.
templates/hooks/package.json, tsconfig.json Deleted: TypeScript and package configuration files for hooks template removed.
.github/workflows/test.yml Added Bun setup alongside Node.js in CI workflow jobs.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant InitCommand
    participant Bun

    User->>InitCommand: Run initialization
    InitCommand->>Bun: Execute 'bun init -y' in .claude/hooks
    Bun-->>InitCommand: Creates package.json, etc.
    InitCommand->>Bun: Execute 'bun add -d @types/node'
    Bun-->>InitCommand: Installs type dependencies
    InitCommand->>User: Display success or error messages
Loading

Possibly related PRs

Suggested labels

released

Poem

In the warren of code, a fresh path begun,
No more old configs—just a dash with Bun!
TypeScript hops in, dependencies align,
If Bun’s not installed, you’ll see a clear sign.
With templates now lighter,
The hooks setup’s brighter—
A rabbit’s delight in every new line! 🐇✨


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a780a21 and d102c01.

📒 Files selected for processing (1)
  • .github/workflows/test.yml (3 hunks)

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
🪧 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.
    • Explain this complex logic.
    • 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. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • 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 src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

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

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

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

Documentation and Community

  • 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

🔭 Outside diff range comments (1)
src/commands/init.ts (1)

176-198: Improve variable naming and add warning for failed installations

Similar to the previous method, _stderr should be renamed. Additionally, when dependency installation fails but continues, users should be warned.

-let _stderr = ''
+let stderr = ''

 child.stderr?.on('data', (data) => {
-  _stderr += data.toString()
+  stderr += data.toString()
 })

 // ... in the exit handler
 child.on('exit', (code) => {
   if (code === 0) {
     resolve()
   } else {
     // Non-zero exit code but not a critical failure
     // User can manually install dependencies later
+    console.log(chalk.yellow('\n⚠️  Warning: Failed to install @types/node dependency'))
+    console.log(chalk.gray('   You can manually install it later with: bun add -d @types/node'))
     resolve()
   }
 })
🧹 Nitpick comments (1)
src/commands/init.ts (1)

141-159: Fix misleading variable naming

The variable _stderr uses an underscore prefix which typically indicates an unused variable, but it's actually used in the error message.

-let _stderr = ''
+let stderr = ''

 child.stderr?.on('data', (data) => {
-  _stderr += data.toString()
+  stderr += data.toString()
 })

 // ... in the exit handler
-reject(new Error(`bun init failed with exit code ${code}: ${_stderr}`))
+reject(new Error(`bun init failed with exit code ${code}: ${stderr}`))
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8e63b74 and a780a21.

📒 Files selected for processing (4)
  • src/commands/init.ts (5 hunks)
  • templates/hooks/.gitignore (0 hunks)
  • templates/hooks/package.json (0 hunks)
  • templates/hooks/tsconfig.json (0 hunks)
💤 Files with no reviewable changes (3)
  • templates/hooks/package.json
  • templates/hooks/.gitignore
  • templates/hooks/tsconfig.json
🧰 Additional context used
📓 Path-based instructions (1)
`src/commands/**/*`: Commands must be implemented in the 'src/commands/' directory; currently, only the main 'init' command exists there.

src/commands/**/*: Commands must be implemented in the 'src/commands/' directory; currently, only the main 'init' command exists there.

📄 Source: CodeRabbit Inference Engine (CLAUDE.md)

List of files the instruction was applied to:

  • src/commands/init.ts
🧠 Learnings (2)
📓 Common learnings
Learnt from: CR
PR: johnlindquist/claude-hooks#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-07T16:54:50.705Z
Learning: Hooks are executed using the Bun runtime, which is a required dependency.
Learnt from: CR
PR: johnlindquist/claude-hooks#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-07T16:54:50.705Z
Learning: Applies to .claude/{settings.json,hooks/index.ts,hooks/lib.ts,hooks/session.ts} : The CLI generates a '.claude/' directory containing 'settings.json', 'hooks/index.ts', 'hooks/lib.ts', and 'hooks/session.ts' when initialized.
Learnt from: CR
PR: johnlindquist/claude-hooks#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-07T16:54:50.705Z
Learning: Applies to package.json : The project must use ESM modules (package.json must include '"type": "module"').
src/commands/init.ts (4)
Learnt from: CR
PR: johnlindquist/claude-hooks#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-07T16:54:50.705Z
Learning: Applies to .claude/{settings.json,hooks/index.ts,hooks/lib.ts,hooks/session.ts} : The CLI generates a '.claude/' directory containing 'settings.json', 'hooks/index.ts', 'hooks/lib.ts', and 'hooks/session.ts' when initialized.
Learnt from: CR
PR: johnlindquist/claude-hooks#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-07T16:54:50.705Z
Learning: Applies to src/commands/**/* : Commands must be implemented in the 'src/commands/' directory; currently, only the main 'init' command exists there.
Learnt from: CR
PR: johnlindquist/claude-hooks#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-07T16:54:50.705Z
Learning: Hooks are executed using the Bun runtime, which is a required dependency.
Learnt from: CR
PR: johnlindquist/claude-hooks#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-07T16:54:50.705Z
Learning: Applies to templates/**/* : Hook templates must be stored in the 'templates/' directory and are copied to the user's '.claude/' directory during initialization.
🔇 Additional comments (3)
src/commands/init.ts (3)

75-78: Good rename for clarity!

The method name installDependencies() better reflects its specific purpose of installing required dependencies rather than the generic runBunInstall().


92-98: Excellent error handling improvement!

The specific error handling for missing Bun installation provides clear, actionable guidance to users. The installation instructions are consistent with those shown in the warning message.


122-129: Confirmed: bun init enables ESM modules by default
Verified that running bun init -y generates a package.json containing "type": "module", so no additional steps are needed to enforce ESM in new projects.

The init command now uses 'bun init -y' to create the TypeScript project,
so Bun needs to be installed in the CI environment for tests to pass.

Added oven-sh/setup-bun@v2 action to all test jobs (test, smoke, integration).

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@johnlindquist johnlindquist merged commit 091ea4e into main Jul 8, 2025
9 of 10 checks passed
@github-actions
Copy link
Contributor

github-actions bot commented Jul 8, 2025

🎉 This PR is included in version 1.2.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@johnlindquist johnlindquist deleted the refactor/use-bun-init branch July 8, 2025 20:00
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