bugwatch-cli 0.2.0 → 0.3.1

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/README.md CHANGED
@@ -17,11 +17,15 @@ npm install --save-dev bugwatch-cli
17
17
 
18
18
  ## Before you start
19
19
 
20
+ 0. **Turn on source maps for the project**: project → Settings →
21
+ Source maps → "Store source maps" (owners and managers). New
22
+ projects start with it off; while it is off, every upload is
23
+ refused (`403`) and the CLI stops after the first one.
20
24
  1. **Create an org CI token** in the dashboard: organization → CI
21
25
  tokens (owners and managers), for all projects or chosen ones. It is
22
26
  shown once; store it as a CI secret named `BUGWATCH_UPLOAD_TOKEN`.
23
27
  Never commit it. Then set **`BUGWATCH_PROJECT`** to the project id
24
- (project → Settings → Source maps). One token can serve several
28
+ (project → Source maps). One token can serve several
25
29
  projects; each upload names its project.
26
30
 
27
31
  Older per-project upload tokens (`bwu_…`) still work without
@@ -107,13 +111,29 @@ unchanged ~/assets/vendor-77aa01e2.js (assets/vendor-77aa01e2.js.map, 912.4 KB)
107
111
  Release 1.4.2: 1 uploaded, 0 replaced, 1 unchanged, 0 failed.
108
112
  ```
109
113
 
110
- Exit codes: `0` everything uploaded, `1` an upload failed, `2` usage
111
- error (no token, no release, no `.map` files, bad prefix).
114
+ Exit codes: `0` everything uploaded, `1` an upload failed or was not
115
+ sent, `2` usage error (no token, no release, no `.map` files, bad
116
+ prefix).
112
117
 
113
118
  Rate limits (`429`, honouring `Retry-After`), server errors (`5xx`),
114
119
  and network errors are retried up to 3 times with backoff. `400`,
115
- `401`, `409`, and `413` are not retried: the message says what to
116
- fix. The token is never printed.
120
+ `401`, `403`, `409`, and `413` are not retried: the message says what
121
+ to fix. The token is never printed.
122
+
123
+ When the server refuses an upload for the whole project — source maps
124
+ are turned off for it, or its plan's storage is full — the CLI stops:
125
+ maps not yet sent are counted as "not sent", the summary ends with
126
+ the server's message, and no `.map` file is deleted:
127
+
128
+ ```
129
+ failed ~/assets/index-3f9a0c1d.js (assets/index-3f9a0c1d.js.map, 1.8 MB): 409 This project's Free plan includes 50 MB of source maps (49.9 MB used). …
130
+
131
+ Release 1.4.2: 0 uploaded, 0 replaced, 0 unchanged, 1 failed. 11 not sent. Stopped: This project's Free plan includes 50 MB …
132
+ ```
133
+
134
+ Each upload also sends the `.map` file's path and the size of the
135
+ minified file it belongs to, so the dashboard can show them
136
+ (Bugwatch API Step 44; older servers ignore them).
117
137
 
118
138
  ## File names
119
139
 
@@ -167,7 +187,10 @@ same script. The prefix must start with `~/`, `http://`, or
167
187
  ## Limits
168
188
 
169
189
  - One map: at most 20 MB
170
- - 500 maps per release, 50 MB stored (compressed) per project
190
+ - 500 maps per release
191
+ - Storage per project by the organization's plan: Free 50 MB, Pro
192
+ 2 GB, counted as the `.map` files' sizes (`409` when full; delete
193
+ older releases' maps in the dashboard or upgrade)
171
194
  - 600 uploads per 10 minutes per token
172
195
  - A CI token uploads only to the projects it covers (`403` for
173
196
  another project of the organization, `404` for any other project)
