|
| 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