@bigbertha/sdk 0.1.4 → 0.1.6

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
@@ -55,14 +55,20 @@ import { withBertha } from "@bigbertha/sdk/next/config"
55
55
  export default withBertha({ /* your config */ })
56
56
  ```
57
57
 
58
- `withBertha` options: `release`, `keepMaps` (default false), `disableUpload`. It also
59
- stamps the environment, so a Vercel preview reports as staging.
58
+ `withBertha` options: `release`, `keepMaps`, `disableUpload`. It removes the maps under
59
+ `.next/static` (the ones browsers can fetch) and keeps the server's, which aren't served
60
+ and which Vercel's build output can need. `keepMaps` takes `true`, `false` or a function
61
+ of the path inside `.next`. It also stamps the environment, so a Vercel preview reports
62
+ as staging.
60
63
 
61
64
  For your own options (`beforeSend`, `tags`, `sampleRate`), call `init` from
62
65
  `@bigbertha/sdk/browser` in `instrumentation-client.ts` instead of importing
63
66
  `next/client`, and `init` from `@bigbertha/sdk/node` in `register()`. The build plugin
64
67
  works the same either way, and it keeps the debug ids another tool (such as Sentry's
65
- plugin) already gave the bundles, so both can run side by side.
68
+ plugin) already gave the bundles, so both can run side by side. Wrap it inside
69
+ `withSentryConfig` and set Sentry's `sourcemaps.deleteSourcemapsAfterUpload: false`:
70
+ Sentry's plugin runs first, and the maps it deletes never reach bertha. bertha removes
71
+ the served ones afterwards.
66
72
 
67
73
  ## Vite (browser)
68
74
 
@@ -24,7 +24,7 @@ export interface Report {
24
24
  files: Processed[];
25
25
  uploaded: number;
26
26
  failed: number;
27
- /** Leftover .js.map files removed because no bundle referenced them. */
27
+ /** Other .js.map and .css.map files removed: no bundle referenced them, or they map CSS. */
28
28
  removedOrphans: number;
29
29
  /** Why nothing was uploaded, when nothing was. */
30
30
  skipped?: string;
@@ -13,7 +13,9 @@ import { dirname, join, relative, resolve, sep } from "node:path";
13
13
  import { gzipSync } from "node:zlib";
14
14
  export { detectRelease, lastCommit } from "./release.js";
15
15
  const JS = /\.(?:m|c)?js$/;
16
- const ORPHAN_MAP = /\.(?:m|c)?js\.map$/;
16
+ const ORPHAN_MAP = /\.(?:(?:m|c)?js|css)\.map$/;
17
+ const CSS = /\.css$/;
18
+ const CSS_MAP_COMMENT = /\n?\/\*# sourceMappingURL=\S+ ?\*\/\s*$/;
17
19
  const MAP_COMMENT = /\n?\/\/[#@] sourceMappingURL=(\S+)[ \t]*\r?\n?$/;
18
20
  const DEBUG_ID_COMMENT = /\/\/# debugId=([0-9a-fA-F-]{36})/;
19
21
  /** In every bundle this step has already stamped, so a second run changes nothing. */
@@ -71,16 +73,22 @@ export async function processDirectory(o) {
71
73
  }
72
74
  report.files.push(entry);
73
75
  });
74
- // Maps no bundle points at (renamed polyfills and the like) are source code too.
76
+ // Maps no bundle points at (renamed polyfills and the like) are source code too,
77
+ // and so are CSS maps (Next writes them once browser source maps are on).
75
78
  if (o.keepMaps !== true) {
76
79
  const keepFn = typeof o.keepMaps === "function" ? o.keepMaps : undefined;
80
+ const kept = (f) => !!keepFn?.(relative(root, f).split(sep).join("/"));
77
81
  for (const f of await walk(root, skip)) {
78
- if (!ORPHAN_MAP.test(f) || !existsSync(f))
79
- continue;
80
- if (keepFn?.(relative(root, f.replace(/\.map$/, "")).split(sep).join("/")))
81
- continue;
82
- await rm(f, { force: true });
83
- report.removedOrphans++;
82
+ if (CSS.test(f) && !kept(f)) {
83
+ const css = await readFile(f, "utf8");
84
+ const stripped = css.replace(CSS_MAP_COMMENT, "\n");
85
+ if (stripped !== css)
86
+ await writeFile(f, stripped);
87
+ }
88
+ else if (ORPHAN_MAP.test(f) && existsSync(f) && !kept(f.replace(/\.map$/, ""))) {
89
+ await rm(f, { force: true });
90
+ report.removedOrphans++;
91
+ }
84
92
  }
85
93
  }
86
94
  report.files.sort((a, b) => a.file.localeCompare(b.file));
@@ -1 +1 @@
1
- export declare const VERSION = "0.1.4";
1
+ export declare const VERSION = "0.1.6";
@@ -1 +1 @@
1
- export const VERSION = "0.1.4";
1
+ export const VERSION = "0.1.6";
@@ -1,8 +1,13 @@
1
1
  export interface BerthaNextOptions {
2
2
  release?: string;
3
- /** Keep .map files in `.next` after uploading. Default false. */
4
- keepMaps?: boolean;
3
+ /**
4
+ * Which .map files stay in `.next` after uploading, by path inside it. Defaults to
5
+ * the server's: only `static/` is served to browsers, and removing server maps can
6
+ * break Vercel's build output (getsentry/sentry-javascript#13099).
7
+ */
8
+ keepMaps?: boolean | ((file: string) => boolean);
5
9
  /** Skip the post-build step entirely (the release is still stamped). */
6
10
  disableUpload?: boolean;
7
11
  }
12
+ export declare const keepServerMaps: (file: string) => boolean;
8
13
  export declare function withBertha<C extends object>(config?: C, options?: BerthaNextOptions): C;
@@ -6,6 +6,7 @@
6
6
  import { join } from "node:path";
7
7
  import { detectRelease, processDirectory } from "../build/index.js";
8
8
  import { firstEnv } from "../core/env.js";
9
+ export const keepServerMaps = (file) => !file.startsWith("static/");
9
10
  export function withBertha(config = {}, options = {}) {
10
11
  const c = config;
11
12
  const release = options.release ?? detectRelease();
@@ -31,7 +32,7 @@ export function withBertha(config = {}, options = {}) {
31
32
  release,
32
33
  url: firstEnv("BERTHA_URL", "NEXT_PUBLIC_BERTHA_URL"),
33
34
  uploadKey: firstEnv("BERTHA_UPLOAD_KEY"),
34
- keepMaps: options.keepMaps,
35
+ keepMaps: options.keepMaps ?? keepServerMaps,
35
36
  skip: ["cache", "standalone", "types"],
36
37
  log: (m) => console.log(`[bertha] ${m}`),
37
38
  }).catch((e) => console.warn(`[bertha] Source maps weren't processed: ${String(e)}`));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bigbertha/sdk",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "Error reporting for bertha: browser, Node, edge and Next.js, with source maps by debug id.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -40,6 +40,34 @@
40
40
  "./build": "./dist/build/index.js",
41
41
  "./package.json": "./package.json"
42
42
  },
43
+ "typesVersions": {
44
+ "*": {
45
+ "browser": [
46
+ "dist/browser/index.d.ts"
47
+ ],
48
+ "node": [
49
+ "dist/node/index.d.ts"
50
+ ],
51
+ "edge": [
52
+ "dist/edge/index.d.ts"
53
+ ],
54
+ "next": [
55
+ "dist/next/index.d.ts"
56
+ ],
57
+ "next/client": [
58
+ "dist/next/client.d.ts"
59
+ ],
60
+ "next/config": [
61
+ "dist/next/config.d.ts"
62
+ ],
63
+ "vite": [
64
+ "dist/vite/index.d.ts"
65
+ ],
66
+ "build": [
67
+ "dist/build/index.d.ts"
68
+ ]
69
+ }
70
+ },
43
71
  "engines": {
44
72
  "node": ">=20"
45
73
  },