@fz-firefly/vue 0.0.0-stage → 0.2.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 CHANGED
@@ -1,3 +1,84 @@
1
- # Temporary Holding Version
1
+ # @fz-firefly/vue
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ 萤火虫 SDK 的 Vue 2 / Vue 3 一键接入包。安装后只需要调用一次 `initFirefly`,内部会自动创建客户端、接入 Vue 错误处理并绑定路由面包屑。
4
+
5
+ `@fz-firefly/web`、`@fz-firefly/core`、`@fz-firefly/vue-plugin` 都是这个包的内部依赖,用户不需要单独安装或 import。
6
+
7
+ ## 安装
8
+
9
+ ```bash
10
+ pnpm add @fz-firefly/vue
11
+ ```
12
+
13
+ ## Vue 3
14
+
15
+ ```ts
16
+ import { createApp } from 'vue'
17
+ import { initFirefly } from '@fz-firefly/vue'
18
+ import App from './App.vue'
19
+ import router from './router'
20
+
21
+ const app = createApp(App)
22
+
23
+ initFirefly({
24
+ app,
25
+ router,
26
+ dsn: import.meta.env.VITE_FIREFLY_DSN,
27
+ endpoint: import.meta.env.VITE_FIREFLY_ENDPOINT,
28
+ environment: import.meta.env.PROD ? 'production' : 'development',
29
+ release: import.meta.env.VITE_APP_RELEASE,
30
+ })
31
+
32
+ app.use(router)
33
+ app.mount('#app')
34
+ ```
35
+
36
+ ## Vue 2
37
+
38
+ ```js
39
+ import Vue from 'vue'
40
+ import { initFirefly } from '@fz-firefly/vue'
41
+ import App from './App.vue'
42
+ import router from './router'
43
+
44
+ initFirefly({
45
+ Vue,
46
+ router,
47
+ dsn: process.env.VUE_APP_FIREFLY_DSN,
48
+ endpoint: process.env.VUE_APP_FIREFLY_ENDPOINT,
49
+ environment:
50
+ process.env.NODE_ENV === 'production' ? 'production' : 'development',
51
+ release: process.env.VUE_APP_RELEASE,
52
+ })
53
+
54
+ new Vue({
55
+ router,
56
+ render: (h) => h(App),
57
+ }).$mount('#app')
58
+ ```
59
+
60
+ ## 手动上报
61
+
62
+ 初始化后,组件里可以直接使用:
63
+
64
+ ```js
65
+ this.$firefly.captureException(new Error('something went wrong'))
66
+ this.$firefly.captureMessage('checkout failed', 'warning')
67
+ ```
68
+
69
+ `initFirefly` 的返回值也可以拿到 client:
70
+
71
+ ```ts
72
+ const firefly = initFirefly({ app, ... })
73
+ firefly.client.captureException(error)
74
+ ```
75
+
76
+ ## 行为
77
+
78
+ - 捕获 Vue 2 / Vue 3 组件错误,并保留业务原有的 `errorHandler`。
79
+ - 把客户端挂到 `Vue.prototype.$firefly` / `app.config.globalProperties.$firefly`。
80
+ - 传入 `router` 时:
81
+ - `onError` 上报路由错误;
82
+ - `afterEach` 记录导航面包屑,并补报导航失败。
83
+ - 不传 `dist` 时默认使用 `h5`。
84
+ - 默认安装 web 全局错误钩子、资源错误钩子和 `pagehide` 冲刷。
package/dist/index.cjs ADDED
@@ -0,0 +1,128 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ let _fz_firefly_vue_plugin = require("@fz-firefly/vue-plugin");
3
+ let _fz_firefly_web = require("@fz-firefly/web");
4
+ // \0@oxc-project+runtime@0.155.0/helpers/esm/objectWithoutPropertiesLoose.js
5
+ function _objectWithoutPropertiesLoose(r, e) {
6
+ if (null == r) return {};
7
+ var t = {};
8
+ for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
9
+ if (e.includes(n)) continue;
10
+ t[n] = r[n];
11
+ }
12
+ return t;
13
+ }
14
+ // \0@oxc-project+runtime@0.155.0/helpers/esm/objectWithoutProperties.js
15
+ function _objectWithoutProperties(e, t) {
16
+ if (null == e) return {};
17
+ var o, r, i = _objectWithoutPropertiesLoose(e, t);
18
+ if (Object.getOwnPropertySymbols) {
19
+ var s = Object.getOwnPropertySymbols(e);
20
+ for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
21
+ }
22
+ return i;
23
+ }
24
+ // \0@oxc-project+runtime@0.155.0/helpers/esm/typeof.js
25
+ function _typeof(o) {
26
+ "@babel/helpers - typeof";
27
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
28
+ return typeof o;
29
+ } : function(o) {
30
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
31
+ }, _typeof(o);
32
+ }
33
+ // \0@oxc-project+runtime@0.155.0/helpers/esm/toPrimitive.js
34
+ function toPrimitive(t, r) {
35
+ if ("object" != _typeof(t) || !t) return t;
36
+ var e = t[Symbol.toPrimitive];
37
+ if (void 0 !== e) {
38
+ var i = e.call(t, r || "default");
39
+ if ("object" != _typeof(i)) return i;
40
+ throw new TypeError("@@toPrimitive must return a primitive value.");
41
+ }
42
+ return ("string" === r ? String : Number)(t);
43
+ }
44
+ // \0@oxc-project+runtime@0.155.0/helpers/esm/toPropertyKey.js
45
+ function toPropertyKey(t) {
46
+ var i = toPrimitive(t, "string");
47
+ return "symbol" == _typeof(i) ? i : i + "";
48
+ }
49
+ // \0@oxc-project+runtime@0.155.0/helpers/esm/defineProperty.js
50
+ function _defineProperty(e, r, t) {
51
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
52
+ value: t,
53
+ enumerable: !0,
54
+ configurable: !0,
55
+ writable: !0
56
+ }) : e[r] = t, e;
57
+ }
58
+ // \0@oxc-project+runtime@0.155.0/helpers/esm/objectSpread2.js
59
+ function ownKeys(e, r) {
60
+ var t = Object.keys(e);
61
+ if (Object.getOwnPropertySymbols) {
62
+ var o = Object.getOwnPropertySymbols(e);
63
+ r && (o = o.filter(function(r) {
64
+ return Object.getOwnPropertyDescriptor(e, r).enumerable;
65
+ })), t.push.apply(t, o);
66
+ }
67
+ return t;
68
+ }
69
+ function _objectSpread2(e) {
70
+ for (var r = 1; r < arguments.length; r++) {
71
+ var t = null != arguments[r] ? arguments[r] : {};
72
+ r % 2 ? ownKeys(Object(t), !0).forEach(function(r) {
73
+ _defineProperty(e, r, t[r]);
74
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r) {
75
+ Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
76
+ });
77
+ }
78
+ return e;
79
+ }
80
+ // src/index.ts
81
+ const _excluded = [
82
+ "app",
83
+ "Vue",
84
+ "router"
85
+ ];
86
+ /**
87
+ * 一次性完成 Firefly 初始化和 Vue 接入。
88
+ *
89
+ * - 创建客户端、安装 web 全局错误钩子;
90
+ * - 安装 Vue 2 / Vue 3 组件错误处理;
91
+ * - 把客户端挂到 `this.$firefly` / `app.config.globalProperties.$firefly`;
92
+ * - 传入 router 时记录路由错误和导航面包屑。
93
+ */
94
+ function initFirefly(options) {
95
+ var _options$dist;
96
+ if (options.app && options.Vue) throw new Error("Firefly: app 和 Vue 只能传一个");
97
+ if (!options.app && !options.Vue) throw new Error("Firefly: @fz-firefly/vue 需要传入 app(Vue 3)或 Vue(Vue 2)");
98
+ const { app, Vue, router } = options, webOptions = _objectWithoutProperties(options, _excluded);
99
+ const handle = (0, _fz_firefly_web.initFirefly)(_objectSpread2(_objectSpread2({}, webOptions), {}, { dist: (_options$dist = options.dist) !== null && _options$dist !== void 0 ? _options$dist : "h5" }));
100
+ (0, _fz_firefly_vue_plugin.installVue)({
101
+ client: handle.client,
102
+ app,
103
+ Vue,
104
+ router
105
+ });
106
+ return handle;
107
+ }
108
+ Object.defineProperty(exports, "fireflyVue", {
109
+ enumerable: true,
110
+ get: function() {
111
+ return _fz_firefly_vue_plugin.fireflyVue;
112
+ }
113
+ });
114
+ Object.defineProperty(exports, "fireflyVue2", {
115
+ enumerable: true,
116
+ get: function() {
117
+ return _fz_firefly_vue_plugin.fireflyVue2;
118
+ }
119
+ });
120
+ exports.initFirefly = initFirefly;
121
+ Object.defineProperty(exports, "installVue", {
122
+ enumerable: true,
123
+ get: function() {
124
+ return _fz_firefly_vue_plugin.installVue;
125
+ }
126
+ });
127
+
128
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1,29 @@
1
+ import { FireflyVueOptions, RouteLike, RouterLike, RouterLike as RouterLike$1, Vue2ConstructorLike, Vue2ConstructorLike as Vue2ConstructorLike$1, Vue3AppLike, Vue3AppLike as Vue3AppLike$1, fireflyVue, fireflyVue2, installVue } from "@fz-firefly/vue-plugin";
2
+ import { FireflyHandle as FireflyHandle$1, InitOptions as InitOptions$1 } from "@fz-firefly/web";
3
+ import { FireflyClient } from "@fz-firefly/core";
4
+ /**
5
+ * Vue Web 一键初始化参数。
6
+ *
7
+ * 在 web 适配层参数的基础上,额外接收 Vue 3 app 或 Vue 2 构造函数。
8
+ */
9
+ export interface InitOptions extends InitOptions$1 {
10
+ /** Vue 3 app;与 Vue 二选一。 */
11
+ app?: Vue3AppLike$1;
12
+ /** Vue 2 构造函数;与 app 二选一。 */
13
+ Vue?: Vue2ConstructorLike$1;
14
+ /** 可选:vue-router 实例,用于捕获路由错误和记录导航面包屑。 */
15
+ router?: RouterLike$1;
16
+ }
17
+ /** initFirefly 的返回值。 */
18
+ export type FireflyHandle = FireflyHandle$1;
19
+ /**
20
+ * 一次性完成 Firefly 初始化和 Vue 接入。
21
+ *
22
+ * - 创建客户端、安装 web 全局错误钩子;
23
+ * - 安装 Vue 2 / Vue 3 组件错误处理;
24
+ * - 把客户端挂到 `this.$firefly` / `app.config.globalProperties.$firefly`;
25
+ * - 传入 router 时记录路由错误和导航面包屑。
26
+ */
27
+ export declare function initFirefly(options: InitOptions): FireflyHandle;
28
+ export { type FireflyClient, type FireflyVueOptions, type RouteLike, type RouterLike, type Vue2ConstructorLike, type Vue3AppLike, fireflyVue, fireflyVue2, installVue };
29
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1,29 @@
1
+ import { FireflyVueOptions, RouteLike, RouterLike, RouterLike as RouterLike$1, Vue2ConstructorLike, Vue2ConstructorLike as Vue2ConstructorLike$1, Vue3AppLike, Vue3AppLike as Vue3AppLike$1, fireflyVue, fireflyVue2, installVue } from "@fz-firefly/vue-plugin";
2
+ import { FireflyHandle as FireflyHandle$1, InitOptions as InitOptions$1 } from "@fz-firefly/web";
3
+ import { FireflyClient } from "@fz-firefly/core";
4
+ /**
5
+ * Vue Web 一键初始化参数。
6
+ *
7
+ * 在 web 适配层参数的基础上,额外接收 Vue 3 app 或 Vue 2 构造函数。
8
+ */
9
+ export interface InitOptions extends InitOptions$1 {
10
+ /** Vue 3 app;与 Vue 二选一。 */
11
+ app?: Vue3AppLike$1;
12
+ /** Vue 2 构造函数;与 app 二选一。 */
13
+ Vue?: Vue2ConstructorLike$1;
14
+ /** 可选:vue-router 实例,用于捕获路由错误和记录导航面包屑。 */
15
+ router?: RouterLike$1;
16
+ }
17
+ /** initFirefly 的返回值。 */
18
+ export type FireflyHandle = FireflyHandle$1;
19
+ /**
20
+ * 一次性完成 Firefly 初始化和 Vue 接入。
21
+ *
22
+ * - 创建客户端、安装 web 全局错误钩子;
23
+ * - 安装 Vue 2 / Vue 3 组件错误处理;
24
+ * - 把客户端挂到 `this.$firefly` / `app.config.globalProperties.$firefly`;
25
+ * - 传入 router 时记录路由错误和导航面包屑。
26
+ */
27
+ export declare function initFirefly(options: InitOptions): FireflyHandle;
28
+ export { type FireflyClient, type FireflyVueOptions, type RouteLike, type RouterLike, type Vue2ConstructorLike, type Vue3AppLike, fireflyVue, fireflyVue2, installVue };
29
+ //# sourceMappingURL=index.d.ts.map
package/dist/index.js ADDED
@@ -0,0 +1,109 @@
1
+ import { fireflyVue, fireflyVue2, installVue, installVue as installVue$1 } from "@fz-firefly/vue-plugin";
2
+ import { initFirefly as initFirefly$1 } from "@fz-firefly/web";
3
+ // \0@oxc-project+runtime@0.155.0/helpers/esm/objectWithoutPropertiesLoose.js
4
+ function _objectWithoutPropertiesLoose(r, e) {
5
+ if (null == r) return {};
6
+ var t = {};
7
+ for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
8
+ if (e.includes(n)) continue;
9
+ t[n] = r[n];
10
+ }
11
+ return t;
12
+ }
13
+ // \0@oxc-project+runtime@0.155.0/helpers/esm/objectWithoutProperties.js
14
+ function _objectWithoutProperties(e, t) {
15
+ if (null == e) return {};
16
+ var o, r, i = _objectWithoutPropertiesLoose(e, t);
17
+ if (Object.getOwnPropertySymbols) {
18
+ var s = Object.getOwnPropertySymbols(e);
19
+ for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
20
+ }
21
+ return i;
22
+ }
23
+ // \0@oxc-project+runtime@0.155.0/helpers/esm/typeof.js
24
+ function _typeof(o) {
25
+ "@babel/helpers - typeof";
26
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
27
+ return typeof o;
28
+ } : function(o) {
29
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
30
+ }, _typeof(o);
31
+ }
32
+ // \0@oxc-project+runtime@0.155.0/helpers/esm/toPrimitive.js
33
+ function toPrimitive(t, r) {
34
+ if ("object" != _typeof(t) || !t) return t;
35
+ var e = t[Symbol.toPrimitive];
36
+ if (void 0 !== e) {
37
+ var i = e.call(t, r || "default");
38
+ if ("object" != _typeof(i)) return i;
39
+ throw new TypeError("@@toPrimitive must return a primitive value.");
40
+ }
41
+ return ("string" === r ? String : Number)(t);
42
+ }
43
+ // \0@oxc-project+runtime@0.155.0/helpers/esm/toPropertyKey.js
44
+ function toPropertyKey(t) {
45
+ var i = toPrimitive(t, "string");
46
+ return "symbol" == _typeof(i) ? i : i + "";
47
+ }
48
+ // \0@oxc-project+runtime@0.155.0/helpers/esm/defineProperty.js
49
+ function _defineProperty(e, r, t) {
50
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
51
+ value: t,
52
+ enumerable: !0,
53
+ configurable: !0,
54
+ writable: !0
55
+ }) : e[r] = t, e;
56
+ }
57
+ // \0@oxc-project+runtime@0.155.0/helpers/esm/objectSpread2.js
58
+ function ownKeys(e, r) {
59
+ var t = Object.keys(e);
60
+ if (Object.getOwnPropertySymbols) {
61
+ var o = Object.getOwnPropertySymbols(e);
62
+ r && (o = o.filter(function(r) {
63
+ return Object.getOwnPropertyDescriptor(e, r).enumerable;
64
+ })), t.push.apply(t, o);
65
+ }
66
+ return t;
67
+ }
68
+ function _objectSpread2(e) {
69
+ for (var r = 1; r < arguments.length; r++) {
70
+ var t = null != arguments[r] ? arguments[r] : {};
71
+ r % 2 ? ownKeys(Object(t), !0).forEach(function(r) {
72
+ _defineProperty(e, r, t[r]);
73
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r) {
74
+ Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
75
+ });
76
+ }
77
+ return e;
78
+ }
79
+ // src/index.ts
80
+ const _excluded = [
81
+ "app",
82
+ "Vue",
83
+ "router"
84
+ ];
85
+ /**
86
+ * 一次性完成 Firefly 初始化和 Vue 接入。
87
+ *
88
+ * - 创建客户端、安装 web 全局错误钩子;
89
+ * - 安装 Vue 2 / Vue 3 组件错误处理;
90
+ * - 把客户端挂到 `this.$firefly` / `app.config.globalProperties.$firefly`;
91
+ * - 传入 router 时记录路由错误和导航面包屑。
92
+ */
93
+ function initFirefly(options) {
94
+ var _options$dist;
95
+ if (options.app && options.Vue) throw new Error("Firefly: app 和 Vue 只能传一个");
96
+ if (!options.app && !options.Vue) throw new Error("Firefly: @fz-firefly/vue 需要传入 app(Vue 3)或 Vue(Vue 2)");
97
+ const { app, Vue, router } = options, webOptions = _objectWithoutProperties(options, _excluded);
98
+ const handle = initFirefly$1(_objectSpread2(_objectSpread2({}, webOptions), {}, { dist: (_options$dist = options.dist) !== null && _options$dist !== void 0 ? _options$dist : "h5" }));
99
+ installVue$1({
100
+ client: handle.client,
101
+ app,
102
+ Vue,
103
+ router
104
+ });
105
+ return handle;
106
+ }
107
+ export { fireflyVue, fireflyVue2, initFirefly, installVue };
108
+
109
+ //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,48 @@
1
1
  {
2
2
  "name": "@fz-firefly/vue",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.2.0",
4
+ "description": "萤火虫 SDK 的 Vue 2 / Vue 3 一键接入包:初始化、组件错误捕获和路由面包屑。",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js",
13
+ "require": "./dist/index.cjs"
14
+ },
15
+ "./package.json": "./package.json"
16
+ },
17
+ "files": [
18
+ "dist",
19
+ "!dist/**/*.map"
20
+ ],
21
+ "publishConfig": {
22
+ "access": "public"
23
+ },
24
+ "dependencies": {
25
+ "@fz-firefly/core": "0.2.0",
26
+ "@fz-firefly/vue-plugin": "0.2.0",
27
+ "@fz-firefly/web": "0.2.0"
28
+ },
29
+ "devDependencies": {
30
+ "tsdown": "0.23.2",
31
+ "typescript": "^5.6.0",
32
+ "vitest": "^5.0.5",
33
+ "vue": "^3.5.0"
34
+ },
35
+ "peerDependencies": {
36
+ "vue": "^2.0.0 || ^3.0.0"
37
+ },
38
+ "peerDependenciesMeta": {
39
+ "vue": {
40
+ "optional": true
41
+ }
42
+ },
43
+ "scripts": {
44
+ "build": "tsdown",
45
+ "test": "vitest run",
46
+ "typecheck": "tsc --noEmit"
47
+ }
6
48
  }