@blazediff/bin 2.0.1 → 3.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/dist/index.d.mts CHANGED
@@ -26,12 +26,16 @@ type BlazeDiffResult = {
26
26
  file: string;
27
27
  };
28
28
  /**
29
- * Compare two PNG images and generate a diff image.
29
+ * Compare two PNG images and optionally generate a diff image.
30
30
  *
31
31
  * @example
32
32
  * ```ts
33
+ * // With diff output
33
34
  * const result = await compare('expected.png', 'actual.png', 'diff.png');
34
35
  *
36
+ * // Without diff output (faster, just returns comparison result)
37
+ * const result = await compare('expected.png', 'actual.png');
38
+ *
35
39
  * if (result.match) {
36
40
  * console.log('Images identical');
37
41
  * } else if (result.reason === 'pixel-diff') {
@@ -39,7 +43,7 @@ type BlazeDiffResult = {
39
43
  * }
40
44
  * ```
41
45
  */
42
- declare function compare(basePath: string, comparePath: string, diffOutput: string, options?: BlazeDiffOptions): Promise<BlazeDiffResult>;
46
+ declare function compare(basePath: string, comparePath: string, diffOutput?: string, options?: BlazeDiffOptions): Promise<BlazeDiffResult>;
43
47
  /** Get the path to the blazediff binary for direct CLI usage. */
44
48
  declare function getBinaryPath(): string;
45
49
 
package/dist/index.d.ts CHANGED
@@ -26,12 +26,16 @@ type BlazeDiffResult = {
26
26
  file: string;
27
27
  };
28
28
  /**
29
- * Compare two PNG images and generate a diff image.
29
+ * Compare two PNG images and optionally generate a diff image.
30
30
  *
31
31
  * @example
32
32
  * ```ts
33
+ * // With diff output
33
34
  * const result = await compare('expected.png', 'actual.png', 'diff.png');
34
35
  *
36
+ * // Without diff output (faster, just returns comparison result)
37
+ * const result = await compare('expected.png', 'actual.png');
38
+ *
35
39
  * if (result.match) {
36
40
  * console.log('Images identical');
37
41
  * } else if (result.reason === 'pixel-diff') {
@@ -39,7 +43,7 @@ type BlazeDiffResult = {
39
43
  * }
40
44
  * ```
41
45
  */
42
- declare function compare(basePath: string, comparePath: string, diffOutput: string, options?: BlazeDiffOptions): Promise<BlazeDiffResult>;
46
+ declare function compare(basePath: string, comparePath: string, diffOutput?: string, options?: BlazeDiffOptions): Promise<BlazeDiffResult>;
43
47
  /** Get the path to the blazediff binary for direct CLI usage. */
44
48
  declare function getBinaryPath(): string;
45
49
 
package/dist/index.js CHANGED
@@ -34,19 +34,102 @@ __export(index_exports, {
34
34
  getBinaryPath: () => getBinaryPath
35
35
  });
36
36
  module.exports = __toCommonJS(index_exports);
37
+
38
+ // ../../node_modules/.pnpm/tsup@8.5.0_jiti@2.6.0_postcss@8.5.6_tsx@4.20.6_typescript@5.9.2_yaml@2.8.1/node_modules/tsup/assets/cjs_shims.js
39
+ var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
40
+ var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
41
+
42
+ // src/index.ts
37
43
  var import_node_child_process = require("child_process");
44
+ var import_node_fs = require("fs");
45
+ var import_node_module = require("module");
46
+ var import_node_os = __toESM(require("os"));
38
47
  var import_node_path = __toESM(require("path"));
48
+ var import_node_url = require("url");
39
49
  var import_node_util = require("util");
40
50
  var execFileAsync = (0, import_node_util.promisify)(import_node_child_process.execFile);
