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 7 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.67%. Comparing base (0ce71fc) to head (f43ae10).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #31770      +/-   ##
==========================================
+ Coverage   78.66%   78.67%   +0.01%     
==========================================
  Files         107      107              
  Lines        7237     7237              
  Branches     1329     1329              
==========================================
+ Hits         5693     5694       +1     
+ Misses       1358     1357       -1     
  Partials      186      186              
Flag Coverage Δ
suite.unit 78.67% <0.00%> (+0.01%) ⬆️

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

Components Coverage Δ
packages/aws-cdk 78.67% <ø> (+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.

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).

Copy link
Contributor

mergify bot commented Dec 5, 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).

mergify bot pushed a commit to blimmer/aws-cdk that referenced this pull request Dec 5, 2024
### Issue aws#31753

Closes aws#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 `NodejsFunction`s.

### 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
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
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.

Copy link
Contributor

mergify bot commented Dec 5, 2024

This pull request has been removed from the queue for the following reason: pull request dequeued.

Pull request #31770 has been dequeued, merge conditions unmatch:

  • #changes-requested-reviews-by = 0 [🛡 GitHub branch protection]
  • #changes-requested-reviews-by=0
  • status-success=validate-pr
  • status-success~=AWS CodeBuild us-east-1
  • any of [🛡 GitHub branch protection]:
    • check-neutral = AWS CodeBuild us-east-1 (AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv)
    • check-skipped = AWS CodeBuild us-east-1 (AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv)
    • check-success = AWS CodeBuild us-east-1 (AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv)
  • any of [🛡 GitHub branch protection]:
    • check-neutral = validate-pr
    • check-skipped = validate-pr
    • check-success = validate-pr
  • any of [🛡 GitHub branch protection]:
    • check-neutral = codecov/patch
    • check-skipped = codecov/patch
    • check-success = codecov/patch
  • any of [🛡 GitHub branch protection]:
    • check-neutral = codecov/patch/packages/aws-cdk
    • check-skipped = codecov/patch/packages/aws-cdk
    • check-success = codecov/patch/packages/aws-cdk
  • any of [🛡 GitHub branch protection]:
    • check-neutral = codecov/project
    • check-skipped = codecov/project
    • check-success = codecov/project
  • any of [🛡 GitHub branch protection]:
    • check-neutral = codecov/project/packages/aws-cdk
    • check-skipped = codecov/project/packages/aws-cdk
    • check-success = codecov/project/packages/aws-cdk
  • #approved-reviews-by >= 1 [🛡 GitHub branch protection]
  • #approved-reviews-by>=1
  • -approved-reviews-by~=author
  • -closed
  • -label~=(blocked|do-not-merge|no-squash)
  • -merged
  • -title~=(WIP|wip)
  • base!=release.

You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it.

If you want to requeue this pull request, you need to post a comment with the text: @mergifyio requeue

@aws-cdk-automation
Copy link
Collaborator

The pull request linter fails with the following errors:

❌ Features must contain a change to a README file.
❌ Features must contain a change to a test file.
❌ Features must contain a change to an integration test file and the resulting snapshot.

PRs must pass status checks before we can provide a meaningful review.

If you would like to request an exemption from the status checks or clarification on feedback, please leave a comment on this PR containing Exemption Request and/or Clarification Request.

✅ A exemption request has been requested. Please wait for a maintainer's review.

@blimmer
Copy link
Contributor Author

blimmer commented Dec 5, 2024

@GavinZZ - any ideas what happened here? It's show 0 files changed... Seems like mergify messed something up.

@blimmer
Copy link
Contributor Author

blimmer commented Dec 5, 2024

Oh, bizarre ... it merged but somehow lost being linked up with this PR? aed8ad1

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

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

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

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