From 9f05344e16da973994325042a5ba7aa430983785 Mon Sep 17 00:00:00 2001 From: Jason Hall Date: Wed, 30 Jul 2025 09:13:03 -0400 Subject: [PATCH] Configure Node.js v20 for local development MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add .node-version and .nvmrc files specifying Node 20.9.0 - Add engines field to package.json requiring Node 20 - Re-enable dist build/check hooks in pre-commit - Add build-dist workflow for automated builds with Node 20 - Update documentation with Node version requirements This ensures consistent builds between local development and CI. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- .github/workflows/build-dist.yml | 52 ++++++++++++++++++++++++++++++++ .node-version | 1 + .nvmrc | 1 + .pre-commit-config.yaml | 29 +++++++++--------- CLAUDE.md | 18 +++++------ package.json | 3 ++ 6 files changed, 80 insertions(+), 24 deletions(-) create mode 100644 .github/workflows/build-dist.yml create mode 100644 .node-version create mode 100644 .nvmrc diff --git a/.github/workflows/build-dist.yml b/.github/workflows/build-dist.yml new file mode 100644 index 0000000..9731d1b --- /dev/null +++ b/.github/workflows/build-dist.yml @@ -0,0 +1,52 @@ +name: Build dist + +on: + push: + branches: [main] + paths: + - 'index.js' + - 'lib/**' + - 'package.json' + - 'package-lock.json' + +permissions: + contents: write + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + token: ${{ secrets.GITHUB_TOKEN }} + + - uses: actions/setup-node@v4 + with: + node-version: '20' + cache: 'npm' + + - name: Install dependencies + run: npm ci + + - name: Build dist + run: npm run build + + - name: Check for changes + id: check-changes + run: | + if [ -n "$(git status --porcelain dist)" ]; then + echo "changes=true" >> $GITHUB_OUTPUT + else + echo "changes=false" >> $GITHUB_OUTPUT + fi + + - name: Commit and push if changed + if: steps.check-changes.outputs.changes == 'true' + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git add dist/ + git commit -m "Build dist with Node 20 + + 🤖 Automated build from workflow" + git push diff --git a/.node-version b/.node-version new file mode 100644 index 0000000..f3f52b4 --- /dev/null +++ b/.node-version @@ -0,0 +1 @@ +20.9.0 diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 0000000..f3f52b4 --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +20.9.0 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1488ee8..e4f0a07 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -28,18 +28,17 @@ repos: args: ['--fix'] exclude: ^dist/ - # Disabled local hooks because dist/ formatting can vary between Node versions - # - repo: local - # hooks: - # - id: build-dist - # name: Build dist - # entry: npm run build - # language: system - # pass_filenames: false - # files: ^(index\.js|lib/.*\.js)$ - # - id: check-dist - # name: Check dist is up to date - # entry: bash -c 'if [ -n "$(git status --porcelain dist)" ]; then echo "dist is out of date. Run npm run build and commit the changes."; exit 1; fi' - # language: system - # pass_filenames: false - # always_run: true + - repo: local + hooks: + - id: build-dist + name: Build dist + entry: npm run build + language: system + pass_filenames: false + files: ^(index\.js|lib/.*\.js)$ + - id: check-dist + name: Check dist is up to date + entry: bash -c 'if [ -n "$(git status --porcelain dist)" ]; then echo "dist is out of date. Run npm run build and commit the changes."; exit 1; fi' + language: system + pass_filenames: false + always_run: true diff --git a/CLAUDE.md b/CLAUDE.md index a49c3d0..17d4cfc 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -84,17 +84,17 @@ Each test case has `old/` and `new/` subdirectories with Go code. The action uses `@vercel/ncc` to compile all dependencies into a single `dist/index.js` file. This is required for GitHub Actions and must be committed to the repository. The dist/ folder is intentionally NOT in .gitignore. -**Important**: Build with Node.js v20 to ensure consistent output with CI. +**Important**: The dist must be built with Node.js v20 to match GitHub Actions runtime. -To update dist/ after making changes: +There are two ways to update dist/: -```bash -# Ensure you're using Node v20 -node --version # Should show v20.x.x - -npm run build -git add dist/index.js -``` +1. **Automatic (recommended)**: Push changes to main branch and the build-dist workflow will automatically rebuild with Node 20 +2. **Manual**: If you have Node 20 installed locally: + ```bash + node --version # Must show v20.x.x + npm run build + git add dist/index.js + ``` ### Pre-commit Hooks diff --git a/package.json b/package.json index 1d73a0f..836e8bb 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,9 @@ "lint-staged": "^16.1.2", "prettier": "^3.1.1" }, + "engines": { + "node": ">=20.0.0 <21.0.0" + }, "jest": { "collectCoverage": true, "coverageThreshold": {