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): esbuild charset option #16726

Merged
merged 5 commits into from
Oct 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/@aws-cdk/aws-lambda-nodejs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,9 @@ new lambda.NodejsFunction(this, 'my-handler', {
keepNames: true, // defaults to false
tsconfig: 'custom-tsconfig.json', // use custom-tsconfig.json instead of default,
metafile: true, // include meta file, defaults to false
banner : '/* comments */', // requires esbuild >= 0.9.0, defaults to none
footer : '/* comments */', // requires esbuild >= 0.9.0, defaults to none
banner: '/* comments */', // requires esbuild >= 0.9.0, defaults to none
footer: '/* comments */', // requires esbuild >= 0.9.0, defaults to none
charset: Charset.UTF8, // do not escape non-ASCII characters, defaults to Charset.ASCII
},
});
```
Expand Down
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-lambda-nodejs/lib/bundling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ export class Bundling implements cdk.BundlingOptions {
...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}`] : [],
];

let depsCommand = '';
Expand Down
38 changes: 35 additions & 3 deletions packages/@aws-cdk/aws-lambda-nodejs/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export interface BundlingOptions {
* bundle buddy can consume esbuild's metadata format and generates a treemap visualization
* of the modules in your bundle and how much space each one takes up.
* @see https://esbuild.github.io/api/#metafile
* @default - false
* @default false
*/
readonly metafile?: boolean

Expand All @@ -124,7 +124,7 @@ export interface BundlingOptions {
*
* This is commonly used to insert comments:
*
* @default - no comments are passed
* @default - no comments are passed
*/
readonly banner? : string

Expand All @@ -135,10 +135,23 @@ export interface BundlingOptions {
*
* This is commonly used to insert comments
*
* @default - no comments are passed
* @default - no comments are passed
*/
readonly footer? : string

/**
* The charset to use for esbuild's output.
*
* By default esbuild's output is ASCII-only. Any non-ASCII characters are escaped
* using backslash escape sequences. Using escape sequences makes the generated output
* slightly bigger, and also makes it harder to read. If you would like for esbuild to print
* the original characters without using escape sequences, use `Charset.UTF8`.
*
* @see https://esbuild.github.io/api/#charset
* @default Charset.ASCII
*/
readonly charset?: Charset;

/**
* Environment variables defined when bundling runs.
*
Expand Down Expand Up @@ -310,3 +323,22 @@ export enum SourceMapMode {
*/
BOTH = 'both'
}

/**
* Charset for esbuild's output
*/
export enum Charset {
/**
* ASCII
*
* Any non-ASCII characters are escaped using backslash escape sequences
*/
ASCII = 'ascii',

/**
* UTF-8
*
* Keep original characters without using escape sequences
*/
UTF8 = 'utf8'
}
4 changes: 3 additions & 1 deletion packages/@aws-cdk/aws-lambda-nodejs/test/bundling.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { AssetHashType, DockerImage } from '@aws-cdk/core';
import { version as delayVersion } from 'delay/package.json';
import { Bundling } from '../lib/bundling';
import { PackageInstallation } from '../lib/package-installation';
import { LogLevel, SourceMapMode } from '../lib/types';
import { Charset, LogLevel, SourceMapMode } from '../lib/types';
import * as util from '../lib/util';


Expand Down Expand Up @@ -198,6 +198,7 @@ test('esbuild bundling with esbuild options', () => {
metafile: true,
banner: '/* comments */',
footer: '/* comments */',
charset: Charset.UTF8,
forceDockerBundling: true,
define: {
'process.env.KEY': JSON.stringify('VALUE'),
Expand All @@ -221,6 +222,7 @@ test('esbuild bundling with esbuild options', () => {
defineInstructions,
'--log-level=silent --keep-names --tsconfig=/asset-input/lib/custom-tsconfig.ts',
'--metafile=/asset-output/index.meta.json --banner:js="/* comments */" --footer:js="/* comments */"',
'--charset=utf8',
].join(' '),
],
}),
Expand Down