Skip to content

Commit 48c50ba

Browse files
authored
Merge branch 'version-8' into feature/ent-3465-node-sdk-workoswebhooksconstructevent-type-should-only
2 parents 87f8afe + 522b0b8 commit 48c50ba

File tree

5 files changed

+273
-58
lines changed

5 files changed

+273
-58
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Runtime Compatibility Tests
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
runtime-compatibility:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v4
10+
- uses: actions/setup-node@v4
11+
with:
12+
node-version: '18'
13+
- uses: denoland/setup-deno@v2
14+
with:
15+
deno-version: v1.x
16+
- uses: oven-sh/setup-bun@v2
17+
18+
- name: Install and build
19+
run: |
20+
npm install
21+
npm run build
22+
23+
- name: Runtime compatibility check
24+
run: npm run check:runtimes

package.json

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
"node": ">=18"
1717
},
1818
"type": "module",
19-
"main": "./lib/index.cjs",
20-
"module": "./lib/index.js",
21-
"types": "./lib/index.d.ts",
19+
"main": "./lib/cjs/index.cjs",
20+
"module": "./lib/esm/index.js",
21+
"types": "./lib/esm/index.d.ts",
2222
"files": [
2323
"lib/",
2424
"package.json"
@@ -37,7 +37,7 @@
3737
"lint": "eslint",
3838
"test": "jest",
3939
"test:watch": "jest --watch",
40-
"test:worker": "jest src/worker.spec.ts",
40+
"check:runtimes": "tsx scripts/ecosystem-check.ts",
4141
"prettier": "prettier \"src/**/*.{js,ts,tsx}\" --check",
4242
"format": "prettier \"src/**/*.{js,ts,tsx}\" --write",
4343
"prepublishOnly": "npm run build"
@@ -54,45 +54,65 @@
5454
"@babel/preset-typescript": "^7.27.0",
5555
"@eslint/js": "^9.21.0",
5656
"@types/cookie": "^0.6.0",
57+
"@types/glob": "^8.1.0",
5758
"@types/jest": "^29.5.14",
5859
"@types/node": "~18",
5960
"@types/pluralize": "0.0.33",
6061
"@typescript-eslint/parser": "^8.25.0",
6162
"babel-jest": "^29.7.0",
63+
"esbuild-fix-imports-plugin": "^1.0.21",
6264
"eslint": "^9.21.0",
6365
"eslint-plugin-jest": "^28.11.0",
6466
"eslint-plugin-n": "^17.15.1",
67+
"glob": "^11.0.3",
6568
"jest": "29.7.0",
6669
"jest-environment-miniflare": "^2.14.2",
6770
"jest-fetch-mock": "^3.0.3",
71+
"miniflare": "^3.20250408.2",
6872
"nock": "^13.5.5",
6973
"prettier": "^3.5.3",
7074
"supertest": "7.1.0",
7175
"ts-jest": "29.3.1",
7276
"tsup": "^8.5.0",
77+
"tsx": "^4.19.0",
7378
"typescript": "5.8.2",
7479
"typescript-eslint": "^8.25.0"
7580
},
7681
"exports": {
7782
".": {
78-
"types": "./lib/index.d.ts",
83+
"types": {
84+
"require": "./lib/cjs/index.d.cts",
85+
"import": "./lib/esm/index.d.ts"
86+
},
7987
"workerd": {
80-
"import": "./lib/index.worker.js",
81-
"require": "./lib/index.worker.cjs"
88+
"import": "./lib/esm/index.worker.js",
89+
"require": "./lib/cjs/index.worker.cjs"
8290
},
8391
"edge-light": {
84-
"import": "./lib/index.worker.js",
85-
"require": "./lib/index.worker.cjs"
92+
"import": "./lib/esm/index.worker.js",
93+
"require": "./lib/cjs/index.worker.cjs"
94+
},
95+
"deno": "./lib/esm/index.js",
96+
"bun": {
97+
"import": "./lib/esm/index.js",
98+
"require": "./lib/cjs/index.cjs"
8699
},
87-
"import": "./lib/index.js",
88-
"require": "./lib/index.cjs",
89-
"default": "./lib/index.js"
100+
"node": {
101+
"import": "./lib/esm/index.js",
102+
"require": "./lib/cjs/index.cjs"
103+
},
104+
"import": "./lib/esm/index.js",
105+
"require": "./lib/cjs/index.cjs",
106+
"default": "./lib/esm/index.js"
90107
},
91108
"./worker": {
92-
"types": "./lib/index.worker.d.ts",
93-
"import": "./lib/index.worker.js",
94-
"require": "./lib/index.worker.cjs",
95-
"default": "./lib/index.worker.js"
109+
"types": {
110+
"require": "./lib/cjs/index.worker.d.cts",
111+
"import": "./lib/esm/index.worker.d.ts"
112+
},
113+
"import": "./lib/esm/index.worker.js",
114+
"require": "./lib/cjs/index.worker.cjs",
115+
"default": "./lib/esm/index.worker.js"
96116
},
97117
"./package.json": "./package.json"
98118
}

