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:
parent
01d826aea0
commit
739c0e049d
2 changed files with 6 additions and 3 deletions
|
|
@ -15,8 +15,9 @@ if grep -E '"resolved": "https?://' package-lock.json | grep -v registry.npmjs.o
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Capture staged files so we only re-stage what the user intended to commit
|
# Capture staged files so we only re-stage what the user intended to commit
|
||||||
# (avoids sweeping unrelated WIP into the commit)
|
# (avoids sweeping unrelated WIP into the commit). --diff-filter=d skips
|
||||||
STAGED=$(git diff --name-only --cached)
|
# 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 build:all
|
||||||
npm run prettier:fix
|
npm run prettier:fix
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,12 @@
|
||||||
* so examples always type-check against the latest local types.
|
* so examples always type-check against the latest local types.
|
||||||
* See: https://github.com/npm/feedback/discussions/774
|
* 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";
|
const target = "node_modules/@modelcontextprotocol/ext-apps";
|
||||||
if (!existsSync(target)) process.exit(0);
|
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("dist", `${target}/dist`, { recursive: true });
|
||||||
cpSync("package.json", `${target}/package.json`);
|
cpSync("package.json", `${target}/package.json`);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue