mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-22 11:22:43 +00:00
chore: use internal apis
This commit is contained in:
parent
46499f7049
commit
88cc6ba9b8
@ -1,8 +1,8 @@
|
|||||||
import type { defineAsyncComponent } from 'vue'
|
import type { defineAsyncComponent } from 'vue'
|
||||||
import { createVNode, defineComponent, onErrorCaptured } from 'vue'
|
import { createVNode, defineComponent, onErrorCaptured } from 'vue'
|
||||||
|
|
||||||
import { injectHead } from '@unhead/vue'
|
|
||||||
import { createError } from '../composables/error'
|
import { createError } from '../composables/error'
|
||||||
|
import { injectHead } from '../composables/head'
|
||||||
|
|
||||||
// @ts-expect-error virtual file
|
// @ts-expect-error virtual file
|
||||||
import { islandComponents } from '#build/components.islands.mjs'
|
import { islandComponents } from '#build/components.islands.mjs'
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import { getCurrentInstance, reactive, toRefs } from 'vue'
|
import { getCurrentInstance, reactive, toRefs } from 'vue'
|
||||||
import type { DefineComponent, defineComponent } from 'vue'
|
import type { DefineComponent, defineComponent } from 'vue'
|
||||||
import { useHead } from '@unhead/vue'
|
|
||||||
import type { NuxtApp } from '../nuxt'
|
import type { NuxtApp } from '../nuxt'
|
||||||
import { useNuxtApp } from '../nuxt'
|
import { useNuxtApp } from '../nuxt'
|
||||||
|
import { useHead } from './head'
|
||||||
import { useAsyncData } from './asyncData'
|
import { useAsyncData } from './asyncData'
|
||||||
import { useRoute } from './router'
|
import { useRoute } from './router'
|
||||||
import { createError } from './error'
|
import { createError } from './error'
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
import type { H3Event } from 'h3'
|
import type { H3Event } from 'h3'
|
||||||
import { setResponseStatus as _setResponseStatus, appendHeader, getRequestHeader, getRequestHeaders, getResponseHeader, removeResponseHeader, setResponseHeader } from 'h3'
|
import { setResponseStatus as _setResponseStatus, appendHeader, getRequestHeader, getRequestHeaders, getResponseHeader, removeResponseHeader, setResponseHeader } from 'h3'
|
||||||
import { computed, getCurrentInstance, ref } from 'vue'
|
import { computed, getCurrentInstance, ref } from 'vue'
|
||||||
import { useServerHead } from '@unhead/vue'
|
|
||||||
import type { H3Event$Fetch } from 'nitro/types'
|
import type { H3Event$Fetch } from 'nitro/types'
|
||||||
|
|
||||||
import type { NuxtApp } from '../nuxt'
|
import type { NuxtApp } from '../nuxt'
|
||||||
import { useNuxtApp } from '../nuxt'
|
import { useNuxtApp } from '../nuxt'
|
||||||
import { toArray } from '../utils'
|
import { toArray } from '../utils'
|
||||||
|
import { useServerHead } from './head'
|
||||||
|
|
||||||
/** @since 3.0.0 */
|
/** @since 3.0.0 */
|
||||||
export function useRequestEvent (nuxtApp: NuxtApp = useNuxtApp()) {
|
export function useRequestEvent (nuxtApp: NuxtApp = useNuxtApp()) {
|
||||||
|
@ -9,7 +9,7 @@ import type { EventHandlerRequest, H3Event } from 'h3'
|
|||||||
import type { AppConfig, AppConfigInput, RuntimeConfig } from 'nuxt/schema'
|
import type { AppConfig, AppConfigInput, RuntimeConfig } from 'nuxt/schema'
|
||||||
import type { RenderResponse } from 'nitro/types'
|
import type { RenderResponse } from 'nitro/types'
|
||||||
import type { LogObject } from 'consola'
|
import type { LogObject } from 'consola'
|
||||||
import type { MergeHead, VueHeadClient } from '@unhead/vue'
|
import type { MergeHead, VueHeadClient } from '@unhead/vue/types'
|
||||||
|
|
||||||
import type { NuxtAppLiterals } from 'nuxt/app'
|
import type { NuxtAppLiterals } from 'nuxt/app'
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { ref } from 'vue'
|
import { ref } from 'vue'
|
||||||
import { useHead } from '@unhead/vue'
|
|
||||||
import { defineNuxtPlugin } from '../nuxt'
|
import { defineNuxtPlugin } from '../nuxt'
|
||||||
|
import { useHead } from '../composables/head'
|
||||||
|
|
||||||
const SUPPORTED_PROTOCOLS = ['http:', 'https:']
|
const SUPPORTED_PROTOCOLS = ['http:', 'https:']
|
||||||
|
|
||||||
|
2
packages/nuxt/src/app/types/augments.d.ts
vendored
2
packages/nuxt/src/app/types/augments.d.ts
vendored
@ -1,4 +1,4 @@
|
|||||||
import type { UseHeadInput } from '@unhead/vue'
|
import type { UseHeadInput } from '@unhead/vue/types'
|
||||||
import type { NuxtApp, useNuxtApp } from '../nuxt.js'
|
import type { NuxtApp, useNuxtApp } from '../nuxt.js'
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import { resolve } from 'pathe'
|
import { dirname, resolve } from 'pathe'
|
||||||
import { addComponent, addImportsSources, addPlugin, addTemplate, defineNuxtModule, tryResolveModule } from '@nuxt/kit'
|
import { addComponent, addPlugin, addTemplate, defineNuxtModule, tryResolveModule } from '@nuxt/kit'
|
||||||
import type { NuxtOptions } from '@nuxt/schema'
|
import type { NuxtOptions } from '@nuxt/schema'
|
||||||
import { unheadVueComposablesImports } from '@unhead/vue'
|
|
||||||
import { distDir } from '../dirs'
|
import { distDir } from '../dirs'
|
||||||
|
|
||||||
const components = ['NoScript', 'Link', 'Base', 'Title', 'Meta', 'Style', 'Head', 'Html', 'Body']
|
const components = ['NoScript', 'Link', 'Base', 'Title', 'Meta', 'Style', 'Head', 'Html', 'Body']
|
||||||
@ -14,10 +13,6 @@ export default defineNuxtModule<NuxtOptions['unhead']>({
|
|||||||
async setup (options, nuxt) {
|
async setup (options, nuxt) {
|
||||||
const runtimeDir = resolve(distDir, 'head/runtime')
|
const runtimeDir = resolve(distDir, 'head/runtime')
|
||||||
const isNuxtV4 = nuxt.options.future?.compatibilityVersion === 4
|
const isNuxtV4 = nuxt.options.future?.compatibilityVersion === 4
|
||||||
|
|
||||||
// Transpile @unhead/vue
|
|
||||||
nuxt.options.build.transpile.push('@unhead/vue')
|
|
||||||
|
|
||||||
// Register components
|
// Register components
|
||||||
const componentsPath = resolve(runtimeDir, 'components')
|
const componentsPath = resolve(runtimeDir, 'components')
|
||||||
for (const componentName of components) {
|
for (const componentName of components) {
|
||||||
@ -39,8 +34,9 @@ export default defineNuxtModule<NuxtOptions['unhead']>({
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
const exportPath = resolve(runtimeDir, 'exports', isNuxtV4 ? 'v4' : 'v3')
|
const realUnheadPath = await tryResolveModule('@unhead/vue', nuxt.options.modulesDir) || '@unhead/vue'
|
||||||
nuxt.options.alias['#unhead/exports'] = exportPath
|
// Transpile @unhead/vue
|
||||||
|
nuxt.options.build.transpile.push(realUnheadPath)
|
||||||
|
|
||||||
// for Nuxt v3 users we will alias `@unhead/vue` to our custom export path so that
|
// for Nuxt v3 users we will alias `@unhead/vue` to our custom export path so that
|
||||||
// import { useHead } from '@unhead/vue'
|
// import { useHead } from '@unhead/vue'
|
||||||
@ -48,10 +44,34 @@ export default defineNuxtModule<NuxtOptions['unhead']>({
|
|||||||
// for Nuxt v4 user should import from #imports
|
// for Nuxt v4 user should import from #imports
|
||||||
if (!isNuxtV4) {
|
if (!isNuxtV4) {
|
||||||
for (const subpath of ['legacy', 'types']) {
|
for (const subpath of ['legacy', 'types']) {
|
||||||
const subpathModule = `@unhead/vue/${subpath}`
|
nuxt.options.alias[`@unhead/vue/${subpath}`] = resolve(dirname(realUnheadPath), subpath)
|
||||||
nuxt.options.alias[subpathModule] = await tryResolveModule(subpathModule, nuxt.options.modulesDir) || subpathModule
|
|
||||||
}
|
}
|
||||||
nuxt.options.alias['@unhead/vue'] = exportPath
|
addTemplate({
|
||||||
|
filename: 'unhead-exports.mjs',
|
||||||
|
getContents () {
|
||||||
|
return `
|
||||||
|
export {
|
||||||
|
injectHead,
|
||||||
|
useHead,
|
||||||
|
useHeadSafe,
|
||||||
|
useSeoMeta,
|
||||||
|
useServerHead,
|
||||||
|
useServerHeadSafe,
|
||||||
|
useServerSeoMeta,
|
||||||
|
} from '#app/composables/head'
|
||||||
|
|
||||||
|
export {
|
||||||
|
createHeadCore,
|
||||||
|
resolveUnrefHeadInput,
|
||||||
|
unheadVueComposablesImports,
|
||||||
|
} from '${JSON.stringify(realUnheadPath)}'
|
||||||
|
|
||||||
|
export * from '@unhead/vue/types'
|
||||||
|
`
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
nuxt.options.alias['@unhead/vue'] = '#build/unhead-exports.mjs'
|
||||||
}
|
}
|
||||||
|
|
||||||
addTemplate({
|
addTemplate({
|
||||||
|
@ -120,6 +120,10 @@ describe('composables', () => {
|
|||||||
'useSeoMeta',
|
'useSeoMeta',
|
||||||
'useServerSeoMeta',
|
'useServerSeoMeta',
|
||||||
'usePreviewMode',
|
'usePreviewMode',
|
||||||
|
'injectHead',
|
||||||
|
'useHeadSafe',
|
||||||
|
'useServerHead',
|
||||||
|
'useServerHeadSafe',
|
||||||
]
|
]
|
||||||
expect(Object.keys(composables).sort()).toEqual([...new Set([...testedComposables, ...skippedComposables])].sort())
|
expect(Object.keys(composables).sort()).toEqual([...new Set([...testedComposables, ...skippedComposables])].sort())
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user