@d-zero/archaeologist 1.1.2 → 1.1.3

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.
@@ -3,5 +3,9 @@ type AnalyzedUrlList = {
3
3
  hasAuth: boolean;
4
4
  hasNoSSL: boolean;
5
5
  };
6
+ /**
7
+ *
8
+ * @param list
9
+ */
6
10
  export declare function analyzeUrlList(list: readonly URLPair[]): AnalyzedUrlList;
7
11
  export {};
@@ -1,3 +1,7 @@
1
+ /**
2
+ *
3
+ * @param list
4
+ */
1
5
  export function analyzeUrlList(list) {
2
6
  const result = {
3
7
  hasAuth: false,
package/dist/analyze.d.ts CHANGED
@@ -6,4 +6,9 @@ export interface AnalyzeOptions {
6
6
  readonly limit?: number;
7
7
  readonly debug?: boolean;
8
8
  }
9
+ /**
10
+ *
11
+ * @param list
12
+ * @param options
13
+ */
9
14
  export declare function analyze(list: readonly URLPair[], options?: AnalyzeOptions): Promise<Result[]>;
package/dist/analyze.js CHANGED
@@ -7,6 +7,11 @@ import { diffImages } from './diff-images.js';
7
7
  import { diffTree } from './diff-tree.js';
8
8
  import { getData } from './get-data.js';
9
9
  import { score } from './output-utils.js';
10
+ /**
11
+ *
12
+ * @param list
13
+ * @param options
14
+ */
10
15
  export async function analyze(list, options) {
11
16
  const results = [];
12
17
  const dir = path.resolve(process.cwd(), '.archaeologist');
@@ -97,6 +102,10 @@ export async function analyze(list, options) {
97
102
  });
98
103
  return results;
99
104
  }
105
+ /**
106
+ *
107
+ * @param ms
108
+ */
100
109
  function delay(ms) {
101
110
  return new Promise((resolve) => setTimeout(resolve, ms));
102
111
  }
@@ -2,4 +2,9 @@ import type { AnalyzeOptions } from './analyze.js';
2
2
  import type { URLPair } from './types.js';
3
3
  export interface ArchaeologistOptions extends AnalyzeOptions {
4
4
  }
5
+ /**
6
+ *
7
+ * @param list
8
+ * @param options
9
+ */
5
10
  export declare function archaeologist(list: readonly URLPair[], options?: ArchaeologistOptions): Promise<void>;
@@ -1,6 +1,11 @@
1
1
  import c from 'ansi-colors';
2
2
  import { analyze } from './analyze.js';
3
3
  import { score } from './output-utils.js';
4
+ /**
5
+ *
6
+ * @param list
7
+ * @param options
8
+ */
4
9
  export async function archaeologist(list, options) {
5
10
  const results = await analyze(list, options);
6
11
  const output = [];
@@ -16,12 +16,18 @@ export type DiffImagesPhase = {
16
16
  };
17
17
  };
18
18
  type DiffImagesListener = (phase: keyof DiffImagesPhase, data: DiffImagesPhase[keyof DiffImagesPhase]) => void;
19
+ /**
20
+ *
21
+ * @param dataA
22
+ * @param dataB
23
+ * @param listener
24
+ */
19
25
  export declare function diffImages(dataA: Screenshot, dataB: Screenshot, listener: DiffImagesListener): Promise<{
20
26
  matches: number;
21
27
  images: {
22
- a: Buffer;
23
- b: Buffer;
24
- diff: Buffer;
28
+ a: Buffer<ArrayBufferLike>;
29
+ b: Buffer<ArrayBufferLike>;
30
+ diff: Buffer<ArrayBufferLike>;
25
31
  };
26
32
  } | null>;
27
33
  export {};
@@ -1,6 +1,12 @@
1
1
  import { Jimp, HorizontalAlign, VerticalAlign, JimpMime } from 'jimp';
2
2
  import pixelmatch from 'pixelmatch';
3
3
  import { PNG } from 'pngjs';
4
+ /**
5
+ *
6
+ * @param dataA
7
+ * @param dataB
8
+ * @param listener
9
+ */
4
10
  export async function diffImages(dataA, dataB, listener) {
5
11
  if (!dataA.binary || !dataB.binary) {
6
12
  return null;
@@ -31,6 +37,12 @@ export async function diffImages(dataA, dataB, listener) {
31
37
  },
32
38
  };
33
39
  }
40
+ /**
41
+ *
42
+ * @param bin
43
+ * @param width
44
+ * @param height
45
+ */
34
46
  async function resizeImg(bin, width, height) {
35
47
  const img = await Jimp.read(bin);
36
48
  img.contain({
@@ -1,3 +1,10 @@
1
+ /**
2
+ *
3
+ * @param urlA
4
+ * @param urlB
5
+ * @param dataA
6
+ * @param dataB
7
+ */
1
8
  export declare function diffTree(urlA: string, urlB: string, dataA: string, dataB: string): {
2
9
  changed: boolean;
3
10
  maxLine: number;
package/dist/diff-tree.js CHANGED
@@ -1,5 +1,12 @@
1
1
  import { createTwoFilesPatch } from 'diff';
2
2
  import parse from 'parse-diff';
3
+ /**
4
+ *
5
+ * @param urlA
6
+ * @param urlB
7
+ * @param dataA
8
+ * @param dataB
9
+ */
3
10
  export function diffTree(urlA, urlB, dataA, dataB) {
4
11
  const result = createTwoFilesPatch(urlA, urlB, dataA, dataB);
5
12
  const info = parse(result)[0];
@@ -0,0 +1,13 @@
1
+ import type { PageData } from './types.js';
2
+ import type { PageHook } from '@d-zero/puppeteer-screenshot';
3
+ export interface FreezeOptions {
4
+ readonly hooks: readonly PageHook[];
5
+ readonly limit?: number;
6
+ readonly debug?: boolean;
7
+ }
8
+ /**
9
+ *
10
+ * @param list
11
+ * @param options
12
+ */
13
+ export declare function freeze(list: readonly string[], options?: FreezeOptions): Promise<PageData[]>;
package/dist/freeze.js ADDED
@@ -0,0 +1,34 @@
1
+ import { mkdir } from 'node:fs/promises';
2
+ import path from 'node:path';
3
+ import { deal } from '@d-zero/puppeteer-dealer';
4
+ import { delay } from '@d-zero/shared/delay';
5
+ import c from 'ansi-colors';
6
+ import { analyzeUrlList } from './analize-url.js';
7
+ import { getData } from './get-data.js';
8
+ /**
9
+ *
10
+ * @param list
11
+ * @param options
12
+ */
13
+ export async function freeze(list, options) {
14
+ const results = [];
15
+ const dir = path.resolve(process.cwd(), '.archaeologist');
16
+ await mkdir(dir, { recursive: true }).catch(() => { });
17
+ const urlInfo = analyzeUrlList(list);
18
+ const useOldMode = urlInfo.hasAuth || urlInfo.hasNoSSL;
19
+ await deal(list.map((url) => ({ id: null, url })), (_, done, total) => {
20
+ return `${c.bold.magenta('🕵️ Archaeologist Freeze❄️')} ${done}/${total}`;
21
+ }, {
22
+ async deal(page, _, url, logger) {
23
+ const data = await getData(page, url, {
24
+ ...options,
25
+ }, logger);
26
+ await delay(600);
27
+ results.push(data);
28
+ },
29
+ }, {
30
+ ...options,
31
+ headless: useOldMode ? 'shell' : true,
32
+ });
33
+ return results;
34
+ }
@@ -5,4 +5,11 @@ export interface GetDataOptions {
5
5
  readonly hooks?: readonly PageHook[];
6
6
  readonly htmlDiffOnly?: boolean;
7
7
  }
8
+ /**
9
+ *
10
+ * @param page
11
+ * @param url
12
+ * @param options
13
+ * @param update
14
+ */
8
15
  export declare function getData(page: Page, url: string, options: GetDataOptions, update: (log: string) => void): Promise<PageData>;
package/dist/get-data.js CHANGED
@@ -1,5 +1,12 @@
1
1
  import { distill } from '@d-zero/html-distiller';
2
2
  import { screenshotListener, screenshot } from '@d-zero/puppeteer-screenshot';
3
+ /**
4
+ *
5
+ * @param page
6
+ * @param url
7
+ * @param options
8
+ * @param update
9
+ */
3
10
  export async function getData(page, url, options, update) {
4
11
  const htmlDiffOnly = options.htmlDiffOnly ?? false;
5
12
  const screenshots = await screenshot(page, url, {
@@ -1 +1,6 @@
1
+ /**
2
+ *
3
+ * @param matches
4
+ * @param threshold
5
+ */
1
6
  export declare function score(matches: number, threshold: number): string;
@@ -1,4 +1,9 @@
1
1
  import c from 'ansi-colors';
2
+ /**
3
+ *
4
+ * @param matches
5
+ * @param threshold
6
+ */
2
7
  export function score(matches, threshold) {
3
8
  const color = matches > threshold ? c.green : c.red;
4
9
  const num = (matches * 100).toFixed(1);
@@ -1,3 +1,7 @@
1
+ /**
2
+ *
3
+ * @param filePath
4
+ */
1
5
  export declare function readConfig(filePath: string): Promise<{
2
6
  pairList: [string, string][];
3
7
  hooks: import("@d-zero/puppeteer-page-scan").PageHook[];
@@ -3,6 +3,10 @@ import path from 'node:path';
3
3
  import { readPageHooks } from '@d-zero/puppeteer-page-scan';
4
4
  import { toList } from '@d-zero/readtext/list';
5
5
  import fm from 'front-matter';
6
+ /**
7
+ *
8
+ * @param filePath
9
+ */
6
10
  export async function readConfig(filePath) {
7
11
  const fileContent = await fs.readFile(filePath, 'utf8');
8
12
  const content =
package/dist/utils.d.ts CHANGED
@@ -1 +1,6 @@
1
+ /**
2
+ *
3
+ * @param matches
4
+ * @param threshold
5
+ */
1
6
  export declare function score(matches: number, threshold: number): string;
package/dist/utils.js CHANGED
@@ -1,4 +1,9 @@
1
1
  import c from 'ansi-colors';
2
+ /**
3
+ *
4
+ * @param matches
5
+ * @param threshold
6
+ */
2
7
  export function score(matches, threshold) {
3
8
  const color = matches > threshold ? c.green : c.red;
4
9
  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.2",
3
+ "version": "1.1.3",
4
4
  "description": "Uncover visual and HTML differences in web pages with precision",
5
5
  "author": "D-ZERO",
6
6
  "license": "MIT",
@@ -27,25 +27,25 @@
27
27
  "clean": "tsc --build --clean"
28
28
  },
29
29
  "dependencies": {
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",
30
+ "@d-zero/html-distiller": "1.0.2",
31
+ "@d-zero/puppeteer-dealer": "0.3.0",
32
+ "@d-zero/puppeteer-page-scan": "3.0.0",
33
+ "@d-zero/puppeteer-screenshot": "3.0.0",
34
+ "@d-zero/readtext": "1.1.2",
35
35
  "ansi-colors": "4.1.3",
36
36
  "diff": "7.0.0",
37
37
  "front-matter": "4.0.2",
38
38
  "jimp": "1.6.0",
39
39
  "minimist": "1.2.8",
40
40
  "parse-diff": "0.11.1",
41
- "pixelmatch": "6.0.0",
41
+ "pixelmatch": "7.1.0",
42
42
  "pngjs": "7.0.0"
43
43
  },
44
44
  "devDependencies": {
45
- "@d-zero/puppeteer-page": "0.2.0",
46
- "@types/diff": "6.0.0",
45
+ "@d-zero/puppeteer-page": "0.3.0",
46
+ "@types/diff": "7.0.1",
47
47
  "@types/pixelmatch": "5.2.6",
48
48
  "@types/pngjs": "6.0.5"
49
49
  },
50
- "gitHead": "1eb1c03400580040119121e11ffb33acd876fe1b"
50
+ "gitHead": "e4fd17857e31022d121527b00fd7f009dbdb2142"
51
51
  }
@@ -1 +0,0 @@
1
- export declare function diffTreeColor(diff: string): string;
@@ -1,15 +0,0 @@
1
- import c from 'ansi-colors';
2
- export function diffTreeColor(diff) {
3
- return diff
4
- .split('\n')
5
- .map((line) => {
6
- if (line.startsWith('+')) {
7
- return c.green(line);
8
- }
9
- if (line.startsWith('-')) {
10
- return c.red(line);
11
- }
12
- return c.gray(line);
13
- })
14
- .join('\n');
15
- }
@@ -1,2 +0,0 @@
1
- import type { PageHook } from '@d-zero/puppeteer-screenshot';
2
- export declare function readHooks(hooks: readonly string[], listfile: string): Promise<PageHook[]>;
@@ -1,20 +0,0 @@
1
- import path from 'node:path';
2
- export async function readHooks(hooks, listfile) {
3
- const listfileDir = path.dirname(listfile);
4
- const pageHooks = await Promise.all(hooks.map(async (hook) => {
5
- const hookAbsPath = path.isAbsolute(hook) ? hook : path.resolve(listfileDir, hook);
6
- const { default: mod } = await import(hookAbsPath).catch((error) => {
7
- if (error instanceof Error &&
8
- 'code' in error &&
9
- error.code === 'ERR_MODULE_NOT_FOUND') {
10
- throw new Error(`Hook: ${hook} not found`, { cause: error });
11
- }
12
- throw error;
13
- });
14
- if (typeof mod !== 'function') {
15
- throw new TypeError(`Hook ${hook} is not a function`);
16
- }
17
- return mod;
18
- }));
19
- return pageHooks;
20
- }