@bigbertha/sdk 0.1.3 → 0.1.5
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 +15 -2
- package/dist/build/index.d.ts +6 -3
- package/dist/build/index.js +14 -7
- package/dist/core/version.d.ts +1 -1
- package/dist/core/version.js +1 -1
- package/dist/edge/index.js +1 -1
- package/dist/next/client.js +1 -1
- package/dist/next/config.d.ts +7 -2
- package/dist/next/config.js +10 -3
- package/dist/node/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -55,7 +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`
|
|
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.
|
|
63
|
+
|
|
64
|
+
For your own options (`beforeSend`, `tags`, `sampleRate`), call `init` from
|
|
65
|
+
`@bigbertha/sdk/browser` in `instrumentation-client.ts` instead of importing
|
|
66
|
+
`next/client`, and `init` from `@bigbertha/sdk/node` in `register()`. The build plugin
|
|
67
|
+
works the same either way, and it keeps the debug ids another tool (such as Sentry's
|
|
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.
|
|
59
72
|
|
|
60
73
|
## Vite (browser)
|
|
61
74
|
|
|
@@ -118,7 +131,7 @@ await flush()
|
|
|
118
131
|
| --- | --- | --- |
|
|
119
132
|
| `key`, `url` | from env (Node, edge) | Required in the browser. |
|
|
120
133
|
| `release` | stamped at build time | The plugins stamp it from `BERTHA_RELEASE`, the CI's commit sha or `git HEAD`. |
|
|
121
|
-
| `environment` | `BERTHA_ENVIRONMENT` or `NODE_ENV` (Node, edge), else production | Free text is mapped to production, staging or development. |
|
|
134
|
+
| `environment` | `BERTHA_ENVIRONMENT`, `VERCEL_ENV` or `NODE_ENV` (Node, edge; `withBertha` stamps it for the browser), else production | Free text is mapped to production, staging or development. |
|
|
122
135
|
| `sampleRate` | `1` | Share of events to send. |
|
|
123
136
|
| `beforeSend` | | Change an event, or return `null` to drop it. |
|
|
124
137
|
| `scrub` | `true` | Redact emails, bearer tokens and secret query values. |
|
package/dist/build/index.d.ts
CHANGED
|
@@ -32,8 +32,11 @@ export interface Report {
|
|
|
32
32
|
export declare function processDirectory(o: ProcessOptions): Promise<Report>;
|
|
33
33
|
/** A stable UUID from the bundle's content, so rebuilding the same code gives the same id. */
|
|
34
34
|
export declare function idFor(code: string): string;
|
|
35
|
-
/**
|
|
36
|
-
|
|
35
|
+
/**
|
|
36
|
+
* The line appended to a bundle. Runs once when the bundle loads; never throws.
|
|
37
|
+
* `comment: false` leaves out the `//# debugId=` comment, for a bundle that has one.
|
|
38
|
+
*/
|
|
39
|
+
export declare function snippet(debugId: string, release?: string, comment?: boolean): string;
|
|
37
40
|
/** Appends the snippet, before a trailing sourceMappingURL comment if there is one. */
|
|
38
|
-
export declare function stamp(code: string, debugId: string, release?: string): string;
|
|
41
|
+
export declare function stamp(code: string, debugId: string, release?: string, comment?: boolean): string;
|
|
39
42
|
export declare function reason(res: Response): Promise<string>;
|
package/dist/build/index.js
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
// to bertha, and take them out of the output so they aren't served.
|
|
3
3
|
//
|
|
4
4
|
// The id goes in a line appended to the bundle. Appending (never prepending) keeps
|
|
5
|
-
// every existing mapping valid.
|
|
5
|
+
// every existing mapping valid. A bundle that already has a debug id (from Sentry's
|
|
6
|
+
// plugin, or Rollup's `sourcemapDebugIds`) keeps it, and still gets bertha's line. At runtime that line records the bundle's own URL
|
|
6
7
|
// from `new Error().stack` against its id, so events can name the map for each frame
|
|
7
8
|
// wherever the file was served from.
|
|
8
9
|
import { createHash } from "node:crypto";
|
|
@@ -15,6 +16,8 @@ const JS = /\.(?:m|c)?js$/;
|
|
|
15
16
|
const ORPHAN_MAP = /\.(?:m|c)?js\.map$/;
|
|
16
17
|
const MAP_COMMENT = /\n?\/\/[#@] sourceMappingURL=(\S+)[ \t]*\r?\n?$/;
|
|
17
18
|
const DEBUG_ID_COMMENT = /\/\/# debugId=([0-9a-fA-F-]{36})/;
|
|
19
|
+
/** In every bundle this step has already stamped, so a second run changes nothing. */
|
|
20
|
+
const REGISTERED = "g.__berthaIds=";
|
|
18
21
|
const CONCURRENCY = 4;
|
|
19
22
|
const UPLOAD_TIMEOUT_MS = 60_000;
|
|
20
23
|
export async function processDirectory(o) {
|
|
@@ -44,7 +47,7 @@ export async function processDirectory(o) {
|
|
|
44
47
|
const json = JSON.parse(map.text);
|
|
45
48
|
json.debugId = debugId;
|
|
46
49
|
const mapText = JSON.stringify(json);
|
|
47
|
-
let out =
|
|
50
|
+
let out = code.includes(REGISTERED) ? code : stamp(code, debugId, o.release, !DEBUG_ID_COMMENT.test(code));
|
|
48
51
|
if (keep && map.path)
|
|
49
52
|
await writeFile(map.path, mapText);
|
|
50
53
|
else if (!keep) {
|
|
@@ -116,18 +119,22 @@ export function idFor(code) {
|
|
|
116
119
|
const variant = ((parseInt(h[16], 16) & 0x3) | 0x8).toString(16);
|
|
117
120
|
return `${h.slice(0, 8)}-${h.slice(8, 12)}-4${h.slice(13, 16)}-${variant}${h.slice(17, 20)}-${h.slice(20, 32)}`;
|
|
118
121
|
}
|
|
119
|
-
/**
|
|
120
|
-
|
|
122
|
+
/**
|
|
123
|
+
* The line appended to a bundle. Runs once when the bundle loads; never throws.
|
|
124
|
+
* `comment: false` leaves out the `//# debugId=` comment, for a bundle that has one.
|
|
125
|
+
*/
|
|
126
|
+
export function snippet(debugId, release, comment = true) {
|
|
121
127
|
const r = release ? `g.__berthaRelease=${JSON.stringify(release)}` : "";
|
|
122
128
|
return (`;!function(){try{var g=typeof globalThis<"u"?globalThis:self,s=(new Error).stack;` +
|
|
123
|
-
`s&&((g.__berthaIds
|
|
129
|
+
`s&&((${REGISTERED}g.__berthaIds||{})[s]="${debugId}");${r}}catch(e){}}();\n` +
|
|
130
|
+
(comment ? `//# debugId=${debugId}\n` : ""));
|
|
124
131
|
}
|
|
125
132
|
/** Appends the snippet, before a trailing sourceMappingURL comment if there is one. */
|
|
126
|
-
export function stamp(code, debugId, release) {
|
|
133
|
+
export function stamp(code, debugId, release, comment = true) {
|
|
127
134
|
const m = MAP_COMMENT.exec(code);
|
|
128
135
|
const body = m ? code.slice(0, m.index) : code;
|
|
129
136
|
const tail = m ? m[0].replace(/^\n?/, "") : "";
|
|
130
|
-
return `${body.endsWith("\n") ? body : `${body}\n`}${snippet(debugId, release)}${tail}`;
|
|
137
|
+
return `${body.endsWith("\n") ? body : `${body}\n`}${snippet(debugId, release, comment)}${tail}`;
|
|
131
138
|
}
|
|
132
139
|
async function upload(o, q, map) {
|
|
133
140
|
const f = o.fetch ?? fetch;
|
package/dist/core/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "0.1.
|
|
1
|
+
export declare const VERSION = "0.1.5";
|
package/dist/core/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "0.1.
|
|
1
|
+
export const VERSION = "0.1.5";
|
package/dist/edge/index.js
CHANGED
|
@@ -18,7 +18,7 @@ export function init(options = {}) {
|
|
|
18
18
|
key,
|
|
19
19
|
url,
|
|
20
20
|
release: options.release ?? firstEnv("BERTHA_RELEASE"),
|
|
21
|
-
environment: options.environment ?? firstEnv("BERTHA_ENVIRONMENT", "NODE_ENV"),
|
|
21
|
+
environment: options.environment ?? firstEnv("BERTHA_ENVIRONMENT", "VERCEL_ENV", "NODE_ENV"),
|
|
22
22
|
}, fetchTransport({ url, key, gzip: streamGzip }), { name: "bertha.edge", version: VERSION }, { runtime: "Edge" });
|
|
23
23
|
setClient(client);
|
|
24
24
|
return client;
|
package/dist/next/client.js
CHANGED
package/dist/next/config.d.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
export interface BerthaNextOptions {
|
|
2
2
|
release?: string;
|
|
3
|
-
/**
|
|
4
|
-
|
|
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;
|
package/dist/next/config.js
CHANGED
|
@@ -1,18 +1,25 @@
|
|
|
1
1
|
// @bigbertha/sdk/next/config, for next.config.ts:
|
|
2
2
|
// export default withBertha(nextConfig)
|
|
3
|
-
// Turns on source maps for production builds, stamps the release
|
|
3
|
+
// Turns on source maps for production builds, stamps the release and environment
|
|
4
|
+
// (BERTHA_ENVIRONMENT, else Vercel's production or preview), and after each
|
|
4
5
|
// build gives bundles debug ids, uploads the maps and removes them from `.next`.
|
|
5
6
|
import { join } from "node:path";
|
|
6
7
|
import { detectRelease, processDirectory } from "../build/index.js";
|
|
7
8
|
import { firstEnv } from "../core/env.js";
|
|
9
|
+
export const keepServerMaps = (file) => !file.startsWith("static/");
|
|
8
10
|
export function withBertha(config = {}, options = {}) {
|
|
9
11
|
const c = config;
|
|
10
12
|
const release = options.release ?? detectRelease();
|
|
13
|
+
const environment = firstEnv("BERTHA_ENVIRONMENT", "VERCEL_ENV");
|
|
11
14
|
const previous = c.compiler?.runAfterProductionCompile;
|
|
12
15
|
const next = {
|
|
13
16
|
...c,
|
|
14
17
|
productionBrowserSourceMaps: true,
|
|
15
|
-
env: {
|
|
18
|
+
env: {
|
|
19
|
+
...c.env,
|
|
20
|
+
...(release ? { BERTHA_RELEASE: release } : {}),
|
|
21
|
+
...(environment ? { BERTHA_ENVIRONMENT: environment } : {}),
|
|
22
|
+
},
|
|
16
23
|
experimental: { ...c.experimental, serverSourceMaps: true },
|
|
17
24
|
compiler: {
|
|
18
25
|
...c.compiler,
|
|
@@ -25,7 +32,7 @@ export function withBertha(config = {}, options = {}) {
|
|
|
25
32
|
release,
|
|
26
33
|
url: firstEnv("BERTHA_URL", "NEXT_PUBLIC_BERTHA_URL"),
|
|
27
34
|
uploadKey: firstEnv("BERTHA_UPLOAD_KEY"),
|
|
28
|
-
keepMaps: options.keepMaps,
|
|
35
|
+
keepMaps: options.keepMaps ?? keepServerMaps,
|
|
29
36
|
skip: ["cache", "standalone", "types"],
|
|
30
37
|
log: (m) => console.log(`[bertha] ${m}`),
|
|
31
38
|
}).catch((e) => console.warn(`[bertha] Source maps weren't processed: ${String(e)}`));
|
package/dist/node/index.js
CHANGED
|
@@ -25,7 +25,7 @@ export function init(options = {}) {
|
|
|
25
25
|
key,
|
|
26
26
|
url,
|
|
27
27
|
release: options.release ?? firstEnv("BERTHA_RELEASE"),
|
|
28
|
-
environment: options.environment ?? firstEnv("BERTHA_ENVIRONMENT", "NODE_ENV"),
|
|
28
|
+
environment: options.environment ?? firstEnv("BERTHA_ENVIRONMENT", "VERCEL_ENV", "NODE_ENV"),
|
|
29
29
|
};
|
|
30
30
|
const client = new Client(opts, fetchTransport({ url, key, gzip: async (body) => new Uint8Array(gzipSync(body)) }), { name: "bertha.node", version: VERSION }, { runtime: `Node ${process.versions.node}`, os: `${platform()} ${arch()}` });
|
|
31
31
|
setClient(client);
|