@beesolve/cdk-constructs 0.1.9 → 0.1.12

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.
package/dist/index.d.ts CHANGED
@@ -198,19 +198,19 @@ import { NodejsFunctionProps } from "aws-cdk-lib/aws-lambda-nodejs";
198
198
  import { LogGroupProps } from "aws-cdk-lib/aws-logs";
199
199
  import { Construct as Construct3 } from "constructs";
200
200
  type Nodejs24FunctionProps = Omit<NodejsFunctionProps, "runtime" | "architecture" | "logGroup" | "entry" | "handler" | "code" | "bundling" | "awsSdkConnectionReuse"> & {
201
- entry: `${string}.ts`;
202
- logGroupProps?: LogGroupProps;
203
- loggingFormat?: LoggingFormat;
204
- runtime?: typeof Runtime.NODEJS_24_X;
205
- architecture?: typeof Architecture.ARM_64;
206
- handler?: string;
201
+ readonly entry: `${string}.ts` | `${string}/`;
202
+ readonly logGroupProps?: LogGroupProps;
203
+ readonly loggingFormat?: LoggingFormat;
204
+ readonly runtime?: typeof Runtime.NODEJS_24_X;
205
+ readonly architecture?: typeof Architecture.ARM_64;
206
+ readonly handler?: string;
207
207
  /**
208
208
  * When function is being built the source maps are bundled without content for better performance.
209
209
  * You should provide revision which is added to the description automatically for easier debugging.
210
210
  *
211
211
  * You can use cached `getRevision()` function which is exported in this file in order to get git commit id.
212
212
  */
213
- revision: string;
213
+ readonly revision: string;
214
214
  };
