bugwatch-cli 0.5.2 → 0.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/README.md CHANGED
@@ -129,6 +129,7 @@ Options:
129
129
  | `urlPrefix` | `"~/"` | See [File names](#file-names) |
130
130
  | `apiUrl` | `BUGWATCH_API_URL`, else Bugwatch's hosted API | |
131
131
  | `deleteAfterUpload` | `true` | Delete the `.map` files from the build output after a fully successful upload |
132
+ | `deleteOld` | `false` | Delete the project's older source maps in Bugwatch after a fully successful upload. See [Keep only the latest deploy](#keep-only-the-latest-deploy) |
132
133
  | `failOnError` | `false` | Fail `vite build` when an upload fails (default: log the error and continue) |
133
134
 
134
135
  The plugin runs only for `vite build` (not the dev server), after the
@@ -153,6 +154,7 @@ npx bugwatch-cli sourcemaps upload dist --release 1.4.2 --delete-after-upload
153
154
  | `--token <token>` | Default `BUGWATCH_UPLOAD_TOKEN` (an org CI token, `bwc_…`). Prefer the variable: flags can end up in CI logs |
154
155
  | `--project <id>` | Default `BUGWATCH_PROJECT`. The project id; required with a CI token |
155
156
  | `--delete-after-upload` | Delete the local `.map` files, only after every upload succeeded |
157
+ | `--delete-old` | Delete the project's older source maps in Bugwatch, only after every upload succeeded. See [Keep only the latest deploy](#keep-only-the-latest-deploy) |
156
158
  | `--dry-run` | Print what would be uploaded; no token needed, nothing sent or deleted |
157
159
 
158
160
  It uploads every `*.map` file under `<dir>` (recursively, skipping
@@ -222,6 +224,33 @@ build. A map uploaded for a full URL wins over a `~/` one for the
222
224
  same script. The prefix must start with `~/`, `http://`, or
223
225
  `https://` and end with `/`.
224
226
 
227
+ ## Keep only the latest deploy
228
+
229
+ By default every deploy adds its maps and the older releases' maps stay
230
+ for 90 days, counting toward the plan's storage. With `--delete-old`
231
+ (Vite: `deleteOld: true`) each deploy replaces them:
232
+
233
+ 1. The new maps are uploaded as usual
234
+ 2. Only if every upload succeeded, Bugwatch deletes the project's maps
235
+ of every other release, and of this release the files not in this
236
+ upload (when every deploy reuses one release name, the old hashed
237
+ chunks go)
238
+ 3. If the plan's storage is full, the older releases are deleted
239
+ first and the refused files are sent again
240
+
241
+ ```sh
242
+ npx bugwatch-cli sourcemaps upload dist --release ${GITHUB_SHA} --delete-after-upload --delete-old
243
+ ```
244
+
245
+ - Needs an org CI token (`bwc_…`); upload tokens (`bwu_…`) cannot delete
246
+ - Errors already in Bugwatch keep their readable stack traces. New
247
+ errors from an older release (e.g. a browser tab opened before the
248
+ deploy) are no longer mapped
249
+ - If the upload fails, nothing is deleted. If only the delete fails,
250
+ the command warns and still exits 0: the new maps are stored
251
+ - Run it on deploys of one environment only: a staging deploy with
252
+ `--delete-old` deletes production's maps of the same project
253
+
225
254
  ## CI example (GitHub Actions)
226
255
 
227
256
  ```yaml
@@ -233,7 +262,7 @@ same script. The prefix must start with `~/`, `http://`, or
233
262
  BUGWATCH_UPLOAD_TOKEN: ${{ secrets.BUGWATCH_UPLOAD_TOKEN }} # an org CI token
234
263
  BUGWATCH_PROJECT: 6735f0c2a1b2c3d4e5f60718 # the project id (not a secret)
235
264
  # Without the Vite plugin:
236
- # - run: npx bugwatch-cli sourcemaps upload dist --release ${{ github.sha }} --delete-after-upload
265
+ # - run: npx bugwatch-cli sourcemaps upload dist --release ${{ github.sha }} --delete-after-upload --delete-old
237
266
  # env:
238
267
  # BUGWATCH_UPLOAD_TOKEN: ${{ secrets.BUGWATCH_UPLOAD_TOKEN }}
239
268
  # BUGWATCH_PROJECT: 6735f0c2a1b2c3d4e5f60718
@@ -244,8 +273,9 @@ same script. The prefix must start with `~/`, `http://`, or
244
273
  - One map: at most 20 MB
245
274
  - 500 maps per release
246
275
  - Storage per project by the organization's plan: Free 50 MB, Pro
247
- 2 GB, counted as the `.map` files' sizes (`409` when full; delete
248
- older releases' maps in the dashboard or upgrade)
276
+ 2 GB, counted as the `.map` files' sizes (`409` when full; use
277
+ `--delete-old`, delete older releases' maps in the dashboard, or
278
+ upgrade)
249
279
  - 600 uploads per 10 minutes per token
250
280
  - A CI token uploads only to the projects it covers (`403` for
251
281
  another project of the organization, `404` for any other project)
@@ -13,20 +13,30 @@ function formatResult(result) {
13
13
  }
14
14
  return `${label} ${result.name} (${detail})`;
15
15
  }
