@tourmind-frontend/monitor-plugin-webpack 1.1.0 → 1.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/dist/index.cjs CHANGED
@@ -81,8 +81,9 @@ async function uploadFiles({ url, query, files }) {
81
81
  }
82
82
  var UploadSourceMapPlugin = class {
83
83
  constructor(options) {
84
- if (!(options == null ? void 0 : options.url)) throw new Error(`${LOG_PREFIX} "url" is required`);
84
+ if (!options.url) throw new Error(`${LOG_PREFIX} "url" is required`);
85
85
  if (!options.token) throw new Error(`${LOG_PREFIX} "token" is required`);
86
+ if (!options.commit) throw new Error(`${LOG_PREFIX} "commit" is required`);
86
87
  this.options = options;
87
88
  }
88
89
  apply(compiler) {
@@ -90,23 +91,24 @@ var UploadSourceMapPlugin = class {
90
91
  const options = this.options;
91
92
  const log = (_a = options.logger) != null ? _a : defaultLogger;
92
93
  if (compiler.options.mode !== "production") return;
94
+ const uploadUrl = `${options.url.replace(/\/+$/, "")}/api/upload`;
93
95
  compiler.options.devtool = "hidden-source-map";
94
96
  let uploadPromise = null;
95
97
  compiler.hooks.emit.tap("UploadSourceMapPlugin", (compilation) => {
96
- var _a2, _b;
98
+ var _a2;
97
99
  const files = extractSourceMaps(compilation);
98
100
  if (files.length === 0) {
99
101
  log("warn", "no .map files found in the bundle, skipping upload");
100
102
  return;
101
103
  }
102
- const commit = (_a2 = options.commit) != null ? _a2 : "";
103
- const timestamp = (_b = options.timestamp) != null ? _b : Date.now();
104
+ const { commit } = options;
105
+ const timestamp = (_a2 = options.timestamp) != null ? _a2 : Date.now();
104
106
  const query = {
105
107
  token: options.token,
106
108
  timestamp: String(timestamp)
107
109
  };
108
- if (commit) query.commit = commit;
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
+ query.commit = commit;
111
+ uploadPromise = uploadFiles({ url: uploadUrl, 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
112
  });
111
113
  compiler.hooks.done.tapPromise("UploadSourceMapPlugin", async () => {
112
114
  if (uploadPromise) await uploadPromise;
package/dist/index.d.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  import { Compiler } from "webpack";
2
2
  export interface UploadSourceMapOptions {
3
- /** 上传接口地址,例如 `https://monitor.example.com/api/upload`。 */
3
+ /** monitor 服务的 base URL,例如 `https://monitor.example.com`。内部拼接 `/api/upload`。 */
4
4
  url: string;
5
5
  /** monitor 项目 token,从 web 控制台创建项目后获取,内部已绑定仓库 + 分支。 */
6
6
  token: string;
7
7
  /** Commit hash,由调用方自行解析(如 `git rev-parse HEAD`)。 */
8
- commit?: string;
8
+ commit: string;
9
9
  /** 构建时间戳(毫秒),未设置时取上传时刻的 `Date.now()`。 */
10
10
  timestamp?: number;
11
11
  /** 自定义 logger,默认走 `console.log` / `console.warn` / `console.error`。 */
package/dist/index.js CHANGED
@@ -47,8 +47,9 @@ async function uploadFiles({ url, query, files }) {
47
47
  }
48
48
  var UploadSourceMapPlugin = class {
49
49
  constructor(options) {
50
- if (!(options == null ? void 0 : options.url)) throw new Error(`${LOG_PREFIX} "url" is required`);
50
+ if (!options.url) throw new Error(`${LOG_PREFIX} "url" is required`);
51
51
  if (!options.token) throw new Error(`${LOG_PREFIX} "token" is required`);
52
+ if (!options.commit) throw new Error(`${LOG_PREFIX} "commit" is required`);
52
53
  this.options = options;
53
54
  }
54
55
  apply(compiler) {
@@ -56,23 +57,24 @@ var UploadSourceMapPlugin = class {
56
57
  const options = this.options;
57
58
  const log = (_a = options.logger) != null ? _a : defaultLogger;
58
59
  if (compiler.options.mode !== "production") return;
60
+ const uploadUrl = `${options.url.replace(/\/+$/, "")}/api/upload`;
59
61
  compiler.options.devtool = "hidden-source-map";
60
62
  let uploadPromise = null;
61
63
  compiler.hooks.emit.tap("UploadSourceMapPlugin", (compilation) => {
62
- var _a2, _b;
64
+ var _a2;
63
65
  const files = extractSourceMaps(compilation);
64
66
  if (files.length === 0) {
65
67
  log("warn", "no .map files found in the bundle, skipping upload");
66
68
  return;
67
69
  }
68
- const commit = (_a2 = options.commit) != null ? _a2 : "";
69
- const timestamp = (_b = options.timestamp) != null ? _b : Date.now();
70
+ const { commit } = options;
71
+ const timestamp = (_a2 = options.timestamp) != null ? _a2 : Date.now();
70
72
  const query = {
71
73
  token: options.token,
72
74
  timestamp: String(timestamp)
73
75
  };
74
- if (commit) query.commit = commit;
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
+ query.commit = commit;
77
+ uploadPromise = uploadFiles({ url: uploadUrl, 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
78
  });
77
79
  compiler.hooks.done.tapPromise("UploadSourceMapPlugin", async () => {
78
80
  if (uploadPromise) await uploadPromise;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tourmind-frontend/monitor-plugin-webpack",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "Webpack plugin that uploads sourcemaps to a frontend-monitor server.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",