@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
@@ -2,72 +2,78 @@
2
2
 
3
3
  const { spawnSync } = require("node:child_process");
4
4
  const fs = require("node:fs");
5
- const net = require("node:net");
6
5
  const path = require("node:path");
6
+ const {
7
+ field,
8
+ normalizePlatform,
9
+ normalizeStringArray,
10
+ optionalString,
11
+ optionalUploadScalar,
12
+ requireUploadEndpoint,
13
+ requiredString
14
+ } = require("./release-artifacts-options.cjs");
15
+ const {
16
+ applyExplicitSourceMapReference,
17
+ ensureInsideBuildDir,
18
+ requireExistingFile,
19
+ resolvePathFromRoot
20
+ } = require("./release-artifacts-files.cjs");
21
+
22
+ /**
23
+ * @typedef {"android" | "ios"} ReleaseArtifactPlatform
24
+ * @typedef {{ readonly report: unknown, readonly stdout: string }} ReleaseArtifactCliResult
25
+ * @typedef {{
26
+ * readonly environment: string,
27
+ * readonly platform: ReleaseArtifactPlatform,
28
+ * readonly projectId: string | undefined,
29
+ * readonly release: string,
30
+ * readonly service: string
31
+ * }} ReleaseIdentity
32
+ * @typedef {{
33
+ * readonly buildDir: string,
34
+ * readonly bundlePath: string,
35
+ * readonly manifestPath: string,
36
+ * readonly root: string,
37
+ * readonly sourcemapPath: string
38
+ * }} ReleaseLocations
39
+ * @typedef {{
40
+ * readonly commitSha: string | undefined,
41
+ * readonly minifiedPathPrefix: string,
42
+ * readonly repositoryUrl: string | undefined,
43
+ * readonly sourcePrefixes: readonly string[],
44
+ * readonly stripSourcesContent: boolean
45
+ * }} ReleaseManifestSettings
46
+ * @typedef {{ readonly relativeBundlePath: string, readonly relativeSourceMapPath: string }} RelativeBundlePaths
47
+ * @typedef {{
48
+ * readonly buildDir: string,
49
+ * readonly bundlePath: string,
50
+ * readonly sourcemapPath: string,
51
+ * readonly manifestPath: string,
52
+ * readonly platform: ReleaseArtifactPlatform,
53
+ * readonly prepareReport: unknown,
54
+ * readonly manifestReport: unknown
55
+ * }} PreparedReleaseArtifacts
56
+ * @typedef {{
57
+ * readonly allowHostedUpload: boolean,
58
+ * readonly dryRun: unknown,
59
+ * readonly endpoint: string,
60
+ * readonly maxRetries: string | undefined,
61
+ * readonly retryDelay: string | undefined,
62
+ * readonly timeout: string | undefined,
63
+ * readonly tokenEnv: string | undefined
64
+ * }} ReleaseUploadSettings
65
+ */
7
66
 
8
67
  const PACKAGE_DIR = path.dirname(require.resolve("./package.json"));
9
68
  const DEFAULT_MANIFEST_NAME = "logbrew-release-artifacts.json";
