@architect/inventory 3.3.5 → 3.4.0-RC.0

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.3.5",
3
+ "version": "3.4.0-RC.0",
4
4
  "description": "Architect project resource enumeration utility",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -21,23 +21,24 @@
21
21
  },
22
22
  "license": "Apache-2.0",
23
23
  "dependencies": {
24
- "@architect/asap": "~5.1.0",
24
+ "@architect/asap": "~5.1.1",
25
25
  "@architect/parser": "~6.0.2",
26
26
  "@architect/utils": "~3.1.2",
27
+ "esm": "~3.2.25",
27
28
  "lambda-runtimes": "~1.1.3"
28
29
  },
29
30
  "devDependencies": {
30
- "@architect/eslint-config": "~2.0.1",
31
+ "@architect/eslint-config": "~2.1.1",
31
32
  "aws-sdk": "2.1055.0",
32
33
  "aws-sdk-mock": "~5.8.0",
33
34
  "cross-env": "~7.0.3",
34
35
  "dotenv": "~16.0.3",
35
- "eslint": "~8.28.0",
36
+ "eslint": "~8.32.0",
36
37
  "mock-fs": "~5.2.0",
37
38
  "mock-require": "~3.0.3",
38
39
  "nyc": "~15.1.0",
39
40
  "tap-spec": "^5.0.0",
40
- "tape": "^5.6.1"
41
+ "tape": "^5.6.3"
41
42
  },
42
43
  "eslintConfig": {
43
44
  "extends": "@architect/eslint-config"
@@ -6,6 +6,7 @@ let nonLambdaSetters = [ 'customLambdas', 'env', 'proxy', 'runtimes', 'shared',
6
6
  let setters = [ ...lambdas, ...nonLambdaSetters ]
7
7
  let pluginMethods = [ 'deploy', 'hydrate', 'sandbox' ]
8
8
  let reservedNames = [ '_methods' ]
9
+ let requireEsm
9
10
 
10
11
  module.exports = function getPluginModules ({ arc, inventory, errors }) {
11
12
  if (!arc?.plugins?.length && !arc?.macros?.length) return null
@@ -44,9 +45,31 @@ module.exports = function getPluginModules ({ arc, inventory, errors }) {
44
45
  }
45
46
  if (pluginPath) {
46
47
  try {
48
+ /* istanbul ignore next: idk why but for some reason nyc isn't picking up the catches; all cases are covered in tests, though! */
47
49
  if (type === 'plugin') {
48
- // eslint-disable-next-line
49
- plugins[name] = require(pluginPath)
50
+ try {
51
+ // eslint-disable-next-line
52
+ plugins[name] = require(pluginPath)
53
+ }
54
+ catch (err) {
55
+ // TODO: if we refactor all pragma visitors to async we can use Node's built in support for dynamic import within CJS
56
+ if (hasEsmError(err)) {
57
+ try {
58
+ if (!requireEsm) {
59
+ // eslint-disable-next-line
60
+ requireEsm = require('esm')(module)
61
+ }
62
+ let plugin = requireEsm(pluginPath)
63
+ plugins[name] = plugin.default ? plugin.default : plugin
64
+ }
65
+ catch (err) {
66
+ errors.push(err)
67
+ }
68
+ }
69
+ else {
70
+ errors.push(err)
71
+ }
72
+ }
50
73
  }
51
74
  // Remap @macros to deploy.start
52
75
  if (type === 'macro') {
@@ -100,15 +123,18 @@ module.exports = function getPluginModules ({ arc, inventory, errors }) {
100
123
  return plugins
101
124
  }
102
125
 
126
+ /* istanbul ignore next: per above, nyc isn't picking this up, but it is covered! */
103
127
  function getPath (cwd, srcDir, name) {
104
128
  let path1 = join(cwd, 'src', srcDir, `${name}.js`)
105
- let path2 = join(cwd, 'src', srcDir, name)
106
- let path3 = join(cwd, 'node_modules', name)
107
- let path4 = join(cwd, 'node_modules', `@${name}`)
129
+ let path2 = join(cwd, 'src', srcDir, `${name}.mjs`)
130
+ let path3 = join(cwd, 'src', srcDir, name)
131
+ let path4 = join(cwd, 'node_modules', name)
132
+ let path5 = join(cwd, 'node_modules', `@${name}`)
108
133
  /**/ if (existsSync(path1)) return path1
109
134
  else if (existsSync(path2)) return path2
110
135
  else if (existsSync(path3)) return path3
111
136
  else if (existsSync(path4)) return path4
137
+ else if (existsSync(path5)) return path5
112
138
  try {
113
139
  return require.resolve(name)
114
140
  }
@@ -121,3 +147,12 @@ function getPath (cwd, srcDir, name) {
121
147
  }
122
148
  }
123
149
  }
150
+
151
+ let esmErrors = [
152
+ 'Cannot use import statement outside a module',
153
+ `Unexpected token 'export'`,
154
+ 'require() of ES Module',
155
+ 'Must use import to load ES Module',
156
+ ]
157
+ /* istanbul ignore next: per above, nyc isn't picking this up, but it is covered! */
158
+ let hasEsmError = err => esmErrors.some(msg => err.message.includes(msg))