@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,200 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The work behind `react.hermesCommand`. React Native runs the launcher with
|
|
6
|
+
* hermesc's own arguments: hermesc-preserve-js.sh on macOS and Linux,
|
|
7
|
+
* hermesc-preserve-js.cmd on Windows (React Native runs every command there
|
|
8
|
+
* through `cmd /c`, which cannot run a shell script). Both start this file.
|
|
9
|
+
*
|
|
10
|
+
* Copy the JS bundle aside before hermesc replaces it with bytecode, note
|
|
11
|
+
* which hermesc compiled it, then run that hermesc. Injection happens later,
|
|
12
|
+
* on the composed map (bugsee-sourcemaps.gradle, hermes-sourcemaps.js).
|
|
13
|
+
*
|
|
14
|
+
* Exits non-zero, with a `bugsee:` line, whenever no bytecode came out:
|
|
15
|
+
* React Native moves `<bundle>.hbc` over the bundle next, and a wrapper that
|
|
16
|
+
* exits 0 without it only fails later, far from the cause.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
const fs = require('node:fs');
|
|
20
|
+
const path = require('node:path');
|
|
21
|
+
const { preserveDirFor } = require('./hermes-sourcemaps');
|
|
22
|
+
|
|
23
|
+
/** The value after the last `-out`, as hermesc reads it. */
|
|
24
|
+
function outputOf(argv) {
|
|
25
|
+
let out;
|
|
26
|
+
for (let i = 1; i < argv.length; i += 1) {
|
|
27
|
+
if (argv[i - 1] === '-out') {
|
|
28
|
+
out = argv[i];
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return out;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** The first argument that is not a flag, not the output, and is a file. */
|
|
35
|
+
function bundleOf(argv, out, isFile) {
|
|
36
|
+
return argv.find((arg) => !arg.startsWith('-') && arg !== out && isFile(arg));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** React Native's own names: getHermesOSBin, getHermesCBin. */
|
|
40
|
+
function hermescBin(platform) {
|
|
41
|
+
if (platform === 'win32') {
|
|
42
|
+
return { osbin: 'win64-bin', bin: 'hermesc.exe' };
|
|
43
|
+
}
|
|
44
|
+
return { osbin: platform === 'linux' ? 'linux64-bin' : 'osx-bin', bin: 'hermesc' };
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** require.resolve from a directory, or null. */
|
|
48
|
+
function resolveFrom(request, from) {
|
|
49
|
+
try {
|
|
50
|
+
return require.resolve(request, { paths: [from] });
|
|
51
|
+
} catch {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* The hermesc React Native would have run. BUGSEE_REAL_HERMESC first. Expo
|
|
58
|
+
* SDK 57 resolves hermes-compiler from the react-native package, so a pnpm or
|
|
59
|
+
* Yarn workspace install under node_modules/react-native/node_modules is
|
|
60
|
+
* found. React Native 0.81 (Expo SDK 54) has no hermes-compiler package and
|
|
61
|
+
* ships sdks/hermesc beside react-native/package.json. Then the app's own
|
|
62
|
+
* node_modules. Null when none is there.
|
|
63
|
+
*/
|
|
64
|
+
function findHermesc({ env, cwd, platform, isExecutable, resolve = resolveFrom }) {
|
|
65
|
+
if (env.BUGSEE_REAL_HERMESC && isExecutable(env.BUGSEE_REAL_HERMESC)) {
|
|
66
|
+
return env.BUGSEE_REAL_HERMESC;
|
|
67
|
+
}
|
|
68
|
+
const { osbin, bin } = hermescBin(platform);
|
|
69
|
+
const candidates = [];
|
|
70
|
+
const rnPkg = resolve('react-native/package.json', cwd);
|
|
71
|
+
if (rnPkg) {
|
|
72
|
+
const rnDir = path.dirname(rnPkg);
|
|
73
|
+
const compilerPkg = resolve('hermes-compiler/package.json', rnDir);
|
|
74
|
+
if (compilerPkg) {
|
|
75
|
+
candidates.push(path.join(path.dirname(compilerPkg), 'hermesc', osbin, bin));
|
|
76
|
+
}
|
|
77
|
+
candidates.push(path.join(rnDir, 'sdks', 'hermesc', osbin, bin));
|
|
78
|
+
}
|
|
79
|
+
candidates.push(
|
|
80
|
+
path.join(cwd, 'node_modules', 'hermes-compiler', 'hermesc', osbin, bin),
|
|
81
|
+
path.join(cwd, 'node_modules', 'react-native', 'sdks', 'hermes', 'build', 'bin', bin),
|
|
82
|
+
);
|
|
83
|
+
return candidates.find((candidate) => isExecutable(candidate)) ?? null;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Where the preserved JS goes. The bundle directory is packaged as assets,
|
|
88
|
+
* so files beside the bundle would ship in the APK; intermediates are not.
|
|
89
|
+
*/
|
|
90
|
+
function preserveDirOf(js, env, cwd) {
|
|
91
|
+
const jsDir = path.dirname(js);
|
|
92
|
+
let dir;
|
|
93
|
+
if (env.BUGSEE_PRESERVE_DIR) {
|
|
94
|
+
dir = path.resolve(cwd, env.BUGSEE_PRESERVE_DIR);
|
|
95
|
+
} else {
|
|
96
|
+
dir = preserveDirFor(js);
|
|
97
|
+
if (dir === jsDir) {
|
|
98
|
+
return { error: `refusing to write preserve files beside the bundle (${jsDir})` };
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (dir === jsDir || dir.startsWith(jsDir + path.sep)) {
|
|
102
|
+
return { error: 'refusing to write preserve files into the packaged asset directory' };
|
|
103
|
+
}
|
|
104
|
+
return { dir };
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function isExecutableFile(file) {
|
|
108
|
+
try {
|
|
109
|
+
fs.accessSync(file, fs.constants.X_OK);
|
|
110
|
+
return fs.statSync(file).isFile();
|
|
111
|
+
} catch {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function isFile(file) {
|
|
117
|
+
try {
|
|
118
|
+
return fs.statSync(file).isFile();
|
|
119
|
+
} catch {
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** hermesc's output goes to the build log, as when React Native runs it. */
|
|
125
|
+
function spawnInherit(file, args, cwd) {
|
|
126
|
+
return require('node:child_process').spawnSync(file, args, { cwd, stdio: 'inherit' });
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** Returns the exit code. */
|
|
130
|
+
function run(argv, deps = {}) {
|
|
131
|
+
const env = deps.env ?? process.env;
|
|
132
|
+
const cwd = deps.cwd ?? process.cwd();
|
|
133
|
+
const platform = deps.platform ?? process.platform;
|
|
134
|
+
const isExecutable = deps.isExecutable ?? isExecutableFile;
|
|
135
|
+
const spawn = deps.spawn ?? spawnInherit;
|
|
136
|
+
const stderr = deps.stderr ?? ((line) => process.stderr.write(line));
|
|
137
|
+
const fail = (message) => {
|
|
138
|
+
stderr(`bugsee: ${message}\n`);
|
|
139
|
+
return 1;
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
const out = outputOf(argv);
|
|
143
|
+
const bundle = bundleOf(argv, out, (arg) => isFile(path.resolve(cwd, arg)));
|
|
144
|
+
if (bundle === undefined) {
|
|
145
|
+
return fail('hermesc wrapper could not find the JS bundle');
|
|
146
|
+
}
|
|
147
|
+
if (out === undefined) {
|
|
148
|
+
return fail('hermesc wrapper was given no -out, so it cannot check that bytecode was written');
|
|
149
|
+
}
|
|
150
|
+
const js = path.resolve(cwd, bundle);
|
|
151
|
+
const preserve = preserveDirOf(js, env, cwd);
|
|
152
|
+
if (preserve.error) {
|
|
153
|
+
return fail(preserve.error);
|
|
154
|
+
}
|
|
155
|
+
fs.mkdirSync(preserve.dir, { recursive: true });
|
|
156
|
+
const base = path.basename(js);
|
|
157
|
+
fs.copyFileSync(js, path.join(preserve.dir, `${base}.bugsee-js-source`));
|
|
158
|
+
|
|
159
|
+
const hermesc = findHermesc({ env, cwd, platform, isExecutable, resolve: deps.resolve });
|
|
160
|
+
if (hermesc === null) {
|
|
161
|
+
return fail('hermesc binary not found');
|
|
162
|
+
}
|
|
163
|
+
fs.writeFileSync(path.join(preserve.dir, `${base}.bugsee-hermesc`), `${hermesc}\n`);
|
|
164
|
+
|
|
165
|
+
// A file left from an earlier run must not pass the check below.
|
|
166
|
+
const bytecode = path.resolve(cwd, out);
|
|
167
|
+
fs.rmSync(bytecode, { force: true });
|
|
168
|
+
const result = spawn(hermesc, argv, cwd);
|
|
169
|
+
if (result.error) {
|
|
170
|
+
return fail(`hermesc failed to start (${hermesc}): ${result.error.message}`);
|
|
171
|
+
}
|
|
172
|
+
if (result.status !== 0) {
|
|
173
|
+
return result.status === null
|
|
174
|
+
? fail(`hermesc was killed by ${result.signal} (${hermesc})`)
|
|
175
|
+
: result.status;
|
|
176
|
+
}
|
|
177
|
+
if (!isFile(bytecode) || fs.statSync(bytecode).size === 0) {
|
|
178
|
+
return fail(`hermesc exited 0 but wrote no bytecode to ${bytecode} (${hermesc})`);
|
|
179
|
+
}
|
|
180
|
+
return 0;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
module.exports = {
|
|
184
|
+
bundleOf,
|
|
185
|
+
findHermesc,
|
|
186
|
+
hermescBin,
|
|
187
|
+
isExecutableFile,
|
|
188
|
+
isFile,
|
|
189
|
+
outputOf,
|
|
190
|
+
preserveDirOf,
|
|
191
|
+
resolveFrom,
|
|
192
|
+
run,
|
|
193
|
+
spawnInherit,
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
// Stryker disable all: the command-line entry runs only in a child process (the launcher tests).
|
|
197
|
+
if (require.main === module) {
|
|
198
|
+
process.exitCode = run(process.argv.slice(2));
|
|
199
|
+
}
|
|
200
|
+
// Stryker restore all
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
# react.hermesCommand on macOS and Linux. Windows runs the command through
|
|
3
|
+
# `cmd /c`, which cannot run this file: there it is hermesc-preserve-js.cmd.
|
|
4
|
+
# The work, and its non-zero exit when no bytecode came out, is in
|
|
5
|
+
# hermesc-preserve-js.js.
|
|
6
|
+
dir="$(cd "$(dirname "$0")" && pwd)" || exit 1
|
|
7
|
+
exec node "$dir/hermesc-preserve-js.js" "$@"
|