@tourmind-frontend/monitor-plugin-vite 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 +9 -4
- package/dist/index.d.ts +5 -5
- package/dist/index.js +9 -4
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -76,9 +76,14 @@ async function uploadFiles({ url, query, files }) {
|
|
|
76
76
|
}
|
|
77
77
|
function uploadSourceMapPlugin(options) {
|
|
78
78
|
var _a;
|
|
79
|
-
if (!
|
|
80
|
-
if (!options.
|
|
79
|
+
if (!options.url) throw new Error(`${LOG_PREFIX} "url" is required`);
|
|
80
|
+
if (!options.authToken) throw new Error(`${LOG_PREFIX} "authToken" is required`);
|
|
81
|
+
if (!options.authToken.startsWith("fm_at_")) {
|
|
82
|
+
throw new Error(`${LOG_PREFIX} "authToken" must start with "fm_at_"; do not use the client key here`);
|
|
83
|
+
}
|
|
84
|
+
if (!options.commit) throw new Error(`${LOG_PREFIX} "commit" is required`);
|
|
81
85
|
const log = (_a = options.logger) != null ? _a : defaultLogger;
|
|
86
|
+
const uploadUrl = `${options.url.replace(/\/+$/, "")}/api/upload`;
|
|
82
87
|
let enabled = false;
|
|
83
88
|
let uploadPromise = null;
|
|
84
89
|
return {
|
|
@@ -100,11 +105,11 @@ function uploadSourceMapPlugin(options) {
|
|
|
100
105
|
const commit = (_a2 = options.commit) != null ? _a2 : "";
|
|
101
106
|
const timestamp = (_b = options.timestamp) != null ? _b : Date.now();
|
|
102
107
|
const query = {
|
|
103
|
-
token: options.
|
|
108
|
+
token: options.authToken,
|
|
104
109
|
timestamp: String(timestamp)
|
|
105
110
|
};
|
|
106
111
|
if (commit) query.commit = commit;
|
|
107
|
-
uploadPromise = uploadFiles({ url:
|
|
112
|
+
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));
|
|
108
113
|
},
|
|
109
114
|
async closeBundle() {
|
|
110
115
|
if (uploadPromise) await uploadPromise;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Plugin } from "vite";
|
|
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`。 */
|
|
@@ -17,7 +17,7 @@ export interface UploadSourceMapOptions {
|
|
|
17
17
|
* 该插件会:
|
|
18
18
|
* - 强制 `build.sourcemap = "hidden"`,让 `.map` 文件生成但不被 bundle 内联引用
|
|
19
19
|
* - 从最终的 bundle 中移除 `.map` chunk,避免泄漏到 public 产物
|
|
20
|
-
* - 将收集到的每个 `.map` 以 `multipart/form-data` 形式 POST 到
|
|
20
|
+
* - 将收集到的每个 `.map` 以 `multipart/form-data` 形式 POST 到 `${options.url}/api/upload`
|
|
21
21
|
* - 在 URL 上追加服务端期望的 `token`、`timestamp`、`commit` 查询参数
|
|
22
22
|
* (`commit` 仅在 options 显式提供时才会发送)
|
|
23
23
|
*/
|
package/dist/index.js
CHANGED
|
@@ -42,9 +42,14 @@ async function uploadFiles({ url, query, files }) {
|
|
|
42
42
|
}
|
|
43
43
|
function uploadSourceMapPlugin(options) {
|
|
44
44
|
var _a;
|
|
45
|
-
if (!
|
|
46
|
-
if (!options.
|
|
45
|
+
if (!options.url) throw new Error(`${LOG_PREFIX} "url" is required`);
|
|
46
|
+
if (!options.authToken) throw new Error(`${LOG_PREFIX} "authToken" is required`);
|
|
47
|
+
if (!options.authToken.startsWith("fm_at_")) {
|
|
48
|
+
throw new Error(`${LOG_PREFIX} "authToken" must start with "fm_at_"; do not use the client key here`);
|
|
49
|
+
}
|
|
50
|
+
if (!options.commit) throw new Error(`${LOG_PREFIX} "commit" is required`);
|
|
47
51
|
const log = (_a = options.logger) != null ? _a : defaultLogger;
|
|
52
|
+
const uploadUrl = `${options.url.replace(/\/+$/, "")}/api/upload`;
|
|
48
53
|
let enabled = false;
|
|
49
54
|
let uploadPromise = null;
|
|
50
55
|
return {
|
|
@@ -66,11 +71,11 @@ function uploadSourceMapPlugin(options) {
|
|
|
66
71
|
const commit = (_a2 = options.commit) != null ? _a2 : "";
|
|
67
72
|
const timestamp = (_b = options.timestamp) != null ? _b : Date.now();
|
|
68
73
|
const query = {
|
|
69
|
-
token: options.
|
|
74
|
+
token: options.authToken,
|
|
70
75
|
timestamp: String(timestamp)
|
|
71
76
|
};
|
|
72
77
|
if (commit) query.commit = commit;
|
|
73
|
-
uploadPromise = uploadFiles({ url:
|
|
78
|
+
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));
|
|
74
79
|
},
|
|
75
80
|
async closeBundle() {
|
|
76
81
|
if (uploadPromise) await uploadPromise;
|