bugwatch-cli 0.1.1 → 0.2.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 +35 -7
- package/dist/{chunk-NWO6RFO7.js → chunk-7356247V.js} +16 -3
- package/dist/{chunk-QGLOKEF7.js → chunk-C7AULTCO.js} +3 -2
- package/dist/{chunk-6YRBKOB7.js → chunk-JYWRABTL.js} +91 -8
- package/dist/cli.js +3 -3
- package/dist/index.d.ts +42 -4
- package/dist/index.js +17 -1
- package/dist/main.js +3 -3
- package/dist/vite.d.ts +3 -1
- package/dist/vite.js +12 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -17,9 +17,16 @@ npm install --save-dev bugwatch-cli
|
|
|
17
17
|
|
|
18
18
|
## Before you start
|
|
19
19
|
|
|
20
|
-
1. **Create an
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
1. **Create an org CI token** in the dashboard: organization → CI
|
|
21
|
+
tokens (owners and managers), for all projects or chosen ones. It is
|
|
22
|
+
shown once; store it as a CI secret named `BUGWATCH_UPLOAD_TOKEN`.
|
|
23
|
+
Never commit it. Then set **`BUGWATCH_PROJECT`** to the project id
|
|
24
|
+
(project → Settings → Source maps). One token can serve several
|
|
25
|
+
projects; each upload names its project.
|
|
26
|
+
|
|
27
|
+
Older per-project upload tokens (`bwu_…`) still work without
|
|
28
|
+
`BUGWATCH_PROJECT`, but are deprecated: the CLI and the plugin print
|
|
29
|
+
a note. Switch to a CI token (`bwc_…`).
|
|
23
30
|
2. **Send a release from the SDK**, the same string you upload maps
|
|
24
31
|
for (SDK 0.2.0 or later):
|
|
25
32
|
|
|
@@ -58,7 +65,8 @@ Options:
|
|
|
58
65
|
| Option | Default | |
|
|
59
66
|
| ------------------- | ------------------------------- | --- |
|
|
60
67
|
| `release` | — | Required. The same value as `Bugwatch.init({ release })` |
|
|
61
|
-
| `token` | `BUGWATCH_UPLOAD_TOKEN` |
|
|
68
|
+
| `token` | `BUGWATCH_UPLOAD_TOKEN` | Org CI token (`bwc_…`) |
|
|
69
|
+
| `project` | `BUGWATCH_PROJECT` | Project id; required with a CI token |
|
|
62
70
|
| `urlPrefix` | `"~/"` | See [File names](#file-names) |
|
|
63
71
|
| `apiUrl` | `BUGWATCH_API_URL`, else Bugwatch's hosted API | |
|
|
64
72
|
| `deleteAfterUpload` | `true` | Delete the `.map` files from the build output after a fully successful upload |
|
|
@@ -83,7 +91,8 @@ npx bugwatch-cli sourcemaps upload dist --release 1.4.2 --delete-after-upload
|
|
|
83
91
|
| `--release <version>` | Required |
|
|
84
92
|
| `--url-prefix <prefix>` | Default `~/`. See [File names](#file-names) |
|
|
85
93
|
| `--api-url <url>` | Default `BUGWATCH_API_URL`, else Bugwatch's hosted API |
|
|
86
|
-
| `--token <token>` | Default `BUGWATCH_UPLOAD_TOKEN
|
|
94
|
+
| `--token <token>` | Default `BUGWATCH_UPLOAD_TOKEN` (an org CI token, `bwc_…`). Prefer the variable: flags can end up in CI logs |
|
|
95
|
+
| `--project <id>` | Default `BUGWATCH_PROJECT`. The project id; required with a CI token |
|
|
87
96
|
| `--delete-after-upload` | Delete the local `.map` files, only after every upload succeeded |
|
|
88
97
|
| `--dry-run` | Print what would be uploaded; no token needed, nothing sent or deleted |
|
|
89
98
|
|
|
@@ -109,13 +118,28 @@ fix. The token is never printed.
|
|
|
109
118
|
## File names
|
|
110
119
|
|
|
111
120
|
Each map is uploaded for the URL of the minified file it belongs to:
|
|
112
|
-
the URL prefix +
|
|
121
|
+
the URL prefix + that file's path inside `<dir>`.
|
|
122
|
+
|
|
123
|
+
- **The script's `sourceMappingURL` comment decides.** A JavaScript file
|
|
124
|
+
ending in `//# sourceMappingURL=559f….js.map` owns that map, so the map
|
|
125
|
+
is uploaded under the script's name, even when the names differ (Next.js
|
|
126
|
+
with Turbopack: `b55a….js` → `559f….js.map`). A map shared by several
|
|
127
|
+
scripts is uploaded once per script.
|
|
128
|
+
- **No comment** (e.g. Vite's `sourcemap: "hidden"`): the map's own path
|
|
129
|
+
without `.map` is used (`index-3f9a.js.map` → `index-3f9a.js`).
|
|
130
|
+
- **CSS maps** (`*.css.map`) are skipped: errors only come from scripts.
|
|
131
|
+
With `--delete-after-upload` they are deleted with the rest.
|
|
113
132
|
|
|
114
133
|
| Map in the build | `--url-prefix` | Uploaded for |
|
|
115
134
|
| ------------------------- | ------------------------------ | --- |
|
|
116
135
|
| `dist/assets/index-3f9a.js.map` | `~/` (default) | `~/assets/index-3f9a.js` |
|
|
117
136
|
| `dist/assets/index-3f9a.js.map` | `https://cdn.shop.com/static/` | `https://cdn.shop.com/static/assets/index-3f9a.js` |
|
|
118
137
|
|
|
138
|
+
For Next.js, upload `.next/static` with `--url-prefix "~/_next/static/"`
|
|
139
|
+
(files in `.next/static/chunks/` are served at `/_next/static/chunks/`), and
|
|
140
|
+
set `productionBrowserSourceMaps: true`. Next.js has no hidden mode, so always
|
|
141
|
+
use `--delete-after-upload` to keep the maps off your site.
|
|
142
|
+
|
|
119
143
|
`~/` matches the path on any host, so it works for every domain and
|
|
120
144
|
preview deployment. Use a full URL prefix when the files are served
|
|
121
145
|
from a different path (e.g. a CDN folder) than their place in the
|
|
@@ -131,11 +155,13 @@ same script. The prefix must start with `~/`, `http://`, or
|
|
|
131
155
|
env:
|
|
132
156
|
RELEASE: ${{ github.sha }}
|
|
133
157
|
VITE_RELEASE: ${{ github.sha }} # pass it to Bugwatch.init too
|
|
134
|
-
BUGWATCH_UPLOAD_TOKEN: ${{ secrets.BUGWATCH_UPLOAD_TOKEN }}
|
|
158
|
+
BUGWATCH_UPLOAD_TOKEN: ${{ secrets.BUGWATCH_UPLOAD_TOKEN }} # an org CI token
|
|
159
|
+
BUGWATCH_PROJECT: 6735f0c2a1b2c3d4e5f60718 # the project id (not a secret)
|
|
135
160
|
# Without the Vite plugin:
|
|
136
161
|
# - run: npx bugwatch-cli sourcemaps upload dist --release ${{ github.sha }} --delete-after-upload
|
|
137
162
|
# env:
|
|
138
163
|
# BUGWATCH_UPLOAD_TOKEN: ${{ secrets.BUGWATCH_UPLOAD_TOKEN }}
|
|
164
|
+
# BUGWATCH_PROJECT: 6735f0c2a1b2c3d4e5f60718
|
|
139
165
|
```
|
|
140
166
|
|
|
141
167
|
## Limits
|
|
@@ -143,6 +169,8 @@ same script. The prefix must start with `~/`, `http://`, or
|
|
|
143
169
|
- One map: at most 20 MB
|
|
144
170
|
- 500 maps per release, 50 MB stored (compressed) per project
|
|
145
171
|
- 600 uploads per 10 minutes per token
|
|
172
|
+
- A CI token uploads only to the projects it covers (`403` for
|
|
173
|
+
another project of the organization, `404` for any other project)
|
|
146
174
|
- Maps are kept 90 days after their latest upload; uploading the same
|
|
147
175
|
file again (e.g. a CI re-run) only refreshes that
|
|
148
176
|
- Index maps (with `sections`) are not supported yet
|
|
@@ -1,14 +1,17 @@
|
|
|
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
|
+
UPLOAD_TOKEN_DEPRECATED,
|
|
8
9
|
UsageError,
|
|
9
10
|
VERSION,
|
|
11
|
+
isCiToken,
|
|
12
|
+
isDeprecatedUploadToken,
|
|
10
13
|
uploadSourceMaps
|
|
11
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-JYWRABTL.js";
|
|
12
15
|
|
|
13
16
|
// src/main.ts
|
|
14
17
|
import { parseArgs } from "util";
|
|
@@ -21,7 +24,9 @@ Options:
|
|
|
21
24
|
--url-prefix <prefix> Prefix of the files' URLs: "~/" (any host, default) or
|
|
22
25
|
e.g. "https://cdn.shop.com/static/". Must end with "/"
|
|
23
26
|
--api-url <url> Bugwatch API (default: $BUGWATCH_API_URL or ${DEFAULT_API_URL})
|
|
24
|
-
--token <token>
|
|
27
|
+
--token <token> Org CI token, bwc_\u2026 (default: $BUGWATCH_UPLOAD_TOKEN; prefer the variable)
|
|
28
|
+
--project <id> Project id, required with a CI token (default: $BUGWATCH_PROJECT;
|
|
29
|
+
shown in the project's Settings \u2192 Source maps)
|
|
25
30
|
--delete-after-upload Delete the local .map files after every upload succeeded
|
|
26
31
|
--dry-run List what would be uploaded; uploads and deletes nothing
|
|
27
32
|
-h, --help Show this help
|
|
@@ -41,6 +46,7 @@ async function main(argv, env = process.env, out = (line) => process.stdout.writ
|
|
|
41
46
|
"url-prefix": { type: "string" },
|
|
42
47
|
"api-url": { type: "string" },
|
|
43
48
|
token: { type: "string" },
|
|
49
|
+
project: { type: "string" },
|
|
44
50
|
"delete-after-upload": { type: "boolean" },
|
|
45
51
|
"dry-run": { type: "boolean" },
|
|
46
52
|
help: { type: "boolean", short: "h" },
|
|
@@ -70,6 +76,7 @@ ${USAGE}`);
|
|
|
70
76
|
const dryRun = values["dry-run"] === true;
|
|
71
77
|
const apiUrl = values["api-url"] || env.BUGWATCH_API_URL || DEFAULT_API_URL;
|
|
72
78
|
const token = values.token || env.BUGWATCH_UPLOAD_TOKEN || void 0;
|
|
79
|
+
const project = values.project || env.BUGWATCH_PROJECT || void 0;
|
|
73
80
|
if (!values.release) {
|
|
74
81
|
err("Error: A release is required (--release)");
|
|
75
82
|
return 2;
|
|
@@ -78,11 +85,17 @@ ${USAGE}`);
|
|
|
78
85
|
err("Error: An upload token is required: set BUGWATCH_UPLOAD_TOKEN (or pass --token)");
|
|
79
86
|
return 2;
|
|
80
87
|
}
|
|
88
|
+
if (!dryRun && isCiToken(token) && !project) {
|
|
89
|
+
err("Error: A CI token (bwc_\u2026) needs the project id: set BUGWATCH_PROJECT (or pass --project)");
|
|
90
|
+
return 2;
|
|
91
|
+
}
|
|
92
|
+
if (!dryRun && isDeprecatedUploadToken(token)) err(`Note: ${UPLOAD_TOKEN_DEPRECATED}`);
|
|
81
93
|
try {
|
|
82
94
|
const { results, summary } = await uploadSourceMaps({
|
|
83
95
|
dir,
|
|
84
96
|
release: values.release,
|
|
85
97
|
token,
|
|
98
|
+
...project ? { project } : {},
|
|
86
99
|
urlPrefix: values["url-prefix"] ?? DEFAULT_URL_PREFIX,
|
|
87
100
|
apiUrl,
|
|
88
101
|
deleteAfterUpload: values["delete-after-upload"] === true,
|
|
@@ -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,9 +1,9 @@
|
|
|
1
1
|
// src/version.ts
|
|
2
|
-
var VERSION = "0.
|
|
2
|
+
var VERSION = "0.2.0";
|
|
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;
|
|
@@ -11,6 +11,17 @@ var MAX_RETRIES = 3;
|
|
|
11
11
|
var MAX_MAP_BYTES = 20 * 1024 * 1024;
|
|
12
12
|
var MAX_NAME_LENGTH = 1e3;
|
|
13
13
|
var MAX_RETRY_DELAY_MS = 6e4;
|
|
14
|
+
function isCiToken(token) {
|
|
15
|
+
return typeof token === "string" && token.startsWith("bwc_");
|
|
16
|
+
}
|
|
17
|
+
function isDeprecatedUploadToken(token) {
|
|
18
|
+
return typeof token === "string" && token.startsWith("bwu_");
|
|
19
|
+
}
|
|
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).";
|
|
21
|
+
function projectProblem(project) {
|
|
22
|
+
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";
|
|
24
|
+
}
|
|
14
25
|
var UsageError = class extends Error {
|
|
15
26
|
constructor(message) {
|
|
16
27
|
super(message);
|
|
@@ -34,7 +45,7 @@ function mapName(relativePath, urlPrefix = DEFAULT_URL_PREFIX) {
|
|
|
34
45
|
const path = relativePath.split(sep).join("/").replace(/^\.?\//, "");
|
|
35
46
|
return urlPrefix + path.replace(/\.map$/, "");
|
|
36
47
|
}
|
|
37
|
-
async function
|
|
48
|
+
async function findFiles(dir, test) {
|
|
38
49
|
const root = resolve(dir);
|
|
39
50
|
const found = [];
|
|
40
51
|
async function walk(folder) {
|
|
@@ -43,12 +54,64 @@ async function findSourceMaps(dir) {
|
|
|
43
54
|
if (entry.name === "node_modules") continue;
|
|
44
55
|
const path = join(folder, entry.name);
|
|
45
56
|
if (entry.isDirectory()) await walk(path);
|
|
46
|
-
else if (entry.isFile() && entry.name
|
|
57
|
+
else if (entry.isFile() && test(entry.name)) found.push(relative(root, path).split(sep).join("/"));
|
|
47
58
|
}
|
|
48
59
|
}
|
|
49
60
|
await walk(root);
|
|
50
61
|
return found.sort();
|
|
51
62
|
}
|
|
63
|
+
function findSourceMaps(dir) {
|
|
64
|
+
return findFiles(dir, (name) => name.endsWith(".map"));
|
|
65
|
+
}
|
|
66
|
+
var COMMENT_TAIL_BYTES = 4096;
|
|
67
|
+
function sourceMappingUrlOf(scriptTail) {
|
|
68
|
+
const matches = [...scriptTail.matchAll(/\/\/[#@][ \t]*sourceMappingURL=([^\s'"]+)[ \t]*/g)];
|
|
69
|
+
const last = matches.at(-1);
|
|
70
|
+
if (!last || scriptTail.slice((last.index ?? 0) + last[0].length).trim() !== "") return null;
|
|
71
|
+
return last[1] ?? null;
|
|
72
|
+
}
|
|
73
|
+
async function readTail(path) {
|
|
74
|
+
const file = await open(path, "r");
|
|
75
|
+
try {
|
|
76
|
+
const { size } = await file.stat();
|
|
77
|
+
const length = Math.min(size, COMMENT_TAIL_BYTES);
|
|
78
|
+
const buffer = Buffer.alloc(length);
|
|
79
|
+
await file.read(buffer, 0, length, size - length);
|
|
80
|
+
return buffer.toString("utf8");
|
|
81
|
+
} finally {
|
|
82
|
+
await file.close();
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
async function findMapOwners(dir, maps) {
|
|
86
|
+
const root = resolve(dir);
|
|
87
|
+
const known = new Set(maps);
|
|
88
|
+
const owners = /* @__PURE__ */ new Map();
|
|
89
|
+
const scripts = await findFiles(root, (name) => /\.(m|c)?js$/.test(name));
|
|
90
|
+
for (const script of scripts) {
|
|
91
|
+
const url = sourceMappingUrlOf(await readTail(join(root, script)));
|
|
92
|
+
if (!url || /^[a-z][a-z0-9+.-]*:/i.test(url) || url.startsWith("/")) continue;
|
|
93
|
+
let decoded;
|
|
94
|
+
try {
|
|
95
|
+
decoded = decodeURIComponent(url.replace(/[?#].*$/, ""));
|
|
96
|
+
} catch {
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
const map = posix.normalize(posix.join(posix.dirname(script), decoded));
|
|
100
|
+
if (map.startsWith("../") || !known.has(map)) continue;
|
|
101
|
+
owners.set(map, [...owners.get(map) ?? [], script]);
|
|
102
|
+
}
|
|
103
|
+
return owners;
|
|
104
|
+
}
|
|
105
|
+
function isCssMap(map) {
|
|
106
|
+
return /\.css\.map$/i.test(map);
|
|
107
|
+
}
|
|
108
|
+
async function planUploads(dir, maps, urlPrefix = DEFAULT_URL_PREFIX) {
|
|
109
|
+
const owners = await findMapOwners(dir, maps);
|
|
110
|
+
return maps.filter((map) => !isCssMap(map)).flatMap((map) => {
|
|
111
|
+
const scripts = owners.get(map);
|
|
112
|
+
return scripts ? scripts.map((script) => ({ map, name: urlPrefix + script })) : [{ map, name: mapName(map, urlPrefix) }];
|
|
113
|
+
});
|
|
114
|
+
}
|
|
52
115
|
function retryAfterMs(header, now = Date.now()) {
|
|
53
116
|
if (!header) return null;
|
|
54
117
|
const seconds = Number(header);
|
|
@@ -68,7 +131,8 @@ async function errorMessage(response) {
|
|
|
68
131
|
return `HTTP ${response.status}`;
|
|
69
132
|
}
|
|
70
133
|
async function uploadFile(context, file, name, body) {
|
|
71
|
-
const
|
|
134
|
+
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)}`;
|
|
72
136
|
const base = { file, name, bytes: body.length };
|
|
73
137
|
for (let attempt = 0; ; attempt += 1) {
|
|
74
138
|
let response = null;
|
|
@@ -137,6 +201,13 @@ async function uploadSourceMaps(options) {
|
|
|
137
201
|
if (!options.dryRun && !options.token) {
|
|
138
202
|
throw new UsageError("An upload token is required: set BUGWATCH_UPLOAD_TOKEN");
|
|
139
203
|
}
|
|
204
|
+
const projectError = projectProblem(options.project);
|
|
205
|
+
if (projectError) throw new UsageError(projectError);
|
|
206
|
+
if (!options.dryRun && isCiToken(options.token) && !options.project) {
|
|
207
|
+
throw new UsageError(
|
|
208
|
+
"A CI token (bwc_\u2026) needs the project id: set BUGWATCH_PROJECT (from the project's Settings \u2192 Source maps)"
|
|
209
|
+
);
|
|
210
|
+
}
|
|
140
211
|
const dir = resolve(options.dir);
|
|
141
212
|
try {
|
|
142
213
|
if (!(await stat(dir)).isDirectory()) throw new UsageError(`Not a folder: ${options.dir}`);
|
|
@@ -146,16 +217,19 @@ async function uploadSourceMaps(options) {
|
|
|
146
217
|
}
|
|
147
218
|
const files = await findSourceMaps(dir);
|
|
148
219
|
if (files.length === 0) throw new UsageError(`No .map files found in ${options.dir}`);
|
|
220
|
+
const uploads = await planUploads(dir, files, urlPrefix);
|
|
221
|
+
if (uploads.length === 0) throw new UsageError(`No JavaScript source maps found in ${options.dir} (only CSS maps)`);
|
|
149
222
|
const context = {
|
|
150
223
|
apiUrl,
|
|
151
224
|
release: options.release,
|
|
152
225
|
token: options.token ?? "",
|
|
226
|
+
// Only CI tokens use the project route; an upload token names its project itself.
|
|
227
|
+
...isCiToken(options.token) && options.project ? { project: options.project.toLowerCase() } : {},
|
|
153
228
|
fetch: options.fetch ?? globalThis.fetch,
|
|
154
229
|
sleep: options.sleep ?? defaultSleep,
|
|
155
230
|
onRetry: options.onRetry
|
|
156
231
|
};
|
|
157
|
-
const results = await mapLimit(
|
|
158
|
-
const name = mapName(file, urlPrefix);
|
|
232
|
+
const results = await mapLimit(uploads, CONCURRENCY, async ({ map: file, name }) => {
|
|
159
233
|
const path = join(dir, file);
|
|
160
234
|
const { size } = await stat(path);
|
|
161
235
|
let result;
|
|
@@ -175,6 +249,7 @@ async function uploadSourceMaps(options) {
|
|
|
175
249
|
});
|
|
176
250
|
const count = (outcome) => results.filter((r) => r.outcome === outcome).length;
|
|
177
251
|
const summary = {
|
|
252
|
+
skipped: files.filter(isCssMap).length,
|
|
178
253
|
uploaded: count("uploaded"),
|
|
179
254
|
replaced: count("replaced"),
|
|
180
255
|
unchanged: count("unchanged"),
|
|
@@ -195,10 +270,18 @@ export {
|
|
|
195
270
|
CONCURRENCY,
|
|
196
271
|
MAX_RETRIES,
|
|
197
272
|
MAX_MAP_BYTES,
|
|
273
|
+
isCiToken,
|
|
274
|
+
isDeprecatedUploadToken,
|
|
275
|
+
UPLOAD_TOKEN_DEPRECATED,
|
|
276
|
+
projectProblem,
|
|
198
277
|
UsageError,
|
|
199
278
|
releaseProblem,
|
|
200
279
|
urlPrefixProblem,
|
|
201
280
|
mapName,
|
|
202
281
|
findSourceMaps,
|
|
282
|
+
sourceMappingUrlOf,
|
|
283
|
+
findMapOwners,
|
|
284
|
+
isCssMap,
|
|
285
|
+
planUploads,
|
|
203
286
|
uploadSourceMaps
|
|
204
287
|
};
|
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-7356247V.js";
|
|
5
|
+
import "./chunk-C7AULTCO.js";
|
|
6
|
+
import "./chunk-JYWRABTL.js";
|
|
7
7
|
|
|
8
8
|
// src/cli.ts
|
|
9
9
|
main(process.argv.slice(2)).then((code) => {
|
package/dist/index.d.ts
CHANGED
|
@@ -6,9 +6,20 @@ declare const CONCURRENCY = 4;
|
|
|
6
6
|
declare const MAX_RETRIES = 3;
|
|
7
7
|
/** The backend rejects larger maps with 413. */
|
|
8
8
|
declare const MAX_MAP_BYTES: number;
|
|
9
|
+
/**
|
|
10
|
+
* Org CI tokens (`bwc_…`, Bugwatch backend Step 33) upload to
|
|
11
|
+
* `/api/projects/<project>/releases/<release>/sourcemaps` and need the project
|
|
12
|
+
* id. Older per-project upload tokens (`bwu_…`) keep the old route, deprecated.
|
|
13
|
+
*/
|
|
14
|
+
declare function isCiToken(token: string | undefined): boolean;
|
|
15
|
+
declare function isDeprecatedUploadToken(token: string | undefined): boolean;
|
|
16
|
+
/** Shown when a `bwu_` token is used (the CLI and the Vite plugin print it). */
|
|
17
|
+
declare const UPLOAD_TOKEN_DEPRECATED: string;
|
|
18
|
+
/** A Bugwatch project id: 24 hex characters. */
|
|
19
|
+
declare function projectProblem(project: string | undefined): string | null;
|
|
9
20
|
type Outcome = "uploaded" | "replaced" | "unchanged" | "failed" | "dry-run";
|
|
10
21
|
interface FileResult {
|
|
11
|
-
/** The map's path relative to `dir`, with `/` separators. */
|
|
22
|
+
/** The map's path relative to `dir`, with `/` separators (one map can be uploaded under several names). */
|
|
12
23
|
file: string;
|
|
13
24
|
/** The minified file's URL the map is uploaded for. */
|
|
14
25
|
name: string;
|
|
@@ -20,6 +31,8 @@ interface FileResult {
|
|
|
20
31
|
error?: string;
|
|
21
32
|
}
|
|
22
33
|
interface UploadSummary {
|
|
34
|
+
/** CSS maps found and not uploaded (errors only come from scripts). */
|
|
35
|
+
skipped: number;
|
|
23
36
|
uploaded: number;
|
|
24
37
|
replaced: number;
|
|
25
38
|
unchanged: number;
|
|
@@ -35,8 +48,10 @@ interface UploadOptions {
|
|
|
35
48
|
/** Folder with the build output (searched recursively, `node_modules` skipped). */
|
|
36
49
|
dir: string;
|
|
37
50
|
release: string;
|
|
38
|
-
/**
|
|
51
|
+
/** Org CI token (`bwc_…`, needs `project`) or a deprecated upload token (`bwu_…`). Not needed for a dry run. */
|
|
39
52
|
token?: string;
|
|
53
|
+
/** The project id (24 hex). Required with a CI token; ignored with an upload token. */
|
|
54
|
+
project?: string;
|
|
40
55
|
/** Default `~/`. Must start with `~/`, `http://` or `https://` and end with `/`. */
|
|
41
56
|
urlPrefix?: string;
|
|
42
57
|
/** Default `https://sentry-like.vercel.app`. */
|
|
@@ -70,6 +85,29 @@ declare function urlPrefixProblem(prefix: string): string | null;
|
|
|
70
85
|
declare function mapName(relativePath: string, urlPrefix?: string): string;
|
|
71
86
|
/** Every `*.map` file under `dir`, relative paths with `/`, sorted. Skips `node_modules`. */
|
|
72
87
|
declare function findSourceMaps(dir: string): Promise<string[]>;
|
|
88
|
+
/** The `//# sourceMappingURL=` (or legacy `//@`) value at the end of a script, or null. */
|
|
89
|
+
declare function sourceMappingUrlOf(scriptTail: string): string | null;
|
|
90
|
+
/**
|
|
91
|
+
* Which script each map belongs to, from the scripts' `sourceMappingURL`
|
|
92
|
+
* comments: map path → script paths (relative to `dir`). Needed because some
|
|
93
|
+
* bundlers (e.g. Next.js with Turbopack) name a chunk's map differently from
|
|
94
|
+
* the chunk (`b55a.js` → `559f.js.map`). `data:` URLs, absolute URLs, and
|
|
95
|
+
* maps outside `dir` are ignored.
|
|
96
|
+
*/
|
|
97
|
+
declare function findMapOwners(dir: string, maps: string[]): Promise<Map<string, string[]>>;
|
|
98
|
+
/** CSS maps are never needed for errors (and Turbopack writes them as index maps, which are rejected). */
|
|
99
|
+
declare function isCssMap(map: string): boolean;
|
|
100
|
+
/** One upload: a map file and the name (minified file URL) it is uploaded for. */
|
|
101
|
+
interface PlannedUpload {
|
|
102
|
+
map: string;
|
|
103
|
+
name: string;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* The uploads for `maps`: a map referenced by scripts is uploaded once per
|
|
107
|
+
* script, named after the script; a map no script points to (e.g. Vite's
|
|
108
|
+
* `sourcemap: "hidden"`) is named after itself without `.map`.
|
|
109
|
+
*/
|
|
110
|
+
declare function planUploads(dir: string, maps: string[], urlPrefix?: string): Promise<PlannedUpload[]>;
|
|
73
111
|
/**
|
|
74
112
|
* Uploads every source map under `dir` for `release` (4 at a time, with
|
|
75
113
|
* retries). Throws `UsageError` for problems with the options; upload
|
|
@@ -78,6 +116,6 @@ declare function findSourceMaps(dir: string): Promise<string[]>;
|
|
|
78
116
|
declare function uploadSourceMaps(options: UploadOptions): Promise<UploadReport>;
|
|
79
117
|
|
|
80
118
|
/** Keep in sync with package.json (a test checks it). */
|
|
81
|
-
declare const VERSION = "0.
|
|
119
|
+
declare const VERSION = "0.2.0";
|
|
82
120
|
|
|
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 };
|
|
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 };
|
package/dist/index.js
CHANGED
|
@@ -4,25 +4,41 @@ import {
|
|
|
4
4
|
DEFAULT_URL_PREFIX,
|
|
5
5
|
MAX_MAP_BYTES,
|
|
6
6
|
MAX_RETRIES,
|
|
7
|
+
UPLOAD_TOKEN_DEPRECATED,
|
|
7
8
|
UsageError,
|
|
8
9
|
VERSION,
|
|
10
|
+
findMapOwners,
|
|
9
11
|
findSourceMaps,
|
|
12
|
+
isCiToken,
|
|
13
|
+
isCssMap,
|
|
14
|
+
isDeprecatedUploadToken,
|
|
10
15
|
mapName,
|
|
16
|
+
planUploads,
|
|
17
|
+
projectProblem,
|
|
11
18
|
releaseProblem,
|
|
19
|
+
sourceMappingUrlOf,
|
|
12
20
|
uploadSourceMaps,
|
|
13
21
|
urlPrefixProblem
|
|
14
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-JYWRABTL.js";
|
|
15
23
|
export {
|
|
16
24
|
CONCURRENCY,
|
|
17
25
|
DEFAULT_API_URL,
|
|
18
26
|
DEFAULT_URL_PREFIX,
|
|
19
27
|
MAX_MAP_BYTES,
|
|
20
28
|
MAX_RETRIES,
|
|
29
|
+
UPLOAD_TOKEN_DEPRECATED,
|
|
21
30
|
UsageError,
|
|
22
31
|
VERSION,
|
|
32
|
+
findMapOwners,
|
|
23
33
|
findSourceMaps,
|
|
34
|
+
isCiToken,
|
|
35
|
+
isCssMap,
|
|
36
|
+
isDeprecatedUploadToken,
|
|
24
37
|
mapName,
|
|
38
|
+
planUploads,
|
|
39
|
+
projectProblem,
|
|
25
40
|
releaseProblem,
|
|
41
|
+
sourceMappingUrlOf,
|
|
26
42
|
uploadSourceMaps,
|
|
27
43
|
urlPrefixProblem
|
|
28
44
|
};
|
package/dist/main.js
CHANGED
package/dist/vite.d.ts
CHANGED
|
@@ -5,8 +5,10 @@ interface BugwatchSourcemapsOptions {
|
|
|
5
5
|
* nothing is uploaded and the build logs why (or fails with `failOnError`).
|
|
6
6
|
*/
|
|
7
7
|
release: string | undefined;
|
|
8
|
-
/**
|
|
8
|
+
/** Org CI token (`bwc_…`). Default: the `BUGWATCH_UPLOAD_TOKEN` environment variable. */
|
|
9
9
|
token?: string;
|
|
10
|
+
/** Project id, required with a CI token. Default: the `BUGWATCH_PROJECT` environment variable. */
|
|
11
|
+
project?: string;
|
|
10
12
|
/** Default `~/` (any host). */
|
|
11
13
|
urlPrefix?: string;
|
|
12
14
|
/** Default: `BUGWATCH_API_URL`, else Bugwatch's hosted API. */
|
package/dist/vite.js
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
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
|
+
UPLOAD_TOKEN_DEPRECATED,
|
|
7
8
|
UsageError,
|
|
9
|
+
isCiToken,
|
|
10
|
+
isDeprecatedUploadToken,
|
|
8
11
|
uploadSourceMaps
|
|
9
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-JYWRABTL.js";
|
|
10
13
|
|
|
11
14
|
// src/vite.ts
|
|
12
15
|
import { resolve } from "path";
|
|
@@ -47,11 +50,18 @@ function bugwatchSourcemaps(options) {
|
|
|
47
50
|
fail("Source maps not uploaded: no upload token. Set BUGWATCH_UPLOAD_TOKEN or the token option");
|
|
48
51
|
return;
|
|
49
52
|
}
|
|
53
|
+
const project = options.project || process.env.BUGWATCH_PROJECT || void 0;
|
|
54
|
+
if (isCiToken(token) && !project) {
|
|
55
|
+
fail("Source maps not uploaded: a CI token needs the project id. Set BUGWATCH_PROJECT or the project option");
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (isDeprecatedUploadToken(token)) logger.warn(`${PREFIX} ${UPLOAD_TOKEN_DEPRECATED}`);
|
|
50
59
|
try {
|
|
51
60
|
const { results, summary } = await uploadSourceMaps({
|
|
52
61
|
dir: resolve(config.root, build.outDir),
|
|
53
62
|
release,
|
|
54
63
|
token,
|
|
64
|
+
...project ? { project } : {},
|
|
55
65
|
urlPrefix: options.urlPrefix ?? DEFAULT_URL_PREFIX,
|
|
56
66
|
apiUrl: options.apiUrl || process.env.BUGWATCH_API_URL || void 0,
|
|
57
67
|
deleteAfterUpload: options.deleteAfterUpload ?? true,
|