@logbrew/react-native 0.1.39 → 0.1.41

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.
Files changed (99) hide show
  1. package/README.md +3 -3
  2. package/android-native-diagnostics.d.ts +15 -5
  3. package/android-native-diagnostics.js +170 -94
  4. package/apollo.cjs +435 -226
  5. package/apollo.d.cts +2 -70
  6. package/apollo.d.ts +24 -12
  7. package/apollo.js +438 -221
  8. package/apple-native-diagnostics-config.js +176 -0
  9. package/apple-native-diagnostics-context.js +232 -0
  10. package/apple-native-diagnostics-module.js +229 -0
  11. package/apple-native-diagnostics.d.ts +42 -11
  12. package/apple-native-diagnostics.js +60 -389
  13. package/expo.cjs +29 -16
  14. package/expo.d.ts +10 -9
  15. package/expo.js +4 -3
  16. package/fatal-admission.cjs +113 -0
  17. package/fatal-record.cjs +317 -0
  18. package/fatal-replay.cjs +297 -508
  19. package/global-errors-capture.cjs +369 -0
  20. package/global-errors-event.cjs +174 -0
  21. package/global-errors-support.cjs +128 -0
  22. package/global-errors.cjs +75 -351
  23. package/global-errors.d.cts +29 -278
  24. package/global-errors.d.ts +57 -27
  25. package/global-errors.js +7 -2
  26. package/global-errors.native.js +83 -48
  27. package/index-breadcrumbs.cjs +139 -0
  28. package/index-errors.cjs +167 -0
  29. package/index-events.cjs +365 -0
  30. package/index-navigation.cjs +327 -0
  31. package/index-random.cjs +120 -0
  32. package/index-react.cjs +189 -0
  33. package/index-spans.cjs +190 -0
  34. package/index-trace-fetch.cjs +322 -0
  35. package/index-trace.cjs +335 -0
  36. package/index-transport.cjs +201 -0
  37. package/index-values.cjs +232 -0
  38. package/index.cjs +97 -1245
  39. package/index.d.cts +2 -505
  40. package/index.d.ts +130 -469
  41. package/index.native.d.ts +146 -22
  42. package/index.native.js +184 -159
  43. package/instrumentation-fetch.cjs +113 -0
  44. package/instrumentation-install.cjs +241 -0
  45. package/instrumentation-runtime.cjs +65 -0
  46. package/instrumentation-teardown.cjs +93 -0
  47. package/instrumentation-values.cjs +282 -0
  48. package/instrumentation-xhr-request.cjs +298 -0
  49. package/instrumentation-xhr.cjs +233 -0
  50. package/instrumentation.cjs +110 -599
  51. package/instrumentation.d.cts +2 -84
  52. package/instrumentation.d.ts +22 -8
  53. package/ios/AppleDiagnostics/LBRNAppleNativeDiagnostics.swift +1 -1
  54. package/ios/GeneratedAppleDiagnostics/LogBrew/DeliveryLifecycle.swift +1 -1
  55. package/ios/GeneratedAppleDiagnostics/SOURCE-MANIFEST.json +1 -1
  56. package/lifecycle.cjs +181 -78
  57. package/lifecycle.d.cts +1 -50
  58. package/lifecycle.d.ts +17 -6
  59. package/metadata.cjs +279 -114
  60. package/metro-debug-id.cjs +296 -0
  61. package/metro-serializer.cjs +219 -0
  62. package/metro.cjs +153 -297
  63. package/metro.d.cts +2 -57
  64. package/metro.d.ts +27 -13
  65. package/metro.js +2 -3
  66. package/native-bridge-async.cjs +165 -0
  67. package/native-bridge-scope.cjs +148 -0
  68. package/native-bridge.cjs +83 -186
  69. package/native-bridge.d.cts +2 -94
  70. package/native-bridge.d.ts +28 -15
  71. package/native-client-bindings.js +230 -0
  72. package/native-diagnostics-values.js +120 -0
  73. package/native-module-lookup.js +31 -0
  74. package/native-null.js +3 -0
  75. package/null-value.cjs +4 -0
  76. package/package.json +43 -1
  77. package/persistent-delivery-store.js +247 -0
  78. package/persistent-delivery.native.js +183 -261
  79. package/promise-rejection-handlers.cjs +368 -0
  80. package/promise-rejections.cjs +169 -361
  81. package/react-native.config.js +3 -1
  82. package/release-artifacts-files.cjs +94 -0
  83. package/release-artifacts-options.cjs +182 -0
  84. package/release-artifacts.cjs +278 -207
  85. package/release-artifacts.d.cts +2 -55
  86. package/release-artifacts.d.ts +18 -7
  87. package/release-artifacts.js +2 -4
  88. package/resource-fetch-graphql.cjs +265 -0
  89. package/resource-fetch-size.cjs +156 -0
  90. package/resource-fetch.cjs +227 -428
  91. package/resource-fetch.d.cts +1 -60
  92. package/resource-fetch.d.ts +17 -6
  93. package/scripts/sync-apple-native-sources.mjs +101 -53
  94. package/types/capture.d.ts +95 -0
  95. package/types/config.d.ts +85 -0
  96. package/types/defaults.d.ts +55 -0
  97. package/types/events.d.ts +203 -0
  98. package/types/provider.d.ts +81 -0
  99. package/types/trace.d.ts +104 -0
