fix(nuxt): fall back to plugin.src for variable name generation (#30649)

This commit is contained in:
Daniel Roe 2025-01-17 22:56:03 +00:00 committed by GitHub
parent 632e7f941f
commit 929dcfbed5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -68,7 +68,7 @@ export const clientPluginTemplate: NuxtTemplate = {
const imports: string[] = [] const imports: string[] = []
for (const plugin of clientPlugins) { for (const plugin of clientPlugins) {
const path = relative(ctx.nuxt.options.rootDir, plugin.src) const path = relative(ctx.nuxt.options.rootDir, plugin.src)
const variable = genSafeVariableName(filename(plugin.src)).replace(PLUGIN_TEMPLATE_RE, '_') + '_' + hash(path) const variable = genSafeVariableName(filename(plugin.src) || path).replace(PLUGIN_TEMPLATE_RE, '_') + '_' + hash(path)
exports.push(variable) exports.push(variable)
imports.push(genImport(plugin.src, variable)) imports.push(genImport(plugin.src, variable))
} }
@ -88,7 +88,7 @@ export const serverPluginTemplate: NuxtTemplate = {
const imports: string[] = [] const imports: string[] = []
for (const plugin of serverPlugins) { for (const plugin of serverPlugins) {
const path = relative(ctx.nuxt.options.rootDir, plugin.src) const path = relative(ctx.nuxt.options.rootDir, plugin.src)
const variable = genSafeVariableName(filename(path)).replace(PLUGIN_TEMPLATE_RE, '_') + '_' + hash(path) const variable = genSafeVariableName(filename(plugin.src) || path).replace(PLUGIN_TEMPLATE_RE, '_') + '_' + hash(path)
exports.push(variable) exports.push(variable)
imports.push(genImport(plugin.src, variable)) imports.push(genImport(plugin.src, variable))
} }