@solidnative-dev/cli 0.0.0-stage → 0.1.0-alpha.0
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/LICENSE +21 -0
- package/README.md +841 -2
- package/dist/android-apk-signing.d.ts +36 -0
- package/dist/android-apk-signing.d.ts.map +1 -0
- package/dist/android-apk-signing.js +292 -0
- package/dist/android-apk-signing.js.map +1 -0
- package/dist/android-bundle-signing.d.ts +34 -0
- package/dist/android-bundle-signing.d.ts.map +1 -0
- package/dist/android-bundle-signing.js +167 -0
- package/dist/android-bundle-signing.js.map +1 -0
- package/dist/android-causal-debug.d.ts +38 -0
- package/dist/android-causal-debug.d.ts.map +1 -0
- package/dist/android-causal-debug.js +239 -0
- package/dist/android-causal-debug.js.map +1 -0
- package/dist/android-device-proof.d.ts +58 -0
- package/dist/android-device-proof.d.ts.map +1 -0
- package/dist/android-device-proof.js +554 -0
- package/dist/android-device-proof.js.map +1 -0
- package/dist/android-logs.d.ts +50 -0
- package/dist/android-logs.d.ts.map +1 -0
- package/dist/android-logs.js +253 -0
- package/dist/android-logs.js.map +1 -0
- package/dist/android-release-signing.d.ts +12 -0
- package/dist/android-release-signing.d.ts.map +1 -0
- package/dist/android-release-signing.js +165 -0
- package/dist/android-release-signing.js.map +1 -0
- package/dist/android-run-lease.d.ts +15 -0
- package/dist/android-run-lease.d.ts.map +1 -0
- package/dist/android-run-lease.js +333 -0
- package/dist/android-run-lease.js.map +1 -0
- package/dist/android-run-preflight.d.ts +45 -0
- package/dist/android-run-preflight.d.ts.map +1 -0
- package/dist/android-run-preflight.js +183 -0
- package/dist/android-run-preflight.js.map +1 -0
- package/dist/android-signing-shared.d.ts +38 -0
- package/dist/android-signing-shared.d.ts.map +1 -0
- package/dist/android-signing-shared.js +210 -0
- package/dist/android-signing-shared.js.map +1 -0
- package/dist/bin.d.ts +3 -0
- package/dist/bin.d.ts.map +1 -0
- package/dist/bin.js +4530 -0
- package/dist/bin.js.map +1 -0
- package/dist/bundle-artifacts.d.ts +48 -0
- package/dist/bundle-artifacts.d.ts.map +1 -0
- package/dist/bundle-artifacts.js +427 -0
- package/dist/bundle-artifacts.js.map +1 -0
- package/dist/causal-debug-compare.d.ts +81 -0
- package/dist/causal-debug-compare.d.ts.map +1 -0
- package/dist/causal-debug-compare.js +238 -0
- package/dist/causal-debug-compare.js.map +1 -0
- package/dist/causal-debug-report.d.ts +33 -0
- package/dist/causal-debug-report.d.ts.map +1 -0
- package/dist/causal-debug-report.js +979 -0
- package/dist/causal-debug-report.js.map +1 -0
- package/dist/causal-debug-watch.d.ts +33 -0
- package/dist/causal-debug-watch.d.ts.map +1 -0
- package/dist/causal-debug-watch.js +92 -0
- package/dist/causal-debug-watch.js.map +1 -0
- package/dist/causal-debug.d.ts +131 -0
- package/dist/causal-debug.d.ts.map +1 -0
- package/dist/causal-debug.js +503 -0
- package/dist/causal-debug.js.map +1 -0
- package/dist/compatibility-catalog.d.ts +88 -0
- package/dist/compatibility-catalog.d.ts.map +1 -0
- package/dist/compatibility-catalog.js +344 -0
- package/dist/compatibility-catalog.js.map +1 -0
- package/dist/deep-link.d.ts +90 -0
- package/dist/deep-link.d.ts.map +1 -0
- package/dist/deep-link.js +346 -0
- package/dist/deep-link.js.map +1 -0
- package/dist/device-proof-signatures.d.ts +307 -0
- package/dist/device-proof-signatures.d.ts.map +1 -0
- package/dist/device-proof-signatures.js +1024 -0
- package/dist/device-proof-signatures.js.map +1 -0
- package/dist/fingerprint.d.ts +35 -0
- package/dist/fingerprint.d.ts.map +1 -0
- package/dist/fingerprint.js +454 -0
- package/dist/fingerprint.js.map +1 -0
- package/dist/index.d.ts +388 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2996 -0
- package/dist/index.js.map +1 -0
- package/dist/ios-causal-debug.d.ts +39 -0
- package/dist/ios-causal-debug.d.ts.map +1 -0
- package/dist/ios-causal-debug.js +318 -0
- package/dist/ios-causal-debug.js.map +1 -0
- package/dist/ios-logs.d.ts +58 -0
- package/dist/ios-logs.d.ts.map +1 -0
- package/dist/ios-logs.js +269 -0
- package/dist/ios-logs.js.map +1 -0
- package/dist/ios-process.d.ts +69 -0
- package/dist/ios-process.d.ts.map +1 -0
- package/dist/ios-process.js +389 -0
- package/dist/ios-process.js.map +1 -0
- package/dist/ios-run-preflight.d.ts +35 -0
- package/dist/ios-run-preflight.d.ts.map +1 -0
- package/dist/ios-run-preflight.js +172 -0
- package/dist/ios-run-preflight.js.map +1 -0
- package/dist/live-causal-debug-report.d.ts +49 -0
- package/dist/live-causal-debug-report.d.ts.map +1 -0
- package/dist/live-causal-debug-report.js +123 -0
- package/dist/live-causal-debug-report.js.map +1 -0
- package/dist/local-symbolication.d.ts +35 -0
- package/dist/local-symbolication.d.ts.map +1 -0
- package/dist/local-symbolication.js +89 -0
- package/dist/local-symbolication.js.map +1 -0
- package/dist/native-archive.d.ts +15 -0
- package/dist/native-archive.d.ts.map +1 -0
- package/dist/native-archive.js +441 -0
- package/dist/native-archive.js.map +1 -0
- package/dist/native-test.d.ts +43 -0
- package/dist/native-test.d.ts.map +1 -0
- package/dist/native-test.js +209 -0
- package/dist/native-test.js.map +1 -0
- package/dist/package-add.d.ts +56 -0
- package/dist/package-add.d.ts.map +1 -0
- package/dist/package-add.js +764 -0
- package/dist/package-add.js.map +1 -0
- package/dist/react-native-upgrade.d.ts +96 -0
- package/dist/react-native-upgrade.d.ts.map +1 -0
- package/dist/react-native-upgrade.js +882 -0
- package/dist/react-native-upgrade.js.map +1 -0
- package/dist/release-device-correlation.d.ts +40 -0
- package/dist/release-device-correlation.d.ts.map +1 -0
- package/dist/release-device-correlation.js +113 -0
- package/dist/release-device-correlation.js.map +1 -0
- package/dist/release-signatures.d.ts +168 -0
- package/dist/release-signatures.d.ts.map +1 -0
- package/dist/release-signatures.js +677 -0
- package/dist/release-signatures.js.map +1 -0
- package/dist/release.d.ts +88 -0
- package/dist/release.d.ts.map +1 -0
- package/dist/release.js +771 -0
- package/dist/release.js.map +1 -0
- package/dist/signature-utilities.d.ts +16 -0
- package/dist/signature-utilities.d.ts.map +1 -0
- package/dist/signature-utilities.js +114 -0
- package/dist/signature-utilities.js.map +1 -0
- package/dist/solid-diagnostics-correlation.d.ts +11 -0
- package/dist/solid-diagnostics-correlation.d.ts.map +1 -0
- package/dist/solid-diagnostics-correlation.js +78 -0
- package/dist/solid-diagnostics-correlation.js.map +1 -0
- package/dist/solid-diagnostics-debug.d.ts +15 -0
- package/dist/solid-diagnostics-debug.d.ts.map +1 -0
- package/dist/solid-diagnostics-debug.js +93 -0
- package/dist/solid-diagnostics-debug.js.map +1 -0
- package/dist/solid-diagnostics-inspection.d.ts +41 -0
- package/dist/solid-diagnostics-inspection.d.ts.map +1 -0
- package/dist/solid-diagnostics-inspection.js +196 -0
- package/dist/solid-diagnostics-inspection.js.map +1 -0
- package/dist/source-map.d.ts +36 -0
- package/dist/source-map.d.ts.map +1 -0
- package/dist/source-map.js +488 -0
- package/dist/source-map.js.map +1 -0
- package/dist/stack-symbolication.d.ts +56 -0
- package/dist/stack-symbolication.d.ts.map +1 -0
- package/dist/stack-symbolication.js +310 -0
- package/dist/stack-symbolication.js.map +1 -0
- package/dist/symbolication.d.ts +27 -0
- package/dist/symbolication.d.ts.map +1 -0
- package/dist/symbolication.js +75 -0
- package/dist/symbolication.js.map +1 -0
- package/dist/tree-debug.d.ts +53 -0
- package/dist/tree-debug.d.ts.map +1 -0
- package/dist/tree-debug.js +283 -0
- package/dist/tree-debug.js.map +1 -0
- package/dist/versions.d.ts +13 -0
- package/dist/versions.d.ts.map +1 -0
- package/dist/versions.js +14 -0
- package/dist/versions.js.map +1 -0
- package/package.json +46 -3
- package/templates/react-native-0.88/README.md +328 -0
- package/templates/react-native-0.88/android/CMakeLists.txt +27 -0
- package/templates/react-native-0.88/android/MainActivity.kt +123 -0
- package/templates/react-native-0.88/android/MainApplication.kt +43 -0
- package/templates/react-native-0.88/android/OnLoad.cpp +60 -0
- package/templates/react-native-0.88/index.js +1 -0
- package/templates/react-native-0.88/ios/AppDelegate.swift +190 -0
- package/templates/react-native-0.88/metro.config.js +16 -0
- package/templates/react-native-0.88/specs/NativeSolidNativeDebug.ts +16 -0
- package/templates/react-native-0.88/specs/NativeSolidNativePlatformAndroid.ts +14 -0
- package/templates/react-native-0.88/src/App.tsx +161 -0
- package/templates/react-native-0.88/src/main.tsx +88 -0
- package/templates/react-native-0.88/test/App.test.tsx +152 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,2996 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
3
|
+
import { createRequire } from "node:module";
|
|
4
|
+
import { access, link, lstat, mkdir, readFile, readdir, realpath, rename, rm, stat, writeFile, } from "node:fs/promises";
|
|
5
|
+
import { homedir } from "node:os";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import { fileURLToPath } from "node:url";
|
|
8
|
+
import { combineReactNativeCodegenSchemas, createSolidNativeSchemaAudit, generateSolidNativeBindingsModule, generateSolidNativeComponentModule, generateSolidNativeTurboModuleAdapterScaffold, generateSolidNativeTurboModuleBindings, } from "@solidnative-dev/codegen";
|
|
9
|
+
import { formatNativeCompatibilityCatalogReport, parseNativeCompatibilityEvidence, parseNativeCompatibilityCatalog, verifyNativeCompatibilityCatalog, } from "./compatibility-catalog.js";
|
|
10
|
+
import { SOLID_NATIVE_CLI_VERSION, VERIFIED_HERMES_BYTECODE_VERSION, VERIFIED_HERMES_COMPILER_VERSION, VERIFIED_REACT_NATIVE_PACKAGE_VERSION, VERIFIED_REACT_NATIVE_RUNTIME_VERSION, VERIFIED_REACT_NATIVE_VERSION, VERIFIED_SAFE_AREA_CONTEXT_VERSION, VERIFIED_SOLID_VERSION, } from "./versions.js";
|
|
11
|
+
import { writeNativeBundleManifest } from "./bundle-artifacts.js";
|
|
12
|
+
import { canonicalizeNativeSourceMap, verifyNativeSourceMapPolicy, } from "./source-map.js";
|
|
13
|
+
import { preflightNativeIosRunDestination, } from "./ios-run-preflight.js";
|
|
14
|
+
import { preflightNativeAndroidRunDestination, restoreNativeAndroidRunDestination, } from "./android-run-preflight.js";
|
|
15
|
+
import { inspectAndroidReleaseSigning } from "./android-release-signing.js";
|
|
16
|
+
export { NATIVE_TEST_MAX_FILE_COUNT, NATIVE_TEST_MAX_DIRECTORY_COUNT, NATIVE_TEST_MAX_DIRECTORY_ENTRY_COUNT, createNativeTestPlan, formatNativeTestPlan, } from "./native-test.js";
|
|
17
|
+
export { createNativeAndroidDeviceProof, parseNativeAndroidBatteryState, parseNativeAndroidInstrumentationResult, } from "./android-device-proof.js";
|
|
18
|
+
export { defaultNativeAndroidBundleSigningCommandRunner, formatNativeAndroidBundleSigningReport, parseNativeAndroidBundleSigners, verifyNativeAndroidBundleSigning, } from "./android-bundle-signing.js";
|
|
19
|
+
export { defaultNativeAndroidApkSigningCommandRunner, formatNativeAndroidApkSigningReport, parseNativeAndroidApkSigners, resolveNativeAndroidApkSignerCommand, verifyNativeAndroidApkSigning, } from "./android-apk-signing.js";
|
|
20
|
+
export { createNativeAndroidLogsPlan, defaultNativeAndroidLogCommandRunner, defaultNativeAndroidLogsExecutor, executeNativeAndroidLogsPlan, formatNativeAndroidLogsPlan, parseAndroidPackageUid, parseAuthorizedAndroidDevices, } from "./android-logs.js";
|
|
21
|
+
export { createNativeIosLogsPlan, defaultNativeIosLogCommandRunner, defaultNativeIosLogsExecutor, executeNativeIosLogsPlan, formatNativeIosLogsPlan, parseNativeIosInstalledApplication, } from "./ios-logs.js";
|
|
22
|
+
export { defaultNativeIosProcessCommandRunner, formatNativeIosApplicationProcessStatus, formatNativeIosApplicationProcessStop, parseNativeIosApplicationProcesses, parseNativeIosProcessTarget, readNativeIosApplicationProcessStatus, stopNativeIosApplicationProcesses, } from "./ios-process.js";
|
|
23
|
+
export { parseNativeAndroidKeyguardShowing, preflightNativeAndroidRunDestination, restoreNativeAndroidRunDestination, } from "./android-run-preflight.js";
|
|
24
|
+
export { parseNativeIosDeviceLockState, parseNativeIosSimulatorIdentifiers, preflightNativeIosRunDestination, } from "./ios-run-preflight.js";
|
|
25
|
+
export { createNativeDeepLinkPlan, defaultNativeDeepLinkExecutor, executeNativeDeepLinkPlan, formatNativeDeepLinkPlan, parseNativeAndroidDeepLinkExecution, parseNativeIosDeepLinkExecution, } from "./deep-link.js";
|
|
26
|
+
export { auditNativeReactNativeUpgrade, formatNativeReactNativeUpgradeReport, } from "./react-native-upgrade.js";
|
|
27
|
+
export { VERIFIED_HERMES_BYTECODE_VERSION, VERIFIED_HERMES_COMPILER_VERSION, VERIFIED_REACT_NATIVE_PACKAGE_VERSION, VERIFIED_REACT_NATIVE_RUNTIME_VERSION, VERIFIED_REACT_NATIVE_VERSION, VERIFIED_SAFE_AREA_CONTEXT_VERSION, VERIFIED_SOLID_VERSION, } from "./versions.js";
|
|
28
|
+
export { formatNativeCompatibilityCatalogReport, parseNativeCompatibilityEvidence, parseNativeCompatibilityCatalog, verifyNativeCompatibilityCatalog, } from "./compatibility-catalog.js";
|
|
29
|
+
export { assembleNativeDeviceProofSignature, createNativeDeviceProofIngestion, createNativeDeviceProofSignature, createNativeDeviceProofSigningRequest, formatNativeDeviceProofIngestion, formatNativeDeviceProofSignatureVerification, inspectNativeDeviceProofProfile, nativeDeviceProofProfileFingerprint, nativeDeviceProofTrustPolicyFingerprint, parseNativeDeviceProofReceipt, readNativeDeviceProofReceipt, readNativeDeviceProofSignature, readNativeDeviceProofSigningRequest, readNativeDeviceProofTrustPolicy, verifyNativeDeviceProofSignature, } from "./device-proof-signatures.js";
|
|
30
|
+
export { createNativeFingerprint, formatNativeFingerprint, } from "./fingerprint.js";
|
|
31
|
+
export { canonicalizeNativeSourceMap, formatNativeSourceMapPolicyReport, validateCanonicalNativeSourceMap, verifyNativeSourceMapPolicy, } from "./source-map.js";
|
|
32
|
+
export { formatNativeBundleVerification, readNativeBundleManifest, verifyNativeBundleManifest, writeNativeBundleManifest, } from "./bundle-artifacts.js";
|
|
33
|
+
export { createNativeReleaseManifest, formatNativeReleaseVerification, nativeReleaseFingerprintMatches, readNativeReleaseManifest, verifyNativeReleaseManifest, } from "./release.js";
|
|
34
|
+
export { assembleNativeReleaseSignature, createNativeReleaseSignature, createNativeReleaseSigningRequest, formatNativeReleaseSignatureVerification, nativeReleaseTrustPolicyFingerprint, readNativeReleaseSigningRequest, readNativeReleaseTrustPolicy, verifyNativeReleaseSignature, } from "./release-signatures.js";
|
|
35
|
+
export { createNativeSymbolicationHandoff, formatNativeSymbolicationHandoff, } from "./symbolication.js";
|
|
36
|
+
export { NATIVE_ANDROID_CAUSAL_DEBUG_DEFAULT_TIMEOUT_MS, NATIVE_ANDROID_CAUSAL_DEBUG_MAX_TIMEOUT_MS, NATIVE_ANDROID_CAUSAL_DEBUG_REQUEST_EVENT, NATIVE_ANDROID_SOLID_DIAGNOSTICS_DEFAULT_DURATION_MS, NATIVE_ANDROID_SOLID_DIAGNOSTICS_MAX_DURATION_MS, captureNativeAndroidCausalDebugSnapshot, captureNativeAndroidSolidDiagnostics, captureNativeAndroidTreeDebugSnapshot, } from "./android-causal-debug.js";
|
|
37
|
+
export { NATIVE_SOLID_DIAGNOSTICS_CONTROL_KIND, NATIVE_SOLID_DIAGNOSTICS_CONTROL_SCHEMA_VERSION, parseNativeSolidDiagnosticsControlBytes, parseNativeSolidDiagnosticsDebugBytes, } from "./solid-diagnostics-debug.js";
|
|
38
|
+
export { NATIVE_SOLID_DIAGNOSTICS_INSPECTION_KIND, NATIVE_SOLID_DIAGNOSTICS_INSPECTION_MAX_RANKED_COSTS, NATIVE_SOLID_DIAGNOSTICS_INSPECTION_SCHEMA_VERSION, NATIVE_SOLID_DIAGNOSTICS_MAX_INPUT_CHUNKS, formatNativeSolidDiagnosticsInspection, inspectNativeSolidDiagnostics, inspectNativeSolidDiagnosticsFile, inspectNativeSolidDiagnosticsStream, } from "./solid-diagnostics-inspection.js";
|
|
39
|
+
export { NATIVE_SOLID_DIAGNOSTICS_CORRELATION_KIND, NATIVE_SOLID_DIAGNOSTICS_CORRELATION_MODE, NATIVE_SOLID_DIAGNOSTICS_CORRELATION_SCHEMA_VERSION, NATIVE_SOLID_DIAGNOSTICS_CORRELATION_WINDOW_TOLERANCE_MS, correlateNativeSolidDiagnostics, correlateNativeSolidDiagnosticsFiles, formatNativeSolidDiagnosticsCorrelation, readNativeSolidDiagnosticsDebugFile, } from "./solid-diagnostics-correlation.js";
|
|
40
|
+
export { NATIVE_IOS_CAUSAL_DEBUG_DEFAULT_TIMEOUT_MS, NATIVE_IOS_CAUSAL_DEBUG_MIN_TIMEOUT_MS, NATIVE_IOS_CAUSAL_DEBUG_MAX_TIMEOUT_MS, NATIVE_IOS_CAUSAL_DEBUG_URL_SCHEME, NATIVE_IOS_SOLID_DIAGNOSTICS_DEFAULT_DURATION_MS, NATIVE_IOS_SOLID_DIAGNOSTICS_MAX_DURATION_MS, captureNativeIosCausalDebugSnapshot, captureNativeIosSolidDiagnostics, captureNativeIosTreeDebugSnapshot, } from "./ios-causal-debug.js";
|
|
41
|
+
export { NATIVE_TREE_DEBUG_CONTROL_KIND, NATIVE_TREE_DEBUG_CONTROL_SCHEMA_VERSION, NATIVE_TREE_DEBUG_INSPECTION_KIND, NATIVE_TREE_DEBUG_INSPECTION_SCHEMA_VERSION, NATIVE_TREE_DEBUG_MAX_INPUT_CHUNKS, formatNativeTreeDebugInspection, inspectNativeTreeDebugFile, inspectNativeTreeDebugSnapshot, inspectNativeTreeDebugStream, parseNativeTreeDebugControlBytes, parseNativeTreeDebugDeviceResponseBytes, parseNativeTreeDebugSnapshotBytes, readNativeTreeDebugSnapshotFile, } from "./tree-debug.js";
|
|
42
|
+
export { NATIVE_CAUSAL_DEBUG_WATCH_DEFAULT_INTERVAL_MS, NATIVE_CAUSAL_DEBUG_WATCH_DEFAULT_MAX_CONSECUTIVE_FAILURES, NATIVE_CAUSAL_DEBUG_WATCH_MAX_CONSECUTIVE_FAILURES, NATIVE_CAUSAL_DEBUG_WATCH_MAX_INTERVAL_MS, NATIVE_CAUSAL_DEBUG_WATCH_MAX_SNAPSHOT_COUNT, NATIVE_CAUSAL_DEBUG_WATCH_MIN_INTERVAL_MS, watchNativeCausalDebugSnapshots, } from "./causal-debug-watch.js";
|
|
43
|
+
export { NATIVE_CAUSAL_DEBUG_MAX_FILE_BYTES, NATIVE_CAUSAL_DEBUG_MAX_INPUT_BYTES, NATIVE_CAUSAL_TRACE_MAX_FLOW_COUNT, createNativeCausalTrace, createNativeCausalTraceFile, createNativeCausalTraceStream, formatNativeCausalDebugInspection, inspectNativeCausalDebugFile, inspectNativeCausalDebugSnapshot, inspectNativeCausalDebugStream, parseNativeCausalDebugSnapshotBytes, } from "./causal-debug.js";
|
|
44
|
+
export { NATIVE_CAUSAL_DEBUG_MAX_REPORT_BYTES, createNativeCausalDebugReport, createNativeCausalDebugReportFile, createNativeCausalDebugReportStream, writeNativeCausalDebugReportFile, } from "./causal-debug-report.js";
|
|
45
|
+
export { captureNativeAndroidCausalDebugReport, captureNativeIosCausalDebugReport, } from "./live-causal-debug-report.js";
|
|
46
|
+
export { compareNativeCausalDebugFiles, compareNativeCausalDebugSnapshots, formatNativeCausalDebugComparison, } from "./causal-debug-compare.js";
|
|
47
|
+
export { NATIVE_SYMBOLICATION_MAX_LOCATIONS, formatNativeSourceLocationSymbolication, symbolicateNativeSourceLocations, } from "./local-symbolication.js";
|
|
48
|
+
export { NATIVE_STACK_MAX_FRAMES, NATIVE_STACK_MAX_INPUT_BYTES, NATIVE_STACK_MAX_INPUT_CHUNKS, NATIVE_STACK_MAX_LINES, NATIVE_STACK_MAX_METHOD_NAME_CHARACTERS, NATIVE_STACK_MAX_SKIPPED_FRAMES, formatNativeStackTraceSymbolication, parseNativeStackTrace, symbolicateNativeStackTrace, symbolicateNativeStackTraceFile, symbolicateNativeStackTraceStream, } from "./stack-symbolication.js";
|
|
49
|
+
export { createNativeReleaseDeviceCorrelation, formatNativeReleaseDeviceCorrelation, } from "./release-device-correlation.js";
|
|
50
|
+
export { inspectAndroidEmbeddedHermesBundle, } from "./native-archive.js";
|
|
51
|
+
export { SOLID_NATIVE_CLI_VERSION } from "./versions.js";
|
|
52
|
+
export { createNativePackageAddPlan, defaultNativePackageAddExecutor, executeNativePackageAddPlan, formatNativePackageAddPlan, } from "./package-add.js";
|
|
53
|
+
const COMMAND_TIMEOUT_MS = 8_000;
|
|
54
|
+
const MAX_COMMAND_OUTPUT = 64 * 1024;
|
|
55
|
+
function commandOutput(result) {
|
|
56
|
+
return `${result.stdout}\n${result.stderr}`.trim();
|
|
57
|
+
}
|
|
58
|
+
function firstLine(value) {
|
|
59
|
+
return (value
|
|
60
|
+
.split(/\r?\n/u)
|
|
61
|
+
.find((line) => line.trim().length > 0)
|
|
62
|
+
?.trim() ?? "");
|
|
63
|
+
}
|
|
64
|
+
function compareNames(left, right) {
|
|
65
|
+
return left < right ? -1 : left > right ? 1 : 0;
|
|
66
|
+
}
|
|
67
|
+
function errorMessage(error) {
|
|
68
|
+
return error instanceof Error ? error.message : String(error);
|
|
69
|
+
}
|
|
70
|
+
function check(id, label, status, message, remediation) {
|
|
71
|
+
return remediation === undefined
|
|
72
|
+
? { id, label, status, message }
|
|
73
|
+
: { id, label, status, message, remediation };
|
|
74
|
+
}
|
|
75
|
+
function parseVersion(value) {
|
|
76
|
+
const match = /^v?(\d+)\.(\d+)\.\d+(?:[-+].*)?$/u.exec(value.trim());
|
|
77
|
+
if (match === null)
|
|
78
|
+
return undefined;
|
|
79
|
+
const major = Number(match[1]);
|
|
80
|
+
const minor = Number(match[2]);
|
|
81
|
+
return Number.isSafeInteger(major) && Number.isSafeInteger(minor)
|
|
82
|
+
? { major, minor }
|
|
83
|
+
: undefined;
|
|
84
|
+
}
|
|
85
|
+
function parseJavaMajor(value) {
|
|
86
|
+
const match = /version\s+"(\d+)(?:\.(\d+))?/u.exec(value);
|
|
87
|
+
if (match === null)
|
|
88
|
+
return undefined;
|
|
89
|
+
const first = Number(match[1]);
|
|
90
|
+
const major = first === 1 ? Number(match[2]) : first;
|
|
91
|
+
return Number.isSafeInteger(major) ? major : undefined;
|
|
92
|
+
}
|
|
93
|
+
function isRecord(value) {
|
|
94
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
95
|
+
}
|
|
96
|
+
function stringRecord(value) {
|
|
97
|
+
if (!isRecord(value))
|
|
98
|
+
return undefined;
|
|
99
|
+
const result = {};
|
|
100
|
+
for (const [key, entry] of Object.entries(value)) {
|
|
101
|
+
if (typeof entry === "string")
|
|
102
|
+
result[key] = entry;
|
|
103
|
+
}
|
|
104
|
+
return result;
|
|
105
|
+
}
|
|
106
|
+
function parseManifest(source) {
|
|
107
|
+
const value = JSON.parse(source);
|
|
108
|
+
if (!isRecord(value)) {
|
|
109
|
+
throw new TypeError("package.json must contain an object.");
|
|
110
|
+
}
|
|
111
|
+
const name = typeof value.name === "string" ? value.name : undefined;
|
|
112
|
+
const version = typeof value.version === "string" ? value.version : undefined;
|
|
113
|
+
const packageManager = typeof value.packageManager === "string" ? value.packageManager : undefined;
|
|
114
|
+
const dependencies = stringRecord(value.dependencies);
|
|
115
|
+
const devDependencies = stringRecord(value.devDependencies);
|
|
116
|
+
const peerDependencies = stringRecord(value.peerDependencies);
|
|
117
|
+
const exports = isRecord(value.exports) ? value.exports : undefined;
|
|
118
|
+
const codegenConfig = isRecord(value.codegenConfig)
|
|
119
|
+
? value.codegenConfig
|
|
120
|
+
: undefined;
|
|
121
|
+
return {
|
|
122
|
+
...(name === undefined ? {} : { name }),
|
|
123
|
+
...(version === undefined ? {} : { version }),
|
|
124
|
+
...(packageManager === undefined ? {} : { packageManager }),
|
|
125
|
+
...(dependencies === undefined ? {} : { dependencies }),
|
|
126
|
+
...(devDependencies === undefined ? {} : { devDependencies }),
|
|
127
|
+
...(peerDependencies === undefined ? {} : { peerDependencies }),
|
|
128
|
+
...(exports === undefined ? {} : { exports }),
|
|
129
|
+
...(codegenConfig === undefined ? {} : { codegenConfig }),
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
function declaredVersion(manifest, packageName) {
|
|
133
|
+
return (manifest.dependencies?.[packageName] ??
|
|
134
|
+
manifest.devDependencies?.[packageName] ??
|
|
135
|
+
manifest.peerDependencies?.[packageName]);
|
|
136
|
+
}
|
|
137
|
+
async function defaultPathExists(target) {
|
|
138
|
+
try {
|
|
139
|
+
await access(target);
|
|
140
|
+
return true;
|
|
141
|
+
}
|
|
142
|
+
catch {
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
export const defaultDoctorCommandRunner = (command, args, context) => new Promise((resolve) => {
|
|
147
|
+
let stdout = "";
|
|
148
|
+
let stderr = "";
|
|
149
|
+
let settled = false;
|
|
150
|
+
let timedOut = false;
|
|
151
|
+
const child = spawn(command, [...args], {
|
|
152
|
+
cwd: context.cwd,
|
|
153
|
+
env: context.env,
|
|
154
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
155
|
+
});
|
|
156
|
+
const append = (current, chunk) => `${current}${chunk.toString("utf8")}`.slice(-MAX_COMMAND_OUTPUT);
|
|
157
|
+
child.stdout.on("data", (chunk) => {
|
|
158
|
+
stdout = append(stdout, chunk);
|
|
159
|
+
});
|
|
160
|
+
child.stderr.on("data", (chunk) => {
|
|
161
|
+
stderr = append(stderr, chunk);
|
|
162
|
+
});
|
|
163
|
+
const finish = (result) => {
|
|
164
|
+
if (settled)
|
|
165
|
+
return;
|
|
166
|
+
settled = true;
|
|
167
|
+
clearTimeout(timer);
|
|
168
|
+
resolve(result);
|
|
169
|
+
};
|
|
170
|
+
const timer = setTimeout(() => {
|
|
171
|
+
timedOut = true;
|
|
172
|
+
child.kill("SIGTERM");
|
|
173
|
+
}, context.timeoutMs);
|
|
174
|
+
child.on("error", (error) => {
|
|
175
|
+
finish({
|
|
176
|
+
exitCode: null,
|
|
177
|
+
stdout,
|
|
178
|
+
stderr,
|
|
179
|
+
timedOut,
|
|
180
|
+
...(error.code === undefined ? {} : { errorCode: error.code }),
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
child.on("close", (exitCode) => {
|
|
184
|
+
finish({ exitCode, stdout, stderr, timedOut });
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
function defaultDependencies() {
|
|
188
|
+
return {
|
|
189
|
+
hostPlatform: process.platform,
|
|
190
|
+
homeDirectory: homedir(),
|
|
191
|
+
nodeVersion: process.versions.node,
|
|
192
|
+
pathExists: defaultPathExists,
|
|
193
|
+
readTextFile: (target) => readFile(target, "utf8"),
|
|
194
|
+
runCommand: defaultDoctorCommandRunner,
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
function fileDependencies(overrides) {
|
|
198
|
+
const realPathOverride = overrides !== undefined && "realPath" in overrides
|
|
199
|
+
? overrides.realPath
|
|
200
|
+
: undefined;
|
|
201
|
+
return {
|
|
202
|
+
pathExists: overrides?.pathExists ?? defaultPathExists,
|
|
203
|
+
readTextFile: overrides?.readTextFile ?? ((target) => readFile(target, "utf8")),
|
|
204
|
+
realPath: realPathOverride ?? realpath,
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
async function findProjectRoot(start, pathExists) {
|
|
208
|
+
let current = path.resolve(start);
|
|
209
|
+
while (true) {
|
|
210
|
+
if (await pathExists(path.join(current, "package.json")))
|
|
211
|
+
return current;
|
|
212
|
+
const parent = path.dirname(current);
|
|
213
|
+
if (parent === current)
|
|
214
|
+
return undefined;
|
|
215
|
+
current = parent;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
async function findReactNativeCli(projectRoot, pathExists) {
|
|
219
|
+
let current = projectRoot;
|
|
220
|
+
while (true) {
|
|
221
|
+
const candidate = path.join(current, "node_modules", "react-native", "cli.js");
|
|
222
|
+
if (await pathExists(candidate))
|
|
223
|
+
return candidate;
|
|
224
|
+
const parent = path.dirname(current);
|
|
225
|
+
if (parent === current)
|
|
226
|
+
return undefined;
|
|
227
|
+
current = parent;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
async function findInstalledPackageManifest(projectRoot, packageName, dependencies) {
|
|
231
|
+
let current = projectRoot;
|
|
232
|
+
while (true) {
|
|
233
|
+
const candidate = path.join(current, "node_modules", packageName, "package.json");
|
|
234
|
+
if (await dependencies.pathExists(candidate)) {
|
|
235
|
+
return {
|
|
236
|
+
path: candidate,
|
|
237
|
+
manifest: parseManifest(await dependencies.readTextFile(candidate)),
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
const parent = path.dirname(current);
|
|
241
|
+
if (parent === current)
|
|
242
|
+
return undefined;
|
|
243
|
+
current = parent;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
const NAVIGATION_BACKEND_EXPORT = "./react-native-screens-backend";
|
|
247
|
+
const MAX_NAVIGATION_BACKEND_CONTRACT_BYTES = 32 * 1024;
|
|
248
|
+
const MAX_NAVIGATION_BACKEND_FILES = 16;
|
|
249
|
+
const SHA256_PATTERN = /^[a-f0-9]{64}$/u;
|
|
250
|
+
function backendContractString(value, label) {
|
|
251
|
+
if (typeof value !== "string" || value.length === 0) {
|
|
252
|
+
throw new TypeError(`${label} must be a non-empty string.`);
|
|
253
|
+
}
|
|
254
|
+
return value;
|
|
255
|
+
}
|
|
256
|
+
function backendContractSha256(value, label) {
|
|
257
|
+
const digest = backendContractString(value, label);
|
|
258
|
+
if (!SHA256_PATTERN.test(digest)) {
|
|
259
|
+
throw new TypeError(`${label} must be a lowercase SHA-256 digest.`);
|
|
260
|
+
}
|
|
261
|
+
return digest;
|
|
262
|
+
}
|
|
263
|
+
function parseNativeNavigationBackendContract(source) {
|
|
264
|
+
if (Buffer.byteLength(source, "utf8") > MAX_NAVIGATION_BACKEND_CONTRACT_BYTES) {
|
|
265
|
+
throw new TypeError("The navigation backend contract is too large.");
|
|
266
|
+
}
|
|
267
|
+
const value = JSON.parse(source);
|
|
268
|
+
if (!isRecord(value) || value.schemaVersion !== 1) {
|
|
269
|
+
throw new TypeError("The navigation backend contract must use schema 1.");
|
|
270
|
+
}
|
|
271
|
+
const patch = value.patch;
|
|
272
|
+
if (!isRecord(patch)) {
|
|
273
|
+
throw new TypeError("The navigation backend contract patch is invalid.");
|
|
274
|
+
}
|
|
275
|
+
if (!Array.isArray(value.installedFiles) ||
|
|
276
|
+
value.installedFiles.length === 0 ||
|
|
277
|
+
value.installedFiles.length > MAX_NAVIGATION_BACKEND_FILES) {
|
|
278
|
+
throw new TypeError(`The navigation backend contract must contain 1-${String(MAX_NAVIGATION_BACKEND_FILES)} installed files.`);
|
|
279
|
+
}
|
|
280
|
+
const seenPaths = new Set();
|
|
281
|
+
const installedFiles = value.installedFiles.map((entry, index) => {
|
|
282
|
+
if (!isRecord(entry)) {
|
|
283
|
+
throw new TypeError(`Navigation backend installed file ${String(index)} is invalid.`);
|
|
284
|
+
}
|
|
285
|
+
const filePath = backendContractString(entry.path, `Navigation backend installed file ${String(index)} path`);
|
|
286
|
+
if (seenPaths.has(filePath)) {
|
|
287
|
+
throw new TypeError(`The navigation backend contract repeats installed file ${filePath}.`);
|
|
288
|
+
}
|
|
289
|
+
seenPaths.add(filePath);
|
|
290
|
+
return {
|
|
291
|
+
path: filePath,
|
|
292
|
+
sha256: backendContractSha256(entry.sha256, `Navigation backend installed file ${String(index)} digest`),
|
|
293
|
+
};
|
|
294
|
+
});
|
|
295
|
+
return {
|
|
296
|
+
schemaVersion: 1,
|
|
297
|
+
packageName: backendContractString(value.packageName, "Navigation backend package name"),
|
|
298
|
+
packageVersion: backendContractString(value.packageVersion, "Navigation backend package version"),
|
|
299
|
+
reactNativeVersion: backendContractString(value.reactNativeVersion, "Navigation backend React Native version"),
|
|
300
|
+
patch: {
|
|
301
|
+
path: backendContractString(patch.path, "Navigation backend patch path"),
|
|
302
|
+
sha256: backendContractSha256(patch.sha256, "Navigation backend patch digest"),
|
|
303
|
+
},
|
|
304
|
+
installedFiles,
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
function resolvePackageContractPath(packageDirectory, relativePath, label) {
|
|
308
|
+
if (relativePath.includes("\\") ||
|
|
309
|
+
relativePath.startsWith("/") ||
|
|
310
|
+
relativePath.includes("\0")) {
|
|
311
|
+
throw new TypeError(`${label} must be a portable package-relative path.`);
|
|
312
|
+
}
|
|
313
|
+
const target = path.resolve(packageDirectory, relativePath);
|
|
314
|
+
const relative = path.relative(packageDirectory, target);
|
|
315
|
+
if (relative === "" ||
|
|
316
|
+
relative === ".." ||
|
|
317
|
+
relative.startsWith(`..${path.sep}`) ||
|
|
318
|
+
path.isAbsolute(relative)) {
|
|
319
|
+
throw new TypeError(`${label} must remain inside its package.`);
|
|
320
|
+
}
|
|
321
|
+
return target;
|
|
322
|
+
}
|
|
323
|
+
function contentSha256(source) {
|
|
324
|
+
return createHash("sha256").update(source).digest("hex");
|
|
325
|
+
}
|
|
326
|
+
async function installedNavigationBackendCheck(projectRoot, manifest, reactNativeVersion, dependencies) {
|
|
327
|
+
const navigationDeclaration = declaredVersion(manifest, "@solidnative-dev/navigation");
|
|
328
|
+
if (navigationDeclaration === undefined)
|
|
329
|
+
return undefined;
|
|
330
|
+
try {
|
|
331
|
+
const [navigation, screens] = await Promise.all([
|
|
332
|
+
findInstalledPackageManifest(projectRoot, "@solidnative-dev/navigation", dependencies),
|
|
333
|
+
findInstalledPackageManifest(projectRoot, "react-native-screens", dependencies),
|
|
334
|
+
]);
|
|
335
|
+
if (navigation === undefined || screens === undefined) {
|
|
336
|
+
const missing = [
|
|
337
|
+
...(navigation === undefined ? ["@solidnative-dev/navigation"] : []),
|
|
338
|
+
...(screens === undefined ? ["react-native-screens"] : []),
|
|
339
|
+
];
|
|
340
|
+
return check("project.navigation-backend", "Native navigation backend", "fail", `The declared ${missing.join(" and ")} package${missing.length === 1 ? " is" : "s are"} not installed.`, "Install the exact navigation peer set from the reviewed lockfile.");
|
|
341
|
+
}
|
|
342
|
+
if (navigation.manifest.name !== "@solidnative-dev/navigation" ||
|
|
343
|
+
navigation.manifest.version === undefined) {
|
|
344
|
+
throw new TypeError("The installed @solidnative-dev/navigation manifest has an invalid name or version.");
|
|
345
|
+
}
|
|
346
|
+
if (/^\d+\.\d+\.\d+(?:[-+].+)?$/u.test(navigationDeclaration) &&
|
|
347
|
+
navigation.manifest.version !== navigationDeclaration) {
|
|
348
|
+
throw new TypeError(`@solidnative-dev/navigation declares ${navigationDeclaration} but ${navigation.manifest.version} is installed.`);
|
|
349
|
+
}
|
|
350
|
+
const navigationDirectory = path.dirname(navigation.path);
|
|
351
|
+
const backendExport = navigation.manifest.exports?.[NAVIGATION_BACKEND_EXPORT];
|
|
352
|
+
if (typeof backendExport !== "string") {
|
|
353
|
+
throw new TypeError(`Installed @solidnative-dev/navigation does not expose ${NAVIGATION_BACKEND_EXPORT}.`);
|
|
354
|
+
}
|
|
355
|
+
const contractPath = resolvePackageContractPath(navigationDirectory, backendExport, "Navigation backend export");
|
|
356
|
+
const contract = parseNativeNavigationBackendContract(await dependencies.readTextFile(contractPath));
|
|
357
|
+
if (contract.packageName !== "react-native-screens" ||
|
|
358
|
+
screens.manifest.name !== contract.packageName ||
|
|
359
|
+
screens.manifest.version !== contract.packageVersion) {
|
|
360
|
+
throw new TypeError(`Installed ${String(screens.manifest.name)} ${String(screens.manifest.version)} does not match ${contract.packageName} ${contract.packageVersion}.`);
|
|
361
|
+
}
|
|
362
|
+
const screensDeclaration = declaredVersion(manifest, "react-native-screens");
|
|
363
|
+
if (screensDeclaration !== contract.packageVersion) {
|
|
364
|
+
throw new TypeError(`react-native-screens must be declared as exact ${contract.packageVersion}, not ${String(screensDeclaration)}.`);
|
|
365
|
+
}
|
|
366
|
+
if (reactNativeVersion !== contract.reactNativeVersion) {
|
|
367
|
+
throw new TypeError(`The navigation backend requires React Native ${contract.reactNativeVersion}, not ${String(reactNativeVersion)}.`);
|
|
368
|
+
}
|
|
369
|
+
const patchPath = resolvePackageContractPath(navigationDirectory, contract.patch.path, "Navigation backend patch");
|
|
370
|
+
const patchSource = await dependencies.readTextFile(patchPath);
|
|
371
|
+
if (contentSha256(patchSource) !== contract.patch.sha256) {
|
|
372
|
+
throw new TypeError("The packaged navigation backend patch digest changed.");
|
|
373
|
+
}
|
|
374
|
+
const screensDirectory = path.dirname(screens.path);
|
|
375
|
+
for (const entry of contract.installedFiles) {
|
|
376
|
+
const installedPath = resolvePackageContractPath(screensDirectory, entry.path, `Navigation backend installed file ${entry.path}`);
|
|
377
|
+
const installedSource = await dependencies.readTextFile(installedPath);
|
|
378
|
+
if (contentSha256(installedSource) !== entry.sha256) {
|
|
379
|
+
throw new TypeError(`Installed react-native-screens file ${entry.path} does not match the reviewed patched backend.`);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
return check("project.navigation-backend", "Native navigation backend", "pass", `Installed react-native-screens ${contract.packageVersion} matches all ${String(contract.installedFiles.length)} reviewed patched backend files.`);
|
|
383
|
+
}
|
|
384
|
+
catch (error) {
|
|
385
|
+
return check("project.navigation-backend", "Native navigation backend", "fail", `Could not verify the installed navigation backend: ${errorMessage(error)}`, "Copy the patch exported by @solidnative-dev/navigation/react-native-screens-patch into the application, configure the package manager to apply it to the exact peer version, reinstall, and rerun solid-native doctor.");
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
function hermesCompilerRelativePath(hostPlatform) {
|
|
389
|
+
switch (hostPlatform) {
|
|
390
|
+
case "darwin":
|
|
391
|
+
return path.join("hermesc", "osx-bin", "hermesc");
|
|
392
|
+
case "linux":
|
|
393
|
+
return path.join("hermesc", "linux64-bin", "hermesc");
|
|
394
|
+
case "win32":
|
|
395
|
+
return path.join("hermesc", "win64-bin", "hermesc.exe");
|
|
396
|
+
default:
|
|
397
|
+
return undefined;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
async function inspectInstalledHermesCompatibility(projectRoot, manifest, dependencies, hostPlatform) {
|
|
401
|
+
let reactNative;
|
|
402
|
+
let compiler;
|
|
403
|
+
try {
|
|
404
|
+
[reactNative, compiler] = await Promise.all([
|
|
405
|
+
findInstalledPackageManifest(projectRoot, "react-native", dependencies),
|
|
406
|
+
findInstalledPackageManifest(projectRoot, "hermes-compiler", dependencies),
|
|
407
|
+
]);
|
|
408
|
+
}
|
|
409
|
+
catch (error) {
|
|
410
|
+
return {
|
|
411
|
+
check: check("project.hermes-pair", "React Native/Hermes compiler pair", "fail", `Could not read the installed React Native/Hermes compiler pair: ${errorMessage(error)}`, "Reinstall dependencies from the reviewed lockfile before building the application."),
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
if (reactNative === undefined || compiler === undefined) {
|
|
415
|
+
const missing = [
|
|
416
|
+
...(reactNative === undefined ? ["react-native"] : []),
|
|
417
|
+
...(compiler === undefined ? ["hermes-compiler"] : []),
|
|
418
|
+
];
|
|
419
|
+
return {
|
|
420
|
+
check: check("project.hermes-pair", "React Native/Hermes compiler pair", "fail", `The declared ${missing.join(" and ")} package${missing.length === 1 ? " is" : "s are"} not installed for this application.`, "Install dependencies from the reviewed lockfile before running native tooling."),
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
const declaredReactNative = declaredVersion(manifest, "react-native");
|
|
424
|
+
const declaredCompiler = declaredVersion(manifest, "hermes-compiler");
|
|
425
|
+
const installedReactNative = reactNative.manifest.version;
|
|
426
|
+
const installedCompiler = compiler.manifest.version;
|
|
427
|
+
const requiredCompiler = reactNative.manifest.dependencies?.["hermes-compiler"];
|
|
428
|
+
const problems = [];
|
|
429
|
+
if (reactNative.manifest.name !== "react-native" ||
|
|
430
|
+
installedReactNative === undefined) {
|
|
431
|
+
problems.push("the installed react-native manifest is invalid");
|
|
432
|
+
}
|
|
433
|
+
else if (installedReactNative !== declaredReactNative) {
|
|
434
|
+
problems.push(`react-native declares ${String(declaredReactNative)} but ${installedReactNative} is installed`);
|
|
435
|
+
}
|
|
436
|
+
if (compiler.manifest.name !== "hermes-compiler" ||
|
|
437
|
+
installedCompiler === undefined) {
|
|
438
|
+
problems.push("the installed hermes-compiler manifest is invalid");
|
|
439
|
+
}
|
|
440
|
+
else if (installedCompiler !== declaredCompiler) {
|
|
441
|
+
problems.push(`hermes-compiler declares ${String(declaredCompiler)} but ${installedCompiler} is installed`);
|
|
442
|
+
}
|
|
443
|
+
if (requiredCompiler === undefined) {
|
|
444
|
+
problems.push(`installed react-native ${String(installedReactNative)} does not pin hermes-compiler`);
|
|
445
|
+
}
|
|
446
|
+
else if (requiredCompiler !== installedCompiler) {
|
|
447
|
+
problems.push(`installed react-native ${String(installedReactNative)} requires hermes-compiler ${requiredCompiler} but the application resolves ${String(installedCompiler)}`);
|
|
448
|
+
}
|
|
449
|
+
if (problems.length > 0) {
|
|
450
|
+
return {
|
|
451
|
+
check: check("project.hermes-pair", "React Native/Hermes compiler pair", "fail", `${problems.join("; ")}.`, "Pin the exact hermes-compiler version declared by the installed react-native package, reinstall from the lockfile, and rerun solid-native doctor."),
|
|
452
|
+
};
|
|
453
|
+
}
|
|
454
|
+
let compilerPath;
|
|
455
|
+
if (hostPlatform !== undefined) {
|
|
456
|
+
const relativeCompilerPath = hermesCompilerRelativePath(hostPlatform);
|
|
457
|
+
if (relativeCompilerPath === undefined) {
|
|
458
|
+
return {
|
|
459
|
+
check: check("project.hermes-pair", "React Native/Hermes compiler pair", "fail", `Solid Native cannot select hermesc on ${hostPlatform}.`, "Build on a supported macOS, Linux, or Windows host, or add a verified compiler mapping."),
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
compilerPath = path.join(path.dirname(compiler.path), relativeCompilerPath);
|
|
463
|
+
if (!(await dependencies.pathExists(compilerPath))) {
|
|
464
|
+
return {
|
|
465
|
+
check: check("project.hermes-pair", "React Native/Hermes compiler pair", "fail", `Installed hermes-compiler ${String(installedCompiler)} does not contain the ${hostPlatform} compiler binary.`, "Reinstall the complete hermes-compiler artifact from the reviewed lockfile."),
|
|
466
|
+
};
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
return {
|
|
470
|
+
check: check("project.hermes-pair", "React Native/Hermes compiler pair", "pass", `Installed React Native ${String(installedReactNative)} requires and resolves hermes-compiler ${String(installedCompiler)}.`),
|
|
471
|
+
...(compilerPath === undefined ? {} : { compilerPath }),
|
|
472
|
+
...(installedCompiler === undefined
|
|
473
|
+
? {}
|
|
474
|
+
: { compilerVersion: installedCompiler }),
|
|
475
|
+
};
|
|
476
|
+
}
|
|
477
|
+
async function probeHermesBytecodeCompatibility(projectRoot, env, installed, dependencies) {
|
|
478
|
+
if (installed.check.status !== "pass" ||
|
|
479
|
+
installed.compilerPath === undefined ||
|
|
480
|
+
installed.compilerVersion === undefined) {
|
|
481
|
+
return check("project.hermes-bytecode", "Hermes bytecode contract", "skip", "The Hermes compiler cannot be probed until the installed React Native/compiler pair is valid.");
|
|
482
|
+
}
|
|
483
|
+
const result = await runTool(dependencies, env, projectRoot, installed.compilerPath, ["-version"]);
|
|
484
|
+
if (result.exitCode !== 0) {
|
|
485
|
+
return commandFailure("project.hermes-bytecode", "Hermes bytecode contract", "hermesc -version", result, "Reinstall the pinned hermes-compiler package before producing a native bundle.");
|
|
486
|
+
}
|
|
487
|
+
const output = commandOutput(result);
|
|
488
|
+
const releaseVersion = /Hermes release version:\s*([^\s]+)/u.exec(output)?.[1];
|
|
489
|
+
const bytecodeText = /HBC bytecode version:\s*(\d+)/u.exec(output)?.[1];
|
|
490
|
+
const bytecodeVersion = bytecodeText === undefined ? undefined : Number(bytecodeText);
|
|
491
|
+
const problems = [];
|
|
492
|
+
if (releaseVersion !== installed.compilerVersion) {
|
|
493
|
+
problems.push(releaseVersion === undefined
|
|
494
|
+
? "hermesc did not report its release version"
|
|
495
|
+
: `hermesc reports release ${releaseVersion}, not package ${installed.compilerVersion}`);
|
|
496
|
+
}
|
|
497
|
+
if (bytecodeVersion !== VERIFIED_HERMES_BYTECODE_VERSION) {
|
|
498
|
+
problems.push(bytecodeVersion === undefined
|
|
499
|
+
? "hermesc did not report its HBC bytecode version"
|
|
500
|
+
: `hermesc emits HBC ${bytecodeVersion}, not device-verified HBC ${VERIFIED_HERMES_BYTECODE_VERSION}`);
|
|
501
|
+
}
|
|
502
|
+
return problems.length === 0
|
|
503
|
+
? check("project.hermes-bytecode", "Hermes bytecode contract", "pass", `hermesc ${installed.compilerVersion} emits the device-verified HBC ${VERIFIED_HERMES_BYTECODE_VERSION} format.`)
|
|
504
|
+
: check("project.hermes-bytecode", "Hermes bytecode contract", "fail", `${problems.join("; ")}.`, "Use the exact compiler/runtime pair in the supported Solid Native backend matrix; a mismatched HBC bundle aborts at application launch.");
|
|
505
|
+
}
|
|
506
|
+
async function installedSolidNativePackagesCheck(projectRoot, platform, declarations, dependencies) {
|
|
507
|
+
if (declarations.core === undefined ||
|
|
508
|
+
declarations.fabricHost === undefined ||
|
|
509
|
+
declarations.runtime === undefined) {
|
|
510
|
+
return check("project.solid-native-installation", "Installed Solid Native packages", "skip", "The installed package set cannot be checked without all three declarations.");
|
|
511
|
+
}
|
|
512
|
+
let core;
|
|
513
|
+
let fabricHost;
|
|
514
|
+
let runtime;
|
|
515
|
+
try {
|
|
516
|
+
[core, fabricHost, runtime] = await Promise.all([
|
|
517
|
+
findInstalledPackageManifest(projectRoot, "@solidnative-dev/core", dependencies),
|
|
518
|
+
findInstalledPackageManifest(projectRoot, "@solidnative-dev/fabric-host", dependencies),
|
|
519
|
+
findInstalledPackageManifest(projectRoot, "@solidnative-dev/runtime", dependencies),
|
|
520
|
+
]);
|
|
521
|
+
}
|
|
522
|
+
catch (error) {
|
|
523
|
+
return check("project.solid-native-installation", "Installed Solid Native packages", "fail", `Could not read the installed Solid Native package set: ${errorMessage(error)}`, "Reinstall dependencies from the lockfile and rerun solid-native doctor.");
|
|
524
|
+
}
|
|
525
|
+
if (core === undefined || fabricHost === undefined || runtime === undefined) {
|
|
526
|
+
const missing = [
|
|
527
|
+
...(core === undefined ? ["@solidnative-dev/core"] : []),
|
|
528
|
+
...(fabricHost === undefined ? ["@solidnative-dev/fabric-host"] : []),
|
|
529
|
+
...(runtime === undefined ? ["@solidnative-dev/runtime"] : []),
|
|
530
|
+
];
|
|
531
|
+
return check("project.solid-native-installation", "Installed Solid Native packages", "fail", `The declared ${missing.join(" and ")} package${missing.length === 1 ? " is" : "s are"} not installed for this application.`, "Install dependencies from the lockfile before running native tooling.");
|
|
532
|
+
}
|
|
533
|
+
if (core.manifest.name !== "@solidnative-dev/core" ||
|
|
534
|
+
fabricHost.manifest.name !== "@solidnative-dev/fabric-host" ||
|
|
535
|
+
runtime.manifest.name !== "@solidnative-dev/runtime" ||
|
|
536
|
+
core.manifest.version === undefined ||
|
|
537
|
+
fabricHost.manifest.version === undefined ||
|
|
538
|
+
runtime.manifest.version === undefined) {
|
|
539
|
+
return check("project.solid-native-installation", "Installed Solid Native packages", "fail", "An installed Solid Native package has an invalid name or version.", "Remove node_modules and reinstall the reviewed package artifacts from the lockfile.");
|
|
540
|
+
}
|
|
541
|
+
if (core.manifest.version !== fabricHost.manifest.version ||
|
|
542
|
+
core.manifest.version !== runtime.manifest.version) {
|
|
543
|
+
return check("project.solid-native-installation", "Installed Solid Native packages", "fail", `Installed @solidnative-dev/core ${core.manifest.version}, @solidnative-dev/fabric-host ${fabricHost.manifest.version}, and @solidnative-dev/runtime ${runtime.manifest.version} do not match.`, "Install matching Solid Native core, Fabric Host, and runtime releases.");
|
|
544
|
+
}
|
|
545
|
+
for (const [declaration, installed, packageName] of [
|
|
546
|
+
[declarations.core, core.manifest.version, "@solidnative-dev/core"],
|
|
547
|
+
[
|
|
548
|
+
declarations.fabricHost,
|
|
549
|
+
fabricHost.manifest.version,
|
|
550
|
+
"@solidnative-dev/fabric-host",
|
|
551
|
+
],
|
|
552
|
+
[
|
|
553
|
+
declarations.runtime,
|
|
554
|
+
runtime.manifest.version,
|
|
555
|
+
"@solidnative-dev/runtime",
|
|
556
|
+
],
|
|
557
|
+
]) {
|
|
558
|
+
if (/^\d+\.\d+\.\d+(?:[-+].+)?$/u.test(declaration) &&
|
|
559
|
+
declaration !== installed) {
|
|
560
|
+
return check("project.solid-native-installation", "Installed Solid Native packages", "fail", `${packageName} declares ${declaration} but ${installed} is installed.`, "Reinstall dependencies from the lockfile or correct the exact package declaration.");
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
const requiredExports = [
|
|
564
|
+
...(platform === "all" || platform === "android"
|
|
565
|
+
? ["./android-gradle"]
|
|
566
|
+
: []),
|
|
567
|
+
...(platform === "all" || platform === "ios"
|
|
568
|
+
? ["./ios-podspec"]
|
|
569
|
+
: []),
|
|
570
|
+
"./react-native-boundary",
|
|
571
|
+
];
|
|
572
|
+
const fabricHostDirectory = path.dirname(fabricHost.path);
|
|
573
|
+
for (const exportName of requiredExports) {
|
|
574
|
+
const target = fabricHost.manifest.exports?.[exportName];
|
|
575
|
+
if (typeof target !== "string" || !target.startsWith("./")) {
|
|
576
|
+
return check("project.solid-native-installation", "Installed Solid Native packages", "fail", `Installed @solidnative-dev/fabric-host ${fabricHost.manifest.version} does not expose ${exportName}.`, "Install the complete device-verified Fabric Host artifact for the selected platform.");
|
|
577
|
+
}
|
|
578
|
+
const resolvedTarget = path.resolve(fabricHostDirectory, target);
|
|
579
|
+
const relativeTarget = path.relative(fabricHostDirectory, resolvedTarget);
|
|
580
|
+
if (relativeTarget === "" ||
|
|
581
|
+
relativeTarget === ".." ||
|
|
582
|
+
relativeTarget.startsWith(`..${path.sep}`) ||
|
|
583
|
+
!(await dependencies.pathExists(resolvedTarget))) {
|
|
584
|
+
return check("project.solid-native-installation", "Installed Solid Native packages", "fail", `Installed @solidnative-dev/fabric-host ${fabricHost.manifest.version} has an invalid or missing ${exportName} target.`, "Reinstall the complete Fabric Host artifact from the reviewed lockfile.");
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
const boundaryTarget = fabricHost.manifest.exports?.["./react-native-boundary"];
|
|
588
|
+
let boundary;
|
|
589
|
+
try {
|
|
590
|
+
boundary = JSON.parse(await dependencies.readTextFile(path.resolve(fabricHostDirectory, boundaryTarget)));
|
|
591
|
+
}
|
|
592
|
+
catch {
|
|
593
|
+
return check("project.solid-native-installation", "Installed Solid Native packages", "fail", `Installed @solidnative-dev/fabric-host ${fabricHost.manifest.version} has an unreadable React Native boundary manifest.`, "Reinstall the complete device-verified Fabric Host artifact from the reviewed lockfile.");
|
|
594
|
+
}
|
|
595
|
+
const boundaryRecord = boundary !== null &&
|
|
596
|
+
typeof boundary === "object" &&
|
|
597
|
+
!Array.isArray(boundary)
|
|
598
|
+
? boundary
|
|
599
|
+
: undefined;
|
|
600
|
+
const boundaryAndroidCmake = boundaryRecord?.androidCmake;
|
|
601
|
+
if (boundaryRecord === undefined ||
|
|
602
|
+
boundaryRecord.schemaVersion !== 1 ||
|
|
603
|
+
boundaryRecord.reactNativeVersion !==
|
|
604
|
+
VERIFIED_REACT_NATIVE_PACKAGE_VERSION ||
|
|
605
|
+
!Array.isArray(boundaryRecord.nativeHeaders) ||
|
|
606
|
+
boundaryRecord.nativeHeaders.length === 0 ||
|
|
607
|
+
!Array.isArray(boundaryRecord.generatedCodegenHeaders) ||
|
|
608
|
+
!Array.isArray(boundaryRecord.androidImports) ||
|
|
609
|
+
!Array.isArray(boundaryRecord.cocoapods) ||
|
|
610
|
+
boundaryAndroidCmake === null ||
|
|
611
|
+
typeof boundaryAndroidCmake !== "object" ||
|
|
612
|
+
Array.isArray(boundaryAndroidCmake) ||
|
|
613
|
+
!Array.isArray(boundaryAndroidCmake
|
|
614
|
+
.reactNativeIncludeDirectories) ||
|
|
615
|
+
boundaryAndroidCmake
|
|
616
|
+
.reactNativeIncludeDirectories.length === 0 ||
|
|
617
|
+
!Array.isArray(boundaryAndroidCmake.inheritedCompileOptions)) {
|
|
618
|
+
return check("project.solid-native-installation", "Installed Solid Native packages", "fail", `Installed @solidnative-dev/fabric-host ${fabricHost.manifest.version} does not contain the verified React Native ${VERIFIED_REACT_NATIVE_PACKAGE_VERSION} boundary inventory.`, "Install a Fabric Host release whose native boundary was reviewed with the selected React Native backend.");
|
|
619
|
+
}
|
|
620
|
+
return check("project.solid-native-installation", "Installed Solid Native packages", "pass", `Installed matching Solid Native ${runtime.manifest.version} core, Fabric Host, and runtime artifacts with the required native exports.`);
|
|
621
|
+
}
|
|
622
|
+
async function resolveNativeApplication(cwd, dependencies) {
|
|
623
|
+
const resolvedCwd = path.resolve(cwd ?? process.cwd());
|
|
624
|
+
const projectRoot = await findProjectRoot(resolvedCwd, dependencies.pathExists);
|
|
625
|
+
if (projectRoot === undefined) {
|
|
626
|
+
throw new TypeError(`No package.json was found at or above ${resolvedCwd}.`);
|
|
627
|
+
}
|
|
628
|
+
let manifest;
|
|
629
|
+
try {
|
|
630
|
+
manifest = parseManifest(await dependencies.readTextFile(path.join(projectRoot, "package.json")));
|
|
631
|
+
}
|
|
632
|
+
catch (error) {
|
|
633
|
+
throw new TypeError(`Could not parse package.json: ${errorMessage(error)}`);
|
|
634
|
+
}
|
|
635
|
+
const reactNativeVersion = declaredVersion(manifest, "react-native");
|
|
636
|
+
if (reactNativeVersion !== VERIFIED_REACT_NATIVE_VERSION) {
|
|
637
|
+
throw new TypeError(reactNativeVersion === undefined
|
|
638
|
+
? "react-native is not declared in the application package.json."
|
|
639
|
+
: `react-native is declared as ${reactNativeVersion}; only exact ${VERIFIED_REACT_NATIVE_VERSION} is device-verified.`);
|
|
640
|
+
}
|
|
641
|
+
for (const packageName of [
|
|
642
|
+
"@solidnative-dev/core",
|
|
643
|
+
"@solidnative-dev/fabric-host",
|
|
644
|
+
"@solidnative-dev/runtime",
|
|
645
|
+
]) {
|
|
646
|
+
if (declaredVersion(manifest, packageName) === undefined) {
|
|
647
|
+
throw new TypeError(`${packageName} is not declared in package.json.`);
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
const reactNativeCli = await findReactNativeCli(projectRoot, dependencies.pathExists);
|
|
651
|
+
if (reactNativeCli === undefined) {
|
|
652
|
+
throw new TypeError("Could not resolve the application-local react-native/cli.js. Install project dependencies before running native tooling.");
|
|
653
|
+
}
|
|
654
|
+
return { projectRoot, reactNativeCli, manifest };
|
|
655
|
+
}
|
|
656
|
+
async function requireNativeDirectory(projectRoot, platform, pathExists) {
|
|
657
|
+
const nativeDirectory = path.join(projectRoot, platform);
|
|
658
|
+
if (!(await pathExists(nativeDirectory))) {
|
|
659
|
+
throw new TypeError(`The ${platform} native project is missing at ${nativeDirectory}.`);
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
async function findInheritedPackageManager(projectRoot, dependencies) {
|
|
663
|
+
let current = path.dirname(projectRoot);
|
|
664
|
+
while (true) {
|
|
665
|
+
const manifestPath = path.join(current, "package.json");
|
|
666
|
+
if (await dependencies.pathExists(manifestPath)) {
|
|
667
|
+
try {
|
|
668
|
+
const manifest = parseManifest(await dependencies.readTextFile(manifestPath));
|
|
669
|
+
if (manifest.packageManager !== undefined) {
|
|
670
|
+
return { value: manifest.packageManager, source: manifestPath };
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
catch {
|
|
674
|
+
// The nearest project manifest is reported separately. An unrelated
|
|
675
|
+
// malformed ancestor must not hide diagnostics for the current app.
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
const parent = path.dirname(current);
|
|
679
|
+
if (parent === current)
|
|
680
|
+
return undefined;
|
|
681
|
+
current = parent;
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
function commandFailure(id, label, command, result, remediation) {
|
|
685
|
+
if (result.timedOut) {
|
|
686
|
+
return check(id, label, "fail", `${command} did not finish within ${COMMAND_TIMEOUT_MS / 1_000} seconds.`, remediation);
|
|
687
|
+
}
|
|
688
|
+
const detail = firstLine(commandOutput(result));
|
|
689
|
+
return check(id, label, "fail", detail.length === 0
|
|
690
|
+
? `${command} is unavailable or exited unsuccessfully.`
|
|
691
|
+
: `${command} failed: ${detail}`, remediation);
|
|
692
|
+
}
|
|
693
|
+
async function runTool(dependencies, env, cwd, command, args) {
|
|
694
|
+
return dependencies.runCommand(command, args, {
|
|
695
|
+
cwd,
|
|
696
|
+
env,
|
|
697
|
+
timeoutMs: COMMAND_TIMEOUT_MS,
|
|
698
|
+
});
|
|
699
|
+
}
|
|
700
|
+
const IGNORED_NATIVE_SOURCE_DIRECTORIES = new Set([
|
|
701
|
+
".git",
|
|
702
|
+
".gradle",
|
|
703
|
+
"Pods",
|
|
704
|
+
"build",
|
|
705
|
+
"DerivedData",
|
|
706
|
+
"node_modules",
|
|
707
|
+
]);
|
|
708
|
+
async function findSourceMatching(directory, fileNames, matches, dependencies, depth = 0) {
|
|
709
|
+
if (depth > 12)
|
|
710
|
+
return undefined;
|
|
711
|
+
let entries;
|
|
712
|
+
try {
|
|
713
|
+
entries = await readdir(directory, { withFileTypes: true });
|
|
714
|
+
}
|
|
715
|
+
catch {
|
|
716
|
+
return undefined;
|
|
717
|
+
}
|
|
718
|
+
entries.sort((left, right) => compareNames(left.name, right.name));
|
|
719
|
+
for (const entry of entries) {
|
|
720
|
+
if (!entry.isFile() || !fileNames.has(entry.name))
|
|
721
|
+
continue;
|
|
722
|
+
const target = path.join(directory, entry.name);
|
|
723
|
+
try {
|
|
724
|
+
const source = await dependencies.readTextFile(target);
|
|
725
|
+
if (matches(source))
|
|
726
|
+
return target;
|
|
727
|
+
}
|
|
728
|
+
catch {
|
|
729
|
+
// A different readable candidate may still provide the integration.
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
for (const entry of entries) {
|
|
733
|
+
if (!entry.isDirectory() ||
|
|
734
|
+
IGNORED_NATIVE_SOURCE_DIRECTORIES.has(entry.name)) {
|
|
735
|
+
continue;
|
|
736
|
+
}
|
|
737
|
+
const found = await findSourceMatching(path.join(directory, entry.name), fileNames, matches, dependencies, depth + 1);
|
|
738
|
+
if (found !== undefined)
|
|
739
|
+
return found;
|
|
740
|
+
}
|
|
741
|
+
return undefined;
|
|
742
|
+
}
|
|
743
|
+
async function findNativeSourceWithTokens(directory, fileNames, tokens, dependencies) {
|
|
744
|
+
return findSourceMatching(directory, fileNames, (source) => tokens.every((token) => source.includes(token)), dependencies);
|
|
745
|
+
}
|
|
746
|
+
async function readFirstExistingFile(candidates, dependencies) {
|
|
747
|
+
for (const candidate of candidates) {
|
|
748
|
+
if (!(await dependencies.pathExists(candidate)))
|
|
749
|
+
continue;
|
|
750
|
+
return {
|
|
751
|
+
path: candidate,
|
|
752
|
+
source: await dependencies.readTextFile(candidate),
|
|
753
|
+
};
|
|
754
|
+
}
|
|
755
|
+
return undefined;
|
|
756
|
+
}
|
|
757
|
+
async function findAncestorFile(start, fileName, pathExists) {
|
|
758
|
+
let current = start;
|
|
759
|
+
while (true) {
|
|
760
|
+
const candidate = path.join(current, fileName);
|
|
761
|
+
if (await pathExists(candidate))
|
|
762
|
+
return candidate;
|
|
763
|
+
const parent = path.dirname(current);
|
|
764
|
+
if (parent === current)
|
|
765
|
+
return undefined;
|
|
766
|
+
current = parent;
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
async function javascriptApplicationChecks(projectRoot, manifest, dependencies) {
|
|
770
|
+
const checks = [];
|
|
771
|
+
const solidVersion = declaredVersion(manifest, "solid-js");
|
|
772
|
+
checks.push(solidVersion === VERIFIED_SOLID_VERSION
|
|
773
|
+
? check("project.solid-runtime", "Solid runtime", "pass", `Solid is exactly pinned to the device-verified ${VERIFIED_SOLID_VERSION} runtime.`)
|
|
774
|
+
: check("project.solid-runtime", "Solid runtime", "fail", solidVersion === undefined
|
|
775
|
+
? "solid-js is not declared by the application."
|
|
776
|
+
: `solid-js is declared as ${solidVersion}; only exact ${VERIFIED_SOLID_VERSION} is device-verified.`, `Pin solid-js to exactly ${VERIFIED_SOLID_VERSION} so the compiler and runtime share one verified reactive implementation.`));
|
|
777
|
+
const buildToolExpectations = [
|
|
778
|
+
["@react-native/codegen", VERIFIED_REACT_NATIVE_VERSION],
|
|
779
|
+
["@react-native/gradle-plugin", VERIFIED_REACT_NATIVE_VERSION],
|
|
780
|
+
["hermes-compiler", VERIFIED_HERMES_COMPILER_VERSION],
|
|
781
|
+
];
|
|
782
|
+
const buildToolProblems = buildToolExpectations.flatMap(([packageName, expected]) => {
|
|
783
|
+
const declaration = declaredVersion(manifest, packageName);
|
|
784
|
+
return declaration === expected
|
|
785
|
+
? []
|
|
786
|
+
: [
|
|
787
|
+
declaration === undefined
|
|
788
|
+
? `${packageName} is missing`
|
|
789
|
+
: `${packageName} is ${declaration}, expected ${expected}`,
|
|
790
|
+
];
|
|
791
|
+
});
|
|
792
|
+
checks.push(buildToolProblems.length === 0
|
|
793
|
+
? check("project.native-build-toolchain", "React Native build toolchain", "pass", "React Native Codegen, Gradle, and Hermes build tools are directly and exactly pinned.")
|
|
794
|
+
: check("project.native-build-toolchain", "React Native build toolchain", "fail", `${buildToolProblems.join("; ")}.`, "Declare the exact React Native Codegen, Gradle plugin, and Hermes compiler versions required by the generated pnpm application."));
|
|
795
|
+
checks.push((await inspectInstalledHermesCompatibility(projectRoot, manifest, dependencies)).check);
|
|
796
|
+
const metroProblems = [];
|
|
797
|
+
const metroDeclaration = declaredVersion(manifest, "@solidnative-dev/metro");
|
|
798
|
+
if (metroDeclaration === undefined) {
|
|
799
|
+
metroProblems.push("@solidnative-dev/metro is not declared");
|
|
800
|
+
}
|
|
801
|
+
const metroConfig = await readFirstExistingFile([
|
|
802
|
+
path.join(projectRoot, "metro.config.js"),
|
|
803
|
+
path.join(projectRoot, "metro.config.cjs"),
|
|
804
|
+
path.join(projectRoot, "metro.config.mjs"),
|
|
805
|
+
], dependencies);
|
|
806
|
+
if (metroConfig === undefined) {
|
|
807
|
+
metroProblems.push("no Metro configuration was found");
|
|
808
|
+
}
|
|
809
|
+
else if (!metroConfig.source.includes("solidNativeTransformWorkerPath") ||
|
|
810
|
+
!metroConfig.source.includes("createSolidNativeMetroResolver") ||
|
|
811
|
+
!metroConfig.source.includes("createSolidNativeFullReloadPattern") ||
|
|
812
|
+
!metroConfig.source.includes("unstable_forceFullRefreshPatterns")) {
|
|
813
|
+
metroProblems.push(`${path.relative(projectRoot, metroConfig.path)} does not install the Solid OXC worker, resolver, and safe full-reload policy`);
|
|
814
|
+
}
|
|
815
|
+
if (metroDeclaration !== undefined) {
|
|
816
|
+
try {
|
|
817
|
+
const installedMetro = await findInstalledPackageManifest(projectRoot, "@solidnative-dev/metro", dependencies);
|
|
818
|
+
if (installedMetro === undefined) {
|
|
819
|
+
metroProblems.push("the declared @solidnative-dev/metro package is not installed");
|
|
820
|
+
}
|
|
821
|
+
else if (installedMetro.manifest.name !== "@solidnative-dev/metro" ||
|
|
822
|
+
installedMetro.manifest.version === undefined) {
|
|
823
|
+
metroProblems.push("the installed @solidnative-dev/metro manifest is invalid");
|
|
824
|
+
}
|
|
825
|
+
else if (/^\d+\.\d+\.\d+(?:[-+].+)?$/u.test(metroDeclaration) &&
|
|
826
|
+
metroDeclaration !== installedMetro.manifest.version) {
|
|
827
|
+
metroProblems.push(`@solidnative-dev/metro declares ${metroDeclaration} but ${installedMetro.manifest.version} is installed`);
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
catch (error) {
|
|
831
|
+
metroProblems.push(`the installed @solidnative-dev/metro package could not be read: ${errorMessage(error)}`);
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
const metroHealthy = metroProblems.length === 0 && metroConfig !== undefined;
|
|
835
|
+
checks.push(metroHealthy
|
|
836
|
+
? check("project.oxc-metro", "Solid OXC/Metro compiler", "pass", `The installed Solid Metro package owns the transform worker, resolver, and safe full-reload policy in ${path.relative(projectRoot, metroConfig.path)}.`)
|
|
837
|
+
: check("project.oxc-metro", "Solid OXC/Metro compiler", "fail", `${metroProblems.join("; ")}.`, "Install @solidnative-dev/metro and configure solidNativeTransformWorkerPath, createSolidNativeMetroResolver, and createSolidNativeFullReloadPattern through unstable_forceFullRefreshPatterns; Babel and React Refresh are not supported Solid compiler or lifecycle fallbacks."));
|
|
838
|
+
const bootstrap = await findSourceMatching(projectRoot, new Set([
|
|
839
|
+
"index.js",
|
|
840
|
+
"index.mjs",
|
|
841
|
+
"index.ts",
|
|
842
|
+
"index.tsx",
|
|
843
|
+
"main.js",
|
|
844
|
+
"main.mjs",
|
|
845
|
+
"main.ts",
|
|
846
|
+
"main.tsx",
|
|
847
|
+
]), (source) => source.includes("@solidnative-dev/runtime") &&
|
|
848
|
+
(source.includes("startNativeApplication") ||
|
|
849
|
+
(source.includes("createNativeFabricHost") &&
|
|
850
|
+
source.includes("startApplication"))), dependencies);
|
|
851
|
+
checks.push(bootstrap === undefined
|
|
852
|
+
? check("project.javascript-bootstrap", "Solid Native JavaScript bootstrap", "fail", "No application entrypoint starts the Solid renderer through @solidnative-dev/runtime.", "Call startNativeApplication, or explicitly createNativeFabricHost and startApplication, from the application entrypoint.")
|
|
853
|
+
: check("project.javascript-bootstrap", "Solid Native JavaScript bootstrap", "pass", `Found the Solid-owned application bootstrap in ${path.relative(projectRoot, bootstrap)}.`));
|
|
854
|
+
return checks;
|
|
855
|
+
}
|
|
856
|
+
async function androidChecks(projectRoot, env, dependencies) {
|
|
857
|
+
const androidDirectory = path.join(projectRoot, "android");
|
|
858
|
+
if (!(await dependencies.pathExists(androidDirectory))) {
|
|
859
|
+
return [
|
|
860
|
+
check("android.project", "Android project", "skip", "No android directory exists in this project."),
|
|
861
|
+
];
|
|
862
|
+
}
|
|
863
|
+
const checks = [
|
|
864
|
+
check("android.project", "Android project", "pass", `Found ${androidDirectory}.`),
|
|
865
|
+
];
|
|
866
|
+
const gradlePropertiesPath = path.join(androidDirectory, "gradle.properties");
|
|
867
|
+
try {
|
|
868
|
+
const gradleProperties = await dependencies.readTextFile(gradlePropertiesPath);
|
|
869
|
+
for (const [id, label, property] of [
|
|
870
|
+
["android.fabric", "React Native new architecture", "newArchEnabled"],
|
|
871
|
+
["android.hermes", "Hermes", "hermesEnabled"],
|
|
872
|
+
]) {
|
|
873
|
+
const enabled = new RegExp(`^${property}\\s*=\\s*true\\s*$`, "mu").test(gradleProperties);
|
|
874
|
+
checks.push(enabled
|
|
875
|
+
? check(id, label, "pass", `${property}=true.`)
|
|
876
|
+
: check(id, label, "fail", `${property}=true is not set in android/gradle.properties.`, `Set ${property}=true; Solid Native's verified backend requires Fabric and Hermes.`));
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
catch (error) {
|
|
880
|
+
checks.push(check("android.configuration", "Android configuration", "fail", `Could not read android/gradle.properties: ${errorMessage(error)}`, "Restore the React Native Android project configuration."));
|
|
881
|
+
}
|
|
882
|
+
const gradleWrapper = path.join(androidDirectory, "gradlew");
|
|
883
|
+
checks.push((await dependencies.pathExists(gradleWrapper))
|
|
884
|
+
? check("android.gradle-wrapper", "Gradle wrapper", "pass", "Found android/gradlew.")
|
|
885
|
+
: check("android.gradle-wrapper", "Gradle wrapper", "fail", "android/gradlew is missing.", "Regenerate or restore the checked-in Gradle wrapper."));
|
|
886
|
+
const applicationBuildCandidates = [
|
|
887
|
+
path.join(androidDirectory, "app", "build.gradle"),
|
|
888
|
+
path.join(androidDirectory, "app", "build.gradle.kts"),
|
|
889
|
+
];
|
|
890
|
+
let applicationBuild;
|
|
891
|
+
try {
|
|
892
|
+
applicationBuild = await readFirstExistingFile(applicationBuildCandidates, dependencies);
|
|
893
|
+
checks.push(applicationBuild?.source.includes("@solidnative-dev/fabric-host/android-gradle") === true
|
|
894
|
+
? check("android.runtime-gradle", "Solid Native Gradle integration", "pass", `The app resolves the package-owned Gradle helper from ${path.relative(projectRoot, applicationBuild.path)}.`)
|
|
895
|
+
: check("android.runtime-gradle", "Solid Native Gradle integration", "fail", "The Android app does not apply @solidnative-dev/fabric-host/android-gradle.", "Resolve @solidnative-dev/fabric-host/android-gradle with Node and apply it after the Android application, Kotlin, and React Native plugins."));
|
|
896
|
+
if (applicationBuild === undefined) {
|
|
897
|
+
checks.push(check("android.release-signing", "Android Release signing", "skip", "No Android application build file is available to inspect."));
|
|
898
|
+
}
|
|
899
|
+
else {
|
|
900
|
+
const signing = inspectAndroidReleaseSigning(applicationBuild.source);
|
|
901
|
+
const relativeBuildPath = path.relative(projectRoot, applicationBuild.path);
|
|
902
|
+
checks.push(signing.kind === "non-debug"
|
|
903
|
+
? check("android.release-signing", "Android Release signing", "pass", `The Release build selects the explicit non-debug ${signing.names.map((name) => `signingConfigs.${name}`).join(", ")} configuration in ${relativeBuildPath}. Secret availability and Play App Signing remain delivery-pipeline responsibilities.`)
|
|
904
|
+
: signing.kind === "debug"
|
|
905
|
+
? check("android.release-signing", "Android Release signing", "warn", `The Release build in ${relativeBuildPath} explicitly reuses signingConfigs.debug. Its AAB is suitable for local development, not Play distribution.`, "Create an app-owned non-debug signing configuration backed by a protected local or CI keystore, assign it to the Release build, and use Play App Signing. Do not commit private keys or credentials.")
|
|
906
|
+
: check("android.release-signing", "Android Release signing", "warn", signing.kind === "ambiguous"
|
|
907
|
+
? `The Release build in ${relativeBuildPath} can select both debug and non-debug signing configurations, so distribution intent is ambiguous.`
|
|
908
|
+
: `The Release build in ${relativeBuildPath} does not expose an explicit non-debug signing configuration that Solid Native can verify statically.`, "Assign an app-owned non-debug signing configuration to the Release build, inject its keystore credentials outside source control, and rerun solid-native doctor."));
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
catch (error) {
|
|
912
|
+
checks.push(check("android.runtime-gradle", "Solid Native Gradle integration", "fail", `Could not read the Android application build file: ${errorMessage(error)}`, "Restore android/app/build.gradle and apply @solidnative-dev/fabric-host/android-gradle."), check("android.release-signing", "Android Release signing", "skip", "Release signing could not be inspected because the Android application build file could not be read."));
|
|
913
|
+
}
|
|
914
|
+
const cmakePath = path.join(androidDirectory, "app", "src", "main", "jni", "CMakeLists.txt");
|
|
915
|
+
try {
|
|
916
|
+
const cmake = await dependencies.readTextFile(cmakePath);
|
|
917
|
+
checks.push(cmake.includes("SolidNativeRuntime.cmake") &&
|
|
918
|
+
cmake.includes("solid_native_configure_android_target")
|
|
919
|
+
? check("android.runtime-cmake", "Solid Native CMake integration", "pass", "The application target includes and configures SolidNativeRuntime.cmake.")
|
|
920
|
+
: check("android.runtime-cmake", "Solid Native CMake integration", "fail", "android/app/src/main/jni/CMakeLists.txt does not configure the Solid Native runtime target.", "Include SolidNativeRuntime.cmake and call solid_native_configure_android_target after React Native creates the application target."));
|
|
921
|
+
}
|
|
922
|
+
catch (error) {
|
|
923
|
+
checks.push(check("android.runtime-cmake", "Solid Native CMake integration", "fail", `Could not read android/app/src/main/jni/CMakeLists.txt: ${errorMessage(error)}`, "Add the React Native application CMake entry point and configure SolidNativeRuntime.cmake."));
|
|
924
|
+
}
|
|
925
|
+
const onLoadPath = path.join(androidDirectory, "app", "src", "main", "jni", "OnLoad.cpp");
|
|
926
|
+
try {
|
|
927
|
+
const onLoad = await dependencies.readTextFile(onLoadPath);
|
|
928
|
+
checks.push(onLoad.includes("registerSolidNativeBindingsInstaller")
|
|
929
|
+
? check("android.runtime-jni", "Solid Native JNI registration", "pass", "JNI_OnLoad registers the Solid Native bindings installer.")
|
|
930
|
+
: check("android.runtime-jni", "Solid Native JNI registration", "fail", "android/app/src/main/jni/OnLoad.cpp does not register the Solid Native bindings installer.", "Call solid_native::android::registerSolidNativeBindingsInstaller() from the fbjni initializer."));
|
|
931
|
+
}
|
|
932
|
+
catch (error) {
|
|
933
|
+
checks.push(check("android.runtime-jni", "Solid Native JNI registration", "fail", `Could not read android/app/src/main/jni/OnLoad.cpp: ${errorMessage(error)}`, "Restore the React Native JNI entry point and register the Solid Native bindings installer."));
|
|
934
|
+
}
|
|
935
|
+
const androidBootstrap = await findNativeSourceWithTokens(path.join(androidDirectory, "app", "src", "main"), new Set(["MainApplication.java", "MainApplication.kt"]), ["SolidNativeBindingsInstaller", "bindingsInstaller"], dependencies);
|
|
936
|
+
checks.push(androidBootstrap === undefined
|
|
937
|
+
? check("android.runtime-bootstrap", "Solid Native Android bootstrap", "fail", "No MainApplication source passes SolidNativeBindingsInstaller to ReactHost.", "Construct the package-owned SolidNativeBindingsInstaller and pass it as ReactHost's bindingsInstaller.")
|
|
938
|
+
: check("android.runtime-bootstrap", "Solid Native Android bootstrap", "pass", `Found the bindings installer bootstrap in ${path.relative(projectRoot, androidBootstrap)}.`));
|
|
939
|
+
const androidRuntimePackage = await findNativeSourceWithTokens(path.join(androidDirectory, "app", "src", "main"), new Set(["MainApplication.java", "MainApplication.kt"]), ["SolidNativePackage"], dependencies);
|
|
940
|
+
checks.push(androidRuntimePackage === undefined
|
|
941
|
+
? check("android.runtime-package", "Solid Native Android package", "fail", "No MainApplication source registers SolidNativePackage with ReactHost.", "Add SolidNativePackage() to the package list so debuggable builds can expose the app-private one-shot tooling module.")
|
|
942
|
+
: check("android.runtime-package", "Solid Native Android package", "pass", `Found the runtime package bootstrap in ${path.relative(projectRoot, androidRuntimePackage)}.`));
|
|
943
|
+
const androidMemoryPressure = await findNativeSourceWithTokens(path.join(androidDirectory, "app", "src", "main"), new Set(["MainApplication.java", "MainApplication.kt"]), ["SolidNativeMemoryWarning", "handleTrimMemory", "handleLowMemory"], dependencies);
|
|
944
|
+
checks.push(androidMemoryPressure === undefined
|
|
945
|
+
? check("android.memory-pressure", "Solid Native Android memory pressure", "fail", "No MainApplication source forwards Android memory-pressure callbacks to Solid Native.", "Forward onTrimMemory and onLowMemory to SolidNativeMemoryWarning so Solid-owned cache policy can react.")
|
|
946
|
+
: check("android.memory-pressure", "Solid Native Android memory pressure", "pass", `Found the memory-pressure lifecycle seam in ${path.relative(projectRoot, androidMemoryPressure)}.`));
|
|
947
|
+
const debugSpecPath = path.join(projectRoot, "specs", "NativeSolidNativeDebug.ts");
|
|
948
|
+
const platformSpecPath = path.join(projectRoot, "specs", "NativeSolidNativePlatformAndroid.ts");
|
|
949
|
+
try {
|
|
950
|
+
const manifest = parseManifest(await dependencies.readTextFile(path.join(projectRoot, "package.json")));
|
|
951
|
+
const codegen = manifest.codegenConfig;
|
|
952
|
+
const androidCodegen = isRecord(codegen?.android)
|
|
953
|
+
? codegen.android
|
|
954
|
+
: undefined;
|
|
955
|
+
const [debugSpec, platformSpec] = await Promise.all([
|
|
956
|
+
dependencies.readTextFile(debugSpecPath),
|
|
957
|
+
dependencies.readTextFile(platformSpecPath),
|
|
958
|
+
]);
|
|
959
|
+
const compactDebugSpec = debugSpec.replaceAll(/\s/gu, "");
|
|
960
|
+
const compactPlatformSpec = platformSpec.replaceAll(/\s/gu, "");
|
|
961
|
+
const valid = (codegen?.type === "modules" || codegen?.type === "all") &&
|
|
962
|
+
codegen.jsSrcsDir === "specs" &&
|
|
963
|
+
androidCodegen?.javaPackageName === "dev.solidnative.runtime" &&
|
|
964
|
+
debugSpec.includes("interface Spec extends TurboModule") &&
|
|
965
|
+
compactDebugSpec.includes("operation:string") &&
|
|
966
|
+
compactDebugSpec.includes("sessionId?:string") &&
|
|
967
|
+
compactDebugSpec.includes('TurboModuleRegistry.getEnforcing<Spec>("SolidNativeDebug"') &&
|
|
968
|
+
platformSpec.includes("interface Spec extends TurboModule") &&
|
|
969
|
+
platformSpec.includes("onMemoryWarning") &&
|
|
970
|
+
compactPlatformSpec.includes('TurboModuleRegistry.getEnforcing<Spec>("SolidNativePlatformAndroid"');
|
|
971
|
+
checks.push(valid
|
|
972
|
+
? check("android.runtime-codegen", "Solid Native runtime TurboModule specs", "pass", "React Native Codegen owns the SolidNativeDebug and SolidNativePlatformAndroid TurboModule contracts.")
|
|
973
|
+
: check("android.runtime-codegen", "Solid Native runtime TurboModule specs", "fail", "The Android application does not declare the complete Solid Native runtime Codegen contracts.", "Restore NativeSolidNativeDebug.ts and NativeSolidNativePlatformAndroid.ts through a modules/all codegenConfig using the dev.solidnative.runtime Java package."));
|
|
974
|
+
}
|
|
975
|
+
catch (error) {
|
|
976
|
+
checks.push(check("android.runtime-codegen", "Solid Native runtime TurboModule specs", "fail", `Could not read the Solid Native runtime Codegen contracts: ${errorMessage(error)}`, "Restore specs/NativeSolidNativeDebug.ts, specs/NativeSolidNativePlatformAndroid.ts, and the scaffolded package.json codegenConfig."));
|
|
977
|
+
}
|
|
978
|
+
const androidSurface = await findNativeSourceWithTokens(path.join(androidDirectory, "app", "src", "main"), new Set(["MainActivity.java", "MainActivity.kt"]), ["SolidNativeSurface", "SolidNativeSurface.start"], dependencies);
|
|
979
|
+
checks.push(androidSurface === undefined
|
|
980
|
+
? check("android.runtime-surface", "Solid Native Android surface", "fail", "No MainActivity source starts the package-owned SolidNativeSurface.", "Start SolidNativeSurface with the activity, ReactHost, and SolidNativeBindingsInstaller so surface and UI-worklet teardown remain package-owned.")
|
|
981
|
+
: check("android.runtime-surface", "Solid Native Android surface", "pass", `Found the production surface bootstrap in ${path.relative(projectRoot, androidSurface)}.`));
|
|
982
|
+
const sdkPath = await findAndroidSdk(env, dependencies);
|
|
983
|
+
checks.push(sdkPath === undefined
|
|
984
|
+
? check("android.sdk", "Android SDK", "fail", "No Android SDK directory was found.", "Install Android Studio's SDK, then set ANDROID_HOME or ANDROID_SDK_ROOT.")
|
|
985
|
+
: check("android.sdk", "Android SDK", "pass", `Found ${sdkPath}.`));
|
|
986
|
+
const adbCommand = sdkPath !== undefined &&
|
|
987
|
+
(await dependencies.pathExists(path.join(sdkPath, "platform-tools", "adb")))
|
|
988
|
+
? path.join(sdkPath, "platform-tools", "adb")
|
|
989
|
+
: "adb";
|
|
990
|
+
const javaHome = await findAndroidJavaHome(env, dependencies);
|
|
991
|
+
const javaCommand = javaHome === undefined
|
|
992
|
+
? "java"
|
|
993
|
+
: path.join(javaHome, "bin", dependencies.hostPlatform === "win32" ? "java.exe" : "java");
|
|
994
|
+
const [java, adb] = await Promise.all([
|
|
995
|
+
runTool(dependencies, env, projectRoot, javaCommand, ["-version"]),
|
|
996
|
+
runTool(dependencies, env, projectRoot, adbCommand, ["version"]),
|
|
997
|
+
]);
|
|
998
|
+
const javaMajor = parseJavaMajor(commandOutput(java));
|
|
999
|
+
checks.push(java.exitCode === 0 && javaMajor !== undefined && javaMajor >= 17
|
|
1000
|
+
? check("android.java", "Java", "pass", javaHome === undefined
|
|
1001
|
+
? `Java ${javaMajor} is available.`
|
|
1002
|
+
: `Java ${javaMajor} is available from ${javaHome}.`)
|
|
1003
|
+
: java.exitCode === 0 && javaMajor !== undefined
|
|
1004
|
+
? check("android.java", "Java", "fail", `Java ${javaMajor} is too old; Java 17 or newer is required.`, "Install a JDK 17+ distribution and update JAVA_HOME.")
|
|
1005
|
+
: commandFailure("android.java", "Java", "java", java, "Install a JDK 17+ distribution and update JAVA_HOME."));
|
|
1006
|
+
checks.push(adb.exitCode === 0
|
|
1007
|
+
? check("android.adb", "Android Debug Bridge", "pass", firstLine(commandOutput(adb)) || "adb is available.")
|
|
1008
|
+
: commandFailure("android.adb", "Android Debug Bridge", "adb", adb, "Install Android SDK Platform-Tools and add adb to PATH."));
|
|
1009
|
+
return checks;
|
|
1010
|
+
}
|
|
1011
|
+
async function findAndroidSdk(env, dependencies) {
|
|
1012
|
+
const candidates = [
|
|
1013
|
+
env.ANDROID_HOME,
|
|
1014
|
+
env.ANDROID_SDK_ROOT,
|
|
1015
|
+
dependencies.hostPlatform === "darwin"
|
|
1016
|
+
? path.join(dependencies.homeDirectory, "Library", "Android", "sdk")
|
|
1017
|
+
: path.join(dependencies.homeDirectory, "Android", "Sdk"),
|
|
1018
|
+
].filter((candidate) => typeof candidate === "string" && candidate.length > 0);
|
|
1019
|
+
for (const candidate of candidates) {
|
|
1020
|
+
if (await dependencies.pathExists(candidate)) {
|
|
1021
|
+
return candidate;
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
return undefined;
|
|
1025
|
+
}
|
|
1026
|
+
async function findAndroidJavaHome(env, dependencies) {
|
|
1027
|
+
if (typeof env.JAVA_HOME === "string" && env.JAVA_HOME.length > 0) {
|
|
1028
|
+
return path.resolve(env.JAVA_HOME);
|
|
1029
|
+
}
|
|
1030
|
+
const candidates = dependencies.hostPlatform === "darwin"
|
|
1031
|
+
? [
|
|
1032
|
+
path.join(dependencies.homeDirectory, "Applications", "Android Studio.app", "Contents", "jbr", "Contents", "Home"),
|
|
1033
|
+
path.join("/Applications", "Android Studio.app", "Contents", "jbr", "Contents", "Home"),
|
|
1034
|
+
path.join("/Applications", "Android Studio Preview.app", "Contents", "jbr", "Contents", "Home"),
|
|
1035
|
+
]
|
|
1036
|
+
: dependencies.hostPlatform === "linux"
|
|
1037
|
+
? [
|
|
1038
|
+
path.join(dependencies.homeDirectory, "android-studio", "jbr"),
|
|
1039
|
+
path.join("/opt", "android-studio", "jbr"),
|
|
1040
|
+
]
|
|
1041
|
+
: dependencies.hostPlatform === "win32"
|
|
1042
|
+
? [
|
|
1043
|
+
...(typeof env.LOCALAPPDATA === "string"
|
|
1044
|
+
? [
|
|
1045
|
+
path.join(env.LOCALAPPDATA, "Programs", "Android Studio", "jbr"),
|
|
1046
|
+
]
|
|
1047
|
+
: []),
|
|
1048
|
+
...(typeof env.ProgramFiles === "string"
|
|
1049
|
+
? [
|
|
1050
|
+
path.join(env.ProgramFiles, "Android", "Android Studio", "jbr"),
|
|
1051
|
+
]
|
|
1052
|
+
: []),
|
|
1053
|
+
]
|
|
1054
|
+
: [];
|
|
1055
|
+
const executable = dependencies.hostPlatform === "win32" ? "java.exe" : "java";
|
|
1056
|
+
for (const candidate of candidates) {
|
|
1057
|
+
if (await dependencies.pathExists(path.join(candidate, "bin", executable))) {
|
|
1058
|
+
return candidate;
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
return undefined;
|
|
1062
|
+
}
|
|
1063
|
+
async function iosChecks(projectRoot, env, dependencies) {
|
|
1064
|
+
const iosDirectory = path.join(projectRoot, "ios");
|
|
1065
|
+
if (!(await dependencies.pathExists(iosDirectory))) {
|
|
1066
|
+
return [
|
|
1067
|
+
check("ios.project", "iOS project", "skip", "No ios directory exists in this project."),
|
|
1068
|
+
];
|
|
1069
|
+
}
|
|
1070
|
+
const checks = [
|
|
1071
|
+
check("ios.project", "iOS project", "pass", `Found ${iosDirectory}.`),
|
|
1072
|
+
];
|
|
1073
|
+
const podfilePath = path.join(iosDirectory, "Podfile");
|
|
1074
|
+
let podfile;
|
|
1075
|
+
try {
|
|
1076
|
+
podfile = await dependencies.readTextFile(podfilePath);
|
|
1077
|
+
checks.push(check("ios.podfile", "Podfile", "pass", "Found ios/Podfile."));
|
|
1078
|
+
}
|
|
1079
|
+
catch {
|
|
1080
|
+
checks.push(check("ios.podfile", "Podfile", "fail", "ios/Podfile is missing or unreadable.", "Regenerate or restore the native iOS project."));
|
|
1081
|
+
}
|
|
1082
|
+
checks.push(podfile?.includes("@solidnative-dev/fabric-host/ios-podspec") === true &&
|
|
1083
|
+
podfile.includes("SolidNativeFabric")
|
|
1084
|
+
? check("ios.runtime-pod", "Solid Native iOS pod", "pass", "The Podfile resolves SolidNativeFabric through the installed Fabric Host package.")
|
|
1085
|
+
: check("ios.runtime-pod", "Solid Native iOS pod", podfile === undefined ? "skip" : "fail", podfile === undefined
|
|
1086
|
+
? "The runtime pod cannot be checked without a readable Podfile."
|
|
1087
|
+
: "The Podfile does not resolve @solidnative-dev/fabric-host/ios-podspec.", "Resolve @solidnative-dev/fabric-host/ios-podspec with Node and pass its directory to the SolidNativeFabric pod."));
|
|
1088
|
+
const iosBootstrap = await findNativeSourceWithTokens(iosDirectory, new Set(["AppDelegate.m", "AppDelegate.mm", "AppDelegate.swift"]), ["SolidNativeFabric", "SolidNativeFabricApplication"], dependencies);
|
|
1089
|
+
checks.push(iosBootstrap === undefined
|
|
1090
|
+
? check("ios.runtime-bootstrap", "Solid Native iOS bootstrap", "fail", "No AppDelegate source starts SolidNativeFabricApplication.", "Import SolidNativeFabric and start its verified empty-surface application from the native AppDelegate.")
|
|
1091
|
+
: check("ios.runtime-bootstrap", "Solid Native iOS bootstrap", "pass", `Found the Solid Native bootstrap in ${path.relative(projectRoot, iosBootstrap)}.`));
|
|
1092
|
+
const iosDebugRequest = await findNativeSourceWithTokens(iosDirectory, new Set(["AppDelegate.m", "AppDelegate.mm", "AppDelegate.swift"]), ["SolidNativeDebugRequest", "handle"], dependencies);
|
|
1093
|
+
checks.push(iosDebugRequest === undefined
|
|
1094
|
+
? check("ios.runtime-debug-url", "Solid Native iOS debug request handoff", "fail", "No AppDelegate source routes CoreDevice payload URLs to SolidNativeDebugRequest.", "Route launch and open-URL callbacks through SolidNativeDebugRequest before application Linking.")
|
|
1095
|
+
: check("ios.runtime-debug-url", "Solid Native iOS debug request handoff", "pass", `Found the one-shot debug URL handoff in ${path.relative(projectRoot, iosDebugRequest)}.`));
|
|
1096
|
+
try {
|
|
1097
|
+
const manifest = parseManifest(await dependencies.readTextFile(path.join(projectRoot, "package.json")));
|
|
1098
|
+
const codegen = manifest.codegenConfig;
|
|
1099
|
+
const iosCodegen = isRecord(codegen?.ios) ? codegen.ios : undefined;
|
|
1100
|
+
const modulesProvider = isRecord(iosCodegen?.modulesProvider)
|
|
1101
|
+
? iosCodegen.modulesProvider
|
|
1102
|
+
: undefined;
|
|
1103
|
+
checks.push((codegen?.type === "modules" || codegen?.type === "all") &&
|
|
1104
|
+
codegen.jsSrcsDir === "specs" &&
|
|
1105
|
+
modulesProvider?.SolidNativeDebug === "SolidNativeDebugModule"
|
|
1106
|
+
? check("ios.runtime-codegen", "Solid Native debug TurboModule provider", "pass", "React Native Codegen owns the SolidNativeDebug iOS provider mapping.")
|
|
1107
|
+
: check("ios.runtime-codegen", "Solid Native debug TurboModule provider", "fail", "The iOS application does not declare the SolidNativeDebug provider mapping.", "Map SolidNativeDebug to SolidNativeDebugModule in codegenConfig.ios.modulesProvider."));
|
|
1108
|
+
}
|
|
1109
|
+
catch (error) {
|
|
1110
|
+
checks.push(check("ios.runtime-codegen", "Solid Native debug TurboModule provider", "fail", `Could not read the iOS SolidNativeDebug Codegen contract: ${errorMessage(error)}`, "Restore the scaffolded package.json codegenConfig."));
|
|
1111
|
+
}
|
|
1112
|
+
if (dependencies.hostPlatform !== "darwin") {
|
|
1113
|
+
checks.push(check("ios.xcode", "Xcode", "fail", `iOS builds require macOS; this host reports ${dependencies.hostPlatform}.`, "Run local iOS builds on a Mac with Xcode installed."));
|
|
1114
|
+
return checks;
|
|
1115
|
+
}
|
|
1116
|
+
const [xcode, pods] = await Promise.all([
|
|
1117
|
+
runTool(dependencies, env, projectRoot, "xcodebuild", ["-version"]),
|
|
1118
|
+
runTool(dependencies, env, projectRoot, "pod", ["--version"]),
|
|
1119
|
+
]);
|
|
1120
|
+
checks.push(xcode.exitCode === 0
|
|
1121
|
+
? check("ios.xcode", "Xcode", "pass", firstLine(commandOutput(xcode)) || "xcodebuild is available.")
|
|
1122
|
+
: commandFailure("ios.xcode", "Xcode", "xcodebuild", xcode, "Install Xcode and select it with xcode-select."));
|
|
1123
|
+
checks.push(pods.exitCode === 0
|
|
1124
|
+
? check("ios.cocoapods", "CocoaPods", "pass", `CocoaPods ${firstLine(commandOutput(pods)) || "is available"}.`)
|
|
1125
|
+
: commandFailure("ios.cocoapods", "CocoaPods", "pod", pods, "Install CocoaPods and ensure pod is available on PATH."));
|
|
1126
|
+
return checks;
|
|
1127
|
+
}
|
|
1128
|
+
export async function runDoctor(options = {}) {
|
|
1129
|
+
const dependencies = { ...defaultDependencies(), ...options.dependencies };
|
|
1130
|
+
const cwd = path.resolve(options.cwd ?? process.cwd());
|
|
1131
|
+
const platform = options.platform ?? "all";
|
|
1132
|
+
const env = options.env ?? process.env;
|
|
1133
|
+
const checks = [];
|
|
1134
|
+
const nodeVersion = parseVersion(dependencies.nodeVersion);
|
|
1135
|
+
const nodeSupported = nodeVersion !== undefined &&
|
|
1136
|
+
((nodeVersion.major === 22 && nodeVersion.minor >= 13) ||
|
|
1137
|
+
(nodeVersion.major === 24 && nodeVersion.minor >= 3) ||
|
|
1138
|
+
nodeVersion.major >= 26);
|
|
1139
|
+
checks.push(nodeSupported
|
|
1140
|
+
? check("runtime.node", "Node.js", "pass", `Node.js ${dependencies.nodeVersion} satisfies the React Native 0.88 toolchain requirement.`)
|
|
1141
|
+
: check("runtime.node", "Node.js", "fail", `Node.js ${dependencies.nodeVersion} is outside the React Native 0.88 toolchain range.`, "Install Node.js 22.13+, 24.3+, or 26+ before running Solid Native tooling."));
|
|
1142
|
+
const discoveredRoot = await findProjectRoot(cwd, dependencies.pathExists);
|
|
1143
|
+
const projectRoot = discoveredRoot ?? cwd;
|
|
1144
|
+
if (discoveredRoot === undefined) {
|
|
1145
|
+
checks.push(check("project.manifest", "Project manifest", "fail", `No package.json was found at or above ${cwd}.`, "Run this command inside a Solid Native project."));
|
|
1146
|
+
}
|
|
1147
|
+
else {
|
|
1148
|
+
let manifest;
|
|
1149
|
+
try {
|
|
1150
|
+
manifest = parseManifest(await dependencies.readTextFile(path.join(projectRoot, "package.json")));
|
|
1151
|
+
checks.push(check("project.manifest", "Project manifest", "pass", `Loaded ${manifest.name ?? "unnamed project"} from ${projectRoot}.`));
|
|
1152
|
+
}
|
|
1153
|
+
catch (error) {
|
|
1154
|
+
checks.push(check("project.manifest", "Project manifest", "fail", `Could not parse package.json: ${errorMessage(error)}`, "Fix package.json before running native tooling."));
|
|
1155
|
+
}
|
|
1156
|
+
if (manifest !== undefined) {
|
|
1157
|
+
const workspaceRoot = await dependencies.pathExists(path.join(projectRoot, "pnpm-workspace.yaml"));
|
|
1158
|
+
const coreVersion = declaredVersion(manifest, "@solidnative-dev/core");
|
|
1159
|
+
const fabricHostVersion = declaredVersion(manifest, "@solidnative-dev/fabric-host");
|
|
1160
|
+
const runtimeVersion = declaredVersion(manifest, "@solidnative-dev/runtime");
|
|
1161
|
+
const hasMatchingPackages = coreVersion !== undefined &&
|
|
1162
|
+
fabricHostVersion !== undefined &&
|
|
1163
|
+
runtimeVersion !== undefined &&
|
|
1164
|
+
coreVersion === fabricHostVersion &&
|
|
1165
|
+
coreVersion === runtimeVersion;
|
|
1166
|
+
const isWorkspaceContainer = workspaceRoot &&
|
|
1167
|
+
coreVersion === undefined &&
|
|
1168
|
+
fabricHostVersion === undefined &&
|
|
1169
|
+
runtimeVersion === undefined;
|
|
1170
|
+
checks.push(isWorkspaceContainer || hasMatchingPackages
|
|
1171
|
+
? check("project.solid-native", "Solid Native packages", "pass", isWorkspaceContainer
|
|
1172
|
+
? "Detected a Solid Native pnpm workspace."
|
|
1173
|
+
: `Declared matching @solidnative-dev/core, @solidnative-dev/fabric-host, and @solidnative-dev/runtime ${coreVersion}.`)
|
|
1174
|
+
: check("project.solid-native", "Solid Native packages", "fail", coreVersion === undefined ||
|
|
1175
|
+
fabricHostVersion === undefined ||
|
|
1176
|
+
runtimeVersion === undefined
|
|
1177
|
+
? "@solidnative-dev/core, @solidnative-dev/fabric-host, and @solidnative-dev/runtime must be declared."
|
|
1178
|
+
: `@solidnative-dev/core ${coreVersion}, @solidnative-dev/fabric-host ${fabricHostVersion}, and @solidnative-dev/runtime ${runtimeVersion} do not match.`, "Add matching Solid Native core, Fabric Host, and runtime versions to the application."));
|
|
1179
|
+
checks.push(await installedSolidNativePackagesCheck(projectRoot, platform, {
|
|
1180
|
+
core: coreVersion,
|
|
1181
|
+
fabricHost: fabricHostVersion,
|
|
1182
|
+
runtime: runtimeVersion,
|
|
1183
|
+
}, dependencies));
|
|
1184
|
+
const reactNativeVersion = declaredVersion(manifest, "react-native");
|
|
1185
|
+
checks.push(reactNativeVersion === VERIFIED_REACT_NATIVE_VERSION
|
|
1186
|
+
? check("project.react-native", "React Native backend", "pass", `React Native is exactly pinned to the device-verified ${VERIFIED_REACT_NATIVE_VERSION} backend.`)
|
|
1187
|
+
: workspaceRoot && reactNativeVersion === undefined
|
|
1188
|
+
? check("project.react-native", "React Native backend", "skip", "This workspace root does not declare an application React Native backend.")
|
|
1189
|
+
: check("project.react-native", "React Native backend", "fail", reactNativeVersion === undefined
|
|
1190
|
+
? "react-native is not declared."
|
|
1191
|
+
: `react-native is declared as ${reactNativeVersion}; only exact ${VERIFIED_REACT_NATIVE_VERSION} is device-verified.`, `Pin react-native to exactly ${VERIFIED_REACT_NATIVE_VERSION} until another backend version is verified.`));
|
|
1192
|
+
const navigationBackend = await installedNavigationBackendCheck(projectRoot, manifest, reactNativeVersion, dependencies);
|
|
1193
|
+
if (navigationBackend !== undefined) {
|
|
1194
|
+
checks.push(navigationBackend);
|
|
1195
|
+
}
|
|
1196
|
+
if (reactNativeVersion === VERIFIED_REACT_NATIVE_VERSION) {
|
|
1197
|
+
const javascriptChecks = await javascriptApplicationChecks(projectRoot, manifest, dependencies);
|
|
1198
|
+
const installedHermes = await inspectInstalledHermesCompatibility(projectRoot, manifest, dependencies, dependencies.hostPlatform);
|
|
1199
|
+
const hasHermesPair = javascriptChecks.some((entry) => entry.id === "project.hermes-pair");
|
|
1200
|
+
checks.push(...javascriptChecks.map((entry) => entry.id === "project.hermes-pair" ? installedHermes.check : entry), ...(hasHermesPair ? [] : [installedHermes.check]));
|
|
1201
|
+
checks.push(await probeHermesBytecodeCompatibility(projectRoot, env, installedHermes, dependencies));
|
|
1202
|
+
}
|
|
1203
|
+
const inheritedPackageManager = manifest.packageManager === undefined
|
|
1204
|
+
? await findInheritedPackageManager(projectRoot, dependencies)
|
|
1205
|
+
: undefined;
|
|
1206
|
+
const packageManager = manifest.packageManager ?? inheritedPackageManager?.value;
|
|
1207
|
+
if (packageManager === undefined) {
|
|
1208
|
+
checks.push(check("project.package-manager", "Package manager", "warn", "package.json does not declare packageManager; reproducible pnpm selection is not enforced.", "Add a packageManager field such as pnpm@12.23.0."));
|
|
1209
|
+
}
|
|
1210
|
+
else if (/^pnpm@12(?:\.|$)/u.test(packageManager)) {
|
|
1211
|
+
checks.push(check("project.package-manager", "Package manager", "pass", inheritedPackageManager === undefined
|
|
1212
|
+
? `Using ${packageManager}.`
|
|
1213
|
+
: `Using ${packageManager} from ${inheritedPackageManager.source}.`));
|
|
1214
|
+
}
|
|
1215
|
+
else {
|
|
1216
|
+
checks.push(check("project.package-manager", "Package manager", "warn", `The repository currently validates pnpm 12, but packageManager is ${packageManager}.`, "Use the repository-pinned pnpm 12 release or validate the alternate package manager explicitly."));
|
|
1217
|
+
}
|
|
1218
|
+
if (reactNativeVersion === VERIFIED_REACT_NATIVE_VERSION &&
|
|
1219
|
+
/^pnpm@12(?:\.|$)/u.test(packageManager ?? "")) {
|
|
1220
|
+
const lockfile = await findAncestorFile(projectRoot, "pnpm-lock.yaml", dependencies.pathExists);
|
|
1221
|
+
checks.push(lockfile === undefined
|
|
1222
|
+
? check("project.lockfile", "Dependency lockfile", "fail", "No pnpm-lock.yaml was found at or above the application.", "Run pnpm install and commit the resulting pnpm-lock.yaml before treating the native build as reproducible.")
|
|
1223
|
+
: check("project.lockfile", "Dependency lockfile", "pass", `Found ${lockfile}.`));
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
1226
|
+
if (platform === "all" || platform === "ios") {
|
|
1227
|
+
checks.push(...(await iosChecks(projectRoot, env, dependencies)));
|
|
1228
|
+
}
|
|
1229
|
+
if (platform === "all" || platform === "android") {
|
|
1230
|
+
checks.push(...(await androidChecks(projectRoot, env, dependencies)));
|
|
1231
|
+
}
|
|
1232
|
+
}
|
|
1233
|
+
const summary = {
|
|
1234
|
+
pass: checks.filter((entry) => entry.status === "pass").length,
|
|
1235
|
+
warn: checks.filter((entry) => entry.status === "warn").length,
|
|
1236
|
+
fail: checks.filter((entry) => entry.status === "fail").length,
|
|
1237
|
+
skip: checks.filter((entry) => entry.status === "skip").length,
|
|
1238
|
+
};
|
|
1239
|
+
return {
|
|
1240
|
+
schemaVersion: 0,
|
|
1241
|
+
ok: summary.fail === 0,
|
|
1242
|
+
projectRoot,
|
|
1243
|
+
platform,
|
|
1244
|
+
checks,
|
|
1245
|
+
summary,
|
|
1246
|
+
};
|
|
1247
|
+
}
|
|
1248
|
+
const PROJECT_NAME_PATTERN = /^[A-Za-z][A-Za-z0-9]*$/u;
|
|
1249
|
+
const PACKAGE_NAME_PATTERN = /^[a-z][a-z0-9_]*(?:\.[a-z][a-z0-9_]*)+$/u;
|
|
1250
|
+
const CREATE_TEMPLATE_DIRECTORY = fileURLToPath(new URL("../templates/react-native-0.88", import.meta.url));
|
|
1251
|
+
const requireFromCli = createRequire(import.meta.url);
|
|
1252
|
+
const SOLID_NATIVE_DEPENDENCY_VERSION = `^${SOLID_NATIVE_CLI_VERSION}`;
|
|
1253
|
+
function assertProjectName(value) {
|
|
1254
|
+
if (value.length > 64 || !PROJECT_NAME_PATTERN.test(value)) {
|
|
1255
|
+
throw new TypeError("The project name must be a 1-64 character identifier beginning with a letter.");
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
function assertPackageName(value) {
|
|
1259
|
+
if (value.length > 160 || !PACKAGE_NAME_PATTERN.test(value)) {
|
|
1260
|
+
throw new TypeError("The package name must be a lowercase reverse-DNS identifier such as dev.example.application.");
|
|
1261
|
+
}
|
|
1262
|
+
}
|
|
1263
|
+
function assertApplicationTitle(value) {
|
|
1264
|
+
if (value.trim().length === 0 ||
|
|
1265
|
+
value.length > 128 ||
|
|
1266
|
+
/[\r\n]/u.test(value)) {
|
|
1267
|
+
throw new TypeError("The application title must be 1-128 characters on one line.");
|
|
1268
|
+
}
|
|
1269
|
+
}
|
|
1270
|
+
function defaultPackageName(projectName) {
|
|
1271
|
+
return `dev.solidnative.${projectName.toLowerCase()}`;
|
|
1272
|
+
}
|
|
1273
|
+
function npmPackageName(projectName) {
|
|
1274
|
+
return projectName.replace(/([a-z0-9])([A-Z])/gu, "$1-$2").toLowerCase();
|
|
1275
|
+
}
|
|
1276
|
+
function resolveReactNativeCommunityCli(explicitPath) {
|
|
1277
|
+
if (explicitPath !== undefined)
|
|
1278
|
+
return path.resolve(explicitPath);
|
|
1279
|
+
const manifest = requireFromCli.resolve("@react-native-community/cli/package.json");
|
|
1280
|
+
return path.join(path.dirname(manifest), "build", "bin.js");
|
|
1281
|
+
}
|
|
1282
|
+
export async function createNativeCreatePlan(options) {
|
|
1283
|
+
assertProjectName(options.projectName);
|
|
1284
|
+
const title = options.title ?? options.projectName;
|
|
1285
|
+
assertApplicationTitle(title);
|
|
1286
|
+
const packageName = options.packageName ?? defaultPackageName(options.projectName);
|
|
1287
|
+
assertPackageName(packageName);
|
|
1288
|
+
const creationRoot = path.resolve(options.cwd ?? process.cwd());
|
|
1289
|
+
const pathExists = options.dependencies?.pathExists ??
|
|
1290
|
+
(async (target) => {
|
|
1291
|
+
try {
|
|
1292
|
+
await access(target);
|
|
1293
|
+
return true;
|
|
1294
|
+
}
|
|
1295
|
+
catch {
|
|
1296
|
+
return false;
|
|
1297
|
+
}
|
|
1298
|
+
});
|
|
1299
|
+
if (!(await pathExists(creationRoot))) {
|
|
1300
|
+
throw new TypeError(`The creation directory does not exist: ${creationRoot}`);
|
|
1301
|
+
}
|
|
1302
|
+
const targetDirectory = path.resolve(creationRoot, options.directory ?? options.projectName);
|
|
1303
|
+
if (await pathExists(targetDirectory)) {
|
|
1304
|
+
throw new TypeError(`Refusing to replace the existing create target: ${targetDirectory}`);
|
|
1305
|
+
}
|
|
1306
|
+
const reactNativeCommunityCli = resolveReactNativeCommunityCli(options.dependencies?.reactNativeCommunityCli);
|
|
1307
|
+
return {
|
|
1308
|
+
schemaVersion: 0,
|
|
1309
|
+
operation: "create",
|
|
1310
|
+
projectName: options.projectName,
|
|
1311
|
+
packageName,
|
|
1312
|
+
title,
|
|
1313
|
+
targetDirectory,
|
|
1314
|
+
packageManager: "pnpm@12.23.0",
|
|
1315
|
+
projectRoot: creationRoot,
|
|
1316
|
+
command: process.execPath,
|
|
1317
|
+
args: [
|
|
1318
|
+
reactNativeCommunityCli,
|
|
1319
|
+
"init",
|
|
1320
|
+
options.projectName,
|
|
1321
|
+
"--version",
|
|
1322
|
+
VERIFIED_REACT_NATIVE_VERSION,
|
|
1323
|
+
"--directory",
|
|
1324
|
+
targetDirectory,
|
|
1325
|
+
"--package-name",
|
|
1326
|
+
packageName,
|
|
1327
|
+
"--title",
|
|
1328
|
+
title,
|
|
1329
|
+
"--pm",
|
|
1330
|
+
"npm",
|
|
1331
|
+
"--skip-install",
|
|
1332
|
+
"--skip-git-init",
|
|
1333
|
+
"--replace-directory",
|
|
1334
|
+
"false",
|
|
1335
|
+
"--install-pods",
|
|
1336
|
+
"false",
|
|
1337
|
+
],
|
|
1338
|
+
...(options.skipInstall === true
|
|
1339
|
+
? {}
|
|
1340
|
+
: {
|
|
1341
|
+
installCommand: {
|
|
1342
|
+
projectRoot: targetDirectory,
|
|
1343
|
+
command: "pnpm",
|
|
1344
|
+
args: ["install"],
|
|
1345
|
+
},
|
|
1346
|
+
}),
|
|
1347
|
+
};
|
|
1348
|
+
}
|
|
1349
|
+
function requireGeneratedMarker(source, marker, relativePath) {
|
|
1350
|
+
if (!source.includes(marker)) {
|
|
1351
|
+
throw new TypeError(`The React Native ${VERIFIED_REACT_NATIVE_VERSION} template changed ${relativePath}; expected ${JSON.stringify(marker)}. No Solid Native integration was written.`);
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1354
|
+
function replaceGeneratedMarker(source, marker, replacement, relativePath) {
|
|
1355
|
+
requireGeneratedMarker(source, marker, relativePath);
|
|
1356
|
+
return source.replace(marker, replacement);
|
|
1357
|
+
}
|
|
1358
|
+
function requiredStringRecord(value, location) {
|
|
1359
|
+
if (value === undefined)
|
|
1360
|
+
return {};
|
|
1361
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
1362
|
+
throw new TypeError(`${location} must be an object.`);
|
|
1363
|
+
}
|
|
1364
|
+
const result = {};
|
|
1365
|
+
for (const [name, entry] of Object.entries(value)) {
|
|
1366
|
+
if (typeof entry !== "string") {
|
|
1367
|
+
throw new TypeError(`${location}.${name} must be a string.`);
|
|
1368
|
+
}
|
|
1369
|
+
result[name] = entry;
|
|
1370
|
+
}
|
|
1371
|
+
return result;
|
|
1372
|
+
}
|
|
1373
|
+
function removeKeys(source, keys) {
|
|
1374
|
+
const result = { ...source };
|
|
1375
|
+
for (const key of keys)
|
|
1376
|
+
delete result[key];
|
|
1377
|
+
return result;
|
|
1378
|
+
}
|
|
1379
|
+
function generatedPackageManifest(source, projectName) {
|
|
1380
|
+
const parsed = JSON.parse(source);
|
|
1381
|
+
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
1382
|
+
throw new TypeError("The generated package.json must contain an object.");
|
|
1383
|
+
}
|
|
1384
|
+
const manifest = parsed;
|
|
1385
|
+
const dependencies = removeKeys(requiredStringRecord(manifest.dependencies, "package.json dependencies"), ["@react-native/new-app-screen"]);
|
|
1386
|
+
const devDependencies = removeKeys(requiredStringRecord(manifest.devDependencies, "package.json devDependencies"), [
|
|
1387
|
+
"@react-native/eslint-config",
|
|
1388
|
+
"@react-native/jest-preset",
|
|
1389
|
+
"@types/jest",
|
|
1390
|
+
"@types/react-test-renderer",
|
|
1391
|
+
"eslint",
|
|
1392
|
+
"jest",
|
|
1393
|
+
"prettier",
|
|
1394
|
+
"react-test-renderer",
|
|
1395
|
+
]);
|
|
1396
|
+
const scripts = removeKeys(requiredStringRecord(manifest.scripts, "package.json scripts"), ["lint", "test"]);
|
|
1397
|
+
if (dependencies["react-native"] !== VERIFIED_REACT_NATIVE_VERSION) {
|
|
1398
|
+
throw new TypeError(`The generated package.json did not pin react-native to ${VERIFIED_REACT_NATIVE_VERSION}.`);
|
|
1399
|
+
}
|
|
1400
|
+
return `${JSON.stringify({
|
|
1401
|
+
...manifest,
|
|
1402
|
+
name: npmPackageName(projectName),
|
|
1403
|
+
packageManager: "pnpm@12.23.0",
|
|
1404
|
+
codegenConfig: {
|
|
1405
|
+
name: "SolidNativeAppSpec",
|
|
1406
|
+
type: "modules",
|
|
1407
|
+
jsSrcsDir: "specs",
|
|
1408
|
+
android: {
|
|
1409
|
+
javaPackageName: "dev.solidnative.runtime",
|
|
1410
|
+
},
|
|
1411
|
+
ios: {
|
|
1412
|
+
modulesProvider: {
|
|
1413
|
+
SolidNativeDebug: "SolidNativeDebugModule",
|
|
1414
|
+
},
|
|
1415
|
+
},
|
|
1416
|
+
},
|
|
1417
|
+
scripts: {
|
|
1418
|
+
...scripts,
|
|
1419
|
+
android: "solid-native run android",
|
|
1420
|
+
ios: "solid-native run ios",
|
|
1421
|
+
"build:android": "solid-native build android",
|
|
1422
|
+
"build:ios": "solid-native build ios",
|
|
1423
|
+
"bundle:android": "solid-native bundle android",
|
|
1424
|
+
"bundle:ios": "solid-native bundle ios",
|
|
1425
|
+
doctor: "solid-native doctor",
|
|
1426
|
+
fingerprint: "solid-native fingerprint",
|
|
1427
|
+
generate: "solid-native generate",
|
|
1428
|
+
release: "solid-native release",
|
|
1429
|
+
start: "solid-native start",
|
|
1430
|
+
test: "solid-native test",
|
|
1431
|
+
check: "tsc -p tsconfig.json --noEmit",
|
|
1432
|
+
},
|
|
1433
|
+
dependencies: {
|
|
1434
|
+
...dependencies,
|
|
1435
|
+
"@solidnative-dev/accessibility": SOLID_NATIVE_DEPENDENCY_VERSION,
|
|
1436
|
+
"@solidnative-dev/animation": SOLID_NATIVE_DEPENDENCY_VERSION,
|
|
1437
|
+
"@solidnative-dev/core": SOLID_NATIVE_DEPENDENCY_VERSION,
|
|
1438
|
+
"@solidnative-dev/devtools": SOLID_NATIVE_DEPENDENCY_VERSION,
|
|
1439
|
+
"@solidnative-dev/dialogs": SOLID_NATIVE_DEPENDENCY_VERSION,
|
|
1440
|
+
"@solidnative-dev/fabric-host": SOLID_NATIVE_DEPENDENCY_VERSION,
|
|
1441
|
+
"@solidnative-dev/networking": SOLID_NATIVE_DEPENDENCY_VERSION,
|
|
1442
|
+
"@solidnative-dev/observability": SOLID_NATIVE_DEPENDENCY_VERSION,
|
|
1443
|
+
"@solidnative-dev/renderer": SOLID_NATIVE_DEPENDENCY_VERSION,
|
|
1444
|
+
"@solidnative-dev/runtime": SOLID_NATIVE_DEPENDENCY_VERSION,
|
|
1445
|
+
"@solidnative-dev/sharing": SOLID_NATIVE_DEPENDENCY_VERSION,
|
|
1446
|
+
"react-native-safe-area-context": VERIFIED_SAFE_AREA_CONTEXT_VERSION,
|
|
1447
|
+
"solid-js": VERIFIED_SOLID_VERSION,
|
|
1448
|
+
},
|
|
1449
|
+
devDependencies: {
|
|
1450
|
+
...devDependencies,
|
|
1451
|
+
"@react-native/codegen": VERIFIED_REACT_NATIVE_VERSION,
|
|
1452
|
+
"@react-native/gradle-plugin": VERIFIED_REACT_NATIVE_VERSION,
|
|
1453
|
+
"@solidnative-dev/cli": SOLID_NATIVE_DEPENDENCY_VERSION,
|
|
1454
|
+
"@solidnative-dev/metro": SOLID_NATIVE_DEPENDENCY_VERSION,
|
|
1455
|
+
"@solidnative-dev/testing": SOLID_NATIVE_DEPENDENCY_VERSION,
|
|
1456
|
+
"@types/node": "^22.10.0",
|
|
1457
|
+
"hermes-compiler": VERIFIED_HERMES_COMPILER_VERSION,
|
|
1458
|
+
typescript: "^5.9.2",
|
|
1459
|
+
},
|
|
1460
|
+
engines: {
|
|
1461
|
+
node: "^22.13.0 || ^24.3.0 || >=26.0.0",
|
|
1462
|
+
},
|
|
1463
|
+
}, null, 2)}\n`;
|
|
1464
|
+
}
|
|
1465
|
+
function generatedGitIgnore(source) {
|
|
1466
|
+
const entry = "/build/solid-native-codegen/";
|
|
1467
|
+
if (source.split(/\r?\n/u).includes(entry))
|
|
1468
|
+
return source;
|
|
1469
|
+
const terminated = source.endsWith("\n") ? source : `${source}\n`;
|
|
1470
|
+
return `${terminated}\n# Solid Native generated artifacts\n${entry}\n`;
|
|
1471
|
+
}
|
|
1472
|
+
async function readCreateTemplate(relativePath, replacements) {
|
|
1473
|
+
let source = await readFile(path.join(CREATE_TEMPLATE_DIRECTORY, relativePath), "utf8");
|
|
1474
|
+
for (const [name, value] of Object.entries(replacements)) {
|
|
1475
|
+
source = source.replaceAll(`__${name}__`, value);
|
|
1476
|
+
}
|
|
1477
|
+
const unresolved = /__(?!DEV__)[A-Z_]+__/u.exec(source);
|
|
1478
|
+
if (unresolved !== null) {
|
|
1479
|
+
throw new TypeError(`The Solid Native create template retained unresolved token ${unresolved[0]} in ${relativePath}.`);
|
|
1480
|
+
}
|
|
1481
|
+
return source;
|
|
1482
|
+
}
|
|
1483
|
+
export async function applyNativeCreateTemplate(plan) {
|
|
1484
|
+
const target = plan.targetDirectory;
|
|
1485
|
+
const androidPackageDirectory = path.join(target, "android", "app", "src", "main", "java", ...plan.packageName.split("."));
|
|
1486
|
+
const paths = {
|
|
1487
|
+
packageManifest: path.join(target, "package.json"),
|
|
1488
|
+
gitIgnore: path.join(target, ".gitignore"),
|
|
1489
|
+
appBuild: path.join(target, "android", "app", "build.gradle"),
|
|
1490
|
+
gradleProperties: path.join(target, "android", "gradle.properties"),
|
|
1491
|
+
mainApplication: path.join(androidPackageDirectory, "MainApplication.kt"),
|
|
1492
|
+
mainActivity: path.join(androidPackageDirectory, "MainActivity.kt"),
|
|
1493
|
+
podfile: path.join(target, "ios", "Podfile"),
|
|
1494
|
+
infoPlist: path.join(target, "ios", plan.projectName, "Info.plist"),
|
|
1495
|
+
appDelegate: path.join(target, "ios", plan.projectName, "AppDelegate.swift"),
|
|
1496
|
+
sceneDelegate: path.join(target, "ios", plan.projectName, "SceneDelegate.swift"),
|
|
1497
|
+
};
|
|
1498
|
+
const [packageManifest, gitIgnore, appBuild, gradleProperties, mainApplication, mainActivity, podfile, infoPlist, appDelegate, sceneDelegate,] = await Promise.all([
|
|
1499
|
+
readFile(paths.packageManifest, "utf8"),
|
|
1500
|
+
readFile(paths.gitIgnore, "utf8"),
|
|
1501
|
+
readFile(paths.appBuild, "utf8"),
|
|
1502
|
+
readFile(paths.gradleProperties, "utf8"),
|
|
1503
|
+
readFile(paths.mainApplication, "utf8"),
|
|
1504
|
+
readFile(paths.mainActivity, "utf8"),
|
|
1505
|
+
readFile(paths.podfile, "utf8"),
|
|
1506
|
+
readFile(paths.infoPlist, "utf8"),
|
|
1507
|
+
readFile(paths.appDelegate, "utf8"),
|
|
1508
|
+
readFile(paths.sceneDelegate, "utf8").catch((error) => {
|
|
1509
|
+
if (typeof error === "object" &&
|
|
1510
|
+
error !== null &&
|
|
1511
|
+
"code" in error &&
|
|
1512
|
+
error.code === "ENOENT") {
|
|
1513
|
+
return undefined;
|
|
1514
|
+
}
|
|
1515
|
+
throw error;
|
|
1516
|
+
}),
|
|
1517
|
+
]);
|
|
1518
|
+
requireGeneratedMarker(mainApplication, "getDefaultReactHost", "android MainApplication.kt");
|
|
1519
|
+
requireGeneratedMarker(mainActivity, "ReactActivity", "android MainActivity.kt");
|
|
1520
|
+
if (sceneDelegate !== undefined) {
|
|
1521
|
+
requireGeneratedMarker(appDelegate, "UIApplicationDelegate", "iOS AppDelegate.swift");
|
|
1522
|
+
requireGeneratedMarker(sceneDelegate, "RCTReactNativeFactory", "iOS SceneDelegate.swift");
|
|
1523
|
+
}
|
|
1524
|
+
else {
|
|
1525
|
+
requireGeneratedMarker(appDelegate, "RCTReactNativeFactory", "iOS AppDelegate.swift");
|
|
1526
|
+
}
|
|
1527
|
+
const gradleIntegration = `apply plugin: "com.facebook.react"
|
|
1528
|
+
|
|
1529
|
+
def solidNativeAndroidGradle = file(
|
|
1530
|
+
providers.exec {
|
|
1531
|
+
workingDir(rootProject.projectDir)
|
|
1532
|
+
commandLine(
|
|
1533
|
+
"node",
|
|
1534
|
+
"--print",
|
|
1535
|
+
"require.resolve('@solidnative-dev/fabric-host/android-gradle')"
|
|
1536
|
+
)
|
|
1537
|
+
}.standardOutput.asText.get().trim()
|
|
1538
|
+
)
|
|
1539
|
+
apply from: solidNativeAndroidGradle`;
|
|
1540
|
+
let nextAppBuild = replaceGeneratedMarker(appBuild, 'apply plugin: "com.facebook.react"', gradleIntegration, "android/app/build.gradle");
|
|
1541
|
+
nextAppBuild = replaceGeneratedMarker(nextAppBuild, "android {", `android {
|
|
1542
|
+
externalNativeBuild {
|
|
1543
|
+
cmake {
|
|
1544
|
+
path "src/main/jni/CMakeLists.txt"
|
|
1545
|
+
}
|
|
1546
|
+
}`, "android/app/build.gradle");
|
|
1547
|
+
nextAppBuild = replaceGeneratedMarker(nextAppBuild, "dependencies {", `dependencies {
|
|
1548
|
+
implementation("androidx.appcompat:appcompat:1.7.1")`, "android/app/build.gradle");
|
|
1549
|
+
const nextGradleProperties = replaceGeneratedMarker(gradleProperties, "edgeToEdgeEnabled=true", "edgeToEdgeEnabled=false", "android/gradle.properties");
|
|
1550
|
+
const podResolution = `solid_native_fabric_host_native_path = File.dirname(
|
|
1551
|
+
Pod::Executable.execute_command('node', ['--preserve-symlinks', '-p',
|
|
1552
|
+
'require.resolve(
|
|
1553
|
+
"@solidnative-dev/fabric-host/ios-podspec",
|
|
1554
|
+
{paths: [process.argv[1]]},
|
|
1555
|
+
)', __dir__]).strip
|
|
1556
|
+
)
|
|
1557
|
+
solid_native_fabric_host_native_path = Pathname
|
|
1558
|
+
.new(solid_native_fabric_host_native_path)
|
|
1559
|
+
.relative_path_from(Pathname.new(__dir__))
|
|
1560
|
+
.to_s
|
|
1561
|
+
|
|
1562
|
+
platform :ios`;
|
|
1563
|
+
let nextPodfile = replaceGeneratedMarker(podfile, "platform :ios", podResolution, "ios/Podfile");
|
|
1564
|
+
nextPodfile = replaceGeneratedMarker(nextPodfile, " config = use_native_modules!", ` config = use_native_modules!
|
|
1565
|
+
|
|
1566
|
+
pod 'SolidNativeFabric', :path => solid_native_fabric_host_native_path`, "ios/Podfile");
|
|
1567
|
+
const hasSceneManifest = infoPlist.includes("<key>UIApplicationSceneManifest</key>");
|
|
1568
|
+
const hasStatusBarAppearance = infoPlist.includes("<key>UIViewControllerBasedStatusBarAppearance</key>");
|
|
1569
|
+
let nextInfoPlist = replaceGeneratedMarker(infoPlist, "\t<key>NSLocationWhenInUseUsageDescription</key>\n\t<string></string>\n", `${hasStatusBarAppearance ? "" : "\t<key>UIViewControllerBasedStatusBarAppearance</key>\n\t<true/>\n"}${hasSceneManifest
|
|
1570
|
+
? ""
|
|
1571
|
+
: `\t<key>UIApplicationSceneManifest</key>
|
|
1572
|
+
\t<dict>
|
|
1573
|
+
\t\t<key>UIApplicationSupportsMultipleScenes</key>
|
|
1574
|
+
\t\t<false/>
|
|
1575
|
+
\t\t<key>UISceneConfigurations</key>
|
|
1576
|
+
\t\t<dict>
|
|
1577
|
+
\t\t\t<key>UIWindowSceneSessionRoleApplication</key>
|
|
1578
|
+
\t\t\t<array>
|
|
1579
|
+
\t\t\t\t<dict>
|
|
1580
|
+
\t\t\t\t\t<key>UISceneConfigurationName</key>
|
|
1581
|
+
\t\t\t\t\t<string>Solid Native</string>
|
|
1582
|
+
\t\t\t\t\t<key>UISceneDelegateClassName</key>
|
|
1583
|
+
\t\t\t\t\t<string>$(PRODUCT_MODULE_NAME).SolidNativeSceneDelegate</string>
|
|
1584
|
+
\t\t\t\t</dict>
|
|
1585
|
+
\t\t\t</array>
|
|
1586
|
+
\t\t</dict>
|
|
1587
|
+
\t</dict>
|
|
1588
|
+
`}`, "iOS Info.plist");
|
|
1589
|
+
if (hasSceneManifest) {
|
|
1590
|
+
nextInfoPlist = replaceGeneratedMarker(nextInfoPlist, "<string>$(PRODUCT_MODULE_NAME).SceneDelegate</string>", "<string>$(PRODUCT_MODULE_NAME).SolidNativeSceneDelegate</string>", "iOS Info.plist");
|
|
1591
|
+
if (nextInfoPlist.includes("<string>Default Configuration</string>")) {
|
|
1592
|
+
nextInfoPlist = nextInfoPlist.replace("<string>Default Configuration</string>", "<string>Solid Native</string>");
|
|
1593
|
+
}
|
|
1594
|
+
}
|
|
1595
|
+
if (hasStatusBarAppearance) {
|
|
1596
|
+
nextInfoPlist = nextInfoPlist.replace(/<key>UIViewControllerBasedStatusBarAppearance<\/key>\s*<false\/>/u, "<key>UIViewControllerBasedStatusBarAppearance</key>\n\t<true/>");
|
|
1597
|
+
}
|
|
1598
|
+
const replacements = {
|
|
1599
|
+
ANDROID_PACKAGE: plan.packageName,
|
|
1600
|
+
APP_TITLE: plan.title,
|
|
1601
|
+
APP_TITLE_LITERAL: JSON.stringify(plan.title),
|
|
1602
|
+
IOS_BUNDLE_ID: plan.packageName,
|
|
1603
|
+
PROJECT_NAME: plan.projectName,
|
|
1604
|
+
};
|
|
1605
|
+
const templateFiles = await Promise.all([
|
|
1606
|
+
"index.js",
|
|
1607
|
+
"src/App.tsx",
|
|
1608
|
+
"src/main.tsx",
|
|
1609
|
+
"test/App.test.tsx",
|
|
1610
|
+
"specs/NativeSolidNativeDebug.ts",
|
|
1611
|
+
"specs/NativeSolidNativePlatformAndroid.ts",
|
|
1612
|
+
"metro.config.js",
|
|
1613
|
+
"android/CMakeLists.txt",
|
|
1614
|
+
"android/OnLoad.cpp",
|
|
1615
|
+
"android/MainApplication.kt",
|
|
1616
|
+
"android/MainActivity.kt",
|
|
1617
|
+
"ios/AppDelegate.swift",
|
|
1618
|
+
"README.md",
|
|
1619
|
+
].map(async (relativePath) => ({
|
|
1620
|
+
relativePath,
|
|
1621
|
+
source: await readCreateTemplate(relativePath, replacements),
|
|
1622
|
+
})));
|
|
1623
|
+
await Promise.all([
|
|
1624
|
+
mkdir(path.join(target, "src"), { recursive: true }),
|
|
1625
|
+
mkdir(path.join(target, "specs"), { recursive: true }),
|
|
1626
|
+
mkdir(path.join(target, "test"), { recursive: true }),
|
|
1627
|
+
mkdir(path.join(target, "android", "app", "src", "main", "jni"), {
|
|
1628
|
+
recursive: true,
|
|
1629
|
+
}),
|
|
1630
|
+
]);
|
|
1631
|
+
const templateDestinations = {
|
|
1632
|
+
"index.js": path.join(target, "index.js"),
|
|
1633
|
+
"src/App.tsx": path.join(target, "src", "App.tsx"),
|
|
1634
|
+
"src/main.tsx": path.join(target, "src", "main.tsx"),
|
|
1635
|
+
"test/App.test.tsx": path.join(target, "test", "App.test.tsx"),
|
|
1636
|
+
"specs/NativeSolidNativeDebug.ts": path.join(target, "specs", "NativeSolidNativeDebug.ts"),
|
|
1637
|
+
"specs/NativeSolidNativePlatformAndroid.ts": path.join(target, "specs", "NativeSolidNativePlatformAndroid.ts"),
|
|
1638
|
+
"metro.config.js": path.join(target, "metro.config.js"),
|
|
1639
|
+
"android/CMakeLists.txt": path.join(target, "android", "app", "src", "main", "jni", "CMakeLists.txt"),
|
|
1640
|
+
"android/OnLoad.cpp": path.join(target, "android", "app", "src", "main", "jni", "OnLoad.cpp"),
|
|
1641
|
+
"android/MainApplication.kt": paths.mainApplication,
|
|
1642
|
+
"android/MainActivity.kt": paths.mainActivity,
|
|
1643
|
+
"ios/AppDelegate.swift": paths.appDelegate,
|
|
1644
|
+
"README.md": path.join(target, "README.md"),
|
|
1645
|
+
};
|
|
1646
|
+
await Promise.all([
|
|
1647
|
+
writeFile(paths.packageManifest, generatedPackageManifest(packageManifest, plan.projectName)),
|
|
1648
|
+
writeFile(paths.gitIgnore, generatedGitIgnore(gitIgnore)),
|
|
1649
|
+
writeFile(paths.appBuild, nextAppBuild),
|
|
1650
|
+
writeFile(paths.gradleProperties, nextGradleProperties),
|
|
1651
|
+
writeFile(paths.podfile, nextPodfile),
|
|
1652
|
+
writeFile(paths.infoPlist, nextInfoPlist),
|
|
1653
|
+
...(sceneDelegate === undefined
|
|
1654
|
+
? []
|
|
1655
|
+
: [
|
|
1656
|
+
writeFile(paths.sceneDelegate, "// Scene lifecycle ownership lives in SolidNativeSceneDelegate inside AppDelegate.swift.\n"),
|
|
1657
|
+
]),
|
|
1658
|
+
writeFile(path.join(target, "tsconfig.json"), `${JSON.stringify({
|
|
1659
|
+
extends: "@react-native/typescript-config",
|
|
1660
|
+
compilerOptions: {
|
|
1661
|
+
jsx: "preserve",
|
|
1662
|
+
jsxImportSource: "@solidnative-dev/core",
|
|
1663
|
+
allowImportingTsExtensions: true,
|
|
1664
|
+
types: ["react-native", "node"],
|
|
1665
|
+
},
|
|
1666
|
+
include: [
|
|
1667
|
+
"src/**/*.ts",
|
|
1668
|
+
"src/**/*.tsx",
|
|
1669
|
+
"specs/**/*.ts",
|
|
1670
|
+
"test/**/*.ts",
|
|
1671
|
+
"test/**/*.tsx",
|
|
1672
|
+
],
|
|
1673
|
+
exclude: ["**/node_modules", "**/Pods"],
|
|
1674
|
+
}, null, 2)}\n`),
|
|
1675
|
+
...templateFiles.map(({ relativePath, source }) => writeFile(templateDestinations[relativePath], source)),
|
|
1676
|
+
]);
|
|
1677
|
+
await Promise.all([
|
|
1678
|
+
rm(path.join(target, "App.tsx"), { force: true }),
|
|
1679
|
+
rm(path.join(target, "__tests__"), { force: true, recursive: true }),
|
|
1680
|
+
rm(path.join(target, "jest.config.js"), { force: true }),
|
|
1681
|
+
rm(path.join(target, ".eslintrc.js"), { force: true }),
|
|
1682
|
+
rm(path.join(target, ".prettierrc.js"), { force: true }),
|
|
1683
|
+
]);
|
|
1684
|
+
}
|
|
1685
|
+
async function requireVerifiedJavaScriptApplication(application, platform, dependencies) {
|
|
1686
|
+
const installedRuntime = await installedSolidNativePackagesCheck(application.projectRoot, platform, {
|
|
1687
|
+
core: declaredVersion(application.manifest, "@solidnative-dev/core"),
|
|
1688
|
+
fabricHost: declaredVersion(application.manifest, "@solidnative-dev/fabric-host"),
|
|
1689
|
+
runtime: declaredVersion(application.manifest, "@solidnative-dev/runtime"),
|
|
1690
|
+
}, dependencies);
|
|
1691
|
+
if (installedRuntime.status !== "pass") {
|
|
1692
|
+
throw new TypeError(`${installedRuntime.message}${installedRuntime.remediation === undefined
|
|
1693
|
+
? ""
|
|
1694
|
+
: ` ${installedRuntime.remediation}`}`);
|
|
1695
|
+
}
|
|
1696
|
+
const applicationFailure = (await javascriptApplicationChecks(application.projectRoot, application.manifest, dependencies)).find((entry) => entry.status === "fail");
|
|
1697
|
+
if (applicationFailure !== undefined) {
|
|
1698
|
+
throw new TypeError(`${applicationFailure.label}: ${applicationFailure.message}${applicationFailure.remediation === undefined
|
|
1699
|
+
? ""
|
|
1700
|
+
: ` ${applicationFailure.remediation}`}`);
|
|
1701
|
+
}
|
|
1702
|
+
}
|
|
1703
|
+
async function resolveNativeProcessApplication(options) {
|
|
1704
|
+
const dependencies = fileDependencies(options.dependencies);
|
|
1705
|
+
const application = await resolveNativeApplication(options.cwd, dependencies);
|
|
1706
|
+
await requireVerifiedJavaScriptApplication(application, options.platform, dependencies);
|
|
1707
|
+
const runEnvironment = options.env ?? process.env;
|
|
1708
|
+
const environmentDefaults = {};
|
|
1709
|
+
if (options.platform === "android" &&
|
|
1710
|
+
runEnvironment.ANDROID_HOME === undefined &&
|
|
1711
|
+
runEnvironment.ANDROID_SDK_ROOT === undefined) {
|
|
1712
|
+
const androidSdk = await findAndroidSdk(runEnvironment, {
|
|
1713
|
+
homeDirectory: options.dependencies?.homeDirectory ?? homedir(),
|
|
1714
|
+
hostPlatform: options.dependencies?.hostPlatform ?? process.platform,
|
|
1715
|
+
pathExists: dependencies.pathExists,
|
|
1716
|
+
});
|
|
1717
|
+
if (androidSdk !== undefined)
|
|
1718
|
+
environmentDefaults.ANDROID_HOME = androidSdk;
|
|
1719
|
+
}
|
|
1720
|
+
if (options.platform === "android" &&
|
|
1721
|
+
runEnvironment.JAVA_HOME === undefined) {
|
|
1722
|
+
const androidJavaHome = await findAndroidJavaHome(runEnvironment, {
|
|
1723
|
+
homeDirectory: options.dependencies?.homeDirectory ?? homedir(),
|
|
1724
|
+
hostPlatform: options.dependencies?.hostPlatform ?? process.platform,
|
|
1725
|
+
pathExists: dependencies.pathExists,
|
|
1726
|
+
});
|
|
1727
|
+
if (androidJavaHome !== undefined) {
|
|
1728
|
+
environmentDefaults.JAVA_HOME = androidJavaHome;
|
|
1729
|
+
}
|
|
1730
|
+
}
|
|
1731
|
+
await requireNativeDirectory(application.projectRoot, options.platform, dependencies.pathExists);
|
|
1732
|
+
return { application, environmentDefaults };
|
|
1733
|
+
}
|
|
1734
|
+
export async function createNativeStartPlan(options = {}) {
|
|
1735
|
+
const dependencies = fileDependencies(options.dependencies);
|
|
1736
|
+
const application = await resolveNativeApplication(options.cwd, dependencies);
|
|
1737
|
+
await requireVerifiedJavaScriptApplication(application, "all", dependencies);
|
|
1738
|
+
return {
|
|
1739
|
+
schemaVersion: 0,
|
|
1740
|
+
operation: "start",
|
|
1741
|
+
projectRoot: application.projectRoot,
|
|
1742
|
+
command: process.execPath,
|
|
1743
|
+
args: [
|
|
1744
|
+
application.reactNativeCli,
|
|
1745
|
+
"start",
|
|
1746
|
+
...(options.forwardedArgs ?? []),
|
|
1747
|
+
],
|
|
1748
|
+
};
|
|
1749
|
+
}
|
|
1750
|
+
function forwardedOptionValue(args, option) {
|
|
1751
|
+
// Commander retains the last occurrence of a repeated scalar option. Walk
|
|
1752
|
+
// backward so destination preflights follow the same target resolution.
|
|
1753
|
+
for (let index = args.length - 1; index >= 0; index -= 1) {
|
|
1754
|
+
const argument = args[index];
|
|
1755
|
+
if (argument === undefined)
|
|
1756
|
+
continue;
|
|
1757
|
+
if (argument.startsWith(`${option}=`)) {
|
|
1758
|
+
const value = argument.slice(option.length + 1);
|
|
1759
|
+
return value.length === 0 ? undefined : value;
|
|
1760
|
+
}
|
|
1761
|
+
if (argument === option) {
|
|
1762
|
+
const value = args[index + 1];
|
|
1763
|
+
return value === undefined || value.startsWith("-") ? undefined : value;
|
|
1764
|
+
}
|
|
1765
|
+
}
|
|
1766
|
+
return undefined;
|
|
1767
|
+
}
|
|
1768
|
+
function iosDestinationPreflight(args) {
|
|
1769
|
+
// React Native gives --udid precedence over --device when both are present.
|
|
1770
|
+
const udid = forwardedOptionValue(args, "--udid");
|
|
1771
|
+
if (udid !== undefined)
|
|
1772
|
+
return { kind: "udid", value: udid };
|
|
1773
|
+
const device = forwardedOptionValue(args, "--device");
|
|
1774
|
+
return device === undefined ? undefined : { kind: "device", value: device };
|
|
1775
|
+
}
|
|
1776
|
+
function androidDestinationPreflight(args) {
|
|
1777
|
+
// The React Native CLI lets interactive/list selection replace an explicit
|
|
1778
|
+
// destination, so do not lease a device it will not necessarily use.
|
|
1779
|
+
if (hasForwardedOption(args, "--interactive") ||
|
|
1780
|
+
args.includes("-i") ||
|
|
1781
|
+
hasForwardedOption(args, "--list-devices")) {
|
|
1782
|
+
return undefined;
|
|
1783
|
+
}
|
|
1784
|
+
// React Native's deprecated deviceId option overwrites device when both are
|
|
1785
|
+
// present. Preserve that precedence so the preflight and native CLI agree.
|
|
1786
|
+
const deviceId = forwardedOptionValue(args, "--deviceId");
|
|
1787
|
+
if (hasForwardedOption(args, "--deviceId") && deviceId === undefined) {
|
|
1788
|
+
throw new TypeError("run android --deviceId requires a device serial.");
|
|
1789
|
+
}
|
|
1790
|
+
if (deviceId !== undefined) {
|
|
1791
|
+
return { kind: "deviceId", value: deviceId };
|
|
1792
|
+
}
|
|
1793
|
+
const device = forwardedOptionValue(args, "--device");
|
|
1794
|
+
if (hasForwardedOption(args, "--device") && device === undefined) {
|
|
1795
|
+
throw new TypeError("run android --device requires a device serial.");
|
|
1796
|
+
}
|
|
1797
|
+
return device === undefined
|
|
1798
|
+
? { kind: "automatic" }
|
|
1799
|
+
: { kind: "device", value: device };
|
|
1800
|
+
}
|
|
1801
|
+
export async function createNativeRunPlan(options) {
|
|
1802
|
+
const { application, environmentDefaults } = await resolveNativeProcessApplication(options);
|
|
1803
|
+
const forwardedArgs = options.forwardedArgs ?? [];
|
|
1804
|
+
const iosPreflight = options.platform === "ios"
|
|
1805
|
+
? iosDestinationPreflight(forwardedArgs)
|
|
1806
|
+
: undefined;
|
|
1807
|
+
const androidPreflight = options.platform === "android"
|
|
1808
|
+
? androidDestinationPreflight(forwardedArgs)
|
|
1809
|
+
: undefined;
|
|
1810
|
+
return {
|
|
1811
|
+
schemaVersion: 0,
|
|
1812
|
+
operation: "run",
|
|
1813
|
+
platform: options.platform,
|
|
1814
|
+
projectRoot: application.projectRoot,
|
|
1815
|
+
command: process.execPath,
|
|
1816
|
+
args: [
|
|
1817
|
+
application.reactNativeCli,
|
|
1818
|
+
options.platform === "ios" ? "run-ios" : "run-android",
|
|
1819
|
+
...forwardedArgs,
|
|
1820
|
+
],
|
|
1821
|
+
...(Object.keys(environmentDefaults).length === 0
|
|
1822
|
+
? {}
|
|
1823
|
+
: { environmentDefaults }),
|
|
1824
|
+
...(androidPreflight === undefined
|
|
1825
|
+
? {}
|
|
1826
|
+
: { androidDestinationPreflight: androidPreflight }),
|
|
1827
|
+
...(iosPreflight === undefined
|
|
1828
|
+
? {}
|
|
1829
|
+
: { iosDestinationPreflight: iosPreflight }),
|
|
1830
|
+
};
|
|
1831
|
+
}
|
|
1832
|
+
function hasForwardedOption(args, option) {
|
|
1833
|
+
return args.some((argument) => argument === option || argument.startsWith(`${option}=`));
|
|
1834
|
+
}
|
|
1835
|
+
const RESERVED_BUNDLE_OPTIONS = [
|
|
1836
|
+
"--asset-catalog-dest",
|
|
1837
|
+
"--assets-dest",
|
|
1838
|
+
"--bundle-encoding",
|
|
1839
|
+
"--bundle-output",
|
|
1840
|
+
"--config",
|
|
1841
|
+
"--dev",
|
|
1842
|
+
"--entry-file",
|
|
1843
|
+
"--minify",
|
|
1844
|
+
"--platform",
|
|
1845
|
+
"--sourcemap-output",
|
|
1846
|
+
"--sourcemap-sources-root",
|
|
1847
|
+
"--sourcemap-use-absolute-path",
|
|
1848
|
+
"--transformer",
|
|
1849
|
+
];
|
|
1850
|
+
function pathContains(root, target) {
|
|
1851
|
+
const relative = path.relative(root, target);
|
|
1852
|
+
return (relative === "" ||
|
|
1853
|
+
(relative !== ".." && !relative.startsWith(`..${path.sep}`)));
|
|
1854
|
+
}
|
|
1855
|
+
async function requirePhysicalOutputContainment(projectRoot, target, label, dependencies) {
|
|
1856
|
+
let existingAncestor = target;
|
|
1857
|
+
while (!(await dependencies.pathExists(existingAncestor))) {
|
|
1858
|
+
const parent = path.dirname(existingAncestor);
|
|
1859
|
+
if (parent === existingAncestor)
|
|
1860
|
+
break;
|
|
1861
|
+
existingAncestor = parent;
|
|
1862
|
+
}
|
|
1863
|
+
const [physicalRoot, physicalAncestor] = await Promise.all([
|
|
1864
|
+
dependencies.realPath(projectRoot),
|
|
1865
|
+
dependencies.realPath(existingAncestor),
|
|
1866
|
+
]);
|
|
1867
|
+
if (!pathContains(physicalRoot, physicalAncestor)) {
|
|
1868
|
+
throw new TypeError(`${label} must remain inside the application root after resolving symlinks.`);
|
|
1869
|
+
}
|
|
1870
|
+
}
|
|
1871
|
+
export async function createNativeBundlePlan(options) {
|
|
1872
|
+
const dependencies = fileDependencies(options.dependencies);
|
|
1873
|
+
const application = await resolveNativeApplication(options.cwd, dependencies);
|
|
1874
|
+
const hermesSource = options.hermesSource === true;
|
|
1875
|
+
await requireVerifiedJavaScriptApplication(application, options.platform, dependencies);
|
|
1876
|
+
await requireNativeDirectory(application.projectRoot, options.platform, dependencies.pathExists);
|
|
1877
|
+
const forwardedArgs = options.forwardedArgs ?? [];
|
|
1878
|
+
for (const option of RESERVED_BUNDLE_OPTIONS) {
|
|
1879
|
+
if (hasForwardedOption(forwardedArgs, option)) {
|
|
1880
|
+
throw new TypeError(`${option} is owned by solid-native bundle and cannot be forwarded.`);
|
|
1881
|
+
}
|
|
1882
|
+
}
|
|
1883
|
+
let entryFile = options.entryFile === undefined
|
|
1884
|
+
? undefined
|
|
1885
|
+
: path.resolve(application.projectRoot, options.entryFile);
|
|
1886
|
+
if (entryFile === undefined) {
|
|
1887
|
+
for (const fileName of ["index.js", "index.tsx", "index.ts", "index.mjs"]) {
|
|
1888
|
+
const candidate = path.join(application.projectRoot, fileName);
|
|
1889
|
+
if (await dependencies.pathExists(candidate)) {
|
|
1890
|
+
entryFile = candidate;
|
|
1891
|
+
break;
|
|
1892
|
+
}
|
|
1893
|
+
}
|
|
1894
|
+
}
|
|
1895
|
+
if (entryFile === undefined ||
|
|
1896
|
+
!pathContains(application.projectRoot, entryFile) ||
|
|
1897
|
+
!(await dependencies.pathExists(entryFile))) {
|
|
1898
|
+
throw new TypeError(`The bundle entry must be a present file inside ${application.projectRoot}.`);
|
|
1899
|
+
}
|
|
1900
|
+
const lockfile = await findAncestorFile(application.projectRoot, "pnpm-lock.yaml", dependencies.pathExists);
|
|
1901
|
+
if (lockfile === undefined) {
|
|
1902
|
+
throw new TypeError("No pnpm-lock.yaml was found at or above the application; the source-map root is not reproducible.");
|
|
1903
|
+
}
|
|
1904
|
+
const sourceRoot = path.dirname(lockfile);
|
|
1905
|
+
if (sourceRoot === path.parse(sourceRoot).root) {
|
|
1906
|
+
throw new TypeError("The pnpm lockfile cannot define the filesystem root as a source-map trust boundary.");
|
|
1907
|
+
}
|
|
1908
|
+
const outputDirectory = path.resolve(application.projectRoot, options.outputDirectory ??
|
|
1909
|
+
(options.platform === "android"
|
|
1910
|
+
? path.join("android", "app", "build", "solid-native-bundle")
|
|
1911
|
+
: path.join("ios", "build", "solid-native-bundle")));
|
|
1912
|
+
if (outputDirectory === sourceRoot ||
|
|
1913
|
+
pathContains(outputDirectory, application.projectRoot)) {
|
|
1914
|
+
throw new TypeError("The bundle output must not be the application, workspace, or an ancestor directory.");
|
|
1915
|
+
}
|
|
1916
|
+
const bundlePath = path.join(outputDirectory, `index.${options.platform}.bundle`);
|
|
1917
|
+
const sourceMapPath = hermesSource
|
|
1918
|
+
? `${bundlePath}.packager.map`
|
|
1919
|
+
: `${bundlePath}.map`;
|
|
1920
|
+
const assetsDirectory = path.join(outputDirectory, "assets");
|
|
1921
|
+
const manifestPath = path.join(outputDirectory, "solid-native-bundle.json");
|
|
1922
|
+
return {
|
|
1923
|
+
schemaVersion: 0,
|
|
1924
|
+
operation: "bundle",
|
|
1925
|
+
platform: options.platform,
|
|
1926
|
+
projectRoot: application.projectRoot,
|
|
1927
|
+
sourceRoot,
|
|
1928
|
+
entryFile,
|
|
1929
|
+
entryPoint: path
|
|
1930
|
+
.relative(application.projectRoot, entryFile)
|
|
1931
|
+
.replaceAll(path.sep, "/"),
|
|
1932
|
+
outputDirectory,
|
|
1933
|
+
bundlePath,
|
|
1934
|
+
sourceMapPath,
|
|
1935
|
+
assetsDirectory,
|
|
1936
|
+
manifestPath,
|
|
1937
|
+
minified: !hermesSource,
|
|
1938
|
+
hermesSource,
|
|
1939
|
+
command: process.execPath,
|
|
1940
|
+
args: [
|
|
1941
|
+
application.reactNativeCli,
|
|
1942
|
+
"bundle",
|
|
1943
|
+
"--platform",
|
|
1944
|
+
options.platform,
|
|
1945
|
+
"--dev",
|
|
1946
|
+
"false",
|
|
1947
|
+
"--minify",
|
|
1948
|
+
hermesSource ? "false" : "true",
|
|
1949
|
+
"--entry-file",
|
|
1950
|
+
entryFile,
|
|
1951
|
+
"--bundle-output",
|
|
1952
|
+
bundlePath,
|
|
1953
|
+
"--sourcemap-output",
|
|
1954
|
+
sourceMapPath,
|
|
1955
|
+
"--sourcemap-sources-root",
|
|
1956
|
+
sourceRoot,
|
|
1957
|
+
"--assets-dest",
|
|
1958
|
+
assetsDirectory,
|
|
1959
|
+
...forwardedArgs,
|
|
1960
|
+
],
|
|
1961
|
+
};
|
|
1962
|
+
}
|
|
1963
|
+
export async function createNativeBuildPlan(options) {
|
|
1964
|
+
const { application, environmentDefaults } = await resolveNativeProcessApplication(options);
|
|
1965
|
+
const forwardedArgs = options.forwardedArgs ?? [];
|
|
1966
|
+
const selectsNativeConfiguration = hasForwardedOption(forwardedArgs, "--mode") ||
|
|
1967
|
+
hasForwardedOption(forwardedArgs, "--interactive") ||
|
|
1968
|
+
forwardedArgs.includes("-i") ||
|
|
1969
|
+
(options.platform === "android" &&
|
|
1970
|
+
hasForwardedOption(forwardedArgs, "--tasks"));
|
|
1971
|
+
return {
|
|
1972
|
+
schemaVersion: 0,
|
|
1973
|
+
operation: "build",
|
|
1974
|
+
platform: options.platform,
|
|
1975
|
+
projectRoot: application.projectRoot,
|
|
1976
|
+
command: process.execPath,
|
|
1977
|
+
args: [
|
|
1978
|
+
application.reactNativeCli,
|
|
1979
|
+
options.platform === "ios" ? "build-ios" : "build-android",
|
|
1980
|
+
...(selectsNativeConfiguration ? [] : ["--mode", "Release"]),
|
|
1981
|
+
...forwardedArgs,
|
|
1982
|
+
],
|
|
1983
|
+
...(Object.keys(environmentDefaults).length === 0
|
|
1984
|
+
? {}
|
|
1985
|
+
: { environmentDefaults }),
|
|
1986
|
+
};
|
|
1987
|
+
}
|
|
1988
|
+
const FORWARDED_NATIVE_SIGNALS = ["SIGHUP", "SIGINT", "SIGTERM"];
|
|
1989
|
+
function nativeSignalExitCode(signal) {
|
|
1990
|
+
switch (signal) {
|
|
1991
|
+
case "SIGHUP":
|
|
1992
|
+
return 129;
|
|
1993
|
+
case "SIGINT":
|
|
1994
|
+
return 130;
|
|
1995
|
+
case "SIGTERM":
|
|
1996
|
+
return 143;
|
|
1997
|
+
default:
|
|
1998
|
+
return 1;
|
|
1999
|
+
}
|
|
2000
|
+
}
|
|
2001
|
+
function forwardNativeSignal(child, signal) {
|
|
2002
|
+
if (process.platform !== "win32" && child.pid !== undefined) {
|
|
2003
|
+
try {
|
|
2004
|
+
process.kill(-child.pid, signal);
|
|
2005
|
+
return;
|
|
2006
|
+
}
|
|
2007
|
+
catch {
|
|
2008
|
+
// Fall back to the direct child if its process group has already gone.
|
|
2009
|
+
}
|
|
2010
|
+
}
|
|
2011
|
+
if (!child.killed)
|
|
2012
|
+
child.kill(signal);
|
|
2013
|
+
}
|
|
2014
|
+
const spawnNativeProcess = (plan, context) => new Promise((resolve, reject) => {
|
|
2015
|
+
const quietOnSuccess = context.output === "quiet-on-success";
|
|
2016
|
+
const child = spawn(plan.command, [...plan.args], {
|
|
2017
|
+
cwd: plan.projectRoot,
|
|
2018
|
+
detached: process.platform !== "win32",
|
|
2019
|
+
env: context.env,
|
|
2020
|
+
stdio: quietOnSuccess ? ["inherit", "pipe", "pipe"] : "inherit",
|
|
2021
|
+
});
|
|
2022
|
+
let stdout = "";
|
|
2023
|
+
let stderr = "";
|
|
2024
|
+
let stdoutTruncated = false;
|
|
2025
|
+
let stderrTruncated = false;
|
|
2026
|
+
const append = (current, chunk) => {
|
|
2027
|
+
const next = `${current}${chunk.toString("utf8")}`;
|
|
2028
|
+
return next.length <= MAX_COMMAND_OUTPUT
|
|
2029
|
+
? { output: next, truncated: false }
|
|
2030
|
+
: {
|
|
2031
|
+
output: next.slice(-MAX_COMMAND_OUTPUT),
|
|
2032
|
+
truncated: true,
|
|
2033
|
+
};
|
|
2034
|
+
};
|
|
2035
|
+
child.stdout?.on("data", (chunk) => {
|
|
2036
|
+
const next = append(stdout, chunk);
|
|
2037
|
+
stdout = next.output;
|
|
2038
|
+
stdoutTruncated ||= next.truncated;
|
|
2039
|
+
});
|
|
2040
|
+
child.stderr?.on("data", (chunk) => {
|
|
2041
|
+
const next = append(stderr, chunk);
|
|
2042
|
+
stderr = next.output;
|
|
2043
|
+
stderrTruncated ||= next.truncated;
|
|
2044
|
+
});
|
|
2045
|
+
let capturedOutputWritten = false;
|
|
2046
|
+
const writeCapturedOutput = () => {
|
|
2047
|
+
if (!quietOnSuccess || capturedOutputWritten)
|
|
2048
|
+
return;
|
|
2049
|
+
capturedOutputWritten = true;
|
|
2050
|
+
if (stdout.length > 0) {
|
|
2051
|
+
process.stdout.write(`${stdoutTruncated ? "[Earlier scaffold output omitted.]\n" : ""}${stdout}`);
|
|
2052
|
+
}
|
|
2053
|
+
if (stderr.length > 0) {
|
|
2054
|
+
process.stderr.write(`${stderrTruncated ? "[Earlier scaffold error output omitted.]\n" : ""}${stderr}`);
|
|
2055
|
+
}
|
|
2056
|
+
};
|
|
2057
|
+
let forwardedSignal;
|
|
2058
|
+
const signalHandlers = new Map();
|
|
2059
|
+
const removeSignalHandlers = () => {
|
|
2060
|
+
for (const [signal, handler] of signalHandlers) {
|
|
2061
|
+
process.removeListener(signal, handler);
|
|
2062
|
+
}
|
|
2063
|
+
signalHandlers.clear();
|
|
2064
|
+
};
|
|
2065
|
+
for (const signal of FORWARDED_NATIVE_SIGNALS) {
|
|
2066
|
+
const handler = () => {
|
|
2067
|
+
forwardedSignal ??= signal;
|
|
2068
|
+
forwardNativeSignal(child, signal);
|
|
2069
|
+
};
|
|
2070
|
+
signalHandlers.set(signal, handler);
|
|
2071
|
+
process.on(signal, handler);
|
|
2072
|
+
}
|
|
2073
|
+
child.once("error", (error) => {
|
|
2074
|
+
removeSignalHandlers();
|
|
2075
|
+
writeCapturedOutput();
|
|
2076
|
+
reject(error);
|
|
2077
|
+
});
|
|
2078
|
+
child.once("close", (exitCode, signal) => {
|
|
2079
|
+
removeSignalHandlers();
|
|
2080
|
+
if (forwardedSignal !== undefined) {
|
|
2081
|
+
writeCapturedOutput();
|
|
2082
|
+
resolve(nativeSignalExitCode(forwardedSignal));
|
|
2083
|
+
return;
|
|
2084
|
+
}
|
|
2085
|
+
if (exitCode !== null) {
|
|
2086
|
+
if (exitCode !== 0)
|
|
2087
|
+
writeCapturedOutput();
|
|
2088
|
+
resolve(exitCode);
|
|
2089
|
+
return;
|
|
2090
|
+
}
|
|
2091
|
+
writeCapturedOutput();
|
|
2092
|
+
resolve(nativeSignalExitCode(signal));
|
|
2093
|
+
});
|
|
2094
|
+
});
|
|
2095
|
+
export const defaultNativeRunExecutor = spawnNativeProcess;
|
|
2096
|
+
export const defaultNativeBuildExecutor = spawnNativeProcess;
|
|
2097
|
+
export const defaultNativeBundleExecutor = spawnNativeProcess;
|
|
2098
|
+
export const defaultNativeStartExecutor = spawnNativeProcess;
|
|
2099
|
+
export const defaultNativeTestExecutor = spawnNativeProcess;
|
|
2100
|
+
export const defaultNativeCreateExecutor = spawnNativeProcess;
|
|
2101
|
+
async function createdScaffoldStatus(targetDirectory) {
|
|
2102
|
+
try {
|
|
2103
|
+
return await lstat(targetDirectory);
|
|
2104
|
+
}
|
|
2105
|
+
catch (error) {
|
|
2106
|
+
if (error instanceof Error && "code" in error && error.code === "ENOENT") {
|
|
2107
|
+
return undefined;
|
|
2108
|
+
}
|
|
2109
|
+
throw error;
|
|
2110
|
+
}
|
|
2111
|
+
}
|
|
2112
|
+
async function removeNewCreateScaffold(targetDirectory, cause) {
|
|
2113
|
+
const scaffold = await createdScaffoldStatus(targetDirectory);
|
|
2114
|
+
if (scaffold === undefined)
|
|
2115
|
+
return;
|
|
2116
|
+
if (!scaffold.isDirectory()) {
|
|
2117
|
+
throw new AggregateError([
|
|
2118
|
+
cause,
|
|
2119
|
+
new TypeError(`Refusing to remove an unexpected non-directory create target: ${targetDirectory}`),
|
|
2120
|
+
], `Solid Native creation failed and its target could not be cleaned safely: ${targetDirectory}.`);
|
|
2121
|
+
}
|
|
2122
|
+
try {
|
|
2123
|
+
await rm(targetDirectory, { force: true, recursive: true });
|
|
2124
|
+
}
|
|
2125
|
+
catch (cleanupError) {
|
|
2126
|
+
throw new AggregateError([cause, cleanupError], `Solid Native creation failed and could not remove its new scaffold at ${targetDirectory}.`);
|
|
2127
|
+
}
|
|
2128
|
+
}
|
|
2129
|
+
export async function executeNativeCreatePlan(plan, options = {}) {
|
|
2130
|
+
const executor = options.executor ?? defaultNativeCreateExecutor;
|
|
2131
|
+
const env = options.env ?? process.env;
|
|
2132
|
+
try {
|
|
2133
|
+
await access(plan.targetDirectory);
|
|
2134
|
+
throw new TypeError(`Refusing to replace the existing create target: ${plan.targetDirectory}`);
|
|
2135
|
+
}
|
|
2136
|
+
catch (error) {
|
|
2137
|
+
if (!(error instanceof Error) ||
|
|
2138
|
+
!("code" in error) ||
|
|
2139
|
+
error.code !== "ENOENT") {
|
|
2140
|
+
throw error;
|
|
2141
|
+
}
|
|
2142
|
+
}
|
|
2143
|
+
const scaffoldExitCode = await executor(plan, {
|
|
2144
|
+
env,
|
|
2145
|
+
output: "quiet-on-success",
|
|
2146
|
+
});
|
|
2147
|
+
if (scaffoldExitCode !== 0) {
|
|
2148
|
+
await removeNewCreateScaffold(plan.targetDirectory, new Error(`The upstream scaffold exited with status ${String(scaffoldExitCode)}.`));
|
|
2149
|
+
return scaffoldExitCode;
|
|
2150
|
+
}
|
|
2151
|
+
const scaffold = await createdScaffoldStatus(plan.targetDirectory);
|
|
2152
|
+
if (scaffold === undefined || !scaffold.isDirectory()) {
|
|
2153
|
+
throw new TypeError(`The upstream scaffold completed without creating the expected directory: ${plan.targetDirectory}`);
|
|
2154
|
+
}
|
|
2155
|
+
try {
|
|
2156
|
+
await applyNativeCreateTemplate(plan);
|
|
2157
|
+
}
|
|
2158
|
+
catch (error) {
|
|
2159
|
+
await removeNewCreateScaffold(plan.targetDirectory, error);
|
|
2160
|
+
throw error;
|
|
2161
|
+
}
|
|
2162
|
+
if (plan.installCommand === undefined)
|
|
2163
|
+
return 0;
|
|
2164
|
+
return executor(plan.installCommand, { env, output: "inherit" });
|
|
2165
|
+
}
|
|
2166
|
+
export async function executeNativeRunPlan(plan, options = {}) {
|
|
2167
|
+
const environment = { ...(options.env ?? process.env) };
|
|
2168
|
+
for (const [name, value] of Object.entries(plan.environmentDefaults ?? {})) {
|
|
2169
|
+
if (environment[name] === undefined)
|
|
2170
|
+
environment[name] = value;
|
|
2171
|
+
}
|
|
2172
|
+
if (plan.iosDestinationPreflight !== undefined) {
|
|
2173
|
+
await (options.iosPreflight ?? preflightNativeIosRunDestination)({
|
|
2174
|
+
selector: plan.iosDestinationPreflight,
|
|
2175
|
+
cwd: plan.projectRoot,
|
|
2176
|
+
env: environment,
|
|
2177
|
+
});
|
|
2178
|
+
}
|
|
2179
|
+
let androidResult;
|
|
2180
|
+
if (plan.androidDestinationPreflight !== undefined) {
|
|
2181
|
+
androidResult = await (options.androidPreflight ?? preflightNativeAndroidRunDestination)({
|
|
2182
|
+
selector: plan.androidDestinationPreflight,
|
|
2183
|
+
cwd: plan.projectRoot,
|
|
2184
|
+
env: environment,
|
|
2185
|
+
});
|
|
2186
|
+
}
|
|
2187
|
+
const executionPlan = plan.androidDestinationPreflight?.kind === "automatic" &&
|
|
2188
|
+
androidResult !== undefined
|
|
2189
|
+
? {
|
|
2190
|
+
...plan,
|
|
2191
|
+
args: [
|
|
2192
|
+
...plan.args.slice(0, 2),
|
|
2193
|
+
"--device",
|
|
2194
|
+
androidResult.serial,
|
|
2195
|
+
...plan.args.slice(2),
|
|
2196
|
+
],
|
|
2197
|
+
}
|
|
2198
|
+
: plan;
|
|
2199
|
+
let exitCode;
|
|
2200
|
+
let executionError;
|
|
2201
|
+
try {
|
|
2202
|
+
exitCode = await (options.executor ?? defaultNativeRunExecutor)(executionPlan, {
|
|
2203
|
+
env: environment,
|
|
2204
|
+
});
|
|
2205
|
+
}
|
|
2206
|
+
catch (error) {
|
|
2207
|
+
executionError = error;
|
|
2208
|
+
}
|
|
2209
|
+
let restoreError;
|
|
2210
|
+
if (androidResult !== undefined) {
|
|
2211
|
+
try {
|
|
2212
|
+
await (options.androidRestore ?? restoreNativeAndroidRunDestination)({
|
|
2213
|
+
result: androidResult,
|
|
2214
|
+
cwd: plan.projectRoot,
|
|
2215
|
+
env: environment,
|
|
2216
|
+
});
|
|
2217
|
+
}
|
|
2218
|
+
catch (error) {
|
|
2219
|
+
restoreError = error;
|
|
2220
|
+
}
|
|
2221
|
+
}
|
|
2222
|
+
if (executionError !== undefined && restoreError !== undefined) {
|
|
2223
|
+
throw new AggregateError([executionError, restoreError], "The Android run failed and its device stay-awake lease could not be restored and released.");
|
|
2224
|
+
}
|
|
2225
|
+
if (executionError !== undefined)
|
|
2226
|
+
throw executionError;
|
|
2227
|
+
if (restoreError !== undefined)
|
|
2228
|
+
throw restoreError;
|
|
2229
|
+
if (exitCode === undefined) {
|
|
2230
|
+
throw new TypeError("The native run executor returned no exit code.");
|
|
2231
|
+
}
|
|
2232
|
+
return exitCode;
|
|
2233
|
+
}
|
|
2234
|
+
export async function executeNativeBuildPlan(plan, options = {}) {
|
|
2235
|
+
const environment = { ...(options.env ?? process.env) };
|
|
2236
|
+
for (const [name, value] of Object.entries(plan.environmentDefaults ?? {})) {
|
|
2237
|
+
if (environment[name] === undefined)
|
|
2238
|
+
environment[name] = value;
|
|
2239
|
+
}
|
|
2240
|
+
return (options.executor ?? defaultNativeBuildExecutor)(plan, {
|
|
2241
|
+
env: environment,
|
|
2242
|
+
});
|
|
2243
|
+
}
|
|
2244
|
+
export async function executeNativeBundlePlan(plan, options = {}) {
|
|
2245
|
+
await Promise.all([
|
|
2246
|
+
mkdir(plan.outputDirectory, { recursive: true }),
|
|
2247
|
+
mkdir(plan.assetsDirectory, { recursive: true }),
|
|
2248
|
+
]);
|
|
2249
|
+
const exitCode = await (options.executor ?? defaultNativeBundleExecutor)(plan, { env: options.env ?? process.env });
|
|
2250
|
+
if (exitCode !== 0)
|
|
2251
|
+
return exitCode;
|
|
2252
|
+
let bundleMetadata;
|
|
2253
|
+
try {
|
|
2254
|
+
bundleMetadata = await stat(plan.bundlePath);
|
|
2255
|
+
}
|
|
2256
|
+
catch {
|
|
2257
|
+
throw new TypeError("Metro reported success without writing the bundle.");
|
|
2258
|
+
}
|
|
2259
|
+
if (!bundleMetadata.isFile() || bundleMetadata.size === 0) {
|
|
2260
|
+
throw new TypeError("Metro wrote an empty or non-regular bundle output.");
|
|
2261
|
+
}
|
|
2262
|
+
await canonicalizeNativeSourceMap(plan.sourceMapPath, plan.sourceRoot);
|
|
2263
|
+
await writeNativeBundleManifest({
|
|
2264
|
+
platform: plan.platform,
|
|
2265
|
+
entryPoint: plan.entryPoint,
|
|
2266
|
+
outputDirectory: plan.outputDirectory,
|
|
2267
|
+
bundlePath: plan.bundlePath,
|
|
2268
|
+
sourceMapPath: plan.sourceMapPath,
|
|
2269
|
+
assetsDirectory: plan.assetsDirectory,
|
|
2270
|
+
manifestPath: plan.manifestPath,
|
|
2271
|
+
minified: plan.minified,
|
|
2272
|
+
});
|
|
2273
|
+
return 0;
|
|
2274
|
+
}
|
|
2275
|
+
/** Checks one bounded Metro source graph against application-owned policy. */
|
|
2276
|
+
export async function checkNativeBundleSources(options) {
|
|
2277
|
+
const dependencies = fileDependencies(options.dependencies);
|
|
2278
|
+
const resolvedCwd = path.resolve(options.cwd ?? process.cwd());
|
|
2279
|
+
const projectRoot = await findProjectRoot(resolvedCwd, dependencies.pathExists);
|
|
2280
|
+
if (projectRoot === undefined) {
|
|
2281
|
+
throw new TypeError(`No package.json was found at or above ${resolvedCwd}.`);
|
|
2282
|
+
}
|
|
2283
|
+
const lockfile = await findAncestorFile(projectRoot, "pnpm-lock.yaml", dependencies.pathExists);
|
|
2284
|
+
if (lockfile === undefined) {
|
|
2285
|
+
throw new TypeError("No pnpm-lock.yaml was found at or above the application; the source-map root is not reproducible.");
|
|
2286
|
+
}
|
|
2287
|
+
const sourceRoot = path.dirname(lockfile);
|
|
2288
|
+
return verifyNativeSourceMapPolicy({
|
|
2289
|
+
sourceMapPath: path.resolve(projectRoot, options.sourceMapPath),
|
|
2290
|
+
sourceRoot,
|
|
2291
|
+
...(options.requiredSources === undefined
|
|
2292
|
+
? {}
|
|
2293
|
+
: { requiredSources: options.requiredSources }),
|
|
2294
|
+
...(options.forbiddenSourceFragments === undefined
|
|
2295
|
+
? {}
|
|
2296
|
+
: { forbiddenSourceFragments: options.forbiddenSourceFragments }),
|
|
2297
|
+
});
|
|
2298
|
+
}
|
|
2299
|
+
export async function executeNativeStartPlan(plan, options = {}) {
|
|
2300
|
+
return (options.executor ?? defaultNativeStartExecutor)(plan, {
|
|
2301
|
+
env: options.env ?? process.env,
|
|
2302
|
+
});
|
|
2303
|
+
}
|
|
2304
|
+
export async function executeNativeTestPlan(plan, options = {}) {
|
|
2305
|
+
return (options.executor ?? defaultNativeTestExecutor)(plan, {
|
|
2306
|
+
env: options.env ?? process.env,
|
|
2307
|
+
});
|
|
2308
|
+
}
|
|
2309
|
+
const SOLID_BINDING_LIBRARY_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/u;
|
|
2310
|
+
const SOLID_BINDING_PACKAGE_NAME = /^(?:@[A-Za-z0-9][A-Za-z0-9._~-]*\/)?[A-Za-z0-9][A-Za-z0-9._~-]*$/u;
|
|
2311
|
+
async function createSolidBindingInput(packageName, packageVersion, packageRoot, config, origin, dependencies) {
|
|
2312
|
+
if (Array.isArray(config.libraries)) {
|
|
2313
|
+
throw new TypeError(`${packageName} uses the deprecated codegenConfig.libraries shape; migrate it to one React Native 0.88 Codegen config before generating Solid bindings.`);
|
|
2314
|
+
}
|
|
2315
|
+
const kind = config.type;
|
|
2316
|
+
const libraryName = config.name;
|
|
2317
|
+
const jsSources = config.jsSrcsDir;
|
|
2318
|
+
if (kind !== "components" && kind !== "modules" && kind !== "all") {
|
|
2319
|
+
throw new TypeError(`${packageName} Codegen config must declare a components, modules, or all type.`);
|
|
2320
|
+
}
|
|
2321
|
+
if (typeof libraryName !== "string" ||
|
|
2322
|
+
libraryName.length === 0 ||
|
|
2323
|
+
libraryName.length > 128 ||
|
|
2324
|
+
!SOLID_BINDING_LIBRARY_NAME.test(libraryName) ||
|
|
2325
|
+
typeof jsSources !== "string" ||
|
|
2326
|
+
jsSources.length === 0) {
|
|
2327
|
+
throw new TypeError(`${packageName} Codegen config must declare an identifier name and a string jsSrcsDir.`);
|
|
2328
|
+
}
|
|
2329
|
+
const sourcePath = path.resolve(packageRoot, jsSources);
|
|
2330
|
+
if (!pathContains(packageRoot, sourcePath)) {
|
|
2331
|
+
throw new TypeError(`${packageName} Solid Codegen source must stay inside its package root.`);
|
|
2332
|
+
}
|
|
2333
|
+
if (!(await dependencies.pathExists(sourcePath))) {
|
|
2334
|
+
throw new TypeError(`${packageName} Solid Codegen source is missing at ${sourcePath}.`);
|
|
2335
|
+
}
|
|
2336
|
+
const [physicalPackageRoot, physicalSourcePath] = await Promise.all([
|
|
2337
|
+
dependencies.realPath(packageRoot),
|
|
2338
|
+
dependencies.realPath(sourcePath),
|
|
2339
|
+
]);
|
|
2340
|
+
if (!pathContains(physicalPackageRoot, physicalSourcePath)) {
|
|
2341
|
+
throw new TypeError(`${packageName} Solid Codegen source must remain inside its package root after resolving symlinks.`);
|
|
2342
|
+
}
|
|
2343
|
+
return {
|
|
2344
|
+
origin,
|
|
2345
|
+
kind,
|
|
2346
|
+
libraryName,
|
|
2347
|
+
packageName,
|
|
2348
|
+
...(packageVersion === undefined ? {} : { packageVersion }),
|
|
2349
|
+
sourcePath,
|
|
2350
|
+
};
|
|
2351
|
+
}
|
|
2352
|
+
function combinedSolidBindingKind(inputs) {
|
|
2353
|
+
const first = inputs[0]?.kind;
|
|
2354
|
+
return first !== undefined && inputs.every((input) => input.kind === first)
|
|
2355
|
+
? first
|
|
2356
|
+
: "all";
|
|
2357
|
+
}
|
|
2358
|
+
function assertSelectedSolidBindingInput(input) {
|
|
2359
|
+
const schema = combineReactNativeCodegenSchemas([input.sourcePath], {
|
|
2360
|
+
libraryName: input.libraryName,
|
|
2361
|
+
});
|
|
2362
|
+
const audit = createSolidNativeSchemaAudit(schema);
|
|
2363
|
+
const componentCount = audit.components.length + audit.interfaceOnlyComponents.length;
|
|
2364
|
+
const moduleCount = audit.modules.length;
|
|
2365
|
+
const expectedCount = input.kind === "components"
|
|
2366
|
+
? componentCount
|
|
2367
|
+
: input.kind === "modules"
|
|
2368
|
+
? moduleCount
|
|
2369
|
+
: componentCount + moduleCount;
|
|
2370
|
+
if (expectedCount === 0) {
|
|
2371
|
+
throw new TypeError(`Selected Solid Codegen dependency ${input.packageName} declares a ${input.kind} config but its ${input.sourcePath} source exposes no matching Codegen surface. The package may contain a stale codegenConfig or a legacy native module rather than a generated binding.`);
|
|
2372
|
+
}
|
|
2373
|
+
}
|
|
2374
|
+
async function createSolidBindingGeneration(application, options, dependencies) {
|
|
2375
|
+
if (options.generateSolidBindings === false &&
|
|
2376
|
+
(options.solidOutputPath !== undefined ||
|
|
2377
|
+
(options.solidLibraries?.length ?? 0) > 0)) {
|
|
2378
|
+
throw new TypeError("solidOutputPath and solidLibraries cannot be combined with disabled Solid binding generation.");
|
|
2379
|
+
}
|
|
2380
|
+
if (options.generateSolidBindings === false)
|
|
2381
|
+
return undefined;
|
|
2382
|
+
const inputs = [];
|
|
2383
|
+
const config = application.manifest.codegenConfig;
|
|
2384
|
+
if (config !== undefined) {
|
|
2385
|
+
const type = config.type;
|
|
2386
|
+
if (type === "components" || type === "modules" || type === "all") {
|
|
2387
|
+
inputs.push(await createSolidBindingInput(application.manifest.name ?? "application", application.manifest.version, application.projectRoot, config, "application", dependencies));
|
|
2388
|
+
}
|
|
2389
|
+
}
|
|
2390
|
+
const requestedLibraries = options.solidLibraries ?? [];
|
|
2391
|
+
if (!Array.isArray(requestedLibraries)) {
|
|
2392
|
+
throw new TypeError("solidLibraries must be an array of package names.");
|
|
2393
|
+
}
|
|
2394
|
+
const uniqueLibraries = new Set();
|
|
2395
|
+
for (const packageName of requestedLibraries) {
|
|
2396
|
+
if (typeof packageName !== "string" ||
|
|
2397
|
+
!SOLID_BINDING_PACKAGE_NAME.test(packageName)) {
|
|
2398
|
+
throw new TypeError(`Invalid Solid Codegen dependency package name ${JSON.stringify(packageName)}.`);
|
|
2399
|
+
}
|
|
2400
|
+
if (uniqueLibraries.has(packageName)) {
|
|
2401
|
+
throw new TypeError(`Solid Codegen dependency ${packageName} was requested more than once.`);
|
|
2402
|
+
}
|
|
2403
|
+
uniqueLibraries.add(packageName);
|
|
2404
|
+
if (declaredVersion(application.manifest, packageName) === undefined) {
|
|
2405
|
+
throw new TypeError(`Solid Codegen dependency ${packageName} must be declared in the application package.json.`);
|
|
2406
|
+
}
|
|
2407
|
+
const installed = await findInstalledPackageManifest(application.projectRoot, packageName, dependencies);
|
|
2408
|
+
if (installed === undefined) {
|
|
2409
|
+
throw new TypeError(`Solid Codegen dependency ${packageName} is not installed.`);
|
|
2410
|
+
}
|
|
2411
|
+
if (installed.manifest.name !== packageName) {
|
|
2412
|
+
throw new TypeError(`Installed Solid Codegen dependency ${packageName} has package name ${String(installed.manifest.name)}.`);
|
|
2413
|
+
}
|
|
2414
|
+
if (installed.manifest.codegenConfig === undefined) {
|
|
2415
|
+
throw new TypeError(`Solid Codegen dependency ${packageName} does not declare codegenConfig.`);
|
|
2416
|
+
}
|
|
2417
|
+
const input = await createSolidBindingInput(packageName, installed.manifest.version, path.dirname(installed.path), installed.manifest.codegenConfig, "dependency", dependencies);
|
|
2418
|
+
assertSelectedSolidBindingInput(input);
|
|
2419
|
+
inputs.push(input);
|
|
2420
|
+
}
|
|
2421
|
+
if (inputs.length === 0) {
|
|
2422
|
+
if (options.solidOutputPath !== undefined) {
|
|
2423
|
+
throw new TypeError("solidOutputPath requires an application or requested dependency Codegen config.");
|
|
2424
|
+
}
|
|
2425
|
+
return undefined;
|
|
2426
|
+
}
|
|
2427
|
+
const outputPath = path.resolve(application.projectRoot, options.solidOutputPath ??
|
|
2428
|
+
path.join("generated", inputs.length === 1
|
|
2429
|
+
? `${inputs[0].libraryName}.ts`
|
|
2430
|
+
: "SolidNativeBindings.ts"));
|
|
2431
|
+
if (!pathContains(application.projectRoot, outputPath) ||
|
|
2432
|
+
outputPath === application.projectRoot ||
|
|
2433
|
+
path.extname(outputPath) !== ".ts") {
|
|
2434
|
+
throw new TypeError("The Solid binding output must be a .ts file inside the application root.");
|
|
2435
|
+
}
|
|
2436
|
+
await requirePhysicalOutputContainment(application.projectRoot, outputPath, "The Solid binding output", dependencies);
|
|
2437
|
+
return {
|
|
2438
|
+
kind: combinedSolidBindingKind(inputs),
|
|
2439
|
+
inputs: Object.freeze(inputs),
|
|
2440
|
+
outputPath,
|
|
2441
|
+
};
|
|
2442
|
+
}
|
|
2443
|
+
export async function createNativeGeneratePlan(options = {}) {
|
|
2444
|
+
const dependencies = fileDependencies(options.dependencies);
|
|
2445
|
+
const application = await resolveNativeApplication(options.cwd, dependencies);
|
|
2446
|
+
const platform = options.platform ?? "all";
|
|
2447
|
+
const requiredPlatforms = platform === "all" ? ["ios", "android"] : [platform];
|
|
2448
|
+
for (const requiredPlatform of requiredPlatforms) {
|
|
2449
|
+
await requireNativeDirectory(application.projectRoot, requiredPlatform, dependencies.pathExists);
|
|
2450
|
+
}
|
|
2451
|
+
const source = options.source ?? "app";
|
|
2452
|
+
const outputPath = path.resolve(application.projectRoot, options.outputPath ?? path.join("build", "solid-native-codegen"));
|
|
2453
|
+
if (!pathContains(application.projectRoot, outputPath) ||
|
|
2454
|
+
outputPath === application.projectRoot) {
|
|
2455
|
+
throw new TypeError("The native Codegen output must be a directory inside the application root.");
|
|
2456
|
+
}
|
|
2457
|
+
await requirePhysicalOutputContainment(application.projectRoot, outputPath, "The native Codegen output", dependencies);
|
|
2458
|
+
const solidBindings = await createSolidBindingGeneration(application, options, dependencies);
|
|
2459
|
+
if (solidBindings !== undefined &&
|
|
2460
|
+
(pathContains(outputPath, solidBindings.outputPath) ||
|
|
2461
|
+
pathContains(solidBindings.outputPath, outputPath))) {
|
|
2462
|
+
throw new TypeError("The native Codegen output and Solid binding output must not overlap.");
|
|
2463
|
+
}
|
|
2464
|
+
return {
|
|
2465
|
+
schemaVersion: 0,
|
|
2466
|
+
operation: "generate",
|
|
2467
|
+
platform,
|
|
2468
|
+
source,
|
|
2469
|
+
projectRoot: application.projectRoot,
|
|
2470
|
+
command: process.execPath,
|
|
2471
|
+
args: [
|
|
2472
|
+
application.reactNativeCli,
|
|
2473
|
+
"codegen",
|
|
2474
|
+
"--path",
|
|
2475
|
+
application.projectRoot,
|
|
2476
|
+
"--platform",
|
|
2477
|
+
platform,
|
|
2478
|
+
"--source",
|
|
2479
|
+
source,
|
|
2480
|
+
"--outputPath",
|
|
2481
|
+
outputPath,
|
|
2482
|
+
...(options.verbose === true ? ["--verbose"] : []),
|
|
2483
|
+
],
|
|
2484
|
+
outputPath,
|
|
2485
|
+
...(solidBindings === undefined ? {} : { solidBindings }),
|
|
2486
|
+
};
|
|
2487
|
+
}
|
|
2488
|
+
export const defaultNativeGenerateExecutor = spawnNativeProcess;
|
|
2489
|
+
/** Deterministically renders the Solid-facing half of an inspected plan. */
|
|
2490
|
+
export function generateNativeSolidBindingSource(generation) {
|
|
2491
|
+
if (generation.inputs.length === 0) {
|
|
2492
|
+
throw new TypeError("Solid binding generation requires at least one input.");
|
|
2493
|
+
}
|
|
2494
|
+
const schema = combineReactNativeCodegenSchemas(generation.inputs.map((input) => input.sourcePath), {
|
|
2495
|
+
libraryName: generation.inputs.length === 1
|
|
2496
|
+
? generation.inputs[0].libraryName
|
|
2497
|
+
: "SolidNativeBindings",
|
|
2498
|
+
});
|
|
2499
|
+
const bindingSource = generation.kind === "components"
|
|
2500
|
+
? generateSolidNativeComponentModule(schema)
|
|
2501
|
+
: generation.kind === "modules"
|
|
2502
|
+
? generateSolidNativeTurboModuleBindings(schema)
|
|
2503
|
+
: generateSolidNativeBindingsModule(schema);
|
|
2504
|
+
const inputs = generation.inputs.map((input) => ({
|
|
2505
|
+
origin: input.origin,
|
|
2506
|
+
kind: input.kind,
|
|
2507
|
+
libraryName: input.libraryName,
|
|
2508
|
+
packageName: input.packageName,
|
|
2509
|
+
...(input.packageVersion === undefined
|
|
2510
|
+
? {}
|
|
2511
|
+
: { packageVersion: input.packageVersion }),
|
|
2512
|
+
}));
|
|
2513
|
+
const bindingSha256 = createHash("sha256")
|
|
2514
|
+
.update(JSON.stringify({
|
|
2515
|
+
schemaVersion: 0,
|
|
2516
|
+
inputs,
|
|
2517
|
+
source: bindingSource,
|
|
2518
|
+
}))
|
|
2519
|
+
.digest("hex");
|
|
2520
|
+
return [
|
|
2521
|
+
bindingSource.trimEnd(),
|
|
2522
|
+
"",
|
|
2523
|
+
"export const SOLID_NATIVE_BINDING_MANIFEST = Object.freeze({",
|
|
2524
|
+
" schemaVersion: 0 as const,",
|
|
2525
|
+
` bindingSha256: ${JSON.stringify(bindingSha256)},`,
|
|
2526
|
+
" inputs: Object.freeze([",
|
|
2527
|
+
...inputs.map((input) => ` Object.freeze(${JSON.stringify(input)}),`),
|
|
2528
|
+
" ]),",
|
|
2529
|
+
"});",
|
|
2530
|
+
"",
|
|
2531
|
+
].join("\n");
|
|
2532
|
+
}
|
|
2533
|
+
/** Checks a generated module without invoking or mutating native Codegen. */
|
|
2534
|
+
export async function checkNativeSolidBindingGeneration(generation, options = {}) {
|
|
2535
|
+
const expected = generateNativeSolidBindingSource(generation);
|
|
2536
|
+
let actual;
|
|
2537
|
+
try {
|
|
2538
|
+
actual = await (options.readTextFile ?? ((target) => readFile(target, "utf8")))(generation.outputPath);
|
|
2539
|
+
}
|
|
2540
|
+
catch (error) {
|
|
2541
|
+
return {
|
|
2542
|
+
schemaVersion: 0,
|
|
2543
|
+
ok: false,
|
|
2544
|
+
outputPath: generation.outputPath,
|
|
2545
|
+
status: error?.code === "ENOENT"
|
|
2546
|
+
? "missing"
|
|
2547
|
+
: "unreadable",
|
|
2548
|
+
};
|
|
2549
|
+
}
|
|
2550
|
+
const ok = actual === expected;
|
|
2551
|
+
return {
|
|
2552
|
+
schemaVersion: 0,
|
|
2553
|
+
ok,
|
|
2554
|
+
outputPath: generation.outputPath,
|
|
2555
|
+
status: ok ? "match" : "stale",
|
|
2556
|
+
};
|
|
2557
|
+
}
|
|
2558
|
+
/** Builds a path-free compatibility inventory without evaluating wrappers. */
|
|
2559
|
+
export function createNativeSolidBindingAudit(generation, options = {}) {
|
|
2560
|
+
if (generation.inputs.length === 0) {
|
|
2561
|
+
throw new TypeError("Solid binding audit requires at least one input.");
|
|
2562
|
+
}
|
|
2563
|
+
const platform = options.platform === undefined || options.platform === "all"
|
|
2564
|
+
? undefined
|
|
2565
|
+
: options.platform;
|
|
2566
|
+
const schema = combineReactNativeCodegenSchemas(generation.inputs.map((input) => input.sourcePath), {
|
|
2567
|
+
libraryName: generation.inputs.length === 1
|
|
2568
|
+
? generation.inputs[0].libraryName
|
|
2569
|
+
: "SolidNativeBindings",
|
|
2570
|
+
...(platform === undefined ? {} : { platform }),
|
|
2571
|
+
});
|
|
2572
|
+
const audit = createSolidNativeSchemaAudit(schema, {
|
|
2573
|
+
...(platform === undefined ? {} : { platform }),
|
|
2574
|
+
});
|
|
2575
|
+
const inputs = generation.inputs.map((input) => Object.freeze({
|
|
2576
|
+
origin: input.origin,
|
|
2577
|
+
kind: input.kind,
|
|
2578
|
+
libraryName: input.libraryName,
|
|
2579
|
+
packageName: input.packageName,
|
|
2580
|
+
...(input.packageVersion === undefined
|
|
2581
|
+
? {}
|
|
2582
|
+
: { packageVersion: input.packageVersion }),
|
|
2583
|
+
}));
|
|
2584
|
+
return Object.freeze({
|
|
2585
|
+
...audit,
|
|
2586
|
+
inputs: Object.freeze(inputs),
|
|
2587
|
+
});
|
|
2588
|
+
}
|
|
2589
|
+
/** Re-audits exact installed schemas against an application-owned catalog. */
|
|
2590
|
+
export async function checkNativeCompatibilityCatalog(options = {}) {
|
|
2591
|
+
const dependencies = fileDependencies(options.dependencies);
|
|
2592
|
+
const application = await resolveNativeApplication(options.cwd, dependencies);
|
|
2593
|
+
const catalogPath = path.resolve(application.projectRoot, options.catalogPath ?? "solid-native.compatibility.json");
|
|
2594
|
+
if (!pathContains(application.projectRoot, catalogPath) ||
|
|
2595
|
+
catalogPath === application.projectRoot) {
|
|
2596
|
+
throw new TypeError("The compatibility catalog must be a file inside the application root.");
|
|
2597
|
+
}
|
|
2598
|
+
await requirePhysicalOutputContainment(application.projectRoot, catalogPath, "The compatibility catalog", dependencies);
|
|
2599
|
+
const catalog = parseNativeCompatibilityCatalog(await dependencies.readTextFile(catalogPath));
|
|
2600
|
+
const platform = options.platform ?? "all";
|
|
2601
|
+
const plan = await createNativeGeneratePlan({
|
|
2602
|
+
cwd: application.projectRoot,
|
|
2603
|
+
platform,
|
|
2604
|
+
solidLibraries: catalog.packages.map((entry) => entry.packageName),
|
|
2605
|
+
dependencies,
|
|
2606
|
+
});
|
|
2607
|
+
if (plan.solidBindings === undefined) {
|
|
2608
|
+
throw new TypeError("The compatibility catalog requires at least one Codegen input.");
|
|
2609
|
+
}
|
|
2610
|
+
const platforms = platform === "all" ? ["android", "ios"] : [platform];
|
|
2611
|
+
const packageAudits = catalog.packages.map((entry) => {
|
|
2612
|
+
const input = plan.solidBindings.inputs.find((candidate) => candidate.origin === "dependency" &&
|
|
2613
|
+
candidate.packageName === entry.packageName);
|
|
2614
|
+
if (input === undefined) {
|
|
2615
|
+
throw new TypeError(`No dependency Codegen input was discovered for ${entry.packageName}.`);
|
|
2616
|
+
}
|
|
2617
|
+
const generation = {
|
|
2618
|
+
kind: input.kind,
|
|
2619
|
+
inputs: Object.freeze([input]),
|
|
2620
|
+
outputPath: plan.solidBindings.outputPath,
|
|
2621
|
+
};
|
|
2622
|
+
const audits = {};
|
|
2623
|
+
for (const target of platforms) {
|
|
2624
|
+
audits[target] = createNativeSolidBindingAudit(generation, {
|
|
2625
|
+
platform: target,
|
|
2626
|
+
});
|
|
2627
|
+
}
|
|
2628
|
+
return Object.freeze({
|
|
2629
|
+
packageName: entry.packageName,
|
|
2630
|
+
audits: Object.freeze(audits),
|
|
2631
|
+
});
|
|
2632
|
+
});
|
|
2633
|
+
const catalogFile = path
|
|
2634
|
+
.relative(application.projectRoot, catalogPath)
|
|
2635
|
+
.split(path.sep)
|
|
2636
|
+
.join("/");
|
|
2637
|
+
const evidenceDigests = new Map();
|
|
2638
|
+
return verifyNativeCompatibilityCatalog(catalog, {
|
|
2639
|
+
catalogFile,
|
|
2640
|
+
platform,
|
|
2641
|
+
packageAudits: Object.freeze(packageAudits),
|
|
2642
|
+
evidenceSha256(reference) {
|
|
2643
|
+
const existing = evidenceDigests.get(reference);
|
|
2644
|
+
if (existing !== undefined)
|
|
2645
|
+
return existing;
|
|
2646
|
+
const digest = (async () => {
|
|
2647
|
+
const target = path.resolve(application.projectRoot, reference);
|
|
2648
|
+
if (!pathContains(application.projectRoot, target))
|
|
2649
|
+
return undefined;
|
|
2650
|
+
try {
|
|
2651
|
+
await requirePhysicalOutputContainment(application.projectRoot, target, "Compatibility evidence", dependencies);
|
|
2652
|
+
}
|
|
2653
|
+
catch {
|
|
2654
|
+
return undefined;
|
|
2655
|
+
}
|
|
2656
|
+
if (!(await dependencies.pathExists(target)))
|
|
2657
|
+
return undefined;
|
|
2658
|
+
try {
|
|
2659
|
+
if (!(await stat(target)).isFile())
|
|
2660
|
+
return undefined;
|
|
2661
|
+
return createHash("sha256")
|
|
2662
|
+
.update(await readFile(target))
|
|
2663
|
+
.digest("hex");
|
|
2664
|
+
}
|
|
2665
|
+
catch {
|
|
2666
|
+
return undefined;
|
|
2667
|
+
}
|
|
2668
|
+
})();
|
|
2669
|
+
evidenceDigests.set(reference, digest);
|
|
2670
|
+
return digest;
|
|
2671
|
+
},
|
|
2672
|
+
});
|
|
2673
|
+
}
|
|
2674
|
+
/** Hashes contained application files into ready-to-review catalog entries. */
|
|
2675
|
+
export async function createNativeCompatibilityEvidenceReport(options) {
|
|
2676
|
+
if (typeof options !== "object" ||
|
|
2677
|
+
options === null ||
|
|
2678
|
+
!Array.isArray(options.paths) ||
|
|
2679
|
+
options.paths.length === 0 ||
|
|
2680
|
+
options.paths.length > 16) {
|
|
2681
|
+
throw new TypeError("Compatibility evidence requires 1-16 file paths.");
|
|
2682
|
+
}
|
|
2683
|
+
const dependencies = fileDependencies(options.dependencies);
|
|
2684
|
+
const application = await resolveNativeApplication(options.cwd, dependencies);
|
|
2685
|
+
const evidence = [];
|
|
2686
|
+
const seen = new Set();
|
|
2687
|
+
for (const reference of options.paths) {
|
|
2688
|
+
if (typeof reference !== "string" ||
|
|
2689
|
+
reference.length === 0 ||
|
|
2690
|
+
reference.length > 512 ||
|
|
2691
|
+
/[\0\r\n]/u.test(reference)) {
|
|
2692
|
+
throw new TypeError("Compatibility evidence paths must be 1-512 character strings without control lines.");
|
|
2693
|
+
}
|
|
2694
|
+
const target = path.resolve(application.projectRoot, reference);
|
|
2695
|
+
if (!pathContains(application.projectRoot, target) ||
|
|
2696
|
+
target === application.projectRoot) {
|
|
2697
|
+
throw new TypeError(`Compatibility evidence must be a file inside the application root: ${reference}.`);
|
|
2698
|
+
}
|
|
2699
|
+
await requirePhysicalOutputContainment(application.projectRoot, target, "Compatibility evidence", dependencies);
|
|
2700
|
+
if (!(await dependencies.pathExists(target))) {
|
|
2701
|
+
throw new TypeError(`Compatibility evidence does not exist: ${reference}.`);
|
|
2702
|
+
}
|
|
2703
|
+
if (!(await stat(target)).isFile()) {
|
|
2704
|
+
throw new TypeError(`Compatibility evidence is not a file: ${reference}.`);
|
|
2705
|
+
}
|
|
2706
|
+
const portablePath = path
|
|
2707
|
+
.relative(application.projectRoot, target)
|
|
2708
|
+
.split(path.sep)
|
|
2709
|
+
.join("/");
|
|
2710
|
+
const entry = parseNativeCompatibilityEvidence({
|
|
2711
|
+
path: portablePath,
|
|
2712
|
+
sha256: createHash("sha256")
|
|
2713
|
+
.update(await readFile(target))
|
|
2714
|
+
.digest("hex"),
|
|
2715
|
+
});
|
|
2716
|
+
if (seen.has(entry.path)) {
|
|
2717
|
+
throw new TypeError(`Compatibility evidence path was requested more than once: ${entry.path}.`);
|
|
2718
|
+
}
|
|
2719
|
+
seen.add(entry.path);
|
|
2720
|
+
evidence.push(entry);
|
|
2721
|
+
}
|
|
2722
|
+
return Object.freeze({
|
|
2723
|
+
schemaVersion: 0,
|
|
2724
|
+
projectRoot: application.projectRoot,
|
|
2725
|
+
evidence: Object.freeze(evidence),
|
|
2726
|
+
});
|
|
2727
|
+
}
|
|
2728
|
+
function nativeAdapterBindingsImport(adapterOutputPath, bindingsOutputPath) {
|
|
2729
|
+
let relative = path
|
|
2730
|
+
.relative(path.dirname(adapterOutputPath), bindingsOutputPath)
|
|
2731
|
+
.split(path.sep)
|
|
2732
|
+
.join("/");
|
|
2733
|
+
relative = relative.slice(0, -path.extname(relative).length);
|
|
2734
|
+
return relative.startsWith(".") ? relative : `./${relative}`;
|
|
2735
|
+
}
|
|
2736
|
+
/** Plans one editable policy-gated adapter without writing application files. */
|
|
2737
|
+
export async function createNativeAdapterScaffoldPlan(options) {
|
|
2738
|
+
if (typeof options !== "object" || options === null) {
|
|
2739
|
+
throw new TypeError("Native adapter scaffold options must be an object.");
|
|
2740
|
+
}
|
|
2741
|
+
const dependencies = fileDependencies(options.dependencies);
|
|
2742
|
+
const platform = options.platform ?? "all";
|
|
2743
|
+
const generationPlan = await createNativeGeneratePlan({
|
|
2744
|
+
platform,
|
|
2745
|
+
solidLibraries: [options.packageName],
|
|
2746
|
+
...(options.cwd === undefined ? {} : { cwd: options.cwd }),
|
|
2747
|
+
...(options.bindingsPath === undefined
|
|
2748
|
+
? {}
|
|
2749
|
+
: { solidOutputPath: options.bindingsPath }),
|
|
2750
|
+
dependencies,
|
|
2751
|
+
});
|
|
2752
|
+
const bindingGeneration = generationPlan.solidBindings;
|
|
2753
|
+
if (bindingGeneration === undefined) {
|
|
2754
|
+
throw new TypeError("Native adapter scaffolding requires a dependency Codegen input.");
|
|
2755
|
+
}
|
|
2756
|
+
const input = bindingGeneration.inputs.find((candidate) => candidate.origin === "dependency" &&
|
|
2757
|
+
candidate.packageName === options.packageName);
|
|
2758
|
+
if (input === undefined) {
|
|
2759
|
+
throw new TypeError(`No dependency Codegen input was discovered for ${options.packageName}.`);
|
|
2760
|
+
}
|
|
2761
|
+
if (input.kind === "components") {
|
|
2762
|
+
throw new TypeError(`Solid adapter scaffolding requires a TurboModule schema; ${options.packageName} declares components only.`);
|
|
2763
|
+
}
|
|
2764
|
+
const outputPath = path.resolve(generationPlan.projectRoot, options.outputPath ?? path.join("adapters", `${options.moduleName}.ts`));
|
|
2765
|
+
if (!pathContains(generationPlan.projectRoot, outputPath) ||
|
|
2766
|
+
outputPath === generationPlan.projectRoot ||
|
|
2767
|
+
path.extname(outputPath) !== ".ts") {
|
|
2768
|
+
throw new TypeError("The native adapter scaffold output must be a .ts file inside the application root.");
|
|
2769
|
+
}
|
|
2770
|
+
await requirePhysicalOutputContainment(generationPlan.projectRoot, outputPath, "The native adapter scaffold output", dependencies);
|
|
2771
|
+
if (outputPath === bindingGeneration.outputPath) {
|
|
2772
|
+
throw new TypeError("The native adapter scaffold output must differ from its generated binding module.");
|
|
2773
|
+
}
|
|
2774
|
+
const bindingsImport = nativeAdapterBindingsImport(outputPath, bindingGeneration.outputPath);
|
|
2775
|
+
const schema = combineReactNativeCodegenSchemas([input.sourcePath], {
|
|
2776
|
+
libraryName: input.libraryName,
|
|
2777
|
+
...(platform === "all" ? {} : { platform }),
|
|
2778
|
+
});
|
|
2779
|
+
const source = generateSolidNativeTurboModuleAdapterScaffold(schema, {
|
|
2780
|
+
moduleName: options.moduleName,
|
|
2781
|
+
bindingsImport,
|
|
2782
|
+
...(platform === "all" ? {} : { platform }),
|
|
2783
|
+
});
|
|
2784
|
+
return {
|
|
2785
|
+
schemaVersion: 0,
|
|
2786
|
+
operation: "adapter-create",
|
|
2787
|
+
platform,
|
|
2788
|
+
projectRoot: generationPlan.projectRoot,
|
|
2789
|
+
packageName: input.packageName,
|
|
2790
|
+
...(input.packageVersion === undefined
|
|
2791
|
+
? {}
|
|
2792
|
+
: { packageVersion: input.packageVersion }),
|
|
2793
|
+
libraryName: input.libraryName,
|
|
2794
|
+
moduleName: options.moduleName,
|
|
2795
|
+
outputPath,
|
|
2796
|
+
bindingsImport,
|
|
2797
|
+
bindingGeneration,
|
|
2798
|
+
source,
|
|
2799
|
+
};
|
|
2800
|
+
}
|
|
2801
|
+
/** Creates a scaffold exactly once after verifying its generated ABI input. */
|
|
2802
|
+
export async function executeNativeAdapterScaffoldPlan(plan) {
|
|
2803
|
+
const binding = await checkNativeSolidBindingGeneration(plan.bindingGeneration);
|
|
2804
|
+
if (!binding.ok) {
|
|
2805
|
+
throw new TypeError(`Generated Solid bindings are ${binding.status}; run solid-native generate --solid-library ${plan.packageName} before scaffolding its adapter.`);
|
|
2806
|
+
}
|
|
2807
|
+
await mkdir(path.dirname(plan.outputPath), { recursive: true });
|
|
2808
|
+
const temporaryPath = `${plan.outputPath}.solid-native-${randomUUID()}.tmp`;
|
|
2809
|
+
try {
|
|
2810
|
+
await writeFile(temporaryPath, plan.source, {
|
|
2811
|
+
encoding: "utf8",
|
|
2812
|
+
flag: "wx",
|
|
2813
|
+
mode: 0o644,
|
|
2814
|
+
});
|
|
2815
|
+
await link(temporaryPath, plan.outputPath);
|
|
2816
|
+
}
|
|
2817
|
+
catch (error) {
|
|
2818
|
+
if (error?.code === "EEXIST") {
|
|
2819
|
+
throw new TypeError(`Native adapter scaffold already exists at ${plan.outputPath}; refusing to overwrite application-owned policy code.`);
|
|
2820
|
+
}
|
|
2821
|
+
throw error;
|
|
2822
|
+
}
|
|
2823
|
+
finally {
|
|
2824
|
+
await rm(temporaryPath, { force: true });
|
|
2825
|
+
}
|
|
2826
|
+
}
|
|
2827
|
+
function nativeGenerateStagingPlan(plan, outputPath) {
|
|
2828
|
+
const flagIndex = plan.args.lastIndexOf("--outputPath");
|
|
2829
|
+
if (flagIndex < 0 ||
|
|
2830
|
+
flagIndex + 1 >= plan.args.length ||
|
|
2831
|
+
plan.args[flagIndex + 1] !== plan.outputPath) {
|
|
2832
|
+
throw new TypeError("Native Codegen plan output does not match its command arguments.");
|
|
2833
|
+
}
|
|
2834
|
+
const args = [...plan.args];
|
|
2835
|
+
args[flagIndex + 1] = outputPath;
|
|
2836
|
+
return {
|
|
2837
|
+
...plan,
|
|
2838
|
+
args: Object.freeze(args),
|
|
2839
|
+
outputPath,
|
|
2840
|
+
};
|
|
2841
|
+
}
|
|
2842
|
+
async function onDisk(target) {
|
|
2843
|
+
try {
|
|
2844
|
+
await access(target);
|
|
2845
|
+
return true;
|
|
2846
|
+
}
|
|
2847
|
+
catch (error) {
|
|
2848
|
+
if (error?.code === "ENOENT") {
|
|
2849
|
+
return false;
|
|
2850
|
+
}
|
|
2851
|
+
throw error;
|
|
2852
|
+
}
|
|
2853
|
+
}
|
|
2854
|
+
async function publishNativeGenerateOutputs(outputs) {
|
|
2855
|
+
const backedUp = new Set();
|
|
2856
|
+
const published = new Set();
|
|
2857
|
+
try {
|
|
2858
|
+
for (const output of outputs) {
|
|
2859
|
+
if (await onDisk(output.finalPath)) {
|
|
2860
|
+
await rename(output.finalPath, output.backupPath);
|
|
2861
|
+
backedUp.add(output.finalPath);
|
|
2862
|
+
}
|
|
2863
|
+
}
|
|
2864
|
+
for (const output of outputs) {
|
|
2865
|
+
await rename(output.stagedPath, output.finalPath);
|
|
2866
|
+
published.add(output.finalPath);
|
|
2867
|
+
}
|
|
2868
|
+
}
|
|
2869
|
+
catch (error) {
|
|
2870
|
+
const rollbackErrors = [];
|
|
2871
|
+
for (const output of [...outputs].reverse()) {
|
|
2872
|
+
try {
|
|
2873
|
+
if (published.has(output.finalPath)) {
|
|
2874
|
+
await rm(output.finalPath, { force: true, recursive: true });
|
|
2875
|
+
}
|
|
2876
|
+
if (backedUp.has(output.finalPath)) {
|
|
2877
|
+
await rename(output.backupPath, output.finalPath);
|
|
2878
|
+
}
|
|
2879
|
+
}
|
|
2880
|
+
catch (rollbackError) {
|
|
2881
|
+
rollbackErrors.push(rollbackError);
|
|
2882
|
+
}
|
|
2883
|
+
}
|
|
2884
|
+
if (rollbackErrors.length > 0) {
|
|
2885
|
+
throw new AggregateError([error, ...rollbackErrors], "Native Codegen output publication failed and could not be fully rolled back.");
|
|
2886
|
+
}
|
|
2887
|
+
throw error;
|
|
2888
|
+
}
|
|
2889
|
+
for (const output of outputs) {
|
|
2890
|
+
if (backedUp.has(output.finalPath)) {
|
|
2891
|
+
await rm(output.backupPath, { force: true, recursive: true });
|
|
2892
|
+
}
|
|
2893
|
+
}
|
|
2894
|
+
}
|
|
2895
|
+
export async function executeNativeGeneratePlan(plan, options = {}) {
|
|
2896
|
+
const transactionId = randomUUID();
|
|
2897
|
+
const nativeOutput = {
|
|
2898
|
+
finalPath: plan.outputPath,
|
|
2899
|
+
stagedPath: `${plan.outputPath}.solid-native-${transactionId}.tmp`,
|
|
2900
|
+
backupPath: `${plan.outputPath}.solid-native-${transactionId}.bak`,
|
|
2901
|
+
};
|
|
2902
|
+
const solidOutput = plan.solidBindings === undefined
|
|
2903
|
+
? undefined
|
|
2904
|
+
: {
|
|
2905
|
+
finalPath: plan.solidBindings.outputPath,
|
|
2906
|
+
stagedPath: `${plan.solidBindings.outputPath}.solid-native-${transactionId}.tmp`,
|
|
2907
|
+
backupPath: `${plan.solidBindings.outputPath}.solid-native-${transactionId}.bak`,
|
|
2908
|
+
};
|
|
2909
|
+
const outputs = solidOutput === undefined ? [nativeOutput] : [nativeOutput, solidOutput];
|
|
2910
|
+
await Promise.all(outputs.map((output) => mkdir(path.dirname(output.stagedPath), { recursive: true })));
|
|
2911
|
+
try {
|
|
2912
|
+
if (solidOutput !== undefined && plan.solidBindings !== undefined) {
|
|
2913
|
+
await writeFile(solidOutput.stagedPath, generateNativeSolidBindingSource(plan.solidBindings), { encoding: "utf8", mode: 0o644 });
|
|
2914
|
+
}
|
|
2915
|
+
const exitCode = await (options.executor ?? defaultNativeGenerateExecutor)(nativeGenerateStagingPlan(plan, nativeOutput.stagedPath), {
|
|
2916
|
+
env: options.env ?? process.env,
|
|
2917
|
+
});
|
|
2918
|
+
if (exitCode !== 0)
|
|
2919
|
+
return exitCode;
|
|
2920
|
+
// An application without a Codegen schema can legitimately produce no
|
|
2921
|
+
// directory. Publishing an empty one still removes any prior stale tree.
|
|
2922
|
+
await mkdir(nativeOutput.stagedPath, { recursive: true });
|
|
2923
|
+
await publishNativeGenerateOutputs(outputs);
|
|
2924
|
+
return 0;
|
|
2925
|
+
}
|
|
2926
|
+
finally {
|
|
2927
|
+
await Promise.all(outputs.map((output) => rm(output.stagedPath, { force: true, recursive: true })));
|
|
2928
|
+
}
|
|
2929
|
+
}
|
|
2930
|
+
function quoteArgument(argument) {
|
|
2931
|
+
return /^[A-Za-z0-9_./:@%+=,-]+$/u.test(argument)
|
|
2932
|
+
? argument
|
|
2933
|
+
: `'${argument.replaceAll("'", `'\\''`)}'`;
|
|
2934
|
+
}
|
|
2935
|
+
export function formatNativeRunPlan(plan) {
|
|
2936
|
+
const environment = Object.entries(plan.environmentDefaults ?? {}).map(([name, value]) => `${name}=${quoteArgument(value)}`);
|
|
2937
|
+
const command = [plan.command, ...plan.args].map(quoteArgument);
|
|
2938
|
+
return [...environment, ...command].join(" ");
|
|
2939
|
+
}
|
|
2940
|
+
export function formatNativeBuildPlan(plan) {
|
|
2941
|
+
const environment = Object.entries(plan.environmentDefaults ?? {}).map(([name, value]) => `${name}=${quoteArgument(value)}`);
|
|
2942
|
+
const command = [plan.command, ...plan.args].map(quoteArgument);
|
|
2943
|
+
return [...environment, ...command].join(" ");
|
|
2944
|
+
}
|
|
2945
|
+
export function formatNativeBundlePlan(plan) {
|
|
2946
|
+
return [plan.command, ...plan.args].map(quoteArgument).join(" ");
|
|
2947
|
+
}
|
|
2948
|
+
export function formatNativeStartPlan(plan) {
|
|
2949
|
+
return [plan.command, ...plan.args].map(quoteArgument).join(" ");
|
|
2950
|
+
}
|
|
2951
|
+
export function formatNativeCreatePlan(plan) {
|
|
2952
|
+
const scaffold = [plan.command, ...plan.args].map(quoteArgument).join(" ");
|
|
2953
|
+
if (plan.installCommand === undefined)
|
|
2954
|
+
return scaffold;
|
|
2955
|
+
const install = [plan.installCommand.command, ...plan.installCommand.args]
|
|
2956
|
+
.map(quoteArgument)
|
|
2957
|
+
.join(" ");
|
|
2958
|
+
return `${scaffold}\nThen in ${quoteArgument(plan.targetDirectory)}: ${install}`;
|
|
2959
|
+
}
|
|
2960
|
+
export function formatNativeCreateSuccess(plan) {
|
|
2961
|
+
return [
|
|
2962
|
+
`Created ${plan.projectName} at ${plan.targetDirectory}.`,
|
|
2963
|
+
"",
|
|
2964
|
+
"Next:",
|
|
2965
|
+
` cd ${quoteArgument(plan.targetDirectory)}`,
|
|
2966
|
+
...(plan.installCommand === undefined ? [" pnpm install"] : []),
|
|
2967
|
+
" pnpm run doctor",
|
|
2968
|
+
" pnpm start",
|
|
2969
|
+
].join("\n");
|
|
2970
|
+
}
|
|
2971
|
+
export function formatNativeGeneratePlan(plan) {
|
|
2972
|
+
return [plan.command, ...plan.args].map(quoteArgument).join(" ");
|
|
2973
|
+
}
|
|
2974
|
+
export function formatDoctorReport(report) {
|
|
2975
|
+
const symbols = {
|
|
2976
|
+
pass: "✓",
|
|
2977
|
+
warn: "!",
|
|
2978
|
+
fail: "✗",
|
|
2979
|
+
skip: "–",
|
|
2980
|
+
};
|
|
2981
|
+
const lines = [
|
|
2982
|
+
"Solid Native doctor",
|
|
2983
|
+
`Project: ${report.projectRoot}`,
|
|
2984
|
+
"",
|
|
2985
|
+
...report.checks.flatMap((entry) => [
|
|
2986
|
+
`${symbols[entry.status]} ${entry.label}: ${entry.message}`,
|
|
2987
|
+
...(entry.remediation === undefined
|
|
2988
|
+
? []
|
|
2989
|
+
: [` Fix: ${entry.remediation}`]),
|
|
2990
|
+
]),
|
|
2991
|
+
"",
|
|
2992
|
+
`${report.ok ? "Ready" : "Not ready"}: ${report.summary.pass} passed, ${report.summary.warn} ${report.summary.warn === 1 ? "warning" : "warnings"}, ${report.summary.fail} failed, ${report.summary.skip} skipped.`,
|
|
2993
|
+
];
|
|
2994
|
+
return lines.join("\n");
|
|
2995
|
+
}
|
|
2996
|
+
//# sourceMappingURL=index.js.map
|