bugwatch-cli 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  initProject
3
- } from "./chunk-IV4JMH5O.js";
3
+ } from "./chunk-T5NSQVQH.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-YJQR3ZHX.js";
15
+ } from "./chunk-UIBXO6IR.js";
16
16
 
17
17
  // src/main.ts
18
18
  import { parseArgs } from "util";
@@ -2,7 +2,7 @@ import {
2
2
  DEFAULT_API_URL,
3
3
  UsageError,
4
4
  VERSION
5
- } from "./chunk-YJQR3ZHX.js";
5
+ } from "./chunk-UIBXO6IR.js";
6
6
 
7
7
  // src/init.ts
8
8
  import { execFile, spawn } from "child_process";
@@ -11,8 +11,9 @@ 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.3.0";
15
- var FETCH_TIMEOUT_MS = 15e3;
14
+ var SDK_VERSION_RANGE = "^0.4.0";
15
+ var FETCH_TIMEOUT_MS = 9e4;
16
+ var SLOW_NOTICE_MS = 5e3;
16
17
  var SETUP_CODE = /^bws_[0-9a-f]{32}$/;
17
18
  var ENTRY_EXTENSIONS = ["tsx", "ts", "jsx", "js", "mts", "mjs"];
18
19
  function setupCodeProblem(code) {
@@ -77,23 +78,34 @@ function defaultRunInstall(command, args, cwd) {
77
78
  child.on("close", (code) => done(code ?? 1));
78
79
  });
79
80
  }
