Skip to content
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

feat(lambda-nodejs) experimental decorators support #15631

Conversation

whimzyLive
Copy link
Contributor

@whimzyLive whimzyLive commented Jul 18, 2021

Desciption

esBuild doesn't support emitting typescript metadata which break workflow of many popular libraries that relies on such runtime metadata information. i.e Nestjs, TypeORM. TypeDORM.
Since this is an experimental feature, ESBuild doen't have any immidiate plan to support it.

Typescript's default tsc compiler does support this and other experimental features. Therefore, This PR adds support for typescript's experimental features by optionally executing tsc on the soruces before passing it through to esBuild for bundling.

For more information, look at the issue #13767

Tasks

  • initial experimental features support
  • update public apis to include new properties
  • ensure bundling happens within the asset bundling-temp-x locations
  • update docker bundling to optionally install typescript as the same version used by host (currently always installs typescript@latest)
  • add test coverage for both local and docker bundling
  • update readme with usage

closes #13767


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@gitpod-io
Copy link

gitpod-io bot commented Jul 18, 2021

@mergify
Copy link
Contributor

mergify bot commented Jul 18, 2021

Title does not follow the guidelines of Conventional Commits. Please adjust title before merge.

@whimzyLive whimzyLive changed the title Feature/13767 aws lambda nodejs experimental decorators support feat(aws-lambda-nodejs) experimental decorators support Jul 18, 2021
@whimzyLive whimzyLive marked this pull request as draft July 18, 2021 11:16
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject89A8053A-LhjRyN9kxr8o
  • Commit ID: 565df81
  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@whimzyLive
Copy link
Contributor Author

This is basically everything that I think is needed to support tsc -> esbuild workflow, but there are some changes that are required in order for it to work correctly with the assets caching/staging logic. I will look into it a bit more next weekend, meanwhile if anyone is looking for a quick patch, @ me here, and I will send over the patch file, or you can extract it directly from the changes above.

@jogold
Copy link
Contributor

jogold commented Jul 20, 2021

@whimzyLive thank you for this PR. I will have more time to review it in August (or maybe someone from the CDK team will review it before).

Question: when working with the AWS CDK in TypeScript you usually have a tsc step that runs during your build (locally and in CI) and it compiles your Lambda handlers files. If you specify the resulting .js file as entry for your NodejsFunction then you already have a working solution/workaround?

@whimzyLive
Copy link
Contributor Author

@jogold No worries, I still have some work to do around the assets' temp-bundling is managed so August is fine.

Question: when working with the AWS CDK in TypeScript you usually have a tsc step that runs during your build (locally and in CI) and it compiles your Lambda handlers files. If you specify the resulting .js file as an entry for your NodejsFunction then you already have a working solution/workaround?

The answer to this question is Yes and No.

In a normal dev workflow, this is statement stands corrected but we are working with a monorepo consisting of many CDK/Ts apps and because of many unrelated issues (i.e slowness), we have decided to completely remove the ts -> js compilation step from all dev steps (and let the tools do it implicitly). Speaking of which, for testing, we use ts-jest preset; for local running/debugging, there is ts-node (to transpile to js on the fly, in memory), and we use NodejsFunctions to take care of compiling, bundling, and minifying, which worked really well until recently, when NodejsFunction was updated to use esBuild instead of the parcel. So basically these changes allow us to continue offloading compiling responsibilities to NodejsFunction and we can continue working in the same manner we used to. Hope this makes sense, and also sorry for the long answer but I didn't know how to explain otherwise. 🙂️

@eladb eladb changed the title feat(aws-lambda-nodejs) experimental decorators support feat(lambda-nodejs) experimental decorators support Jul 20, 2021
@nija-at nija-at added effort/medium Medium work item – several days of effort p2 labels Aug 24, 2021
@nija-at nija-at removed their assignment Aug 24, 2021
@rix0rrr rix0rrr added feature-request A feature should be added or improved. p1 and removed p2 effort/medium Medium work item – several days of effort @aws-cdk/aws-lambda-nodejs labels Mar 4, 2022
@TheRealAmazonKendra
Copy link
Contributor

This PR has been deemed to be abandoned, and will be closed. Please create a new PR for these changes if you think this decision has been made in error.

@meg2208
Copy link

meg2208 commented Oct 19, 2022

Just want to confirm... lambda-nodejs does not support decorators, right? So if I'm using a library that uses them like typedi or typeorm, then would it be best to use a docker image?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request A feature should be added or improved. p1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(aws-lambda-nodejs): esbuild does not support emitting typescript decorator metadata
8 participants