@architect/inventory 3.2.2 → 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 CHANGED
@@ -2,6 +2,14 @@
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
+
5
13
  ## [3.2.2] 2022-08-20
6
14
 
7
15
  ### Changed
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@architect/inventory",
3
- "version": "3.2.2",
3
+ "version": "3.3.0-RC.0",
4
4
  "description": "Architect project resource enumeration utility",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -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.x+ Lambda releases use the same CJS/ESM pattern
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 = 'js' } = findHandler(nodeHandlers, src)
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
- handlerModuleSystem = getModSystem(pkg)
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
- }