@blazediff/bin 1.7.0 → 2.0.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/README.md +167 -81
- package/bin/blazediff.exe +0 -0
- package/binaries/blazediff-linux-arm64 +0 -0
- package/binaries/blazediff-linux-x64 +0 -0
- package/binaries/blazediff-macos-arm64 +0 -0
- package/binaries/blazediff-macos-x64 +0 -0
- package/binaries/blazediff-windows-arm64.exe +0 -0
- package/binaries/blazediff-windows-x64.exe +0 -0
- package/dist/index.d.mts +44 -67
- package/dist/index.d.ts +44 -67
- package/dist/index.js +108 -1
- package/dist/index.mjs +72 -0
- package/package.json +23 -21
- package/post_install.js +40 -0
- package/dist/cli.js +0 -979
- package/dist/commands/diff.js +0 -255
- package/dist/commands/gmsd.js +0 -201
- package/dist/commands/hitchhikers-ssim.js +0 -217
- package/dist/commands/msssim.js +0 -163
- package/dist/commands/ssim.js +0 -163
package/dist/index.mjs
CHANGED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { execFile } from "child_process";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import { promisify } from "util";
|
|
5
|
+
var execFileAsync = promisify(execFile);
|
|
6
|
+
var BINARY_PATH = path.join(__dirname, "..", "bin", "blazediff.exe");
|
|
7
|
+
function buildArgs(diffOutput, options) {
|
|
8
|
+
const args = [diffOutput, "--output-format=json"];
|
|
9
|
+
if (!options) return args;
|
|
10
|
+
if (options.threshold !== void 0) args.push(`--threshold=${options.threshold}`);
|
|
11
|
+
if (options.antialiasing) args.push("--antialiasing");
|
|
12
|
+
if (options.diffMask) args.push("--diff-mask");
|
|
13
|
+
if (options.failOnLayoutDiff) args.push("--fail-on-layout");
|
|
14
|
+
if (options.compression !== void 0) args.push(`--compression=${options.compression}`);
|
|
15
|
+
return args;
|
|
16
|
+
}
|
|
17
|
+
function parseJsonOutput(text) {
|
|
18
|
+
try {
|
|
19
|
+
return JSON.parse(text);
|
|
20
|
+
} catch {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function detectMissingFile(error, basePath, comparePath) {
|
|
25
|
+
if (!/Failed to load images:.*(?:No such file|not found)/i.test(error)) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
if (error.includes(basePath)) return basePath;
|
|
29
|
+
if (error.includes(comparePath)) return comparePath;
|
|
30
|
+
return basePath;
|
|
31
|
+
}
|
|
32
|
+
async function compare(basePath, comparePath, diffOutput, options) {
|
|
33
|
+
const args = [basePath, comparePath, ...buildArgs(diffOutput, options)];
|
|
34
|
+
try {
|
|
35
|
+
await execFileAsync(BINARY_PATH, args);
|
|
36
|
+
return { match: true };
|
|
37
|
+
} catch (err) {
|
|
38
|
+
const { code, stdout, stderr } = err;
|
|
39
|
+
const output = stdout || stderr || "";
|
|
40
|
+
if (code === 1) {
|
|
41
|
+
const json = parseJsonOutput(output);
|
|
42
|
+
if (json?.error?.includes("Layout differs")) {
|
|
43
|
+
return { match: false, reason: "layout-diff" };
|
|
44
|
+
}
|
|
45
|
+
if (json) {
|
|
46
|
+
return {
|
|
47
|
+
match: false,
|
|
48
|
+
reason: "pixel-diff",
|
|
49
|
+
diffCount: json.diffCount,
|
|
50
|
+
diffPercentage: json.diffPercentage
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
if (output.includes("Layout differs")) {
|
|
54
|
+
return { match: false, reason: "layout-diff" };
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (code === 2) {
|
|
58
|
+
const missingFile = detectMissingFile(output, basePath, comparePath);
|
|
59
|
+
if (missingFile) {
|
|
60
|
+
return { match: false, reason: "file-not-exists", file: missingFile };
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
throw new Error(output || `blazediff exited with code ${code}`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function getBinaryPath() {
|
|
67
|
+
return BINARY_PATH;
|
|
68
|
+
}
|
|
69
|
+
export {
|
|
70
|
+
compare,
|
|
71
|
+
getBinaryPath
|
|
72
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blazediff/bin",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "Native Rust binaries for blazediff - the fastest image diff in the world",
|
|
5
5
|
"private": false,
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -9,48 +9,50 @@
|
|
|
9
9
|
"main": "dist/index.js",
|
|
10
10
|
"module": "dist/index.mjs",
|
|
11
11
|
"types": "dist/index.d.ts",
|
|
12
|
-
"bin": {
|
|
13
|
-
"blazediff": "./dist/cli.js"
|
|
14
|
-
},
|
|
15
12
|
"exports": {
|
|
16
13
|
".": {
|
|
17
14
|
"types": "./dist/index.d.ts",
|
|
18
15
|
"import": "./dist/index.mjs",
|
|
19
16
|
"require": "./dist/index.js"
|
|
20
|
-
},
|
|
21
|
-
"./cli": {
|
|
22
|
-
"import": "./dist/cli.mjs",
|
|
23
|
-
"require": "./dist/cli.js"
|
|
24
17
|
}
|
|
25
18
|
},
|
|
19
|
+
"bin": {
|
|
20
|
+
"blazediff": "bin/blazediff.exe"
|
|
21
|
+
},
|
|
26
22
|
"files": [
|
|
27
|
-
"dist"
|
|
23
|
+
"dist",
|
|
24
|
+
"bin",
|
|
25
|
+
"binaries",
|
|
26
|
+
"post_install.js"
|
|
28
27
|
],
|
|
29
28
|
"keywords": [
|
|
30
|
-
"cli",
|
|
31
29
|
"image",
|
|
32
30
|
"comparison",
|
|
33
|
-
"diff"
|
|
31
|
+
"diff",
|
|
32
|
+
"pixel",
|
|
33
|
+
"visual-testing",
|
|
34
|
+
"visual-regression",
|
|
35
|
+
"screenshot",
|
|
36
|
+
"native",
|
|
37
|
+
"rust",
|
|
38
|
+
"simd",
|
|
39
|
+
"fast"
|
|
34
40
|
],
|
|
35
41
|
"author": "Teimur Gasanov <me@teimurjan.dev> (https://github.com/teimurjan)",
|
|
36
42
|
"repository": "https://github.com/teimurjan/blazediff",
|
|
37
43
|
"homepage": "https://blazediff.dev",
|
|
38
44
|
"license": "MIT",
|
|
39
|
-
"dependencies": {
|
|
40
|
-
"@blazediff/core": "1.7.0",
|
|
41
|
-
"@blazediff/gmsd": "1.7.0",
|
|
42
|
-
"@blazediff/pngjs-transformer": "2.0.0",
|
|
43
|
-
"@blazediff/sharp-transformer": "2.0.0",
|
|
44
|
-
"@blazediff/ssim": "1.7.0"
|
|
45
|
-
},
|
|
46
45
|
"devDependencies": {
|
|
47
46
|
"@types/node": "^24.3.0",
|
|
48
47
|
"tsup": "8.5.0",
|
|
49
48
|
"typescript": "5.9.2"
|
|
50
49
|
},
|
|
51
50
|
"scripts": {
|
|
51
|
+
"postinstall": "node ./post_install.js",
|
|
52
52
|
"build": "tsup",
|
|
53
|
-
"
|
|
54
|
-
"
|
|
53
|
+
"build:rust": "cd rust && ./scripts/build-all.sh --all",
|
|
54
|
+
"build:rust:local": "cd rust && cargo build --release && cp target/release/blazediff ../binaries/blazediff-$(node -e \"console.log(process.platform === 'darwin' ? 'macos' : process.platform)-$(process.arch === 'arm64' ? 'arm64' : 'x64')\")",
|
|
55
|
+
"prepare-binaries": "node ./scripts/prepare-binaries.js",
|
|
56
|
+
"clean": "rm -rf dist bin"
|
|
55
57
|
}
|
|
56
58
|
}
|
package/post_install.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
const path = require("path");
|
|
3
|
+
const os = require("os");
|
|
4
|
+
|
|
5
|
+
const binaries = {
|
|
6
|
+
"linux-x64": "blazediff-linux-x64",
|
|
7
|
+
"linux-arm64": "blazediff-linux-arm64",
|
|
8
|
+
"darwin-arm64": "blazediff-macos-arm64",
|
|
9
|
+
"darwin-x64": "blazediff-macos-x64",
|
|
10
|
+
"win32-x64": "blazediff-windows-x64.exe",
|
|
11
|
+
"win32-arm64": "blazediff-windows-arm64.exe",
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const platform = os.platform();
|
|
15
|
+
const arch = os.arch();
|
|
16
|
+
|
|
17
|
+
const binaryKey = `${platform}-${arch}`;
|
|
18
|
+
const binaryFile = binaries[binaryKey];
|
|
19
|
+
|
|
20
|
+
if (!binaryFile) {
|
|
21
|
+
console.error(
|
|
22
|
+
`blazediff: Sorry your platform or architecture is not supported. Supported: ${Object.keys(binaries).join(", ")}`,
|
|
23
|
+
);
|
|
24
|
+
process.exit(1);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const sourcePath = path.join(__dirname, "binaries", binaryFile);
|
|
28
|
+
const binDir = path.join(__dirname, "bin");
|
|
29
|
+
const destPath = path.join(binDir, "blazediff.exe");
|
|
30
|
+
|
|
31
|
+
try {
|
|
32
|
+
if (!fs.existsSync(binDir)) {
|
|
33
|
+
fs.mkdirSync(binDir, { recursive: true });
|
|
34
|
+
}
|
|
35
|
+
fs.copyFileSync(sourcePath, destPath);
|
|
36
|
+
fs.chmodSync(destPath, 0o755);
|
|
37
|
+
} catch (err) {
|
|
38
|
+
console.error(`blazediff: failed to copy and link the binary file: ${err}`);
|
|
39
|
+
process.exit(1);
|
|
40
|
+
}
|