From 37ec28c46be938eb7bef5feddbc1e3689da0e960 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Wed, 5 Mar 2025 13:18:55 +0000 Subject: [PATCH] chore(deps): upgrade to unenv v2 (#31198) --- packages/nuxt/package.json | 2 +- packages/nuxt/src/core/nitro.ts | 15 +++++++++------ packages/rspack/package.json | 2 +- packages/vite/package.json | 3 ++- packages/vite/src/client.ts | 10 +++++++--- packages/vite/src/vite.ts | 7 +++++-- packages/webpack/package.json | 2 +- packages/webpack/src/configs/client.ts | 7 +++++-- pnpm-lock.yaml | 19 +++++++++++-------- 9 files changed, 42 insertions(+), 25 deletions(-) diff --git a/packages/nuxt/package.json b/packages/nuxt/package.json index e61c4ea8a7..f3746206b9 100644 --- a/packages/nuxt/package.json +++ b/packages/nuxt/package.json @@ -125,7 +125,7 @@ "ultrahtml": "^1.5.3", "uncrypto": "^0.1.3", "unctx": "^2.4.1", - "unenv": "^1.10.0", + "unenv": "^2.0.0-rc.10", "unimport": "^4.1.2", "unplugin": "^2.2.0", "unplugin-vue-router": "^0.12.0", diff --git a/packages/nuxt/src/core/nitro.ts b/packages/nuxt/src/core/nitro.ts index 05e23b8162..5d8b19bad1 100644 --- a/packages/nuxt/src/core/nitro.ts +++ b/packages/nuxt/src/core/nitro.ts @@ -13,6 +13,7 @@ import { dynamicEventHandler } from 'h3' 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' @@ -62,6 +63,8 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) { } } + const mockProxy = resolveModulePath('unenv/mock/proxy', { from: import.meta.url }) + const nitroConfig: NitroConfig = defu(nuxt.options.nitro, { debug: nuxt.options.debug ? nuxt.options.debug.nitro : false, rootDir: nuxt.options.rootDir, @@ -202,11 +205,11 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) { ...nuxt.options.vue.runtimeCompiler || nuxt.options.experimental.externalVue ? {} : { - 'estree-walker': 'unenv/runtime/mock/proxy', - '@babel/parser': 'unenv/runtime/mock/proxy', - '@vue/compiler-core': 'unenv/runtime/mock/proxy', - '@vue/compiler-dom': 'unenv/runtime/mock/proxy', - '@vue/compiler-ssr': 'unenv/runtime/mock/proxy', + 'estree-walker': mockProxy, + '@babel/parser': mockProxy, + '@vue/compiler-core': mockProxy, + '@vue/compiler-dom': mockProxy, + '@vue/compiler-ssr': mockProxy, }, '@vue/devtools-api': 'vue-devtools-stub', @@ -375,7 +378,7 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) { // add stub alias to allow vite to resolve import if (!nuxt.options.experimental.appManifest) { - nuxt.options.alias['#app-manifest'] = 'unenv/runtime/mock/proxy' + nuxt.options.alias['#app-manifest'] = mockProxy } // Add fallback server for `ssr: false` diff --git a/packages/rspack/package.json b/packages/rspack/package.json index 5fecdc52ee..43906d0b88 100644 --- a/packages/rspack/package.json +++ b/packages/rspack/package.json @@ -60,7 +60,7 @@ "std-env": "^3.8.1", "time-fix-plugin": "^2.0.7", "ufo": "^1.5.4", - "unenv": "^1.10.0", + "unenv": "^2.0.0-rc.10", "unplugin": "^2.2.0", "url-loader": "^4.1.1", "vue-bundle-renderer": "^2.1.1", diff --git a/packages/vite/package.json b/packages/vite/package.json index ed3250de79..878e32252a 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -41,6 +41,7 @@ "defu": "^6.1.4", "esbuild": "^0.25.0", "escape-string-regexp": "^5.0.0", + "exsolve": "^1.0.1", "externality": "^1.0.2", "get-port-please": "^3.1.2", "h3": "^1.15.1", @@ -56,7 +57,7 @@ "rollup-plugin-visualizer": "^5.14.0", "std-env": "^3.8.1", "ufo": "^1.5.4", - "unenv": "^1.10.0", + "unenv": "^2.0.0-rc.10", "unplugin": "^2.2.0", "vite": "^6.2.0", "vite-node": "^3.0.7", diff --git a/packages/vite/src/client.ts b/packages/vite/src/client.ts index 707e1a1ecf..0e5818d87e 100644 --- a/packages/vite/src/client.ts +++ b/packages/vite/src/client.ts @@ -8,7 +8,8 @@ import { logger } from '@nuxt/kit' import { getPort } from 'get-port-please' import { joinURL, withoutLeadingSlash } from 'ufo' import { defu } from 'defu' -import { env, nodeless } from 'unenv' +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' @@ -22,7 +23,10 @@ import { createViteLogger } from './utils/logger' export async function buildClient (ctx: ViteBuildContext) { const nodeCompat = ctx.nuxt.options.experimental.clientNodeCompat ? { - alias: env(nodeless).alias, + alias: defineEnv({ + nodeCompat: true, + resolve: true, + }).env.alias, define: { global: 'globalThis', }, @@ -116,7 +120,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': 'unenv/runtime/mock/empty', + '#app-manifest': resolveModulePath('unenv/mock/empty', { from: import.meta.url }), }, dedupe: [ 'vue', diff --git a/packages/vite/src/vite.ts b/packages/vite/src/vite.ts index e231f2e0ba..c913bcdd53 100644 --- a/packages/vite/src/vite.ts +++ b/packages/vite/src/vite.ts @@ -8,6 +8,7 @@ import type { RollupReplaceOptions } from '@rollup/plugin-replace' import { sanitizeFilePath } from 'mlly' import { withoutLeadingSlash } from 'ufo' import { filename } from 'pathe/utils' +import { resolveModulePath } from 'exsolve' import { resolveTSConfig } from 'pkg-types' import { buildClient } from './client' @@ -55,6 +56,8 @@ export const bundle: NuxtBuilder['bundle'] = async (nuxt) => { const { $client, $server, ...viteConfig } = nuxt.options.vite const isIgnored = createIsIgnored(nuxt) + + const mockEmpty = resolveModulePath('unenv/mock/empty', { from: import.meta.url }) const ctx: ViteBuildContext = { nuxt, entry, @@ -65,9 +68,9 @@ export const bundle: NuxtBuilder['bundle'] = async (nuxt) => { alias: { ...nuxt.options.alias, '#app': nuxt.options.appDir, - 'web-streams-polyfill/ponyfill/es2018': 'unenv/runtime/mock/empty', + 'web-streams-polyfill/ponyfill/es2018': mockEmpty, // Cannot destructure property 'AbortController' of .. - 'abort-controller': 'unenv/runtime/mock/empty', + 'abort-controller': mockEmpty, }, }, css: await resolveCSSOptions(nuxt), diff --git a/packages/webpack/package.json b/packages/webpack/package.json index ad0167ea1e..82d9f5d9c3 100644 --- a/packages/webpack/package.json +++ b/packages/webpack/package.json @@ -58,7 +58,7 @@ "std-env": "^3.8.1", "time-fix-plugin": "^2.0.7", "ufo": "^1.5.4", - "unenv": "^1.10.0", + "unenv": "^2.0.0-rc.10", "unplugin": "^2.2.0", "url-loader": "^4.1.1", "vue-bundle-renderer": "^2.1.1", diff --git a/packages/webpack/src/configs/client.ts b/packages/webpack/src/configs/client.ts index da08af89a2..bf90282140 100644 --- a/packages/webpack/src/configs/client.ts +++ b/packages/webpack/src/configs/client.ts @@ -4,7 +4,7 @@ import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer' import { logger } from '@nuxt/kit' import { joinURL } from 'ufo' import ForkTSCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin' -import { env, nodeless } from 'unenv' +import { defineEnv } from 'unenv' import type { WebpackConfigContext } from '../utils/config' import { applyPresets } from '../utils/config' @@ -58,7 +58,10 @@ function clientNodeCompat (ctx: WebpackConfigContext) { ctx.config.resolve ||= {} ctx.config.resolve.fallback = { - ...env(nodeless).alias, + ...defineEnv({ + nodeCompat: true, + resolve: true, + }).env.alias, ...ctx.config.resolve.fallback, } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c72715a7c5..3e0ebd82e4 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -481,8 +481,8 @@ importers: specifier: ^2.4.1 version: 2.4.1 unenv: - specifier: ^1.10.0 - version: 1.10.0 + specifier: ^2.0.0-rc.10 + version: 2.0.0-rc.12 unimport: specifier: 4.1.2 version: 4.1.2 @@ -632,8 +632,8 @@ importers: specifier: 1.5.4 version: 1.5.4 unenv: - specifier: ^1.10.0 - version: 1.10.0 + specifier: ^2.0.0-rc.10 + version: 2.0.0-rc.12 unplugin: specifier: ^2.2.0 version: 2.2.0 @@ -894,6 +894,9 @@ importers: escape-string-regexp: specifier: ^5.0.0 version: 5.0.0 + exsolve: + specifier: ^1.0.1 + version: 1.0.1 externality: specifier: ^1.0.2 version: 1.0.2 @@ -940,8 +943,8 @@ importers: specifier: 1.5.4 version: 1.5.4 unenv: - specifier: ^1.10.0 - version: 1.10.0 + specifier: ^2.0.0-rc.10 + version: 2.0.0-rc.12 unplugin: specifier: ^2.2.0 version: 2.2.0 @@ -1058,8 +1061,8 @@ importers: specifier: 1.5.4 version: 1.5.4 unenv: - specifier: ^1.10.0 - version: 1.10.0 + specifier: ^2.0.0-rc.10 + version: 2.0.0-rc.12 unplugin: specifier: ^2.2.0 version: 2.2.0