peachsim 0.1.1655 → 0.1.1659
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/cli/app-config.ts +4 -0
- package/cli/app-stubs.ts +43 -6
- package/cli/commands/inspect/shared.ts +5 -2
- package/cli/commands/inspect/url.ts +2 -1
- package/cli/commands/screenshot.ts +5 -5
- package/cli/commands/state.ts +9 -6
- package/cli/outbound-endpoints.ts +9 -1
- package/cli/output-redaction.ts +49 -0
- package/dist-lib/agent-daemon-client.cjs +1 -1
- package/dist-lib/agent-events.cjs +1 -1
- package/dist-lib/attached-projects.cjs +1 -1
- package/dist-lib/auth/shared-session.cjs +1 -1
- package/dist-lib/backend-origin.cjs +1 -1
- package/dist-lib/beta.cjs +1 -1
- package/dist-lib/beta.mjs +1 -1
- package/dist-lib/bridge-constants.cjs +1 -1
- package/dist-lib/bridge-contract-input.cjs +1 -1
- package/dist-lib/bridge-contract-input.mjs +1 -1
- package/dist-lib/bridge-contract.cjs +1 -1
- package/dist-lib/bridge-contract.mjs +1 -1
- package/dist-lib/bundle-channel.cjs +11251 -1123
- package/dist-lib/capture-contract.cjs +1 -1
- package/dist-lib/capture-contract.mjs +1 -1
- package/dist-lib/cloud-contract.cjs +1 -1
- package/dist-lib/cloud-contract.mjs +1 -1
- package/dist-lib/cloud-test-args.cjs +1 -1
- package/dist-lib/cloud-test-args.mjs +1 -1
- package/dist-lib/cloud.cjs +1 -1
- package/dist-lib/cloud.mjs +1 -1
- package/dist-lib/config.cjs +29 -5
- package/dist-lib/config.mjs +29 -5
- package/dist-lib/detox/index.cjs +19 -5
- package/dist-lib/dev-bundle-resolution.cjs +1 -1
- package/dist-lib/expo-swift-bundle.cjs +8960 -134
- package/dist-lib/expo-swift-metadata.cjs +1 -1
- package/dist-lib/expo-swift-metadata.mjs +1 -1
- package/dist-lib/home-paths.cjs +1 -1
- package/dist-lib/host/bridge-host.cjs +9769 -731
- package/dist-lib/host/fetch-proxy-handler.cjs +260 -197
- package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
- package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
- package/dist-lib/host/replacement-module-handler.cjs +1 -1
- package/dist-lib/host/websocket-proxy.cjs +1 -1
- package/dist-lib/index.cjs +653 -338
- package/dist-lib/jump-to-source-babel.cjs +1 -1
- package/dist-lib/jump-to-source-native.cjs +1 -1
- package/dist-lib/kotlin-host.cjs +443 -312
- package/dist-lib/menu.cjs +1 -1
- package/dist-lib/menu.mjs +1 -1
- package/dist-lib/metro-fingerprint-registry.cjs +1 -1
- package/dist-lib/metro-fingerprint-registry.mjs +1 -1
- package/dist-lib/metro-production-bundle.cjs +1 -1
- package/dist-lib/metro-production-bundle.mjs +1 -1
- package/dist-lib/metro.cjs +548 -163
- package/dist-lib/native-app-identity-project.cjs +179 -33
- package/dist-lib/native-app-identity-project.mjs +179 -33
- package/dist-lib/native-app-identity.cjs +1 -1
- package/dist-lib/native-app-identity.mjs +1 -1
- package/dist-lib/native-firebase-metadata.cjs +1 -1
- package/dist-lib/native-firebase-metadata.mjs +1 -1
- package/dist-lib/plist.cjs +1 -1
- package/dist-lib/plist.mjs +1 -1
- package/dist-lib/profiles.cjs +1 -1
- package/dist-lib/public-brand.cjs +1 -1
- package/dist-lib/public-origins-lib-esm.json +23 -23
- package/dist-lib/public-origins-lib.json +96 -63
- package/dist-lib/react-native-host-modules.cjs +1 -1
- package/dist-lib/react-native-host-modules.mjs +1 -1
- package/dist-lib/scripts/dev-server-scanner.cjs +2 -2
- package/dist-lib/sdk.cjs +1 -1
- package/dist-lib/sdk.mjs +1 -1
- package/dist-lib/skills.cjs +10651 -1418
- package/dist-lib/swift-compile.cjs +8802 -138
- package/dist-lib/swift-compile.mjs +8802 -138
- package/dist-lib/swift-package.cjs +1 -1
- package/dist-lib/swift-package.mjs +1 -1
- package/dist-lib/swift-submit.cjs +1 -1
- package/dist-lib/swift-submit.mjs +1 -1
- package/dist-lib/swift-toolchain.cjs +1 -1
- package/dist-lib/swift.cjs +1 -1
- package/dist-lib/vite-swift.cjs +8960 -134
- package/dist-lib/vite.cjs +149 -163
- package/dist-lib/worklet-executable.cjs +1 -1
- package/dist-lib/worklet-executable.mjs +1 -1
- package/dist-types/packages/peach-compat/src/stubs/native-seams/react-native-gesture-handler.d.ts +1 -0
- package/dist-types/packages/peach-engine/src/engine/app-font-registry.d.ts +14 -0
- package/dist-types/packages/peach-engine/src/engine/image-loader.d.ts +8 -0
- package/dist-types/packages/peach-engine/src/engine/node.d.ts +3 -0
- package/dist-types/packages/peach-engine/src/render-worker/compositor-protocol.d.ts +21 -0
- package/dist-types/packages/peach-engine/src/render-worker/gesture-seam-protocol.d.ts +2 -1
- package/dist-types/packages/peach-engine/src/render-worker/test-bridge-protocol.d.ts +1 -1
- package/dist-types/packages/peach-engine/src/rolldown-bundle-inventory.d.ts +1 -0
- package/dist-types/packages/peach-globals/src/index.d.ts +25 -0
- package/kotlin/README.md +38 -23
- package/kotlin/sdk.tar.gz +0 -0
- package/package.json +2 -12
- package/runtime-companion.json +1 -1
- package/src/bundleGlobalFooter.ts +0 -2
- package/src/config.ts +54 -2
- package/src/configured-bundle-producer.ts +7 -1
- package/src/host/fetch-proxy-handler.ts +14 -50
- package/src/host/rolldown-bundle-forward.ts +71 -0
- package/src/installed-package-versions.ts +54 -2
- package/src/kotlin-host.ts +138 -285
- package/src/kotlin-module.ts +4 -7
- package/src/kotlin-sdk.ts +81 -0
- package/src/kotlin-toolchain.ts +152 -0
- package/src/kotlin-view-models.ts +1 -1
- package/src/kotlinSdkContract.ts +113 -0
- package/src/nitro-adapter.lock.json +3 -3
- package/src/nitro-bundle.ts +18 -4
- package/src/nitro-compile.ts +5 -1
- package/src/nitro-source.ts +112 -28
- package/src/nitroContract.ts +16 -4
- package/src/swift-compile.ts +12 -3
- package/src/swift-host.ts +2 -1
- package/src/swift-objc-compile.ts +117 -4
- package/src/swift-objc-sdk.ts +8792 -135
- package/src/swift-objc-standin.ts +1 -0
- package/src/vite-plugin-one.ts +73 -134
- package/src/worker-system-chunks.ts +14 -4
- package/src/xcode-project.ts +261 -34
- package/kotlin/AndroidViewSources/android/content/Context.kt +0 -22
- package/kotlin/AndroidViewSources/android/content/res/Configuration.kt +0 -25
- package/kotlin/AndroidViewSources/android/content/res/Resources.kt +0 -72
- package/kotlin/AndroidViewSources/android/graphics/Canvas.kt +0 -22
- package/kotlin/AndroidViewSources/android/graphics/Color.kt +0 -13
- package/kotlin/AndroidViewSources/android/graphics/Paint.kt +0 -18
- package/kotlin/AndroidViewSources/android/util/DisplayMetrics.kt +0 -12
- package/kotlin/AndroidViewSources/android/view/View.kt +0 -211
- package/kotlin/AndroidViewSources/android/widget/FrameLayout.kt +0 -61
- package/kotlin/AndroidViewSources/android/widget/LinearLayout.kt +0 -49
- package/kotlin/AndroidViewSources/dev/peach/app/JavaFormat.kt +0 -272
- package/kotlin/AppSources/android/app/Activity.kt +0 -174
- package/kotlin/AppSources/android/app/Application.kt +0 -11
- package/kotlin/AppSources/android/app/UiModeManager.kt +0 -9
- package/kotlin/AppSources/android/content/Intent.kt +0 -16
- package/kotlin/AppSources/android/os/Bundle.kt +0 -11
- package/kotlin/AppSources/android/util/SuperNotCalledException.kt +0 -3
- package/kotlin/AppSources/android/view/Window.kt +0 -182
- package/kotlin/AppSources/android/view/WindowInsets.kt +0 -9
- package/kotlin/AppSources/android/view/WindowInsetsController.kt +0 -17
- package/kotlin/AppSources/android/view/WindowManager.kt +0 -16
- package/kotlin/AppSources/android/window/BackEvent.kt +0 -24
- package/kotlin/AppSources/android/window/OnBackAnimationCallback.kt +0 -7
- package/kotlin/AppSources/android/window/OnBackInvokedDispatcher.kt +0 -84
- package/kotlin/AppSources/androidx/activity/ActivityFlags.kt +0 -9
- package/kotlin/AppSources/androidx/activity/ActivityViewModelLazy.kt +0 -21
- package/kotlin/AppSources/androidx/activity/BackEventCompat.kt +0 -43
- package/kotlin/AppSources/androidx/activity/ComponentActivity.kt +0 -122
- package/kotlin/AppSources/androidx/activity/EdgeToEdge.kt +0 -75
- package/kotlin/AppSources/androidx/activity/ExperimentalActivityApi.kt +0 -6
- package/kotlin/AppSources/androidx/activity/OnBackPressedCallback.kt +0 -69
- package/kotlin/AppSources/androidx/activity/OnBackPressedDispatcher.kt +0 -144
- package/kotlin/AppSources/androidx/activity/OnBackPressedDispatcherOwner.kt +0 -7
- package/kotlin/AppSources/androidx/activity/compose/BackHandler.kt +0 -86
- package/kotlin/AppSources/androidx/activity/compose/ComponentActivity.kt +0 -29
- package/kotlin/AppSources/androidx/activity/compose/internal/BackHandlerCompat.kt +0 -38
- package/kotlin/AppSources/androidx/activity/compose/internal/BackHandlerDispatcherCompat.kt +0 -27
- package/kotlin/AppSources/androidx/compose/foundation/layout/WindowInsets.kt +0 -15
- package/kotlin/AppSources/androidx/compose/ui/platform/AndroidCompositionLocals.kt +0 -27
- package/kotlin/AppSources/androidx/compose/ui/platform/ComposeView.kt +0 -68
- package/kotlin/AppSources/androidx/compose/ui/res/ColorResources.kt +0 -16
- package/kotlin/AppSources/androidx/compose/ui/res/PainterResources.kt +0 -70
- package/kotlin/AppSources/androidx/compose/ui/res/StringResources.kt +0 -38
- package/kotlin/AppSources/androidx/core/view/WindowCompat.kt +0 -32
- package/kotlin/AppSources/androidx/lifecycle/AndroidViewModel.kt +0 -10
- package/kotlin/AppSources/dev/peach/app/PeachApp.kt +0 -388
- package/kotlin/AppSources/dev/peach/app/PeachDrawable.kt +0 -102
- package/kotlin/AppSources/dev/peach/app/PeachWindowHost.kt +0 -14
- package/kotlin/CompilerSources/META-INF/services/org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar +0 -1
- package/kotlin/CompilerSources/PeachJniIncoming.kt +0 -243
- package/kotlin/CompilerSources/PeachJniPlugin.kt +0 -116
- package/kotlin/ComposeSources/PeachComposeHost.kt +0 -724
- package/kotlin/ComposeSources/PeachMagnifier.kt +0 -185
- package/kotlin/ComposeSources/PeachSemantics.kt +0 -127
- package/kotlin/ExpoComposeSources/PeachAndroidView.kt +0 -103
- package/kotlin/ExpoComposeSources/PeachExpoViewMount.kt +0 -24
- package/kotlin/ExpoComposeSources/dev/peach/expo/PeachExpoCompose.kt +0 -28
- package/kotlin/ExpoComposeSources/expo/modules/kotlin/views/ExpoComposeView.kt +0 -70
- package/kotlin/ExpoSources/dev/peach/expo/PeachExpoRuntime.kt +0 -516
- package/kotlin/ExpoSources/dev/peach/expo/PeachExpoTypes.kt +0 -173
- package/kotlin/ExpoSources/expo/modules/kotlin/AppContext.kt +0 -20
- package/kotlin/ExpoSources/expo/modules/kotlin/Promise.kt +0 -19
- package/kotlin/ExpoSources/expo/modules/kotlin/classcomponent/ClassComponentBuilder.kt +0 -198
- package/kotlin/ExpoSources/expo/modules/kotlin/exception/CodedException.kt +0 -126
- package/kotlin/ExpoSources/expo/modules/kotlin/functions/Functions.kt +0 -132
- package/kotlin/ExpoSources/expo/modules/kotlin/jni/JavaScriptTypedArray.kt +0 -81
- package/kotlin/ExpoSources/expo/modules/kotlin/modules/Module.kt +0 -98
- package/kotlin/ExpoSources/expo/modules/kotlin/objects/ObjectDefinitionBuilder.kt +0 -236
- package/kotlin/ExpoSources/expo/modules/kotlin/records/Record.kt +0 -12
- package/kotlin/ExpoSources/expo/modules/kotlin/runtime/Runtime.kt +0 -9
- package/kotlin/ExpoSources/expo/modules/kotlin/sharedobjects/SharedObject.kt +0 -50
- package/kotlin/ExpoSources/expo/modules/kotlin/sharedobjects/SharedObjectRegistry.kt +0 -57
- package/kotlin/ExpoSources/expo/modules/kotlin/sharedobjects/SharedRef.kt +0 -19
- package/kotlin/ExpoSources/expo/modules/kotlin/typedarray/ConcreteTypedArrays.kt +0 -158
- package/kotlin/ExpoSources/expo/modules/kotlin/typedarray/GenericTypedArray.kt +0 -8
- package/kotlin/ExpoSources/expo/modules/kotlin/typedarray/TypedArray.kt +0 -29
- package/kotlin/ExpoSources/expo/modules/kotlin/typedarray/TypedArrayIterator.kt +0 -9
- package/kotlin/ExpoSources/expo/modules/kotlin/types/AnyType.kt +0 -155
- package/kotlin/ExpoSources/expo/modules/kotlin/types/Either.kt +0 -91
- package/kotlin/ExpoSources/expo/modules/kotlin/types/Enumerable.kt +0 -6
- package/kotlin/ExpoSources/expo/modules/kotlin/viewevent/ViewEvent.kt +0 -68
- package/kotlin/ExpoSources/expo/modules/kotlin/views/ExpoView.kt +0 -20
- package/kotlin/ExpoSources/expo/modules/kotlin/views/ViewDefinitionBuilder.kt +0 -72
- package/kotlin/ExpoSources/expo/modules/kotlin/views/ViewProps.kt +0 -36
- package/kotlin/JniPlatformSources/androidx/annotation/CallSuper.kt +0 -5
- package/kotlin/JniPlatformSources/com/facebook/proguard/annotations/DoNotStrip.kt +0 -5
- package/kotlin/JniPlatformSources/dalvik/annotation/optimization/FastNative.kt +0 -5
- package/kotlin/JniPlatformSources/kotlin/Synchronized.kt +0 -6
- package/kotlin/JniPlatformSources/kotlin/jvm/JvmField.kt +0 -5
- package/kotlin/JniPlatformSources/kotlin/jvm/JvmStatic.kt +0 -5
- package/kotlin/JniSources/com/facebook/jni/HybridData.kt +0 -66
- package/kotlin/JniSources/dev/peach/jni/IncomingBindings.kt +0 -157
- package/kotlin/JniSources/dev/peach/jni/NativeBindings.kt +0 -77
- package/kotlin/JniTransportSources/dev/peach/jni/integration/JniTransport.kt +0 -89
- package/kotlin/Sources/android/os/Build.kt +0 -17
- package/kotlin/Sources/android/os/Handler.kt +0 -35
- package/kotlin/Sources/android/os/Looper.kt +0 -17
- package/kotlin/Sources/android/os/MessageQueue.kt +0 -56
- package/kotlin/Sources/android/os/SystemClock.kt +0 -14
- package/kotlin/Sources/android/util/Log.kt +0 -64
- package/kotlin/Sources/androidx/annotation/DrawableRes.kt +0 -14
- package/kotlin/Sources/androidx/annotation/Keep.kt +0 -4
- package/kotlin/Sources/dev/onejs/one/OneNativeSourceDispatch.kt +0 -7
- package/kotlin/Sources/dev/onejs/one/OneNativeSourceViewDispatch.kt +0 -13
- package/kotlin/Sources/dev/onejs/one/source/OneModule.kt +0 -4
- package/kotlin/Sources/java/lang/Runnable.kt +0 -6
- package/kotlin/Sources/java/security/MessageDigest.kt +0 -114
- package/kotlin/Sources/java/util/IllegalFormatCodePointException.kt +0 -10
- package/kotlin/Sources/java/util/IllegalFormatException.kt +0 -5
- package/kotlin/Sources/kotlin/text/StringFormat.kt +0 -9
- package/kotlin/Sources/org/json/JSON.kt +0 -307
- package/kotlin/tools/abi-classes.main.kts +0 -41
- package/kotlin/tools/expo-types.main.kts +0 -127
package/dist-lib/kotlin-host.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! peach v0.1.
|
|
1
|
+
/*! peach v0.1.1659 | (c) 2026 Tamagui LLC | Proprietary; see LICENSE */
|
|
2
2
|
let __sootsim_import_meta_url = '', __sootsim_import_meta_dirname = ''; try { __sootsim_import_meta_url = require('url').pathToFileURL(__filename).href; __sootsim_import_meta_dirname = __dirname; } catch {}
|
|
3
3
|
"use strict";
|
|
4
4
|
var __create = Object.create;
|
|
@@ -43,13 +43,32 @@ __export(kotlin_host_exports, {
|
|
|
43
43
|
serveKotlinRequest: () => serveKotlinRequest
|
|
44
44
|
});
|
|
45
45
|
module.exports = __toCommonJS(kotlin_host_exports);
|
|
46
|
-
var
|
|
46
|
+
var import_node_child_process3 = require("node:child_process");
|
|
47
|
+
var import_node_crypto4 = require("node:crypto");
|
|
48
|
+
var import_node_fs4 = __toESM(require("node:fs"), 1);
|
|
49
|
+
var import_node_module = require("node:module");
|
|
50
|
+
var import_node_path5 = __toESM(require("node:path"), 1);
|
|
51
|
+
var import_node_util3 = require("node:util");
|
|
52
|
+
var import_acorn = require("acorn");
|
|
53
|
+
|
|
54
|
+
// src/is-record.ts
|
|
55
|
+
function isRecord(value) {
|
|
56
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// src/kotlin-sdk.ts
|
|
60
|
+
var import_node_child_process2 = require("node:child_process");
|
|
47
61
|
var import_node_crypto2 = require("node:crypto");
|
|
48
62
|
var import_node_fs2 = __toESM(require("node:fs"), 1);
|
|
49
|
-
var import_node_module = require("node:module");
|
|
50
63
|
var import_node_path3 = __toESM(require("node:path"), 1);
|
|
64
|
+
var import_node_util2 = require("node:util");
|
|
65
|
+
|
|
66
|
+
// src/kotlin-toolchain.ts
|
|
67
|
+
var import_node_child_process = require("node:child_process");
|
|
68
|
+
var import_node_crypto = require("node:crypto");
|
|
69
|
+
var import_node_fs = __toESM(require("node:fs"), 1);
|
|
70
|
+
var import_node_path2 = __toESM(require("node:path"), 1);
|
|
51
71
|
var import_node_util = require("node:util");
|
|
52
|
-
var import_acorn = require("acorn");
|
|
53
72
|
|
|
54
73
|
// src/home-paths.ts
|
|
55
74
|
var import_node_os = require("node:os");
|
|
@@ -62,9 +81,225 @@ function rnxHomeDir() {
|
|
|
62
81
|
}
|
|
63
82
|
var DAEMON_LOCKFILE_MAX_BYTES = 16 * 1024;
|
|
64
83
|
|
|
65
|
-
// src/
|
|
66
|
-
|
|
67
|
-
|
|
84
|
+
// src/kotlin-toolchain.ts
|
|
85
|
+
var run = (0, import_node_util.promisify)(import_node_child_process.execFile);
|
|
86
|
+
function readToolchain(moduleRoot) {
|
|
87
|
+
const parsed = JSON.parse(
|
|
88
|
+
import_node_fs.default.readFileSync(import_node_path2.default.join(moduleRoot, "toolchain.json"), "utf8")
|
|
89
|
+
);
|
|
90
|
+
const download = (value) => {
|
|
91
|
+
if (!isRecord(value) || typeof value.url !== "string" || typeof value.sha256 !== "string")
|
|
92
|
+
throw new Error(
|
|
93
|
+
"peachsim kotlin/toolchain.json names a download without url and sha256"
|
|
94
|
+
);
|
|
95
|
+
return { url: value.url, sha256: value.sha256 };
|
|
96
|
+
};
|
|
97
|
+
if (!isRecord(parsed) || !isRecord(parsed.compiler) || !Array.isArray(parsed.libraries) || !Array.isArray(parsed.composeLibraries) || !Array.isArray(parsed.composeJsLibraries) || !isRecord(parsed.composeRuntime) || typeof parsed.composeRuntime.name !== "string")
|
|
98
|
+
throw new Error("peachsim kotlin/toolchain.json has no compiler and libraries");
|
|
99
|
+
const version = parsed.compiler.version;
|
|
100
|
+
if (typeof version !== "string")
|
|
101
|
+
throw new Error("peachsim kotlin/toolchain.json has no compiler version");
|
|
102
|
+
const libraries = (values) => values.map((library) => {
|
|
103
|
+
if (!isRecord(library) || typeof library.name !== "string")
|
|
104
|
+
throw new Error("peachsim kotlin/toolchain.json names a library without a name");
|
|
105
|
+
return { ...download(library), name: library.name };
|
|
106
|
+
});
|
|
107
|
+
return {
|
|
108
|
+
compiler: { ...download(parsed.compiler), version },
|
|
109
|
+
libraries: libraries(parsed.libraries),
|
|
110
|
+
composeLibraries: libraries(parsed.composeLibraries),
|
|
111
|
+
composeRuntime: {
|
|
112
|
+
...download(parsed.composeRuntime),
|
|
113
|
+
name: parsed.composeRuntime.name
|
|
114
|
+
},
|
|
115
|
+
composeJsLibraries: parsed.composeJsLibraries.map((library) => {
|
|
116
|
+
if (!isRecord(library) || typeof library.name !== "string" || typeof library.module !== "string" || typeof library.file !== "string" || typeof library.archiveEntry !== "string")
|
|
117
|
+
throw new Error("peachsim kotlin/toolchain.json has an incomplete JS library");
|
|
118
|
+
return {
|
|
119
|
+
...download(library),
|
|
120
|
+
name: library.name,
|
|
121
|
+
module: library.module,
|
|
122
|
+
file: library.file,
|
|
123
|
+
archiveEntry: library.archiveEntry
|
|
124
|
+
};
|
|
125
|
+
})
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
function kotlinHome() {
|
|
129
|
+
return import_node_path2.default.join(rnxHomeDir(), "kotlin");
|
|
130
|
+
}
|
|
131
|
+
async function fetchVerified(download, target) {
|
|
132
|
+
if (import_node_fs.default.existsSync(target)) {
|
|
133
|
+
if ((0, import_node_crypto.createHash)("sha256").update(import_node_fs.default.readFileSync(target)).digest("hex") !== download.sha256)
|
|
134
|
+
throw new Error(
|
|
135
|
+
`cached Kotlin download differs from its pin: ${import_node_path2.default.basename(target)}`
|
|
136
|
+
);
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
const response = await fetch(download.url);
|
|
140
|
+
if (!response.ok) throw new Error(`${download.url} answered ${response.status}`);
|
|
141
|
+
const bytes = Buffer.from(await response.arrayBuffer());
|
|
142
|
+
const digest = (0, import_node_crypto.createHash)("sha256").update(bytes).digest("hex");
|
|
143
|
+
if (digest !== download.sha256)
|
|
144
|
+
throw new Error(`${download.url} has sha256 ${digest}, expected ${download.sha256}`);
|
|
145
|
+
import_node_fs.default.mkdirSync(import_node_path2.default.dirname(target), { recursive: true });
|
|
146
|
+
const partial = `${target}.${process.pid}.partial`;
|
|
147
|
+
import_node_fs.default.writeFileSync(partial, bytes);
|
|
148
|
+
import_node_fs.default.renameSync(partial, target);
|
|
149
|
+
}
|
|
150
|
+
var toolchains = /* @__PURE__ */ new Map();
|
|
151
|
+
function ensureToolchain(toolchain) {
|
|
152
|
+
const key = JSON.stringify(toolchain);
|
|
153
|
+
const pending = toolchains.get(key);
|
|
154
|
+
if (pending) return pending;
|
|
155
|
+
const ready = (async () => {
|
|
156
|
+
const dir = import_node_path2.default.join(kotlinHome(), toolchain.compiler.version);
|
|
157
|
+
const kotlinc = import_node_path2.default.join(dir, "kotlinc", "bin", "kotlinc-wasm");
|
|
158
|
+
if (!import_node_fs.default.existsSync(kotlinc)) {
|
|
159
|
+
const zip = import_node_path2.default.join(dir, "kotlin-compiler.zip");
|
|
160
|
+
await fetchVerified(toolchain.compiler, zip);
|
|
161
|
+
await run("unzip", ["-q", "-o", zip, "-d", dir]);
|
|
162
|
+
import_node_fs.default.rmSync(zip);
|
|
163
|
+
}
|
|
164
|
+
const java = process.env.JAVA_HOME ? import_node_path2.default.join(process.env.JAVA_HOME, "bin", "java") : "java";
|
|
165
|
+
const { stderr } = await run(java, ["-XshowSettings:properties", "-version"]).catch(
|
|
166
|
+
() => {
|
|
167
|
+
throw new Error(
|
|
168
|
+
`Kotlin in Peach compiles with kotlinc, which needs a Java runtime (17 or newer, as android builds use); ${process.env.JAVA_HOME ? `JAVA_HOME ${process.env.JAVA_HOME} has none` : "set JAVA_HOME or put java on PATH"}`
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
);
|
|
172
|
+
const javaHome = /^\s*java\.home\s*=\s*(.+)$/m.exec(stderr)?.[1]?.trim();
|
|
173
|
+
if (!javaHome || !import_node_path2.default.isAbsolute(javaHome))
|
|
174
|
+
throw new Error("the configured Java runtime did not report an absolute java.home");
|
|
175
|
+
const libraries = [import_node_path2.default.join(dir, "kotlinc", "lib", "kotlin-stdlib-wasm-js.klib")];
|
|
176
|
+
for (const library of toolchain.libraries) {
|
|
177
|
+
const target = import_node_path2.default.join(dir, library.name);
|
|
178
|
+
await fetchVerified(library, target);
|
|
179
|
+
libraries.push(target);
|
|
180
|
+
}
|
|
181
|
+
return { kotlinc, libraries, javaHome };
|
|
182
|
+
})().catch((error) => {
|
|
183
|
+
toolchains.delete(key);
|
|
184
|
+
throw error;
|
|
185
|
+
});
|
|
186
|
+
toolchains.set(key, ready);
|
|
187
|
+
return ready;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// src/kotlinSdkContract.ts
|
|
191
|
+
var platform = ["Sources", "JniPlatformSources", "JniSources"];
|
|
192
|
+
var KOTLIN_SDK_PROFILES = {
|
|
193
|
+
core: { compose: false, directories: platform },
|
|
194
|
+
compose: { compose: true, directories: platform },
|
|
195
|
+
views: { compose: true, directories: [...platform, "ComposeSources"] },
|
|
196
|
+
jni: { compose: false, directories: [...platform, "JniTransportSources"] },
|
|
197
|
+
jniCompose: {
|
|
198
|
+
compose: true,
|
|
199
|
+
directories: [...platform, "JniTransportSources"]
|
|
200
|
+
},
|
|
201
|
+
jniViews: {
|
|
202
|
+
compose: true,
|
|
203
|
+
directories: [...platform, "JniTransportSources", "ComposeSources"]
|
|
204
|
+
},
|
|
205
|
+
expo: {
|
|
206
|
+
compose: false,
|
|
207
|
+
directories: [...platform, "ExpoSources", "AndroidViewSources"]
|
|
208
|
+
},
|
|
209
|
+
expoCompose: {
|
|
210
|
+
compose: true,
|
|
211
|
+
directories: [
|
|
212
|
+
...platform,
|
|
213
|
+
"ExpoSources",
|
|
214
|
+
"AndroidViewSources",
|
|
215
|
+
"ComposeSources",
|
|
216
|
+
"ExpoComposeSources"
|
|
217
|
+
]
|
|
218
|
+
},
|
|
219
|
+
app: {
|
|
220
|
+
compose: true,
|
|
221
|
+
directories: [...platform, "ComposeSources", "AppSources", "AndroidViewSources"]
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
var KOTLIN_SDK_FILES = [
|
|
225
|
+
"plugin.jar",
|
|
226
|
+
"tools.jar",
|
|
227
|
+
...Object.keys(KOTLIN_SDK_PROFILES).map((name) => `${name}.klib`)
|
|
228
|
+
];
|
|
229
|
+
function readKotlinSdkManifest(source, compilerSha256) {
|
|
230
|
+
const value = JSON.parse(source);
|
|
231
|
+
if (!isRecord(value) || value.format !== 1 || value.abi !== 1 || value.compilerSha256 !== compilerSha256 || typeof value.sourceDigest !== "string" || !/^[a-f0-9]{64}$/.test(value.sourceDigest) || !isRecord(value.files) || Object.keys(value.files).length !== KOTLIN_SDK_FILES.length)
|
|
232
|
+
throw new Error("Kotlin SDK manifest is incompatible with this compiler");
|
|
233
|
+
const files = {};
|
|
234
|
+
for (const name of KOTLIN_SDK_FILES) {
|
|
235
|
+
const file = value.files[name];
|
|
236
|
+
if (!isRecord(file) || typeof file.sha256 !== "string" || !/^[a-f0-9]{64}$/.test(file.sha256) || typeof file.bytes !== "number" || !Number.isSafeInteger(file.bytes) || file.bytes < 1)
|
|
237
|
+
throw new Error(`Kotlin SDK has no verified binary ${name}`);
|
|
238
|
+
files[name] = { sha256: file.sha256, bytes: file.bytes };
|
|
239
|
+
}
|
|
240
|
+
return {
|
|
241
|
+
format: 1,
|
|
242
|
+
abi: 1,
|
|
243
|
+
compilerSha256,
|
|
244
|
+
sourceDigest: value.sourceDigest,
|
|
245
|
+
files
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// src/kotlin-sdk.ts
|
|
250
|
+
var run2 = (0, import_node_util2.promisify)(import_node_child_process2.execFile);
|
|
251
|
+
function verifyKotlinSdkDirectory(root, compilerSha256) {
|
|
252
|
+
const expectedNames = ["manifest.json", ...KOTLIN_SDK_FILES];
|
|
253
|
+
const names = import_node_fs2.default.readdirSync(root);
|
|
254
|
+
if (names.length !== expectedNames.length || names.some((name) => !expectedNames.includes(name)))
|
|
255
|
+
throw new Error("Kotlin SDK directory contains unexpected inputs");
|
|
256
|
+
const manifestStat = import_node_fs2.default.lstatSync(import_node_path3.default.join(root, "manifest.json"));
|
|
257
|
+
if (!manifestStat.isFile() || manifestStat.nlink !== 1)
|
|
258
|
+
throw new Error("Kotlin SDK manifest is not a regular file");
|
|
259
|
+
const manifest = readKotlinSdkManifest(
|
|
260
|
+
import_node_fs2.default.readFileSync(import_node_path3.default.join(root, "manifest.json"), "utf8"),
|
|
261
|
+
compilerSha256
|
|
262
|
+
);
|
|
263
|
+
for (const [name, expected] of Object.entries(manifest.files)) {
|
|
264
|
+
const target = import_node_path3.default.join(root, name);
|
|
265
|
+
const stat = import_node_fs2.default.lstatSync(target);
|
|
266
|
+
if (!stat.isFile() || stat.nlink !== 1)
|
|
267
|
+
throw new Error(`Kotlin SDK binary is not a regular file: ${name}`);
|
|
268
|
+
const bytes = import_node_fs2.default.readFileSync(target);
|
|
269
|
+
if (bytes.length !== expected.bytes || (0, import_node_crypto2.createHash)("sha256").update(bytes).digest("hex") !== expected.sha256)
|
|
270
|
+
throw new Error(`Kotlin SDK binary differs from its manifest: ${name}`);
|
|
271
|
+
}
|
|
272
|
+
return manifest;
|
|
273
|
+
}
|
|
274
|
+
async function installKotlinSdkArchive(archive, compilerSha256) {
|
|
275
|
+
const sha256 = (0, import_node_crypto2.createHash)("sha256").update(archive).digest("hex");
|
|
276
|
+
const parent = import_node_path3.default.join(kotlinHome(), "sdk");
|
|
277
|
+
const root = import_node_path3.default.join(parent, sha256);
|
|
278
|
+
if (import_node_fs2.default.existsSync(root))
|
|
279
|
+
return { root, sha256, manifest: verifyKotlinSdkDirectory(root, compilerSha256) };
|
|
280
|
+
import_node_fs2.default.mkdirSync(parent, { recursive: true });
|
|
281
|
+
const work = import_node_fs2.default.mkdtempSync(import_node_path3.default.join(parent, ".install-"));
|
|
282
|
+
try {
|
|
283
|
+
const packed = import_node_path3.default.join(work, "sdk.tar.gz");
|
|
284
|
+
import_node_fs2.default.writeFileSync(packed, archive);
|
|
285
|
+
const { stdout } = await run2("tar", ["-tzf", packed]);
|
|
286
|
+
const names = stdout.trim().split("\n");
|
|
287
|
+
const expected = ["manifest.json", ...KOTLIN_SDK_FILES];
|
|
288
|
+
if (names.length !== expected.length || new Set(names).size !== names.length || names.some((name) => !expected.includes(name)))
|
|
289
|
+
throw new Error("Kotlin SDK archive contains unexpected inputs");
|
|
290
|
+
await run2("tar", ["-xzf", packed, "-C", work, "--", ...expected]);
|
|
291
|
+
import_node_fs2.default.rmSync(packed);
|
|
292
|
+
const manifest = verifyKotlinSdkDirectory(work, compilerSha256);
|
|
293
|
+
try {
|
|
294
|
+
import_node_fs2.default.renameSync(work, root);
|
|
295
|
+
} catch (error) {
|
|
296
|
+
if (!import_node_fs2.default.existsSync(root)) throw error;
|
|
297
|
+
verifyKotlinSdkDirectory(root, compilerSha256);
|
|
298
|
+
}
|
|
299
|
+
return { root, sha256, manifest };
|
|
300
|
+
} finally {
|
|
301
|
+
import_node_fs2.default.rmSync(work, { recursive: true, force: true });
|
|
302
|
+
}
|
|
68
303
|
}
|
|
69
304
|
|
|
70
305
|
// src/kotlin-view-models.ts
|
|
@@ -143,9 +378,9 @@ function viewModelClasses(rows) {
|
|
|
143
378
|
}
|
|
144
379
|
|
|
145
380
|
// src/kotlin-module.ts
|
|
146
|
-
var
|
|
147
|
-
var
|
|
148
|
-
var
|
|
381
|
+
var import_node_crypto3 = require("node:crypto");
|
|
382
|
+
var import_node_fs3 = __toESM(require("node:fs"), 1);
|
|
383
|
+
var import_node_path4 = __toESM(require("node:path"), 1);
|
|
149
384
|
var import_node_url = require("node:url");
|
|
150
385
|
|
|
151
386
|
// cli/standalone.ts
|
|
@@ -155,33 +390,33 @@ var IS_STANDALONE = typeof __SOOTSIM_STANDALONE__ !== "undefined" && __SOOTSIM_S
|
|
|
155
390
|
var installedRoot;
|
|
156
391
|
function peachKotlinModuleRoot() {
|
|
157
392
|
if (!IS_STANDALONE)
|
|
158
|
-
return
|
|
393
|
+
return import_node_path4.default.resolve(import_node_path4.default.dirname((0, import_node_url.fileURLToPath)(__sootsim_import_meta_url)), "..", "kotlin");
|
|
159
394
|
if (installedRoot) return installedRoot;
|
|
160
395
|
const files = __PEACH_BUNDLED_KOTLIN__;
|
|
161
|
-
const digest = (0,
|
|
162
|
-
const parent =
|
|
163
|
-
const root =
|
|
164
|
-
|
|
165
|
-
if (!
|
|
166
|
-
const pending =
|
|
396
|
+
const digest = (0, import_node_crypto3.createHash)("sha256").update(JSON.stringify(files)).digest("hex");
|
|
397
|
+
const parent = import_node_path4.default.join(rnxHomeDir(), "kotlin", "modules");
|
|
398
|
+
const root = import_node_path4.default.join(parent, digest);
|
|
399
|
+
import_node_fs3.default.mkdirSync(parent, { recursive: true });
|
|
400
|
+
if (!import_node_fs3.default.existsSync(root)) {
|
|
401
|
+
const pending = import_node_fs3.default.mkdtempSync(import_node_path4.default.join(parent, ".install-"));
|
|
167
402
|
try {
|
|
168
403
|
for (const [name, contents] of Object.entries(files)) {
|
|
169
|
-
const file =
|
|
170
|
-
|
|
171
|
-
|
|
404
|
+
const file = import_node_path4.default.join(pending, name);
|
|
405
|
+
import_node_fs3.default.mkdirSync(import_node_path4.default.dirname(file), { recursive: true });
|
|
406
|
+
import_node_fs3.default.writeFileSync(file, Buffer.from(contents, "base64"));
|
|
172
407
|
}
|
|
173
408
|
try {
|
|
174
|
-
|
|
409
|
+
import_node_fs3.default.renameSync(pending, root);
|
|
175
410
|
} catch (error) {
|
|
176
411
|
if (!isRecord(error) || error.code !== "EEXIST" && error.code !== "ENOTEMPTY")
|
|
177
412
|
throw error;
|
|
178
413
|
}
|
|
179
414
|
} finally {
|
|
180
|
-
|
|
415
|
+
import_node_fs3.default.rmSync(pending, { recursive: true, force: true });
|
|
181
416
|
}
|
|
182
417
|
}
|
|
183
418
|
for (const [name, contents] of Object.entries(files)) {
|
|
184
|
-
if (
|
|
419
|
+
if (!import_node_fs3.default.readFileSync(import_node_path4.default.join(root, name)).equals(Buffer.from(contents, "base64")))
|
|
185
420
|
throw new Error(`packaged Kotlin module differs from this CLI: ${name}`);
|
|
186
421
|
}
|
|
187
422
|
installedRoot = root;
|
|
@@ -189,106 +424,20 @@ function peachKotlinModuleRoot() {
|
|
|
189
424
|
}
|
|
190
425
|
|
|
191
426
|
// src/kotlin-host.ts
|
|
192
|
-
var
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
427
|
+
var run3 = (0, import_node_util3.promisify)(import_node_child_process3.execFile);
|
|
428
|
+
function loadKotlinSdk(moduleRoot, toolchain) {
|
|
429
|
+
return installKotlinSdkArchive(
|
|
430
|
+
import_node_fs4.default.readFileSync(import_node_path5.default.join(moduleRoot, "sdk.tar.gz")),
|
|
431
|
+
toolchain.compiler.sha256
|
|
197
432
|
);
|
|
198
|
-
const download = (value) => {
|
|
199
|
-
if (!isRecord(value) || typeof value.url !== "string" || typeof value.sha256 !== "string")
|
|
200
|
-
throw new Error(
|
|
201
|
-
"peachsim kotlin/toolchain.json names a download without url and sha256"
|
|
202
|
-
);
|
|
203
|
-
return { url: value.url, sha256: value.sha256 };
|
|
204
|
-
};
|
|
205
|
-
if (!isRecord(parsed) || !isRecord(parsed.compiler) || !Array.isArray(parsed.libraries) || !Array.isArray(parsed.composeLibraries) || !Array.isArray(parsed.composeJsLibraries) || !isRecord(parsed.composeRuntime) || typeof parsed.composeRuntime.name !== "string")
|
|
206
|
-
throw new Error("peachsim kotlin/toolchain.json has no compiler and libraries");
|
|
207
|
-
const version = parsed.compiler.version;
|
|
208
|
-
if (typeof version !== "string")
|
|
209
|
-
throw new Error("peachsim kotlin/toolchain.json has no compiler version");
|
|
210
|
-
const libraries = (values) => values.map((library) => {
|
|
211
|
-
if (!isRecord(library) || typeof library.name !== "string")
|
|
212
|
-
throw new Error("peachsim kotlin/toolchain.json names a library without a name");
|
|
213
|
-
return { ...download(library), name: library.name };
|
|
214
|
-
});
|
|
215
|
-
return {
|
|
216
|
-
compiler: { ...download(parsed.compiler), version },
|
|
217
|
-
libraries: libraries(parsed.libraries),
|
|
218
|
-
composeLibraries: libraries(parsed.composeLibraries),
|
|
219
|
-
composeRuntime: {
|
|
220
|
-
...download(parsed.composeRuntime),
|
|
221
|
-
name: parsed.composeRuntime.name
|
|
222
|
-
},
|
|
223
|
-
composeJsLibraries: parsed.composeJsLibraries.map((library) => {
|
|
224
|
-
if (!isRecord(library) || typeof library.name !== "string" || typeof library.module !== "string" || typeof library.file !== "string" || typeof library.archiveEntry !== "string")
|
|
225
|
-
throw new Error("peachsim kotlin/toolchain.json has an incomplete JS library");
|
|
226
|
-
return {
|
|
227
|
-
...download(library),
|
|
228
|
-
name: library.name,
|
|
229
|
-
module: library.module,
|
|
230
|
-
file: library.file,
|
|
231
|
-
archiveEntry: library.archiveEntry
|
|
232
|
-
};
|
|
233
|
-
})
|
|
234
|
-
};
|
|
235
|
-
}
|
|
236
|
-
function kotlinHome() {
|
|
237
|
-
return import_node_path3.default.join(rnxHomeDir(), "kotlin");
|
|
238
|
-
}
|
|
239
|
-
async function fetchVerified(download, target) {
|
|
240
|
-
if (import_node_fs2.default.existsSync(target)) return;
|
|
241
|
-
const response = await fetch(download.url);
|
|
242
|
-
if (!response.ok) throw new Error(`${download.url} answered ${response.status}`);
|
|
243
|
-
const bytes = Buffer.from(await response.arrayBuffer());
|
|
244
|
-
const digest = (0, import_node_crypto2.createHash)("sha256").update(bytes).digest("hex");
|
|
245
|
-
if (digest !== download.sha256)
|
|
246
|
-
throw new Error(`${download.url} has sha256 ${digest}, expected ${download.sha256}`);
|
|
247
|
-
import_node_fs2.default.mkdirSync(import_node_path3.default.dirname(target), { recursive: true });
|
|
248
|
-
const partial = `${target}.${process.pid}.partial`;
|
|
249
|
-
import_node_fs2.default.writeFileSync(partial, bytes);
|
|
250
|
-
import_node_fs2.default.renameSync(partial, target);
|
|
251
|
-
}
|
|
252
|
-
var toolchains = /* @__PURE__ */ new Map();
|
|
253
|
-
function ensureToolchain(toolchain) {
|
|
254
|
-
const key = JSON.stringify(toolchain);
|
|
255
|
-
const pending = toolchains.get(key);
|
|
256
|
-
if (pending) return pending;
|
|
257
|
-
const ready = (async () => {
|
|
258
|
-
const dir = import_node_path3.default.join(kotlinHome(), toolchain.compiler.version);
|
|
259
|
-
const kotlinc = import_node_path3.default.join(dir, "kotlinc", "bin", "kotlinc-wasm");
|
|
260
|
-
if (!import_node_fs2.default.existsSync(kotlinc)) {
|
|
261
|
-
const zip = import_node_path3.default.join(dir, "kotlin-compiler.zip");
|
|
262
|
-
await fetchVerified(toolchain.compiler, zip);
|
|
263
|
-
await run("unzip", ["-q", "-o", zip, "-d", dir]);
|
|
264
|
-
import_node_fs2.default.rmSync(zip);
|
|
265
|
-
}
|
|
266
|
-
const java = process.env.JAVA_HOME ? import_node_path3.default.join(process.env.JAVA_HOME, "bin", "java") : "java";
|
|
267
|
-
await run(java, ["-version"]).catch(() => {
|
|
268
|
-
throw new Error(
|
|
269
|
-
`Kotlin in Peach compiles with kotlinc, which needs a Java runtime (17 or newer, as android builds use); ${process.env.JAVA_HOME ? `JAVA_HOME ${process.env.JAVA_HOME} has none` : "set JAVA_HOME or put java on PATH"}`
|
|
270
|
-
);
|
|
271
|
-
});
|
|
272
|
-
const libraries = [import_node_path3.default.join(dir, "kotlinc", "lib", "kotlin-stdlib-wasm-js.klib")];
|
|
273
|
-
for (const library of toolchain.libraries) {
|
|
274
|
-
const target = import_node_path3.default.join(dir, library.name);
|
|
275
|
-
await fetchVerified(library, target);
|
|
276
|
-
libraries.push(target);
|
|
277
|
-
}
|
|
278
|
-
return { kotlinc, libraries };
|
|
279
|
-
})().catch((error) => {
|
|
280
|
-
toolchains.delete(key);
|
|
281
|
-
throw error;
|
|
282
|
-
});
|
|
283
|
-
toolchains.set(key, ready);
|
|
284
|
-
return ready;
|
|
285
433
|
}
|
|
434
|
+
var KOTLIN_ARTIFACT_PREFIX = "/__peach/kotlin-artifact/";
|
|
286
435
|
function appKotlinLanguage(root) {
|
|
287
|
-
const reactNative =
|
|
288
|
-
(0, import_node_module.createRequire)(
|
|
436
|
+
const reactNative = import_node_path5.default.dirname(
|
|
437
|
+
(0, import_node_module.createRequire)(import_node_path5.default.join(root, "package.json")).resolve("react-native/package.json")
|
|
289
438
|
);
|
|
290
|
-
const versions =
|
|
291
|
-
|
|
439
|
+
const versions = import_node_fs4.default.readFileSync(
|
|
440
|
+
import_node_path5.default.join(reactNative, "gradle", "libs.versions.toml"),
|
|
292
441
|
"utf8"
|
|
293
442
|
);
|
|
294
443
|
const match = /^kotlin\s*=\s*"(\d+)\.(\d+)/m.exec(versions);
|
|
@@ -310,9 +459,9 @@ var SKIP_DIRS = /* @__PURE__ */ new Set([
|
|
|
310
459
|
function kotlinSources(root, skip = SKIP_DIRS) {
|
|
311
460
|
const sources = [];
|
|
312
461
|
const walk = (dir) => {
|
|
313
|
-
for (const entry of
|
|
462
|
+
for (const entry of import_node_fs4.default.readdirSync(dir, { withFileTypes: true })) {
|
|
314
463
|
if (entry.name.startsWith(".") || skip.has(entry.name)) continue;
|
|
315
|
-
const full =
|
|
464
|
+
const full = import_node_path5.default.join(dir, entry.name);
|
|
316
465
|
if (entry.isDirectory()) walk(full);
|
|
317
466
|
else if (entry.isFile() && entry.name.endsWith(".kt")) sources.push(full);
|
|
318
467
|
}
|
|
@@ -320,60 +469,6 @@ function kotlinSources(root, skip = SKIP_DIRS) {
|
|
|
320
469
|
walk(root);
|
|
321
470
|
return sources.sort();
|
|
322
471
|
}
|
|
323
|
-
function kotlinPlatformSources(moduleRoot, usesCompose) {
|
|
324
|
-
return ["Sources", "JniPlatformSources", "JniSources"].flatMap(
|
|
325
|
-
(directory) => kotlinSources(import_node_path3.default.join(moduleRoot, directory), /* @__PURE__ */ new Set()).filter(
|
|
326
|
-
(file) => usesCompose ? !file.endsWith("/androidx/annotation/CallSuper.kt") : !file.endsWith("/OneNativeSourceViewDispatch.kt")
|
|
327
|
-
)
|
|
328
|
-
);
|
|
329
|
-
}
|
|
330
|
-
var compilerPlugins = /* @__PURE__ */ new Map();
|
|
331
|
-
var COMPILER_PLUGIN_SERVICE = "META-INF/services/org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar";
|
|
332
|
-
function ensureCompilerPlugin(kotlinc, plugin) {
|
|
333
|
-
const cache = import_node_path3.default.join(kotlinHome(), "compiler-plugins");
|
|
334
|
-
const out = import_node_path3.default.join(cache, plugin.hash);
|
|
335
|
-
if (import_node_fs2.default.existsSync(out)) return Promise.resolve(out);
|
|
336
|
-
const pending = compilerPlugins.get(plugin.hash);
|
|
337
|
-
if (pending) return pending;
|
|
338
|
-
const build = (async () => {
|
|
339
|
-
import_node_fs2.default.mkdirSync(cache, { recursive: true });
|
|
340
|
-
const work = import_node_fs2.default.mkdtempSync(import_node_path3.default.join(cache, `${plugin.hash}-`));
|
|
341
|
-
const classes = import_node_path3.default.join(work, "classes");
|
|
342
|
-
try {
|
|
343
|
-
const sources = [];
|
|
344
|
-
for (const { name, bytes } of plugin.files) {
|
|
345
|
-
const target = import_node_path3.default.join(work, "sources", name);
|
|
346
|
-
import_node_fs2.default.mkdirSync(import_node_path3.default.dirname(target), { recursive: true });
|
|
347
|
-
import_node_fs2.default.writeFileSync(target, bytes);
|
|
348
|
-
if (name.endsWith(".kt")) sources.push(target);
|
|
349
|
-
}
|
|
350
|
-
await run(
|
|
351
|
-
import_node_path3.default.join(import_node_path3.default.dirname(kotlinc), "kotlinc"),
|
|
352
|
-
[
|
|
353
|
-
"-cp",
|
|
354
|
-
import_node_path3.default.resolve(import_node_path3.default.dirname(kotlinc), "../lib/kotlin-compiler.jar"),
|
|
355
|
-
...sources,
|
|
356
|
-
"-d",
|
|
357
|
-
classes
|
|
358
|
-
],
|
|
359
|
-
{ maxBuffer: 16 * 1024 * 1024 }
|
|
360
|
-
);
|
|
361
|
-
const service = import_node_path3.default.join(classes, COMPILER_PLUGIN_SERVICE);
|
|
362
|
-
import_node_fs2.default.mkdirSync(import_node_path3.default.dirname(service), { recursive: true });
|
|
363
|
-
import_node_fs2.default.copyFileSync(import_node_path3.default.join(work, "sources", COMPILER_PLUGIN_SERVICE), service);
|
|
364
|
-
try {
|
|
365
|
-
import_node_fs2.default.renameSync(classes, out);
|
|
366
|
-
} catch (error) {
|
|
367
|
-
if (!import_node_fs2.default.existsSync(out)) throw error;
|
|
368
|
-
}
|
|
369
|
-
return out;
|
|
370
|
-
} finally {
|
|
371
|
-
import_node_fs2.default.rmSync(work, { recursive: true, force: true });
|
|
372
|
-
}
|
|
373
|
-
})().finally(() => compilerPlugins.delete(plugin.hash));
|
|
374
|
-
compilerPlugins.set(plugin.hash, build);
|
|
375
|
-
return build;
|
|
376
|
-
}
|
|
377
472
|
function entrySource(ids) {
|
|
378
473
|
return [
|
|
379
474
|
"import android.os.Build",
|
|
@@ -421,10 +516,10 @@ function entrySource(ids) {
|
|
|
421
516
|
""
|
|
422
517
|
].join("\n");
|
|
423
518
|
}
|
|
424
|
-
var BUILD_FORMAT =
|
|
519
|
+
var BUILD_FORMAT = 17;
|
|
425
520
|
var builds = /* @__PURE__ */ new Map();
|
|
426
521
|
function buildsDir() {
|
|
427
|
-
return
|
|
522
|
+
return import_node_path5.default.join(kotlinHome(), "builds");
|
|
428
523
|
}
|
|
429
524
|
async function kotlinArtifact(root, moduleRoot, origin, target = "app") {
|
|
430
525
|
const { kotlinSourceId, nativeSourceContract, renderKotlinSourceGlue } = await import("vxrn/native-source-contract");
|
|
@@ -437,7 +532,7 @@ async function kotlinArtifact(root, moduleRoot, origin, target = "app") {
|
|
|
437
532
|
const viewIds = [];
|
|
438
533
|
let usesCompose = false;
|
|
439
534
|
for (const file of sources) {
|
|
440
|
-
const source =
|
|
535
|
+
const source = import_node_fs4.default.readFileSync(file, "utf8");
|
|
441
536
|
if (/\bandroidx\.compose\./.test(source)) usesCompose = true;
|
|
442
537
|
const contract = nativeSourceContract(file, source);
|
|
443
538
|
if (contract.modules.length === 0 && contract.views.length === 0) continue;
|
|
@@ -448,13 +543,18 @@ async function kotlinArtifact(root, moduleRoot, origin, target = "app") {
|
|
|
448
543
|
}
|
|
449
544
|
generated["PeachEntry.kt"] = entrySource(ids);
|
|
450
545
|
if (viewIds.length > 0) generated["PeachViews.kt"] = viewsSource(viewIds);
|
|
451
|
-
const
|
|
452
|
-
if (target === "jni")
|
|
453
|
-
shims.push(...kotlinSources(import_node_path3.default.join(moduleRoot, "JniTransportSources"), /* @__PURE__ */ new Set()));
|
|
454
|
-
if (viewIds.length > 0)
|
|
455
|
-
shims.push(...kotlinSources(import_node_path3.default.join(moduleRoot, "ComposeSources")));
|
|
546
|
+
const sdkProfile = target === "jni" ? viewIds.length > 0 ? "jniViews" : usesCompose ? "jniCompose" : "jni" : viewIds.length > 0 ? "views" : usesCompose ? "compose" : "core";
|
|
456
547
|
return compileKotlin(
|
|
457
|
-
{
|
|
548
|
+
{
|
|
549
|
+
root,
|
|
550
|
+
moduleRoot,
|
|
551
|
+
toolchain,
|
|
552
|
+
language,
|
|
553
|
+
sources,
|
|
554
|
+
generated,
|
|
555
|
+
sdkProfile,
|
|
556
|
+
usesCompose
|
|
557
|
+
},
|
|
458
558
|
origin
|
|
459
559
|
);
|
|
460
560
|
}
|
|
@@ -520,28 +620,36 @@ function readExpoTypes(output) {
|
|
|
520
620
|
});
|
|
521
621
|
}
|
|
522
622
|
var expoTypeScans = /* @__PURE__ */ new Map();
|
|
523
|
-
function scanExpoTypes(toolchain,
|
|
623
|
+
async function scanExpoTypes(toolchain, moduleRoot, sources) {
|
|
524
624
|
const candidates = sources.filter(
|
|
525
625
|
(file) => /\bRecord\b|\benum\s+class\b|\bExpoComposeView\b|\bExpoView\b|\bComposeProps\b|:\s*(?:[A-Za-z0-9_.]+\.)?(?:View|FrameLayout|LinearLayout|ViewGroup)\b/.test(
|
|
526
|
-
|
|
626
|
+
import_node_fs4.default.readFileSync(file, "utf8")
|
|
527
627
|
)
|
|
528
628
|
);
|
|
529
629
|
if (candidates.length === 0) return Promise.resolve([]);
|
|
530
|
-
const digest = (0,
|
|
531
|
-
|
|
532
|
-
|
|
630
|
+
const digest = (0, import_node_crypto4.createHash)("sha256").update(JSON.stringify(toolchain.compiler));
|
|
631
|
+
const sdk = await loadKotlinSdk(moduleRoot, toolchain);
|
|
632
|
+
const packedSdk = import_node_fs4.default.readFileSync(import_node_path5.default.join(moduleRoot, "sdk.tar.gz"));
|
|
633
|
+
digest.update(packedSdk);
|
|
634
|
+
for (const file of candidates)
|
|
635
|
+
digest.update(`${file}\0${import_node_fs4.default.readFileSync(file, "utf8")}\0`);
|
|
533
636
|
const key = digest.digest("hex");
|
|
534
637
|
let scan = expoTypeScans.get(key);
|
|
535
638
|
if (!scan) {
|
|
536
639
|
scan = (async () => {
|
|
537
|
-
const { kotlinc } = await
|
|
538
|
-
|
|
539
|
-
|
|
640
|
+
const [{ kotlinc }, installed] = await Promise.all([
|
|
641
|
+
ensureToolchain(toolchain),
|
|
642
|
+
Promise.resolve(sdk)
|
|
643
|
+
]);
|
|
644
|
+
const { stdout } = await run3(
|
|
645
|
+
import_node_path5.default.join(import_node_path5.default.dirname(kotlinc), "kotlin"),
|
|
540
646
|
[
|
|
541
647
|
"-cp",
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
648
|
+
[
|
|
649
|
+
import_node_path5.default.resolve(import_node_path5.default.dirname(kotlinc), "../lib/kotlin-compiler.jar"),
|
|
650
|
+
import_node_path5.default.join(installed.root, "tools.jar")
|
|
651
|
+
].join(import_node_path5.default.delimiter),
|
|
652
|
+
"dev.peach.tools.expo.ExpoTypesKt",
|
|
545
653
|
...candidates
|
|
546
654
|
],
|
|
547
655
|
{ maxBuffer: 16 * 1024 * 1024 }
|
|
@@ -616,7 +724,7 @@ function expoTypeSources(files) {
|
|
|
616
724
|
)
|
|
617
725
|
];
|
|
618
726
|
if (edits.length > 0 || views.length > 0) {
|
|
619
|
-
let text =
|
|
727
|
+
let text = import_node_fs4.default.readFileSync(file.file, "utf8").replaceAll("\r\n", "\n");
|
|
620
728
|
for (const { range, owner, field } of edits.sort((a, b) => b.range[0] - a.range[0]))
|
|
621
729
|
text = `${text.slice(0, range[0])}dev.peach.expo.PeachExpoTypes.initial(${owner}::class, ${literal(field.key)}, ${field.required}) { ${text.slice(range[0], range[1])} }${text.slice(range[1])}`;
|
|
622
730
|
if (views.length > 0) {
|
|
@@ -632,7 +740,7 @@ function expoTypeSources(files) {
|
|
|
632
740
|
`${file.package ? `${file.package}.` : ""}peachExpoViews${index}()`
|
|
633
741
|
);
|
|
634
742
|
}
|
|
635
|
-
const name = `PeachExpoSource_${index}_${
|
|
743
|
+
const name = `PeachExpoSource_${index}_${import_node_path5.default.basename(file.file)}`;
|
|
636
744
|
generated[name] = text;
|
|
637
745
|
origins[name] = file.file;
|
|
638
746
|
}
|
|
@@ -653,23 +761,10 @@ function expoTypeSources(files) {
|
|
|
653
761
|
async function expoKotlinArtifact(root, moduleRoot, origin, modules) {
|
|
654
762
|
const toolchain = readToolchain(moduleRoot);
|
|
655
763
|
const language = appKotlinLanguage(root);
|
|
656
|
-
const scanned = await scanExpoTypes(
|
|
657
|
-
toolchain,
|
|
658
|
-
import_node_path3.default.join(moduleRoot, "tools/expo-types.main.kts"),
|
|
659
|
-
modules.sources
|
|
660
|
-
);
|
|
764
|
+
const scanned = await scanExpoTypes(toolchain, moduleRoot, modules.sources);
|
|
661
765
|
const usesCompose = scanned.some((file) => file.views.length > 0) || modules.sources.some(
|
|
662
|
-
(file) => /\bandroidx\.compose\./.test(
|
|
766
|
+
(file) => /\bandroidx\.compose\./.test(import_node_fs4.default.readFileSync(file, "utf8"))
|
|
663
767
|
);
|
|
664
|
-
const shims = [
|
|
665
|
-
...kotlinPlatformSources(moduleRoot, usesCompose),
|
|
666
|
-
...kotlinSources(import_node_path3.default.join(moduleRoot, "ExpoSources"), /* @__PURE__ */ new Set()),
|
|
667
|
-
...kotlinSources(import_node_path3.default.join(moduleRoot, "AndroidViewSources"), /* @__PURE__ */ new Set()),
|
|
668
|
-
...usesCompose ? [
|
|
669
|
-
...kotlinSources(import_node_path3.default.join(moduleRoot, "ComposeSources")),
|
|
670
|
-
...kotlinSources(import_node_path3.default.join(moduleRoot, "ExpoComposeSources"), /* @__PURE__ */ new Set())
|
|
671
|
-
] : []
|
|
672
|
-
];
|
|
673
768
|
const types = expoTypeSources(scanned);
|
|
674
769
|
const rewritten = new Set(Object.values(types.origins));
|
|
675
770
|
const entry = [
|
|
@@ -710,7 +805,7 @@ async function expoKotlinArtifact(root, moduleRoot, origin, modules) {
|
|
|
710
805
|
...usesCompose ? { "PeachViews.kt": viewsSource([]) } : {}
|
|
711
806
|
},
|
|
712
807
|
origins: types.origins,
|
|
713
|
-
|
|
808
|
+
sdkProfile: usesCompose ? "expoCompose" : "expo",
|
|
714
809
|
usesCompose
|
|
715
810
|
},
|
|
716
811
|
origin
|
|
@@ -721,9 +816,11 @@ function viewsSource(viewIds) {
|
|
|
721
816
|
return [
|
|
722
817
|
"import dev.onejs.one.OneNativeSourceViewDispatch",
|
|
723
818
|
"",
|
|
724
|
-
"fun
|
|
819
|
+
"internal fun initializeApplicationViews() {",
|
|
820
|
+
" peachViewDispatcher = { source -> when (source) {",
|
|
725
821
|
...viewIds.map((id) => ` ${JSON.stringify(id)} -> OneNativeSourceViews_${id}()`),
|
|
726
822
|
' else -> error("composable source $source is not linked; rebuild the app")',
|
|
823
|
+
" } }",
|
|
727
824
|
"}"
|
|
728
825
|
].join("\n");
|
|
729
826
|
}
|
|
@@ -766,6 +863,7 @@ async function kotlinAppArtifact(app, moduleRoot, origin) {
|
|
|
766
863
|
" font: String, insets: String, night: Boolean,",
|
|
767
864
|
" invalidate: (Boolean) -> Unit): String = dev.peach.app.peachStartApp(",
|
|
768
865
|
" dev.peach.app.PeachAppSpec(",
|
|
866
|
+
" dev.peach.app.compiledAppResources,",
|
|
769
867
|
` android.content.ComponentName(${literal(app.packageName)}, ${literal(app.launcher.name)}),`,
|
|
770
868
|
` android.content.ComponentName(${literal(app.packageName)}, ${literal(app.launcher.targetClass)}),`,
|
|
771
869
|
...windowTheme(app.window.day),
|
|
@@ -810,12 +908,6 @@ async function kotlinAppArtifact(app, moduleRoot, origin) {
|
|
|
810
908
|
"PeachAppEntry.kt": appEntry([]),
|
|
811
909
|
...appResourceSources(app)
|
|
812
910
|
};
|
|
813
|
-
const shims = [
|
|
814
|
-
...kotlinPlatformSources(moduleRoot, true),
|
|
815
|
-
...kotlinSources(import_node_path3.default.join(moduleRoot, "ComposeSources")),
|
|
816
|
-
...kotlinSources(import_node_path3.default.join(moduleRoot, "AppSources"), /* @__PURE__ */ new Set()),
|
|
817
|
-
...kotlinSources(import_node_path3.default.join(moduleRoot, "AndroidViewSources"), /* @__PURE__ */ new Set())
|
|
818
|
-
];
|
|
819
911
|
return compileKotlin(
|
|
820
912
|
{
|
|
821
913
|
root: app.projectDir,
|
|
@@ -824,12 +916,12 @@ async function kotlinAppArtifact(app, moduleRoot, origin) {
|
|
|
824
916
|
language: app.language,
|
|
825
917
|
sources: app.sources,
|
|
826
918
|
generated,
|
|
827
|
-
|
|
919
|
+
sdkProfile: "app",
|
|
828
920
|
usesCompose: true,
|
|
829
921
|
viewModels: {
|
|
830
922
|
file: "PeachAppEntry.kt",
|
|
831
923
|
render: appEntry,
|
|
832
|
-
|
|
924
|
+
toolClass: "dev.peach.tools.abi.AbiClassesKt"
|
|
833
925
|
}
|
|
834
926
|
},
|
|
835
927
|
origin
|
|
@@ -886,7 +978,7 @@ function appResourceSources(app) {
|
|
|
886
978
|
entries: app.drawables.map((drawable) => ({
|
|
887
979
|
name: drawable.name,
|
|
888
980
|
init: `listOf(
|
|
889
|
-
${drawable.files.map((file) => drawableInit(file,
|
|
981
|
+
${drawable.files.map((file) => drawableInit(file, import_node_path5.default.relative(app.moduleDir, file.file))).join(",\n")}
|
|
890
982
|
)`
|
|
891
983
|
}))
|
|
892
984
|
},
|
|
@@ -941,7 +1033,12 @@ ${drawable.files.map((file) => drawableInit(file, import_node_path3.default.rela
|
|
|
941
1033
|
...kind.entries.map((entry) => ` ${entry.id} to ${entry.init},`),
|
|
942
1034
|
")",
|
|
943
1035
|
""
|
|
944
|
-
])
|
|
1036
|
+
]),
|
|
1037
|
+
"internal val compiledAppResources = PeachAppResources(",
|
|
1038
|
+
...kinds.map(
|
|
1039
|
+
(kind) => ` ${kind.table.slice("peachApp".length).toLowerCase()} = ${kind.table},`
|
|
1040
|
+
),
|
|
1041
|
+
")"
|
|
945
1042
|
].join("\n")
|
|
946
1043
|
};
|
|
947
1044
|
}
|
|
@@ -950,7 +1047,7 @@ function drawableInit(drawable, file) {
|
|
|
950
1047
|
if (drawable.kind === "xml") return `PeachDrawable.Xml(${where})`;
|
|
951
1048
|
if (drawable.kind === "bitmap")
|
|
952
1049
|
return `PeachDrawable.Bitmap(${where}, ${drawable.ninePatch}, ${literal(
|
|
953
|
-
|
|
1050
|
+
import_node_fs4.default.readFileSync(drawable.file).toString("base64")
|
|
954
1051
|
)})`;
|
|
955
1052
|
const vector = drawable.vector;
|
|
956
1053
|
const float = (value) => `${value}f`;
|
|
@@ -1005,39 +1102,50 @@ async function compileKotlin(input, origin) {
|
|
|
1005
1102
|
toolchain,
|
|
1006
1103
|
language,
|
|
1007
1104
|
sources,
|
|
1008
|
-
generated,
|
|
1105
|
+
generated: sourceGenerated,
|
|
1009
1106
|
origins = {},
|
|
1010
|
-
|
|
1107
|
+
sdkProfile,
|
|
1011
1108
|
usesCompose,
|
|
1012
1109
|
viewModels
|
|
1013
1110
|
} = input;
|
|
1014
|
-
const
|
|
1015
|
-
const
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1111
|
+
const sdk = await loadKotlinSdk(moduleRoot, toolchain);
|
|
1112
|
+
const plugin = import_node_path5.default.join(sdk.root, "plugin.jar");
|
|
1113
|
+
const sdkLibrary = import_node_path5.default.join(sdk.root, `${sdkProfile}.klib`);
|
|
1114
|
+
const generated = {
|
|
1115
|
+
...sourceGenerated,
|
|
1116
|
+
"PeachBindingsInitialization.kt": [
|
|
1117
|
+
"@file:OptIn(kotlin.js.ExperimentalJsExport::class)",
|
|
1118
|
+
"package dev.peach.jni",
|
|
1119
|
+
...sourceGenerated["PeachViews.kt"] ? ["import initializeApplicationViews"] : [],
|
|
1120
|
+
'internal fun initializeApplicationIncomingBindings() { error("application bindings require the compiler plugin") }',
|
|
1121
|
+
"private var initialized = false",
|
|
1122
|
+
"@JsExport fun peachInitializeModuleBindings() {",
|
|
1123
|
+
" if (!initialized) {",
|
|
1124
|
+
" requireIncomingBindings()",
|
|
1125
|
+
" initializeApplicationIncomingBindings()",
|
|
1126
|
+
...sourceGenerated["PeachViews.kt"] ? [" initializeApplicationViews()"] : [],
|
|
1127
|
+
" initialized = true",
|
|
1128
|
+
" }",
|
|
1129
|
+
"}"
|
|
1130
|
+
].join("\n")
|
|
1131
|
+
};
|
|
1132
|
+
const inputs = sources.map((file) => ({
|
|
1031
1133
|
file,
|
|
1032
|
-
bytes:
|
|
1134
|
+
bytes: import_node_fs4.default.readFileSync(file)
|
|
1033
1135
|
}));
|
|
1034
|
-
const digest = (0,
|
|
1136
|
+
const digest = (0, import_node_crypto4.createHash)("sha256");
|
|
1035
1137
|
digest.update(
|
|
1036
|
-
JSON.stringify({
|
|
1138
|
+
JSON.stringify({
|
|
1139
|
+
format: BUILD_FORMAT,
|
|
1140
|
+
toolchain,
|
|
1141
|
+
language,
|
|
1142
|
+
sdk: sdk.sha256,
|
|
1143
|
+
sdkProfile
|
|
1144
|
+
})
|
|
1037
1145
|
);
|
|
1038
1146
|
for (const { file, bytes } of inputs)
|
|
1039
|
-
digest.update(
|
|
1040
|
-
if (viewModels) digest.update(
|
|
1147
|
+
digest.update(import_node_path5.default.relative(root, file)).update("\0").update(bytes).update("\0");
|
|
1148
|
+
if (viewModels) digest.update(viewModels.toolClass);
|
|
1041
1149
|
for (const [name, text] of Object.entries(generated))
|
|
1042
1150
|
digest.update(`${name}\0${text}\0`);
|
|
1043
1151
|
const hash = digest.digest("hex").slice(0, 24);
|
|
@@ -1045,38 +1153,37 @@ async function compileKotlin(input, origin) {
|
|
|
1045
1153
|
url: `${origin}${KOTLIN_ARTIFACT_PREFIX}${hash}/app.mjs`,
|
|
1046
1154
|
hash
|
|
1047
1155
|
};
|
|
1048
|
-
const out =
|
|
1049
|
-
if (
|
|
1156
|
+
const out = import_node_path5.default.join(buildsDir(), hash);
|
|
1157
|
+
if (import_node_fs4.default.existsSync(import_node_path5.default.join(out, "js", "app.wasm"))) return artifact;
|
|
1050
1158
|
const pending = builds.get(hash);
|
|
1051
1159
|
if (pending) return pending;
|
|
1052
1160
|
const build = (async () => {
|
|
1053
1161
|
const ready = await ensureToolchain(toolchain);
|
|
1054
1162
|
const { kotlinc } = ready;
|
|
1055
|
-
const
|
|
1056
|
-
const
|
|
1057
|
-
const composeRuntime = import_node_path3.default.join(
|
|
1163
|
+
const libraries = [...ready.libraries, sdkLibrary];
|
|
1164
|
+
const composeRuntime = import_node_path5.default.join(
|
|
1058
1165
|
kotlinHome(),
|
|
1059
1166
|
toolchain.compiler.version,
|
|
1060
1167
|
toolchain.composeRuntime.name
|
|
1061
1168
|
);
|
|
1062
1169
|
if (usesCompose) {
|
|
1063
1170
|
for (const library of toolchain.composeLibraries) {
|
|
1064
|
-
const target =
|
|
1171
|
+
const target = import_node_path5.default.join(kotlinHome(), toolchain.compiler.version, library.name);
|
|
1065
1172
|
await fetchVerified(library, target);
|
|
1066
1173
|
libraries.push(target);
|
|
1067
1174
|
}
|
|
1068
1175
|
await fetchVerified(toolchain.composeRuntime, composeRuntime);
|
|
1069
1176
|
}
|
|
1070
|
-
|
|
1071
|
-
const work =
|
|
1072
|
-
const generatedDir =
|
|
1073
|
-
|
|
1177
|
+
import_node_fs4.default.mkdirSync(buildsDir(), { recursive: true });
|
|
1178
|
+
const work = import_node_fs4.default.mkdtempSync(import_node_path5.default.join(buildsDir(), `${hash}-`));
|
|
1179
|
+
const generatedDir = import_node_path5.default.join(work, "generated");
|
|
1180
|
+
import_node_fs4.default.mkdirSync(generatedDir);
|
|
1074
1181
|
for (const [name, text] of Object.entries(generated))
|
|
1075
|
-
|
|
1182
|
+
import_node_fs4.default.writeFileSync(import_node_path5.default.join(generatedDir, name), text);
|
|
1076
1183
|
const compiledSources = inputs.map(({ file, bytes }, index) => {
|
|
1077
|
-
const target =
|
|
1078
|
-
|
|
1079
|
-
|
|
1184
|
+
const target = import_node_path5.default.join(work, "sources", String(index), import_node_path5.default.basename(file));
|
|
1185
|
+
import_node_fs4.default.mkdirSync(import_node_path5.default.dirname(target), { recursive: true });
|
|
1186
|
+
import_node_fs4.default.writeFileSync(target, bytes);
|
|
1080
1187
|
return { file, target };
|
|
1081
1188
|
});
|
|
1082
1189
|
const common = [
|
|
@@ -1085,15 +1192,16 @@ async function compileKotlin(input, origin) {
|
|
|
1085
1192
|
"-Xallow-kotlin-package",
|
|
1086
1193
|
"-Xwasm-target=js",
|
|
1087
1194
|
"-libraries",
|
|
1088
|
-
libraries.join(
|
|
1195
|
+
libraries.join(import_node_path5.default.delimiter)
|
|
1089
1196
|
];
|
|
1090
|
-
const compileKlib = (outputDir) =>
|
|
1197
|
+
const compileKlib = (outputDir) => run3(
|
|
1091
1198
|
kotlinc,
|
|
1092
1199
|
[
|
|
1093
1200
|
...common,
|
|
1094
|
-
`-Xplugin=${
|
|
1201
|
+
`-Xplugin=${plugin}`,
|
|
1202
|
+
`-Xfriend-modules=${sdkLibrary}`,
|
|
1095
1203
|
...usesCompose ? [
|
|
1096
|
-
`-Xplugin=${
|
|
1204
|
+
`-Xplugin=${import_node_path5.default.resolve(import_node_path5.default.dirname(kotlinc), "../lib/compose-compiler-plugin.jar")}`
|
|
1097
1205
|
] : [],
|
|
1098
1206
|
"-language-version",
|
|
1099
1207
|
language,
|
|
@@ -1106,7 +1214,7 @@ async function compileKotlin(input, origin) {
|
|
|
1106
1214
|
"-ir-output-name",
|
|
1107
1215
|
"app",
|
|
1108
1216
|
...compiledSources.map(({ target }) => target),
|
|
1109
|
-
...Object.keys(generated).map((name) =>
|
|
1217
|
+
...Object.keys(generated).map((name) => import_node_path5.default.join(generatedDir, name))
|
|
1110
1218
|
],
|
|
1111
1219
|
{ maxBuffer: 16 * 1024 * 1024 }
|
|
1112
1220
|
);
|
|
@@ -1114,49 +1222,51 @@ async function compileKotlin(input, origin) {
|
|
|
1114
1222
|
if (viewModels && inputs.some(
|
|
1115
1223
|
({ file, bytes }) => sources.includes(file) && bytes.includes("ViewModel")
|
|
1116
1224
|
)) {
|
|
1117
|
-
await compileKlib(
|
|
1118
|
-
const { stdout } = await
|
|
1119
|
-
|
|
1225
|
+
await compileKlib(import_node_path5.default.join(work, "abi"));
|
|
1226
|
+
const { stdout } = await run3(
|
|
1227
|
+
import_node_path5.default.join(import_node_path5.default.dirname(kotlinc), "kotlin"),
|
|
1120
1228
|
[
|
|
1121
1229
|
"-cp",
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1230
|
+
[
|
|
1231
|
+
import_node_path5.default.resolve(import_node_path5.default.dirname(kotlinc), "../lib/kotlin-compiler.jar"),
|
|
1232
|
+
import_node_path5.default.join(sdk.root, "tools.jar")
|
|
1233
|
+
].join(import_node_path5.default.delimiter),
|
|
1234
|
+
viewModels.toolClass,
|
|
1235
|
+
import_node_path5.default.join(work, "abi")
|
|
1126
1236
|
],
|
|
1127
1237
|
{ maxBuffer: 64 * 1024 * 1024 }
|
|
1128
1238
|
);
|
|
1129
|
-
|
|
1130
|
-
|
|
1239
|
+
import_node_fs4.default.writeFileSync(
|
|
1240
|
+
import_node_path5.default.join(generatedDir, viewModels.file),
|
|
1131
1241
|
viewModels.render(viewModelClasses(readAbiClasses(stdout)))
|
|
1132
1242
|
);
|
|
1133
1243
|
}
|
|
1134
|
-
await compileKlib(
|
|
1135
|
-
await
|
|
1244
|
+
await compileKlib(import_node_path5.default.join(work, "klib"));
|
|
1245
|
+
await run3(
|
|
1136
1246
|
kotlinc,
|
|
1137
1247
|
[
|
|
1138
1248
|
...common,
|
|
1139
1249
|
"-nowarn",
|
|
1140
|
-
`-Xinclude=${
|
|
1250
|
+
`-Xinclude=${import_node_path5.default.join(work, "klib")}`,
|
|
1141
1251
|
"-Xir-produce-js",
|
|
1142
1252
|
"-ir-output-dir",
|
|
1143
|
-
|
|
1253
|
+
import_node_path5.default.join(work, "js"),
|
|
1144
1254
|
"-ir-output-name",
|
|
1145
1255
|
"app"
|
|
1146
1256
|
],
|
|
1147
1257
|
{ maxBuffer: 16 * 1024 * 1024 }
|
|
1148
1258
|
);
|
|
1149
1259
|
if (usesCompose) {
|
|
1150
|
-
await
|
|
1260
|
+
await run3("unzip", [
|
|
1151
1261
|
"-q",
|
|
1152
1262
|
"-j",
|
|
1153
1263
|
composeRuntime,
|
|
1154
1264
|
"skiko.mjs",
|
|
1155
1265
|
"-d",
|
|
1156
|
-
|
|
1266
|
+
import_node_path5.default.join(work, "js")
|
|
1157
1267
|
]);
|
|
1158
|
-
const skikoPath =
|
|
1159
|
-
const upstream = (0, import_acorn.parse)(
|
|
1268
|
+
const skikoPath = import_node_path5.default.join(work, "js", "skiko.mjs");
|
|
1269
|
+
const upstream = (0, import_acorn.parse)(import_node_fs4.default.readFileSync(skikoPath, "utf8"), {
|
|
1160
1270
|
ecmaVersion: "latest",
|
|
1161
1271
|
sourceType: "module"
|
|
1162
1272
|
});
|
|
@@ -1179,7 +1289,7 @@ async function compileKotlin(input, origin) {
|
|
|
1179
1289
|
"GL",
|
|
1180
1290
|
...bindings
|
|
1181
1291
|
];
|
|
1182
|
-
|
|
1292
|
+
import_node_fs4.default.writeFileSync(
|
|
1183
1293
|
skikoPath,
|
|
1184
1294
|
[
|
|
1185
1295
|
"const runtime = globalThis.__peachKotlinSkiko;",
|
|
@@ -1193,10 +1303,10 @@ async function compileKotlin(input, origin) {
|
|
|
1193
1303
|
if (usesCompose) {
|
|
1194
1304
|
for (const library of toolchain.composeJsLibraries) {
|
|
1195
1305
|
let imported = false;
|
|
1196
|
-
for (const file of
|
|
1306
|
+
for (const file of import_node_fs4.default.readdirSync(import_node_path5.default.join(work, "js"))) {
|
|
1197
1307
|
if (!file.endsWith(".mjs")) continue;
|
|
1198
|
-
const target =
|
|
1199
|
-
const source =
|
|
1308
|
+
const target = import_node_path5.default.join(work, "js", file);
|
|
1309
|
+
const source = import_node_fs4.default.readFileSync(target, "utf8");
|
|
1200
1310
|
let next = source;
|
|
1201
1311
|
for (const quote of ["'", '"'])
|
|
1202
1312
|
next = next.replaceAll(
|
|
@@ -1204,29 +1314,29 @@ async function compileKotlin(input, origin) {
|
|
|
1204
1314
|
`from ${quote}./${library.file}${quote}`
|
|
1205
1315
|
);
|
|
1206
1316
|
if (next === source) continue;
|
|
1207
|
-
|
|
1317
|
+
import_node_fs4.default.writeFileSync(target, next);
|
|
1208
1318
|
imported = true;
|
|
1209
1319
|
}
|
|
1210
1320
|
if (!imported) continue;
|
|
1211
|
-
const archive =
|
|
1321
|
+
const archive = import_node_path5.default.join(
|
|
1212
1322
|
kotlinHome(),
|
|
1213
1323
|
toolchain.compiler.version,
|
|
1214
1324
|
library.name
|
|
1215
1325
|
);
|
|
1216
1326
|
await fetchVerified(library, archive);
|
|
1217
|
-
const { stdout } = await
|
|
1327
|
+
const { stdout } = await run3("tar", ["-xOf", archive, library.archiveEntry], {
|
|
1218
1328
|
maxBuffer: 16 * 1024 * 1024
|
|
1219
1329
|
});
|
|
1220
|
-
|
|
1330
|
+
import_node_fs4.default.writeFileSync(import_node_path5.default.join(work, "js", library.file), stdout);
|
|
1221
1331
|
}
|
|
1222
1332
|
}
|
|
1223
1333
|
} catch (error) {
|
|
1224
|
-
|
|
1334
|
+
import_node_fs4.default.rmSync(work, { recursive: true, force: true });
|
|
1225
1335
|
let output = isRecord(error) ? `${String(error.stderr ?? "")}${String(error.stdout ?? "")}` : "";
|
|
1226
1336
|
for (const [name, source] of Object.entries(origins))
|
|
1227
|
-
output = output.replaceAll(
|
|
1337
|
+
output = output.replaceAll(import_node_path5.default.join(generatedDir, name), source);
|
|
1228
1338
|
for (const { file, target } of compiledSources)
|
|
1229
|
-
output = output.replaceAll(target, file).replaceAll(
|
|
1339
|
+
output = output.replaceAll(target, file).replaceAll(import_node_path5.default.relative(process.cwd(), target), file);
|
|
1230
1340
|
throw new Error(
|
|
1231
1341
|
`kotlin compile failed:
|
|
1232
1342
|
${output.trim() || (error instanceof Error ? error.message : String(error))}`
|
|
@@ -1235,9 +1345,9 @@ ${output.trim() || (error instanceof Error ? error.message : String(error))}`
|
|
|
1235
1345
|
const seams = [
|
|
1236
1346
|
["process.release.name", "process.release?.name"]
|
|
1237
1347
|
];
|
|
1238
|
-
const js =
|
|
1348
|
+
const js = import_node_fs4.default.readdirSync(import_node_path5.default.join(work, "js")).filter((file) => file.endsWith(".mjs"));
|
|
1239
1349
|
if (js.some(
|
|
1240
|
-
(file) =>
|
|
1350
|
+
(file) => import_node_fs4.default.readFileSync(import_node_path5.default.join(work, "js", file), "utf8").includes("'kotlinx.coroutines.")
|
|
1241
1351
|
))
|
|
1242
1352
|
seams.push([
|
|
1243
1353
|
"(typeof(window) !== 'undefined' && window != null && typeof(window.addEventListener) === 'function') ? window : null",
|
|
@@ -1246,12 +1356,12 @@ ${output.trim() || (error instanceof Error ? error.message : String(error))}`
|
|
|
1246
1356
|
for (const [from, to] of seams) {
|
|
1247
1357
|
let patched = 0;
|
|
1248
1358
|
for (const file of js) {
|
|
1249
|
-
const target =
|
|
1250
|
-
const text =
|
|
1359
|
+
const target = import_node_path5.default.join(work, "js", file);
|
|
1360
|
+
const text = import_node_fs4.default.readFileSync(target, "utf8");
|
|
1251
1361
|
const next = text.replaceAll(from, to);
|
|
1252
1362
|
if (next !== text) {
|
|
1253
1363
|
patched++;
|
|
1254
|
-
|
|
1364
|
+
import_node_fs4.default.writeFileSync(target, next);
|
|
1255
1365
|
}
|
|
1256
1366
|
}
|
|
1257
1367
|
if (patched === 0)
|
|
@@ -1259,11 +1369,32 @@ ${output.trim() || (error instanceof Error ? error.message : String(error))}`
|
|
|
1259
1369
|
`kotlin output no longer contains ${from}; recheck how it detects its host in Peach`
|
|
1260
1370
|
);
|
|
1261
1371
|
}
|
|
1372
|
+
const entry = import_node_path5.default.join(work, "js/app.mjs");
|
|
1373
|
+
const entrySource2 = import_node_fs4.default.readFileSync(entry, "utf8");
|
|
1374
|
+
const hasDefault = (0, import_acorn.parse)(entrySource2, {
|
|
1375
|
+
ecmaVersion: "latest",
|
|
1376
|
+
sourceType: "module"
|
|
1377
|
+
}).body.some(
|
|
1378
|
+
(statement) => statement.type === "ExportDefaultDeclaration" || statement.type === "ExportNamedDeclaration" && statement.specifiers.some(
|
|
1379
|
+
(specifier) => specifier.exported.type === "Identifier" && specifier.exported.name === "default"
|
|
1380
|
+
)
|
|
1381
|
+
);
|
|
1382
|
+
import_node_fs4.default.renameSync(entry, import_node_path5.default.join(work, "js/app-runtime.mjs"));
|
|
1383
|
+
import_node_fs4.default.writeFileSync(
|
|
1384
|
+
entry,
|
|
1385
|
+
[
|
|
1386
|
+
"export * from './app-runtime.mjs';",
|
|
1387
|
+
...hasDefault ? ["export { default } from './app-runtime.mjs';"] : [],
|
|
1388
|
+
"import { peachInitializeModuleBindings } from './app-runtime.mjs';",
|
|
1389
|
+
"peachInitializeModuleBindings();",
|
|
1390
|
+
""
|
|
1391
|
+
].join("\n")
|
|
1392
|
+
);
|
|
1262
1393
|
try {
|
|
1263
|
-
|
|
1394
|
+
import_node_fs4.default.renameSync(work, out);
|
|
1264
1395
|
} catch (error) {
|
|
1265
|
-
if (!
|
|
1266
|
-
|
|
1396
|
+
if (!import_node_fs4.default.existsSync(import_node_path5.default.join(out, "js", "app.wasm"))) throw error;
|
|
1397
|
+
import_node_fs4.default.rmSync(work, { recursive: true, force: true });
|
|
1267
1398
|
}
|
|
1268
1399
|
return artifact;
|
|
1269
1400
|
})().finally(() => builds.delete(hash));
|
|
@@ -1275,24 +1406,24 @@ var CONTENT_TYPES = {
|
|
|
1275
1406
|
".wasm": "application/wasm"
|
|
1276
1407
|
};
|
|
1277
1408
|
function kotlinArtifactFiles(hash) {
|
|
1278
|
-
const dir =
|
|
1279
|
-
return
|
|
1280
|
-
const contentType = CONTENT_TYPES[
|
|
1409
|
+
const dir = import_node_path5.default.join(buildsDir(), hash, "js");
|
|
1410
|
+
return import_node_fs4.default.readdirSync(dir).sort().map((name) => {
|
|
1411
|
+
const contentType = CONTENT_TYPES[import_node_path5.default.extname(name)];
|
|
1281
1412
|
if (!contentType) throw new Error(`unexpected kotlin artifact file ${name}`);
|
|
1282
|
-
return { name, bytes:
|
|
1413
|
+
return { name, bytes: import_node_fs4.default.readFileSync(import_node_path5.default.join(dir, name)), contentType };
|
|
1283
1414
|
});
|
|
1284
1415
|
}
|
|
1285
1416
|
function serveKotlinArtifact(pathname, res) {
|
|
1286
1417
|
if (!pathname.startsWith(KOTLIN_ARTIFACT_PREFIX)) return false;
|
|
1287
1418
|
const [hash, file, ...rest] = pathname.slice(KOTLIN_ARTIFACT_PREFIX.length).split("/");
|
|
1288
|
-
const type = file ? CONTENT_TYPES[
|
|
1419
|
+
const type = file ? CONTENT_TYPES[import_node_path5.default.extname(file)] : void 0;
|
|
1289
1420
|
if (!hash || !/^[0-9a-f]+$/.test(hash) || !file || rest.length > 0 || !type || file.includes("..")) {
|
|
1290
1421
|
res.statusCode = 404;
|
|
1291
1422
|
res.end("not a kotlin artifact");
|
|
1292
1423
|
return true;
|
|
1293
1424
|
}
|
|
1294
|
-
const target =
|
|
1295
|
-
if (!
|
|
1425
|
+
const target = import_node_path5.default.join(buildsDir(), hash, "js", file);
|
|
1426
|
+
if (!import_node_fs4.default.existsSync(target)) {
|
|
1296
1427
|
res.statusCode = 404;
|
|
1297
1428
|
res.end(`kotlin artifact ${hash}/${file} was not built`);
|
|
1298
1429
|
return true;
|
|
@@ -1300,7 +1431,7 @@ function serveKotlinArtifact(pathname, res) {
|
|
|
1300
1431
|
res.setHeader("access-control-allow-origin", "*");
|
|
1301
1432
|
res.setHeader("content-type", type);
|
|
1302
1433
|
res.setHeader("cache-control", "public, max-age=31536000, immutable");
|
|
1303
|
-
res.end(
|
|
1434
|
+
res.end(import_node_fs4.default.readFileSync(target));
|
|
1304
1435
|
return true;
|
|
1305
1436
|
}
|
|
1306
1437
|
var KOTLIN_PACKAGE_PATH = "/__peach/kotlin-package";
|