peachsim 0.1.730 → 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 +1616 -532
- 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 +2306 -1067
- package/dist-lib/swift-compile.cjs +317 -60
- package/dist-lib/swift-compile.mjs +313 -61
- 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 +1310 -226
- 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 +403 -68
- 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,4 +1,4 @@
|
|
|
1
|
-
/*! rnx v0.1.
|
|
1
|
+
/*! rnx v0.1.745 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
|
|
2
2
|
let __sootsim_import_meta_url = ''; try { __sootsim_import_meta_url = require('url').pathToFileURL(__filename).href; } catch {}
|
|
3
3
|
"use strict";
|
|
4
4
|
var __create = Object.create;
|
|
@@ -38,13 +38,18 @@ __export(swift_compile_exports, {
|
|
|
38
38
|
compileTargets: () => compileTargets,
|
|
39
39
|
emitSwiftPackageManifest: () => emitSwiftPackageManifest,
|
|
40
40
|
lowerAnyObjectDoubleValue: () => lowerAnyObjectDoubleValue,
|
|
41
|
+
missingSwiftModules: () => missingSwiftModules,
|
|
42
|
+
objcExtensionMemberIndex: () => objcExtensionMemberIndex,
|
|
41
43
|
prepareSwiftDependency: () => prepareSwiftDependency,
|
|
42
44
|
swiftArtifactHash: () => swiftArtifactHash,
|
|
45
|
+
swiftAvailableModules: () => swiftAvailableModules,
|
|
43
46
|
swiftDistributionAt: () => swiftDistributionAt,
|
|
44
47
|
swiftIcuAsset: () => swiftIcuAsset,
|
|
48
|
+
swiftImportNames: () => swiftImportNames,
|
|
45
49
|
swiftModuleDigest: () => swiftModuleDigest,
|
|
46
50
|
swiftModuleInputFiles: () => swiftModuleInputFiles,
|
|
47
51
|
swiftModuleSdk: () => swiftModuleSdk,
|
|
52
|
+
swiftPeachModules: () => swiftPeachModules,
|
|
48
53
|
swiftSourceAsIOS: () => swiftSourceAsIOS,
|
|
49
54
|
swiftTargetDependencies: () => swiftTargetDependencies,
|
|
50
55
|
syncSwiftTree: () => syncSwiftTree,
|
|
@@ -200,14 +205,24 @@ function swiftImplicitResourcePaths(paths) {
|
|
|
200
205
|
) || /(?:^|\/)[^/]+\.lproj\/[^/]+$/.test(file))
|
|
201
206
|
).sort();
|
|
202
207
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
+
var MANIFEST_DECLARATIONS = [
|
|
209
|
+
"executableTarget",
|
|
210
|
+
"testTarget",
|
|
211
|
+
"binaryTarget",
|
|
212
|
+
"systemLibrary",
|
|
213
|
+
"macro",
|
|
214
|
+
"plugin",
|
|
215
|
+
"target",
|
|
216
|
+
"library",
|
|
217
|
+
"executable",
|
|
218
|
+
"package"
|
|
219
|
+
];
|
|
220
|
+
function manifestCalls(manifest, kinds) {
|
|
221
|
+
const code = manifest.replace(/\/\*[\s\S]*?\*\//g, "").replace(/(^|[^:"])\/\/[^\n]*/g, "$1");
|
|
222
|
+
const calls = [];
|
|
223
|
+
const pattern = new RegExp(`\\.(${MANIFEST_DECLARATIONS.join("|")})\\s*\\(`, "g");
|
|
208
224
|
let match;
|
|
209
225
|
while ((match = pattern.exec(code)) !== null) {
|
|
210
|
-
const executable = match[1] === "executableTarget";
|
|
211
226
|
let depth = 1;
|
|
212
227
|
const start = pattern.lastIndex;
|
|
213
228
|
let i = start;
|
|
@@ -235,18 +250,31 @@ function swiftManifestTargets(manifest, resourcePaths = []) {
|
|
|
235
250
|
}
|
|
236
251
|
i++;
|
|
237
252
|
}
|
|
253
|
+
if (kinds.includes(match[1]))
|
|
254
|
+
calls.push({ kind: match[1], flat, call: code.slice(start, i) });
|
|
255
|
+
pattern.lastIndex = i;
|
|
256
|
+
}
|
|
257
|
+
return calls;
|
|
258
|
+
}
|
|
259
|
+
function swiftManifestTargets(manifest, resourcePaths = []) {
|
|
260
|
+
const implicitResources = swiftImplicitResourcePaths(resourcePaths);
|
|
261
|
+
const targets = [];
|
|
262
|
+
for (const { kind, flat, call } of manifestCalls(manifest, [
|
|
263
|
+
"executableTarget",
|
|
264
|
+
"target"
|
|
265
|
+
])) {
|
|
266
|
+
const executable = kind === "executableTarget";
|
|
238
267
|
const name = /\bname\s*:\s*"([^"]+)"/.exec(flat)?.[1];
|
|
239
268
|
if (!name) continue;
|
|
240
269
|
const rawPath = /\bpath\s*:\s*"([^"]*)"/.exec(flat)?.[1];
|
|
241
270
|
const targetPath = rawPath == null || rawPath === "" ? `Sources/${name}` : rawPath.replace(/^\.\//, "").replace(/\/+$/, "");
|
|
242
|
-
const call = code.slice(start, i);
|
|
243
271
|
const languageMode = Number(
|
|
244
272
|
/\.swiftLanguageMode\(\s*\.v(\d+)\s*\)/.exec(call)?.[1] ?? "5"
|
|
245
273
|
);
|
|
246
274
|
const mainActorIsolation = /\.defaultIsolation\(\s*MainActor\.self\s*\)/.test(call);
|
|
247
275
|
const excluded = [
|
|
248
276
|
...(/\bexclude\s*:\s*\[([^\]]*)\]/.exec(flat)?.[1] ?? "").matchAll(/"([^"]+)"/g)
|
|
249
|
-
].map((
|
|
277
|
+
].map((match) => match[1].replace(/^\.\//, "").replace(/\/+$/, ""));
|
|
250
278
|
const prefix = targetPath === "." ? "" : `${targetPath}/`;
|
|
251
279
|
const resources = /\bresources\s*:/.test(flat) || implicitResources.some((file) => {
|
|
252
280
|
if (!file.startsWith(prefix)) return false;
|
|
@@ -394,6 +422,9 @@ var OPTIONAL_FRAMEWORK_DEPENDENCIES = {
|
|
|
394
422
|
CryptoKit: [],
|
|
395
423
|
CommonCrypto: [],
|
|
396
424
|
CoreText: [],
|
|
425
|
+
Compression: ["PeachCodec"],
|
|
426
|
+
zlib: ["PeachCodec"],
|
|
427
|
+
PeachCodec: [],
|
|
397
428
|
Security: ["CryptoKit"],
|
|
398
429
|
TikTokBusinessSDK: [],
|
|
399
430
|
nSure: [],
|
|
@@ -404,6 +435,66 @@ var OPTIONAL_FRAMEWORK_DEPENDENCIES = {
|
|
|
404
435
|
DatadogTrace: ["DatadogCore"]
|
|
405
436
|
};
|
|
406
437
|
var OPTIONAL_FRAMEWORKS = new Set(Object.keys(OPTIONAL_FRAMEWORK_DEPENDENCIES));
|
|
438
|
+
var SWIFT_IMPORT = /^\s*(?:@\w+(?:\([^)]*\))?\s+)*import\s+(?:(?:typealias|struct|class|enum|protocol|let|var|func)\s+)?([A-Za-z_][A-Za-z0-9_]*)/;
|
|
439
|
+
function swiftImportNames(contents, unconditional = false) {
|
|
440
|
+
const names = [];
|
|
441
|
+
let depth = 0;
|
|
442
|
+
for (const line of contents.split("\n")) {
|
|
443
|
+
const directive = /^\s*#(if|endif)\b/.exec(line)?.[1];
|
|
444
|
+
if (directive === "if") depth++;
|
|
445
|
+
else if (directive === "endif") depth = Math.max(0, depth - 1);
|
|
446
|
+
if (unconditional && depth > 0) continue;
|
|
447
|
+
const name = SWIFT_IMPORT.exec(line)?.[1];
|
|
448
|
+
if (name) names.push(name);
|
|
449
|
+
}
|
|
450
|
+
return names;
|
|
451
|
+
}
|
|
452
|
+
function swiftPeachModules(moduleRoot) {
|
|
453
|
+
const distribution = swiftDistributionAt(moduleRoot);
|
|
454
|
+
return distribution ? distribution.modules : [
|
|
455
|
+
...(0, import_node_fs2.readFileSync)(import_node_path2.default.join(moduleRoot, "Package.swift"), "utf8").matchAll(
|
|
456
|
+
/\.(?:target|systemLibrary)\(\s*name:\s*"([^"]+)"/g
|
|
457
|
+
)
|
|
458
|
+
].map((match) => match[1]);
|
|
459
|
+
}
|
|
460
|
+
var availableModules = /* @__PURE__ */ new Map();
|
|
461
|
+
function swiftAvailableModules(moduleRoot, toolchainBin) {
|
|
462
|
+
const sdk = swiftModuleSdk(moduleRoot).wasmSdkId;
|
|
463
|
+
const key = `${moduleRoot}\0${sdk}`;
|
|
464
|
+
const cached = availableModules.get(key);
|
|
465
|
+
if (cached) return cached;
|
|
466
|
+
const modules = new Set(swiftPeachModules(moduleRoot));
|
|
467
|
+
const configuration = (0, import_node_child_process2.execFileSync)(
|
|
468
|
+
import_node_path2.default.join(toolchainBin, "swift"),
|
|
469
|
+
["sdk", "configure", "--show-configuration", sdk, "wasm32-unknown-wasip1"],
|
|
470
|
+
{ encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] }
|
|
471
|
+
);
|
|
472
|
+
const resources = /^swiftResourcesPath:\s*(.+)$/m.exec(configuration)?.[1]?.trim();
|
|
473
|
+
if (!resources) throw new Error(`swift sdk ${sdk} reports no swiftResourcesPath`);
|
|
474
|
+
for (const entry of (0, import_node_fs2.readdirSync)(import_node_path2.default.join(resources, "wasi"))) {
|
|
475
|
+
if (entry.endsWith(".swiftmodule"))
|
|
476
|
+
modules.add(entry.slice(0, -".swiftmodule".length));
|
|
477
|
+
}
|
|
478
|
+
for (const entry of (0, import_node_fs2.readdirSync)(resources)) {
|
|
479
|
+
const map = import_node_path2.default.join(resources, entry, "module.modulemap");
|
|
480
|
+
if (!(0, import_node_fs2.existsSync)(map)) continue;
|
|
481
|
+
for (const match of (0, import_node_fs2.readFileSync)(map, "utf8").matchAll(/^module\s+([A-Za-z_]\w*)/gm))
|
|
482
|
+
modules.add(match[1]);
|
|
483
|
+
}
|
|
484
|
+
availableModules.set(key, modules);
|
|
485
|
+
return modules;
|
|
486
|
+
}
|
|
487
|
+
function missingSwiftModules(files, available) {
|
|
488
|
+
const missing = /* @__PURE__ */ new Map();
|
|
489
|
+
for (const [file, contents] of Object.entries(files)) {
|
|
490
|
+
if (!file.endsWith(".swift") || file === "Package.swift") continue;
|
|
491
|
+
for (const name of new Set(swiftImportNames(contents, true))) {
|
|
492
|
+
if (available.has(name)) continue;
|
|
493
|
+
missing.set(name, [...missing.get(name) ?? [], file]);
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
return new Map([...missing].sort(([left], [right]) => left.localeCompare(right)));
|
|
497
|
+
}
|
|
407
498
|
function swiftTargetDependencies(files, targets) {
|
|
408
499
|
const names = /* @__PURE__ */ new Set([...OPTIONAL_FRAMEWORKS, ...targets.map((target) => target.name)]);
|
|
409
500
|
const siblings = /* @__PURE__ */ new Map();
|
|
@@ -416,10 +507,8 @@ function swiftTargetDependencies(files, targets) {
|
|
|
416
507
|
(candidate) => candidate.name !== target.name && candidate.path !== "." && candidate.path.startsWith(prefix) && file.startsWith(`${candidate.path}/`)
|
|
417
508
|
))
|
|
418
509
|
continue;
|
|
419
|
-
for (const
|
|
420
|
-
|
|
421
|
-
)) {
|
|
422
|
-
if (names.has(match[1]) && match[1] !== target.name) deps.add(match[1]);
|
|
510
|
+
for (const name of swiftImportNames(contents)) {
|
|
511
|
+
if (names.has(name) && name !== target.name) deps.add(name);
|
|
423
512
|
}
|
|
424
513
|
}
|
|
425
514
|
siblings.set(target.name, [...deps].sort());
|
|
@@ -429,16 +518,14 @@ function swiftTargetDependencies(files, targets) {
|
|
|
429
518
|
var ONE_PRODUCT = '.product(name: "One", package: "sootsim-swift")';
|
|
430
519
|
var SPRITEKIT_PRODUCT = '.product(name: "SpriteKit", package: "sootsim-swift")';
|
|
431
520
|
var importsSpriteKit = (files) => Object.entries(files).some(
|
|
432
|
-
([file, contents]) => file.endsWith(".swift") &&
|
|
433
|
-
contents
|
|
434
|
-
)
|
|
521
|
+
([file, contents]) => file.endsWith(".swift") && swiftImportNames(contents).includes("SpriteKit")
|
|
435
522
|
);
|
|
436
|
-
var FOUNDATION_IMPLICIT_FLAGS = ', "-Xfrontend", "-import-module", "-Xfrontend", "PeachObjC", "-Xfrontend", "-import-module", "-Xfrontend", "Dispatch", "-Xfrontend", "-import-module", "-Xfrontend", "FoundationNetworking"';
|
|
523
|
+
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"';
|
|
437
524
|
var ONE_IMPLICIT_FLAGS = ', "-Xfrontend", "-import-module", "-Xfrontend", "One"';
|
|
438
|
-
var MULTI_MANIFEST_VERSION =
|
|
525
|
+
var MULTI_MANIFEST_VERSION = 11;
|
|
439
526
|
function swiftArtifactHash(input, release, moduleRoot) {
|
|
440
527
|
const hash = (0, import_node_crypto2.createHash)("sha256");
|
|
441
|
-
hash.update(`swift-compile/
|
|
528
|
+
hash.update(`swift-compile/v16
|
|
442
529
|
${release}
|
|
443
530
|
`);
|
|
444
531
|
if (input.oneModule) hash.update("one-module\n");
|
|
@@ -610,23 +697,98 @@ function forwardedArguments(parameters) {
|
|
|
610
697
|
}
|
|
611
698
|
return args.join(", ");
|
|
612
699
|
}
|
|
613
|
-
function
|
|
700
|
+
function closingBrace(source, tokens, open) {
|
|
701
|
+
let depth = 0;
|
|
702
|
+
for (const at of tokens) {
|
|
703
|
+
if (at < open) continue;
|
|
704
|
+
if (source[at] === "{") depth++;
|
|
705
|
+
else if (source[at] === "}" && --depth === 0) return at + 1;
|
|
706
|
+
}
|
|
707
|
+
return source.length;
|
|
708
|
+
}
|
|
709
|
+
function scanObjCExtensionMembers(source, tokens, records) {
|
|
710
|
+
const masked = swiftCodeMask(source);
|
|
711
|
+
const found = /* @__PURE__ */ new Map();
|
|
712
|
+
const member = /\b(func|var)\s+([A-Za-z_]\w*)/g;
|
|
713
|
+
for (const record of records) {
|
|
714
|
+
const close = closingBrace(source, tokens, record.open);
|
|
715
|
+
const body = masked.slice(record.open, close);
|
|
716
|
+
member.lastIndex = 0;
|
|
717
|
+
for (let match = member.exec(body); match; match = member.exec(body)) {
|
|
718
|
+
const at = record.open + match.index + match[0].indexOf(match[1]);
|
|
719
|
+
let depth = 0;
|
|
720
|
+
for (const token of tokens) {
|
|
721
|
+
if (token <= record.open) continue;
|
|
722
|
+
if (token >= at) break;
|
|
723
|
+
if (source[token] === "{") depth++;
|
|
724
|
+
else if (source[token] === "}") depth--;
|
|
725
|
+
}
|
|
726
|
+
if (depth > 0) continue;
|
|
727
|
+
const head = masked.slice(record.open, at);
|
|
728
|
+
const bound = Math.max(
|
|
729
|
+
head.lastIndexOf(";"),
|
|
730
|
+
head.lastIndexOf("{"),
|
|
731
|
+
head.lastIndexOf("}")
|
|
732
|
+
);
|
|
733
|
+
const prefix = head.slice(bound + 1);
|
|
734
|
+
if (/(?:^|[^A-Za-z0-9_$])(?:private|fileprivate|static|class)(?:[^A-Za-z0-9_$]|$)/.test(
|
|
735
|
+
prefix
|
|
736
|
+
))
|
|
737
|
+
continue;
|
|
738
|
+
if (!/@objc\b/.test(prefix) && !/@IBAction\b/.test(prefix) && !record.objcMembers)
|
|
739
|
+
continue;
|
|
740
|
+
const members = found.get(record.type) ?? /* @__PURE__ */ new Set();
|
|
741
|
+
members.add(match[2]);
|
|
742
|
+
found.set(record.type, members);
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
return found;
|
|
746
|
+
}
|
|
747
|
+
function objcExtensionMemberIndex(sources) {
|
|
748
|
+
const index = /* @__PURE__ */ new Map();
|
|
749
|
+
for (const source of sources) {
|
|
750
|
+
const { tokens } = swiftCodeScan(source);
|
|
751
|
+
const masked = swiftCodeMask(source);
|
|
752
|
+
const records = [];
|
|
753
|
+
let pending = null;
|
|
754
|
+
for (const at of tokens) {
|
|
755
|
+
const rest = source.slice(at, at + 600);
|
|
756
|
+
if (rest.startsWith("{")) {
|
|
757
|
+
if (pending) records.push({ ...pending, open: at });
|
|
758
|
+
pending = null;
|
|
759
|
+
continue;
|
|
760
|
+
}
|
|
761
|
+
if (rest.startsWith("}")) continue;
|
|
762
|
+
const extended = EXTENSION_DECL.exec(rest);
|
|
763
|
+
if (extended) {
|
|
764
|
+
const lines = source.lastIndexOf("\n", source.lastIndexOf("\n", at - 1) - 1) + 1;
|
|
765
|
+
pending = {
|
|
766
|
+
type: extended[1].split(".").pop(),
|
|
767
|
+
objcMembers: /@objcMembers\b/.test(masked.slice(lines, at))
|
|
768
|
+
};
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
for (const [type, members] of scanObjCExtensionMembers(source, tokens, records)) {
|
|
772
|
+
const into = index.get(type) ?? /* @__PURE__ */ new Set();
|
|
773
|
+
for (const member of members) into.add(member);
|
|
774
|
+
index.set(type, into);
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
return index;
|
|
778
|
+
}
|
|
779
|
+
function liftExtensionOverrides(source, extraObjCExtensions) {
|
|
614
780
|
const { tokens } = swiftCodeScan(source);
|
|
781
|
+
const masked = swiftCodeMask(source);
|
|
615
782
|
const stack = [];
|
|
616
783
|
let pending = null;
|
|
617
784
|
const classes = /* @__PURE__ */ new Map();
|
|
618
785
|
let declaredBase = null;
|
|
619
786
|
let declaredObjCMembers = false;
|
|
787
|
+
const extensions = [];
|
|
788
|
+
let declaredExtObjCMembers = false;
|
|
620
789
|
const lifted = [];
|
|
621
|
-
const
|
|
622
|
-
|
|
623
|
-
for (const at of tokens) {
|
|
624
|
-
if (at < open) continue;
|
|
625
|
-
if (source[at] === "{") depth++;
|
|
626
|
-
else if (source[at] === "}" && --depth === 0) return at + 1;
|
|
627
|
-
}
|
|
628
|
-
return source.length;
|
|
629
|
-
};
|
|
790
|
+
const overrides = [];
|
|
791
|
+
const closing = (open) => closingBrace(source, tokens, open);
|
|
630
792
|
for (const at of tokens) {
|
|
631
793
|
const rest = source.slice(at, at + 600);
|
|
632
794
|
if (rest.startsWith("{")) {
|
|
@@ -637,6 +799,12 @@ function liftExtensionOverrides(source) {
|
|
|
637
799
|
base: declaredBase,
|
|
638
800
|
objcMembers: declaredObjCMembers
|
|
639
801
|
});
|
|
802
|
+
if (frame.kind === "extension")
|
|
803
|
+
extensions.push({
|
|
804
|
+
type: frame.name,
|
|
805
|
+
open: at,
|
|
806
|
+
objcMembers: declaredExtObjCMembers
|
|
807
|
+
});
|
|
640
808
|
stack.push(frame);
|
|
641
809
|
pending = null;
|
|
642
810
|
continue;
|
|
@@ -656,12 +824,39 @@ function liftExtensionOverrides(source) {
|
|
|
656
824
|
const extended = EXTENSION_DECL.exec(rest);
|
|
657
825
|
if (extended) {
|
|
658
826
|
pending = { kind: "extension", name: extended[1].split(".").pop() };
|
|
827
|
+
const lines = source.lastIndexOf("\n", source.lastIndexOf("\n", at - 1) - 1) + 1;
|
|
828
|
+
declaredExtObjCMembers = /@objcMembers\b/.test(masked.slice(lines, at));
|
|
659
829
|
continue;
|
|
660
830
|
}
|
|
661
831
|
const top = stack.at(-1);
|
|
662
|
-
if (!rest.startsWith("override") ||
|
|
832
|
+
if (!rest.startsWith("override") || pending) continue;
|
|
663
833
|
const line = source.slice(source.lastIndexOf("\n", at - 1) + 1, at);
|
|
664
834
|
const modifiers = (` ${line} `.match(MODIFIERS) ?? []).map((word) => word.trim());
|
|
835
|
+
if (top?.kind === "class") {
|
|
836
|
+
let member;
|
|
837
|
+
let nameAt = 0;
|
|
838
|
+
const direct = OVERRIDE_FUNC.exec(rest);
|
|
839
|
+
if (direct) {
|
|
840
|
+
member = direct[2];
|
|
841
|
+
nameAt = at + rest.indexOf(
|
|
842
|
+
member,
|
|
843
|
+
rest.indexOf("func", "override".length + direct[1].length) + 4
|
|
844
|
+
);
|
|
845
|
+
} else {
|
|
846
|
+
const property2 = OVERRIDE_VAR.exec(rest);
|
|
847
|
+
if (property2) {
|
|
848
|
+
const open = at + property2[0].length - 1;
|
|
849
|
+
if (!/\b(?:set|willSet|didSet)\b/.test(source.slice(open, closing(open)))) {
|
|
850
|
+
member = property2[2];
|
|
851
|
+
nameAt = at + rest.indexOf(member, rest.indexOf("var"));
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
if (member !== void 0 && !modifiers.includes("private") && !modifiers.includes("fileprivate"))
|
|
856
|
+
overrides.push({ type: top.name, member, at, nameAt });
|
|
857
|
+
continue;
|
|
858
|
+
}
|
|
859
|
+
if (top?.kind !== "extension") continue;
|
|
665
860
|
const func = OVERRIDE_FUNC.exec(rest);
|
|
666
861
|
if (func) {
|
|
667
862
|
const name = func[2];
|
|
@@ -679,20 +874,18 @@ function liftExtensionOverrides(source) {
|
|
|
679
874
|
if (args === null) continue;
|
|
680
875
|
const call = (clause.includes("->") ? "return " : "") + (/\b(?:throws|rethrows)\b/.test(clause) ? "try " : "") + (/\basync\b/.test(clause) ? "await " : "") + `__peach_ext_${name}(${args})`;
|
|
681
876
|
const signature = `func ${name}${func[3] ?? ""}${source.slice(open, close + 1)}${clause ? ` ${clause}` : ""}`;
|
|
877
|
+
const nameAt = at + rest.indexOf(name, rest.indexOf("func", "override".length + func[1].length) + 4);
|
|
682
878
|
lifted.push({
|
|
683
879
|
type: top.name,
|
|
684
880
|
member: name,
|
|
685
|
-
|
|
881
|
+
at,
|
|
882
|
+
modifiers,
|
|
883
|
+
decl: signature,
|
|
884
|
+
forward: `{ ${call} };`,
|
|
885
|
+
nameAt,
|
|
686
886
|
edits: [
|
|
687
887
|
[at, "override".length, " ".repeat("override".length)],
|
|
688
|
-
[
|
|
689
|
-
at + rest.indexOf(
|
|
690
|
-
name,
|
|
691
|
-
rest.indexOf("func", "override".length + func[1].length) + 4
|
|
692
|
-
),
|
|
693
|
-
0,
|
|
694
|
-
"__peach_ext_"
|
|
695
|
-
]
|
|
888
|
+
[nameAt, 0, "__peach_ext_"]
|
|
696
889
|
]
|
|
697
890
|
});
|
|
698
891
|
continue;
|
|
@@ -702,40 +895,77 @@ function liftExtensionOverrides(source) {
|
|
|
702
895
|
const open = at + property[0].length - 1;
|
|
703
896
|
if (/\b(?:set|willSet|didSet)\b/.test(source.slice(open, closing(open)))) continue;
|
|
704
897
|
const name = property[2];
|
|
898
|
+
const nameAt = at + rest.indexOf(name, rest.indexOf("var"));
|
|
705
899
|
lifted.push({
|
|
706
900
|
type: top.name,
|
|
707
901
|
member: name,
|
|
708
|
-
|
|
902
|
+
at,
|
|
903
|
+
modifiers,
|
|
904
|
+
decl: `var ${name}: ${property[3].trim()}`,
|
|
905
|
+
forward: `{ __peach_ext_${name} };`,
|
|
906
|
+
nameAt,
|
|
709
907
|
edits: [
|
|
710
908
|
[at, "override".length, " ".repeat("override".length)],
|
|
711
|
-
[
|
|
909
|
+
[nameAt, 0, "__peach_ext_"]
|
|
712
910
|
]
|
|
713
911
|
});
|
|
714
912
|
}
|
|
715
913
|
}
|
|
716
|
-
const
|
|
914
|
+
const extIndex = /* @__PURE__ */ new Map();
|
|
915
|
+
if (extraObjCExtensions)
|
|
916
|
+
for (const [type, members] of extraObjCExtensions)
|
|
917
|
+
extIndex.set(type, new Set(members));
|
|
918
|
+
for (const [type, members] of scanObjCExtensionMembers(source, tokens, extensions)) {
|
|
919
|
+
const into = extIndex.get(type) ?? /* @__PURE__ */ new Set();
|
|
920
|
+
for (const member of members) into.add(member);
|
|
921
|
+
extIndex.set(type, into);
|
|
922
|
+
}
|
|
923
|
+
const overrideKind = (type, member) => {
|
|
717
924
|
let base = classes.get(type)?.base ?? null;
|
|
718
925
|
while (base !== null) {
|
|
719
|
-
if (APPLE_CLASS.test(base)) return true;
|
|
720
926
|
const declaredClass = classes.get(base);
|
|
721
|
-
if (
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
927
|
+
if (declaredClass) {
|
|
928
|
+
const body = source.slice(declaredClass.brace, closing(declaredClass.brace));
|
|
929
|
+
const found = new RegExp(`\\b(?:func|var)\\s+${member}\\b`).exec(body);
|
|
930
|
+
if (found) {
|
|
931
|
+
const line = body.slice(body.lastIndexOf("\n", found.index) + 1, found.index);
|
|
932
|
+
return declaredClass.objcMembers || /@objc\b/.test(line) ? "objc" : "plain";
|
|
933
|
+
}
|
|
934
|
+
if (extIndex.get(base)?.has(member)) return "ext";
|
|
935
|
+
base = declaredClass.base;
|
|
936
|
+
} else if (extIndex.get(base)?.has(member)) return "ext";
|
|
937
|
+
else if (APPLE_CLASS.test(base)) return "apple";
|
|
938
|
+
else return "unknown";
|
|
729
939
|
}
|
|
730
|
-
return
|
|
940
|
+
return "unknown";
|
|
731
941
|
};
|
|
942
|
+
const rename = (at, nameAt) => [
|
|
943
|
+
[at, "override".length, " ".repeat("override".length)],
|
|
944
|
+
[nameAt, 0, "__peach_ovr_"]
|
|
945
|
+
];
|
|
732
946
|
const edits = [];
|
|
733
947
|
const stubs = /* @__PURE__ */ new Map();
|
|
734
948
|
for (const entry of lifted) {
|
|
735
949
|
const brace = classes.get(entry.type)?.brace;
|
|
736
|
-
if (brace === void 0
|
|
950
|
+
if (brace === void 0) continue;
|
|
951
|
+
const kind = overrideKind(entry.type, entry.member);
|
|
952
|
+
if (kind !== "apple" && kind !== "objc" && kind !== "ext") continue;
|
|
953
|
+
if (kind === "ext" && (entry.modifiers.includes("private") || entry.modifiers.includes("fileprivate")))
|
|
954
|
+
continue;
|
|
955
|
+
if (kind === "ext") {
|
|
956
|
+
edits.push(...rename(entry.at, entry.nameAt));
|
|
957
|
+
continue;
|
|
958
|
+
}
|
|
737
959
|
edits.push(...entry.edits);
|
|
738
|
-
|
|
960
|
+
const head = [...entry.modifiers, "override"].filter((word) => word !== "").join(" ");
|
|
961
|
+
stubs.set(brace, [
|
|
962
|
+
...stubs.get(brace) ?? [],
|
|
963
|
+
`${head} ${entry.decl} ${entry.forward}`
|
|
964
|
+
]);
|
|
965
|
+
}
|
|
966
|
+
for (const candidate of overrides) {
|
|
967
|
+
if (overrideKind(candidate.type, candidate.member) !== "ext") continue;
|
|
968
|
+
edits.push(...rename(candidate.at, candidate.nameAt));
|
|
739
969
|
}
|
|
740
970
|
for (const [brace, list] of stubs) edits.push([brace + 1, 0, ` ${list.join(" ")}`]);
|
|
741
971
|
let out = source;
|
|
@@ -917,8 +1147,8 @@ function swiftCodeMask(source) {
|
|
|
917
1147
|
scanCode(0, false);
|
|
918
1148
|
return chars.join("");
|
|
919
1149
|
}
|
|
920
|
-
function swiftSourceAsIOS(original) {
|
|
921
|
-
const source = liftExtensionOverrides(original);
|
|
1150
|
+
function swiftSourceAsIOS(original, extraObjCExtensions) {
|
|
1151
|
+
const source = liftExtensionOverrides(original, extraObjCExtensions);
|
|
922
1152
|
const { lineStarts, tokens } = swiftCodeScan(source);
|
|
923
1153
|
let offset = 0;
|
|
924
1154
|
const conditioned = source.split("\n").map((line) => {
|
|
@@ -1087,9 +1317,22 @@ function swiftCodeScan(source) {
|
|
|
1087
1317
|
}
|
|
1088
1318
|
return { lineStarts: starts, tokens };
|
|
1089
1319
|
}
|
|
1090
|
-
var compiledSource = (file, contents) => file.endsWith(".swift") ? swiftSourceAsIOS(contents) : contents;
|
|
1320
|
+
var compiledSource = (file, contents, extraObjCExtensions) => file.endsWith(".swift") ? swiftSourceAsIOS(contents, extraObjCExtensions) : contents;
|
|
1091
1321
|
function prepareSwiftDependency(source, destination) {
|
|
1092
1322
|
(0, import_node_fs2.rmSync)(destination, { recursive: true, force: true });
|
|
1323
|
+
const origins = [];
|
|
1324
|
+
const gather = (from, root) => {
|
|
1325
|
+
for (const entry of (0, import_node_fs2.readdirSync)(from, { withFileTypes: true })) {
|
|
1326
|
+
if (entry.name === ".git" || entry.name === ".build" || entry.name === ".swiftpm")
|
|
1327
|
+
continue;
|
|
1328
|
+
const file = import_node_path2.default.join(from, entry.name);
|
|
1329
|
+
if (entry.isDirectory()) gather(file, false);
|
|
1330
|
+
else if (entry.isFile() && entry.name.endsWith(".swift") && !(root && /^Package(@swift-[\d.]+)?\.swift$/.test(entry.name)))
|
|
1331
|
+
origins.push((0, import_node_fs2.readFileSync)(file, "utf8"));
|
|
1332
|
+
}
|
|
1333
|
+
};
|
|
1334
|
+
gather(source, true);
|
|
1335
|
+
const objcExtensions = objcExtensionMemberIndex(origins);
|
|
1093
1336
|
const copy = (from, to, root) => {
|
|
1094
1337
|
(0, import_node_fs2.mkdirSync)(to, { recursive: true });
|
|
1095
1338
|
for (const entry of (0, import_node_fs2.readdirSync)(from, { withFileTypes: true })) {
|
|
@@ -1099,7 +1342,10 @@ function prepareSwiftDependency(source, destination) {
|
|
|
1099
1342
|
const target = import_node_path2.default.join(to, entry.name);
|
|
1100
1343
|
if (entry.isDirectory()) copy(file, target, false);
|
|
1101
1344
|
else if (entry.isFile() && entry.name.endsWith(".swift") && !(root && /^Package(@swift-[\d.]+)?\.swift$/.test(entry.name)))
|
|
1102
|
-
(0, import_node_fs2.writeFileSync)(
|
|
1345
|
+
(0, import_node_fs2.writeFileSync)(
|
|
1346
|
+
target,
|
|
1347
|
+
compiledSource(file, (0, import_node_fs2.readFileSync)(file, "utf8"), objcExtensions)
|
|
1348
|
+
);
|
|
1103
1349
|
else (0, import_node_fs2.cpSync)(file, target, { verbatimSymlinks: true });
|
|
1104
1350
|
}
|
|
1105
1351
|
};
|
|
@@ -1137,10 +1383,16 @@ function writeSwiftProject(layout, input, moduleRoot) {
|
|
|
1137
1383
|
// sootsim-swift files ${modulePlan.digest("hex").slice(0, 16)}
|
|
1138
1384
|
// resource accessors ${resourcePlan}
|
|
1139
1385
|
`;
|
|
1386
|
+
const objcExtensions = objcExtensionMemberIndex(
|
|
1387
|
+
Object.entries(input.files).filter(([file]) => file.endsWith(".swift")).map(([, contents]) => contents)
|
|
1388
|
+
);
|
|
1140
1389
|
if (targets.length === 0) {
|
|
1141
1390
|
for (const [file, contents] of Object.entries(input.files)) {
|
|
1142
1391
|
if (file === "Package.swift") continue;
|
|
1143
|
-
files.set(
|
|
1392
|
+
files.set(
|
|
1393
|
+
import_node_path2.default.join(layout.sources, file),
|
|
1394
|
+
compiledSource(file, contents, objcExtensions)
|
|
1395
|
+
);
|
|
1144
1396
|
}
|
|
1145
1397
|
let manifest = (0, import_node_fs2.readFileSync)(
|
|
1146
1398
|
import_node_path2.default.join(moduleRoot, "scripts/contrast-app-Package.swift"),
|
|
@@ -1186,7 +1438,7 @@ function writeSwiftProject(layout, input, moduleRoot) {
|
|
|
1186
1438
|
const base = layout.multi ? layout.root : layout.sources;
|
|
1187
1439
|
for (const [file, contents] of Object.entries(input.files)) {
|
|
1188
1440
|
if (file === "Package.swift") continue;
|
|
1189
|
-
files.set(import_node_path2.default.join(base, file), compiledSource(file, contents));
|
|
1441
|
+
files.set(import_node_path2.default.join(base, file), compiledSource(file, contents, objcExtensions));
|
|
1190
1442
|
}
|
|
1191
1443
|
files.set(
|
|
1192
1444
|
import_node_path2.default.join(layout.root, "Package.swift"),
|
|
@@ -1332,13 +1584,18 @@ function compileSwiftProjectUnit(input, options) {
|
|
|
1332
1584
|
compileTargets,
|
|
1333
1585
|
emitSwiftPackageManifest,
|
|
1334
1586
|
lowerAnyObjectDoubleValue,
|
|
1587
|
+
missingSwiftModules,
|
|
1588
|
+
objcExtensionMemberIndex,
|
|
1335
1589
|
prepareSwiftDependency,
|
|
1336
1590
|
swiftArtifactHash,
|
|
1591
|
+
swiftAvailableModules,
|
|
1337
1592
|
swiftDistributionAt,
|
|
1338
1593
|
swiftIcuAsset,
|
|
1594
|
+
swiftImportNames,
|
|
1339
1595
|
swiftModuleDigest,
|
|
1340
1596
|
swiftModuleInputFiles,
|
|
1341
1597
|
swiftModuleSdk,
|
|
1598
|
+
swiftPeachModules,
|
|
1342
1599
|
swiftSourceAsIOS,
|
|
1343
1600
|
swiftTargetDependencies,
|
|
1344
1601
|
syncSwiftTree,
|