@logbrew/react-native 0.1.7 → 0.1.8
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 +41 -2
- package/metro.cjs +89 -5
- package/metro.d.cts +24 -4
- package/metro.d.ts +24 -4
- package/metro.js +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -229,7 +229,30 @@ The callbacks match the common `(id, rejection)` and `(id)` tracker shapes, but
|
|
|
229
229
|
|
|
230
230
|
`onUnhandled()` emits a fixed-content issue and deliberately does not inspect or send the rejection value, raw runtime rejection ID, error message, stack, Promise, or arbitrary metadata. Numeric IDs and bounded strings are retained only in local memory for duplicate suppression and `onHandled()` health. The set defaults to 128 entries and can be configured from 1 to 1024 with `maxTrackedRejections`; old entries are evicted. Missing or unsafe IDs still produce an untracked privacy-safe report. `onHandled()` updates local health only and cannot retract an issue that was already queued. Use `health()` for frozen counters and the last bounded outcome. Capture and diagnostic failures never escape these callbacks.
|
|
231
231
|
|
|
232
|
-
When you prepare
|
|
232
|
+
When you prepare Expo release artifacts, create the Expo Metro config through
|
|
233
|
+
LogBrew. The helper uses Expo's pre-serialization hook, so each production
|
|
234
|
+
bundle receives Expo's final Debug ID before Hermes compilation. Apply
|
|
235
|
+
the React Native Worklets bundle-mode transform after
|
|
236
|
+
`getLogBrewExpoConfig()`, as shown:
|
|
237
|
+
|
|
238
|
+
```js
|
|
239
|
+
// metro.config.js
|
|
240
|
+
const { getLogBrewExpoConfig } = require("@logbrew/react-native/metro");
|
|
241
|
+
const { getBundleModeMetroConfig } = require("react-native-worklets/bundleMode");
|
|
242
|
+
|
|
243
|
+
const config = getLogBrewExpoConfig(__dirname);
|
|
244
|
+
|
|
245
|
+
module.exports = getBundleModeMetroConfig(config);
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
Pass normal Expo Metro options directly to the helper. If the app owns a
|
|
249
|
+
custom `getDefaultConfig` function, pass it as the `getDefaultConfig` option.
|
|
250
|
+
Existing `unstable_beforeAssetSerializationPlugins` are preserved and run
|
|
251
|
+
before LogBrew's plugin.
|
|
252
|
+
|
|
253
|
+
Bare React Native apps should instead wrap the completed app-owned Metro
|
|
254
|
+
config once. Production bundles and source maps receive one matching Debug ID,
|
|
255
|
+
while development and hot-reload serialization remain unchanged:
|
|
233
256
|
|
|
234
257
|
```js
|
|
235
258
|
// metro.config.js
|
|
@@ -241,6 +264,11 @@ module.exports = withLogBrewMetroConfig(
|
|
|
241
264
|
);
|
|
242
265
|
```
|
|
243
266
|
|
|
267
|
+
Do not apply `withLogBrewMetroConfig()` to an Expo config. Expo static exports
|
|
268
|
+
return asset sets and can produce Hermes bytecode; the bare React Native
|
|
269
|
+
serializer wrapper stops with a recovery message that points to
|
|
270
|
+
`getLogBrewExpoConfig()` rather than producing an untraceable build.
|
|
271
|
+
|
|
244
272
|
Then use the same release identity when capturing the error. The Metro-injected runtime registry connects each matching parsed JavaScript frame to its Debug ID without another app option:
|
|
245
273
|
|
|
246
274
|
```js
|
|
@@ -255,7 +283,18 @@ captureReactNativeError(client, error, {
|
|
|
255
283
|
});
|
|
256
284
|
```
|
|
257
285
|
|
|
258
|
-
The
|
|
286
|
+
The Expo helper and bare wrapper add no network behavior. The bare wrapper
|
|
287
|
+
composes an existing custom serializer and is idempotent. A string-returning
|
|
288
|
+
custom serializer may preserve Metro's default bundle code; a serializer that
|
|
289
|
+
changes code must return `{ code, map }` so LogBrew cannot attach a mismatched
|
|
290
|
+
source map. If an advanced build pipeline cannot use either integration,
|
|
291
|
+
`debugIdMap` remains an explicit override and takes precedence over runtime
|
|
292
|
+
discovery. LogBrew records up to 32 ordered path-only generated frames with
|
|
293
|
+
matching Debug IDs, release/environment/service/runtime, and active trace IDs
|
|
294
|
+
when available. It strips query strings, hashes, hosts, and local absolute
|
|
295
|
+
paths from React Native frame data; raw stack text is still opt-in with
|
|
296
|
+
`includeStack: true`. Hosted source-map lookup remains backend-owned and
|
|
297
|
+
requires the matching uploaded release artifact.
|
|
259
298
|
|
|
260
299
|
## Provider And Hooks
|
|
261
300
|
|
package/metro.cjs
CHANGED
|
@@ -2,12 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
const crypto = require("node:crypto");
|
|
4
4
|
const { Buffer } = require("node:buffer");
|
|
5
|
+
const { createRequire } = require("node:module");
|
|
6
|
+
const path = require("node:path");
|
|
5
7
|
|
|
6
8
|
const DEBUG_ID_PLACEHOLDER = "__LOGBREW_REACT_NATIVE_DEBUG_ID__";
|
|
7
9
|
const DEBUG_ID_MODULE_PATH = "__logbrew_debug_id__";
|
|
8
10
|
const DEBUG_ID_REGISTRY_NAME = "@logbrew/react-native/debug-ids";
|
|
9
11
|
const DEBUG_ID_KEYS = ["debug_id", "debugId", "debugID", "x_debug_id"];
|
|
10
12
|
const DEBUG_ID_COMMENT_RE = /(?:\/\/[#@]|\/\*[#@])\s*debugId=[^\r\n]*/iu;
|
|
13
|
+
const DEBUG_ID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu;
|
|
11
14
|
const SOURCE_MAPPING_COMMENT_RE = /(?:\/\/[#@]|\/\*[#@])\s*sourceMappingURL=[^\r\n]*/giu;
|
|
12
15
|
const WRAPPED_SERIALIZER = Symbol.for("@logbrew/react-native/metro-serializer");
|
|
13
16
|
|
|
@@ -35,8 +38,8 @@ function countLines(source) {
|
|
|
35
38
|
return source === "" ? 0 : source.split("\n").length;
|
|
36
39
|
}
|
|
37
40
|
|
|
38
|
-
function createDebugIdModule() {
|
|
39
|
-
const code = runtimeDebugIdSnippet(
|
|
41
|
+
function createDebugIdModule(debugId = DEBUG_ID_PLACEHOLDER) {
|
|
42
|
+
const code = runtimeDebugIdSnippet(debugId);
|
|
40
43
|
return {
|
|
41
44
|
dependencies: new Map(),
|
|
42
45
|
getSource: () => Buffer.from(code),
|
|
@@ -55,14 +58,14 @@ function createDebugIdModule() {
|
|
|
55
58
|
};
|
|
56
59
|
}
|
|
57
60
|
|
|
58
|
-
function prependDebugIdModule(preModules) {
|
|
61
|
+
function prependDebugIdModule(preModules, debugId = DEBUG_ID_PLACEHOLDER) {
|
|
59
62
|
if (!Array.isArray(preModules)) {
|
|
60
63
|
throw configurationError("LogBrew Metro serializer expected preModules to be an array");
|
|
61
64
|
}
|
|
62
65
|
if (preModules.some((module) => module?.path === DEBUG_ID_MODULE_PATH)) {
|
|
63
66
|
return preModules;
|
|
64
67
|
}
|
|
65
|
-
const debugIdModule = createDebugIdModule();
|
|
68
|
+
const debugIdModule = createDebugIdModule(debugId);
|
|
66
69
|
if (preModules[0]?.path === "__prelude__") {
|
|
67
70
|
return [preModules[0], debugIdModule, ...preModules.slice(1)];
|
|
68
71
|
}
|
|
@@ -130,7 +133,12 @@ function sourceWithDebugId(source, debugId) {
|
|
|
130
133
|
}
|
|
131
134
|
|
|
132
135
|
function productionResult(result) {
|
|
133
|
-
if (
|
|
136
|
+
if (Array.isArray(result)) {
|
|
137
|
+
throw configurationError(
|
|
138
|
+
"LogBrew Metro received Expo static assets; use getLogBrewExpoConfig instead of withLogBrewMetroConfig for Expo projects",
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
if (!result || typeof result !== "object") {
|
|
134
142
|
throw configurationError("LogBrew Metro production serializer must return { code, map }");
|
|
135
143
|
}
|
|
136
144
|
if (typeof result.code !== "string") {
|
|
@@ -156,6 +164,81 @@ function productionResult(result) {
|
|
|
156
164
|
};
|
|
157
165
|
}
|
|
158
166
|
|
|
167
|
+
function requireExpoPluginOptions(options) {
|
|
168
|
+
requireOptions(options);
|
|
169
|
+
if (
|
|
170
|
+
options.unstable_beforeAssetSerializationPlugins !== undefined &&
|
|
171
|
+
(!Array.isArray(options.unstable_beforeAssetSerializationPlugins) ||
|
|
172
|
+
options.unstable_beforeAssetSerializationPlugins.some((plugin) => typeof plugin !== "function"))
|
|
173
|
+
) {
|
|
174
|
+
throw configurationError(
|
|
175
|
+
"LogBrew Expo option unstable_beforeAssetSerializationPlugins must be an array of functions",
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
if (options.getDefaultConfig !== undefined && typeof options.getDefaultConfig !== "function") {
|
|
179
|
+
throw configurationError("LogBrew Expo option getDefaultConfig must be a function");
|
|
180
|
+
}
|
|
181
|
+
return options;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function createLogBrewExpoDebugIdPlugin(options = {}) {
|
|
185
|
+
requireOptions(options);
|
|
186
|
+
return (input) => {
|
|
187
|
+
if (!input || Array.isArray(input) || typeof input !== "object") {
|
|
188
|
+
throw configurationError("LogBrew Expo Debug ID plugin requires a serialization input object");
|
|
189
|
+
}
|
|
190
|
+
const preModules = input.premodules;
|
|
191
|
+
if (!Array.isArray(preModules)) {
|
|
192
|
+
throw configurationError("LogBrew Expo Debug ID plugin expected premodules to be an array");
|
|
193
|
+
}
|
|
194
|
+
if (options.enabled === false || input.debugId === undefined || input.debugId === null) {
|
|
195
|
+
return preModules;
|
|
196
|
+
}
|
|
197
|
+
if (typeof input.debugId !== "string" || !DEBUG_ID_RE.test(input.debugId)) {
|
|
198
|
+
throw configurationError("LogBrew Expo Debug ID plugin requires a valid Expo Debug ID");
|
|
199
|
+
}
|
|
200
|
+
return prependDebugIdModule(preModules, input.debugId.toLowerCase());
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function loadExpoGetDefaultConfig(projectRoot) {
|
|
205
|
+
let expoMetroConfig;
|
|
206
|
+
try {
|
|
207
|
+
const projectRequire = createRequire(path.join(projectRoot, "package.json"));
|
|
208
|
+
expoMetroConfig = projectRequire("expo/metro-config");
|
|
209
|
+
} catch (error) {
|
|
210
|
+
throw configurationError(
|
|
211
|
+
"LogBrew could not load expo/metro-config from the app; install a supported Expo SDK or pass getDefaultConfig",
|
|
212
|
+
{ cause: error },
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
if (typeof expoMetroConfig?.getDefaultConfig !== "function") {
|
|
216
|
+
throw configurationError("LogBrew could not resolve getDefaultConfig from expo/metro-config");
|
|
217
|
+
}
|
|
218
|
+
return expoMetroConfig.getDefaultConfig;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function getLogBrewExpoConfig(projectRoot, options = {}) {
|
|
222
|
+
if (typeof projectRoot !== "string" || projectRoot.trim() === "") {
|
|
223
|
+
throw configurationError("getLogBrewExpoConfig requires a non-empty Expo project root");
|
|
224
|
+
}
|
|
225
|
+
requireExpoPluginOptions(options);
|
|
226
|
+
const root = path.resolve(projectRoot);
|
|
227
|
+
const {
|
|
228
|
+
enabled = true,
|
|
229
|
+
getDefaultConfig = loadExpoGetDefaultConfig(root),
|
|
230
|
+
unstable_beforeAssetSerializationPlugins = [],
|
|
231
|
+
...expoOptions
|
|
232
|
+
} = options;
|
|
233
|
+
const plugins = enabled
|
|
234
|
+
? [...unstable_beforeAssetSerializationPlugins, createLogBrewExpoDebugIdPlugin()]
|
|
235
|
+
: [...unstable_beforeAssetSerializationPlugins];
|
|
236
|
+
return getDefaultConfig(root, {
|
|
237
|
+
...expoOptions,
|
|
238
|
+
unstable_beforeAssetSerializationPlugins: plugins,
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
|
|
159
242
|
function requireMetroModule(privatePath, sourcePath) {
|
|
160
243
|
try {
|
|
161
244
|
return require(privatePath);
|
|
@@ -305,6 +388,7 @@ function withLogBrewMetroConfig(config, options = {}) {
|
|
|
305
388
|
|
|
306
389
|
module.exports = {
|
|
307
390
|
createLogBrewMetroSerializer,
|
|
391
|
+
getLogBrewExpoConfig,
|
|
308
392
|
withLogBrewMetroConfig,
|
|
309
393
|
default: withLogBrewMetroConfig,
|
|
310
394
|
};
|
package/metro.d.cts
CHANGED
|
@@ -14,21 +14,41 @@ export type LogBrewMetroSerializer<TModule = unknown, TGraph = unknown, TOptions
|
|
|
14
14
|
export type LogBrewMetroConfig = {
|
|
15
15
|
serializer?: {
|
|
16
16
|
customSerializer?: unknown;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
[key: string]: unknown;
|
|
20
|
-
};
|
|
17
|
+
} | Record<string, unknown>;
|
|
18
|
+
} | Record<string, unknown>;
|
|
21
19
|
|
|
22
20
|
export type LogBrewMetroConfigOptions = {
|
|
23
21
|
enabled?: boolean;
|
|
24
22
|
};
|
|
25
23
|
|
|
24
|
+
export type LogBrewExpoSerializationInput<TModule = unknown, TGraph = unknown> = {
|
|
25
|
+
debugId?: string;
|
|
26
|
+
graph: TGraph;
|
|
27
|
+
premodules: TModule[];
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export type LogBrewExpoDebugIdPlugin<TModule = unknown, TGraph = unknown> = (
|
|
31
|
+
input: LogBrewExpoSerializationInput<TModule, TGraph>,
|
|
32
|
+
) => TModule[];
|
|
33
|
+
|
|
34
|
+
export type LogBrewExpoConfigOptions<TConfig extends LogBrewMetroConfig = LogBrewMetroConfig> = {
|
|
35
|
+
enabled?: boolean;
|
|
36
|
+
getDefaultConfig?: (...args: never[]) => TConfig;
|
|
37
|
+
unstable_beforeAssetSerializationPlugins?: LogBrewExpoDebugIdPlugin[];
|
|
38
|
+
[key: string]: unknown;
|
|
39
|
+
};
|
|
40
|
+
|
|
26
41
|
export declare function createLogBrewMetroSerializer<TModule, TGraph, TOptions>(
|
|
27
42
|
customSerializer: LogBrewMetroSerializer<TModule, TGraph, TOptions>,
|
|
28
43
|
): LogBrewMetroSerializer<TModule, TGraph, TOptions>;
|
|
29
44
|
|
|
30
45
|
export declare function createLogBrewMetroSerializer(customSerializer?: null): LogBrewMetroSerializer;
|
|
31
46
|
|
|
47
|
+
export declare function getLogBrewExpoConfig<TConfig extends LogBrewMetroConfig = LogBrewMetroConfig>(
|
|
48
|
+
projectRoot: string,
|
|
49
|
+
options?: LogBrewExpoConfigOptions<TConfig>,
|
|
50
|
+
): TConfig;
|
|
51
|
+
|
|
32
52
|
export declare function withLogBrewMetroConfig<T extends LogBrewMetroConfig>(
|
|
33
53
|
config: T,
|
|
34
54
|
options?: LogBrewMetroConfigOptions,
|
package/metro.d.ts
CHANGED
|
@@ -14,21 +14,41 @@ export type LogBrewMetroSerializer<TModule = unknown, TGraph = unknown, TOptions
|
|
|
14
14
|
export type LogBrewMetroConfig = {
|
|
15
15
|
serializer?: {
|
|
16
16
|
customSerializer?: unknown;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
[key: string]: unknown;
|
|
20
|
-
};
|
|
17
|
+
} | Record<string, unknown>;
|
|
18
|
+
} | Record<string, unknown>;
|
|
21
19
|
|
|
22
20
|
export type LogBrewMetroConfigOptions = {
|
|
23
21
|
enabled?: boolean;
|
|
24
22
|
};
|
|
25
23
|
|
|
24
|
+
export type LogBrewExpoSerializationInput<TModule = unknown, TGraph = unknown> = {
|
|
25
|
+
debugId?: string;
|
|
26
|
+
graph: TGraph;
|
|
27
|
+
premodules: TModule[];
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export type LogBrewExpoDebugIdPlugin<TModule = unknown, TGraph = unknown> = (
|
|
31
|
+
input: LogBrewExpoSerializationInput<TModule, TGraph>,
|
|
32
|
+
) => TModule[];
|
|
33
|
+
|
|
34
|
+
export type LogBrewExpoConfigOptions<TConfig extends LogBrewMetroConfig = LogBrewMetroConfig> = {
|
|
35
|
+
enabled?: boolean;
|
|
36
|
+
getDefaultConfig?: (...args: never[]) => TConfig;
|
|
37
|
+
unstable_beforeAssetSerializationPlugins?: LogBrewExpoDebugIdPlugin[];
|
|
38
|
+
[key: string]: unknown;
|
|
39
|
+
};
|
|
40
|
+
|
|
26
41
|
export declare function createLogBrewMetroSerializer<TModule, TGraph, TOptions>(
|
|
27
42
|
customSerializer: LogBrewMetroSerializer<TModule, TGraph, TOptions>,
|
|
28
43
|
): LogBrewMetroSerializer<TModule, TGraph, TOptions>;
|
|
29
44
|
|
|
30
45
|
export declare function createLogBrewMetroSerializer(customSerializer?: null): LogBrewMetroSerializer;
|
|
31
46
|
|
|
47
|
+
export declare function getLogBrewExpoConfig<TConfig extends LogBrewMetroConfig = LogBrewMetroConfig>(
|
|
48
|
+
projectRoot: string,
|
|
49
|
+
options?: LogBrewExpoConfigOptions<TConfig>,
|
|
50
|
+
): TConfig;
|
|
51
|
+
|
|
32
52
|
export declare function withLogBrewMetroConfig<T extends LogBrewMetroConfig>(
|
|
33
53
|
config: T,
|
|
34
54
|
options?: LogBrewMetroConfigOptions,
|
package/metro.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import metro from "./metro.cjs";
|
|
2
2
|
|
|
3
3
|
export const createLogBrewMetroSerializer = metro.createLogBrewMetroSerializer;
|
|
4
|
+
export const getLogBrewExpoConfig = metro.getLogBrewExpoConfig;
|
|
4
5
|
export const withLogBrewMetroConfig = metro.withLogBrewMetroConfig;
|
|
5
6
|
|
|
6
7
|
export default withLogBrewMetroConfig;
|