215
215
  /**
216
216
  * This construct provides easy way of deploying Node.js function with opinionated defaults.
@@ -224,4 +224,14 @@ declare class Nodejs24Function extends Function2 {
224
224
  constructor(scope: Construct3, id: string, props: Nodejs24FunctionProps);
225
225
  }
226
226
  declare function getRevision(enforceGit: boolean): string;
227
- export { getRevision, SqsWithDlqProps, SqsWithDlqLambdaInputProps, SqsWithDlq, Nodejs24FunctionProps, Nodejs24Function, CloudFrontAccessLoggingSettingsProps, CloudFrontAccessLoggingSettings };
227
+ import { Message } from "esbuild";
228
+ interface BuildProps {
229
+ readonly entryPoints: string[];
230
+ readonly outDir: string;
231
+ }
232
+ declare function esmBuild(props: BuildProps): Promise<void>;
233
+ declare function esmBuildSync(props: BuildProps): void;
234
+ declare class BuildError extends Error {
235
+ constructor(messages: Message[]);
236
+ }
237
+ export { getRevision, esmBuildSync, esmBuild, SqsWithDlqProps, SqsWithDlqLambdaInputProps, SqsWithDlq, Nodejs24FunctionProps, Nodejs24Function, CloudFrontAccessLoggingSettingsProps, CloudFrontAccessLoggingSettings, BuildError };
package/dist/index.js CHANGED
@@ -173,18 +173,62 @@ import {
173
173
  LoggingFormat,
174
174
  Runtime
175
175
  } from "aws-cdk-lib/aws-lambda";
176
- import {
177
- Charset
178
- } from "aws-cdk-lib/aws-lambda-nodejs";
179
176
  import {
180
177
  LogGroup,
181
178
  RetentionDays
182
179
  } from "aws-cdk-lib/aws-logs";
183
- import { buildSync } from "esbuild";
184
180
  import { execSync } from "node:child_process";
185
181
  import { resolve } from "node:path";
186
182
  import { cwd } from "node:process";
187
183
 
184
+ // packages/cdk-constructs/src/esbuildBuild.ts
185
+ import { build, buildSync } from "esbuild";
186
+ async function esmBuild(props) {
187
+ const buildResult = await build(toBuildConfig(props));
188
+ if (buildResult.errors.length !== 0) {
189
+ throw new BuildError(buildResult.errors);
190
+ }
191
+ }
192
+ function esmBuildSync(props) {
193
+ const buildResult = buildSync(toBuildConfig(props));
194
+ if (buildResult.errors.length !== 0) {
195
+ throw new BuildError(buildResult.errors);
196
+ }
197
+ }
198
+ function toBuildConfig(props) {
199
+ return {
200
+ entryPoints: props.entryPoints,
201
+ banner: {
202
+ js: `/* CommonJS polyfills */import { fileURLToPath } from 'node:url';import { createRequire } from 'node:module';const __filename = fileURLToPath(import.meta.url);const __dirname = fileURLToPath(new URL('.', import.meta.url));const require = createRequire(import.meta.url);/* end of CommonJS polyfills */`
203
+ },
204
+ charset: "utf8",
205
+ bundle: true,
206
+ external: [],
207
+ format: "esm",
208
+ keepNames: true,
209
+ mainFields: ["module", "main"],
210
+ minify: true,
211
+ sourcemap: "external",
212
+ target: "node24",
213
+ platform: "node",
214
+ resolveExtensions: [".ts", ".js", ".mjs", ".json"],
215
+ legalComments: "none",
216
+ splitting: true,
217
+ treeShaking: true,
218
+ outdir: props.outDir
219
+ };
220
+ }
221
+
222
+ class BuildError extends Error {
223
+ constructor(messages) {
224
+ super(`Couldn't build the code.
225
+
226
+ ${messages.map((message) => message.text).join(`
227
+ `)}`);
228
+ }
229
+ }
230
+
231
+ // packages/cdk-constructs/src/nodejsFunction.ts
188
232
  class Nodejs24Function extends Function {
189
233
  constructor(scope, id, props) {
190
234
  const {
@@ -199,32 +243,15 @@ class Nodejs24Function extends Function {
199
243
  revision = true,
200
244
  ...rest
201
245
  } = props;
202
- const outDir = resolve(`${cwd()}/cdk.out/bundling.${id}.beesolve-nodejs.${Date.now()}`);
203
- const buildResult = buildSync({
204
- entryPoints: [`${cwd()}/${entry}`],
205
- banner: {
206
- js: `/* CommonJS polyfills */import { fileURLToPath } from 'node:url';import { createRequire } from 'node:module';const __filename = fileURLToPath(import.meta.url);const __dirname = fileURLToPath(new URL('.', import.meta.url));const require = createRequire(import.meta.url);/* end of CommonJS polyfills */`
207
- },
208
- charset: Charset.UTF8,
209
- bundle: true,
210
- external: [],
211
- format: "esm",
212
- keepNames: true,
213
- mainFields: ["module", "main"],
214
- minify: true,
215
- sourcemap: "external",
216
- target: "node24",
217
- platform: "node",
218
- resolveExtensions: [".ts", ".js", ".mjs", ".json"],
219
- legalComments: "none",
220
- splitting: true,
221
- treeShaking: true,
222
- outdir: outDir
223
- });
224
- if (buildResult.errors.length !== 0) {
225
- throw new BuildError(buildResult.errors);
246
+ const shouldBuild = entry.endsWith(".ts");
247
+ const outDir = shouldBuild ? resolve(`${cwd()}/cdk.out/bundling.${id}.beesolve-nodejs.${Date.now()}`) : entry;
248
+ if (shouldBuild) {
249
+ esmBuildSync({
250
+ entryPoints: [props.entry],
251
+ outDir
252
+ });
226
253
  }
227
- const fileName = entry.split("/").at(-1)?.replace(".ts", "");
254
+ const fileName = shouldBuild ? entry.split("/").at(-1)?.replace(".ts", "") : "";
228
255
  const handlerName = `${fileName}.${handler ?? "handler"}`;
229
256
  super(scope, id, {
230
257
  ...rest,
@@ -238,15 +265,6 @@ class Nodejs24Function extends Function {
238
265
  });
239
266
  }
240
267
  }
241
-
242
- class BuildError extends Error {
243
- constructor(messages) {
244
- super(`Couldn't build the code.
245
-
246
- ${messages.map((message) => message.text).join(`
247
- `)}`);
248
- }
249
- }
250
268
  var revisionCache;
251
269
  function getRevision(enforceGit) {
252
270
  if (revisionCache == null) {
@@ -282,7 +300,10 @@ class NotAGitRepositoryError extends Error {
282
300
  }
283
301
  export {
284
302
  getRevision,
303
+ esmBuildSync,
304
+ esmBuild,
285
305
  SqsWithDlq,
286
306
  Nodejs24Function,
287
- CloudFrontAccessLoggingSettings
307
+ CloudFrontAccessLoggingSettings,
308
+ BuildError
288
309
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@beesolve/cdk-constructs",
3
- "version": "0.1.9",
3
+ "version": "0.1.12",
4
4
  "description": "",
5
5
  "homepage": "https://github.com/beesolve/packages/tree/main/packages/cdk-constructs#readme",
6
6
  "license": "MIT",