mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 13:45:18 +00:00
fix(nuxt): add module declarations for virtual files (#27311)
This commit is contained in:
parent
f256210d55
commit
5b1ca73886
@ -129,6 +129,8 @@ async function initNuxt (nuxt: Nuxt) {
|
||||
if (nuxt.options.typescript.shim) {
|
||||
opts.references.push({ path: resolve(nuxt.options.buildDir, 'types/vue-shim.d.ts') })
|
||||
}
|
||||
// Add shims for `#build/*` imports that do not already have matching types
|
||||
opts.references.push({ path: resolve(nuxt.options.buildDir, 'types/build.d.ts') })
|
||||
// Add module augmentations directly to NuxtConfig
|
||||
opts.references.push({ path: resolve(nuxt.options.buildDir, 'types/schema.d.ts') })
|
||||
opts.references.push({ path: resolve(nuxt.options.buildDir, 'types/app.config.d.ts') })
|
||||
|
@ -413,3 +413,29 @@ export const nuxtConfigTemplate: NuxtTemplate = {
|
||||
].join('\n\n')
|
||||
},
|
||||
}
|
||||
|
||||
const TYPE_FILENAME_RE = /\.([cm])?[jt]s$/
|
||||
const DECLARATION_RE = /\.d\.[cm]?ts$/
|
||||
export const buildTypeTemplate: NuxtTemplate = {
|
||||
filename: 'types/build.d.ts',
|
||||
getContents ({ app }) {
|
||||
let declarations = ''
|
||||
|
||||
for (const file of app.templates) {
|
||||
if (file.write || !file.filename || DECLARATION_RE.test(file.filename)) {
|
||||
continue
|
||||
}
|
||||
|
||||
if (TYPE_FILENAME_RE.test(file.filename)) {
|
||||
const typeFilenames = new Set([file.filename.replace(TYPE_FILENAME_RE, '.d.$1ts'), file.filename.replace(TYPE_FILENAME_RE, '.d.ts')])
|
||||
if (app.templates.some(f => f.filename && typeFilenames.has(f.filename))) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
declarations += 'declare module ' + JSON.stringify(join('#build', file.filename)) + ';\n'
|
||||
}
|
||||
|
||||
return declarations
|
||||
},
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user