fix(nuxt): avoid stripping js extensions in plugin injections (#28593)

This commit is contained in:
Daniel Roe 2024-08-19 10:38:03 +01:00 committed by GitHub
parent 4f9a3104bb
commit b6d33506ab
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 9 additions and 2 deletions

View File

@ -96,6 +96,8 @@ export const serverPluginTemplate: NuxtTemplate = {
}, },
} }
const TS_RE = /\.[cm]?tsx?$/
export const pluginsDeclaration: NuxtTemplate = { export const pluginsDeclaration: NuxtTemplate = {
filename: 'types/plugins.d.ts', filename: 'types/plugins.d.ts',
getContents: async ({ nuxt, app }) => { getContents: async ({ nuxt, app }) => {
@ -124,9 +126,14 @@ export const pluginsDeclaration: NuxtTemplate = {
} }
if (exists(pluginPath)) { if (exists(pluginPath)) {
tsImports.push(relativePath.replace(EXTENSION_RE, '')) if (TS_RE.test(pluginPath)) {
continue tsImports.push(relativePath.replace(EXTENSION_RE, ''))
continue
}
tsImports.push(relativePath)
} }
// No declaration found that TypeScript can use
} }
return `// Generated by Nuxt' return `// Generated by Nuxt'