@architect/inventory 3.5.0-RC.0 → 3.5.0-RC.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@architect/inventory",
3
- "version": "3.5.0-RC.0",
3
+ "version": "3.5.0-RC.1",
4
4
  "description": "Architect project resource enumeration utility",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -7,6 +7,9 @@ let setters = [ ...lambdas, ...nonLambdaSetters ]
7
7
  let pluginMethods = [ 'deploy', 'create', 'hydrate', 'sandbox' ]
8
8
  let reservedNames = [ '_methods' ]
9
9
 
10
+ // Exceptions to the rule where plugin hooks must be functions
11
+ let stringOrArrayHooks = { create: { register: true } }
12
+
10
13
  module.exports = async function getPluginModules ({ arc, inventory, errors }) {
11
14
  if (!arc?.plugins?.length && !arc?.macros?.length) return null
12
15
  let plugins = {}
@@ -92,8 +95,18 @@ module.exports = async function getPluginModules ({ arc, inventory, errors }) {
92
95
  // Command hooks
93
96
  else if (pluginMethods.includes(method)) {
94
97
  Object.entries(item).forEach(([ hook, fn ]) => {
95
- if (!is.fn(fn)) {
96
- let msg = `Invalid plugin, must be a function: plugin: ${name}, method: ${method}.${hook}`
98
+ let isStringOrArrayHook = stringOrArrayHooks?.[method]?.[hook]
99
+ if (isStringOrArrayHook) {
100
+ if (!(is.string(fn) || is.array(fn))) {
101
+ let msg = `Invalid plugin, property must be a string or array: plugin: ${name}, property: ${method}.${hook}`
102
+ errors.push(msg)
103
+ return
104
+ }
105
+ // Normalize strings to arrays
106
+ if (is.string(fn)) plugins[name][method][hook] = fn = [ fn ]
107
+ }
108
+ else if (!isStringOrArrayHook && !is.fn(fn)) {
109
+ let msg = `Invalid plugin, method must be a function: plugin: ${name}, method: ${method}.${hook}`
97
110
  errors.push(msg)
98
111
  return
99
112
  }