@architect/inventory 2.0.7-RC.0 → 2.1.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/changelog.md CHANGED
@@ -2,6 +2,40 @@
2
2
 
3
3
  ---
4
4
 
5
+ ## [2.1.1] 2021-10-13
6
+
7
+ ### Added
8
+
9
+ - Added `config.runtimeAlias` property to Lambdas whose `config.runtime` is interpolated by way of latest-runtime aliasing (e.g. `node` or `py`)
10
+
11
+
12
+ ### Changed
13
+
14
+ - Internal change: implement [Lambda runtimes module](https://www.npmjs.com/package/lambda-runtimes) instead of maintaining valid runtime list in Inventory
15
+
16
+
17
+ ### Fixed
18
+
19
+ - Fixed `@scheduled` parsing in `app.json` + `package.json` > `arc.scheduled`
20
+
21
+ ---
22
+
23
+ ## [2.1.0] 2021-10-11
24
+
25
+ ### Added
26
+
27
+ - Added latest-runtime version aliasing
28
+ - Example: you want your app to always run the latest Lambda version of Python (instead of specifying `python3.9`(and changing it every time a new version of Python is released); now you can specify `python` or `py`
29
+ - Valid shortcuts: Node.js: `node`, `nodejs`, `node.js`; Python: `python`, `py`; Ruby: `ruby`, `rb`; Java: `java`; Go: `go`, `golang`; .NET: `dotnet`, `.net`; and custom runtimes: `custom`
30
+ - Added runtime validation
31
+
32
+
33
+ ### Changed
34
+
35
+ - Updated dependencies
36
+
37
+ ---
38
+
5
39
  ## [2.0.7] 2021-09-30
6
40
 
7
41
  ### Added
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@architect/inventory",
3
- "version": "2.0.7-RC.0",
3
+ "version": "2.1.1",
4
4
  "description": "Architect project resource enumeration utility",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -20,17 +20,18 @@
20
20
  },
21
21
  "license": "Apache-2.0",
22
22
  "dependencies": {
23
- "@architect/asap": "~4.0.0",
24
- "@architect/parser": "~5.0.0",
25
- "@architect/utils": "~3.0.2"
23
+ "@architect/asap": "~4.1.0",
24
+ "@architect/parser": "~5.0.2",
25
+ "@architect/utils": "~3.0.4",
26
+ "lambda-runtimes": "~1.0.1"
26
27
  },
27
28
  "devDependencies": {
28
- "@architect/eslint-config": "~2.0.0",
29
+ "@architect/eslint-config": "~2.0.1",
29
30
  "aws-sdk": "2.880.0",
30
- "aws-sdk-mock": "5.1.0",
31
+ "aws-sdk-mock": "~5.4.0",
31
32
  "cross-env": "~7.0.3",
32
- "eslint": "~7.32.0",
33
- "mock-fs": "~5.0.0",
33
+ "eslint": "~8.0.1",
34
+ "mock-fs": "~5.1.1",
34
35
  "mock-require": "~3.0.3",
35
36
  "nyc": "~15.1.0",
36
37
  "tap-spec": "^5.0.0",
@@ -8,7 +8,7 @@ module.exports = function configureCDN ({ arc, errors }) {
8
8
  let cdn = true
9
9
  arc.cdn.forEach(setting => {
10
10
  let disabled = [ false, 'disable', 'disabled' ]
11
- let isDisabled = disabled.some(s => s === setting)
11
+ let isDisabled = disabled.includes(setting)
12
12
  if (isDisabled) cdn = false
13
13
  })
14
14
 
@@ -33,7 +33,7 @@ let get = {
33
33
  module.exports = function populateScheduled ({ item, dir, cwd, errors }) {
34
34
  let rate = null
35
35
  let cron = null
36
- if (is.array(item) && item.length >= 3) {
36
+ if (is.array(item)) {
37
37
  let name = item[0]
38
38
 
39
39
  // Hacky but it works
@@ -52,9 +52,17 @@ module.exports = function populateScheduled ({ item, dir, cwd, errors }) {
52
52
  else if (is.object(item)) {
53
53
  let name = Object.keys(item)[0]
54
54
 
55
- // Handle rate + cron
56
- if (item[name].rate) rate = get.rate(item[name].rate.join(' '))
57
- if (item[name].cron) cron = get.cron(item[name].cron.join(' '))
55
+ // Handle rate + cron props
56
+ if (item[name].rate) {
57
+ let itemRate = item[name].rate
58
+ let exp = is.array(itemRate) ? itemRate.join(' ') : itemRate
59
+ rate = get.rate(exp)
60
+ }
61
+ if (item[name].cron) {
62
+ let itemCron = item[name].cron
63
+ let exp = is.array(itemCron) ? itemCron.join(' ') : itemCron
64
+ cron = get.cron(exp)
65
+ }
58
66
 
59
67
  let src = item[name].src
60
68
  ? join(cwd, item[name].src)
@@ -0,0 +1,22 @@
1
+ let { aliases, runtimes, runtimeList } = require('lambda-runtimes')
2
+
3
+ // Runtime interpolater
4
+ module.exports = function getRuntime (config) {
5
+ let { runtime } = config
6
+
7
+ if (runtimeList.includes(runtime) || runtime === 'deno') {
8
+ return config
9
+ }
10
+
11
+ if (typeof runtime === 'string') {
12
+ runtime = runtime.toLowerCase()
13
+
14
+ // Runtime is not actually an AWS value, but a shorthand/aliased name
15
+ if (aliases[runtime]) {
16
+ let aliased = aliases[runtime]
17
+ config.runtime = runtimes[aliased][0]
18
+ config.runtimeAlias = runtime
19
+ }
20
+ }
21
+ return config
22
+ }
@@ -1,4 +1,5 @@
1
1
  let read = require('../../../read')
2
+ let getRuntime = require('./get-runtime')
2
3
  let getHandler = require('./get-handler')
3
4
  let upsert = require('../../_upsert')
4
5
  let is = require('../../../lib/is')
@@ -58,6 +59,9 @@ function populateLambda (type, pragma, inventory, errors) {
58
59
  config = upsert(config, arcConfig.arc)
59
60
  }
60
61
 
62
+ // Interpolate runtimes
63
+ config = getRuntime(config)
64
+
61
65
  // Tidy up any irrelevant params
62
66
  if (type !== 'http') {
63
67
  delete config.apigateway
@@ -5,7 +5,7 @@ module.exports = function collectSourceDirs ({ pragmas, errors }) {
5
5
  let lambdaSrcDirs = []
6
6
  let unsortedBySrcDir = {}
7
7
  Object.entries(pragmas).forEach(([ pragma, values ]) => {
8
- let mayHaveSrcDirs = lambdas.some(p => p === pragma)
8
+ let mayHaveSrcDirs = lambdas.includes(pragma)
9
9
  if (mayHaveSrcDirs && is.array(values)) {
10
10
  pragmas[pragma].forEach(item => {
11
11
  if (item.arcStaticAssetProxy === true) return // Special exception for ASAP
@@ -19,13 +19,13 @@ module.exports = function configureStatic ({ arc, inventory }) {
19
19
 
20
20
  if (is.array(arc.static)) {
21
21
  let disabled = [ false, 'disable', 'disabled' ]
22
- let isDisabled = disabled.some(s => s === arc.static[0])
22
+ let isDisabled = disabled.includes(arc.static[0])
23
23
  if (isDisabled) return false
24
24
  }
25
25
 
26
26
  let settings = Object.entries(_static).map(([ setting ]) => setting)
27
27
  for (let setting of staticPragma) {
28
- let validSetting = key => settings.some(s => s === key)
28
+ let validSetting = key => settings.includes(key)
29
29
  if (setting.ignore) {
30
30
  _static.ignore = setting.ignore
31
31
  }
@@ -3,7 +3,7 @@ module.exports = function validateAWS (aws, errors) {
3
3
 
4
4
  if (apigateway) {
5
5
  let valid = [ 'http', 'httpv1', 'httpv2', 'rest' ]
6
- if (!valid.some(v => v === apigateway)) {
6
+ if (!valid.includes(apigateway)) {
7
7
  errors.push(`API type must be 'http[v1|v2]', or 'rest'`)
8
8
  }
9
9
  }
@@ -5,7 +5,7 @@ module.exports = function validateHTTP (http, errors) {
5
5
  unique(http, '@http routes', errors)
6
6
 
7
7
  let methods = [ 'get', 'post', 'put', 'patch', 'delete', 'options', 'head', 'any' ]
8
- let validMethod = str => methods.some(m => m === str.toLowerCase())
8
+ let validMethod = str => methods.includes(str.toLowerCase())
9
9
  let validPath = str => str.match(/^\/[a-zA-Z0-9/\-:._\*]*$/)
10
10
  http.forEach(route => {
11
11
  let { name, method, path } = route
@@ -80,15 +80,15 @@ function validateRate (schedule, errors) {
80
80
  return expErr(`rate interval must be 'minute', 'minutes', 'hour', 'hours', 'day', or 'days'`, interval)
81
81
  }
82
82
  // Interval must be use the singular/plural values above
83
- if (!singular.concat(plural).some(i => i === interval)) {
83
+ if (!singular.concat(plural).includes(interval)) {
84
84
  expErr(`rate interval must be 'minute', 'minutes', 'hour', 'hours', 'day', or 'days'`, interval)
85
85
  }
86
86
  // Value of 1 must use singular interval
87
- if (value === 1 && plural.some(i => i === interval)) {
87
+ if (value === 1 && plural.includes(interval)) {
88
88
  expErr(`rate value of 1 must use a singular interval, e.g. 'minute', 'hour', 'day'`, interval)
89
89
  }
90
90
  // Value >1 must use plural interval
91
- if (value > 1 && singular.some(i => i === interval)) {
91
+ if (value > 1 && singular.includes(interval)) {
92
92
  expErr(`rate values greater than 1 must use plural intervals, e.g. 'minutes', 'hours', 'days'`, interval)
93
93
  }
94
94
  }
@@ -5,7 +5,7 @@ module.exports = function createDefaultFunctionConfig () {
5
5
  return {
6
6
  timeout: 5,
7
7
  memory: 1152,
8
- runtime: 'nodejs14.x', // TODO add runtime validation
8
+ runtime: 'nodejs14.x',
9
9
  architecture: 'x86_64', // TODO [BREAKING]: default to 'arm64'
10
10
  handler: 'index.handler',
11
11
  state: 'n/a',
@@ -1,3 +1,4 @@
1
+ let runtimes = require('./runtimes')
1
2
  let layers = require('./layers')
2
3
  let tablesChildren = require('./tables-children')
3
4
  let errorFmt = require('../lib/error-fmt')
@@ -12,6 +13,9 @@ module.exports = function finalValidation (params, inventory) {
12
13
  * Deal with vendor configuration errors
13
14
  */
14
15
 
16
+ // Blow up on any non-matching runtimes
17
+ runtimes(params, inventory, errors)
18
+
15
19
  // Ensure layer configuration will work, AWS blows up with awful errors on this
16
20
  layers(params, inventory, errors)
17
21
 
@@ -24,7 +24,7 @@ module.exports = function layerValidator (params, inventory, errors) {
24
24
  let layers = item.layers
25
25
  validateLayer({ layers, region, location })
26
26
  }
27
- else if (lambdas.some(p => p === i) && item) {
27
+ else if (lambdas.includes(i) && item) {
28
28
  item.forEach(entry => {
29
29
  // Probably unnecessary if no configFile is present but why not, let's be extra safe
30
30
  let location = entry.configFile && entry.configFile.replace(cwd, '')
@@ -0,0 +1,28 @@
1
+ let { lambdas } = require('../lib/pragmas')
2
+ let { aliases, runtimeList } = require('lambda-runtimes')
3
+
4
+ /**
5
+ * Runtime validator
6
+ */
7
+ module.exports = function runtimeValidator (params, inventory, errors) {
8
+
9
+ let allRuntimes = runtimeList.concat([ 'deno' ])
10
+ let globalRuntime = inventory.aws?.runtime
11
+ if (globalRuntime &&
12
+ !allRuntimes.includes(globalRuntime) &&
13
+ !aliases[globalRuntime]) {
14
+ errors.push(`Invalid project-level runtime: ${globalRuntime}`)
15
+ }
16
+
17
+ // Walk the tree of layer configs, starting with @aws
18
+ lambdas.forEach(p => {
19
+ let pragma = inventory[p]
20
+ if (pragma) pragma.forEach(entry => {
21
+ let runtime = entry.config.runtime
22
+ if (runtime === globalRuntime) return
23
+ if (!allRuntimes.includes(runtime)) {
24
+ errors.push(`Invalid runtime: ${runtime} (@${p} ${entry.name})`)
25
+ }
26
+ })
27
+ })
28
+ }