From 957a75a7e102debc36adb5db2451ff77c318231a Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Sat, 20 May 2023 23:14:52 +0100 Subject: [PATCH] fix(nuxt): exclude plugin declaration from non-existent files (#20974) --- packages/nuxt/src/core/templates.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/nuxt/src/core/templates.ts b/packages/nuxt/src/core/templates.ts index b328bb7996..a54f1a7c60 100644 --- a/packages/nuxt/src/core/templates.ts +++ b/packages/nuxt/src/core/templates.ts @@ -1,3 +1,4 @@ +import { existsSync } from 'node:fs' import { genArrayFromRaw, genDynamicImport, genExport, genImport, genObjectFromRawEntries, genSafeVariableName, genString } from 'knitwork' import { isAbsolute, join, relative, resolve } from 'pathe' import { generateTypes, resolveSchema } from 'untyped' @@ -93,7 +94,9 @@ export const pluginsDeclaration: NuxtTemplate = { filename: 'types/plugins.d.ts', getContents: (ctx) => { const EXTENSION_RE = new RegExp(`(?<=\\w)(${ctx.nuxt.options.extensions.map(e => escapeRE(e)).join('|')})$`, 'g') - const tsImports = ctx.app.plugins.map(p => (isAbsolute(p.src) ? relative(join(ctx.nuxt.options.buildDir, 'types'), p.src) : p.src).replace(EXTENSION_RE, '')) + const tsImports = ctx.app.plugins + .filter(p => !isAbsolute(p.src) || existsSync(p.src) || existsSync(p.src.replace(EXTENSION_RE, '.d.ts'))) + .map(p => (isAbsolute(p.src) ? relative(join(ctx.nuxt.options.buildDir, 'types'), p.src) : p.src).replace(EXTENSION_RE, '')) return `// Generated by Nuxt' import type { Plugin } from '#app'