80
- async function fetchSetup(apiUrl, setupCode) {
81
+ async function fetchSetup(apiUrl, setupCode, notice, timeouts = {}) {
81
82
  const url = `${apiUrl.replace(/\/+$/, "")}/api/cli/setup`;
83
+ const fetchMs = timeouts.fetchMs ?? FETCH_TIMEOUT_MS;
84
+ const slow = setTimeout(
85
+ () => notice("Waiting for Bugwatch to answer (a sleeping server can take up to a minute to wake up)\u2026"),
86
+ timeouts.slowNoticeMs ?? SLOW_NOTICE_MS
87
+ );
82
88
  let response;
89
+ let body = {};
83
90
  try {
84
91
  response = await fetch(url, {
85
92
  method: "POST",
86
93
  headers: { "Content-Type": "application/json", "User-Agent": `bugwatch-cli/${VERSION}` },
87
94
  body: JSON.stringify({ setupCode }),
88
- signal: AbortSignal.timeout(FETCH_TIMEOUT_MS)
95
+ signal: AbortSignal.timeout(fetchMs)
89
96
  });
97
+ try {
98
+ body = await response.json();
99
+ } catch {
100
+ }
90
101
  } catch (error) {
102
+ const name = error?.name;
103
+ if (name === "TimeoutError" || name === "AbortError") {
104
+ throw new Error(`Bugwatch at ${apiUrl} did not answer within ${Math.ceil(fetchMs / 1e3)} s. Try again in a minute`);
105
+ }
91
106
  throw new Error(`Could not reach Bugwatch at ${apiUrl}: ${error instanceof Error ? error.message : String(error)}`);
92
- }
93
- let body = {};
94
- try {
95
- body = await response.json();
96
- } catch {
107
+ } finally {
108
+ clearTimeout(slow);
97
109
  }
98
110
  if (!response.ok || !body.ok || !body.data) {
99
111
  const message = body.error?.message ?? `Bugwatch answered ${response.status}`;
@@ -243,7 +255,7 @@ async function initProject(options) {
243
255
  if (!gitRoot) throw new UsageError("Run this inside your project's git repository (no .git folder found)");
244
256
  const packageDir = findUp(cwd, "package.json", gitRoot);
245
257
  if (!packageDir) throw new UsageError("No package.json found. Run this in your JavaScript app's folder");
246
- const setup = await fetchSetup(apiUrl, options.setupCode);
258
+ const setup = await fetchSetup(apiUrl, options.setupCode, err, options.timeouts);
247
259
  out(`Bugwatch project "${setup.projectName}" for ${setup.repo.fullName}`);
248
260
  const warnings = [];
249
261
  const remote = await gitRemote(gitRoot);
@@ -26,7 +26,7 @@ function formatSummary(summary, { dryRun, release, files }) {
26
26
  }
27
27
 
28
28
  // src/version.ts
29
- var VERSION = "0.4.0";
29
+ var VERSION = "0.4.1";
30
30
 
31
31
  // src/upload.ts
32
32
  import { open, readdir, readFile, stat, unlink } from "fs/promises";
package/dist/cli.js CHANGED
@@ -1,9 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  main
4
- } from "./chunk-TL4HJZ2T.js";
5
- import "./chunk-IV4JMH5O.js";
6
- import "./chunk-YJQR3ZHX.js";
4
+ } from "./chunk-ODCYZAF4.js";
5
+ import "./chunk-T5NSQVQH.js";
6
+ import "./chunk-UIBXO6IR.js";
7
7
 
8
8
  // src/cli.ts
9
9
  main(process.argv.slice(2)).then((code) => {
package/dist/index.d.ts CHANGED
@@ -175,6 +175,11 @@ interface InitOptions {
175
175
  err?: (line: string) => void;
176
176
  /** Runs the install command; returns its exit code. Tests replace it. */
177
177
  runInstall?: (command: string, args: string[], cwd: string) => Promise<number>;
178
+ /** How long to wait for Bugwatch (default 90 s) and when to say it is waking up (default 5 s). Tests shorten them. */
179
+ timeouts?: {
180
+ fetchMs?: number;
181
+ slowNoticeMs?: number;
182
+ };
178
183
  }
179
184
  interface InitReport {
180
185
  setup: CliSetup;
@@ -208,6 +213,6 @@ declare function addImport(text: string, spec: string): string | null;
208
213
  declare function initProject(options: InitOptions): Promise<InitReport>;
209
214
 
210
215
  /** Keep in sync with package.json (a test checks it). */
211
- declare const VERSION = "0.4.0";
216
+ declare const VERSION = "0.4.1";
212
217
 
213
218
  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, sendableMapFile, setupCodeProblem, sourceMappingUrlOf, uploadSourceMaps, urlPrefixProblem };
package/dist/index.js CHANGED
@@ -10,7 +10,7 @@ import {
10
10
  remoteRepo,
11
11
  replaceApiKey,
12
12
  setupCodeProblem
13
- } from "./chunk-IV4JMH5O.js";
13
+ } from "./chunk-T5NSQVQH.js";
14
14
  import {
15
15
  CONCURRENCY,
16
16
  DEFAULT_API_URL,
@@ -37,7 +37,7 @@ import {
37
37
  sourceMappingUrlOf,
38
38
  uploadSourceMaps,
39
39
  urlPrefixProblem
40
- } from "./chunk-YJQR3ZHX.js";
40
+ } from "./chunk-UIBXO6IR.js";
41
41
  export {
42
42
  CONCURRENCY,
43
43
  DEFAULT_API_URL,
package/dist/main.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  main
3
- } from "./chunk-TL4HJZ2T.js";
4
- import "./chunk-IV4JMH5O.js";
5
- import "./chunk-YJQR3ZHX.js";
3
+ } from "./chunk-ODCYZAF4.js";
4
+ import "./chunk-T5NSQVQH.js";
5
+ import "./chunk-UIBXO6IR.js";
6
6
  export {
7
7
  main
8
8
  };
package/dist/vite.js CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  isCiToken,
8
8
  isDeprecatedUploadToken,
9
9
  uploadSourceMaps
10
- } from "./chunk-YJQR3ZHX.js";
10
+ } from "./chunk-UIBXO6IR.js";
11
11
 
12
12
  // src/vite.ts
13
13
  import { resolve } from "path";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bugwatch-cli",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
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": {