fix(vite): greater type-safety within runtime vite-node (#21849)

This commit is contained in:
Daniel Roe 2023-06-28 22:19:51 +01:00 committed by GitHub
parent cc4cf68ed4
commit d4addcf7b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 9 deletions

View File

@ -1,8 +0,0 @@
export interface ViteNodeRuntimeOptions {
baseURL: string,
rootDir: string,
entryPath: string,
base: string
}
export function getViteNodeOptions (): ViteNodeRuntimeOptions

View File

@ -2,6 +2,7 @@
import { Agent as HTTPSAgent } from 'node:https'
import { $fetch } from 'ofetch'
/** @type {import('../vite-node').ViteNodeServerOptions} */
export const viteNodeOptions = JSON.parse(process.env.NUXT_VITE_NODE_OPTIONS || '{}')
export const viteNodeFetch = $fetch.create({

View File

@ -161,6 +161,13 @@ function createViteNodeApp (ctx: ViteBuildContext, invalidates: Set<string> = ne
return app
}
export type ViteNodeServerOptions = {
baseURL: string
root: string
entryPath: string
base: string
}
export async function initViteNodeServer (ctx: ViteBuildContext) {
// Serialize and pass vite-node runtime options
const viteNodeServerOptions = {
@ -168,7 +175,7 @@ export async function initViteNodeServer (ctx: ViteBuildContext) {
root: ctx.nuxt.options.srcDir,
entryPath: ctx.entry,
base: ctx.ssrServer!.config.base || '/_nuxt/'
}
} satisfies ViteNodeServerOptions
process.env.NUXT_VITE_NODE_OPTIONS = JSON.stringify(viteNodeServerOptions)
const serverResolvedPath = resolve(distDir, 'runtime/vite-node.mjs')