node-lambda 1.2.1 → 1.3.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.
@@ -29,7 +29,7 @@ jobs:
29
29
 
30
30
  # Initializes the CodeQL tools for scanning.
31
31
  - name: Initialize CodeQL
32
- uses: github/codeql-action/init@v2
32
+ uses: github/codeql-action/init@v3
33
33
  with:
34
34
  languages: ${{ matrix.language }}
35
35
  # If you wish to specify custom queries, you can do so here or in a config file.
@@ -40,7 +40,7 @@ jobs:
40
40
  # Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
41
41
  # If this step fails, then you should remove it and run the build manually (see below)
42
42
  - name: Autobuild
43
- uses: github/codeql-action/autobuild@v2
43
+ uses: github/codeql-action/autobuild@v3
44
44
 
45
45
  # ℹ️ Command-line programs to run using the OS shell.
46
46
  # 📚 https://git.io/JvXDl
@@ -54,4 +54,4 @@ jobs:
54
54
  # make release
55
55
 
56
56
  - name: Perform CodeQL Analysis
57
- uses: github/codeql-action/analyze@v2
57
+ uses: github/codeql-action/analyze@v3
package/CHANGELOG.md CHANGED
@@ -480,3 +480,11 @@ This project adheres to [Semantic Versioning](http://semver.org/).
480
480
  - Improve testing
481
481
  - Update dependencies
482
482
  - Update README
483
+
484
+ ## [1.3.0] - 2024-01-04
485
+ ### Features
486
+ - Support .mjs [#701](https://github.com/motdotla/node-lambda/pull/701)
487
+ - Update lambda runtime list [#702](https://github.com/motdotla/node-lambda/pull/702)
488
+
489
+ ### Minor changes
490
+ - Update dependencies
package/README.md CHANGED
@@ -230,7 +230,7 @@ AWS Lambda will let you set environment variables for your function. Use the sam
230
230
 
231
231
  ## Node.js Runtime Configuration
232
232
 
233
- AWS Lambda now supports Node.js 18, Node.js 16 and Node.js 14. Please also check the [Lambda runtimes](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html) page.
233
+ AWS Lambda now supports Node.js 20, Node.js 18 and Node.js 16. Please also check the [Lambda runtimes](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html) page.
234
234
 
235
235
  ## Use S3 to deploy
236
236
 
package/index_mjs.mjs ADDED
@@ -0,0 +1,9 @@
1
+ // For development/testing purposes
2
+ export const handler = (event, context, callback) => {
3
+ console.log('Running index.handler (mjs)')
4
+ console.log('==================================')
5
+ console.log('event', event)
6
+ console.log('==================================')
7
+ console.log('Stopping index.handler (mjs)')
8
+ callback(null)
9
+ }
package/lib/.env.example CHANGED
@@ -10,7 +10,7 @@ AWS_HANDLER=index.handler
10
10
  AWS_MEMORY_SIZE=128
11
11
  AWS_TIMEOUT=3
12
12
  AWS_DESCRIPTION=
13
- AWS_RUNTIME=nodejs18.x
13
+ AWS_RUNTIME=nodejs20.x
14
14
  AWS_VPC_SUBNETS=
15
15
  AWS_VPC_SECURITY_GROUPS=
16
16
  AWS_TRACING_CONFIG=
package/lib/main.js CHANGED
@@ -52,14 +52,25 @@ event_sources.json and ${program.eventFile} files as needed.`)
52
52
  }
53
53
 
54
54
  async run (program) {
55
- if (!['nodejs14.x', 'nodejs16.x', 'nodejs18.x'].includes(program.runtime)) {
55
+ if (!['nodejs16.x', 'nodejs18.x', 'nodejs20.x'].includes(program.runtime)) {
56
56
  console.error(`Runtime [${program.runtime}] is not supported.`)
57
57
  process.exit(254)
58
58
  }
59
59
 
60
60
  this._createSampleFile(program.eventFile, 'event.json')
61
61
  const splitHandler = program.handler.split('.')
62
- const filename = splitHandler[0] + '.js'
62
+ const filename = (() => {
63
+ for (const extension of ['.js', '.mjs']) {
64
+ if (fs.existsSync(splitHandler[0] + extension)) {
65
+ return splitHandler[0] + extension
66
+ }
67
+ }
68
+ })()
69
+ if (filename == null) {
70
+ console.error('Handler file not found.')
71
+ process.exitCode = 255
72
+ return
73
+ }
63
74
  const handlername = splitHandler[1]
64
75
 
65
76
  // Set custom environment variables if program.configFile is defined
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-lambda",
3
- "version": "1.2.1",
3
+ "version": "1.3.0",
4
4
  "description": "Command line tool for locally running and remotely deploying your node.js applications to Amazon Lambda.",
5
5
  "main": "lib/main.js",
6
6
  "directories": {
package/test/main.js CHANGED
@@ -23,7 +23,7 @@ const originalProgram = {
23
23
  memorySize: 128,
24
24
  timeout: 3,
25
25
  description: '',
26
- runtime: 'nodejs18.x',
26
+ runtime: 'nodejs20.x',
27
27
  deadLetterConfigTargetArn: '',
28
28
  tracingConfig: '',
29
29
  Layers: '',
@@ -160,7 +160,7 @@ describe('lib/main', function () {
160
160
  })
161
161
 
162
162
  it('version should be set', () => {
163
- assert.equal(lambda.version, '1.2.1')
163
+ assert.equal(lambda.version, '1.3.0')
164
164
  })
165
165
 
166
166
  describe('_codeDirectory', () => {
@@ -157,7 +157,7 @@ describe('bin/node-lambda', () => {
157
157
  process.env.AWS_RUNTIME = 'test'
158
158
  })
159
159
  after(() => {
160
- process.env.AWS_RUNTIME = 'nodejs18.x'
160
+ process.env.AWS_RUNTIME = 'nodejs20.x'
161
161
  })
162
162
 
163
163
  it('`node-lambda run` exitCode is `254` (callback(null))', (done) => {
@@ -171,14 +171,14 @@ describe('bin/node-lambda', () => {
171
171
  })
172
172
  })
173
173
 
174
- describe('node-lambda run (Runtime nodejs18.x is supported)', () => {
174
+ describe('node-lambda run (Runtime nodejs20.x is supported)', () => {
175
175
  const eventObj = {
176
176
  asyncTest: false,
177
177
  callbackWaitsForEmptyEventLoop: true // True is the default value of Lambda
178
178
  }
179
179
 
180
180
  before(() => {
181
- process.env.AWS_RUNTIME = 'nodejs18.x'
181
+ process.env.AWS_RUNTIME = 'nodejs20.x'
182
182
  })
183
183
 
184
184
  it('`node-lambda run` exitCode is not `254` (callback(null))', (done) => {
@@ -189,7 +189,7 @@ describe('bin/node-lambda', () => {
189
189
  })
190
190
  })
191
191
 
192
- describe('node-lambda run (Multiple events))', () => {
192
+ describe('node-lambda run (Multiple events)', () => {
193
193
  const eventObj = [{
194
194
  asyncTest: false,
195
195
  callbackWaitsForEmptyEventLoop: true,
@@ -217,7 +217,7 @@ describe('bin/node-lambda', () => {
217
217
  })
218
218
  })
219
219
 
220
- describe('node-lambda run (disable Multiple events))', () => {
220
+ describe('node-lambda run (disable Multiple events)', () => {
221
221
  const eventObj = [{
222
222
  asyncTest: false,
223
223
  callbackWaitsForEmptyEventLoop: true,
@@ -264,7 +264,7 @@ describe('bin/node-lambda', () => {
264
264
  })
265
265
  })
266
266
 
267
- describe('node-lambda run (API Gateway events))', () => {
267
+ describe('node-lambda run (API Gateway events)', () => {
268
268
  const eventObj = {
269
269
  asyncTest: false,
270
270
  callbackWaitsForEmptyEventLoop: true,
@@ -295,6 +295,54 @@ describe('bin/node-lambda', () => {
295
295
  })
296
296
  })
297
297
  })
298
+
299
+ describe('node-lambda run (by *.mjs)', () => {
300
+ it('`node-lambda run` by index.mjs', function (done) {
301
+ const run = spawn('node', [
302
+ nodeLambdaPath, 'run',
303
+ '--handler', 'index_mjs.handler'
304
+ ])
305
+ let stdoutString = ''
306
+ run.stdout.on('data', (data) => {
307
+ stdoutString += data.toString().replace(/\r|\n|\s/g, '')
308
+ })
309
+
310
+ run.on('exit', (code) => {
311
+ const expected = 'Runningindex.handler(mjs)' +
312
+ '==================================' +
313
+ 'event{asyncTest:false,callbackWaitsForEmptyEventLoop:true,callbackCode:\'callback(null);\'}' +
314
+ '==================================' +
315
+ 'Stoppingindex.handler(mjs)Success:'
316
+ assert.equal(stdoutString, expected)
317
+ assert.equal(code, 0)
318
+ done()
319
+ })
320
+ })
321
+ })
322
+
323
+ describe('node-lambda run (handler file not found)', () => {
324
+ it('`node-lambda run` Invalid handler specification.', function (done) {
325
+ const run = spawn('node', [
326
+ nodeLambdaPath, 'run',
327
+ '--handler', 'not_found.handler'
328
+ ])
329
+ let stdoutString = ''
330
+ run.stdout.on('data', (data) => {
331
+ stdoutString += data.toString().replace(/\r|\n|\s/g, '')
332
+ })
333
+ let stderrString = ''
334
+ run.stderr.on('data', (data) => {
335
+ stderrString += data.toString()
336
+ })
337
+
338
+ run.on('exit', (code) => {
339
+ assert.equal(stdoutString, '')
340
+ assert.match(stderrString, /Handler file not found\./)
341
+ assert.equal(code, 255)
342
+ done()
343
+ })
344
+ })
345
+ })
298
346
  })
299
347
 
300
348
  describe('node-lambda duplicate check of short option', () => {