peachsim 0.1.2610 → 0.1.2612
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/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 +2 -2
- package/dist-lib/bridge-constants.cjs +1 -1
- package/dist-lib/bridge-contract-input.cjs +1 -1
- package/dist-lib/bridge-contract-input.mjs +5 -5
- package/dist-lib/bridge-contract.cjs +1 -1
- package/dist-lib/bridge-contract.mjs +3 -3
- package/dist-lib/bundle-channel.cjs +1213 -684
- package/dist-lib/capture-contract.cjs +1 -1
- package/dist-lib/capture-contract.mjs +3 -3
- package/dist-lib/cloud-contract.cjs +1 -1
- package/dist-lib/cloud-contract.mjs +3 -3
- package/dist-lib/cloud-test-args.cjs +1 -1
- package/dist-lib/cloud-test-args.mjs +2 -2
- package/dist-lib/cloud.cjs +1 -1
- package/dist-lib/cloud.mjs +7 -7
- package/dist-lib/config.cjs +1 -1
- package/dist-lib/config.mjs +5 -5
- package/dist-lib/detox/index.cjs +1 -1
- package/dist-lib/dev-bundle-resolution.cjs +1 -1
- package/dist-lib/esm-chunks/{acorn-L2SFCOHG.mjs → acorn-QO4N4OBM.mjs} +3 -3
- package/dist-lib/esm-chunks/{chunk-MK4DOEDN.mjs → chunk-252KNQUF.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-ZZB2LFYV.mjs → chunk-3ZTDI2MF.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-WZHEW7Z7.mjs → chunk-4JTACUL3.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-WBQFHIGS.mjs → chunk-6VWQEI2U.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-FP447MCW.mjs → chunk-6ZP7JWNX.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-X74N3K5N.mjs → chunk-7OAXAYW7.mjs} +4 -4
- package/dist-lib/esm-chunks/{chunk-XN74REO2.mjs → chunk-BWWPWGZW.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-W3LNUIUA.mjs → chunk-GRDRKYB5.mjs} +6 -6
- package/dist-lib/esm-chunks/{chunk-VDLPNJ6P.mjs → chunk-HEPU5HEE.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-2LJTZ2KG.mjs → chunk-HHQHP6NX.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-MJP4WOSX.mjs → chunk-HQGPI7FM.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-RN73P2DY.mjs → chunk-LDYLSTVC.mjs} +5 -5
- package/dist-lib/esm-chunks/{chunk-YLUD2UET.mjs → chunk-O5VA25UA.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-CUBTZPSZ.mjs → chunk-PDKX5WGD.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-KTAGV5U6.mjs → chunk-PPDXMRAA.mjs} +6 -6
- package/dist-lib/esm-chunks/{chunk-EYSNLE5V.mjs → chunk-THHH7IPK.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-N3M5KT33.mjs → chunk-UGPX2JTI.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-73NIGS7D.mjs → chunk-VAIU3RSQ.mjs} +14 -14
- package/dist-lib/esm-chunks/{chunk-N7XU2WWO.mjs → chunk-VM5QGKMB.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-HMTSU22Q.mjs → chunk-WMQA6U5H.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-EU5WMP5O.mjs → chunk-WTTIS3AY.mjs} +2 -2
- package/dist-lib/esm-chunks/{chunk-YVLXYLNV.mjs → chunk-XPVBWRWY.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-42NDD4R7.mjs → chunk-YAK7RNDV.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-YYGSN3BN.mjs → chunk-ZRJG25JE.mjs} +3 -3
- package/dist-lib/esm-chunks/{metro-layout-parser-VDPXJ7LW.mjs → metro-layout-parser-UUA4AJ2Q.mjs} +3 -3
- package/dist-lib/esm-chunks/{swift-package-prebuilt-HRPDLN2P.mjs → swift-package-prebuilt-EVJIROFN.mjs} +12 -12
- package/dist-lib/esm-chunks/{swift-sdk-app-module-5DOGMU3M.mjs → swift-sdk-app-module-M5TKMPU6.mjs} +16 -16
- package/dist-lib/esm-chunks/{swift-sdk-image-W3UU4H4L.mjs → swift-sdk-image-4FST3VAH.mjs} +16 -16
- package/dist-lib/esm-chunks/{swift-sdk-image-producer-OJWD6ZOH.mjs → swift-sdk-image-producer-4DUU7RUD.mjs} +5 -5
- package/dist-lib/expo-swift-bundle.cjs +11 -6
- package/dist-lib/expo-swift-metadata.cjs +1 -1
- package/dist-lib/expo-swift-metadata.mjs +7 -7
- package/dist-lib/home-paths.cjs +1 -1
- package/dist-lib/host/bridge-host.cjs +1544 -1015
- package/dist-lib/host/fetch-proxy-handler.cjs +2 -2
- package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
- package/dist-lib/host/fetch-proxy-overrides.mjs +2 -2
- package/dist-lib/host/replacement-module-handler.cjs +1 -1
- package/dist-lib/host/websocket-proxy.cjs +1 -1
- package/dist-lib/index.cjs +1 -1
- package/dist-lib/kotlin-host.cjs +676 -171
- package/dist-lib/menu.cjs +1 -1
- package/dist-lib/menu.mjs +3 -3
- package/dist-lib/metro-fingerprint-registry.cjs +1 -1
- package/dist-lib/metro-fingerprint-registry.mjs +3 -3
- package/dist-lib/metro-production-bundle.cjs +1 -1
- package/dist-lib/metro-production-bundle.mjs +4 -4
- package/dist-lib/native-app-identity-project.cjs +1 -1
- package/dist-lib/native-app-identity-project.mjs +15 -15
- package/dist-lib/native-app-identity.cjs +1 -1
- package/dist-lib/native-app-identity.mjs +6 -6
- package/dist-lib/native-firebase-metadata.cjs +1 -1
- package/dist-lib/native-firebase-metadata.mjs +3 -3
- package/dist-lib/pdfium-raster.cjs +1 -1
- package/dist-lib/pdfium-raster.mjs +2 -2
- package/dist-lib/plist.cjs +1 -1
- package/dist-lib/plist.mjs +3 -3
- package/dist-lib/profiles.cjs +1 -1
- package/dist-lib/public-brand.cjs +1 -1
- package/dist-lib/public-origins-lib-esm.json +85 -85
- package/dist-lib/public-origins-lib.json +76 -65
- package/dist-lib/react-native-host-modules.cjs +1 -1
- package/dist-lib/react-native-host-modules.mjs +2 -2
- package/dist-lib/reap-browser.cjs +1 -1
- package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
- package/dist-lib/sdk.cjs +1 -1
- package/dist-lib/sdk.mjs +8 -8
- package/dist-lib/skills.cjs +2100 -1632
- package/dist-lib/swift-compile.cjs +1 -1
- package/dist-lib/swift-compile.mjs +12 -12
- package/dist-lib/swift-package.cjs +1 -1
- package/dist-lib/swift-package.mjs +3 -3
- package/dist-lib/swift-submit.cjs +1 -1
- package/dist-lib/swift-submit.mjs +6 -6
- package/dist-lib/swift-svg-raster.cjs +1 -1
- package/dist-lib/swift-svg-raster.mjs +2 -2
- package/dist-lib/swift-toolchain.cjs +1 -1
- package/dist-lib/swift.cjs +1 -1
- package/dist-lib/vendor/@peculiar/x509.cjs +1 -1
- package/dist-lib/vendor/@ruby/prism/src/nodes.js.cjs +1 -1
- package/dist-lib/vendor/@ruby/prism/src/parsePrism.js.cjs +1 -1
- package/dist-lib/vendor/acorn.cjs +1 -1
- package/dist-lib/vendor/magic-string.cjs +1 -1
- package/dist-lib/vendor/stream-json.cjs +1 -1
- package/dist-lib/vendor/sucrase/dist/index.js.cjs +1 -1
- package/dist-lib/vendor/sucrase/dist/parser/index.js.cjs +1 -1
- package/dist-lib/vendor/sucrase/dist/parser/tokenizer/index.js.cjs +1 -1
- package/dist-lib/vendor/sucrase/dist/parser/tokenizer/types.js.cjs +1 -1
- package/dist-lib/vendor/sucrase.cjs +1 -1
- package/dist-lib/vendor/terser.cjs +1 -1
- package/dist-lib/vendor/valibot.cjs +1 -1
- package/dist-lib/vendor/ws.cjs +1 -1
- package/dist-lib/vendor/zod.cjs +1 -1
- package/dist-lib/worklet-executable.cjs +1 -1
- package/dist-lib/worklet-executable.mjs +3 -3
- package/package.json +1 -1
- package/src/android-gradle-sources.ts +97 -2
- package/src/androidGradleContract.ts +11 -0
- package/src/gitignore.ts +9 -4
- package/src/kotlin-app.ts +37 -4
- package/src/kotlin-gradle-library-plan.ts +142 -0
- package/src/kotlin-host.ts +32 -3
- package/src/kotlin-library-sources.ts +320 -0
- package/src/kotlin-maven-sources.ts +0 -7
package/dist-lib/kotlin-host.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! peach v0.1.
|
|
1
|
+
/*! peach v0.1.2612 | (c) 2026 Tamagui LLC | Proprietary; see LICENSE */
|
|
2
2
|
let __sootsim_import_meta_url = '', __sootsim_import_meta_dirname = '', __sootsim_import_meta_filename = ''; try { __sootsim_import_meta_url = require('url').pathToFileURL(__filename).href; __sootsim_import_meta_dirname = __dirname; __sootsim_import_meta_filename = __filename; } catch {}
|
|
3
3
|
"use strict";
|
|
4
4
|
var __create = Object.create;
|
|
@@ -914,8 +914,8 @@ async function ensureCompose(toolchain) {
|
|
|
914
914
|
}
|
|
915
915
|
function ensureToolchain(toolchain) {
|
|
916
916
|
const key = JSON.stringify(toolchain);
|
|
917
|
-
const
|
|
918
|
-
if (
|
|
917
|
+
const pending2 = toolchains.get(key);
|
|
918
|
+
if (pending2) return pending2;
|
|
919
919
|
const ready = (async () => {
|
|
920
920
|
const dir = import_node_path6.default.join(kotlinHome(), toolchain.compiler.version);
|
|
921
921
|
const compilerDir = import_node_path6.default.join(dir, `compiler-${toolchain.compiler.sha256}`);
|
|
@@ -1001,16 +1001,16 @@ async function resolveAndroidGradleSources(request) {
|
|
|
1001
1001
|
includeDependencySources = false
|
|
1002
1002
|
} = request;
|
|
1003
1003
|
if (projectDirs.length === 0) return [];
|
|
1004
|
-
if (!
|
|
1004
|
+
if (!import_node_path14.default.isAbsolute(root) || projectDirs.some((dir) => !import_node_path14.default.isAbsolute(dir)))
|
|
1005
1005
|
throw new Error("Android Gradle source selection requires absolute project paths");
|
|
1006
1006
|
if (!variant) throw new Error("Android Gradle source selection requires a variant");
|
|
1007
|
-
root =
|
|
1008
|
-
const projects = [...new Set(projectDirs.map((dir) =>
|
|
1009
|
-
const parent =
|
|
1010
|
-
|
|
1011
|
-
const work =
|
|
1012
|
-
const task = `peachAndroidSources${(0,
|
|
1013
|
-
const script =
|
|
1007
|
+
root = import_node_fs15.default.realpathSync(root);
|
|
1008
|
+
const projects = [...new Set(projectDirs.map((dir) => import_node_fs15.default.realpathSync(dir)))];
|
|
1009
|
+
const parent = import_node_path14.default.join(kotlinHome(), "gradle-sources");
|
|
1010
|
+
import_node_fs15.default.mkdirSync(parent, { recursive: true });
|
|
1011
|
+
const work = import_node_fs15.default.mkdtempSync(import_node_path14.default.join(parent, ".query-"));
|
|
1012
|
+
const task = `peachAndroidSources${(0, import_node_crypto10.randomBytes)(8).toString("hex")}`;
|
|
1013
|
+
const script = import_node_path14.default.join(work, "sources.gradle");
|
|
1014
1014
|
const encoded = Buffer.from(
|
|
1015
1015
|
JSON.stringify({
|
|
1016
1016
|
root,
|
|
@@ -1024,12 +1024,12 @@ async function resolveAndroidGradleSources(request) {
|
|
|
1024
1024
|
task
|
|
1025
1025
|
})
|
|
1026
1026
|
).toString("base64");
|
|
1027
|
-
|
|
1027
|
+
import_node_fs15.default.writeFileSync(script, modelQuery.replace("__PEACH_REQUEST__", encoded));
|
|
1028
1028
|
try {
|
|
1029
1029
|
await run4(
|
|
1030
1030
|
"bash",
|
|
1031
1031
|
[
|
|
1032
|
-
|
|
1032
|
+
import_node_path14.default.join(root, "gradlew"),
|
|
1033
1033
|
"--init-script",
|
|
1034
1034
|
script,
|
|
1035
1035
|
`${task}All`,
|
|
@@ -1048,19 +1048,19 @@ async function resolveAndroidGradleSources(request) {
|
|
|
1048
1048
|
);
|
|
1049
1049
|
return projects.map((projectDir, index) => {
|
|
1050
1050
|
const value = JSON.parse(
|
|
1051
|
-
|
|
1051
|
+
import_node_fs15.default.readFileSync(import_node_path14.default.join(work, `${index}.json`), "utf8")
|
|
1052
1052
|
);
|
|
1053
1053
|
if (!isRecord(value) || value.projectDir !== projectDir || value.variant !== variant || typeof value.projectPath !== "string" || value.applicationId !== null && typeof value.applicationId !== "string" || typeof value.namespace !== "string" || !value.namespace || value.targetSdk !== null && (typeof value.targetSdk !== "number" || !Number.isInteger(value.targetSdk) || value.targetSdk <= 0))
|
|
1054
1054
|
throw new Error("Gradle printed an invalid Android project source model");
|
|
1055
1055
|
const paths = (field) => {
|
|
1056
1056
|
const list = value[field];
|
|
1057
|
-
if (!Array.isArray(list) || !list.every((file) => typeof file === "string" &&
|
|
1057
|
+
if (!Array.isArray(list) || !list.every((file) => typeof file === "string" && import_node_path14.default.isAbsolute(file)))
|
|
1058
1058
|
throw new Error(`Gradle printed invalid Android ${field} paths`);
|
|
1059
1059
|
return list.map(String);
|
|
1060
1060
|
};
|
|
1061
1061
|
const linkedResource = (field) => {
|
|
1062
1062
|
const file = value[field];
|
|
1063
|
-
if (typeof file !== "string" || !
|
|
1063
|
+
if (typeof file !== "string" || !import_node_path14.default.isAbsolute(file) || !import_node_fs15.default.statSync(file, { throwIfNoEntry: false })?.isFile())
|
|
1064
1064
|
throw new Error(`Gradle did not produce ${field} for ${projectDir}:${variant}`);
|
|
1065
1065
|
return file;
|
|
1066
1066
|
};
|
|
@@ -1088,6 +1088,7 @@ async function resolveAndroidGradleSources(request) {
|
|
|
1088
1088
|
}
|
|
1089
1089
|
);
|
|
1090
1090
|
const dependencySources = includeDependencySources ? readDependencySources(value.dependencySources) : void 0;
|
|
1091
|
+
const dependencyGraph = includeDependencySources ? readDependencyGraph(value.dependencyGraph) : void 0;
|
|
1091
1092
|
return {
|
|
1092
1093
|
projectDir,
|
|
1093
1094
|
projectPath: value.projectPath,
|
|
@@ -1105,18 +1106,48 @@ async function resolveAndroidGradleSources(request) {
|
|
|
1105
1106
|
linkedResourcePackage: linkedResource("linkedResourcePackage")
|
|
1106
1107
|
} : {},
|
|
1107
1108
|
dependencies,
|
|
1108
|
-
...dependencySources ? { dependencySources } : {}
|
|
1109
|
+
...dependencySources ? { dependencySources, dependencyGraph } : {}
|
|
1109
1110
|
};
|
|
1110
1111
|
});
|
|
1111
1112
|
} finally {
|
|
1112
|
-
|
|
1113
|
+
import_node_fs15.default.rmSync(work, { recursive: true, force: true });
|
|
1113
1114
|
}
|
|
1114
1115
|
}
|
|
1116
|
+
function readDependencyGraph(value) {
|
|
1117
|
+
if (!isRecord(value) || !Array.isArray(value.javaClasspath) || !value.javaClasspath.every(
|
|
1118
|
+
(file) => typeof file === "string" && import_node_path14.default.isAbsolute(file)
|
|
1119
|
+
)) {
|
|
1120
|
+
throw new Error("Gradle printed invalid module graphs");
|
|
1121
|
+
}
|
|
1122
|
+
return {
|
|
1123
|
+
compile: readModules(value.compile),
|
|
1124
|
+
runtime: readModules(value.runtime),
|
|
1125
|
+
javaClasspath: value.javaClasspath.map(String)
|
|
1126
|
+
};
|
|
1127
|
+
}
|
|
1128
|
+
function readModules(value) {
|
|
1129
|
+
if (!Array.isArray(value)) throw new Error("Gradle printed an invalid module graph");
|
|
1130
|
+
const modules = value.map((entry) => {
|
|
1131
|
+
if (!isRecord(entry) || typeof entry.coordinate !== "string" || !/^[^:]+:[^:]+:[^:]+$/.test(entry.coordinate) || !Array.isArray(entry.dependencies) || !entry.dependencies.every((coordinate) => typeof coordinate === "string") || !Array.isArray(entry.jars) || !entry.jars.every((file) => typeof file === "string" && import_node_path14.default.isAbsolute(file)))
|
|
1132
|
+
throw new Error("Gradle printed an invalid module");
|
|
1133
|
+
return {
|
|
1134
|
+
coordinate: entry.coordinate,
|
|
1135
|
+
dependencies: entry.dependencies.map(String),
|
|
1136
|
+
jars: entry.jars.map(String)
|
|
1137
|
+
};
|
|
1138
|
+
});
|
|
1139
|
+
const coordinates = new Set(modules.map(({ coordinate }) => coordinate));
|
|
1140
|
+
if (coordinates.size !== modules.length || modules.some(
|
|
1141
|
+
({ dependencies }) => dependencies.some((dependency) => !coordinates.has(dependency))
|
|
1142
|
+
))
|
|
1143
|
+
throw new Error("Gradle printed duplicate modules or unresolved module edges");
|
|
1144
|
+
return modules;
|
|
1145
|
+
}
|
|
1115
1146
|
function readDependencySources(value) {
|
|
1116
1147
|
if (!Array.isArray(value)) throw new Error("Gradle printed invalid dependency sources");
|
|
1117
1148
|
const coordinates = /* @__PURE__ */ new Set();
|
|
1118
1149
|
return value.map((entry) => {
|
|
1119
|
-
if (!isRecord(entry) || typeof entry.group !== "string" || !entry.group || typeof entry.name !== "string" || !entry.name || typeof entry.version !== "string" || !entry.version || typeof entry.archive !== "string" || !
|
|
1150
|
+
if (!isRecord(entry) || typeof entry.group !== "string" || !entry.group || typeof entry.name !== "string" || !entry.name || typeof entry.version !== "string" || !entry.version || typeof entry.archive !== "string" || !import_node_path14.default.isAbsolute(entry.archive) || !import_node_fs15.default.statSync(entry.archive, { throwIfNoEntry: false })?.isFile())
|
|
1120
1151
|
throw new Error("Gradle printed an invalid dependency sources archive");
|
|
1121
1152
|
const coordinate = `${entry.group}:${entry.name}:${entry.version}`;
|
|
1122
1153
|
if (coordinates.has(coordinate))
|
|
@@ -1130,19 +1161,19 @@ function readDependencySources(value) {
|
|
|
1130
1161
|
};
|
|
1131
1162
|
});
|
|
1132
1163
|
}
|
|
1133
|
-
var
|
|
1164
|
+
var import_node_child_process9, import_node_crypto10, import_node_fs15, import_node_path14, import_node_util5, run4, modelQuery;
|
|
1134
1165
|
var init_android_gradle_sources = __esm({
|
|
1135
1166
|
"src/android-gradle-sources.ts"() {
|
|
1136
1167
|
"use strict";
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1168
|
+
import_node_child_process9 = require("node:child_process");
|
|
1169
|
+
import_node_crypto10 = require("node:crypto");
|
|
1170
|
+
import_node_fs15 = __toESM(require("node:fs"), 1);
|
|
1171
|
+
import_node_path14 = __toESM(require("node:path"), 1);
|
|
1141
1172
|
import_node_util5 = require("node:util");
|
|
1142
1173
|
init_forked_script_contract();
|
|
1143
1174
|
init_is_record();
|
|
1144
1175
|
init_kotlin_toolchain();
|
|
1145
|
-
run4 = (0, import_node_util5.promisify)(
|
|
1176
|
+
run4 = (0, import_node_util5.promisify)(import_node_child_process9.execFile);
|
|
1146
1177
|
modelQuery = `
|
|
1147
1178
|
import groovy.json.JsonOutput
|
|
1148
1179
|
import groovy.json.JsonSlurper
|
|
@@ -1173,6 +1204,42 @@ def resolveDependencySources = { project, configurations ->
|
|
|
1173
1204
|
}
|
|
1174
1205
|
}.sort { it.group + ':' + it.name + ':' + it.version }
|
|
1175
1206
|
}
|
|
1207
|
+
def moduleCoordinate = { id -> id.group + ':' + id.module + ':' + id.version }
|
|
1208
|
+
def resolveModuleGraph = { configuration ->
|
|
1209
|
+
def classArtifacts = configuration.incoming.artifactView { view ->
|
|
1210
|
+
view.attributes.attribute(ArtifactTypeDefinition.ARTIFACT_TYPE_ATTRIBUTE, 'android-classes-jar')
|
|
1211
|
+
}.artifacts.artifacts.findAll { it.id.componentIdentifier instanceof ModuleComponentIdentifier }
|
|
1212
|
+
def classJars = classArtifacts.groupBy { moduleCoordinate(it.id.componentIdentifier) }
|
|
1213
|
+
def resolution = configuration.incoming.resolutionResult
|
|
1214
|
+
def byCoordinate = [:]
|
|
1215
|
+
def seen = [] as Set
|
|
1216
|
+
def visit
|
|
1217
|
+
visit = { component, selectedVariant ->
|
|
1218
|
+
if (!seen.add([component.id, selectedVariant])) return
|
|
1219
|
+
def edges = component.getDependenciesForVariant(selectedVariant).findAll { edge ->
|
|
1220
|
+
if (edge.constraint) return false
|
|
1221
|
+
if (!(edge instanceof ResolvedDependencyResult)) {
|
|
1222
|
+
throw new GradleException('Unresolved Android dependency: ' + edge.requested, edge.failure)
|
|
1223
|
+
}
|
|
1224
|
+
def category = edge.resolvedVariant.attributes.getAttribute(Category.CATEGORY_ATTRIBUTE)?.name
|
|
1225
|
+
category != Category.REGULAR_PLATFORM && category != Category.ENFORCED_PLATFORM
|
|
1226
|
+
}
|
|
1227
|
+
if (component.id instanceof ModuleComponentIdentifier) {
|
|
1228
|
+
def coordinate = moduleCoordinate(component.id)
|
|
1229
|
+
def entry = byCoordinate.get(coordinate, [coordinate:coordinate, dependencies:[] as Set,
|
|
1230
|
+
jars:classJars.get(coordinate, []).collect { it.file.absolutePath }.unique().sort()])
|
|
1231
|
+
edges.findAll { it.selected.id instanceof ModuleComponentIdentifier }.each { edge ->
|
|
1232
|
+
entry.dependencies.add(moduleCoordinate(edge.selected.id))
|
|
1233
|
+
}
|
|
1234
|
+
}
|
|
1235
|
+
edges.each { edge -> visit(edge.selected, edge.resolvedVariant) }
|
|
1236
|
+
}
|
|
1237
|
+
visit(resolution.rootComponent.get(), resolution.rootVariant.get())
|
|
1238
|
+
def modules = byCoordinate.values().collect { entry ->
|
|
1239
|
+
[coordinate:entry.coordinate, dependencies:entry.dependencies.toList().sort(), jars:entry.jars]
|
|
1240
|
+
}.sort { it.coordinate }
|
|
1241
|
+
[modules:modules, classpath:classArtifacts.collect { it.file.absolutePath }.unique()]
|
|
1242
|
+
}
|
|
1176
1243
|
gradle.beforeProject { project ->
|
|
1177
1244
|
def directory = project.projectDir.canonicalPath
|
|
1178
1245
|
if (project.rootProject.projectDir.canonicalPath != request.root || !request.projects.contains(directory)) return
|
|
@@ -1276,10 +1343,17 @@ gradle.projectsEvaluated {
|
|
|
1276
1343
|
linkedResourcePackage = packages[0].outputFile
|
|
1277
1344
|
}
|
|
1278
1345
|
def bootClasspath = []
|
|
1279
|
-
if (request.includeJavaClasspath || runtimeClasses != null) {
|
|
1346
|
+
if (request.includeJavaClasspath || runtimeClasses != null || request.includeDependencySources) {
|
|
1280
1347
|
def sdk = project.extensions.getByName('androidComponents').sdkComponents
|
|
1281
1348
|
bootClasspath = sdk.bootClasspath.get().collect { it.asFile }
|
|
1282
1349
|
}
|
|
1350
|
+
def dependencyGraph = null
|
|
1351
|
+
if (request.includeDependencySources) {
|
|
1352
|
+
def compile = resolveModuleGraph(configurations[0])
|
|
1353
|
+
def runtime = resolveModuleGraph(configurations[1])
|
|
1354
|
+
dependencyGraph = [compile:compile.modules, runtime:runtime.modules,
|
|
1355
|
+
javaClasspath:(bootClasspath.collect { it.absolutePath } + compile.classpath).unique()]
|
|
1356
|
+
}
|
|
1283
1357
|
new File(request.output, index.toString() + '.json').text = JsonOutput.toJson([
|
|
1284
1358
|
projectDir:project.projectDir.canonicalPath,
|
|
1285
1359
|
projectPath:project.path,
|
|
@@ -1293,6 +1367,7 @@ gradle.projectsEvaluated {
|
|
|
1293
1367
|
dependencies:dependencies,
|
|
1294
1368
|
dependencySources:request.includeDependencySources
|
|
1295
1369
|
? resolveDependencySources(project, configurations) : null,
|
|
1370
|
+
dependencyGraph:dependencyGraph,
|
|
1296
1371
|
javaClasspath:request.includeJavaClasspath
|
|
1297
1372
|
? (bootClasspath + javac.classpath.files.findAll { it.exists() }).unique().collect { it.absolutePath } : null,
|
|
1298
1373
|
runtimeJavaClasspath:runtimeClasses != null
|
|
@@ -1324,11 +1399,11 @@ __export(kotlin_host_exports, {
|
|
|
1324
1399
|
serveKotlinRequest: () => serveKotlinRequest
|
|
1325
1400
|
});
|
|
1326
1401
|
module.exports = __toCommonJS(kotlin_host_exports);
|
|
1327
|
-
var
|
|
1328
|
-
var
|
|
1329
|
-
var
|
|
1402
|
+
var import_node_child_process10 = require("node:child_process");
|
|
1403
|
+
var import_node_crypto11 = require("node:crypto");
|
|
1404
|
+
var import_node_fs16 = __toESM(require("node:fs"), 1);
|
|
1330
1405
|
var import_node_module = require("node:module");
|
|
1331
|
-
var
|
|
1406
|
+
var import_node_path15 = __toESM(require("node:path"), 1);
|
|
1332
1407
|
var import_node_util6 = require("node:util");
|
|
1333
1408
|
|
|
1334
1409
|
// ../peach-globals/src/kotlinDiscoveryContract.ts
|
|
@@ -1535,6 +1610,412 @@ var kotlinCoroutineDispatcher = [
|
|
|
1535
1610
|
"null"
|
|
1536
1611
|
];
|
|
1537
1612
|
|
|
1613
|
+
// src/kotlin-gradle-library-plan.ts
|
|
1614
|
+
var import_node_crypto6 = require("node:crypto");
|
|
1615
|
+
var import_node_fs11 = __toESM(require("node:fs"), 1);
|
|
1616
|
+
var import_node_path10 = __toESM(require("node:path"), 1);
|
|
1617
|
+
|
|
1618
|
+
// src/kotlin-library-sources.ts
|
|
1619
|
+
var import_node_child_process6 = require("node:child_process");
|
|
1620
|
+
var import_node_fs9 = __toESM(require("node:fs"), 1);
|
|
1621
|
+
var import_node_path8 = __toESM(require("node:path"), 1);
|
|
1622
|
+
init_is_record();
|
|
1623
|
+
init_kotlin_toolchain();
|
|
1624
|
+
function runCompiler(file, args, options, operation) {
|
|
1625
|
+
return new Promise((resolve, reject) => {
|
|
1626
|
+
const child = (0, import_node_child_process6.spawn)(file, args, options);
|
|
1627
|
+
child.once("error", reject);
|
|
1628
|
+
child.once("close", (code, signal) => {
|
|
1629
|
+
if (code === 0) resolve();
|
|
1630
|
+
else reject(new Error(operation + " stopped with " + (code ?? signal)));
|
|
1631
|
+
});
|
|
1632
|
+
});
|
|
1633
|
+
}
|
|
1634
|
+
function kotlinFragmentFlags(filename, kotlinSources2, translatedSources) {
|
|
1635
|
+
const input = JSON.parse(import_node_fs9.default.readFileSync(filename, "utf8"));
|
|
1636
|
+
if (!Array.isArray(input) || !input.length)
|
|
1637
|
+
throw new Error("Kotlin fragments must be a nonempty array");
|
|
1638
|
+
const fragments = input.map(
|
|
1639
|
+
(fragment) => {
|
|
1640
|
+
if (!isRecord(fragment) || typeof fragment.name !== "string" || !/^[a-zA-Z][a-zA-Z0-9_]*$/.test(fragment.name) || !Array.isArray(fragment.sources) || !fragment.sources.every((source) => typeof source === "string") || !Array.isArray(fragment.refines) || !fragment.refines.every((parent) => typeof parent === "string") || fragment.java !== void 0 && typeof fragment.java !== "boolean")
|
|
1641
|
+
throw new Error(
|
|
1642
|
+
"Each Kotlin fragment needs a name, source paths and refined fragments"
|
|
1643
|
+
);
|
|
1644
|
+
return {
|
|
1645
|
+
name: fragment.name,
|
|
1646
|
+
sources: fragment.sources.map((source) => import_node_path8.default.resolve(source)),
|
|
1647
|
+
refines: fragment.refines,
|
|
1648
|
+
java: fragment.java === true
|
|
1649
|
+
};
|
|
1650
|
+
}
|
|
1651
|
+
);
|
|
1652
|
+
const names = new Set(fragments.map(({ name }) => name));
|
|
1653
|
+
const refined = new Set(fragments.flatMap(({ refines }) => refines));
|
|
1654
|
+
const [platform2, ...otherPlatforms] = [...names].filter((name) => !refined.has(name));
|
|
1655
|
+
const javaFragments = fragments.filter(({ java }) => java);
|
|
1656
|
+
if (names.size !== fragments.length || [...refined].some((name) => !names.has(name)) || !platform2 || otherPlatforms.length || javaFragments.length > 1)
|
|
1657
|
+
throw new Error(
|
|
1658
|
+
"Kotlin fragments need unique names, known parents, one platform fragment and at most one Java source fragment"
|
|
1659
|
+
);
|
|
1660
|
+
const sources = fragments.flatMap(({ sources: sources2 }) => sources2);
|
|
1661
|
+
const selected = new Set(kotlinSources2);
|
|
1662
|
+
if (sources.length !== selected.size || new Set(sources).size !== sources.length || sources.some((source) => !selected.has(source)) || [...sources, ...translatedSources].some((source) => source.includes(",")))
|
|
1663
|
+
throw new Error("Each Kotlin library source must belong to exactly one fragment");
|
|
1664
|
+
const mappings = fragments.flatMap(
|
|
1665
|
+
({ name, sources: sources2 }) => sources2.map((source) => `${name}:${source}`)
|
|
1666
|
+
);
|
|
1667
|
+
const javaFragment = javaFragments[0]?.name ?? platform2;
|
|
1668
|
+
mappings.push(...translatedSources.map((source) => `${javaFragment}:${source}`));
|
|
1669
|
+
const edges = fragments.flatMap(
|
|
1670
|
+
({ name, refines }) => refines.map((parent) => `${name}:${parent}`)
|
|
1671
|
+
);
|
|
1672
|
+
return [
|
|
1673
|
+
"-Xmulti-platform",
|
|
1674
|
+
`-Xfragments=${[...names].join(",")}`,
|
|
1675
|
+
...edges.length ? [`-Xfragment-refines=${edges.join(",")}`] : [],
|
|
1676
|
+
`-Xfragment-sources=${mappings.join(",")}`
|
|
1677
|
+
];
|
|
1678
|
+
}
|
|
1679
|
+
async function compileKotlinLibrarySources(input) {
|
|
1680
|
+
const output = import_node_path8.default.resolve(input.output);
|
|
1681
|
+
const name = import_node_path8.default.basename(output, ".klib");
|
|
1682
|
+
if (!name || !output.endsWith(".klib") || input.source.kind === "files" && !input.source.java.length && !input.source.kotlin.length)
|
|
1683
|
+
throw new Error("Android library compilation requires sources and a KLIB output");
|
|
1684
|
+
const { ready, sdkRoot, libraries } = input;
|
|
1685
|
+
const parent = import_node_path8.default.dirname(output);
|
|
1686
|
+
import_node_fs9.default.mkdirSync(parent, { recursive: true });
|
|
1687
|
+
const work = import_node_fs9.default.mkdtempSync(import_node_path8.default.join(parent, ".android-library-"));
|
|
1688
|
+
try {
|
|
1689
|
+
const compileLibraries = [...libraries, ...input.dependencies];
|
|
1690
|
+
let javaSources;
|
|
1691
|
+
if (input.source.kind === "resources") {
|
|
1692
|
+
const generated = import_node_path8.default.join(work, "resources");
|
|
1693
|
+
await runKotlinTool(
|
|
1694
|
+
ready,
|
|
1695
|
+
sdkRoot,
|
|
1696
|
+
"dev.peach.tools.platform.AndroidResourceClassesKt",
|
|
1697
|
+
[import_node_path8.default.resolve(input.source.archive), generated]
|
|
1698
|
+
);
|
|
1699
|
+
javaSources = import_node_fs9.default.readdirSync(generated, { recursive: true, encoding: "utf8" }).filter((file) => file.endsWith(".java")).sort().map((file) => import_node_path8.default.join(generated, file));
|
|
1700
|
+
} else {
|
|
1701
|
+
javaSources = input.source.java;
|
|
1702
|
+
}
|
|
1703
|
+
const kotlinSources2 = input.source.kind === "files" ? input.source.kotlin.map((file) => import_node_path8.default.resolve(file)) : [];
|
|
1704
|
+
const commonSources = (input.commonSources ?? []).map((file) => import_node_path8.default.resolve(file));
|
|
1705
|
+
if (commonSources.length && input.kotlinFragments)
|
|
1706
|
+
throw new Error("Choose common sources or a Kotlin fragment graph");
|
|
1707
|
+
if (commonSources.some((file) => file.includes(",") || !kotlinSources2.includes(file)))
|
|
1708
|
+
throw new Error("Common Kotlin sources must be included in the library source list");
|
|
1709
|
+
const kotlinJvmAbi = input.kotlinJvmAbi && import_node_path8.default.resolve(input.kotlinJvmAbi);
|
|
1710
|
+
if (kotlinJvmAbi && (!javaSources.length || !kotlinSources2.length || !kotlinJvmAbi.endsWith(".jar") || !input.javaClasspath.some((file) => import_node_path8.default.resolve(file) === kotlinJvmAbi)))
|
|
1711
|
+
throw new Error(
|
|
1712
|
+
"The Kotlin JVM ABI must be a JAR on the mixed library\u2019s Java classpath"
|
|
1713
|
+
);
|
|
1714
|
+
const dependencyAbiFlags = [];
|
|
1715
|
+
if (input.dependencyJvmAbi) {
|
|
1716
|
+
const dependencyPaths = new Set(
|
|
1717
|
+
input.dependencies.map((file) => import_node_path8.default.resolve(file))
|
|
1718
|
+
);
|
|
1719
|
+
const classpathPaths = new Set(
|
|
1720
|
+
input.javaClasspath.map((file) => import_node_path8.default.resolve(file))
|
|
1721
|
+
);
|
|
1722
|
+
const value = JSON.parse(import_node_fs9.default.readFileSync(input.dependencyJvmAbi, "utf8"));
|
|
1723
|
+
if (!Array.isArray(value) || !value.length || !javaSources.length)
|
|
1724
|
+
throw new Error(
|
|
1725
|
+
"Dependency JVM ABIs require Java sources and a nonempty array of KLIB/JAR pairs"
|
|
1726
|
+
);
|
|
1727
|
+
for (const pair of value) {
|
|
1728
|
+
if (!isRecord(pair) || typeof pair.klib !== "string" || typeof pair.jar !== "string")
|
|
1729
|
+
throw new Error("Each dependency JVM ABI requires a klib and a jar path");
|
|
1730
|
+
const klib = import_node_path8.default.resolve(pair.klib);
|
|
1731
|
+
const jar = import_node_path8.default.resolve(pair.jar);
|
|
1732
|
+
if (!klib.endsWith(".klib") || !dependencyPaths.has(klib) || !jar.endsWith(".jar") || !classpathPaths.has(jar) || jar === kotlinJvmAbi)
|
|
1733
|
+
throw new Error(
|
|
1734
|
+
"Dependency JVM ABI pairs must refer to a dependency KLIB and its Java classpath JAR"
|
|
1735
|
+
);
|
|
1736
|
+
dependencyAbiFlags.push("--dependency-jvm-abi", klib, jar);
|
|
1737
|
+
}
|
|
1738
|
+
}
|
|
1739
|
+
let translatedSources = [];
|
|
1740
|
+
if (javaSources.length) {
|
|
1741
|
+
const platform2 = import_node_path8.default.join(work, "platform.txt");
|
|
1742
|
+
const members = kotlinToolCommand(
|
|
1743
|
+
ready,
|
|
1744
|
+
sdkRoot,
|
|
1745
|
+
"dev.peach.tools.platform.KlibClassesKt",
|
|
1746
|
+
[
|
|
1747
|
+
...compileLibraries.map((file) => import_node_path8.default.resolve(file)),
|
|
1748
|
+
...kotlinJvmAbi ? ["--same-library-jvm-abi", kotlinJvmAbi] : [],
|
|
1749
|
+
...dependencyAbiFlags
|
|
1750
|
+
]
|
|
1751
|
+
);
|
|
1752
|
+
const fd = import_node_fs9.default.openSync(platform2, "w");
|
|
1753
|
+
try {
|
|
1754
|
+
await runCompiler(
|
|
1755
|
+
members.file,
|
|
1756
|
+
members.args,
|
|
1757
|
+
{ stdio: ["ignore", fd, "inherit"] },
|
|
1758
|
+
"Android library " + name + " metadata read"
|
|
1759
|
+
);
|
|
1760
|
+
} finally {
|
|
1761
|
+
import_node_fs9.default.closeSync(fd);
|
|
1762
|
+
}
|
|
1763
|
+
const sourceList = import_node_path8.default.join(work, "sources.txt");
|
|
1764
|
+
import_node_fs9.default.writeFileSync(
|
|
1765
|
+
sourceList,
|
|
1766
|
+
javaSources.map((file) => import_node_path8.default.resolve(file)).join("\n")
|
|
1767
|
+
);
|
|
1768
|
+
const translated = import_node_path8.default.join(work, "translated");
|
|
1769
|
+
const diagnostics = await runKotlinTool(
|
|
1770
|
+
ready,
|
|
1771
|
+
sdkRoot,
|
|
1772
|
+
"dev.peach.tools.java.JavaTranslatorKt",
|
|
1773
|
+
[
|
|
1774
|
+
"--target",
|
|
1775
|
+
"wasm",
|
|
1776
|
+
"--release",
|
|
1777
|
+
input.release,
|
|
1778
|
+
"--classpath",
|
|
1779
|
+
input.javaClasspath.map((file) => import_node_path8.default.resolve(file)).join(import_node_path8.default.delimiter),
|
|
1780
|
+
"--platform",
|
|
1781
|
+
platform2,
|
|
1782
|
+
...input.processorPath ? ["--processorpath", input.processorPath] : [],
|
|
1783
|
+
"--out",
|
|
1784
|
+
translated,
|
|
1785
|
+
`@${sourceList}`
|
|
1786
|
+
]
|
|
1787
|
+
);
|
|
1788
|
+
if (/^refuses /m.test(diagnostics))
|
|
1789
|
+
throw new Error(
|
|
1790
|
+
`Android library ${name} requires unsupported platform members:
|
|
1791
|
+
${diagnostics.trimEnd()}`
|
|
1792
|
+
);
|
|
1793
|
+
translatedSources = input.kotlinFragments ? import_node_fs9.default.readdirSync(translated, { recursive: true, encoding: "utf8" }).filter((file) => file.endsWith(".kt")).sort().map((file) => import_node_path8.default.join(translated, file)) : [translated];
|
|
1794
|
+
}
|
|
1795
|
+
const multiplatform = input.kotlinFragments ? kotlinFragmentFlags(input.kotlinFragments, kotlinSources2, translatedSources) : commonSources.length ? ["-Xmulti-platform", `-Xcommon-sources=${commonSources.join(",")}`] : [];
|
|
1796
|
+
const language = input.kotlinLanguage ?? "2.1";
|
|
1797
|
+
const raw = import_node_path8.default.join(work, "raw");
|
|
1798
|
+
await runCompiler(
|
|
1799
|
+
ready.kotlinc,
|
|
1800
|
+
[
|
|
1801
|
+
"-J-Xmx4g",
|
|
1802
|
+
"-Xwasm-target=js",
|
|
1803
|
+
"-nowarn",
|
|
1804
|
+
`-Xplugin=${import_node_path8.default.join(sdkRoot, "plugin.jar")}`,
|
|
1805
|
+
"-P",
|
|
1806
|
+
"plugin:dev.peach.jni:android=true",
|
|
1807
|
+
"-language-version",
|
|
1808
|
+
language,
|
|
1809
|
+
"-api-version",
|
|
1810
|
+
language,
|
|
1811
|
+
...(input.kotlinOptIns ?? []).map((marker) => `-opt-in=${marker}`),
|
|
1812
|
+
...multiplatform,
|
|
1813
|
+
"-libraries",
|
|
1814
|
+
compileLibraries.join(import_node_path8.default.delimiter),
|
|
1815
|
+
"-ir-output-dir",
|
|
1816
|
+
raw,
|
|
1817
|
+
"-ir-output-name",
|
|
1818
|
+
name,
|
|
1819
|
+
...kotlinSources2,
|
|
1820
|
+
...translatedSources
|
|
1821
|
+
],
|
|
1822
|
+
{ stdio: "inherit", env: { ...process.env, JAVA_HOME: ready.javaHome } },
|
|
1823
|
+
"Android library " + name + " compilation"
|
|
1824
|
+
);
|
|
1825
|
+
const compiled = import_node_path8.default.join(raw, `${name}.klib`);
|
|
1826
|
+
if (!javaSources.length) {
|
|
1827
|
+
import_node_fs9.default.renameSync(compiled, output);
|
|
1828
|
+
return;
|
|
1829
|
+
}
|
|
1830
|
+
const normalized = import_node_path8.default.join(work, "normalized.klib");
|
|
1831
|
+
await runKotlinTool(ready, sdkRoot, "dev.peach.tools.platform.JavaPlatformTypesKt", [
|
|
1832
|
+
compiled,
|
|
1833
|
+
normalized,
|
|
1834
|
+
"--java-classes"
|
|
1835
|
+
]);
|
|
1836
|
+
import_node_fs9.default.renameSync(normalized, output);
|
|
1837
|
+
} finally {
|
|
1838
|
+
import_node_fs9.default.rmSync(work, { recursive: true, force: true });
|
|
1839
|
+
}
|
|
1840
|
+
}
|
|
1841
|
+
|
|
1842
|
+
// src/kotlin-maven-sources.ts
|
|
1843
|
+
var import_node_crypto5 = require("node:crypto");
|
|
1844
|
+
var import_node_fs10 = __toESM(require("node:fs"), 1);
|
|
1845
|
+
var import_node_os5 = __toESM(require("node:os"), 1);
|
|
1846
|
+
var import_node_path9 = __toESM(require("node:path"), 1);
|
|
1847
|
+
var import_node_zlib2 = require("node:zlib");
|
|
1848
|
+
var pending = /* @__PURE__ */ new Map();
|
|
1849
|
+
var MAX_SOURCES_JAR_BYTES = 64 * 1024 * 1024;
|
|
1850
|
+
var MAX_SOURCE_ENTRY_BYTES = 16 * 1024 * 1024;
|
|
1851
|
+
var MAX_TOTAL_EXTRACTED_BYTES = 64 * 1024 * 1024;
|
|
1852
|
+
function zipSources(bytes, where) {
|
|
1853
|
+
let end = -1;
|
|
1854
|
+
const earliest = Math.max(0, bytes.length - 22 - 65535);
|
|
1855
|
+
for (let index = bytes.length - 22; index >= earliest; index--) {
|
|
1856
|
+
if (bytes.readUInt32LE(index) === 101010256) {
|
|
1857
|
+
end = index;
|
|
1858
|
+
break;
|
|
1859
|
+
}
|
|
1860
|
+
}
|
|
1861
|
+
if (end < 0) throw new Error(`${where}: sources jar is not a zip`);
|
|
1862
|
+
const count = bytes.readUInt16LE(end + 8);
|
|
1863
|
+
if (count !== bytes.readUInt16LE(end + 10))
|
|
1864
|
+
throw new Error(`${where}: sources jar spans zip disks`);
|
|
1865
|
+
let offset = bytes.readUInt32LE(end + 16);
|
|
1866
|
+
if (offset === 4294967295) throw new Error(`${where}: sources jar is zip64`);
|
|
1867
|
+
const entries = [];
|
|
1868
|
+
let totalExtractedBytes = 0;
|
|
1869
|
+
for (let index = 0; index < count; index++) {
|
|
1870
|
+
if (bytes.readUInt32LE(offset) !== 33639248)
|
|
1871
|
+
throw new Error(`${where}: sources jar has a broken central directory`);
|
|
1872
|
+
const flags = bytes.readUInt16LE(offset + 8);
|
|
1873
|
+
const method = bytes.readUInt16LE(offset + 10);
|
|
1874
|
+
const compressed = bytes.readUInt32LE(offset + 20);
|
|
1875
|
+
const uncompressed = bytes.readUInt32LE(offset + 24);
|
|
1876
|
+
const nameLength = bytes.readUInt16LE(offset + 28);
|
|
1877
|
+
const extraLength = bytes.readUInt16LE(offset + 30);
|
|
1878
|
+
const commentLength = bytes.readUInt16LE(offset + 32);
|
|
1879
|
+
const localOffset = bytes.readUInt32LE(offset + 42);
|
|
1880
|
+
const name = bytes.toString("utf8", offset + 46, offset + 46 + nameLength);
|
|
1881
|
+
offset += 46 + nameLength + extraLength + commentLength;
|
|
1882
|
+
if (name.endsWith("/")) continue;
|
|
1883
|
+
if (flags & 1) throw new Error(`${where}: ${name} is encrypted`);
|
|
1884
|
+
if (name.includes("\0") || name.includes("\\") || name.includes("\n") || name.includes("\r") || name.startsWith("/") || name.split("/").includes(".."))
|
|
1885
|
+
throw new Error(`${where}: ${name} escapes the sources jar`);
|
|
1886
|
+
if (!name.endsWith(".kt") && !name.endsWith(".java")) continue;
|
|
1887
|
+
if (uncompressed > MAX_SOURCE_ENTRY_BYTES || totalExtractedBytes + uncompressed > MAX_TOTAL_EXTRACTED_BYTES) {
|
|
1888
|
+
throw new Error(`${where}: ${name} exceeds sources jar extraction budget`);
|
|
1889
|
+
}
|
|
1890
|
+
if (bytes.readUInt32LE(localOffset) !== 67324752)
|
|
1891
|
+
throw new Error(`${where}: ${name} has no local header`);
|
|
1892
|
+
const localName = bytes.readUInt16LE(localOffset + 26);
|
|
1893
|
+
const localExtra = bytes.readUInt16LE(localOffset + 28);
|
|
1894
|
+
const start = localOffset + 30 + localName + localExtra;
|
|
1895
|
+
if (start + compressed > bytes.byteLength)
|
|
1896
|
+
throw new Error(`${where}: ${name} exceeds sources jar bounds`);
|
|
1897
|
+
const remainingBudget = Math.min(
|
|
1898
|
+
MAX_SOURCE_ENTRY_BYTES,
|
|
1899
|
+
MAX_TOTAL_EXTRACTED_BYTES - totalExtractedBytes
|
|
1900
|
+
);
|
|
1901
|
+
const payload = bytes.subarray(start, start + compressed);
|
|
1902
|
+
let data = null;
|
|
1903
|
+
if (method === 0) {
|
|
1904
|
+
if (payload.byteLength > remainingBudget) {
|
|
1905
|
+
throw new Error(`${where}: ${name} exceeds sources jar extraction budget`);
|
|
1906
|
+
}
|
|
1907
|
+
data = Buffer.from(payload);
|
|
1908
|
+
} else if (method === 8) {
|
|
1909
|
+
data = (0, import_node_zlib2.inflateRawSync)(payload, { maxOutputLength: remainingBudget });
|
|
1910
|
+
}
|
|
1911
|
+
if (!data) throw new Error(`${where}: ${name} uses zip method ${method}`);
|
|
1912
|
+
totalExtractedBytes += data.byteLength;
|
|
1913
|
+
if (totalExtractedBytes > MAX_TOTAL_EXTRACTED_BYTES) {
|
|
1914
|
+
throw new Error(`${where}: sources jar exceeds extraction budget`);
|
|
1915
|
+
}
|
|
1916
|
+
entries.push({ name, data });
|
|
1917
|
+
}
|
|
1918
|
+
return entries;
|
|
1919
|
+
}
|
|
1920
|
+
function extract(bytes, where) {
|
|
1921
|
+
const key = (0, import_node_crypto5.createHash)("sha256").update(bytes).digest("hex");
|
|
1922
|
+
const cached = pending.get(key);
|
|
1923
|
+
if (cached) return cached;
|
|
1924
|
+
const request = (async () => {
|
|
1925
|
+
const dest = import_node_path9.default.join(import_node_os5.default.tmpdir(), "peach-maven-sources", key);
|
|
1926
|
+
const marker = import_node_path9.default.join(dest, ".complete");
|
|
1927
|
+
if (!import_node_fs10.default.existsSync(marker)) {
|
|
1928
|
+
const sources = zipSources(bytes, where);
|
|
1929
|
+
const staging = `${dest}.partial-${process.pid}`;
|
|
1930
|
+
import_node_fs10.default.rmSync(staging, { recursive: true, force: true });
|
|
1931
|
+
const stagingRoot = import_node_path9.default.resolve(staging);
|
|
1932
|
+
import_node_fs10.default.mkdirSync(stagingRoot, { recursive: true });
|
|
1933
|
+
for (const entry of sources) {
|
|
1934
|
+
const file = import_node_path9.default.resolve(stagingRoot, entry.name);
|
|
1935
|
+
if (!file.startsWith(`${stagingRoot}${import_node_path9.default.sep}`)) {
|
|
1936
|
+
throw new Error(`${where}: ${entry.name} escapes the sources jar`);
|
|
1937
|
+
}
|
|
1938
|
+
import_node_fs10.default.mkdirSync(import_node_path9.default.dirname(file), { recursive: true });
|
|
1939
|
+
import_node_fs10.default.writeFileSync(file, entry.data);
|
|
1940
|
+
}
|
|
1941
|
+
import_node_fs10.default.writeFileSync(import_node_path9.default.join(staging, ".complete"), "");
|
|
1942
|
+
try {
|
|
1943
|
+
import_node_fs10.default.renameSync(staging, dest);
|
|
1944
|
+
} catch (error) {
|
|
1945
|
+
import_node_fs10.default.rmSync(staging, { recursive: true, force: true });
|
|
1946
|
+
if (!import_node_fs10.default.existsSync(marker)) throw error;
|
|
1947
|
+
}
|
|
1948
|
+
}
|
|
1949
|
+
const files = import_node_fs10.default.readdirSync(dest, { recursive: true, withFileTypes: true }).filter((entry) => entry.isFile()).map((entry) => import_node_path9.default.join(entry.parentPath, entry.name)).sort();
|
|
1950
|
+
return {
|
|
1951
|
+
directory: dest,
|
|
1952
|
+
java: files.filter((file) => file.endsWith(".java")),
|
|
1953
|
+
kotlin: files.filter((file) => file.endsWith(".kt"))
|
|
1954
|
+
};
|
|
1955
|
+
})().catch((error) => {
|
|
1956
|
+
pending.delete(key);
|
|
1957
|
+
throw error;
|
|
1958
|
+
});
|
|
1959
|
+
pending.set(key, request);
|
|
1960
|
+
return request;
|
|
1961
|
+
}
|
|
1962
|
+
function readSourcesJar(archive, where) {
|
|
1963
|
+
if (import_node_fs10.default.statSync(archive).size > MAX_SOURCES_JAR_BYTES)
|
|
1964
|
+
throw new Error(`${where}: ${archive} exceeds sources jar size limit`);
|
|
1965
|
+
return import_node_fs10.default.readFileSync(archive);
|
|
1966
|
+
}
|
|
1967
|
+
function readMavenSourcesArchive(archive) {
|
|
1968
|
+
return extract(readSourcesJar(archive, archive), archive);
|
|
1969
|
+
}
|
|
1970
|
+
|
|
1971
|
+
// src/kotlin-gradle-library-plan.ts
|
|
1972
|
+
async function compileKotlinGradleLibraries(input) {
|
|
1973
|
+
const compiled = /* @__PURE__ */ new Map();
|
|
1974
|
+
for (const library of input.plan.libraries) {
|
|
1975
|
+
const { java: archiveJava, kotlin } = await readMavenSourcesArchive(library.archive);
|
|
1976
|
+
const java = archiveJava.filter((file) => import_node_path10.default.basename(file) !== "module-info.java");
|
|
1977
|
+
const dependencies = library.dependencies.map((name2) => {
|
|
1978
|
+
const dependency = compiled.get(name2);
|
|
1979
|
+
if (!dependency) throw new Error(`${library.coordinate} depends on missing ${name2}`);
|
|
1980
|
+
return dependency;
|
|
1981
|
+
});
|
|
1982
|
+
const classpath = [
|
|
1983
|
+
.../* @__PURE__ */ new Set([
|
|
1984
|
+
...library.jars,
|
|
1985
|
+
...dependencies.flatMap(({ jars }) => jars),
|
|
1986
|
+
...input.plan.classpath
|
|
1987
|
+
])
|
|
1988
|
+
];
|
|
1989
|
+
const name = library.coordinate.replace(/[^a-zA-Z0-9._-]/g, "-");
|
|
1990
|
+
const suffix = (0, import_node_crypto6.createHash)("sha256").update(library.coordinate).digest("hex").slice(0, 12);
|
|
1991
|
+
const klib = import_node_path10.default.join(input.output, `${name}-${suffix}.klib`);
|
|
1992
|
+
const kotlinJvmAbi = java.length && kotlin.length && library.jars.length === 1 ? library.jars[0] : void 0;
|
|
1993
|
+
const abiPairs = java.length ? dependencies.flatMap(
|
|
1994
|
+
({ klib: klib2, jars }) => jars.length === 1 ? [{ klib: klib2, jar: jars[0] }] : []
|
|
1995
|
+
) : [];
|
|
1996
|
+
const dependencyJvmAbi = abiPairs.length ? `${klib}.json` : void 0;
|
|
1997
|
+
if (dependencyJvmAbi) {
|
|
1998
|
+
import_node_fs11.default.mkdirSync(input.output, { recursive: true });
|
|
1999
|
+
import_node_fs11.default.writeFileSync(dependencyJvmAbi, JSON.stringify(abiPairs));
|
|
2000
|
+
}
|
|
2001
|
+
await compileKotlinLibrarySources({
|
|
2002
|
+
ready: input.ready,
|
|
2003
|
+
sdkRoot: input.sdkRoot,
|
|
2004
|
+
libraries: input.libraries,
|
|
2005
|
+
source: { kind: "files", java, kotlin },
|
|
2006
|
+
javaClasspath: classpath,
|
|
2007
|
+
release: "17",
|
|
2008
|
+
kotlinJvmAbi,
|
|
2009
|
+
dependencyJvmAbi,
|
|
2010
|
+
kotlinLanguage: input.language,
|
|
2011
|
+
dependencies: dependencies.map(({ klib: klib2 }) => klib2),
|
|
2012
|
+
output: klib
|
|
2013
|
+
});
|
|
2014
|
+
compiled.set(library.coordinate, { klib, jars: library.jars });
|
|
2015
|
+
}
|
|
2016
|
+
return [...compiled.values()].map(({ klib }) => klib);
|
|
2017
|
+
}
|
|
2018
|
+
|
|
1538
2019
|
// src/kotlin-instance-source.ts
|
|
1539
2020
|
var import_acorn = require("peachsim/vendor/acorn");
|
|
1540
2021
|
var androidLooperPoll = "android.os.looperPoll";
|
|
@@ -1662,10 +2143,10 @@ return { peachDisposeInstance, ${exports2.map((item) => `${JSON.stringify(item.e
|
|
|
1662
2143
|
}
|
|
1663
2144
|
|
|
1664
2145
|
// src/kotlin-sdk.ts
|
|
1665
|
-
var
|
|
1666
|
-
var
|
|
1667
|
-
var
|
|
1668
|
-
var
|
|
2146
|
+
var import_node_child_process7 = require("node:child_process");
|
|
2147
|
+
var import_node_crypto7 = require("node:crypto");
|
|
2148
|
+
var import_node_fs12 = __toESM(require("node:fs"), 1);
|
|
2149
|
+
var import_node_path11 = __toESM(require("node:path"), 1);
|
|
1669
2150
|
var import_node_util3 = require("node:util");
|
|
1670
2151
|
init_kotlin_toolchain();
|
|
1671
2152
|
|
|
@@ -1741,66 +2222,66 @@ function readKotlinSdkManifest(source, compilerSha256) {
|
|
|
1741
2222
|
}
|
|
1742
2223
|
|
|
1743
2224
|
// src/kotlin-sdk.ts
|
|
1744
|
-
var run3 = (0, import_node_util3.promisify)(
|
|
2225
|
+
var run3 = (0, import_node_util3.promisify)(import_node_child_process7.execFile);
|
|
1745
2226
|
function verifyKotlinSdkDirectory(root, compiler) {
|
|
1746
2227
|
const expectedNames = ["manifest.json", ...KOTLIN_SDK_FILES];
|
|
1747
|
-
const names =
|
|
2228
|
+
const names = import_node_fs12.default.readdirSync(root);
|
|
1748
2229
|
if (names.length !== expectedNames.length || names.some((name) => !expectedNames.includes(name)))
|
|
1749
2230
|
throw new Error("Kotlin SDK directory contains unexpected inputs");
|
|
1750
|
-
const manifestStat =
|
|
2231
|
+
const manifestStat = import_node_fs12.default.lstatSync(import_node_path11.default.join(root, "manifest.json"));
|
|
1751
2232
|
if (!manifestStat.isFile() || manifestStat.nlink !== 1)
|
|
1752
2233
|
throw new Error("Kotlin SDK manifest is not a regular file");
|
|
1753
2234
|
const manifest = readKotlinSdkManifest(
|
|
1754
|
-
|
|
2235
|
+
import_node_fs12.default.readFileSync(import_node_path11.default.join(root, "manifest.json"), "utf8"),
|
|
1755
2236
|
compiler.upstreamSha256
|
|
1756
2237
|
);
|
|
1757
2238
|
for (const [name, expected] of Object.entries(manifest.files)) {
|
|
1758
|
-
const target =
|
|
1759
|
-
const stat =
|
|
2239
|
+
const target = import_node_path11.default.join(root, name);
|
|
2240
|
+
const stat = import_node_fs12.default.lstatSync(target);
|
|
1760
2241
|
if (!stat.isFile() || stat.nlink !== 1)
|
|
1761
2242
|
throw new Error(`Kotlin SDK binary is not a regular file: ${name}`);
|
|
1762
|
-
const bytes =
|
|
1763
|
-
if (bytes.length !== expected.bytes || (0,
|
|
2243
|
+
const bytes = import_node_fs12.default.readFileSync(target);
|
|
2244
|
+
if (bytes.length !== expected.bytes || (0, import_node_crypto7.createHash)("sha256").update(bytes).digest("hex") !== expected.sha256)
|
|
1764
2245
|
throw new Error(`Kotlin SDK binary differs from its manifest: ${name}`);
|
|
1765
2246
|
}
|
|
1766
2247
|
return manifest;
|
|
1767
2248
|
}
|
|
1768
2249
|
async function installKotlinSdkArchive(archive, compiler) {
|
|
1769
|
-
const sha256 = (0,
|
|
1770
|
-
const parent =
|
|
1771
|
-
const root =
|
|
1772
|
-
if (
|
|
2250
|
+
const sha256 = (0, import_node_crypto7.createHash)("sha256").update(archive).digest("hex");
|
|
2251
|
+
const parent = import_node_path11.default.join(kotlinHome(), "sdk");
|
|
2252
|
+
const root = import_node_path11.default.join(parent, sha256);
|
|
2253
|
+
if (import_node_fs12.default.existsSync(root))
|
|
1773
2254
|
return { root, sha256, manifest: verifyKotlinSdkDirectory(root, compiler) };
|
|
1774
|
-
|
|
1775
|
-
const work =
|
|
2255
|
+
import_node_fs12.default.mkdirSync(parent, { recursive: true });
|
|
2256
|
+
const work = import_node_fs12.default.mkdtempSync(import_node_path11.default.join(parent, ".install-"));
|
|
1776
2257
|
try {
|
|
1777
|
-
const packed =
|
|
1778
|
-
|
|
2258
|
+
const packed = import_node_path11.default.join(work, "sdk.tar.gz");
|
|
2259
|
+
import_node_fs12.default.writeFileSync(packed, archive);
|
|
1779
2260
|
const { stdout } = await run3("tar", ["-tzf", packed]);
|
|
1780
2261
|
const names = stdout.trim().split("\n");
|
|
1781
2262
|
const expected = ["manifest.json", ...KOTLIN_SDK_FILES];
|
|
1782
2263
|
if (names.length !== expected.length || new Set(names).size !== names.length || names.some((name) => !expected.includes(name)))
|
|
1783
2264
|
throw new Error("Kotlin SDK archive contains unexpected inputs");
|
|
1784
2265
|
await run3("tar", ["-xzf", packed, "-C", work, "--", ...expected]);
|
|
1785
|
-
|
|
2266
|
+
import_node_fs12.default.rmSync(packed);
|
|
1786
2267
|
const manifest = verifyKotlinSdkDirectory(work, compiler);
|
|
1787
2268
|
try {
|
|
1788
|
-
|
|
2269
|
+
import_node_fs12.default.renameSync(work, root);
|
|
1789
2270
|
} catch (error) {
|
|
1790
|
-
if (!
|
|
2271
|
+
if (!import_node_fs12.default.existsSync(root)) throw error;
|
|
1791
2272
|
verifyKotlinSdkDirectory(root, compiler);
|
|
1792
2273
|
}
|
|
1793
2274
|
return { root, sha256, manifest };
|
|
1794
2275
|
} finally {
|
|
1795
|
-
|
|
2276
|
+
import_node_fs12.default.rmSync(work, { recursive: true, force: true });
|
|
1796
2277
|
}
|
|
1797
2278
|
}
|
|
1798
2279
|
|
|
1799
2280
|
// src/kotlin-skiko-source.ts
|
|
1800
|
-
var
|
|
2281
|
+
var import_node_zlib3 = require("node:zlib");
|
|
1801
2282
|
var import_acorn2 = require("peachsim/vendor/acorn");
|
|
1802
2283
|
function kotlinSkikoSource(loader) {
|
|
1803
|
-
const upstream = (0, import_acorn2.parse)((0,
|
|
2284
|
+
const upstream = (0, import_acorn2.parse)((0, import_node_zlib3.gunzipSync)(loader).toString("utf8"), {
|
|
1804
2285
|
ecmaVersion: "latest",
|
|
1805
2286
|
sourceType: "module"
|
|
1806
2287
|
});
|
|
@@ -1909,9 +2390,9 @@ function viewModelClasses(rows) {
|
|
|
1909
2390
|
}
|
|
1910
2391
|
|
|
1911
2392
|
// src/kotlin-module.ts
|
|
1912
|
-
var
|
|
1913
|
-
var
|
|
1914
|
-
var
|
|
2393
|
+
var import_node_crypto9 = require("node:crypto");
|
|
2394
|
+
var import_node_fs14 = __toESM(require("node:fs"), 1);
|
|
2395
|
+
var import_node_path13 = __toESM(require("node:path"), 1);
|
|
1915
2396
|
|
|
1916
2397
|
// cli/standalone.ts
|
|
1917
2398
|
var IS_STANDALONE = typeof __SOOTSIM_STANDALONE__ !== "undefined" && __SOOTSIM_STANDALONE__;
|
|
@@ -1921,15 +2402,15 @@ init_home_paths();
|
|
|
1921
2402
|
init_is_record();
|
|
1922
2403
|
|
|
1923
2404
|
// src/swift-toolchain.ts
|
|
1924
|
-
var
|
|
1925
|
-
var
|
|
1926
|
-
var
|
|
1927
|
-
var
|
|
1928
|
-
var
|
|
2405
|
+
var import_node_child_process8 = require("node:child_process");
|
|
2406
|
+
var import_node_crypto8 = require("node:crypto");
|
|
2407
|
+
var import_node_fs13 = __toESM(require("node:fs"), 1);
|
|
2408
|
+
var import_node_os6 = __toESM(require("node:os"), 1);
|
|
2409
|
+
var import_node_path12 = __toESM(require("node:path"), 1);
|
|
1929
2410
|
var import_promises3 = require("node:stream/promises");
|
|
1930
2411
|
var import_node_url = require("node:url");
|
|
1931
2412
|
var import_node_util4 = require("node:util");
|
|
1932
|
-
var
|
|
2413
|
+
var import_node_zlib4 = __toESM(require("node:zlib"), 1);
|
|
1933
2414
|
|
|
1934
2415
|
// src/swiftTargetContract.ts
|
|
1935
2416
|
var wasmThreadFlags = [
|
|
@@ -1943,8 +2424,8 @@ var swiftWasmThreadFlags = wasmThreadFlags.flatMap((flag) => ["-Xcc", flag]);
|
|
|
1943
2424
|
// src/swift-toolchain.ts
|
|
1944
2425
|
function peachsimPackageRoot() {
|
|
1945
2426
|
let dir = __sootsim_import_meta_dirname;
|
|
1946
|
-
while (!
|
|
1947
|
-
dir =
|
|
2427
|
+
while (!import_node_fs13.default.existsSync(import_node_path12.default.join(dir, "package.json")) && dir !== import_node_path12.default.dirname(dir))
|
|
2428
|
+
dir = import_node_path12.default.dirname(dir);
|
|
1948
2429
|
return dir;
|
|
1949
2430
|
}
|
|
1950
2431
|
var SWIFT_CACHE_HOLD_MS = 7 * 24 * 36e5;
|
|
@@ -1952,33 +2433,33 @@ var SWIFT_CACHE_HOLD_MS = 7 * 24 * 36e5;
|
|
|
1952
2433
|
// src/kotlin-module.ts
|
|
1953
2434
|
var installedRoot;
|
|
1954
2435
|
function peachKotlinModuleRoot() {
|
|
1955
|
-
if (!IS_STANDALONE) return
|
|
2436
|
+
if (!IS_STANDALONE) return import_node_path13.default.join(peachsimPackageRoot(), "kotlin");
|
|
1956
2437
|
if (installedRoot) return installedRoot;
|
|
1957
2438
|
const files = JSON.parse(__PEACH_BUNDLED_KOTLIN__);
|
|
1958
|
-
const digest = (0,
|
|
1959
|
-
const parent =
|
|
1960
|
-
const root =
|
|
1961
|
-
|
|
1962
|
-
if (!
|
|
1963
|
-
const
|
|
2439
|
+
const digest = (0, import_node_crypto9.createHash)("sha256").update(__PEACH_BUNDLED_KOTLIN__).digest("hex");
|
|
2440
|
+
const parent = import_node_path13.default.join(rnxHomeDir(), "kotlin", "modules");
|
|
2441
|
+
const root = import_node_path13.default.join(parent, digest);
|
|
2442
|
+
import_node_fs14.default.mkdirSync(parent, { recursive: true });
|
|
2443
|
+
if (!import_node_fs14.default.existsSync(root)) {
|
|
2444
|
+
const pending2 = import_node_fs14.default.mkdtempSync(import_node_path13.default.join(parent, ".install-"));
|
|
1964
2445
|
try {
|
|
1965
2446
|
for (const [name, contents] of Object.entries(files)) {
|
|
1966
|
-
const file =
|
|
1967
|
-
|
|
1968
|
-
|
|
2447
|
+
const file = import_node_path13.default.join(pending2, name);
|
|
2448
|
+
import_node_fs14.default.mkdirSync(import_node_path13.default.dirname(file), { recursive: true });
|
|
2449
|
+
import_node_fs14.default.writeFileSync(file, Buffer.from(contents, "base64"));
|
|
1969
2450
|
}
|
|
1970
2451
|
try {
|
|
1971
|
-
|
|
2452
|
+
import_node_fs14.default.renameSync(pending2, root);
|
|
1972
2453
|
} catch (error) {
|
|
1973
2454
|
if (!isRecord(error) || error.code !== "EEXIST" && error.code !== "ENOTEMPTY")
|
|
1974
2455
|
throw error;
|
|
1975
2456
|
}
|
|
1976
2457
|
} finally {
|
|
1977
|
-
|
|
2458
|
+
import_node_fs14.default.rmSync(pending2, { recursive: true, force: true });
|
|
1978
2459
|
}
|
|
1979
2460
|
}
|
|
1980
2461
|
for (const [name, contents] of Object.entries(files)) {
|
|
1981
|
-
if (!
|
|
2462
|
+
if (!import_node_fs14.default.readFileSync(import_node_path13.default.join(root, name)).equals(Buffer.from(contents, "base64")))
|
|
1982
2463
|
throw new Error(`packaged Kotlin module differs from this CLI: ${name}`);
|
|
1983
2464
|
}
|
|
1984
2465
|
installedRoot = root;
|
|
@@ -1986,20 +2467,20 @@ function peachKotlinModuleRoot() {
|
|
|
1986
2467
|
}
|
|
1987
2468
|
|
|
1988
2469
|
// src/kotlin-host.ts
|
|
1989
|
-
var run5 = (0, import_node_util6.promisify)(
|
|
2470
|
+
var run5 = (0, import_node_util6.promisify)(import_node_child_process10.execFile);
|
|
1990
2471
|
function loadKotlinSdk(moduleRoot, toolchain) {
|
|
1991
2472
|
return installKotlinSdkArchive(
|
|
1992
|
-
|
|
2473
|
+
import_node_fs16.default.readFileSync(import_node_path15.default.join(moduleRoot, "sdk.tar.gz")),
|
|
1993
2474
|
toolchain.compiler
|
|
1994
2475
|
);
|
|
1995
2476
|
}
|
|
1996
2477
|
var KOTLIN_ARTIFACT_PREFIX = "/__peach/kotlin-artifact/";
|
|
1997
2478
|
function appKotlinLanguage(root) {
|
|
1998
|
-
const reactNative =
|
|
1999
|
-
(0, import_node_module.createRequire)(
|
|
2479
|
+
const reactNative = import_node_path15.default.dirname(
|
|
2480
|
+
(0, import_node_module.createRequire)(import_node_path15.default.join(root, "package.json")).resolve("react-native/package.json")
|
|
2000
2481
|
);
|
|
2001
|
-
const versions =
|
|
2002
|
-
|
|
2482
|
+
const versions = import_node_fs16.default.readFileSync(
|
|
2483
|
+
import_node_path15.default.join(reactNative, "gradle", "libs.versions.toml"),
|
|
2003
2484
|
"utf8"
|
|
2004
2485
|
);
|
|
2005
2486
|
const match = /^kotlin\s*=\s*"(\d+)\.(\d+)/m.exec(versions);
|
|
@@ -2021,9 +2502,9 @@ var SKIP_DIRS = /* @__PURE__ */ new Set([
|
|
|
2021
2502
|
function kotlinSources(root, skip = SKIP_DIRS) {
|
|
2022
2503
|
const sources = [];
|
|
2023
2504
|
const walk = (dir) => {
|
|
2024
|
-
for (const entry of
|
|
2505
|
+
for (const entry of import_node_fs16.default.readdirSync(dir, { withFileTypes: true })) {
|
|
2025
2506
|
if (entry.name.startsWith(".") || skip.has(entry.name)) continue;
|
|
2026
|
-
const full =
|
|
2507
|
+
const full = import_node_path15.default.join(dir, entry.name);
|
|
2027
2508
|
if (entry.isDirectory()) walk(full);
|
|
2028
2509
|
else if (entry.isFile() && entry.name.endsWith(".kt")) sources.push(full);
|
|
2029
2510
|
}
|
|
@@ -2093,7 +2574,7 @@ function entrySource(ids) {
|
|
|
2093
2574
|
var BUILD_FORMAT = 23;
|
|
2094
2575
|
var builds = /* @__PURE__ */ new Map();
|
|
2095
2576
|
function buildsDir() {
|
|
2096
|
-
return
|
|
2577
|
+
return import_node_path15.default.join(kotlinHome(), "builds");
|
|
2097
2578
|
}
|
|
2098
2579
|
async function kotlinArtifact(root, moduleRoot, origin, target = "app") {
|
|
2099
2580
|
const { kotlinSourceId, nativeSourceContract, renderKotlinSourceGlue } = await import("vxrn/native-source-contract");
|
|
@@ -2106,7 +2587,7 @@ async function kotlinArtifact(root, moduleRoot, origin, target = "app") {
|
|
|
2106
2587
|
const viewIds = [];
|
|
2107
2588
|
let usesCompose = false;
|
|
2108
2589
|
for (const file of sources) {
|
|
2109
|
-
const source =
|
|
2590
|
+
const source = import_node_fs16.default.readFileSync(file, "utf8");
|
|
2110
2591
|
if (/\bandroidx\.compose\./.test(source)) usesCompose = true;
|
|
2111
2592
|
const contract = nativeSourceContract(file, source);
|
|
2112
2593
|
if (contract.modules.length === 0 && contract.views.length === 0) continue;
|
|
@@ -2196,11 +2677,11 @@ function readExpoTypes(output) {
|
|
|
2196
2677
|
}
|
|
2197
2678
|
var toolScans = /* @__PURE__ */ new Map();
|
|
2198
2679
|
async function scanSources(tool, parse3, toolchain, moduleRoot, files) {
|
|
2199
|
-
const digest = (0,
|
|
2680
|
+
const digest = (0, import_node_crypto11.createHash)("sha256").update(JSON.stringify(toolchain.compiler));
|
|
2200
2681
|
const sdk = await loadKotlinSdk(moduleRoot, toolchain);
|
|
2201
|
-
digest.update(
|
|
2682
|
+
digest.update(import_node_fs16.default.readFileSync(import_node_path15.default.join(moduleRoot, "sdk.tar.gz")));
|
|
2202
2683
|
digest.update(tool);
|
|
2203
|
-
for (const file of files) digest.update(`${file}\0${
|
|
2684
|
+
for (const file of files) digest.update(`${file}\0${import_node_fs16.default.readFileSync(file, "utf8")}\0`);
|
|
2204
2685
|
const key = digest.digest("hex");
|
|
2205
2686
|
let scan = toolScans.get(key);
|
|
2206
2687
|
if (!scan) {
|
|
@@ -2215,7 +2696,7 @@ async function scanSources(tool, parse3, toolchain, moduleRoot, files) {
|
|
|
2215
2696
|
async function scanExpoTypes(toolchain, moduleRoot, sources) {
|
|
2216
2697
|
const candidates = sources.filter(
|
|
2217
2698
|
(file) => /\bRecord\b|\benum\s+class\b|\bExpoComposeView\b|\bExpoView\b|\bComposeProps\b|:\s*(?:[A-Za-z0-9_.]+\.)?(?:View|FrameLayout|LinearLayout|ViewGroup)\b/.test(
|
|
2218
|
-
|
|
2699
|
+
import_node_fs16.default.readFileSync(file, "utf8")
|
|
2219
2700
|
)
|
|
2220
2701
|
);
|
|
2221
2702
|
if (candidates.length === 0) return [];
|
|
@@ -2404,7 +2885,7 @@ function expoTypeSources(files) {
|
|
|
2404
2885
|
)
|
|
2405
2886
|
];
|
|
2406
2887
|
if (edits.length > 0 || views.length > 0) {
|
|
2407
|
-
let text =
|
|
2888
|
+
let text = import_node_fs16.default.readFileSync(file.file, "utf8").replaceAll("\r\n", "\n");
|
|
2408
2889
|
for (const { range, owner, field } of edits.sort((a, b) => b.range[0] - a.range[0]))
|
|
2409
2890
|
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])}`;
|
|
2410
2891
|
if (views.length > 0) {
|
|
@@ -2420,7 +2901,7 @@ function expoTypeSources(files) {
|
|
|
2420
2901
|
`${file.package ? `${file.package}.` : ""}peachExpoViews${index}()`
|
|
2421
2902
|
);
|
|
2422
2903
|
}
|
|
2423
|
-
const name = `PeachExpoSource_${index}_${
|
|
2904
|
+
const name = `PeachExpoSource_${index}_${import_node_path15.default.basename(file.file)}`;
|
|
2424
2905
|
generated[name] = text;
|
|
2425
2906
|
origins[name] = file.file;
|
|
2426
2907
|
}
|
|
@@ -2462,7 +2943,7 @@ async function expoKotlinArtifact(root, moduleRoot, origin, modules) {
|
|
|
2462
2943
|
const language = appKotlinLanguage(root);
|
|
2463
2944
|
const scanned = await scanExpoTypes(toolchain, moduleRoot, modules.sources);
|
|
2464
2945
|
const usesCompose = scanned.some((file) => file.views.length > 0) || modules.sources.some(
|
|
2465
|
-
(file) => /\bandroidx\.compose\./.test(
|
|
2946
|
+
(file) => /\bandroidx\.compose\./.test(import_node_fs16.default.readFileSync(file, "utf8"))
|
|
2466
2947
|
);
|
|
2467
2948
|
const types = expoTypeSources(scanned);
|
|
2468
2949
|
const rewritten = new Set(Object.values(types.origins));
|
|
@@ -2629,6 +3110,7 @@ async function kotlinAppArtifact(app, moduleRoot, origin) {
|
|
|
2629
3110
|
kotlinOptIns: app.kotlinOptIns,
|
|
2630
3111
|
sources: app.sources,
|
|
2631
3112
|
javaSpecs: app.javaSources,
|
|
3113
|
+
gradleLibraries: app.gradleLibraries,
|
|
2632
3114
|
generated,
|
|
2633
3115
|
sdkProfile: "app",
|
|
2634
3116
|
usesCompose: true,
|
|
@@ -2693,7 +3175,7 @@ function appResourceSources(app) {
|
|
|
2693
3175
|
entries: app.drawables.map((drawable) => ({
|
|
2694
3176
|
name: drawable.name,
|
|
2695
3177
|
init: `listOf(
|
|
2696
|
-
${drawable.files.map((file) => drawableInit(file,
|
|
3178
|
+
${drawable.files.map((file) => drawableInit(file, import_node_path15.default.relative(app.moduleDir, file.file))).join(",\n")}
|
|
2697
3179
|
)`
|
|
2698
3180
|
}))
|
|
2699
3181
|
},
|
|
@@ -2817,7 +3299,7 @@ function drawableInit(drawable, file) {
|
|
|
2817
3299
|
if (drawable.kind === "xml") return `PeachDrawable.Xml(${where})`;
|
|
2818
3300
|
if (drawable.kind === "bitmap")
|
|
2819
3301
|
return `PeachDrawable.Bitmap(${where}, ${drawable.ninePatch}, ${literal(
|
|
2820
|
-
|
|
3302
|
+
import_node_fs16.default.readFileSync(drawable.file).toString("base64")
|
|
2821
3303
|
)})`;
|
|
2822
3304
|
const vector = drawable.vector;
|
|
2823
3305
|
const float = (value) => `${value}f`;
|
|
@@ -2879,11 +3361,12 @@ async function compileKotlin(input, origin) {
|
|
|
2879
3361
|
usesCompose,
|
|
2880
3362
|
usesSerialization = false,
|
|
2881
3363
|
viewModels,
|
|
2882
|
-
javaSpecs = []
|
|
3364
|
+
javaSpecs = [],
|
|
3365
|
+
gradleLibraries
|
|
2883
3366
|
} = input;
|
|
2884
3367
|
const sdk = await loadKotlinSdk(moduleRoot, toolchain);
|
|
2885
|
-
const plugin =
|
|
2886
|
-
const sdkLibrary =
|
|
3368
|
+
const plugin = import_node_path15.default.join(sdk.root, "plugin.jar");
|
|
3369
|
+
const sdkLibrary = import_node_path15.default.join(sdk.root, `${sdkProfile}.klib`);
|
|
2887
3370
|
const javaRead = javaSpecs.length ? await readJavaModuleSpecs(javaSpecs, sdk.root, await ensureToolchain(toolchain)) : null;
|
|
2888
3371
|
const java = javaRead && javaRead.specs.some((spec) => !spec.application) ? { ...javaRead, specs: javaRead.specs.filter((spec) => !spec.application) } : null;
|
|
2889
3372
|
const applicationJava = javaRead?.specs.filter((spec) => spec.application) ?? [];
|
|
@@ -2911,10 +3394,10 @@ async function compileKotlin(input, origin) {
|
|
|
2911
3394
|
};
|
|
2912
3395
|
const inputs = sources.map((file) => ({
|
|
2913
3396
|
file,
|
|
2914
|
-
bytes:
|
|
3397
|
+
bytes: import_node_fs16.default.readFileSync(file)
|
|
2915
3398
|
}));
|
|
2916
3399
|
const { composeArchive, ...compilerInputs } = toolchain;
|
|
2917
|
-
const digest = (0,
|
|
3400
|
+
const digest = (0, import_node_crypto11.createHash)("sha256");
|
|
2918
3401
|
digest.update(
|
|
2919
3402
|
JSON.stringify({
|
|
2920
3403
|
format: BUILD_FORMAT,
|
|
@@ -2928,7 +3411,17 @@ async function compileKotlin(input, origin) {
|
|
|
2928
3411
|
})
|
|
2929
3412
|
);
|
|
2930
3413
|
for (const { file, bytes } of inputs)
|
|
2931
|
-
digest.update(
|
|
3414
|
+
digest.update(import_node_path15.default.relative(root, file)).update("\0").update(bytes).update("\0");
|
|
3415
|
+
if (gradleLibraries) {
|
|
3416
|
+
digest.update(JSON.stringify(gradleLibraries));
|
|
3417
|
+
const files = /* @__PURE__ */ new Set([
|
|
3418
|
+
...gradleLibraries.classpath,
|
|
3419
|
+
...gradleLibraries.libraries.flatMap(({ archive, jars }) => [archive, ...jars])
|
|
3420
|
+
]);
|
|
3421
|
+
for (const file of files) {
|
|
3422
|
+
digest.update((0, import_node_crypto11.createHash)("sha256").update(import_node_fs16.default.readFileSync(file)).digest());
|
|
3423
|
+
}
|
|
3424
|
+
}
|
|
2932
3425
|
if (viewModels) digest.update(viewModels.toolClass);
|
|
2933
3426
|
for (const [name, text] of Object.entries(generated))
|
|
2934
3427
|
digest.update(`${name}\0${text}\0`);
|
|
@@ -2937,49 +3430,49 @@ async function compileKotlin(input, origin) {
|
|
|
2937
3430
|
url: `${origin}${KOTLIN_ARTIFACT_PREFIX}${hash}/app.mjs`,
|
|
2938
3431
|
hash
|
|
2939
3432
|
};
|
|
2940
|
-
const out =
|
|
2941
|
-
if (
|
|
2942
|
-
const
|
|
2943
|
-
if (
|
|
3433
|
+
const out = import_node_path15.default.join(buildsDir(), hash);
|
|
3434
|
+
if (import_node_fs16.default.existsSync(import_node_path15.default.join(out, "js", "app.wasm"))) return artifact;
|
|
3435
|
+
const pending2 = builds.get(hash);
|
|
3436
|
+
if (pending2) return pending2;
|
|
2944
3437
|
const build = (async () => {
|
|
2945
3438
|
const ready = await ensureToolchain(toolchain);
|
|
2946
3439
|
const { kotlinc } = ready;
|
|
2947
|
-
const libraries = [...ready.libraries, sdkLibrary,
|
|
3440
|
+
const libraries = [...ready.libraries, sdkLibrary, import_node_path15.default.join(sdk.root, "java.klib")];
|
|
2948
3441
|
const compose = usesCompose ? await ensureCompose(toolchain) : null;
|
|
2949
3442
|
if (compose) libraries.push(...compose.libraries);
|
|
2950
|
-
|
|
2951
|
-
const work =
|
|
2952
|
-
const javaLibrary = java ?
|
|
3443
|
+
import_node_fs16.default.mkdirSync(buildsDir(), { recursive: true });
|
|
3444
|
+
const work = import_node_fs16.default.mkdtempSync(import_node_path15.default.join(buildsDir(), `${hash}-`));
|
|
3445
|
+
const javaLibrary = java ? import_node_path15.default.join(work, "java-abi", "java-abi.klib") : null;
|
|
2953
3446
|
if (javaLibrary) libraries.push(javaLibrary);
|
|
2954
|
-
const generatedDir =
|
|
2955
|
-
|
|
3447
|
+
const generatedDir = import_node_path15.default.join(work, "generated");
|
|
3448
|
+
import_node_fs16.default.mkdirSync(generatedDir);
|
|
2956
3449
|
for (const [name, text] of Object.entries(generated))
|
|
2957
|
-
|
|
3450
|
+
import_node_fs16.default.writeFileSync(import_node_path15.default.join(generatedDir, name), text);
|
|
2958
3451
|
const compiledSources = inputs.map(({ file, bytes }, index) => {
|
|
2959
|
-
const target =
|
|
2960
|
-
|
|
2961
|
-
|
|
3452
|
+
const target = import_node_path15.default.join(work, "sources", String(index), import_node_path15.default.basename(file));
|
|
3453
|
+
import_node_fs16.default.mkdirSync(import_node_path15.default.dirname(target), { recursive: true });
|
|
3454
|
+
import_node_fs16.default.writeFileSync(target, bytes);
|
|
2962
3455
|
return { file, target };
|
|
2963
3456
|
});
|
|
2964
|
-
const common = [
|
|
3457
|
+
const common = () => [
|
|
2965
3458
|
// the full upstream Compose graph exceeds kotlinc's 512 mib default heap.
|
|
2966
3459
|
"-J-Xmx2g",
|
|
2967
3460
|
"-Xallow-kotlin-package",
|
|
2968
3461
|
"-Xwasm-target=js",
|
|
2969
3462
|
"-libraries",
|
|
2970
|
-
libraries.join(
|
|
3463
|
+
libraries.join(import_node_path15.default.delimiter)
|
|
2971
3464
|
];
|
|
2972
3465
|
const compileKlib = (outputDir) => run5(
|
|
2973
3466
|
kotlinc,
|
|
2974
3467
|
[
|
|
2975
|
-
...common,
|
|
3468
|
+
...common(),
|
|
2976
3469
|
`-Xplugin=${plugin}`,
|
|
2977
|
-
`-Xfriend-modules=${[sdkLibrary, ...javaLibrary ? [javaLibrary] : []].join(
|
|
3470
|
+
`-Xfriend-modules=${[sdkLibrary, ...javaLibrary ? [javaLibrary] : []].join(import_node_path15.default.delimiter)}`,
|
|
2978
3471
|
...usesCompose ? [
|
|
2979
|
-
`-Xplugin=${
|
|
3472
|
+
`-Xplugin=${import_node_path15.default.resolve(import_node_path15.default.dirname(kotlinc), "../lib/compose-compiler-plugin.jar")}`
|
|
2980
3473
|
] : [],
|
|
2981
3474
|
...usesSerialization ? [
|
|
2982
|
-
`-Xplugin=${
|
|
3475
|
+
`-Xplugin=${import_node_path15.default.resolve(import_node_path15.default.dirname(kotlinc), "../lib/kotlinx-serialization-compiler-plugin.jar")}`
|
|
2983
3476
|
] : [],
|
|
2984
3477
|
"-language-version",
|
|
2985
3478
|
language,
|
|
@@ -2993,11 +3486,23 @@ async function compileKotlin(input, origin) {
|
|
|
2993
3486
|
"-ir-output-name",
|
|
2994
3487
|
"app",
|
|
2995
3488
|
...compiledSources.map(({ target }) => target),
|
|
2996
|
-
...Object.keys(generated).map((name) =>
|
|
3489
|
+
...Object.keys(generated).map((name) => import_node_path15.default.join(generatedDir, name))
|
|
2997
3490
|
],
|
|
2998
3491
|
{ maxBuffer: 16 * 1024 * 1024 }
|
|
2999
3492
|
);
|
|
3000
3493
|
try {
|
|
3494
|
+
if (gradleLibraries) {
|
|
3495
|
+
libraries.push(
|
|
3496
|
+
...await compileKotlinGradleLibraries({
|
|
3497
|
+
plan: gradleLibraries,
|
|
3498
|
+
ready,
|
|
3499
|
+
sdkRoot: sdk.root,
|
|
3500
|
+
libraries: libraries.filter((library) => library !== javaLibrary),
|
|
3501
|
+
language,
|
|
3502
|
+
output: import_node_path15.default.join(work, "gradle-libraries")
|
|
3503
|
+
})
|
|
3504
|
+
);
|
|
3505
|
+
}
|
|
3001
3506
|
if (java)
|
|
3002
3507
|
await compileJavaModuleAbi({
|
|
3003
3508
|
specs: java,
|
|
@@ -3012,49 +3517,49 @@ async function compileKotlin(input, origin) {
|
|
|
3012
3517
|
if (viewModels && inputs.some(
|
|
3013
3518
|
({ file, bytes }) => sources.includes(file) && bytes.includes("ViewModel")
|
|
3014
3519
|
)) {
|
|
3015
|
-
await compileKlib(
|
|
3520
|
+
await compileKlib(import_node_path15.default.join(work, "abi"));
|
|
3016
3521
|
const stdout = await runKotlinTool(
|
|
3017
3522
|
ready,
|
|
3018
3523
|
sdk.root,
|
|
3019
3524
|
viewModels.toolClass,
|
|
3020
|
-
[
|
|
3525
|
+
[import_node_path15.default.join(work, "abi")],
|
|
3021
3526
|
64 * 1024 * 1024
|
|
3022
3527
|
);
|
|
3023
|
-
|
|
3024
|
-
|
|
3528
|
+
import_node_fs16.default.writeFileSync(
|
|
3529
|
+
import_node_path15.default.join(generatedDir, viewModels.file),
|
|
3025
3530
|
viewModels.render(viewModelClasses(readAbiClasses(stdout)))
|
|
3026
3531
|
);
|
|
3027
3532
|
}
|
|
3028
|
-
await compileKlib(
|
|
3533
|
+
await compileKlib(import_node_path15.default.join(work, "klib"));
|
|
3029
3534
|
await run5(
|
|
3030
3535
|
kotlinc,
|
|
3031
3536
|
[
|
|
3032
|
-
...common,
|
|
3537
|
+
...common(),
|
|
3033
3538
|
"-nowarn",
|
|
3034
3539
|
"-Xpartial-linkage-loglevel=error",
|
|
3035
|
-
`-Xinclude=${
|
|
3540
|
+
`-Xinclude=${import_node_path15.default.join(work, "klib")}`,
|
|
3036
3541
|
"-Xir-produce-js",
|
|
3037
3542
|
"-Xir-dce",
|
|
3038
3543
|
"-ir-output-dir",
|
|
3039
|
-
|
|
3544
|
+
import_node_path15.default.join(work, "js"),
|
|
3040
3545
|
"-ir-output-name",
|
|
3041
3546
|
"app"
|
|
3042
3547
|
],
|
|
3043
3548
|
{ maxBuffer: 16 * 1024 * 1024 }
|
|
3044
3549
|
);
|
|
3045
3550
|
if (compose) {
|
|
3046
|
-
|
|
3047
|
-
|
|
3048
|
-
kotlinSkikoSource(
|
|
3551
|
+
import_node_fs16.default.writeFileSync(
|
|
3552
|
+
import_node_path15.default.join(work, "js", "skiko.mjs"),
|
|
3553
|
+
kotlinSkikoSource(import_node_fs16.default.readFileSync(compose.loader))
|
|
3049
3554
|
);
|
|
3050
3555
|
}
|
|
3051
3556
|
if (usesCompose) {
|
|
3052
3557
|
for (const library of toolchain.composeJsLibraries) {
|
|
3053
3558
|
let imported = false;
|
|
3054
|
-
for (const file of
|
|
3559
|
+
for (const file of import_node_fs16.default.readdirSync(import_node_path15.default.join(work, "js"))) {
|
|
3055
3560
|
if (!file.endsWith(".mjs")) continue;
|
|
3056
|
-
const target =
|
|
3057
|
-
const source =
|
|
3561
|
+
const target = import_node_path15.default.join(work, "js", file);
|
|
3562
|
+
const source = import_node_fs16.default.readFileSync(target, "utf8");
|
|
3058
3563
|
let next = source;
|
|
3059
3564
|
for (const quote of ["'", '"'])
|
|
3060
3565
|
next = next.replaceAll(
|
|
@@ -3062,11 +3567,11 @@ async function compileKotlin(input, origin) {
|
|
|
3062
3567
|
`from ${quote}./${library.file}${quote}`
|
|
3063
3568
|
);
|
|
3064
3569
|
if (next === source) continue;
|
|
3065
|
-
|
|
3570
|
+
import_node_fs16.default.writeFileSync(target, next);
|
|
3066
3571
|
imported = true;
|
|
3067
3572
|
}
|
|
3068
3573
|
if (!imported) continue;
|
|
3069
|
-
const archive =
|
|
3574
|
+
const archive = import_node_path15.default.join(
|
|
3070
3575
|
kotlinHome(),
|
|
3071
3576
|
toolchain.compiler.version,
|
|
3072
3577
|
library.name
|
|
@@ -3075,24 +3580,24 @@ async function compileKotlin(input, origin) {
|
|
|
3075
3580
|
const { stdout } = await run5("tar", ["-xOf", archive, library.archiveEntry], {
|
|
3076
3581
|
maxBuffer: 16 * 1024 * 1024
|
|
3077
3582
|
});
|
|
3078
|
-
|
|
3583
|
+
import_node_fs16.default.writeFileSync(import_node_path15.default.join(work, "js", library.file), stdout);
|
|
3079
3584
|
}
|
|
3080
3585
|
}
|
|
3081
3586
|
} catch (error) {
|
|
3082
|
-
|
|
3587
|
+
import_node_fs16.default.rmSync(work, { recursive: true, force: true });
|
|
3083
3588
|
let output = isRecord(error) ? `${String(error.stderr ?? "")}${String(error.stdout ?? "")}` : "";
|
|
3084
3589
|
for (const [name, source] of Object.entries(origins))
|
|
3085
|
-
output = output.replaceAll(
|
|
3590
|
+
output = output.replaceAll(import_node_path15.default.join(generatedDir, name), source);
|
|
3086
3591
|
for (const [index, spec] of applicationJava.entries())
|
|
3087
3592
|
output = output.replaceAll(
|
|
3088
|
-
|
|
3593
|
+
import_node_path15.default.join(generatedDir, `JavaApplication${index}.kt`),
|
|
3089
3594
|
spec.file
|
|
3090
3595
|
);
|
|
3091
3596
|
for (const { file, target } of compiledSources)
|
|
3092
|
-
output = output.replaceAll(target, file).replaceAll(
|
|
3597
|
+
output = output.replaceAll(target, file).replaceAll(import_node_path15.default.relative(process.cwd(), target), file);
|
|
3093
3598
|
for (const [index, spec] of (java?.specs ?? []).entries())
|
|
3094
3599
|
output = output.replaceAll(
|
|
3095
|
-
|
|
3600
|
+
import_node_path15.default.join(work, "java-abi", `Spec${index}.kt`),
|
|
3096
3601
|
spec.file
|
|
3097
3602
|
);
|
|
3098
3603
|
output = output.replace(
|
|
@@ -3105,20 +3610,20 @@ ${output.trim() || (error instanceof Error ? error.message : String(error))}`
|
|
|
3105
3610
|
);
|
|
3106
3611
|
}
|
|
3107
3612
|
const seams = [kotlinNodeDetection];
|
|
3108
|
-
const js =
|
|
3613
|
+
const js = import_node_fs16.default.readdirSync(import_node_path15.default.join(work, "js")).filter((file) => file.endsWith(".mjs"));
|
|
3109
3614
|
if (js.some(
|
|
3110
|
-
(file) =>
|
|
3615
|
+
(file) => import_node_fs16.default.readFileSync(import_node_path15.default.join(work, "js", file), "utf8").includes("'kotlinx.coroutines.")
|
|
3111
3616
|
))
|
|
3112
3617
|
seams.push(kotlinCoroutineDispatcher);
|
|
3113
3618
|
for (const [from, to] of seams) {
|
|
3114
3619
|
let patched = 0;
|
|
3115
3620
|
for (const file of js) {
|
|
3116
|
-
const target =
|
|
3117
|
-
const text =
|
|
3621
|
+
const target = import_node_path15.default.join(work, "js", file);
|
|
3622
|
+
const text = import_node_fs16.default.readFileSync(target, "utf8");
|
|
3118
3623
|
const next = text.replaceAll(from, to);
|
|
3119
3624
|
if (next !== text) {
|
|
3120
3625
|
patched++;
|
|
3121
|
-
|
|
3626
|
+
import_node_fs16.default.writeFileSync(target, next);
|
|
3122
3627
|
}
|
|
3123
3628
|
}
|
|
3124
3629
|
if (patched === 0)
|
|
@@ -3126,11 +3631,11 @@ ${output.trim() || (error instanceof Error ? error.message : String(error))}`
|
|
|
3126
3631
|
`kotlin output no longer contains ${from}; recheck how it detects its host in Peach`
|
|
3127
3632
|
);
|
|
3128
3633
|
}
|
|
3129
|
-
const entry =
|
|
3130
|
-
const entrySource2 =
|
|
3131
|
-
const importsPath =
|
|
3634
|
+
const entry = import_node_path15.default.join(work, "js/app.mjs");
|
|
3635
|
+
const entrySource2 = import_node_fs16.default.readFileSync(entry, "utf8");
|
|
3636
|
+
const importsPath = import_node_path15.default.join(work, "js/app.import-object.mjs");
|
|
3132
3637
|
const importsFactory = kotlinInstanceSource(
|
|
3133
|
-
|
|
3638
|
+
import_node_fs16.default.readFileSync(importsPath, "utf8"),
|
|
3134
3639
|
"createKotlinImportObject"
|
|
3135
3640
|
);
|
|
3136
3641
|
const runtimeFactory = kotlinInstanceSource(
|
|
@@ -3138,9 +3643,9 @@ ${output.trim() || (error instanceof Error ? error.message : String(error))}`
|
|
|
3138
3643
|
"createKotlinInstance",
|
|
3139
3644
|
/* @__PURE__ */ new Map([["./app.import-object.mjs", "createKotlinImportObject"]])
|
|
3140
3645
|
);
|
|
3141
|
-
|
|
3142
|
-
|
|
3143
|
-
|
|
3646
|
+
import_node_fs16.default.writeFileSync(importsPath, importsFactory.source);
|
|
3647
|
+
import_node_fs16.default.writeFileSync(import_node_path15.default.join(work, "js/app-runtime.mjs"), runtimeFactory.source);
|
|
3648
|
+
import_node_fs16.default.writeFileSync(
|
|
3144
3649
|
entry,
|
|
3145
3650
|
[
|
|
3146
3651
|
"import { createKotlinInstance } from './app-runtime.mjs';",
|
|
@@ -3153,10 +3658,10 @@ ${output.trim() || (error instanceof Error ? error.message : String(error))}`
|
|
|
3153
3658
|
].join("\n")
|
|
3154
3659
|
);
|
|
3155
3660
|
try {
|
|
3156
|
-
|
|
3661
|
+
import_node_fs16.default.renameSync(work, out);
|
|
3157
3662
|
} catch (error) {
|
|
3158
|
-
if (!
|
|
3159
|
-
|
|
3663
|
+
if (!import_node_fs16.default.existsSync(import_node_path15.default.join(out, "js", "app.wasm"))) throw error;
|
|
3664
|
+
import_node_fs16.default.rmSync(work, { recursive: true, force: true });
|
|
3160
3665
|
}
|
|
3161
3666
|
return artifact;
|
|
3162
3667
|
})().finally(() => builds.delete(hash));
|
|
@@ -3168,24 +3673,24 @@ var CONTENT_TYPES = {
|
|
|
3168
3673
|
".wasm": "application/wasm"
|
|
3169
3674
|
};
|
|
3170
3675
|
function kotlinArtifactFiles(hash) {
|
|
3171
|
-
const dir =
|
|
3172
|
-
return
|
|
3173
|
-
const contentType = CONTENT_TYPES[
|
|
3676
|
+
const dir = import_node_path15.default.join(buildsDir(), hash, "js");
|
|
3677
|
+
return import_node_fs16.default.readdirSync(dir).sort().map((name) => {
|
|
3678
|
+
const contentType = CONTENT_TYPES[import_node_path15.default.extname(name)];
|
|
3174
3679
|
if (!contentType) throw new Error(`unexpected kotlin artifact file ${name}`);
|
|
3175
|
-
return { name, bytes:
|
|
3680
|
+
return { name, bytes: import_node_fs16.default.readFileSync(import_node_path15.default.join(dir, name)), contentType };
|
|
3176
3681
|
});
|
|
3177
3682
|
}
|
|
3178
3683
|
function serveKotlinArtifact(pathname, res) {
|
|
3179
3684
|
if (!pathname.startsWith(KOTLIN_ARTIFACT_PREFIX)) return false;
|
|
3180
3685
|
const [hash, file, ...rest] = pathname.slice(KOTLIN_ARTIFACT_PREFIX.length).split("/");
|
|
3181
|
-
const type = file ? CONTENT_TYPES[
|
|
3686
|
+
const type = file ? CONTENT_TYPES[import_node_path15.default.extname(file)] : void 0;
|
|
3182
3687
|
if (!hash || !/^[0-9a-f]+$/.test(hash) || !file || rest.length > 0 || !type || file.includes("..")) {
|
|
3183
3688
|
res.statusCode = 404;
|
|
3184
3689
|
res.end("not a kotlin artifact");
|
|
3185
3690
|
return true;
|
|
3186
3691
|
}
|
|
3187
|
-
const target =
|
|
3188
|
-
if (!
|
|
3692
|
+
const target = import_node_path15.default.join(buildsDir(), hash, "js", file);
|
|
3693
|
+
if (!import_node_fs16.default.existsSync(target)) {
|
|
3189
3694
|
res.statusCode = 404;
|
|
3190
3695
|
res.end(`kotlin artifact ${hash}/${file} was not built`);
|
|
3191
3696
|
return true;
|
|
@@ -3193,7 +3698,7 @@ function serveKotlinArtifact(pathname, res) {
|
|
|
3193
3698
|
res.setHeader("access-control-allow-origin", "*");
|
|
3194
3699
|
res.setHeader("content-type", type);
|
|
3195
3700
|
res.setHeader("cache-control", "public, max-age=31536000, immutable");
|
|
3196
|
-
res.end(
|
|
3701
|
+
res.end(import_node_fs16.default.readFileSync(target));
|
|
3197
3702
|
return true;
|
|
3198
3703
|
}
|
|
3199
3704
|
async function serveKotlinRequest(pathname, res, app) {
|