Skip to content

Commit

Permalink
feat: add support for serverless v4 and typescript (#1806)
Browse files Browse the repository at this point in the history
* feat: add support for serverless v4 and typescript

* ci: fix unit tests with new serverless version

* test: remove tests for deprecated plugins

* test: fix serverless path

* test: add typescript module test

* feat: add support for python 3.12

* chore: remove docker-serverless test

* test: restore plugin tests with serverless esbuild disabled

* chore: move docker-in-docker folder

* ci: fix tests on windows

* ci: add timeout for jobs

* ci: fix teardown

* fix: use wpathToFileURL to fix windows imports

* test: move teardown to afterEach function

* test: fill empty test descriptions
  • Loading branch information
DorianMazur authored Jul 31, 2024
1 parent 31afde0 commit b983ceb
Show file tree
Hide file tree
Showing 60 changed files with 32,821 additions and 93,532 deletions.
3 changes: 1 addition & 2 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
/coverage
/src/lambda/handler-runner/in-process-runner/aws-lambda-ric/UserFunction.js
/coverage
3 changes: 2 additions & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ on:
env:
FORCE_COLOR: 1
PRINT_OFFLINE_OUTPUT: 1
SERVERLESS_ACCESS_KEY: ${{ secrets.SERVERLESS_ACCESS_KEY }}

jobs:
build:
name: "[${{ matrix.os }}] node.js v${{ matrix.node-version }}"
runs-on: ${{ matrix.os }}

timeout-minutes: 40
strategy:
fail-fast: false
matrix:
Expand Down
15,733 changes: 5,632 additions & 10,101 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@
"luxon": "^3.4.4",
"node-schedule": "^2.1.1",
"p-memoize": "^7.1.1",
"tree-kill": "^1.2.2",
"tsx": "^4.16.2",
"velocityjs": "^2.0.6",
"ws": "^8.18.0"
},
Expand All @@ -113,9 +115,9 @@
"mocha": "^10.6.0",
"nyc": "^17.0.0",
"prettier": "^3.3.2",
"serverless": "^3.39.0"
"serverless": "^4.1.18"
},
"peerDependencies": {
"serverless": "^3.2.0"
"serverless": "^4.0.0"
}
}
1 change: 1 addition & 0 deletions src/config/supportedRuntimes.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export const supportedPython = new Set([
"python3.9",
"python3.10",
"python3.11",
"python3.12",
])

// RUBY
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* eslint-disable max-classes-per-file */
/**
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* This code was copied from:
* https://github.com/aws/aws-lambda-nodejs-runtime-interface-client/blob/main/src/Errors.js
*
* Defines custom error types throwable by the runtime.
*/

"use strict"

const errorClasses = [
class ImportModuleError extends Error {},
class HandlerNotFound extends Error {},
class MalformedHandlerName extends Error {},
class UserCodeSyntaxError extends Error {},
class MalformedStreamingHandler extends Error {},
class InvalidStreamingOperation extends Error {},
class UnhandledPromiseRejection extends Error {
constructor(reason, promise) {
super(reason)
this.reason = reason
this.promise = promise
}
},
]

errorClasses.forEach((e) => {
module.exports[e.name] = e
e.prototype.name = `Runtime.${e.name}`
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/* eslint-disable no-underscore-dangle */
/* eslint-disable no-param-reassign */
/**
* Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* This code was copied from:
* https://github.com/aws/aws-lambda-nodejs-runtime-interface-client/blob/main/src/HttpResponseStream.js
*
* HttpResponseStream is NOT used by the runtime.
* It is only exposed in the `awslambda` variable for customers to use.
*/

"use strict"

const METADATA_PRELUDE_CONTENT_TYPE =
"application/vnd.awslambda.http-integration-response"
const DELIMITER_LEN = 8

// Implements the application/vnd.awslambda.http-integration-response content type.
class HttpResponseStream {
static from(underlyingStream, prelude) {
underlyingStream.setContentType(METADATA_PRELUDE_CONTENT_TYPE)

// JSON.stringify is required. NULL byte is not allowed in metadataPrelude.
const metadataPrelude = JSON.stringify(prelude)

underlyingStream._onBeforeFirstWrite = (write) => {
write(metadataPrelude)

// Write 8 null bytes after the JSON prelude.
write(new Uint8Array(DELIMITER_LEN))
}

return underlyingStream
}
}

module.exports.HttpResponseStream = HttpResponseStream
Loading

0 comments on commit b983ceb

Please sign in to comment.