16
- function formatSummary(summary, { dryRun, release, files }) {
16
+ var plural = (n, word) => `${n} ${word}${n === 1 ? "" : "s"}`;
17
+ function formatPrune(summary, deleteOld) {
18
+ if (!deleteOld) return "";
19
+ const first = summary.prunedFirst ? " (storage was full, so older releases were deleted first and the rest retried)" : "";
20
+ if (summary.pruned != null) return ` Deleted ${plural(summary.pruned, "old source map")} on the server${first}.`;
21
+ if (summary.pruneError) return ` Old source maps were not deleted: ${summary.pruneError}.`;
22
+ return " Old source maps were kept because an upload failed.";
23
+ }
24
+ function formatSummary(summary, { dryRun, release, files, deleteOld = false }) {
17
25
  const css = summary.skipped > 0 ? ` Skipped ${summary.skipped} CSS map${summary.skipped === 1 ? "" : "s"}.` : "";
18
26
  if (dryRun) {
19
27
  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}`;
28
+ const old = deleteOld ? " With --delete-old, the project's source maps of other releases (and this release's other files) would then be deleted." : "";
29
+ return `Dry run for release ${release}: ${files} source map${files === 1 ? "" : "s"} found${skipped}; nothing was uploaded.${css}${old}`;
21
30
  }
22
31
  const notSent = summary.notSent > 0 ? ` ${summary.notSent} not sent.` : "";
23
32
  const stopped = summary.stopped ? ` Stopped: ${summary.stopped}` : "";
24
33
  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;
34
+ const local = summary.deleted > 0 ? ` Deleted ${plural(summary.deleted, "local .map file")}.` : "";
35
+ return `${line}${local}${formatPrune(summary, deleteOld)}`;
26
36
  }
27
37
 
28
38
  // src/version.ts
29
- var VERSION = "0.5.2";
39
+ var VERSION = "0.6.0";
30
40
 
31
41
  // src/upload.ts
32
42
  import { open, readdir, readFile, stat, unlink } from "fs/promises";
@@ -223,6 +233,49 @@ async function uploadFile(context, file, name, body, chunkSize) {
223
233
  await context.sleep(delayMs);
224
234
  }
225
235
  }
236
+ async function pruneOld(context, keepNames) {
237
+ const url = `${context.apiUrl}/api/projects/${encodeURIComponent(context.project ?? "")}/releases/${encodeURIComponent(context.release)}/sourcemaps/prune`;
238
+ const body = JSON.stringify(keepNames ? { keepNames } : {});
239
+ for (let attempt = 0; ; attempt += 1) {
240
+ let reason;
241
+ let response = null;
242
+ try {
243
+ response = await context.fetch(url, {
244
+ method: "POST",
245
+ headers: {
246
+ authorization: `Bearer ${context.token}`,
247
+ "content-type": "application/json",
248
+ "user-agent": `bugwatch-cli/${VERSION}`
249
+ },
250
+ body
251
+ });
252
+ } catch (error) {
253
+ reason = error instanceof Error ? error.message : "network error";
254
+ }
255
+ if (response) {
256
+ if (response.ok) {
257
+ try {
258
+ const deleted = (await response.json()).data?.deleted;
259
+ return { deleted: typeof deleted === "number" ? deleted : 0 };
260
+ } catch {
261
+ return { deleted: 0 };
262
+ }
263
+ }
264
+ const { message } = await errorOf(response);
265
+ if (response.status === 404 && message !== "Project not found") {
266
+ return { error: "This Bugwatch server cannot delete old source maps yet (HTTP 404)" };
267
+ }
268
+ if (response.status !== 429 && response.status < 500) return { error: `${response.status} ${message}` };
269
+ reason = `${response.status} ${message}`;
270
+ }
271
+ if (attempt === MAX_RETRIES) return { error: reason };
272
+ const retry = attempt + 1;
273
+ const fromHeader = response?.status === 429 ? retryAfterMs(response.headers.get("retry-after")) : null;
274
+ const delayMs = Math.min(fromHeader ?? backoffMs(retry), MAX_RETRY_DELAY_MS);
275
+ context.onRetry?.({ file: "(delete old source maps)", attempt: retry, delayMs, reason });
276
+ await context.sleep(delayMs);
277
+ }
278
+ }
226
279
  async function mapLimit(items, limit, worker) {
227
280
  const results = new Array(items.length);
228
281
  let next = 0;
@@ -250,6 +303,9 @@ async function uploadSourceMaps(options) {
250
303
  }
251
304
  const projectError = projectProblem(options.project);
252
305
  if (projectError) throw new UsageError(projectError);
306
+ if (options.deleteOld && !options.dryRun && !isCiToken(options.token)) {
307
+ throw new UsageError("Deleting old source maps needs an org CI token (bwc_\u2026); upload tokens (bwu_\u2026) cannot delete");
308
+ }
253
309
  if (!options.dryRun && isCiToken(options.token) && !options.project) {
254
310
  throw new UsageError(
255
311
  "A CI token (bwc_\u2026) needs the project id: set BUGWATCH_PROJECT (from the project's Source maps page)"
@@ -277,7 +333,7 @@ async function uploadSourceMaps(options) {
277
333
  onRetry: options.onRetry
278
334
  };
279
335
  let stopped = null;
280
- const results = await mapLimit(uploads, CONCURRENCY, async ({ map: file, name, script }) => {
336
+ const send = async ({ map: file, name, script }) => {
281
337
  const path = join(dir, file);
282
338
  const { size } = await stat(path);
283
339
  let result;
@@ -298,7 +354,28 @@ async function uploadSourceMaps(options) {
298
354
  }
299
355
  options.onResult?.(result);
300
356
  return result;
301
- });
357
+ };
358
+ const results = await mapLimit(uploads, CONCURRENCY, send);
359
+ const deleteOld = options.deleteOld === true && !options.dryRun;
360
+ let pruneError = null;
361
+ let prunedFirst = false;
362
+ let pruned = 0;
363
+ const refusedForSpace = (result) => result.outcome === "not-sent" || result.code === "SOURCEMAP_PLAN_LIMIT";
364
+ if (deleteOld && results.some((r) => r.code === "SOURCEMAP_PLAN_LIMIT")) {
365
+ const first = await pruneOld(context);
366
+ if ("error" in first) {
367
+ pruneError = first.error;
368
+ } else {
369
+ prunedFirst = true;
370
+ pruned += first.deleted;
371
+ stopped = null;
372
+ const again = uploads.map((upload, index) => ({ upload, index })).filter(({ index }) => refusedForSpace(results[index]));
373
+ const retried = await mapLimit(again, CONCURRENCY, ({ upload }) => send(upload));
374
+ again.forEach(({ index }, i) => {
375
+ results[index] = retried[i];
376
+ });
377
+ }
378
+ }
302
379
  const count = (outcome) => results.filter((r) => r.outcome === outcome).length;
303
380
  const summary = {
304
381
  skipped: files.filter(isCssMap).length,
@@ -308,8 +385,17 @@ async function uploadSourceMaps(options) {
308
385
  failed: count("failed"),
309
386
  notSent: count("not-sent"),
310
387
  stopped,
311
- deleted: 0
388
+ deleted: 0,
389
+ ...options.deleteOld ? { pruned: null, pruneError, prunedFirst } : {}
312
390
  };
391
+ if (deleteOld && pruneError === null && summary.failed === 0 && summary.notSent === 0) {
392
+ const keepNames = [...new Set(uploads.map((upload) => upload.name))];
393
+ const done = await pruneOld(context, keepNames);
394
+ if ("error" in done) summary.pruneError = done.error;
395
+ else summary.pruned = pruned + done.deleted;
396
+ } else if (prunedFirst) {
397
+ summary.pruned = pruned;
398
+ }
313
399
  if (options.deleteAfterUpload && !options.dryRun && summary.failed === 0 && summary.notSent === 0) {
314
400
  await Promise.all(files.map((file) => unlink(join(dir, file))));
315
401
  summary.deleted = files.length;
@@ -2,7 +2,7 @@ import {
2
2
  DEFAULT_API_URL,
3
3
  UsageError,
4
4
  VERSION
5
- } from "./chunk-WHSSABPJ.js";
5
+ } from "./chunk-H6KZ37MK.js";
6
6
 
7
7
  // src/init.ts
8
8
  import { execFile, spawn } from "child_process";
@@ -11,7 +11,7 @@ import { readFile, writeFile } from "fs/promises";
11
11
  import { dirname, join, posix, relative, resolve, sep } from "path";
12
12
  var MARKER_FILE = ".bugwatch.json";
13
13
  var DEFAULT_INGEST_URL = `${DEFAULT_API_URL}/api/ingest`;
14
- var SDK_VERSION_RANGE = "^0.7.0";
14
+ var SDK_VERSION_RANGE = "^0.8.0";
15
15
  var FETCH_TIMEOUT_MS = 9e4;
16
16
  var SLOW_NOTICE_MS = 5e3;
17
17
  var SETUP_CODE = /^bws_[0-9a-f]{32}$/;
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  initProject
3
- } from "./chunk-NKQH22HJ.js";
3
+ } from "./chunk-HO2KESIB.js";
4
4
  import {
5
5
  DEFAULT_API_URL,
6
6
  DEFAULT_URL_PREFIX,
@@ -12,7 +12,7 @@ import {
12
12
  isCiToken,
13
13
  isDeprecatedUploadToken,
14
14
  uploadSourceMaps
15
- } from "./chunk-WHSSABPJ.js";
15
+ } from "./chunk-H6KZ37MK.js";
16
16
 
17
17
  // src/main.ts
18
18
  import { parseArgs } from "util";
@@ -47,6 +47,9 @@ Options:
47
47
  --project <id> Project id, required with a CI token (default: $BUGWATCH_PROJECT;
48
48
  shown on the project's Source maps page)
49
49
  --delete-after-upload Delete the local .map files after every upload succeeded
50
+ --delete-old After every upload succeeded, delete the project's older source
51
+ maps in Bugwatch (other releases, and this release's files not in
52
+ this upload). Needs a CI token
50
53
  --dry-run List what would be uploaded; uploads and deletes nothing
51
54
  -h, --help Show this help
52
55
  -v, --version Show the version
@@ -69,6 +72,7 @@ async function main(argv, env = process.env, out = (line) => process.stdout.writ
69
72
  token: { type: "string" },
70
73
  project: { type: "string" },
71
74
  "delete-after-upload": { type: "boolean" },
75
+ "delete-old": { type: "boolean" },
72
76
  "dry-run": { type: "boolean" },
73
77
  setup: { type: "string" },
74
78
  entry: { type: "string" },
@@ -140,6 +144,11 @@ ${USAGE}`);
140
144
  err("Error: A CI token (bwc_\u2026) needs the project id: set BUGWATCH_PROJECT (or pass --project)");
141
145
  return 2;
142
146
  }
