peachsim 0.1.687 → 0.1.689
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/cloud-client.ts +3 -3
- package/cli/command-registry.ts +2 -0
- package/cli/commands/control.ts +1 -0
- package/cli/commands/debug.ts +10 -33
- package/cli/commands/do-chain.ts +56 -6
- package/cli/commands/inspect/core.ts +2 -0
- package/cli/commands/inspect/list.ts +2 -1
- package/cli/commands/inspect/settling.ts +17 -3
- package/cli/commands/inspect/shared.ts +2 -0
- package/cli/commands/inspect/wait-idle.ts +2 -2
- package/cli/commands/inspect/wait-ready.ts +3 -3
- package/cli/commands/inspect.ts +33 -7
- package/cli/commands/location.ts +164 -0
- package/cli/commands/platform.ts +1 -1
- package/cli/drivers/playwright-sim-host.ts +46 -25
- package/cli/main.ts +6 -0
- package/detox/index.ts +13 -8
- 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 +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 +4 -3
- package/dist-lib/bridge-contract-input.cjs +12 -1
- package/dist-lib/bridge-contract-input.mjs +12 -1
- package/dist-lib/bridge-contract.cjs +4 -3
- package/dist-lib/bridge-contract.mjs +4 -3
- package/dist-lib/capture-contract.cjs +1 -1
- package/dist-lib/capture-contract.mjs +1 -1
- package/dist-lib/cli-constants.cjs +1 -1
- package/dist-lib/cloud-contract.cjs +2 -1
- package/dist-lib/cloud-contract.mjs +2 -1
- package/dist-lib/cloud-test-args.cjs +1 -1
- package/dist-lib/cloud-test-args.mjs +1 -1
- package/dist-lib/cloud.cjs +2 -1
- package/dist-lib/cloud.mjs +2 -1
- package/dist-lib/config.cjs +1 -1
- package/dist-lib/detox/index.cjs +1197 -65
- package/dist-lib/dev-bundle-resolution.cjs +1 -1
- package/dist-lib/home-paths.cjs +1 -1
- package/dist-lib/host/bridge-host.cjs +362 -108
- package/dist-lib/host/fetch-proxy-handler.cjs +50 -40
- package/dist-lib/host/fetch-proxy-overrides.cjs +50 -6
- package/dist-lib/host/fetch-proxy-overrides.mjs +48 -5
- package/dist-lib/host/replacement-module-handler.cjs +1 -1
- package/dist-lib/host/websocket-proxy.cjs +1 -1
- package/dist-lib/index.cjs +29 -11
- 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 +89 -13
- 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 +5 -3
- package/dist-lib/native-app-identity.cjs +8 -3
- package/dist-lib/native-app-identity.mjs +8 -3
- 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 +2 -2
- package/dist-lib/sdk.cjs +21 -6
- package/dist-lib/sdk.mjs +21 -6
- package/dist-lib/skills.cjs +401 -130
- package/dist-lib/swift-compile.cjs +277 -22
- package/dist-lib/swift-compile.mjs +275 -22
- package/dist-lib/swift-package.cjs +1 -1
- package/dist-lib/swift-package.mjs +1 -1
- package/dist-lib/swift-submit.cjs +2 -2
- package/dist-lib/swift-submit.mjs +2 -2
- package/dist-lib/swift-toolchain.cjs +10 -10
- package/dist-lib/swift.cjs +1 -1
- package/dist-lib/vite-swift.cjs +280 -44
- package/dist-lib/vite.cjs +1 -1
- package/kotlin/AppSources/android/content/res/Configuration.kt +2 -0
- package/kotlin/AppSources/android/content/res/Resources.kt +6 -3
- package/kotlin/AppSources/android/util/DisplayMetrics.kt +12 -0
- package/kotlin/AppSources/androidx/compose/ui/res/PainterResources.kt +70 -0
- package/kotlin/AppSources/dev/peach/app/PeachApp.kt +12 -10
- package/kotlin/AppSources/dev/peach/app/PeachDrawable.kt +95 -0
- package/kotlin/fixtures/kotlin-app-variants/Bitmaps.kt +50 -0
- package/kotlin/fixtures/kotlin-app-variants/Drawables.kt +53 -0
- package/package.json +2 -2
- package/scripts/dev-server-scanner.ts +3 -1
- package/skills/contrast/SKILL.md +1 -0
- package/src/android-drawables.ts +315 -0
- package/src/android-theme.ts +9 -0
- package/src/bridge-constants.ts +3 -2
- package/src/bridge-contract-input.ts +11 -0
- package/src/bridge-contract.ts +45 -3
- package/src/cloud-contract.ts +1 -0
- package/src/host/fetch-proxy-handler.ts +13 -49
- package/src/host/fetch-proxy-overrides.ts +69 -12
- package/src/kotlin-app.ts +6 -0
- package/src/kotlin-host.ts +103 -15
- package/src/native-app-identity.ts +16 -3
- package/src/swift-compile.ts +366 -24
- package/src/swift-distribution-contract.ts +11 -4
- package/src/swift-distribution.lock.json +11 -9
- package/src/swift-distribution.ts +4 -4
- package/src/swift-icu.ts +8 -11
- package/src/swift-submit.ts +13 -1
- package/src/swift-toolchain.ts +17 -9
- package/src/vite-plugin.ts +86 -34
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! rnx v0.1.
|
|
1
|
+
/*! rnx v0.1.689 | (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;
|
|
@@ -37,12 +37,15 @@ __export(swift_compile_exports, {
|
|
|
37
37
|
compileSwiftProjectUnit: () => compileSwiftProjectUnit,
|
|
38
38
|
compileTargets: () => compileTargets,
|
|
39
39
|
emitSwiftPackageManifest: () => emitSwiftPackageManifest,
|
|
40
|
+
prepareSwiftDependency: () => prepareSwiftDependency,
|
|
40
41
|
swiftArtifactHash: () => swiftArtifactHash,
|
|
41
42
|
swiftDistributionAt: () => swiftDistributionAt,
|
|
42
43
|
swiftIcuAsset: () => swiftIcuAsset,
|
|
43
44
|
swiftModuleDigest: () => swiftModuleDigest,
|
|
44
45
|
swiftModuleInputFiles: () => swiftModuleInputFiles,
|
|
46
|
+
swiftModuleSdk: () => swiftModuleSdk,
|
|
45
47
|
swiftSourceAsIOS: () => swiftSourceAsIOS,
|
|
48
|
+
swiftTargetDependencies: () => swiftTargetDependencies,
|
|
46
49
|
withNativeSourceGlue: () => withNativeSourceGlue,
|
|
47
50
|
writeSwiftProject: () => writeSwiftProject
|
|
48
51
|
});
|
|
@@ -68,7 +71,7 @@ var SWIFT_DISTRIBUTION_HOSTS = [
|
|
|
68
71
|
];
|
|
69
72
|
var isStrings = (value) => Array.isArray(value) && value.every((item) => typeof item === "string");
|
|
70
73
|
function parseSwiftDistributionManifest(value) {
|
|
71
|
-
if (!isRecord(value) || typeof value.id !== "string" || typeof value.release !== "string" || typeof value.wasmSdkChecksum !== "string" || !isStrings(value.modules) || !isStrings(value.objects) || !isStrings(value.link) || !isRecord(value.files) || !Object.values(value.files).every((sha) => typeof sha === "string") || typeof value.host !== "string" || !isStrings(value.plugins)) {
|
|
74
|
+
if (!isRecord(value) || typeof value.id !== "string" || typeof value.release !== "string" || typeof value.wasmSdkId !== "string" || typeof value.wasmSdkUrl !== "string" || typeof value.wasmSdkChecksum !== "string" || !isStrings(value.modules) || !isStrings(value.objects) || !isStrings(value.link) || !isRecord(value.files) || !Object.values(value.files).every((sha) => typeof sha === "string") || typeof value.host !== "string" || !isStrings(value.plugins)) {
|
|
72
75
|
throw new Error(`invalid Swift distribution ${SWIFT_DISTRIBUTION_MANIFEST}`);
|
|
73
76
|
}
|
|
74
77
|
const host2 = SWIFT_DISTRIBUTION_HOSTS.find((candidate) => candidate === value.host);
|
|
@@ -76,6 +79,8 @@ function parseSwiftDistributionManifest(value) {
|
|
|
76
79
|
return {
|
|
77
80
|
id: value.id,
|
|
78
81
|
release: value.release,
|
|
82
|
+
wasmSdkId: value.wasmSdkId,
|
|
83
|
+
wasmSdkUrl: value.wasmSdkUrl,
|
|
79
84
|
wasmSdkChecksum: value.wasmSdkChecksum,
|
|
80
85
|
modules: value.modules,
|
|
81
86
|
objects: value.objects,
|
|
@@ -110,25 +115,25 @@ function memo(cache, key, load2) {
|
|
|
110
115
|
}
|
|
111
116
|
return pending;
|
|
112
117
|
}
|
|
113
|
-
function swiftIcuData(toolchainBin,
|
|
114
|
-
return memo(raw, `${toolchainBin}\0${
|
|
118
|
+
function swiftIcuData(toolchainBin, sdk) {
|
|
119
|
+
return memo(raw, `${toolchainBin}\0${sdk}`, () => load(toolchainBin, sdk));
|
|
115
120
|
}
|
|
116
|
-
function swiftIcuAsset(toolchainBin,
|
|
117
|
-
return memo(assets, `${toolchainBin}\0${
|
|
118
|
-
const zipped = await deflate(await swiftIcuData(toolchainBin,
|
|
121
|
+
function swiftIcuAsset(toolchainBin, sdk) {
|
|
122
|
+
return memo(assets, `${toolchainBin}\0${sdk}`, async () => {
|
|
123
|
+
const zipped = await deflate(await swiftIcuData(toolchainBin, sdk));
|
|
119
124
|
return { sha256: (0, import_node_crypto.createHash)("sha256").update(zipped).digest("hex"), gzip: zipped };
|
|
120
125
|
});
|
|
121
126
|
}
|
|
122
|
-
async function load(toolchainBin,
|
|
127
|
+
async function load(toolchainBin, sdk) {
|
|
123
128
|
const { stdout } = await run(import_node_path.default.join(toolchainBin, "swift"), [
|
|
124
129
|
"sdk",
|
|
125
130
|
"configure",
|
|
126
131
|
"--show-configuration",
|
|
127
|
-
|
|
132
|
+
sdk,
|
|
128
133
|
"wasm32-unknown-wasip1"
|
|
129
134
|
]);
|
|
130
135
|
const resources = /^swiftStaticResourcesPath: (.+)$/m.exec(stdout)?.[1]?.trim();
|
|
131
|
-
if (!resources) throw new Error(`swift-icu: ${
|
|
136
|
+
if (!resources) throw new Error(`swift-icu: ${sdk} names no static resources`);
|
|
132
137
|
return Buffer.from(
|
|
133
138
|
icuSegment(archiveMember((0, import_node_fs.readFileSync)(import_node_path.default.join(resources, ARCHIVE)), MEMBER))
|
|
134
139
|
);
|
|
@@ -257,6 +262,16 @@ function swiftDistributionAt(root) {
|
|
|
257
262
|
if (!(0, import_node_fs2.existsSync)(file)) return null;
|
|
258
263
|
return parseSwiftDistributionManifest(JSON.parse((0, import_node_fs2.readFileSync)(file, "utf8")));
|
|
259
264
|
}
|
|
265
|
+
function swiftModuleSdk(root) {
|
|
266
|
+
const pin = swiftDistributionAt(root) ?? JSON.parse((0, import_node_fs2.readFileSync)(import_node_path2.default.join(root, "toolchain.json"), "utf8"));
|
|
267
|
+
if (!pin || typeof pin !== "object" || typeof Reflect.get(pin, "wasmSdkId") !== "string" || typeof Reflect.get(pin, "wasmSdkUrl") !== "string" || typeof Reflect.get(pin, "wasmSdkChecksum") !== "string")
|
|
268
|
+
throw new Error(`${root} pins no wasm SDK id, url and checksum`);
|
|
269
|
+
return {
|
|
270
|
+
wasmSdkId: String(Reflect.get(pin, "wasmSdkId")),
|
|
271
|
+
wasmSdkUrl: String(Reflect.get(pin, "wasmSdkUrl")),
|
|
272
|
+
wasmSdkChecksum: String(Reflect.get(pin, "wasmSdkChecksum"))
|
|
273
|
+
};
|
|
274
|
+
}
|
|
260
275
|
function swiftModuleInputFiles(root) {
|
|
261
276
|
if (swiftDistributionAt(root)) return [SWIFT_DISTRIBUTION_MANIFEST];
|
|
262
277
|
const files = [
|
|
@@ -268,7 +283,7 @@ function swiftModuleInputFiles(root) {
|
|
|
268
283
|
for (const entry of (0, import_node_fs2.readdirSync)(import_node_path2.default.join(root, dir), { withFileTypes: true })) {
|
|
269
284
|
const relative = `${dir}/${entry.name}`;
|
|
270
285
|
if (entry.isDirectory()) walk(relative);
|
|
271
|
-
else if (/\.(swift|c|h)$/.test(entry.name)) files.push(relative);
|
|
286
|
+
else if (/\.(swift|c|cpp|h)$/.test(entry.name)) files.push(relative);
|
|
272
287
|
}
|
|
273
288
|
};
|
|
274
289
|
walk("Sources");
|
|
@@ -351,7 +366,17 @@ function withNativeSourceGlue(input, glue) {
|
|
|
351
366
|
oneModule: true
|
|
352
367
|
};
|
|
353
368
|
}
|
|
354
|
-
var
|
|
369
|
+
var OPTIONAL_FRAMEWORK_DEPENDENCIES = {
|
|
370
|
+
Accelerate: [],
|
|
371
|
+
CryptoKit: [],
|
|
372
|
+
Security: [],
|
|
373
|
+
Statsig: [],
|
|
374
|
+
DatadogCore: [],
|
|
375
|
+
DatadogLogs: ["DatadogCore"],
|
|
376
|
+
DatadogRUM: ["DatadogCore"],
|
|
377
|
+
DatadogTrace: ["DatadogCore"]
|
|
378
|
+
};
|
|
379
|
+
var OPTIONAL_FRAMEWORKS = new Set(Object.keys(OPTIONAL_FRAMEWORK_DEPENDENCIES));
|
|
355
380
|
function swiftTargetDependencies(files, targets) {
|
|
356
381
|
const names = /* @__PURE__ */ new Set([...OPTIONAL_FRAMEWORKS, ...targets.map((target) => target.name)]);
|
|
357
382
|
const siblings = /* @__PURE__ */ new Map();
|
|
@@ -381,12 +406,12 @@ var importsSpriteKit = (files) => Object.entries(files).some(
|
|
|
381
406
|
contents
|
|
382
407
|
)
|
|
383
408
|
);
|
|
384
|
-
var
|
|
409
|
+
var FOUNDATION_IMPLICIT_FLAGS = ', "-Xfrontend", "-import-module", "-Xfrontend", "PeachObjC", "-Xfrontend", "-import-module", "-Xfrontend", "Dispatch", "-Xfrontend", "-import-module", "-Xfrontend", "FoundationNetworking"';
|
|
385
410
|
var ONE_IMPLICIT_FLAGS = ', "-Xfrontend", "-import-module", "-Xfrontend", "One"';
|
|
386
|
-
var MULTI_MANIFEST_VERSION =
|
|
411
|
+
var MULTI_MANIFEST_VERSION = 10;
|
|
387
412
|
function swiftArtifactHash(input, release, moduleRoot) {
|
|
388
413
|
const hash = (0, import_node_crypto2.createHash)("sha256");
|
|
389
|
-
hash.update(`swift-compile/
|
|
414
|
+
hash.update(`swift-compile/v12
|
|
390
415
|
${release}
|
|
391
416
|
`);
|
|
392
417
|
if (input.oneModule) hash.update("one-module\n");
|
|
@@ -428,7 +453,7 @@ function emitSwiftPackageManifest(args) {
|
|
|
428
453
|
const reachedFrameworks = new Set(
|
|
429
454
|
[...siblings.values()].flat().filter(
|
|
430
455
|
(name) => OPTIONAL_FRAMEWORKS.has(name) && !targets.some((target) => target.name === name)
|
|
431
|
-
)
|
|
456
|
+
).flatMap((name) => [name, ...OPTIONAL_FRAMEWORK_DEPENDENCIES[name] ?? []])
|
|
432
457
|
);
|
|
433
458
|
const distributionObjects = distribution?.objects.filter(
|
|
434
459
|
(object) => [...OPTIONAL_FRAMEWORKS].every(
|
|
@@ -440,7 +465,7 @@ function emitSwiftPackageManifest(args) {
|
|
|
440
465
|
const stanza = (target) => {
|
|
441
466
|
const isolation = target.mainActorIsolation ? " .defaultIsolation(MainActor.self)," : "";
|
|
442
467
|
const imports = distribution ? `, "-I", ${JSON.stringify(import_node_path2.default.join(moduleRoot, "modules"))}` : "";
|
|
443
|
-
const swiftSettings = `swiftSettings: [.swiftLanguageMode(.v${target.languageMode}),${isolation} .unsafeFlags(["-Osize"${
|
|
468
|
+
const swiftSettings = `swiftSettings: [.swiftLanguageMode(.v${target.languageMode}),${isolation} .unsafeFlags(["-Osize"${FOUNDATION_IMPLICIT_FLAGS}${oneModule ? ONE_IMPLICIT_FLAGS : ""}${imports}])]`;
|
|
444
469
|
const deps = [
|
|
445
470
|
...distribution ? [] : [
|
|
446
471
|
'.product(name: "SwiftUI", package: "sootsim-swift")',
|
|
@@ -510,8 +535,185 @@ var DIRECTIVE = /^[ \t]*#(?:if|elseif)\b/;
|
|
|
510
535
|
var OS_IOS = /\bos\(\s*iOS\s*\)/g;
|
|
511
536
|
var OBJC_ATTRIBUTE = /^@(?:objcMembers\b|objc\b(?:(\s*)\(([^()]*)\))?|IBAction\b)/;
|
|
512
537
|
var SELECTOR = /^#selector\b/;
|
|
538
|
+
var TYPE_AFTER_ATTRIBUTE = /^(?:\s+|\/\/[^\n]*|\/\*[\s\S]*?\*\/|@\w+(?:\([^()]*\))?|\b(?:public|open|final|internal|fileprivate|private|package|nonisolated|indirect)\b)*\b(?:class(?!\s+(?:func|var|let|subscript)\b)|struct|enum|protocol|extension|actor)\b/;
|
|
513
539
|
var DELEGATE_CLASS = /^class\s+[A-Za-z_]\w*\s*(?:<[^>{]*>)?\s*:[^{]*\b(?:UIApplicationDelegate|UISceneDelegate|UIWindowSceneDelegate)\b[^{]*\{/;
|
|
514
|
-
|
|
540
|
+
var REUSABLE_INIT = /^override(?=\s+init\s*\(\s*(?:style\s*:[^,)]*,\s*reuseIdentifier|reuseIdentifier)\s*:)/;
|
|
541
|
+
var REUSABLE_VIEW_BASES = [
|
|
542
|
+
"UICollectionReusableView",
|
|
543
|
+
"UICollectionViewCell",
|
|
544
|
+
"UICollectionViewListCell"
|
|
545
|
+
];
|
|
546
|
+
var CLASS_BASE = /^class\s+([A-Za-z_]\w*)\s*(?:<[^>{]*>)?\s*:\s*([A-Za-z_][\w.]*)[^{]*\{/;
|
|
547
|
+
var FRAME_INIT = /^override(?=\s+(?:(?:public|open|internal)\s+)?init\s*\(\s*frame\s*:)/;
|
|
548
|
+
var APPLE_CLASS = /^(?:UI|NS|CA|SK|WK|MK|AV|PK|CL|GK|PH|SF|AS|QL)[A-Z]/;
|
|
549
|
+
var EXTENSION_DECL = /^extension\s+([A-Za-z_][\w.]*)/;
|
|
550
|
+
var CLASS_DECL = /^class\s+(?!(?:func|var|let|subscript)\b)([A-Za-z_]\w*)/;
|
|
551
|
+
var MODIFIERS = /(?:^|\s)(public|open|internal|fileprivate|private|final|nonisolated|@MainActor)(?=\s)/g;
|
|
552
|
+
var OVERRIDE_FUNC = /^override((?:\s+(?:public|open|internal|fileprivate|private|final|nonisolated|dynamic|@\w+))*)\s+func\s+([A-Za-z_]\w*)\s*(<[^>{}]*>)?\s*\(/;
|
|
553
|
+
var OVERRIDE_VAR = /^override((?:\s+(?:public|open|internal|fileprivate|private|final|nonisolated|dynamic|@\w+))*)\s+var\s+([A-Za-z_]\w*)\s*:\s*([^{=]+?)\s*\{/;
|
|
554
|
+
function splitTopLevel(text) {
|
|
555
|
+
const parts = [];
|
|
556
|
+
let depth = 0;
|
|
557
|
+
let start = 0;
|
|
558
|
+
for (let i = 0; i < text.length; i++) {
|
|
559
|
+
const char = text[i];
|
|
560
|
+
if (char === "(" || char === "[" || char === "<") depth++;
|
|
561
|
+
else if (char === ")" || char === "]" || char === ">" && text[i - 1] !== "-")
|
|
562
|
+
depth--;
|
|
563
|
+
else if (char === "," && depth === 0) {
|
|
564
|
+
parts.push(text.slice(start, i));
|
|
565
|
+
start = i + 1;
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
parts.push(text.slice(start));
|
|
569
|
+
return parts.map((part) => part.trim()).filter((part) => part !== "");
|
|
570
|
+
}
|
|
571
|
+
function forwardedArguments(parameters) {
|
|
572
|
+
const args = [];
|
|
573
|
+
for (const parameter of splitTopLevel(parameters)) {
|
|
574
|
+
const match = /^(?:([A-Za-z_]\w*)\s+)?([A-Za-z_]\w*)\s*:\s*([\s\S]*)$/.exec(parameter);
|
|
575
|
+
if (!match || match[3].includes("...")) return null;
|
|
576
|
+
const label = match[1] ?? match[2];
|
|
577
|
+
const value = (/^(?:@\w+\s+)*inout\b/.test(match[3]) ? "&" : "") + match[2];
|
|
578
|
+
args.push(label === "_" ? value : `${label}: ${value}`);
|
|
579
|
+
}
|
|
580
|
+
return args.join(", ");
|
|
581
|
+
}
|
|
582
|
+
function liftExtensionOverrides(source) {
|
|
583
|
+
const { tokens } = swiftCodeScan(source);
|
|
584
|
+
const stack = [];
|
|
585
|
+
let pending = null;
|
|
586
|
+
const classes = /* @__PURE__ */ new Map();
|
|
587
|
+
let declaredBase = null;
|
|
588
|
+
let declaredObjCMembers = false;
|
|
589
|
+
const lifted = [];
|
|
590
|
+
const closing = (open) => {
|
|
591
|
+
let depth = 0;
|
|
592
|
+
for (const at of tokens) {
|
|
593
|
+
if (at < open) continue;
|
|
594
|
+
if (source[at] === "{") depth++;
|
|
595
|
+
else if (source[at] === "}" && --depth === 0) return at + 1;
|
|
596
|
+
}
|
|
597
|
+
return source.length;
|
|
598
|
+
};
|
|
599
|
+
for (const at of tokens) {
|
|
600
|
+
const rest = source.slice(at, at + 600);
|
|
601
|
+
if (rest.startsWith("{")) {
|
|
602
|
+
const frame = pending ?? { kind: "other", name: "" };
|
|
603
|
+
if (frame.kind === "class" && !classes.has(frame.name))
|
|
604
|
+
classes.set(frame.name, {
|
|
605
|
+
brace: at,
|
|
606
|
+
base: declaredBase,
|
|
607
|
+
objcMembers: declaredObjCMembers
|
|
608
|
+
});
|
|
609
|
+
stack.push(frame);
|
|
610
|
+
pending = null;
|
|
611
|
+
continue;
|
|
612
|
+
}
|
|
613
|
+
if (rest.startsWith("}")) {
|
|
614
|
+
stack.pop();
|
|
615
|
+
continue;
|
|
616
|
+
}
|
|
617
|
+
const declared = CLASS_DECL.exec(rest);
|
|
618
|
+
if (declared) {
|
|
619
|
+
pending = { kind: "class", name: declared[1] };
|
|
620
|
+
declaredBase = CLASS_BASE.exec(rest)?.[2]?.split(".").pop() ?? null;
|
|
621
|
+
const lines = source.lastIndexOf("\n", source.lastIndexOf("\n", at - 1) - 1) + 1;
|
|
622
|
+
declaredObjCMembers = /@objcMembers\b/.test(source.slice(lines, at));
|
|
623
|
+
continue;
|
|
624
|
+
}
|
|
625
|
+
const extended = EXTENSION_DECL.exec(rest);
|
|
626
|
+
if (extended) {
|
|
627
|
+
pending = { kind: "extension", name: extended[1].split(".").pop() };
|
|
628
|
+
continue;
|
|
629
|
+
}
|
|
630
|
+
const top = stack.at(-1);
|
|
631
|
+
if (!rest.startsWith("override") || top?.kind !== "extension" || pending) continue;
|
|
632
|
+
const line = source.slice(source.lastIndexOf("\n", at - 1) + 1, at);
|
|
633
|
+
const modifiers = (` ${line} `.match(MODIFIERS) ?? []).map((word) => word.trim());
|
|
634
|
+
const func = OVERRIDE_FUNC.exec(rest);
|
|
635
|
+
if (func) {
|
|
636
|
+
const name = func[2];
|
|
637
|
+
const open = at + func[0].length - 1;
|
|
638
|
+
let depth = 0;
|
|
639
|
+
let close = open;
|
|
640
|
+
for (; close < source.length; close++) {
|
|
641
|
+
if (source[close] === "(") depth++;
|
|
642
|
+
else if (source[close] === ")" && --depth === 0) break;
|
|
643
|
+
}
|
|
644
|
+
const body = tokens.find((token) => token > close && source[token] === "{");
|
|
645
|
+
if (body === void 0) continue;
|
|
646
|
+
const clause = source.slice(close + 1, body).trim();
|
|
647
|
+
const args = forwardedArguments(source.slice(open + 1, close));
|
|
648
|
+
if (args === null) continue;
|
|
649
|
+
const call = (clause.includes("->") ? "return " : "") + (/\b(?:throws|rethrows)\b/.test(clause) ? "try " : "") + (/\basync\b/.test(clause) ? "await " : "") + `__peach_ext_${name}(${args})`;
|
|
650
|
+
const signature = `func ${name}${func[3] ?? ""}${source.slice(open, close + 1)}${clause ? ` ${clause}` : ""}`;
|
|
651
|
+
lifted.push({
|
|
652
|
+
type: top.name,
|
|
653
|
+
member: name,
|
|
654
|
+
stub: `${[...modifiers, "override"].join(" ")} ${signature} { ${call} };`,
|
|
655
|
+
edits: [
|
|
656
|
+
[at, "override".length, " ".repeat("override".length)],
|
|
657
|
+
[
|
|
658
|
+
at + rest.indexOf(
|
|
659
|
+
name,
|
|
660
|
+
rest.indexOf("func", "override".length + func[1].length) + 4
|
|
661
|
+
),
|
|
662
|
+
0,
|
|
663
|
+
"__peach_ext_"
|
|
664
|
+
]
|
|
665
|
+
]
|
|
666
|
+
});
|
|
667
|
+
continue;
|
|
668
|
+
}
|
|
669
|
+
const property = OVERRIDE_VAR.exec(rest);
|
|
670
|
+
if (property) {
|
|
671
|
+
const open = at + property[0].length - 1;
|
|
672
|
+
if (/\b(?:set|willSet|didSet)\b/.test(source.slice(open, closing(open)))) continue;
|
|
673
|
+
const name = property[2];
|
|
674
|
+
lifted.push({
|
|
675
|
+
type: top.name,
|
|
676
|
+
member: name,
|
|
677
|
+
stub: `${[...modifiers, "override"].join(" ")} var ${name}: ${property[3].trim()} { __peach_ext_${name} };`,
|
|
678
|
+
edits: [
|
|
679
|
+
[at, "override".length, " ".repeat("override".length)],
|
|
680
|
+
[at + rest.indexOf(name, rest.indexOf("var")), 0, "__peach_ext_"]
|
|
681
|
+
]
|
|
682
|
+
});
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
const overridesObjC = (type, member) => {
|
|
686
|
+
let base = classes.get(type)?.base ?? null;
|
|
687
|
+
while (base !== null) {
|
|
688
|
+
if (APPLE_CLASS.test(base)) return true;
|
|
689
|
+
const declaredClass = classes.get(base);
|
|
690
|
+
if (!declaredClass) return false;
|
|
691
|
+
const body = source.slice(declaredClass.brace, closing(declaredClass.brace));
|
|
692
|
+
const found = new RegExp(`\\b(?:func|var)\\s+${member}\\b`).exec(body);
|
|
693
|
+
if (found) {
|
|
694
|
+
const line = body.slice(body.lastIndexOf("\n", found.index) + 1, found.index);
|
|
695
|
+
return declaredClass.objcMembers || /@objc\b/.test(line);
|
|
696
|
+
}
|
|
697
|
+
base = declaredClass.base;
|
|
698
|
+
}
|
|
699
|
+
return false;
|
|
700
|
+
};
|
|
701
|
+
const edits = [];
|
|
702
|
+
const stubs = /* @__PURE__ */ new Map();
|
|
703
|
+
for (const entry of lifted) {
|
|
704
|
+
const brace = classes.get(entry.type)?.brace;
|
|
705
|
+
if (brace === void 0 || !overridesObjC(entry.type, entry.member)) continue;
|
|
706
|
+
edits.push(...entry.edits);
|
|
707
|
+
stubs.set(brace, [...stubs.get(brace) ?? [], entry.stub]);
|
|
708
|
+
}
|
|
709
|
+
for (const [brace, list] of stubs) edits.push([brace + 1, 0, ` ${list.join(" ")}`]);
|
|
710
|
+
let out = source;
|
|
711
|
+
for (const [at, remove, insert] of edits.sort((a, b) => b[0] - a[0]))
|
|
712
|
+
out = out.slice(0, at) + insert + out.slice(at + remove);
|
|
713
|
+
return out;
|
|
714
|
+
}
|
|
715
|
+
function swiftSourceAsIOS(original) {
|
|
716
|
+
const source = liftExtensionOverrides(original);
|
|
515
717
|
const { lineStarts, tokens } = swiftCodeScan(source);
|
|
516
718
|
let offset = 0;
|
|
517
719
|
const conditioned = source.split("\n").map((line) => {
|
|
@@ -522,8 +724,30 @@ function swiftSourceAsIOS(source) {
|
|
|
522
724
|
}).join("\n");
|
|
523
725
|
let out = "";
|
|
524
726
|
let copied = 0;
|
|
727
|
+
const reusableViews = new Set(REUSABLE_VIEW_BASES);
|
|
728
|
+
const reusableBodies = [];
|
|
729
|
+
let depth = 0;
|
|
730
|
+
let opensReusableBody = false;
|
|
525
731
|
for (const at of tokens) {
|
|
526
732
|
const rest = conditioned.slice(at, at + 400);
|
|
733
|
+
if (rest.startsWith("{")) {
|
|
734
|
+
depth++;
|
|
735
|
+
if (opensReusableBody) reusableBodies.push(depth);
|
|
736
|
+
opensReusableBody = false;
|
|
737
|
+
continue;
|
|
738
|
+
}
|
|
739
|
+
if (rest.startsWith("}")) {
|
|
740
|
+
if (reusableBodies.at(-1) === depth) reusableBodies.pop();
|
|
741
|
+
depth--;
|
|
742
|
+
continue;
|
|
743
|
+
}
|
|
744
|
+
if (rest.startsWith("override")) {
|
|
745
|
+
if (REUSABLE_INIT.test(rest) || reusableBodies.at(-1) === depth && FRAME_INIT.test(rest)) {
|
|
746
|
+
out += `${conditioned.slice(copied, at)}required`;
|
|
747
|
+
copied = at + "override".length;
|
|
748
|
+
}
|
|
749
|
+
continue;
|
|
750
|
+
}
|
|
527
751
|
const imported = /^import\s+CoreImage\.CIFilterBuiltins\b/.exec(rest);
|
|
528
752
|
if (imported) {
|
|
529
753
|
out += conditioned.slice(copied, at) + "import CoreImage".padEnd(imported[0].length);
|
|
@@ -536,6 +760,11 @@ function swiftSourceAsIOS(source) {
|
|
|
536
760
|
continue;
|
|
537
761
|
}
|
|
538
762
|
if (rest.startsWith("class")) {
|
|
763
|
+
const declared = CLASS_BASE.exec(rest);
|
|
764
|
+
if (declared && reusableViews.has(declared[2].split(".").pop())) {
|
|
765
|
+
reusableViews.add(declared[1]);
|
|
766
|
+
opensReusableBody = true;
|
|
767
|
+
}
|
|
539
768
|
const modifiers = conditioned.slice(conditioned.lastIndexOf("\n", at - 1) + 1, at);
|
|
540
769
|
if (DELEGATE_CLASS.test(rest) && !/\b(?:final|open)\b/.test(modifiers)) {
|
|
541
770
|
out += `${conditioned.slice(copied, at)}final `;
|
|
@@ -550,6 +779,8 @@ function swiftSourceAsIOS(source) {
|
|
|
550
779
|
if (selector) replacement = "#Selector";
|
|
551
780
|
else if (match[0] === "@objcMembers") replacement = "@ObjCMembers";
|
|
552
781
|
else if (match[0] === "@IBAction") replacement = "@ObjC".padEnd(match[0].length);
|
|
782
|
+
else if (TYPE_AFTER_ATTRIBUTE.test(rest.slice(match[0].length)))
|
|
783
|
+
replacement = " ".repeat(match[0].length);
|
|
553
784
|
else if (match[2] !== void 0)
|
|
554
785
|
replacement = `@ObjC${match[1]}("${match[2].trim()}")`;
|
|
555
786
|
out += conditioned.slice(copied, at) + replacement;
|
|
@@ -628,6 +859,9 @@ function swiftCodeScan(source) {
|
|
|
628
859
|
if (hashes > 0) tokens.push(at - 1);
|
|
629
860
|
i = Math.max(at, i + 1);
|
|
630
861
|
}
|
|
862
|
+
} else if (char === "{" || char === "}") {
|
|
863
|
+
tokens.push(i);
|
|
864
|
+
i++;
|
|
631
865
|
} else if (char === "(") {
|
|
632
866
|
top.parens++;
|
|
633
867
|
i++;
|
|
@@ -636,7 +870,7 @@ function swiftCodeScan(source) {
|
|
|
636
870
|
else top.parens--;
|
|
637
871
|
i++;
|
|
638
872
|
} else {
|
|
639
|
-
const keyword = source.startsWith("class", i) ? "class" : source.startsWith("import", i) ? "import" : source.startsWith("NSClassFromString", i) ? "NSClassFromString" : null;
|
|
873
|
+
const keyword = source.startsWith("class", i) ? "class" : source.startsWith("extension", i) ? "extension" : source.startsWith("override", i) ? "override" : source.startsWith("import", i) ? "import" : source.startsWith("NSClassFromString", i) ? "NSClassFromString" : null;
|
|
640
874
|
if (keyword && !/[\w$]/.test(source[i - 1] ?? "") && !/[\w$]/.test(source[i + keyword.length] ?? "")) {
|
|
641
875
|
tokens.push(i);
|
|
642
876
|
i += keyword.length;
|
|
@@ -649,6 +883,23 @@ function swiftCodeScan(source) {
|
|
|
649
883
|
return { lineStarts: starts, tokens };
|
|
650
884
|
}
|
|
651
885
|
var compiledSource = (file, contents) => file.endsWith(".swift") ? swiftSourceAsIOS(contents) : contents;
|
|
886
|
+
function prepareSwiftDependency(source, destination) {
|
|
887
|
+
(0, import_node_fs2.rmSync)(destination, { recursive: true, force: true });
|
|
888
|
+
const copy = (from, to, root) => {
|
|
889
|
+
(0, import_node_fs2.mkdirSync)(to, { recursive: true });
|
|
890
|
+
for (const entry of (0, import_node_fs2.readdirSync)(from, { withFileTypes: true })) {
|
|
891
|
+
if (entry.name === ".git" || entry.name === ".build" || entry.name === ".swiftpm")
|
|
892
|
+
continue;
|
|
893
|
+
const file = import_node_path2.default.join(from, entry.name);
|
|
894
|
+
const target = import_node_path2.default.join(to, entry.name);
|
|
895
|
+
if (entry.isDirectory()) copy(file, target, false);
|
|
896
|
+
else if (entry.isFile() && entry.name.endsWith(".swift") && !(root && /^Package(@swift-[\d.]+)?\.swift$/.test(entry.name)))
|
|
897
|
+
(0, import_node_fs2.writeFileSync)(target, compiledSource(file, (0, import_node_fs2.readFileSync)(file, "utf8")));
|
|
898
|
+
else (0, import_node_fs2.cpSync)(file, target, { verbatimSymlinks: true });
|
|
899
|
+
}
|
|
900
|
+
};
|
|
901
|
+
copy(source, destination, true);
|
|
902
|
+
}
|
|
652
903
|
function writeSwiftProject(layout, input, moduleRoot) {
|
|
653
904
|
const distribution = swiftDistributionAt(moduleRoot);
|
|
654
905
|
const targets = distribution && compileTargets(input).length === 0 ? [
|
|
@@ -691,7 +942,7 @@ function writeSwiftProject(layout, input, moduleRoot) {
|
|
|
691
942
|
}
|
|
692
943
|
if (input.oneModule) {
|
|
693
944
|
const product = '.product(name: "CoreLocation", package: "sootsim-swift"),';
|
|
694
|
-
const flags = `"-Osize"${
|
|
945
|
+
const flags = `"-Osize"${FOUNDATION_IMPLICIT_FLAGS}`;
|
|
695
946
|
if (!manifest.includes(product) || !manifest.includes(flags)) {
|
|
696
947
|
throw new Error(
|
|
697
948
|
"scripts/contrast-app-Package.swift lost the lines the One module links at"
|
|
@@ -815,7 +1066,8 @@ function compileSwiftProjectUnit(input, options) {
|
|
|
815
1066
|
);
|
|
816
1067
|
}
|
|
817
1068
|
const macroPlugins = await ensureMacroPlugins(moduleRoot, options.toolchainBin);
|
|
818
|
-
const
|
|
1069
|
+
const sdk = swiftModuleSdk(moduleRoot).wasmSdkId;
|
|
1070
|
+
const icu = swiftIcuAsset(options.toolchainBin, sdk);
|
|
819
1071
|
try {
|
|
820
1072
|
await run2(
|
|
821
1073
|
swift,
|
|
@@ -826,7 +1078,7 @@ function compileSwiftProjectUnit(input, options) {
|
|
|
826
1078
|
"--package-path",
|
|
827
1079
|
root,
|
|
828
1080
|
"--swift-sdk",
|
|
829
|
-
|
|
1081
|
+
sdk,
|
|
830
1082
|
"-c",
|
|
831
1083
|
"release",
|
|
832
1084
|
"-Xswiftc",
|
|
@@ -857,12 +1109,15 @@ function compileSwiftProjectUnit(input, options) {
|
|
|
857
1109
|
compileSwiftProjectUnit,
|
|
858
1110
|
compileTargets,
|
|
859
1111
|
emitSwiftPackageManifest,
|
|
1112
|
+
prepareSwiftDependency,
|
|
860
1113
|
swiftArtifactHash,
|
|
861
1114
|
swiftDistributionAt,
|
|
862
1115
|
swiftIcuAsset,
|
|
863
1116
|
swiftModuleDigest,
|
|
864
1117
|
swiftModuleInputFiles,
|
|
1118
|
+
swiftModuleSdk,
|
|
865
1119
|
swiftSourceAsIOS,
|
|
1120
|
+
swiftTargetDependencies,
|
|
866
1121
|
withNativeSourceGlue,
|
|
867
1122
|
writeSwiftProject
|
|
868
1123
|
});
|