Repository navigation
Conversation
🦋 Changeset detectedLatest commit: 9c3119b The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to The change is mergeable after normal checks. The dependency-install scenario is covered by a test, though that test was not executed in this review. Pre-merge checks |
|
Fixes #82
cli.jsnow exits early with an[INFO]message when the working directory is insidenode_modules, so a dependency that runsnpx simple-git-hooksfrom its ownpostinstallcan no longer overwrite or remove the parent project's git hooks.Problem
In that case the CLI runs from
<parent>/node_modules/<dep>.setHooksFromConfigreads the dependency's config,getGitProjectRootwalks up to the parent's.git, and the dependency's hooks are written there. Parent hooks missing from the dependency's config are deleted unlesspreserveUnusedis set.Change
simple-git-hooks.js: new exportedisInsideNodeModules(directory=process.cwd()). It splits on/and\and looks for an exactnode_modulessegment, asgetProjectRootDirectoryFromNodeModulesdoes.cli.js: guard after the existingskipInstall()check, same shape.postinstall.jsis unchanged. It always runs insidenode_modulesand already resolves the project root throughINIT_CWD.The dependency's own developer still gets hooks in their checkout, because that checkout is not under
node_modules.I chose to skip rather than install into the parent root, because the config in the working directory belongs to the dependency, not the parent.
Known limit: a project that itself lives under a directory named
node_modulescan no longer run the CLI from there, because it looks the same as a dependency. I expect this to be rare. If you want an escape hatch, I can add an opt-out environment variable.Tests
isInsideNodeModules: plain layout, nested pnpm store, Windows separators, a normal project, and anode_modules_backupsegment that must not match.simple-git-hooks.test.jsbuilds a parent repo with an existingpre-pushhook and anode_modules/some-deppackage with its own config, then runs the CLI from the dependency directory.Without the
cli.jsguard the e2e test fails: the CLI installs the dependency'spre-commitand deletes the parent'spre-push. With the guard it passes.Summary by CodeRabbit
node_modulesdirectory. The CLI displays an informational message, and existing hooks in the parent project remain unchanged.node_modulesare not treated as being inside it.