@tourmind-frontend/monitor-plugin-webpack 1.0.1 → 1.1.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/dist/index.cjs CHANGED
@@ -82,38 +82,34 @@ async function uploadFiles({ url, query, files }) {
82
82
  var UploadSourceMapPlugin = class {
83
83
  constructor(options) {
84
84
  if (!(options == null ? void 0 : options.url)) throw new Error(`${LOG_PREFIX} "url" is required`);
85
- if (!options.project) throw new Error(`${LOG_PREFIX} "project" is required`);
86
- if (!options.branch) throw new Error(`${LOG_PREFIX} "branch" is required`);
85
+ if (!options.token) throw new Error(`${LOG_PREFIX} "token" is required`);
87
86
  this.options = options;
88
87
  }
89
88
  apply(compiler) {
90
- var _a, _b;
89
+ var _a;
91
90
  const options = this.options;
92
91
  const log = (_a = options.logger) != null ? _a : defaultLogger;
93
- const enabled = (_b = options.enabled) != null ? _b : compiler.options.mode === "production";
94
- if (!enabled) return;
92
+ if (compiler.options.mode !== "production") return;
95
93
  compiler.options.devtool = "hidden-source-map";
96
- compiler.hooks.emit.tapPromise("UploadSourceMapPlugin", async (compilation) => {
97
- var _a2, _b2;
94
+ let uploadPromise = null;
95
+ compiler.hooks.emit.tap("UploadSourceMapPlugin", (compilation) => {
96
+ var _a2, _b;
98
97
  const files = extractSourceMaps(compilation);
99
98
  if (files.length === 0) {
100
99
  log("warn", "no .map files found in the bundle, skipping upload");
101
100
  return;
102
101
  }
103
102
  const commit = (_a2 = options.commit) != null ? _a2 : "";
104
- const timestamp = (_b2 = options.timestamp) != null ? _b2 : Date.now();
103
+ const timestamp = (_b = options.timestamp) != null ? _b : Date.now();
105
104
  const query = {
106
- project: options.project,
107
- branch: options.branch,
105
+ token: options.token,
108
106
  timestamp: String(timestamp)
109
107
  };
110
108
  if (commit) query.commit = commit;
111
- try {
112
- await uploadFiles({ url: options.url, query, files });
113
- log("info", `uploaded ${files.length} sourcemap file(s) (branch=${options.branch}, commit=${commit || "-"})`);
114
- } catch (err) {
115
- log("error", "upload failed", err instanceof Error ? err.message : err);
116
- }
109
+ uploadPromise = uploadFiles({ url: options.url, query, files }).then(() => log("info", `uploaded ${files.length} sourcemap file(s) (commit=${commit || "-"})`)).catch((err) => log("error", "upload failed", err instanceof Error ? err.message : err));
110
+ });
111
+ compiler.hooks.done.tapPromise("UploadSourceMapPlugin", async () => {
112
+ if (uploadPromise) await uploadPromise;
117
113
  });
118
114
  }
119
115
  };
package/dist/index.d.ts CHANGED
@@ -2,15 +2,10 @@ import { Compiler } from "webpack";
2
2
  export interface UploadSourceMapOptions {
3
3
  /** 上传接口地址,例如 `https://monitor.example.com/api/upload`。 */
4
4
  url: string;
5
- /** 项目名,必须为 `owner/name` 格式以匹配服务端。 */
6
- project: string;
7
- /** 分支名,必填,由调用方自行解析(如 `git rev-parse --abbrev-ref HEAD`)。
8
- * 服务端使用此字段标识来源;主分支(`main` / `master`)等同于"生产环境"。 */
9
- branch: string;
5
+ /** monitor 项目 token,从 web 控制台创建项目后获取,内部已绑定仓库 + 分支。 */
6
+ token: string;
10
7
  /** Commit hash,由调用方自行解析(如 `git rev-parse HEAD`)。 */
11
8
  commit?: string;
12
- /** 强制启用 / 禁用。默认仅在 webpack `mode === "production"` 时为 `true`。 */
13
- enabled?: boolean;
14
9
  /** 构建时间戳(毫秒),未设置时取上传时刻的 `Date.now()`。 */
15
10
  timestamp?: number;
16
11
  /** 自定义 logger,默认走 `console.log` / `console.warn` / `console.error`。 */
package/dist/index.js CHANGED
@@ -48,38 +48,34 @@ async function uploadFiles({ url, query, files }) {
48
48
  var UploadSourceMapPlugin = class {
49
49
  constructor(options) {
50
50
  if (!(options == null ? void 0 : options.url)) throw new Error(`${LOG_PREFIX} "url" is required`);
51
- if (!options.project) throw new Error(`${LOG_PREFIX} "project" is required`);
52
- if (!options.branch) throw new Error(`${LOG_PREFIX} "branch" is required`);
51
+ if (!options.token) throw new Error(`${LOG_PREFIX} "token" is required`);
53
52
  this.options = options;
54
53
  }
55
54
  apply(compiler) {
56
- var _a, _b;
55
+ var _a;
57
56
  const options = this.options;
58
57
  const log = (_a = options.logger) != null ? _a : defaultLogger;
59
- const enabled = (_b = options.enabled) != null ? _b : compiler.options.mode === "production";
60
- if (!enabled) return;
58
+ if (compiler.options.mode !== "production") return;
61
59
  compiler.options.devtool = "hidden-source-map";
62
- compiler.hooks.emit.tapPromise("UploadSourceMapPlugin", async (compilation) => {
63
- var _a2, _b2;
60
+ let uploadPromise = null;
61
+ compiler.hooks.emit.tap("UploadSourceMapPlugin", (compilation) => {
62
+ var _a2, _b;
64
63
  const files = extractSourceMaps(compilation);
65
64
  if (files.length === 0) {
66
65
  log("warn", "no .map files found in the bundle, skipping upload");
67
66
  return;
68
67
  }
69
68
  const commit = (_a2 = options.commit) != null ? _a2 : "";
70
- const timestamp = (_b2 = options.timestamp) != null ? _b2 : Date.now();
69
+ const timestamp = (_b = options.timestamp) != null ? _b : Date.now();
71
70
  const query = {
72
- project: options.project,
73
- branch: options.branch,
71
+ token: options.token,
74
72
  timestamp: String(timestamp)
75
73
  };
76
74
  if (commit) query.commit = commit;
77
- try {
78
- await uploadFiles({ url: options.url, query, files });
79
- log("info", `uploaded ${files.length} sourcemap file(s) (branch=${options.branch}, commit=${commit || "-"})`);
80
- } catch (err) {
81
- log("error", "upload failed", err instanceof Error ? err.message : err);
82
- }
75
+ uploadPromise = uploadFiles({ url: options.url, query, files }).then(() => log("info", `uploaded ${files.length} sourcemap file(s) (commit=${commit || "-"})`)).catch((err) => log("error", "upload failed", err instanceof Error ? err.message : err));
76
+ });
77
+ compiler.hooks.done.tapPromise("UploadSourceMapPlugin", async () => {
78
+ if (uploadPromise) await uploadPromise;
83
79
  });
84
80
  }
85
81
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tourmind-frontend/monitor-plugin-webpack",
3
- "version": "1.0.1",
3
+ "version": "1.1.0",
4
4
  "description": "Webpack plugin that uploads sourcemaps to a frontend-monitor server.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -43,4 +43,4 @@
43
43
  "frontend-monitor",
44
44
  "error-tracking"
45
45
  ]
46
- }
46
+ }