Skip to content

Commit 512ff2c

Browse files
committed
add ecosystem-check manual script
1 parent 3bda22a commit 512ff2c

File tree

2 files changed

+140
-0
lines changed

2 files changed

+140
-0
lines changed

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@
3838
"test": "jest",
3939
"test:watch": "jest --watch",
4040
"test:worker": "jest src/worker.spec.ts",
41+
"check:runtimes": "tsx scripts/ecosystem-check.ts",
42+
"test:node": "node -e \"console.log('CJS:', require('./lib/cjs/index.cjs').WorkOS.name)\" && node -e \"import('./lib/esm/index.js').then(m => console.log('ESM:', m.WorkOS.name))\"",
43+
"test:deno": "deno eval \"import('./lib/esm/index.js').then(m => console.log('Deno:', m.WorkOS.name))\"",
44+
"test:bun": "bun -e \"console.log('Bun:', require('./lib/cjs/index.cjs').WorkOS.name)\"",
4145
"prettier": "prettier \"src/**/*.{js,ts,tsx}\" --check",
4246
"format": "prettier \"src/**/*.{js,ts,tsx}\" --write",
4347
"prepublishOnly": "npm run build"
@@ -68,11 +72,13 @@
6872
"jest": "29.7.0",
6973
"jest-environment-miniflare": "^2.14.2",
7074
"jest-fetch-mock": "^3.0.3",
75+
"miniflare": "^3.20250408.2",
7176
"nock": "^13.5.5",
7277
"prettier": "^3.5.3",
7378
"supertest": "7.1.0",
7479
"ts-jest": "29.3.1",
7580
"tsup": "^8.5.0",
81+
"tsx": "^4.19.0",
7682
"typescript": "5.8.2",
7783
"typescript-eslint": "^8.25.0"
7884
},

scripts/ecosystem-check.ts

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
// scripts/ecosystem-check.ts
2+
import { spawnSync } from 'node:child_process';
3+
import { mkdtempSync, rmSync } 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+
// Worker test using simple import check
55+
const workerTest = {
56+
cmd: 'node',
57+
args: [
58+
'-e',
59+
`
60+
try {
61+
// Test if the worker build exists and can be imported
62+
import("${libEsm}/index.worker.js").then(m => {
63+
if (m.WorkOS) {
64+
console.log('✅ Worker: WorkOS import successful');
65+
} else {
66+
throw new Error('WorkOS not found in worker build');
67+
}
68+
}).catch(err => {
69+
console.log('❌ Worker test failed:', err.message);
70+
process.exit(1);
71+
});
72+
} catch (error) {
73+
console.log('❌ Worker test failed:', error.message);
74+
process.exit(1);
75+
}
76+
`,
77+
],
78+
};
79+
80+
let allOK = true;
81+
let ranTests = 0;
82+
83+
console.log('🚀 Running WorkOS SDK ecosystem compatibility checks...\n');
84+
85+
// Run basic runtime tests
86+
for (const [name, { cmd, args }] of Object.entries(tests)) {
87+
process.stdout.write(`Testing ${name.padEnd(12)}... `);
88+
89+
const { status, stderr } = spawnSync(cmd, args, {
90+
stdio: ['inherit', 'pipe', 'pipe'],
91+
encoding: 'utf8',
92+
});
93+
94+
if (status !== 0) {
95+
allOK = false;
96+
console.error(`❌ Failed`);
97+
if (stderr) {
98+
console.error(` Error: ${stderr.trim()}`);
99+
}
100+
} else {
101+
ranTests++;
102+
console.log(`✅ Passed`);
103+
}
104+
}
105+
106+
// Try worker test if miniflare is available
107+
console.log(`\nTesting worker.........`);
108+
const workerResult = spawnSync(workerTest.cmd, workerTest.args, {
109+
stdio: ['inherit', 'pipe', 'pipe'],
110+
encoding: 'utf8',
111+
});
112+
113+
if (workerResult.status === 0) {
114+
ranTests++;
115+
console.log(`✅ Passed`);
116+
} else {
117+
console.log(`⚠️ Skipped (miniflare test failed)`);
118+
if (workerResult.stderr) {
119+
console.log(` Error: ${workerResult.stderr.trim()}`);
120+
}
121+
// Don't fail overall test for worker issues
122+
}
123+
124+
// Cleanup
125+
rmSync(tmp, { recursive: true, force: true });
126+
127+
console.log(`\n📊 Results: ${ranTests} runtime tests completed`);
128+
129+
if (allOK) {
130+
console.log('🎉 All core runtime compatibility checks passed!');
131+
} else {
132+
console.log('💥 Some runtime tests failed. Check the output above.');
133+
throw new Error('Ecosystem compatibility checks failed');
134+
}

0 commit comments

Comments
 (0)