@architect/inventory 4.0.6 → 4.0.8

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.6",
3
+ "version": "4.0.8",
4
4
  "description": "Architect project resource enumeration utility",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -22,7 +22,9 @@ module.exports = async function getPluginModules ({ arc, inventory, errors }) {
22
22
  if (arc?.macros?.length) tagPlugins(arc.macros, 'macro')
23
23
 
24
24
  let { node } = process.versions
25
- let nodeVer = Number(node.split('.')[0])
25
+ let nodeVersionParts = node.split('.')
26
+ let nodeMajorVer = Number(nodeVersionParts[0])
27
+ let nodeMinorVer = Number(nodeVersionParts[1])
26
28
 
27
29
  for (let pluginItem of pluginItems) {
28
30
  let { plugin, type } = pluginItem
@@ -31,12 +33,12 @@ module.exports = async function getPluginModules ({ arc, inventory, errors }) {
31
33
 
32
34
  if (is.string(plugin)) {
33
35
  name = plugin
34
- pluginPath = getPath(cwd, type + 's', name)
36
+ pluginPath = await getPath(cwd, type + 's', name)
35
37
  }
36
38
  else if (is.object(plugin)) {
37
39
  name = Object.keys(plugin)[0]
38
40
  pluginPath = plugin[name].src
39
- ? resolve('.' + sep + plugin[name].src, cwd)
41
+ ? await resolve('.' + sep + plugin[name].src, cwd)
40
42
  : join(cwd, 'src', type + 's', name)
41
43
  }
42
44
 
@@ -55,7 +57,8 @@ module.exports = async function getPluginModules ({ arc, inventory, errors }) {
55
57
  if (type === 'plugin') {
56
58
  try {
57
59
  plugins[name] = require(pluginPath)
58
- if (nodeVer >= 22 && plugins[name].default) {
60
+ // starting in node 20.19, you can now require() esm
61
+ if ((nodeMajorVer >= 22 || (nodeMajorVer >= 20 && nodeMinorVer >= 19)) && plugins[name].default) {
59
62
  plugins[name] = plugins[name].default
60
63
  }
61
64
  }
@@ -133,17 +136,17 @@ module.exports = async function getPluginModules ({ arc, inventory, errors }) {
133
136
  return plugins
134
137
  }
135
138
 
136
- function getPath (cwd, srcDir, name) {
139
+ async function getPath (cwd, srcDir, name) {
137
140
  let path1 = join(cwd, 'src', srcDir, `${name}.js`)
138
141
  let path2 = join(cwd, 'src', srcDir, `${name}.mjs`)
139
142
  let path3 = join(cwd, 'src', srcDir, name)
140
143
  /**/ if (existsSync(path1)) return path1
141
144
  else if (existsSync(path2)) return path2
142
- else if (existsSync(path3)) return resolve(path3, cwd)
143
- return resolve(name, cwd)
145
+ else if (existsSync(path3)) return await resolve(path3, cwd)
146
+ return await resolve(name, cwd)
144
147
  }
145
148
 
146
- function resolve (path, cwd) {
149
+ async function resolve (path, cwd) {
147
150
  try {
148
151
  return require.resolve(path, { paths: [ cwd ] })
149
152
  }
@@ -152,7 +155,17 @@ function resolve (path, cwd) {
152
155
  return require.resolve(`@${path}`, { paths: [ cwd ] })
153
156
  }
154
157
  catch {
155
- return
158
+ let gotSomething
159
+ let mjsPath = `${path}/index.mjs`
160
+ try {
161
+ gotSomething = await import(mjsPath)
162
+ }
163
+ catch {
164
+ return
165
+ }
166
+ /* istanbul ignore next: idk why but for some reason nyc isn't picking up the catches; all cases are covered in tests, though! */
167
+ if (gotSomething) return mjsPath
168
+ else return
156
169
  }
157
170
  }
158
171
  }