41
- var BINARY_PATH = import_node_path.default.join(__dirname, "..", "bin", "blazediff.exe");
51
+ var PLATFORM_PACKAGES = {
52
+ "darwin-arm64": {
53
+ packageName: "@blazediff/bin-darwin-arm64",
54
+ packageDir: "bin-darwin-arm64"
55
+ },
56
+ "darwin-x64": {
57
+ packageName: "@blazediff/bin-darwin-x64",
58
+ packageDir: "bin-darwin-x64"
59
+ },
60
+ "linux-arm64": {
61
+ packageName: "@blazediff/bin-linux-arm64",
62
+ packageDir: "bin-linux-arm64"
63
+ },
64
+ "linux-x64": {
65
+ packageName: "@blazediff/bin-linux-x64",
66
+ packageDir: "bin-linux-x64"
67
+ },
68
+ "win32-arm64": {
69
+ packageName: "@blazediff/bin-win32-arm64",
70
+ packageDir: "bin-win32-arm64"
71
+ },
72
+ "win32-x64": {
73
+ packageName: "@blazediff/bin-win32-x64",
74
+ packageDir: "bin-win32-x64"
75
+ }
76
+ };
77
+ function resolveBinaryPath() {
78
+ const platform = import_node_os.default.platform();
79
+ const arch = import_node_os.default.arch();
80
+ const key = `${platform}-${arch}`;
81
+ const platformInfo = PLATFORM_PACKAGES[key];
82
+ if (!platformInfo) {
83
+ throw new Error(
84
+ `Unsupported platform: ${key}. Supported: ${Object.keys(PLATFORM_PACKAGES).join(", ")}`
85
+ );
86
+ }
87
+ const binaryName = platform === "win32" ? "blazediff.exe" : "blazediff";
88
+ try {
89
+ const require2 = (0, import_node_module.createRequire)(importMetaUrl);
90
+ const packagePath = require2.resolve(
91
+ `${platformInfo.packageName}/package.json`
92
+ );
93
+ const packageDir = import_node_path.default.dirname(packagePath);
94
+ const binaryPath = import_node_path.default.join(packageDir, binaryName);
95
+ if ((0, import_node_fs.existsSync)(binaryPath)) {
96
+ return binaryPath;
97
+ }
98
+ } catch {
99
+ }
100
+ const currentDir = import_node_path.default.dirname((0, import_node_url.fileURLToPath)(importMetaUrl));
101
+ const packagesDir = import_node_path.default.resolve(currentDir, "..", "..");
102
+ const siblingPath = import_node_path.default.join(
103
+ packagesDir,
104
+ platformInfo.packageDir,
105
+ binaryName
106
+ );
107
+ if ((0, import_node_fs.existsSync)(siblingPath)) {
108
+ return siblingPath;
109
+ }
110
+ throw new Error(
111
+ `Platform package ${platformInfo.packageName} is not installed. This usually means the optional dependency wasn't installed for your platform. Try reinstalling with: npm install @blazediff/bin`
112
+ );
113
+ }
114
+ var cachedBinaryPath = null;
115
+ function getBinaryPathInternal() {
116
+ if (!cachedBinaryPath) {
117
+ cachedBinaryPath = resolveBinaryPath();
118
+ }
119
+ return cachedBinaryPath;
120
+ }
42
121
  function buildArgs(diffOutput, options) {
43
- const args = [diffOutput, "--output-format=json"];
122
+ const args = [];
123
+ if (diffOutput) args.push(diffOutput);
124
+ args.push("--output-format=json");
44
125
  if (!options) return args;
45
- if (options.threshold !== void 0) args.push(`--threshold=${options.threshold}`);
126
+ if (options.threshold !== void 0)
127
+ args.push(`--threshold=${options.threshold}`);
46
128
  if (options.antialiasing) args.push("--antialiasing");
47
129
  if (options.diffMask) args.push("--diff-mask");
48
130
  if (options.failOnLayoutDiff) args.push("--fail-on-layout");
49
- if (options.compression !== void 0) args.push(`--compression=${options.compression}`);
131
+ if (options.compression !== void 0)
132
+ args.push(`--compression=${options.compression}`);
50
133
  return args;
51
134
  }
