mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-26 07:32:01 +00:00
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:
parent
5bb6a13eae
commit
bb533f8d25
@ -101,9 +101,15 @@ export const pluginsDeclaration: NuxtTemplate<TemplateContext> = {
|
|||||||
filename: 'types/plugins.d.ts',
|
filename: 'types/plugins.d.ts',
|
||||||
getContents: (ctx) => {
|
getContents: (ctx) => {
|
||||||
const EXTENSION_RE = new RegExp(`(?<=\\w)(${ctx.nuxt.options.extensions.map(e => escapeRE(e)).join('|')})$`, 'g')
|
const EXTENSION_RE = new RegExp(`(?<=\\w)(${ctx.nuxt.options.extensions.map(e => escapeRE(e)).join('|')})$`, 'g')
|
||||||
const tsImports = ctx.app.plugins
|
const tsImports: string[] = []
|
||||||
.filter(p => !isAbsolute(p.src) || existsSync(p.src) || existsSync(p.src.replace(EXTENSION_RE, '.d.ts')))
|
for (const p of ctx.app.plugins) {
|
||||||
.map(p => (isAbsolute(p.src) ? relative(join(ctx.nuxt.options.buildDir, 'types'), p.src) : p.src).replace(EXTENSION_RE, ''))
|
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'
|
return `// Generated by Nuxt'
|
||||||
import type { Plugin } from '#app'
|
import type { Plugin } from '#app'
|
||||||
|
Loading…
Reference in New Issue
Block a user