fix(nuxt): use new mocked-exports (#31295)

This commit is contained in:
Daniel Roe 2025-03-09 10:48:50 +00:00
parent c3352e80b1
commit d09c8ec71f
No known key found for this signature in database
GPG Key ID: CBC814C393D93268
7 changed files with 21 additions and 7 deletions

View File

@ -106,6 +106,7 @@
"knitwork": "^1.2.0",
"magic-string": "^0.30.17",
"mlly": "^1.7.4",
"mocked-exports": "^0.1.0",
"nanotar": "^0.2.0",
"nitropack": "^2.11.5",
"nypm": "^0.6.0",
@ -126,7 +127,6 @@
"ultrahtml": "^1.5.3",
"uncrypto": "^0.1.3",
"unctx": "^2.4.1",
"unenv": "^2.0.0-rc.12",
"unimport": "^4.1.2",
"unplugin": "^2.2.0",
"unplugin-vue-router": "^0.12.0",

View File

@ -14,6 +14,7 @@ import { isWindows } from 'std-env'
import { ImpoundPlugin } from 'impound'
import type { Nuxt, NuxtOptions } from 'nuxt/schema'
import { resolveModulePath } from 'exsolve'
import { version as nuxtVersion } from '../../package.json'
import { distDir } from '../dirs'
import { toArray } from '../utils'
@ -63,7 +64,7 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) {
}
}
const mockProxy = resolveModulePath('unenv/mock/proxy', { from: import.meta.url })
const mockProxy = resolveModulePath('mocked-exports/proxy', { from: import.meta.url })
const nitroConfig: NitroConfig = defu(nuxt.options.nitro, {
debug: nuxt.options.debug ? nuxt.options.debug.nitro : false,

View File

@ -872,6 +872,7 @@ export async function loadNuxt (opts: LoadNuxtOptions): Promise<Nuxt> {
options.modulesDir.push(resolve(options.workspaceDir, 'node_modules'))
options.modulesDir.push(resolve(pkgDir, 'node_modules'))
options.build.transpile.push(
'mocked-exports',
'std-env', // we need to statically replace process.env when used in runtime code
)
options.alias['vue-demi'] = resolve(options.appDir, 'compat/vue-demi')

View File

@ -50,6 +50,7 @@
"magic-string": "^0.30.17",
"mlly": "^1.7.4",
"ohash": "^2.0.11",
"mocked-exports": "^0.1.0",
"pathe": "^2.0.3",
"perfect-debounce": "^1.0.0",
"pkg-types": "^2.1.0",

View File

@ -12,6 +12,7 @@ import { defineEnv } from 'unenv'
import { resolveModulePath } from 'exsolve'
import { defineEventHandler, handleCors, setHeader } from 'h3'
import type { ViteConfig } from '@nuxt/schema'
import type { ViteBuildContext } from './vite'
import { DevStyleSSRPlugin } from './plugins/dev-ssr-css'
import { RuntimePathsPlugin } from './plugins/paths'
@ -120,7 +121,7 @@ export async function buildClient (ctx: ViteBuildContext) {
...ctx.config.resolve?.alias,
'#internal/nitro': join(ctx.nuxt.options.buildDir, 'nitro.client.mjs'),
// work around vite optimizer bug
'#app-manifest': resolveModulePath('unenv/mock/empty', { from: import.meta.url }),
'#app-manifest': resolveModulePath('mocked-exports/empty', { from: import.meta.url }),
},
dedupe: [
'vue',

View File

@ -10,6 +10,7 @@ import { withoutLeadingSlash } from 'ufo'
import { filename } from 'pathe/utils'
import { resolveModulePath } from 'exsolve'
import { resolveTSConfig } from 'pkg-types'
import { resolveModulePath } from 'exsolve'
import { buildClient } from './client'
import { buildServer } from './server'
@ -55,9 +56,10 @@ export const bundle: NuxtBuilder['bundle'] = async (nuxt) => {
const { $client, $server, ...viteConfig } = nuxt.options.vite
const mockEmpty = resolveModulePath('mocked-exports/empty', { from: import.meta.url })
const isIgnored = createIsIgnored(nuxt)
const mockEmpty = resolveModulePath('unenv/mock/empty', { from: import.meta.url })
const ctx: ViteBuildContext = {
nuxt,
entry,

View File

@ -429,6 +429,9 @@ importers:
mlly:
specifier: ^1.7.4
version: 1.7.4
mocked-exports:
specifier: ^0.1.0
version: 0.1.0
nanotar:
specifier: ^0.2.0
version: 0.2.0
@ -489,9 +492,6 @@ importers:
unctx:
specifier: ^2.4.1
version: 2.4.1
unenv:
specifier: ^2.0.0-rc.12
version: 2.0.0-rc.12
unimport:
specifier: 4.1.2
version: 4.1.2
@ -927,6 +927,9 @@ importers:
mlly:
specifier: ^1.7.4
version: 1.7.4
mocked-exports:
specifier: ^0.1.0
version: 0.1.0
ohash:
specifier: ^2.0.11
version: 2.0.11
@ -5754,6 +5757,9 @@ packages:
mlly@1.7.4:
resolution: {integrity: sha512-qmdSIPC4bDJXgZTCR7XosJiNKySV7O215tsPtDN9iEO/7q/76b/ijtgRu/+epFXSJhijtTCCGp3DWS549P3xKw==}
mocked-exports@0.1.0:
resolution: {integrity: sha512-sD6J0bqR2L9OPz0Tmkb2iVFTft8u1VigiAb5vKC9wVk5Fmp70wkpnOYHIww4icXD5mn/kGW7q/kQN3VEOPL8QQ==}
mri@1.2.0:
resolution: {integrity: sha512-tzzskb3bG8LvYGFF/mDTpq3jpI6Q9wc3LEmBaghu+DdCssd1FakN7Bc0hVNmEyGq1bq3RgfkCb3cmQLpNPOroA==}
engines: {node: '>=4'}
@ -13209,6 +13215,8 @@ snapshots:
pkg-types: 1.3.1
ufo: 1.5.4
mocked-exports@0.1.0: {}
mri@1.2.0: {}
mrmime@2.0.0: {}