@tauri-cordis/review 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.
Files changed (2) hide show
  1. package/package.json +4 -1
  2. package/src/files.mjs +5 -28
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tauri-cordis/review",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Version-to-version plugin source and bundle diff analyzer for tauri-cordis markets",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -32,6 +32,9 @@
32
32
  "engines": {
33
33
  "node": ">=22.15"
34
34
  },
35
+ "dependencies": {
36
+ "@tauri-cordis/manifest": "0.2.0"
37
+ },
35
38
  "scripts": {
36
39
  "test": "node --test \"test/**/*.test.mjs\""
37
40
  }
package/src/files.mjs CHANGED
@@ -1,14 +1,16 @@
1
1
  import { createHash } from "node:crypto";
2
2
  import { lstatSync, readdirSync, readFileSync } from "node:fs";
3
3
  import { join, relative, sep } from "node:path";
4
+ import { EXECUTABLE_EXTENSIONS, executableKind, zipEntryNames } from "@tauri-cordis/manifest";
5
+
6
+ export { executableKind, zipEntryNames };
4
7
 
5
8
  const SKIP_DIRS = new Set([".git", "node_modules"]);
6
9
  export const CODE_EXTENSIONS = /\.(?:[cm]?js|jsx|[cm]?ts|tsx)$/i;
7
10
  export const LOCKFILES = new Set(["package-lock.json", "npm-shrinkwrap.json", "pnpm-lock.yaml"]);
8
- const EXECUTABLE_EXTENSIONS = new Set([".exe", ".dll", ".sys", ".scr", ".com", ".msi", ".so", ".dylib", ".bin", ".elf", ".app", ".appimage", ".deb", ".rpm", ".pkg", ".dmg", ".wasm", ".jar", ".class"]);
11
+ const EXECUTABLE_EXTENSION_SET = new Set(EXECUTABLE_EXTENSIONS);
9
12
  const SCRIPT_EXTENSIONS = /\.(?:sh|bash|zsh|ps1|psm1|bat|cmd|command|vbs|applescript|scpt)$/i;
10
13
  const ASSET_EXTENSIONS = /\.(?:png|jpe?g|gif|webp|ico|icns|bmp|avif|woff2?|ttf|otf|eot|mp3|wav|ogg|m4a|flac|mp4|webm|pdf)$/i;
11
- const MACHO = new Set([0xfeedface, 0xfeedfacf, 0xcefaedfe, 0xcffaedfe, 0xbebafeca, 0xcafebabf, 0xbfbafeca]);
12
14
 
13
15
  function extensionOf(path) {
14
16
  const base = path.slice(path.lastIndexOf("/") + 1).toLowerCase();
@@ -16,38 +18,13 @@ function extensionOf(path) {
16
18
  return dot > 0 ? base.slice(dot) : "";
17
19
  }
18
20
 
19
- export function zipEntryNames(data) {
20
- const names = new Set();
21
- for (const [signature, nameAt, lengthAt] of [[Buffer.from([0x50, 0x4b, 0x03, 0x04]), 30, 26], [Buffer.from([0x50, 0x4b, 0x01, 0x02]), 46, 28]]) {
22
- for (let at = data.indexOf(signature); at >= 0 && at + nameAt <= data.length; at = data.indexOf(signature, at + 4)) {
23
- const length = data.readUInt16LE(at + lengthAt);
24
- if (at + nameAt + length <= data.length) names.add(data.toString("utf8", at + nameAt, at + nameAt + length));
25
- }
26
- }
27
- return [...names];
28
- }
29
-
30
- const isJarEntry = (name) => name === "META-INF/MANIFEST.MF" || name.toLowerCase().endsWith(".class");
31
-
32
- export function executableKind(data) {
33
- if (data.length >= 2 && data[0] === 0x4d && data[1] === 0x5a) return "PE";
34
- if (data.length < 4) return null;
35
- const magic = data.readUInt32BE(0);
36
- if (magic === 0x7f454c46) return "ELF";
37
- if (magic === 0xcafebabe) return data.length >= 8 && data.readUInt32BE(4) >= 45 ? "Java class" : "Mach-O";
38
- if (MACHO.has(magic)) return "Mach-O";
39
- if (magic === 0x0061736d) return "WebAssembly";
40
- if (magic === 0x504b0304 && zipEntryNames(data).some(isJarEntry)) return "Java archive";
41
- return null;
42
- }
43
-
44
21
  function classify(path, buffer) {
45
22
  const binary = buffer.subarray(0, 8000).includes(0);
46
23
  const extension = extensionOf(path);
47
24
  if (extension === ".node") return { kind: "native", label: ".node" };
48
25
  const magic = executableKind(buffer);
49
26
  if (magic) return { kind: "executable", label: magic };
50
- if (EXECUTABLE_EXTENSIONS.has(extension)) return { kind: "executable", label: extension };
27
+ if (EXECUTABLE_EXTENSION_SET.has(extension)) return { kind: "executable", label: extension };
51
28
  if (SCRIPT_EXTENSIONS.test(path)) return { kind: "script" };
52
29
  if (binary) return { kind: ASSET_EXTENSIONS.test(path) ? "asset" : "binary" };
53
30
  if (ASSET_EXTENSIONS.test(path)) return { kind: "asset" };