diff --git a/.github/workflows/check-dist.yml b/.github/workflows/check-dist.yml new file mode 100644 index 0000000..87efcf1 --- /dev/null +++ b/.github/workflows/check-dist.yml @@ -0,0 +1,39 @@ +name: Check dist + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + check-dist: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - 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: Compare dist + run: | + if [ ! -d dist/ ]; then + echo "Expected dist/ directory does not exist" + exit 1 + fi + if [ "$(git diff --ignore-space-at-eol --text dist/ | wc -l)" -gt "0" ]; then + echo "Detected uncommitted changes after build. See diff below:" + git diff --ignore-space-at-eol --text dist/ + echo "" + echo "Please run 'npm run build' locally and commit the changes" + exit 1 + fi diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d0175d6..1f51da5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -27,18 +27,3 @@ repos: files: \.js$ args: ['--fix'] exclude: ^dist/ - - - repo: local - hooks: - - id: build-dist - name: Build dist - entry: ./scripts/pre-commit-build.sh - language: system - pass_filenames: false - files: ^(index\.js|lib/.*\.js)$ - - id: check-dist - name: Check dist is up to date - entry: ./scripts/pre-commit-check-dist.sh - language: system - pass_filenames: false - always_run: true diff --git a/scripts/pre-commit-build.sh b/scripts/pre-commit-build.sh deleted file mode 100755 index 6f2eff8..0000000 --- a/scripts/pre-commit-build.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/bash -# Pre-commit script to build dist with Node 20 - -# Check if we're already on Node 20 -node_version=$(node --version) -if [[ "$node_version" =~ ^v20\. ]]; then - # Already on Node 20, just build - npm run build - exit 0 -fi - -# Try to use nvm if available -export NVM_DIR="$HOME/.nvm" -if [ -s "$NVM_DIR/nvm.sh" ]; then - . "$NVM_DIR/nvm.sh" - nvm install 20.9.0 >/dev/null 2>&1 - nvm use 20.9.0 >/dev/null 2>&1 - - # Verify we switched to Node 20 - node_version=$(node --version) - if [[ "$node_version" =~ ^v20\. ]]; then - npm run build - exit 0 - fi -fi - -# If we're not on Node 20 and can't switch, error out -echo "Error: Node.js v20 is required (found $node_version)" -echo "Please install Node 20 or use nvm to switch versions" -exit 1 diff --git a/scripts/pre-commit-check-dist.sh b/scripts/pre-commit-check-dist.sh deleted file mode 100755 index f85df3c..0000000 --- a/scripts/pre-commit-check-dist.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash -# Pre-commit script to check if dist is up to date - -# Try to use Node 20 via nvm if available -export NVM_DIR="$HOME/.nvm" -if [ -s "$NVM_DIR/nvm.sh" ]; then - . "$NVM_DIR/nvm.sh" - nvm use 20.9.0 >/dev/null 2>&1 -fi - -# Check if dist has uncommitted changes -if [ -n "$(git status --porcelain dist)" ]; then - echo "dist is out of date. Run npm run build and commit the changes." - exit 1 -fi