-
Notifications
You must be signed in to change notification settings - Fork 36
ESM modules support #282
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ESM modules support #282
Conversation
Codecov Report
@@ Coverage Diff @@
## main #282 +/- ##
==========================================
- Coverage 82.43% 80.68% -1.75%
==========================================
Files 37 37
Lines 1662 1698 +36
Branches 364 378 +14
==========================================
Hits 1370 1370
- Misses 240 276 +36
Partials 52 52
📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't find anything immediately wrong with it. I'd say as long as it's tested well LGTM 👍
Closing this, we are going to use another approach that doesn't involve using deasync |
What does this PR do?
Adds support for ESM modules and top level async await support with the lambda layer.
JS files with a '.mjs' extension, or with a package.json containing 'type':'module' field, will be imported as ESM modules..
ESM modules look like this:
VS CommonJS
Motivation
This is a supported feature of Lambda, that we are catching up to.
Testing Guidelines
I've added an integration test for the .mjs use case. II have tested manually for ARM for now.
Additional Notes
We upgraded the handler wrapper script to use a dynamic imports for mjs modules, (node will throw an error if you try to use require).
Dynamic imports look like this:
We need a way to depromisify the handler library. Usually this is done be turning the calling function into an async function, and awaiting the result. However, this will be reflected all the way up the call hierachy, until we get to our root function, where we still have a promise.
The solution is to use the library deasync. This is a native library, (written in C), that needs to be compiled to use each CPU Architecture, and hooks more directly into the Node runtime. Unfortunately, deasync doesn't come with a prebuilt version of the library for linux-arm64, so we added a script to our build process that will create this. We also strip out other pre-built versions of deasync, since they would add > 6mb to the layer size.
Types of Changes
Check all that apply