From ed1fb3ee0362f78bc45f1e51ff8a2137d7b1450f Mon Sep 17 00:00:00 2001 From: Olivier Chafik Date: Fri, 6 Mar 2026 16:15:26 +0000 Subject: [PATCH] fix: pre-commit stages only originally-staged files; add .npmrc Bug 1: .husky/pre-commit line 21 ran: git diff --name-only --diff-filter=M | xargs -r git add which stages EVERY modified tracked file in the worktree. If a contributor has unstaged WIP elsewhere, it gets silently swept into the commit. Fix: capture `git diff --name-only --cached` before running build/prettier, then only re-add that set. src/generated/ is staged explicitly since build:all regenerates it from spec.types.ts. Bug 2: no repo-local .npmrc meant the maintainer's global artifactory registry leaked into package-lock.json, requiring the Docker regen dance. Committing .npmrc with registry=https://registry.npmjs.org/ overrides user-global config. Docker regen is now optional (still useful for linux-amd64 optionalDeps). --- .husky/pre-commit | 11 +++++++++-- .npmrc | 1 + AGENTS.md | 5 ++++- 3 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 .npmrc diff --git a/.husky/pre-commit b/.husky/pre-commit index 942f08589..b0d5ff537 100644 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -14,8 +14,15 @@ if grep -E '"resolved": "https?://' package-lock.json | grep -v registry.npmjs.o exit 1 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) + npm run build:all npm run prettier:fix -# Stage any files reformatted by prettier (generated files, source, docs, etc.) -git diff --name-only --diff-filter=M | xargs -r git add +# Re-stage originally-staged files (prettier may have reformatted them) +echo "$STAGED" | xargs -r git add + +# Also stage generated files (regenerated by build:all from spec.types.ts) +git add src/generated/ diff --git a/.npmrc b/.npmrc new file mode 100644 index 000000000..214c29d13 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +registry=https://registry.npmjs.org/ diff --git a/AGENTS.md b/AGENTS.md index 41997da16..6bfc8cdd6 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -39,7 +39,10 @@ npm test # Check JSDoc comment syntax and `{@link}` references npm exec typedoc -- --treatValidationWarningsAsErrors --emit none -# Regenerate package-lock.json (especially on setups w/ custom npm registry) +# Regenerate package-lock.json +# Note: repo .npmrc pins registry to npmjs.org, so a plain `npm i` is safe even +# if your global npm config points elsewhere. The Docker step below is optional +# — it locks linux-amd64 optionalDependencies (sharp, rollup, bun) for CI. rm -fR package-lock.json node_modules && \ docker run --rm -it --platform linux/amd64 -v $PWD:/src:rw -w /src node:latest npm i && \ rm -fR node_modules && \