cdk-booster 1.1.0-alpha.2 → 1.1.0-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -53,7 +53,9 @@ async function run() {
53
53
  compileCodeFile,
54
54
  });
55
55
  Logger.verbose(`Found ${lambdas.length} Lambda functions in the CDK code:`, JSON.stringify(lambdas, null, 2));
56
- const lambdasEsBuildCommands = lambdas;
56
+ let lambdasEsBuildCommands = lambdas;
57
+ // skip all lambdas that have SKIP_CDK_BOOSTER env var set to true in their bundling environment
58
+ lambdasEsBuildCommands = lambdasEsBuildCommands.filter((lambda) => lambda.environment?.SKIP_CDK_BOOSTER !== 'true');
57
59
  // Prepare bundling temp folders for each Lambda function
58
60
  await recreateBundlingTempFolders(lambdasEsBuildCommands);
59
61
  // Execute pre-bundling commands
@@ -97,9 +99,10 @@ async function bundle(lambdasEsBuildCommands) {
97
99
  for (const buildBatch of buildBatches) {
98
100
  const build = async () => {
99
101
  parallelCount++;
102
+ let context;
103
+ const buildOptions = buildBatch.buildOptions;
104
+ const entryPoints = buildBatch.entryPoints;
100
105
  try {
101
- const buildOptions = buildBatch.buildOptions;
102
- const entryPoints = buildBatch.entryPoints;
103
106
  const normalizedEsbuildArgs = normalizeEsbuildArgs(buildOptions.esbuildArgs);
104
107
  const esBuildOpt = {
105
108
  entryPoints,
@@ -136,13 +139,52 @@ async function bundle(lambdasEsBuildCommands) {
136
139
  else {
137
140
  Logger.log(`Bundling:\n - ${entryPoints.join('\n - ')}`);
138
141
  }
139
- const buildingResults = await esbuild.build(esBuildOpt);
142
+ // Create esbuild context for this build batch
143
+ context = await esbuild.context(esBuildOpt);
144
+ let buildingResults;
145
+ try {
146
+ // Perform the build using the context
147
+ buildingResults = await context.rebuild();
148
+ }
149
+ catch (err) {
150
+ Logger.log(`Error creating esbuild context.`, err);
151
+ // Esbuild’s child process was stopped; recreate the context once.
152
+ if (String(err?.message || err).includes('The service was stopped') &&
153
+ context) {
154
+ Logger.log(`Retrying bundling.`);
155
+ try {
156
+ await context.dispose();
157
+ }
158
+ catch {
159
+ // ignore
160
+ }
161
+ try {
162
+ context = await esbuild.context(esBuildOpt);
163
+ buildingResults = await context.rebuild();
164
+ Logger.log(`Retry successful.`);
165
+ }
166
+ catch (err) {
167
+ Logger.log(`Retry failed.`, err);
168
+ throw err;
169
+ }
170
+ }
171
+ else {
172
+ throw err;
173
+ }
174
+ }
140
175
  outputs = {
141
176
  ...outputs,
142
177
  ...buildingResults.metafile?.outputs,
143
178
  };
144
179
  }
180
+ catch (error) {
181
+ Logger.error(`The following functions failed to bundle:\n - ${entryPoints.join('\n - ')}. Set batch parameter (-b) to a smaller number, like 5, to lower the chance of this error, and in case of error, a smaller batch would be affected.`, error);
182
+ }
145
183
  finally {
184
+ // Always dispose of the context to free resources
185
+ if (context) {
186
+ await context.dispose();
187
+ }
146
188
  parallelCount--;
147
189
  }
148
190
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cdk-booster",
3
- "version": "1.1.0-alpha.2",
3
+ "version": "1.1.0-alpha.3",
4
4
  "type": "module",
5
5
  "description": "Speed up AWS CDK's bundling of TypeScript/JavaScript Lambda handlers",
6
6
  "homepage": "https://www.cdkbooster.com",