diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e4f0a07..8152929 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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)$ diff --git a/CLAUDE.md b/CLAUDE.md index 1025fcc..1e7ac05 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -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 diff --git a/scripts/use-node-20.sh b/scripts/use-node-20.sh new file mode 100755 index 0000000..1e72088 --- /dev/null +++ b/scripts/use-node-20.sh @@ -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"