@xifan0/monitor-web 0.0.2-beta.12 → 0.0.2-beta.13

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/dist/index.js CHANGED
@@ -37,17 +37,23 @@ __export(index_exports, {
37
37
  setUser: () => setUser
38
38
  });
39
39
  module.exports = __toCommonJS(index_exports);
40
- var SentryModule = __toESM(require("@sentry/react"));
40
+ var Sentry = __toESM(require("@sentry/react"));
41
41
 
42
42
  // ../monitor-core/src/createMonitor.ts
43
43
  function createMonitor(sentry) {
44
+ const sentryInstance = sentry && typeof sentry === "object" && sentry.default ? sentry.default : sentry;
44
45
  const monitor = {
45
46
  init(options) {
46
- return sentry.init(options);
47
+ if (!sentryInstance || typeof sentryInstance.init !== "function") {
48
+ throw new Error(
49
+ "Sentry.init is not a function. Please ensure @sentry/react is properly imported."
50
+ );
51
+ }
52
+ return sentryInstance.init(options);
47
53
  },
48
54
  /** 上报异常 */
49
55
  captureException(error, ctx) {
50
- return sentry.captureException(error, (scope) => {
56
+ return sentryInstance.captureException(error, (scope) => {
51
57
  (ctx == null ? void 0 : ctx.tags) && scope.setTags(ctx.tags);
52
58
  (ctx == null ? void 0 : ctx.extra) && scope.setExtras(ctx.extra);
53
59
  return scope;
@@ -55,7 +61,7 @@ function createMonitor(sentry) {
55
61
  },
56
62
  /** 发送消息/提醒/日志 */
57
63
  captureMessage(message, ctx) {
58
- return sentry.captureMessage(message, (scope) => {
64
+ return sentryInstance.captureMessage(message, (scope) => {
59
65
  (ctx == null ? void 0 : ctx.tags) && scope.setTags(ctx.tags);
60
66
  (ctx == null ? void 0 : ctx.extra) && scope.setExtras(ctx.extra);
61
67
  return scope;
@@ -63,7 +69,7 @@ function createMonitor(sentry) {
63
69
  },
64
70
  /** 设置用户信息 */
65
71
  setUser(user) {
66
- return sentry.setUser(user);
72
+ return sentryInstance.setUser(user);
67
73
  }
68
74
  };
69
75
  const proxy = new Proxy(monitor, {
@@ -71,13 +77,13 @@ function createMonitor(sentry) {
71
77
  if (key in target) {
72
78
  return Reflect.get(target, key, receiver);
73
79
  }
74
- const sentryFn = sentry[key];
80
+ const sentryFn = sentryInstance[key];
75
81
  if (typeof sentryFn === "function") {
76
82
  const isClass = sentryFn.prototype && sentryFn.prototype.constructor === sentryFn && Object.getOwnPropertyNames(sentryFn.prototype).length > 1;
77
83
  if (isClass) {
78
84
  return sentryFn;
79
85
  }
80
- return sentryFn.bind(sentry);
86
+ return sentryFn.bind(sentryInstance);
81
87
  }
82
88
  return sentryFn;
83
89
  }
@@ -86,7 +92,6 @@ function createMonitor(sentry) {
86
92
  }
87
93
 
88
94
  // src/index.ts
89
- var Sentry = SentryModule.default || SentryModule;
90
95
  var Monitor = createMonitor(Sentry);
91
96
  var { init, captureException, captureMessage, setUser } = Monitor;
92
97
  var index_default = Monitor;
package/dist/index.mjs CHANGED
@@ -1,15 +1,21 @@
1
1
  // src/index.ts
2
- import * as SentryModule from "@sentry/react";
2
+ import * as Sentry from "@sentry/react";
3
3
 
4
4
  // ../monitor-core/src/createMonitor.ts
5
5
  function createMonitor(sentry) {
6
+ const sentryInstance = sentry && typeof sentry === "object" && sentry.default ? sentry.default : sentry;
6
7
  const monitor = {
7
8
  init(options) {
8
- return sentry.init(options);
9
+ if (!sentryInstance || typeof sentryInstance.init !== "function") {
10
+ throw new Error(
11
+ "Sentry.init is not a function. Please ensure @sentry/react is properly imported."
12
+ );
13
+ }
14
+ return sentryInstance.init(options);
9
15
  },
10
16
  /** 上报异常 */
11
17
  captureException(error, ctx) {
12
- return sentry.captureException(error, (scope) => {
18
+ return sentryInstance.captureException(error, (scope) => {
13
19
  (ctx == null ? void 0 : ctx.tags) && scope.setTags(ctx.tags);
14
20
  (ctx == null ? void 0 : ctx.extra) && scope.setExtras(ctx.extra);
15
21
  return scope;
@@ -17,7 +23,7 @@ function createMonitor(sentry) {
17
23
  },
18
24
  /** 发送消息/提醒/日志 */
19
25
  captureMessage(message, ctx) {
20
- return sentry.captureMessage(message, (scope) => {
26
+ return sentryInstance.captureMessage(message, (scope) => {
21
27
  (ctx == null ? void 0 : ctx.tags) && scope.setTags(ctx.tags);
22
28
  (ctx == null ? void 0 : ctx.extra) && scope.setExtras(ctx.extra);
23
29
  return scope;
@@ -25,7 +31,7 @@ function createMonitor(sentry) {
25
31
  },
26
32
  /** 设置用户信息 */
27
33
  setUser(user) {
28
- return sentry.setUser(user);
34
+ return sentryInstance.setUser(user);
29
35
  }
30
36
  };
31
37
  const proxy = new Proxy(monitor, {
@@ -33,13 +39,13 @@ function createMonitor(sentry) {
33
39
  if (key in target) {
34
40
  return Reflect.get(target, key, receiver);
35
41
  }
36
- const sentryFn = sentry[key];
42
+ const sentryFn = sentryInstance[key];
37
43
  if (typeof sentryFn === "function") {
38
44
  const isClass = sentryFn.prototype && sentryFn.prototype.constructor === sentryFn && Object.getOwnPropertyNames(sentryFn.prototype).length > 1;
39
45
  if (isClass) {
40
46
  return sentryFn;
41
47
  }
42
- return sentryFn.bind(sentry);
48
+ return sentryFn.bind(sentryInstance);
43
49
  }
44
50
  return sentryFn;
45
51
  }
@@ -48,7 +54,6 @@ function createMonitor(sentry) {
48
54
  }
49
55
 
50
56
  // src/index.ts
51
- var Sentry = SentryModule.default || SentryModule;
52
57
  var Monitor = createMonitor(Sentry);
53
58
  var { init, captureException, captureMessage, setUser } = Monitor;
54
59
  var index_default = Monitor;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xifan0/monitor-web",
3
- "version": "0.0.2-beta.12",
3
+ "version": "0.0.2-beta.13",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",
@@ -20,7 +20,7 @@
20
20
  },
21
21
  "dependencies": {
22
22
  "@sentry/react": "^7",
23
- "@xifan0/monitor-core": "0.0.2-beta.12"
23
+ "@xifan0/monitor-core": "0.0.2-beta.13"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@sentry/react": "^7",