-
Notifications
You must be signed in to change notification settings - Fork 93
feat: add hono standalone builder #119
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
Closed
+657
−48
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
407c79b
add hono local builder
adriandlam f5528fb
add hono workflow route export and other package stuff
adriandlam 40763d4
rename existing hono nitro app
adriandlam ab8db91
add hono app to workbench
adriandlam 2f82fd1
lockfile
adriandlam e6137c3
add check for local
adriandlam d3b42ef
update workbench hono
adriandlam 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
File renamed without changes.
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,3 @@ | ||
| # workflow/hono | ||
|
|
||
| The docs have moved! Refer to them [here](https://useworkflow.dev/) |
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,39 @@ | ||
| { | ||
| "name": "@workflow/hono", | ||
| "version": "4.0.0-beta.1", | ||
| "description": "Hono integration for Workflow DevKit", | ||
| "type": "module", | ||
| "main": "dist/index.js", | ||
| "files": [ | ||
| "dist" | ||
| ], | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "license": "MIT", | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "https://github.com/vercel/workflow.git", | ||
| "directory": "packages/hono" | ||
| }, | ||
| "exports": { | ||
| ".": "./dist/index.js" | ||
| }, | ||
| "scripts": { | ||
| "build": "tsc", | ||
| "dev": "tsc --watch", | ||
| "clean": "tsc --build --clean && rm -rf dist" | ||
| }, | ||
| "dependencies": { | ||
| "@swc/core": "1.11.24", | ||
| "@workflow/cli": "workspace:*", | ||
| "@workflow/core": "workspace:*", | ||
| "@workflow/swc-plugin": "workspace:*", | ||
| "hono": "^4.9.10", | ||
| "workflow": "4.0.1-beta.4" | ||
| }, | ||
| "devDependencies": { | ||
| "@types/node": "catalog:", | ||
| "@workflow/tsconfig": "workspace:*" | ||
| } | ||
| } |
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,58 @@ | ||
| import { mkdir } from 'node:fs/promises'; | ||
| import { join } from 'node:path'; | ||
| import { BaseBuilder } from '@workflow/cli/dist/lib/builders/base-builder.js'; | ||
| import { VercelBuildOutputAPIBuilder } from '@workflow/cli/dist/lib/builders/vercel-build-output-api.js'; | ||
| import type { WorkflowConfig } from '@workflow/cli/dist/lib/config/types.js'; | ||
|
|
||
| const CommonBuildOptions = { | ||
| dirs: ['workflows'], | ||
| buildTarget: 'next' as const, // unused in base | ||
| stepsBundlePath: '', // unused in base | ||
| workflowsBundlePath: '', // unused in base | ||
| webhookBundlePath: '', // unused in base | ||
| }; | ||
|
|
||
| export class LocalBuilder extends BaseBuilder { | ||
| #outDir: string; | ||
|
|
||
| constructor(config: Partial<WorkflowConfig>) { | ||
| const workingDir = process.cwd(); | ||
| const outDir = join(workingDir, '.workflow'); | ||
| super({ | ||
| ...CommonBuildOptions, | ||
| ...config, | ||
| workingDir, | ||
| clientBundlePath: join(workingDir, '_workflows.js'), | ||
| }); | ||
| this.#outDir = outDir; | ||
| } | ||
|
|
||
| override async build(): Promise<void> { | ||
| const inputFiles = await this.getInputFiles(); | ||
| await mkdir(this.#outDir, { recursive: true }); | ||
|
|
||
| await this.createWorkflowsBundle({ | ||
| outfile: join(this.#outDir, 'workflows.mjs'), | ||
| bundleFinalOutput: false, | ||
| format: 'esm', | ||
| inputFiles, | ||
| }); | ||
|
|
||
| await this.createStepsBundle({ | ||
| outfile: join(this.#outDir, 'steps.mjs'), | ||
| externalizeNonSteps: true, | ||
| format: 'esm', | ||
| inputFiles, | ||
| }); | ||
|
|
||
| await this.createWebhookBundle({ | ||
| outfile: join(this.#outDir, 'webhook.mjs'), | ||
| bundle: false, | ||
| }); | ||
|
|
||
| this.buildClientLibrary(); | ||
| } | ||
| } | ||
|
|
||
| // TODO: Implement Vercel builder | ||
| export class VercelBuilder extends VercelBuildOutputAPIBuilder {} | ||
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,50 @@ | ||
| import { join } from 'node:path'; | ||
| import { pathToFileURL } from 'node:url'; | ||
| import type { WorkflowConfig } from '@workflow/cli/dist/lib/config/types'; | ||
| import { Hono } from 'hono'; | ||
| import { LocalBuilder } from './builder'; | ||
|
|
||
| async function loadBundle(outdir: string, filename: string) { | ||
| const path = join(process.cwd(), outdir, filename); | ||
| const module = await import(pathToFileURL(path).href); | ||
| const handler = module.POST; | ||
| return { handler }; | ||
| } | ||
|
|
||
| export async function createWorkflowRoutes( | ||
| options?: Partial<WorkflowConfig> | ||
| ): Promise<Hono> { | ||
| options ??= {}; | ||
| const app = new Hono(); | ||
| const outDir = '.workflow'; | ||
|
|
||
| const isVercelDeploy = process.env.VERCEL === '1'; | ||
|
|
||
| if (isVercelDeploy) { | ||
| // TODO: Implement Vercel builder | ||
| } else { | ||
| await new LocalBuilder(options).build(); | ||
|
|
||
| // Load bundles | ||
| const stepsModule = await loadBundle(outDir, 'steps.mjs'); | ||
| const workflowsModule = await loadBundle(outDir, 'workflows.mjs'); | ||
| const webhookModule = await loadBundle(outDir, 'webhook.mjs'); | ||
|
|
||
| // Register routes directly on one app | ||
| app.post('/v1/step', async (c) => { | ||
| return await stepsModule.handler(c.req.raw); | ||
| }); | ||
|
|
||
| app.post('/v1/flow', async (c) => { | ||
| return await workflowsModule.handler(c.req.raw); | ||
| }); | ||
|
|
||
| app.all('/v1/webhook/:token', async (c) => { | ||
| const handler = webhookModule.handler; | ||
| if (!handler) return c.text('Method not supported', 405); | ||
| return await handler(c.req.raw); | ||
| }); | ||
| } | ||
|
|
||
| return app; | ||
| } |
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,12 @@ | ||
| { | ||
| "extends": "@workflow/tsconfig/base.json", | ||
| "compilerOptions": { | ||
| "outDir": "dist", | ||
| "target": "es2022", | ||
| "module": "preserve", | ||
| "baseUrl": ".", | ||
| "moduleResolution": "bundler" | ||
| }, | ||
| "include": ["src"], | ||
| "exclude": ["node_modules", "**/*.test.ts"] | ||
| } |
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.
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.
The
buildClientLibrary()call is missing theawaitkeyword, causing the build method to potentially return before the client library is finished building. This creates a race condition.View Details
Analysis
Missing await in LocalBuilder.build() causes race condition with client library generation
What fails:
LocalBuilder.build()completes and returns beforebuildClientLibrary()finishes writing the client library file to disk. Callers awaitingbuild()may immediately try to access the client library before it's been written, causing file not found errors.How to reproduce:
Result: Potential FileNotFoundError when trying to access the client library file immediately after
build()completes.Expected: The
build()method should not resolve until all async operations, including the client library generation, are complete. Per the method signatureasync build(): Promise<void>, callers expect a fully completed build when the promise resolves.Evidence:
buildClientLibrary()is defined asprotected async buildClientLibrary(): Promise<void>in BaseBuilderawait this.buildClientLibrary();await this.buildClientLibrary();LocalBuilder.build()are properly awaited (lines 34, 41, 48)