52
135
  function parseJsonOutput(text) {
@@ -65,9 +148,10 @@ function detectMissingFile(error, basePath, comparePath) {
65
148
  return basePath;
66
149
  }
67
150
  async function compare(basePath, comparePath, diffOutput, options) {
151
+ const binaryPath = getBinaryPathInternal();
68
152
  const args = [basePath, comparePath, ...buildArgs(diffOutput, options)];
69
153
  try {
70
- await execFileAsync(BINARY_PATH, args);
154
+ await execFileAsync(binaryPath, args);
71
155
  return { match: true };
72
156
  } catch (err) {
73
157
  const { code, stdout, stderr } = err;
@@ -99,7 +183,7 @@ async function compare(basePath, comparePath, diffOutput, options) {
99
183
  }
100
184
  }
101
185
  function getBinaryPath() {
102
- return BINARY_PATH;
186
+ return getBinaryPathInternal();
103
187
  }
104
188
  // Annotate the CommonJS export names for ESM import in node:
105
189
  0 && (module.exports = {
package/dist/index.mjs CHANGED
@@ -1,24 +1,94 @@
1
- // ../../node_modules/.pnpm/tsup@8.5.0_jiti@2.6.0_postcss@8.5.6_tsx@4.20.6_typescript@5.9.2_yaml@2.8.1/node_modules/tsup/assets/esm_shims.js
2
- import path from "path";
3
- import { fileURLToPath } from "url";
4
- var getFilename = () => fileURLToPath(import.meta.url);
5
- var getDirname = () => path.dirname(getFilename());
6
- var __dirname = /* @__PURE__ */ getDirname();
7
-
8
1
  // src/index.ts
9
2
  import { execFile } from "child_process";
10
- import path2 from "path";
3
+ import { existsSync } from "fs";
4
+ import { createRequire } from "module";
5
+ import os from "os";
6
+ import path from "path";
7
+ import { fileURLToPath } from "url";
11
8
  import { promisify } from "util";
12
9
  var execFileAsync = promisify(execFile);
13
- var BINARY_PATH = path2.join(__dirname, "..", "bin", "blazediff.exe");
10
+ var PLATFORM_PACKAGES = {
11
+ "darwin-arm64": {
12
+ packageName: "@blazediff/bin-darwin-arm64",
13
+ packageDir: "bin-darwin-arm64"
14
+ },
15
+ "darwin-x64": {
16
+ packageName: "@blazediff/bin-darwin-x64",
17
+ packageDir: "bin-darwin-x64"
18
+ },
19
+ "linux-arm64": {
20
+ packageName: "@blazediff/bin-linux-arm64",
21
+ packageDir: "bin-linux-arm64"
22
+ },
23
+ "linux-x64": {
24
+ packageName: "@blazediff/bin-linux-x64",
25
+ packageDir: "bin-linux-x64"
26
+ },
27
+ "win32-arm64": {
28
+ packageName: "@blazediff/bin-win32-arm64",
29
+ packageDir: "bin-win32-arm64"
30
+ },
31
+ "win32-x64": {
32
+ packageName: "@blazediff/bin-win32-x64",
33
+ packageDir: "bin-win32-x64"
34
+ }
35
+ };
36
+ function resolveBinaryPath() {
37
+ const platform = os.platform();
38
+ const arch = os.arch();
39
+ const key = `${platform}-${arch}`;
40
+ const platformInfo = PLATFORM_PACKAGES[key];
41
+ if (!platformInfo) {
42
+ throw new Error(
43
+ `Unsupported platform: ${key}. Supported: ${Object.keys(PLATFORM_PACKAGES).join(", ")}`
44
+ );
45
+ }
46
+ const binaryName = platform === "win32" ? "blazediff.exe" : "blazediff";
47
+ try {
48
+ const require2 = createRequire(import.meta.url);
49
+ const packagePath = require2.resolve(
50
+ `${platformInfo.packageName}/package.json`
51
+ );
52
+ const packageDir = path.dirname(packagePath);
53
+ const binaryPath = path.join(packageDir, binaryName);
54
+ if (existsSync(binaryPath)) {
55
+ return binaryPath;
56
+ }
57
+ } catch {
58
+ }
59
+ const currentDir = path.dirname(fileURLToPath(import.meta.url));
60
+ const packagesDir = path.resolve(currentDir, "..", "..");
61
+ const siblingPath = path.join(
62
+ packagesDir,
63
+ platformInfo.packageDir,
64
+ binaryName
65
+ );
66
+ if (existsSync(siblingPath)) {
67
+ return siblingPath;
68
+ }
69
+ throw new Error(
70
+ `Platform package ${platformInfo.packageName} is not installed. This usually means the optional dependency wasn't installed for your platform. Try reinstalling with: npm install @blazediff/bin`
71
+ );
72
+ }
73
+ var cachedBinaryPath = null;
74
+ function getBinaryPathInternal() {
75
+ if (!cachedBinaryPath) {
76
+ cachedBinaryPath = resolveBinaryPath();
77
+ }
78
+ return cachedBinaryPath;
79
+ }
14
80
  function buildArgs(diffOutput, options) {
15
- const args = [diffOutput, "--output-format=json"];
81
+ const args = [];
82
+ if (diffOutput) args.push(diffOutput);
83
+ args.push("--output-format=json");
16
84
  if (!options) return args;
17
- if (options.threshold !== void 0) args.push(`--threshold=${options.threshold}`);
85
+ if (options.threshold !== void 0)
86
+ args.push(`--threshold=${options.threshold}`);
18
87
  if (options.antialiasing) args.push("--antialiasing");
19
88
  if (options.diffMask) args.push("--diff-mask");
20
89
  if (options.failOnLayoutDiff) args.push("--fail-on-layout");
21
- if (options.compression !== void 0) args.push(`--compression=${options.compression}`);
90
+ if (options.compression !== void 0)
91
+ args.push(`--compression=${options.compression}`);
22
92
  return args;
23
93
  }
24
94
  function parseJsonOutput(text) {
@@ -37,9 +107,10 @@ function detectMissingFile(error, basePath, comparePath) {
37
107
  return basePath;
38
108
  }
39
109
  async function compare(basePath, comparePath, diffOutput, options) {
110
+ const binaryPath = getBinaryPathInternal();
40
111
  const args = [basePath, comparePath, ...buildArgs(diffOutput, options)];
41
112
  try {
42
- await execFileAsync(BINARY_PATH, args);
113
+ await execFileAsync(binaryPath, args);
43
114
  return { match: true };
44
115
  } catch (err) {
45
116
  const { code, stdout, stderr } = err;
@@ -71,7 +142,7 @@ async function compare(basePath, comparePath, diffOutput, options) {
71
142
  }
72
143
  }
73
144
  function getBinaryPath() {
74
- return BINARY_PATH;
145
+ return getBinaryPathInternal();
75
146
  }
76
147
  export {
77
148
  compare,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blazediff/bin",
3
- "version": "2.0.1",
3
+ "version": "3.0.0",
4
4
  "description": "Native Rust binaries for blazediff - the fastest image diff in the world",
5
5
  "private": false,
6
6
  "publishConfig": {
@@ -16,15 +16,17 @@
16
16
  "require": "./dist/index.js"
17
17
  }
18
18
  },
19
- "bin": {
20
- "blazediff": "bin/blazediff.exe"
21
- },
22
19
  "files": [
23
- "dist",
24
- "bin",
25
- "binaries",
26
- "post_install.js"
20
+ "dist"
27
21
  ],
22
+ "optionalDependencies": {
23
+ "@blazediff/bin-darwin-arm64": "3.0.0",
24
+ "@blazediff/bin-darwin-x64": "3.0.0",
25
+ "@blazediff/bin-linux-arm64": "3.0.0",
26
+ "@blazediff/bin-linux-x64": "3.0.0",
27
+ "@blazediff/bin-win32-arm64": "3.0.0",
28
+ "@blazediff/bin-win32-x64": "3.0.0"
29
+ },
28
30
  "keywords": [
29
31
  "image",
30
32
  "comparison",
@@ -48,11 +50,7 @@
48
50
  "typescript": "5.9.2"
49
51
  },
50
52
  "scripts": {
51
- "postinstall": "node ./post_install.js",
52
53
  "build": "tsup",
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"
54
+ "clean": "rm -rf dist"
57
55
  }
58
56
  }
package/bin/blazediff.exe DELETED
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
package/post_install.js DELETED
@@ -1,40 +0,0 @@
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
- }