diff --git a/src/parser.ts b/src/parser.ts index 4bdab61..addf317 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -8,6 +8,7 @@ import type { Component } from '@nuxt/schema' import { resolvePathSync } from 'mlly' import type { ModuleOptions } from './options' import type { NuxtComponentMeta } from './types' +import { defu } from 'defu' export type ComponentMetaParserOptions = Omit & { components: Component[] @@ -210,6 +211,12 @@ export function useComponentMetaParser ( component.meta.exposed = component.meta.exposed.map((sch: any) => stripeTypeScriptInternalTypesSchema(sch, true)) component.meta.events = component.meta.events.map((sch: any) => stripeTypeScriptInternalTypesSchema(sch, true)) + + const content = await readFile(component.fullPath, 'utf-8') + const extendComponentMetaMatch = content.match(/extendComponentMeta\((\{[\s\S]*?\})\)/); + const extendedComponentMeta = extendComponentMetaMatch?.length ? eval(`(${extendComponentMetaMatch[1]})`) : null + component.meta = defu(component.meta, extendedComponentMeta) + // Remove descriptional fileds to reduce chunk size removeFields(component.meta, ['declarations']) @@ -260,7 +267,6 @@ function removeFields(obj: Record, fieldsToRemove: string[]): any { } } } - return obj; } diff --git a/src/runtime/composables/extendComponentMeta.ts b/src/runtime/composables/extendComponentMeta.ts new file mode 100644 index 0000000..6c868fe --- /dev/null +++ b/src/runtime/composables/extendComponentMeta.ts @@ -0,0 +1 @@ +export function extendComponentMeta(_meta: Record) { /* Placeholder for extending component meta */ } diff --git a/test/fixtures/basic/components/TestComponent.vue b/test/fixtures/basic/components/TestComponent.vue index 65b17e4..3022ac4 100644 --- a/test/fixtures/basic/components/TestComponent.vue +++ b/test/fixtures/basic/components/TestComponent.vue @@ -7,6 +7,12 @@