@bifravst/aws-cdk-lambda-helpers 1.2.3 → 1.2.4
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/lambdas/test.zip +0 -0
- package/dist/layers/baseLayer/nodejs/package-lock.json +8 -8
- package/dist/layers/baseLayer.zip +0 -0
- package/dist/src/module-folder-named-like-handler-bug.spec.d.ts +1 -0
- package/dist/src/module-folder-named-like-handler-bug.spec.js +15 -0
- package/dist/src/packLambda.d.ts +7 -0
- package/dist/src/packLambda.js +20 -1
- package/dist/src/test-data/module-folder-named-like-handler-bug/acme/lib.d.ts +1 -0
- package/dist/src/test-data/module-folder-named-like-handler-bug/acme/lib.js +1 -0
- package/dist/src/test-data/module-folder-named-like-handler-bug/acme.d.ts +1 -0
- package/dist/src/test-data/module-folder-named-like-handler-bug/acme.js +2 -0
- package/package.json +3 -3
package/dist/lambdas/test.zip
CHANGED
Binary file
|
@@ -16,7 +16,7 @@
|
|
16
16
|
},
|
17
17
|
"devDependencies": {
|
18
18
|
"@aws-sdk/client-cloudformation": "3.549.0",
|
19
|
-
"@bifravst/eslint-config-typescript": "6.0.
|
19
|
+
"@bifravst/eslint-config-typescript": "6.0.20",
|
20
20
|
"@bifravst/prettier-config": "1.0.0",
|
21
21
|
"@commitlint/config-conventional": "19.1.0",
|
22
22
|
"@nordicsemiconductor/cloudformation-helpers": "^9.0.3",
|
@@ -34,7 +34,7 @@
|
|
34
34
|
"npm": ">=9"
|
35
35
|
},
|
36
36
|
"peerDependencies": {
|
37
|
-
"aws-cdk-lib": "^2.
|
37
|
+
"aws-cdk-lib": "^2.136.0",
|
38
38
|
"constructs": "^10.3.0"
|
39
39
|
}
|
40
40
|
},
|
@@ -745,9 +745,9 @@
|
|
745
745
|
}
|
746
746
|
},
|
747
747
|
"node_modules/@bifravst/eslint-config-typescript": {
|
748
|
-
"version": "6.0.
|
749
|
-
"resolved": "https://registry.npmjs.org/@bifravst/eslint-config-typescript/-/eslint-config-typescript-6.0.
|
750
|
-
"integrity": "sha512-
|
748
|
+
"version": "6.0.20",
|
749
|
+
"resolved": "https://registry.npmjs.org/@bifravst/eslint-config-typescript/-/eslint-config-typescript-6.0.20.tgz",
|
750
|
+
"integrity": "sha512-yaaBpMQPtcN0WbEloCg5tWPICoE7VnD0Cg+KpeZAk2FCXm6I/svvRtmeIvnQPq5BOvCN5eqV9DO+7Z6bg+4PLA==",
|
751
751
|
"dev": true,
|
752
752
|
"dependencies": {
|
753
753
|
"@eslint/js": "8.57.0",
|
@@ -2653,9 +2653,9 @@
|
|
2653
2653
|
}
|
2654
2654
|
},
|
2655
2655
|
"node_modules/aws-cdk-lib": {
|
2656
|
-
"version": "2.
|
2657
|
-
"resolved": "https://registry.npmjs.org/aws-cdk-lib/-/aws-cdk-lib-2.
|
2658
|
-
"integrity": "sha512-
|
2656
|
+
"version": "2.136.0",
|
2657
|
+
"resolved": "https://registry.npmjs.org/aws-cdk-lib/-/aws-cdk-lib-2.136.0.tgz",
|
2658
|
+
"integrity": "sha512-zdkWNe91mvZH6ESghUoIxB8ORoreExg2wowTLEVfy3vWY1a6n69crxk8mkCG+vn6GhXEnEPpovoG1QV8BpXTpA==",
|
2659
2659
|
"bundleDependencies": [
|
2660
2660
|
"@balena/dockerignore",
|
2661
2661
|
"case",
|
Binary file
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import assert from 'node:assert/strict';
|
2
|
+
import { it, describe } from 'node:test';
|
3
|
+
import { ImportFromFolderNameError, packLambda } from './packLambda.js';
|
4
|
+
import path, { dirname } from 'node:path';
|
5
|
+
import { fileURLToPath } from 'node:url';
|
6
|
+
import fs from 'node:fs/promises';
|
7
|
+
import os from 'node:os';
|
8
|
+
const tmpDir = os.tmpdir();
|
9
|
+
void describe('packLambda()', () => {
|
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'),
|
13
|
+
zipFile: path.join(await fs.mkdtemp(`${tmpDir}${path.sep}`), 'acme.zip'),
|
14
|
+
}), ImportFromFolderNameError));
|
15
|
+
});
|
package/dist/src/packLambda.d.ts
CHANGED
@@ -16,3 +16,10 @@ export declare const packLambda: ({ sourceFile, zipFile, debug, progress, }: {
|
|
16
16
|
handler: string;
|
17
17
|
hash: string;
|
18
18
|
}>;
|
19
|
+
/**
|
20
|
+
* @see https://github.com/aws/aws-lambda-nodejs-runtime-interface-client/issues/93#issuecomment-2042201321
|
21
|
+
*/
|
22
|
+
export declare class ImportFromFolderNameError extends Error {
|
23
|
+
readonly folderName: string;
|
24
|
+
constructor(folderName: string);
|
25
|
+
}
|
package/dist/src/packLambda.js
CHANGED
@@ -6,6 +6,7 @@ import { checkSumOfFiles } from './checksumOfFiles.js';
|
|
6
6
|
import { commonParent } from './commonParent.js';
|
7
7
|
import { findDependencies } from './findDependencies.js';
|
8
8
|
import { fileURLToPath } from 'node:url';
|
9
|
+
import path from 'node:path';
|
9
10
|
const removeCommonAncestor = (parentDir) => (file) => {
|
10
11
|
const p = parse(file);
|
11
12
|
const jsFileName = [
|
@@ -21,9 +22,16 @@ const removeCommonAncestor = (parentDir) => (file) => {
|
|
21
22
|
* In the bundle we only include code that's not in the layer.
|
22
23
|
*/
|
23
24
|
export const packLambda = async ({ sourceFile, zipFile, debug, progress, }) => {
|
24
|
-
const
|
25
|
+
const deps = findDependencies(sourceFile);
|
26
|
+
const lambdaFiles = [sourceFile, ...deps];
|
25
27
|
const zipfile = new yazl.ZipFile();
|
26
28
|
const stripCommon = removeCommonAncestor(commonParent(lambdaFiles));
|
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)) {
|
33
|
+
throw new ImportFromFolderNameError(handlerName);
|
34
|
+
}
|
27
35
|
for (const file of lambdaFiles) {
|
28
36
|
const compiled = (await swc.transformFile(file, {
|
29
37
|
jsc: {
|
@@ -54,3 +62,14 @@ export const packLambda = async ({ sourceFile, zipFile, debug, progress, }) => {
|
|
54
62
|
progress?.(`written`, zipFile);
|
55
63
|
return { handler: stripCommon(sourceFile), hash };
|
56
64
|
};
|
65
|
+
/**
|
66
|
+
* @see https://github.com/aws/aws-lambda-nodejs-runtime-interface-client/issues/93#issuecomment-2042201321
|
67
|
+
*/
|
68
|
+
export class ImportFromFolderNameError extends Error {
|
69
|
+
folderName;
|
70
|
+
constructor(folderName) {
|
71
|
+
super(`Import from folder with same name as handler ("${folderName}") not allowed!`);
|
72
|
+
this.name = 'ImportFromFolderNameError';
|
73
|
+
this.folderName = folderName;
|
74
|
+
}
|
75
|
+
}
|
@@ -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.
|
3
|
+
"version": "1.2.4",
|
4
4
|
"description": "Helper functions which simplify working with TypeScript lambdas for AWS CDK.",
|
5
5
|
"exports": {
|
6
6
|
".": {
|
@@ -52,7 +52,7 @@
|
|
52
52
|
"license": "BSD-3-Clause",
|
53
53
|
"devDependencies": {
|
54
54
|
"@aws-sdk/client-cloudformation": "3.549.0",
|
55
|
-
"@bifravst/eslint-config-typescript": "6.0.
|
55
|
+
"@bifravst/eslint-config-typescript": "6.0.20",
|
56
56
|
"@bifravst/prettier-config": "1.0.0",
|
57
57
|
"@commitlint/config-conventional": "19.1.0",
|
58
58
|
"@nordicsemiconductor/cloudformation-helpers": "^9.0.3",
|
@@ -117,7 +117,7 @@
|
|
117
117
|
"yazl": "2.5.1"
|
118
118
|
},
|
119
119
|
"peerDependencies": {
|
120
|
-
"aws-cdk-lib": "^2.
|
120
|
+
"aws-cdk-lib": "^2.136.0",
|
121
121
|
"constructs": "^10.3.0"
|
122
122
|
}
|
123
123
|
}
|