@d-zero/archaeologist 1.1.0 → 1.1.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/analyze.js CHANGED
@@ -37,40 +37,7 @@ export async function analyze(list, options) {
37
37
  for (const url of urlPair) {
38
38
  const data = await getData(page, url, {
39
39
  ...options,
40
- }, (phase, data) => {
41
- const outputUrl = c.gray(url);
42
- const sizeName = label(data.name);
43
- switch (phase) {
44
- case 'setViewport': {
45
- const { width } = data;
46
- update(`%braille% ${outputUrl} ${sizeName}: ↔️ Change viewport size to ${width}px`);
47
- break;
48
- }
49
- case 'load': {
50
- const { type } = data;
51
- update(`%braille% ${outputUrl} ${sizeName}: %earth% ${type === 'open' ? 'Open' : 'Reload'} page`);
52
- break;
53
- }
54
- case 'hook': {
55
- const { message } = data;
56
- update(`%braille% ${outputUrl} ${sizeName}: ${message}`);
57
- break;
58
- }
59
- case 'scroll': {
60
- update(`%braille% ${outputUrl} ${sizeName}: %propeller% Scroll the page`);
61
- break;
62
- }
63
- case 'screenshotStart': {
64
- update(`%braille% ${outputUrl} ${sizeName}: 📸 Take a screenshot`);
65
- break;
66
- }
67
- case 'screenshotEnd': {
68
- const { binary } = data;
69
- update(`%braille% ${outputUrl} ${sizeName}: 📸 Screenshot taken (${binary.length} bytes)`);
70
- break;
71
- }
72
- }
73
- });
40
+ }, update);
74
41
  dataPair.push(data);
75
42
  await delay(600);
76
43
  }
package/dist/cli.js CHANGED
@@ -7,7 +7,7 @@ const cli = minimist(process.argv.slice(2), {
7
7
  f: 'listfile',
8
8
  },
9
9
  });
