fix(kit): revert change to tryResolveModule

This commit is contained in:
Daniel Roe 2024-07-03 23:19:54 +01:00
parent 655e1473da
commit 2d136e04c6
No known key found for this signature in database
GPG Key ID: CBC814C393D93268
2 changed files with 8 additions and 7 deletions

View File

@ -1,5 +1,5 @@
import { pathToFileURL } from 'node:url'
import { interopDefault, resolvePathSync } from 'mlly'
import { interopDefault, resolvePath, resolvePathSync } from 'mlly'
export interface ResolveModuleOptions {
paths?: string | string[]
@ -11,9 +11,9 @@ export interface ResolveModuleOptions {
*
* @internal
*/
export function tryResolveModule (id: string, url: string | string[] = import.meta.url) {
export async function tryResolveModule (id: string, url: string | string[] = import.meta.url) {
try {
return resolvePathSync(id, { url })
return await resolvePath(id, { url })
} catch {
// intentionally empty as this is a `try-` function
}

View File

@ -2,7 +2,7 @@ import { resolve } from 'pathe'
import * as vite from 'vite'
import vuePlugin from '@vitejs/plugin-vue'
import viteJsxPlugin from '@vitejs/plugin-vue-jsx'
import { logger, resolvePath, tryResolveModule } from '@nuxt/kit'
import { logger, resolvePath, tryImportModule } from '@nuxt/kit'
import { joinURL, withTrailingSlash, withoutLeadingSlash } from 'ufo'
import type { ViteConfig } from '@nuxt/schema'
import type { ViteBuildContext } from './vite'
@ -107,14 +107,15 @@ export async function buildServer (ctx: ViteBuildContext) {
} satisfies vite.InlineConfig, ctx.nuxt.options.vite.$server || {}))
if (!ctx.nuxt.options.dev) {
const nitroDependencies = await tryResolveModule('nitro/runtime/meta', ctx.nuxt.options.modulesDir)
.then(r => import(r!)).then(r => r.runtimeDependencies || []).catch(() => [])
const { runtimeDependencies = [] } = await tryImportModule<typeof import('nitro/runtime/meta')>('nitro/runtime/meta', {
paths: ctx.nuxt.options.modulesDir,
}) || {}
if (Array.isArray(serverConfig.ssr!.external)) {
serverConfig.ssr!.external.push(
// explicit dependencies we use in our ssr renderer - these can be inlined (if necessary) in the nitro build
'unhead', '@unhead/ssr', 'unctx', 'h3', 'devalue', '@nuxt/devalue', 'radix3', 'unstorage', 'hookable',
// dependencies we might share with nitro - these can be inlined (if necessary) in the nitro build
...nitroDependencies,
...runtimeDependencies,
)
}
}