@@ -1,5 +1,32 @@
1
+ // src/format.ts
2
+ function formatBytes(bytes) {
3
+ if (bytes < 1024) return `${bytes} B`;
4
+ if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
5
+ return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
6
+ }
7
+ function formatResult(result) {
8
+ const label = result.outcome.padEnd(9);
9
+ const detail = `${result.file}, ${formatBytes(result.bytes)}`;
10
+ if (result.outcome === "failed") {
11
+ const status = result.status ? `${result.status} ` : "";
12
+ return `${label} ${result.name} (${detail}): ${status}${result.error ?? "unknown error"}`;
13
+ }
14
+ return `${label} ${result.name} (${detail})`;
15
+ }
16
+ function formatSummary(summary, { dryRun, release, files }) {
17
+ const css = summary.skipped > 0 ? ` Skipped ${summary.skipped} CSS map${summary.skipped === 1 ? "" : "s"}.` : "";
18
+ if (dryRun) {
19
+ const skipped = summary.failed > 0 ? ` (${summary.failed} would fail)` : "";
20
+ return `Dry run for release ${release}: ${files} source map${files === 1 ? "" : "s"} found${skipped}; nothing was uploaded.${css}`;
21
+ }
22
+ const notSent = summary.notSent > 0 ? ` ${summary.notSent} not sent.` : "";
23
+ const stopped = summary.stopped ? ` Stopped: ${summary.stopped}` : "";
24
+ const line = `Release ${release}: ${summary.uploaded} uploaded, ${summary.replaced} replaced, ${summary.unchanged} unchanged, ${summary.failed} failed.${notSent}${css}${stopped}`;
25
+ return summary.deleted > 0 ? `${line} Deleted ${summary.deleted} local .map file${summary.deleted === 1 ? "" : "s"}.` : line;
26
+ }
27
+
1
28
  // src/version.ts
2
- var VERSION = "0.2.0";
29
+ var VERSION = "0.3.1";
3
30
 
4
31
  // src/upload.ts
5
32
  import { open, readdir, readFile, stat, unlink } from "fs/promises";