10
- const HERMES_MAGIC = Buffer.from("c61fbc03c103191f", "hex");
11
- const HERMES_RUNTIME_DEBUG_ID_RE =
12
- /\/\*logbrew-runtime-debug-id\*\/\/\/# debugId=[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[89ab][0-9a-f]{3}-[0-9a-f]{12}/iu;
13
- const HOSTED_UPLOAD_ENDPOINT = "https://api.logbrew.co/api/release-artifacts";
14
- const SUPPORTED_PLATFORMS = new Set(["android", "ios"]);
15
- const SOURCE_MAPPING_COMMENT_RE = /(?:\/\/#|\/\*#)\s*sourceMappingURL=[^\r\n]*/giu;
16
-
17
- function requiredString(options, name) {
18
- const value = options?.[name];
19
- if (typeof value !== "string" || value.trim() === "") {
20
- throw new Error(`LogBrew React Native release-artifact helper requires ${name}`);
21
- }
22
- return value.trim();
23
- }
24
-
25
- function optionalString(options, name) {
26
- const value = options?.[name];
27
- if (value === undefined || value === null) {
28
- return null;
29
- }
30
- if (typeof value !== "string" || value.trim() === "") {
31
- throw new Error(`LogBrew React Native release-artifact helper option ${name} must be a non-empty string`);
32
- }
33
- return value.trim();
34
- }
35
-
36
- function optionalUploadScalar(options, name) {
37
- const value = options?.[name];
38
- if (value === undefined || value === null) {
39
- return null;
40
- }
41
- if (typeof value === "number") {
42
- if (!Number.isFinite(value) || value < 0) {
43
- throw new Error(`LogBrew React Native release-artifact helper option ${name} must be non-negative`);
44
- }
45
- return String(value);
46
- }
47
- if (typeof value !== "string" || value.trim() === "") {
48
- throw new Error(`LogBrew React Native release-artifact helper option ${name} must be a non-empty string or number`);
49
- }
50
- return value.trim();
51
- }
52
-
53
- function normalizeStringArray(value, name) {
54
- if (value === undefined || value === null) {
55
- return [];
56
- }
57
- if (!Array.isArray(value) || value.some((item) => typeof item !== "string" || item.trim() === "")) {
58
- throw new Error(`LogBrew React Native release-artifact helper option ${name} must be an array of non-empty strings`);
59
- }
60
- return value.map((item) => item.trim());
61
- }
62
-
63
- function normalizePlatform(options) {
64
- const platform = requiredString(options, "platform").toLowerCase();
65
- if (!SUPPORTED_PLATFORMS.has(platform)) {
66
- throw new Error("LogBrew React Native release-artifact helper option platform must be android or ios");
67
- }
68
- return platform;
69
- }
70
-
69
+ const NONE = 0;
70
+ const SUCCESS_EXIT_CODE = 0;
71
+
72
+ /**
73
+ * @param {string} stdout
74
+ * @param {string} command
75
+ * @returns {unknown}
76
+ */
71
77
  function parseJson(stdout, command) {
72
78
  try {
73
79
  return JSON.parse(stdout);
@@ -76,13 +82,56 @@ function parseJson(stdout, command) {
76
82
  }
77
83
  }
78
84
 
85
+ /**
86
+ * @param {unknown} value
87
+ * @returns {value is readonly unknown[]}
88
+ */
89
+ function isArray(value) {
90
+ return Array.isArray(value);
91
+ }
92
+
93
+ /**
94
+ * @param {unknown} value
95
+ * @returns {value is (this: unknown, ...args: readonly unknown[]) => unknown}
96
+ */
97
+ function isCallable(value) {
98
+ return typeof value === "function";
99
+ }
100
+
101
+ /**
102
+ * @param {unknown} report
103
+ * @returns {unknown[]}
104
+ */
79
105
  function validationErrors(report) {
80
- if (report?.validation && Array.isArray(report.validation.errors)) {
81
- return report.validation.errors.filter((message) => typeof message === "string" && message.trim() !== "");
106
+ const validation = field(report, "validation");
107
+ const errors = field(validation, "errors");
108
+ if (Boolean(validation) && isArray(errors)) {
109
+ return errors.filter((message) => typeof message === "string" && message.trim() !== "");
82
110
  }
83
111
  return [];
84
112
  }
85
113
 
114
+ /**
115
+ * @param {unknown} report
116
+ * @param {string} label
117
+ * @param {(artifact: unknown) => boolean} predicate
118
+ * @returns {unknown}
119
+ */
120
+ function findReportArtifact(report, label, predicate) {
121
+ const artifacts = field(report, "artifacts");
122
+ if (artifacts === undefined || artifacts === null) {
123
+ return undefined;
124
+ }
125
+ const find = field(artifacts, "find");
126
+ if (!isCallable(find)) {
127
+ throw new TypeError(`${label}?.artifacts?.find is not a function`);
128
+ }
129
+ return find.call(artifacts, predicate);
130
+ }
131
+
132
+ /**
133
+ * @returns {string}
134
+ */
86
135
  function resolveLogBrewReleaseArtifactsCli() {
87
136
  try {
88
137
  const sdkEntry = require.resolve("@logbrew/sdk", { paths: [PACKAGE_DIR, process.cwd()] });
@@ -96,135 +145,91 @@ function resolveLogBrewReleaseArtifactsCli() {
96
145
  }
97
146
  }
98
147
 
99
- function parseUploadEndpoint(endpoint) {
100
- let parsed;
101
- try {
102
- parsed = new URL(endpoint);
103
- } catch (error) {
104
- throw new Error(`upload endpoint is not a valid URL: ${error.message}`, { cause: error });
105
- }
106
- if (!["http:", "https:"].includes(parsed.protocol)) {
107
- throw new Error("release artifact upload proof endpoint must use http or https");
108
- }
109
- return parsed;
110
- }
111
-
112
- function isLoopbackUploadEndpoint(parsed) {
113
- const hostname = parsed.hostname.toLowerCase();
114
- return (
115
- hostname === "localhost" ||
116
- hostname === "[::1]" ||
117
- hostname === "::1" ||
118
- (net.isIP(hostname) !== 0 && (hostname.startsWith("127.") || hostname === "::1"))
119
- );
120
- }
121
-
122
- function requireUploadEndpoint(endpoint, allowHosted) {
123
- const parsed = parseUploadEndpoint(endpoint);
124
- if (isLoopbackUploadEndpoint(parsed)) {
125
- return;
126
- }
127
- if (!allowHosted) {
128
- throw new Error("release artifact hosted upload requires explicit allowHostedUpload; use loopback endpoints for local proof");
129
- }
130
- if (endpoint !== HOSTED_UPLOAD_ENDPOINT) {
131
- throw new Error(`hosted release artifact uploads must use ${HOSTED_UPLOAD_ENDPOINT}`);
132
- }
133
- }
134
-
148
+ /**
149
+ * @param {string} command
150
+ * @param {readonly string[]} args
151
+ * @returns {ReleaseArtifactCliResult}
152
+ */
135
153
  function runReleaseArtifactCli(command, args) {
136
154
  const result = spawnSync(process.execPath, [resolveLogBrewReleaseArtifactsCli(), command, ...args], {
137
155
  cwd: process.cwd(),
138
156
  encoding: "utf8",
139
- windowsHide: true,
157
+ windowsHide: true
140
158
  });
141
159
  const report = result.stdout ? parseJson(result.stdout, command) : null;
142
- if (result.status !== 0) {
143
- const details = validationErrors(report).join("; ") || result.stderr.trim() || `exit code ${result.status}`;
160
+ if (result.status !== SUCCESS_EXIT_CODE) {
161
+ const details = validationErrors(report).join("; ") || result.stderr.trim() || `exit code ${String(result.status)}`;
144
162
  throw new Error(`LogBrew release-artifact ${command} failed: ${details}`);
145
163
  }
146
164
  return { report, stdout: result.stdout };
147
165
  }
148
166
 
149
- function resolvePathFromRoot(root, value) {
150
- return path.isAbsolute(value) ? path.resolve(value) : path.resolve(root, value);
151
- }
152
-
153
- function requireExistingFile(label, filePath) {
154
- if (!fs.existsSync(filePath) || !fs.statSync(filePath).isFile()) {
155
- throw new Error(`LogBrew React Native release-artifact helper ${label} does not exist: ${filePath}`);
156
- }
157
- }
158
-
159
- function ensureInsideBuildDir(label, filePath, buildDir) {
160
- const relative = path.relative(buildDir, filePath);
161
- if (relative === "" || relative.startsWith("..") || path.isAbsolute(relative)) {
162
- throw new Error(`LogBrew React Native release-artifact helper ${label} must stay inside buildDir`);
163
- }
164
- return relative.split(path.sep).join("/");
165
- }
166
-
167
- function artifactForBundle(report, relativeBundlePath) {
168
- return report?.artifacts?.find((artifact) => artifact?.path === relativeBundlePath) || null;
169
- }
170
-
171
- function sourceWithSourceMappingUrl(source, reference) {
172
- const sourceWithoutMapComments = source.replace(SOURCE_MAPPING_COMMENT_RE, "").replace(/[ \t\r\n]*$/u, "");
173
- return `${sourceWithoutMapComments}${sourceWithoutMapComments === "" ? "" : "\n"}//# sourceMappingURL=${reference}\n`;
174
- }
175
-
176
- function applyExplicitSourceMapReference(bundlePath, sourcemapPath) {
177
- const bundle = fs.readFileSync(bundlePath);
178
- if (bundle.subarray(0, HERMES_MAGIC.length).equals(HERMES_MAGIC)) {
179
- if (!HERMES_RUNTIME_DEBUG_ID_RE.test(bundle.toString("latin1"))) {
180
- throw new Error("LogBrew React Native Hermes bytecode requires the LogBrew Metro wrapper");
181
- }
182
- if (sourcemapPath !== `${bundlePath}.map`) {
183
- throw new Error("LogBrew React Native Hermes source map must use the bundle's sibling .map path");
184
- }
185
- return;
186
- }
187
- const reference = path.relative(path.dirname(bundlePath), sourcemapPath).split(path.sep).join("/");
188
- const source = bundle.toString("utf8");
189
- const updated = sourceWithSourceMappingUrl(source, reference);
190
- if (updated !== source) {
191
- fs.writeFileSync(bundlePath, updated, "utf8");
192
- }
193
- }
194
-
195
- function defaultMinifiedPathPrefix(platform) {
196
- return `app:///react-native/${platform}`;
197
- }
198
-
199
- function prepareLogBrewReactNativeReleaseArtifacts(options = {}) {
167
+ /**
168
+ * @param {unknown} options
169
+ * @returns {ReleaseIdentity}
170
+ */
171
+ function readReleaseIdentity(options) {
200
172
  const release = requiredString(options, "release");
201
173
  const environment = requiredString(options, "environment");
202
174
  const service = requiredString(options, "service");
203
175
  const projectId = optionalString(options, "projectId");
204
176
  const platform = normalizePlatform(options);
205
- const root = path.resolve(optionalString(options, "root") || process.cwd());
177
+ return { environment, platform, projectId, release, service };
178
+ }
179
+
180
+ /**
181
+ * @param {unknown} options
182
+ * @returns {ReleaseLocations}
183
+ */
184
+ function readReleaseLocations(options) {
185
+ const root = path.resolve(optionalString(options, "root") ?? process.cwd());
206
186
  const bundlePath = resolvePathFromRoot(root, requiredString(options, "bundle"));
207
187
  const sourcemapOption = optionalString(options, "sourcemap");
208
- const sourcemapPath = sourcemapOption ? resolvePathFromRoot(root, sourcemapOption) : `${bundlePath}.map`;
188
+ const sourcemapPath = sourcemapOption === undefined ? `${bundlePath}.map` : resolvePathFromRoot(root, sourcemapOption);
209
189
  const buildDirOption = optionalString(options, "buildDir");
210
- const buildDir = buildDirOption ? resolvePathFromRoot(root, buildDirOption) : path.dirname(bundlePath);
190
+ const buildDir = buildDirOption === undefined ? path.dirname(bundlePath) : resolvePathFromRoot(root, buildDirOption);
211
191
  const manifestPath = resolvePathFromRoot(
212
192
  root,
213
- optionalString(options, "manifestPath") || path.join(buildDir, DEFAULT_MANIFEST_NAME),
193
+ optionalString(options, "manifestPath") ?? path.join(buildDir, DEFAULT_MANIFEST_NAME)
214
194
  );
215
- const minifiedPathPrefix = optionalString(options, "minifiedPathPrefix") || defaultMinifiedPathPrefix(platform);
195
+ return { buildDir, bundlePath, manifestPath, root, sourcemapPath };
196
+ }
197
+
198
+ /**
199
+ * @param {unknown} options
200
+ * @param {ReleaseArtifactPlatform} platform
201
+ * @param {string} root
202
+ * @returns {ReleaseManifestSettings}
203
+ */
204
+ function readManifestSettings(options, platform, root) {
205
+ const minifiedPathPrefix = optionalString(options, "minifiedPathPrefix") ?? `app:///react-native/${platform}`;
216
206
  const repositoryUrl = optionalString(options, "repositoryUrl");
217
207
  const commitSha = optionalString(options, "commitSha");
218
- const stripSourcesContent = options?.stripSourcesContent !== false;
219
- const userSourcePrefixes = normalizeStringArray(options?.stripSourcePrefix, "stripSourcePrefix");
220
- const sourcePrefixes = userSourcePrefixes.length > 0 ? userSourcePrefixes : [root];
208
+ const stripSourcesContent = field(options, "stripSourcesContent") !== false;
209
+ const userSourcePrefixes = normalizeStringArray(field(options, "stripSourcePrefix"), "stripSourcePrefix");
210
+ const sourcePrefixes = userSourcePrefixes.length > NONE ? userSourcePrefixes : [root];
211
+ return { commitSha, minifiedPathPrefix, repositoryUrl, sourcePrefixes, stripSourcesContent };
212
+ }
221
213
 
214
+ /**
215
+ * @param {ReleaseLocations} locations
216
+ * @returns {RelativeBundlePaths}
217
+ */
218
+ function checkBundleFiles({ buildDir, bundlePath, sourcemapPath }) {
222
219
  requireExistingFile("bundle", bundlePath);
223
220
  requireExistingFile("sourcemap", sourcemapPath);
224
221
  const relativeBundlePath = ensureInsideBuildDir("bundle", bundlePath, buildDir);
225
222
  const relativeSourceMapPath = ensureInsideBuildDir("sourcemap", sourcemapPath, buildDir);
226
223
  applyExplicitSourceMapReference(bundlePath, sourcemapPath);
224
+ return { relativeBundlePath, relativeSourceMapPath };
225
+ }
227
226
 
227
+ /**
228
+ * @param {ReleaseLocations} locations
229
+ * @param {ReleaseManifestSettings} settings
230
+ * @returns {string[]}
231
+ */
232
+ function prepareArguments({ buildDir, root }, { sourcePrefixes, stripSourcesContent }) {
228
233
  const prepareArgs = ["--build-dir", buildDir, "--write"];
229
234
  if (stripSourcesContent) {
230
235
  prepareArgs.push("--strip-sources-content");
@@ -232,18 +237,36 @@ function prepareLogBrewReactNativeReleaseArtifacts(options = {}) {
232
237
  for (const prefix of sourcePrefixes) {
233
238
  prepareArgs.push("--strip-source-prefix", resolvePathFromRoot(root, prefix));
234
239
  }
240
+ return prepareArgs;
241
+ }
235
242
 
236
- const { report: prepareReport } = runReleaseArtifactCli("prepare-js", prepareArgs);
237
- const preparedArtifact = artifactForBundle(prepareReport, relativeBundlePath);
238
- if (!preparedArtifact) {
243
+ /**
244
+ * @param {ReleaseLocations} locations
245
+ * @param {ReleaseManifestSettings} settings
246
+ * @param {RelativeBundlePaths} relative
247
+ * @returns {unknown}
248
+ */
249
+ function runPrepare(locations, settings, { relativeBundlePath, relativeSourceMapPath }) {
250
+ const { report } = runReleaseArtifactCli("prepare-js", prepareArguments(locations, settings));
251
+ const preparedArtifact = findReportArtifact(report, "report", (artifact) => field(artifact, "path") === relativeBundlePath);
252
+ if (preparedArtifact === undefined || preparedArtifact === null) {
239
253
  throw new Error(`LogBrew React Native release-artifact helper did not find bundle: ${relativeBundlePath}`);
240
254
  }
241
- if (preparedArtifact.sourceMapPath !== relativeSourceMapPath) {
255
+ if (field(preparedArtifact, "sourceMapPath") !== relativeSourceMapPath) {
242
256
  throw new Error(
243
- `LogBrew React Native release-artifact helper expected source map ${relativeSourceMapPath} for ${relativeBundlePath}`,
257
+ `LogBrew React Native release-artifact helper expected source map ${relativeSourceMapPath} for ${relativeBundlePath}`
244
258
  );
245
259
  }
260
+ return report;
261
+ }
246
262
 
263
+ /**
264
+ * @param {ReleaseIdentity} identity
265
+ * @param {ReleaseLocations} locations
266
+ * @param {ReleaseManifestSettings} settings
267
+ * @returns {string[]}
268
+ */
269
+ function manifestArguments({ environment, projectId, release, service }, { buildDir }, { commitSha, minifiedPathPrefix, repositoryUrl }) {
247
270
  const manifestArgs = [
248
271
  "--build-dir",
249
272
  buildDir,
@@ -254,94 +277,142 @@ function prepareLogBrewReactNativeReleaseArtifacts(options = {}) {
254
277
  "--service",
255
278
  service,
256
279
  "--minified-path-prefix",
257
- minifiedPathPrefix,
280
+ minifiedPathPrefix
258
281
  ];
259
- if (projectId) {
282
+ if (projectId !== undefined) {
260
283
  manifestArgs.push("--project-id", projectId);
261
284
  }
262
- if (repositoryUrl) {
285
+ if (repositoryUrl !== undefined) {
263
286
  manifestArgs.push("--repository-url", repositoryUrl);
264
287
  }
265
- if (commitSha) {
288
+ if (commitSha !== undefined) {
266
289
  manifestArgs.push("--commit-sha", commitSha);
267
290
  }
291
+ return manifestArgs;
292
+ }
268
293
 
269
- const { report: manifestReport, stdout } = runReleaseArtifactCli("manifest-js", manifestArgs);
270
- const manifestArtifact = manifestReport?.artifacts?.find(
271
- (artifact) => artifact?.minifiedSource?.path === relativeBundlePath,
294
+ /**
295
+ * @param {readonly string[]} manifestArgs
296
+ * @param {RelativeBundlePaths} relative
297
+ * @param {string} manifestPath
298
+ * @returns {unknown}
299
+ */
300
+ function runManifest(manifestArgs, { relativeBundlePath }, manifestPath) {
301
+ const { report, stdout } = runReleaseArtifactCli("manifest-js", manifestArgs);
302
+ const manifestArtifact = findReportArtifact(
303
+ report,
304
+ "manifestReport",
305
+ (artifact) => field(field(artifact, "minifiedSource"), "path") === relativeBundlePath
272
306
  );
273
- if (!manifestArtifact) {
307
+ if (manifestArtifact === undefined || manifestArtifact === null) {
274
308
  throw new Error(`LogBrew React Native release-artifact manifest did not include bundle: ${relativeBundlePath}`);
275
309
  }
276
-
277
310
  fs.mkdirSync(path.dirname(manifestPath), { recursive: true });
278
311
  fs.writeFileSync(manifestPath, stdout, "utf8");
312
+ return report;
313
+ }
279
314
 
315
+ /**
316
+ * @param {unknown} [options]
317
+ * @returns {PreparedReleaseArtifacts}
318
+ */
319
+ function prepareLogBrewReactNativeReleaseArtifacts(options = {}) {
320
+ const identity = readReleaseIdentity(options);
321
+ const locations = readReleaseLocations(options);
322
+ const settings = readManifestSettings(options, identity.platform, locations.root);
323
+ const relative = checkBundleFiles(locations);
324
+ const prepareReport = runPrepare(locations, settings, relative);
325
+ const manifestReport = runManifest(manifestArguments(identity, locations, settings), relative, locations.manifestPath);
326
+ const { buildDir, bundlePath, manifestPath, sourcemapPath } = locations;
280
327
  return {
281
328
  buildDir,
282
329
  bundlePath,
330
+
283
331
  sourcemapPath,
332
+
284
333
  manifestPath,
285
- platform,
334
+ platform: identity.platform,
286
335
  prepareReport,
287
- manifestReport,
336
+
337
+ manifestReport
288
338
  };
289
339
  }
290
340
 
291
- function uploadLogBrewReactNativeReleaseArtifacts(options = {}) {
341
+ /**
342
+ * @param {unknown} options
343
+ * @returns {{ readonly allowHostedUpload: boolean, readonly endpoint: string }}
344
+ */
345
+ function readUploadEndpoint(options) {
292
346
  const endpoint = requiredString(options, "endpoint");
293
- const allowHostedUpload = options?.allowHostedUpload === true;
294
- if (options?.allowHostedUpload !== undefined && typeof options.allowHostedUpload !== "boolean") {
347
+ const allowHostedUpload = field(options, "allowHostedUpload");
348
+ if (allowHostedUpload !== undefined && typeof allowHostedUpload !== "boolean") {
295
349
  throw new Error("LogBrew React Native release-artifact helper option allowHostedUpload must be a boolean");
296
350
  }
297
- requireUploadEndpoint(endpoint, allowHostedUpload);
351
+ requireUploadEndpoint(endpoint, allowHostedUpload === true);
352
+ return { allowHostedUpload: allowHostedUpload === true, endpoint };
353
+ }
354
+
355
+ /**
356
+ * @param {unknown} options
357
+ * @returns {ReleaseUploadSettings}
358
+ */
359
+ function readUploadSettings(options) {
360
+ const { allowHostedUpload, endpoint } = readUploadEndpoint(options);
298
361
  const tokenEnv = optionalString(options, "tokenEnv");
299
362
  const maxRetries = optionalUploadScalar(options, "maxRetries");
300
363
  const retryDelay = optionalUploadScalar(options, "retryDelay");
301
364
  const timeout = optionalUploadScalar(options, "timeout");
302
- const dryRun = options?.dryRun;
365
+ const dryRun = field(options, "dryRun");
303
366
  if (dryRun !== undefined && typeof dryRun !== "boolean") {
304
367
  throw new Error("LogBrew React Native release-artifact helper option dryRun must be a boolean");
305
368
  }
369
+ return { allowHostedUpload, dryRun, endpoint, maxRetries, retryDelay, timeout, tokenEnv };
370
+ }
306
371
 
307
- const prepared = prepareLogBrewReactNativeReleaseArtifacts(options);
372
+ /**
373
+ * @param {PreparedReleaseArtifacts} prepared
374
+ * @param {ReleaseUploadSettings} settings
375
+ * @returns {string[]}
376
+ */
377
+ function uploadArguments({ buildDir, manifestPath }, { allowHostedUpload, dryRun, endpoint, maxRetries, retryDelay, timeout, tokenEnv }) {
308
378
  const uploadArgs = [
309
379
  "--build-dir",
310
- prepared.buildDir,
380
+ buildDir,
311
381
  "--manifest",
312
- prepared.manifestPath,
382
+ manifestPath,
313
383
  "--endpoint",
314
384
  endpoint,
385
+ ...(tokenEnv === undefined ? [] : ["--token-env", tokenEnv]),
386
+ ...(dryRun === true ? ["--dry-run"] : []),
387
+ ...(allowHostedUpload ? ["--allow-hosted"] : [])
315
388
  ];
316
-
317
- if (tokenEnv) {
318
- uploadArgs.push("--token-env", tokenEnv);
319
- }
320
- if (dryRun === true) {
321
- uploadArgs.push("--dry-run");
322
- }
323
- if (allowHostedUpload) {
324
- uploadArgs.push("--allow-hosted");
325
- }
326
- if (maxRetries) {
327
- uploadArgs.push("--max-retries", maxRetries);
328
- }
329
- if (retryDelay) {
330
- uploadArgs.push("--retry-delay", retryDelay);
331
- }
332
- if (timeout) {
333
- uploadArgs.push("--timeout", timeout);
389
+ /** @type {ReadonlyArray<readonly [string, string | undefined]>} */
390
+ const scalarOptions = [["--max-retries", maxRetries], ["--retry-delay", retryDelay], ["--timeout", timeout]];
391
+ for (const [flag, value] of scalarOptions) {
392
+ if (value !== undefined) {
393
+ uploadArgs.push(flag, value);
394
+ }
334
395
  }
396
+ return uploadArgs;
397
+ }
335
398
 
336
- const { report: uploadReport } = runReleaseArtifactCli("upload-js", uploadArgs);
399
+ /**
400
+ * @param {unknown} [options]
401
+ * @returns {PreparedReleaseArtifacts & { uploadReport: unknown }}
402
+ */
403
+ function uploadLogBrewReactNativeReleaseArtifacts(options = {}) {
404
+ const settings = readUploadSettings(options);
405
+ const prepared = prepareLogBrewReactNativeReleaseArtifacts(options);
406
+ const { report: uploadReport } = runReleaseArtifactCli("upload-js", uploadArguments(prepared, settings));
337
407
  return {
338
408
  ...prepared,
339
- uploadReport,
409
+ uploadReport
340
410
  };
341
411
  }
342
412
 
343
413
  module.exports = {
344
414
  prepareLogBrewReactNativeReleaseArtifacts,
345
415
  uploadLogBrewReactNativeReleaseArtifacts,
346
- default: prepareLogBrewReactNativeReleaseArtifacts,
416
+
417
+ default: prepareLogBrewReactNativeReleaseArtifacts
347
418
  };
@@ -1,55 +1,2 @@
1
- export type LogBrewReactNativeReleaseArtifactPlatform = "android" | "ios";
2
-
3
- export type LogBrewReactNativeReleaseArtifactsOptions = {
4
- bundle: string;
5
- platform: LogBrewReactNativeReleaseArtifactPlatform;
6
- release: string;
7
- environment: string;
8
- service: string;
9
- projectId?: string;
10
- sourcemap?: string;
11
- root?: string;
12
- buildDir?: string;
13
- manifestPath?: string;
14
- minifiedPathPrefix?: string;
15
- repositoryUrl?: string;
16
- commitSha?: string;
17
- stripSourcesContent?: boolean;
18
- stripSourcePrefix?: string[];
19
- };
20
-
21
- export type LogBrewReactNativeReleaseArtifactsResult = {
22
- buildDir: string;
23
- bundlePath: string;
24
- sourcemapPath: string;
25
- manifestPath: string;
26
- platform: LogBrewReactNativeReleaseArtifactPlatform;
27
- prepareReport: Record<string, unknown>;
28
- manifestReport: Record<string, unknown>;
29
- };
30
-
31
- export type LogBrewReactNativeReleaseArtifactUploadOptions = LogBrewReactNativeReleaseArtifactsOptions & {
32
- endpoint: string;
33
- allowHostedUpload?: boolean;
34
- tokenEnv?: string;
35
- dryRun?: boolean;
36
- maxRetries?: string | number;
37
- retryDelay?: string | number;
38
- timeout?: string | number;
39
- };
40
-
41
- export type LogBrewReactNativeReleaseArtifactUploadResult = LogBrewReactNativeReleaseArtifactsResult & {
42
- uploadReport: Record<string, unknown>;
43
- };
44
-
45
- export declare function prepareLogBrewReactNativeReleaseArtifacts(
46
- options: LogBrewReactNativeReleaseArtifactsOptions
47
- ): LogBrewReactNativeReleaseArtifactsResult;
48
-
49
- export declare function uploadLogBrewReactNativeReleaseArtifacts(
50
- options: LogBrewReactNativeReleaseArtifactUploadOptions
51
- ): LogBrewReactNativeReleaseArtifactUploadResult;
52
-
53
- declare const defaultExport: typeof prepareLogBrewReactNativeReleaseArtifacts;
54
-
55
- export default defaultExport;
1
+ export * from "./release-artifacts.js";
2
+ export { default } from "./release-artifacts.js";