@tourmind-frontend/monitor-plugin-vite 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 CHANGED
@@ -76,10 +76,11 @@ async function uploadFiles({ url, query, files }) {
76
76
  }
77
77
  function uploadSourceMapPlugin(options) {
78
78
  var _a;
79
- if (!(options == null ? void 0 : options.url)) throw new Error(`${LOG_PREFIX} "url" is required`);
80
- if (!options.project) throw new Error(`${LOG_PREFIX} "project" is required`);
81
- if (!options.branch) throw new Error(`${LOG_PREFIX} "branch" is required`);
79
+ if (!options.url) throw new Error(`${LOG_PREFIX} "url" is required`);
80
+ if (!options.token) throw new Error(`${LOG_PREFIX} "token" is required`);
81
+ if (!options.commit) throw new Error(`${LOG_PREFIX} "commit" is required`);
82
82
  const log = (_a = options.logger) != null ? _a : defaultLogger;
83
+ const uploadUrl = `${options.url.replace(/\/+$/, "")}/api/upload`;
83
84
  let enabled = false;
84
85
  let uploadPromise = null;
85
86
  return {
@@ -101,14 +102,11 @@ function uploadSourceMapPlugin(options) {
101
102
  const commit = (_a2 = options.commit) != null ? _a2 : "";
102
103
  const timestamp = (_b = options.timestamp) != null ? _b : Date.now();
103
104
  const query = {
104
- project: options.project,
105
- branch: options.branch,
105
+ token: options.token,
106
106
  timestamp: String(timestamp)
107
107
  };
108
108
  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));
109
+ 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));
112
110
  },
113
111
  async closeBundle() {
114
112
  if (uploadPromise) await uploadPromise;
package/dist/index.d.ts CHANGED
@@ -1,14 +1,11 @@
1
1
  import { Plugin } from "vite";
2
2
  export interface UploadSourceMapOptions {
3
- /** 上传接口地址,例如 `https://monitor.example.com/api/upload`。 */
3
+ /** monitor 服务的 base URL,例如 `https://monitor.example.com`。内部拼接 `/api/upload`。 */
4
4
  url: string;
5
- /** 项目名,必须为 `owner/name` 格式以匹配服务端。 */
6
- project: string;
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?: string;
8
+ commit: string;
12
9
  /** 构建时间戳(毫秒),未设置时取上传时刻的 `Date.now()`。 */
13
10
  timestamp?: number;
14
11
  /** 自定义 logger,默认走 `console.log` / `console.warn` / `console.error`。 */
@@ -20,8 +17,8 @@ export interface UploadSourceMapOptions {
20
17
  * 该插件会:
21
18
  * - 强制 `build.sourcemap = "hidden"`,让 `.map` 文件生成但不被 bundle 内联引用
22
19
  * - 从最终的 bundle 中移除 `.map` chunk,避免泄漏到 public 产物
23
- * - 将收集到的每个 `.map` 以 `multipart/form-data` 形式 POST 到 `options.url`
24
- * - 在 URL 上追加服务端期望的 `project`、`branch`、`timestamp`、`commit` 查询参数
20
+ * - 将收集到的每个 `.map` 以 `multipart/form-data` 形式 POST 到 `${options.url}/api/upload`
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
@@ -42,10 +42,11 @@ async function uploadFiles({ url, query, files }) {
42
42
  }
43
43
  function uploadSourceMapPlugin(options) {
44
44
  var _a;
45
- if (!(options == null ? void 0 : options.url)) throw new Error(`${LOG_PREFIX} "url" is required`);
46
- if (!options.project) throw new Error(`${LOG_PREFIX} "project" is required`);
47
- if (!options.branch) throw new Error(`${LOG_PREFIX} "branch" is required`);
45
+ if (!options.url) throw new Error(`${LOG_PREFIX} "url" is required`);
46
+ if (!options.token) throw new Error(`${LOG_PREFIX} "token" is required`);
47
+ if (!options.commit) throw new Error(`${LOG_PREFIX} "commit" is required`);
48
48
  const log = (_a = options.logger) != null ? _a : defaultLogger;
49
+ const uploadUrl = `${options.url.replace(/\/+$/, "")}/api/upload`;
49
50
  let enabled = false;
50
51
  let uploadPromise = null;
51
52
  return {
@@ -67,14 +68,11 @@ function uploadSourceMapPlugin(options) {
67
68
  const commit = (_a2 = options.commit) != null ? _a2 : "";
68
69
  const timestamp = (_b = options.timestamp) != null ? _b : Date.now();
69
70
  const query = {
70
- project: options.project,
71
- branch: options.branch,
71
+ token: options.token,
72
72
  timestamp: String(timestamp)
73
73
  };
74
74
  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));
75
+ 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));
78
76
  },
79
77
  async closeBundle() {
80
78
  if (uploadPromise) await uploadPromise;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tourmind-frontend/monitor-plugin-vite",
3
- "version": "1.0.5",
3
+ "version": "1.2.0",
4
4
  "description": "Vite plugin that uploads sourcemaps to a frontend-monitor server.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",