MCPcopy
hub / github.com/nuxt/nuxt / extractMetaFromObject

Function extractMetaFromObject

packages/nuxt/src/core/plugins/plugin-metadata.ts:92–114  ·  view source on GitHub ↗
(properties: Array<ObjectPropertyKind>)

Source from the content-addressed store, hash-verified

90}
91
92function extractMetaFromObject (properties: Array<ObjectPropertyKind>) {
93 const meta: PluginMeta = {}
94 for (const property of properties) {
95 if (property.type === 'SpreadElement' || !('name' in property.key)) {
96 throw new Error('Invalid plugin metadata')
97 }
98 const propertyKey = property.key.name
99 if (!isMetadataKey(propertyKey)) { continue }
100 if (property.value.type === 'Literal') {
101 meta[propertyKey] = property.value.value as any
102 }
103 if (property.value.type === 'UnaryExpression' && property.value.argument.type === 'Literal') {
104 meta[propertyKey] = JSON.parse(property.value.operator + property.value.argument.raw!)
105 }
106 if (propertyKey === 'dependsOn' && property.value.type === 'ArrayExpression') {
107 if (property.value.elements.some(e => !e || e.type !== 'Literal' || typeof e.value !== 'string')) {
108 throw new Error('dependsOn must take an array of string literals')
109 }
110 meta[propertyKey] = property.value.elements.map(e => (e as Literal)!.value as NuxtAppLiterals['pluginName'])
111 }
112 }
113 return meta
114}
115
116export const RemovePluginMetadataPlugin = (nuxt: Nuxt) => createUnplugin(() => {
117 return {

Callers 1

extractMetadataFunction · 0.85

Calls 1

isMetadataKeyFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…