@architect/inventory 3.2.0 → 3.3.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/changelog.md +30 -0
- package/package.json +1 -1
- package/src/config/pragmas/plugins.js +1 -1
- package/src/config/pragmas/populate-lambda/get-handler.js +12 -10
- package/src/config/pragmas/populate-other/index.js +5 -5
- package/src/config/pragmas/shared.js +26 -14
- package/src/config/pragmas/validate/_shared.js +5 -6
- package/src/config/pragmas/views.js +27 -15
package/changelog.md
CHANGED
|
@@ -2,6 +2,36 @@
|
|
|
2
2
|
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
+
## [3.3.0] 2022-09-06
|
|
6
|
+
|
|
7
|
+
### Changed
|
|
8
|
+
|
|
9
|
+
- Node 14+ Lambda handler selection now defaults to ESM (unless otherwise specified)
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## [3.2.2] 2022-08-20
|
|
14
|
+
|
|
15
|
+
### Changed
|
|
16
|
+
|
|
17
|
+
- Enabled `hydrate` plugin API support
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## [3.2.1] 2022-08-10
|
|
22
|
+
|
|
23
|
+
### Changed
|
|
24
|
+
|
|
25
|
+
- By default, when a `set.shared|views` plugin sets a `src` path, if it is not present on the filesystem, Inventory falls back to default paths (e.g. `src/shared|views`)
|
|
26
|
+
- `set.shared|views` plugins now accept a `required` flag to enforce a validation error should a `src` path conflict with the project manifest (or not be found on the filesystem)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
### Fixed
|
|
30
|
+
|
|
31
|
+
- Fixed an obscure internal reference passing bug in `set.proxy|shared|static|views` plugins
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
5
35
|
## [3.2.0] 2022-07-24
|
|
6
36
|
|
|
7
37
|
### Added
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@ let { is, normalizeSrc, pragmas, tidyError, validationPatterns } = require('../.
|
|
|
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', 'sandbox' ]
|
|
7
|
+
let pluginMethods = [ 'deploy', 'hydrate', 'sandbox' ]
|
|
8
8
|
let reservedNames = [ '_methods' ]
|
|
9
9
|
|
|
10
10
|
module.exports = function getPluginModules ({ arc, inventory, errors }) {
|
|
@@ -32,6 +32,7 @@ module.exports = function getHandler ({ config, src, build, errors }) {
|
|
|
32
32
|
return handlerConfig
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
+
// As of nodejs14.x, CJS remains the default over ESM when both are present
|
|
35
36
|
let nodeHandlers = [ 'index.js', 'index.mjs', 'index.cjs' ]
|
|
36
37
|
let denoHandlers = [ 'mod.ts', 'mod.js' ]
|
|
37
38
|
// TODO: these are all prob going away
|
|
@@ -43,14 +44,22 @@ function getExt ({ runtime, src, errors }) {
|
|
|
43
44
|
if (runtime === 'nodejs12.x') {
|
|
44
45
|
return { ext: 'js', handlerModuleSystem: 'cjs' }
|
|
45
46
|
}
|
|
46
|
-
// This presumes Node.js 14
|
|
47
|
+
// This presumes Node.js ≥14 Lambda releases use the same CJS/ESM pattern
|
|
48
|
+
// Generally in Lambda: CJS wins, but in Architect-land we attempt to default to ESM
|
|
47
49
|
else {
|
|
48
|
-
let { file, ext = '
|
|
50
|
+
let { file, ext = 'mjs' } = findHandler(nodeHandlers, src)
|
|
49
51
|
let handlerModuleSystem = ext === 'mjs' ? 'esm' : 'cjs'
|
|
50
52
|
let pkgFile = join(src, 'package.json')
|
|
51
53
|
if (existsSync(pkgFile)) {
|
|
52
54
|
let pkg = JSON.parse(readFileSync(pkgFile))
|
|
53
|
-
|
|
55
|
+
|
|
56
|
+
/**/ if (pkg?.type === 'module') handlerModuleSystem = 'esm'
|
|
57
|
+
else if (pkg?.type === 'commonjs') handlerModuleSystem = 'cjs'
|
|
58
|
+
else if (pkg?.type) throw Error(`Invalid 'type' field: ${pkg.type}`)
|
|
59
|
+
else handlerModuleSystem = 'cjs' // Lambda's default, not ours
|
|
60
|
+
|
|
61
|
+
// We always get to make this a .js file, even if it's ESM!
|
|
62
|
+
ext = 'js'
|
|
54
63
|
}
|
|
55
64
|
return { file, ext, handlerModuleSystem }
|
|
56
65
|
}
|
|
@@ -78,10 +87,3 @@ function findHandler (arr, src){
|
|
|
78
87
|
}
|
|
79
88
|
return {}
|
|
80
89
|
}
|
|
81
|
-
|
|
82
|
-
function getModSystem (pkg) {
|
|
83
|
-
if (pkg?.type === 'module') return 'esm'
|
|
84
|
-
else if (pkg?.type === 'commonjs') return 'cjs'
|
|
85
|
-
else if (pkg?.type) throw Error(`Invalid 'type' field: ${pkg.type}`)
|
|
86
|
-
return 'cjs'
|
|
87
|
-
}
|
|
@@ -75,9 +75,9 @@ function validate (item, valid, type) {
|
|
|
75
75
|
*/
|
|
76
76
|
function settings (params) {
|
|
77
77
|
let { errors, settings, plugins, inventory, type, valid } = params
|
|
78
|
+
let newSettings = is.defined(settings) ? JSON.parse(JSON.stringify(settings)) : settings
|
|
78
79
|
if (plugins) {
|
|
79
80
|
let invCopy = deepFrozenCopy(inventory)
|
|
80
|
-
let pluginSettings = settings
|
|
81
81
|
let foundError = false
|
|
82
82
|
plugins.forEach(fn => {
|
|
83
83
|
try {
|
|
@@ -95,7 +95,7 @@ function settings (params) {
|
|
|
95
95
|
else {
|
|
96
96
|
Object.entries(result).forEach(([ setting, value ]) => {
|
|
97
97
|
if (is.defined(settings[setting]) && is.defined(value)) {
|
|
98
|
-
|
|
98
|
+
newSettings[setting] = value
|
|
99
99
|
}
|
|
100
100
|
})
|
|
101
101
|
}
|
|
@@ -103,15 +103,15 @@ function settings (params) {
|
|
|
103
103
|
if (foundError) return null
|
|
104
104
|
|
|
105
105
|
// Validation pass
|
|
106
|
-
let validationErrors = validate(
|
|
106
|
+
let validationErrors = validate(newSettings, valid, type)
|
|
107
107
|
if (validationErrors.length) {
|
|
108
108
|
errors = errors.push(...validationErrors)
|
|
109
109
|
return null
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
-
return
|
|
112
|
+
return newSettings
|
|
113
113
|
}
|
|
114
|
-
return
|
|
114
|
+
return newSettings
|
|
115
115
|
}
|
|
116
116
|
|
|
117
117
|
module.exports = { resources, settings }
|
|
@@ -14,10 +14,10 @@ module.exports = function configureShared ({ arc, pragmas, inventory, errors })
|
|
|
14
14
|
shared: []
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
let
|
|
17
|
+
let foundPluginSrc, foundArcSrc, required = false
|
|
18
18
|
let pluginSrc = populate.settings({
|
|
19
19
|
errors,
|
|
20
|
-
settings: shared,
|
|
20
|
+
settings: { ...shared, required: null },
|
|
21
21
|
plugins: inventory.plugins?._methods?.set?.shared,
|
|
22
22
|
inventory,
|
|
23
23
|
type: 'shared',
|
|
@@ -27,33 +27,45 @@ module.exports = function configureShared ({ arc, pragmas, inventory, errors })
|
|
|
27
27
|
// Lambda paths have not yet been reified in Inventory
|
|
28
28
|
if (is.string(pluginSrc?.src)) {
|
|
29
29
|
shared.src = pluginSrc.src
|
|
30
|
-
|
|
30
|
+
required = pluginSrc.required
|
|
31
|
+
foundPluginSrc = true
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
// First pass to get + check shared folder (if any)
|
|
34
35
|
if (arc?.shared?.length) {
|
|
35
36
|
for (let share of arc.shared) {
|
|
36
|
-
if (is.array(share)) {
|
|
37
|
-
|
|
38
|
-
if (key === 'src' && is.string(share[1])) {
|
|
37
|
+
if (is.array(share) && share[0]?.toLowerCase() === 'src') {
|
|
38
|
+
if (is.string(share[1])) {
|
|
39
39
|
shared.src = share[1]
|
|
40
|
-
|
|
40
|
+
foundArcSrc = true
|
|
41
|
+
if (required) errors.push(`@shared src setting conflicts with plugin`)
|
|
41
42
|
continue
|
|
42
43
|
}
|
|
43
|
-
|
|
44
|
-
errors.push(`@shared invalid setting: ${key}`)
|
|
45
|
-
}
|
|
44
|
+
else errors.push(`@shared invalid setting: src`)
|
|
46
45
|
}
|
|
47
46
|
}
|
|
48
47
|
}
|
|
49
48
|
|
|
50
|
-
if
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
// Source path selection + validation: manifest always wins; validate plugins differently if required; if not, fall back to `src/shared` (or null)
|
|
50
|
+
if (foundArcSrc) {
|
|
51
|
+
validate.shared(shared.src, cwd, errors, true)
|
|
52
|
+
}
|
|
53
|
+
else if (foundPluginSrc) {
|
|
54
|
+
if (!required) {
|
|
55
|
+
if (!is.exists(shared.src)) shared.src = src
|
|
56
|
+
if (!is.exists(shared.src)) return null
|
|
57
|
+
}
|
|
58
|
+
validate.shared(shared.src, cwd, errors, required)
|
|
59
|
+
}
|
|
60
|
+
else if (is.exists(src)) {
|
|
61
|
+
shared.src = src
|
|
62
|
+
validate.shared(shared.src, cwd, errors, false)
|
|
63
|
+
}
|
|
53
64
|
// Exit if configured shared folder doesn't exist
|
|
54
|
-
|
|
65
|
+
else return null
|
|
55
66
|
|
|
56
67
|
// Proceeding from here resets all shared config, so make sure it's only if specific shared are specified
|
|
68
|
+
let foundSrcSetting = foundArcSrc || foundPluginSrc
|
|
57
69
|
let some = arc.shared?.length && !(arc?.shared?.length === 1 && foundSrcSetting)
|
|
58
70
|
if (some) {
|
|
59
71
|
// Reset shared settings
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
let { join, resolve, sep } = require('path')
|
|
2
2
|
let { is } = require('../../../lib')
|
|
3
3
|
|
|
4
|
-
module.exports = function validateShared (src, cwd, errors) {
|
|
5
|
-
let path = src
|
|
4
|
+
module.exports = function validateShared (src, cwd, errors, required) {
|
|
5
|
+
let path = src?.startsWith(cwd) ? src : resolve(join(cwd, src))
|
|
6
6
|
|
|
7
|
-
if (
|
|
8
|
-
else if (!is.
|
|
7
|
+
if (is.exists(path) && !is.folder(path)) errors.push(`Must be a directory: ${src}`)
|
|
8
|
+
else if (!is.exists(path) && required) errors.push(`Directory not found: ${src}`)
|
|
9
9
|
|
|
10
|
-
let valid = path && path.
|
|
11
|
-
(cwd.split(sep) < path.split(sep))
|
|
10
|
+
let valid = path?.startsWith(cwd) && (cwd.split(sep) < path.split(sep))
|
|
12
11
|
if (!valid) errors.push(`Directory must be a subfolder of this project: ${src}`)
|
|
13
12
|
}
|
|
@@ -18,10 +18,10 @@ module.exports = function configureViews ({ arc, pragmas, inventory, errors }) {
|
|
|
18
18
|
views: []
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
let
|
|
21
|
+
let foundPluginSrc, foundArcSrc, required = false
|
|
22
22
|
let pluginSrc = populate.settings({
|
|
23
23
|
errors,
|
|
24
|
-
settings: views,
|
|
24
|
+
settings: { ...views, required: null },
|
|
25
25
|
plugins: inventory.plugins?._methods?.set?.views,
|
|
26
26
|
inventory,
|
|
27
27
|
type: 'views',
|
|
@@ -31,33 +31,45 @@ module.exports = function configureViews ({ arc, pragmas, inventory, errors }) {
|
|
|
31
31
|
// Lambda paths have not yet been reified in Inventory
|
|
32
32
|
if (is.string(pluginSrc?.src)) {
|
|
33
33
|
views.src = pluginSrc.src
|
|
34
|
-
|
|
34
|
+
required = pluginSrc.required
|
|
35
|
+
foundPluginSrc = true
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
// First pass to get + check views folder (if any)
|
|
38
39
|
if (arc?.views?.length) {
|
|
39
40
|
for (let view of arc.views) {
|
|
40
|
-
if (is.array(view)) {
|
|
41
|
-
|
|
42
|
-
if (key === 'src' && is.string(view[1])) {
|
|
41
|
+
if (is.array(view) && view[0]?.toLowerCase() === 'src') {
|
|
42
|
+
if (is.string(view[1])) {
|
|
43
43
|
views.src = view[1]
|
|
44
|
-
|
|
44
|
+
foundArcSrc = true
|
|
45
|
+
if (required) errors.push(`@views src setting conflicts with plugin`)
|
|
45
46
|
continue
|
|
46
47
|
}
|
|
47
|
-
|
|
48
|
-
errors.push(`@shared invalid setting: ${key}`)
|
|
49
|
-
}
|
|
48
|
+
else errors.push(`@views invalid setting: src`)
|
|
50
49
|
}
|
|
51
50
|
}
|
|
52
51
|
}
|
|
53
52
|
|
|
54
|
-
if
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
if (
|
|
53
|
+
// Source path selection + validation: manifest always wins; validate plugins differently if required; if not, fall back to `src/shared` (or null)
|
|
54
|
+
if (foundArcSrc) {
|
|
55
|
+
validate.shared(views.src, cwd, errors, true)
|
|
56
|
+
}
|
|
57
|
+
else if (foundPluginSrc) {
|
|
58
|
+
if (!required) {
|
|
59
|
+
if (!is.exists(views.src)) views.src = src
|
|
60
|
+
if (!is.exists(views.src)) return null
|
|
61
|
+
}
|
|
62
|
+
validate.shared(views.src, cwd, errors, required)
|
|
63
|
+
}
|
|
64
|
+
else if (is.exists(src)) {
|
|
65
|
+
views.src = src
|
|
66
|
+
validate.shared(views.src, cwd, errors, false)
|
|
67
|
+
}
|
|
68
|
+
// Exit if configured shared folder doesn't exist
|
|
69
|
+
else return null
|
|
59
70
|
|
|
60
71
|
// Proceeding from here resets all views config, so make sure it's only if specific views are specified
|
|
72
|
+
let foundSrcSetting = foundArcSrc || foundPluginSrc
|
|
61
73
|
let some = arc.views?.length && !(arc?.views?.length === 1 && foundSrcSetting)
|
|
62
74
|
if (some) {
|
|
63
75
|
// Reset views settings
|