(properties: Array<ObjectPropertyKind>)
| 90 | } |
| 91 | |
| 92 | function 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 | |
| 116 | export const RemovePluginMetadataPlugin = (nuxt: Nuxt) => createUnplugin(() => { |
| 117 | return { |
no test coverage detected
searching dependent graphs…