@tourmind-frontend/monitor-plugin-vite 1.4.0 → 1.6.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
@@ -33,6 +33,7 @@ __export(src_exports, {
33
33
  default: () => uploadSourceMapPlugin
34
34
  });
35
35
  module.exports = __toCommonJS(src_exports);
36
+ var import_zlib = require("zlib");
36
37
  var import_axios = __toESM(require("axios"), 1);
37
38
  var import_form_data = __toESM(require("form-data"), 1);
38
39
  var LOG_PREFIX = "[frontend-monitor]";
@@ -43,6 +44,11 @@ function defaultLogger(level, msg, extra) {
43
44
  else if (level === "warn") console.warn(line, tail);
44
45
  else console.error(line, tail);
45
46
  }
47
+ function formatSize(bytes) {
48
+ if (bytes >= 1024 * 1024) return `${(bytes / 1024 / 1024).toFixed(1)}MB`;
49
+ if (bytes >= 1024) return `${(bytes / 1024).toFixed(1)}KB`;
50
+ return `${bytes}B`;
51
+ }
46
52
  function extractSourceMaps(bundle) {
47
53
  const result = [];
48
54
  for (const fileName of Object.keys(bundle)) {
@@ -60,10 +66,16 @@ function extractSourceMaps(bundle) {
60
66
  }
61
67
  async function uploadFiles({ url, query, files }) {
62
68
  const form = new import_form_data.default();
69
+ let rawBytes = 0;
70
+ let gzipBytes = 0;
63
71
  for (const [filename, content] of files) {
64
- form.append("file", Buffer.from(content, "utf-8"), { filename });
72
+ const raw = Buffer.from(content, "utf-8");
73
+ const gz = (0, import_zlib.gzipSync)(raw);
74
+ rawBytes += raw.byteLength;
75
+ gzipBytes += gz.byteLength;
76
+ form.append("file", gz, { filename });
65
77
  }
66
- const qs = new URLSearchParams(query).toString();
78
+ const qs = new URLSearchParams({ ...query, encoding: "gzip" }).toString();
67
79
  const fullUrl = `${url}${url.includes("?") ? "&" : "?"}${qs}`;
68
80
  await (0, import_axios.default)({
69
81
  method: "POST",
@@ -73,6 +85,7 @@ async function uploadFiles({ url, query, files }) {
73
85
  maxBodyLength: Infinity,
74
86
  maxContentLength: Infinity
75
87
  });
88
+ return { rawBytes, gzipBytes };
76
89
  }
77
90
  function uploadSourceMapPlugin(options) {
78
91
  var _a;
@@ -109,7 +122,12 @@ function uploadSourceMapPlugin(options) {
109
122
  timestamp: String(timestamp)
110
123
  };
111
124
  if (commit) query.commit = commit;
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));
125
+ uploadPromise = uploadFiles({ url: uploadUrl, query, files }).then(
126
+ ({ rawBytes, gzipBytes }) => log(
127
+ "info",
128
+ `uploaded ${files.length} sourcemap file(s) (commit=${commit || "-"}, ${formatSize(rawBytes)} -> ${formatSize(gzipBytes)} gzipped)`
129
+ )
130
+ ).catch((err) => log("error", "upload failed", err instanceof Error ? err.message : err));
113
131
  },
114
132
  async closeBundle() {
115
133
  if (uploadPromise) await uploadPromise;
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  // extensions/plugin-vite/src/index.ts
2
+ import { gzipSync } from "zlib";
2
3
  import axios from "axios";
3
4
  import FormData from "form-data";
4
5
  var LOG_PREFIX = "[frontend-monitor]";
@@ -9,6 +10,11 @@ function defaultLogger(level, msg, extra) {
9
10
  else if (level === "warn") console.warn(line, tail);
10
11
  else console.error(line, tail);
11
12
  }
13
+ function formatSize(bytes) {
14
+ if (bytes >= 1024 * 1024) return `${(bytes / 1024 / 1024).toFixed(1)}MB`;
15
+ if (bytes >= 1024) return `${(bytes / 1024).toFixed(1)}KB`;
16
+ return `${bytes}B`;
17
+ }
12
18
  function extractSourceMaps(bundle) {
13
19
  const result = [];
14
20
  for (const fileName of Object.keys(bundle)) {
@@ -26,10 +32,16 @@ function extractSourceMaps(bundle) {
26
32
  }
27
33
  async function uploadFiles({ url, query, files }) {
28
34
  const form = new FormData();
35
+ let rawBytes = 0;
36
+ let gzipBytes = 0;
29
37
  for (const [filename, content] of files) {
30
- form.append("file", Buffer.from(content, "utf-8"), { filename });
38
+ const raw = Buffer.from(content, "utf-8");
39
+ const gz = gzipSync(raw);
40
+ rawBytes += raw.byteLength;
41
+ gzipBytes += gz.byteLength;
42
+ form.append("file", gz, { filename });
31
43
  }
32
- const qs = new URLSearchParams(query).toString();
44
+ const qs = new URLSearchParams({ ...query, encoding: "gzip" }).toString();
33
45
  const fullUrl = `${url}${url.includes("?") ? "&" : "?"}${qs}`;
34
46
  await axios({
35
47
  method: "POST",
@@ -39,6 +51,7 @@ async function uploadFiles({ url, query, files }) {
39
51
  maxBodyLength: Infinity,
40
52
  maxContentLength: Infinity
41
53
  });
54
+ return { rawBytes, gzipBytes };
42
55
  }
43
56
  function uploadSourceMapPlugin(options) {
44
57
  var _a;
@@ -75,7 +88,12 @@ function uploadSourceMapPlugin(options) {
75
88
  timestamp: String(timestamp)
76
89
  };
77
90
  if (commit) query.commit = commit;
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));
91
+ uploadPromise = uploadFiles({ url: uploadUrl, query, files }).then(
92
+ ({ rawBytes, gzipBytes }) => log(
93
+ "info",
94
+ `uploaded ${files.length} sourcemap file(s) (commit=${commit || "-"}, ${formatSize(rawBytes)} -> ${formatSize(gzipBytes)} gzipped)`
95
+ )
96
+ ).catch((err) => log("error", "upload failed", err instanceof Error ? err.message : err));
79
97
  },
80
98
  async closeBundle() {
81
99
  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.4.0",
3
+ "version": "1.6.0",
4
4
  "description": "Vite plugin that uploads sourcemaps to a frontend-monitor server.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",