@bifravst/aws-cdk-lambda-helpers 2.1.0 → 2.2.0

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.
@@ -5,6 +5,7 @@ export declare const findDependencies: (args: {
5
5
  sourceFilePath: string;
6
6
  imports?: string[];
7
7
  visited?: string[];
8
+ packages?: Set<string>;
8
9
  tsConfigFilePath?: string;
9
10
  importsSubpathPatterns?: Record<string, string>;
10
11
  }) => {
@@ -14,4 +15,8 @@ export declare const findDependencies: (args: {
14
15
  * @see https://nodejs.org/api/packages.html#subpath-patterns
15
16
  */
16
17
  importsSubpathPatterns: Record<string, string>;
18
+ /**
19
+ * The external packages that the source file depends on
20
+ */
21
+ packages: Set<string>;
17
22
  };
@@ -8,9 +8,10 @@ export const findDependencies = (args) => {
8
8
  const sourceFilePath = args.sourceFilePath;
9
9
  const visited = args.visited ?? [];
10
10
  const dependencies = args.imports ?? [];
11
+ const packages = args.packages ?? new Set();
11
12
  let importsSubpathPatterns = args.importsSubpathPatterns ?? {};
12
13
  if (visited.includes(sourceFilePath))
13
- return { dependencies, importsSubpathPatterns };
14
+ return { dependencies, importsSubpathPatterns, packages };
14
15
  const tsConfigFilePath = args.tsConfigFilePath;
15
16
  const tsConfig = tsConfigFilePath !== undefined
16
17
  ? JSON.parse(readFileSync(tsConfigFilePath, 'utf-8').toString())
@@ -38,6 +39,7 @@ export const findDependencies = (args) => {
38
39
  catch {
39
40
  // Module or file not found
40
41
  visited.push(file);
42
+ packages.add(moduleSpecifier);
41
43
  }
42
44
  };
43
45
  ts.forEachChild(fileNode, parseChild);
@@ -49,9 +51,10 @@ export const findDependencies = (args) => {
49
51
  visited,
50
52
  tsConfigFilePath,
51
53
  importsSubpathPatterns,
54
+ packages,
52
55
  });
53
56
  }
54
- return { dependencies, importsSubpathPatterns };
57
+ return { dependencies, importsSubpathPatterns, packages };
55
58
  };
56
59
  const resolve = ({ moduleSpecifier, sourceFilePath, tsConfigFilePath, tsConfig, importsSubpathPatterns, }) => {
57
60
  if (moduleSpecifier.startsWith('.'))
@@ -5,6 +5,13 @@ import { URL } from 'node:url';
5
5
  import { findDependencies } from './findDependencies.js';
6
6
  const __dirname = new URL('.', import.meta.url).pathname;
7
7
  void describe('findDependencies()', () => {
8
+ void it('should return a list of external dependencies', () => {
9
+ const { packages } = findDependencies({
10
+ sourceFilePath: path.join(__dirname, '..', 'cdk', 'lambda.ts'),
11
+ });
12
+ assert.equal(packages.has('aws-lambda'), true, "Should include the 'aws-lambda' package");
13
+ assert.equal(packages.has('id128'), true, "Should include the 'id128' package");
14
+ });
8
15
  void it('should honor tsconfig.json paths', () => {
9
16
  const { dependencies } = findDependencies({
10
17
  sourceFilePath: path.join(__dirname, 'test-data', 'resolve-paths', 'lambda.ts'),
@@ -22,10 +22,11 @@ const removeCommonAncestor = (parentDir) => (filePath) => {
22
22
  * In the bundle we only include code that's not in the layer.
23
23
  */
24
24
  export const packLambda = async ({ sourceFilePath, zipFilePath, tsConfigFilePath, debug, progress, }) => {
25
- const { dependencies: deps, importsSubpathPatterns } = findDependencies({
25
+ const { dependencies: deps, importsSubpathPatterns, packages, } = findDependencies({
26
26
  sourceFilePath,
27
27
  tsConfigFilePath,
28
28
  });
29
+ debug?.(`dependencies`, [...packages].join(', '));
29
30
  const lambdaFiles = [sourceFilePath, ...deps];
30
31
  const zipfile = new yazl.ZipFile();
31
32
  const stripCommon = removeCommonAncestor(commonParent(lambdaFiles));
@@ -62,6 +63,7 @@ export const packLambda = async ({ sourceFilePath, zipFilePath, tsConfigFilePath
62
63
  zipfile.addBuffer(Buffer.from(JSON.stringify({
63
64
  type: 'module',
64
65
  imports: importsSubpathPatterns,
66
+ dependencies: Object.fromEntries(packages.values().map((pkg) => [pkg, '*'])),
65
67
  }), 'utf-8'), 'package.json');
66
68
  progress?.(`added`, 'package.json');
67
69
  await new Promise((resolve) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bifravst/aws-cdk-lambda-helpers",
3
- "version": "2.1.0",
3
+ "version": "2.2.0",
4
4
  "description": "Helper functions which simplify working with TypeScript lambdas for AWS CDK.",
5
5
  "exports": {
6
6
  ".": {
@@ -51,7 +51,7 @@
51
51
  "author": "Nordic Semiconductor ASA | nordicsemi.no",
52
52
  "license": "BSD-3-Clause",
53
53
  "devDependencies": {
54
- "@aws-sdk/client-cloudformation": "3.692.0",
54
+ "@aws-sdk/client-cloudformation": "3.693.0",
55
55
  "@bifravst/cloudformation-helpers": "9.1.1",
56
56
  "@bifravst/eslint-config-typescript": "6.1.18",
57
57
  "@bifravst/from-env": "3.0.2",
@@ -113,7 +113,7 @@
113
113
  "yazl": "3.3.0"
114
114
  },
115
115
  "peerDependencies": {
116
- "@bifravst/aws-ssm-settings-helpers": "^1.2.61",
116
+ "@bifravst/aws-ssm-settings-helpers": "^1.2.63",
117
117
  "aws-cdk-lib": "^2.167.0",
118
118
  "constructs": "^10.4.2"
119
119
  }