From 8ed647587b04cb37929f8ebe722f9201ede21c75 Mon Sep 17 00:00:00 2001 From: Bas van den Aakster Date: Sun, 31 Aug 2025 17:58:46 +0200 Subject: [PATCH] Fix ES module imports to eliminate runtime require() calls MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Changed node-cron import from namespace import to default import - Added GitHub workflow for automatic npm publishing on version changes - Ensured all build output uses pure ES module imports without CommonJS remnants This fixes the runtime error: "ReferenceError: require is not defined in ES module scope" 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- .github/workflows/publish.yml | 74 +++++++++++++++++++++++++++++++++++ src/plugin/cron-scheduler.ts | 2 +- 2 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..9196f2d --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,74 @@ +name: Publish to NPM + +on: + push: + branches: [main] + workflow_dispatch: + +jobs: + publish: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '20' + registry-url: 'https://registry.npmjs.org' + + - name: Setup pnpm + uses: pnpm/action-setup@v2 + with: + version: 10 + + - name: Install dependencies + run: pnpm install --frozen-lockfile + + - name: Run tests + run: pnpm test:int + + - name: Build + run: pnpm build + + - name: Check if version changed + id: version-check + run: | + # Get current version from package.json + CURRENT_VERSION=$(node -p "require('./package.json').version") + + # Get previous commit's version + git show HEAD~1:package.json > prev-package.json 2>/dev/null || echo '{"version":"0.0.0"}' > prev-package.json + PREVIOUS_VERSION=$(node -p "require('./prev-package.json').version") + + echo "current=$CURRENT_VERSION" >> $GITHUB_OUTPUT + echo "previous=$PREVIOUS_VERSION" >> $GITHUB_OUTPUT + + if [ "$CURRENT_VERSION" != "$PREVIOUS_VERSION" ]; then + echo "changed=true" >> $GITHUB_OUTPUT + echo "Version changed from $PREVIOUS_VERSION to $CURRENT_VERSION" + else + echo "changed=false" >> $GITHUB_OUTPUT + echo "Version unchanged: $CURRENT_VERSION" + fi + + - name: Publish to NPM + if: steps.version-check.outputs.changed == 'true' + run: npm publish + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + + - name: Create GitHub Release + if: steps.version-check.outputs.changed == 'true' + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: v${{ steps.version-check.outputs.current }} + release_name: Release v${{ steps.version-check.outputs.current }} + draft: false + prerelease: false \ No newline at end of file diff --git a/src/plugin/cron-scheduler.ts b/src/plugin/cron-scheduler.ts index e99e3e1..68c0a00 100644 --- a/src/plugin/cron-scheduler.ts +++ b/src/plugin/cron-scheduler.ts @@ -1,6 +1,6 @@ import type {Config, Payload, TaskConfig} from 'payload' -import * as cron from 'node-cron' +import cron from 'node-cron' import {type Workflow, WorkflowExecutor} from '../core/workflow-executor.js' import {getConfigLogger} from './logger.js'