peachsim 0.1.2411 → 0.1.2421
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/README.md +1 -1
- package/cli/catalog/content.ts +6 -3
- package/cli/catalog/meta.ts +63 -17
- package/cli/catalog/routes.ts +4 -0
- package/cli/cloud-box-artifact.ts +45 -24
- package/cli/cloud-client.ts +6 -2
- package/cli/command-registry.ts +3 -1
- package/cli/commands/control.ts +74 -55
- package/cli/commands/desktop.ts +3 -3
- package/cli/commands/electron.ts +7 -5
- package/cli/commands/kotlin.ts +8 -1
- package/cli/commands/platform.ts +5 -7
- package/cli/commands/profile.ts +2 -2
- package/cli/commands/settings.ts +90 -0
- package/cli/commands/shell-url.ts +18 -10
- package/cli/commands/swift.ts +3 -1
- package/cli/main.ts +6 -0
- package/cli/outbound-endpoints.ts +17 -15
- package/cli/settings-flags.ts +115 -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 +3706 -1818
- 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 +3 -7
- package/dist-lib/config.mjs +3 -7
- package/dist-lib/detox/index.cjs +4 -4
- package/dist-lib/dev-bundle-resolution.cjs +1 -1
- package/dist-lib/expo-swift-bundle.cjs +17144 -15295
- 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 +63288 -62269
- package/dist-lib/host/fetch-proxy-handler.cjs +1598 -211
- 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 +3007 -1512
- 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 +972 -246
- 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 +1742 -247
- package/dist-lib/native-app-identity-project.cjs +40 -204
- package/dist-lib/native-app-identity-project.mjs +40 -204
- 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/pdfium-raster.cjs +1 -1
- package/dist-lib/pdfium-raster.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 +26 -24
- package/dist-lib/public-origins-lib.json +198 -117
- package/dist-lib/react-native-host-modules.cjs +1 -1
- package/dist-lib/react-native-host-modules.mjs +1 -1
- package/dist-lib/reap-browser.cjs +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 +21765 -20511
- package/dist-lib/swift-compile.cjs +48 -228
- package/dist-lib/swift-compile.mjs +48 -228
- 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 -199
- package/dist-lib/swift.cjs +1 -1
- package/dist-lib/vite-swift.cjs +227 -251
- package/dist-lib/vite.cjs +5240 -3788
- package/dist-lib/worklet-executable.cjs +1 -1
- package/dist-lib/worklet-executable.mjs +1 -1
- package/dist-types/packages/peach-engine/src/config.d.ts +1 -4
- package/dist-types/packages/peach-engine/src/engine/image-loader.d.ts +1 -0
- package/dist-types/packages/peach-engine/src/render-worker/compositor-gpu.d.ts +1 -0
- package/dist-types/packages/peach-engine/src/render-worker/compositor-protocol.d.ts +4 -0
- package/dist-types/packages/peach-engine/src/render-worker/native-widgetContract.d.ts +5 -0
- package/kotlin/README.md +4 -3
- package/kotlin/sdk.tar.gz +0 -0
- package/kotlin/toolchain.json +3 -6
- package/package.json +1 -1
- package/runtime-companion.json +1 -1
- package/sdk/ios/System/Library/Frameworks/QuartzCore.framework/Headers/CALayer.h +1 -43
- package/sdk/ios/System/Library/Frameworks/QuartzCore.framework/Headers/CALayerContents.h +55 -0
- package/sdk/ios/System/Library/Frameworks/QuartzCore.framework/Modules/module.modulemap +3 -3
- package/sdk/ios/usr/include/ObjectiveC.apinotes +0 -24
- package/sdk/ios/usr/include/grp.h +93 -0
- package/sdk/ios/usr/include/netinet/tcp.h +299 -0
- package/sdk/ios/wasm/include/netinet/tcp.h +6 -0
- package/sdk/ios/wasm/include/stdlib.h +1 -0
- package/sdk/ios/wasm/include/unistd.h +2 -0
- package/skills/contrast/SKILL.md +1 -0
- package/skills/peach-setup/SKILL.md +11 -1
- package/src/android-bridge-dependencies.ts +1 -1
- package/src/app-config.ts +7 -0
- package/src/binaryen.lock.json +21 -0
- package/src/cocoapods-trunk.ts +52 -0
- package/src/config.ts +21 -31
- package/src/expo-native-workspace.ts +4 -0
- package/src/kotlin-host.ts +1 -1
- package/src/kotlin-sdk.ts +7 -7
- package/src/kotlin-toolchain.ts +28 -24
- package/src/kotlinSdkContract.ts +2 -2
- package/src/native-bundles.ts +5 -2
- package/src/native-static-libraries.ts +38 -5
- package/src/podfile-cocoapods.ts +1473 -0
- package/src/podspec-cocoapods.ts +331 -106
- package/src/podspec-ruby-stdlib.ts +134 -19
- package/src/podspec-ruby.ts +199 -46
- package/src/settingsContract.ts +74 -0
- package/src/swift-compile.ts +1 -1
- package/src/swift-compiler-digest.ts +1 -0
- package/src/swift-host.ts +107 -15
- package/src/swift-objc-compile.ts +5 -0
- package/src/swift-packages.ts +75 -0
- package/src/swift-shared-sdk.ts +19 -0
- package/src/swift-toolchain.ts +2 -201
- package/src/turbo-source.ts +7 -37
- package/src/wasm-optimize.ts +4 -27
- package/src/xcode-project.ts +22 -7
package/dist-lib/kotlin-host.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! peach v0.1.
|
|
1
|
+
/*! peach v0.1.2421 | (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;
|
|
@@ -42,20 +42,744 @@ var init_is_record = __esm({
|
|
|
42
42
|
}
|
|
43
43
|
});
|
|
44
44
|
|
|
45
|
+
// src/process-table.ts
|
|
46
|
+
function linuxClockTicks() {
|
|
47
|
+
const auxv = (0, import_node_fs.readFileSync)("/proc/self/auxv");
|
|
48
|
+
const word = (offset) => (0, import_node_os.endianness)() === "LE" ? auxv.readBigUInt64LE(offset) : auxv.readBigUInt64BE(offset);
|
|
49
|
+
for (let offset = 0; offset + 16 <= auxv.length; offset += 16) {
|
|
50
|
+
if (word(offset) !== 17n) continue;
|
|
51
|
+
const ticks = Number(word(offset + 8));
|
|
52
|
+
if (!Number.isSafeInteger(ticks) || ticks <= 0)
|
|
53
|
+
throw new Error("unreadable process clock tick rate");
|
|
54
|
+
return ticks;
|
|
55
|
+
}
|
|
56
|
+
throw new Error("missing process clock tick rate");
|
|
57
|
+
}
|
|
58
|
+
function readProcessTable(timeoutMs = 1e4, pid) {
|
|
59
|
+
if (process.platform === "linux") {
|
|
60
|
+
clockTicks ??= linuxClockTicks();
|
|
61
|
+
const boot = /^btime (\d+)$/m.exec((0, import_node_fs.readFileSync)("/proc/stat", "utf8"));
|
|
62
|
+
if (!boot) throw new Error("unreadable process boot time");
|
|
63
|
+
const bootMs = Number(boot[1]) * 1e3;
|
|
64
|
+
const deadline = Date.now() + timeoutMs;
|
|
65
|
+
const rows2 = [];
|
|
66
|
+
const names = pid === void 0 ? (0, import_node_fs.readdirSync)("/proc") : [String(pid)];
|
|
67
|
+
for (const name of names) {
|
|
68
|
+
if (!/^\d+$/.test(name)) continue;
|
|
69
|
+
if (Date.now() >= deadline)
|
|
70
|
+
throw new Error("process inspection exceeded its deadline");
|
|
71
|
+
let stat;
|
|
72
|
+
try {
|
|
73
|
+
stat = (0, import_node_fs.readFileSync)(`/proc/${name}/stat`, "utf8");
|
|
74
|
+
} catch (error) {
|
|
75
|
+
if (error instanceof Error && "code" in error && error.code === "ENOENT") continue;
|
|
76
|
+
throw error;
|
|
77
|
+
}
|
|
78
|
+
const fields = stat.slice(stat.lastIndexOf(")") + 2).trim().split(/\s+/);
|
|
79
|
+
const pgid = Number(fields[2]);
|
|
80
|
+
const ticks = Number(fields[19]);
|
|
81
|
+
if (!fields[0] || !Number.isSafeInteger(pgid) || !Number.isSafeInteger(ticks))
|
|
82
|
+
throw new Error(`unreadable process table row for ${name}`);
|
|
83
|
+
rows2.push({
|
|
84
|
+
pid: Number(name),
|
|
85
|
+
pgid,
|
|
86
|
+
zombie: fields[0] === "Z" || fields[0] === "X",
|
|
87
|
+
start: bootMs + ticks * 1e3 / clockTicks
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
return rows2;
|
|
91
|
+
}
|
|
92
|
+
const result = (0, import_node_child_process.spawnSync)(
|
|
93
|
+
"ps",
|
|
94
|
+
[
|
|
95
|
+
...pid === void 0 ? ["-A"] : ["-p", String(pid)],
|
|
96
|
+
"-o",
|
|
97
|
+
"pid=,pgid=,stat=,lstart="
|
|
98
|
+
],
|
|
99
|
+
{
|
|
100
|
+
encoding: "utf8",
|
|
101
|
+
env: { ...process.env, LC_ALL: "C", TZ: "UTC" },
|
|
102
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
103
|
+
timeout: timeoutMs,
|
|
104
|
+
killSignal: "SIGKILL"
|
|
105
|
+
}
|
|
106
|
+
);
|
|
107
|
+
if (!result.error && pid !== void 0 && result.status === 1 && !result.stdout.trim() && !result.stderr.trim())
|
|
108
|
+
return [];
|
|
109
|
+
if (result.error || result.status !== 0)
|
|
110
|
+
throw new Error(
|
|
111
|
+
result.error?.message || result.stderr.trim() || `ps exited ${result.status}`
|
|
112
|
+
);
|
|
113
|
+
const rows = result.stdout.split("\n").filter((line) => line.trim()).map((line) => {
|
|
114
|
+
const match = /^\s*(\d+)\s+(\d+)\s+(\S+)\s+(.+?)\s*$/.exec(line);
|
|
115
|
+
if (!match) throw new Error(`unreadable process table row: ${line}`);
|
|
116
|
+
const start = Date.parse(`${match[4]} UTC`);
|
|
117
|
+
if (Number.isNaN(start))
|
|
118
|
+
throw new Error(`unreadable process start time "${match[4]}"`);
|
|
119
|
+
return {
|
|
120
|
+
pid: Number(match[1]),
|
|
121
|
+
pgid: Number(match[2]),
|
|
122
|
+
zombie: match[3].startsWith("Z"),
|
|
123
|
+
start
|
|
124
|
+
};
|
|
125
|
+
});
|
|
126
|
+
return pid === void 0 ? rows : rows.filter((row) => row.pid === pid);
|
|
127
|
+
}
|
|
128
|
+
var import_node_child_process, import_node_fs, import_node_os, clockTicks;
|
|
129
|
+
var init_process_table = __esm({
|
|
130
|
+
"src/process-table.ts"() {
|
|
131
|
+
"use strict";
|
|
132
|
+
import_node_child_process = require("node:child_process");
|
|
133
|
+
import_node_fs = require("node:fs");
|
|
134
|
+
import_node_os = require("node:os");
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
// src/process-group.ts
|
|
139
|
+
function listProcessChildren(parents, timeoutMs = 1e4) {
|
|
140
|
+
if (parents.some((pid) => !Number.isInteger(pid) || pid <= 1))
|
|
141
|
+
throw new Error("process inspection requires valid parent pids");
|
|
142
|
+
if (parents.length === 0) return [];
|
|
143
|
+
const deadline = Date.now() + timeoutMs;
|
|
144
|
+
let children;
|
|
145
|
+
if (process.platform === "linux") {
|
|
146
|
+
const lists = [];
|
|
147
|
+
for (const parent of parents) {
|
|
148
|
+
try {
|
|
149
|
+
const tasks = `/proc/${parent}/task`;
|
|
150
|
+
for (const thread of (0, import_node_fs2.readdirSync)(tasks)) {
|
|
151
|
+
if (Date.now() >= deadline)
|
|
152
|
+
throw new Error("process descendant inspection exceeded its deadline");
|
|
153
|
+
try {
|
|
154
|
+
lists.push((0, import_node_fs2.readFileSync)(`${tasks}/${thread}/children`, "utf8"));
|
|
155
|
+
} catch (error) {
|
|
156
|
+
if (!(error instanceof Error && "code" in error && error.code === "ENOENT"))
|
|
157
|
+
throw error;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
} catch (error) {
|
|
161
|
+
if (!(error instanceof Error && "code" in error && error.code === "ENOENT"))
|
|
162
|
+
throw error;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
children = lists.join(" ");
|
|
166
|
+
} else {
|
|
167
|
+
const result = (0, import_node_child_process2.spawnSync)("pgrep", ["-P", parents.join(",")], {
|
|
168
|
+
encoding: "utf8",
|
|
169
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
170
|
+
timeout: Math.max(1, timeoutMs),
|
|
171
|
+
killSignal: "SIGKILL"
|
|
172
|
+
});
|
|
173
|
+
if (result.error || result.status !== 0 && result.status !== 1) {
|
|
174
|
+
throw new Error(
|
|
175
|
+
`could not inspect descendants of processes ${parents.join(",")}: ${result.error?.message || result.stderr.trim() || `pgrep exited ${result.status}`}`
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
children = result.stdout;
|
|
179
|
+
}
|
|
180
|
+
return [...new Set(children.trim().split(/\s+/).map(Number))].filter(
|
|
181
|
+
(pid) => Number.isInteger(pid) && pid > 1 && !parents.includes(pid)
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
function signalProcessGroup(child, signal) {
|
|
185
|
+
if (!child.pid) return;
|
|
186
|
+
try {
|
|
187
|
+
process.kill(-child.pid, signal);
|
|
188
|
+
} catch {
|
|
189
|
+
try {
|
|
190
|
+
process.kill(child.pid, signal);
|
|
191
|
+
} catch {
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
async function protectProcessFreeze(rootPid) {
|
|
196
|
+
const directory = (0, import_node_fs2.mkdtempSync)((0, import_node_path.join)((0, import_node_os2.tmpdir)(), "peach-process-freeze-"));
|
|
197
|
+
const journal = (0, import_node_path.join)(directory, "targets");
|
|
198
|
+
(0, import_node_fs2.writeFileSync)(journal, `group ${rootPid}
|
|
199
|
+
pid ${rootPid}
|
|
200
|
+
`, { mode: 384 });
|
|
201
|
+
const guard = (0, import_node_child_process2.spawn)(
|
|
202
|
+
"/bin/sh",
|
|
203
|
+
[
|
|
204
|
+
"-c",
|
|
205
|
+
`
|
|
206
|
+
(
|
|
207
|
+
journal=$1
|
|
208
|
+
cleanup() {
|
|
209
|
+
trap '' HUP INT TERM
|
|
210
|
+
while read -r kind pid; do
|
|
211
|
+
case $kind in
|
|
212
|
+
group) target=-$pid ;;
|
|
213
|
+
pid) target=$pid ;;
|
|
214
|
+
*) continue ;;
|
|
215
|
+
esac
|
|
216
|
+
kill -TERM "$target" 2>/dev/null || :
|
|
217
|
+
kill -CONT "$target" 2>/dev/null || :
|
|
218
|
+
done < "$journal"
|
|
219
|
+
}
|
|
220
|
+
trap 'cleanup; exit 0' HUP INT TERM
|
|
221
|
+
trap 'rm -f "$journal"; rmdir "\${journal%/*}"' EXIT
|
|
222
|
+
printf 'ready
|
|
223
|
+
'
|
|
224
|
+
if ! IFS= read -r command <&3 || [ "$command" != disarm ]; then cleanup; fi
|
|
225
|
+
) &
|
|
226
|
+
`,
|
|
227
|
+
FREEZE_GUARD_NAME,
|
|
228
|
+
journal
|
|
229
|
+
],
|
|
230
|
+
{
|
|
231
|
+
detached: true,
|
|
232
|
+
// the launcher exits before capture, reparenting the guard outside any
|
|
233
|
+
// nested target tree. fd 3 survives that exit, unlike child.stdin.
|
|
234
|
+
stdio: ["ignore", "pipe", "ignore", "pipe"]
|
|
235
|
+
}
|
|
236
|
+
);
|
|
237
|
+
let guardClosed = false;
|
|
238
|
+
const closed = new Promise(
|
|
239
|
+
(resolveClose) => guard.once("close", () => {
|
|
240
|
+
guardClosed = true;
|
|
241
|
+
resolveClose();
|
|
242
|
+
})
|
|
243
|
+
);
|
|
244
|
+
const control = guard.stdio[3];
|
|
245
|
+
const output = guard.stdout;
|
|
246
|
+
if (!(control instanceof import_node_stream.Duplex) || !output) {
|
|
247
|
+
guard.kill();
|
|
248
|
+
await closed;
|
|
249
|
+
(0, import_node_fs2.rmSync)(directory, { recursive: true, force: true });
|
|
250
|
+
throw new Error("process freeze guard control pipe is unavailable");
|
|
251
|
+
}
|
|
252
|
+
control.on("error", () => {
|
|
253
|
+
});
|
|
254
|
+
try {
|
|
255
|
+
await new Promise((resolveReady, reject) => {
|
|
256
|
+
let readyOutput = "";
|
|
257
|
+
let launcherExited = false;
|
|
258
|
+
const ready = () => {
|
|
259
|
+
if (launcherExited && readyOutput.includes("ready\n")) resolveReady();
|
|
260
|
+
};
|
|
261
|
+
output.on("data", (bytes) => {
|
|
262
|
+
readyOutput += bytes.toString();
|
|
263
|
+
ready();
|
|
264
|
+
});
|
|
265
|
+
guard.once("exit", (code, signal) => {
|
|
266
|
+
if (code !== 0 || signal !== null) {
|
|
267
|
+
reject(new Error("process freeze guard launcher failed"));
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
launcherExited = true;
|
|
271
|
+
ready();
|
|
272
|
+
});
|
|
273
|
+
guard.once("error", reject);
|
|
274
|
+
guard.once(
|
|
275
|
+
"close",
|
|
276
|
+
() => reject(new Error("process freeze guard exited before readiness"))
|
|
277
|
+
);
|
|
278
|
+
});
|
|
279
|
+
} catch (error) {
|
|
280
|
+
control.destroy();
|
|
281
|
+
await closed;
|
|
282
|
+
(0, import_node_fs2.rmSync)(directory, { recursive: true, force: true });
|
|
283
|
+
throw error;
|
|
284
|
+
}
|
|
285
|
+
return {
|
|
286
|
+
record(pid) {
|
|
287
|
+
if (guardClosed || control.destroyed)
|
|
288
|
+
throw new Error("process freeze guard exited during capture");
|
|
289
|
+
(0, import_node_fs2.appendFileSync)(journal, `pid ${pid}
|
|
290
|
+
`);
|
|
291
|
+
},
|
|
292
|
+
async release(disarm) {
|
|
293
|
+
control.end(disarm ? "disarm\n" : void 0);
|
|
294
|
+
await closed;
|
|
295
|
+
(0, import_node_fs2.rmSync)(directory, { recursive: true, force: true });
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
function processesHaveExited(pids, pgid) {
|
|
300
|
+
const mayExist = [-pgid, ...pids].some((target) => {
|
|
301
|
+
try {
|
|
302
|
+
process.kill(target, 0);
|
|
303
|
+
return true;
|
|
304
|
+
} catch (error) {
|
|
305
|
+
return !(error instanceof Error && "code" in error && error.code === "ESRCH");
|
|
306
|
+
}
|
|
307
|
+
});
|
|
308
|
+
if (!mayExist) return true;
|
|
309
|
+
const knownPids = new Set(pids);
|
|
310
|
+
try {
|
|
311
|
+
return !readProcessTable(FORCED_EXIT_TIMEOUT_MS).some(
|
|
312
|
+
(row) => (row.pgid === pgid || knownPids.has(row.pid)) && !row.zombie
|
|
313
|
+
);
|
|
314
|
+
} catch {
|
|
315
|
+
return false;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
function groupIsEmpty(pgid) {
|
|
319
|
+
return processesHaveExited([], pgid);
|
|
320
|
+
}
|
|
321
|
+
async function waitForExit(pids, pgid, timeoutMs) {
|
|
322
|
+
const deadline = Date.now() + timeoutMs;
|
|
323
|
+
const gone = () => processesHaveExited(pids, pgid);
|
|
324
|
+
while (Date.now() < deadline) {
|
|
325
|
+
if (gone()) return true;
|
|
326
|
+
await (0, import_promises.setTimeout)(50);
|
|
327
|
+
}
|
|
328
|
+
return gone();
|
|
329
|
+
}
|
|
330
|
+
async function terminateProcessGroup(child, signal = "SIGTERM", gracefulTimeoutMs = GRACEFUL_TIMEOUT_MS) {
|
|
331
|
+
if (!child.pid) {
|
|
332
|
+
try {
|
|
333
|
+
child.kill(signal);
|
|
334
|
+
} catch {
|
|
335
|
+
}
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
if (child.exitCode !== null || child.signalCode !== null) {
|
|
339
|
+
if (groupIsEmpty(child.pid)) return;
|
|
340
|
+
}
|
|
341
|
+
const freeze = await protectProcessFreeze(child.pid);
|
|
342
|
+
const descendants = /* @__PURE__ */ new Set();
|
|
343
|
+
let inspectionError = null;
|
|
344
|
+
let signaled = false;
|
|
345
|
+
let gracefulDeadline = 0;
|
|
346
|
+
try {
|
|
347
|
+
signalProcessGroup(child, "SIGSTOP");
|
|
348
|
+
let parents = [child.pid];
|
|
349
|
+
const inspectionDeadline = Date.now() + INSPECTION_TIMEOUT_MS;
|
|
350
|
+
while (parents.length > 0) {
|
|
351
|
+
const remaining = inspectionDeadline - Date.now();
|
|
352
|
+
if (remaining <= 0) {
|
|
353
|
+
inspectionError = new Error("process descendant inspection exceeded its deadline");
|
|
354
|
+
break;
|
|
355
|
+
}
|
|
356
|
+
let children;
|
|
357
|
+
try {
|
|
358
|
+
children = listProcessChildren(parents, remaining);
|
|
359
|
+
} catch (error) {
|
|
360
|
+
inspectionError = new Error(`could not inspect descendants: ${String(error)}`);
|
|
361
|
+
break;
|
|
362
|
+
}
|
|
363
|
+
const next = [];
|
|
364
|
+
for (const descendantPid of children) {
|
|
365
|
+
if (!descendants.has(descendantPid)) {
|
|
366
|
+
freeze.record(descendantPid);
|
|
367
|
+
descendants.add(descendantPid);
|
|
368
|
+
next.push(descendantPid);
|
|
369
|
+
try {
|
|
370
|
+
process.kill(descendantPid, "SIGSTOP");
|
|
371
|
+
} catch {
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
parents = next;
|
|
376
|
+
}
|
|
377
|
+
gracefulDeadline = Date.now() + gracefulTimeoutMs;
|
|
378
|
+
try {
|
|
379
|
+
process.kill(child.pid, signal);
|
|
380
|
+
} catch {
|
|
381
|
+
}
|
|
382
|
+
signaled = true;
|
|
383
|
+
} finally {
|
|
384
|
+
signalProcessGroup(child, "SIGCONT");
|
|
385
|
+
for (const pid of descendants) {
|
|
386
|
+
try {
|
|
387
|
+
process.kill(pid, "SIGCONT");
|
|
388
|
+
} catch {
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
await freeze.release(signaled);
|
|
392
|
+
}
|
|
393
|
+
const pids = [child.pid, ...descendants];
|
|
394
|
+
let rootExited = child.exitCode !== null || child.signalCode !== null;
|
|
395
|
+
if (!rootExited) {
|
|
396
|
+
rootExited = await new Promise((resolveExit) => {
|
|
397
|
+
const onExit = () => {
|
|
398
|
+
clearTimeout(deadlineTimer);
|
|
399
|
+
resolveExit(true);
|
|
400
|
+
};
|
|
401
|
+
const deadlineTimer = setTimeout(
|
|
402
|
+
() => {
|
|
403
|
+
child.removeListener("exit", onExit);
|
|
404
|
+
resolveExit(false);
|
|
405
|
+
},
|
|
406
|
+
Math.max(0, gracefulDeadline - Date.now())
|
|
407
|
+
);
|
|
408
|
+
child.once("exit", onExit);
|
|
409
|
+
if (child.exitCode !== null || child.signalCode !== null) {
|
|
410
|
+
child.removeListener("exit", onExit);
|
|
411
|
+
onExit();
|
|
412
|
+
}
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
if (rootExited) {
|
|
416
|
+
signalProcessGroup(child, signal);
|
|
417
|
+
for (const pid of descendants) {
|
|
418
|
+
try {
|
|
419
|
+
process.kill(pid, signal);
|
|
420
|
+
} catch {
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
if (await waitForExit(pids, child.pid, Math.max(0, gracefulDeadline - Date.now()))) {
|
|
425
|
+
if (inspectionError) throw inspectionError;
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
for (const pid of pids) {
|
|
429
|
+
try {
|
|
430
|
+
process.kill(pid, "SIGKILL");
|
|
431
|
+
} catch {
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
signalProcessGroup(child, "SIGKILL");
|
|
435
|
+
const gone = await waitForExit(pids, child.pid, FORCED_EXIT_TIMEOUT_MS);
|
|
436
|
+
if (!gone) {
|
|
437
|
+
const survivors = new Error(
|
|
438
|
+
`process group ${child.pid} exit could not be confirmed after SIGKILL`
|
|
439
|
+
);
|
|
440
|
+
if (!inspectionError) throw survivors;
|
|
441
|
+
throw new Error(`${inspectionError.message}; ${survivors.message}`);
|
|
442
|
+
}
|
|
443
|
+
if (inspectionError) throw inspectionError;
|
|
444
|
+
}
|
|
445
|
+
var import_node_child_process2, import_node_fs2, import_node_os2, import_node_path, import_node_stream, import_promises, GRACEFUL_TIMEOUT_MS, FORCED_EXIT_TIMEOUT_MS, INSPECTION_TIMEOUT_MS, FREEZE_GUARD_NAME;
|
|
446
|
+
var init_process_group = __esm({
|
|
447
|
+
"src/process-group.ts"() {
|
|
448
|
+
"use strict";
|
|
449
|
+
import_node_child_process2 = require("node:child_process");
|
|
450
|
+
import_node_fs2 = require("node:fs");
|
|
451
|
+
import_node_os2 = require("node:os");
|
|
452
|
+
import_node_path = require("node:path");
|
|
453
|
+
import_node_stream = require("node:stream");
|
|
454
|
+
import_promises = require("node:timers/promises");
|
|
455
|
+
init_process_table();
|
|
456
|
+
GRACEFUL_TIMEOUT_MS = 3e3;
|
|
457
|
+
FORCED_EXIT_TIMEOUT_MS = 1e3;
|
|
458
|
+
INSPECTION_TIMEOUT_MS = 1e4;
|
|
459
|
+
FREEZE_GUARD_NAME = "process-freeze-guard";
|
|
460
|
+
}
|
|
461
|
+
});
|
|
462
|
+
|
|
463
|
+
// ../contrast-runtime-delivery/src/version.ts
|
|
464
|
+
var init_version = __esm({
|
|
465
|
+
"../contrast-runtime-delivery/src/version.ts"() {
|
|
466
|
+
"use strict";
|
|
467
|
+
}
|
|
468
|
+
});
|
|
469
|
+
|
|
470
|
+
// ../contrast-runtime-delivery/src/product.ts
|
|
471
|
+
var init_product = __esm({
|
|
472
|
+
"../contrast-runtime-delivery/src/product.ts"() {
|
|
473
|
+
"use strict";
|
|
474
|
+
init_version();
|
|
475
|
+
}
|
|
476
|
+
});
|
|
477
|
+
|
|
478
|
+
// ../contrast-runtime-delivery/src/packs.ts
|
|
479
|
+
var init_packs = __esm({
|
|
480
|
+
"../contrast-runtime-delivery/src/packs.ts"() {
|
|
481
|
+
"use strict";
|
|
482
|
+
}
|
|
483
|
+
});
|
|
484
|
+
|
|
485
|
+
// ../contrast-runtime-delivery/src/index.ts
|
|
486
|
+
async function installVerifiedTarball(tarball) {
|
|
487
|
+
const { destDir, installedMarker, signal } = tarball;
|
|
488
|
+
import_node_fs3.default.mkdirSync(import_node_path2.default.dirname(destDir), { recursive: true });
|
|
489
|
+
const presentAtStart = import_node_fs3.default.existsSync(import_node_path2.default.join(destDir, installedMarker));
|
|
490
|
+
const lock = `${destDir}.lock`;
|
|
491
|
+
for (; ; ) {
|
|
492
|
+
signal?.throwIfAborted();
|
|
493
|
+
try {
|
|
494
|
+
import_node_fs3.default.writeFileSync(lock, String(process.pid), { flag: "wx" });
|
|
495
|
+
break;
|
|
496
|
+
} catch (err) {
|
|
497
|
+
if (!isErrnoCode(err, "EEXIST")) throw err;
|
|
498
|
+
if (lockOwnerGone(lock)) import_node_fs3.default.rmSync(lock, { force: true });
|
|
499
|
+
else await new Promise((resolve) => setTimeout(resolve, 250));
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
try {
|
|
503
|
+
if (!presentAtStart && import_node_fs3.default.existsSync(import_node_path2.default.join(destDir, installedMarker))) {
|
|
504
|
+
await tarball.verify?.(destDir);
|
|
505
|
+
return;
|
|
506
|
+
}
|
|
507
|
+
await installVerifiedTarballLocked(tarball, presentAtStart);
|
|
508
|
+
} finally {
|
|
509
|
+
import_node_fs3.default.rmSync(lock, { force: true });
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
function lockOwnerGone(lock) {
|
|
513
|
+
try {
|
|
514
|
+
process.kill(Number(import_node_fs3.default.readFileSync(lock, "utf8")), 0);
|
|
515
|
+
return false;
|
|
516
|
+
} catch (err) {
|
|
517
|
+
return !isErrnoCode(err, "EPERM", "ENOENT");
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
async function installVerifiedTarballLocked(tarball, presentAtStart) {
|
|
521
|
+
const { url, digest, destDir, installedMarker, label, signal } = tarball;
|
|
522
|
+
signal?.throwIfAborted();
|
|
523
|
+
const downloadDir = import_node_fs3.default.mkdtempSync(import_node_path2.default.join(import_node_os3.default.tmpdir(), "runtime-delivery-download-"));
|
|
524
|
+
const archivePath = import_node_path2.default.join(downloadDir, "archive");
|
|
525
|
+
const tmpDir = import_node_fs3.default.mkdtempSync(
|
|
526
|
+
import_node_path2.default.join(import_node_path2.default.dirname(destDir), `.installing-${import_node_path2.default.basename(destDir)}-`)
|
|
527
|
+
);
|
|
528
|
+
try {
|
|
529
|
+
for (let attempt = 1; ; attempt++) {
|
|
530
|
+
await downloadToFile(url, archivePath, signal);
|
|
531
|
+
const actual = await digestFile(
|
|
532
|
+
archivePath,
|
|
533
|
+
digest.algorithm,
|
|
534
|
+
digest.encoding,
|
|
535
|
+
signal
|
|
536
|
+
);
|
|
537
|
+
if (actual === digest.value) break;
|
|
538
|
+
if (attempt >= 2) {
|
|
539
|
+
throw new Error(
|
|
540
|
+
`${digest.algorithm} mismatch for ${label}: expected ${digest.value}, actual ${actual}`
|
|
541
|
+
);
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
const { pathname } = new URL(url);
|
|
545
|
+
if (pathname.endsWith(".zip")) await extractZip(archivePath, tmpDir, signal);
|
|
546
|
+
else
|
|
547
|
+
await extractTarball(
|
|
548
|
+
archivePath,
|
|
549
|
+
pathname.endsWith(".tar.zst"),
|
|
550
|
+
tmpDir,
|
|
551
|
+
tarball.stripComponents ?? 0,
|
|
552
|
+
signal
|
|
553
|
+
);
|
|
554
|
+
signal?.throwIfAborted();
|
|
555
|
+
if (!import_node_fs3.default.existsSync(import_node_path2.default.join(tmpDir, installedMarker))) {
|
|
556
|
+
throw new Error(`extracted tarball for ${label} is missing ${installedMarker}`);
|
|
557
|
+
}
|
|
558
|
+
await tarball.verify?.(tmpDir);
|
|
559
|
+
signal?.throwIfAborted();
|
|
560
|
+
try {
|
|
561
|
+
import_node_fs3.default.renameSync(tmpDir, destDir);
|
|
562
|
+
} catch (err) {
|
|
563
|
+
if (!isErrnoCode(err, "ENOTEMPTY", "EEXIST")) throw err;
|
|
564
|
+
if (!presentAtStart && import_node_fs3.default.existsSync(import_node_path2.default.join(destDir, installedMarker))) {
|
|
565
|
+
await tarball.verify?.(destDir);
|
|
566
|
+
return;
|
|
567
|
+
}
|
|
568
|
+
const aside = `${tmpDir}-replaced`;
|
|
569
|
+
try {
|
|
570
|
+
import_node_fs3.default.renameSync(destDir, aside);
|
|
571
|
+
} catch (moveErr) {
|
|
572
|
+
if (!isErrnoCode(moveErr, "ENOENT")) throw moveErr;
|
|
573
|
+
}
|
|
574
|
+
try {
|
|
575
|
+
import_node_fs3.default.renameSync(tmpDir, destDir);
|
|
576
|
+
} catch (landErr) {
|
|
577
|
+
if (!isErrnoCode(landErr, "ENOTEMPTY", "EEXIST") || !import_node_fs3.default.existsSync(import_node_path2.default.join(destDir, installedMarker))) {
|
|
578
|
+
throw landErr;
|
|
579
|
+
}
|
|
580
|
+
await tarball.verify?.(destDir);
|
|
581
|
+
} finally {
|
|
582
|
+
import_node_fs3.default.rmSync(aside, { recursive: true, force: true });
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
} finally {
|
|
586
|
+
import_node_fs3.default.rmSync(tmpDir, { recursive: true, force: true });
|
|
587
|
+
import_node_fs3.default.rmSync(downloadDir, { recursive: true, force: true });
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
function isErrnoCode(err, ...codes) {
|
|
591
|
+
return err instanceof Error && "code" in err && codes.includes(String(err.code));
|
|
592
|
+
}
|
|
593
|
+
async function waitRetryDelay(ms, signal) {
|
|
594
|
+
signal?.throwIfAborted();
|
|
595
|
+
await new Promise((resolve, reject) => {
|
|
596
|
+
const onAbort = () => {
|
|
597
|
+
clearTimeout(timer);
|
|
598
|
+
const reason = signal?.reason;
|
|
599
|
+
reject(
|
|
600
|
+
reason instanceof Error ? reason : new Error("Download canceled", { cause: reason })
|
|
601
|
+
);
|
|
602
|
+
};
|
|
603
|
+
const timer = setTimeout(() => {
|
|
604
|
+
signal?.removeEventListener("abort", onAbort);
|
|
605
|
+
resolve();
|
|
606
|
+
}, ms);
|
|
607
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
608
|
+
});
|
|
609
|
+
}
|
|
610
|
+
async function downloadToFile(url, destPath, signal) {
|
|
611
|
+
import_node_fs3.default.mkdirSync(import_node_path2.default.dirname(destPath), { recursive: true });
|
|
612
|
+
const tmp = `${destPath}.partial`;
|
|
613
|
+
for (let attempt = 1; attempt <= 4; attempt++) {
|
|
614
|
+
signal?.throwIfAborted();
|
|
615
|
+
let reader;
|
|
616
|
+
let handle;
|
|
617
|
+
let completed = false;
|
|
618
|
+
try {
|
|
619
|
+
const res = await fetch(url, { signal });
|
|
620
|
+
if (!res.ok || !res.body) {
|
|
621
|
+
throw new DownloadHttpError(res.status, res.statusText, url);
|
|
622
|
+
}
|
|
623
|
+
reader = res.body.getReader();
|
|
624
|
+
handle = await import_node_fs3.default.promises.open(tmp, "w");
|
|
625
|
+
let written = 0;
|
|
626
|
+
for (; ; ) {
|
|
627
|
+
signal?.throwIfAborted();
|
|
628
|
+
const { done, value } = await reader.read();
|
|
629
|
+
if (done) break;
|
|
630
|
+
let offset = 0;
|
|
631
|
+
while (offset < value.byteLength) {
|
|
632
|
+
const { bytesWritten } = await handle.write(
|
|
633
|
+
value,
|
|
634
|
+
offset,
|
|
635
|
+
value.byteLength - offset
|
|
636
|
+
);
|
|
637
|
+
offset += bytesWritten;
|
|
638
|
+
}
|
|
639
|
+
written += value.byteLength;
|
|
640
|
+
}
|
|
641
|
+
await handle.close();
|
|
642
|
+
handle = void 0;
|
|
643
|
+
if (!res.headers.get("content-encoding")) {
|
|
644
|
+
const header = res.headers.get("content-length");
|
|
645
|
+
const expected = header ? Number(header) : Number.NaN;
|
|
646
|
+
if (Number.isFinite(expected) && expected > 0 && written !== expected) {
|
|
647
|
+
throw new Error(`incomplete download (${written}/${expected} bytes): ${url}`);
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
signal?.throwIfAborted();
|
|
651
|
+
import_node_fs3.default.renameSync(tmp, destPath);
|
|
652
|
+
completed = true;
|
|
653
|
+
return;
|
|
654
|
+
} catch (err) {
|
|
655
|
+
if (handle) await handle.close().catch(() => {
|
|
656
|
+
});
|
|
657
|
+
if (reader && !completed) await reader.cancel().catch(() => {
|
|
658
|
+
});
|
|
659
|
+
try {
|
|
660
|
+
import_node_fs3.default.unlinkSync(tmp);
|
|
661
|
+
} catch {
|
|
662
|
+
}
|
|
663
|
+
const nonRetryable = err instanceof DownloadHttpError && !err.retryable;
|
|
664
|
+
if (signal?.aborted || nonRetryable || attempt === 4) throw err;
|
|
665
|
+
await waitRetryDelay(250 * attempt, signal);
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
async function digestFile(filePath, algorithm, encoding, signal) {
|
|
670
|
+
const hash = import_node_crypto.default.createHash(algorithm);
|
|
671
|
+
await (0, import_promises2.pipeline)(import_node_fs3.default.createReadStream(filePath), hash, { signal });
|
|
672
|
+
return hash.digest(encoding);
|
|
673
|
+
}
|
|
674
|
+
function extractZip(zipPath, destDir, signal) {
|
|
675
|
+
return runExtractor("ditto", ["-x", "-k", zipPath, destDir], signal);
|
|
676
|
+
}
|
|
677
|
+
async function extractTarball(tarPath, zstd, destDir, stripComponents, signal) {
|
|
678
|
+
const args = [zstd ? "-xf" : "-xzf", "-"];
|
|
679
|
+
if (stripComponents > 0) args.push(`--strip-components=${stripComponents}`);
|
|
680
|
+
if (zstd) {
|
|
681
|
+
const decoder = import_node_zlib.default.createZstdDecompress({
|
|
682
|
+
params: { [import_node_zlib.default.constants.ZSTD_d_windowLogMax]: 30 }
|
|
683
|
+
});
|
|
684
|
+
await runExtractor("tar", ["--ignore-zeros", ...args], signal, {
|
|
685
|
+
cwd: destDir,
|
|
686
|
+
stdin: (stdin) => (0, import_promises2.pipeline)(import_node_fs3.default.createReadStream(tarPath), decoder, stdin, { signal })
|
|
687
|
+
});
|
|
688
|
+
return;
|
|
689
|
+
}
|
|
690
|
+
const archive = import_node_fs3.default.openSync(tarPath, "r");
|
|
691
|
+
try {
|
|
692
|
+
await runExtractor("tar", args, signal, { cwd: destDir, stdin: archive });
|
|
693
|
+
} finally {
|
|
694
|
+
import_node_fs3.default.closeSync(archive);
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
async function runExtractor(command, args, signal, input) {
|
|
698
|
+
signal?.throwIfAborted();
|
|
699
|
+
const stdin = input?.stdin;
|
|
700
|
+
const stdio = [
|
|
701
|
+
typeof stdin === "function" ? "pipe" : stdin ?? "ignore",
|
|
702
|
+
"inherit",
|
|
703
|
+
"inherit"
|
|
704
|
+
];
|
|
705
|
+
const child = (0, import_node_child_process3.spawn)(command, args, {
|
|
706
|
+
cwd: input?.cwd,
|
|
707
|
+
stdio,
|
|
708
|
+
detached: process.platform !== "win32"
|
|
709
|
+
});
|
|
710
|
+
const fed = typeof stdin === "function" && child.stdin ? stdin(child.stdin) : void 0;
|
|
711
|
+
void fed?.catch(() => {
|
|
712
|
+
});
|
|
713
|
+
let stopping;
|
|
714
|
+
const abort = () => {
|
|
715
|
+
stopping ??= terminateProcessGroup(child, "SIGKILL", 0);
|
|
716
|
+
void stopping.catch(() => {
|
|
717
|
+
});
|
|
718
|
+
};
|
|
719
|
+
try {
|
|
720
|
+
await new Promise((resolve, reject) => {
|
|
721
|
+
let failure;
|
|
722
|
+
child.on("error", (error) => {
|
|
723
|
+
failure = error;
|
|
724
|
+
});
|
|
725
|
+
child.on("close", (code) => {
|
|
726
|
+
if (signal?.aborted) {
|
|
727
|
+
const reason = signal.reason;
|
|
728
|
+
reject(
|
|
729
|
+
reason instanceof Error ? reason : new Error("Extraction canceled", { cause: reason })
|
|
730
|
+
);
|
|
731
|
+
} else if (failure) reject(failure);
|
|
732
|
+
else if (code === 0) resolve();
|
|
733
|
+
else reject(new Error(`${command} exited with code ${code}`));
|
|
734
|
+
});
|
|
735
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
736
|
+
if (signal?.aborted) abort();
|
|
737
|
+
});
|
|
738
|
+
await fed;
|
|
739
|
+
} finally {
|
|
740
|
+
signal?.removeEventListener("abort", abort);
|
|
741
|
+
await stopping;
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
var import_node_child_process3, import_node_crypto, import_node_fs3, import_node_os3, import_node_path2, import_promises2, import_node_zlib, DownloadHttpError;
|
|
745
|
+
var init_src = __esm({
|
|
746
|
+
"../contrast-runtime-delivery/src/index.ts"() {
|
|
747
|
+
"use strict";
|
|
748
|
+
import_node_child_process3 = require("node:child_process");
|
|
749
|
+
import_node_crypto = __toESM(require("node:crypto"), 1);
|
|
750
|
+
import_node_fs3 = __toESM(require("node:fs"), 1);
|
|
751
|
+
import_node_os3 = __toESM(require("node:os"), 1);
|
|
752
|
+
import_node_path2 = __toESM(require("node:path"), 1);
|
|
753
|
+
import_promises2 = require("node:stream/promises");
|
|
754
|
+
import_node_zlib = __toESM(require("node:zlib"), 1);
|
|
755
|
+
init_process_group();
|
|
756
|
+
init_product();
|
|
757
|
+
init_packs();
|
|
758
|
+
init_product();
|
|
759
|
+
DownloadHttpError = class extends Error {
|
|
760
|
+
retryable;
|
|
761
|
+
constructor(status, statusText, url) {
|
|
762
|
+
super(`download failed: ${status} ${statusText} (${url})`);
|
|
763
|
+
this.retryable = status < 400 || status >= 500 || status === 408 || status === 429;
|
|
764
|
+
}
|
|
765
|
+
};
|
|
766
|
+
}
|
|
767
|
+
});
|
|
768
|
+
|
|
45
769
|
// src/home-paths.ts
|
|
46
770
|
function ambientHomeDir() {
|
|
47
|
-
return
|
|
771
|
+
return import_node_path3.default.join((0, import_node_os4.homedir)(), ".peach");
|
|
48
772
|
}
|
|
49
773
|
function rnxHomeDir() {
|
|
50
774
|
const override = process.env[PEACH_HOME_ENV];
|
|
51
|
-
return override && override.length > 0 ?
|
|
775
|
+
return override && override.length > 0 ? import_node_path3.default.resolve(override) : ambientHomeDir();
|
|
52
776
|
}
|
|
53
|
-
var
|
|
777
|
+
var import_node_os4, import_node_path3, PEACH_HOME_ENV, DAEMON_LOCKFILE_MAX_BYTES;
|
|
54
778
|
var init_home_paths = __esm({
|
|
55
779
|
"src/home-paths.ts"() {
|
|
56
780
|
"use strict";
|
|
57
|
-
|
|
58
|
-
|
|
781
|
+
import_node_os4 = require("node:os");
|
|
782
|
+
import_node_path3 = __toESM(require("node:path"), 1);
|
|
59
783
|
PEACH_HOME_ENV = "PEACH_HOME";
|
|
60
784
|
DAEMON_LOCKFILE_MAX_BYTES = 16 * 1024;
|
|
61
785
|
}
|
|
@@ -64,10 +788,10 @@ var init_home_paths = __esm({
|
|
|
64
788
|
// src/kotlin-toolchain.ts
|
|
65
789
|
function readToolchain(moduleRoot) {
|
|
66
790
|
const parsed = JSON.parse(
|
|
67
|
-
|
|
791
|
+
import_node_fs4.default.readFileSync(import_node_path4.default.join(moduleRoot, "toolchain.json"), "utf8")
|
|
68
792
|
);
|
|
69
793
|
const download = (value) => {
|
|
70
|
-
if (!isRecord(value) || typeof value.url !== "string" || typeof value.sha256 !== "string")
|
|
794
|
+
if (!isRecord(value) || typeof value.url !== "string" || typeof value.sha256 !== "string" || !/^[a-f0-9]{64}$/.test(value.sha256))
|
|
71
795
|
throw new Error(
|
|
72
796
|
"peachsim kotlin/toolchain.json names a download without url and sha256"
|
|
73
797
|
);
|
|
@@ -75,9 +799,9 @@ function readToolchain(moduleRoot) {
|
|
|
75
799
|
};
|
|
76
800
|
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")
|
|
77
801
|
throw new Error("peachsim kotlin/toolchain.json has no compiler and libraries");
|
|
78
|
-
const version = parsed.compiler
|
|
79
|
-
if (typeof version !== "string")
|
|
80
|
-
throw new Error("peachsim kotlin/toolchain.json has no compiler
|
|
802
|
+
const { version, upstreamSha256 } = parsed.compiler;
|
|
803
|
+
if (typeof version !== "string" || typeof upstreamSha256 !== "string" || !/^[a-f0-9]{64}$/.test(upstreamSha256))
|
|
804
|
+
throw new Error("peachsim kotlin/toolchain.json has no upstream compiler pin");
|
|
81
805
|
const libraries = (values) => values.map((library) => {
|
|
82
806
|
if (!isRecord(library) || typeof library.name !== "string")
|
|
83
807
|
throw new Error("peachsim kotlin/toolchain.json names a library without a name");
|
|
@@ -87,7 +811,7 @@ function readToolchain(moduleRoot) {
|
|
|
87
811
|
compiler: {
|
|
88
812
|
...download(parsed.compiler),
|
|
89
813
|
version,
|
|
90
|
-
|
|
814
|
+
upstreamSha256
|
|
91
815
|
},
|
|
92
816
|
libraries: libraries(parsed.libraries),
|
|
93
817
|
composeLibraries: libraries(parsed.composeLibraries),
|
|
@@ -109,49 +833,50 @@ function readToolchain(moduleRoot) {
|
|
|
109
833
|
};
|
|
110
834
|
}
|
|
111
835
|
function kotlinHome() {
|
|
112
|
-
return
|
|
836
|
+
return import_node_path4.default.join(rnxHomeDir(), "kotlin");
|
|
113
837
|
}
|
|
114
838
|
async function fetchVerified(download, target) {
|
|
115
|
-
if (
|
|
116
|
-
if ((0,
|
|
839
|
+
if (import_node_fs4.default.existsSync(target)) {
|
|
840
|
+
if ((0, import_node_crypto2.createHash)("sha256").update(import_node_fs4.default.readFileSync(target)).digest("hex") !== download.sha256)
|
|
117
841
|
throw new Error(
|
|
118
|
-
`cached Kotlin download differs from its pin: ${
|
|
842
|
+
`cached Kotlin download differs from its pin: ${import_node_path4.default.basename(target)}`
|
|
119
843
|
);
|
|
120
844
|
return;
|
|
121
845
|
}
|
|
122
846
|
const response = await fetch(download.url);
|
|
123
847
|
if (!response.ok) throw new Error(`${download.url} answered ${response.status}`);
|
|
124
848
|
const bytes = Buffer.from(await response.arrayBuffer());
|
|
125
|
-
const digest = (0,
|
|
849
|
+
const digest = (0, import_node_crypto2.createHash)("sha256").update(bytes).digest("hex");
|
|
126
850
|
if (digest !== download.sha256)
|
|
127
851
|
throw new Error(`${download.url} has sha256 ${digest}, expected ${download.sha256}`);
|
|
128
|
-
|
|
852
|
+
import_node_fs4.default.mkdirSync(import_node_path4.default.dirname(target), { recursive: true });
|
|
129
853
|
const partial = `${target}.${process.pid}.partial`;
|
|
130
|
-
|
|
131
|
-
|
|
854
|
+
import_node_fs4.default.writeFileSync(partial, bytes);
|
|
855
|
+
import_node_fs4.default.renameSync(partial, target);
|
|
132
856
|
}
|
|
133
857
|
function ensureToolchain(toolchain) {
|
|
134
858
|
const key = JSON.stringify(toolchain);
|
|
135
859
|
const pending = toolchains.get(key);
|
|
136
860
|
if (pending) return pending;
|
|
137
861
|
const ready = (async () => {
|
|
138
|
-
const dir =
|
|
139
|
-
const
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
await
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
862
|
+
const dir = import_node_path4.default.join(kotlinHome(), toolchain.compiler.version);
|
|
863
|
+
const compilerDir = import_node_path4.default.join(dir, `compiler-${toolchain.compiler.sha256}`);
|
|
864
|
+
const installedMarker = "bin/kotlinc-wasm";
|
|
865
|
+
const kotlinc = import_node_path4.default.join(compilerDir, installedMarker);
|
|
866
|
+
if (!import_node_fs4.default.existsSync(kotlinc))
|
|
867
|
+
await installVerifiedTarball({
|
|
868
|
+
url: toolchain.compiler.url,
|
|
869
|
+
digest: {
|
|
870
|
+
algorithm: "sha256",
|
|
871
|
+
encoding: "hex",
|
|
872
|
+
value: toolchain.compiler.sha256
|
|
873
|
+
},
|
|
874
|
+
destDir: compilerDir,
|
|
875
|
+
installedMarker,
|
|
876
|
+
stripComponents: 1,
|
|
877
|
+
label: `Kotlin compiler ${toolchain.compiler.version}`
|
|
878
|
+
});
|
|
879
|
+
const java = process.env.JAVA_HOME ? import_node_path4.default.join(process.env.JAVA_HOME, "bin", "java") : "java";
|
|
155
880
|
const { stderr } = await run(java, ["-XshowSettings:properties", "-version"]).catch(
|
|
156
881
|
() => {
|
|
157
882
|
throw new Error(
|
|
@@ -160,11 +885,11 @@ function ensureToolchain(toolchain) {
|
|
|
160
885
|
}
|
|
161
886
|
);
|
|
162
887
|
const javaHome = /^\s*java\.home\s*=\s*(.+)$/m.exec(stderr)?.[1]?.trim();
|
|
163
|
-
if (!javaHome || !
|
|
888
|
+
if (!javaHome || !import_node_path4.default.isAbsolute(javaHome))
|
|
164
889
|
throw new Error("the configured Java runtime did not report an absolute java.home");
|
|
165
|
-
const libraries = [
|
|
890
|
+
const libraries = [import_node_path4.default.join(compilerDir, "lib", "kotlin-stdlib-wasm-js.klib")];
|
|
166
891
|
for (const library of toolchain.libraries) {
|
|
167
|
-
const target =
|
|
892
|
+
const target = import_node_path4.default.join(dir, library.name);
|
|
168
893
|
await fetchVerified(library, target);
|
|
169
894
|
libraries.push(target);
|
|
170
895
|
}
|
|
@@ -176,18 +901,19 @@ function ensureToolchain(toolchain) {
|
|
|
176
901
|
toolchains.set(key, ready);
|
|
177
902
|
return ready;
|
|
178
903
|
}
|
|
179
|
-
var
|
|
904
|
+
var import_node_child_process4, import_node_crypto2, import_node_fs4, import_node_path4, import_node_util, run, toolchains;
|
|
180
905
|
var init_kotlin_toolchain = __esm({
|
|
181
906
|
"src/kotlin-toolchain.ts"() {
|
|
182
907
|
"use strict";
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
908
|
+
import_node_child_process4 = require("node:child_process");
|
|
909
|
+
import_node_crypto2 = require("node:crypto");
|
|
910
|
+
import_node_fs4 = __toESM(require("node:fs"), 1);
|
|
911
|
+
import_node_path4 = __toESM(require("node:path"), 1);
|
|
187
912
|
import_node_util = require("node:util");
|
|
913
|
+
init_src();
|
|
188
914
|
init_home_paths();
|
|
189
915
|
init_is_record();
|
|
190
|
-
run = (0, import_node_util.promisify)(
|
|
916
|
+
run = (0, import_node_util.promisify)(import_node_child_process4.execFile);
|
|
191
917
|
toolchains = /* @__PURE__ */ new Map();
|
|
192
918
|
}
|
|
193
919
|
});
|
|
@@ -210,25 +936,25 @@ async function resolveAndroidGradleSources(request) {
|
|
|
210
936
|
let { root } = request;
|
|
211
937
|
const { projects: projectDirs, variant, includeJavaClasspath = false } = request;
|
|
212
938
|
if (projectDirs.length === 0) return [];
|
|
213
|
-
if (!
|
|
939
|
+
if (!import_node_path8.default.isAbsolute(root) || projectDirs.some((dir) => !import_node_path8.default.isAbsolute(dir)))
|
|
214
940
|
throw new Error("Android Gradle source selection requires absolute project paths");
|
|
215
941
|
if (!variant) throw new Error("Android Gradle source selection requires a variant");
|
|
216
|
-
root =
|
|
217
|
-
const projects = [...new Set(projectDirs.map((dir) =>
|
|
218
|
-
const parent =
|
|
219
|
-
|
|
220
|
-
const work =
|
|
221
|
-
const task = `peachAndroidSources${(0,
|
|
222
|
-
const script =
|
|
942
|
+
root = import_node_fs8.default.realpathSync(root);
|
|
943
|
+
const projects = [...new Set(projectDirs.map((dir) => import_node_fs8.default.realpathSync(dir)))];
|
|
944
|
+
const parent = import_node_path8.default.join(kotlinHome(), "gradle-sources");
|
|
945
|
+
import_node_fs8.default.mkdirSync(parent, { recursive: true });
|
|
946
|
+
const work = import_node_fs8.default.mkdtempSync(import_node_path8.default.join(parent, ".query-"));
|
|
947
|
+
const task = `peachAndroidSources${(0, import_node_crypto6.randomBytes)(8).toString("hex")}`;
|
|
948
|
+
const script = import_node_path8.default.join(work, "sources.gradle");
|
|
223
949
|
const encoded = Buffer.from(
|
|
224
950
|
JSON.stringify({ root, projects, variant, includeJavaClasspath, output: work, task })
|
|
225
951
|
).toString("base64");
|
|
226
|
-
|
|
952
|
+
import_node_fs8.default.writeFileSync(script, modelQuery.replace("__PEACH_REQUEST__", encoded));
|
|
227
953
|
try {
|
|
228
954
|
await run4(
|
|
229
955
|
"bash",
|
|
230
956
|
[
|
|
231
|
-
|
|
957
|
+
import_node_path8.default.join(root, "gradlew"),
|
|
232
958
|
"--init-script",
|
|
233
959
|
script,
|
|
234
960
|
`${task}All`,
|
|
@@ -247,13 +973,13 @@ async function resolveAndroidGradleSources(request) {
|
|
|
247
973
|
);
|
|
248
974
|
return projects.map((projectDir, index) => {
|
|
249
975
|
const value = JSON.parse(
|
|
250
|
-
|
|
976
|
+
import_node_fs8.default.readFileSync(import_node_path8.default.join(work, `${index}.json`), "utf8")
|
|
251
977
|
);
|
|
252
978
|
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))
|
|
253
979
|
throw new Error("Gradle printed an invalid Android project source model");
|
|
254
980
|
const paths = (field) => {
|
|
255
981
|
const list = value[field];
|
|
256
|
-
if (!Array.isArray(list) || !list.every((file) => typeof file === "string" &&
|
|
982
|
+
if (!Array.isArray(list) || !list.every((file) => typeof file === "string" && import_node_path8.default.isAbsolute(file)))
|
|
257
983
|
throw new Error(`Gradle printed invalid Android ${field} paths`);
|
|
258
984
|
return list.map(String);
|
|
259
985
|
};
|
|
@@ -289,22 +1015,22 @@ async function resolveAndroidGradleSources(request) {
|
|
|
289
1015
|
};
|
|
290
1016
|
});
|
|
291
1017
|
} finally {
|
|
292
|
-
|
|
1018
|
+
import_node_fs8.default.rmSync(work, { recursive: true, force: true });
|
|
293
1019
|
}
|
|
294
1020
|
}
|
|
295
|
-
var
|
|
1021
|
+
var import_node_child_process7, import_node_crypto6, import_node_fs8, import_node_path8, import_node_util4, run4, modelQuery;
|
|
296
1022
|
var init_android_gradle_sources = __esm({
|
|
297
1023
|
"src/android-gradle-sources.ts"() {
|
|
298
1024
|
"use strict";
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
1025
|
+
import_node_child_process7 = require("node:child_process");
|
|
1026
|
+
import_node_crypto6 = require("node:crypto");
|
|
1027
|
+
import_node_fs8 = __toESM(require("node:fs"), 1);
|
|
1028
|
+
import_node_path8 = __toESM(require("node:path"), 1);
|
|
303
1029
|
import_node_util4 = require("node:util");
|
|
304
1030
|
init_forked_script_contract();
|
|
305
1031
|
init_is_record();
|
|
306
1032
|
init_kotlin_toolchain();
|
|
307
|
-
run4 = (0, import_node_util4.promisify)(
|
|
1033
|
+
run4 = (0, import_node_util4.promisify)(import_node_child_process7.execFile);
|
|
308
1034
|
modelQuery = `
|
|
309
1035
|
import groovy.json.JsonOutput
|
|
310
1036
|
import groovy.json.JsonSlurper
|
|
@@ -414,11 +1140,11 @@ __export(kotlin_host_exports, {
|
|
|
414
1140
|
serveKotlinRequest: () => serveKotlinRequest
|
|
415
1141
|
});
|
|
416
1142
|
module.exports = __toCommonJS(kotlin_host_exports);
|
|
417
|
-
var
|
|
418
|
-
var
|
|
419
|
-
var
|
|
1143
|
+
var import_node_child_process8 = require("node:child_process");
|
|
1144
|
+
var import_node_crypto7 = require("node:crypto");
|
|
1145
|
+
var import_node_fs9 = __toESM(require("node:fs"), 1);
|
|
420
1146
|
var import_node_module = require("node:module");
|
|
421
|
-
var
|
|
1147
|
+
var import_node_path9 = __toESM(require("node:path"), 1);
|
|
422
1148
|
var import_node_util5 = require("node:util");
|
|
423
1149
|
var import_acorn2 = require("acorn");
|
|
424
1150
|
|
|
@@ -503,39 +1229,39 @@ function layoutViewClasses(roots) {
|
|
|
503
1229
|
init_is_record();
|
|
504
1230
|
|
|
505
1231
|
// src/java-module-abi.ts
|
|
506
|
-
var
|
|
507
|
-
var
|
|
508
|
-
var
|
|
509
|
-
var
|
|
1232
|
+
var import_node_child_process5 = require("node:child_process");
|
|
1233
|
+
var import_node_crypto3 = require("node:crypto");
|
|
1234
|
+
var import_node_fs5 = __toESM(require("node:fs"), 1);
|
|
1235
|
+
var import_node_path5 = __toESM(require("node:path"), 1);
|
|
510
1236
|
var import_node_util2 = require("node:util");
|
|
511
1237
|
init_is_record();
|
|
512
1238
|
init_kotlin_toolchain();
|
|
513
|
-
var run2 = (0, import_node_util2.promisify)(
|
|
1239
|
+
var run2 = (0, import_node_util2.promisify)(import_node_child_process5.execFile);
|
|
514
1240
|
var JAVA_BINDINGS_INITIALIZER = "initializeJavaBindings";
|
|
515
1241
|
async function readJavaModuleSpecs(files, sdkRoot, toolchain) {
|
|
516
|
-
const digest = (0,
|
|
517
|
-
const parent =
|
|
518
|
-
|
|
519
|
-
const work =
|
|
1242
|
+
const digest = (0, import_node_crypto3.createHash)("sha256");
|
|
1243
|
+
const parent = import_node_path5.default.join(kotlinHome(), "java-specs");
|
|
1244
|
+
import_node_fs5.default.mkdirSync(parent, { recursive: true });
|
|
1245
|
+
const work = import_node_fs5.default.mkdtempSync(import_node_path5.default.join(parent, ".read-"));
|
|
520
1246
|
try {
|
|
521
1247
|
const origins = /* @__PURE__ */ new Map();
|
|
522
1248
|
for (const [index, file] of files.entries()) {
|
|
523
|
-
const bytes =
|
|
1249
|
+
const bytes = import_node_fs5.default.readFileSync(file);
|
|
524
1250
|
digest.update(file).update("\0").update(bytes).update("\0");
|
|
525
|
-
const target =
|
|
526
|
-
|
|
527
|
-
|
|
1251
|
+
const target = import_node_path5.default.join(work, String(index), import_node_path5.default.basename(file));
|
|
1252
|
+
import_node_fs5.default.mkdirSync(import_node_path5.default.dirname(target));
|
|
1253
|
+
import_node_fs5.default.writeFileSync(target, bytes);
|
|
528
1254
|
origins.set(target, file);
|
|
529
1255
|
}
|
|
530
1256
|
const { stdout } = await run2(
|
|
531
|
-
|
|
1257
|
+
import_node_path5.default.join(toolchain.javaHome, "bin", "java"),
|
|
532
1258
|
[
|
|
533
1259
|
"-cp",
|
|
534
1260
|
[
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
].join(
|
|
1261
|
+
import_node_path5.default.join(sdkRoot, "tools.jar"),
|
|
1262
|
+
import_node_path5.default.resolve(import_node_path5.default.dirname(toolchain.kotlinc), "../lib/kotlin-compiler.jar"),
|
|
1263
|
+
import_node_path5.default.resolve(import_node_path5.default.dirname(toolchain.kotlinc), "../lib/kotlin-stdlib.jar")
|
|
1264
|
+
].join(import_node_path5.default.delimiter),
|
|
539
1265
|
"dev.peach.tools.javaabi.JavaModuleSpecsKt",
|
|
540
1266
|
...origins.keys()
|
|
541
1267
|
],
|
|
@@ -565,20 +1291,20 @@ ${diagnostic.trim()}`, { cause });
|
|
|
565
1291
|
});
|
|
566
1292
|
return { sha256: digest.digest("hex"), specs };
|
|
567
1293
|
} finally {
|
|
568
|
-
|
|
1294
|
+
import_node_fs5.default.rmSync(work, { recursive: true, force: true });
|
|
569
1295
|
}
|
|
570
1296
|
}
|
|
571
1297
|
async function compileJavaModuleAbi(input) {
|
|
572
1298
|
const { specs, work, hash, toolchain, libraries, sdkRoot, sdkLibrary, language } = input;
|
|
573
|
-
const directory =
|
|
574
|
-
|
|
1299
|
+
const directory = import_node_path5.default.join(work, "java-abi");
|
|
1300
|
+
import_node_fs5.default.mkdirSync(directory);
|
|
575
1301
|
const sources = specs.specs.map((spec, index) => {
|
|
576
|
-
const target =
|
|
577
|
-
|
|
1302
|
+
const target = import_node_path5.default.join(directory, `Spec${index}.kt`);
|
|
1303
|
+
import_node_fs5.default.writeFileSync(target, spec.source);
|
|
578
1304
|
return target;
|
|
579
1305
|
});
|
|
580
|
-
const initializer =
|
|
581
|
-
|
|
1306
|
+
const initializer = import_node_path5.default.join(directory, "Bindings.kt");
|
|
1307
|
+
import_node_fs5.default.writeFileSync(
|
|
582
1308
|
initializer,
|
|
583
1309
|
[
|
|
584
1310
|
"package dev.peach.jni",
|
|
@@ -592,8 +1318,8 @@ async function compileJavaModuleAbi(input) {
|
|
|
592
1318
|
"-J-Xmx2g",
|
|
593
1319
|
"-Xwasm-target=js",
|
|
594
1320
|
"-libraries",
|
|
595
|
-
libraries.join(
|
|
596
|
-
`-Xplugin=${
|
|
1321
|
+
libraries.join(import_node_path5.default.delimiter),
|
|
1322
|
+
`-Xplugin=${import_node_path5.default.join(sdkRoot, "plugin.jar")}`,
|
|
597
1323
|
`-Xfriend-modules=${sdkLibrary}`,
|
|
598
1324
|
"-language-version",
|
|
599
1325
|
language,
|
|
@@ -609,18 +1335,18 @@ async function compileJavaModuleAbi(input) {
|
|
|
609
1335
|
],
|
|
610
1336
|
{ maxBuffer: 16 * 1024 * 1024 }
|
|
611
1337
|
);
|
|
612
|
-
const library =
|
|
1338
|
+
const library = import_node_path5.default.join(directory, "java-abi.klib");
|
|
613
1339
|
await run2(
|
|
614
|
-
|
|
1340
|
+
import_node_path5.default.join(toolchain.javaHome, "bin", "java"),
|
|
615
1341
|
[
|
|
616
1342
|
"-cp",
|
|
617
1343
|
[
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
].join(
|
|
1344
|
+
import_node_path5.default.join(sdkRoot, "tools.jar"),
|
|
1345
|
+
import_node_path5.default.resolve(import_node_path5.default.dirname(toolchain.kotlinc), "../lib/kotlin-compiler.jar"),
|
|
1346
|
+
import_node_path5.default.resolve(import_node_path5.default.dirname(toolchain.kotlinc), "../lib/kotlin-stdlib.jar")
|
|
1347
|
+
].join(import_node_path5.default.delimiter),
|
|
622
1348
|
"dev.peach.tools.platform.JavaPlatformTypesKt",
|
|
623
|
-
|
|
1349
|
+
import_node_path5.default.join(directory, `${name}.klib`),
|
|
624
1350
|
library
|
|
625
1351
|
],
|
|
626
1352
|
{ maxBuffer: 16 * 1024 * 1024 }
|
|
@@ -735,10 +1461,10 @@ return { peachDisposeInstance, ${exports2.map((item) => `${JSON.stringify(item.e
|
|
|
735
1461
|
}
|
|
736
1462
|
|
|
737
1463
|
// src/kotlin-sdk.ts
|
|
738
|
-
var
|
|
739
|
-
var
|
|
740
|
-
var
|
|
741
|
-
var
|
|
1464
|
+
var import_node_child_process6 = require("node:child_process");
|
|
1465
|
+
var import_node_crypto4 = require("node:crypto");
|
|
1466
|
+
var import_node_fs6 = __toESM(require("node:fs"), 1);
|
|
1467
|
+
var import_node_path6 = __toESM(require("node:path"), 1);
|
|
742
1468
|
var import_node_util3 = require("node:util");
|
|
743
1469
|
init_kotlin_toolchain();
|
|
744
1470
|
|
|
@@ -814,58 +1540,58 @@ function readKotlinSdkManifest(source, compilerSha256) {
|
|
|
814
1540
|
}
|
|
815
1541
|
|
|
816
1542
|
// src/kotlin-sdk.ts
|
|
817
|
-
var run3 = (0, import_node_util3.promisify)(
|
|
818
|
-
function verifyKotlinSdkDirectory(root,
|
|
1543
|
+
var run3 = (0, import_node_util3.promisify)(import_node_child_process6.execFile);
|
|
1544
|
+
function verifyKotlinSdkDirectory(root, compiler) {
|
|
819
1545
|
const expectedNames = ["manifest.json", ...KOTLIN_SDK_FILES];
|
|
820
|
-
const names =
|
|
1546
|
+
const names = import_node_fs6.default.readdirSync(root);
|
|
821
1547
|
if (names.length !== expectedNames.length || names.some((name) => !expectedNames.includes(name)))
|
|
822
1548
|
throw new Error("Kotlin SDK directory contains unexpected inputs");
|
|
823
|
-
const manifestStat =
|
|
1549
|
+
const manifestStat = import_node_fs6.default.lstatSync(import_node_path6.default.join(root, "manifest.json"));
|
|
824
1550
|
if (!manifestStat.isFile() || manifestStat.nlink !== 1)
|
|
825
1551
|
throw new Error("Kotlin SDK manifest is not a regular file");
|
|
826
1552
|
const manifest = readKotlinSdkManifest(
|
|
827
|
-
|
|
828
|
-
|
|
1553
|
+
import_node_fs6.default.readFileSync(import_node_path6.default.join(root, "manifest.json"), "utf8"),
|
|
1554
|
+
compiler.upstreamSha256
|
|
829
1555
|
);
|
|
830
1556
|
for (const [name, expected] of Object.entries(manifest.files)) {
|
|
831
|
-
const target =
|
|
832
|
-
const stat =
|
|
1557
|
+
const target = import_node_path6.default.join(root, name);
|
|
1558
|
+
const stat = import_node_fs6.default.lstatSync(target);
|
|
833
1559
|
if (!stat.isFile() || stat.nlink !== 1)
|
|
834
1560
|
throw new Error(`Kotlin SDK binary is not a regular file: ${name}`);
|
|
835
|
-
const bytes =
|
|
836
|
-
if (bytes.length !== expected.bytes || (0,
|
|
1561
|
+
const bytes = import_node_fs6.default.readFileSync(target);
|
|
1562
|
+
if (bytes.length !== expected.bytes || (0, import_node_crypto4.createHash)("sha256").update(bytes).digest("hex") !== expected.sha256)
|
|
837
1563
|
throw new Error(`Kotlin SDK binary differs from its manifest: ${name}`);
|
|
838
1564
|
}
|
|
839
1565
|
return manifest;
|
|
840
1566
|
}
|
|
841
|
-
async function installKotlinSdkArchive(archive,
|
|
842
|
-
const sha256 = (0,
|
|
843
|
-
const parent =
|
|
844
|
-
const root =
|
|
845
|
-
if (
|
|
846
|
-
return { root, sha256, manifest: verifyKotlinSdkDirectory(root,
|
|
847
|
-
|
|
848
|
-
const work =
|
|
1567
|
+
async function installKotlinSdkArchive(archive, compiler) {
|
|
1568
|
+
const sha256 = (0, import_node_crypto4.createHash)("sha256").update(archive).digest("hex");
|
|
1569
|
+
const parent = import_node_path6.default.join(kotlinHome(), "sdk");
|
|
1570
|
+
const root = import_node_path6.default.join(parent, sha256);
|
|
1571
|
+
if (import_node_fs6.default.existsSync(root))
|
|
1572
|
+
return { root, sha256, manifest: verifyKotlinSdkDirectory(root, compiler) };
|
|
1573
|
+
import_node_fs6.default.mkdirSync(parent, { recursive: true });
|
|
1574
|
+
const work = import_node_fs6.default.mkdtempSync(import_node_path6.default.join(parent, ".install-"));
|
|
849
1575
|
try {
|
|
850
|
-
const packed =
|
|
851
|
-
|
|
1576
|
+
const packed = import_node_path6.default.join(work, "sdk.tar.gz");
|
|
1577
|
+
import_node_fs6.default.writeFileSync(packed, archive);
|
|
852
1578
|
const { stdout } = await run3("tar", ["-tzf", packed]);
|
|
853
1579
|
const names = stdout.trim().split("\n");
|
|
854
1580
|
const expected = ["manifest.json", ...KOTLIN_SDK_FILES];
|
|
855
1581
|
if (names.length !== expected.length || new Set(names).size !== names.length || names.some((name) => !expected.includes(name)))
|
|
856
1582
|
throw new Error("Kotlin SDK archive contains unexpected inputs");
|
|
857
1583
|
await run3("tar", ["-xzf", packed, "-C", work, "--", ...expected]);
|
|
858
|
-
|
|
859
|
-
const manifest = verifyKotlinSdkDirectory(work,
|
|
1584
|
+
import_node_fs6.default.rmSync(packed);
|
|
1585
|
+
const manifest = verifyKotlinSdkDirectory(work, compiler);
|
|
860
1586
|
try {
|
|
861
|
-
|
|
1587
|
+
import_node_fs6.default.renameSync(work, root);
|
|
862
1588
|
} catch (error) {
|
|
863
|
-
if (!
|
|
864
|
-
verifyKotlinSdkDirectory(root,
|
|
1589
|
+
if (!import_node_fs6.default.existsSync(root)) throw error;
|
|
1590
|
+
verifyKotlinSdkDirectory(root, compiler);
|
|
865
1591
|
}
|
|
866
1592
|
return { root, sha256, manifest };
|
|
867
1593
|
} finally {
|
|
868
|
-
|
|
1594
|
+
import_node_fs6.default.rmSync(work, { recursive: true, force: true });
|
|
869
1595
|
}
|
|
870
1596
|
}
|
|
871
1597
|
|
|
@@ -949,9 +1675,9 @@ function viewModelClasses(rows) {
|
|
|
949
1675
|
}
|
|
950
1676
|
|
|
951
1677
|
// src/kotlin-module.ts
|
|
952
|
-
var
|
|
953
|
-
var
|
|
954
|
-
var
|
|
1678
|
+
var import_node_crypto5 = require("node:crypto");
|
|
1679
|
+
var import_node_fs7 = __toESM(require("node:fs"), 1);
|
|
1680
|
+
var import_node_path7 = __toESM(require("node:path"), 1);
|
|
955
1681
|
var import_node_url = require("node:url");
|
|
956
1682
|
|
|
957
1683
|
// cli/standalone.ts
|
|
@@ -963,33 +1689,33 @@ init_is_record();
|
|
|
963
1689
|
var installedRoot;
|
|
964
1690
|
function peachKotlinModuleRoot() {
|
|
965
1691
|
if (!IS_STANDALONE)
|
|
966
|
-
return
|
|
1692
|
+
return import_node_path7.default.resolve(import_node_path7.default.dirname((0, import_node_url.fileURLToPath)(__sootsim_import_meta_url)), "..", "kotlin");
|
|
967
1693
|
if (installedRoot) return installedRoot;
|
|
968
1694
|
const files = JSON.parse(__PEACH_BUNDLED_KOTLIN__);
|
|
969
|
-
const digest = (0,
|
|
970
|
-
const parent =
|
|
971
|
-
const root =
|
|
972
|
-
|
|
973
|
-
if (!
|
|
974
|
-
const pending =
|
|
1695
|
+
const digest = (0, import_node_crypto5.createHash)("sha256").update(__PEACH_BUNDLED_KOTLIN__).digest("hex");
|
|
1696
|
+
const parent = import_node_path7.default.join(rnxHomeDir(), "kotlin", "modules");
|
|
1697
|
+
const root = import_node_path7.default.join(parent, digest);
|
|
1698
|
+
import_node_fs7.default.mkdirSync(parent, { recursive: true });
|
|
1699
|
+
if (!import_node_fs7.default.existsSync(root)) {
|
|
1700
|
+
const pending = import_node_fs7.default.mkdtempSync(import_node_path7.default.join(parent, ".install-"));
|
|
975
1701
|
try {
|
|
976
1702
|
for (const [name, contents] of Object.entries(files)) {
|
|
977
|
-
const file =
|
|
978
|
-
|
|
979
|
-
|
|
1703
|
+
const file = import_node_path7.default.join(pending, name);
|
|
1704
|
+
import_node_fs7.default.mkdirSync(import_node_path7.default.dirname(file), { recursive: true });
|
|
1705
|
+
import_node_fs7.default.writeFileSync(file, Buffer.from(contents, "base64"));
|
|
980
1706
|
}
|
|
981
1707
|
try {
|
|
982
|
-
|
|
1708
|
+
import_node_fs7.default.renameSync(pending, root);
|
|
983
1709
|
} catch (error) {
|
|
984
1710
|
if (!isRecord(error) || error.code !== "EEXIST" && error.code !== "ENOTEMPTY")
|
|
985
1711
|
throw error;
|
|
986
1712
|
}
|
|
987
1713
|
} finally {
|
|
988
|
-
|
|
1714
|
+
import_node_fs7.default.rmSync(pending, { recursive: true, force: true });
|
|
989
1715
|
}
|
|
990
1716
|
}
|
|
991
1717
|
for (const [name, contents] of Object.entries(files)) {
|
|
992
|
-
if (!
|
|
1718
|
+
if (!import_node_fs7.default.readFileSync(import_node_path7.default.join(root, name)).equals(Buffer.from(contents, "base64")))
|
|
993
1719
|
throw new Error(`packaged Kotlin module differs from this CLI: ${name}`);
|
|
994
1720
|
}
|
|
995
1721
|
installedRoot = root;
|
|
@@ -997,20 +1723,20 @@ function peachKotlinModuleRoot() {
|
|
|
997
1723
|
}
|
|
998
1724
|
|
|
999
1725
|
// src/kotlin-host.ts
|
|
1000
|
-
var run5 = (0, import_node_util5.promisify)(
|
|
1726
|
+
var run5 = (0, import_node_util5.promisify)(import_node_child_process8.execFile);
|
|
1001
1727
|
function loadKotlinSdk(moduleRoot, toolchain) {
|
|
1002
1728
|
return installKotlinSdkArchive(
|
|
1003
|
-
|
|
1004
|
-
toolchain.compiler
|
|
1729
|
+
import_node_fs9.default.readFileSync(import_node_path9.default.join(moduleRoot, "sdk.tar.gz")),
|
|
1730
|
+
toolchain.compiler
|
|
1005
1731
|
);
|
|
1006
1732
|
}
|
|
1007
1733
|
var KOTLIN_ARTIFACT_PREFIX = "/__peach/kotlin-artifact/";
|
|
1008
1734
|
function appKotlinLanguage(root) {
|
|
1009
|
-
const reactNative =
|
|
1010
|
-
(0, import_node_module.createRequire)(
|
|
1735
|
+
const reactNative = import_node_path9.default.dirname(
|
|
1736
|
+
(0, import_node_module.createRequire)(import_node_path9.default.join(root, "package.json")).resolve("react-native/package.json")
|
|
1011
1737
|
);
|
|
1012
|
-
const versions =
|
|
1013
|
-
|
|
1738
|
+
const versions = import_node_fs9.default.readFileSync(
|
|
1739
|
+
import_node_path9.default.join(reactNative, "gradle", "libs.versions.toml"),
|
|
1014
1740
|
"utf8"
|
|
1015
1741
|
);
|
|
1016
1742
|
const match = /^kotlin\s*=\s*"(\d+)\.(\d+)/m.exec(versions);
|
|
@@ -1032,9 +1758,9 @@ var SKIP_DIRS = /* @__PURE__ */ new Set([
|
|
|
1032
1758
|
function kotlinSources(root, skip = SKIP_DIRS) {
|
|
1033
1759
|
const sources = [];
|
|
1034
1760
|
const walk = (dir) => {
|
|
1035
|
-
for (const entry of
|
|
1761
|
+
for (const entry of import_node_fs9.default.readdirSync(dir, { withFileTypes: true })) {
|
|
1036
1762
|
if (entry.name.startsWith(".") || skip.has(entry.name)) continue;
|
|
1037
|
-
const full =
|
|
1763
|
+
const full = import_node_path9.default.join(dir, entry.name);
|
|
1038
1764
|
if (entry.isDirectory()) walk(full);
|
|
1039
1765
|
else if (entry.isFile() && entry.name.endsWith(".kt")) sources.push(full);
|
|
1040
1766
|
}
|
|
@@ -1104,7 +1830,7 @@ function entrySource(ids) {
|
|
|
1104
1830
|
var BUILD_FORMAT = 22;
|
|
1105
1831
|
var builds = /* @__PURE__ */ new Map();
|
|
1106
1832
|
function buildsDir() {
|
|
1107
|
-
return
|
|
1833
|
+
return import_node_path9.default.join(kotlinHome(), "builds");
|
|
1108
1834
|
}
|
|
1109
1835
|
async function kotlinArtifact(root, moduleRoot, origin, target = "app") {
|
|
1110
1836
|
const { kotlinSourceId, nativeSourceContract, renderKotlinSourceGlue } = await import("vxrn/native-source-contract");
|
|
@@ -1117,7 +1843,7 @@ async function kotlinArtifact(root, moduleRoot, origin, target = "app") {
|
|
|
1117
1843
|
const viewIds = [];
|
|
1118
1844
|
let usesCompose = false;
|
|
1119
1845
|
for (const file of sources) {
|
|
1120
|
-
const source =
|
|
1846
|
+
const source = import_node_fs9.default.readFileSync(file, "utf8");
|
|
1121
1847
|
if (/\bandroidx\.compose\./.test(source)) usesCompose = true;
|
|
1122
1848
|
const contract = nativeSourceContract(file, source);
|
|
1123
1849
|
if (contract.modules.length === 0 && contract.views.length === 0) continue;
|
|
@@ -1207,24 +1933,24 @@ function readExpoTypes(output) {
|
|
|
1207
1933
|
}
|
|
1208
1934
|
var toolScans = /* @__PURE__ */ new Map();
|
|
1209
1935
|
async function scanSources(tool, parse3, toolchain, moduleRoot, files) {
|
|
1210
|
-
const digest = (0,
|
|
1936
|
+
const digest = (0, import_node_crypto7.createHash)("sha256").update(JSON.stringify(toolchain.compiler));
|
|
1211
1937
|
const sdk = await loadKotlinSdk(moduleRoot, toolchain);
|
|
1212
|
-
digest.update(
|
|
1938
|
+
digest.update(import_node_fs9.default.readFileSync(import_node_path9.default.join(moduleRoot, "sdk.tar.gz")));
|
|
1213
1939
|
digest.update(tool);
|
|
1214
|
-
for (const file of files) digest.update(`${file}\0${
|
|
1940
|
+
for (const file of files) digest.update(`${file}\0${import_node_fs9.default.readFileSync(file, "utf8")}\0`);
|
|
1215
1941
|
const key = digest.digest("hex");
|
|
1216
1942
|
let scan = toolScans.get(key);
|
|
1217
1943
|
if (!scan) {
|
|
1218
1944
|
scan = (async () => {
|
|
1219
1945
|
const { kotlinc } = await ensureToolchain(toolchain);
|
|
1220
1946
|
const { stdout } = await run5(
|
|
1221
|
-
|
|
1947
|
+
import_node_path9.default.join(import_node_path9.default.dirname(kotlinc), "kotlin"),
|
|
1222
1948
|
[
|
|
1223
1949
|
"-cp",
|
|
1224
1950
|
[
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
].join(
|
|
1951
|
+
import_node_path9.default.resolve(import_node_path9.default.dirname(kotlinc), "../lib/kotlin-compiler.jar"),
|
|
1952
|
+
import_node_path9.default.join(sdk.root, "tools.jar")
|
|
1953
|
+
].join(import_node_path9.default.delimiter),
|
|
1228
1954
|
tool,
|
|
1229
1955
|
...files
|
|
1230
1956
|
],
|
|
@@ -1242,7 +1968,7 @@ async function scanSources(tool, parse3, toolchain, moduleRoot, files) {
|
|
|
1242
1968
|
async function scanExpoTypes(toolchain, moduleRoot, sources) {
|
|
1243
1969
|
const candidates = sources.filter(
|
|
1244
1970
|
(file) => /\bRecord\b|\benum\s+class\b|\bExpoComposeView\b|\bExpoView\b|\bComposeProps\b|:\s*(?:[A-Za-z0-9_.]+\.)?(?:View|FrameLayout|LinearLayout|ViewGroup)\b/.test(
|
|
1245
|
-
|
|
1971
|
+
import_node_fs9.default.readFileSync(file, "utf8")
|
|
1246
1972
|
)
|
|
1247
1973
|
);
|
|
1248
1974
|
if (candidates.length === 0) return [];
|
|
@@ -1431,7 +2157,7 @@ function expoTypeSources(files) {
|
|
|
1431
2157
|
)
|
|
1432
2158
|
];
|
|
1433
2159
|
if (edits.length > 0 || views.length > 0) {
|
|
1434
|
-
let text =
|
|
2160
|
+
let text = import_node_fs9.default.readFileSync(file.file, "utf8").replaceAll("\r\n", "\n");
|
|
1435
2161
|
for (const { range, owner, field } of edits.sort((a, b) => b.range[0] - a.range[0]))
|
|
1436
2162
|
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])}`;
|
|
1437
2163
|
if (views.length > 0) {
|
|
@@ -1447,7 +2173,7 @@ function expoTypeSources(files) {
|
|
|
1447
2173
|
`${file.package ? `${file.package}.` : ""}peachExpoViews${index}()`
|
|
1448
2174
|
);
|
|
1449
2175
|
}
|
|
1450
|
-
const name = `PeachExpoSource_${index}_${
|
|
2176
|
+
const name = `PeachExpoSource_${index}_${import_node_path9.default.basename(file.file)}`;
|
|
1451
2177
|
generated[name] = text;
|
|
1452
2178
|
origins[name] = file.file;
|
|
1453
2179
|
}
|
|
@@ -1489,7 +2215,7 @@ async function expoKotlinArtifact(root, moduleRoot, origin, modules) {
|
|
|
1489
2215
|
const language = appKotlinLanguage(root);
|
|
1490
2216
|
const scanned = await scanExpoTypes(toolchain, moduleRoot, modules.sources);
|
|
1491
2217
|
const usesCompose = scanned.some((file) => file.views.length > 0) || modules.sources.some(
|
|
1492
|
-
(file) => /\bandroidx\.compose\./.test(
|
|
2218
|
+
(file) => /\bandroidx\.compose\./.test(import_node_fs9.default.readFileSync(file, "utf8"))
|
|
1493
2219
|
);
|
|
1494
2220
|
const types = expoTypeSources(scanned);
|
|
1495
2221
|
const rewritten = new Set(Object.values(types.origins));
|
|
@@ -1719,7 +2445,7 @@ function appResourceSources(app) {
|
|
|
1719
2445
|
entries: app.drawables.map((drawable) => ({
|
|
1720
2446
|
name: drawable.name,
|
|
1721
2447
|
init: `listOf(
|
|
1722
|
-
${drawable.files.map((file) => drawableInit(file,
|
|
2448
|
+
${drawable.files.map((file) => drawableInit(file, import_node_path9.default.relative(app.moduleDir, file.file))).join(",\n")}
|
|
1723
2449
|
)`
|
|
1724
2450
|
}))
|
|
1725
2451
|
},
|
|
@@ -1843,7 +2569,7 @@ function drawableInit(drawable, file) {
|
|
|
1843
2569
|
if (drawable.kind === "xml") return `PeachDrawable.Xml(${where})`;
|
|
1844
2570
|
if (drawable.kind === "bitmap")
|
|
1845
2571
|
return `PeachDrawable.Bitmap(${where}, ${drawable.ninePatch}, ${literal(
|
|
1846
|
-
|
|
2572
|
+
import_node_fs9.default.readFileSync(drawable.file).toString("base64")
|
|
1847
2573
|
)})`;
|
|
1848
2574
|
const vector = drawable.vector;
|
|
1849
2575
|
const float = (value) => `${value}f`;
|
|
@@ -1907,8 +2633,8 @@ async function compileKotlin(input, origin) {
|
|
|
1907
2633
|
javaSpecs = []
|
|
1908
2634
|
} = input;
|
|
1909
2635
|
const sdk = await loadKotlinSdk(moduleRoot, toolchain);
|
|
1910
|
-
const plugin =
|
|
1911
|
-
const sdkLibrary =
|
|
2636
|
+
const plugin = import_node_path9.default.join(sdk.root, "plugin.jar");
|
|
2637
|
+
const sdkLibrary = import_node_path9.default.join(sdk.root, `${sdkProfile}.klib`);
|
|
1912
2638
|
const javaRead = javaSpecs.length ? await readJavaModuleSpecs(javaSpecs, sdk.root, await ensureToolchain(toolchain)) : null;
|
|
1913
2639
|
const java = javaRead && javaRead.specs.some((spec) => !spec.application) ? { ...javaRead, specs: javaRead.specs.filter((spec) => !spec.application) } : null;
|
|
1914
2640
|
const applicationJava = javaRead?.specs.filter((spec) => spec.application) ?? [];
|
|
@@ -1936,9 +2662,9 @@ async function compileKotlin(input, origin) {
|
|
|
1936
2662
|
};
|
|
1937
2663
|
const inputs = sources.map((file) => ({
|
|
1938
2664
|
file,
|
|
1939
|
-
bytes:
|
|
2665
|
+
bytes: import_node_fs9.default.readFileSync(file)
|
|
1940
2666
|
}));
|
|
1941
|
-
const digest = (0,
|
|
2667
|
+
const digest = (0, import_node_crypto7.createHash)("sha256");
|
|
1942
2668
|
digest.update(
|
|
1943
2669
|
JSON.stringify({
|
|
1944
2670
|
format: BUILD_FORMAT,
|
|
@@ -1951,7 +2677,7 @@ async function compileKotlin(input, origin) {
|
|
|
1951
2677
|
})
|
|
1952
2678
|
);
|
|
1953
2679
|
for (const { file, bytes } of inputs)
|
|
1954
|
-
digest.update(
|
|
2680
|
+
digest.update(import_node_path9.default.relative(root, file)).update("\0").update(bytes).update("\0");
|
|
1955
2681
|
if (viewModels) digest.update(viewModels.toolClass);
|
|
1956
2682
|
for (const [name, text] of Object.entries(generated))
|
|
1957
2683
|
digest.update(`${name}\0${text}\0`);
|
|
@@ -1960,39 +2686,39 @@ async function compileKotlin(input, origin) {
|
|
|
1960
2686
|
url: `${origin}${KOTLIN_ARTIFACT_PREFIX}${hash}/app.mjs`,
|
|
1961
2687
|
hash
|
|
1962
2688
|
};
|
|
1963
|
-
const out =
|
|
1964
|
-
if (
|
|
2689
|
+
const out = import_node_path9.default.join(buildsDir(), hash);
|
|
2690
|
+
if (import_node_fs9.default.existsSync(import_node_path9.default.join(out, "js", "app.wasm"))) return artifact;
|
|
1965
2691
|
const pending = builds.get(hash);
|
|
1966
2692
|
if (pending) return pending;
|
|
1967
2693
|
const build = (async () => {
|
|
1968
2694
|
const ready = await ensureToolchain(toolchain);
|
|
1969
2695
|
const { kotlinc } = ready;
|
|
1970
|
-
const libraries = [...ready.libraries, sdkLibrary,
|
|
1971
|
-
const composeRuntime =
|
|
2696
|
+
const libraries = [...ready.libraries, sdkLibrary, import_node_path9.default.join(sdk.root, "java.klib")];
|
|
2697
|
+
const composeRuntime = import_node_path9.default.join(
|
|
1972
2698
|
kotlinHome(),
|
|
1973
2699
|
toolchain.compiler.version,
|
|
1974
2700
|
toolchain.composeRuntime.name
|
|
1975
2701
|
);
|
|
1976
2702
|
if (usesCompose) {
|
|
1977
2703
|
for (const library of toolchain.composeLibraries) {
|
|
1978
|
-
const target =
|
|
2704
|
+
const target = import_node_path9.default.join(kotlinHome(), toolchain.compiler.version, library.name);
|
|
1979
2705
|
await fetchVerified(library, target);
|
|
1980
2706
|
libraries.push(target);
|
|
1981
2707
|
}
|
|
1982
2708
|
await fetchVerified(toolchain.composeRuntime, composeRuntime);
|
|
1983
2709
|
}
|
|
1984
|
-
|
|
1985
|
-
const work =
|
|
1986
|
-
const javaLibrary = java ?
|
|
2710
|
+
import_node_fs9.default.mkdirSync(buildsDir(), { recursive: true });
|
|
2711
|
+
const work = import_node_fs9.default.mkdtempSync(import_node_path9.default.join(buildsDir(), `${hash}-`));
|
|
2712
|
+
const javaLibrary = java ? import_node_path9.default.join(work, "java-abi", "java-abi.klib") : null;
|
|
1987
2713
|
if (javaLibrary) libraries.push(javaLibrary);
|
|
1988
|
-
const generatedDir =
|
|
1989
|
-
|
|
2714
|
+
const generatedDir = import_node_path9.default.join(work, "generated");
|
|
2715
|
+
import_node_fs9.default.mkdirSync(generatedDir);
|
|
1990
2716
|
for (const [name, text] of Object.entries(generated))
|
|
1991
|
-
|
|
2717
|
+
import_node_fs9.default.writeFileSync(import_node_path9.default.join(generatedDir, name), text);
|
|
1992
2718
|
const compiledSources = inputs.map(({ file, bytes }, index) => {
|
|
1993
|
-
const target =
|
|
1994
|
-
|
|
1995
|
-
|
|
2719
|
+
const target = import_node_path9.default.join(work, "sources", String(index), import_node_path9.default.basename(file));
|
|
2720
|
+
import_node_fs9.default.mkdirSync(import_node_path9.default.dirname(target), { recursive: true });
|
|
2721
|
+
import_node_fs9.default.writeFileSync(target, bytes);
|
|
1996
2722
|
return { file, target };
|
|
1997
2723
|
});
|
|
1998
2724
|
const common = [
|
|
@@ -2001,19 +2727,19 @@ async function compileKotlin(input, origin) {
|
|
|
2001
2727
|
"-Xallow-kotlin-package",
|
|
2002
2728
|
"-Xwasm-target=js",
|
|
2003
2729
|
"-libraries",
|
|
2004
|
-
libraries.join(
|
|
2730
|
+
libraries.join(import_node_path9.default.delimiter)
|
|
2005
2731
|
];
|
|
2006
2732
|
const compileKlib = (outputDir) => run5(
|
|
2007
2733
|
kotlinc,
|
|
2008
2734
|
[
|
|
2009
2735
|
...common,
|
|
2010
2736
|
`-Xplugin=${plugin}`,
|
|
2011
|
-
`-Xfriend-modules=${[sdkLibrary, ...javaLibrary ? [javaLibrary] : []].join(
|
|
2737
|
+
`-Xfriend-modules=${[sdkLibrary, ...javaLibrary ? [javaLibrary] : []].join(import_node_path9.default.delimiter)}`,
|
|
2012
2738
|
...usesCompose ? [
|
|
2013
|
-
`-Xplugin=${
|
|
2739
|
+
`-Xplugin=${import_node_path9.default.resolve(import_node_path9.default.dirname(kotlinc), "../lib/compose-compiler-plugin.jar")}`
|
|
2014
2740
|
] : [],
|
|
2015
2741
|
...usesSerialization ? [
|
|
2016
|
-
`-Xplugin=${
|
|
2742
|
+
`-Xplugin=${import_node_path9.default.resolve(import_node_path9.default.dirname(kotlinc), "../lib/kotlinx-serialization-compiler-plugin.jar")}`
|
|
2017
2743
|
] : [],
|
|
2018
2744
|
"-language-version",
|
|
2019
2745
|
language,
|
|
@@ -2026,7 +2752,7 @@ async function compileKotlin(input, origin) {
|
|
|
2026
2752
|
"-ir-output-name",
|
|
2027
2753
|
"app",
|
|
2028
2754
|
...compiledSources.map(({ target }) => target),
|
|
2029
|
-
...Object.keys(generated).map((name) =>
|
|
2755
|
+
...Object.keys(generated).map((name) => import_node_path9.default.join(generatedDir, name))
|
|
2030
2756
|
],
|
|
2031
2757
|
{ maxBuffer: 16 * 1024 * 1024 }
|
|
2032
2758
|
);
|
|
@@ -2045,37 +2771,37 @@ async function compileKotlin(input, origin) {
|
|
|
2045
2771
|
if (viewModels && inputs.some(
|
|
2046
2772
|
({ file, bytes }) => sources.includes(file) && bytes.includes("ViewModel")
|
|
2047
2773
|
)) {
|
|
2048
|
-
await compileKlib(
|
|
2774
|
+
await compileKlib(import_node_path9.default.join(work, "abi"));
|
|
2049
2775
|
const { stdout } = await run5(
|
|
2050
|
-
|
|
2776
|
+
import_node_path9.default.join(import_node_path9.default.dirname(kotlinc), "kotlin"),
|
|
2051
2777
|
[
|
|
2052
2778
|
"-cp",
|
|
2053
2779
|
[
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
].join(
|
|
2780
|
+
import_node_path9.default.resolve(import_node_path9.default.dirname(kotlinc), "../lib/kotlin-compiler.jar"),
|
|
2781
|
+
import_node_path9.default.join(sdk.root, "tools.jar")
|
|
2782
|
+
].join(import_node_path9.default.delimiter),
|
|
2057
2783
|
viewModels.toolClass,
|
|
2058
|
-
|
|
2784
|
+
import_node_path9.default.join(work, "abi")
|
|
2059
2785
|
],
|
|
2060
2786
|
{ maxBuffer: 64 * 1024 * 1024 }
|
|
2061
2787
|
);
|
|
2062
|
-
|
|
2063
|
-
|
|
2788
|
+
import_node_fs9.default.writeFileSync(
|
|
2789
|
+
import_node_path9.default.join(generatedDir, viewModels.file),
|
|
2064
2790
|
viewModels.render(viewModelClasses(readAbiClasses(stdout)))
|
|
2065
2791
|
);
|
|
2066
2792
|
}
|
|
2067
|
-
await compileKlib(
|
|
2793
|
+
await compileKlib(import_node_path9.default.join(work, "klib"));
|
|
2068
2794
|
await run5(
|
|
2069
2795
|
kotlinc,
|
|
2070
2796
|
[
|
|
2071
2797
|
...common,
|
|
2072
2798
|
"-nowarn",
|
|
2073
2799
|
"-Xpartial-linkage-loglevel=error",
|
|
2074
|
-
`-Xinclude=${
|
|
2800
|
+
`-Xinclude=${import_node_path9.default.join(work, "klib")}`,
|
|
2075
2801
|
"-Xir-produce-js",
|
|
2076
2802
|
"-Xir-dce",
|
|
2077
2803
|
"-ir-output-dir",
|
|
2078
|
-
|
|
2804
|
+
import_node_path9.default.join(work, "js"),
|
|
2079
2805
|
"-ir-output-name",
|
|
2080
2806
|
"app"
|
|
2081
2807
|
],
|
|
@@ -2088,10 +2814,10 @@ async function compileKotlin(input, origin) {
|
|
|
2088
2814
|
composeRuntime,
|
|
2089
2815
|
"skiko.mjs",
|
|
2090
2816
|
"-d",
|
|
2091
|
-
|
|
2817
|
+
import_node_path9.default.join(work, "js")
|
|
2092
2818
|
]);
|
|
2093
|
-
const skikoPath =
|
|
2094
|
-
const upstream = (0, import_acorn2.parse)(
|
|
2819
|
+
const skikoPath = import_node_path9.default.join(work, "js", "skiko.mjs");
|
|
2820
|
+
const upstream = (0, import_acorn2.parse)(import_node_fs9.default.readFileSync(skikoPath, "utf8"), {
|
|
2095
2821
|
ecmaVersion: "latest",
|
|
2096
2822
|
sourceType: "module"
|
|
2097
2823
|
});
|
|
@@ -2113,7 +2839,7 @@ async function compileKotlin(input, origin) {
|
|
|
2113
2839
|
"GL",
|
|
2114
2840
|
...bindings
|
|
2115
2841
|
];
|
|
2116
|
-
|
|
2842
|
+
import_node_fs9.default.writeFileSync(
|
|
2117
2843
|
skikoPath,
|
|
2118
2844
|
[
|
|
2119
2845
|
"const runtime = globalThis.__peachKotlinSkiko;",
|
|
@@ -2127,10 +2853,10 @@ async function compileKotlin(input, origin) {
|
|
|
2127
2853
|
if (usesCompose) {
|
|
2128
2854
|
for (const library of toolchain.composeJsLibraries) {
|
|
2129
2855
|
let imported = false;
|
|
2130
|
-
for (const file of
|
|
2856
|
+
for (const file of import_node_fs9.default.readdirSync(import_node_path9.default.join(work, "js"))) {
|
|
2131
2857
|
if (!file.endsWith(".mjs")) continue;
|
|
2132
|
-
const target =
|
|
2133
|
-
const source =
|
|
2858
|
+
const target = import_node_path9.default.join(work, "js", file);
|
|
2859
|
+
const source = import_node_fs9.default.readFileSync(target, "utf8");
|
|
2134
2860
|
let next = source;
|
|
2135
2861
|
for (const quote of ["'", '"'])
|
|
2136
2862
|
next = next.replaceAll(
|
|
@@ -2138,11 +2864,11 @@ async function compileKotlin(input, origin) {
|
|
|
2138
2864
|
`from ${quote}./${library.file}${quote}`
|
|
2139
2865
|
);
|
|
2140
2866
|
if (next === source) continue;
|
|
2141
|
-
|
|
2867
|
+
import_node_fs9.default.writeFileSync(target, next);
|
|
2142
2868
|
imported = true;
|
|
2143
2869
|
}
|
|
2144
2870
|
if (!imported) continue;
|
|
2145
|
-
const archive =
|
|
2871
|
+
const archive = import_node_path9.default.join(
|
|
2146
2872
|
kotlinHome(),
|
|
2147
2873
|
toolchain.compiler.version,
|
|
2148
2874
|
library.name
|
|
@@ -2151,24 +2877,24 @@ async function compileKotlin(input, origin) {
|
|
|
2151
2877
|
const { stdout } = await run5("tar", ["-xOf", archive, library.archiveEntry], {
|
|
2152
2878
|
maxBuffer: 16 * 1024 * 1024
|
|
2153
2879
|
});
|
|
2154
|
-
|
|
2880
|
+
import_node_fs9.default.writeFileSync(import_node_path9.default.join(work, "js", library.file), stdout);
|
|
2155
2881
|
}
|
|
2156
2882
|
}
|
|
2157
2883
|
} catch (error) {
|
|
2158
|
-
|
|
2884
|
+
import_node_fs9.default.rmSync(work, { recursive: true, force: true });
|
|
2159
2885
|
let output = isRecord(error) ? `${String(error.stderr ?? "")}${String(error.stdout ?? "")}` : "";
|
|
2160
2886
|
for (const [name, source] of Object.entries(origins))
|
|
2161
|
-
output = output.replaceAll(
|
|
2887
|
+
output = output.replaceAll(import_node_path9.default.join(generatedDir, name), source);
|
|
2162
2888
|
for (const [index, spec] of applicationJava.entries())
|
|
2163
2889
|
output = output.replaceAll(
|
|
2164
|
-
|
|
2890
|
+
import_node_path9.default.join(generatedDir, `JavaApplication${index}.kt`),
|
|
2165
2891
|
spec.file
|
|
2166
2892
|
);
|
|
2167
2893
|
for (const { file, target } of compiledSources)
|
|
2168
|
-
output = output.replaceAll(target, file).replaceAll(
|
|
2894
|
+
output = output.replaceAll(target, file).replaceAll(import_node_path9.default.relative(process.cwd(), target), file);
|
|
2169
2895
|
for (const [index, spec] of (java?.specs ?? []).entries())
|
|
2170
2896
|
output = output.replaceAll(
|
|
2171
|
-
|
|
2897
|
+
import_node_path9.default.join(work, "java-abi", `Spec${index}.kt`),
|
|
2172
2898
|
spec.file
|
|
2173
2899
|
);
|
|
2174
2900
|
output = output.replace(
|
|
@@ -2183,9 +2909,9 @@ ${output.trim() || (error instanceof Error ? error.message : String(error))}`
|
|
|
2183
2909
|
const seams = [
|
|
2184
2910
|
["process.release.name", "process.release?.name"]
|
|
2185
2911
|
];
|
|
2186
|
-
const js =
|
|
2912
|
+
const js = import_node_fs9.default.readdirSync(import_node_path9.default.join(work, "js")).filter((file) => file.endsWith(".mjs"));
|
|
2187
2913
|
if (js.some(
|
|
2188
|
-
(file) =>
|
|
2914
|
+
(file) => import_node_fs9.default.readFileSync(import_node_path9.default.join(work, "js", file), "utf8").includes("'kotlinx.coroutines.")
|
|
2189
2915
|
))
|
|
2190
2916
|
seams.push([
|
|
2191
2917
|
"(typeof(window) !== 'undefined' && window != null && typeof(window.addEventListener) === 'function') ? window : null",
|
|
@@ -2194,12 +2920,12 @@ ${output.trim() || (error instanceof Error ? error.message : String(error))}`
|
|
|
2194
2920
|
for (const [from, to] of seams) {
|
|
2195
2921
|
let patched = 0;
|
|
2196
2922
|
for (const file of js) {
|
|
2197
|
-
const target =
|
|
2198
|
-
const text =
|
|
2923
|
+
const target = import_node_path9.default.join(work, "js", file);
|
|
2924
|
+
const text = import_node_fs9.default.readFileSync(target, "utf8");
|
|
2199
2925
|
const next = text.replaceAll(from, to);
|
|
2200
2926
|
if (next !== text) {
|
|
2201
2927
|
patched++;
|
|
2202
|
-
|
|
2928
|
+
import_node_fs9.default.writeFileSync(target, next);
|
|
2203
2929
|
}
|
|
2204
2930
|
}
|
|
2205
2931
|
if (patched === 0)
|
|
@@ -2207,11 +2933,11 @@ ${output.trim() || (error instanceof Error ? error.message : String(error))}`
|
|
|
2207
2933
|
`kotlin output no longer contains ${from}; recheck how it detects its host in Peach`
|
|
2208
2934
|
);
|
|
2209
2935
|
}
|
|
2210
|
-
const entry =
|
|
2211
|
-
const entrySource2 =
|
|
2212
|
-
const importsPath =
|
|
2936
|
+
const entry = import_node_path9.default.join(work, "js/app.mjs");
|
|
2937
|
+
const entrySource2 = import_node_fs9.default.readFileSync(entry, "utf8");
|
|
2938
|
+
const importsPath = import_node_path9.default.join(work, "js/app.import-object.mjs");
|
|
2213
2939
|
const importsFactory = kotlinInstanceSource(
|
|
2214
|
-
|
|
2940
|
+
import_node_fs9.default.readFileSync(importsPath, "utf8"),
|
|
2215
2941
|
"createKotlinImportObject"
|
|
2216
2942
|
);
|
|
2217
2943
|
const runtimeFactory = kotlinInstanceSource(
|
|
@@ -2219,9 +2945,9 @@ ${output.trim() || (error instanceof Error ? error.message : String(error))}`
|
|
|
2219
2945
|
"createKotlinInstance",
|
|
2220
2946
|
/* @__PURE__ */ new Map([["./app.import-object.mjs", "createKotlinImportObject"]])
|
|
2221
2947
|
);
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2948
|
+
import_node_fs9.default.writeFileSync(importsPath, importsFactory.source);
|
|
2949
|
+
import_node_fs9.default.writeFileSync(import_node_path9.default.join(work, "js/app-runtime.mjs"), runtimeFactory.source);
|
|
2950
|
+
import_node_fs9.default.writeFileSync(
|
|
2225
2951
|
entry,
|
|
2226
2952
|
[
|
|
2227
2953
|
"import { createKotlinInstance } from './app-runtime.mjs';",
|
|
@@ -2234,10 +2960,10 @@ ${output.trim() || (error instanceof Error ? error.message : String(error))}`
|
|
|
2234
2960
|
].join("\n")
|
|
2235
2961
|
);
|
|
2236
2962
|
try {
|
|
2237
|
-
|
|
2963
|
+
import_node_fs9.default.renameSync(work, out);
|
|
2238
2964
|
} catch (error) {
|
|
2239
|
-
if (!
|
|
2240
|
-
|
|
2965
|
+
if (!import_node_fs9.default.existsSync(import_node_path9.default.join(out, "js", "app.wasm"))) throw error;
|
|
2966
|
+
import_node_fs9.default.rmSync(work, { recursive: true, force: true });
|
|
2241
2967
|
}
|
|
2242
2968
|
return artifact;
|
|
2243
2969
|
})().finally(() => builds.delete(hash));
|
|
@@ -2249,24 +2975,24 @@ var CONTENT_TYPES = {
|
|
|
2249
2975
|
".wasm": "application/wasm"
|
|
2250
2976
|
};
|
|
2251
2977
|
function kotlinArtifactFiles(hash) {
|
|
2252
|
-
const dir =
|
|
2253
|
-
return
|
|
2254
|
-
const contentType = CONTENT_TYPES[
|
|
2978
|
+
const dir = import_node_path9.default.join(buildsDir(), hash, "js");
|
|
2979
|
+
return import_node_fs9.default.readdirSync(dir).sort().map((name) => {
|
|
2980
|
+
const contentType = CONTENT_TYPES[import_node_path9.default.extname(name)];
|
|
2255
2981
|
if (!contentType) throw new Error(`unexpected kotlin artifact file ${name}`);
|
|
2256
|
-
return { name, bytes:
|
|
2982
|
+
return { name, bytes: import_node_fs9.default.readFileSync(import_node_path9.default.join(dir, name)), contentType };
|
|
2257
2983
|
});
|
|
2258
2984
|
}
|
|
2259
2985
|
function serveKotlinArtifact(pathname, res) {
|
|
2260
2986
|
if (!pathname.startsWith(KOTLIN_ARTIFACT_PREFIX)) return false;
|
|
2261
2987
|
const [hash, file, ...rest] = pathname.slice(KOTLIN_ARTIFACT_PREFIX.length).split("/");
|
|
2262
|
-
const type = file ? CONTENT_TYPES[
|
|
2988
|
+
const type = file ? CONTENT_TYPES[import_node_path9.default.extname(file)] : void 0;
|
|
2263
2989
|
if (!hash || !/^[0-9a-f]+$/.test(hash) || !file || rest.length > 0 || !type || file.includes("..")) {
|
|
2264
2990
|
res.statusCode = 404;
|
|
2265
2991
|
res.end("not a kotlin artifact");
|
|
2266
2992
|
return true;
|
|
2267
2993
|
}
|
|
2268
|
-
const target =
|
|
2269
|
-
if (!
|
|
2994
|
+
const target = import_node_path9.default.join(buildsDir(), hash, "js", file);
|
|
2995
|
+
if (!import_node_fs9.default.existsSync(target)) {
|
|
2270
2996
|
res.statusCode = 404;
|
|
2271
2997
|
res.end(`kotlin artifact ${hash}/${file} was not built`);
|
|
2272
2998
|
return true;
|
|
@@ -2274,7 +3000,7 @@ function serveKotlinArtifact(pathname, res) {
|
|
|
2274
3000
|
res.setHeader("access-control-allow-origin", "*");
|
|
2275
3001
|
res.setHeader("content-type", type);
|
|
2276
3002
|
res.setHeader("cache-control", "public, max-age=31536000, immutable");
|
|
2277
|
-
res.end(
|
|
3003
|
+
res.end(import_node_fs9.default.readFileSync(target));
|
|
2278
3004
|
return true;
|
|
2279
3005
|
}
|
|
2280
3006
|
var KOTLIN_PACKAGE_PATH = "/__peach/kotlin-package";
|