-
Notifications
You must be signed in to change notification settings - Fork 86
feat: add bun support #160
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
Conversation
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
| import { transform } from '@swc/core'; | ||
| import { BaseBuilder } from '@workflow/cli/dist/lib/builders/base-builder'; | ||
| import type { WorkflowConfig } from '@workflow/cli/dist/lib/config/types'; | ||
| import type { BunPlugin } from 'bun'; | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| import { transform } from '@swc/core'; | |
| import { BaseBuilder } from '@workflow/cli/dist/lib/builders/base-builder'; | |
| import type { WorkflowConfig } from '@workflow/cli/dist/lib/config/types'; | |
| import type { BunPlugin } from 'bun'; | |
| import { createRequire } from 'module'; | |
| import { transform } from '@swc/core'; | |
| import { BaseBuilder } from '@workflow/cli/dist/lib/builders/base-builder'; | |
| import type { WorkflowConfig } from '@workflow/cli/dist/lib/config/types'; | |
| import type { BunPlugin } from 'bun'; | |
| const require = createRequire(import.meta.filename); | |
The code uses require.resolve() without importing or initializing require, which will cause a runtime error in ES modules.
View Details
Analysis
Missing require initialization in Bun plugin causes runtime error in ES module
What fails: packages/bun/src/index.ts calls require.resolve('@workflow/swc-plugin') on line 26 without initializing require, which causes ReferenceError: require is not defined at runtime when the Bun plugin attempts to transform files with workflow directives.
How to reproduce:
- Import the
@workflow/bunpackage (which has"type": "module"in package.json) - Call the
workflowPlugin()function to register the Bun plugin - Process any TypeScript/JavaScript file containing "use workflow" or "use step" directives
- The plugin's
build.onLoad()handler will execute and throw:ReferenceError: require is not defined
Expected behavior: The plugin should successfully resolve the SWC plugin path and transform the file. Per Node.js ES Module documentation, require must be explicitly created in ES modules using createRequire from the 'module' package.
Root cause: The file uses ES module syntax (import statements) and declares "type": "module" in package.json, but attempts to use the global require function which is only available in CommonJS modules. This contrasts with @workflow/next which uses "type": "commonjs" and can use require directly.
Solution: Import createRequire from 'module' and initialize the require function at the module level, following the pattern established in packages/cli/src/lib/builders/apply-swc-transform.ts.
|
@adriandlam What's required to get bun support for workflows over the line? |
|
hey @versecafe! I'm just working on other integrations right now and will take a look at this again after. You can take a look at #162 if you'd like to get started on where I left off. The main problem is finding a way to tap into Bun's HMR to bundle the workflows/steps/webhook routes. Open to thoughts! |
No description provided.