147
+ const deleteOld = values["delete-old"] === true;
148
+ if (!dryRun && deleteOld && !isCiToken(token)) {
149
+ err("Error: --delete-old needs an org CI token (bwc_\u2026); upload tokens (bwu_\u2026) cannot delete source maps");
150
+ return 2;
151
+ }
143
152
  if (!dryRun && isDeprecatedUploadToken(token)) err(`Note: ${UPLOAD_TOKEN_DEPRECATED}`);
144
153
  try {
145
154
  const { results, summary } = await uploadSourceMaps({
@@ -150,12 +159,14 @@ ${USAGE}`);
150
159
  urlPrefix: values["url-prefix"] ?? DEFAULT_URL_PREFIX,
151
160
  apiUrl,
152
161
  deleteAfterUpload: values["delete-after-upload"] === true,
162
+ deleteOld,
153
163
  dryRun,
154
164
  onResult: (result) => (result.outcome === "failed" ? err : out)(formatResult(result)),
155
165
  onRetry: ({ file, attempt, delayMs, reason }) => err(`retry ${file} (attempt ${attempt + 1}, in ${Math.round(delayMs / 100) / 10} s): ${reason}`)
156
166
  });
157
167
  out("");
158
- out(formatSummary(summary, { dryRun, release: values.release, files: results.length }));
168
+ out(formatSummary(summary, { dryRun, release: values.release, files: results.length, deleteOld }));
169
+ if (summary.pruneError) err(`Warning: old source maps were not deleted: ${summary.pruneError}`);
159
170
  if ((summary.failed > 0 || summary.notSent > 0) && values["delete-after-upload"]) {
160
171
  out("Kept the local .map files because an upload failed.");
161
172
  }
package/dist/cli.js CHANGED
@@ -1,9 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  main
4
- } from "./chunk-4ADC7XIS.js";
5
- import "./chunk-NKQH22HJ.js";
6
- import "./chunk-WHSSABPJ.js";
4
+ } from "./chunk-VFCYFSZI.js";
5
+ import "./chunk-HO2KESIB.js";
6
+ import "./chunk-H6KZ37MK.js";
7
7
 
8
8
  // src/cli.ts
9
9
  main(process.argv.slice(2)).then((code) => {
package/dist/index.d.ts CHANGED
@@ -50,6 +50,17 @@ interface UploadSummary {
50
50
  stopped: string | null;
51
51
  /** Local `.map` files deleted after a fully successful upload. */
52
52
  deleted: number;
53
+ /**
54
+ * `--delete-old`: the project's older maps deleted on the server (other
55
+ * releases, and this release's names not sent in this run), or null when
56
+ * nothing was pruned (dry run, an upload failed, or the prune failed).
57
+ * Only present with `deleteOld`, like the two fields below.
58
+ */
59
+ pruned?: number | null;
60
+ /** `--delete-old`: why deleting the older maps failed (the uploads still count), or null. */
61
+ pruneError?: string | null;
62
+ /** `--delete-old`: the plan's storage was full, so older releases were deleted first and the rest retried. */
63
+ prunedFirst?: boolean;
53
64
  }
54
65
  interface UploadReport {
55
66
  results: FileResult[];
@@ -69,6 +80,13 @@ interface UploadOptions {
69
80
  apiUrl?: string;
70
81
  /** Delete the local `.map` files, only when every upload succeeded. */
71
82
  deleteAfterUpload?: boolean;
83
+ /**
84
+ * After every upload succeeded, delete the project's other source maps on
85
+ * the server: every other release's, and this release's names not uploaded
86
+ * in this run. If the plan's storage is full, older releases are deleted
87
+ * first and the rest retried. Needs a CI token (`bwc_…`).
88
+ */
89
+ deleteOld?: boolean;
72
90
  /** List what would be uploaded; no network, nothing deleted. */
73
91
  dryRun?: boolean;
74
92
  /** Called once per file as it finishes. */
@@ -133,10 +151,11 @@ declare function uploadSourceMaps(options: UploadOptions): Promise<UploadReport>
133
151
  declare function formatBytes(bytes: number): string;
134
152
  /** `uploaded ~/assets/index.js (assets/index.js.map, 1.8 MB)`, or the reason it failed. */
135
153
  declare function formatResult(result: FileResult): string;
136
- declare function formatSummary(summary: UploadSummary, { dryRun, release, files }: {
154
+ declare function formatSummary(summary: UploadSummary, { dryRun, release, files, deleteOld }: {
137
155
  dryRun: boolean;
138
156
  release: string;
139
157
  files: number;
158
+ deleteOld?: boolean;
140
159
  }): string;
141
160
 
142
161
  /**
@@ -219,6 +238,6 @@ declare function addImport(text: string, spec: string): string | null;
219
238
  declare function initProject(options: InitOptions): Promise<InitReport>;
220
239
 
221
240
  /** Keep in sync with package.json (a test checks it). */
222
- declare const VERSION = "0.5.2";
241
+ declare const VERSION = "0.6.0";
223
242
 
224
243
  export { CONCURRENCY, type CliSetup, DEFAULT_API_URL, DEFAULT_INGEST_URL, DEFAULT_URL_PREFIX, type FileResult, type Framework, type InitOptions, type InitReport, MARKER_FILE, MAX_MAP_BYTES, MAX_RETRIES, type Outcome, type PackageManager, type PlannedUpload, STOP_CODES, UPLOAD_TOKEN_DEPRECATED, type UploadOptions, type UploadReport, type UploadSummary, UsageError, VERSION, addImport, detectFramework, detectPackageManager, findMapOwners, findSourceMaps, formatBytes, formatResult, formatSummary, importSpecifier, initProject, installCommand, isCiToken, isCssMap, isDeprecatedUploadToken, mapName, planUploads, projectProblem, releaseProblem, remoteRepo, replaceApiKey, sdkTooOld, sendableMapFile, setupCodeProblem, sourceMappingUrlOf, uploadSourceMaps, urlPrefixProblem };
package/dist/index.js CHANGED
@@ -11,7 +11,7 @@ import {
11
11
  replaceApiKey,
12
12
  sdkTooOld,
13
13
  setupCodeProblem
14
- } from "./chunk-NKQH22HJ.js";
14
+ } from "./chunk-HO2KESIB.js";
15
15
  import {
16
16
  CONCURRENCY,
17
17
  DEFAULT_API_URL,
@@ -38,7 +38,7 @@ import {
38
38
  sourceMappingUrlOf,
39
39
  uploadSourceMaps,
40
40
  urlPrefixProblem
41
- } from "./chunk-WHSSABPJ.js";
41
+ } from "./chunk-H6KZ37MK.js";
42
42
  export {
43
43
  CONCURRENCY,
44
44
  DEFAULT_API_URL,
package/dist/main.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  main
3
- } from "./chunk-4ADC7XIS.js";
4
- import "./chunk-NKQH22HJ.js";
5
- import "./chunk-WHSSABPJ.js";
3
+ } from "./chunk-VFCYFSZI.js";
4
+ import "./chunk-HO2KESIB.js";
5
+ import "./chunk-H6KZ37MK.js";
6
6
  export {
7
7
  main
8
8
  };
package/dist/vite.d.ts CHANGED
@@ -15,6 +15,12 @@ interface BugwatchSourcemapsOptions {
15
15
  apiUrl?: string;
16
16
  /** Delete the `.map` files from the build output after uploading. Default `true`. */
17
17
  deleteAfterUpload?: boolean;
18
+ /**
19
+ * After every upload succeeded, delete the project's older source maps in
20
+ * Bugwatch (other releases, and this release's files not in this build).
21
+ * Needs a CI token. Default `false`.
22
+ */
23
+ deleteOld?: boolean;
18
24
  /** Fail `vite build` when an upload fails. Default `false` (log and continue). */
19
25
  failOnError?: boolean;
20
26
  }
package/dist/vite.js CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  isCiToken,
8
8
  isDeprecatedUploadToken,
9
9
  uploadSourceMaps
10
- } from "./chunk-WHSSABPJ.js";
10
+ } from "./chunk-H6KZ37MK.js";
11
11
 
12
12
  // src/vite.ts
13
13
  import { resolve } from "path";
@@ -53,6 +53,11 @@ function bugwatchSourcemaps(options) {
53
53
  fail("Source maps not uploaded: a CI token needs the project id. Set BUGWATCH_PROJECT or the project option");
54
54
  return;
55
55
  }
56
+ const deleteOld = options.deleteOld === true;
57
+ if (deleteOld && !isCiToken(token)) {
58
+ fail("Source maps not uploaded: deleteOld needs an org CI token (bwc_\u2026). Set BUGWATCH_UPLOAD_TOKEN to one");
59
+ return;
60
+ }
56
61
  if (isDeprecatedUploadToken(token)) logger.warn(`${PREFIX} ${UPLOAD_TOKEN_DEPRECATED}`);
57
62
  try {
58
63
  const { results, summary } = await uploadSourceMaps({
@@ -63,10 +68,12 @@ function bugwatchSourcemaps(options) {
63
68
  urlPrefix: options.urlPrefix ?? DEFAULT_URL_PREFIX,
64
69
  apiUrl: options.apiUrl || process.env.BUGWATCH_API_URL || void 0,
65
70
  deleteAfterUpload: options.deleteAfterUpload ?? true,
71
+ deleteOld,
66
72
  onResult: (result) => (result.outcome === "failed" ? logger.error : logger.info)(`${PREFIX} ${formatResult(result)}`),
67
73
  onRetry: ({ file, attempt, reason }) => logger.warn(`${PREFIX} retry ${file} (attempt ${attempt + 1}): ${reason}`)
68
74
  });
69
- logger.info(`${PREFIX} ${formatSummary(summary, { dryRun: false, release, files: results.length })}`);
75
+ logger.info(`${PREFIX} ${formatSummary(summary, { dryRun: false, release, files: results.length, deleteOld })}`);
76
+ if (summary.pruneError) logger.warn(`${PREFIX} Old source maps were not deleted: ${summary.pruneError}`);
70
77
  if (summary.failed > 0 || summary.notSent > 0) {
71
78
  const count = summary.failed + summary.notSent;
72
79
  fail(`${count} source map upload${count === 1 ? "" : "s"} failed or not sent; the .map files were kept`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bugwatch-cli",
3
- "version": "0.5.2",
3
+ "version": "0.6.0",
4
4
  "description": "Set up Bugwatch in your app and upload source maps from CI (CLI and Vite plugin)",
5
5
  "type": "module",
6
6
  "bin": {