@bugsee/react-native 0.0.0-stage → 7.0.0-beta2
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/BugseeReactNative.podspec +95 -0
- package/LICENSE +21 -0
- package/README.md +557 -2
- package/android/build.gradle +162 -0
- package/android/consumer-rules.pro +2 -0
- package/android/src/main/AndroidManifest.xml +33 -0
- package/android/src/main/java/com/bugsee/reactnative/AppearanceBridge.java +82 -0
- package/android/src/main/java/com/bugsee/reactnative/AttributeBridge.java +209 -0
- package/android/src/main/java/com/bugsee/reactnative/BreadcrumbFilterBridge.java +443 -0
- package/android/src/main/java/com/bugsee/reactnative/BridgeJson.java +168 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseeModule.java +1869 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseeOptionEnums.java +136 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseePackage.java +42 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseeReactNativeWrapper.java +200 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseeStatusMapper.java +66 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseeTokens.java +22 -0
- package/android/src/main/java/com/bugsee/reactnative/ConsoleEchoDedup.java +202 -0
- package/android/src/main/java/com/bugsee/reactnative/CreatedReports.java +127 -0
- package/android/src/main/java/com/bugsee/reactnative/DataRequestBridge.java +375 -0
- package/android/src/main/java/com/bugsee/reactnative/ExceptionBridge.java +88 -0
- package/android/src/main/java/com/bugsee/reactnative/ExceptionExecutors.java +33 -0
- package/android/src/main/java/com/bugsee/reactnative/LogFilterBridge.java +375 -0
- package/android/src/main/java/com/bugsee/reactnative/NetworkEvents.java +227 -0
- package/android/src/main/java/com/bugsee/reactnative/NetworkFilterBridge.java +498 -0
- package/android/src/main/java/com/bugsee/reactnative/PluginEndpoint.java +48 -0
- package/android/src/main/java/com/bugsee/reactnative/ReactNativeWebException.java +19 -0
- package/android/src/main/java/com/bugsee/reactnative/ReactNativeWrapperInitProvider.java +61 -0
- package/android/src/main/java/com/bugsee/reactnative/ReactRootOriginTracker.java +867 -0
- package/android/src/main/java/com/bugsee/reactnative/ReportArgs.java +58 -0
- package/android/src/main/java/com/bugsee/reactnative/ReportHandlerBridge.java +336 -0
- package/android/src/main/java/com/bugsee/reactnative/ReportHandlerDeadlines.java +57 -0
- package/android/src/main/java/com/bugsee/reactnative/ReportOps.java +287 -0
- package/android/src/main/java/com/bugsee/reactnative/SecureRectanglePulls.java +113 -0
- package/android/src/main/java/com/bugsee/reactnative/SecureRectangleStore.java +692 -0
- package/android/src/main/java/com/bugsee/reactnative/SpanHandles.java +143 -0
- package/android/src/main/java/com/bugsee/reactnative/WrapperChannelHolder.java +137 -0
- package/android/src/main/java/com/bugsee/reactnative/WrapperEventBus.java +110 -0
- package/android/src/main/java/com/bugsee/reactnative/WrapperRegistrar.java +54 -0
- package/app.plugin.js +4 -0
- package/ios/BGSRNConsoleCapture.h +52 -0
- package/ios/BGSRNConsoleCapture.mm +344 -0
- package/ios/BugseeModule.h +25 -0
- package/ios/BugseeModule.mm +2728 -0
- package/ios/Package.swift +71 -0
- package/ios/Support/Package.resolved +14 -0
- package/ios/Support/Package.swift +44 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNAttributes.m +52 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNCreatedReportOps.m +236 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNCreatedReports.m +184 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNDataRequestBridge.m +431 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNErrorMessage.m +40 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNEventBus.m +70 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNExceptions.m +63 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNGuardedEmit.mm +32 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNJSON.m +40 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNLaunchHold.m +147 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNMainThread.m +23 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNNetworkEvents.m +159 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNNetworkFilter.m +155 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNPluginEndpoint.m +21 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReactRootOriginTracker.m +63 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReactWindow.m +251 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReportArgs.m +47 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReportDeadlines.m +8 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReportHandlerBridge.m +308 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReportOps.m +345 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNSecureRectangles.m +508 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNSettleOnce.m +62 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNSpanHandles.m +136 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNStatusMapper.m +18 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNTokens.m +9 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNValues.m +5 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNWrapper.m +54 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNWrapperChannelHolder.m +59 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNAttributes.h +63 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNCreatedReportOps.h +51 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNCreatedReports.h +81 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNDataRequestBridge.h +118 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNErrorMessage.h +30 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNEventBus.h +45 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNExceptions.h +31 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNGuardedEmit.h +31 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNJSON.h +25 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNLaunchHold.h +86 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNMainThread.h +32 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNNetworkEvents.h +28 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNNetworkFilter.h +28 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNPluginEndpoint.h +17 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReactRootOriginTracker.h +48 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReactWindow.h +135 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportArgs.h +17 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportDeadlines.h +37 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportHandlerBridge.h +94 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportOps.h +86 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNSecureRectangles.h +198 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNSettleOnce.h +25 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNSpanHandles.h +49 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNStatusMapper.h +26 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNTokens.h +14 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNValues.h +18 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNWrapper.h +40 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNWrapperChannelHolder.h +74 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNAttributesTests.m +194 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNCreatedReportOpsTests.m +274 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNCreatedReportsTests.m +240 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNDataRequestBridgeTests.m +685 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNErrorMessageTests.m +102 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNEventBusTests.m +136 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNExceptionsTests.m +68 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNFakeReport.h +41 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNFakeReport.m +166 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNGuardedEmitTests.mm +85 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNJSONTests.m +281 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNLaunchHoldTests.m +230 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNMainThreadTests.m +97 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNNetworkEventsTests.m +99 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNNetworkFilterTests.m +134 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNPluginEndpointTests.m +38 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReactRootOriginTrackerTests.m +210 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReactWindowTests.m +548 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportArgsTests.m +51 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportDeadlinesTests.m +22 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportHandlerBridgeTests.m +382 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportOpsTests.m +295 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNSecureRectanglesTests.m +568 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNSettleOnceTests.m +134 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNSpanHandlesTests.m +153 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNStatusMapperTests.m +81 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNValuesTests.m +32 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNWrapperChannelHolderTests.m +205 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNWrapperTests.m +66 -0
- package/ios/react-native-spm-prefix.h +10 -0
- package/native-versions.json +10 -0
- package/package.json +62 -3
- package/plugin/build/bundle-phase.d.ts +41 -0
- package/plugin/build/bundle-phase.js +116 -0
- package/plugin/build/bundle-phase.js.map +1 -0
- package/plugin/build/dsym-script.d.ts +32 -0
- package/plugin/build/dsym-script.js +159 -0
- package/plugin/build/dsym-script.js.map +1 -0
- package/plugin/build/endpoint.d.ts +30 -0
- package/plugin/build/endpoint.js +69 -0
- package/plugin/build/endpoint.js.map +1 -0
- package/plugin/build/gradle.d.ts +65 -0
- package/plugin/build/gradle.js +1066 -0
- package/plugin/build/gradle.js.map +1 -0
- package/plugin/build/index.d.ts +85 -0
- package/plugin/build/index.js +217 -0
- package/plugin/build/index.js.map +1 -0
- package/plugin/build/manifest.d.ts +48 -0
- package/plugin/build/manifest.js +69 -0
- package/plugin/build/manifest.js.map +1 -0
- package/plugin/build/native-versions.baked.json +4 -0
- package/plugin/build/native-versions.d.ts +10 -0
- package/plugin/build/native-versions.js +27 -0
- package/plugin/build/native-versions.js.map +1 -0
- package/plugin/build/pbx-string.d.ts +8 -0
- package/plugin/build/pbx-string.js +31 -0
- package/plugin/build/pbx-string.js.map +1 -0
- package/plugin/build/podfile.d.ts +3 -0
- package/plugin/build/podfile.js +28 -0
- package/plugin/build/podfile.js.map +1 -0
- package/plugin/build/properties.d.ts +19 -0
- package/plugin/build/properties.js +41 -0
- package/plugin/build/properties.js.map +1 -0
- package/plugin/build/scheme.d.ts +20 -0
- package/plugin/build/scheme.js +107 -0
- package/plugin/build/scheme.js.map +1 -0
- package/react-native.config.js +26 -0
- package/scripts/bugsee-sourcemaps.gradle +201 -0
- package/scripts/bugsee-xcode.sh +83 -0
- package/scripts/compose-then-inject.js +113 -0
- package/scripts/hermes-sourcemaps.js +634 -0
- package/scripts/hermesc-preserve-js.cmd +6 -0
- package/scripts/hermesc-preserve-js.js +200 -0
- package/scripts/hermesc-preserve-js.sh +7 -0
- package/src/NativeBugsee.ts +622 -0
- package/src/apm/notify.ts +58 -0
- package/src/apm/span.ts +403 -0
- package/src/apm/types.ts +57 -0
- package/src/appearance/report.ts +171 -0
- package/src/architecture.ts +48 -0
- package/src/attributes/errors.ts +39 -0
- package/src/attributes/validate.ts +150 -0
- package/src/breadcrumbs/add.ts +58 -0
- package/src/breadcrumbs/data.ts +33 -0
- package/src/breadcrumbs/filter.ts +215 -0
- package/src/breadcrumbs/types.ts +64 -0
- package/src/bridge/json.ts +110 -0
- package/src/console/capture.ts +180 -0
- package/src/console/dedup.ts +175 -0
- package/src/data/validate.ts +259 -0
- package/src/errorName.ts +32 -0
- package/src/exceptions/ErrorBoundary.tsx +92 -0
- package/src/exceptions/RootErrorReporter.tsx +61 -0
- package/src/exceptions/debugIds.ts +118 -0
- package/src/exceptions/handlers.ts +236 -0
- package/src/exceptions/options.ts +85 -0
- package/src/exceptions/payload.ts +456 -0
- package/src/exceptions/report.ts +170 -0
- package/src/exceptions/sha1.ts +148 -0
- package/src/exceptions/stack.ts +355 -0
- package/src/index.ts +962 -0
- package/src/logs/filter.ts +90 -0
- package/src/logs/log.ts +36 -0
- package/src/network/add.ts +165 -0
- package/src/network/filter.ts +198 -0
- package/src/options/AndroidLaunchOptions.ts +78 -0
- package/src/options/BugseeLaunchOptions.ts +190 -0
- package/src/options/IOSLaunchOptions.ts +57 -0
- package/src/options/android-options-manifest.json +646 -0
- package/src/options/createDefaultLaunchOptions.ts +29 -0
- package/src/options/endpoint.ts +58 -0
- package/src/options/enums.ts +104 -0
- package/src/options/ios-enums.json +19 -0
- package/src/options/keys.ts +39 -0
- package/src/options/option-enums.json +34 -0
- package/src/options/option-keys.json +107 -0
- package/src/report/BugseeReport.ts +264 -0
- package/src/report/CreatedReport.ts +127 -0
- package/src/report/dispatcher.ts +95 -0
- package/src/report/errors.ts +48 -0
- package/src/report/fields.ts +40 -0
- package/src/report/types.ts +157 -0
- package/src/report/validate.ts +197 -0
- package/src/secure/BugseeSecure.tsx +202 -0
- package/src/secure/ancestry.ts +622 -0
- package/src/secure/drivers.ts +342 -0
- package/src/secure/followEvents.ts +57 -0
- package/src/secure/hold.ts +99 -0
- package/src/secure/measureLoop.ts +323 -0
- package/src/secure/nativeAnimation.ts +1005 -0
- package/src/secure/rectangles.ts +93 -0
- package/src/secure/registry.ts +237 -0
- package/src/secure/surface.ts +83 -0
- package/src/secure/tracker.ts +723 -0
- package/src/secure/transition.ts +488 -0
- package/src/secure/unit.ts +22 -0
- package/src/status.ts +16 -0
- package/src/version.ts +9 -0
- package/src/viewtree/anchor.tsx +105 -0
- package/src/viewtree/constants.ts +20 -0
- package/src/viewtree/fiber.ts +251 -0
- package/src/viewtree/requests.ts +347 -0
- package/src/viewtree/walk.ts +902 -0
- package/src/wrapper/channel.ts +33 -0
- package/src/wrapper/collect.ts +52 -0
- package/src/wrapper/events.ts +45 -0
- package/src/wrapper/identity.ts +54 -0
- package/src/wrapper/lifecycle-events.ts +89 -0
|
@@ -0,0 +1,634 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Hermes emits an intermediate compiler map, then `compose-source-maps.js`
|
|
5
|
+
* writes the map a crash actually consults. `composeSourceMaps` builds a new
|
|
6
|
+
* object and drops `debug_id`, so `bugsee-cli sourcemaps inject` has to run
|
|
7
|
+
* on the composed map, after that script. The runtime stub has to be in the
|
|
8
|
+
* JavaScript `hermesc` compiles; when a bytecode output is given, this
|
|
9
|
+
* recompiles that JS and copies the same id back onto the recomposed map.
|
|
10
|
+
*
|
|
11
|
+
* `upload`, and `finish` after it has stamped the map, run
|
|
12
|
+
* `bugsee-cli debug-files upload --type sourcemaps` on that composed map. The
|
|
13
|
+
* upload runs only when it is switched on and a real app token is configured;
|
|
14
|
+
* otherwise one line says why it skipped. A failed upload warns and the build
|
|
15
|
+
* continues. The token reaches the CLI through its environment, never argv.
|
|
16
|
+
*
|
|
17
|
+
* Before upload, `sources` that are absolute paths under the project root are
|
|
18
|
+
* rewritten to root-relative ones with a leading slash (`/scenarios/a.ts`),
|
|
19
|
+
* the shape Expo's maps already have, so the dashboard never shows the build
|
|
20
|
+
* machine's directory layout. Absolute paths outside the root (workspace
|
|
21
|
+
* packages in a monorepo) become `../`-relative to it; entries that are
|
|
22
|
+
* already relative, and paths on another Windows drive, are left as they are.
|
|
23
|
+
* The rewrite goes to a
|
|
24
|
+
* temporary copy; the map on disk is untouched. Symbolication reads the map's
|
|
25
|
+
* `mappings` and the debug id, never the `sources` strings.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
const fs = require('node:fs');
|
|
29
|
+
const os = require('node:os');
|
|
30
|
+
const path = require('node:path');
|
|
31
|
+
|
|
32
|
+
const UPLOAD_ARGV = ['debug-files', 'upload', '--type', 'sourcemaps'];
|
|
33
|
+
const DEBUG_ID_MARK = '//# debugId=';
|
|
34
|
+
const UPLOAD_TIMEOUT_MS = 5 * 60 * 1000;
|
|
35
|
+
const SOURCE_MAP_FLAG = '-output-source-map';
|
|
36
|
+
|
|
37
|
+
function uploadArgv(composedMapPath, appVersion, appBuild) {
|
|
38
|
+
return [...UPLOAD_ARGV, '--version', appVersion, '--build', appBuild, composedMapPath];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function say(line) {
|
|
42
|
+
process.stderr.write(`bugsee: ${line}\n`);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Xcode reads a build-phase line shaped `error: ...` (optionally after a
|
|
46
|
+
// `file:line: ` prefix) as a build error and fails the Archive, whatever the
|
|
47
|
+
// script's exit status. bugsee-cli prints `error: upload failed: ...`, so its
|
|
48
|
+
// output is relayed as `warning: bugsee: ...`: the failure stays visible and
|
|
49
|
+
// the customer's build goes on. Mirrors CLI_OUTPUT_FILTER in
|
|
50
|
+
// plugin/src/dsym-script.ts, which does the same in sh.
|
|
51
|
+
const XCODE_ERROR_LINE = /^(?:.*: )?(?:[Ff]atal [Ee]rror|[Ee]rror): (.*)$/;
|
|
52
|
+
|
|
53
|
+
function diagnosticSafe(text) {
|
|
54
|
+
return String(text)
|
|
55
|
+
.split('\n')
|
|
56
|
+
.map((line) => {
|
|
57
|
+
const match = XCODE_ERROR_LINE.exec(line);
|
|
58
|
+
return match ? `warning: bugsee: ${match[1]}` : line;
|
|
59
|
+
})
|
|
60
|
+
.join('\n');
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function spawn(file, args, options) {
|
|
64
|
+
return require('node:child_process').spawnSync(file, args, { encoding: 'utf8', ...options });
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function run(file, args, what) {
|
|
68
|
+
const result = spawn(file, args);
|
|
69
|
+
if (result.error) {
|
|
70
|
+
throw new Error(`${what} failed to start: ${result.error.message}`);
|
|
71
|
+
}
|
|
72
|
+
if (result.status !== 0) {
|
|
73
|
+
const detail = (result.stderr || result.stdout || '').trim();
|
|
74
|
+
throw new Error(`${what} exited ${result.status}${detail ? `: ${detail}` : ''}`);
|
|
75
|
+
}
|
|
76
|
+
return result;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function readJson(file) {
|
|
80
|
+
return JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function remove(file) {
|
|
84
|
+
fs.rmSync(file, { recursive: true, force: true });
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function resolveCli() {
|
|
88
|
+
const pkgPath = require.resolve('@bugsee/cli/package.json');
|
|
89
|
+
return path.join(path.dirname(pkgPath), readJson(pkgPath).bin['bugsee-cli']);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function retargetSourceMappingUrl(source, url) {
|
|
93
|
+
const comment = `//# sourceMappingURL=${url}`;
|
|
94
|
+
if (source.includes('//# sourceMappingURL=')) {
|
|
95
|
+
return source.replace(/\/\/# sourceMappingURL=\S+/g, comment);
|
|
96
|
+
}
|
|
97
|
+
return source.endsWith('\n') ? `${source}${comment}\n` : `${source}\n${comment}\n`;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function readDebugId(source) {
|
|
101
|
+
const at = source.lastIndexOf(DEBUG_ID_MARK);
|
|
102
|
+
if (at < 0) {
|
|
103
|
+
throw new Error('sourcemaps inject did not write a debug id into the bundle');
|
|
104
|
+
}
|
|
105
|
+
const id = source.slice(at + DEBUG_ID_MARK.length).split(/\s/)[0];
|
|
106
|
+
if (!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(id)) {
|
|
107
|
+
throw new Error('sourcemaps inject wrote a debug id that is not a UUID');
|
|
108
|
+
}
|
|
109
|
+
return id;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Inject into `bundlePath`, pairing it with the composed map. The intermediate
|
|
114
|
+
* compiler map is not staged and is not an argument to the CLI.
|
|
115
|
+
*/
|
|
116
|
+
function injectComposedSourceMap({ bundlePath, composedMapPath, cliPath }) {
|
|
117
|
+
const stage = fs.mkdtempSync(path.join(os.tmpdir(), 'bugsee-sourcemaps-'));
|
|
118
|
+
try {
|
|
119
|
+
const stagedBundle = path.join(stage, 'bundle.js');
|
|
120
|
+
const stagedMap = path.join(stage, 'composed.js.map');
|
|
121
|
+
fs.writeFileSync(
|
|
122
|
+
stagedBundle,
|
|
123
|
+
retargetSourceMappingUrl(fs.readFileSync(bundlePath, 'utf8'), 'composed.js.map'),
|
|
124
|
+
);
|
|
125
|
+
fs.copyFileSync(composedMapPath, stagedMap);
|
|
126
|
+
const cli = cliPath || resolveCli();
|
|
127
|
+
run(process.execPath, [cli, 'sourcemaps', 'inject', stagedBundle], 'bugsee-cli sourcemaps inject');
|
|
128
|
+
const injected = fs.readFileSync(stagedBundle, 'utf8');
|
|
129
|
+
const debugId = readDebugId(injected);
|
|
130
|
+
const map = readJson(stagedMap);
|
|
131
|
+
if (map.debug_id !== debugId || map.debugId !== debugId) {
|
|
132
|
+
throw new Error('composed map debug id does not match the bundle');
|
|
133
|
+
}
|
|
134
|
+
// Checked first, so a refused inject leaves both inputs as they were.
|
|
135
|
+
fs.writeFileSync(bundlePath, injected);
|
|
136
|
+
fs.copyFileSync(stagedMap, composedMapPath);
|
|
137
|
+
return { debugId };
|
|
138
|
+
} finally {
|
|
139
|
+
remove(stage);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Where hermesc-preserve-js.sh writes, for a bundle under
|
|
145
|
+
* `generated/assets`: the last such segment is the one under the build
|
|
146
|
+
* directory, which is what the Gradle hook relativizes against. Any other
|
|
147
|
+
* directory maps to itself.
|
|
148
|
+
*/
|
|
149
|
+
function preserveDirFor(filePath, paths = path) {
|
|
150
|
+
const marker = `${paths.sep}generated${paths.sep}assets${paths.sep}`;
|
|
151
|
+
const dir = paths.dirname(filePath);
|
|
152
|
+
const at = dir.lastIndexOf(marker);
|
|
153
|
+
if (at < 0) {
|
|
154
|
+
return dir;
|
|
155
|
+
}
|
|
156
|
+
const replacement = `${paths.sep}intermediates${paths.sep}bugsee-sourcemaps${paths.sep}`;
|
|
157
|
+
return `${dir.slice(0, at)}${replacement}${dir.slice(at + marker.length)}`;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function sidecarName(bytecodePath) {
|
|
161
|
+
return `${path.basename(bytecodePath)}.bugsee-hermesc`;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function readHermescSidecar(bytecodePath) {
|
|
165
|
+
const name = sidecarName(bytecodePath);
|
|
166
|
+
const candidates = [path.join(preserveDirFor(bytecodePath), name), path.join(path.dirname(bytecodePath), name)];
|
|
167
|
+
for (const sidecar of candidates) {
|
|
168
|
+
if (!fs.existsSync(sidecar)) continue;
|
|
169
|
+
const hermesc = fs.readFileSync(sidecar, 'utf8').trim();
|
|
170
|
+
if (hermesc) return hermesc;
|
|
171
|
+
}
|
|
172
|
+
return null;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const PACKAGED_PRESERVE_SUFFIXES = [
|
|
176
|
+
'.bugsee-js-source',
|
|
177
|
+
'.bugsee-hermesc',
|
|
178
|
+
'.bugsee-recompile',
|
|
179
|
+
'.bugsee-recompile.map',
|
|
180
|
+
];
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Copies beside the packaged bundle would ship in the APK. The preserved JS
|
|
184
|
+
* and the hermesc note belong to this build: left behind, a later build whose
|
|
185
|
+
* hermesc did not run through hermesc-preserve-js.sh would recompile the old
|
|
186
|
+
* JS over its new bundle. Only a `.bugsee-js-source` bundle is deleted: iOS
|
|
187
|
+
* passes the real `main.jsbundle`.
|
|
188
|
+
*/
|
|
189
|
+
function removePreserveFiles(bundlePath, bytecodePath) {
|
|
190
|
+
if (bundlePath.endsWith('.bugsee-js-source')) {
|
|
191
|
+
remove(bundlePath);
|
|
192
|
+
}
|
|
193
|
+
if (!bytecodePath) return;
|
|
194
|
+
for (const suffix of PACKAGED_PRESERVE_SUFFIXES) {
|
|
195
|
+
remove(bytecodePath + suffix);
|
|
196
|
+
}
|
|
197
|
+
remove(path.join(preserveDirFor(bytecodePath), sidecarName(bytecodePath)));
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function recompile({ hermesc, bundlePath, bytecodePath, intermediateMapPath, hermesArgs }) {
|
|
201
|
+
const stage = fs.mkdtempSync(path.join(os.tmpdir(), 'bugsee-hermesc-'));
|
|
202
|
+
try {
|
|
203
|
+
const tempOut = path.join(stage, 'bundle.hbc');
|
|
204
|
+
// hermesArgs carries -output-source-map; finishAfterCompose checked.
|
|
205
|
+
const args = ['-w', '-emit-binary', '-max-diagnostic-width=80', ...hermesArgs, '-out', tempOut, bundlePath];
|
|
206
|
+
run(hermesc, args, 'hermesc');
|
|
207
|
+
fs.copyFileSync(tempOut, bytecodePath);
|
|
208
|
+
fs.copyFileSync(`${tempOut}.map`, intermediateMapPath);
|
|
209
|
+
} finally {
|
|
210
|
+
remove(stage);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function runCompose({ composeScript, packagerMapPath, intermediateMapPath, composedMapPath }) {
|
|
215
|
+
run(
|
|
216
|
+
process.execPath,
|
|
217
|
+
[composeScript, packagerMapPath, intermediateMapPath, '-o', composedMapPath],
|
|
218
|
+
'compose-source-maps.js',
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function stampDebugId(mapPath, debugId) {
|
|
223
|
+
const map = readJson(mapPath);
|
|
224
|
+
map.debug_id = debugId;
|
|
225
|
+
map.debugId = debugId;
|
|
226
|
+
fs.writeFileSync(mapPath, JSON.stringify(map));
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Compose has already produced `composedMapPath`. Inject that map and the JS
|
|
231
|
+
* bundle. When bytecode output is set, compile the injected JS and, if a
|
|
232
|
+
* compose script is set, compose again — that second compose drops the id —
|
|
233
|
+
* then write the bundle's id back onto the composed map only.
|
|
234
|
+
*/
|
|
235
|
+
function finishAfterCompose(opts) {
|
|
236
|
+
try {
|
|
237
|
+
if (opts.bytecodePath && !opts.hermesArgs?.includes(SOURCE_MAP_FLAG)) {
|
|
238
|
+
say(
|
|
239
|
+
`hermesFlags has no ${SOURCE_MAP_FLAG}, so React Native composed no source map; ` +
|
|
240
|
+
'no debug id is injected and no source map is uploaded',
|
|
241
|
+
);
|
|
242
|
+
return null;
|
|
243
|
+
}
|
|
244
|
+
const injected = injectComposedSourceMap(opts);
|
|
245
|
+
if (!opts.bytecodePath) {
|
|
246
|
+
return injected;
|
|
247
|
+
}
|
|
248
|
+
const hermesc = opts.hermesc || readHermescSidecar(opts.bytecodePath);
|
|
249
|
+
if (!hermesc) {
|
|
250
|
+
throw new Error('hermesc not found; the debug-id stub would not be in the bytecode');
|
|
251
|
+
}
|
|
252
|
+
recompile({
|
|
253
|
+
hermesc,
|
|
254
|
+
bundlePath: opts.bundlePath,
|
|
255
|
+
bytecodePath: opts.bytecodePath,
|
|
256
|
+
intermediateMapPath: opts.intermediateMapPath,
|
|
257
|
+
hermesArgs: opts.hermesArgs,
|
|
258
|
+
});
|
|
259
|
+
if (opts.composeScript) {
|
|
260
|
+
runCompose(opts);
|
|
261
|
+
stampDebugId(opts.composedMapPath, injected.debugId);
|
|
262
|
+
}
|
|
263
|
+
return injected;
|
|
264
|
+
} finally {
|
|
265
|
+
removePreserveFiles(opts.bundlePath, opts.bytecodePath);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
const OFF_VALUES = new Set(['false', '0', 'no', 'off']);
|
|
270
|
+
|
|
271
|
+
function isOff(value) {
|
|
272
|
+
return value === false || OFF_VALUES.has(String(value).trim().toLowerCase());
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
const ON_VALUES = new Set(['true', '1', 'yes', 'on']);
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* iOS Debug builds for a device bundle and compose too. Their -Og maps are
|
|
279
|
+
* not uploaded unless BUGSEE_UPLOAD_DEBUG_SOURCEMAPS opts in, as Android
|
|
280
|
+
* never bundles debug variants.
|
|
281
|
+
*/
|
|
282
|
+
function debugUploadAllowed(env) {
|
|
283
|
+
return ON_VALUES.has(String(env.BUGSEE_UPLOAD_DEBUG_SOURCEMAPS).trim().toLowerCase());
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/** Off when the build passes `false` or BUGSEE_UPLOAD_SOURCEMAPS says so. */
|
|
287
|
+
function uploadDisabled(option, env) {
|
|
288
|
+
return isOff(option) || isOff(env.BUGSEE_UPLOAD_SOURCEMAPS);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
function readProperties(file) {
|
|
292
|
+
const values = {};
|
|
293
|
+
let text;
|
|
294
|
+
try {
|
|
295
|
+
text = fs.readFileSync(file, 'utf8');
|
|
296
|
+
} catch {
|
|
297
|
+
return values;
|
|
298
|
+
}
|
|
299
|
+
// A `#` comment yields a key starting with `#`, which nothing reads.
|
|
300
|
+
for (const line of text.split('\n')) {
|
|
301
|
+
const eq = line.indexOf('=');
|
|
302
|
+
if (eq < 0) continue;
|
|
303
|
+
values[line.slice(0, eq).trim()] = line.slice(eq + 1).trim();
|
|
304
|
+
}
|
|
305
|
+
return values;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
function readCredentials(file) {
|
|
309
|
+
try {
|
|
310
|
+
return readJson(file);
|
|
311
|
+
} catch {
|
|
312
|
+
return {};
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
function firstString(...values) {
|
|
317
|
+
return values.find((value) => typeof value === 'string' && value.length > 0) ?? '';
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Token: the one the Expo plugin baked into the build (BUGSEE_PLUGIN_APP_TOKEN
|
|
322
|
+
* on iOS, `app_token` in android/bugsee.properties), then BUGSEE_APP_TOKEN,
|
|
323
|
+
* then BUGSEE_TOKEN_IOS / BUGSEE_TOKEN_ANDROID, then the example app's
|
|
324
|
+
* credentials.json. Endpoint: `plugin.endpoint`, BUGSEE_ENDPOINT, then
|
|
325
|
+
* credentials.json. EAS keeps a credentials.json of its own whose values are
|
|
326
|
+
* objects, so only strings count.
|
|
327
|
+
*/
|
|
328
|
+
function resolveUploadSettings({ platform, propertiesPath, credentialsPath, env }) {
|
|
329
|
+
const props = propertiesPath ? readProperties(propertiesPath) : {};
|
|
330
|
+
const creds = credentialsPath ? readCredentials(credentialsPath) : {};
|
|
331
|
+
const platformToken = platform === 'ios' ? env.BUGSEE_TOKEN_IOS : env.BUGSEE_TOKEN_ANDROID;
|
|
332
|
+
return {
|
|
333
|
+
token: firstString(
|
|
334
|
+
env.BUGSEE_PLUGIN_APP_TOKEN,
|
|
335
|
+
props.app_token,
|
|
336
|
+
env.BUGSEE_APP_TOKEN,
|
|
337
|
+
platformToken,
|
|
338
|
+
creds[platform],
|
|
339
|
+
),
|
|
340
|
+
endpoint: firstString(props['plugin.endpoint'], env.BUGSEE_ENDPOINT, creds.endpoint),
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
function isAbsoluteSource(source) {
|
|
345
|
+
return path.posix.isAbsolute(source) || path.win32.isAbsolute(source);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* `dir` with symlinks resolved, through its nearest existing parent when it
|
|
350
|
+
* does not exist. `cache` (a Map) keeps one answer per directory, so a map with
|
|
351
|
+
* thousands of sources pays one filesystem lookup per directory, not per source.
|
|
352
|
+
*/
|
|
353
|
+
function realDirectory(dir, flavor, cache) {
|
|
354
|
+
const known = cache.get(dir);
|
|
355
|
+
if (known !== undefined) return known;
|
|
356
|
+
const parent = flavor.dirname(dir);
|
|
357
|
+
let real;
|
|
358
|
+
try {
|
|
359
|
+
real = fs.realpathSync(dir);
|
|
360
|
+
} catch {
|
|
361
|
+
real = parent === dir ? dir : flavor.join(realDirectory(parent, flavor, cache), flavor.basename(dir));
|
|
362
|
+
}
|
|
363
|
+
cache.set(dir, real);
|
|
364
|
+
return real;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/** The parts of `to` relative to `from`, or undefined when there is no relative form (another drive). */
|
|
368
|
+
function relativeParts(flavor, from, to) {
|
|
369
|
+
const relative = flavor.relative(from, to);
|
|
370
|
+
if (!relative || flavor.isAbsolute(relative)) return undefined;
|
|
371
|
+
return relative.split(/[\\/]/);
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
/**
|
|
375
|
+
* Root-relative form of one `sources` entry, or the entry itself when it is
|
|
376
|
+
* not an absolute path (or has no relative form).
|
|
377
|
+
*
|
|
378
|
+
* `memo` ({ dirs }) is shared across one map's entries.
|
|
379
|
+
*/
|
|
380
|
+
function relativizeSource(source, projectRoot, memo = { dirs: new Map() }) {
|
|
381
|
+
if (typeof source !== 'string' || !isAbsoluteSource(source)) return source;
|
|
382
|
+
const flavor = /^(?:[A-Za-z]:|\\\\)/.test(source) ? path.win32 : path.posix;
|
|
383
|
+
const direct = relativeParts(flavor, flavor.resolve(projectRoot), flavor.resolve(source));
|
|
384
|
+
// Another drive on Windows: there is no relative form.
|
|
385
|
+
if (direct === undefined) return source;
|
|
386
|
+
// Inside the root: `/scenarios/a.ts`, as Expo writes it. A source that reaches
|
|
387
|
+
// the root through an in-tree symlink (a linked workspace package under
|
|
388
|
+
// node_modules) stays under the root too, so it is not resolved here.
|
|
389
|
+
if (direct[0] !== '..') return `/${direct.join('/')}`;
|
|
390
|
+
// Outside the root by plain paths. That is also what a root and a source that
|
|
391
|
+
// name the same place through a symlink look like (macOS: Xcode reports
|
|
392
|
+
// /tmp/... while Metro writes /private/tmp/...), so compare real paths,
|
|
393
|
+
// which gives `/scenarios/a.ts` for that case and `../packages/x/a.js` for a
|
|
394
|
+
// genuinely outside source (a linked workspace package), still free of the
|
|
395
|
+
// machine's absolute layout. Only this machine's own paths can be resolved:
|
|
396
|
+
// `path` is the host's flavor (posix or win32).
|
|
397
|
+
if (flavor === path) {
|
|
398
|
+
const root = realDirectory(flavor.resolve(projectRoot), flavor, memo.dirs);
|
|
399
|
+
const resolved = flavor.resolve(source);
|
|
400
|
+
let real;
|
|
401
|
+
try {
|
|
402
|
+
// The file itself first: it may be a symlink to a file inside the root.
|
|
403
|
+
real = fs.realpathSync(resolved);
|
|
404
|
+
} catch {
|
|
405
|
+
real = flavor.join(realDirectory(flavor.dirname(resolved), flavor, memo.dirs), flavor.basename(resolved));
|
|
406
|
+
}
|
|
407
|
+
const viaReal = relativeParts(flavor, root, real);
|
|
408
|
+
// No relative form: the source is the root itself (through a link).
|
|
409
|
+
if (viaReal !== undefined) return viaReal[0] === '..' ? viaReal.join('/') : `/${viaReal.join('/')}`;
|
|
410
|
+
}
|
|
411
|
+
return direct.join('/');
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
/** Returns the map text with `sources` made project-relative, or the text itself if nothing changed. */
|
|
415
|
+
function relativizeSourceMap(mapText, projectRoot) {
|
|
416
|
+
const map = JSON.parse(mapText);
|
|
417
|
+
if (!Array.isArray(map.sources) || !projectRoot) return mapText;
|
|
418
|
+
let changed = false;
|
|
419
|
+
const memo = { dirs: new Map() };
|
|
420
|
+
map.sources = map.sources.map((source) => {
|
|
421
|
+
const next = relativizeSource(source, projectRoot, memo);
|
|
422
|
+
if (next !== source) changed = true;
|
|
423
|
+
return next;
|
|
424
|
+
});
|
|
425
|
+
return changed ? JSON.stringify(map) : mapText;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
const PLACEHOLDER_TOKEN = /^0{12}[0-9a-f]0{3}[0-9a-f]0{15}$/i;
|
|
429
|
+
|
|
430
|
+
function readMapDebugId(mapPath) {
|
|
431
|
+
try {
|
|
432
|
+
return readJson(mapPath).debug_id ?? null;
|
|
433
|
+
} catch {
|
|
434
|
+
return null;
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* Upload one composed map. Never throws: a build is not failed over symbols.
|
|
440
|
+
* Returns what happened, for the caller's tests.
|
|
441
|
+
*/
|
|
442
|
+
function uploadComposedSourceMap({
|
|
443
|
+
composedMapPath,
|
|
444
|
+
enabled = true,
|
|
445
|
+
configuration,
|
|
446
|
+
allowDebug = false,
|
|
447
|
+
token,
|
|
448
|
+
endpoint,
|
|
449
|
+
appVersion,
|
|
450
|
+
appBuild,
|
|
451
|
+
cliPath,
|
|
452
|
+
nodePath,
|
|
453
|
+
projectRoot,
|
|
454
|
+
}) {
|
|
455
|
+
if (!enabled) {
|
|
456
|
+
say('source map upload skipped: uploadSourcemaps is off');
|
|
457
|
+
return { status: 'skipped', reason: 'disabled' };
|
|
458
|
+
}
|
|
459
|
+
if (String(configuration).includes('Debug') && !allowDebug) {
|
|
460
|
+
say('source map upload skipped: Debug configuration (set BUGSEE_UPLOAD_DEBUG_SOURCEMAPS=true to upload)');
|
|
461
|
+
return { status: 'skipped', reason: 'debug' };
|
|
462
|
+
}
|
|
463
|
+
// Checked trimmed: bugsee-cli trims the token before it builds the URL, so
|
|
464
|
+
// a padded placeholder would otherwise reach the endpoint.
|
|
465
|
+
const tokenCheck = typeof token === 'string' ? token.trim() : '';
|
|
466
|
+
if (!tokenCheck) {
|
|
467
|
+
say('source map upload skipped: no app token is configured');
|
|
468
|
+
return { status: 'skipped', reason: 'no-token' };
|
|
469
|
+
}
|
|
470
|
+
if (PLACEHOLDER_TOKEN.test(tokenCheck.replace(/-/g, ''))) {
|
|
471
|
+
say('source map upload skipped: the app token is the placeholder');
|
|
472
|
+
return { status: 'skipped', reason: 'placeholder' };
|
|
473
|
+
}
|
|
474
|
+
if (!appVersion || !appBuild) {
|
|
475
|
+
say('source map upload skipped: the app version or build number is unknown');
|
|
476
|
+
return { status: 'skipped', reason: 'no-version' };
|
|
477
|
+
}
|
|
478
|
+
if (!fs.existsSync(composedMapPath)) {
|
|
479
|
+
say(`source map upload skipped: no source map at ${composedMapPath}`);
|
|
480
|
+
return { status: 'skipped', reason: 'no-map' };
|
|
481
|
+
}
|
|
482
|
+
let cli;
|
|
483
|
+
try {
|
|
484
|
+
cli = cliPath || resolveCli();
|
|
485
|
+
} catch {
|
|
486
|
+
say('source map upload failed (@bugsee/cli is not installed); the app build continues');
|
|
487
|
+
return { status: 'failed', exitCode: null };
|
|
488
|
+
}
|
|
489
|
+
const env = { ...process.env, BUGSEE_APP_TOKEN: token };
|
|
490
|
+
if (endpoint) env.BUGSEE_ENDPOINT = endpoint;
|
|
491
|
+
let stage = null;
|
|
492
|
+
let uploadPath = composedMapPath;
|
|
493
|
+
try {
|
|
494
|
+
const original = fs.readFileSync(composedMapPath, 'utf8');
|
|
495
|
+
const rewritten = relativizeSourceMap(original, projectRoot);
|
|
496
|
+
if (rewritten !== original) {
|
|
497
|
+
stage = fs.mkdtempSync(path.join(os.tmpdir(), 'bugsee-upload-'));
|
|
498
|
+
uploadPath = path.join(stage, path.basename(composedMapPath));
|
|
499
|
+
fs.writeFileSync(uploadPath, rewritten);
|
|
500
|
+
}
|
|
501
|
+
} catch (err) {
|
|
502
|
+
say(`could not make source map paths project-relative (${err.message}); uploading the map as it is`);
|
|
503
|
+
if (stage) remove(stage);
|
|
504
|
+
stage = null;
|
|
505
|
+
uploadPath = composedMapPath;
|
|
506
|
+
}
|
|
507
|
+
let result;
|
|
508
|
+
try {
|
|
509
|
+
result = spawn(nodePath || process.execPath, [cli, ...uploadArgv(uploadPath, appVersion, appBuild)], {
|
|
510
|
+
env,
|
|
511
|
+
timeout: UPLOAD_TIMEOUT_MS,
|
|
512
|
+
});
|
|
513
|
+
} finally {
|
|
514
|
+
if (stage) remove(stage);
|
|
515
|
+
}
|
|
516
|
+
if (result.stdout) process.stdout.write(diagnosticSafe(result.stdout));
|
|
517
|
+
if (result.stderr) process.stderr.write(diagnosticSafe(result.stderr));
|
|
518
|
+
if (result.error && !result.signal) {
|
|
519
|
+
say(`source map upload failed (bugsee-cli did not start: ${result.error.code}); the app build continues`);
|
|
520
|
+
return { status: 'failed', exitCode: null };
|
|
521
|
+
}
|
|
522
|
+
if (result.status !== 0) {
|
|
523
|
+
say(`source map upload failed (bugsee-cli exit ${result.status ?? result.signal}); the app build continues`);
|
|
524
|
+
return { status: 'failed', exitCode: result.status };
|
|
525
|
+
}
|
|
526
|
+
const debugId = readMapDebugId(composedMapPath);
|
|
527
|
+
say(`uploaded source map ${debugId}`);
|
|
528
|
+
return { status: 'uploaded', debugId };
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
function uploadFromArgs(args) {
|
|
532
|
+
const settings = resolveUploadSettings({
|
|
533
|
+
platform: args.platform,
|
|
534
|
+
propertiesPath: args.properties,
|
|
535
|
+
credentialsPath: args.credentials,
|
|
536
|
+
env: process.env,
|
|
537
|
+
});
|
|
538
|
+
return uploadComposedSourceMap({
|
|
539
|
+
composedMapPath: args.composed,
|
|
540
|
+
enabled: !uploadDisabled(args['upload-sourcemaps'], process.env),
|
|
541
|
+
configuration: args.configuration,
|
|
542
|
+
allowDebug: debugUploadAllowed(process.env),
|
|
543
|
+
token: settings.token,
|
|
544
|
+
endpoint: settings.endpoint,
|
|
545
|
+
appVersion: args['app-version'],
|
|
546
|
+
appBuild: args['app-build'],
|
|
547
|
+
projectRoot: args['project-root'],
|
|
548
|
+
});
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
function parseArgs(argv) {
|
|
552
|
+
const out = { _: [], hermesArgs: [] };
|
|
553
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
554
|
+
const arg = argv[i];
|
|
555
|
+
if (arg === '--hermes-arg') {
|
|
556
|
+
out.hermesArgs.push(argv[(i += 1)]);
|
|
557
|
+
continue;
|
|
558
|
+
}
|
|
559
|
+
if (arg.startsWith('--')) {
|
|
560
|
+
out[arg.slice(2)] = argv[(i += 1)];
|
|
561
|
+
continue;
|
|
562
|
+
}
|
|
563
|
+
out._.push(arg);
|
|
564
|
+
}
|
|
565
|
+
return out;
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
function main(argv) {
|
|
569
|
+
const args = parseArgs(argv);
|
|
570
|
+
const command = args._[0];
|
|
571
|
+
if (command === 'inject') {
|
|
572
|
+
finishAfterCompose({
|
|
573
|
+
bundlePath: args.bundle,
|
|
574
|
+
composedMapPath: args.composed,
|
|
575
|
+
intermediateMapPath: args.intermediate,
|
|
576
|
+
});
|
|
577
|
+
return;
|
|
578
|
+
}
|
|
579
|
+
if (command === 'finish') {
|
|
580
|
+
const finished = finishAfterCompose({
|
|
581
|
+
bundlePath: args.bundle,
|
|
582
|
+
bytecodePath: args.bytecode,
|
|
583
|
+
composedMapPath: args.composed,
|
|
584
|
+
intermediateMapPath: args.intermediate,
|
|
585
|
+
packagerMapPath: args.packager,
|
|
586
|
+
composeScript: args.compose,
|
|
587
|
+
hermesc: args.hermesc,
|
|
588
|
+
hermesArgs: args.hermesArgs,
|
|
589
|
+
});
|
|
590
|
+
if (finished) {
|
|
591
|
+
uploadFromArgs(args);
|
|
592
|
+
}
|
|
593
|
+
return;
|
|
594
|
+
}
|
|
595
|
+
if (command === 'upload') {
|
|
596
|
+
uploadFromArgs(args);
|
|
597
|
+
return;
|
|
598
|
+
}
|
|
599
|
+
process.stderr.write('usage: hermes-sourcemaps.js inject|finish|upload [options]\n');
|
|
600
|
+
process.exitCode = 1;
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
module.exports = {
|
|
604
|
+
UPLOAD_ARGV,
|
|
605
|
+
cli,
|
|
606
|
+
debugUploadAllowed,
|
|
607
|
+
finishAfterCompose,
|
|
608
|
+
injectComposedSourceMap,
|
|
609
|
+
main,
|
|
610
|
+
preserveDirFor,
|
|
611
|
+
readDebugId,
|
|
612
|
+
relativizeSource,
|
|
613
|
+
relativizeSourceMap,
|
|
614
|
+
resolveUploadSettings,
|
|
615
|
+
retargetSourceMappingUrl,
|
|
616
|
+
diagnosticSafe,
|
|
617
|
+
uploadArgv,
|
|
618
|
+
uploadComposedSourceMap,
|
|
619
|
+
uploadDisabled,
|
|
620
|
+
};
|
|
621
|
+
|
|
622
|
+
/** Command-line entry: a failure prints its reason and sets exit code 1. */
|
|
623
|
+
function cli(argv) {
|
|
624
|
+
try {
|
|
625
|
+
main(argv);
|
|
626
|
+
} catch (err) {
|
|
627
|
+
process.stderr.write(`${err.message}\n`);
|
|
628
|
+
process.exitCode = 1;
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
if (require.main === module) {
|
|
633
|
+
cli(process.argv.slice(2));
|
|
634
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
@echo off
|
|
2
|
+
rem react.hermesCommand on Windows, where React Native runs it through
|
|
3
|
+
rem "cmd /c". macOS and Linux use hermesc-preserve-js.sh. The work, and its
|
|
4
|
+
rem non-zero exit when no bytecode came out, is in hermesc-preserve-js.js.
|
|
5
|
+
node "%~dp0hermesc-preserve-js.js" %*
|
|
6
|
+
exit /b %ERRORLEVEL%
|