bugwatch-cli 0.1.0 → 0.1.2
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 +18 -2
- package/dist/{chunk-J4RLBS7A.js → chunk-3TESXBNC.js} +67 -9
- package/dist/{chunk-QGLOKEF7.js → chunk-C7AULTCO.js} +3 -2
- package/dist/{chunk-FITJFXB5.js → chunk-RRAHAYFL.js} +14 -5
- package/dist/cli.js +3 -3
- package/dist/index.d.ts +28 -3
- package/dist/index.js +9 -1
- package/dist/main.js +3 -3
- package/dist/vite.d.ts +6 -2
- package/dist/vite.js +17 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -46,7 +46,8 @@ export default defineConfig({
|
|
|
46
46
|
build: { sourcemap: "hidden" },
|
|
47
47
|
plugins: [
|
|
48
48
|
bugwatchSourcemaps({
|
|
49
|
-
|
|
49
|
+
// e.g. the git SHA or package version, set by CI; without it, nothing is uploaded
|
|
50
|
+
release: process.env.RELEASE ?? "",
|
|
50
51
|
}),
|
|
51
52
|
],
|
|
52
53
|
});
|
|
@@ -108,13 +109,28 @@ fix. The token is never printed.
|
|
|
108
109
|
## File names
|
|
109
110
|
|
|
110
111
|
Each map is uploaded for the URL of the minified file it belongs to:
|
|
111
|
-
the URL prefix +
|
|
112
|
+
the URL prefix + that file's path inside `<dir>`.
|
|
113
|
+
|
|
114
|
+
- **The script's `sourceMappingURL` comment decides.** A JavaScript file
|
|
115
|
+
ending in `//# sourceMappingURL=559f….js.map` owns that map, so the map
|
|
116
|
+
is uploaded under the script's name, even when the names differ (Next.js
|
|
117
|
+
with Turbopack: `b55a….js` → `559f….js.map`). A map shared by several
|
|
118
|
+
scripts is uploaded once per script.
|
|
119
|
+
- **No comment** (e.g. Vite's `sourcemap: "hidden"`): the map's own path
|
|
120
|
+
without `.map` is used (`index-3f9a.js.map` → `index-3f9a.js`).
|
|
121
|
+
- **CSS maps** (`*.css.map`) are skipped: errors only come from scripts.
|
|
122
|
+
With `--delete-after-upload` they are deleted with the rest.
|
|
112
123
|
|
|
113
124
|
| Map in the build | `--url-prefix` | Uploaded for |
|
|
114
125
|
| ------------------------- | ------------------------------ | --- |
|
|
115
126
|
| `dist/assets/index-3f9a.js.map` | `~/` (default) | `~/assets/index-3f9a.js` |
|
|
116
127
|
| `dist/assets/index-3f9a.js.map` | `https://cdn.shop.com/static/` | `https://cdn.shop.com/static/assets/index-3f9a.js` |
|
|
117
128
|
|
|
129
|
+
For Next.js, upload `.next/static` with `--url-prefix "~/_next/static/"`
|
|
130
|
+
(files in `.next/static/chunks/` are served at `/_next/static/chunks/`), and
|
|
131
|
+
set `productionBrowserSourceMaps: true`. Next.js has no hidden mode, so always
|
|
132
|
+
use `--delete-after-upload` to keep the maps off your site.
|
|
133
|
+
|
|
118
134
|
`~/` matches the path on any host, so it works for every domain and
|
|
119
135
|
preview deployment. Use a full URL prefix when the files are served
|
|
120
136
|
from a different path (e.g. a CDN folder) than their place in the
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// src/version.ts
|
|
2
|
-
var VERSION = "0.1.
|
|
2
|
+
var VERSION = "0.1.2";
|
|
3
3
|
|
|
4
4
|
// src/upload.ts
|
|
5
|
-
import { readdir, readFile, stat, unlink } from "fs/promises";
|
|
6
|
-
import { join, relative, resolve, sep } from "path";
|
|
5
|
+
import { open, readdir, readFile, stat, unlink } from "fs/promises";
|
|
6
|
+
import { join, posix, relative, resolve, sep } from "path";
|
|
7
7
|
var DEFAULT_API_URL = "https://sentry-like.vercel.app";
|
|
8
8
|
var DEFAULT_URL_PREFIX = "~/";
|
|
9
9
|
var CONCURRENCY = 4;
|
|
@@ -18,7 +18,7 @@ var UsageError = class extends Error {
|
|
|
18
18
|
}
|
|
19
19
|
};
|
|
20
20
|
function releaseProblem(release) {
|
|
21
|
-
if (!release) return "A release is required
|
|
21
|
+
if (!release) return "A release is required";
|
|
22
22
|
if (release.length > 200) return "The release must be at most 200 characters";
|
|
23
23
|
if (/[\s\u0000-\u001f\u007f]/.test(release)) return "The release must not contain spaces or control characters";
|
|
24
24
|
if (release === "." || release === "..") return 'The release must not be "." or ".."';
|
|
@@ -34,7 +34,7 @@ function mapName(relativePath, urlPrefix = DEFAULT_URL_PREFIX) {
|
|
|
34
34
|
const path = relativePath.split(sep).join("/").replace(/^\.?\//, "");
|
|
35
35
|
return urlPrefix + path.replace(/\.map$/, "");
|
|
36
36
|
}
|
|
37
|
-
async function
|
|
37
|
+
async function findFiles(dir, test) {
|
|
38
38
|
const root = resolve(dir);
|
|
39
39
|
const found = [];
|
|
40
40
|
async function walk(folder) {
|
|
@@ -43,12 +43,64 @@ async function findSourceMaps(dir) {
|
|
|
43
43
|
if (entry.name === "node_modules") continue;
|
|
44
44
|
const path = join(folder, entry.name);
|
|
45
45
|
if (entry.isDirectory()) await walk(path);
|
|
46
|
-
else if (entry.isFile() && entry.name
|
|
46
|
+
else if (entry.isFile() && test(entry.name)) found.push(relative(root, path).split(sep).join("/"));
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
await walk(root);
|
|
50
50
|
return found.sort();
|
|
51
51
|
}
|
|
52
|
+
function findSourceMaps(dir) {
|
|
53
|
+
return findFiles(dir, (name) => name.endsWith(".map"));
|
|
54
|
+
}
|
|
55
|
+
var COMMENT_TAIL_BYTES = 4096;
|
|
56
|
+
function sourceMappingUrlOf(scriptTail) {
|
|
57
|
+
const matches = [...scriptTail.matchAll(/\/\/[#@][ \t]*sourceMappingURL=([^\s'"]+)[ \t]*/g)];
|
|
58
|
+
const last = matches.at(-1);
|
|
59
|
+
if (!last || scriptTail.slice((last.index ?? 0) + last[0].length).trim() !== "") return null;
|
|
60
|
+
return last[1] ?? null;
|
|
61
|
+
}
|
|
62
|
+
async function readTail(path) {
|
|
63
|
+
const file = await open(path, "r");
|
|
64
|
+
try {
|
|
65
|
+
const { size } = await file.stat();
|
|
66
|
+
const length = Math.min(size, COMMENT_TAIL_BYTES);
|
|
67
|
+
const buffer = Buffer.alloc(length);
|
|
68
|
+
await file.read(buffer, 0, length, size - length);
|
|
69
|
+
return buffer.toString("utf8");
|
|
70
|
+
} finally {
|
|
71
|
+
await file.close();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
async function findMapOwners(dir, maps) {
|
|
75
|
+
const root = resolve(dir);
|
|
76
|
+
const known = new Set(maps);
|
|
77
|
+
const owners = /* @__PURE__ */ new Map();
|
|
78
|
+
const scripts = await findFiles(root, (name) => /\.(m|c)?js$/.test(name));
|
|
79
|
+
for (const script of scripts) {
|
|
80
|
+
const url = sourceMappingUrlOf(await readTail(join(root, script)));
|
|
81
|
+
if (!url || /^[a-z][a-z0-9+.-]*:/i.test(url) || url.startsWith("/")) continue;
|
|
82
|
+
let decoded;
|
|
83
|
+
try {
|
|
84
|
+
decoded = decodeURIComponent(url.replace(/[?#].*$/, ""));
|
|
85
|
+
} catch {
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
const map = posix.normalize(posix.join(posix.dirname(script), decoded));
|
|
89
|
+
if (map.startsWith("../") || !known.has(map)) continue;
|
|
90
|
+
owners.set(map, [...owners.get(map) ?? [], script]);
|
|
91
|
+
}
|
|
92
|
+
return owners;
|
|
93
|
+
}
|
|
94
|
+
function isCssMap(map) {
|
|
95
|
+
return /\.css\.map$/i.test(map);
|
|
96
|
+
}
|
|
97
|
+
async function planUploads(dir, maps, urlPrefix = DEFAULT_URL_PREFIX) {
|
|
98
|
+
const owners = await findMapOwners(dir, maps);
|
|
99
|
+
return maps.filter((map) => !isCssMap(map)).flatMap((map) => {
|
|
100
|
+
const scripts = owners.get(map);
|
|
101
|
+
return scripts ? scripts.map((script) => ({ map, name: urlPrefix + script })) : [{ map, name: mapName(map, urlPrefix) }];
|
|
102
|
+
});
|
|
103
|
+
}
|
|
52
104
|
function retryAfterMs(header, now = Date.now()) {
|
|
53
105
|
if (!header) return null;
|
|
54
106
|
const seconds = Number(header);
|
|
@@ -135,7 +187,7 @@ async function uploadSourceMaps(options) {
|
|
|
135
187
|
if (prefixError) throw new UsageError(prefixError);
|
|
136
188
|
if (!/^https?:\/\//.test(apiUrl)) throw new UsageError("The API URL must start with http:// or https://");
|
|
137
189
|
if (!options.dryRun && !options.token) {
|
|
138
|
-
throw new UsageError("An upload token is required: set BUGWATCH_UPLOAD_TOKEN
|
|
190
|
+
throw new UsageError("An upload token is required: set BUGWATCH_UPLOAD_TOKEN");
|
|
139
191
|
}
|
|
140
192
|
const dir = resolve(options.dir);
|
|
141
193
|
try {
|
|
@@ -146,6 +198,8 @@ async function uploadSourceMaps(options) {
|
|
|
146
198
|
}
|
|
147
199
|
const files = await findSourceMaps(dir);
|
|
148
200
|
if (files.length === 0) throw new UsageError(`No .map files found in ${options.dir}`);
|
|
201
|
+
const uploads = await planUploads(dir, files, urlPrefix);
|
|
202
|
+
if (uploads.length === 0) throw new UsageError(`No JavaScript source maps found in ${options.dir} (only CSS maps)`);
|
|
149
203
|
const context = {
|
|
150
204
|
apiUrl,
|
|
151
205
|
release: options.release,
|
|
@@ -154,8 +208,7 @@ async function uploadSourceMaps(options) {
|
|
|
154
208
|
sleep: options.sleep ?? defaultSleep,
|
|
155
209
|
onRetry: options.onRetry
|
|
156
210
|
};
|
|
157
|
-
const results = await mapLimit(
|
|
158
|
-
const name = mapName(file, urlPrefix);
|
|
211
|
+
const results = await mapLimit(uploads, CONCURRENCY, async ({ map: file, name }) => {
|
|
159
212
|
const path = join(dir, file);
|
|
160
213
|
const { size } = await stat(path);
|
|
161
214
|
let result;
|
|
@@ -175,6 +228,7 @@ async function uploadSourceMaps(options) {
|
|
|
175
228
|
});
|
|
176
229
|
const count = (outcome) => results.filter((r) => r.outcome === outcome).length;
|
|
177
230
|
const summary = {
|
|
231
|
+
skipped: files.filter(isCssMap).length,
|
|
178
232
|
uploaded: count("uploaded"),
|
|
179
233
|
replaced: count("replaced"),
|
|
180
234
|
unchanged: count("unchanged"),
|
|
@@ -200,5 +254,9 @@ export {
|
|
|
200
254
|
urlPrefixProblem,
|
|
201
255
|
mapName,
|
|
202
256
|
findSourceMaps,
|
|
257
|
+
sourceMappingUrlOf,
|
|
258
|
+
findMapOwners,
|
|
259
|
+
isCssMap,
|
|
260
|
+
planUploads,
|
|
203
261
|
uploadSourceMaps
|
|
204
262
|
};
|
|
@@ -14,11 +14,12 @@ function formatResult(result) {
|
|
|
14
14
|
return `${label} ${result.name} (${detail})`;
|
|
15
15
|
}
|
|
16
16
|
function formatSummary(summary, { dryRun, release, files }) {
|
|
17
|
+
const css = summary.skipped > 0 ? ` Skipped ${summary.skipped} CSS map${summary.skipped === 1 ? "" : "s"}.` : "";
|
|
17
18
|
if (dryRun) {
|
|
18
19
|
const skipped = summary.failed > 0 ? ` (${summary.failed} would fail)` : "";
|
|
19
|
-
return `Dry run for release ${release}: ${files} source map${files === 1 ? "" : "s"} found${skipped}; nothing was uploaded
|
|
20
|
+
return `Dry run for release ${release}: ${files} source map${files === 1 ? "" : "s"} found${skipped}; nothing was uploaded.${css}`;
|
|
20
21
|
}
|
|
21
|
-
const line = `Release ${release}: ${summary.uploaded} uploaded, ${summary.replaced} replaced, ${summary.unchanged} unchanged, ${summary.failed} failed
|
|
22
|
+
const line = `Release ${release}: ${summary.uploaded} uploaded, ${summary.replaced} replaced, ${summary.unchanged} unchanged, ${summary.failed} failed.${css}`;
|
|
22
23
|
return summary.deleted > 0 ? `${line} Deleted ${summary.deleted} local .map file${summary.deleted === 1 ? "" : "s"}.` : line;
|
|
23
24
|
}
|
|
24
25
|
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
2
|
formatResult,
|
|
3
3
|
formatSummary
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-C7AULTCO.js";
|
|
5
5
|
import {
|
|
6
6
|
DEFAULT_API_URL,
|
|
7
7
|
DEFAULT_URL_PREFIX,
|
|
8
8
|
UsageError,
|
|
9
9
|
VERSION,
|
|
10
10
|
uploadSourceMaps
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-3TESXBNC.js";
|
|
12
12
|
|
|
13
13
|
// src/main.ts
|
|
14
14
|
import { parseArgs } from "util";
|
|
@@ -69,11 +69,20 @@ ${USAGE}`);
|
|
|
69
69
|
}
|
|
70
70
|
const dryRun = values["dry-run"] === true;
|
|
71
71
|
const apiUrl = values["api-url"] || env.BUGWATCH_API_URL || DEFAULT_API_URL;
|
|
72
|
+
const token = values.token || env.BUGWATCH_UPLOAD_TOKEN || void 0;
|
|
73
|
+
if (!values.release) {
|
|
74
|
+
err("Error: A release is required (--release)");
|
|
75
|
+
return 2;
|
|
76
|
+
}
|
|
77
|
+
if (!dryRun && !token) {
|
|
78
|
+
err("Error: An upload token is required: set BUGWATCH_UPLOAD_TOKEN (or pass --token)");
|
|
79
|
+
return 2;
|
|
80
|
+
}
|
|
72
81
|
try {
|
|
73
82
|
const { results, summary } = await uploadSourceMaps({
|
|
74
83
|
dir,
|
|
75
|
-
release: values.release
|
|
76
|
-
token
|
|
84
|
+
release: values.release,
|
|
85
|
+
token,
|
|
77
86
|
urlPrefix: values["url-prefix"] ?? DEFAULT_URL_PREFIX,
|
|
78
87
|
apiUrl,
|
|
79
88
|
deleteAfterUpload: values["delete-after-upload"] === true,
|
|
@@ -82,7 +91,7 @@ ${USAGE}`);
|
|
|
82
91
|
onRetry: ({ file, attempt, delayMs, reason }) => err(`retry ${file} (attempt ${attempt + 1}, in ${Math.round(delayMs / 100) / 10} s): ${reason}`)
|
|
83
92
|
});
|
|
84
93
|
out("");
|
|
85
|
-
out(formatSummary(summary, { dryRun, release: values.release
|
|
94
|
+
out(formatSummary(summary, { dryRun, release: values.release, files: results.length }));
|
|
86
95
|
if (summary.failed > 0 && values["delete-after-upload"]) {
|
|
87
96
|
out("Kept the local .map files because an upload failed.");
|
|
88
97
|
}
|
package/dist/cli.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
main
|
|
4
|
-
} from "./chunk-
|
|
5
|
-
import "./chunk-
|
|
6
|
-
import "./chunk-
|
|
4
|
+
} from "./chunk-RRAHAYFL.js";
|
|
5
|
+
import "./chunk-C7AULTCO.js";
|
|
6
|
+
import "./chunk-3TESXBNC.js";
|
|
7
7
|
|
|
8
8
|
// src/cli.ts
|
|
9
9
|
main(process.argv.slice(2)).then((code) => {
|
package/dist/index.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ declare const MAX_RETRIES = 3;
|
|
|
8
8
|
declare const MAX_MAP_BYTES: number;
|
|
9
9
|
type Outcome = "uploaded" | "replaced" | "unchanged" | "failed" | "dry-run";
|
|
10
10
|
interface FileResult {
|
|
11
|
-
/** The map's path relative to `dir`, with `/` separators. */
|
|
11
|
+
/** The map's path relative to `dir`, with `/` separators (one map can be uploaded under several names). */
|
|
12
12
|
file: string;
|
|
13
13
|
/** The minified file's URL the map is uploaded for. */
|
|
14
14
|
name: string;
|
|
@@ -20,6 +20,8 @@ interface FileResult {
|
|
|
20
20
|
error?: string;
|
|
21
21
|
}
|
|
22
22
|
interface UploadSummary {
|
|
23
|
+
/** CSS maps found and not uploaded (errors only come from scripts). */
|
|
24
|
+
skipped: number;
|
|
23
25
|
uploaded: number;
|
|
24
26
|
replaced: number;
|
|
25
27
|
unchanged: number;
|
|
@@ -70,6 +72,29 @@ declare function urlPrefixProblem(prefix: string): string | null;
|
|
|
70
72
|
declare function mapName(relativePath: string, urlPrefix?: string): string;
|
|
71
73
|
/** Every `*.map` file under `dir`, relative paths with `/`, sorted. Skips `node_modules`. */
|
|
72
74
|
declare function findSourceMaps(dir: string): Promise<string[]>;
|
|
75
|
+
/** The `//# sourceMappingURL=` (or legacy `//@`) value at the end of a script, or null. */
|
|
76
|
+
declare function sourceMappingUrlOf(scriptTail: string): string | null;
|
|
77
|
+
/**
|
|
78
|
+
* Which script each map belongs to, from the scripts' `sourceMappingURL`
|
|
79
|
+
* comments: map path → script paths (relative to `dir`). Needed because some
|
|
80
|
+
* bundlers (e.g. Next.js with Turbopack) name a chunk's map differently from
|
|
81
|
+
* the chunk (`b55a.js` → `559f.js.map`). `data:` URLs, absolute URLs, and
|
|
82
|
+
* maps outside `dir` are ignored.
|
|
83
|
+
*/
|
|
84
|
+
declare function findMapOwners(dir: string, maps: string[]): Promise<Map<string, string[]>>;
|
|
85
|
+
/** CSS maps are never needed for errors (and Turbopack writes them as index maps, which are rejected). */
|
|
86
|
+
declare function isCssMap(map: string): boolean;
|
|
87
|
+
/** One upload: a map file and the name (minified file URL) it is uploaded for. */
|
|
88
|
+
interface PlannedUpload {
|
|
89
|
+
map: string;
|
|
90
|
+
name: string;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* The uploads for `maps`: a map referenced by scripts is uploaded once per
|
|
94
|
+
* script, named after the script; a map no script points to (e.g. Vite's
|
|
95
|
+
* `sourcemap: "hidden"`) is named after itself without `.map`.
|
|
96
|
+
*/
|
|
97
|
+
declare function planUploads(dir: string, maps: string[], urlPrefix?: string): Promise<PlannedUpload[]>;
|
|
73
98
|
/**
|
|
74
99
|
* Uploads every source map under `dir` for `release` (4 at a time, with
|
|
75
100
|
* retries). Throws `UsageError` for problems with the options; upload
|
|
@@ -78,6 +103,6 @@ declare function findSourceMaps(dir: string): Promise<string[]>;
|
|
|
78
103
|
declare function uploadSourceMaps(options: UploadOptions): Promise<UploadReport>;
|
|
79
104
|
|
|
80
105
|
/** Keep in sync with package.json (a test checks it). */
|
|
81
|
-
declare const VERSION = "0.1.
|
|
106
|
+
declare const VERSION = "0.1.2";
|
|
82
107
|
|
|
83
|
-
export { CONCURRENCY, DEFAULT_API_URL, DEFAULT_URL_PREFIX, type FileResult, MAX_MAP_BYTES, MAX_RETRIES, type Outcome, type UploadOptions, type UploadReport, type UploadSummary, UsageError, VERSION, findSourceMaps, mapName, releaseProblem, uploadSourceMaps, urlPrefixProblem };
|
|
108
|
+
export { CONCURRENCY, DEFAULT_API_URL, DEFAULT_URL_PREFIX, type FileResult, MAX_MAP_BYTES, MAX_RETRIES, type Outcome, type PlannedUpload, type UploadOptions, type UploadReport, type UploadSummary, UsageError, VERSION, findMapOwners, findSourceMaps, isCssMap, mapName, planUploads, releaseProblem, sourceMappingUrlOf, uploadSourceMaps, urlPrefixProblem };
|
package/dist/index.js
CHANGED
|
@@ -6,12 +6,16 @@ import {
|
|
|
6
6
|
MAX_RETRIES,
|
|
7
7
|
UsageError,
|
|
8
8
|
VERSION,
|
|
9
|
+
findMapOwners,
|
|
9
10
|
findSourceMaps,
|
|
11
|
+
isCssMap,
|
|
10
12
|
mapName,
|
|
13
|
+
planUploads,
|
|
11
14
|
releaseProblem,
|
|
15
|
+
sourceMappingUrlOf,
|
|
12
16
|
uploadSourceMaps,
|
|
13
17
|
urlPrefixProblem
|
|
14
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-3TESXBNC.js";
|
|
15
19
|
export {
|
|
16
20
|
CONCURRENCY,
|
|
17
21
|
DEFAULT_API_URL,
|
|
@@ -20,9 +24,13 @@ export {
|
|
|
20
24
|
MAX_RETRIES,
|
|
21
25
|
UsageError,
|
|
22
26
|
VERSION,
|
|
27
|
+
findMapOwners,
|
|
23
28
|
findSourceMaps,
|
|
29
|
+
isCssMap,
|
|
24
30
|
mapName,
|
|
31
|
+
planUploads,
|
|
25
32
|
releaseProblem,
|
|
33
|
+
sourceMappingUrlOf,
|
|
26
34
|
uploadSourceMaps,
|
|
27
35
|
urlPrefixProblem
|
|
28
36
|
};
|
package/dist/main.js
CHANGED
package/dist/vite.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
interface BugwatchSourcemapsOptions {
|
|
2
|
-
/**
|
|
3
|
-
|
|
2
|
+
/**
|
|
3
|
+
* The release the SDK sends (`Bugwatch.init({ release })`). Required, but
|
|
4
|
+
* may be `undefined` so `release: process.env.RELEASE` type-checks: then
|
|
5
|
+
* nothing is uploaded and the build logs why (or fails with `failOnError`).
|
|
6
|
+
*/
|
|
7
|
+
release: string | undefined;
|
|
4
8
|
/** Upload token. Default: the `BUGWATCH_UPLOAD_TOKEN` environment variable. */
|
|
5
9
|
token?: string;
|
|
6
10
|
/** Default `~/` (any host). */
|
package/dist/vite.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
formatResult,
|
|
3
3
|
formatSummary
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-C7AULTCO.js";
|
|
5
5
|
import {
|
|
6
6
|
DEFAULT_URL_PREFIX,
|
|
7
7
|
UsageError,
|
|
8
8
|
uploadSourceMaps
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-3TESXBNC.js";
|
|
10
10
|
|
|
11
11
|
// src/vite.ts
|
|
12
12
|
import { resolve } from "path";
|
|
@@ -35,18 +35,30 @@ function bugwatchSourcemaps(options) {
|
|
|
35
35
|
if (failOnError) throw new Error(`${PREFIX} ${message}`);
|
|
36
36
|
logger.error(`${PREFIX} ${message}`);
|
|
37
37
|
};
|
|
38
|
+
const release = options.release;
|
|
39
|
+
const token = options.token || process.env.BUGWATCH_UPLOAD_TOKEN || void 0;
|
|
40
|
+
if (!release) {
|
|
41
|
+
fail(
|
|
42
|
+
"Source maps not uploaded: no release. Pass release to bugwatchSourcemaps() (e.g. release: process.env.RELEASE) and set it in CI"
|
|
43
|
+
);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
if (!token) {
|
|
47
|
+
fail("Source maps not uploaded: no upload token. Set BUGWATCH_UPLOAD_TOKEN or the token option");
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
38
50
|
try {
|
|
39
51
|
const { results, summary } = await uploadSourceMaps({
|
|
40
52
|
dir: resolve(config.root, build.outDir),
|
|
41
|
-
release
|
|
42
|
-
token
|
|
53
|
+
release,
|
|
54
|
+
token,
|
|
43
55
|
urlPrefix: options.urlPrefix ?? DEFAULT_URL_PREFIX,
|
|
44
56
|
apiUrl: options.apiUrl || process.env.BUGWATCH_API_URL || void 0,
|
|
45
57
|
deleteAfterUpload: options.deleteAfterUpload ?? true,
|
|
46
58
|
onResult: (result) => (result.outcome === "failed" ? logger.error : logger.info)(`${PREFIX} ${formatResult(result)}`),
|
|
47
59
|
onRetry: ({ file, attempt, reason }) => logger.warn(`${PREFIX} retry ${file} (attempt ${attempt + 1}): ${reason}`)
|
|
48
60
|
});
|
|
49
|
-
logger.info(`${PREFIX} ${formatSummary(summary, { dryRun: false, release
|
|
61
|
+
logger.info(`${PREFIX} ${formatSummary(summary, { dryRun: false, release, files: results.length })}`);
|
|
50
62
|
if (summary.failed > 0) {
|
|
51
63
|
fail(`${summary.failed} source map upload${summary.failed === 1 ? "" : "s"} failed; the .map files were kept`);
|
|
52
64
|
}
|