@bifravst/aws-cdk-lambda-helpers 2.2.1 → 2.2.2
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.
@@ -9,9 +9,13 @@ export const findDependencies = (args) => {
|
|
9
9
|
const visited = args.visited ?? [];
|
10
10
|
const dependencies = args.imports ?? [];
|
11
11
|
const packages = args.packages ?? new Set();
|
12
|
-
|
12
|
+
const importsSubpathPatterns = args.importsSubpathPatterns ?? {};
|
13
13
|
if (visited.includes(sourceFilePath))
|
14
|
-
return {
|
14
|
+
return {
|
15
|
+
dependencies,
|
16
|
+
importsSubpathPatterns,
|
17
|
+
packages,
|
18
|
+
};
|
15
19
|
const tsConfigFilePath = args.tsConfigFilePath;
|
16
20
|
const tsConfig = tsConfigFilePath !== undefined
|
17
21
|
? JSON.parse(readFileSync(tsConfigFilePath, 'utf-8').toString())
|
@@ -23,14 +27,13 @@ export const findDependencies = (args) => {
|
|
23
27
|
node.kind !== ts.SyntaxKind.ExportDeclaration)
|
24
28
|
return;
|
25
29
|
const moduleSpecifier = node.moduleSpecifier.text;
|
26
|
-
const { resolvedPath: file
|
30
|
+
const { resolvedPath: file } = resolve({
|
27
31
|
moduleSpecifier,
|
28
32
|
sourceFilePath,
|
29
33
|
tsConfigFilePath,
|
30
34
|
tsConfig,
|
31
35
|
importsSubpathPatterns,
|
32
36
|
});
|
33
|
-
importsSubpathPatterns = updatedImportsSubpathPatterns;
|
34
37
|
try {
|
35
38
|
const s = statSync(file);
|
36
39
|
if (!s.isDirectory())
|
@@ -54,7 +57,25 @@ export const findDependencies = (args) => {
|
|
54
57
|
packages,
|
55
58
|
});
|
56
59
|
}
|
57
|
-
return {
|
60
|
+
return {
|
61
|
+
dependencies,
|
62
|
+
importsSubpathPatterns,
|
63
|
+
packages: new Set([
|
64
|
+
...packages.difference(new Set([
|
65
|
+
'aws-lambda', // Ignore type-only package
|
66
|
+
])),
|
67
|
+
]
|
68
|
+
.filter((p) => !p.startsWith('node:'))
|
69
|
+
.filter((p) => !p.startsWith('@aws-crypto/'))
|
70
|
+
.filter((p) => !p.startsWith('@aws-sdk/'))
|
71
|
+
.map((d) => {
|
72
|
+
if (d.startsWith('@')) {
|
73
|
+
const [org, packageName] = d.split('/');
|
74
|
+
return `${org}/${packageName}`;
|
75
|
+
}
|
76
|
+
return d.split('/')[0];
|
77
|
+
})),
|
78
|
+
};
|
58
79
|
};
|
59
80
|
const resolve = ({ moduleSpecifier, sourceFilePath, tsConfigFilePath, tsConfig, importsSubpathPatterns, }) => {
|
60
81
|
if (moduleSpecifier.startsWith('.'))
|
@@ -67,7 +88,6 @@ const resolve = ({ moduleSpecifier, sourceFilePath, tsConfigFilePath, tsConfig,
|
|
67
88
|
// Example: import { Network, notifyClients } from './notifyClients.js'
|
68
89
|
// The source file for that is actually in './notifyClients.ts'
|
69
90
|
.replace(/\.js$/, '.ts'),
|
70
|
-
importsSubpathPatterns,
|
71
91
|
};
|
72
92
|
if (tsConfigFilePath !== undefined &&
|
73
93
|
tsConfig?.compilerOptions?.paths !== undefined) {
|
@@ -78,16 +98,13 @@ const resolve = ({ moduleSpecifier, sourceFilePath, tsConfigFilePath, tsConfig,
|
|
78
98
|
// Exact match
|
79
99
|
if (moduleSpecifier === key) {
|
80
100
|
const fullResolvedPath = path.join(path.parse(tsConfigFilePath).dir, tsConfig.compilerOptions.baseUrl, resolvedPath);
|
101
|
+
importsSubpathPatterns[key] = [
|
102
|
+
tsConfig.compilerOptions.baseUrl,
|
103
|
+
path.sep,
|
104
|
+
resolvedPath.replace(/\.ts$/, '.js'),
|
105
|
+
].join('');
|
81
106
|
return {
|
82
107
|
resolvedPath: fullResolvedPath,
|
83
|
-
importsSubpathPatterns: {
|
84
|
-
...importsSubpathPatterns,
|
85
|
-
[key]: [
|
86
|
-
tsConfig.compilerOptions.baseUrl,
|
87
|
-
path.sep,
|
88
|
-
resolvedPath.replace(/\.ts$/, '.js'),
|
89
|
-
].join(''),
|
90
|
-
},
|
91
108
|
};
|
92
109
|
}
|
93
110
|
// Wildcard match
|
@@ -97,24 +114,20 @@ const resolve = ({ moduleSpecifier, sourceFilePath, tsConfigFilePath, tsConfig,
|
|
97
114
|
const maybeMatch = rx.exec(moduleSpecifier);
|
98
115
|
if (maybeMatch?.groups?.wildcard === undefined)
|
99
116
|
continue;
|
117
|
+
importsSubpathPatterns[key] = [
|
118
|
+
tsConfig.compilerOptions.baseUrl,
|
119
|
+
path.sep,
|
120
|
+
resolvedPath.replace(/\.ts$/, '.js'),
|
121
|
+
].join('');
|
100
122
|
return {
|
101
123
|
resolvedPath: path
|
102
124
|
.resolve(path.parse(tsConfigFilePath).dir, tsConfig.compilerOptions.baseUrl, resolvedPath.replace('*', maybeMatch.groups.wildcard))
|
103
125
|
// Same as above, replace `.js` with `.ts`
|
104
126
|
.replace(/\.js$/, '.ts'),
|
105
|
-
importsSubpathPatterns: {
|
106
|
-
...importsSubpathPatterns,
|
107
|
-
[key]: [
|
108
|
-
tsConfig.compilerOptions.baseUrl,
|
109
|
-
path.sep,
|
110
|
-
resolvedPath.replace(/\.ts$/, '.js'),
|
111
|
-
].join(''),
|
112
|
-
},
|
113
127
|
};
|
114
128
|
}
|
115
129
|
}
|
116
130
|
return {
|
117
131
|
resolvedPath: moduleSpecifier,
|
118
|
-
importsSubpathPatterns,
|
119
132
|
};
|
120
133
|
};
|
@@ -9,8 +9,11 @@ void describe('findDependencies()', () => {
|
|
9
9
|
const { packages } = findDependencies({
|
10
10
|
sourceFilePath: path.join(__dirname, '..', 'cdk', 'lambda.ts'),
|
11
11
|
});
|
12
|
-
assert.equal(packages.has('aws-lambda'), true, "Should include the 'aws-lambda' package");
|
13
12
|
assert.equal(packages.has('id128'), true, "Should include the 'id128' package");
|
13
|
+
assert.equal(packages.has('aws-lambda'), false, "Should not include the type-only 'aws-lambda' package");
|
14
|
+
assert.equal(packages.has('node:crypto'), false, 'Should not include built-in node dependencies');
|
15
|
+
assert.equal(packages.has('fp-ts'), true, 'Should include the top-level package only');
|
16
|
+
assert.equal(packages.has('@aws-sdk/client-dynamodb'), false, 'Should not include AWS SDK packages');
|
14
17
|
});
|
15
18
|
void it('should honor tsconfig.json paths', () => {
|
16
19
|
const { dependencies } = findDependencies({
|
package/dist/src/packLambda.js
CHANGED
@@ -26,7 +26,10 @@ export const packLambda = async ({ sourceFilePath, zipFilePath, tsConfigFilePath
|
|
26
26
|
sourceFilePath,
|
27
27
|
tsConfigFilePath,
|
28
28
|
});
|
29
|
-
debug?.(
|
29
|
+
debug?.(`${sourceFilePath}: dependencies`, [...packages].join(', '));
|
30
|
+
Object.entries(importsSubpathPatterns).forEach(([k, v]) => {
|
31
|
+
debug?.(`${sourceFilePath}:importsSubpathPattern`, `${k} -> ${v}`);
|
32
|
+
});
|
30
33
|
const lambdaFiles = [sourceFilePath, ...deps];
|
31
34
|
const zipfile = new yazl.ZipFile();
|
32
35
|
const stripCommon = removeCommonAncestor(commonParent(lambdaFiles));
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@bifravst/aws-cdk-lambda-helpers",
|
3
|
-
"version": "2.2.
|
3
|
+
"version": "2.2.2",
|
4
4
|
"description": "Helper functions which simplify working with TypeScript lambdas for AWS CDK.",
|
5
5
|
"exports": {
|
6
6
|
".": {
|
@@ -52,6 +52,7 @@
|
|
52
52
|
"license": "BSD-3-Clause",
|
53
53
|
"devDependencies": {
|
54
54
|
"@aws-sdk/client-cloudformation": "3.693.0",
|
55
|
+
"@aws-sdk/client-dynamodb": "3.693.0",
|
55
56
|
"@bifravst/cloudformation-helpers": "9.1.1",
|
56
57
|
"@bifravst/eslint-config-typescript": "6.1.18",
|
57
58
|
"@bifravst/from-env": "3.0.2",
|
@@ -108,6 +109,7 @@
|
|
108
109
|
"prettier": "@bifravst/prettier-config",
|
109
110
|
"dependencies": {
|
110
111
|
"@swc/core": "1.9.2",
|
112
|
+
"fp-ts": "2.16.9",
|
111
113
|
"glob": "11.0.0",
|
112
114
|
"typescript": "5.6.3",
|
113
115
|
"yazl": "3.3.0"
|