@bifravst/aws-cdk-lambda-helpers 1.2.5 → 1.2.6

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/README.md CHANGED
@@ -11,4 +11,12 @@ Helper functions which simplify working with TypeScript lambdas for AWS CDK.
11
11
 
12
12
  ## Installation
13
13
 
14
- npm i --save --save-exact @bifravst/aws-cdk-lambda-helpers
14
+ npm i --save-dev --save-exact @bifravst/aws-cdk-lambda-helpers
15
+
16
+ ## Usage
17
+
18
+ See [the end-to-end test stack](./cdk/e2e.ts).
19
+
20
+ ## Example migrations to `@bifravst/aws-cdk-lambda-helpers`
21
+
22
+ - [world.thingy.rocks backend](https://github.com/NordicPlayground/thingy-rocks-cloud-aws-js/commit/3ca6e267917db4d8cb09ca63ed54384c0e23f163)
@@ -8,8 +8,12 @@ import os from 'node:os';
8
8
  const tmpDir = os.tmpdir();
9
9
  void describe('packLambda()', () => {
10
10
  // See https://github.com/aws/aws-lambda-nodejs-runtime-interface-client/issues/93#issuecomment-2042201321
11
- void it('should fail if it imports from a folder that has the same name as the handler module', async () => assert.rejects(async () => packLambda({
12
- sourceFile: path.join(dirname(fileURLToPath(import.meta.url)), 'test-data', 'module-folder-named-like-handler-bug', 'acme.ts'),
11
+ void it('should fail if it imports from a folder on the same level that has the same name as the handler module', async () => assert.rejects(async () => packLambda({
12
+ sourceFile: path.join(dirname(fileURLToPath(import.meta.url)), 'test-data', 'module-folder-named-like-handler-bug', 'same-level', 'acme.ts'),
13
13
  zipFile: path.join(await fs.mkdtemp(`${tmpDir}${path.sep}`), 'acme.zip'),
14
14
  }), ImportFromFolderNameError));
15
+ void it('should not fail if it a folder with the same name is on a different level', async () => assert.doesNotReject(async () => packLambda({
16
+ sourceFile: path.join(dirname(fileURLToPath(import.meta.url)), 'test-data', 'module-folder-named-like-handler-bug', 'different-level', 'lambda', 'acme.ts'),
17
+ zipFile: path.join(await fs.mkdtemp(`${tmpDir}${path.sep}`), 'acme.zip'),
18
+ })));
15
19
  });
@@ -27,11 +27,18 @@ export const packLambda = async ({ sourceFile, zipFile, debug, progress, }) => {
27
27
  const zipfile = new yazl.ZipFile();
28
28
  const stripCommon = removeCommonAncestor(commonParent(lambdaFiles));
29
29
  const handler = stripCommon(sourceFile);
30
- const folderNames = new Set(deps.map(stripCommon).map((s) => s.split('/')[0]));
31
- const handlerName = path.parse(handler).name;
32
- if (folderNames.has(handlerName)) {
30
+ // Make sure that the handler does not import from a folder with the same name in the folder
31
+ const handlerInfo = path.parse(handler);
32
+ const handlerName = handlerInfo.name;
33
+ const handlerDir = handlerInfo.dir;
34
+ const handlerDepsFromSameDirectory = deps
35
+ .map(stripCommon)
36
+ .filter((d) => handlerDir === '' ? true : d.startsWith(`${handlerDir}${path.sep}`));
37
+ const handlerDepsFolderNames = new Set(handlerDepsFromSameDirectory.map((s) => s.split('/')[0]));
38
+ if (handlerDepsFolderNames.has(handlerName)) {
33
39
  throw new ImportFromFolderNameError(handlerName);
34
40
  }
41
+ // Compile files
35
42
  for (const file of lambdaFiles) {
36
43
  const compiled = (await swc.transformFile(file, {
37
44
  jsc: {
@@ -0,0 +1,2 @@
1
+ import { hello } from '../acme/lib.js';
2
+ export const handler = () => hello();
@@ -0,0 +1 @@
1
+ export declare const hello: () => string;
@@ -0,0 +1 @@
1
+ export const hello = () => 'Hello World!';
@@ -0,0 +1 @@
1
+ export declare const handler: () => string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bifravst/aws-cdk-lambda-helpers",
3
- "version": "1.2.5",
3
+ "version": "1.2.6",
4
4
  "description": "Helper functions which simplify working with TypeScript lambdas for AWS CDK.",
5
5
  "exports": {
6
6
  ".": {