@architect/inventory 4.0.7 → 4.0.9

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": "4.0.7",
3
+ "version": "4.0.9",
4
4
  "description": "Architect project resource enumeration utility",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -33,12 +33,12 @@ module.exports = async function getPluginModules ({ arc, inventory, errors }) {
33
33
 
34
34
  if (is.string(plugin)) {
35
35
  name = plugin
36
- pluginPath = getPath(cwd, type + 's', name)
36
+ pluginPath = await getPath(cwd, type + 's', name)
37
37
  }
38
38
  else if (is.object(plugin)) {
39
39
  name = Object.keys(plugin)[0]
40
40
  pluginPath = plugin[name].src
41
- ? resolve('.' + sep + plugin[name].src, cwd)
41
+ ? await resolve('.' + sep + plugin[name].src, cwd)
42
42
  : join(cwd, 'src', type + 's', name)
43
43
  }
44
44
 
@@ -79,6 +79,10 @@ module.exports = async function getPluginModules ({ arc, inventory, errors }) {
79
79
  if (type === 'macro') {
80
80
  plugins[name] = { deploy: { start: require(pluginPath) } }
81
81
  }
82
+ // Check the plugin has at least one recognised method configured
83
+ if (![ 'set', ...pluginMethods ].some((method) => plugins[name][method])) {
84
+ errors.push(`No recognized methods for plugin: ${name}`)
85
+ }
82
86
  // Walk each plugin and build the method tree
83
87
  Object.entries(plugins[name]).forEach(([ method, item ]) => {
84
88
  // Primitive setters
@@ -136,17 +140,17 @@ module.exports = async function getPluginModules ({ arc, inventory, errors }) {
136
140
  return plugins
137
141
  }
138
142
 
139
- function getPath (cwd, srcDir, name) {
143
+ async function getPath (cwd, srcDir, name) {
140
144
  let path1 = join(cwd, 'src', srcDir, `${name}.js`)
141
145
  let path2 = join(cwd, 'src', srcDir, `${name}.mjs`)
142
146
  let path3 = join(cwd, 'src', srcDir, name)
143
147
  /**/ if (existsSync(path1)) return path1
144
148
  else if (existsSync(path2)) return path2
145
- else if (existsSync(path3)) return resolve(path3, cwd)
146
- return resolve(name, cwd)
149
+ else if (existsSync(path3)) return await resolve(path3, cwd)
150
+ return await resolve(name, cwd)
147
151
  }
148
152
 
149
- function resolve (path, cwd) {
153
+ async function resolve (path, cwd) {
150
154
  try {
151
155
  return require.resolve(path, { paths: [ cwd ] })
152
156
  }
@@ -155,7 +159,17 @@ function resolve (path, cwd) {
155
159
  return require.resolve(`@${path}`, { paths: [ cwd ] })
156
160
  }
157
161
  catch {
158
- return
162
+ let gotSomething
163
+ let mjsPath = `${path}/index.mjs`
164
+ try {
165
+ gotSomething = await import(mjsPath)
166
+ }
167
+ catch {
168
+ return
169
+ }
170
+ /* istanbul ignore next: idk why but for some reason nyc isn't picking up the catches; all cases are covered in tests, though! */
171
+ if (gotSomething) return mjsPath
172
+ else return
159
173
  }
160
174
  }
161
175
  }