fix: bsh sync writes into the pnpm store instead of the project root#46
Merged
Conversation
🦋 Changeset detectedLatest commit: 2fc95df 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 |
commit: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Symptom
In a project using pnpm's default isolated
node_moduleslayout,pnpm bsh syncreports success (Synced 8 skills to skills/) but nothing appears at the project root. The output —skills/symlinks, theAGENTS.mdsentinel block, and the.gitignoresection — lands inside the store instead:Observed with
@bomb.sh/tools@0.5.4on pnpm 10.7.0 / Node 24 (bombshell-dev/cooper).Cause
findParentPackagestarted fromfindPackageJSON(import.meta.url)and walked up looking for the nearest enclosingpackage.json. Under pnpm,import.meta.urlresolves through thenode_modules/@bomb.sh/toolssymlink to the real location insidenode_modules/.pnpm/<hash>/node_modules/@bomb.sh/tools, so the first "parent" it finds is a neighbor in the store, and the store directory becomes the sync root. Hoisted layouts (npm,node-linker=hoisted) walk up to the actual project, which is why only pnpm's default layout is affected.Fix
Resolve the project from the invocation context instead of the package's physical location:
INIT_CWD(set by pnpm/npm to the directory the script was run from, surviving package-script cwd rewrites) with a fallback tocwd(), thenfindPackageJSONfrom there. A candidate named@bomb.sh/toolsreturnsnull, preserving the existing skip when running inside this repo.Verified end to end: from a scratch project with the fixed CLI,
syncwritesskills/,AGENTS.md, and.gitignoreat that project's root; running inside this repo still prints the skip message. Two unit tests cover theINIT_CWDresolution and the self-package guard.