@yysports/tools 3.0.1 → 3.0.2

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.
@@ -2,8 +2,17 @@ type RRWebEvent = any;
2
2
  export default class Replay {
3
3
  private static _events;
4
4
  private static _stop;
5
+ private static _loading;
5
6
  private static _bytes;
6
- static run(): void;
7
+ /**
8
+ * 启动录制。
9
+ *
10
+ * rrweb(record 与 console 插件)改为动态 import:`enableReplay: false` 时完全不加载,
11
+ * 接入方的打包产物里也就不含 rrweb;开启回放时 rrweb 由接入方打包器拆成独立异步 chunk。
12
+ * 代价是启动异步化——加载完成前发生的错误不带回放(`snapshot()` 返回空数组,
13
+ * 错误本体的上报不受影响)。
14
+ */
15
+ static run(): Promise<void>;
7
16
  /** 截断到体积上限,保留最近片段 */
8
17
  private static truncate;
9
18
  /** 快照当前回放片段(不移除,待上报成功后 commitSnapshot) */
@@ -1,10 +1,11 @@
1
1
  import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
+ import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
2
3
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
4
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
5
+ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
3
6
  import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
4
7
  import _createClass from "@babel/runtime/helpers/esm/createClass";
5
8
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
6
- import { record } from '@rrweb/record';
7
- import { getRecordConsolePlugin } from '@rrweb/rrweb-plugin-console-record';
8
9
  import Config from "./Config";
9
10
  var Replay = /*#__PURE__*/function () {
10
11
  function Replay() {
@@ -12,36 +13,77 @@ var Replay = /*#__PURE__*/function () {
12
13
  }
13
14
  _createClass(Replay, null, [{
14
15
  key: "run",
15
- value: function run() {
16
- var _this = this;
17
- if (this._stop || !Config.data.enableReplay) {
18
- return;
19
- }
20
- try {
21
- this._stop = record(_objectSpread(_objectSpread({
22
- emit: function emit(e) {
23
- _this._events.push(e);
24
- _this._bytes += JSON.stringify(e).length;
25
- _this.truncate();
26
- },
27
- // 输入掩码:password 类型强制掩码,防止敏感输入进入回放文件;
28
- // 其余类型可由接入方通过 replayMaskTextClass 扩展
29
- maskInputOptions: {
30
- password: true
16
+ value: (
17
+ /**
18
+ * 启动录制。
19
+ *
20
+ * rrweb(record 与 console 插件)改为动态 import:`enableReplay: false` 时完全不加载,
21
+ * 接入方的打包产物里也就不含 rrweb;开启回放时 rrweb 由接入方打包器拆成独立异步 chunk。
22
+ * 代价是启动异步化——加载完成前发生的错误不带回放(`snapshot()` 返回空数组,
23
+ * 错误本体的上报不受影响)。
24
+ */
25
+ function () {
26
+ var _run = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
27
+ var _this = this;
28
+ var _yield$Promise$all, _yield$Promise$all2, startRecord, getRecordConsolePlugin;
29
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
30
+ while (1) switch (_context.prev = _context.next) {
31
+ case 0:
32
+ if (!(this._stop || this._loading || !Config.data.enableReplay)) {
33
+ _context.next = 2;
34
+ break;
35
+ }
36
+ return _context.abrupt("return");
37
+ case 2:
38
+ this._loading = true;
39
+ _context.prev = 3;
40
+ _context.next = 6;
41
+ return Promise.all([import('@rrweb/record'), import('@rrweb/rrweb-plugin-console-record')]);
42
+ case 6:
43
+ _yield$Promise$all = _context.sent;
44
+ _yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 2);
45
+ startRecord = _yield$Promise$all2[0].record;
46
+ getRecordConsolePlugin = _yield$Promise$all2[1].getRecordConsolePlugin;
47
+ this._stop = startRecord(_objectSpread(_objectSpread({
48
+ emit: function emit(e) {
49
+ _this._events.push(e);
50
+ _this._bytes += JSON.stringify(e).length;
51
+ _this.truncate();
52
+ },
53
+ // 输入掩码:password 类型强制掩码,防止敏感输入进入回放文件;
54
+ // 其余类型可由接入方通过 replayMaskTextClass 扩展
55
+ maskInputOptions: {
56
+ password: true
57
+ }
58
+ }, Config.data.replayMaskTextClass ? {
59
+ maskTextClass: Config.data.replayMaskTextClass
60
+ } : {}), {}, {
61
+ plugins: [getRecordConsolePlugin({
62
+ level: ['log', 'info', 'warn', 'error', 'debug']
63
+ })]
64
+ }));
65
+ _context.next = 16;
66
+ break;
67
+ case 13:
68
+ _context.prev = 13;
69
+ _context.t0 = _context["catch"](3);
70
+ // 加载或启动失败:静默降级,仅回放不可用
71
+ this._stop = undefined;
72
+ case 16:
73
+ _context.prev = 16;
74
+ this._loading = false;
75
+ return _context.finish(16);
76
+ case 19:
77
+ case "end":
78
+ return _context.stop();
31
79
  }
32
- }, Config.data.replayMaskTextClass ? {
33
- maskTextClass: Config.data.replayMaskTextClass
34
- } : {}), {}, {
35
- plugins: [getRecordConsolePlugin({
36
- level: ['log', 'info', 'warn', 'error', 'debug']
37
- })]
38
- }));
39
- } catch (err) {
40
- this._stop = undefined;
80
+ }, _callee, this, [[3, 13, 16, 19]]);
81
+ }));
82
+ function run() {
83
+ return _run.apply(this, arguments);
41
84
  }
42
- }
43
-
44
- /** 截断到体积上限,保留最近片段 */
85
+ return run;
86
+ }() /** 截断到体积上限,保留最近片段 */)
45
87
  }, {
46
88
  key: "truncate",
47
89
  value: function truncate() {
@@ -81,6 +123,8 @@ var Replay = /*#__PURE__*/function () {
81
123
  }();
82
124
  _defineProperty(Replay, "_events", []);
83
125
  _defineProperty(Replay, "_stop", void 0);
126
+ // rrweb 异步加载中的标记:避免 init 被重复调用时启动两个录制实例
127
+ _defineProperty(Replay, "_loading", false);
84
128
  // 录制阶段的累计体积(近似值),达到 replayMaxBytes 后从最早事件开始截断
85
129
  _defineProperty(Replay, "_bytes", 0);
86
130
  export { Replay as default };
@@ -44,7 +44,8 @@ var Track = /*#__PURE__*/function () {
44
44
  key: "run",
45
45
  value: function run() {
46
46
  Listener.run();
47
- Replay.run();
47
+ // 回放为异步启动(rrweb 懒加载),不阻塞 init;未开回放时不会加载 rrweb
48
+ void Replay.run();
48
49
  // 版本上报已并入信封 sdkVersion,不再有独立请求
49
50
  Beacon.start();
50
51
  }
@@ -2,8 +2,17 @@ type RRWebEvent = any;
2
2
  export default class Replay {
3
3
  private static _events;
4
4
  private static _stop;
5
+ private static _loading;
5
6
  private static _bytes;
6
- static run(): void;
7
+ /**
8
+ * 启动录制。
9
+ *
10
+ * rrweb(record 与 console 插件)改为动态 import:`enableReplay: false` 时完全不加载,
11
+ * 接入方的打包产物里也就不含 rrweb;开启回放时 rrweb 由接入方打包器拆成独立异步 chunk。
12
+ * 代价是启动异步化——加载完成前发生的错误不带回放(`snapshot()` 返回空数组,
13
+ * 错误本体的上报不受影响)。
14
+ */
15
+ static run(): Promise<void>;
7
16
  /** 截断到体积上限,保留最近片段 */
8
17
  private static truncate;
9
18
  /** 快照当前回放片段(不移除,待上报成功后 commitSnapshot) */
@@ -32,16 +32,27 @@ __export(Replay_exports, {
32
32
  default: () => Replay
33
33
  });
34
34
  module.exports = __toCommonJS(Replay_exports);
35
- var import_record = require("@rrweb/record");
36
- var import_rrweb_plugin_console_record = require("@rrweb/rrweb-plugin-console-record");
37
35
  var import_Config = __toESM(require("./Config"));
38
36
  var Replay = class {
39
- static run() {
40
- if (this._stop || !import_Config.default.data.enableReplay) {
37
+ /**
38
+ * 启动录制。
39
+ *
40
+ * rrweb(record 与 console 插件)改为动态 import:`enableReplay: false` 时完全不加载,
41
+ * 接入方的打包产物里也就不含 rrweb;开启回放时 rrweb 由接入方打包器拆成独立异步 chunk。
42
+ * 代价是启动异步化——加载完成前发生的错误不带回放(`snapshot()` 返回空数组,
43
+ * 错误本体的上报不受影响)。
44
+ */
45
+ static async run() {
46
+ if (this._stop || this._loading || !import_Config.default.data.enableReplay) {
41
47
  return;
42
48
  }
49
+ this._loading = true;
43
50
  try {
44
- this._stop = (0, import_record.record)({
51
+ const [{ record: startRecord }, { getRecordConsolePlugin }] = await Promise.all([
52
+ import("@rrweb/record"),
53
+ import("@rrweb/rrweb-plugin-console-record")
54
+ ]);
55
+ this._stop = startRecord({
45
56
  emit: (e) => {
46
57
  this._events.push(e);
47
58
  this._bytes += JSON.stringify(e).length;
@@ -52,13 +63,15 @@ var Replay = class {
52
63
  maskInputOptions: { password: true },
53
64
  ...import_Config.default.data.replayMaskTextClass ? { maskTextClass: import_Config.default.data.replayMaskTextClass } : {},
54
65
  plugins: [
55
- (0, import_rrweb_plugin_console_record.getRecordConsolePlugin)({
66
+ getRecordConsolePlugin({
56
67
  level: ["log", "info", "warn", "error", "debug"]
57
68
  })
58
69
  ]
59
70
  });
60
71
  } catch (err) {
61
72
  this._stop = void 0;
73
+ } finally {
74
+ this._loading = false;
62
75
  }
63
76
  }
64
77
  /** 截断到体积上限,保留最近片段 */
@@ -90,5 +103,7 @@ var Replay = class {
90
103
  }
91
104
  };
92
105
  Replay._events = [];
106
+ // rrweb 异步加载中的标记:避免 init 被重复调用时启动两个录制实例
107
+ Replay._loading = false;
93
108
  // 录制阶段的累计体积(近似值),达到 replayMaxBytes 后从最早事件开始截断
94
109
  Replay._bytes = 0;
@@ -59,7 +59,7 @@ var Track = class {
59
59
  // 需要初始化执行的组件都需在这里初始化调用
60
60
  static run() {
61
61
  import_Listener.default.run();
62
- import_Replay.default.run();
62
+ void import_Replay.default.run();
63
63
  import_Beacon.default.start();
64
64
  }
65
65
  // 获取当前页面模块名称
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yysports/tools",
3
- "version": "3.0.1",
3
+ "version": "3.0.2",
4
4
  "description": "常用工具函数库",
5
5
  "homepage": "https://git.pousheng.com/sport-service-department/pousheng-guard/yysports_tools#readme",
6
6
  "bugs": {