Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/vendor-superjson-esm-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@trigger.dev/core": patch
---

fix: vendor superjson to fix ESM/CJS compatibility

Bundle superjson during build to avoid `ERR_REQUIRE_ESM` errors on Node.js versions that don't support `require(ESM)` by default (< 22.12.0) and AWS Lambda which intentionally disables it.
4 changes: 4 additions & 0 deletions .github/workflows/pr_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ jobs:
with:
package: cli-v3
secrets: inherit

sdk-compat:
uses: ./.github/workflows/sdk-compat.yml
secrets: inherit
182 changes: 182 additions & 0 deletions .github/workflows/sdk-compat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
name: "🔌 SDK Compatibility Tests"

permissions:
contents: read

on:
workflow_call:

jobs:
node-compat:
name: "Node.js ${{ matrix.node }} (${{ matrix.os }})"
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
node: ["18.20", "20.20", "22.12"]
exclude:
# Skip Node 18 on macOS/Windows to reduce CI time
# Linux coverage is sufficient for Node 18 compatibility
- os: macos-latest
node: "18.20"
- os: windows-latest
node: "18.20"

steps:
- name: ⬇️ Checkout repo
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: ⎔ Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 10.23.0

- name: ⎔ Setup node
uses: buildjet/setup-node@v4
with:
node-version: ${{ matrix.node }}
cache: "pnpm"

- name: 📥 Download deps
run: pnpm install --frozen-lockfile

- name: 📀 Generate Prisma Client
run: pnpm run generate

- name: 🔨 Build SDK dependencies
run: pnpm run build --filter @trigger.dev/sdk^...

- name: 🔨 Build SDK
run: pnpm run build --filter @trigger.dev/sdk

- name: 🧪 Run SDK Compatibility Tests
run: pnpm --filter @internal/sdk-compat-tests test

bun-compat:
name: "Bun Runtime"
runs-on: ubuntu-latest
steps:
- name: ⬇️ Checkout repo
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: ⎔ Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 10.23.0

- name: ⎔ Setup node
uses: buildjet/setup-node@v4
with:
node-version: 20.20.0
cache: "pnpm"

- name: 🥟 Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest

- name: 📥 Download deps
run: pnpm install --frozen-lockfile

- name: 📀 Generate Prisma Client
run: pnpm run generate

- name: 🔨 Build SDK dependencies
run: pnpm run build --filter @trigger.dev/sdk^...

- name: 🔨 Build SDK
run: pnpm run build --filter @trigger.dev/sdk

- name: 🧪 Run Bun Compatibility Test
working-directory: internal-packages/sdk-compat-tests/src/fixtures/bun
run: bun run test.ts

deno-compat:
name: "Deno Runtime"
runs-on: ubuntu-latest
steps:
- name: ⬇️ Checkout repo
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: ⎔ Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 10.23.0

- name: ⎔ Setup node
uses: buildjet/setup-node@v4
with:
node-version: 20.20.0
cache: "pnpm"

- name: 🦕 Setup Deno
uses: denoland/setup-deno@v2
with:
deno-version: v2.x

- name: 📥 Download deps
run: pnpm install --frozen-lockfile

- name: 📀 Generate Prisma Client
run: pnpm run generate

- name: 🔨 Build SDK dependencies
run: pnpm run build --filter @trigger.dev/sdk^...

- name: 🔨 Build SDK
run: pnpm run build --filter @trigger.dev/sdk

- name: 🔗 Link node_modules for Deno fixture
working-directory: internal-packages/sdk-compat-tests/src/fixtures/deno
run: ln -s ../../../../../node_modules node_modules

- name: 🧪 Run Deno Compatibility Test
working-directory: internal-packages/sdk-compat-tests/src/fixtures/deno
run: deno run --allow-read --allow-env --allow-sys test.ts

cloudflare-compat:
name: "Cloudflare Workers"
runs-on: ubuntu-latest
steps:
- name: ⬇️ Checkout repo
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: ⎔ Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 10.23.0

- name: ⎔ Setup node
uses: buildjet/setup-node@v4
with:
node-version: 20.20.0
cache: "pnpm"

- name: 📥 Download deps
run: pnpm install --frozen-lockfile

- name: 📀 Generate Prisma Client
run: pnpm run generate

- name: 🔨 Build SDK dependencies
run: pnpm run build --filter @trigger.dev/sdk^...

- name: 🔨 Build SDK
run: pnpm run build --filter @trigger.dev/sdk

- name: 📥 Install Cloudflare fixture deps
working-directory: internal-packages/sdk-compat-tests/src/fixtures/cloudflare-worker
run: pnpm install

