fix(nuxt): include plugin templates in plugins.d.ts if they will be written (#23943)

Co-authored-by: Daniel Roe <daniel@roe.dev>
This commit is contained in:
Nasser BOUKEHIL 2023-11-09 12:25:37 +01:00 committed by GitHub
parent 5bb6a13eae
commit bb533f8d25
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -101,9 +101,15 @@ 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
.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, ''))
const tsImports: string[] = []
for (const p of ctx.app.plugins) {
const sources = [p.src, p.src.replace(EXTENSION_RE, '.d.ts')]
if (!isAbsolute(p.src)) {
tsImports.push(p.src.replace(EXTENSION_RE, ''))
} else if (ctx.app.templates.some(t => t.write && t.dst && sources.includes(t.dst)) || sources.some(s => existsSync(s))) {
tsImports.push(relative(join(ctx.nuxt.options.buildDir, 'types'), p.src).replace(EXTENSION_RE, ''))
}
}
return `// Generated by Nuxt'
import type { Plugin } from '#app'