mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 05:35:13 +00:00
fix(nuxt): handle mismatching declaration/plugin extensions (#28709)
This commit is contained in:
parent
5e360f2c2f
commit
ae8cc86483
@ -134,11 +134,21 @@ export const pluginsDeclaration: NuxtTemplate = {
|
|||||||
const relativePath = relative(typesDir, pluginPath)
|
const relativePath = relative(typesDir, pluginPath)
|
||||||
|
|
||||||
const correspondingDeclaration = pluginPath.replace(/\.(?<letter>[cm])?jsx?$/, '.d.$<letter>ts')
|
const correspondingDeclaration = pluginPath.replace(/\.(?<letter>[cm])?jsx?$/, '.d.$<letter>ts')
|
||||||
|
// if `.d.ts` file exists alongside a `.js` plugin, or if `.d.mts` file exists alongside a `.mjs` plugin, we can use the entire path
|
||||||
if (correspondingDeclaration !== pluginPath && exists(correspondingDeclaration)) {
|
if (correspondingDeclaration !== pluginPath && exists(correspondingDeclaration)) {
|
||||||
tsImports.push(relativePath)
|
tsImports.push(relativePath)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const incorrectDeclaration = pluginPath.replace(/\.[cm]jsx?$/, '.d.ts')
|
||||||
|
// if `.d.ts` file exists, but plugin is `.mjs`, add `.js` extension to the import
|
||||||
|
// to hotfix issue until ecosystem updates to `@nuxt/module-builder@>=0.8.0`
|
||||||
|
if (incorrectDeclaration !== pluginPath && exists(incorrectDeclaration)) {
|
||||||
|
tsImports.push(relativePath.replace(/\.[cm](jsx?)$/, '.$1'))
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// if there is no declaration we only want to remove the extension if it's a TypeScript file
|
||||||
if (exists(pluginPath)) {
|
if (exists(pluginPath)) {
|
||||||
if (TS_RE.test(pluginPath)) {
|
if (TS_RE.test(pluginPath)) {
|
||||||
tsImports.push(relativePath.replace(EXTENSION_RE, ''))
|
tsImports.push(relativePath.replace(EXTENSION_RE, ''))
|
||||||
|
Loading…
Reference in New Issue
Block a user