@u1f992/pdfdiff 0.3.0 → 0.3.1

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
@@ -36665,7 +36665,7 @@ function sliceBackingBuffer(src) {
36665
36665
  return src.buffer.slice(src.byteOffset, src.byteOffset + src.byteLength);
36666
36666
  }
36667
36667
 
36668
- const VERSION = "0.3.0";
36668
+ const VERSION = "0.3.1";
36669
36669
 
36670
36670
  // Default parallelism scales with the machine: rendering and diffing run across
36671
36671
  // several workers, so the out-of-the-box run uses the CPU rather than a single
@@ -36832,7 +36832,11 @@ async function* visualizeDifferences(a, b, options) {
36832
36832
  let aborted = null;
36833
36833
  const makeSlots = (count) => Array.from({ length: maxPages }, (_, i) => {
36834
36834
  if (i >= count) {
36835
- return { p: Promise.resolve(null), resolve: () => { }, reject: () => { } };
36835
+ return {
36836
+ p: Promise.resolve(null),
36837
+ resolve: () => { },
36838
+ reject: () => { },
36839
+ };
36836
36840
  }
36837
36841
  let resolve;
36838
36842
  let reject;
@@ -37012,8 +37016,18 @@ class PngWriterPool {
37012
37016
  await Promise.all(this.workers.map((w) => w.terminate()));
37013
37017
  }
37014
37018
  }
37019
+ // Errors always exit 2, following diff(1)'s 0/1/2 convention, so that with
37020
+ // --exit-code a caller can tell "differences found" (1) from a failed run.
37021
+ process.on("uncaughtException", (err) => {
37022
+ console.error(err);
37023
+ process.exit(2);
37024
+ });
37025
+ process.on("unhandledRejection", (err) => {
37026
+ console.error(err);
37027
+ process.exit(2);
37028
+ });
37015
37029
  const _wallSpan = perf.span("cli.wallTotal_ms");
37016
- const { positionals, values: { dpi: dpi_, alpha: alpha_, mask: mask_, align: align_, "addition-color": additionColorHex, "deletion-color": deletionColorHex, "modification-color": modificationColorHex, workers: workers_, version, help, }, } = util$2.parseArgs({
37030
+ const { positionals, values: { dpi: dpi_, alpha: alpha_, mask: mask_, align: align_, "addition-color": additionColorHex, "deletion-color": deletionColorHex, "modification-color": modificationColorHex, workers: workers_, "exit-code": exitCode_, version, help, }, } = util$2.parseArgs({
37017
37031
  allowPositionals: true,
37018
37032
  options: {
37019
37033
  dpi: { type: "string" },
@@ -37024,6 +37038,7 @@ const { positionals, values: { dpi: dpi_, alpha: alpha_, mask: mask_, align: ali
37024
37038
  "deletion-color": { type: "string" },
37025
37039
  "modification-color": { type: "string" },
37026
37040
  workers: { type: "string" },
37041
+ "exit-code": { type: "boolean" },
37027
37042
  version: { type: "boolean", short: "v" },
37028
37043
  help: { type: "boolean", short: "h" },
37029
37044
  },
@@ -37043,9 +37058,15 @@ OPTIONS:
37043
37058
  --deletion-color <#HEX> default: ${formatHex(defaultOptions.pallet.deletion)}
37044
37059
  --modification-color <#HEX> default: ${formatHex(defaultOptions.pallet.modification)}
37045
37060
  --workers <N> default: ${defaultOptions.workers}
37061
+ --exit-code exit 1 if differences are found
37046
37062
  -v, --version
37047
37063
  -h, --help
37048
37064
 
37065
+ EXIT STATUS:
37066
+ 0 success (with --exit-code: no differences found)
37067
+ 1 differences found (only with --exit-code)
37068
+ 2 error
37069
+
37049
37070
  NOTES:
37050
37071
  Pages are rendered with Ghostscript (gs-wasm). Each page render spins up a
37051
37072
  transient Ghostscript instance (~26 MB WASM binary plus a rasterization
@@ -37101,9 +37122,11 @@ const workers = typeof workers_ !== "undefined"
37101
37122
  if (Number.isNaN(workers) || workers < 1) {
37102
37123
  throw new Error("Invalid workers value");
37103
37124
  }
37125
+ const exitCodeOnDiff = exitCode_ ?? false;
37104
37126
  fs.mkdirSync(outDir, { recursive: true });
37105
37127
  const writerPool = new PngWriterPool(workers, new URL("./cli-png-worker.js", import.meta.url));
37106
37128
  const pendingWrites = [];
37129
+ let hasDiff = false;
37107
37130
  const _loopSpan = perf.span("cli.loopWall_ms");
37108
37131
  for await (const [i, { a, b, diff, addition, deletion, modification },] of withIndex(visualizeDifferences(pdfA, pdfB, {
37109
37132
  dpi,
@@ -37118,6 +37141,9 @@ for await (const [i, { a, b, diff, addition, deletion, modification },] of withI
37118
37141
  workers,
37119
37142
  }), 1)) {
37120
37143
  console.log(`Page ${i}, Addition: ${addition.length}, Deletion: ${deletion.length}, Modification: ${modification.length}`);
37144
+ if (addition.length > 0 || deletion.length > 0 || modification.length > 0) {
37145
+ hasDiff = true;
37146
+ }
37121
37147
  const dir = path.join(outDir, i.toString(10));
37122
37148
  fs.mkdirSync(dir, { recursive: true });
37123
37149
  const sSubmit = perf.span("cli.poolSubmit_ms");
@@ -37148,6 +37174,9 @@ sDrain.stop();
37148
37174
  await writerPool.terminate();
37149
37175
  _loopSpan.stop();
37150
37176
  _wallSpan.stop();
37177
+ if (exitCodeOnDiff && hasDiff) {
37178
+ process.exitCode = 1;
37179
+ }
37151
37180
  if (perf.enabled) {
37152
37181
  const counters = perf.dump();
37153
37182
  process.stderr.write("\n=== PERF ===\n");