Skip to content

Commit

Permalink
fix(nuxt): include plugin templates in plugins.d.ts if they will be…
Browse files Browse the repository at this point in the history
… written (#23943)

Co-authored-by: Daniel Roe <daniel@roe.dev>
  • Loading branch information
2 people authored and manniL committed Dec 11, 2023
1 parent 8c07aa0 commit 57e5400
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions packages/nuxt/src/core/templates.ts
Expand Up @@ -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'
Expand Down

0 comments on commit 57e5400

Please sign in to comment.