@@ -17,11 +44,12 @@ function isCiToken(token) {
17
44
  function isDeprecatedUploadToken(token) {
18
45
  return typeof token === "string" && token.startsWith("bwu_");
19
46
  }
20
- var UPLOAD_TOKEN_DEPRECATED = "Upload tokens (bwu_\u2026) are deprecated. Create an org CI token in Bugwatch (organization \u2192 CI tokens), store it as BUGWATCH_UPLOAD_TOKEN, and set BUGWATCH_PROJECT to the project id (project \u2192 Settings \u2192 Source maps).";
47
+ var UPLOAD_TOKEN_DEPRECATED = "Upload tokens (bwu_\u2026) are deprecated. Create an org CI token in Bugwatch (organization \u2192 CI tokens), store it as BUGWATCH_UPLOAD_TOKEN, and set BUGWATCH_PROJECT to the project id (project \u2192 Source maps).";
21
48
  function projectProblem(project) {
22
49
  if (project === void 0 || project === "") return null;
23
- return /^[0-9a-f]{24}$/i.test(project) ? null : "The project must be a project id: 24 hex characters, from the project's Settings \u2192 Source maps";
50
+ return /^[0-9a-f]{24}$/i.test(project) ? null : "The project must be a project id: 24 hex characters, from the project's Source maps page";
24
51
  }
52
+ var STOP_CODES = /* @__PURE__ */ new Set(["SOURCEMAPS_DISABLED", "SOURCEMAP_PLAN_LIMIT"]);
25
53
  var UsageError = class extends Error {
26
54
  constructor(message) {
27
55
  super(message);
@@ -109,7 +137,8 @@ async function planUploads(dir, maps, urlPrefix = DEFAULT_URL_PREFIX) {
109
137
  const owners = await findMapOwners(dir, maps);
110
138
  return maps.filter((map) => !isCssMap(map)).flatMap((map) => {
111
139
  const scripts = owners.get(map);
112
- return scripts ? scripts.map((script) => ({ map, name: urlPrefix + script })) : [{ map, name: mapName(map, urlPrefix) }];
140
+ if (scripts) return scripts.map((script) => ({ map, name: urlPrefix + script, script }));
141
+ return [{ map, name: mapName(map, urlPrefix), script: map.replace(/\.map$/, "") }];
113
142
  });
114
143
  }
115
144
  function retryAfterMs(header, now = Date.now()) {
@@ -122,17 +151,35 @@ function retryAfterMs(header, now = Date.now()) {
122
151
  function backoffMs(retry) {
123
152
  return 1e3 * 2 ** (retry - 1);
124
153
  }
125
- async function errorMessage(response) {
154
+ async function errorOf(response) {
126
155
  try {
127
156
  const body = await response.json();
128
- if (typeof body.error?.message === "string") return body.error.message;
157
+ if (typeof body.error?.message === "string") {
158
+ return { message: body.error.message, ...typeof body.error.code === "string" ? { code: body.error.code } : {} };
159
+ }
129
160
  } catch {
130
161
  }
131
- return `HTTP ${response.status}`;
162
+ return { message: `HTTP ${response.status}` };
132
163
  }
133
- async function uploadFile(context, file, name, body) {
164
+ function sendableMapFile(path) {
165
+ return path.length > 0 && path.length <= 500 && // eslint-disable-next-line no-control-regex
166
+ !/[\s\u0000-\u001f\u007f?#\\]/.test(path) && !path.startsWith("/") && !path.split("/").includes("..");
167
+ }
168
+ async function chunkSizeOf(dir, script) {
169
+ if (!script) return void 0;
170
+ try {
171
+ const info = await stat(join(dir, script));
172
+ return info.isFile() ? info.size : void 0;
173
+ } catch {
174
+ return void 0;
175
+ }
176
+ }
177
+ async function uploadFile(context, file, name, body, chunkSize) {
134
178
  const route = context.project ? `/api/projects/${encodeURIComponent(context.project)}/releases/${encodeURIComponent(context.release)}/sourcemaps` : `/api/releases/${encodeURIComponent(context.release)}/sourcemaps`;
135
- const url = `${context.apiUrl}${route}?name=${encodeURIComponent(name)}`;
179
+ const query = new URLSearchParams({ name });
180
+ if (sendableMapFile(file)) query.set("mapFile", file);
181
+ if (chunkSize !== void 0) query.set("chunkSize", String(chunkSize));
182
+ const url = `${context.apiUrl}${route}?${query.toString().replace(/\+/g, "%20")}`;
136
183
  const base = { file, name, bytes: body.length };
137
184
  for (let attempt = 0; ; attempt += 1) {
138
185
  let response = null;
@@ -160,9 +207,9 @@ async function uploadFile(context, file, name, body) {
160
207
  }
161
208
  return { ...base, outcome: unchanged ? "unchanged" : "replaced", status: 200 };
162
209
  }
163
- const message = await errorMessage(response);
210
+ const { message, code } = await errorOf(response);
164
211
  if (response.status !== 429 && response.status < 500) {
165
- return { ...base, outcome: "failed", status: response.status, error: message };
212
+ return { ...base, outcome: "failed", status: response.status, error: message, ...code ? { code } : {} };
166
213
  }
167
214
  reason = `${response.status} ${message}`;
168
215
  if (attempt === MAX_RETRIES) return { ...base, outcome: "failed", status: response.status, error: message };
@@ -205,7 +252,7 @@ async function uploadSourceMaps(options) {
205
252
  if (projectError) throw new UsageError(projectError);
206
253
  if (!options.dryRun && isCiToken(options.token) && !options.project) {
207
254
  throw new UsageError(
208
- "A CI token (bwc_\u2026) needs the project id: set BUGWATCH_PROJECT (from the project's Settings \u2192 Source maps)"
255
+ "A CI token (bwc_\u2026) needs the project id: set BUGWATCH_PROJECT (from the project's Source maps page)"
209
256
  );
210
257
  }
211
258
  const dir = resolve(options.dir);
@@ -229,10 +276,14 @@ async function uploadSourceMaps(options) {
229
276
  sleep: options.sleep ?? defaultSleep,
230
277
  onRetry: options.onRetry
231
278
  };
232
- const results = await mapLimit(uploads, CONCURRENCY, async ({ map: file, name }) => {
279
+ let stopped = null;
280
+ const results = await mapLimit(uploads, CONCURRENCY, async ({ map: file, name, script }) => {
233
281
  const path = join(dir, file);
234
282
  const { size } = await stat(path);
235
283
  let result;
284
+ if (stopped !== null) {
285
+ return { file, name, bytes: size, outcome: "not-sent", error: stopped };
286
+ }
236
287
  if (name.length > MAX_NAME_LENGTH) {
237
288
  result = { file, name, bytes: size, outcome: "failed", error: `The file URL is longer than ${MAX_NAME_LENGTH} characters` };
238
289
  } else if (/[\s?#]/.test(name)) {
@@ -242,7 +293,8 @@ async function uploadSourceMaps(options) {
242
293
  } else if (options.dryRun) {
243
294
  result = { file, name, bytes: size, outcome: "dry-run" };
244
295
  } else {
245
- result = await uploadFile(context, file, name, await readFile(path));
296
+ result = await uploadFile(context, file, name, await readFile(path), await chunkSizeOf(dir, script));
297
+ if (result.code && STOP_CODES.has(result.code)) stopped ??= result.error ?? result.code;
246
298
  }
247
299
  options.onResult?.(result);
248
300
  return result;
@@ -254,9 +306,11 @@ async function uploadSourceMaps(options) {
254
306
  replaced: count("replaced"),
255
307
  unchanged: count("unchanged"),
256
308
  failed: count("failed"),
309
+ notSent: count("not-sent"),
310
+ stopped,
257
311
  deleted: 0
258
312
  };
259
- if (options.deleteAfterUpload && !options.dryRun && summary.failed === 0) {
313
+ if (options.deleteAfterUpload && !options.dryRun && summary.failed === 0 && summary.notSent === 0) {
260
314
  await Promise.all(files.map((file) => unlink(join(dir, file))));
261
315
  summary.deleted = files.length;
262
316
  }
@@ -264,6 +318,9 @@ async function uploadSourceMaps(options) {
264
318
  }
265
319
 
266
320
  export {
321
+ formatBytes,
322
+ formatResult,
323
+ formatSummary,
267
324
  VERSION,
268
325
  DEFAULT_API_URL,
269
326
  DEFAULT_URL_PREFIX,
@@ -274,6 +331,7 @@ export {
274
331
  isDeprecatedUploadToken,
275
332
  UPLOAD_TOKEN_DEPRECATED,
276
333
  projectProblem,
334
+ STOP_CODES,
277
335
  UsageError,
278
336
  releaseProblem,
279
337
  urlPrefixProblem,
@@ -283,5 +341,6 @@ export {
283
341
  findMapOwners,
284
342
  isCssMap,
285
343
  planUploads,
344
+ sendableMapFile,
286
345
  uploadSourceMaps
287
346
  };
@@ -1,17 +1,15 @@
1
- import {
2
- formatResult,
3
- formatSummary
4
- } from "./chunk-C7AULTCO.js";
5
1
  import {
6
2
  DEFAULT_API_URL,
7
3
  DEFAULT_URL_PREFIX,
8
4
  UPLOAD_TOKEN_DEPRECATED,
9
5
  UsageError,
10
6
  VERSION,
7
+ formatResult,
8
+ formatSummary,
11
9
  isCiToken,
12
10
  isDeprecatedUploadToken,
13
11
  uploadSourceMaps
14
- } from "./chunk-JYWRABTL.js";
12
+ } from "./chunk-NJEKNSX4.js";
15
13
 
16
14
  // src/main.ts
17
15
  import { parseArgs } from "util";
@@ -26,7 +24,7 @@ Options:
26
24
  --api-url <url> Bugwatch API (default: $BUGWATCH_API_URL or ${DEFAULT_API_URL})
27
25
  --token <token> Org CI token, bwc_\u2026 (default: $BUGWATCH_UPLOAD_TOKEN; prefer the variable)
28
26
  --project <id> Project id, required with a CI token (default: $BUGWATCH_PROJECT;
29
- shown in the project's Settings \u2192 Source maps)
27
+ shown on the project's Source maps page)
30
28
  --delete-after-upload Delete the local .map files after every upload succeeded
31
29
  --dry-run List what would be uploaded; uploads and deletes nothing
32
30
  -h, --help Show this help
@@ -105,10 +103,10 @@ ${USAGE}`);
105
103
  });
106
104
  out("");
107
105
  out(formatSummary(summary, { dryRun, release: values.release, files: results.length }));
108
- if (summary.failed > 0 && values["delete-after-upload"]) {
106
+ if ((summary.failed > 0 || summary.notSent > 0) && values["delete-after-upload"]) {
109
107
  out("Kept the local .map files because an upload failed.");
110
108
  }
111
- return summary.failed > 0 ? 1 : 0;
109
+ return summary.failed > 0 || summary.notSent > 0 ? 1 : 0;
112
110
  } catch (error) {
113
111
  if (error instanceof UsageError) {
114
112
  err(`Error: ${error.message}`);
package/dist/cli.js CHANGED
@@ -1,9 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  main
4
- } from "./chunk-7356247V.js";
5
- import "./chunk-C7AULTCO.js";
6
- import "./chunk-JYWRABTL.js";
4
+ } from "./chunk-YSCPONSJ.js";
5
+ import "./chunk-NJEKNSX4.js";
7
6
 
8
7
  // src/cli.ts
9
8
  main(process.argv.slice(2)).then((code) => {
package/dist/index.d.ts CHANGED
@@ -17,7 +17,12 @@ declare function isDeprecatedUploadToken(token: string | undefined): boolean;
17
17
  declare const UPLOAD_TOKEN_DEPRECATED: string;
18
18
  /** A Bugwatch project id: 24 hex characters. */
19
19
  declare function projectProblem(project: string | undefined): string | null;
20
- type Outcome = "uploaded" | "replaced" | "unchanged" | "failed" | "dry-run";
20
+ type Outcome = "uploaded" | "replaced" | "unchanged" | "failed" | "dry-run" | "not-sent";
21
+ /**
22
+ * Error codes after which no further upload can succeed (Bugwatch backend
23
+ * Steps 42 and 45): the remaining files are not sent.
24
+ */
25
+ declare const STOP_CODES: Set<string>;
21
26
  interface FileResult {
22
27
  /** The map's path relative to `dir`, with `/` separators (one map can be uploaded under several names). */
23
28
  file: string;
@@ -29,6 +34,8 @@ interface FileResult {
29
34
  status?: number;
30
35
  /** Why it failed. */
31
36
  error?: string;
37
+ /** The backend's error code, when it sent one. */
38
+ code?: string;
32
39
  }
33
40
  interface UploadSummary {
34
41
  /** CSS maps found and not uploaded (errors only come from scripts). */
@@ -37,6 +44,10 @@ interface UploadSummary {
37
44
  replaced: number;
38
45
  unchanged: number;
39
46
  failed: number;
47
+ /** Not sent because an earlier upload was refused for the whole project (source maps off, plan limit full). */
48
+ notSent: number;
49
+ /** The server's message that stopped the run, or null. */
50
+ stopped: string | null;
40
51
  /** Local `.map` files deleted after a fully successful upload. */
41
52
  deleted: number;
42
53
  }
@@ -101,6 +112,8 @@ declare function isCssMap(map: string): boolean;
101
112
  interface PlannedUpload {
102
113
  map: string;
103
114
  name: string;
115
+ /** The minified file (relative to `dir`) the map belongs to, when known; its size is sent as `chunkSize`. */
116
+ script?: string;
104
117
  }
105
118
  /**
106
119
  * The uploads for `maps`: a map referenced by scripts is uploaded once per
@@ -108,6 +121,8 @@ interface PlannedUpload {
108
121
  * `sourcemap: "hidden"`) is named after itself without `.map`.
109
122
  */
110
123
  declare function planUploads(dir: string, maps: string[], urlPrefix?: string): Promise<PlannedUpload[]>;
124
+ /** Same rules as the backend's `mapFile` (Step 44); a path that breaks them is simply not sent. */
125
+ declare function sendableMapFile(path: string): boolean;
111
126
  /**
112
127
  * Uploads every source map under `dir` for `release` (4 at a time, with
113
128
  * retries). Throws `UsageError` for problems with the options; upload
@@ -115,7 +130,16 @@ declare function planUploads(dir: string, maps: string[], urlPrefix?: string): P
115
130
  */
116
131
  declare function uploadSourceMaps(options: UploadOptions): Promise<UploadReport>;
117
132
 
133
+ declare function formatBytes(bytes: number): string;
134
+ /** `uploaded ~/assets/index.js (assets/index.js.map, 1.8 MB)`, or the reason it failed. */
135
+ declare function formatResult(result: FileResult): string;
136
+ declare function formatSummary(summary: UploadSummary, { dryRun, release, files }: {
137
+ dryRun: boolean;
138
+ release: string;
139
+ files: number;
140
+ }): string;
141
+
118
142
  /** Keep in sync with package.json (a test checks it). */
119
- declare const VERSION = "0.2.0";
143
+ declare const VERSION = "0.3.1";
120
144
 
121
- export { CONCURRENCY, DEFAULT_API_URL, DEFAULT_URL_PREFIX, type FileResult, MAX_MAP_BYTES, MAX_RETRIES, type Outcome, type PlannedUpload, UPLOAD_TOKEN_DEPRECATED, type UploadOptions, type UploadReport, type UploadSummary, UsageError, VERSION, findMapOwners, findSourceMaps, isCiToken, isCssMap, isDeprecatedUploadToken, mapName, planUploads, projectProblem, releaseProblem, sourceMappingUrlOf, uploadSourceMaps, urlPrefixProblem };
145
+ export { CONCURRENCY, DEFAULT_API_URL, DEFAULT_URL_PREFIX, type FileResult, MAX_MAP_BYTES, MAX_RETRIES, type Outcome, type PlannedUpload, STOP_CODES, UPLOAD_TOKEN_DEPRECATED, type UploadOptions, type UploadReport, type UploadSummary, UsageError, VERSION, findMapOwners, findSourceMaps, formatBytes, formatResult, formatSummary, isCiToken, isCssMap, isDeprecatedUploadToken, mapName, planUploads, projectProblem, releaseProblem, sendableMapFile, sourceMappingUrlOf, uploadSourceMaps, urlPrefixProblem };
package/dist/index.js CHANGED
@@ -4,11 +4,15 @@ import {
4
4
  DEFAULT_URL_PREFIX,
5
5
  MAX_MAP_BYTES,
6
6
  MAX_RETRIES,
7
+ STOP_CODES,
7
8
  UPLOAD_TOKEN_DEPRECATED,
8
9
  UsageError,
9
10
  VERSION,
10
11
  findMapOwners,
11
12
  findSourceMaps,
13
+ formatBytes,
14
+ formatResult,
15
+ formatSummary,
12
16
  isCiToken,
13
17
  isCssMap,
14
18
  isDeprecatedUploadToken,
@@ -16,21 +20,26 @@ import {
16
20
  planUploads,
17
21
  projectProblem,
18
22
  releaseProblem,
23
+ sendableMapFile,
19
24
  sourceMappingUrlOf,
20
25
  uploadSourceMaps,
21
26
  urlPrefixProblem
22
- } from "./chunk-JYWRABTL.js";
27
+ } from "./chunk-NJEKNSX4.js";
23
28
  export {
24
29
  CONCURRENCY,
25
30
  DEFAULT_API_URL,
26
31
  DEFAULT_URL_PREFIX,
27
32
  MAX_MAP_BYTES,
28
33
  MAX_RETRIES,
34
+ STOP_CODES,
29
35
  UPLOAD_TOKEN_DEPRECATED,
30
36
  UsageError,
31
37
  VERSION,
32
38
  findMapOwners,
33
39
  findSourceMaps,
40
+ formatBytes,
41
+ formatResult,
42
+ formatSummary,
34
43
  isCiToken,
35
44
  isCssMap,
36
45
  isDeprecatedUploadToken,
@@ -38,6 +47,7 @@ export {
38
47
  planUploads,
39
48
  projectProblem,
40
49
  releaseProblem,
50
+ sendableMapFile,
41
51
  sourceMappingUrlOf,
42
52
  uploadSourceMaps,
43
53
  urlPrefixProblem
package/dist/main.js CHANGED
@@ -1,8 +1,7 @@
1
1
  import {
2
2
  main
3
- } from "./chunk-7356247V.js";
4
- import "./chunk-C7AULTCO.js";
5
- import "./chunk-JYWRABTL.js";
3
+ } from "./chunk-YSCPONSJ.js";
4
+ import "./chunk-NJEKNSX4.js";
6
5
  export {
7
6
  main
8
7
  };
package/dist/vite.js CHANGED
@@ -1,15 +1,13 @@
1
- import {
2
- formatResult,
3
- formatSummary
4
- } from "./chunk-C7AULTCO.js";
5
1
  import {
6
2
  DEFAULT_URL_PREFIX,
7
3
  UPLOAD_TOKEN_DEPRECATED,
8
4
  UsageError,
5
+ formatResult,
6
+ formatSummary,
9
7
  isCiToken,
10
8
  isDeprecatedUploadToken,
11
9
  uploadSourceMaps
12
- } from "./chunk-JYWRABTL.js";
10
+ } from "./chunk-NJEKNSX4.js";
13
11
 
14
12
  // src/vite.ts
15
13
  import { resolve } from "path";
@@ -69,8 +67,9 @@ function bugwatchSourcemaps(options) {
69
67
  onRetry: ({ file, attempt, reason }) => logger.warn(`${PREFIX} retry ${file} (attempt ${attempt + 1}): ${reason}`)
70
68
  });
71
69
  logger.info(`${PREFIX} ${formatSummary(summary, { dryRun: false, release, files: results.length })}`);
72
- if (summary.failed > 0) {
73
- fail(`${summary.failed} source map upload${summary.failed === 1 ? "" : "s"} failed; the .map files were kept`);
70
+ if (summary.failed > 0 || summary.notSent > 0) {
71
+ const count = summary.failed + summary.notSent;
72
+ fail(`${count} source map upload${count === 1 ? "" : "s"} failed or not sent; the .map files were kept`);
74
73
  }
75
74
  } catch (error) {
76
75
  if (error instanceof Error && error.message.startsWith(PREFIX)) throw error;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bugwatch-cli",
3
- "version": "0.2.0",
3
+ "version": "0.3.1",
4
4
  "description": "Upload source maps to Bugwatch from CI (CLI and Vite plugin)",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1,29 +0,0 @@
1
- // src/format.ts
2
- function formatBytes(bytes) {
3
- if (bytes < 1024) return `${bytes} B`;
4
- if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
5
- return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
6
- }
7
- function formatResult(result) {
8
- const label = result.outcome.padEnd(9);
9
- const detail = `${result.file}, ${formatBytes(result.bytes)}`;
10
- if (result.outcome === "failed") {
11
- const status = result.status ? `${result.status} ` : "";
12
- return `${label} ${result.name} (${detail}): ${status}${result.error ?? "unknown error"}`;
13
- }
14
- return `${label} ${result.name} (${detail})`;
15
- }
16
- function formatSummary(summary, { dryRun, release, files }) {
17
- const css = summary.skipped > 0 ? ` Skipped ${summary.skipped} CSS map${summary.skipped === 1 ? "" : "s"}.` : "";
18
- if (dryRun) {
19
- const skipped = summary.failed > 0 ? ` (${summary.failed} would fail)` : "";
20
- return `Dry run for release ${release}: ${files} source map${files === 1 ? "" : "s"} found${skipped}; nothing was uploaded.${css}`;
21
- }
22
- const line = `Release ${release}: ${summary.uploaded} uploaded, ${summary.replaced} replaced, ${summary.unchanged} unchanged, ${summary.failed} failed.${css}`;
23
- return summary.deleted > 0 ? `${line} Deleted ${summary.deleted} local .map file${summary.deleted === 1 ? "" : "s"}.` : line;
24
- }
25
-
26
- export {
27
- formatResult,
28
- formatSummary
29
- };