Skip to content

Conversation

@lucashuy
Copy link
Contributor

@lucashuy lucashuy commented Jul 15, 2022

Related to lambda builders change: aws/aws-lambda-builders#375

Why is this change necessary?

Previously, both Sourcemap: true and NODE_OPTIONS: --enable-source-maps needed to be provided to enable source map usage. This is redundant since explicitly defining one would imply source map usage.

How does it address the issue?

This change allows users to specify either NODE_OPTIONS: --enable-source-maps under environment variables or Sourcemap: true under esbuild build properties and have source maps enabled and added to their functions.

NODE_OPTIONS can be defined at either the Globals level or the Function level.

What side effects does this change have?

This change will modify the final template file in sam build by adding either Sourcemap or NODE_OPTIONS at the function level.

Mandatory Checklist

PRs will only be reviewed after checklist is complete

  • Add input/output type hints to new functions/methods
  • Write design document if needed (Do I need to write a design document?)
  • Write/update unit tests
  • Write/update integration tests
  • Write/update functional tests if needed
  • make pr passes
  • make update-reproducible-reqs if dependencies were changed
  • Write documentation

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 pr/external stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. area/build sam build command labels Jul 15, 2022
@lucashuy lucashuy marked this pull request as ready for review July 19, 2022 20:47
@lucashuy lucashuy requested a review from mildaniel July 20, 2022 20:05
@lucashuy lucashuy marked this pull request as draft July 21, 2022 17:25
@lucashuy lucashuy marked this pull request as ready for review July 21, 2022 23:11
@qingchm qingchm removed maintainer/need-followup stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. labels Jul 25, 2022
build_properties = metadata.get("BuildProperties", {})
source_map = build_properties.get("Sourcemap", None)

if source_map and not node_option_set:
Copy link
Contributor

Choose a reason for hiding this comment

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

Based on the logic here it doesn't seem to have special handling to the scenario where node_option_set is true and the build_properties.get("Sourcemap") is an explicit value False, which I feel we might want to handle differently from it being None? Open to any reason for this self conflict input should not be a concern

Copy link
Contributor Author

@lucashuy lucashuy Jul 25, 2022

Choose a reason for hiding this comment

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

Yup, you're correct that it does not handle the case where NODE_OPTIONS is set and Sourcemap is false. In this case, no source map is generated, so the environment variable to enable source maps will not do anything even though it is set. The only potential concern the performance hit with source maps, I'm not quite sure if the performance is degraded with a source map file, or if its just solely by using the enable source map environment variable.

Copy link
Contributor

Choose a reason for hiding this comment

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

Unsure of the performance concerns here, but to @qingchm 's question is there a change in behavior from before this PR and after? If there is a conflict, we can raise that as LOG warning that there is a conflict.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(not @qingchm answering) Before this PR, setting Sourcemaps to false would effectively disable source map usage since no map file is generated, even if the env variable was provided, this was expected behaviour. The behaviour remains the same after the PR. The Sourcemap: false option is basically just a way to opt out of source maps if it was defined at the Global level.

@sriram-mv sriram-mv self-requested a review July 26, 2022 19:06
@lucashuy
Copy link
Contributor Author

Currently blocked awaiting further discussion/planning.

@lucashuy lucashuy marked this pull request as draft July 27, 2022 16:45
@lucashuy lucashuy marked this pull request as ready for review August 3, 2022 17:43
@staticmethod
def _warn_using_source_maps():
click.secho(
"\nYou are using source maps, note that this comes with a performance hit!"
Copy link
Contributor

Choose a reason for hiding this comment

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

If they try to remove just the env var it will still be set next time if the source maps are still set in the metadata, right? Should we clarify that it needs to be removed from both spots?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice catch, I'll update it to reflect this change

source_map = build_properties.get("Sourcemap", None)

if source_map and not node_option_set:
LOG.debug(
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we're mutating the customer template, I think it's more appropriate to make this an info level log.

@lucashuy lucashuy enabled auto-merge (squash) August 3, 2022 20:36
@lucashuy lucashuy merged commit 7f6d71c into aws:develop Aug 3, 2022
torresxb1 pushed a commit to torresxb1/aws-sam-cli that referenced this pull request Sep 2, 2022
…-maps is provided (aws#4062)

* Added support to only specific Sourcemap or NODE_OPTIONS to enable source map usage

* Added unit tests

* Added warning message about improper NODE_OPTIONS usage

* Fixed enabling source maps too late

* Added missing space in string join

* Improved clarity in enable source map function

* Changed wording of variable from 'incorrect' to 'invalid'

* Fixed comments and make pr

* Adding missing newline

* Changed warning message to make it clear they need to remove both options

* Improved log message to include function name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants