Skip to content

Commit 7eb72c7

Browse files
authored
fix: pre-commit stages only originally-staged files; add .npmrc (#538)
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).
1 parent b093e39 commit 7eb72c7

3 files changed

Lines changed: 14 additions & 3 deletions

File tree

.husky/pre-commit

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

17+
# 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)
20+
1721
npm run build:all
1822
npm run prettier:fix
1923

20-
# Stage any files reformatted by prettier (generated files, source, docs, etc.)
21-
git diff --name-only --diff-filter=M | xargs -r git add
24+
# Re-stage originally-staged files (prettier may have reformatted them)
25+
echo "$STAGED" | xargs -r git add
26+
27+
# Also stage generated files (regenerated by build:all from spec.types.ts)
28+
git add src/generated/

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
registry=https://registry.npmjs.org/

AGENTS.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ npm test
3939
# Check JSDoc comment syntax and `{@link}` references
4040
npm exec typedoc -- --treatValidationWarningsAsErrors --emit none
4141

42-
# Regenerate package-lock.json (especially on setups w/ custom npm registry)
42+
# Regenerate package-lock.json
43+
# Note: repo .npmrc pins registry to npmjs.org, so a plain `npm i` is safe even
44+
# if your global npm config points elsewhere. The Docker step below is optional
45+
# — it locks linux-amd64 optionalDependencies (sharp, rollup, bun) for CI.
4346
rm -fR package-lock.json node_modules && \
4447
docker run --rm -it --platform linux/amd64 -v $PWD:/src:rw -w /src node:latest npm i && \
4548
rm -fR node_modules && \

0 commit comments

Comments
 (0)