@architect/inventory 3.4.4-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
|
@@ -4,9 +4,12 @@ let { is, pragmas, tidyError, validationPatterns } = require('../../lib')
|
|
|
4
4
|
let { lambdas } = pragmas
|
|
5
5
|
let nonLambdaSetters = [ 'customLambdas', 'env', 'proxy', 'runtimes', 'shared', 'static', 'views', 'tables', 'tables-indexes' ]
|
|
6
6
|
let setters = [ ...lambdas, ...nonLambdaSetters ]
|
|
7
|
-
let pluginMethods = [ 'deploy', 'hydrate', 'sandbox' ]
|
|
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
|
-
|
|
96
|
-
|
|
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
|
}
|
|
@@ -12,18 +12,18 @@ module.exports = function setRuntimePlugins (params, project) {
|
|
|
12
12
|
if (runtimePlugins?.length) {
|
|
13
13
|
let runtimes = {
|
|
14
14
|
runtimes: [],
|
|
15
|
+
runtimePlugins: {}, // Map runtimes to their corresponding plugins
|
|
15
16
|
}
|
|
16
17
|
// inventory._project is not yet built, so provide as much as we can to plugins for now
|
|
17
18
|
let inv = deepFrozenCopy({ ...inventory, _project: project })
|
|
18
19
|
let build
|
|
19
20
|
runtimePlugins.forEach(fn => {
|
|
20
|
-
let errType = `plugin: ${fn.
|
|
21
|
+
let errType = `plugin: ${fn._plugin}, method: set.runtimes`
|
|
21
22
|
try {
|
|
22
23
|
var result = fn({ arc: inv._project.arc, inventory: { inv } })
|
|
23
24
|
}
|
|
24
25
|
catch (err) {
|
|
25
|
-
err.message = `Runtime plugin exception: ${errType}`
|
|
26
|
-
+ `\n` + err.message
|
|
26
|
+
err.message = `Runtime plugin exception: ${errType}\n` + err.message
|
|
27
27
|
throw err
|
|
28
28
|
}
|
|
29
29
|
// Accept one or more results, then loop through them
|
|
@@ -55,13 +55,14 @@ module.exports = function setRuntimePlugins (params, project) {
|
|
|
55
55
|
if (is.string(runtime.build)) build = runtime.build
|
|
56
56
|
}
|
|
57
57
|
if (type === 'transpiled' && !allRuntimes.includes(baseRuntime)) {
|
|
58
|
-
return errors.push(`Runtime '${name}' must include a valid baseRuntime property corresponding to a valid Lambda runtime (e.g. '
|
|
58
|
+
return errors.push(`Runtime '${name}' must include a valid baseRuntime property corresponding to a valid Lambda runtime (e.g. 'nodejs18.x')`)
|
|
59
59
|
}
|
|
60
60
|
runtimes.runtimes.push(name)
|
|
61
|
+
runtimes.runtimePlugins[name] = fn._plugin
|
|
61
62
|
runtimes[name] = runtime
|
|
62
63
|
})
|
|
63
64
|
})
|
|
64
|
-
return { build, runtimes }
|
|
65
|
+
return { build, runtimes, runtimePlugins }
|
|
65
66
|
}
|
|
66
67
|
return {}
|
|
67
68
|
}
|