@aws-sdk/find-v2 0.1.1 → 0.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.
@@ -1,4 +1,4 @@
1
- import unzipper from "unzipper";
1
+ import StreamZip from "node-stream-zip";
2
2
  const PACKAGE_JSON_FILENAME = "package.json";
3
3
  /**
4
4
  * Extracts the contents of a Lambda Function zip file.
@@ -9,30 +9,54 @@ const PACKAGE_JSON_FILENAME = "package.json";
9
9
  * @returns Promise<LambdaFunctionContents> - Resolves to an object containing the extracted contents.
10
10
  */
11
11
  export const getLambdaFunctionContents = async (zipPath) => {
12
- const directory = await unzipper.Open.file(zipPath);
12
+ const zip = new StreamZip.async({ file: zipPath });
13
13
  const packageJsonContents = [];
14
- for (const file of directory.files) {
14
+ let zipEntries = {};
15
+ try {
16
+ zipEntries = await zip.entries();
17
+ }
18
+ catch {
19
+ // Continue with empty object, if zip entries can't be read.
20
+ // ToDo: add warning when logging is supported in future.
21
+ }
22
+ for (const zipEntry of Object.values(zipEntries)) {
15
23
  // Skip 'node_modules' directory, as it's not the customer source code.
16
- if (file.path.includes("node_modules/"))
24
+ if (zipEntry.name.includes("node_modules/"))
25
+ continue;
26
+ // Skip anything which is not 'package.json'
27
+ if (!zipEntry.name.endsWith(PACKAGE_JSON_FILENAME))
17
28
  continue;
18
- // Skip anything which is not `package.json`
19
- if (!file.path.endsWith(PACKAGE_JSON_FILENAME))
29
+ // Skip if 'package.json' is not a file
30
+ if (!zipEntry.isFile)
20
31
  continue;
21
- const packageJsonContent = await file.buffer();
22
- packageJsonContents.push(packageJsonContent.toString());
32
+ try {
33
+ const packageJsonContent = await zip.entryData(zipEntry.name);
34
+ packageJsonContents.push(packageJsonContent.toString());
35
+ }
36
+ catch {
37
+ // Continue without adding package.json file, if entry data can't be read.
38
+ // ToDo: add warning when logging is supported in future.
39
+ }
23
40
  }
24
41
  if (packageJsonContents.length !== 0) {
42
+ await zip.close();
25
43
  return { packageJsonContents };
26
44
  }
27
- let indexFile;
28
45
  for (const path of ["index.js", "index.mjs", "index.cjs"]) {
29
- indexFile = directory.files.find((f) => f.path === path && f.type === "File");
30
- if (indexFile)
31
- break;
32
- }
33
- if (indexFile) {
34
- const bundleContent = await indexFile.buffer();
35
- return { bundleContent: bundleContent.toString() };
46
+ if (!zipEntries[path])
47
+ continue;
48
+ if (!zipEntries[path].isFile)
49
+ continue;
50
+ try {
51
+ const bundleContent = await zip.entryData(path);
52
+ await zip.close();
53
+ return { bundleContent: bundleContent.toString() };
54
+ }
55
+ catch {
56
+ // Continue processing next index file, if entry data can't be read.
57
+ // ToDo: add warning when logging is supported in future.
58
+ }
36
59
  }
60
+ await zip.close();
37
61
  return {};
38
62
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-sdk/find-v2",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "description": "CLI to find resources which call AWS using JavaScript SDK v2",
5
5
  "main": "dist/cli.js",
6
6
  "types": "dist/cli.d.ts",
@@ -8,7 +8,7 @@
8
8
  "dependencies": {
9
9
  "@aws-sdk/client-lambda": "^3.942.0",
10
10
  "commander": "^14.0.2",
11
- "unzipper": "^0.12.3"
11
+ "node-stream-zip": "^1.15.0"
12
12
  },
13
13
  "devDependencies": {
14
14
  "@aws-sdk/client-sts": "^3.946.0",
@@ -20,7 +20,6 @@
20
20
  "@tsconfig/node-ts": "^23.6.2",
21
21
  "@tsconfig/node20": "^20.1.8",
22
22
  "@types/node": "^20.14.8",
23
- "@types/unzipper": "^0.10.11",
24
23
  "aws-sdk": "^2.1692.0",
25
24
  "esbuild": "~0.27.1",
26
25
  "oxfmt": "^0.18.0",