Skip to content

[ef-29] fix: npm uninstall leaves hooks in settings.json#26

Merged
NiveditJain merged 1 commit into
mainfrom
ef-29
Apr 7, 2026
Merged

[ef-29] fix: npm uninstall leaves hooks in settings.json#26
NiveditJain merged 1 commit into
mainfrom
ef-29

Conversation

@NiveditJain

@NiveditJain NiveditJain commented Apr 7, 2026

Copy link
Copy Markdown
Member

Summary

  • Root cause: npm uninstall does not set INIT_CWD (unlike npm install). The preuninstall guard !process.env.INIT_CWD || ... treated a missing INIT_CWD as a dev-context signal and exited immediately — before removing any hooks from ~/.claude/settings.json.
  • Fix: Changed the guard in scripts/preuninstall.mjs to process.env.INIT_CWD && process.env.INIT_CWD === process.cwd() — now only skips in true dev context (where INIT_CWD is explicitly set and matches cwd). When INIT_CWD is absent, cleanup proceeds normally.
  • Test fix: Replaced the test that was asserting the broken early-exit behavior with one that verifies hooks are actually removed when INIT_CWD is not set (the real npm uninstall -g scenario).
  • Bumps version to 0.0.1-beta.5.

Test plan

  • bun run test:run __tests__/scripts/preuninstall.test.ts — all 14 tests pass
  • After publishing, run npm install -g failproofai && failproofai --install-policies && npm uninstall -g failproofai and confirm hook entries are removed from ~/.claude/settings.json

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Fixed uninstall cleanup logic to properly execute in development scenarios
  • Tests
    • Updated preuninstall tests to reflect corrected cleanup behavior

Version: 0.0.1-beta.5

…to 0.0.1-beta.5

npm uninstall does not set INIT_CWD (unlike npm install), so the guard
`!process.env.INIT_CWD || ...` caused the preuninstall script to exit
immediately without removing hook entries from ~/.claude/settings.json.

Fix: only skip when INIT_CWD is set AND equals cwd (true dev-context
signal). When INIT_CWD is absent the script now proceeds with cleanup.

Also updates the test that was asserting the broken early-exit behavior
to instead verify hooks are removed in the npm-uninstall scenario.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Apr 7, 2026

Copy link
Copy Markdown
ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Free

Run ID: 56467de3-a196-4456-9de0-34a30f0793be

📥 Commits

Reviewing files that changed from the base of the PR and between 3361804 and f34dbb7.

📒 Files selected for processing (3)
  • __tests__/scripts/preuninstall.test.ts
  • package.json
  • scripts/preuninstall.mjs

📝 Walkthrough

Walkthrough

The preuninstall script's development-context guard condition was inverted to exit only when INIT_CWD is set and equals the current directory. This reversal enables hook removal logic when INIT_CWD is unset. The test suite was updated to reflect this behavior change, and the package version was incremented.

Changes

Cohort / File(s) Summary
Development Context Guard Logic
scripts/preuninstall.mjs, __tests__/scripts/preuninstall.test.ts
Reversed the early-exit condition: script now exits only when INIT_CWD is set and equals current directory. Test updated to verify hook removal logic executes when INIT_CWD is unset, asserting fs.writeFileSync is called with hooks set to undefined.
Version Bump
package.json
Updated version from 0.0.1-beta.4 to 0.0.1-beta.5.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A guard reversed, a logic dance,
Where INIT_CWD now takes its chance,
Hooks removed when unset it stays,
Beta bumped through smoother ways,
Cleanup works in dev's own place! ✨


Note

🎁 Summarized by CodeRabbit Free

Your organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login.

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

@NiveditJain NiveditJain merged commit e8e10fe into main Apr 7, 2026
8 checks passed
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.

1 participant