@vizejs/vite-plugin-musea 0.443.0 → 0.457.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/README.md +4 -0
- package/dist/a11y/index.d.mts +1 -1
- package/dist/cli/index.d.mts +3 -2
- package/dist/cli/index.d.mts.map +1 -1
- package/dist/cli/index.mjs +341 -61
- package/dist/cli/index.mjs.map +1 -1
- package/dist/gallery/assets/{MonacoEditor-CmjDtbrI.js → MonacoEditor-CwTBvTDB.js} +2 -2
- package/dist/gallery/assets/{cssMode-B16oWKdO.js → cssMode-CelCYNbn.js} +1 -1
- package/dist/gallery/assets/{editor.api-CfYscGcC.js → editor.api-a6jnMk-M.js} +1 -1
- package/dist/gallery/assets/{freemarker2-Bsla50n3.js → freemarker2-DPAvE--z.js} +1 -1
- package/dist/gallery/assets/{handlebars-CS_Y5cXs.js → handlebars-BM0wnfAw.js} +1 -1
- package/dist/gallery/assets/{html-DagAGhpS.js → html-BVxuhUk3.js} +1 -1
- package/dist/gallery/assets/{htmlMode-CiuL2Y-P.js → htmlMode-BMPJCjfA.js} +1 -1
- package/dist/gallery/assets/index-B0odPzN2.css +1 -0
- package/dist/gallery/assets/index-Dc3b2Q04.js +73 -0
- package/dist/gallery/assets/{javascript-BQYQMq9R.js → javascript-DNIAc6FS.js} +1 -1
- package/dist/gallery/assets/{jsonMode-C5lyVqru.js → jsonMode-DoEfywTC.js} +1 -1
- package/dist/gallery/assets/{liquid-qbEuwx0o.js → liquid-Bda2NkY3.js} +1 -1
- package/dist/gallery/assets/{lspLanguageFeatures-Dqts9s1L.js → lspLanguageFeatures-Bss0uLYW.js} +1 -1
- package/dist/gallery/assets/{mdx-DN6uw21R.js → mdx-Cz_EcYUc.js} +1 -1
- package/dist/gallery/assets/{python-Cbp5CGeG.js → python-DumZpK8Y.js} +1 -1
- package/dist/gallery/assets/{razor-BXu36P7p.js → razor-B35B929n.js} +1 -1
- package/dist/gallery/assets/{register-vvpXemvQ.js → register-CQcuOoyc.js} +2 -2
- package/dist/gallery/assets/{toggleHighContrast-9EQLxoB9.js → toggleHighContrast-MeFDOtI7.js} +1 -1
- package/dist/gallery/assets/{tsMode-DakVvyMV.js → tsMode-DJXGbiLp.js} +1 -1
- package/dist/gallery/assets/{typescript-DEY4mnQU.js → typescript-CkqSzVk4.js} +1 -1
- package/dist/gallery/assets/{vs-Cd8KAJDG.js → vs-BnuldxuJ.js} +3 -3
- package/dist/gallery/assets/{workers-GvANOwSC.js → workers-tF2102zJ.js} +1 -1
- package/dist/gallery/assets/{xml-cZMAcMEr.js → xml-ntbvGSvU.js} +1 -1
- package/dist/gallery/assets/{yaml-CReFeuuC.js → yaml-s2GvmKpO.js} +1 -1
- package/dist/gallery/index.html +2 -2
- package/dist/{index-BU4-FGUC.d.mts → index-DENP7L3t.d.mts} +2 -2
- package/dist/{index-BU4-FGUC.d.mts.map → index-DENP7L3t.d.mts.map} +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +54 -101
- package/dist/index.mjs.map +1 -1
- package/dist/{options-DnKPMMPV.mjs → options-DNFbTB_5.mjs} +103 -21
- package/dist/options-DNFbTB_5.mjs.map +1 -0
- package/dist/{vrt-PuxpRuHa.mjs → vrt-dFU3k2J6.mjs} +49 -6
- package/dist/vrt-dFU3k2J6.mjs.map +1 -0
- package/dist/{vrt-DtcnqPhF.d.mts → vrt-nAWyjDmd.d.mts} +8 -5
- package/dist/vrt-nAWyjDmd.d.mts.map +1 -0
- package/dist/vrt.d.mts +1 -1
- package/dist/vrt.mjs +1 -1
- package/package.json +5 -5
- package/dist/gallery/assets/index-BaRljRmN.css +0 -1
- package/dist/gallery/assets/index-Bma1gCA8.js +0 -73
- package/dist/options-DnKPMMPV.mjs.map +0 -1
- package/dist/vrt-DtcnqPhF.d.mts.map +0 -1
- package/dist/vrt-PuxpRuHa.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -94,6 +94,10 @@ for path completion, missing-file diagnostics, go-to-definition, and prop/slot i
|
|
|
94
94
|
The source may be a `.vue`, `.ts`, `.tsx`, `.js`, or `.jsx` file. For render-function components,
|
|
95
95
|
Musea reads statically declared runtime `props` and `emits` for the analysis and props panel.
|
|
96
96
|
|
|
97
|
+
Vue 3.5.41 does not apply a component prop literally named `__proto__`. Retaining its raw editor
|
|
98
|
+
value does not make it a rendered prop. Avoid this prop name; [#8533](https://github.com/ubugeeei-prod/vize/issues/8533)
|
|
99
|
+
tracks explicit editor refusal and release acceptance.
|
|
100
|
+
|
|
97
101
|
## TypeScript and Editor Setup
|
|
98
102
|
|
|
99
103
|
Add the client types once, usually in `src/env.d.ts`:
|
package/dist/a11y/index.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as generateA11yHtmlReport, i as computeA11ySummary, n as MuseaA11yRunner, o as generateA11yJsonReport, r as resolveAxeSource, t as A11ySummary } from "../index-
|
|
1
|
+
import { a as generateA11yHtmlReport, i as computeA11ySummary, n as MuseaA11yRunner, o as generateA11yJsonReport, r as resolveAxeSource, t as A11ySummary } from "../index-DENP7L3t.mjs";
|
|
2
2
|
export { A11ySummary, MuseaA11yRunner, computeA11ySummary, generateA11yHtmlReport, generateA11yJsonReport, resolveAxeSource };
|
package/dist/cli/index.d.mts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { l as MuseaVrtOptions } from "../index-ZFHsOEPD.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/cli/index.d.ts
|
|
4
|
-
type Command = "run" | "approve" | "clean" | "generate";
|
|
4
|
+
type Command = "run" | "approve" | "clean" | "generate" | "serve";
|
|
5
5
|
interface CliOptions {
|
|
6
6
|
command: Command;
|
|
7
7
|
update: boolean;
|
|
8
|
-
config
|
|
8
|
+
config?: string;
|
|
9
|
+
configDir?: string;
|
|
9
10
|
output: string;
|
|
10
11
|
threshold: number;
|
|
11
12
|
thresholdProvided: boolean;
|
package/dist/cli/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/cli/index.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/cli/index.ts"],"mappings":";;;KAoCK,OAAA;AAAA,UAEY,UAAA;EACf,OAAA,EAAS,OAAA;EACT,MAAA;EACA,MAAA;EACA,SAAA;EACA,MAAA;EACA,SAAA;EACA,iBAAA;EACA,OAAA;EACA,eAAA;EACA,IAAA;EACA,EAAA;EACA,IAAA;EACA,IAAA;EACA,OAAA;EACA,OAAA;EACA,aAAA;EACA,GAAA,GAAM,eAAA;EACN,UAAA;EACA,eAAA;EACA,WAAA,GAAc,MAAA,SAAe,MAAA;EAC7B,WAAA;EACA,kBAAA,GAAqB,MAAA;EACrB,oBAAA;AAAA;AAAA,iBAGc,SAAA,CAAU,IAAA,aAAiB,UAAU"}
|
package/dist/cli/index.mjs
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { a as scanArtFiles } from "../utils-BloA9YP9.mjs";
|
|
3
|
-
import { i as
|
|
4
|
-
import { a as normalizeVrtWorkerCount, i as MuseaVrtRunner, n as generateVrtJsonReport, o as normalizeSnapshotIdentity, r as generateVrtReport } from "../vrt-
|
|
3
|
+
import { a as attachArtReportOwner, i as assertArtReportOwnership, n as readMuseaOptions, o as resolveArtReportTarget, r as processMuseaArtFile, s as publicBasePathFromViteBase } from "../options-DNFbTB_5.mjs";
|
|
4
|
+
import { a as normalizeVrtWorkerCount, i as MuseaVrtRunner, n as generateVrtJsonReport, o as normalizeSnapshotIdentity, r as generateVrtReport } from "../vrt-dFU3k2J6.mjs";
|
|
5
5
|
import fs, { realpathSync } from "node:fs";
|
|
6
6
|
import path from "node:path";
|
|
7
|
+
import { randomBytes, randomUUID, timingSafeEqual } from "node:crypto";
|
|
7
8
|
import { fileURLToPath } from "node:url";
|
|
9
|
+
import { mkdir, readFile, rename, rm, writeFile } from "node:fs/promises";
|
|
10
|
+
import { loadConfig, resolveViteConfigExport } from "@vizejs/vite-plugin";
|
|
8
11
|
import { loadConfigFromFile } from "vite";
|
|
12
|
+
import { createServer } from "node:http";
|
|
9
13
|
//#region src/cli/utils.ts
|
|
10
14
|
/** Parse a single .art.vue file into an ArtFileInfo structure. */
|
|
11
15
|
async function parseArtFile(filePath) {
|
|
@@ -14,6 +18,10 @@ async function parseArtFile(filePath) {
|
|
|
14
18
|
command: "serve"
|
|
15
19
|
});
|
|
16
20
|
}
|
|
21
|
+
function parseWorkers(value) {
|
|
22
|
+
const workers = Number.parseInt(value ?? "", 10);
|
|
23
|
+
return Number.isFinite(workers) ? Math.max(1, workers) : 1;
|
|
24
|
+
}
|
|
17
25
|
//#endregion
|
|
18
26
|
//#region src/cli/commands.ts
|
|
19
27
|
/**
|
|
@@ -54,7 +62,8 @@ function createVrtOptions(options) {
|
|
|
54
62
|
*/
|
|
55
63
|
function resolveVrtSnapshotDir(options, snapshotDir) {
|
|
56
64
|
if (!snapshotDir) return path.join(options.output, "snapshots");
|
|
57
|
-
|
|
65
|
+
const configDir = options.configDir ?? (options.config ? path.dirname(path.resolve(options.config)) : process.cwd());
|
|
66
|
+
return path.resolve(configDir, snapshotDir);
|
|
58
67
|
}
|
|
59
68
|
function withoutA11y(vrt) {
|
|
60
69
|
if (!vrt) return {};
|
|
@@ -226,57 +235,57 @@ async function runGenerate(options) {
|
|
|
226
235
|
//#region src/cli/config.ts
|
|
227
236
|
const DEFAULT_INCLUDE = ["**/*.art.vue"];
|
|
228
237
|
const DEFAULT_EXCLUDE = ["node_modules/**", "dist/**"];
|
|
229
|
-
const
|
|
230
|
-
"
|
|
231
|
-
"
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
async function loadMuseaVrtOptions(configPath, cwd = process.cwd()) {
|
|
237
|
-
const loaded = await loadViteConfig(configPath, cwd);
|
|
238
|
-
if (!loaded) return void 0;
|
|
239
|
-
return readPluginMuseaOptions(loaded.plugins)?.vrt;
|
|
240
|
-
}
|
|
241
|
-
async function loadMuseaFileSet(configPath, cwd = process.cwd()) {
|
|
238
|
+
const CONFIG_ENV = {
|
|
239
|
+
command: "serve",
|
|
240
|
+
mode: "development",
|
|
241
|
+
isSsrBuild: false
|
|
242
|
+
};
|
|
243
|
+
/** Resolve all CLI gallery metadata from one evaluation of the Vite config. */
|
|
244
|
+
async function loadMuseaConfiguration(configPath, cwd = process.cwd()) {
|
|
242
245
|
const loaded = await loadViteConfig(configPath, cwd);
|
|
243
246
|
const pluginOptions = loaded ? readPluginMuseaOptions(loaded.plugins) : void 0;
|
|
244
|
-
const vizeOptions =
|
|
247
|
+
const vizeOptions = await readSharedMuseaOptions(loaded, cwd, configPath);
|
|
245
248
|
const include = pluginOptions?.include ?? vizeOptions?.include ?? DEFAULT_INCLUDE;
|
|
246
249
|
const exclude = pluginOptions?.exclude ?? vizeOptions?.exclude ?? DEFAULT_EXCLUDE;
|
|
250
|
+
const sharedVrt = vizeOptions?.vrt;
|
|
251
|
+
const { outDir, ...sharedVrtOptions } = sharedVrt ?? {};
|
|
252
|
+
const vrt = sharedVrt ? {
|
|
253
|
+
...sharedVrtOptions,
|
|
254
|
+
...outDir === void 0 ? {} : { snapshotDir: outDir },
|
|
255
|
+
...pluginOptions?.vrt
|
|
256
|
+
} : pluginOptions?.vrt;
|
|
247
257
|
const root = loaded?.root ?? cwd;
|
|
248
258
|
return {
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
259
|
+
fileSet: {
|
|
260
|
+
root,
|
|
261
|
+
projectRoot: path.resolve(root, pluginOptions?.projectRoot ?? "."),
|
|
262
|
+
include,
|
|
263
|
+
exclude
|
|
264
|
+
},
|
|
265
|
+
vrt,
|
|
266
|
+
configDir: loaded?.configDir ?? cwd,
|
|
267
|
+
previewBasePath: publicBasePathFromViteBase(loaded?.config.base, pluginOptions?.basePath ?? vizeOptions?.basePath ?? "/__musea__")
|
|
253
268
|
};
|
|
254
269
|
}
|
|
255
|
-
async function loadMuseaPreviewBasePath(configPath, cwd = process.cwd()) {
|
|
256
|
-
const loaded = await loadViteConfig(configPath, cwd);
|
|
257
|
-
const pluginOptions = loaded ? readPluginMuseaOptions(loaded.plugins) : void 0;
|
|
258
|
-
const shared = pluginOptions?.basePath === void 0 ? await readVizeMuseaOptions(loaded?.configDir ?? cwd) : void 0;
|
|
259
|
-
return publicBasePathFromViteBase(loaded?.base, pluginOptions?.basePath ?? shared?.basePath ?? "/__musea__");
|
|
260
|
-
}
|
|
261
270
|
async function loadViteConfig(configPath, cwd) {
|
|
262
|
-
const resolvedConfigPath =
|
|
263
|
-
if (!await fileExists(resolvedConfigPath)) return void 0;
|
|
271
|
+
const resolvedConfigPath = configPath ? path.resolve(cwd, configPath) : void 0;
|
|
272
|
+
if (resolvedConfigPath && !await fileExists(resolvedConfigPath)) return void 0;
|
|
264
273
|
const loaded = await loadConfigFromFile({
|
|
265
274
|
command: "serve",
|
|
266
275
|
mode: "development",
|
|
267
276
|
isPreview: false,
|
|
268
277
|
isSsrBuild: false
|
|
269
|
-
}, resolvedConfigPath);
|
|
278
|
+
}, resolvedConfigPath, cwd);
|
|
270
279
|
if (!loaded) return void 0;
|
|
271
280
|
const plugins = [];
|
|
272
281
|
await collectPlugins(loaded.config.plugins, plugins);
|
|
273
|
-
const configDir = path.dirname(
|
|
282
|
+
const configDir = path.dirname(loaded.path);
|
|
274
283
|
const configuredRoot = loaded.config.root;
|
|
275
284
|
return {
|
|
276
285
|
root: configuredRoot ? path.resolve(configDir, configuredRoot) : configDir,
|
|
277
286
|
configDir,
|
|
278
|
-
|
|
279
|
-
|
|
287
|
+
config: loaded.config,
|
|
288
|
+
plugins
|
|
280
289
|
};
|
|
281
290
|
}
|
|
282
291
|
function readPluginMuseaOptions(plugins) {
|
|
@@ -285,22 +294,15 @@ function readPluginMuseaOptions(plugins) {
|
|
|
285
294
|
if (options) return options;
|
|
286
295
|
}
|
|
287
296
|
}
|
|
288
|
-
async function
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
isSsrBuild: false
|
|
298
|
-
}, file))?.config)?.musea;
|
|
299
|
-
if (musea?.include || musea?.exclude || musea?.basePath !== void 0) return musea;
|
|
300
|
-
} catch {
|
|
301
|
-
continue;
|
|
302
|
-
}
|
|
303
|
-
}
|
|
297
|
+
async function readSharedMuseaOptions(loaded, cwd, configPath) {
|
|
298
|
+
if (!loaded && configPath !== void 0) return void 0;
|
|
299
|
+
return (loaded ? await loadConfig(loaded.configDir, {
|
|
300
|
+
viteConfig: false,
|
|
301
|
+
env: CONFIG_ENV
|
|
302
|
+
}) ?? await resolveViteConfigExport(loaded.config, CONFIG_ENV) : await loadConfig(cwd, {
|
|
303
|
+
mode: "auto",
|
|
304
|
+
env: CONFIG_ENV
|
|
305
|
+
}))?.musea;
|
|
304
306
|
}
|
|
305
307
|
async function collectPlugins(input, plugins) {
|
|
306
308
|
const resolved = await input;
|
|
@@ -376,6 +378,275 @@ function isRecord(value) {
|
|
|
376
378
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
377
379
|
}
|
|
378
380
|
//#endregion
|
|
381
|
+
//#region src/cli/service/auth.ts
|
|
382
|
+
function authorizeSession(request, response, origin, host, token) {
|
|
383
|
+
response.setHeader("Cache-Control", "no-store");
|
|
384
|
+
response.setHeader("Vary", "Origin");
|
|
385
|
+
if (request.headers.origin !== origin || request.headers.host !== host) {
|
|
386
|
+
response.writeHead(403).end();
|
|
387
|
+
return false;
|
|
388
|
+
}
|
|
389
|
+
response.setHeader("Access-Control-Allow-Origin", origin);
|
|
390
|
+
if (request.method === "OPTIONS") {
|
|
391
|
+
const method = request.headers["access-control-request-method"];
|
|
392
|
+
const headers = String(request.headers["access-control-request-headers"] ?? "").toLowerCase().split(",").map((item) => item.trim());
|
|
393
|
+
if (!["GET", "POST"].includes(String(method)) || !headers.includes("authorization") || headers.some((item) => !["authorization", "content-type"].includes(item))) {
|
|
394
|
+
response.writeHead(403).end();
|
|
395
|
+
return false;
|
|
396
|
+
}
|
|
397
|
+
response.setHeader("Access-Control-Allow-Methods", "GET, POST");
|
|
398
|
+
response.setHeader("Access-Control-Allow-Headers", "Authorization, Content-Type");
|
|
399
|
+
response.writeHead(204).end();
|
|
400
|
+
return false;
|
|
401
|
+
}
|
|
402
|
+
const actual = Buffer.from(request.headers.authorization ?? "");
|
|
403
|
+
const expected = Buffer.from(`Bearer ${token}`);
|
|
404
|
+
if (actual.length !== expected.length || !timingSafeEqual(actual, expected)) {
|
|
405
|
+
response.writeHead(401).end();
|
|
406
|
+
return false;
|
|
407
|
+
}
|
|
408
|
+
return true;
|
|
409
|
+
}
|
|
410
|
+
async function captureInput(request) {
|
|
411
|
+
if ((request.headers["content-type"] ?? "").split(";")[0].trim().toLowerCase() !== "application/json") throw new Error("Expected JSON");
|
|
412
|
+
const chunks = [];
|
|
413
|
+
let size = 0;
|
|
414
|
+
for await (const chunk of request) {
|
|
415
|
+
if (!Buffer.isBuffer(chunk)) throw new Error("Expected HTTP bytes");
|
|
416
|
+
size += chunk.length;
|
|
417
|
+
if (size > 4096) throw new Error("Capture input is too large");
|
|
418
|
+
chunks.push(chunk);
|
|
419
|
+
}
|
|
420
|
+
let input;
|
|
421
|
+
try {
|
|
422
|
+
input = JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
423
|
+
} catch {
|
|
424
|
+
throw new Error("Capture input must contain valid JSON");
|
|
425
|
+
}
|
|
426
|
+
if (!input || typeof input !== "object" || Array.isArray(input) || Object.keys(input).sort().join(",") !== "artPath,update" || typeof input.artPath !== "string" || typeof input.update !== "boolean") throw new Error("Capture requires a known artPath and boolean update");
|
|
427
|
+
return input;
|
|
428
|
+
}
|
|
429
|
+
//#endregion
|
|
430
|
+
//#region src/cli/service/artifacts.ts
|
|
431
|
+
/** Registrations contain frozen capture bytes, never request-derived filesystem paths. */
|
|
432
|
+
var SessionArtifacts = class {
|
|
433
|
+
files = /* @__PURE__ */ new Map();
|
|
434
|
+
add(bytes, type) {
|
|
435
|
+
const url = `/artifacts/${randomUUID()}`;
|
|
436
|
+
this.files.set(url, {
|
|
437
|
+
bytes: Buffer.from(bytes),
|
|
438
|
+
type
|
|
439
|
+
});
|
|
440
|
+
return url;
|
|
441
|
+
}
|
|
442
|
+
clear() {
|
|
443
|
+
this.files.clear();
|
|
444
|
+
}
|
|
445
|
+
send(url, response) {
|
|
446
|
+
const artifact = this.files.get(url);
|
|
447
|
+
if (!artifact) return false;
|
|
448
|
+
response.setHeader("Content-Type", artifact.type);
|
|
449
|
+
response.setHeader("X-Content-Type-Options", "nosniff");
|
|
450
|
+
response.setHeader("Content-Security-Policy", "default-src 'none'; style-src 'unsafe-inline'; img-src data:; sandbox");
|
|
451
|
+
response.end(artifact.bytes);
|
|
452
|
+
return true;
|
|
453
|
+
}
|
|
454
|
+
async results(results) {
|
|
455
|
+
return Promise.all(results.map(async (result) => {
|
|
456
|
+
const urls = {};
|
|
457
|
+
for (const [key, file] of [
|
|
458
|
+
["snapshot", result.snapshotPath],
|
|
459
|
+
["current", result.currentPath],
|
|
460
|
+
["diff", result.diffPath]
|
|
461
|
+
]) if (file && !result.error) urls[key] = this.add(await readFile(file), "image/png");
|
|
462
|
+
return {
|
|
463
|
+
artPath: result.artPath,
|
|
464
|
+
variantName: result.variantName,
|
|
465
|
+
viewport: result.viewport.name,
|
|
466
|
+
passed: result.passed,
|
|
467
|
+
isNew: result.isNew,
|
|
468
|
+
diffPercentage: result.diffPercentage,
|
|
469
|
+
error: result.error,
|
|
470
|
+
images: urls
|
|
471
|
+
};
|
|
472
|
+
}));
|
|
473
|
+
}
|
|
474
|
+
};
|
|
475
|
+
//#endregion
|
|
476
|
+
//#region src/cli/service/reports.ts
|
|
477
|
+
/** Publish one complete owned report; JSON/HTML retain independent file atomicity. */
|
|
478
|
+
async function writeSessionReport(file, bytes) {
|
|
479
|
+
const temporary = `${file}.${randomUUID()}.tmp`;
|
|
480
|
+
try {
|
|
481
|
+
await writeFile(temporary, bytes, { flag: "wx" });
|
|
482
|
+
await rename(temporary, file);
|
|
483
|
+
} finally {
|
|
484
|
+
await rm(temporary, { force: true });
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
//#endregion
|
|
488
|
+
//#region src/cli/serve.ts
|
|
489
|
+
function json(response, value, status = 200) {
|
|
490
|
+
response.setHeader("Content-Type", "application/json");
|
|
491
|
+
response.writeHead(status).end(JSON.stringify(value));
|
|
492
|
+
}
|
|
493
|
+
/** Local lifecycle authority; callers must keep credentials out of reports and artifacts. */
|
|
494
|
+
async function startHostedVrtSession(options, certificateSpki) {
|
|
495
|
+
if (!options.galleryUrl) throw new Error("serve requires --gallery-url");
|
|
496
|
+
const gallery = new URL(options.galleryUrl);
|
|
497
|
+
gallery.pathname = `${gallery.pathname.replace(/\/+$/, "")}/`;
|
|
498
|
+
gallery.search = "";
|
|
499
|
+
gallery.hash = "";
|
|
500
|
+
if (gallery.protocol !== "https:" || gallery.username || gallery.password) throw new Error("serve requires an HTTPS gallery without embedded credentials");
|
|
501
|
+
await loadHostedGallery(gallery.href);
|
|
502
|
+
const token = randomBytes(32).toString("base64url");
|
|
503
|
+
const artifacts = new SessionArtifacts();
|
|
504
|
+
let host = "";
|
|
505
|
+
let busy;
|
|
506
|
+
let closing = false;
|
|
507
|
+
let closeTask;
|
|
508
|
+
const server = createServer((request, response) => {
|
|
509
|
+
if (!authorizeSession(request, response, gallery.origin, host, token)) return;
|
|
510
|
+
if (closing) {
|
|
511
|
+
json(response, { error: "Session is closing" }, 503);
|
|
512
|
+
return;
|
|
513
|
+
}
|
|
514
|
+
if (request.method === "GET" && request.url === "/session") {
|
|
515
|
+
json(response, {
|
|
516
|
+
version: 1,
|
|
517
|
+
galleryUrl: gallery.href
|
|
518
|
+
});
|
|
519
|
+
return;
|
|
520
|
+
}
|
|
521
|
+
if (request.method === "GET" && request.url && artifacts.send(request.url, response)) return;
|
|
522
|
+
if (request.method !== "POST" || request.url !== "/capture") {
|
|
523
|
+
json(response, { error: "Not found" }, 404);
|
|
524
|
+
return;
|
|
525
|
+
}
|
|
526
|
+
if (busy) {
|
|
527
|
+
json(response, { error: "Capture already running" }, 409);
|
|
528
|
+
return;
|
|
529
|
+
}
|
|
530
|
+
busy = (async () => {
|
|
531
|
+
let runner;
|
|
532
|
+
let outcome = {
|
|
533
|
+
body: { error: "Capture incomplete" },
|
|
534
|
+
status: 500
|
|
535
|
+
};
|
|
536
|
+
try {
|
|
537
|
+
const input = await captureInput(request);
|
|
538
|
+
const hosted = await loadHostedGallery(gallery.href);
|
|
539
|
+
const art = hosted.arts.find((item) => item.path === input.artPath);
|
|
540
|
+
if (!art) {
|
|
541
|
+
outcome = {
|
|
542
|
+
body: { error: "Art not found" },
|
|
543
|
+
status: 404
|
|
544
|
+
};
|
|
545
|
+
return;
|
|
546
|
+
}
|
|
547
|
+
for (const variant of art.variants.filter((item) => !item.skipVrt)) {
|
|
548
|
+
const preview = await fetch(hosted.previewUrls[art.path][variant.name], {
|
|
549
|
+
redirect: "error",
|
|
550
|
+
signal: AbortSignal.timeout(3e4)
|
|
551
|
+
});
|
|
552
|
+
if (!preview.ok) throw new Error(`Hosted preview: HTTP ${preview.status}`);
|
|
553
|
+
await preview.body?.cancel();
|
|
554
|
+
}
|
|
555
|
+
const reportDir = path.resolve(options.output, "reports");
|
|
556
|
+
const identity = hosted.snapshotIdentities[art.path];
|
|
557
|
+
const target = resolveArtReportTarget(identity, Object.values(hosted.snapshotIdentities), process.cwd(), reportDir);
|
|
558
|
+
await assertArtReportOwnership(target, process.cwd());
|
|
559
|
+
runner = new MuseaVrtRunner({
|
|
560
|
+
...createVrtOptions(options),
|
|
561
|
+
capture: {
|
|
562
|
+
...createVrtOptions(options).capture,
|
|
563
|
+
waitForPreviewReady: true
|
|
564
|
+
},
|
|
565
|
+
previewUrls: hosted.previewUrls,
|
|
566
|
+
snapshotIdentities: hosted.snapshotIdentities,
|
|
567
|
+
hostedNavigation: gallery.href
|
|
568
|
+
});
|
|
569
|
+
await runner.init({ hostedCertificateSpki: certificateSpki });
|
|
570
|
+
const results = await runner.runAllTests([art], gallery.origin);
|
|
571
|
+
const summary = runner.getSummary(results);
|
|
572
|
+
if ((summary.errors ?? 0) > 0) throw new Error(results.find((item) => item.error).error);
|
|
573
|
+
if (input.update) await runner.updateBaselines(results);
|
|
574
|
+
const rawJson = attachArtReportOwner(generateVrtJsonReport(results, summary), target);
|
|
575
|
+
const html = generateVrtReport(results, summary);
|
|
576
|
+
await mkdir(reportDir, { recursive: true });
|
|
577
|
+
await writeSessionReport(target.jsonReportPath, rawJson);
|
|
578
|
+
await writeSessionReport(target.htmlReportPath, html);
|
|
579
|
+
artifacts.clear();
|
|
580
|
+
outcome = {
|
|
581
|
+
status: 200,
|
|
582
|
+
body: {
|
|
583
|
+
success: true,
|
|
584
|
+
results: await artifacts.results(results),
|
|
585
|
+
summary,
|
|
586
|
+
reports: {
|
|
587
|
+
json: artifacts.add(rawJson, "application/json"),
|
|
588
|
+
html: artifacts.add(html, "text/html")
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
};
|
|
592
|
+
} catch (error) {
|
|
593
|
+
outcome = {
|
|
594
|
+
status: 400,
|
|
595
|
+
body: { error: error instanceof Error ? error.message : String(error) }
|
|
596
|
+
};
|
|
597
|
+
} finally {
|
|
598
|
+
try {
|
|
599
|
+
await runner?.close();
|
|
600
|
+
} catch (error) {
|
|
601
|
+
outcome = {
|
|
602
|
+
status: 500,
|
|
603
|
+
body: { error: `Capture cleanup failed: ${String(error)}` }
|
|
604
|
+
};
|
|
605
|
+
}
|
|
606
|
+
busy = void 0;
|
|
607
|
+
if (!response.destroyed) json(response, outcome.body, outcome.status);
|
|
608
|
+
}
|
|
609
|
+
})().catch((error) => {
|
|
610
|
+
busy = void 0;
|
|
611
|
+
if (!response.destroyed && !response.headersSent) json(response, { error: String(error) }, 500);
|
|
612
|
+
});
|
|
613
|
+
});
|
|
614
|
+
await new Promise((resolve, reject) => {
|
|
615
|
+
server.once("error", reject);
|
|
616
|
+
server.listen(0, "127.0.0.1", resolve);
|
|
617
|
+
});
|
|
618
|
+
const address = server.address();
|
|
619
|
+
if (!address || typeof address === "string") throw new Error("Missing loopback listener");
|
|
620
|
+
host = `127.0.0.1:${address.port}`;
|
|
621
|
+
return {
|
|
622
|
+
endpoint: `http://${host}`,
|
|
623
|
+
token,
|
|
624
|
+
close() {
|
|
625
|
+
return closeTask ??= (async () => {
|
|
626
|
+
closing = true;
|
|
627
|
+
await busy;
|
|
628
|
+
artifacts.clear();
|
|
629
|
+
await new Promise((resolve, reject) => server.close((error) => error ? reject(error) : resolve()));
|
|
630
|
+
})();
|
|
631
|
+
}
|
|
632
|
+
};
|
|
633
|
+
}
|
|
634
|
+
async function runServe(options) {
|
|
635
|
+
const session = await startHostedVrtSession(options);
|
|
636
|
+
console.log(" This session token is a live credential; do not share it or retain it in captured logs.");
|
|
637
|
+
console.log(` VRT endpoint: ${session.endpoint}\n Session token: ${session.token}\n`);
|
|
638
|
+
const stop = () => {
|
|
639
|
+
session.close().then(() => {
|
|
640
|
+
process.exitCode = 0;
|
|
641
|
+
}, (error) => {
|
|
642
|
+
console.error("VRT session cleanup failed:", error);
|
|
643
|
+
process.exitCode = 1;
|
|
644
|
+
});
|
|
645
|
+
};
|
|
646
|
+
process.once("SIGINT", stop);
|
|
647
|
+
process.once("SIGTERM", stop);
|
|
648
|
+
}
|
|
649
|
+
//#endregion
|
|
379
650
|
//#region src/cli/index.ts
|
|
380
651
|
/**
|
|
381
652
|
* Musea CLI
|
|
@@ -390,7 +661,7 @@ function isRecord(value) {
|
|
|
390
661
|
*
|
|
391
662
|
* Options:
|
|
392
663
|
* -u, --update Update baseline snapshots
|
|
393
|
-
* -c, --config Path to
|
|
664
|
+
* -c, --config Path to Vite config (default: Vite config discovery)
|
|
394
665
|
* -o, --output Output directory for reports (default: .vize)
|
|
395
666
|
* -t, --threshold Diff threshold percentage (default: 0.1)
|
|
396
667
|
* -w, --workers Number of concurrent captures (default: 1)
|
|
@@ -403,7 +674,6 @@ function parseArgs(args) {
|
|
|
403
674
|
const options = {
|
|
404
675
|
command: "run",
|
|
405
676
|
update: false,
|
|
406
|
-
config: "vite.config.ts",
|
|
407
677
|
output: ".vize",
|
|
408
678
|
threshold: .1,
|
|
409
679
|
thresholdProvided: false,
|
|
@@ -418,7 +688,10 @@ function parseArgs(args) {
|
|
|
418
688
|
let i = 0;
|
|
419
689
|
if (args.length > 0 && !args[0].startsWith("-")) {
|
|
420
690
|
const sub = args[0];
|
|
421
|
-
if (sub === "
|
|
691
|
+
if (sub === "serve") {
|
|
692
|
+
options.command = "serve";
|
|
693
|
+
i = 1;
|
|
694
|
+
} else if (sub === "approve") {
|
|
422
695
|
options.command = "approve";
|
|
423
696
|
i = 1;
|
|
424
697
|
if (args.length > 1 && !args[1].startsWith("-")) {
|
|
@@ -444,7 +717,7 @@ function parseArgs(args) {
|
|
|
444
717
|
break;
|
|
445
718
|
case "-c":
|
|
446
719
|
case "--config":
|
|
447
|
-
options.config = args[++i] ||
|
|
720
|
+
options.config = args[++i] || void 0;
|
|
448
721
|
break;
|
|
449
722
|
case "-o":
|
|
450
723
|
case "--output":
|
|
@@ -491,10 +764,6 @@ function parseThreshold(value) {
|
|
|
491
764
|
const threshold = Number.parseFloat(value ?? "");
|
|
492
765
|
return Number.isFinite(threshold) ? threshold : .1;
|
|
493
766
|
}
|
|
494
|
-
function parseWorkers(value) {
|
|
495
|
-
const workers = Number.parseInt(value ?? "", 10);
|
|
496
|
-
return Number.isFinite(workers) ? Math.max(1, workers) : 1;
|
|
497
|
-
}
|
|
498
767
|
function printHelp() {
|
|
499
768
|
console.log(`
|
|
500
769
|
Musea VRT - Visual Regression Testing for Component Gallery
|
|
@@ -507,11 +776,12 @@ Commands:
|
|
|
507
776
|
approve [pattern] Approve failed snapshots and update baselines
|
|
508
777
|
Optional pattern filters which snapshots to approve
|
|
509
778
|
clean Remove orphaned snapshots (no matching art/variant)
|
|
779
|
+
serve --gallery-url Connect a secure hosted gallery to a local VRT session
|
|
510
780
|
generate <component> Auto-generate .art.vue from a Vue component
|
|
511
781
|
|
|
512
782
|
Options:
|
|
513
783
|
-u, --update Update baseline snapshots with current screenshots
|
|
514
|
-
-c, --config <path> Path to
|
|
784
|
+
-c, --config <path> Path to Vite config file (default: Vite config discovery)
|
|
515
785
|
-o, --output <dir> Output directory for reports (default: .vize)
|
|
516
786
|
-t, --threshold <n> Diff threshold percentage (default: 0.1)
|
|
517
787
|
-b, --base-url <url> Base URL for dev server (default: http://localhost:5173)
|
|
@@ -576,8 +846,19 @@ async function main() {
|
|
|
576
846
|
}
|
|
577
847
|
return;
|
|
578
848
|
}
|
|
579
|
-
|
|
580
|
-
options.
|
|
849
|
+
const { fileSet, vrt, configDir, previewBasePath } = await loadMuseaConfiguration(options.config, cwd);
|
|
850
|
+
options.vrt = vrt;
|
|
851
|
+
options.configDir = configDir;
|
|
852
|
+
if (options.command === "serve") {
|
|
853
|
+
try {
|
|
854
|
+
await runServe(options);
|
|
855
|
+
} catch (error) {
|
|
856
|
+
console.error("\n Error:", error);
|
|
857
|
+
process.exit(1);
|
|
858
|
+
}
|
|
859
|
+
return;
|
|
860
|
+
}
|
|
861
|
+
options.previewBasePath = vrt?.previewBasePath ?? previewBasePath;
|
|
581
862
|
if (options.galleryUrl) {
|
|
582
863
|
const hosted = await loadHostedGallery(options.galleryUrl);
|
|
583
864
|
options.previewUrls = hosted.previewUrls;
|
|
@@ -587,7 +868,6 @@ async function main() {
|
|
|
587
868
|
else if (options.command === "clean") await runClean(options, hosted.arts);
|
|
588
869
|
return;
|
|
589
870
|
}
|
|
590
|
-
const fileSet = await loadMuseaFileSet(options.config, cwd);
|
|
591
871
|
options.projectRoot = fileSet.projectRoot;
|
|
592
872
|
console.log(" Scanning for art files...");
|
|
593
873
|
const artFilePaths = await scanArtFiles(fileSet.root, fileSet.include, fileSet.exclude);
|