@tourmind-frontend/monitor-plugin-nuxt 1.0.3 → 1.0.5

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.cjs CHANGED
@@ -34,81 +34,19 @@ __export(src_exports, {
34
34
  });
35
35
  module.exports = __toCommonJS(src_exports);
36
36
  var import_node_path = require("path");
37
- var import_axios = __toESM(require("axios"));
38
- var import_form_data = __toESM(require("form-data"));
37
+ var import_monitor_plugin_webpack = __toESM(require("@tourmind-frontend/monitor-plugin-webpack"));
39
38
  var LOG_PREFIX = "[frontend-monitor]";
40
- var UploadSourceMapWebpackPlugin = class {
41
- constructor(options) {
42
- if (!(options == null ? void 0 : options.url)) throw new Error(`${LOG_PREFIX} "uploadUrl" is required`);
43
- if (!options.project) throw new Error(`${LOG_PREFIX} "project" is required`);
44
- if (!options.branch) throw new Error(`${LOG_PREFIX} "branch" is required`);
45
- this.options = options;
46
- }
47
- // 兼容 webpack 4 / 5;类型留作 any 以避免把 webpack 拉入类型声明。
48
- apply(compiler) {
49
- const opts = this.options;
50
- compiler.hooks.emit.tapPromise("MonitorUploadSourceMapPlugin", async (compilation) => {
51
- const files = [];
52
- const assets = compilation.assets || {};
53
- for (const name of Object.keys(assets)) {
54
- if (!name.endsWith(".map")) continue;
55
- const asset = assets[name];
56
- const raw = typeof (asset == null ? void 0 : asset.source) === "function" ? asset.source() : "";
57
- const content = typeof raw === "string" ? raw : raw ? Buffer.from(raw).toString("utf-8") : "";
58
- if (typeof compilation.deleteAsset === "function") compilation.deleteAsset(name);
59
- else delete assets[name];
60
- if (!content) continue;
61
- const base = name.includes("/") ? name.split("/").pop() : name;
62
- if (!base) continue;
63
- files.push([base, content]);
64
- }
65
- if (files.length === 0) {
66
- console.warn(`${LOG_PREFIX} no .map files found in the bundle, skipping upload`);
67
- return;
68
- }
69
- const query = {
70
- project: opts.project,
71
- branch: opts.branch,
72
- timestamp: String(Date.now())
73
- };
74
- if (opts.commit) query.commit = opts.commit;
75
- const qs = new URLSearchParams(query).toString();
76
- const fullUrl = `${opts.url}${opts.url.includes("?") ? "&" : "?"}${qs}`;
77
- const form = new import_form_data.default();
78
- for (const [filename, content] of files) {
79
- form.append("file", Buffer.from(content, "utf-8"), { filename });
80
- }
81
- try {
82
- await (0, import_axios.default)({
83
- method: "POST",
84
- url: fullUrl,
85
- data: form,
86
- headers: form.getHeaders(),
87
- maxBodyLength: Infinity,
88
- maxContentLength: Infinity
89
- });
90
- console.log(
91
- `${LOG_PREFIX} uploaded ${files.length} sourcemap file(s) (branch=${opts.branch}, commit=${opts.commit || "-"})`
92
- );
93
- } catch (err) {
94
- console.error(`${LOG_PREFIX} upload failed`, err instanceof Error ? err.message : err);
95
- }
96
- });
97
- }
98
- };
99
39
  function MonitorModule(options) {
100
40
  if (!(options == null ? void 0 : options.project)) throw new Error(`${LOG_PREFIX} "project" is required`);
101
41
  if (!options.reportUrl) throw new Error(`${LOG_PREFIX} "reportUrl" is required`);
102
42
  if (!options.uploadUrl) throw new Error(`${LOG_PREFIX} "uploadUrl" is required`);
103
43
  if (!options.branch) throw new Error(`${LOG_PREFIX} "branch" is required`);
104
44
  this.extendBuild((config, { isClient, isDev }) => {
105
- var _a;
106
- const enabled = (_a = options.uploadEnabled) != null ? _a : !isDev;
107
- if (!enabled || !isClient) return;
45
+ if (isDev || !isClient) return;
108
46
  config.devtool = "hidden-source-map";
109
47
  config.plugins = config.plugins || [];
110
48
  config.plugins.push(
111
- new UploadSourceMapWebpackPlugin({
49
+ new import_monitor_plugin_webpack.default({
112
50
  url: options.uploadUrl,
113
51
  project: options.project,
114
52
  branch: options.branch,
package/dist/index.d.ts CHANGED
@@ -9,8 +9,6 @@ export interface MonitorModuleOptions {
9
9
  branch: string;
10
10
  /** Commit hash,由调用方自行解析(如 `git rev-parse HEAD`)。 */
11
11
  commit?: string;
12
- /** 强制启用 / 禁用 sourcemap 上传。默认仅在生产构建(`!isDev`)时为 `true`。 */
13
- uploadEnabled?: boolean;
14
12
  }
15
13
  interface NuxtBuildContext {
16
14
  isClient: boolean;
@@ -35,9 +33,10 @@ interface NuxtModuleThis {
35
33
  /**
36
34
  * Nuxt 2 模块入口(兼容 `nuxt@>=2.4.0` + `nuxt-property-decorator@>=2.3.0`)。
37
35
  *
38
- * - 客户端生产构建时注入 webpack 插件,把 sourcemap 上传到 `uploadUrl`
39
- * - 始终注入客户端运行时插件,监听 `window.error` / `unhandledrejection` /
40
- * `Vue.config.errorHandler`,把错误堆栈上报到 `reportUrl`
36
+ * - 客户端生产构建时:通过 `@tourmind-frontend/monitor-plugin-webpack` sourcemap
37
+ * 上传到 `uploadUrl`,避免逻辑重复
38
+ * - 客户端运行时:复用 `@tourmind-frontend/monitor-tracking`,捕获 `window.error` /
39
+ * `unhandledrejection` / `Vue.config.errorHandler` 并上报到 `reportUrl`
41
40
  *
42
41
  * 在 `nuxt.config.js` 中使用:
43
42
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tourmind-frontend/monitor-plugin-nuxt",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "Nuxt 2 module that captures runtime errors and uploads sourcemaps to a frontend-monitor server.",
5
5
  "main": "./dist/index.cjs",
6
6
  "types": "./dist/index.d.ts",
@@ -17,13 +17,12 @@
17
17
  "node": ">=13"
18
18
  },
19
19
  "dependencies": {
20
- "axios": "^0.27.2",
21
- "form-data": "^3.0.0"
20
+ "@tourmind-frontend/monitor-plugin-webpack": "^1.0.5"
22
21
  },
23
22
  "peerDependencies": {
24
- "nuxt": ">=2.4.0",
25
- "vue": ">=2.5.0",
26
- "@tourmind-frontend/monitor-tracking": "^1.0.1"
23
+ "nuxt": "^2.4.0",
24
+ "vue": "^2.5.0",
25
+ "@tourmind-frontend/monitor-tracking": "^1.0.5"
27
26
  },
28
27
  "devDependencies": {
29
28
  "@types/node": "^20.0.0",