@midscene/shared 1.7.5-beta-20260420052829.0 → 1.7.5-beta-20260420065618.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.
@@ -21,6 +21,14 @@ class CLIError extends Error {
21
21
  super(message), _define_property(this, "exitCode", void 0), this.exitCode = exitCode;
22
22
  }
23
23
  }
24
+ function reportCLIError(error, log = console.error) {
25
+ if (error instanceof CLIError) {
26
+ log(error.message);
27
+ return error.exitCode;
28
+ }
29
+ log(error);
30
+ return 1;
31
+ }
24
32
  function parseValue(raw) {
25
33
  if (raw.startsWith('{') || raw.startsWith('[')) try {
26
34
  return JSON.parse(raw);
@@ -253,4 +261,4 @@ async function runToolsCLI(tools, scriptName, options) {
253
261
  await tools.destroy();
254
262
  if (result.isError) throw new CLIError('Command failed', 1);
255
263
  }
256
- export { CLIError, parseCliArgs, parseValue, removePrefix, runToolsCLI };
264
+ export { CLIError, parseCliArgs, parseValue, removePrefix, reportCLIError, runToolsCLI };
@@ -1,2 +1,2 @@
1
- import { CLIError, parseCliArgs, parseValue, removePrefix, runToolsCLI } from "./cli-runner.mjs";
2
- export { CLIError, parseCliArgs, parseValue, removePrefix, runToolsCLI };
1
+ import { CLIError, parseCliArgs, parseValue, removePrefix, reportCLIError, runToolsCLI } from "./cli-runner.mjs";
2
+ export { CLIError, parseCliArgs, parseValue, removePrefix, reportCLIError, runToolsCLI };
@@ -37,6 +37,7 @@ __webpack_require__.d(__webpack_exports__, {
37
37
  parseCliArgs: ()=>parseCliArgs,
38
38
  parseValue: ()=>parseValue,
39
39
  runToolsCLI: ()=>runToolsCLI,
40
+ reportCLIError: ()=>reportCLIError,
40
41
  removePrefix: ()=>removePrefix
41
42
  });
42
43
  const external_node_fs_namespaceObject = require("node:fs");
@@ -63,6 +64,14 @@ class CLIError extends Error {
63
64
  super(message), _define_property(this, "exitCode", void 0), this.exitCode = exitCode;
64
65
  }
65
66
  }
67
+ function reportCLIError(error, log = console.error) {
68
+ if (error instanceof CLIError) {
69
+ log(error.message);
70
+ return error.exitCode;
71
+ }
72
+ log(error);
73
+ return 1;
74
+ }
66
75
  function parseValue(raw) {
67
76
  if (raw.startsWith('{') || raw.startsWith('[')) try {
68
77
  return JSON.parse(raw);
@@ -299,12 +308,14 @@ exports.CLIError = __webpack_exports__.CLIError;
299
308
  exports.parseCliArgs = __webpack_exports__.parseCliArgs;
300
309
  exports.parseValue = __webpack_exports__.parseValue;
301
310
  exports.removePrefix = __webpack_exports__.removePrefix;
311
+ exports.reportCLIError = __webpack_exports__.reportCLIError;
302
312
  exports.runToolsCLI = __webpack_exports__.runToolsCLI;
303
313
  for(var __rspack_i in __webpack_exports__)if (-1 === [
304
314
  "CLIError",
305
315
  "parseCliArgs",
306
316
  "parseValue",
307
317
  "removePrefix",
318
+ "reportCLIError",
308
319
  "runToolsCLI"
309
320
  ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
310
321
  Object.defineProperty(exports, '__esModule', {
@@ -28,6 +28,7 @@ __webpack_require__.d(__webpack_exports__, {
28
28
  parseCliArgs: ()=>external_cli_runner_js_namespaceObject.parseCliArgs,
29
29
  parseValue: ()=>external_cli_runner_js_namespaceObject.parseValue,
30
30
  runToolsCLI: ()=>external_cli_runner_js_namespaceObject.runToolsCLI,
31
+ reportCLIError: ()=>external_cli_runner_js_namespaceObject.reportCLIError,
31
32
  removePrefix: ()=>external_cli_runner_js_namespaceObject.removePrefix
32
33
  });
33
34
  const external_cli_runner_js_namespaceObject = require("./cli-runner.js");
@@ -35,12 +36,14 @@ exports.CLIError = __webpack_exports__.CLIError;
35
36
  exports.parseCliArgs = __webpack_exports__.parseCliArgs;
36
37
  exports.parseValue = __webpack_exports__.parseValue;
37
38
  exports.removePrefix = __webpack_exports__.removePrefix;
39
+ exports.reportCLIError = __webpack_exports__.reportCLIError;
38
40
  exports.runToolsCLI = __webpack_exports__.runToolsCLI;
39
41
  for(var __rspack_i in __webpack_exports__)if (-1 === [
40
42
  "CLIError",
41
43
  "parseCliArgs",
42
44
  "parseValue",
43
45
  "removePrefix",
46
+ "reportCLIError",
44
47
  "runToolsCLI"
45
48
  ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
46
49
  Object.defineProperty(exports, '__esModule', {
@@ -16,6 +16,7 @@ export declare class CLIError extends Error {
16
16
  exitCode: number;
17
17
  constructor(message: string, exitCode?: number);
18
18
  }
19
+ export declare function reportCLIError(error: unknown, log?: (message?: unknown, ...optionalParams: unknown[]) => void): number;
19
20
  export declare function parseValue(raw: string): unknown;
20
21
  export declare function parseCliArgs(args: string[]): Record<string, unknown>;
21
22
  export declare function removePrefix(name: string, prefix?: string): string;
@@ -1,2 +1,2 @@
1
- export { runToolsCLI, CLIError, parseValue, parseCliArgs, removePrefix, } from './cli-runner';
1
+ export { runToolsCLI, CLIError, reportCLIError, parseValue, parseCliArgs, removePrefix, } from './cli-runner';
2
2
  export type { CLIRunnerOptions, CLIExtraCommand } from './cli-runner';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midscene/shared",
3
- "version": "1.7.5-beta-20260420052829.0",
3
+ "version": "1.7.5-beta-20260420065618.0",
4
4
  "repository": "https://github.com/web-infra-dev/midscene",
5
5
  "homepage": "https://midscenejs.com/",
6
6
  "types": "./dist/types/index.d.ts",
@@ -44,6 +44,22 @@ export class CLIError extends Error {
44
44
  }
45
45
  }
46
46
 
47
+ export function reportCLIError(
48
+ error: unknown,
49
+ log: (
50
+ message?: unknown,
51
+ ...optionalParams: unknown[]
52
+ ) => void = console.error,
53
+ ): number {
54
+ if (error instanceof CLIError) {
55
+ log(error.message);
56
+ return error.exitCode;
57
+ }
58
+
59
+ log(error);
60
+ return 1;
61
+ }
62
+
47
63
  export function parseValue(raw: string): unknown {
48
64
  // JSON objects/arrays
49
65
  if (raw.startsWith('{') || raw.startsWith('[')) {
package/src/cli/index.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export {
2
2
  runToolsCLI,
3
3
  CLIError,
4
+ reportCLIError,
4
5
  parseValue,
5
6
  parseCliArgs,
6
7
  removePrefix,