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

fix(lambda-nodejs): fixing esbuildArgs to take in account re-specified keys #29167

Merged
merged 5 commits into from
Mar 8, 2024

Conversation

Vandita2020
Copy link
Contributor

@Vandita2020 Vandita2020 commented Feb 19, 2024

Issue # (if applicable)

Closes #25385

Reason for this change

This PR fixes a bug in CDK where CDK does not take into account re-specified keys while doing bundling. The CLI supports flags in one of three forms: --foo, --foo=bar, or --foo:bar. However, the --foo:bar form was not initially supported.
With --foo:bar, users can now specify flags that have multiple values and can be re-specified multiple times.

Description of changes

The code has a list of keys that can be re-specified multiple times. While assigning the flags it checks whether the key is among the list of re-specified keys, if yes, it specifies the flag with :.

Description of how you validated changes

The PR includes unit test and integration test both to validate the changes.

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 bug This issue is a bug. effort/small Small work item – less than a day of effort p1 beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK labels Feb 19, 2024
@aws-cdk-automation aws-cdk-automation requested a review from a team February 19, 2024 18:53
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.

@@ -245,6 +245,7 @@ test('esbuild bundling with esbuild options', () => {
'--resolve-extensions': '.ts,.js',
'--splitting': true,
'--keep-names': '',
'--out-extension': '.js=.mjs',
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we need this?

Copy link
Contributor Author

@Vandita2020 Vandita2020 Feb 19, 2024

Choose a reason for hiding this comment

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

There is a list of esbuildArgs that uses ':' to assign the flags. Here is the list with all of them. I have added this line to check if the code is working fine. out-extension is one of the fields that uses :

Copy link
Contributor

Choose a reason for hiding this comment

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

so why didn't we add the others here?

Copy link
Contributor Author

@Vandita2020 Vandita2020 Feb 19, 2024

Choose a reason for hiding this comment

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

The reason I chose --out-extension to test the code is because it was the one among the list that could be set without modifying much of the test code or without breaking any existing functionality.

@aws-cdk-automation aws-cdk-automation dismissed their stale review February 19, 2024 21:14

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

@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Feb 19, 2024
@jonife
Copy link
Contributor

jonife commented Feb 19, 2024

Great job on fixing the integration test. However it seems you need to rebase your changes on the latest changes in the main branch.

Also can you change the title to:
fix(lambda-nodejs): fixing esbuildArgs to consider re-specified keys.
Or
fix(lambda-nodejs): fixing Bundling command to take account re-specified keys

This should be clear to the reviewers what problems you are trying to fix.

@Vandita2020 Vandita2020 changed the title fix(lambda-nodejs): fixing esbuildArgs to accept --foo:bar fix(lambda-nodejs): fixing Bundling command to take account re-specified keys Feb 19, 2024
@Vandita2020 Vandita2020 changed the title fix(lambda-nodejs): fixing Bundling command to take account re-specified keys fix(lambda-nodejs): fixing esbuildArgs to take in account re-specified keys Feb 19, 2024
@@ -418,10 +418,13 @@ function toTarget(runtime: Runtime): string {

function toCliArgs(esbuildArgs: { [key: string]: string | boolean }): string {
const args = new Array<string>();
const ls = ['--alias', '--drop', '--pure', '--log-override', '--out-extension'];
Copy link
Contributor

Choose a reason for hiding this comment

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

what does ls stand for here? Should this variable have a better/clearer name?

Also, does it make sense maybe to have this as a top level constant instead of just being a local variable here?
(I'm not sure about this because I'm not familiar with other functionalities or the structure of this file)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have changed the name to reSpecifiedKeys, making it more specific to what the list is about. And I have kept the list inside toCliAgs function as it is being used inside this function only and for other functions too they have their constants declared inside the Function only.

@GavinZZ
Copy link
Contributor

GavinZZ commented Mar 7, 2024

I'm a bit hesitant to approve this PR because I'm not sure if this change will cause a breaking change as technically these new args will come in effect after this PR. And there may be users who used these args in their CDK stack before the PR (and CDK falsely ignore these args, now adding effect to these args cause a behavioural change, although very unlikely).

Will get another team member to review this for a second opinion.

@GavinZZ
Copy link
Contributor

GavinZZ commented Mar 7, 2024

I'm a bit hesitant to approve this PR because I'm not sure if this change will cause a breaking change as technically these new args will come in effect after this PR. And there may be users who used these args in their CDK stack before the PR (and CDK falsely ignore these args, now adding effect to these args cause a behavioural change, although very unlikely).

Will get another team member to review this for a second opinion.

Dismissing my concern, I didn't notice that before the code change, it will cause an error during deployment. Happy to approve.

@GavinZZ
Copy link
Contributor

GavinZZ commented Mar 7, 2024

@mergify update

Copy link
Contributor

mergify bot commented Mar 7, 2024

update

❌ Mergify doesn't have permission to update

For security reasons, Mergify can't update this pull request. Try updating locally.
GitHub response: refusing to allow a GitHub App to create or update workflow .github/workflows/github-merit-badger.yml without workflows permission

Copy link
Contributor

mergify bot commented Mar 8, 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 Mar 8, 2024
Copy link
Contributor

mergify bot commented Mar 8, 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
Copy link
Collaborator

AWS CodeBuild CI Report

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

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

@mergify mergify bot merged commit 919d16f into aws:main Mar 8, 2024
9 checks passed
Copy link
Contributor

mergify bot commented Mar 8, 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
beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK bug This issue is a bug. effort/small Small work item – less than a day of effort p1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

@aws-cdk/aws-lambda-nodejs: esbuildArgs alias must use : instead of =
6 participants