@xbrowser/cli 1.9.0 → 1.9.1

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.
@@ -22,9 +22,33 @@ var DEFAULT_EXCLUDE_TYPES = [
22
22
  "mousedown"
23
23
  ];
24
24
  function filterRecording(inputPath, outputPath, excludeTypes) {
25
- const content = fs.readFileSync(inputPath, "utf-8");
26
- const recording = yaml.parse(content);
27
- const events = recording.actions || recording.events || [];
25
+ let recording;
26
+ try {
27
+ const content = fs.readFileSync(inputPath, "utf-8");
28
+ recording = yaml.parse(content);
29
+ } catch (e) {
30
+ throw new Error(`Failed to read "${inputPath}": ${e instanceof Error ? e.message.split("\n")[0] : String(e)}`);
31
+ }
32
+ if (recording === null || typeof recording !== "object" || Array.isArray(recording)) {
33
+ throw new Error(`"${inputPath}" does not contain a valid recording (expected a YAML object with events or actions).`);
34
+ }
35
+ let rawEvents = recording.events ?? [];
36
+ const rawActions = recording.actions;
37
+ if (Array.isArray(rawActions) && rawEvents.length === 0) {
38
+ rawEvents = rawActions.map((a) => {
39
+ const action = a;
40
+ const element = action.element ?? {};
41
+ return {
42
+ type: action.type,
43
+ selector: element.selector ?? action.selector,
44
+ data: { ...action.data, value: action.value, key: action.key },
45
+ scrollX: action.scrollX,
46
+ scrollY: action.scrollY
47
+ };
48
+ });
49
+ delete recording.actions;
50
+ }
51
+ const events = rawEvents;
28
52
  const originalCount = events.length;
29
53
  const exclude = excludeTypes || DEFAULT_EXCLUDE_TYPES;
30
54
  const filteredEvents = events.filter((event) => {
@@ -417,12 +417,24 @@ var XBrowserPluginLoader = class {
417
417
  // src/utils/plugin-singleton.ts
418
418
  var pluginLoader = null;
419
419
  var pluginsScanned = false;
420
+ function silenceSchemaWarnings(fn) {
421
+ if (process.env.XBROWSER_DEBUG || process.env.VITEST_WORKER_ID) return fn();
422
+ const originalWarn = console.warn;
423
+ console.warn = (...args) => {
424
+ const msg = typeof args[0] === "string" ? args[0] : "";
425
+ if (msg.includes('has no "result" schema')) return;
426
+ originalWarn(...args);
427
+ };
428
+ return fn().finally(() => {
429
+ console.warn = originalWarn;
430
+ });
431
+ }
420
432
  async function getPluginLoader() {
421
433
  if (!pluginLoader) {
422
434
  pluginLoader = new XBrowserPluginLoader();
423
435
  }
424
436
  if (!pluginsScanned) {
425
- await pluginLoader.scanAndLoad();
437
+ await silenceSchemaWarnings(() => pluginLoader.scanAndLoad());
426
438
  pluginsScanned = true;
427
439
  }
428
440
  return pluginLoader;
@@ -2,9 +2,33 @@
2
2
  import * as fs from "fs";
3
3
  import * as yaml from "yaml";
4
4
  function extractRecording(filePath) {
5
- const content = fs.readFileSync(filePath, "utf-8");
6
- const recording = yaml.parse(content);
7
- const events = recording.actions || recording.events || [];
5
+ let recording;
6
+ try {
7
+ const content = fs.readFileSync(filePath, "utf-8");
8
+ recording = yaml.parse(content);
9
+ } catch (e) {
10
+ throw new Error(`Failed to read "${filePath}": ${e instanceof Error ? e.message.split("\n")[0] : String(e)}`);
11
+ }
12
+ if (recording === null || typeof recording !== "object" || Array.isArray(recording)) {
13
+ throw new Error(`"${filePath}" does not contain a valid recording (expected a YAML object with events or actions).`);
14
+ }
15
+ let rawEvents = recording.events ?? [];
16
+ const rawActions = recording.actions;
17
+ if (Array.isArray(rawActions) && rawEvents.length === 0) {
18
+ rawEvents = rawActions.map((a) => {
19
+ const action = a;
20
+ const element = action.element ?? {};
21
+ return {
22
+ type: action.type,
23
+ selector: element.selector ?? action.selector,
24
+ tagName: element.tag ?? action.tagName,
25
+ data: { ...action.data, value: action.value, key: action.key },
26
+ timestamp: action.timestamp,
27
+ pageState: action.pageState
28
+ };
29
+ });
30
+ }
31
+ const events = rawEvents;
8
32
  const keyEvents = [];
9
33
  const eventTypes = {};
10
34
  for (const event of events) {