-
Notifications
You must be signed in to change notification settings - Fork 53
feat: Universal runtime compatibility for Node.js SDK v8 - fixes import resolution across all target runtimes #1301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
fbe76af
fix the ESM/CJS build
nicknisi 3bda22a
build analysis and plan
nicknisi 512ff2c
add ecosystem-check manual script
nicknisi ee84188
plan updates
nicknisi e8c2a51
fix imports
nicknisi 4593d61
add runtime-tests workflow
nicknisi d0c5aa0
formatting
nicknisi b0bcce2
fix smoke tests
nicknisi 0391049
fix lint error
nicknisi 118b499
remove markdown
nicknisi ed57d33
clean up unnecessary ecosystem check duplication
nicknisi 3fcffe4
remove worker spec (which is skipped)
nicknisi 146cb8a
fix worker ecosystem check
nicknisi 6a1823d
build fixes
nicknisi e33afd5
change node version to minimum (18)
nicknisi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| name: Runtime Compatibility Tests | ||
|
|
||
| on: [push, pull_request] | ||
|
|
||
| jobs: | ||
| runtime-compatibility: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: '18' | ||
| - uses: denoland/setup-deno@v2 | ||
| with: | ||
| deno-version: v1.x | ||
| - uses: oven-sh/setup-bun@v2 | ||
|
|
||
| - name: Install and build | ||
| run: | | ||
| npm install | ||
| npm run build | ||
|
|
||
| - name: Runtime compatibility check | ||
| run: npm run check:runtimes |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| // scripts/ecosystem-check.ts | ||
| import { spawnSync } from 'node:child_process'; | ||
| import { mkdtempSync, rmSync, writeFileSync } from 'node:fs'; | ||
| import os from 'node:os'; | ||
| import { dirname, join } from 'node:path'; | ||
| import { fileURLToPath } from 'node:url'; | ||
|
|
||
| const __filename = fileURLToPath(import.meta.url); | ||
| const __dirname = dirname(__filename); | ||
| const root = join(__dirname, '..'); | ||
| const libCjs = join(root, 'lib/cjs'); | ||
| const libEsm = join(root, 'lib/esm'); | ||
| const tmp = mkdtempSync(join(os.tmpdir(), 'workos-test-')); | ||
|
|
||
| // Map of "runtime label" → { cmd, args } | ||
| const tests: Record<string, { cmd: string; args: string[] }> = { | ||
| 'node-cjs': { | ||
| cmd: 'node', | ||
| args: [ | ||
| '-e', | ||
| `console.log('✅ Node CJS:', require("${libCjs}/index.cjs").WorkOS.name)`, | ||
| ], | ||
| }, | ||
| 'node-esm': { | ||
| cmd: 'node', | ||
| args: [ | ||
| '-e', | ||
| `import("${libEsm}/index.js").then(m => console.log('✅ Node ESM:', m.WorkOS.name))`, | ||
| ], | ||
| }, | ||
| deno: { | ||
| cmd: 'deno', | ||
| args: [ | ||
| 'eval', | ||
| `import("${libEsm}/index.js").then(m => console.log('✅ Deno:', m.WorkOS.name))`, | ||
| ], | ||
| }, | ||
| 'bun-cjs': { | ||
| cmd: 'bun', | ||
| args: [ | ||
| '-e', | ||
| `console.log('✅ Bun CJS:', require("${libCjs}/index.cjs").WorkOS.name)`, | ||
| ], | ||
| }, | ||
| 'bun-esm': { | ||
| cmd: 'bun', | ||
| args: [ | ||
| '-e', | ||
| `import("${libEsm}/index.js").then(m => console.log('✅ Bun ESM:', m.WorkOS.name))`, | ||
| ], | ||
| }, | ||
| }; | ||
|
|
||
| let allOK = true; | ||
| let ranTests = 0; | ||
|
|
||
| console.log('🚀 Running WorkOS SDK ecosystem compatibility checks...\n'); | ||
|
|
||
| // Run basic runtime tests | ||
| for (const [name, { cmd, args }] of Object.entries(tests)) { | ||
| process.stdout.write(`Testing ${name.padEnd(12)}... `); | ||
|
|
||
| const { status, stderr } = spawnSync(cmd, args, { | ||
| stdio: ['inherit', 'pipe', 'pipe'], | ||
| encoding: 'utf8', | ||
| }); | ||
|
|
||
| if (status !== 0) { | ||
| allOK = false; | ||
| console.error(`❌ Failed`); | ||
| if (stderr) { | ||
| console.error(` Error: ${stderr.trim()}`); | ||
| } | ||
| } else { | ||
| ranTests++; | ||
| console.log(`✅ Passed`); | ||
| } | ||
| } | ||
|
|
||
| // Test Cloudflare Worker environment using miniflare | ||
| process.stdout.write(`Testing worker ... `); | ||
|
|
||
| // 1. Check if miniflare is available | ||
| const miniflareCheck = spawnSync('npx', ['miniflare', '--version'], { | ||
| stdio: 'ignore', // We don't need to see the version output | ||
| encoding: 'utf8', | ||
| }); | ||
|
|
||
| if (miniflareCheck.status !== 0) { | ||
| console.log(`⚠️ Skipped (miniflare not found or failed to execute)`); | ||
| } else { | ||
| // 2. Create the temporary worker script | ||
| const workerScriptPath = join(tmp, 'worker-test.js'); | ||
| const safeLibEsmPath = libEsm.replace(/\\/g, '\\\\'); // For Windows compatibility | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logic: Windows path handling might still fail if path contains spaces. Use |
||
|
|
||
| const workerScriptContent = ` | ||
| import { WorkOS } from '${safeLibEsmPath}/index.js'; | ||
|
|
||
| if (WorkOS && WorkOS.name === 'WorkOS') { | ||
| console.log('✅ Worker (miniflare): SDK imported successfully.'); | ||
| } else { | ||
| console.error('❌ Worker (miniflare): SDK import failed or WorkOS class is incorrect.'); | ||
| process.exit(1); | ||
| } | ||
| `; | ||
|
|
||
| writeFileSync(workerScriptPath, workerScriptContent); | ||
|
|
||
| // 3. Execute the worker script with miniflare | ||
| const { status, stderr } = spawnSync( | ||
| 'npx', | ||
| ['miniflare', '--modules', workerScriptPath], | ||
| { | ||
| stdio: ['inherit', 'pipe', 'pipe'], | ||
| encoding: 'utf8', | ||
| }, | ||
| ); | ||
|
|
||
| // 4. Process the result | ||
| if (status !== 0) { | ||
| allOK = false; | ||
| console.error(`❌ Failed`); | ||
| if (stderr) { | ||
| console.error(` Error: ${stderr.trim()}`); | ||
| } | ||
| } else { | ||
| ranTests++; | ||
| console.log(`✅ Passed`); | ||
| } | ||
| } | ||
|
|
||
| // Cleanup | ||
| rmSync(tmp, { recursive: true, force: true }); | ||
|
|
||
| console.log(`\n📊 Results: ${ranTests} runtime tests completed`); | ||
|
|
||
| if (allOK) { | ||
| console.log('🎉 All core runtime compatibility checks passed!'); | ||
| } else { | ||
| console.log('💥 Some runtime tests failed. Check the output above.'); | ||
| throw new Error('Ecosystem compatibility checks failed'); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.