bugwatch-cli 0.1.2 → 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 +19 -6
- package/dist/{chunk-RRAHAYFL.js → chunk-7356247V.js} +15 -2
- package/dist/{chunk-3TESXBNC.js → chunk-JYWRABTL.js} +27 -2
- package/dist/cli.js +2 -2
- package/dist/index.d.ts +16 -3
- package/dist/index.js +9 -1
- package/dist/main.js +2 -2
- package/dist/vite.d.ts +3 -1
- package/dist/vite.js +11 -1
- 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
|
|
|
@@ -146,11 +155,13 @@ same script. The prefix must start with `~/`, `http://`, or
|
|
|
146
155
|
env:
|
|
147
156
|
RELEASE: ${{ github.sha }}
|
|
148
157
|
VITE_RELEASE: ${{ github.sha }} # pass it to Bugwatch.init too
|
|
149
|
-
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)
|
|
150
160
|
# Without the Vite plugin:
|
|
151
161
|
# - run: npx bugwatch-cli sourcemaps upload dist --release ${{ github.sha }} --delete-after-upload
|
|
152
162
|
# env:
|
|
153
163
|
# BUGWATCH_UPLOAD_TOKEN: ${{ secrets.BUGWATCH_UPLOAD_TOKEN }}
|
|
164
|
+
# BUGWATCH_PROJECT: 6735f0c2a1b2c3d4e5f60718
|
|
154
165
|
```
|
|
155
166
|
|
|
156
167
|
## Limits
|
|
@@ -158,6 +169,8 @@ same script. The prefix must start with `~/`, `http://`, or
|
|
|
158
169
|
- One map: at most 20 MB
|
|
159
170
|
- 500 maps per release, 50 MB stored (compressed) per project
|
|
160
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)
|
|
161
174
|
- Maps are kept 90 days after their latest upload; uploading the same
|
|
162
175
|
file again (e.g. a CI re-run) only refreshes that
|
|
163
176
|
- Index maps (with `sections`) are not supported yet
|
|
@@ -5,10 +5,13 @@ import {
|
|
|
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,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/version.ts
|
|
2
|
-
var VERSION = "0.
|
|
2
|
+
var VERSION = "0.2.0";
|
|
3
3
|
|
|
4
4
|
// src/upload.ts
|
|
5
5
|
import { open, readdir, readFile, stat, unlink } from "fs/promises";
|
|
@@ -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);
|
|
@@ -120,7 +131,8 @@ async function errorMessage(response) {
|
|
|
120
131
|
return `HTTP ${response.status}`;
|
|
121
132
|
}
|
|
122
133
|
async function uploadFile(context, file, name, body) {
|
|
123
|
-
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)}`;
|
|
124
136
|
const base = { file, name, bytes: body.length };
|
|
125
137
|
for (let attempt = 0; ; attempt += 1) {
|
|
126
138
|
let response = null;
|
|
@@ -189,6 +201,13 @@ async function uploadSourceMaps(options) {
|
|
|
189
201
|
if (!options.dryRun && !options.token) {
|
|
190
202
|
throw new UsageError("An upload token is required: set BUGWATCH_UPLOAD_TOKEN");
|
|
191
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
|
+
}
|
|
192
211
|
const dir = resolve(options.dir);
|
|
193
212
|
try {
|
|
194
213
|
if (!(await stat(dir)).isDirectory()) throw new UsageError(`Not a folder: ${options.dir}`);
|
|
@@ -204,6 +223,8 @@ async function uploadSourceMaps(options) {
|
|
|
204
223
|
apiUrl,
|
|
205
224
|
release: options.release,
|
|
206
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() } : {},
|
|
207
228
|
fetch: options.fetch ?? globalThis.fetch,
|
|
208
229
|
sleep: options.sleep ?? defaultSleep,
|
|
209
230
|
onRetry: options.onRetry
|
|
@@ -249,6 +270,10 @@ export {
|
|
|
249
270
|
CONCURRENCY,
|
|
250
271
|
MAX_RETRIES,
|
|
251
272
|
MAX_MAP_BYTES,
|
|
273
|
+
isCiToken,
|
|
274
|
+
isDeprecatedUploadToken,
|
|
275
|
+
UPLOAD_TOKEN_DEPRECATED,
|
|
276
|
+
projectProblem,
|
|
252
277
|
UsageError,
|
|
253
278
|
releaseProblem,
|
|
254
279
|
urlPrefixProblem,
|
package/dist/cli.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
main
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-7356247V.js";
|
|
5
5
|
import "./chunk-C7AULTCO.js";
|
|
6
|
-
import "./chunk-
|
|
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,6 +6,17 @@ 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
22
|
/** The map's path relative to `dir`, with `/` separators (one map can be uploaded under several names). */
|
|
@@ -37,8 +48,10 @@ interface UploadOptions {
|
|
|
37
48
|
/** Folder with the build output (searched recursively, `node_modules` skipped). */
|
|
38
49
|
dir: string;
|
|
39
50
|
release: string;
|
|
40
|
-
/**
|
|
51
|
+
/** Org CI token (`bwc_…`, needs `project`) or a deprecated upload token (`bwu_…`). Not needed for a dry run. */
|
|
41
52
|
token?: string;
|
|
53
|
+
/** The project id (24 hex). Required with a CI token; ignored with an upload token. */
|
|
54
|
+
project?: string;
|
|
42
55
|
/** Default `~/`. Must start with `~/`, `http://` or `https://` and end with `/`. */
|
|
43
56
|
urlPrefix?: string;
|
|
44
57
|
/** Default `https://sentry-like.vercel.app`. */
|
|
@@ -103,6 +116,6 @@ declare function planUploads(dir: string, maps: string[], urlPrefix?: string): P
|
|
|
103
116
|
declare function uploadSourceMaps(options: UploadOptions): Promise<UploadReport>;
|
|
104
117
|
|
|
105
118
|
/** Keep in sync with package.json (a test checks it). */
|
|
106
|
-
declare const VERSION = "0.
|
|
119
|
+
declare const VERSION = "0.2.0";
|
|
107
120
|
|
|
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 };
|
|
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,31 +4,39 @@ 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,
|
|
9
10
|
findMapOwners,
|
|
10
11
|
findSourceMaps,
|
|
12
|
+
isCiToken,
|
|
11
13
|
isCssMap,
|
|
14
|
+
isDeprecatedUploadToken,
|
|
12
15
|
mapName,
|
|
13
16
|
planUploads,
|
|
17
|
+
projectProblem,
|
|
14
18
|
releaseProblem,
|
|
15
19
|
sourceMappingUrlOf,
|
|
16
20
|
uploadSourceMaps,
|
|
17
21
|
urlPrefixProblem
|
|
18
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-JYWRABTL.js";
|
|
19
23
|
export {
|
|
20
24
|
CONCURRENCY,
|
|
21
25
|
DEFAULT_API_URL,
|
|
22
26
|
DEFAULT_URL_PREFIX,
|
|
23
27
|
MAX_MAP_BYTES,
|
|
24
28
|
MAX_RETRIES,
|
|
29
|
+
UPLOAD_TOKEN_DEPRECATED,
|
|
25
30
|
UsageError,
|
|
26
31
|
VERSION,
|
|
27
32
|
findMapOwners,
|
|
28
33
|
findSourceMaps,
|
|
34
|
+
isCiToken,
|
|
29
35
|
isCssMap,
|
|
36
|
+
isDeprecatedUploadToken,
|
|
30
37
|
mapName,
|
|
31
38
|
planUploads,
|
|
39
|
+
projectProblem,
|
|
32
40
|
releaseProblem,
|
|
33
41
|
sourceMappingUrlOf,
|
|
34
42
|
uploadSourceMaps,
|
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
|
@@ -4,9 +4,12 @@ import {
|
|
|
4
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,
|