aws / aws-lambda-builders

Python library to compile, build & package AWS Lambda functions for several runtimes & framework
Apache License 2.0
333 stars 137 forks source link

Bug: SourcesContent has no effect when is set to false #605

Closed Grmiade closed 6 months ago

Grmiade commented 7 months ago

Description:

When we configure BuildProperties.SourcesContent to false, the setting has no effect on the generated bundle. See this documentation: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-using-build-typescript.html#serverless-sam-cli-using-build-typescript-example

Steps to reproduce:

Set BuildProperties.Sourcemap to true and BuildProperties.SourcesContent to false. The sourcesContent field is visible on the generated source map.

Observed result:

2024-01-06 22:11:18,238 | Configuring the parameter 'minify=False'                                                                                                      
2024-01-06 22:11:18,238 | Configuring the parameter 'target=es2020'                                                                                                     
2024-01-06 22:11:18,238 | Configuring the parameter 'sources_content=False'                                                                                             
2024-01-06 22:11:18,239 | Configuring the parameter 'sourcemap=True'                                    
2024-01-06 22:11:18,239 | Found the following args in the config: ['--target=es2020', '--sources-content=false', '--sourcemap'] 

IMO The issue is coming from this function: https://github.com/aws/aws-lambda-builders/blob/d21f0d501a6903065bc426ff1cd97e2f6234ddce/aws_lambda_builders/workflows/nodejs_npm_esbuild/esbuild.py#L182-L196 Since SourcesContent is enabled by default, we need to set the option to false to disable it, but the code ignores the boolean options when they are set to false.

Expected result:

The sourcesContent field should not be visible on the generated source map.

Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

  1. OS: MacOS Sonoma
  2. If using SAM CLI, sam --version: 1.106.0
Grmiade commented 7 months ago

BTW I found a workaround by setting the SourcesContent property to 'false' (as a string).

mildaniel commented 7 months ago

Hi @Grmiade, thanks for reporting this issue. Using the string form here is actually expected since this is part of the 'single value` esbuild API as defined in their documentation https://esbuild.github.io/api/ and how it's used here https://esbuild.github.io/api/#sources-content

Grmiade commented 7 months ago

@mildaniel So we should probably update the documentation https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-using-build-typescript.html#serverless-sam-cli-using-build-typescript-example. What do you think?

mildaniel commented 6 months ago

Thanks for pointing this out and you're absolutely right, we should update those docs.

mildaniel commented 6 months ago

Documentation updates have been made, resolving.