- name: 🧪 Run Cloudflare Workers Compatibility Test (dry-run)
working-directory: internal-packages/sdk-compat-tests/src/fixtures/cloudflare-worker
run: pnpm exec wrangler deploy --dry-run --outdir dist
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ out/
dist
packages/**/dist

# vendored bundles (generated during build)
packages/**/src/**/vendor

# Tailwind
apps/**/styles/tailwind.css
packages/**/styles/tailwind.css
Expand Down
20 changes: 20 additions & 0 deletions internal-packages/sdk-compat-tests/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "@internal/sdk-compat-tests",
"private": true,
"version": "0.0.1",
"type": "module",
"scripts": {
"test": "vitest --run",
"test:watch": "vitest",
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@trigger.dev/sdk": "workspace:*"
},
"devDependencies": {
"esbuild": "^0.24.0",
"execa": "^9.3.0",
"typescript": "^5.5.0",
"vitest": "^2.0.5"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "bun-fixture",
"private": true,
"type": "module"
}
62 changes: 62 additions & 0 deletions internal-packages/sdk-compat-tests/src/fixtures/bun/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* Bun Import Test Fixture
*
* Tests that the SDK works correctly with Bun runtime.
* Bun has high Node.js compatibility but uses its own module resolver.
*/

import { task, logger, schedules, runs, configure, queue, retry, wait } from "@trigger.dev/sdk";

// Validate exports exist
const checks: [string, boolean][] = [
["task", typeof task === "function"],
["logger", typeof logger === "object" && typeof logger.info === "function"],
["schedules", typeof schedules === "object"],
["runs", typeof runs === "object"],
["configure", typeof configure === "function"],
["queue", typeof queue === "function"],
["retry", typeof retry === "object"],
["wait", typeof wait === "object"],
];

let failed = false;
for (const [name, passed] of checks) {
if (!passed) {
console.error(`FAIL: ${name} export check failed`);
failed = true;
}
}

// Test task definition with types
interface Payload {
message: string;
}

const myTask = task({
id: "bun-test-task",
run: async (payload: Payload) => {
return { received: payload.message };
},
});

if (myTask.id !== "bun-test-task") {
console.error(`FAIL: task.id mismatch`);
failed = true;
}

// Test queue definition
const myQueue = queue({
name: "bun-test-queue",
concurrencyLimit: 5,
});

if (!myQueue) {
console.error(`FAIL: queue creation failed`);
failed = true;
}

if (failed) {
process.exit(1);
}

console.log("SUCCESS: Bun imports validated");
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "cjs-require-fixture",
"private": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* CJS Require Test Fixture
*
* This file validates that the SDK can be required using CommonJS syntax.
* This is critical for:
* - Node.js < 22.12.0 (where require(ESM) is not enabled by default)
* - AWS Lambda (intentionally disables require(ESM))
* - Legacy Node.js applications
*/

// Test main export
const sdk = require("@trigger.dev/sdk");

// Test /v3 subpath
const sdkV3 = require("@trigger.dev/sdk/v3");

// Validate exports exist
const checks = [
["task", typeof sdk.task === "function"],
["taskV3", typeof sdkV3.task === "function"],
["logger", typeof sdk.logger === "object" && typeof sdk.logger.info === "function"],
["schedules", typeof sdk.schedules === "object"],
["runs", typeof sdk.runs === "object"],
["configure", typeof sdk.configure === "function"],
["queue", typeof sdk.queue === "function"],
["retry", typeof sdk.retry === "object"],
["wait", typeof sdk.wait === "object"],
["metadata", typeof sdk.metadata === "object"],
["tags", typeof sdk.tags === "object"],
];

let failed = false;
for (const [name, passed] of checks) {
if (!passed) {
console.error(`FAIL: ${name} export check failed`);
failed = true;
}
}

// Test task definition works
const myTask = sdk.task({
id: "cjs-test-task",
run: async (payload) => {
return { received: payload };
},
});

if (myTask.id !== "cjs-test-task") {
console.error(`FAIL: task.id mismatch: expected "cjs-test-task", got "${myTask.id}"`);
failed = true;
}

if (failed) {
process.exit(1);
}

console.log("SUCCESS: All CJS requires validated");
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "cloudflare-worker-fixture",
"private": true,
"type": "module",
"scripts": {
"build": "wrangler deploy --dry-run --outdir dist"
},
"devDependencies": {
"wrangler": "^3.0.0"
}
}
Loading
Loading