@justinmoto/frontend-guardian-core 0.1.7 → 0.1.9

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.
@@ -19,7 +19,7 @@ export type ScanResult = {
19
19
  warnings: Warning[];
20
20
  duplicates: Duplicate[];
21
21
  };
22
- export declare function scanZip(buffer: Buffer): Promise<ScanResult>;
22
+ export declare function scanZip(buffer: Buffer | ArrayBuffer): Promise<ScanResult>;
23
23
  export declare function scanFiles(files: {
24
24
  path: string;
25
25
  code: string;
@@ -1 +1 @@
1
- {"version":3,"file":"scanEngine.d.ts","sourceRoot":"","sources":["../src/scanEngine.ts"],"names":[],"mappings":"AASA,MAAM,MAAM,OAAO,GAAG;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAC7C,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AACF,MAAM,MAAM,SAAS,GAAG;IAAE,KAAK,EAAE,MAAM,EAAE,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAClF,MAAM,MAAM,UAAU,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,OAAO,EAAE,CAAC;IAAC,UAAU,EAAE,SAAS,EAAE,CAAA;CAAE,CAAC;AA2W/G,wBAAsB,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAajE;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,EAAE,GAAG,UAAU,CAG7E"}
1
+ {"version":3,"file":"scanEngine.d.ts","sourceRoot":"","sources":["../src/scanEngine.ts"],"names":[],"mappings":"AASA,MAAM,MAAM,OAAO,GAAG;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAC7C,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AACF,MAAM,MAAM,SAAS,GAAG;IAAE,KAAK,EAAE,MAAM,EAAE,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAClF,MAAM,MAAM,UAAU,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,OAAO,EAAE,CAAC;IAAC,UAAU,EAAE,SAAS,EAAE,CAAA;CAAE,CAAC;AA2W/G,wBAAsB,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,CAa/E;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,EAAE,GAAG,UAAU,CAG7E"}
@@ -1,7 +1,7 @@
1
1
  import * as parser from "@babel/parser";
2
2
  import _traverse from "@babel/traverse";
3
3
  const traverse = (typeof _traverse === "function" ? _traverse : _traverse.default);
4
- import * as crypto from "crypto";
4
+ import md5 from "md5";
5
5
  import JSZip from "jszip";
6
6
  const EXT = [".js", ".jsx", ".ts", ".tsx"];
7
7
  const IGNORE_PATH_PARTS = ["node_modules", ".next", "dist", "build", ".git"];
@@ -239,7 +239,7 @@ function runAnalysis(fileContents) {
239
239
  buttonDataByFile.set(filePath, btnEntries.map((e) => ({ classes: e.classes.split(/\s+/).filter(Boolean), line: e.line })));
240
240
  const normalized = normalizeJsxForHash(code);
241
241
  if (normalized.length > 50) {
242
- const hash = crypto.createHash("md5").update(normalized).digest("hex");
242
+ const hash = md5(normalized);
243
243
  if (!jsxHashes.has(hash))
244
244
  jsxHashes.set(hash, []);
245
245
  jsxHashes.get(hash).push(filePath);
@@ -377,7 +377,7 @@ function runAnalysis(fileContents) {
377
377
  return { score, filesScanned: sourceOnly.length, warnings, duplicates };
378
378
  }
379
379
  export async function scanZip(buffer) {
380
- const zip = await JSZip.loadAsync(buffer);
380
+ const zip = await JSZip.loadAsync(buffer instanceof ArrayBuffer ? new Uint8Array(buffer) : buffer);
381
381
  const fileContents = [];
382
382
  for (const [path, entry] of Object.entries(zip.files)) {
383
383
  if (entry.dir || !isCodeFile(path) || !isSourcePath(path))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@justinmoto/frontend-guardian-core",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "description": "Scan engine for Frontend Guardian. To run scans from the CLI use: npx frontend-guardian .",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -12,14 +12,15 @@
12
12
  "default": "./dist/index.js"
13
13
  }
14
14
  },
15
- "files": [
16
- "dist",
17
- "README.md"
18
- ],
15
+ "files": ["dist", "README.md"],
16
+ "scripts": {
17
+ "build": "tsc"
18
+ },
19
19
  "dependencies": {
20
20
  "@babel/parser": "^7.26.0",
21
21
  "@babel/traverse": "^7.26.0",
22
- "jszip": "^3.10.1"
22
+ "jszip": "^3.10.1",
23
+ "md5": "^2.3.0"
23
24
  },
24
25
  "devDependencies": {
25
26
  "typescript": "^5"
@@ -35,8 +36,5 @@
35
36
  "components",
36
37
  "ast"
37
38
  ],
38
- "license": "MIT",
39
- "scripts": {
40
- "build": "tsc"
41
- }
42
- }
39
+ "license": "MIT"
40
+ }