@d-zero/archaeologist 1.1.1 → 1.1.2

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
@@ -1,43 +1,31 @@
1
1
  import { writeFile, mkdir } from 'node:fs/promises';
2
2
  import path from 'node:path';
3
- import { deal } from '@d-zero/dealer';
3
+ import { deal } from '@d-zero/puppeteer-dealer';
4
4
  import c from 'ansi-colors';
5
- import puppeteer from 'puppeteer';
6
5
  import { analyzeUrlList } from './analize-url.js';
7
6
  import { diffImages } from './diff-images.js';
8
7
  import { diffTree } from './diff-tree.js';
9
8
  import { getData } from './get-data.js';
10
- import { label, score } from './output-utils.js';
9
+ import { score } from './output-utils.js';
11
10
  export async function analyze(list, options) {
12
- const urlInfo = analyzeUrlList(list);
13
- const useOldMode = urlInfo.hasAuth && urlInfo.hasNoSSL;
14
- const browser = await puppeteer.launch({
15
- headless: useOldMode ? 'shell' : true,
16
- args: [
17
- //
18
- '--lang=ja',
19
- '--no-zygote',
20
- '--ignore-certificate-errors',
21
- ],
22
- });
23
11
  const results = [];
24
12
  const dir = path.resolve(process.cwd(), '.archaeologist');
25
13
  await mkdir(dir, { recursive: true }).catch(() => { });
26
- await deal(list,
27
- //
28
- async (urlPair, update, index) => {
29
- const page = await browser.newPage();
30
- page.setDefaultNavigationTimeout(0);
31
- await page.setUserAgent('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36');
32
- await page.setExtraHTTPHeaders({
33
- 'Accept-Language': 'ja-JP',
34
- });
35
- return async () => {
14
+ const urlInfo = analyzeUrlList(list);
15
+ const useOldMode = urlInfo.hasAuth || urlInfo.hasNoSSL;
16
+ await deal(list.map(([urlA]) => ({ id: null, url: urlA })), (_, done, total) => {
17
+ return `${c.bold.magenta('🕵️ Archaeologist')} ${done}/${total}`;
18
+ }, {
19
+ async deal(page, _, urlA, logger, index) {
20
+ const urlPair = list.find(([url]) => url === urlA);
21
+ if (!urlPair) {
22
+ throw new Error(`Failed to find urlPair: ${urlA}`);
23
+ }
36
24
  const dataPair = [];
37
25
  for (const url of urlPair) {
38
26
  const data = await getData(page, url, {
39
27
  ...options,
40
- }, update);
28
+ }, logger);
41
29
  dataPair.push(data);
42
30
  await delay(600);
43
31
  }
@@ -46,10 +34,10 @@ export async function analyze(list, options) {
46
34
  throw new Error('Failed to get screenshots');
47
35
  }
48
36
  const screenshotResult = {};
49
- const outputUrl = c.gray(urlPair.join(' vs '));
37
+ const outputUrl = 'vs ' + c.gray(urlPair[1]);
50
38
  for (const [name, screenshotA] of Object.entries(a.screenshots)) {
51
39
  const screenshotB = b.screenshots[name];
52
- const sizeName = label(name);
40
+ const sizeName = c.bgMagenta(` ${name} `);
53
41
  const id = `${index}_${name}`;
54
42
  if (!screenshotB) {
55
43
  throw new Error(`Failed to get screenshotB: ${id}`);
@@ -57,28 +45,28 @@ export async function analyze(list, options) {
57
45
  const imageDiff = await diffImages(screenshotA, screenshotB, (phase, data) => {
58
46
  switch (phase) {
59
47
  case 'create': {
60
- update(`%braille% ${outputUrl} ${sizeName}: 🖼️ Create images`);
48
+ logger(`${sizeName} ${outputUrl} 🖼️ Create images`);
61
49
  break;
62
50
  }
63
51
  case 'resize': {
64
52
  const { width, height } = data;
65
- update(`%braille% ${outputUrl} ${sizeName}: ↔️ Resize images to ${width}x${height}`);
53
+ logger(`${sizeName} ${outputUrl} ↔️ Resize images to ${width}x${height}`);
66
54
  break;
67
55
  }
68
56
  case 'diff': {
69
- update(`%braille% ${outputUrl} ${sizeName}: 📊 Compare images`);
57
+ logger(`${sizeName} ${outputUrl} 📊 Compare images`);
70
58
  break;
71
59
  }
72
60
  }
73
61
  });
74
62
  let image = null;
75
63
  if (imageDiff) {
76
- update(`%braille% ${outputUrl} ${sizeName}: 🧩 Matches ${score(imageDiff.matches, 0.9)}`);
64
+ logger(`${sizeName} ${outputUrl} 🧩 Matches ${score(imageDiff.matches, 0.9)}`);
77
65
  await delay(1500);
78
66
  await writeFile(path.resolve(dir, `${id}_a.png`), imageDiff.images.a);
79
67
  await writeFile(path.resolve(dir, `${id}_b.png`), imageDiff.images.b);
80
68
  const outFilePath = path.resolve(dir, `${id}_diff.png`);
81
- update(`%braille% ${outputUrl} ${sizeName}: 📊 Save diff image to ${path.relative(dir, outFilePath)}`);
69
+ logger(`${sizeName} ${outputUrl} 📊 Save diff image to ${path.relative(dir, outFilePath)}`);
82
70
  await writeFile(outFilePath, imageDiff.images.diff);
83
71
  image = {
84
72
  matches: imageDiff.matches,
@@ -102,15 +90,11 @@ export async function analyze(list, options) {
102
90
  screenshots: screenshotResult,
103
91
  };
104
92
  results.push(result);
105
- };
106
- }, {
107
- limit: options?.limit,
108
- debug: options?.debug,
109
- header(_, done, total) {
110
- return `${c.bold.magenta('🕵️ Archaeologist')} ${done}/${total}`;
111
93
  },
94
+ }, {
95
+ ...options,
96
+ headless: useOldMode ? 'shell' : true,
112
97
  });
113
- await browser.close();
114
98
  return results;
115
99
  }
116
100
  function delay(ms) {
@@ -1,6 +1,6 @@
1
1
  import c from 'ansi-colors';
2
2
  import { analyze } from './analyze.js';
3
- import { label, score } from './output-utils.js';
3
+ import { score } from './output-utils.js';
4
4
  export async function archaeologist(list, options) {
5
5
  const results = await analyze(list, options);
6
6
  const output = [];
@@ -9,9 +9,9 @@ export async function archaeologist(list, options) {
9
9
  for (const [sizeName, { image, dom }] of Object.entries(result.screenshots)) {
10
10
  if (image) {
11
11
  const { matches, file } = image;
12
- output.push(` ${label(sizeName)} ${score(matches, 0.9)} ${file}`);
12
+ output.push(` ${c.bgMagenta(` ${sizeName} `)} ${score(matches, 0.9)} ${file}`);
13
13
  }
14
- output.push(` ${label('HTML', c.bgBlueBright)}: ${score(dom.matches, 0.995)} ${dom.file}`);
14
+ output.push(` ${c.bgBlueBright(' HTML ')}: ${score(dom.matches, 0.995)} ${dom.file}`);
15
15
  }
16
16
  }
17
17
  process.stdout.write(output.join('\n') + '\n');
@@ -1,6 +1,6 @@
1
1
  import type { PageData } from './types.js';
2
+ import type { Page } from '@d-zero/puppeteer-page';
2
3
  import type { PageHook } from '@d-zero/puppeteer-screenshot';
3
- import type { Page } from 'puppeteer';
4
4
  export interface GetDataOptions {
5
5
  readonly hooks?: readonly PageHook[];
6
6
  readonly htmlDiffOnly?: boolean;
@@ -1,3 +1 @@
1
- import c from 'ansi-colors';
2
- export declare function label(str: string, color?: c.StyleFunction): string;
3
1
  export declare function score(matches: number, threshold: number): string;
@@ -1,7 +1,4 @@
1
1
  import c from 'ansi-colors';
2
- export function label(str, color = c.bgMagenta) {
3
- return color(` ${str} `);
4
- }
5
2
  export function score(matches, threshold) {
6
3
  const color = matches > threshold ? c.green : c.red;
7
4
  const num = (matches * 100).toFixed(1);
package/dist/utils.d.ts CHANGED
@@ -1,2 +1 @@
1
- export declare function label(str: string): string;
2
1
  export declare function score(matches: number, threshold: number): string;
package/dist/utils.js CHANGED
@@ -1,7 +1,4 @@
1
1
  import c from 'ansi-colors';
2
- export function label(str) {
3
- return c.bgMagenta(` ${str} `);
4
- }
5
2
  export function score(matches, threshold) {
6
3
  const color = matches > threshold ? c.green : c.red;
7
4
  const num = (matches * 100).toFixed(1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@d-zero/archaeologist",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "description": "Uncover visual and HTML differences in web pages with precision",
5
5
  "author": "D-ZERO",
6
6
  "license": "MIT",
@@ -23,14 +23,15 @@
23
23
  ],
24
24
  "scripts": {
25
25
  "build": "tsc",
26
+ "watch": "tsc --watch",
26
27
  "clean": "tsc --build --clean"
27
28
  },
28
29
  "dependencies": {
29
- "@d-zero/dealer": "1.1.0",
30
- "@d-zero/html-distiller": "1.0.0",
31
- "@d-zero/puppeteer-page-scan": "1.0.0",
32
- "@d-zero/puppeteer-screenshot": "1.2.0",
33
- "@d-zero/readtext": "1.1.0",
30
+ "@d-zero/html-distiller": "1.0.1",
31
+ "@d-zero/puppeteer-dealer": "0.2.0",
32
+ "@d-zero/puppeteer-page-scan": "2.0.0",
33
+ "@d-zero/puppeteer-screenshot": "2.0.0",
34
+ "@d-zero/readtext": "1.1.1",
34
35
  "ansi-colors": "4.1.3",
35
36
  "diff": "7.0.0",
36
37
  "front-matter": "4.0.2",
@@ -38,13 +39,13 @@
38
39
  "minimist": "1.2.8",
39
40
  "parse-diff": "0.11.1",
40
41
  "pixelmatch": "6.0.0",
41
- "pngjs": "7.0.0",
42
- "puppeteer": "23.5.0"
42
+ "pngjs": "7.0.0"
43
43
  },
44
44
  "devDependencies": {
45
- "@types/diff": "5.2.2",
45
+ "@d-zero/puppeteer-page": "0.2.0",
46
+ "@types/diff": "6.0.0",
46
47
  "@types/pixelmatch": "5.2.6",
47
48
  "@types/pngjs": "6.0.5"
48
49
  },
49
- "gitHead": "e8f65086bf7c316dda6667f1173da8585a5ef19c"
50
+ "gitHead": "1eb1c03400580040119121e11ffb33acd876fe1b"
50
51
  }