Skip to content

Commit

Permalink
fix: replace dir names from types sorted by length
Browse files Browse the repository at this point in the history
  • Loading branch information
harlan-zw committed Jan 8, 2024
1 parent d277d3a commit 9a1627a
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,10 +419,13 @@ export default defineNuxtModule<ModuleOptions>({
const componentImports = ogImageComponentCtx.components.map((component) => {
const relativeComponentPath = relative(resolve(nuxt!.options.rootDir, nuxt!.options.buildDir, 'module'), component.path!)
// remove dirNames from component name
const name = config.componentDirs.reduce((name, dir) => {
const name = config.componentDirs
// need to sort by longest first so we don't replace the wrong part of the string
.sort((a, b) => b.length - a.length)
.reduce((name, dir) => {
// only replace from the start of the string
return name.replace(new RegExp(`^${dir}`), '')
}, component.pascalName)
return name.replace(new RegExp(`^${dir}`), '')
}, component.pascalName)
return ` '${name}': typeof import('${relativeComponentPath}')['default']`
}).join('\n')
return `
Expand Down

0 comments on commit 9a1627a

Please sign in to comment.