10
- if (cli.listfile) {
10
+ if (cli.listfile?.length) {
11
11
  const { pairList, hooks } = await readConfig(cli.listfile);
12
12
  await archaeologist(pairList, {
13
13
  hooks,
@@ -17,5 +17,5 @@ if (cli.listfile) {
17
17
  });
18
18
  process.exit(0);
19
19
  }
20
- process.stdout.write('Usage: archaeologist -f <listfile> [--limit <number>]');
20
+ process.stderr.write('Usage: archaeologist -f <listfile> [--limit <number>]\n');
21
21
  process.exit(1);
@@ -1,18 +1,18 @@
1
1
  import type { Screenshot } from '@d-zero/puppeteer-screenshot';
2
2
  export type DiffImagesPhase = {
3
3
  create: {
4
- a: Buffer;
5
- b: Buffer;
4
+ a: Uint8Array;
5
+ b: Uint8Array;
6
6
  };
7
7
  resize: {
8
- a: Buffer;
9
- b: Buffer;
8
+ a: Uint8Array;
9
+ b: Uint8Array;
10
10
  width: number;
11
11
  height: number;
12
12
  };
13
13
  diff: {
14
- a: Buffer;
15
- b: Buffer;
14
+ a: Uint8Array;
15
+ b: Uint8Array;
16
16
  };
17
17
  };
18
18
  type DiffImagesListener = (phase: keyof DiffImagesPhase, data: DiffImagesPhase[keyof DiffImagesPhase]) => void;
@@ -1,4 +1,4 @@
1
- import Jimp from 'jimp';
1
+ import { Jimp, HorizontalAlign, VerticalAlign, JimpMime } from 'jimp';
2
2
  import pixelmatch from 'pixelmatch';
3
3
  import { PNG } from 'pngjs';
4
4
  export async function diffImages(dataA, dataB, listener) {
@@ -6,13 +6,13 @@ export async function diffImages(dataA, dataB, listener) {
6
6
  return null;
7
7
  }
8
8
  listener('create', { a: dataA.binary, b: dataB.binary });
9
- const imgA = PNG.sync.read(dataA.binary);
10
- const imgB = PNG.sync.read(dataB.binary);
9
+ const imgA = PNG.sync.read(Buffer.from(dataA.binary));
10
+ const imgB = PNG.sync.read(Buffer.from(dataB.binary));
11
11
  const width = Math.max(imgA.width, imgB.width);
12
12
  const height = Math.max(imgA.height, imgB.height);
13
13
  listener('resize', { a: dataA.binary, b: dataB.binary, width, height });
14
- const resizedA = await resizeImg(dataA.binary, width, height);
15
- const resizedB = await resizeImg(dataB.binary, width, height);
14
+ const resizedA = await resizeImg(Buffer.from(dataA.binary), width, height);
15
+ const resizedB = await resizeImg(Buffer.from(dataB.binary), width, height);
16
16
  listener('diff', { a: resizedA, b: resizedB });
17
17
  const imgA_ = PNG.sync.read(resizedA);
18
18
  const imgB_ = PNG.sync.read(resizedB);
@@ -33,12 +33,10 @@ export async function diffImages(dataA, dataB, listener) {
33
33
  }
34
34
  async function resizeImg(bin, width, height) {
35
35
  const img = await Jimp.read(bin);
36
- img.contain(width, height, Jimp.HORIZONTAL_ALIGN_LEFT | Jimp.VERTICAL_ALIGN_TOP);
37
- return new Promise((resolve, reject) => {
38
- img.getBuffer(Jimp.MIME_PNG, (err, buffer) => {
39
- if (err)
40
- reject(err);
41
- resolve(buffer);
42
- });
36
+ img.contain({
37
+ w: width,
38
+ h: height,
39
+ align: HorizontalAlign.LEFT | VerticalAlign.TOP,
43
40
  });
41
+ return img.getBuffer(JimpMime.png);
44
42
  }
@@ -1,8 +1,8 @@
1
1
  import type { PageData } from './types.js';
2
- import type { Listener, PageHook } from '@d-zero/puppeteer-screenshot';
2
+ import type { PageHook } from '@d-zero/puppeteer-screenshot';
3
3
  import type { Page } from 'puppeteer';
4
4
  export interface GetDataOptions {
5
5
  readonly hooks?: readonly PageHook[];
6
6
  readonly htmlDiffOnly?: boolean;
7
7
  }
8
- export declare function getData(page: Page, url: string, options: GetDataOptions, listener: Listener): Promise<PageData>;
8
+ export declare function getData(page: Page, url: string, options: GetDataOptions, update: (log: string) => void): Promise<PageData>;
package/dist/get-data.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { distill } from '@d-zero/html-distiller';
2
- import { screenshot } from '@d-zero/puppeteer-screenshot';
3
- export async function getData(page, url, options, listener) {
2
+ import { screenshotListener, screenshot } from '@d-zero/puppeteer-screenshot';
3
+ export async function getData(page, url, options, update) {
4
4
  const htmlDiffOnly = options.htmlDiffOnly ?? false;
5
5
  const screenshots = await screenshot(page, url, {
6
6
  sizes: {
@@ -13,7 +13,7 @@ export async function getData(page, url, options, listener) {
13
13
  },
14
14
  },
15
15
  hooks: options?.hooks ?? [],
16
- listener,
16
+ listener: screenshotListener(update),
17
17
  domOnly: htmlDiffOnly,
18
18
  });
19
19
  const data = { url, screenshots: {} };
@@ -1,4 +1,4 @@
1
1
  export declare function readConfig(filePath: string): Promise<{
2
2
  pairList: [string, string][];
3
- hooks: import("@d-zero/puppeteer-screenshot").PageHook[];
3
+ hooks: import("@d-zero/puppeteer-page-scan").PageHook[];
4
4
  }>;
@@ -1,7 +1,8 @@
1
1
  import fs from 'node:fs/promises';
2
+ import path from 'node:path';
3
+ import { readPageHooks } from '@d-zero/puppeteer-page-scan';
2
4
  import { toList } from '@d-zero/readtext/list';
3
5
  import fm from 'front-matter';
4
- import { readHooks } from './read-hooks.js';
5
6
  export async function readConfig(filePath) {
6
7
  const fileContent = await fs.readFile(filePath, 'utf8');
7
8
  const content =
@@ -15,7 +16,8 @@ export async function readConfig(filePath) {
15
16
  `${content.attributes.comparisonHost}${url.pathname}${url.search}`,
16
17
  ];
17
18
  });
18
- const hooks = await readHooks(content.attributes?.hooks ?? [], filePath);
19
+ const baseDir = path.dirname(filePath);
20
+ const hooks = await readPageHooks(content.attributes?.hooks ?? [], baseDir);
19
21
  return {
20
22
  pairList,
21
23
  hooks,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@d-zero/archaeologist",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "Uncover visual and HTML differences in web pages with precision",
5
5
  "author": "D-ZERO",
6
6
  "license": "MIT",
@@ -26,25 +26,25 @@
26
26
  "clean": "tsc --build --clean"
27
27
  },
28
28
  "dependencies": {
29
- "@d-zero/dealer": "1.0.2",
29
+ "@d-zero/dealer": "1.1.0",
30
30
  "@d-zero/html-distiller": "1.0.0",
31
- "@d-zero/puppeteer-screenshot": "1.1.0",
32
- "@d-zero/readtext": "1.0.3",
31
+ "@d-zero/puppeteer-page-scan": "1.0.0",
32
+ "@d-zero/puppeteer-screenshot": "1.2.0",
33
+ "@d-zero/readtext": "1.1.0",
33
34
  "ansi-colors": "4.1.3",
34
- "diff": "5.2.0",
35
+ "diff": "7.0.0",
35
36
  "front-matter": "4.0.2",
36
- "jimp": "0.22.12",
37
+ "jimp": "1.6.0",
37
38
  "minimist": "1.2.8",
38
39
  "parse-diff": "0.11.1",
39
- "pixelmatch": "5.3.0",
40
+ "pixelmatch": "6.0.0",
40
41
  "pngjs": "7.0.0",
41
- "puppeteer": "22.12.0"
42
+ "puppeteer": "23.5.0"
42
43
  },
43
44
  "devDependencies": {
44
- "@types/diff": "5.2.1",
45
+ "@types/diff": "5.2.2",
45
46
  "@types/pixelmatch": "5.2.6",
46
- "@types/pngjs": "6.0.5",
47
- "puppeteer": "22.12.0"
47
+ "@types/pngjs": "6.0.5"
48
48
  },
49
- "gitHead": "9b4c167933f33237bb688e4835f17b499dc4c48d"
49
+ "gitHead": "e8f65086bf7c316dda6667f1173da8585a5ef19c"
50
50
  }