refactor(nuxt): remove `process.*` usage in nuxt vue app (#24749)

This commit is contained in:
Daniel Roe 2023-12-14 13:58:25 +00:00 committed by GitHub
parent 37a5d35a6d
commit 6c7d430845
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 9 additions and 11 deletions

View File

@ -1,6 +1,7 @@
/* eslint-disable no-var */
declare global {
var __NUXT_VERSION__: string
var __NUXT_ASYNC_CONTEXT__: boolean
var __NUXT_PREPATHS__: string[] | string | undefined
var __NUXT_PATHS__: string[] | string | undefined

View File

@ -41,7 +41,7 @@ export function createClientOnly<T extends ComponentOptions> (component: T) {
: h(res)
} else {
const fragment = getFragmentHTML(ctx._.vnode.el ?? null) ?? ['<div></div>']
return process.client ? createStaticVNode(fragment.join(''), fragment.length) : h('div', ctx.$attrs ?? ctx._.attrs)
return import.meta.client ? createStaticVNode(fragment.join(''), fragment.length) : h('div', ctx.$attrs ?? ctx._.attrs)
}
}
} else if (clone.template) {
@ -80,7 +80,7 @@ export function createClientOnly<T extends ComponentOptions> (component: T) {
: h(res)
} else {
const fragment = getFragmentHTML(instance?.vnode.el ?? null) ?? ['<div></div>']
return process.client ? createStaticVNode(fragment.join(''), fragment.length) : h('div', ctx.attrs)
return import.meta.client ? createStaticVNode(fragment.join(''), fragment.length) : h('div', ctx.attrs)
}
}
})

View File

@ -36,7 +36,7 @@ export function setResponseStatus (arg1: H3Event | number | undefined, arg2?: nu
}
export function prerenderRoutes (path: string | string[]) {
if (!process.server || !process.env.prerender) { return }
if (!import.meta.server || !import.meta.prerender) { return }
const paths = Array.isArray(path) ? path : [path]
appendHeader(useRequestEvent(), 'x-nitro-prerender', paths.map(p => encodeURIComponent(p)).join(', '))

View File

@ -19,7 +19,7 @@ import type { AsyncDataRequestStatus } from '../app/composables/asyncData'
import type { NuxtAppManifestMeta } from '../app/composables/manifest'
const nuxtAppCtx = /*@__PURE__*/ getContext<NuxtApp>('nuxt-app', {
asyncContext: !!process.env.NUXT_ASYNC_CONTEXT && process.server
asyncContext: !!__NUXT_ASYNC_CONTEXT__ && import.meta.server
})
type HookResult = Promise<void> | void

View File

@ -11,7 +11,7 @@ export default defineNuxtPlugin({
name: 'nuxt:payload',
setup (nuxtApp) {
// TODO: Support dev
if (process.dev) { return }
if (import.meta.dev) { return }
// Load payload after middleware & once final route is resolved
useRouter().beforeResolve(async (to, from) => {

View File

@ -62,7 +62,7 @@ export default defineNuxtModule({
return 'export default []'
}
return `import { CapoPlugin } from ${JSON.stringify(unheadVue)};
export default process.server ? [CapoPlugin({ track: true })] : [];`
export default import.meta.server ? [CapoPlugin({ track: true })] : [];`
}
})

View File

@ -77,7 +77,7 @@ export const bundle: NuxtBuilder['bundle'] = async (nuxt) => {
css: resolveCSSOptions(nuxt),
define: {
__NUXT_VERSION__: JSON.stringify(nuxt._version),
'process.env.NUXT_ASYNC_CONTEXT': nuxt.options.experimental.asyncContext
__NUXT_ASYNC_CONTEXT__: nuxt.options.experimental.asyncContext
},
build: {
copyPublicDir: false,

View File

@ -217,8 +217,8 @@ function getEnv (ctx: WebpackConfigContext) {
const _env: Record<string, string | boolean> = {
'process.env.NODE_ENV': JSON.stringify(ctx.config.mode),
__NUXT_VERSION__: JSON.stringify(ctx.nuxt._version),
__NUXT_ASYNC_CONTEXT__: ctx.options.experimental.asyncContext,
'process.env.VUE_ENV': JSON.stringify(ctx.name),
'process.env.NUXT_ASYNC_CONTEXT': ctx.options.experimental.asyncContext,
'process.dev': ctx.options.dev,
'process.test': isTest,
'process.browser': ctx.isClient,

View File

@ -11,9 +11,6 @@ export default defineConfig({
'#app': resolve('./packages/nuxt/dist/app')
}
},
define: {
'process.env.NUXT_ASYNC_CONTEXT': 'false'
},
test: {
globalSetup: './test/setup.ts',
setupFiles: ['./test/setup-env.ts'],