Skip to content

Commit 739c0e0

Browse files
authored
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.
1 parent 01d826a commit 739c0e0

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

.husky/pre-commit

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ if grep -E '"resolved": "https?://' package-lock.json | grep -v registry.npmjs.o
1515
fi
1616

1717
# Capture staged files so we only re-stage what the user intended to commit
18-
# (avoids sweeping unrelated WIP into the commit)
19-
STAGED=$(git diff --name-only --cached)
18+
# (avoids sweeping unrelated WIP into the commit). --diff-filter=d skips
19+
# deletions so the xargs git add below doesn't fail on removed paths.
20+
STAGED=$(git diff --name-only --cached --diff-filter=d)
2021

2122
npm run build:all
2223
npm run prettier:fix

scripts/link-self.mjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
* so examples always type-check against the latest local types.
66
* See: https://github.com/npm/feedback/discussions/774
77
*/
8-
import { cpSync, existsSync } from "fs";
8+
import { cpSync, existsSync, lstatSync } from "fs";
99

1010
const target = "node_modules/@modelcontextprotocol/ext-apps";
1111
if (!existsSync(target)) process.exit(0);
12+
// If target is a symlink (e.g. to the repo root), dist is already current.
13+
if (lstatSync(target).isSymbolicLink()) process.exit(0);
1214

1315
cpSync("dist", `${target}/dist`, { recursive: true });
1416
cpSync("package.json", `${target}/package.json`);

0 commit comments

Comments
 (0)