-
Notifications
You must be signed in to change notification settings - Fork 11
refactor: use bun init instead of copying template config files #24
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
Conversation
- 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]>
|
Caution Review failedThe pull request is closed. WalkthroughThe initialization process for hooks was refactored to use Changes
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
Possibly related PRs
Suggested labels
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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 installationsSimilar to the previous method,
_stderrshould 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 namingThe variable
_stderruses 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
📒 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 genericrunBunInstall().
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 runningbun init -ygenerates apackage.jsoncontaining"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]>
|
🎉 This PR is included in version 1.2.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Summary
bun init -yto generate project configMotivation
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
templates/hooks/package.json,templates/hooks/tsconfig.json, andtemplates/hooks/.gitignoresrc/commands/init.tsto:runBunInit()method that runsbun init -ygenerateHookFiles()to callrunBunInit()before copying template filesrunBunInstall()toinstallDependencies()and install@types/nodespecificallyTesting
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
Bug Fixes
Chores