Skip to content

Commit 1df19cc

Browse files
committed
fix(esbuild): use precise es version target for a runtime
fix #3
1 parent b33be2f commit 1df19cc

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ node_modules
44
dist
55
*.log
66
package-lock.json
7+
coverage

src/function.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ import { mergeRight, union, without } from 'ramda';
66

77
import { packExternalModules } from './pack-externals';
88
import { NodejsFunctionProps } from './props';
9-
import { extractFileName, findProjectRoot, nodeMajorVersion } from './utils';
9+
import { extractFileName, findProjectRoot, NodeMajorESMap, nodeMajorVersion } from './utils';
1010

1111
const BUILD_FOLDER = '.build';
1212
const DEFAULT_BUILD_OPTIONS: es.BuildOptions = {
1313
bundle: true,
14-
target: 'es2017',
14+
target: NodeMajorESMap[nodeMajorVersion()],
1515
};
1616

1717
/**
@@ -33,10 +33,10 @@ export class NodejsFunction extends lambda.Function {
3333
const exclude = union(props.exclude || [], ['aws-sdk']);
3434
const packager = props.packager ?? true;
3535
const handler = props.handler ?? 'index.handler';
36-
const defaultRunTime = nodeMajorVersion() >= 12
36+
const defaultRuntime = nodeMajorVersion() >= 12
3737
? lambda.Runtime.NODEJS_12_X
3838
: lambda.Runtime.NODEJS_10_X;
39-
const runtime = props.runtime ?? defaultRunTime;
39+
const runtime = props.runtime ?? defaultRuntime;
4040
const entry = extractFileName(projectRoot, handler);
4141

4242
es.buildSync({

src/props.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,17 @@ export interface NodejsFunctionProps extends lambda.FunctionOptions {
5050
/**
5151
* The esbuild bundler specific options.
5252
*
53-
* @default = { bundle: true, target: 'es2017' }
53+
* @default = NodeMajorESMap {
54+
* 8 : 'es2016'
55+
* 9 : 'es2017'
56+
* 10: 'es2018'
57+
* 11: 'es2018'
58+
* 12: 'es2019'
59+
* 13: 'es2019'
60+
* 14: 'es2020'
61+
* 15: 'es2020'
62+
* >=16: 'esnext'
63+
* };
5464
*/
5565
readonly esbuildOptions?: BuildOptions;
5666
}

src/utils.ts

+12
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,18 @@ export function nodeMajorVersion(): number {
105105
return parseInt(process.versions.node.split('.')[0], 10);
106106
}
107107

108+
export const NodeMajorESMap = {
109+
8: 'es2016',
110+
9: 'es2017',
111+
10: 'es2018',
112+
11: 'es2018',
113+
12: 'es2019',
114+
13: 'es2019',
115+
14: 'es2020',
116+
15: 'es2020',
117+
16: 'esnext',
118+
};
119+
108120
/**
109121
* Returns the package manager currently active if the program is executed
110122
* through an npm or yarn script like:

0 commit comments

Comments
 (0)