@tourmind-frontend/monitor-plugin-webpack 1.0.5 → 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 +10 -12
- package/dist/index.d.ts +4 -7
- package/dist/index.js +10 -12
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -81,9 +81,9 @@ async function uploadFiles({ url, query, files }) {
|
|
|
81
81
|
}
|
|
82
82
|
var UploadSourceMapPlugin = class {
|
|
83
83
|
constructor(options) {
|
|
84
|
-
if (!
|
|
85
|
-
if (!options.
|
|
86
|
-
if (!options.
|
|
84
|
+
if (!options.url) throw new Error(`${LOG_PREFIX} "url" is required`);
|
|
85
|
+
if (!options.token) throw new Error(`${LOG_PREFIX} "token" is required`);
|
|
86
|
+
if (!options.commit) throw new Error(`${LOG_PREFIX} "commit" is required`);
|
|
87
87
|
this.options = options;
|
|
88
88
|
}
|
|
89
89
|
apply(compiler) {
|
|
@@ -91,26 +91,24 @@ var UploadSourceMapPlugin = class {
|
|
|
91
91
|
const options = this.options;
|
|
92
92
|
const log = (_a = options.logger) != null ? _a : defaultLogger;
|
|
93
93
|
if (compiler.options.mode !== "production") return;
|
|
94
|
+
const uploadUrl = `${options.url.replace(/\/+$/, "")}/api/upload`;
|
|
94
95
|
compiler.options.devtool = "hidden-source-map";
|
|
95
96
|
let uploadPromise = null;
|
|
96
97
|
compiler.hooks.emit.tap("UploadSourceMapPlugin", (compilation) => {
|
|
97
|
-
var _a2
|
|
98
|
+
var _a2;
|
|
98
99
|
const files = extractSourceMaps(compilation);
|
|
99
100
|
if (files.length === 0) {
|
|
100
101
|
log("warn", "no .map files found in the bundle, skipping upload");
|
|
101
102
|
return;
|
|
102
103
|
}
|
|
103
|
-
const commit
|
|
104
|
-
const timestamp = (
|
|
104
|
+
const { commit } = options;
|
|
105
|
+
const timestamp = (_a2 = options.timestamp) != null ? _a2 : Date.now();
|
|
105
106
|
const query = {
|
|
106
|
-
|
|
107
|
-
branch: options.branch,
|
|
107
|
+
token: options.token,
|
|
108
108
|
timestamp: String(timestamp)
|
|
109
109
|
};
|
|
110
|
-
|
|
111
|
-
uploadPromise = uploadFiles({ url:
|
|
112
|
-
() => log("info", `uploaded ${files.length} sourcemap file(s) (branch=${options.branch}, commit=${commit || "-"})`)
|
|
113
|
-
).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));
|
|
114
112
|
});
|
|
115
113
|
compiler.hooks.done.tapPromise("UploadSourceMapPlugin", async () => {
|
|
116
114
|
if (uploadPromise) await uploadPromise;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
import { Compiler } from "webpack";
|
|
2
2
|
export interface UploadSourceMapOptions {
|
|
3
|
-
/**
|
|
3
|
+
/** monitor 服务的 base URL,例如 `https://monitor.example.com`。内部拼接 `/api/upload`。 */
|
|
4
4
|
url: string;
|
|
5
|
-
/**
|
|
6
|
-
|
|
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
|
-
commit
|
|
8
|
+
commit: string;
|
|
12
9
|
/** 构建时间戳(毫秒),未设置时取上传时刻的 `Date.now()`。 */
|
|
13
10
|
timestamp?: number;
|
|
14
11
|
/** 自定义 logger,默认走 `console.log` / `console.warn` / `console.error`。 */
|
package/dist/index.js
CHANGED
|
@@ -47,9 +47,9 @@ async function uploadFiles({ url, query, files }) {
|
|
|
47
47
|
}
|
|
48
48
|
var UploadSourceMapPlugin = class {
|
|
49
49
|
constructor(options) {
|
|
50
|
-
if (!
|
|
51
|
-
if (!options.
|
|
52
|
-
if (!options.
|
|
50
|
+
if (!options.url) throw new Error(`${LOG_PREFIX} "url" is required`);
|
|
51
|
+
if (!options.token) throw new Error(`${LOG_PREFIX} "token" is required`);
|
|
52
|
+
if (!options.commit) throw new Error(`${LOG_PREFIX} "commit" is required`);
|
|
53
53
|
this.options = options;
|
|
54
54
|
}
|
|
55
55
|
apply(compiler) {
|
|
@@ -57,26 +57,24 @@ var UploadSourceMapPlugin = class {
|
|
|
57
57
|
const options = this.options;
|
|
58
58
|
const log = (_a = options.logger) != null ? _a : defaultLogger;
|
|
59
59
|
if (compiler.options.mode !== "production") return;
|
|
60
|
+
const uploadUrl = `${options.url.replace(/\/+$/, "")}/api/upload`;
|
|
60
61
|
compiler.options.devtool = "hidden-source-map";
|
|
61
62
|
let uploadPromise = null;
|
|
62
63
|
compiler.hooks.emit.tap("UploadSourceMapPlugin", (compilation) => {
|
|
63
|
-
var _a2
|
|
64
|
+
var _a2;
|
|
64
65
|
const files = extractSourceMaps(compilation);
|
|
65
66
|
if (files.length === 0) {
|
|
66
67
|
log("warn", "no .map files found in the bundle, skipping upload");
|
|
67
68
|
return;
|
|
68
69
|
}
|
|
69
|
-
const commit
|
|
70
|
-
const timestamp = (
|
|
70
|
+
const { commit } = options;
|
|
71
|
+
const timestamp = (_a2 = options.timestamp) != null ? _a2 : Date.now();
|
|
71
72
|
const query = {
|
|
72
|
-
|
|
73
|
-
branch: options.branch,
|
|
73
|
+
token: options.token,
|
|
74
74
|
timestamp: String(timestamp)
|
|
75
75
|
};
|
|
76
|
-
|
|
77
|
-
uploadPromise = uploadFiles({ url:
|
|
78
|
-
() => log("info", `uploaded ${files.length} sourcemap file(s) (branch=${options.branch}, commit=${commit || "-"})`)
|
|
79
|
-
).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));
|
|
80
78
|
});
|
|
81
79
|
compiler.hooks.done.tapPromise("UploadSourceMapPlugin", async () => {
|
|
82
80
|
if (uploadPromise) await uploadPromise;
|
package/package.json
CHANGED