@@ -0,0 +1,296 @@
1
+ "use strict";
2
+
3
+ const crypto = require("node:crypto");
4
+ const { Buffer } = require("node:buffer");
5
+
6
+ /**
7
+ * @typedef {(this: unknown, ...args: readonly unknown[]) => unknown} Callable
8
+ * @typedef {Error & { code: string }} ConfigurationError
9
+ */
10
+
11
+ const DEBUG_ID_PLACEHOLDER = "__LOGBREW_REACT_NATIVE_DEBUG_ID__";
12
+ const DEBUG_ID_MODULE_PATH = "__logbrew_debug_id__";
13
+ const DEBUG_ID_REGISTRY_NAME = "@logbrew/react-native/debug-ids";
14
+ const RUNTIME_DEBUG_ID_MARKER = "/*logbrew-runtime-debug-id*/";
15
+ const DEBUG_ID_KEYS = ["debug_id", "debugId", "debugID", "x_debug_id"];
16
+ const DEBUG_ID_COMMENT_RE = /(?:\/\/[#@]|\/\*[#@])\s*debugId=[^\r\n]*/iu;
17
+ const SOURCE_MAPPING_COMMENT_RE = /(?:\/\/[#@]|\/\*[#@])\s*sourceMappingURL=[^\r\n]*/giu;
18
+ const NO_LINES = 0;
19
+ const NO_MATCHES = 0;
20
+ const LAST = -1;
21
+ const FIRST = 0;
22
+ const SECOND = 1;
23
+ const PLACEHOLDER_PARTS = 2;
24
+ const DEBUG_ID_BYTES = 16;
25
+ const VERSION_BYTE = 6;
26
+ const VARIANT_BYTE = 8;
27
+ const LOW_NIBBLE = 16;
28
+ const VERSION_FIVE = 80;
29
+ const VARIANT_BITS = 64;
30
+ const RFC_4122_VARIANT = 128;
31
+ const TIME_LOW_END = 8;
32
+ const TIME_MID_END = 12;
33
+ const TIME_HIGH_END = 16;
34
+ const CLOCK_SEQ_END = 20;
35
+
36
+ /**
37
+ * @param {unknown} value
38
+ * @param {PropertyKey} key
39
+ * @returns {unknown}
40
+ */
41
+ function field(value, key) {
42
+ return (typeof value === "object" && value !== null) || typeof value === "function" ? Reflect.get(value, key) : undefined;
43
+ }
44
+
45
+ /**
46
+ * @param {unknown} value
47
+ * @returns {value is Callable}
48
+ */
49
+ function isCallable(value) {
50
+ return typeof value === "function";
51
+ }
52
+
53
+ /**
54
+ * @param {unknown} value
55
+ * @returns {value is Readonly<Record<string, unknown>>}
56
+ */
57
+ function isRecord(value) {
58
+ return typeof value === "object" && value !== null;
59
+ }
60
+
61
+ /**
62
+ * @param {unknown} value
63
+ * @returns {value is readonly unknown[]}
64
+ */
65
+ function isArray(value) {
66
+ return Array.isArray(value);
67
+ }
68
+
69
+ /**
70
+ * @param {string} message
71
+ * @param {Readonly<ErrorOptions>} [options]
72
+ * @returns {ConfigurationError}
73
+ */
74
+ function configurationError(message, options) {
75
+ return Object.assign(new Error(message, options), { code: "configuration_error" });
76
+ }
77
+
78
+ /**
79
+ * @param {string} debugId
80
+ * @returns {string}
81
+ */
82
+ function runtimeDebugIdSnippet(debugId) {
83
+ const embedded = `${RUNTIME_DEBUG_ID_MARKER}//# debugId=${debugId}`;
84
+ return `;(()=>{try{const d=${JSON.stringify(embedded)}.slice(-36),k=Symbol.for(${JSON.stringify(DEBUG_ID_REGISTRY_NAME)}),g=globalThis,r=g[k]||(g[k]=Object.create(null)),s=(new Error).stack;if(s){r[s]=d;const e=Object.keys(r);if(e.length>64)delete r[e[0]]}}catch{}})();`;
85
+ }
86
+
87
+ /**
88
+ * @param {string} source
89
+ * @returns {number}
90
+ */
91
+ function countLines(source) {
92
+ return source === "" ? NO_LINES : source.split("\n").length;
93
+ }
94
+
95
+ /**
96
+ * @param {string} [debugId]
97
+ * @returns {Readonly<Record<string, unknown>>}
98
+ */
99
+ function createDebugIdModule(debugId = DEBUG_ID_PLACEHOLDER) {
100
+ const code = runtimeDebugIdSnippet(debugId);
101
+ return {
102
+ dependencies: new Map(),
103
+ getSource: () => Buffer.from(code),
104
+ inverseDependencies: new Set(),
105
+ path: DEBUG_ID_MODULE_PATH,
106
+
107
+ output: [
108
+ {
109
+ type: "js/script/virtual",
110
+
111
+ data: {
112
+ code,
113
+ lineCount: countLines(code),
114
+ map: []
115
+ }
116
+ }
117
+ ]
118
+ };
119
+ }
120
+
121
+ /**
122
+ * @param {unknown} preModules
123
+ * @param {string} [debugId]
124
+ * @returns {readonly unknown[]}
125
+ */
126
+ function prependDebugIdModule(preModules, debugId = DEBUG_ID_PLACEHOLDER) {
127
+ if (!isArray(preModules)) {
128
+ throw configurationError("LogBrew Metro serializer expected preModules to be an array");
129
+ }
130
+ if (preModules.some((candidate) => field(candidate, "path") === DEBUG_ID_MODULE_PATH)) {
131
+ return preModules;
132
+ }
133
+ const debugIdModule = createDebugIdModule(debugId);
134
+ if (field(preModules[FIRST], "path") === "__prelude__") {
135
+ return [preModules[FIRST], debugIdModule, ...preModules.slice(SECOND)];
136
+ }
137
+ return [debugIdModule, ...preModules];
138
+ }
139
+
140
+ /**
141
+ * @param {unknown} graph
142
+ * @returns {boolean}
143
+ */
144
+ function isDevelopmentGraph(graph) {
145
+ const transformOptions = field(graph, "transformOptions");
146
+ return field(transformOptions, "hot") === true || field(transformOptions, "dev") === true;
147
+ }
148
+
149
+ /**
150
+ * @param {string} value
151
+ * @returns {unknown}
152
+ */
153
+ function parseSourceMapJson(value) {
154
+ try {
155
+ return JSON.parse(value);
156
+ } catch (error) {
157
+ throw configurationError(`LogBrew Metro production serializer returned invalid source map JSON: ${error instanceof Error ? error.message : String(error)}`);
158
+ }
159
+ }
160
+
161
+ /**
162
+ * @param {unknown} value
163
+ * @returns {Record<string, unknown>}
164
+ */
165
+ function parseSourceMap(value) {
166
+ if (typeof value !== "string" || value.trim() === "") {
167
+ throw configurationError("LogBrew Metro production serializer must return a non-empty source map string");
168
+ }
169
+ const sourceMap = parseSourceMapJson(value);
170
+ if (!isRecord(sourceMap) || Array.isArray(sourceMap)) {
171
+ throw configurationError("LogBrew Metro production serializer source map must be an object");
172
+ }
173
+ return { ...sourceMap };
174
+ }
175
+
176
+ /**
177
+ * @param {Readonly<Record<string, unknown>>} sourceMap
178
+ * @returns {string}
179
+ */
180
+ function canonicalSourceMap(sourceMap) {
181
+ const copy = { ...sourceMap };
182
+ for (const key of DEBUG_ID_KEYS) {
183
+ Reflect.deleteProperty(copy, key);
184
+ }
185
+ return JSON.stringify(copy);
186
+ }
187
+
188
+ /**
189
+ * @param {Buffer} bytes
190
+ * @returns {string}
191
+ */
192
+ function formatDebugId(bytes) {
193
+ const value = Buffer.from(bytes.subarray(FIRST, DEBUG_ID_BYTES));
194
+ value.writeUInt8((value.readUInt8(VERSION_BYTE) % LOW_NIBBLE) + VERSION_FIVE, VERSION_BYTE);
195
+ value.writeUInt8((value.readUInt8(VARIANT_BYTE) % VARIANT_BITS) + RFC_4122_VARIANT, VARIANT_BYTE);
196
+ const hex = value.toString("hex");
197
+ return `${hex.slice(FIRST, TIME_LOW_END)}-${hex.slice(TIME_LOW_END, TIME_MID_END)}-${hex.slice(TIME_MID_END, TIME_HIGH_END)}-${hex.slice(TIME_HIGH_END, CLOCK_SEQ_END)}-${hex.slice(CLOCK_SEQ_END)}`;
198
+ }
199
+
200
+ /**
201
+ * @param {string} code
202
+ * @param {Readonly<Record<string, unknown>>} sourceMap
203
+ * @returns {string}
204
+ */
205
+ function createDebugId(code, sourceMap) {
206
+ const digest = crypto
207
+ .createHash("sha256")
208
+ .update(code.split(DEBUG_ID_PLACEHOLDER).join(""))
209
+ .update("\0")
210
+ .update(canonicalSourceMap(sourceMap))
211
+ .digest();
212
+ return formatDebugId(digest);
213
+ }
214
+
215
+ /**
216
+ * @param {string} source
217
+ * @param {string} debugId
218
+ * @returns {string}
219
+ */
220
+ function sourceWithDebugId(source, debugId) {
221
+ const replaced = source.split(DEBUG_ID_PLACEHOLDER).join(debugId);
222
+ const debugLine = `//# debugId=${debugId}\n`;
223
+ const matches = [...replaced.matchAll(SOURCE_MAPPING_COMMENT_RE)];
224
+ const last = matches.at(LAST);
225
+ if (matches.length === NO_MATCHES || last === undefined) {
226
+ return `${replaced}${replaced.endsWith("\n") ? "" : "\n"}${debugLine}`;
227
+ }
228
+ const prefix = replaced.slice(FIRST, last.index);
229
+ const separator = prefix.endsWith("\n") || prefix.endsWith("\r") ? "" : "\n";
230
+ return `${prefix}${separator}${debugLine}${replaced.slice(last.index)}`;
231
+ }
232
+
233
+ /**
234
+ * @param {unknown} result
235
+ * @returns {Readonly<Record<string, unknown>>}
236
+ */
237
+ function requireResultObject(result) {
238
+ if (Array.isArray(result)) {
239
+ throw configurationError(
240
+ "LogBrew Metro received Expo static assets; use getLogBrewExpoConfig instead of withLogBrewMetroConfig for Expo projects"
241
+ );
242
+ }
243
+ if (!isRecord(result)) {
244
+ throw configurationError("LogBrew Metro production serializer must return { code, map }");
245
+ }
246
+ return result;
247
+ }
248
+
249
+ /**
250
+ * @param {Readonly<Record<string, unknown>>} result
251
+ * @returns {string}
252
+ */
253
+ function requireProductionCode(result) {
254
+ const { code } = result;
255
+ if (typeof code !== "string") {
256
+ throw configurationError("LogBrew Metro production serializer code must be a string");
257
+ }
258
+ if (code.split(DEBUG_ID_PLACEHOLDER).length !== PLACEHOLDER_PARTS) {
259
+ throw configurationError("LogBrew Metro production serializer must include the injected Debug ID module exactly once");
260
+ }
261
+ if (DEBUG_ID_COMMENT_RE.test(code.replace(`${RUNTIME_DEBUG_ID_MARKER}//# debugId=${DEBUG_ID_PLACEHOLDER}`, ""))) {
262
+ throw configurationError("LogBrew Metro production serializer already contains Debug ID metadata");
263
+ }
264
+ return code;
265
+ }
266
+
267
+ /**
268
+ * @param {unknown} result
269
+ * @returns {Record<string, unknown>}
270
+ */
271
+ function productionResult(result) {
272
+ const checked = requireResultObject(result);
273
+ const code = requireProductionCode(checked);
274
+ const sourceMap = parseSourceMap(checked["map"]);
275
+ if (DEBUG_ID_KEYS.some((key) => Object.hasOwn(sourceMap, key))) {
276
+ throw configurationError("LogBrew Metro production serializer already contains Debug ID metadata");
277
+ }
278
+ const debugId = createDebugId(code, sourceMap);
279
+ sourceMap["debug_id"] = debugId;
280
+ sourceMap["debugId"] = debugId;
281
+ return {
282
+ ...checked,
283
+ code: sourceWithDebugId(code, debugId),
284
+ map: JSON.stringify(sourceMap)
285
+ };
286
+ }
287
+
288
+ module.exports = {
289
+ configurationError,
290
+ field,
291
+ isCallable,
292
+ isDevelopmentGraph,
293
+ isRecord,
294
+ prependDebugIdModule,
295
+ productionResult
296
+ };
@@ -0,0 +1,219 @@
1
+ "use strict";
2
+
3
+ const { createRequire } = require("node:module");
4
+ const { configurationError, field, isCallable, isDevelopmentGraph } = require("./metro-debug-id.cjs");
5
+
6
+ /**
7
+ * @typedef {(this: unknown, ...args: readonly unknown[]) => unknown} Callable
8
+ * @typedef {(entryPoint: unknown, preModules: unknown, graph: unknown, options: unknown) => Promise<unknown>} MetroSerializer
9
+ */
10
+
11
+ /**
12
+ * @param {string} privatePath
13
+ * @param {string} sourcePath
14
+ * @returns {unknown}
15
+ */
16
+ function requireMetroModule(privatePath, sourcePath) {
17
+ try {
18
+ return require(privatePath);
19
+ } catch (privateError) {
20
+ try {
21
+ return require(sourcePath);
22
+ } catch {
23
+ throw configurationError(
24
+ `LogBrew Metro could not load ${privatePath}; install a supported React Native Metro package`,
25
+ { cause: privateError }
26
+ );
27
+ }
28
+ }
29
+ }
30
+
31
+ /**
32
+ * @param {unknown} moduleValue
33
+ * @param {readonly string[]} names
34
+ * @param {string} label
35
+ * @returns {Callable}
36
+ */
37
+ function moduleFunction(moduleValue, names, label) {
38
+ if (isCallable(moduleValue)) {
39
+ return moduleValue;
40
+ }
41
+ for (const name of names) {
42
+ const candidate = field(moduleValue, name);
43
+ if (isCallable(candidate)) {
44
+ return candidate;
45
+ }
46
+ }
47
+ throw configurationError(`LogBrew Metro could not resolve ${label} from the installed Metro package`);
48
+ }
49
+
50
+ /**
51
+ * @param {unknown} value
52
+ * @returns {value is Iterable<unknown>}
53
+ */
54
+ function isIterable(value) {
55
+ return typeof value === "string" || isCallable(field(value, Symbol.iterator));
56
+ }
57
+
58
+ /**
59
+ * @param {unknown} values
60
+ * @returns {Iterable<unknown>}
61
+ */
62
+ function requireIterable(values) {
63
+ if (!isIterable(values)) {
64
+ throw new TypeError("Spread syntax requires ...iterable[Symbol.iterator] to be a function");
65
+ }
66
+ return values;
67
+ }
68
+
69
+ /**
70
+ * @param {unknown} graph
71
+ * @returns {unknown}
72
+ */
73
+ function graphDependencyValues(graph) {
74
+ const dependencies = field(graph, "dependencies");
75
+ const values = field(dependencies, "values");
76
+ if (values === undefined || values === null) {
77
+ return [];
78
+ }
79
+ if (!isCallable(values)) {
80
+ throw new TypeError("graph?.dependencies?.values is not a function");
81
+ }
82
+ return values.call(dependencies) ?? [];
83
+ }
84
+
85
+ /**
86
+ * @param {unknown} graph
87
+ * @param {unknown} options
88
+ * @returns {unknown[]}
89
+ */
90
+ function sortedModules(graph, options) {
91
+ const modules = [...requireIterable(graphDependencyValues(graph))];
92
+ const createModuleId = field(options, "createModuleId");
93
+ if (!isCallable(createModuleId)) {
94
+ return modules;
95
+ }
96
+ modules.sort((left, right) => (
97
+ Number(createModuleId.call(options, field(left, "path"))) - Number(createModuleId.call(options, field(right, "path")))
98
+ ));
99
+ return modules;
100
+ }
101
+
102
+ /**
103
+ * @template {Callable | null} Fallback
104
+ * @param {unknown} options
105
+ * @param {string} name
106
+ * @param {Fallback} fallback
107
+ * @returns {Callable | Fallback}
108
+ */
109
+ function optionFunction(options, name, fallback) {
110
+ const value = field(options, name);
111
+ return isCallable(value) ? value : fallback;
112
+ }
113
+
114
+ /**
115
+ * @returns {{ readonly fromRawMappings: Callable, readonly getSourceMapInfo: Callable, readonly isJsModule: Callable }}
116
+ */
117
+ function loadSourceMapHelpers() {
118
+ const getSourceMapInfo = moduleFunction(
119
+ requireMetroModule(
120
+ "metro/private/DeltaBundler/Serializers/helpers/getSourceMapInfo",
121
+ "metro/src/DeltaBundler/Serializers/helpers/getSourceMapInfo"
122
+ ),
123
+ ["default"],
124
+ "getSourceMapInfo"
125
+ );
126
+ const isJsModule = moduleFunction(
127
+ requireMetroModule(
128
+ "metro/private/DeltaBundler/Serializers/helpers/js",
129
+ "metro/src/DeltaBundler/Serializers/helpers/js"
130
+ ),
131
+ ["isJsModule"],
132
+ "isJsModule"
133
+ );
134
+ const metroRequire = createRequire(require.resolve("metro/package.json"));
135
+ /** @type {unknown} */
136
+ const sourceMapModule = metroRequire("metro-source-map");
137
+ const fromRawMappings = moduleFunction(sourceMapModule, ["fromRawMappings"], "fromRawMappings");
138
+ return { fromRawMappings, getSourceMapInfo, isJsModule };
139
+ }
140
+
141
+ /**
142
+ * @param {unknown} generator
143
+ * @param {unknown} sourceMapOptions
144
+ * @returns {unknown}
145
+ */
146
+ function sourceMapString(generator, sourceMapOptions) {
147
+ const toString = field(generator, "toString");
148
+ if (!isCallable(toString)) {
149
+ throw new TypeError("fromRawMappings(...).toString is not a function");
150
+ }
151
+ return toString.call(generator, undefined, sourceMapOptions);
152
+ }
153
+
154
+ /**
155
+ * @returns {(preModules: unknown, graph: unknown, options: unknown) => unknown}
156
+ */
157
+ function createMetroSourceMapSerializer() {
158
+ const { fromRawMappings, getSourceMapInfo, isJsModule } = loadSourceMapHelpers();
159
+ return (preModules, graph, options) => {
160
+ const sourceMapOptions = {
161
+ excludeSource: field(options, "excludeSource") === true,
162
+ getSourceUrl: optionFunction(options, "getSourceUrl", null),
163
+ processModuleFilter: optionFunction(options, "processModuleFilter", () => true),
164
+ shouldAddToIgnoreList: optionFunction(options, "shouldAddToIgnoreList", () => false)
165
+ };
166
+ const modules = [...requireIterable(preModules), ...sortedModules(graph, options)]
167
+ .filter(
168
+ /**
169
+ * @param {unknown} module
170
+ * @param {number} index
171
+ * @param {readonly unknown[]} array
172
+ * @returns {boolean}
173
+ */
174
+ (module, index, array) => Boolean(isJsModule(module, index, array))
175
+ )
176
+ .filter(
177
+ /**
178
+ * @param {unknown} module
179
+ * @param {number} index
180
+ * @param {readonly unknown[]} array
181
+ * @returns {boolean}
182
+ */
183
+ (module, index, array) => Boolean(sourceMapOptions.processModuleFilter(module, index, array))
184
+ )
185
+ .map((module) => getSourceMapInfo(module, sourceMapOptions));
186
+ return sourceMapString(fromRawMappings(modules), sourceMapOptions);
187
+ };
188
+ }
189
+
190
+ /**
191
+ * @returns {MetroSerializer}
192
+ */
193
+ function createDefaultMetroSerializer() {
194
+ const baseJSBundle = moduleFunction(
195
+ requireMetroModule(
196
+ "metro/private/DeltaBundler/Serializers/baseJSBundle",
197
+ "metro/src/DeltaBundler/Serializers/baseJSBundle"
198
+ ),
199
+ ["baseJSBundle", "default"],
200
+ "baseJSBundle"
201
+ );
202
+ const bundleToString = moduleFunction(
203
+ requireMetroModule("metro/private/lib/bundleToString", "metro/src/lib/bundleToString"),
204
+ ["bundleToString", "default"],
205
+ "bundleToString"
206
+ );
207
+ const serializeSourceMap = createMetroSourceMapSerializer();
208
+
209
+ return async (entryPoint, preModules, graph, options) => {
210
+ const code = field(bundleToString(baseJSBundle(entryPoint, preModules, graph, options)), "code");
211
+ if (isDevelopmentGraph(graph)) {
212
+ return code;
213
+ }
214
+ const map = await serializeSourceMap(preModules, graph, options);
215
+ return { code, map };
216
+ };
217
+ }
218
+
219
+ module.exports = { createDefaultMetroSerializer };