From 4823b17836e1b413c54de3725cdfcbf182e7defd Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Mon, 3 Oct 2022 14:32:01 +0100 Subject: [PATCH] fix(nuxt): handle schema types for relative module paths (#7946) --- packages/nuxt/src/core/templates.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/nuxt/src/core/templates.ts b/packages/nuxt/src/core/templates.ts index 3dbf745dee..d8cd4c3264 100644 --- a/packages/nuxt/src/core/templates.ts +++ b/packages/nuxt/src/core/templates.ts @@ -1,7 +1,7 @@ import type { Nuxt, NuxtApp, NuxtTemplate } from '@nuxt/schema' import { genArrayFromRaw, genDynamicImport, genExport, genImport, genObjectFromRawEntries, genString, genSafeVariableName } from 'knitwork' -import { isAbsolute, join, relative } from 'pathe' +import { isAbsolute, join, relative, resolve } from 'pathe' import { resolveSchema, generateTypes } from 'untyped' import escapeRE from 'escape-string-regexp' import { hash } from 'ohash' @@ -120,12 +120,14 @@ export const schemaTemplate: NuxtTemplate = { importName: m.entryPath || m.meta?.name })).filter(m => m.configKey && m.name && !adHocModules.includes(m.name)) + const relativeRoot = relative(resolve(nuxt.options.buildDir, 'types'), nuxt.options.rootDir) + return [ "import { NuxtModule } from '@nuxt/schema'", "declare module '@nuxt/schema' {", ' interface NuxtConfig {', ...moduleInfo.filter(Boolean).map(meta => - ` [${genString(meta.configKey)}]?: typeof ${genDynamicImport(meta.importName, { wrapper: false })}.default extends NuxtModule ? Partial : Record` + ` [${genString(meta.configKey)}]?: typeof ${genDynamicImport(meta.importName.startsWith('.') ? './' + join(relativeRoot, meta.importName) : meta.importName, { wrapper: false })}.default extends NuxtModule ? Partial : Record` ), ' }', generateTypes(await resolveSchema(Object.fromEntries(Object.entries(nuxt.options.runtimeConfig).filter(([key]) => key !== 'public'))),