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): add bun support #31770

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

blimmer
Copy link
Contributor

@blimmer blimmer commented Oct 15, 2024

Issue #31753

Closes #31753.

Reason for this change

bun is rapidly gaining popularity because it's extremely performant compared to node. bun has its own lockfile, bun.lockb, which is not currently respected by AWS CDK when bundling NodejsFunctions.

Description of changes

This code is very well-structured, so it was simple to add bun support alongside yarn, pnpm and npm.

Description of how you validated changes

I linked this code up to a simple, sample CDK app with a bun lockfile. I wasn't able to bun cdk synth before my changes. Then, after linking up my local workspace, I was able to bundle with my bun lockfile.

I also added unit tests similar to those that exist for the other packages managers.

Checklist


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

@github-actions github-actions bot added effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2 labels Oct 15, 2024
@aws-cdk-automation aws-cdk-automation requested a review from a team October 15, 2024 22:56
@github-actions github-actions bot added the admired-contributor [Pilot] contributed between 13-24 PRs to the CDK label Oct 15, 2024
@blimmer blimmer force-pushed the add-bun-nodejs-function-support branch from a9e0a4e to 8308ec9 Compare October 15, 2024 22:57
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.

A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed add Clarification Request to a comment.

# Ensure all users can write to bun cache
RUN mkdir /tmp/bun-cache && \
chmod -R 777 /tmp/bun-cache && \
echo -e "[install.cache]\ndir = \"/tmp/bun-cache\"" >> /home/user/.bunfig.toml
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no bun config set --global command for this cache location. The best place to set this is in the global user homedir according to the docs.

Therefore, this cache statement needs to happen after useradd is called, not above where the other caches are configured. If it's called before, even if I create /home/user, useradd overwrites it.

@blimmer
Copy link
Contributor Author

blimmer commented Oct 15, 2024

Exemption Request - I'm following the patterns of existing PRs to add package managers, so I don't feel I need to add an integration test.

@blimmer blimmer marked this pull request as ready for review October 15, 2024 23:00
@aws-cdk-automation aws-cdk-automation added the pr-linter/exemption-requested The contributor has requested an exemption to the PR Linter feedback. label Oct 15, 2024
@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Oct 15, 2024
@blimmer
Copy link
Contributor Author

blimmer commented Oct 26, 2024

@khushail - could I get a review on this? thanks in advance

@khushail
Copy link
Contributor

@blimmer , thanks for your contribution. I see this PR has label pr/needs-community-review so it would be great to reach out to CDK Community to get it approved first by the trusted community reviewers and afterwards, the core team should be able to review it. hope that would be helpful!

@suds-sky
Copy link
Contributor

Hi @blimmer Great work on picking this up. We are also in need of this. It hasn't been moved for 3 weeks. Do you need any helping hand to proceed with this or it is waiting to find a community member to take a look

@blimmer
Copy link
Contributor Author

blimmer commented Nov 18, 2024

Hey @suds-sky - this is awaiting community review. From my perspective it's good to go!

@suds-sky
Copy link
Contributor

Hey @suds-sky - this is awaiting community review. From my perspective it's good to go!

Looks like the checks are failing, may be the reason community member is waiting for. There is CDK community Slack, may be we can reach there to get some help 🤔

@blimmer
Copy link
Contributor Author

blimmer commented Nov 18, 2024

The failing checks are because I didn't add an integration test. None of the other supported package managers add an integration test, so I felt I didn't need to add one for bun. I've requested an exemption. This is ready for review.

@blimmer
Copy link
Contributor Author

blimmer commented Nov 18, 2024

Exemption Request - I'm following the patterns of existing PRs to add package managers, so I don't feel I need to add an integration test.

Copy link

codecov bot commented Nov 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 78.42%. Comparing base (6931632) to head (e44ae4f).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #31770      +/-   ##
==========================================
+ Coverage   78.41%   78.42%   +0.01%     
==========================================
  Files         106      106              
  Lines        7208     7208              
  Branches     1323     1323              
==========================================
+ Hits         5652     5653       +1     
+ Misses       1369     1368       -1     
  Partials      187      187              
Flag Coverage Δ
suite.unit 78.42% <ø> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
packages/aws-cdk 78.42% <ø> (+0.01%) ⬆️

@badmintoncryer
Copy link
Contributor

@blimmer Thank you for your great work! I really want to use this feature.
I think it is better to create integ test and snapshots files because this is a new feature PR.

If you have any problem for that, please feel free to contact me.

@blimmer blimmer force-pushed the add-bun-nodejs-function-support branch from 22bcd2a to 4f3a72c Compare November 25, 2024 16:19
@blimmer
Copy link
Contributor Author

blimmer commented Nov 25, 2024

Thanks for the nudge. I missed that PNPM actually did have an integration test. I added one for bun (and fixed errors found in the integration test 😅). This is ready for review.

@aws-cdk-automation aws-cdk-automation dismissed their stale review November 25, 2024 16:21

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

@blimmer
Copy link
Contributor Author

blimmer commented Nov 25, 2024

The CodeQL failure is in the generated integration test code, so I think it's a false positive.

@badmintoncryer
Copy link
Contributor

@blimmer Thank you for your update. I'll check it later. Please wait for a while.

Copy link
Contributor

@badmintoncryer badmintoncryer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have only a question.

// Will be installed, not bundled
// (axios is a package with sub-dependencies,
// will be used to ensure bun bundling works as expected)
nodeModules: ['axios'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please let me know: If axios is not listed in bun.lockb, will specifying it in nodeModules still ensure it is installed and works correctly?

If that is the case, I think it would be better to run an integration test to ensure that a Lambda function using modules listed only in bun.lockb works correctly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what's also done in the PNPM integration test:

// Will be installed, not bundled
// (axios is a package with sub-dependencies,
// will be used to ensure pnpm bundling works as expected)
nodeModules: ['axios'],

Axios is listed in bun.lockb, but specifying it in nodeModules installs it using bun inside the docker container (docs). I verified that the sub-dependencies (locked by bun.lockb) were installed properly.

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: e44ae4f
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

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

Copy link
Contributor

@badmintoncryer badmintoncryer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I'm sorry for my late response.

@aws-cdk-automation aws-cdk-automation added pr/needs-maintainer-review This PR needs a review from a Core Team Member and removed pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. labels Dec 2, 2024
Copy link
Contributor

@GavinZZ GavinZZ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love it! Thanks for adding support for bun.

Copy link
Contributor

mergify bot commented Dec 4, 2024

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation aws-cdk-automation removed the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Dec 4, 2024
Copy link
Contributor

mergify bot commented Dec 4, 2024

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
admired-contributor [Pilot] contributed between 13-24 PRs to the CDK effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2 pr-linter/exemption-requested The contributor has requested an exemption to the PR Linter feedback.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(aws-lambda-nodejs): Support bun lockfiles for NodejsFunction bundling
6 participants