@aws-sdk/find-v2 0.1.0 → 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.
package/dist/cli.js CHANGED
@@ -16,8 +16,9 @@ export const createProgram = () => {
16
16
  program
17
17
  .command("lambda")
18
18
  .description("Scans Lambda Node.js Functions for JavaScript SDK v2.")
19
- .action(async () => {
20
- await scanLambdaFunctions();
19
+ .option("-r, --region <region>", "AWS region to scan")
20
+ .action(async (options) => {
21
+ await scanLambdaFunctions(options.region);
21
22
  });
22
23
  return program;
23
24
  };
@@ -31,6 +31,7 @@ export const scanLambdaFunction = async (client, functionName) => {
31
31
  console.log(`${JS_SDK_V2_MARKER.Y} ${functionName}`);
32
32
  return;
33
33
  }
34
+ // oxlint-disable-next-line no-unused-vars
34
35
  }
35
36
  catch (error) {
36
37
  // Parsing failure for package.json which is rare, continue.
@@ -1,12 +1,12 @@
1
1
  import { Lambda, paginateListFunctions } from "@aws-sdk/client-lambda";
2
2
  import { JS_SDK_V2_MARKER } from "./constants.js";
3
3
  import { scanLambdaFunction } from "./scanLambdaFunction.js";
4
- const client = new Lambda();
5
4
  const getNodeJsFunctionNames = (functions) => (functions ?? [])
6
5
  .filter((fn) => fn.Runtime?.startsWith("nodejs"))
7
6
  .map((fn) => fn.FunctionName)
8
7
  .filter((fnName) => fnName !== undefined);
9
- export const scanLambdaFunctions = async () => {
8
+ export const scanLambdaFunctions = async (region) => {
9
+ const client = new Lambda({ region });
10
10
  const functions = [];
11
11
  const paginator = paginateListFunctions({ client }, {});
12
12
  for await (const page of paginator) {
@@ -21,8 +21,8 @@ export const scanLambdaFunctions = async () => {
21
21
  console.log(`- ${JS_SDK_V2_MARKER.Y} means "aws-sdk" is found in Lambda function, and migration is recommended.`);
22
22
  console.log(`- ${JS_SDK_V2_MARKER.N} means "aws-sdk" is not found in Lambda function.`);
23
23
  console.log(`- ${JS_SDK_V2_MARKER.UNKNOWN} means script was not able to proceed, and it emits reason.\n`);
24
- const region = await client.config.region();
25
- console.log(`Reading ${functionsLength} function${functionsLength > 1 ? "s" : ""} from "${region}" region.`);
24
+ const clientRegion = await client.config.region();
25
+ console.log(`Reading ${functionsLength} function${functionsLength > 1 ? "s" : ""} from "${clientRegion}" region.`);
26
26
  for (const functionName of functions) {
27
27
  await scanLambdaFunction(client, functionName);
28
28
  }
@@ -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.0",
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,10 +20,10 @@
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",
26
+ "oxlint": "^1.33.0",
27
27
  "rolldown": "1.0.0-beta.54",
28
28
  "rollup": "^4.53.3",
29
29
  "typescript": "^5.9.3",
@@ -33,6 +33,7 @@
33
33
  },
34
34
  "scripts": {
35
35
  "build": "tsc",
36
+ "lint": "oxlint src/**/*.ts",
36
37
  "format": "oxfmt",
37
38
  "test": "vitest",
38
39
  "test:generate:bundles": "node scripts/generateBundles.ts",