fix(nuxt): use relative paths when augmenting types (#22633)

This commit is contained in:
Daniel Roe 2023-08-14 18:07:17 +01:00 committed by GitHub
parent a16edba2f5
commit bb83ab5b3f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,7 +4,7 @@ import { addBuildPlugin, addComponent, addPlugin, addTemplate, addVitePlugin, ad
import { dirname, join, relative, resolve } from 'pathe' import { dirname, join, relative, resolve } from 'pathe'
import { genImport, genObjectFromRawEntries, genString } from 'knitwork' import { genImport, genObjectFromRawEntries, genString } from 'knitwork'
import { joinURL } from 'ufo' import { joinURL } from 'ufo'
import type { NuxtApp, NuxtPage } from 'nuxt/schema' import type { Nuxt, NuxtApp, NuxtPage } from 'nuxt/schema'
import { createRoutesContext } from 'unplugin-vue-router' import { createRoutesContext } from 'unplugin-vue-router'
import { resolveOptions } from 'unplugin-vue-router/options' import { resolveOptions } from 'unplugin-vue-router/options'
import type { EditableTreeNode, Options as TypedRouterOptions } from 'unplugin-vue-router' import type { EditableTreeNode, Options as TypedRouterOptions } from 'unplugin-vue-router'
@ -339,8 +339,8 @@ export default defineNuxtModule({
addTemplate({ addTemplate({
filename: 'types/middleware.d.ts', filename: 'types/middleware.d.ts',
getContents: ({ app }: { app: NuxtApp }) => { getContents: ({ nuxt, app }: { nuxt: Nuxt, app: NuxtApp }) => {
const composablesFile = resolve(runtimeDir, 'composables') const composablesFile = relative(join(nuxt.options.buildDir, 'types'), resolve(runtimeDir, 'composables'))
const namedMiddleware = app.middleware.filter(mw => !mw.global) const namedMiddleware = app.middleware.filter(mw => !mw.global)
return [ return [
'import type { NavigationGuard } from \'vue-router\'', 'import type { NavigationGuard } from \'vue-router\'',
@ -356,8 +356,8 @@ export default defineNuxtModule({
addTemplate({ addTemplate({
filename: 'types/layouts.d.ts', filename: 'types/layouts.d.ts',
getContents: ({ app }: { app: NuxtApp }) => { getContents: ({ nuxt, app }: { nuxt: Nuxt, app: NuxtApp }) => {
const composablesFile = resolve(runtimeDir, 'composables') const composablesFile = relative(join(nuxt.options.buildDir, 'types'), resolve(runtimeDir, 'composables'))
return [ return [
'import { ComputedRef, MaybeRef } from \'vue\'', 'import { ComputedRef, MaybeRef } from \'vue\'',
`export type LayoutKey = ${Object.keys(app.layouts).map(name => genString(name)).join(' | ') || 'string'}`, `export type LayoutKey = ${Object.keys(app.layouts).map(name => genString(name)).join(' | ') || 'string'}`,