visual-regression-ci 0.0.0-stage → 0.9.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/LICENSE +21 -0
- package/README.md +953 -2
- package/package.json +76 -4
- package/src/ci/actionReport.js +340 -0
- package/src/ci/prComment.js +420 -0
- package/src/cli/capture.js +243 -0
- package/src/cli/compare.js +190 -0
- package/src/cli/config.js +287 -0
- package/src/cli/database.js +69 -0
- package/src/cli/display.js +119 -0
- package/src/cli/errors.js +17 -0
- package/src/cli/index.js +577 -0
- package/src/cli/installBrowsers.js +59 -0
- package/src/cli/invocation.js +66 -0
- package/src/cli/jsonTarget.js +100 -0
- package/src/cli/logger.js +15 -0
- package/src/cli/manifest.js +139 -0
- package/src/cli/naming.js +60 -0
- package/src/cli/reporter.js +172 -0
- package/src/cli/result.js +225 -0
- package/src/cli/serve.js +64 -0
- package/src/server/app.js +135 -0
- package/src/server/db.js +691 -0
- package/src/server/importRuns.js +837 -0
- package/src/server/paths.js +107 -0
- package/src/server/public/css/styles.css +2362 -0
- package/src/server/public/js/common.js +32 -0
- package/src/server/public/js/dashboard.js +140 -0
- package/src/server/public/js/import-upload.js +169 -0
- package/src/server/public/js/review-actions.js +379 -0
- package/src/server/public/js/shortcuts.js +242 -0
- package/src/server/public/js/slider.js +104 -0
- package/src/server/public/js/tabs.js +85 -0
- package/src/server/public/js/theme.js +83 -0
- package/src/server/routes/api.js +141 -0
- package/src/server/routes/views.js +68 -0
- package/src/server/security.js +79 -0
- package/src/server/uploadImport.js +227 -0
- package/src/server/urls.js +31 -0
- package/src/server/viewModels.js +366 -0
- package/src/server/views/history.ejs +111 -0
- package/src/server/views/index.ejs +283 -0
- package/src/server/views/layout.ejs +11 -0
- package/src/server/views/partials/footer.ejs +11 -0
- package/src/server/views/partials/header.ejs +93 -0
- package/src/server/views/run-detail.ejs +295 -0
- package/src/shared/packageSpec.js +49 -0
- package/src/shared/text.js +59 -0
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { stripJsonComments, validateStorageDir } from '../cli/config.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Absolute storage root (holds runs/, baselines/ and the SQLite DB) for a given
|
|
7
|
+
* config storageDir. Precedence: VISUAL_STORAGE_DIR env > storageDir > ./storage.
|
|
8
|
+
*
|
|
9
|
+
* @param {string} [storageDir] - storageDir from visual.config.json (relative to cwd)
|
|
10
|
+
* @returns {string}
|
|
11
|
+
*/
|
|
12
|
+
export function resolveStorageRoot(storageDir) {
|
|
13
|
+
if (process.env.VISUAL_STORAGE_DIR) return path.resolve(process.env.VISUAL_STORAGE_DIR);
|
|
14
|
+
return path.resolve(process.cwd(), storageDir || 'storage');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
let configStorageDir; // undefined = visual.config.json not read yet
|
|
18
|
+
|
|
19
|
+
// Only storageDir matters here, so a config the CLI completes with flags (e.g. no
|
|
20
|
+
// baseUrl, passed via --base-url) still works. Read once per process.
|
|
21
|
+
function readConfiguredStorageDir() {
|
|
22
|
+
const configPath = path.resolve(process.cwd(), 'visual.config.json');
|
|
23
|
+
if (!fs.existsSync(configPath)) return null;
|
|
24
|
+
try {
|
|
25
|
+
const parsed = JSON.parse(stripJsonComments(fs.readFileSync(configPath, 'utf8')));
|
|
26
|
+
return validateStorageDir(parsed?.storageDir);
|
|
27
|
+
} catch (err) {
|
|
28
|
+
console.warn(`[WARN] Ignoring storageDir in ${configPath} (${err.message}); using ./storage. ` +
|
|
29
|
+
'Set VISUAL_STORAGE_DIR to choose the storage folder explicitly.');
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Storage root for the dashboard, which has no --config flag: honours
|
|
36
|
+
* VISUAL_STORAGE_DIR, then storageDir from ./visual.config.json, then ./storage.
|
|
37
|
+
* The env var is read on every call so tests can repoint it.
|
|
38
|
+
*
|
|
39
|
+
* @returns {string}
|
|
40
|
+
*/
|
|
41
|
+
export function getStorageRoot() {
|
|
42
|
+
if (process.env.VISUAL_STORAGE_DIR) return resolveStorageRoot();
|
|
43
|
+
if (configStorageDir === undefined) configStorageDir = readConfiguredStorageDir();
|
|
44
|
+
return resolveStorageRoot(configStorageDir);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* True when `child` is strictly inside `parent` (both absolute).
|
|
49
|
+
* Compares path segments, so "/a/storage-evil" is not inside "/a/storage".
|
|
50
|
+
*
|
|
51
|
+
* @param {string} child
|
|
52
|
+
* @param {string} parent
|
|
53
|
+
* @returns {boolean}
|
|
54
|
+
*/
|
|
55
|
+
export function isInside(child, parent) {
|
|
56
|
+
const rel = path.relative(parent, child);
|
|
57
|
+
return rel !== '' && rel.split(path.sep)[0] !== '..' && !path.isAbsolute(rel);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Resolves `filePath` and verifies it is a .png located inside `allowedDir`,
|
|
62
|
+
* following symlinks so a link cannot point outside the allowed directory.
|
|
63
|
+
*
|
|
64
|
+
* @param {string} filePath - Absolute, or relative to process.cwd()
|
|
65
|
+
* @param {string} allowedDir - Absolute directory the file must live in
|
|
66
|
+
* @param {object} [options]
|
|
67
|
+
* @param {boolean} [options.mustExist=true] - false allows a not-yet-created target file
|
|
68
|
+
* @returns {string} The resolved real path
|
|
69
|
+
* @throws {Error} "Access denied: ..." when the path is not allowed
|
|
70
|
+
*/
|
|
71
|
+
export function resolvePngInside(filePath, allowedDir, { mustExist = true } = {}) {
|
|
72
|
+
const resolved = path.resolve(process.cwd(), filePath);
|
|
73
|
+
|
|
74
|
+
if (path.extname(resolved).toLowerCase() !== '.png') {
|
|
75
|
+
throw new Error(`Access denied: "${filePath}" is not a .png file.`);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Lexical check first, before touching the filesystem.
|
|
79
|
+
if (!isInside(resolved, allowedDir)) {
|
|
80
|
+
throw new Error(`Access denied: "${filePath}" is outside ${allowedDir}.`);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (!mustExist) {
|
|
84
|
+
fs.mkdirSync(allowedDir, { recursive: true });
|
|
85
|
+
} else if (!fs.existsSync(allowedDir)) {
|
|
86
|
+
throw new Error(`File not found: "${filePath}".`);
|
|
87
|
+
}
|
|
88
|
+
const realAllowed = fs.realpathSync(allowedDir);
|
|
89
|
+
|
|
90
|
+
let real;
|
|
91
|
+
if (fs.existsSync(resolved)) {
|
|
92
|
+
// Existing file (or symlink): check where it really points.
|
|
93
|
+
real = fs.realpathSync(resolved);
|
|
94
|
+
} else if (mustExist) {
|
|
95
|
+
throw new Error(`File not found: "${filePath}".`);
|
|
96
|
+
} else {
|
|
97
|
+
// New target: its parent directory must really be inside the allowed dir.
|
|
98
|
+
fs.mkdirSync(path.dirname(resolved), { recursive: true });
|
|
99
|
+
real = path.join(fs.realpathSync(path.dirname(resolved)), path.basename(resolved));
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (!isInside(real, realAllowed)) {
|
|
103
|
+
throw new Error(`Access denied: "${filePath}" resolves outside ${allowedDir}.`);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return real;
|
|
107
|
+
}
|