feat(nuxt): update nitropack to latest (#6442)

* feat(nuxt): update nitropack

* update renderer to use defineRenderHandler

* update
This commit is contained in:
pooya parsa 2022-08-08 21:12:15 +02:00 committed by GitHub
parent 745d6115d2
commit c954dcb9e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 254 additions and 19 deletions

View File

@ -1,17 +1,20 @@
import { createRenderer } from 'vue-bundle-renderer/runtime' import { createRenderer } from 'vue-bundle-renderer/runtime'
import type { RenderHandler, RenderResponse } from 'nitropack'
import type { Manifest } from 'vite' import type { Manifest } from 'vite'
import { eventHandler, useQuery } from 'h3' import { CompatibilityEvent, getQuery } from 'h3'
import devalue from '@nuxt/devalue' import devalue from '@nuxt/devalue'
import { renderToString as _renderToString } from 'vue/server-renderer' import { renderToString as _renderToString } from 'vue/server-renderer'
import type { NuxtApp } from '#app' import type { NuxtApp } from '#app'
// @ts-ignore // @ts-ignore
import { useRuntimeConfig, useNitroApp } from '#internal/nitro' import { useRuntimeConfig, useNitroApp, defineRenderHandler as _defineRenderHandler } from '#internal/nitro'
// @ts-ignore // @ts-ignore
import { buildAssetsURL } from '#paths' import { buildAssetsURL } from '#paths'
export type NuxtSSRContext = NuxtApp['ssrContext'] export type NuxtSSRContext = NuxtApp['ssrContext']
const defineRenderHandler = _defineRenderHandler as (h: RenderHandler) => CompatibilityEvent
export interface NuxtRenderContext { export interface NuxtRenderContext {
ssrContext: NuxtSSRContext ssrContext: NuxtSSRContext
html: { html: {
@ -98,9 +101,9 @@ const getSPARenderer = lazyCachedFunction(async () => {
return { renderToString } return { renderToString }
}) })
export default eventHandler(async (event) => { export default defineRenderHandler(async (event) => {
// Whether we're rendering an error page // Whether we're rendering an error page
const ssrError = event.req.url?.startsWith('/__nuxt_error') ? useQuery(event) as Exclude<NuxtApp['payload']['error'], Error> : null const ssrError = event.req.url?.startsWith('/__nuxt_error') ? getQuery(event) as Exclude<NuxtApp['payload']['error'], Error> : null
const url = ssrError?.url as string || event.req.url! const url = ssrError?.url as string || event.req.url!
// Initialize ssr context // Initialize ssr context
@ -168,7 +171,7 @@ export default eventHandler(async (event) => {
await nitroApp.hooks.callHook('nuxt:app:rendered', rendered) await nitroApp.hooks.callHook('nuxt:app:rendered', rendered)
// Construct HTML response // Construct HTML response
const response: NuxtRenderResponse = { const response: RenderResponse = {
body: renderHTMLDocument(rendered), body: renderHTMLDocument(rendered),
statusCode: event.res.statusCode, statusCode: event.res.statusCode,
statusMessage: event.res.statusMessage, statusMessage: event.res.statusMessage,
@ -178,20 +181,7 @@ export default eventHandler(async (event) => {
} }
} }
// Allow extending the response return response
await nitroApp.hooks.callHook('nuxt:app:response', { response })
// Send HTML response
if (!event.res.headersSent) {
for (const header in response.headers) {
event.res.setHeader(header, response.headers[header])
}
event.res.statusCode = response.statusCode
event.res.statusMessage = response.statusMessage
}
if (!event.res.writableEnded) {
event.res.end(response.body)
}
}) })
function lazyCachedFunction <T> (fn: () => Promise<T>): () => Promise<T> { function lazyCachedFunction <T> (fn: () => Promise<T>): () => Promise<T> {

245
yarn.lock
View File

@ -490,6 +490,13 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"@esbuild/linux-loong64@npm:0.14.54":
version: 0.14.54
resolution: "@esbuild/linux-loong64@npm:0.14.54"
conditions: os=linux & cpu=loong64
languageName: node
linkType: hard
"@eslint/eslintrc@npm:^1.3.0": "@eslint/eslintrc@npm:^1.3.0":
version: 1.3.0 version: 1.3.0
resolution: "@eslint/eslintrc@npm:1.3.0" resolution: "@eslint/eslintrc@npm:1.3.0"
@ -5670,6 +5677,13 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"esbuild-android-64@npm:0.14.54":
version: 0.14.54
resolution: "esbuild-android-64@npm:0.14.54"
conditions: os=android & cpu=x64
languageName: node
linkType: hard
"esbuild-android-arm64@npm:0.14.50": "esbuild-android-arm64@npm:0.14.50":
version: 0.14.50 version: 0.14.50
resolution: "esbuild-android-arm64@npm:0.14.50" resolution: "esbuild-android-arm64@npm:0.14.50"
@ -5684,6 +5698,13 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"esbuild-android-arm64@npm:0.14.54":
version: 0.14.54
resolution: "esbuild-android-arm64@npm:0.14.54"
conditions: os=android & cpu=arm64
languageName: node
linkType: hard
"esbuild-darwin-64@npm:0.14.50": "esbuild-darwin-64@npm:0.14.50":
version: 0.14.50 version: 0.14.50
resolution: "esbuild-darwin-64@npm:0.14.50" resolution: "esbuild-darwin-64@npm:0.14.50"
@ -5698,6 +5719,13 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"esbuild-darwin-64@npm:0.14.54":
version: 0.14.54
resolution: "esbuild-darwin-64@npm:0.14.54"
conditions: os=darwin & cpu=x64
languageName: node
linkType: hard
"esbuild-darwin-arm64@npm:0.14.50": "esbuild-darwin-arm64@npm:0.14.50":
version: 0.14.50 version: 0.14.50
resolution: "esbuild-darwin-arm64@npm:0.14.50" resolution: "esbuild-darwin-arm64@npm:0.14.50"
@ -5712,6 +5740,13 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"esbuild-darwin-arm64@npm:0.14.54":
version: 0.14.54
resolution: "esbuild-darwin-arm64@npm:0.14.54"
conditions: os=darwin & cpu=arm64
languageName: node
linkType: hard
"esbuild-freebsd-64@npm:0.14.50": "esbuild-freebsd-64@npm:0.14.50":
version: 0.14.50 version: 0.14.50
resolution: "esbuild-freebsd-64@npm:0.14.50" resolution: "esbuild-freebsd-64@npm:0.14.50"
@ -5726,6 +5761,13 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"esbuild-freebsd-64@npm:0.14.54":
version: 0.14.54
resolution: "esbuild-freebsd-64@npm:0.14.54"
conditions: os=freebsd & cpu=x64
languageName: node
linkType: hard
"esbuild-freebsd-arm64@npm:0.14.50": "esbuild-freebsd-arm64@npm:0.14.50":
version: 0.14.50 version: 0.14.50
resolution: "esbuild-freebsd-arm64@npm:0.14.50" resolution: "esbuild-freebsd-arm64@npm:0.14.50"
@ -5740,6 +5782,13 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"esbuild-freebsd-arm64@npm:0.14.54":
version: 0.14.54
resolution: "esbuild-freebsd-arm64@npm:0.14.54"
conditions: os=freebsd & cpu=arm64
languageName: node
linkType: hard
"esbuild-linux-32@npm:0.14.50": "esbuild-linux-32@npm:0.14.50":
version: 0.14.50 version: 0.14.50
resolution: "esbuild-linux-32@npm:0.14.50" resolution: "esbuild-linux-32@npm:0.14.50"
@ -5754,6 +5803,13 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"esbuild-linux-32@npm:0.14.54":
version: 0.14.54
resolution: "esbuild-linux-32@npm:0.14.54"
conditions: os=linux & cpu=ia32
languageName: node
linkType: hard
"esbuild-linux-64@npm:0.14.50": "esbuild-linux-64@npm:0.14.50":
version: 0.14.50 version: 0.14.50
resolution: "esbuild-linux-64@npm:0.14.50" resolution: "esbuild-linux-64@npm:0.14.50"
@ -5768,6 +5824,13 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"esbuild-linux-64@npm:0.14.54":
version: 0.14.54
resolution: "esbuild-linux-64@npm:0.14.54"
conditions: os=linux & cpu=x64
languageName: node
linkType: hard
"esbuild-linux-arm64@npm:0.14.50": "esbuild-linux-arm64@npm:0.14.50":
version: 0.14.50 version: 0.14.50
resolution: "esbuild-linux-arm64@npm:0.14.50" resolution: "esbuild-linux-arm64@npm:0.14.50"
@ -5782,6 +5845,13 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"esbuild-linux-arm64@npm:0.14.54":
version: 0.14.54
resolution: "esbuild-linux-arm64@npm:0.14.54"
conditions: os=linux & cpu=arm64
languageName: node
linkType: hard
"esbuild-linux-arm@npm:0.14.50": "esbuild-linux-arm@npm:0.14.50":
version: 0.14.50 version: 0.14.50
resolution: "esbuild-linux-arm@npm:0.14.50" resolution: "esbuild-linux-arm@npm:0.14.50"
@ -5796,6 +5866,13 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"esbuild-linux-arm@npm:0.14.54":
version: 0.14.54
resolution: "esbuild-linux-arm@npm:0.14.54"
conditions: os=linux & cpu=arm
languageName: node
linkType: hard
"esbuild-linux-mips64le@npm:0.14.50": "esbuild-linux-mips64le@npm:0.14.50":
version: 0.14.50 version: 0.14.50
resolution: "esbuild-linux-mips64le@npm:0.14.50" resolution: "esbuild-linux-mips64le@npm:0.14.50"
@ -5810,6 +5887,13 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"esbuild-linux-mips64le@npm:0.14.54":
version: 0.14.54
resolution: "esbuild-linux-mips64le@npm:0.14.54"
conditions: os=linux & cpu=mips64el
languageName: node
linkType: hard
"esbuild-linux-ppc64le@npm:0.14.50": "esbuild-linux-ppc64le@npm:0.14.50":
version: 0.14.50 version: 0.14.50
resolution: "esbuild-linux-ppc64le@npm:0.14.50" resolution: "esbuild-linux-ppc64le@npm:0.14.50"
@ -5824,6 +5908,13 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"esbuild-linux-ppc64le@npm:0.14.54":
version: 0.14.54
resolution: "esbuild-linux-ppc64le@npm:0.14.54"
conditions: os=linux & cpu=ppc64
languageName: node
linkType: hard
"esbuild-linux-riscv64@npm:0.14.50": "esbuild-linux-riscv64@npm:0.14.50":
version: 0.14.50 version: 0.14.50
resolution: "esbuild-linux-riscv64@npm:0.14.50" resolution: "esbuild-linux-riscv64@npm:0.14.50"
@ -5838,6 +5929,13 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"esbuild-linux-riscv64@npm:0.14.54":
version: 0.14.54
resolution: "esbuild-linux-riscv64@npm:0.14.54"
conditions: os=linux & cpu=riscv64
languageName: node
linkType: hard
"esbuild-linux-s390x@npm:0.14.50": "esbuild-linux-s390x@npm:0.14.50":
version: 0.14.50 version: 0.14.50
resolution: "esbuild-linux-s390x@npm:0.14.50" resolution: "esbuild-linux-s390x@npm:0.14.50"
@ -5852,6 +5950,13 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"esbuild-linux-s390x@npm:0.14.54":
version: 0.14.54
resolution: "esbuild-linux-s390x@npm:0.14.54"
conditions: os=linux & cpu=s390x
languageName: node
linkType: hard
"esbuild-loader@npm:^2.19.0": "esbuild-loader@npm:^2.19.0":
version: 2.19.0 version: 2.19.0
resolution: "esbuild-loader@npm:2.19.0" resolution: "esbuild-loader@npm:2.19.0"
@ -5882,6 +5987,13 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"esbuild-netbsd-64@npm:0.14.54":
version: 0.14.54
resolution: "esbuild-netbsd-64@npm:0.14.54"
conditions: os=netbsd & cpu=x64
languageName: node
linkType: hard
"esbuild-openbsd-64@npm:0.14.50": "esbuild-openbsd-64@npm:0.14.50":
version: 0.14.50 version: 0.14.50
resolution: "esbuild-openbsd-64@npm:0.14.50" resolution: "esbuild-openbsd-64@npm:0.14.50"
@ -5896,6 +6008,13 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"esbuild-openbsd-64@npm:0.14.54":
version: 0.14.54
resolution: "esbuild-openbsd-64@npm:0.14.54"
conditions: os=openbsd & cpu=x64
languageName: node
linkType: hard
"esbuild-sunos-64@npm:0.14.50": "esbuild-sunos-64@npm:0.14.50":
version: 0.14.50 version: 0.14.50
resolution: "esbuild-sunos-64@npm:0.14.50" resolution: "esbuild-sunos-64@npm:0.14.50"
@ -5910,6 +6029,13 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"esbuild-sunos-64@npm:0.14.54":
version: 0.14.54
resolution: "esbuild-sunos-64@npm:0.14.54"
conditions: os=sunos & cpu=x64
languageName: node
linkType: hard
"esbuild-windows-32@npm:0.14.50": "esbuild-windows-32@npm:0.14.50":
version: 0.14.50 version: 0.14.50
resolution: "esbuild-windows-32@npm:0.14.50" resolution: "esbuild-windows-32@npm:0.14.50"
@ -5924,6 +6050,13 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"esbuild-windows-32@npm:0.14.54":
version: 0.14.54
resolution: "esbuild-windows-32@npm:0.14.54"
conditions: os=win32 & cpu=ia32
languageName: node
linkType: hard
"esbuild-windows-64@npm:0.14.50": "esbuild-windows-64@npm:0.14.50":
version: 0.14.50 version: 0.14.50
resolution: "esbuild-windows-64@npm:0.14.50" resolution: "esbuild-windows-64@npm:0.14.50"
@ -5938,6 +6071,13 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"esbuild-windows-64@npm:0.14.54":
version: 0.14.54
resolution: "esbuild-windows-64@npm:0.14.54"
conditions: os=win32 & cpu=x64
languageName: node
linkType: hard
"esbuild-windows-arm64@npm:0.14.50": "esbuild-windows-arm64@npm:0.14.50":
version: 0.14.50 version: 0.14.50
resolution: "esbuild-windows-arm64@npm:0.14.50" resolution: "esbuild-windows-arm64@npm:0.14.50"
@ -5952,6 +6092,13 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"esbuild-windows-arm64@npm:0.14.54":
version: 0.14.54
resolution: "esbuild-windows-arm64@npm:0.14.54"
conditions: os=win32 & cpu=arm64
languageName: node
linkType: hard
"esbuild@npm:^0.14.39, esbuild@npm:^0.14.47, esbuild@npm:^0.14.49": "esbuild@npm:^0.14.39, esbuild@npm:^0.14.47, esbuild@npm:^0.14.49":
version: 0.14.50 version: 0.14.50
resolution: "esbuild@npm:0.14.50" resolution: "esbuild@npm:0.14.50"
@ -6097,6 +6244,80 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"esbuild@npm:^0.14.54":
version: 0.14.54
resolution: "esbuild@npm:0.14.54"
dependencies:
"@esbuild/linux-loong64": 0.14.54
esbuild-android-64: 0.14.54
esbuild-android-arm64: 0.14.54
esbuild-darwin-64: 0.14.54
esbuild-darwin-arm64: 0.14.54
esbuild-freebsd-64: 0.14.54
esbuild-freebsd-arm64: 0.14.54
esbuild-linux-32: 0.14.54
esbuild-linux-64: 0.14.54
esbuild-linux-arm: 0.14.54
esbuild-linux-arm64: 0.14.54
esbuild-linux-mips64le: 0.14.54
esbuild-linux-ppc64le: 0.14.54
esbuild-linux-riscv64: 0.14.54
esbuild-linux-s390x: 0.14.54
esbuild-netbsd-64: 0.14.54
esbuild-openbsd-64: 0.14.54
esbuild-sunos-64: 0.14.54
esbuild-windows-32: 0.14.54
esbuild-windows-64: 0.14.54
esbuild-windows-arm64: 0.14.54
dependenciesMeta:
"@esbuild/linux-loong64":
optional: true
esbuild-android-64:
optional: true
esbuild-android-arm64:
optional: true
esbuild-darwin-64:
optional: true
esbuild-darwin-arm64:
optional: true
esbuild-freebsd-64:
optional: true
esbuild-freebsd-arm64:
optional: true
esbuild-linux-32:
optional: true
esbuild-linux-64:
optional: true
esbuild-linux-arm:
optional: true
esbuild-linux-arm64:
optional: true
esbuild-linux-mips64le:
optional: true
esbuild-linux-ppc64le:
optional: true
esbuild-linux-riscv64:
optional: true
esbuild-linux-s390x:
optional: true
esbuild-netbsd-64:
optional: true
esbuild-openbsd-64:
optional: true
esbuild-sunos-64:
optional: true
esbuild-windows-32:
optional: true
esbuild-windows-64:
optional: true
esbuild-windows-arm64:
optional: true
bin:
esbuild: bin/esbuild
checksum: 49e360b1185c797f5ca3a7f5f0a75121494d97ddf691f65ed1796e6257d318f928342a97f559bb8eced6a90cf604dd22db4a30e0dbbf15edd9dbf22459b639af
languageName: node
linkType: hard
"escalade@npm:^3.1.1": "escalade@npm:^3.1.1":
version: 3.1.1 version: 3.1.1
resolution: "escalade@npm:3.1.1" resolution: "escalade@npm:3.1.1"
@ -7302,6 +7523,15 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"get-port-please@npm:^2.6.1":
version: 2.6.1
resolution: "get-port-please@npm:2.6.1"
dependencies:
fs-memo: ^1.2.0
checksum: 258b33f7e36c1b36994ea616b0965556d941aa78bf649a74f8074b12f2f9fb676c96be4eed55fac6fe2710183eb8c621312d74f00967a1e40a984d052c5e9056
languageName: node
linkType: hard
"get-port@npm:^5.1.1": "get-port@npm:^5.1.1":
version: 5.1.1 version: 5.1.1
resolution: "get-port@npm:5.1.1" resolution: "get-port@npm:5.1.1"
@ -8754,6 +8984,21 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"listhen@npm:^0.2.15":
version: 0.2.15
resolution: "listhen@npm:0.2.15"
dependencies:
clipboardy: ^3.0.0
colorette: ^2.0.19
defu: ^6.0.0
get-port-please: ^2.6.1
http-shutdown: ^1.2.2
selfsigned: ^2.0.1
ufo: ^0.8.5
checksum: 6190a0dec7b150698c26b08b429888e6d86a4f81121cd0bc59fe0180097a9ed4e9839bc8bfbe10d1bc7d8a176958fb9ade161e50977275ac73fa536d7656075a
languageName: node
linkType: hard
"load-json-file@npm:^4.0.0": "load-json-file@npm:^4.0.0":
version: 4.0.0 version: 4.0.0
resolution: "load-json-file@npm:4.0.0" resolution: "load-json-file@npm:4.0.0"