@tourmind-frontend/monitor-plugin-vite 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 +9 -13
- package/dist/index.d.ts +3 -8
- package/dist/index.js +9 -13
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -77,20 +77,19 @@ async function uploadFiles({ url, query, files }) {
|
|
|
77
77
|
function uploadSourceMapPlugin(options) {
|
|
78
78
|
var _a;
|
|
79
79
|
if (!(options == null ? void 0 : options.url)) throw new Error(`${LOG_PREFIX} "url" is required`);
|
|
80
|
-
if (!options.
|
|
81
|
-
if (!options.branch) throw new Error(`${LOG_PREFIX} "branch" is required`);
|
|
80
|
+
if (!options.token) throw new Error(`${LOG_PREFIX} "token" is required`);
|
|
82
81
|
const log = (_a = options.logger) != null ? _a : defaultLogger;
|
|
83
82
|
let enabled = false;
|
|
83
|
+
let uploadPromise = null;
|
|
84
84
|
return {
|
|
85
85
|
name: "frontend-monitor-plugin",
|
|
86
86
|
apply: "build",
|
|
87
87
|
configResolved(config) {
|
|
88
|
-
|
|
89
|
-
enabled = (_a2 = options.enabled) != null ? _a2 : config.mode === "production";
|
|
88
|
+
enabled = config.mode === "production";
|
|
90
89
|
if (!enabled) return;
|
|
91
90
|
config.build.sourcemap = "hidden";
|
|
92
91
|
},
|
|
93
|
-
|
|
92
|
+
generateBundle(_, bundle) {
|
|
94
93
|
var _a2, _b;
|
|
95
94
|
if (!enabled) return;
|
|
96
95
|
const files = extractSourceMaps(bundle);
|
|
@@ -101,17 +100,14 @@ function uploadSourceMapPlugin(options) {
|
|
|
101
100
|
const commit = (_a2 = options.commit) != null ? _a2 : "";
|
|
102
101
|
const timestamp = (_b = options.timestamp) != null ? _b : Date.now();
|
|
103
102
|
const query = {
|
|
104
|
-
|
|
105
|
-
branch: options.branch,
|
|
103
|
+
token: options.token,
|
|
106
104
|
timestamp: String(timestamp)
|
|
107
105
|
};
|
|
108
106
|
if (commit) query.commit = commit;
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
log("error", "upload failed", err instanceof Error ? err.message : err);
|
|
114
|
-
}
|
|
107
|
+
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));
|
|
108
|
+
},
|
|
109
|
+
async closeBundle() {
|
|
110
|
+
if (uploadPromise) await uploadPromise;
|
|
115
111
|
}
|
|
116
112
|
};
|
|
117
113
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,15 +2,10 @@ import { Plugin } from "vite";
|
|
|
2
2
|
export interface UploadSourceMapOptions {
|
|
3
3
|
/** 上传接口地址,例如 `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
8
|
commit?: string;
|
|
12
|
-
/** 强制启用 / 禁用。默认仅在 Vite mode === "production" 时为 `true`。 */
|
|
13
|
-
enabled?: boolean;
|
|
14
9
|
/** 构建时间戳(毫秒),未设置时取上传时刻的 `Date.now()`。 */
|
|
15
10
|
timestamp?: number;
|
|
16
11
|
/** 自定义 logger,默认走 `console.log` / `console.warn` / `console.error`。 */
|
|
@@ -23,7 +18,7 @@ export interface UploadSourceMapOptions {
|
|
|
23
18
|
* - 强制 `build.sourcemap = "hidden"`,让 `.map` 文件生成但不被 bundle 内联引用
|
|
24
19
|
* - 从最终的 bundle 中移除 `.map` chunk,避免泄漏到 public 产物
|
|
25
20
|
* - 将收集到的每个 `.map` 以 `multipart/form-data` 形式 POST 到 `options.url`
|
|
26
|
-
* - 在 URL 上追加服务端期望的 `
|
|
21
|
+
* - 在 URL 上追加服务端期望的 `token`、`timestamp`、`commit` 查询参数
|
|
27
22
|
* (`commit` 仅在 options 显式提供时才会发送)
|
|
28
23
|
*/
|
|
29
24
|
export default function uploadSourceMapPlugin(options: UploadSourceMapOptions): Plugin;
|
package/dist/index.js
CHANGED
|
@@ -43,20 +43,19 @@ async function uploadFiles({ url, query, files }) {
|
|
|
43
43
|
function uploadSourceMapPlugin(options) {
|
|
44
44
|
var _a;
|
|
45
45
|
if (!(options == null ? void 0 : options.url)) throw new Error(`${LOG_PREFIX} "url" is required`);
|
|
46
|
-
if (!options.
|
|
47
|
-
if (!options.branch) throw new Error(`${LOG_PREFIX} "branch" is required`);
|
|
46
|
+
if (!options.token) throw new Error(`${LOG_PREFIX} "token" is required`);
|
|
48
47
|
const log = (_a = options.logger) != null ? _a : defaultLogger;
|
|
49
48
|
let enabled = false;
|
|
49
|
+
let uploadPromise = null;
|
|
50
50
|
return {
|
|
51
51
|
name: "frontend-monitor-plugin",
|
|
52
52
|
apply: "build",
|
|
53
53
|
configResolved(config) {
|
|
54
|
-
|
|
55
|
-
enabled = (_a2 = options.enabled) != null ? _a2 : config.mode === "production";
|
|
54
|
+
enabled = config.mode === "production";
|
|
56
55
|
if (!enabled) return;
|
|
57
56
|
config.build.sourcemap = "hidden";
|
|
58
57
|
},
|
|
59
|
-
|
|
58
|
+
generateBundle(_, bundle) {
|
|
60
59
|
var _a2, _b;
|
|
61
60
|
if (!enabled) return;
|
|
62
61
|
const files = extractSourceMaps(bundle);
|
|
@@ -67,17 +66,14 @@ function uploadSourceMapPlugin(options) {
|
|
|
67
66
|
const commit = (_a2 = options.commit) != null ? _a2 : "";
|
|
68
67
|
const timestamp = (_b = options.timestamp) != null ? _b : Date.now();
|
|
69
68
|
const query = {
|
|
70
|
-
|
|
71
|
-
branch: options.branch,
|
|
69
|
+
token: options.token,
|
|
72
70
|
timestamp: String(timestamp)
|
|
73
71
|
};
|
|
74
72
|
if (commit) query.commit = commit;
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
log("error", "upload failed", err instanceof Error ? err.message : err);
|
|
80
|
-
}
|
|
73
|
+
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));
|
|
74
|
+
},
|
|
75
|
+
async closeBundle() {
|
|
76
|
+
if (uploadPromise) await uploadPromise;
|
|
81
77
|
}
|
|
82
78
|
};
|
|
83
79
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tourmind-frontend/monitor-plugin-vite",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Vite 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
|
+
}
|