1
0
Fork 0
mirror of https://github.com/imjasonh/apidiff-action synced 2026-07-06 22:52:43 +00:00

Enforce Node 20 in pre-commit hooks

- Add Node version check to build-dist pre-commit hook
- Create helper script to switch to Node 20
- Update documentation with clear instructions
- Fix YAML syntax in pre-commit config

This ensures dist is always built with Node 20, preventing CI failures
due to version mismatches.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Jason Hall 2025-07-30 09:22:44 -04:00
parent f2b49d3bf2
commit 051f997977
Failed to extract signature
3 changed files with 41 additions and 5 deletions

View file

@ -32,7 +32,7 @@ repos:
hooks:
- id: build-dist
name: Build dist
entry: npm run build
entry: bash -c 'node_version=$(node --version); if [[ ! "$node_version" =~ ^v20\. ]]; then echo "Error - Node.js v20 is required (found $node_version). Use nvm to switch to Node 20."; exit 1; fi; npm run build'
language: system
pass_filenames: false
files: ^(index\.js|lib/.*\.js)$

View file

@ -89,17 +89,26 @@ The action uses `@vercel/ncc` to compile all dependencies into a single `dist/in
To build and commit dist after making changes:
```bash
# Ensure you're using Node v20 (use nvm if installed)
# Method 1: Use the helper script
./scripts/use-node-20.sh # Switches to Node 20
npm run build
git add dist/index.js
git commit -m "Rebuild dist"
# Method 2: Manual with nvm
nvm use # Reads .nvmrc and switches to Node 20.9.0
node --version # Should show v20.x.x
# Build and commit
npm run build
git add dist/index.js
git commit -m "Rebuild dist"
```
The pre-commit hooks will ensure dist is up to date before allowing commits.
**Important**: The pre-commit hooks will:
1. Verify you're using Node 20 before building dist
2. Automatically rebuild dist when source files change
3. Prevent commits if dist is out of date
If you get an error about Node version, switch to Node 20 using `nvm use` or `./scripts/use-node-20.sh`.
### Pre-commit Hooks

27
scripts/use-node-20.sh Executable file
View file

@ -0,0 +1,27 @@
#!/bin/bash
# Helper script to ensure Node 20 is being used
# Check if nvm is available
if ! command -v nvm &> /dev/null; then
if [ -f "$HOME/.nvm/nvm.sh" ]; then
source "$HOME/.nvm/nvm.sh"
else
echo "Error: nvm is not installed or not loaded"
echo "Please install nvm or source it in your shell"
exit 1
fi
fi
# Install Node 20 if needed and switch to it
echo "Switching to Node 20..."
nvm install
nvm use
# Verify we're on Node 20
node_version=$(node --version)
if [[ ! "$node_version" =~ ^v20\. ]]; then
echo "Error: Failed to switch to Node 20 (current: $node_version)"
exit 1
fi
echo "✓ Using Node $node_version"