@tourmind-frontend/monitor-plugin-vite 1.0.5 → 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 +3 -7
- package/dist/index.d.ts +3 -6
- package/dist/index.js +3 -7
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -77,8 +77,7 @@ 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;
|
|
84
83
|
let uploadPromise = null;
|
|
@@ -101,14 +100,11 @@ 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
|
-
uploadPromise = uploadFiles({ url: options.url, query, files }).then(
|
|
110
|
-
() => log("info", `uploaded ${files.length} sourcemap file(s) (branch=${options.branch}, commit=${commit || "-"})`)
|
|
111
|
-
).catch((err) => log("error", "upload failed", err instanceof Error ? err.message : err));
|
|
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));
|
|
112
108
|
},
|
|
113
109
|
async closeBundle() {
|
|
114
110
|
if (uploadPromise) await uploadPromise;
|
package/dist/index.d.ts
CHANGED
|
@@ -2,11 +2,8 @@ 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
9
|
/** 构建时间戳(毫秒),未设置时取上传时刻的 `Date.now()`。 */
|
|
@@ -21,7 +18,7 @@ export interface UploadSourceMapOptions {
|
|
|
21
18
|
* - 强制 `build.sourcemap = "hidden"`,让 `.map` 文件生成但不被 bundle 内联引用
|
|
22
19
|
* - 从最终的 bundle 中移除 `.map` chunk,避免泄漏到 public 产物
|
|
23
20
|
* - 将收集到的每个 `.map` 以 `multipart/form-data` 形式 POST 到 `options.url`
|
|
24
|
-
* - 在 URL 上追加服务端期望的 `
|
|
21
|
+
* - 在 URL 上追加服务端期望的 `token`、`timestamp`、`commit` 查询参数
|
|
25
22
|
* (`commit` 仅在 options 显式提供时才会发送)
|
|
26
23
|
*/
|
|
27
24
|
export default function uploadSourceMapPlugin(options: UploadSourceMapOptions): Plugin;
|
package/dist/index.js
CHANGED
|
@@ -43,8 +43,7 @@ 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;
|
|
50
49
|
let uploadPromise = null;
|
|
@@ -67,14 +66,11 @@ 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
|
-
uploadPromise = uploadFiles({ url: options.url, query, files }).then(
|
|
76
|
-
() => log("info", `uploaded ${files.length} sourcemap file(s) (branch=${options.branch}, commit=${commit || "-"})`)
|
|
77
|
-
).catch((err) => log("error", "upload failed", err instanceof Error ? err.message : err));
|
|
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));
|
|
78
74
|
},
|
|
79
75
|
async closeBundle() {
|
|
80
76
|
if (uploadPromise) await uploadPromise;
|