scripts/ecosystem-check.ts

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
// scripts/ecosystem-check.ts
2+
import { spawnSync } from 'node:child_process';
3+
import { mkdtempSync, rmSync, writeFileSync } from 'node:fs';
4+
import os from 'node:os';
5+
import { dirname, join } from 'node:path';
6+
import { fileURLToPath } from 'node:url';
7+
8+
const __filename = fileURLToPath(import.meta.url);
9+
const __dirname = dirname(__filename);
10+
const root = join(__dirname, '..');
11+
const libCjs = join(root, 'lib/cjs');
12+
const libEsm = join(root, 'lib/esm');
13+
const tmp = mkdtempSync(join(os.tmpdir(), 'workos-test-'));
14+
15+
// Map of "runtime label" → { cmd, args }
16+
const tests: Record<string, { cmd: string; args: string[] }> = {
17+
'node-cjs': {
18+
cmd: 'node',
19+
args: [
20+
'-e',
21+
`console.log('✅ Node CJS:', require("${libCjs}/index.cjs").WorkOS.name)`,
22+
],
23+
},
24+
'node-esm': {
25+
cmd: 'node',
26+
args: [
27+
'-e',
28+
`import("${libEsm}/index.js").then(m => console.log('✅ Node ESM:', m.WorkOS.name))`,
29+
],
30+
},
31+
deno: {
32+
cmd: 'deno',
33+
args: [
34+
'eval',
35+
`import("${libEsm}/index.js").then(m => console.log('✅ Deno:', m.WorkOS.name))`,
36+
],
37+
},
38+
'bun-cjs': {
39+
cmd: 'bun',
40+
args: [
41+
'-e',
42+
`console.log('✅ Bun CJS:', require("${libCjs}/index.cjs").WorkOS.name)`,
43+
],
44+
},
45+
'bun-esm': {
46+
cmd: 'bun',
47+
args: [
48+
'-e',
49+
`import("${libEsm}/index.js").then(m => console.log('✅ Bun ESM:', m.WorkOS.name))`,
50+
],
51+
},
52+
};
53+
54+
let allOK = true;
55+
let ranTests = 0;
56+
57+
console.log('🚀 Running WorkOS SDK ecosystem compatibility checks...\n');
58+
59+
// Run basic runtime tests
60+
for (const [name, { cmd, args }] of Object.entries(tests)) {
61+
process.stdout.write(`Testing ${name.padEnd(12)}... `);
62+
63+
const { status, stderr } = spawnSync(cmd, args, {
64+
stdio: ['inherit', 'pipe', 'pipe'],
65+
encoding: 'utf8',
66+
});
67+
68+
if (status !== 0) {
69+
allOK = false;
70+
console.error(`❌ Failed`);
71+
if (stderr) {
72+
console.error(` Error: ${stderr.trim()}`);
73+
}
74+
} else {
75+
ranTests++;
76+
console.log(`✅ Passed`);
77+
}
78+
}
79+
80+
// Test Cloudflare Worker environment using miniflare
81+
process.stdout.write(`Testing worker ... `);
82+
83+
// 1. Check if miniflare is available
84+
const miniflareCheck = spawnSync('npx', ['miniflare', '--version'], {
85+
stdio: 'ignore', // We don't need to see the version output
86+
encoding: 'utf8',
87+
});
88+
89+
if (miniflareCheck.status !== 0) {
90+
console.log(`⚠️ Skipped (miniflare not found or failed to execute)`);
91+
} else {
92+
// 2. Create the temporary worker script
93+
const workerScriptPath = join(tmp, 'worker-test.js');
94+
const safeLibEsmPath = libEsm.replace(/\\/g, '\\\\'); // For Windows compatibility
95+
96+
const workerScriptContent = `
97+
import { WorkOS } from '${safeLibEsmPath}/index.js';
98+
99+
if (WorkOS && WorkOS.name === 'WorkOS') {
100+
console.log('✅ Worker (miniflare): SDK imported successfully.');
101+
} else {
102+
console.error('❌ Worker (miniflare): SDK import failed or WorkOS class is incorrect.');
103+
process.exit(1);
104+
}
105+
`;
106+
107+
writeFileSync(workerScriptPath, workerScriptContent);
108+
109+
// 3. Execute the worker script with miniflare
110+
const { status, stderr } = spawnSync(
111+
'npx',
112+
['miniflare', '--modules', workerScriptPath],
113+
{
114+
stdio: ['inherit', 'pipe', 'pipe'],
115+
encoding: 'utf8',
116+
},
117+
);
118+
119+
// 4. Process the result
120+
if (status !== 0) {
121+
allOK = false;
122+
console.error(`❌ Failed`);
123+
if (stderr) {
124+
console.error(` Error: ${stderr.trim()}`);
125+
}
126+
} else {
127+
ranTests++;
128+
console.log(`✅ Passed`);
129+
}
130+
}
131+
132+
// Cleanup
133+
rmSync(tmp, { recursive: true, force: true });
134+
135+
console.log(`\n📊 Results: ${ranTests} runtime tests completed`);
136+
137+
if (allOK) {
138+
console.log('🎉 All core runtime compatibility checks passed!');
139+
} else {
140+
console.log('💥 Some runtime tests failed. Check the output above.');
141+
throw new Error('Ecosystem compatibility checks failed');
142+
}

