fix(nuxt): exclude plugin declaration from non-existent files (#20974)

This commit is contained in:
Daniel Roe 2023-05-20 23:14:52 +01:00 committed by GitHub
parent 26861e68ce
commit 957a75a7e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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<TemplateContext> = {
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'