From 9943c00a68c62852c79d5889d32c6cc2d974b919 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Tue, 26 Mar 2024 16:37:50 +0000 Subject: [PATCH] fix: opt in to `import.meta.*` properties (#2597) --- src/runtime/composables/head.ts | 12 ++++++------ src/runtime/composables/navigation.ts | 2 +- src/runtime/composables/preview.ts | 6 +++--- src/runtime/composables/query.ts | 2 +- src/runtime/composables/utils.ts | 2 +- src/runtime/legacy/composables/navigation.ts | 2 +- src/runtime/legacy/composables/query.ts | 2 +- src/runtime/legacy/plugins/documentDriven.ts | 6 +++--- src/runtime/pages/document-driven.vue | 2 +- src/runtime/plugins/documentDriven.ts | 6 +++--- src/runtime/plugins/ws.ts | 2 +- src/runtime/transformers/component-resolver.ts | 2 +- 12 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/runtime/composables/head.ts b/src/runtime/composables/head.ts index 89eaf3ecd..4e74acf2d 100644 --- a/src/runtime/composables/head.ts +++ b/src/runtime/composables/head.ts @@ -26,7 +26,7 @@ export const useContentHead = ( const title = head.title || data?.title if (title) { head.title = title - if (process.server && !head.meta.some(m => m.property === 'og:title')) { + if (import.meta.server && !head.meta.some(m => m.property === 'og:title')) { head.meta.push({ property: 'og:title', content: title as string @@ -35,14 +35,14 @@ export const useContentHead = ( } const host = config.public.content.host - // if (process.server && !host) { + // if (import.meta.server && !host) { // const req = useRequestEvent().node?.req // if (req && req.headers.host !== 'localhost') { // const protocol = req.headers['x-forwarded-proto'] || req.connection.encrypted ? 'https' : 'http' // host = `${protocol}://${req.headers.host}` // } // } - if (process.server && host) { + if (import.meta.server && host) { const _url = joinURL(host ?? '/', config.app.baseURL, to.fullPath) const url = config.public.content.trailingSlash ? withTrailingSlash(_url) : withoutTrailingSlash(_url) if (!head.meta.some(m => m.property === 'og:url')) { @@ -70,7 +70,7 @@ export const useContentHead = ( content: description }) } - if (process.server && description && !head.meta.some(m => m.property === 'og:description')) { + if (import.meta.server && description && !head.meta.some(m => m.property === 'og:description')) { head.meta.push({ property: 'og:description', content: description @@ -82,7 +82,7 @@ export const useContentHead = ( const image = head?.image || data?.image // Shortcut for head.image to og:image in meta - if (process.server && image && head.meta.filter(m => m.property === 'og:image').length === 0) { + if (import.meta.server && image && head.meta.filter(m => m.property === 'og:image').length === 0) { // Handles `image: '/image/src.jpg'` if (typeof image === 'string') { head.meta.push({ @@ -125,7 +125,7 @@ export const useContentHead = ( } // @ts-ignore - if (process.client) { nextTick(() => useHead(head)) } else { useHead(head) } + if (import.meta.client) { nextTick(() => useHead(head)) } else { useHead(head) } } watch(() => unref(_content), refreshHead, { immediate: true }) diff --git a/src/runtime/composables/navigation.ts b/src/runtime/composables/navigation.ts index 1d8533a35..0ba18dd55 100644 --- a/src/runtime/composables/navigation.ts +++ b/src/runtime/composables/navigation.ts @@ -24,7 +24,7 @@ export const fetchContentNavigation = async (queryBuilder?: QueryBuilder | Query : withContentBase(process.dev ? `/navigation/${hash(params)}` : `/navigation/${hash(params)}.${content.integrity}.json`) // Add `prefetch` to `` in production - if (!process.dev && process.server) { + if (!process.dev && import.meta.server) { addPrerenderPath(apiPath) } diff --git a/src/runtime/composables/preview.ts b/src/runtime/composables/preview.ts index c0c7fab87..7e3ac14b6 100644 --- a/src/runtime/composables/preview.ts +++ b/src/runtime/composables/preview.ts @@ -5,7 +5,7 @@ let showWarning = true export const useContentPreview = () => { const getPreviewToken = () => { return useCookie('previewToken').value || - (process.client && sessionStorage.getItem('previewToken')) || + (import.meta.client && sessionStorage.getItem('previewToken')) || undefined } @@ -14,7 +14,7 @@ export const useContentPreview = () => { useRoute().query.preview = token || '' - if (process.client) { + if (import.meta.client) { if (token) { sessionStorage.setItem('previewToken', token) } else { @@ -42,7 +42,7 @@ export const useContentPreview = () => { return true } - if (process.client && sessionStorage.getItem('previewToken')) { + if (import.meta.client && sessionStorage.getItem('previewToken')) { return true } diff --git a/src/runtime/composables/query.ts b/src/runtime/composables/query.ts index 8d7612fb5..a1943c59d 100644 --- a/src/runtime/composables/query.ts +++ b/src/runtime/composables/query.ts @@ -22,7 +22,7 @@ export const createQueryFetch = () => async (query: ContentQu : withContentBase(process.dev ? '/query' : `/query/${hash(params)}.${content.integrity}.json`) // Prefetch the query - if (!process.dev && process.server) { + if (!process.dev && import.meta.server) { addPrerenderPath(apiPath) } diff --git a/src/runtime/composables/utils.ts b/src/runtime/composables/utils.ts index 3a494315e..aaba28abe 100644 --- a/src/runtime/composables/utils.ts +++ b/src/runtime/composables/utils.ts @@ -40,7 +40,7 @@ export const addPrerenderPath = (path: string) => { export const shouldUseClientDB = () => { const { experimental } = useRuntimeConfig().public.content - if (process.server) { return false } + if (import.meta.server) { return false } if (experimental.clientDB) { return true } return useContentPreview().isEnabled() diff --git a/src/runtime/legacy/composables/navigation.ts b/src/runtime/legacy/composables/navigation.ts index 5a3c46c54..83ab39c49 100644 --- a/src/runtime/legacy/composables/navigation.ts +++ b/src/runtime/legacy/composables/navigation.ts @@ -24,7 +24,7 @@ export const fetchContentNavigation = async (queryBuilder?: QueryBuilder | Query : withContentBase(process.dev ? `/navigation/${hash(params)}` : `/navigation/${hash(params)}.${content.integrity}.json`) // Add `prefetch` to `` in production - if (!process.dev && process.server) { + if (!process.dev && import.meta.server) { addPrerenderPath(apiPath) } diff --git a/src/runtime/legacy/composables/query.ts b/src/runtime/legacy/composables/query.ts index ee6f64bcd..e7abbc629 100644 --- a/src/runtime/legacy/composables/query.ts +++ b/src/runtime/legacy/composables/query.ts @@ -21,7 +21,7 @@ export const createQueryFetch = () => async (query: QueryBuil : withContentBase(process.dev ? '/query' : `/query/${hash(params)}.${content.integrity}.json`) // Prefetch the query - if (!process.dev && process.server) { + if (!process.dev && import.meta.server) { addPrerenderPath(apiPath) } diff --git a/src/runtime/legacy/plugins/documentDriven.ts b/src/runtime/legacy/plugins/documentDriven.ts index 169ef3c0f..ff12c4056 100644 --- a/src/runtime/legacy/plugins/documentDriven.ts +++ b/src/runtime/legacy/plugins/documentDriven.ts @@ -254,7 +254,7 @@ export default defineNuxtPlugin((nuxt) => { } // Prefetch page content - if (process.client) { + if (import.meta.client) { const router = useRouter() nuxt.hook('link:prefetch', (link) => { if (!(link in pages.value) && !hasProtocol(link)) { @@ -275,7 +275,7 @@ export default defineNuxtPlugin((nuxt) => { // Route middleware addRouteMiddleware(async (to, from) => { // Avoid calling on hash change - if (process.client && !isClientDBEnabled && to.path === from.path) { + if (import.meta.client && !isClientDBEnabled && to.path === from.path) { if (!to.meta.layout) { const _path = withoutTrailingSlash(to.path) if (pages.value[_path]) { @@ -297,7 +297,7 @@ export default defineNuxtPlugin((nuxt) => { }) // @ts-ignore - Refresh on client-side - nuxt.hook('app:data:refresh', async () => process.client && await refresh(useRoute(), true)) + nuxt.hook('app:data:refresh', async () => import.meta.client && await refresh(useRoute(), true)) }) function prefetchBodyComponents (nodes: MarkdownNode[]) { diff --git a/src/runtime/pages/document-driven.vue b/src/runtime/pages/document-driven.vue index db5689734..316aa7627 100644 --- a/src/runtime/pages/document-driven.vue +++ b/src/runtime/pages/document-driven.vue @@ -6,7 +6,7 @@ const { contentHead } = useRuntimeConfig().public.content const { page, layout } = useContent() // Page not found, set correct status code on SSR -if (!(page as any).value && process.server) { +if (!(page as any).value && import.meta.server) { const event = useRequestEvent() event.res.statusCode = 404 } diff --git a/src/runtime/plugins/documentDriven.ts b/src/runtime/plugins/documentDriven.ts index b323fc6c5..3efec3756 100644 --- a/src/runtime/plugins/documentDriven.ts +++ b/src/runtime/plugins/documentDriven.ts @@ -235,7 +235,7 @@ export default defineNuxtPlugin((nuxt) => { } // Prefetch page content - if (process.client) { + if (import.meta.client) { const router = useRouter() nuxt.hook('link:prefetch', (link) => { if (!(link in pages.value) && !hasProtocol(link)) { @@ -256,7 +256,7 @@ export default defineNuxtPlugin((nuxt) => { // Route middleware addRouteMiddleware(async (to, from) => { // Avoid calling on hash change - if (process.client && !isClientDBEnabled && to.path === from.path) { + if (import.meta.client && !isClientDBEnabled && to.path === from.path) { if (!to.meta.layout) { const _path = withoutTrailingSlash(to.path) if (pages.value[_path]) { @@ -278,7 +278,7 @@ export default defineNuxtPlugin((nuxt) => { }) // @ts-ignore - Refresh on client-side - nuxt.hook('app:data:refresh', async () => process.client && await refresh(useRoute(), true)) + nuxt.hook('app:data:refresh', async () => import.meta.client && await refresh(useRoute(), true)) }) function prefetchBodyComponents (nodes: MarkdownNode[]) { diff --git a/src/runtime/plugins/ws.ts b/src/runtime/plugins/ws.ts index de9762203..56885967b 100644 --- a/src/runtime/plugins/ws.ts +++ b/src/runtime/plugins/ws.ts @@ -3,7 +3,7 @@ import { defineNuxtPlugin, useRuntimeConfig } from '#imports' export default defineNuxtPlugin(() => { const publicConfig = useRuntimeConfig().public - if (process.client && publicConfig.content.wsUrl) { + if (import.meta.client && publicConfig.content.wsUrl) { // Connect to websocket import('../composables/web-socket').then(({ useContentWebSocket }) => useContentWebSocket()) } diff --git a/src/runtime/transformers/component-resolver.ts b/src/runtime/transformers/component-resolver.ts index 28fe37488..fefbb20fb 100644 --- a/src/runtime/transformers/component-resolver.ts +++ b/src/runtime/transformers/component-resolver.ts @@ -35,7 +35,7 @@ export default defineTransformer({ name: 'component-resolver', extensions: ['.*'], async transform (content, options = {}) { - if (process.server) { + if (import.meta.server) { // This transformer is only needed on client side to resolve components return content }