src/worker.spec.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

tsup.config.ts

Lines changed: 71 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,75 @@
11
import { defineConfig } from 'tsup';
2+
import { fixImportsPlugin } from 'esbuild-fix-imports-plugin';
23

3-
export default defineConfig({
4-
entry: [
5-
'src/**/*.ts',
6-
'!src/**/*.spec.ts',
7-
'!src/**/*.test.ts',
8-
'!src/**/fixtures/**',
9-
'!src/**/*.d.ts',
10-
'!src/**/test-utils.ts',
11-
],
12-
format: ['cjs', 'esm'],
13-
dts: {
14-
resolve: true,
15-
compilerOptions: {
16-
lib: ['dom', 'es2022'],
17-
types: ['node'],
4+
export default defineConfig([
5+
// ESM build
6+
{
7+
entry: [
8+
'src/**/*.ts',
9+
'!src/**/*.spec.ts',
10+
'!src/**/*.test.ts',
11+
'!src/**/fixtures/**',
12+
'!src/**/*.d.ts',
13+
'!src/**/test-utils.ts',
14+
],
15+
format: 'esm',
16+
outDir: 'lib/esm',
17+
splitting: false,
18+
target: 'es2022',
19+
sourcemap: true,
20+
clean: true,
21+
dts: {
22+
resolve: true,
23+
compilerOptions: {
24+
lib: ['dom', 'es2022'],
25+
types: ['node'],
26+
},
1827
},
28+
bundle: false,
29+
external: ['iron-session', 'jose', 'leb', 'pluralize'],
30+
outExtension() {
31+
return { js: '.js' };
32+
},
33+
esbuildOptions(options) {
34+
options.keepNames = true;
35+
},
36+
esbuildPlugins: [
37+
fixImportsPlugin()
38+
]
1939
},
20-
bundle: false,
21-
sourcemap: true,
22-
clean: true,
23-
target: 'es2022',
24-
platform: 'node',
25-
outDir: 'lib',
26-
splitting: false,
27-
external: ['iron-session', 'jose', 'leb', 'pluralize'],
28-
outExtension({ format }) {
29-
return {
30-
js: format === 'cjs' ? '.cjs' : '.js',
31-
};
32-
},
33-
esbuildOptions(options, { format }) {
34-
options.keepNames = true;
35-
},
36-
});
37-
40+
// CJS build
41+
{
42+
entry: [
43+
'src/**/*.ts',
44+
'!src/**/*.spec.ts',
45+
'!src/**/*.test.ts',
46+
'!src/**/fixtures/**',
47+
'!src/**/*.d.ts',
48+
'!src/**/test-utils.ts',
49+
],
50+
format: 'cjs',
51+
outDir: 'lib/cjs',
52+
splitting: false,
53+
target: 'es2022',
54+
sourcemap: true,
55+
clean: false, // Don't clean, keep ESM files
56+
dts: {
57+
resolve: true,
58+
compilerOptions: {
59+
lib: ['dom', 'es2022'],
60+
types: ['node'],
61+
},
62+
},
63+
bundle: false,
64+
external: ['iron-session', 'jose', 'leb', 'pluralize'],
65+
outExtension() {
66+
return { js: '.cjs', dts: '.d.cts' };
67+
},
68+
esbuildOptions(options) {
69+
options.keepNames = true;
70+
},
71+
esbuildPlugins: [
72+
fixImportsPlugin()
73+
]
74+
}
75+
]);

0 commit comments

Comments
 (0)