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

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,68 +34,8 @@ __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`);
@@ -108,11 +48,13 @@ function MonitorModule(options) {
108
48
  config.devtool = "hidden-source-map";
109
49
  config.plugins = config.plugins || [];
110
50
  config.plugins.push(
111
- new UploadSourceMapWebpackPlugin({
51
+ new import_monitor_plugin_webpack.default({
112
52
  url: options.uploadUrl,
113
53
  project: options.project,
114
54
  branch: options.branch,
115
- commit: options.commit
55
+ commit: options.commit,
56
+ // 已经在 extendBuild 层 gate 过,跳过 plugin 内部的 mode 判断。
57
+ enabled: true
116
58
  })
117
59
  );
118
60
  });
package/dist/index.d.ts CHANGED
@@ -35,9 +35,10 @@ interface NuxtModuleThis {
35
35
  /**
36
36
  * Nuxt 2 模块入口(兼容 `nuxt@>=2.4.0` + `nuxt-property-decorator@>=2.3.0`)。
37
37
  *
38
- * - 客户端生产构建时注入 webpack 插件,把 sourcemap 上传到 `uploadUrl`
39
- * - 始终注入客户端运行时插件,监听 `window.error` / `unhandledrejection` /
40
- * `Vue.config.errorHandler`,把错误堆栈上报到 `reportUrl`
38
+ * - 客户端生产构建时:通过 `@tourmind-frontend/monitor-plugin-webpack` sourcemap
39
+ * 上传到 `uploadUrl`,避免逻辑重复
40
+ * - 客户端运行时:复用 `@tourmind-frontend/monitor-tracking`,捕获 `window.error` /
41
+ * `unhandledrejection` / `Vue.config.errorHandler` 并上报到 `reportUrl`
41
42
  *
42
43
  * 在 `nuxt.config.js` 中使用:
43
44
  *
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.4",
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,8 +17,7 @@
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.1"
22
21
  },
23
22
  "peerDependencies": {
24
23
  "nuxt": ">=2.4.0",