peachsim 0.1.729 → 0.1.745
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli/bridge-flow-runner.ts +15 -2
- package/cli/commands/control.ts +13 -3
- package/cli/commands/desktop.ts +1 -0
- package/cli/commands/electron.ts +12 -8
- package/cli/commands/flow.ts +1 -3
- package/cli/commands/install-desktop.ts +105 -66
- package/cli/commands/logout.ts +5 -1
- package/cli/commands/no-bridge-hint.ts +2 -2
- package/cli/commands/swift.ts +26 -9
- package/cli/desktop-companion.ts +36 -9
- package/cli/drivers/desktop.ts +65 -0
- package/cli/drivers/electron.ts +4 -66
- package/cli/drivers/index.ts +1 -0
- package/cli/drivers/playwright.ts +3 -3
- package/cli/drivers/registry.ts +7 -2
- package/cli/drivers/types.ts +4 -3
- package/cli/maestro-js.ts +10 -0
- package/cli/outbound-endpoints.ts +2 -2
- package/dist-lib/agent-daemon-client.cjs +1 -1
- package/dist-lib/agent-events.cjs +1 -1
- package/dist-lib/agent-identity.cjs +1 -1
- package/dist-lib/agent-sessions.cjs +1 -1
- package/dist-lib/attached-projects.cjs +1 -1
- package/dist-lib/auth/shared-session.cjs +39 -9
- 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/capture-contract.cjs +13 -19
- package/dist-lib/capture-contract.mjs +13 -19
- package/dist-lib/cli-constants.cjs +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 +1 -1
- package/dist-lib/detox/index.cjs +20 -2
- package/dist-lib/dev-bundle-resolution.cjs +1 -1
- package/dist-lib/home-paths.cjs +32 -1
- package/dist-lib/host/bridge-host.cjs +1617 -533
- package/dist-lib/host/fetch-proxy-handler.cjs +1 -1
- 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 +14 -19
- 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 +1 -1
- 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 +1 -1
- package/dist-lib/native-app-identity.cjs +1 -1
- package/dist-lib/native-app-identity.mjs +1 -1
- package/dist-lib/native-firebase-metadata.cjs +1 -1
- package/dist-lib/native-firebase-metadata.mjs +1 -1
- package/dist-lib/plist.cjs +1 -1
- package/dist-lib/plist.mjs +1 -1
- package/dist-lib/profiles.cjs +1 -1
- package/dist-lib/public-brand.cjs +1 -1
- package/dist-lib/react-native-host-modules.cjs +1 -1
- package/dist-lib/react-native-host-modules.mjs +1 -1
- package/dist-lib/render-mode.cjs +1 -1
- package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
- package/dist-lib/sdk.cjs +2 -1
- package/dist-lib/sdk.mjs +2 -1
- package/dist-lib/skills.cjs +2307 -1068
- package/dist-lib/swift-compile.cjs +318 -61
- package/dist-lib/swift-compile.mjs +314 -62
- package/dist-lib/swift-package.cjs +146 -9
- package/dist-lib/swift-package.mjs +144 -9
- package/dist-lib/swift-submit.cjs +2 -2
- package/dist-lib/swift-submit.mjs +2 -2
- package/dist-lib/swift-toolchain.cjs +1 -1
- package/dist-lib/swift.cjs +1 -1
- package/dist-lib/vite-swift.cjs +1311 -227
- package/dist-lib/vite.cjs +1 -1
- package/package.json +1 -1
- package/skills/contrast/SKILL.md +1 -1
- package/src/auth/shared-session.ts +45 -9
- package/src/bridge-constants.ts +7 -7
- package/src/capture-contract.ts +18 -33
- package/src/desktop-host-delivery.ts +81 -0
- package/src/home-paths.ts +30 -0
- package/src/host/bridge-host.ts +11 -6
- package/src/native-seam-manifest.ts +0 -11
- package/src/sim-client.ts +1 -0
- package/src/swift-compile.ts +404 -69
- package/src/swift-distribution.lock.json +11 -11
- package/src/swift-host.ts +316 -43
- package/src/swift-package.ts +204 -19
- package/src/swift-remote-packages.ts +255 -0
- package/src/swift-submit.ts +4 -1
- package/src/vite-plugin.ts +19 -8
- package/src/xcode-project.ts +527 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
/*! rnx v0.1.
|
|
1
|
+
/*! rnx v0.1.745 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
|
|
2
2
|
|
|
3
3
|
// src/swift-compile.ts
|
|
4
|
-
import { execFile as execFile2 } from "node:child_process";
|
|
4
|
+
import { execFile as execFile2, execFileSync } from "node:child_process";
|
|
5
5
|
import { createHash as createHash2 } from "node:crypto";
|
|
6
6
|
import {
|
|
7
7
|
cpSync,
|
|
@@ -159,14 +159,24 @@ function swiftImplicitResourcePaths(paths) {
|
|
|
159
159
|
) || /(?:^|\/)[^/]+\.lproj\/[^/]+$/.test(file))
|
|
160
160
|
).sort();
|
|
161
161
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
162
|
+
var MANIFEST_DECLARATIONS = [
|
|
163
|
+
"executableTarget",
|
|
164
|
+
"testTarget",
|
|
165
|
+
"binaryTarget",
|
|
166
|
+
"systemLibrary",
|
|
167
|
+
"macro",
|
|
168
|
+
"plugin",
|
|
169
|
+
"target",
|
|
170
|
+
"library",
|
|
171
|
+
"executable",
|
|
172
|
+
"package"
|
|
173
|
+
];
|
|
174
|
+
function manifestCalls(manifest, kinds) {
|
|
175
|
+
const code = manifest.replace(/\/\*[\s\S]*?\*\//g, "").replace(/(^|[^:"])\/\/[^\n]*/g, "$1");
|
|
176
|
+
const calls = [];
|
|
177
|
+
const pattern = new RegExp(`\\.(${MANIFEST_DECLARATIONS.join("|")})\\s*\\(`, "g");
|
|
167
178
|
let match;
|
|
168
179
|
while ((match = pattern.exec(code)) !== null) {
|
|
169
|
-
const executable = match[1] === "executableTarget";
|
|
170
180
|
let depth = 1;
|
|
171
181
|
const start = pattern.lastIndex;
|
|
172
182
|
let i = start;
|
|
@@ -194,18 +204,31 @@ function swiftManifestTargets(manifest, resourcePaths = []) {
|
|
|
194
204
|
}
|
|
195
205
|
i++;
|
|
196
206
|
}
|
|
207
|
+
if (kinds.includes(match[1]))
|
|
208
|
+
calls.push({ kind: match[1], flat, call: code.slice(start, i) });
|
|
209
|
+
pattern.lastIndex = i;
|
|
210
|
+
}
|
|
211
|
+
return calls;
|
|
212
|
+
}
|
|
213
|
+
function swiftManifestTargets(manifest, resourcePaths = []) {
|
|
214
|
+
const implicitResources = swiftImplicitResourcePaths(resourcePaths);
|
|
215
|
+
const targets = [];
|
|
216
|
+
for (const { kind, flat, call } of manifestCalls(manifest, [
|
|
217
|
+
"executableTarget",
|
|
218
|
+
"target"
|
|
219
|
+
])) {
|
|
220
|
+
const executable = kind === "executableTarget";
|
|
197
221
|
const name = /\bname\s*:\s*"([^"]+)"/.exec(flat)?.[1];
|
|
198
222
|
if (!name) continue;
|
|
199
223
|
const rawPath = /\bpath\s*:\s*"([^"]*)"/.exec(flat)?.[1];
|
|
200
224
|
const targetPath = rawPath == null || rawPath === "" ? `Sources/${name}` : rawPath.replace(/^\.\//, "").replace(/\/+$/, "");
|
|
201
|
-
const call = code.slice(start, i);
|
|
202
225
|
const languageMode = Number(
|
|
203
226
|
/\.swiftLanguageMode\(\s*\.v(\d+)\s*\)/.exec(call)?.[1] ?? "5"
|
|
204
227
|
);
|
|
205
228
|
const mainActorIsolation = /\.defaultIsolation\(\s*MainActor\.self\s*\)/.test(call);
|
|
206
229
|
const excluded = [
|
|
207
230
|
...(/\bexclude\s*:\s*\[([^\]]*)\]/.exec(flat)?.[1] ?? "").matchAll(/"([^"]+)"/g)
|
|
208
|
-
].map((
|
|
231
|
+
].map((match) => match[1].replace(/^\.\//, "").replace(/\/+$/, ""));
|
|
209
232
|
const prefix = targetPath === "." ? "" : `${targetPath}/`;
|
|
210
233
|
const resources = /\bresources\s*:/.test(flat) || implicitResources.some((file) => {
|
|
211
234
|
if (!file.startsWith(prefix)) return false;
|
|
@@ -353,7 +376,10 @@ var OPTIONAL_FRAMEWORK_DEPENDENCIES = {
|
|
|
353
376
|
CryptoKit: [],
|
|
354
377
|
CommonCrypto: [],
|
|
355
378
|
CoreText: [],
|
|
356
|
-
|
|
379
|
+
Compression: ["PeachCodec"],
|
|
380
|
+
zlib: ["PeachCodec"],
|
|
381
|
+
PeachCodec: [],
|
|
382
|
+
Security: ["CryptoKit"],
|
|
357
383
|
TikTokBusinessSDK: [],
|
|
358
384
|
nSure: [],
|
|
359
385
|
Statsig: [],
|
|
@@ -363,6 +389,66 @@ var OPTIONAL_FRAMEWORK_DEPENDENCIES = {
|
|
|
363
389
|
DatadogTrace: ["DatadogCore"]
|
|
364
390
|
};
|
|
365
391
|
var OPTIONAL_FRAMEWORKS = new Set(Object.keys(OPTIONAL_FRAMEWORK_DEPENDENCIES));
|
|
392
|
+
var SWIFT_IMPORT = /^\s*(?:@\w+(?:\([^)]*\))?\s+)*import\s+(?:(?:typealias|struct|class|enum|protocol|let|var|func)\s+)?([A-Za-z_][A-Za-z0-9_]*)/;
|
|
393
|
+
function swiftImportNames(contents, unconditional = false) {
|
|
394
|
+
const names = [];
|
|
395
|
+
let depth = 0;
|
|
396
|
+
for (const line of contents.split("\n")) {
|
|
397
|
+
const directive = /^\s*#(if|endif)\b/.exec(line)?.[1];
|
|
398
|
+
if (directive === "if") depth++;
|
|
399
|
+
else if (directive === "endif") depth = Math.max(0, depth - 1);
|
|
400
|
+
if (unconditional && depth > 0) continue;
|
|
401
|
+
const name = SWIFT_IMPORT.exec(line)?.[1];
|
|
402
|
+
if (name) names.push(name);
|
|
403
|
+
}
|
|
404
|
+
return names;
|
|
405
|
+
}
|
|
406
|
+
function swiftPeachModules(moduleRoot) {
|
|
407
|
+
const distribution = swiftDistributionAt(moduleRoot);
|
|
408
|
+
return distribution ? distribution.modules : [
|
|
409
|
+
...readFileSync2(path2.join(moduleRoot, "Package.swift"), "utf8").matchAll(
|
|
410
|
+
/\.(?:target|systemLibrary)\(\s*name:\s*"([^"]+)"/g
|
|
411
|
+
)
|
|
412
|
+
].map((match) => match[1]);
|
|
413
|
+
}
|
|
414
|
+
var availableModules = /* @__PURE__ */ new Map();
|
|
415
|
+
function swiftAvailableModules(moduleRoot, toolchainBin) {
|
|
416
|
+
const sdk = swiftModuleSdk(moduleRoot).wasmSdkId;
|
|
417
|
+
const key = `${moduleRoot}\0${sdk}`;
|
|
418
|
+
const cached = availableModules.get(key);
|
|
419
|
+
if (cached) return cached;
|
|
420
|
+
const modules = new Set(swiftPeachModules(moduleRoot));
|
|
421
|
+
const configuration = execFileSync(
|
|
422
|
+
path2.join(toolchainBin, "swift"),
|
|
423
|
+
["sdk", "configure", "--show-configuration", sdk, "wasm32-unknown-wasip1"],
|
|
424
|
+
{ encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] }
|
|
425
|
+
);
|
|
426
|
+
const resources = /^swiftResourcesPath:\s*(.+)$/m.exec(configuration)?.[1]?.trim();
|
|
427
|
+
if (!resources) throw new Error(`swift sdk ${sdk} reports no swiftResourcesPath`);
|
|
428
|
+
for (const entry of readdirSync(path2.join(resources, "wasi"))) {
|
|
429
|
+
if (entry.endsWith(".swiftmodule"))
|
|
430
|
+
modules.add(entry.slice(0, -".swiftmodule".length));
|
|
431
|
+
}
|
|
432
|
+
for (const entry of readdirSync(resources)) {
|
|
433
|
+
const map = path2.join(resources, entry, "module.modulemap");
|
|
434
|
+
if (!existsSync(map)) continue;
|
|
435
|
+
for (const match of readFileSync2(map, "utf8").matchAll(/^module\s+([A-Za-z_]\w*)/gm))
|
|
436
|
+
modules.add(match[1]);
|
|
437
|
+
}
|
|
438
|
+
availableModules.set(key, modules);
|
|
439
|
+
return modules;
|
|
440
|
+
}
|
|
441
|
+
function missingSwiftModules(files, available) {
|
|
442
|
+
const missing = /* @__PURE__ */ new Map();
|
|
443
|
+
for (const [file, contents] of Object.entries(files)) {
|
|
444
|
+
if (!file.endsWith(".swift") || file === "Package.swift") continue;
|
|
445
|
+
for (const name of new Set(swiftImportNames(contents, true))) {
|
|
446
|
+
if (available.has(name)) continue;
|
|
447
|
+
missing.set(name, [...missing.get(name) ?? [], file]);
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
return new Map([...missing].sort(([left], [right]) => left.localeCompare(right)));
|
|
451
|
+
}
|
|
366
452
|
function swiftTargetDependencies(files, targets) {
|
|
367
453
|
const names = /* @__PURE__ */ new Set([...OPTIONAL_FRAMEWORKS, ...targets.map((target) => target.name)]);
|
|
368
454
|
const siblings = /* @__PURE__ */ new Map();
|
|
@@ -375,10 +461,8 @@ function swiftTargetDependencies(files, targets) {
|
|
|
375
461
|
(candidate) => candidate.name !== target.name && candidate.path !== "." && candidate.path.startsWith(prefix) && file.startsWith(`${candidate.path}/`)
|
|
376
462
|
))
|
|
377
463
|
continue;
|
|
378
|
-
for (const
|
|
379
|
-
|
|
380
|
-
)) {
|
|
381
|
-
if (names.has(match[1]) && match[1] !== target.name) deps.add(match[1]);
|
|
464
|
+
for (const name of swiftImportNames(contents)) {
|
|
465
|
+
if (names.has(name) && name !== target.name) deps.add(name);
|
|
382
466
|
}
|
|
383
467
|
}
|
|
384
468
|
siblings.set(target.name, [...deps].sort());
|
|
@@ -388,16 +472,14 @@ function swiftTargetDependencies(files, targets) {
|
|
|
388
472
|
var ONE_PRODUCT = '.product(name: "One", package: "sootsim-swift")';
|
|
389
473
|
var SPRITEKIT_PRODUCT = '.product(name: "SpriteKit", package: "sootsim-swift")';
|
|
390
474
|
var importsSpriteKit = (files) => Object.entries(files).some(
|
|
391
|
-
([file, contents]) => file.endsWith(".swift") &&
|
|
392
|
-
contents
|
|
393
|
-
)
|
|
475
|
+
([file, contents]) => file.endsWith(".swift") && swiftImportNames(contents).includes("SpriteKit")
|
|
394
476
|
);
|
|
395
|
-
var FOUNDATION_IMPLICIT_FLAGS = ', "-Xfrontend", "-import-module", "-Xfrontend", "PeachObjC", "-Xfrontend", "-import-module", "-Xfrontend", "Dispatch", "-Xfrontend", "-import-module", "-Xfrontend", "FoundationNetworking"';
|
|
477
|
+
var FOUNDATION_IMPLICIT_FLAGS = ', "-Xfrontend", "-import-module", "-Xfrontend", "PeachObjC", "-Xfrontend", "-import-module", "-Xfrontend", "Dispatch", "-Xfrontend", "-import-module", "-Xfrontend", "FoundationNetworking", "-Xfrontend", "-import-module", "-Xfrontend", "WASILibc", "-Xfrontend", "-import-module", "-Xfrontend", "wasi_pthread"';
|
|
396
478
|
var ONE_IMPLICIT_FLAGS = ', "-Xfrontend", "-import-module", "-Xfrontend", "One"';
|
|
397
|
-
var MULTI_MANIFEST_VERSION =
|
|
479
|
+
var MULTI_MANIFEST_VERSION = 11;
|
|
398
480
|
function swiftArtifactHash(input, release, moduleRoot) {
|
|
399
481
|
const hash = createHash2("sha256");
|
|
400
|
-
hash.update(`swift-compile/
|
|
482
|
+
hash.update(`swift-compile/v16
|
|
401
483
|
${release}
|
|
402
484
|
`);
|
|
403
485
|
if (input.oneModule) hash.update("one-module\n");
|
|
@@ -569,23 +651,98 @@ function forwardedArguments(parameters) {
|
|
|
569
651
|
}
|
|
570
652
|
return args.join(", ");
|
|
571
653
|
}
|
|
572
|
-
function
|
|
654
|
+
function closingBrace(source, tokens, open) {
|
|
655
|
+
let depth = 0;
|
|
656
|
+
for (const at of tokens) {
|
|
657
|
+
if (at < open) continue;
|
|
658
|
+
if (source[at] === "{") depth++;
|
|
659
|
+
else if (source[at] === "}" && --depth === 0) return at + 1;
|
|
660
|
+
}
|
|
661
|
+
return source.length;
|
|
662
|
+
}
|
|
663
|
+
function scanObjCExtensionMembers(source, tokens, records) {
|
|
664
|
+
const masked = swiftCodeMask(source);
|
|
665
|
+
const found = /* @__PURE__ */ new Map();
|
|
666
|
+
const member = /\b(func|var)\s+([A-Za-z_]\w*)/g;
|
|
667
|
+
for (const record of records) {
|
|
668
|
+
const close = closingBrace(source, tokens, record.open);
|
|
669
|
+
const body = masked.slice(record.open, close);
|
|
670
|
+
member.lastIndex = 0;
|
|
671
|
+
for (let match = member.exec(body); match; match = member.exec(body)) {
|
|
672
|
+
const at = record.open + match.index + match[0].indexOf(match[1]);
|
|
673
|
+
let depth = 0;
|
|
674
|
+
for (const token of tokens) {
|
|
675
|
+
if (token <= record.open) continue;
|
|
676
|
+
if (token >= at) break;
|
|
677
|
+
if (source[token] === "{") depth++;
|
|
678
|
+
else if (source[token] === "}") depth--;
|
|
679
|
+
}
|
|
680
|
+
if (depth > 0) continue;
|
|
681
|
+
const head = masked.slice(record.open, at);
|
|
682
|
+
const bound = Math.max(
|
|
683
|
+
head.lastIndexOf(";"),
|
|
684
|
+
head.lastIndexOf("{"),
|
|
685
|
+
head.lastIndexOf("}")
|
|
686
|
+
);
|
|
687
|
+
const prefix = head.slice(bound + 1);
|
|
688
|
+
if (/(?:^|[^A-Za-z0-9_$])(?:private|fileprivate|static|class)(?:[^A-Za-z0-9_$]|$)/.test(
|
|
689
|
+
prefix
|
|
690
|
+
))
|
|
691
|
+
continue;
|
|
692
|
+
if (!/@objc\b/.test(prefix) && !/@IBAction\b/.test(prefix) && !record.objcMembers)
|
|
693
|
+
continue;
|
|
694
|
+
const members = found.get(record.type) ?? /* @__PURE__ */ new Set();
|
|
695
|
+
members.add(match[2]);
|
|
696
|
+
found.set(record.type, members);
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
return found;
|
|
700
|
+
}
|
|
701
|
+
function objcExtensionMemberIndex(sources) {
|
|
702
|
+
const index = /* @__PURE__ */ new Map();
|
|
703
|
+
for (const source of sources) {
|
|
704
|
+
const { tokens } = swiftCodeScan(source);
|
|
705
|
+
const masked = swiftCodeMask(source);
|
|
706
|
+
const records = [];
|
|
707
|
+
let pending = null;
|
|
708
|
+
for (const at of tokens) {
|
|
709
|
+
const rest = source.slice(at, at + 600);
|
|
710
|
+
if (rest.startsWith("{")) {
|
|
711
|
+
if (pending) records.push({ ...pending, open: at });
|
|
712
|
+
pending = null;
|
|
713
|
+
continue;
|
|
714
|
+
}
|
|
715
|
+
if (rest.startsWith("}")) continue;
|
|
716
|
+
const extended = EXTENSION_DECL.exec(rest);
|
|
717
|
+
if (extended) {
|
|
718
|
+
const lines = source.lastIndexOf("\n", source.lastIndexOf("\n", at - 1) - 1) + 1;
|
|
719
|
+
pending = {
|
|
720
|
+
type: extended[1].split(".").pop(),
|
|
721
|
+
objcMembers: /@objcMembers\b/.test(masked.slice(lines, at))
|
|
722
|
+
};
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
for (const [type, members] of scanObjCExtensionMembers(source, tokens, records)) {
|
|
726
|
+
const into = index.get(type) ?? /* @__PURE__ */ new Set();
|
|
727
|
+
for (const member of members) into.add(member);
|
|
728
|
+
index.set(type, into);
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
return index;
|
|
732
|
+
}
|
|
733
|
+
function liftExtensionOverrides(source, extraObjCExtensions) {
|
|
573
734
|
const { tokens } = swiftCodeScan(source);
|
|
735
|
+
const masked = swiftCodeMask(source);
|
|
574
736
|
const stack = [];
|
|
575
737
|
let pending = null;
|
|
576
738
|
const classes = /* @__PURE__ */ new Map();
|
|
577
739
|
let declaredBase = null;
|
|
578
740
|
let declaredObjCMembers = false;
|
|
741
|
+
const extensions = [];
|
|
742
|
+
let declaredExtObjCMembers = false;
|
|
579
743
|
const lifted = [];
|
|
580
|
-
const
|
|
581
|
-
|
|
582
|
-
for (const at of tokens) {
|
|
583
|
-
if (at < open) continue;
|
|
584
|
-
if (source[at] === "{") depth++;
|
|
585
|
-
else if (source[at] === "}" && --depth === 0) return at + 1;
|
|
586
|
-
}
|
|
587
|
-
return source.length;
|
|
588
|
-
};
|
|
744
|
+
const overrides = [];
|
|
745
|
+
const closing = (open) => closingBrace(source, tokens, open);
|
|
589
746
|
for (const at of tokens) {
|
|
590
747
|
const rest = source.slice(at, at + 600);
|
|
591
748
|
if (rest.startsWith("{")) {
|
|
@@ -596,6 +753,12 @@ function liftExtensionOverrides(source) {
|
|
|
596
753
|
base: declaredBase,
|
|
597
754
|
objcMembers: declaredObjCMembers
|
|
598
755
|
});
|
|
756
|
+
if (frame.kind === "extension")
|
|
757
|
+
extensions.push({
|
|
758
|
+
type: frame.name,
|
|
759
|
+
open: at,
|
|
760
|
+
objcMembers: declaredExtObjCMembers
|
|
761
|
+
});
|
|
599
762
|
stack.push(frame);
|
|
600
763
|
pending = null;
|
|
601
764
|
continue;
|
|
@@ -615,12 +778,39 @@ function liftExtensionOverrides(source) {
|
|
|
615
778
|
const extended = EXTENSION_DECL.exec(rest);
|
|
616
779
|
if (extended) {
|
|
617
780
|
pending = { kind: "extension", name: extended[1].split(".").pop() };
|
|
781
|
+
const lines = source.lastIndexOf("\n", source.lastIndexOf("\n", at - 1) - 1) + 1;
|
|
782
|
+
declaredExtObjCMembers = /@objcMembers\b/.test(masked.slice(lines, at));
|
|
618
783
|
continue;
|
|
619
784
|
}
|
|
620
785
|
const top = stack.at(-1);
|
|
621
|
-
if (!rest.startsWith("override") ||
|
|
786
|
+
if (!rest.startsWith("override") || pending) continue;
|
|
622
787
|
const line = source.slice(source.lastIndexOf("\n", at - 1) + 1, at);
|
|
623
788
|
const modifiers = (` ${line} `.match(MODIFIERS) ?? []).map((word) => word.trim());
|
|
789
|
+
if (top?.kind === "class") {
|
|
790
|
+
let member;
|
|
791
|
+
let nameAt = 0;
|
|
792
|
+
const direct = OVERRIDE_FUNC.exec(rest);
|
|
793
|
+
if (direct) {
|
|
794
|
+
member = direct[2];
|
|
795
|
+
nameAt = at + rest.indexOf(
|
|
796
|
+
member,
|
|
797
|
+
rest.indexOf("func", "override".length + direct[1].length) + 4
|
|
798
|
+
);
|
|
799
|
+
} else {
|
|
800
|
+
const property2 = OVERRIDE_VAR.exec(rest);
|
|
801
|
+
if (property2) {
|
|
802
|
+
const open = at + property2[0].length - 1;
|
|
803
|
+
if (!/\b(?:set|willSet|didSet)\b/.test(source.slice(open, closing(open)))) {
|
|
804
|
+
member = property2[2];
|
|
805
|
+
nameAt = at + rest.indexOf(member, rest.indexOf("var"));
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
if (member !== void 0 && !modifiers.includes("private") && !modifiers.includes("fileprivate"))
|
|
810
|
+
overrides.push({ type: top.name, member, at, nameAt });
|
|
811
|
+
continue;
|
|
812
|
+
}
|
|
813
|
+
if (top?.kind !== "extension") continue;
|
|
624
814
|
const func = OVERRIDE_FUNC.exec(rest);
|
|
625
815
|
if (func) {
|
|
626
816
|
const name = func[2];
|
|
@@ -638,20 +828,18 @@ function liftExtensionOverrides(source) {
|
|
|
638
828
|
if (args === null) continue;
|
|
639
829
|
const call = (clause.includes("->") ? "return " : "") + (/\b(?:throws|rethrows)\b/.test(clause) ? "try " : "") + (/\basync\b/.test(clause) ? "await " : "") + `__peach_ext_${name}(${args})`;
|
|
640
830
|
const signature = `func ${name}${func[3] ?? ""}${source.slice(open, close + 1)}${clause ? ` ${clause}` : ""}`;
|
|
831
|
+
const nameAt = at + rest.indexOf(name, rest.indexOf("func", "override".length + func[1].length) + 4);
|
|
641
832
|
lifted.push({
|
|
642
833
|
type: top.name,
|
|
643
834
|
member: name,
|
|
644
|
-
|
|
835
|
+
at,
|
|
836
|
+
modifiers,
|
|
837
|
+
decl: signature,
|
|
838
|
+
forward: `{ ${call} };`,
|
|
839
|
+
nameAt,
|
|
645
840
|
edits: [
|
|
646
841
|
[at, "override".length, " ".repeat("override".length)],
|
|
647
|
-
[
|
|
648
|
-
at + rest.indexOf(
|
|
649
|
-
name,
|
|
650
|
-
rest.indexOf("func", "override".length + func[1].length) + 4
|
|
651
|
-
),
|
|
652
|
-
0,
|
|
653
|
-
"__peach_ext_"
|
|
654
|
-
]
|
|
842
|
+
[nameAt, 0, "__peach_ext_"]
|
|
655
843
|
]
|
|
656
844
|
});
|
|
657
845
|
continue;
|
|
@@ -661,40 +849,77 @@ function liftExtensionOverrides(source) {
|
|
|
661
849
|
const open = at + property[0].length - 1;
|
|
662
850
|
if (/\b(?:set|willSet|didSet)\b/.test(source.slice(open, closing(open)))) continue;
|
|
663
851
|
const name = property[2];
|
|
852
|
+
const nameAt = at + rest.indexOf(name, rest.indexOf("var"));
|
|
664
853
|
lifted.push({
|
|
665
854
|
type: top.name,
|
|
666
855
|
member: name,
|
|
667
|
-
|
|
856
|
+
at,
|
|
857
|
+
modifiers,
|
|
858
|
+
decl: `var ${name}: ${property[3].trim()}`,
|
|
859
|
+
forward: `{ __peach_ext_${name} };`,
|
|
860
|
+
nameAt,
|
|
668
861
|
edits: [
|
|
669
862
|
[at, "override".length, " ".repeat("override".length)],
|
|
670
|
-
[
|
|
863
|
+
[nameAt, 0, "__peach_ext_"]
|
|
671
864
|
]
|
|
672
865
|
});
|
|
673
866
|
}
|
|
674
867
|
}
|
|
675
|
-
const
|
|
868
|
+
const extIndex = /* @__PURE__ */ new Map();
|
|
869
|
+
if (extraObjCExtensions)
|
|
870
|
+
for (const [type, members] of extraObjCExtensions)
|
|
871
|
+
extIndex.set(type, new Set(members));
|
|
872
|
+
for (const [type, members] of scanObjCExtensionMembers(source, tokens, extensions)) {
|
|
873
|
+
const into = extIndex.get(type) ?? /* @__PURE__ */ new Set();
|
|
874
|
+
for (const member of members) into.add(member);
|
|
875
|
+
extIndex.set(type, into);
|
|
876
|
+
}
|
|
877
|
+
const overrideKind = (type, member) => {
|
|
676
878
|
let base = classes.get(type)?.base ?? null;
|
|
677
879
|
while (base !== null) {
|
|
678
|
-
if (APPLE_CLASS.test(base)) return true;
|
|
679
880
|
const declaredClass = classes.get(base);
|
|
680
|
-
if (
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
881
|
+
if (declaredClass) {
|
|
882
|
+
const body = source.slice(declaredClass.brace, closing(declaredClass.brace));
|
|
883
|
+
const found = new RegExp(`\\b(?:func|var)\\s+${member}\\b`).exec(body);
|
|
884
|
+
if (found) {
|
|
885
|
+
const line = body.slice(body.lastIndexOf("\n", found.index) + 1, found.index);
|
|
886
|
+
return declaredClass.objcMembers || /@objc\b/.test(line) ? "objc" : "plain";
|
|
887
|
+
}
|
|
888
|
+
if (extIndex.get(base)?.has(member)) return "ext";
|
|
889
|
+
base = declaredClass.base;
|
|
890
|
+
} else if (extIndex.get(base)?.has(member)) return "ext";
|
|
891
|
+
else if (APPLE_CLASS.test(base)) return "apple";
|
|
892
|
+
else return "unknown";
|
|
688
893
|
}
|
|
689
|
-
return
|
|
894
|
+
return "unknown";
|
|
690
895
|
};
|
|
896
|
+
const rename = (at, nameAt) => [
|
|
897
|
+
[at, "override".length, " ".repeat("override".length)],
|
|
898
|
+
[nameAt, 0, "__peach_ovr_"]
|
|
899
|
+
];
|
|
691
900
|
const edits = [];
|
|
692
901
|
const stubs = /* @__PURE__ */ new Map();
|
|
693
902
|
for (const entry of lifted) {
|
|
694
903
|
const brace = classes.get(entry.type)?.brace;
|
|
695
|
-
if (brace === void 0
|
|
904
|
+
if (brace === void 0) continue;
|
|
905
|
+
const kind = overrideKind(entry.type, entry.member);
|
|
906
|
+
if (kind !== "apple" && kind !== "objc" && kind !== "ext") continue;
|
|
907
|
+
if (kind === "ext" && (entry.modifiers.includes("private") || entry.modifiers.includes("fileprivate")))
|
|
908
|
+
continue;
|
|
909
|
+
if (kind === "ext") {
|
|
910
|
+
edits.push(...rename(entry.at, entry.nameAt));
|
|
911
|
+
continue;
|
|
912
|
+
}
|
|
696
913
|
edits.push(...entry.edits);
|
|
697
|
-
|
|
914
|
+
const head = [...entry.modifiers, "override"].filter((word) => word !== "").join(" ");
|
|
915
|
+
stubs.set(brace, [
|
|
916
|
+
...stubs.get(brace) ?? [],
|
|
917
|
+
`${head} ${entry.decl} ${entry.forward}`
|
|
918
|
+
]);
|
|
919
|
+
}
|
|
920
|
+
for (const candidate of overrides) {
|
|
921
|
+
if (overrideKind(candidate.type, candidate.member) !== "ext") continue;
|
|
922
|
+
edits.push(...rename(candidate.at, candidate.nameAt));
|
|
698
923
|
}
|
|
699
924
|
for (const [brace, list] of stubs) edits.push([brace + 1, 0, ` ${list.join(" ")}`]);
|
|
700
925
|
let out = source;
|
|
@@ -876,8 +1101,8 @@ function swiftCodeMask(source) {
|
|
|
876
1101
|
scanCode(0, false);
|
|
877
1102
|
return chars.join("");
|
|
878
1103
|
}
|
|
879
|
-
function swiftSourceAsIOS(original) {
|
|
880
|
-
const source = liftExtensionOverrides(original);
|
|
1104
|
+
function swiftSourceAsIOS(original, extraObjCExtensions) {
|
|
1105
|
+
const source = liftExtensionOverrides(original, extraObjCExtensions);
|
|
881
1106
|
const { lineStarts, tokens } = swiftCodeScan(source);
|
|
882
1107
|
let offset = 0;
|
|
883
1108
|
const conditioned = source.split("\n").map((line) => {
|
|
@@ -1046,9 +1271,22 @@ function swiftCodeScan(source) {
|
|
|
1046
1271
|
}
|
|
1047
1272
|
return { lineStarts: starts, tokens };
|
|
1048
1273
|
}
|
|
1049
|
-
var compiledSource = (file, contents) => file.endsWith(".swift") ? swiftSourceAsIOS(contents) : contents;
|
|
1274
|
+
var compiledSource = (file, contents, extraObjCExtensions) => file.endsWith(".swift") ? swiftSourceAsIOS(contents, extraObjCExtensions) : contents;
|
|
1050
1275
|
function prepareSwiftDependency(source, destination) {
|
|
1051
1276
|
rmSync(destination, { recursive: true, force: true });
|
|
1277
|
+
const origins = [];
|
|
1278
|
+
const gather = (from, root) => {
|
|
1279
|
+
for (const entry of readdirSync(from, { withFileTypes: true })) {
|
|
1280
|
+
if (entry.name === ".git" || entry.name === ".build" || entry.name === ".swiftpm")
|
|
1281
|
+
continue;
|
|
1282
|
+
const file = path2.join(from, entry.name);
|
|
1283
|
+
if (entry.isDirectory()) gather(file, false);
|
|
1284
|
+
else if (entry.isFile() && entry.name.endsWith(".swift") && !(root && /^Package(@swift-[\d.]+)?\.swift$/.test(entry.name)))
|
|
1285
|
+
origins.push(readFileSync2(file, "utf8"));
|
|
1286
|
+
}
|
|
1287
|
+
};
|
|
1288
|
+
gather(source, true);
|
|
1289
|
+
const objcExtensions = objcExtensionMemberIndex(origins);
|
|
1052
1290
|
const copy = (from, to, root) => {
|
|
1053
1291
|
mkdirSync(to, { recursive: true });
|
|
1054
1292
|
for (const entry of readdirSync(from, { withFileTypes: true })) {
|
|
@@ -1058,7 +1296,10 @@ function prepareSwiftDependency(source, destination) {
|
|
|
1058
1296
|
const target = path2.join(to, entry.name);
|
|
1059
1297
|
if (entry.isDirectory()) copy(file, target, false);
|
|
1060
1298
|
else if (entry.isFile() && entry.name.endsWith(".swift") && !(root && /^Package(@swift-[\d.]+)?\.swift$/.test(entry.name)))
|
|
1061
|
-
writeFileSync(
|
|
1299
|
+
writeFileSync(
|
|
1300
|
+
target,
|
|
1301
|
+
compiledSource(file, readFileSync2(file, "utf8"), objcExtensions)
|
|
1302
|
+
);
|
|
1062
1303
|
else cpSync(file, target, { verbatimSymlinks: true });
|
|
1063
1304
|
}
|
|
1064
1305
|
};
|
|
@@ -1096,10 +1337,16 @@ function writeSwiftProject(layout, input, moduleRoot) {
|
|
|
1096
1337
|
// sootsim-swift files ${modulePlan.digest("hex").slice(0, 16)}
|
|
1097
1338
|
// resource accessors ${resourcePlan}
|
|
1098
1339
|
`;
|
|
1340
|
+
const objcExtensions = objcExtensionMemberIndex(
|
|
1341
|
+
Object.entries(input.files).filter(([file]) => file.endsWith(".swift")).map(([, contents]) => contents)
|
|
1342
|
+
);
|
|
1099
1343
|
if (targets.length === 0) {
|
|
1100
1344
|
for (const [file, contents] of Object.entries(input.files)) {
|
|
1101
1345
|
if (file === "Package.swift") continue;
|
|
1102
|
-
files.set(
|
|
1346
|
+
files.set(
|
|
1347
|
+
path2.join(layout.sources, file),
|
|
1348
|
+
compiledSource(file, contents, objcExtensions)
|
|
1349
|
+
);
|
|
1103
1350
|
}
|
|
1104
1351
|
let manifest = readFileSync2(
|
|
1105
1352
|
path2.join(moduleRoot, "scripts/contrast-app-Package.swift"),
|
|
@@ -1145,7 +1392,7 @@ function writeSwiftProject(layout, input, moduleRoot) {
|
|
|
1145
1392
|
const base = layout.multi ? layout.root : layout.sources;
|
|
1146
1393
|
for (const [file, contents] of Object.entries(input.files)) {
|
|
1147
1394
|
if (file === "Package.swift") continue;
|
|
1148
|
-
files.set(path2.join(base, file), compiledSource(file, contents));
|
|
1395
|
+
files.set(path2.join(base, file), compiledSource(file, contents, objcExtensions));
|
|
1149
1396
|
}
|
|
1150
1397
|
files.set(
|
|
1151
1398
|
path2.join(layout.root, "Package.swift"),
|
|
@@ -1290,13 +1537,18 @@ export {
|
|
|
1290
1537
|
compileTargets,
|
|
1291
1538
|
emitSwiftPackageManifest,
|
|
1292
1539
|
lowerAnyObjectDoubleValue,
|
|
1540
|
+
missingSwiftModules,
|
|
1541
|
+
objcExtensionMemberIndex,
|
|
1293
1542
|
prepareSwiftDependency,
|
|
1294
1543
|
swiftArtifactHash,
|
|
1544
|
+
swiftAvailableModules,
|
|
1295
1545
|
swiftDistributionAt,
|
|
1296
1546
|
swiftIcuAsset,
|
|
1547
|
+
swiftImportNames,
|
|
1297
1548
|
swiftModuleDigest,
|
|
1298
1549
|
swiftModuleInputFiles,
|
|
1299
1550
|
swiftModuleSdk,
|
|
1551
|
+
swiftPeachModules,
|
|
1300
1552
|
swiftSourceAsIOS,
|
|
1301
1553
|
swiftTargetDependencies,
|
|
1302
1554
|
syncSwiftTree,
|