@tourmind-frontend/monitor-plugin-vite 1.0.1 → 1.0.5

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
@@ -81,16 +81,16 @@ function uploadSourceMapPlugin(options) {
81
81
  if (!options.branch) throw new Error(`${LOG_PREFIX} "branch" is required`);
82
82
  const log = (_a = options.logger) != null ? _a : defaultLogger;
83
83
  let enabled = false;
84
+ let uploadPromise = null;
84
85
  return {
85
86
  name: "frontend-monitor-plugin",
86
87
  apply: "build",
87
88
  configResolved(config) {
88
- var _a2;
89
- enabled = (_a2 = options.enabled) != null ? _a2 : config.mode === "production";
89
+ enabled = config.mode === "production";
90
90
  if (!enabled) return;
91
91
  config.build.sourcemap = "hidden";
92
92
  },
93
- async generateBundle(_, bundle) {
93
+ generateBundle(_, bundle) {
94
94
  var _a2, _b;
95
95
  if (!enabled) return;
96
96
  const files = extractSourceMaps(bundle);
@@ -106,12 +106,12 @@ function uploadSourceMapPlugin(options) {
106
106
  timestamp: String(timestamp)
107
107
  };
108
108
  if (commit) query.commit = commit;
109
- try {
110
- await uploadFiles({ url: options.url, query, files });
111
- log("info", `uploaded ${files.length} sourcemap file(s) (branch=${options.branch}, commit=${commit || "-"})`);
112
- } catch (err) {
113
- log("error", "upload failed", err instanceof Error ? err.message : err);
114
- }
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));
112
+ },
113
+ async closeBundle() {
114
+ if (uploadPromise) await uploadPromise;
115
115
  }
116
116
  };
117
117
  }
package/dist/index.d.ts CHANGED
@@ -9,8 +9,6 @@ export interface UploadSourceMapOptions {
9
9
  branch: string;
10
10
  /** Commit hash,由调用方自行解析(如 `git rev-parse HEAD`)。 */
11
11
  commit?: string;
12
- /** 强制启用 / 禁用。默认仅在 Vite mode === "production" 时为 `true`。 */
13
- enabled?: boolean;
14
12
  /** 构建时间戳(毫秒),未设置时取上传时刻的 `Date.now()`。 */
15
13
  timestamp?: number;
16
14
  /** 自定义 logger,默认走 `console.log` / `console.warn` / `console.error`。 */
package/dist/index.js CHANGED
@@ -47,16 +47,16 @@ function uploadSourceMapPlugin(options) {
47
47
  if (!options.branch) throw new Error(`${LOG_PREFIX} "branch" is required`);
48
48
  const log = (_a = options.logger) != null ? _a : defaultLogger;
49
49
  let enabled = false;
50
+ let uploadPromise = null;
50
51
  return {
51
52
  name: "frontend-monitor-plugin",
52
53
  apply: "build",
53
54
  configResolved(config) {
54
- var _a2;
55
- enabled = (_a2 = options.enabled) != null ? _a2 : config.mode === "production";
55
+ enabled = config.mode === "production";
56
56
  if (!enabled) return;
57
57
  config.build.sourcemap = "hidden";
58
58
  },
59
- async generateBundle(_, bundle) {
59
+ generateBundle(_, bundle) {
60
60
  var _a2, _b;
61
61
  if (!enabled) return;
62
62
  const files = extractSourceMaps(bundle);
@@ -72,12 +72,12 @@ function uploadSourceMapPlugin(options) {
72
72
  timestamp: String(timestamp)
73
73
  };
74
74
  if (commit) query.commit = commit;
75
- try {
76
- await uploadFiles({ url: options.url, query, files });
77
- log("info", `uploaded ${files.length} sourcemap file(s) (branch=${options.branch}, commit=${commit || "-"})`);
78
- } catch (err) {
79
- log("error", "upload failed", err instanceof Error ? err.message : err);
80
- }
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));
78
+ },
79
+ async closeBundle() {
80
+ if (uploadPromise) await uploadPromise;
81
81
  }
82
82
  };
83
83
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tourmind-frontend/monitor-plugin-vite",
3
- "version": "1.0.1",
3
+ "version": "1.0.5",
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
+ }