ext-apps/scripts/link-self.mjs
Olivier Chafik 739c0e049d
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.
2026-04-21 11:28:46 +01:00

16 lines
766 B
JavaScript

/**
* Workaround: npm workspaces don't symlink the root package into node_modules
* when child workspaces depend on it — it installs a stale registry copy instead.
* This script syncs the freshly-built dist/ and package.json into that copy
* so examples always type-check against the latest local types.
* See: https://github.com/npm/feedback/discussions/774
*/
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`);