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

@aws-cdk/aws-lambda-nodejs: Esbuild bundling option to disable sourcesContent #17256

Closed
1 of 2 tasks
suds-sky opened this issue Nov 1, 2021 · 2 comments · Fixed by #17280
Closed
1 of 2 tasks

@aws-cdk/aws-lambda-nodejs: Esbuild bundling option to disable sourcesContent #17256

suds-sky opened this issue Nov 1, 2021 · 2 comments · Fixed by #17280
Assignees
Labels
@aws-cdk/aws-lambda-nodejs effort/small Small work item – less than a day of effort feature/enhancement A new API to make things easier or more intuitive. A catch-all for general feature requests. feature-request A feature should be added or improved. good first issue Related to contributions. See CONTRIBUTING.md p1

Comments

@suds-sky
Copy link
Contributor

suds-sky commented Nov 1, 2021

Description

With the NodeJsFunction construct, We have observed that the source code is included as part of the source maps. For production builds, We do not need this as we are not going to debug the lambda.

Use Case

For production lambdas, it is desirable to omit the source code in source maps generated by esbuild through NodeJsFunction construct

Proposed Solution

In esbuild, there is an option we can set to disable this to not to include the source code as per esbuild docs -https://esbuild.github.io/api/#sources-content

We can add a property (sourcesContent) to BundlingOptions type and allow the function to enable/disable the inclusion of sourcesContent into the source map generated.

Other information

No response

Acknowledge

  • I may be able to implement this feature request
  • This feature might incur a breaking change
@suds-sky suds-sky added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Nov 1, 2021
@peterwoodworth peterwoodworth added effort/small Small work item – less than a day of effort p1 good first issue Related to contributions. See CONTRIBUTING.md and removed needs-triage This issue or PR still needs to be triaged. labels Nov 2, 2021
@peterwoodworth
Copy link
Contributor

peterwoodworth commented Nov 2, 2021

Thanks for submitting this issue, contributions are welcome!

I think you know what you need to do if you want to contribute, but I'll share what I've found on a quick look for visibility :)

Like you said, we'll want to add a prop to BundlingOptions

export interface BundlingOptions {

These end up getting passed here

code: Bundling.bundle({
...props.bundling ?? {},
entry,
runtime,
architecture,
depsLockFilePath,
projectRoot,
}),

And ultimately I think we'll want to add something here

const esbuildCommand: string[] = [
options.esbuildRunner,
'--bundle', `"${pathJoin(options.inputDir, relativeEntryPath)}"`,
`--target=${this.props.target ?? toTarget(this.props.runtime)}`,
'--platform=node',
`--outfile="${pathJoin(options.outputDir, 'index.js')}"`,
...this.props.minify ? ['--minify'] : [],
...sourceMapEnabled ? [`--sourcemap${sourceMapValue}`] : [],
...this.externals.map(external => `--external:${external}`),
...loaders.map(([ext, name]) => `--loader:${ext}=${name}`),
...defines.map(([key, value]) => `--define:${key}=${JSON.stringify(value)}`),
...this.props.logLevel ? [`--log-level=${this.props.logLevel}`] : [],
...this.props.keepNames ? ['--keep-names'] : [],
...this.relativeTsconfigPath ? [`--tsconfig=${pathJoin(options.inputDir, this.relativeTsconfigPath)}`] : [],
...this.props.metafile ? [`--metafile=${pathJoin(options.outputDir, 'index.meta.json')}`] : [],
...this.props.banner ? [`--banner:js=${JSON.stringify(this.props.banner)}`] : [],
...this.props.footer ? [`--footer:js=${JSON.stringify(this.props.footer)}`] : [],
...this.props.charset ? [`--charset=${this.props.charset}`] : [],
];

@peterwoodworth peterwoodworth added the feature/enhancement A new API to make things easier or more intuitive. A catch-all for general feature requests. label Nov 2, 2021
@mergify mergify bot closed this as completed in #17280 Nov 4, 2021
mergify bot pushed a commit that referenced this issue Nov 4, 2021
Support excluding sourcesContent from `esbuild` generated source map 

Closes #17256

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@github-actions
Copy link

github-actions bot commented Nov 4, 2021

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

TikiTDO pushed a commit to TikiTDO/aws-cdk that referenced this issue Feb 21, 2022
Support excluding sourcesContent from `esbuild` generated source map 

Closes aws#17256

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-lambda-nodejs effort/small Small work item – less than a day of effort feature/enhancement A new API to make things easier or more intuitive. A catch-all for general feature requests. feature-request A feature should be added or improved. good first issue Related to contributions. See CONTRIBUTING.md p1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants