@tourmind-frontend/monitor-plugin-webpack 1.1.0 → 1.4.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 +13 -8
- package/dist/index.d.ts +4 -4
- package/dist/index.js +13 -8
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -81,8 +81,12 @@ async function uploadFiles({ url, query, files }) {
|
|
|
81
81
|
}
|
|
82
82
|
var UploadSourceMapPlugin = class {
|
|
83
83
|
constructor(options) {
|
|
84
|
-
if (!
|
|
85
|
-
if (!options.
|
|
84
|
+
if (!options.url) throw new Error(`${LOG_PREFIX} "url" is required`);
|
|
85
|
+
if (!options.authToken) throw new Error(`${LOG_PREFIX} "authToken" is required`);
|
|
86
|
+
if (!options.authToken.startsWith("fm_at_")) {
|
|
87
|
+
throw new Error(`${LOG_PREFIX} "authToken" must start with "fm_at_"; do not use the client key here`);
|
|
88
|
+
}
|
|
89
|
+
if (!options.commit) throw new Error(`${LOG_PREFIX} "commit" is required`);
|
|
86
90
|
this.options = options;
|
|
87
91
|
}
|
|
88
92
|
apply(compiler) {
|
|
@@ -90,23 +94,24 @@ var UploadSourceMapPlugin = class {
|
|
|
90
94
|
const options = this.options;
|
|
91
95
|
const log = (_a = options.logger) != null ? _a : defaultLogger;
|
|
92
96
|
if (compiler.options.mode !== "production") return;
|
|
97
|
+
const uploadUrl = `${options.url.replace(/\/+$/, "")}/api/upload`;
|
|
93
98
|
compiler.options.devtool = "hidden-source-map";
|
|
94
99
|
let uploadPromise = null;
|
|
95
100
|
compiler.hooks.emit.tap("UploadSourceMapPlugin", (compilation) => {
|
|
96
|
-
var _a2
|
|
101
|
+
var _a2;
|
|
97
102
|
const files = extractSourceMaps(compilation);
|
|
98
103
|
if (files.length === 0) {
|
|
99
104
|
log("warn", "no .map files found in the bundle, skipping upload");
|
|
100
105
|
return;
|
|
101
106
|
}
|
|
102
|
-
const commit
|
|
103
|
-
const timestamp = (
|
|
107
|
+
const { commit } = options;
|
|
108
|
+
const timestamp = (_a2 = options.timestamp) != null ? _a2 : Date.now();
|
|
104
109
|
const query = {
|
|
105
|
-
token: options.
|
|
110
|
+
token: options.authToken,
|
|
106
111
|
timestamp: String(timestamp)
|
|
107
112
|
};
|
|
108
|
-
|
|
109
|
-
uploadPromise = uploadFiles({ url:
|
|
113
|
+
query.commit = commit;
|
|
114
|
+
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
115
|
});
|
|
111
116
|
compiler.hooks.done.tapPromise("UploadSourceMapPlugin", async () => {
|
|
112
117
|
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
|
-
/**
|
|
3
|
+
/** monitor 服务的 base URL,例如 `https://monitor.example.com`。内部拼接 `/api/upload`。 */
|
|
4
4
|
url: string;
|
|
5
|
-
/** monitor 项目 token
|
|
6
|
-
|
|
5
|
+
/** monitor 项目 auth token(前缀 `fm_at_`),仅供 CI / 构建机使用,从 web 控制台「项目」页获取。 */
|
|
6
|
+
authToken: string;
|
|
7
7
|
/** Commit hash,由调用方自行解析(如 `git rev-parse HEAD`)。 */
|
|
8
|
-
commit
|
|
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,12 @@ async function uploadFiles({ url, query, files }) {
|
|
|
47
47
|
}
|
|
48
48
|
var UploadSourceMapPlugin = class {
|
|
49
49
|
constructor(options) {
|
|
50
|
-
if (!
|
|
51
|
-
if (!options.
|
|
50
|
+
if (!options.url) throw new Error(`${LOG_PREFIX} "url" is required`);
|
|
51
|
+
if (!options.authToken) throw new Error(`${LOG_PREFIX} "authToken" is required`);
|
|
52
|
+
if (!options.authToken.startsWith("fm_at_")) {
|
|
53
|
+
throw new Error(`${LOG_PREFIX} "authToken" must start with "fm_at_"; do not use the client key here`);
|
|
54
|
+
}
|
|
55
|
+
if (!options.commit) throw new Error(`${LOG_PREFIX} "commit" is required`);
|
|
52
56
|
this.options = options;
|
|
53
57
|
}
|
|
54
58
|
apply(compiler) {
|
|
@@ -56,23 +60,24 @@ var UploadSourceMapPlugin = class {
|
|
|
56
60
|
const options = this.options;
|
|
57
61
|
const log = (_a = options.logger) != null ? _a : defaultLogger;
|
|
58
62
|
if (compiler.options.mode !== "production") return;
|
|
63
|
+
const uploadUrl = `${options.url.replace(/\/+$/, "")}/api/upload`;
|
|
59
64
|
compiler.options.devtool = "hidden-source-map";
|
|
60
65
|
let uploadPromise = null;
|
|
61
66
|
compiler.hooks.emit.tap("UploadSourceMapPlugin", (compilation) => {
|
|
62
|
-
var _a2
|
|
67
|
+
var _a2;
|
|
63
68
|
const files = extractSourceMaps(compilation);
|
|
64
69
|
if (files.length === 0) {
|
|
65
70
|
log("warn", "no .map files found in the bundle, skipping upload");
|
|
66
71
|
return;
|
|
67
72
|
}
|
|
68
|
-
const commit
|
|
69
|
-
const timestamp = (
|
|
73
|
+
const { commit } = options;
|
|
74
|
+
const timestamp = (_a2 = options.timestamp) != null ? _a2 : Date.now();
|
|
70
75
|
const query = {
|
|
71
|
-
token: options.
|
|
76
|
+
token: options.authToken,
|
|
72
77
|
timestamp: String(timestamp)
|
|
73
78
|
};
|
|
74
|
-
|
|
75
|
-
uploadPromise = uploadFiles({ url:
|
|
79
|
+
query.commit = commit;
|
|
80
|
+
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
81
|
});
|
|
77
82
|
compiler.hooks.done.tapPromise("UploadSourceMapPlugin", async () => {
|
|
78
83
|
if (uploadPromise) await uploadPromise;
|
package/package.json
CHANGED