@argos-ci/util 3.2.1-alpha.19 → 3.4.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/browser.d.mts +2 -0
- package/dist/browser.mjs +2 -0
- package/dist/{index.d.ts → index.d.mts} +12 -8
- package/dist/index.mjs +103 -0
- package/dist/threshold-BUYeKTxB.d.mts +78 -0
- package/dist/threshold-BxFlev7-.mjs +46 -0
- package/package.json +9 -9
- package/dist/browser.d.ts +0 -101
- package/dist/browser.js +0 -10
- package/dist/chunk-TTRT2C3N.js +0 -41
- package/dist/index.js +0 -113
package/dist/browser.mjs
ADDED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ScreenshotMetadata } from
|
|
2
|
-
export { getMetadataPath, getScreenshotName, validateThreshold } from './browser.js';
|
|
1
|
+
import { i as getMetadataPath, n as getScreenshotName, r as ScreenshotMetadata, t as validateThreshold } from "./threshold-BUYeKTxB.mjs";
|
|
3
2
|
|
|
3
|
+
//#region src/fs.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* Create a directory if it doesn't exist.
|
|
6
6
|
*/
|
|
@@ -9,17 +9,20 @@ declare function createDirectory(pathname: string): Promise<void>;
|
|
|
9
9
|
* Create temporary directory.
|
|
10
10
|
*/
|
|
11
11
|
declare function createTemporaryDirectory(): Promise<string>;
|
|
12
|
-
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region src/git.d.ts
|
|
13
14
|
/**
|
|
14
15
|
* Get the top level of the git repository.
|
|
15
16
|
*/
|
|
16
17
|
declare function getGitRepositoryPath(): Promise<string | null>;
|
|
17
|
-
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/introspection.d.ts
|
|
18
20
|
/**
|
|
19
21
|
* Read the version from a package.json file.
|
|
20
22
|
*/
|
|
21
23
|
declare function readVersionFromPackage(pkgPath: string): Promise<string>;
|
|
22
|
-
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region src/metadata-io.d.ts
|
|
23
26
|
/**
|
|
24
27
|
* Write screenshot metadata to disk.
|
|
25
28
|
*/
|
|
@@ -29,11 +32,12 @@ declare function writeMetadata(screenshotPath: string, metadata: ScreenshotMetad
|
|
|
29
32
|
* If not found, returns null.
|
|
30
33
|
*/
|
|
31
34
|
declare function readMetadata(screenshotPath: string): Promise<ScreenshotMetadata | null>;
|
|
32
|
-
|
|
35
|
+
//#endregion
|
|
36
|
+
//#region src/playwright-trace.d.ts
|
|
33
37
|
/**
|
|
34
38
|
* Get playwright trace from screenshot path.
|
|
35
39
|
* If not found, returns null.
|
|
36
40
|
*/
|
|
37
41
|
declare function getPlaywrightTracePath(screenshotPath: string): Promise<string | null>;
|
|
38
|
-
|
|
39
|
-
export { ScreenshotMetadata, createDirectory, createTemporaryDirectory, getGitRepositoryPath, getPlaywrightTracePath, readMetadata, readVersionFromPackage, writeMetadata };
|
|
42
|
+
//#endregion
|
|
43
|
+
export { ScreenshotMetadata, createDirectory, createTemporaryDirectory, getGitRepositoryPath, getMetadataPath, getPlaywrightTracePath, getScreenshotName, readMetadata, readVersionFromPackage, validateThreshold, writeMetadata };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { n as getScreenshotName, r as getMetadataPath, t as validateThreshold } from "./threshold-BxFlev7-.mjs";
|
|
2
|
+
import { randomBytes } from "node:crypto";
|
|
3
|
+
import { access, mkdir, readFile, writeFile } from "node:fs/promises";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
import { exec } from "node:child_process";
|
|
7
|
+
//#region src/fs.ts
|
|
8
|
+
const createDirectoryPromises = /* @__PURE__ */ new Map();
|
|
9
|
+
/**
|
|
10
|
+
* Create a directory if it doesn't exist.
|
|
11
|
+
*/
|
|
12
|
+
async function createDirectory(pathname) {
|
|
13
|
+
let promise = createDirectoryPromises.get(pathname);
|
|
14
|
+
if (promise) return promise;
|
|
15
|
+
promise = mkdir(pathname, { recursive: true }).then(() => {});
|
|
16
|
+
createDirectoryPromises.set(pathname, promise);
|
|
17
|
+
return promise;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Create temporary directory.
|
|
21
|
+
*/
|
|
22
|
+
async function createTemporaryDirectory() {
|
|
23
|
+
const path = join(tmpdir(), "argos." + randomBytes(16).toString("hex"));
|
|
24
|
+
await createDirectory(path);
|
|
25
|
+
return path;
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
//#region src/git.ts
|
|
29
|
+
let cached;
|
|
30
|
+
/**
|
|
31
|
+
* Get the top level of the git repository.
|
|
32
|
+
*/
|
|
33
|
+
function getGitRepositoryPath() {
|
|
34
|
+
if (!cached) cached = new Promise((resolve) => {
|
|
35
|
+
exec("git rev-parse --show-toplevel", (error, stdout, stderr) => {
|
|
36
|
+
if (error) resolve(null);
|
|
37
|
+
if (stderr) resolve(null);
|
|
38
|
+
resolve(stdout.trim());
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
return cached;
|
|
42
|
+
}
|
|
43
|
+
//#endregion
|
|
44
|
+
//#region src/introspection.ts
|
|
45
|
+
const versionCache = /* @__PURE__ */ new Map();
|
|
46
|
+
/**
|
|
47
|
+
* Read the version from a package.json file.
|
|
48
|
+
*/
|
|
49
|
+
function readVersionFromPackage(pkgPath) {
|
|
50
|
+
const readVersion = async () => {
|
|
51
|
+
const { version } = JSON.parse(await readFile(pkgPath, "utf-8"));
|
|
52
|
+
if (typeof version !== "string") throw new Error("Invalid version");
|
|
53
|
+
return version;
|
|
54
|
+
};
|
|
55
|
+
if (!versionCache.has(pkgPath)) versionCache.set(pkgPath, readVersion());
|
|
56
|
+
const fromCache = versionCache.get(pkgPath);
|
|
57
|
+
if (!fromCache) throw new Error("Invariant violation: version not in cache");
|
|
58
|
+
return fromCache;
|
|
59
|
+
}
|
|
60
|
+
//#endregion
|
|
61
|
+
//#region src/metadata-io.ts
|
|
62
|
+
/**
|
|
63
|
+
* Write screenshot metadata to disk.
|
|
64
|
+
*/
|
|
65
|
+
async function writeMetadata(screenshotPath, metadata) {
|
|
66
|
+
await writeFile(getMetadataPath(screenshotPath), JSON.stringify(metadata));
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Read screenshot metadata from disk.
|
|
70
|
+
* If not found, returns null.
|
|
71
|
+
*/
|
|
72
|
+
async function readMetadata(screenshotPath) {
|
|
73
|
+
try {
|
|
74
|
+
const metadata = await readFile(getMetadataPath(screenshotPath), "utf8");
|
|
75
|
+
return JSON.parse(metadata);
|
|
76
|
+
} catch (error) {
|
|
77
|
+
if (error instanceof Error && "code" in error && error.code === "ENOENT") return null;
|
|
78
|
+
throw new Error("Failed to read metadata", { cause: error });
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
//#endregion
|
|
82
|
+
//#region src/playwright-trace.ts
|
|
83
|
+
/**
|
|
84
|
+
* Get trace path from screenshot path.
|
|
85
|
+
*/
|
|
86
|
+
function getTracePath(screenshotPath) {
|
|
87
|
+
return screenshotPath + ".pw-trace.zip";
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Get playwright trace from screenshot path.
|
|
91
|
+
* If not found, returns null.
|
|
92
|
+
*/
|
|
93
|
+
async function getPlaywrightTracePath(screenshotPath) {
|
|
94
|
+
try {
|
|
95
|
+
const tracePath = getTracePath(screenshotPath);
|
|
96
|
+
await access(tracePath);
|
|
97
|
+
return tracePath;
|
|
98
|
+
} catch {
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
//#endregion
|
|
103
|
+
export { createDirectory, createTemporaryDirectory, getGitRepositoryPath, getMetadataPath, getPlaywrightTracePath, getScreenshotName, readMetadata, readVersionFromPackage, validateThreshold, writeMetadata };
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
//#region src/metadata.d.ts
|
|
2
|
+
type ScreenshotMetadata = {
|
|
3
|
+
/** @description The URL of the page that was screenshotted */url?: string | null; /** @description An URL to an accessible preview of the screenshot */
|
|
4
|
+
previewUrl?: string | null;
|
|
5
|
+
viewport?: {
|
|
6
|
+
/** @description The width of the viewport */width: number; /** @description The height of the viewport */
|
|
7
|
+
height: number;
|
|
8
|
+
} | null; /** @description The color scheme when the screenshot was taken */
|
|
9
|
+
colorScheme?: ("light" | "dark") | null; /** @description The media type when the screenshot was taken */
|
|
10
|
+
mediaType?: ("screen" | "print") | null; /** @description Tags associated with the screenshot */
|
|
11
|
+
tags?: string[];
|
|
12
|
+
test?: ({
|
|
13
|
+
/** @description The unique identifier of the test */id?: string | null; /** @description The title of the test */
|
|
14
|
+
title: string; /** @description The path of titles leading to the test */
|
|
15
|
+
titlePath: string[]; /** @description Tags associated with the test */
|
|
16
|
+
tags?: string[]; /** @description The number of retries for the test */
|
|
17
|
+
retries?: number | null; /** @description The current retry count */
|
|
18
|
+
retry?: number | null; /** @description The repeat count for the test */
|
|
19
|
+
repeat?: number | null; /** @description The location of the test in the source code */
|
|
20
|
+
location?: {
|
|
21
|
+
/** @description The located file */file: string; /** @description The line number in the file */
|
|
22
|
+
line: number; /** @description The column number in the file */
|
|
23
|
+
column: number;
|
|
24
|
+
}; /** @description Annotations associated to the test */
|
|
25
|
+
annotations?: {
|
|
26
|
+
/** @description The type of annotation */type: string; /** @description The description of the annotation */
|
|
27
|
+
description?: string; /** @description The location of the annotation in the source code */
|
|
28
|
+
location?: {
|
|
29
|
+
/** @description The located file */file: string; /** @description The line number in the file */
|
|
30
|
+
line: number; /** @description The column number in the file */
|
|
31
|
+
column: number;
|
|
32
|
+
};
|
|
33
|
+
}[];
|
|
34
|
+
} | null) | null;
|
|
35
|
+
story?: {
|
|
36
|
+
/** @description Unique ID of the story */id: string; /** @description Tags attached to the story */
|
|
37
|
+
tags: string[]; /** @description Story mode */
|
|
38
|
+
mode?: string; /** @description True if the story has a play function */
|
|
39
|
+
play?: boolean;
|
|
40
|
+
};
|
|
41
|
+
browser?: {
|
|
42
|
+
/** @description The name of the browser */name: string; /** @description The version of the browser */
|
|
43
|
+
version: string;
|
|
44
|
+
} | null; /** @description The automation library that generated the screenshot */
|
|
45
|
+
automationLibrary: {
|
|
46
|
+
/** @description The name of the automation library */name: string; /** @description The version of the automation library */
|
|
47
|
+
version: string;
|
|
48
|
+
}; /** @description The Argos SDK that generated the screenshot */
|
|
49
|
+
sdk: {
|
|
50
|
+
/** @description The name of the Argos SDK */name: string; /** @description The version of the Argos SDK */
|
|
51
|
+
version: string;
|
|
52
|
+
};
|
|
53
|
+
transient?: {
|
|
54
|
+
/** Threshold configured for this screenshot. */threshold?: number; /** Override the name to find the comparison baseline. */
|
|
55
|
+
baseName?: string; /** Name of the parent screenshot. */
|
|
56
|
+
parentName?: string;
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Get metadata path from snapshot path.
|
|
61
|
+
*/
|
|
62
|
+
declare function getMetadataPath(snapshotPath: string): string;
|
|
63
|
+
//#endregion
|
|
64
|
+
//#region src/name.d.ts
|
|
65
|
+
/**
|
|
66
|
+
* Build a screenshot name from a test name and options.
|
|
67
|
+
*/
|
|
68
|
+
declare function getScreenshotName(name: string, options?: {
|
|
69
|
+
viewportWidth?: number;
|
|
70
|
+
}): string;
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region src/threshold.d.ts
|
|
73
|
+
/**
|
|
74
|
+
* Validates the threshold value.
|
|
75
|
+
*/
|
|
76
|
+
declare function validateThreshold(threshold: number): void;
|
|
77
|
+
//#endregion
|
|
78
|
+
export { getMetadataPath as i, getScreenshotName as n, ScreenshotMetadata as r, validateThreshold as t };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
//#region src/metadata.ts
|
|
2
|
+
/**
|
|
3
|
+
* Get metadata path from snapshot path.
|
|
4
|
+
*/
|
|
5
|
+
function getMetadataPath(snapshotPath) {
|
|
6
|
+
return snapshotPath + ".argos.json";
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
//#region src/name.ts
|
|
10
|
+
/**
|
|
11
|
+
* Build a screenshot name from a test name and options.
|
|
12
|
+
*/
|
|
13
|
+
function getScreenshotName(name, options = {}) {
|
|
14
|
+
return sanitizePath(`${name}${options.viewportWidth ? ` vw-${options.viewportWidth}` : ""}`);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Sanitize a path to be safe on all OSes.
|
|
18
|
+
*/
|
|
19
|
+
function sanitizePath(name) {
|
|
20
|
+
return name.split("/").map((filename) => sanitizeFilename(filename)).join("/");
|
|
21
|
+
}
|
|
22
|
+
function filenameReservedRegex() {
|
|
23
|
+
return /[<>:"/\\|?*\u0000-\u001F]|[. ]$/g;
|
|
24
|
+
}
|
|
25
|
+
function windowsReservedNameRegex() {
|
|
26
|
+
return /^(con|prn|aux|nul|com\d|lpt\d)$/i;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Sanitize a filename to be safe on all OSes.
|
|
30
|
+
*/
|
|
31
|
+
function sanitizeFilename(name) {
|
|
32
|
+
const replacement = "-";
|
|
33
|
+
const sanitized = name.replace(filenameReservedRegex(), replacement);
|
|
34
|
+
if (windowsReservedNameRegex().test(sanitized)) return `${sanitized}${replacement}`;
|
|
35
|
+
return sanitized;
|
|
36
|
+
}
|
|
37
|
+
//#endregion
|
|
38
|
+
//#region src/threshold.ts
|
|
39
|
+
/**
|
|
40
|
+
* Validates the threshold value.
|
|
41
|
+
*/
|
|
42
|
+
function validateThreshold(threshold) {
|
|
43
|
+
if (threshold < 0 || threshold > 1) throw new Error("The threshold must be between 0 and 1.");
|
|
44
|
+
}
|
|
45
|
+
//#endregion
|
|
46
|
+
export { getScreenshotName as n, getMetadataPath as r, validateThreshold as t };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@argos-ci/util",
|
|
3
3
|
"description": "Set of utilities used across all Argos SDKs.",
|
|
4
|
-
"version": "3.
|
|
4
|
+
"version": "3.4.0",
|
|
5
5
|
"author": "Smooth Code",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
@@ -23,14 +23,14 @@
|
|
|
23
23
|
"type": "module",
|
|
24
24
|
"exports": {
|
|
25
25
|
".": {
|
|
26
|
-
"types": "./dist/index.d.
|
|
27
|
-
"import": "./dist/index.
|
|
28
|
-
"default": "./dist/index.
|
|
26
|
+
"types": "./dist/index.d.mts",
|
|
27
|
+
"import": "./dist/index.mjs",
|
|
28
|
+
"default": "./dist/index.mjs"
|
|
29
29
|
},
|
|
30
30
|
"./browser": {
|
|
31
|
-
"types": "./dist/browser.d.
|
|
32
|
-
"import": "./dist/browser.
|
|
33
|
-
"default": "./dist/browser.
|
|
31
|
+
"types": "./dist/browser.d.mts",
|
|
32
|
+
"import": "./dist/browser.mjs",
|
|
33
|
+
"default": "./dist/browser.mjs"
|
|
34
34
|
},
|
|
35
35
|
"./package.json": "./package.json"
|
|
36
36
|
},
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"node": ">=20.0.0"
|
|
39
39
|
},
|
|
40
40
|
"scripts": {
|
|
41
|
-
"build": "
|
|
41
|
+
"build": "tsdown",
|
|
42
42
|
"check-types": "tsc",
|
|
43
43
|
"check-format": "prettier --check --ignore-unknown --ignore-path=../../.gitignore --ignore-path=../../.prettierignore .",
|
|
44
44
|
"lint": "eslint ."
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"@types/node": "catalog:",
|
|
48
48
|
"vitest": "catalog:"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "b49d186d5eb6e1338982a4cd5c3cb29e6cb0b7af"
|
|
51
51
|
}
|
package/dist/browser.d.ts
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
type ScreenshotMetadata = {
|
|
2
|
-
/** @description The URL of the page that was screenshotted */
|
|
3
|
-
url?: string | null;
|
|
4
|
-
/** @description An URL to an accessible preview of the screenshot */
|
|
5
|
-
previewUrl?: string | null;
|
|
6
|
-
viewport?: {
|
|
7
|
-
/** @description The width of the viewport */
|
|
8
|
-
width: number;
|
|
9
|
-
/** @description The height of the viewport */
|
|
10
|
-
height: number;
|
|
11
|
-
} | null;
|
|
12
|
-
/** @description The color scheme when the screenshot was taken */
|
|
13
|
-
colorScheme?: ("light" | "dark") | null;
|
|
14
|
-
/** @description The media type when the screenshot was taken */
|
|
15
|
-
mediaType?: ("screen" | "print") | null;
|
|
16
|
-
test?: ({
|
|
17
|
-
/** @description The unique identifier of the test */
|
|
18
|
-
id?: string | null;
|
|
19
|
-
/** @description The title of the test */
|
|
20
|
-
title: string;
|
|
21
|
-
/** @description The path of titles leading to the test */
|
|
22
|
-
titlePath: string[];
|
|
23
|
-
/** @description The number of retries for the test */
|
|
24
|
-
retries?: number | null;
|
|
25
|
-
/** @description The current retry count */
|
|
26
|
-
retry?: number | null;
|
|
27
|
-
/** @description The repeat count for the test */
|
|
28
|
-
repeat?: number | null;
|
|
29
|
-
/** @description The location of the test in the source code */
|
|
30
|
-
location?: {
|
|
31
|
-
/** @description The located file */
|
|
32
|
-
file: string;
|
|
33
|
-
/** @description The line number in the file */
|
|
34
|
-
line: number;
|
|
35
|
-
/** @description The column number in the file */
|
|
36
|
-
column: number;
|
|
37
|
-
};
|
|
38
|
-
/** @description Annotations associated to the test */
|
|
39
|
-
annotations?: {
|
|
40
|
-
/** @description The type of annotation */
|
|
41
|
-
type: string;
|
|
42
|
-
/** @description The description of the annotation */
|
|
43
|
-
description?: string;
|
|
44
|
-
/** @description The location of the annotation in the source code */
|
|
45
|
-
location?: {
|
|
46
|
-
/** @description The located file */
|
|
47
|
-
file: string;
|
|
48
|
-
/** @description The line number in the file */
|
|
49
|
-
line: number;
|
|
50
|
-
/** @description The column number in the file */
|
|
51
|
-
column: number;
|
|
52
|
-
};
|
|
53
|
-
}[];
|
|
54
|
-
} | null) | null;
|
|
55
|
-
browser?: {
|
|
56
|
-
/** @description The name of the browser */
|
|
57
|
-
name: string;
|
|
58
|
-
/** @description The version of the browser */
|
|
59
|
-
version: string;
|
|
60
|
-
} | null;
|
|
61
|
-
/** @description The automation library that generated the screenshot */
|
|
62
|
-
automationLibrary: {
|
|
63
|
-
/** @description The name of the automation library */
|
|
64
|
-
name: string;
|
|
65
|
-
/** @description The version of the automation library */
|
|
66
|
-
version: string;
|
|
67
|
-
};
|
|
68
|
-
/** @description The Argos SDK that generated the screenshot */
|
|
69
|
-
sdk: {
|
|
70
|
-
/** @description The name of the Argos SDK */
|
|
71
|
-
name: string;
|
|
72
|
-
/** @description The version of the Argos SDK */
|
|
73
|
-
version: string;
|
|
74
|
-
};
|
|
75
|
-
transient?: {
|
|
76
|
-
/** Threshold configured for this screenshot. */
|
|
77
|
-
threshold?: number;
|
|
78
|
-
/** Override the name to find the comparison baseline. */
|
|
79
|
-
baseName?: string;
|
|
80
|
-
/** Name of the parent screenshot. */
|
|
81
|
-
parentName?: string;
|
|
82
|
-
};
|
|
83
|
-
};
|
|
84
|
-
/**
|
|
85
|
-
* Get metadata path from snapshot path.
|
|
86
|
-
*/
|
|
87
|
-
declare function getMetadataPath(snapshotPath: string): string;
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Build a screenshot name from a test name and options.
|
|
91
|
-
*/
|
|
92
|
-
declare function getScreenshotName(name: string, options?: {
|
|
93
|
-
viewportWidth?: number;
|
|
94
|
-
}): string;
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Validates the threshold value.
|
|
98
|
-
*/
|
|
99
|
-
declare function validateThreshold(threshold: number): void;
|
|
100
|
-
|
|
101
|
-
export { type ScreenshotMetadata, getMetadataPath, getScreenshotName, validateThreshold };
|
package/dist/browser.js
DELETED
package/dist/chunk-TTRT2C3N.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
// src/metadata.ts
|
|
2
|
-
function getMetadataPath(snapshotPath) {
|
|
3
|
-
return snapshotPath + ".argos.json";
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
// src/name.ts
|
|
7
|
-
function getScreenshotName(name, options = {}) {
|
|
8
|
-
return sanitizePath(
|
|
9
|
-
`${name}${options.viewportWidth ? ` vw-${options.viewportWidth}` : ""}`
|
|
10
|
-
);
|
|
11
|
-
}
|
|
12
|
-
function sanitizePath(name) {
|
|
13
|
-
return name.split("/").map((filename) => sanitizeFilename(filename)).join("/");
|
|
14
|
-
}
|
|
15
|
-
function filenameReservedRegex() {
|
|
16
|
-
return /[<>:"/\\|?*\u0000-\u001F]|[. ]$/g;
|
|
17
|
-
}
|
|
18
|
-
function windowsReservedNameRegex() {
|
|
19
|
-
return /^(con|prn|aux|nul|com\d|lpt\d)$/i;
|
|
20
|
-
}
|
|
21
|
-
function sanitizeFilename(name) {
|
|
22
|
-
const replacement = "-";
|
|
23
|
-
const sanitized = name.replace(filenameReservedRegex(), replacement);
|
|
24
|
-
if (windowsReservedNameRegex().test(sanitized)) {
|
|
25
|
-
return `${sanitized}${replacement}`;
|
|
26
|
-
}
|
|
27
|
-
return sanitized;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// src/threshold.ts
|
|
31
|
-
function validateThreshold(threshold) {
|
|
32
|
-
if (threshold < 0 || threshold > 1) {
|
|
33
|
-
throw new Error("The threshold must be between 0 and 1.");
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export {
|
|
38
|
-
getMetadataPath,
|
|
39
|
-
getScreenshotName,
|
|
40
|
-
validateThreshold
|
|
41
|
-
};
|
package/dist/index.js
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getMetadataPath,
|
|
3
|
-
getScreenshotName,
|
|
4
|
-
validateThreshold
|
|
5
|
-
} from "./chunk-TTRT2C3N.js";
|
|
6
|
-
|
|
7
|
-
// src/fs.ts
|
|
8
|
-
import { randomBytes } from "crypto";
|
|
9
|
-
import { mkdir } from "fs/promises";
|
|
10
|
-
import { tmpdir } from "os";
|
|
11
|
-
import { join } from "path";
|
|
12
|
-
var createDirectoryPromises = /* @__PURE__ */ new Map();
|
|
13
|
-
async function createDirectory(pathname) {
|
|
14
|
-
let promise = createDirectoryPromises.get(pathname);
|
|
15
|
-
if (promise) {
|
|
16
|
-
return promise;
|
|
17
|
-
}
|
|
18
|
-
promise = mkdir(pathname, { recursive: true }).then(() => {
|
|
19
|
-
});
|
|
20
|
-
createDirectoryPromises.set(pathname, promise);
|
|
21
|
-
return promise;
|
|
22
|
-
}
|
|
23
|
-
async function createTemporaryDirectory() {
|
|
24
|
-
const osTmpDirectory = tmpdir();
|
|
25
|
-
const path = join(osTmpDirectory, "argos." + randomBytes(16).toString("hex"));
|
|
26
|
-
await createDirectory(path);
|
|
27
|
-
return path;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// src/git.ts
|
|
31
|
-
import { exec } from "child_process";
|
|
32
|
-
var cached;
|
|
33
|
-
function getGitRepositoryPath() {
|
|
34
|
-
if (!cached) {
|
|
35
|
-
cached = new Promise((resolve) => {
|
|
36
|
-
exec("git rev-parse --show-toplevel", (error, stdout, stderr) => {
|
|
37
|
-
if (error) {
|
|
38
|
-
resolve(null);
|
|
39
|
-
}
|
|
40
|
-
if (stderr) {
|
|
41
|
-
resolve(null);
|
|
42
|
-
}
|
|
43
|
-
resolve(stdout.trim());
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
return cached;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// src/introspection.ts
|
|
51
|
-
import { readFile } from "fs/promises";
|
|
52
|
-
var versionCache = /* @__PURE__ */ new Map();
|
|
53
|
-
function readVersionFromPackage(pkgPath) {
|
|
54
|
-
const readVersion = async () => {
|
|
55
|
-
const { version } = JSON.parse(await readFile(pkgPath, "utf-8"));
|
|
56
|
-
if (typeof version !== "string") {
|
|
57
|
-
throw new Error("Invalid version");
|
|
58
|
-
}
|
|
59
|
-
return version;
|
|
60
|
-
};
|
|
61
|
-
if (!versionCache.has(pkgPath)) {
|
|
62
|
-
versionCache.set(pkgPath, readVersion());
|
|
63
|
-
}
|
|
64
|
-
const fromCache = versionCache.get(pkgPath);
|
|
65
|
-
if (!fromCache) {
|
|
66
|
-
throw new Error("Invariant violation: version not in cache");
|
|
67
|
-
}
|
|
68
|
-
return fromCache;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// src/metadata-io.ts
|
|
72
|
-
import { readFile as readFile2, writeFile } from "fs/promises";
|
|
73
|
-
async function writeMetadata(screenshotPath, metadata) {
|
|
74
|
-
await writeFile(getMetadataPath(screenshotPath), JSON.stringify(metadata));
|
|
75
|
-
}
|
|
76
|
-
async function readMetadata(screenshotPath) {
|
|
77
|
-
try {
|
|
78
|
-
const metadata = await readFile2(getMetadataPath(screenshotPath), "utf8");
|
|
79
|
-
return JSON.parse(metadata);
|
|
80
|
-
} catch (error) {
|
|
81
|
-
if (error instanceof Error && "code" in error && error.code === "ENOENT") {
|
|
82
|
-
return null;
|
|
83
|
-
}
|
|
84
|
-
throw new Error("Failed to read metadata", { cause: error });
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// src/playwright-trace.ts
|
|
89
|
-
import { access } from "fs/promises";
|
|
90
|
-
function getTracePath(screenshotPath) {
|
|
91
|
-
return screenshotPath + ".pw-trace.zip";
|
|
92
|
-
}
|
|
93
|
-
async function getPlaywrightTracePath(screenshotPath) {
|
|
94
|
-
try {
|
|
95
|
-
const tracePath = getTracePath(screenshotPath);
|
|
96
|
-
await access(tracePath);
|
|
97
|
-
return tracePath;
|
|
98
|
-
} catch {
|
|
99
|
-
return null;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
export {
|
|
103
|
-
createDirectory,
|
|
104
|
-
createTemporaryDirectory,
|
|
105
|
-
getGitRepositoryPath,
|
|
106
|
-
getMetadataPath,
|
|
107
|
-
getPlaywrightTracePath,
|
|
108
|
-
getScreenshotName,
|
|
109
|
-
readMetadata,
|
|
110
|
-
readVersionFromPackage,
|
|
111
|
-
validateThreshold,
|
|
112
|
-
writeMetadata
|
|
113
|
-
};
|