Skip to content

Commit

Permalink
fix(build): support latest hono
Browse files Browse the repository at this point in the history
  • Loading branch information
yusukebe committed Dec 5, 2024
1 parent 6152be1 commit 9be44cc
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/build/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"homepage": "https://github.com/honojs/vite-plugins",
"devDependencies": {
"glob": "^10.3.10",
"hono": "^4.6.1",
"hono": "^4.6.12",
"publint": "^0.1.12",
"rimraf": "^5.0.1",
"tsup": "^7.2.0",
Expand Down
9 changes: 8 additions & 1 deletion packages/build/src/entry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,14 @@ export const getEntryContent = async (options: GetEntryContentOptions) => {
for (const [, app] of Object.entries(modules)) {
if (app) {
mainApp.route('/', app)
mainApp.notFound(app.notFoundHandler)
mainApp.notFound((c) => {
let executionCtx
try {
executionCtx = c.executionCtx
} catch {}
return app.fetch(c.req.raw, c.env, executionCtx)
})
console.log(app.notFoundHandler)
added = true
}
}
Expand Down
14 changes: 12 additions & 2 deletions packages/build/test/basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ import buildPlugin from '../src/base'
describe('Base Plugin', () => {
const testDir = './test/mocks/app'
const entry = './src/server.ts'
const outputFile = `${testDir}/dist/index.js`

afterAll(() => {
rmSync(`${testDir}/dist`, { recursive: true, force: true })
})

it('Should build the project correctly with the plugin', async () => {
const outputFile = `${testDir}/dist/index.js`

await build({
root: testDir,
plugins: [
Expand All @@ -27,4 +26,15 @@ describe('Base Plugin', () => {
const output = readFileSync(outputFile, 'utf-8')
expect(output).toContain('Hello World')
})

it('Should return correct responses from the output file', async () => {
const module = await import(outputFile)
const app = module['default']

let res = await app.request('/')
expect(res.status).toBe(200)

res = await app.request('/not-found')
expect(res.status).toBe(404)
})
})
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,7 @@ __metadata:
resolution: "@hono/vite-build@workspace:packages/build"
dependencies:
glob: ^10.3.10
hono: ^4.6.1
hono: ^4.6.12
publint: ^0.1.12
rimraf: ^5.0.1
tsup: ^7.2.0
Expand Down Expand Up @@ -3473,10 +3473,10 @@ __metadata:
languageName: node
linkType: hard

"hono@npm:^4.6.1":
version: 4.6.1
resolution: "hono@npm:4.6.1"
checksum: 8b8a996013ad44019a326723fed8435e590d1696d46ae5d1297c5057794766c7d54832446f08f22113e144e7dfa491fddb52146bc4e7ab708089049d004d0a16
"hono@npm:^4.6.12":
version: 4.6.12
resolution: "hono@npm:4.6.12"
checksum: a2690db239d6390efdc4080d2ac35155ad0f1f87c3f39ee56578fa3a8631e5dd173c31cff493588205b81a4fd19997f3ccffea19dd2f0b4040a65cc85b1f07e8
languageName: node
linkType: hard

Expand Down

0 comments on commit 9be44cc

Please sign in to comment.