Skip to content

Commit 11f8bf7

Browse files
committed
feat(dev): experimentally support nitro v3 + inline h3
1 parent 70dcc9b commit 11f8bf7

5 files changed

Lines changed: 834 additions & 47 deletions

File tree

‎packages/nuxi/package.json‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,12 @@
4949
"get-port-please": "^3.2.0",
5050
"giget": "^2.0.0",
5151
"h3": "^1.15.4",
52+
"h3-next": "npm:h3@^2.0.1-rc.4",
5253
"jiti": "^2.6.1",
5354
"listhen": "^1.9.0",
5455
"magicast": "^0.3.5",
55-
"nitropack": "npm:nitropack-nightly",
56+
"nitro": "^3.0.1-alpha.0",
57+
"nitropack": "^2.12.7",
5658
"nypm": "^0.6.2",
5759
"ofetch": "^1.4.1",
5860
"ohash": "^2.0.11",

‎packages/nuxi/src/commands/analyze.ts‎

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ import process from 'node:process'
55

66
import{defineCommand}from'citty'
77
import{defu}from'defu'
8-
import{createApp,eventHandler,lazyEventHandler,toNodeListener}from'h3'
8+
import{H3,lazyEventHandler}from'h3-next'
99
import{listen}from'listhen'
1010
import{join,resolve}from'pathe'
11+
import{toNodeHandler}from'srvx/node'
1112

1213
import{overrideEnv}from'../utils/env'
1314
import{clearDir}from'../utils/fs'
@@ -112,43 +113,41 @@ export default defineCommand({
112113
logger.warn('Do not deploy analyze results! Use `nuxi build` before deploying.')
113114

114115
if(ctx.args.serve!==false&&!process.env.CI){
115-
constapp=createApp()
116+
constapp=newH3()
116117

117-
constserveFile=(filePath: string)=>
118-
lazyEventHandler(async()=>{
119-
constcontents=awaitfsp.readFile(filePath,'utf-8')
120-
returneventHandler((event)=>{
121-
event.node.res.end(contents)
122-
})
123-
})
118+
constopts={headers: {'content-type': 'text/html'}}
119+
constserveFile=(filePath: string)=>lazyEventHandler(async()=>{
120+
constcontents=awaitfsp.readFile(filePath,'utf-8')
121+
return()=>newResponse(contents,opts)
122+
})
124123

125124
logger.info('Starting stats server...')
126125

127126
app.use('/client',serveFile(join(analyzeDir,'client.html')))
128127
app.use('/nitro',serveFile(join(analyzeDir,'nitro.html')))
129-
app.use(
130-
eventHandler(
131-
()=>`<!DOCTYPE html>
132-
<html lang="en">
133-
<head>
134-
<meta charset="utf-8">
135-
<title>Nuxt Bundle Stats (experimental)</title>
136-
</head>
137-
<h1>Nuxt Bundle Stats (experimental)</h1>
138-
<ul>
139-
<li>
140-
<a href="/nitro">Nitro server bundle stats</a>
141-
</li>
142-
<li>
143-
<a href="/client">Client bundle stats</a>
144-
</li>
145-
</ul>
146-
</html>
147-
`,
148-
),
128+
app.use(()=>newResponse(
129+
`<!DOCTYPE html>
130+
<html lang="en">
131+
<head>
132+
<meta charset="utf-8">
133+
<title>Nuxt Bundle Stats (experimental)</title>
134+
</head>
135+
<h1>Nuxt Bundle Stats (experimental)</h1>
136+
<ul>
137+
<li>
138+
<a href="/nitro">Nitro server bundle stats</a>
139+
</li>
140+
<li>
141+
<a href="/client">Client bundle stats</a>
142+
</li>
143+
</ul>
144+
</html>
145+
`,
146+
opts,
147+
),
149148
)
150149

151-
awaitlisten(toNodeListener(app))
150+
awaitlisten(toNodeHandler(app.fetch))
152151
}
153152
},
154153
})

‎packages/nuxi/src/dev/utils.ts‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
importtype{Nuxt,NuxtConfig}from'@nuxt/schema'
22
importtype{DotenvOptions}from'c12'
33
importtype{HTTPSOptions,Listener,ListenOptions,ListenURL}from'listhen'
4+
importtype{createDevServer}from'nitro'
45
importtype{NitroDevServer}from'nitropack'
56
importtype{FSWatcher}from'node:fs'
67
importtype{IncomingMessage,RequestListener,ServerResponse}from'node:http'
@@ -17,6 +18,7 @@ import { resolveModulePath } from 'exsolve'
1718
import{toNodeListener}from'h3'
1819
import{resolve}from'pathe'
1920
import{debounce}from'perfect-debounce'
21+
import{toNodeHandler}from'srvx/node'
2022
import{provider}from'std-env'
2123
import{joinURL}from'ufo'
2224

@@ -95,7 +97,7 @@ export class FileChangeTracker {
9597
}
9698
}
9799

98-
typeNuxtWithServer=Omit<Nuxt,'server'>&{server?: NitroDevServer}
100+
typeNuxtWithServer=Omit<Nuxt,'server'>&{server?: NitroDevServer|ReturnType<typeofcreateDevServer>}
99101

100102
interfaceDevServerEventMap{
101103
'loading:error': [error: Error]
@@ -348,7 +350,12 @@ export class NuxtDevServer extends EventEmitter<DevServerEventMap> {
348350
this.loadDebounced(true,'.nuxt/dist directory has been removed')
349351
})
350352

351-
this._handler=toNodeListener(this._currentNuxt.server.app)
353+
if('fetch'inthis._currentNuxt.server){
354+
this._handler=toNodeHandler(this._currentNuxt.server.fetch)
355+
}
356+
else{
357+
this._handler=toNodeListener(this._currentNuxt.server.app)
358+
}
352359
this.emit('ready','socketPath'inaddr ? formatSocketURL(addr.socketPath,!!this.listener.https) : `http://127.0.0.1:${addr.port}`)
353360
}
354361

‎packages/nuxt-cli/package.json‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
"fuse.js": "^7.1.0",
4444
"get-port-please": "^3.2.0",
4545
"giget": "^2.0.0",
46-
"h3": "^1.15.4",
4746
"jiti": "^2.6.1",
4847
"listhen": "^1.9.0",
4948
"nypm": "^0.6.2",
@@ -65,6 +64,10 @@
6564
"@nuxt/kit": "^4.1.3",
6665
"@nuxt/schema": "^4.1.3",
6766
"@types/node": "^22.18.12",
67+
"h3": "^1.15.4",
68+
"h3-next": "npm:h3@^2.0.1-rc.4",
69+
"nitro": "^3.0.1-alpha.0",
70+
"nitropack": "^2.12.7",
6871
"rollup": "^4.52.5",
6972
"rollup-plugin-visualizer": "^6.0.5",
7073
"tsdown": "^0.15.9",

0 commit comments

Comments
 (0)