build: fix pre-commit hook for symlinked self-dep and staged deletions (#621)

- link-self.mjs: skip when node_modules/@modelcontextprotocol/ext-apps is
  a symlink (e.g. to the repo root). cpSync("dist", target/dist) was
  failing with ERR_FS_CP_EINVAL because src and dest resolved to the
  same path.
- .husky/pre-commit: capture staged files with --diff-filter=d so the
  re-stage step doesn't fail with "pathspec did not match" on commits
  (typically merges) that include deletions.
This commit is contained in:
Olivier Chafik 2026-04-21 11:28:46 +01:00 • committed by GitHub
commit 739c0e049d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 6 additions and 3 deletions

View file

@ -15,8 +15,9 @@ if grep -E '"resolved": "https?://' package-lock.json | grep -v registry.npmjs.o
fi
# Capture staged files so we only re-stage what the user intended to commit
# (avoids sweeping unrelated WIP into the commit)
STAGED=$(git diff --name-only --cached)
# (avoids sweeping unrelated WIP into the commit). --diff-filter=d skips
# deletions so the xargs git add below doesn't fail on removed paths.
STAGED=$(git diff --name-only --cached --diff-filter=d)
npm run build:all
npm run prettier:fix

View file

@ -5,10 +5,12 @@
* so examples always type-check against the latest local types.
* See: https://github.com/npm/feedback/discussions/774
*/
import { cpSync, existsSync } from "fs";
import { cpSync, existsSync, lstatSync } from "fs";
const target = "node_modules/@modelcontextprotocol/ext-apps";
if (!existsSync(target)) process.exit(0);
// If target is a symlink (e.g. to the repo root), dist is already current.
if (lstatSync(target).isSymbolicLink()) process.exit(0);
cpSync("dist", `${target}/dist`, { recursive: true });
cpSync("package.json", `${target}/package.json`);