peachsim 0.1.679 → 0.1.681

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.
Files changed (84) hide show
  1. package/cli/commands/daemon-mac-app.ts +11 -2
  2. package/cli/commands/daemon.ts +2 -3
  3. package/cli/commands/swift.ts +40 -19
  4. package/cli/outbound-endpoints.ts +8 -0
  5. package/dist-lib/agent-daemon-client.cjs +1 -1
  6. package/dist-lib/agent-events.cjs +1 -1
  7. package/dist-lib/agent-identity.cjs +1 -1
  8. package/dist-lib/agent-sessions.cjs +1 -1
  9. package/dist-lib/attached-projects.cjs +1 -1
  10. package/dist-lib/auth/shared-session.cjs +1 -1
  11. package/dist-lib/backend-origin.cjs +1 -1
  12. package/dist-lib/beta.cjs +1 -1
  13. package/dist-lib/beta.mjs +1 -1
  14. package/dist-lib/bridge-constants.cjs +1 -1
  15. package/dist-lib/bridge-contract-input.cjs +1 -1
  16. package/dist-lib/bridge-contract-input.mjs +1 -1
  17. package/dist-lib/bridge-contract.cjs +1 -1
  18. package/dist-lib/bridge-contract.mjs +1 -1
  19. package/dist-lib/capture-contract.cjs +1 -1
  20. package/dist-lib/capture-contract.mjs +1 -1
  21. package/dist-lib/cli-constants.cjs +1 -1
  22. package/dist-lib/cloud-contract.cjs +1 -1
  23. package/dist-lib/cloud-contract.mjs +1 -1
  24. package/dist-lib/cloud-test-args.cjs +1 -1
  25. package/dist-lib/cloud-test-args.mjs +1 -1
  26. package/dist-lib/cloud.cjs +1 -1
  27. package/dist-lib/cloud.mjs +1 -1
  28. package/dist-lib/config.cjs +1 -1
  29. package/dist-lib/detox/index.cjs +1 -1
  30. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  31. package/dist-lib/home-paths.cjs +1 -1
  32. package/dist-lib/host/bridge-host.cjs +2548 -2327
  33. package/dist-lib/host/fetch-proxy-handler.cjs +5 -13
  34. package/dist-lib/host/fetch-proxy-overrides.cjs +2 -6
  35. package/dist-lib/host/fetch-proxy-overrides.mjs +2 -6
  36. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  37. package/dist-lib/host/websocket-proxy.cjs +1 -1
  38. package/dist-lib/index.cjs +1 -1
  39. package/dist-lib/jump-to-source-babel.cjs +1 -1
  40. package/dist-lib/jump-to-source-native.cjs +1 -1
  41. package/dist-lib/kotlin-host.cjs +1 -1
  42. package/dist-lib/menu.cjs +1 -1
  43. package/dist-lib/menu.mjs +1 -1
  44. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  45. package/dist-lib/metro-fingerprint-registry.mjs +1 -1
  46. package/dist-lib/metro-production-bundle.cjs +1 -1
  47. package/dist-lib/metro-production-bundle.mjs +1 -1
  48. package/dist-lib/metro.cjs +1 -1
  49. package/dist-lib/native-app-identity.cjs +1 -1
  50. package/dist-lib/native-app-identity.mjs +1 -1
  51. package/dist-lib/native-firebase-metadata.cjs +1 -1
  52. package/dist-lib/native-firebase-metadata.mjs +1 -1
  53. package/dist-lib/plist.cjs +1 -1
  54. package/dist-lib/plist.mjs +1 -1
  55. package/dist-lib/profiles.cjs +1 -1
  56. package/dist-lib/public-brand.cjs +1 -1
  57. package/dist-lib/react-native-host-modules.cjs +1 -1
  58. package/dist-lib/react-native-host-modules.mjs +1 -1
  59. package/dist-lib/render-mode.cjs +1 -1
  60. package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
  61. package/dist-lib/sdk.cjs +1 -1
  62. package/dist-lib/sdk.mjs +1 -1
  63. package/dist-lib/skills.cjs +2296 -2053
  64. package/dist-lib/swift-compile.cjs +78 -12
  65. package/dist-lib/swift-compile.mjs +76 -12
  66. package/dist-lib/swift-package.cjs +1 -1
  67. package/dist-lib/swift-package.mjs +1 -1
  68. package/dist-lib/swift-submit.cjs +1 -1
  69. package/dist-lib/swift-submit.mjs +1 -1
  70. package/dist-lib/swift-toolchain.cjs +115 -0
  71. package/dist-lib/swift.cjs +1 -1
  72. package/dist-lib/vite-swift.cjs +470 -149
  73. package/dist-lib/vite.cjs +1 -1
  74. package/package.json +7 -1
  75. package/skills/contrast/SKILL.md +1 -1
  76. package/src/expo-swift-host.ts +9 -13
  77. package/src/host/fetch-proxy-handler.ts +11 -10
  78. package/src/host/fetch-proxy-overrides.ts +9 -10
  79. package/src/swift-compile.ts +76 -10
  80. package/src/swift-distribution-contract.ts +138 -0
  81. package/src/swift-distribution.lock.json +20 -0
  82. package/src/swift-distribution.ts +108 -0
  83. package/src/swift-host.ts +8 -30
  84. package/src/swift-toolchain.ts +102 -0
@@ -1,4 +1,4 @@
1
- /*! rnx v0.1.679 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
1
+ /*! rnx v0.1.681 | (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;
@@ -45,8 +45,8 @@ __export(vite_plugin_swift_exports, {
45
45
  swiftPlugin: () => swiftPlugin
46
46
  });
47
47
  module.exports = __toCommonJS(vite_plugin_swift_exports);
48
- var import_node_fs5 = __toESM(require("node:fs"), 1);
49
- var import_node_path7 = __toESM(require("node:path"), 1);
48
+ var import_node_fs8 = __toESM(require("node:fs"), 1);
49
+ var import_node_path9 = __toESM(require("node:path"), 1);
50
50
 
51
51
  // ../sootsim-swift/src/entryModule.ts
52
52
  function nativeExportLines(args, commonjs) {
@@ -77,6 +77,71 @@ var import_node_os = __toESM(require("node:os"), 1);
77
77
  var import_node_path2 = __toESM(require("node:path"), 1);
78
78
  var import_node_util2 = require("node:util");
79
79
 
80
+ // src/is-record.ts
81
+ function isRecord(value) {
82
+ return typeof value === "object" && value !== null && !Array.isArray(value);
83
+ }
84
+
85
+ // src/swift-distribution-contract.ts
86
+ var SWIFT_DISTRIBUTION_MANIFEST = "distribution.json";
87
+ var SWIFT_DISTRIBUTION_HOSTS = [
88
+ "darwin-arm64",
89
+ "linux-x64",
90
+ "linux-arm64"
91
+ ];
92
+ function swiftDistributionHost(platform, arch) {
93
+ const host2 = `${platform}-${arch}`;
94
+ return SWIFT_DISTRIBUTION_HOSTS.find((candidate) => candidate === host2) ?? null;
95
+ }
96
+ var isStrings = (value) => Array.isArray(value) && value.every((item) => typeof item === "string");
97
+ function parseSwiftDistributionManifest(value) {
98
+ 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)) {
99
+ throw new Error(`invalid Swift distribution ${SWIFT_DISTRIBUTION_MANIFEST}`);
100
+ }
101
+ const host2 = SWIFT_DISTRIBUTION_HOSTS.find((candidate) => candidate === value.host);
102
+ if (!host2) throw new Error(`Swift distribution names an unknown host ${value.host}`);
103
+ return {
104
+ id: value.id,
105
+ release: value.release,
106
+ wasmSdkChecksum: value.wasmSdkChecksum,
107
+ modules: value.modules,
108
+ objects: value.objects,
109
+ link: value.link,
110
+ files: Object.fromEntries(
111
+ Object.entries(value.files).map(([file, sha]) => [file, String(sha)])
112
+ ),
113
+ host: host2,
114
+ plugins: value.plugins
115
+ };
116
+ }
117
+ function parseSwiftDistributionLock(value) {
118
+ if (!isRecord(value) || typeof value.id !== "string" || !/^[a-f0-9]{16}$/.test(value.id) || typeof value.release !== "string" || typeof value.wasmSdkChecksum !== "string" || typeof value.source !== "string" || !isRecord(value.hosts)) {
119
+ throw new Error("invalid Swift distribution lock");
120
+ }
121
+ const hosts = value.hosts;
122
+ const entry = (host2) => {
123
+ const item = hosts[host2];
124
+ if (!isRecord(item) || typeof item.sha256 !== "string" || !/^[a-f0-9]{64}$/.test(item.sha256) || typeof item.size !== "number") {
125
+ throw new Error(`invalid Swift distribution lock entry for ${host2}`);
126
+ }
127
+ return { sha256: item.sha256, size: item.size };
128
+ };
129
+ return {
130
+ id: value.id,
131
+ release: value.release,
132
+ wasmSdkChecksum: value.wasmSdkChecksum,
133
+ source: value.source,
134
+ hosts: {
135
+ "darwin-arm64": entry("darwin-arm64"),
136
+ "linux-x64": entry("linux-x64"),
137
+ "linux-arm64": entry("linux-arm64")
138
+ }
139
+ };
140
+ }
141
+ function swiftDistributionKey(id, host2) {
142
+ return `${id}/${host2}.tar.gz`;
143
+ }
144
+
80
145
  // src/swift-icu.ts
81
146
  var import_node_child_process = require("node:child_process");
82
147
  var import_node_crypto = require("node:crypto");
@@ -241,7 +306,13 @@ var WASM_TRIPLE = "wasm32-unknown-wasip1";
241
306
  var cores = import_node_os.default.availableParallelism();
242
307
  var BUILD_ENV = { ...process.env, BINARYEN_CORES: String(Math.min(4, cores)) };
243
308
  var BUILD_JOBS = String(Math.max(1, Math.floor(cores / 2)));
309
+ function swiftDistributionAt(root) {
310
+ const file = import_node_path2.default.join(root, SWIFT_DISTRIBUTION_MANIFEST);
311
+ if (!(0, import_node_fs2.existsSync)(file)) return null;
312
+ return parseSwiftDistributionManifest(JSON.parse((0, import_node_fs2.readFileSync)(file, "utf8")));
313
+ }
244
314
  function swiftModuleInputFiles(root) {
315
+ if (swiftDistributionAt(root)) return [SWIFT_DISTRIBUTION_MANIFEST];
245
316
  const files = [
246
317
  "Package.swift",
247
318
  "scripts/contrast-app-Package.swift",
@@ -258,6 +329,9 @@ function swiftModuleInputFiles(root) {
258
329
  return files.sort();
259
330
  }
260
331
  async function ensureMacroPlugins(moduleRoot, toolchainBin) {
332
+ const distribution = swiftDistributionAt(moduleRoot);
333
+ if (distribution)
334
+ return distribution.plugins.map((plugin) => import_node_path2.default.join(moduleRoot, plugin));
261
335
  const dir = import_node_path2.default.join(moduleRoot, ".build/host/RnxPreviewMacros");
262
336
  const ext = process.platform === "darwin" ? "dylib" : "so";
263
337
  const plugins = [
@@ -283,7 +357,7 @@ async function ensureMacroPlugins(moduleRoot, toolchainBin) {
283
357
  return plugins.map(({ library }) => library);
284
358
  }
285
359
  var linkedModuleDigests = /* @__PURE__ */ new Map();
286
- function linkedModuleDigest(root) {
360
+ function swiftModuleDigest(root) {
287
361
  const files = swiftModuleInputFiles(root);
288
362
  const stampHash = (0, import_node_crypto2.createHash)("sha256");
289
363
  for (const file of files) {
@@ -355,7 +429,7 @@ function swiftArtifactHash(input, release, moduleRoot) {
355
429
  ${release}
356
430
  `);
357
431
  if (input.oneModule) hash.update("one-module\n");
358
- hash.update(linkedModuleDigest(moduleRoot));
432
+ hash.update(swiftModuleDigest(moduleRoot));
359
433
  for (const file of Object.keys(input.files).sort()) {
360
434
  hash.update((0, import_node_crypto2.createHash)("sha256").update(file).digest());
361
435
  hash.update((0, import_node_crypto2.createHash)("sha256").update(input.files[file]).digest());
@@ -389,23 +463,30 @@ ${release}
389
463
  return hash.digest("hex");
390
464
  }
391
465
  function emitSwiftPackageManifest(args) {
392
- const { targets, siblings, moduleRoot, oneModule } = args;
466
+ const { targets, siblings, moduleRoot, oneModule, distribution } = args;
393
467
  const executable = targets.find((target) => target.executable);
394
468
  if (!executable) throw new Error("swift-compile: no executable target to emit");
395
469
  const stanza = (target) => {
396
470
  const isolation = target.mainActorIsolation ? " .defaultIsolation(MainActor.self)," : "";
397
- const swiftSettings = `swiftSettings: [.swiftLanguageMode(.v${target.languageMode}),${isolation} .unsafeFlags(["-Osize"${OBJC_IMPLICIT_FLAGS}${oneModule ? ONE_IMPLICIT_FLAGS : ""}])]`;
471
+ const imports = distribution ? `, "-I", ${JSON.stringify(import_node_path2.default.join(moduleRoot, "modules"))}` : "";
472
+ const swiftSettings = `swiftSettings: [.swiftLanguageMode(.v${target.languageMode}),${isolation} .unsafeFlags(["-Osize"${OBJC_IMPLICIT_FLAGS}${oneModule ? ONE_IMPLICIT_FLAGS : ""}${imports}])]`;
398
473
  const deps = [
399
- '.product(name: "SwiftUI", package: "sootsim-swift")',
400
- ...oneModule ? [ONE_PRODUCT] : [],
474
+ ...distribution ? [] : [
475
+ '.product(name: "SwiftUI", package: "sootsim-swift")',
476
+ ...oneModule ? [ONE_PRODUCT] : []
477
+ ],
401
478
  ...(siblings.get(target.name) ?? []).map((sibling) => `"${sibling}"`)
402
479
  ].join(", ");
480
+ const library = distribution ? [
481
+ ...distribution.objects.map((object) => import_node_path2.default.join(moduleRoot, object)),
482
+ ...distribution.link
483
+ ].map((flag) => `, ${JSON.stringify(flag)}`).join("") : "";
403
484
  const kind = target.executable ? ".executableTarget" : ".target";
404
485
  const link = target.executable ? `,
405
486
  linkerSettings: [
406
487
  .unsafeFlags([
407
488
  "-Xclang-linker", "-mexec-model=reactor",
408
- "-Xlinker", "--export-if-defined=__main_argc_argv",
489
+ "-Xlinker", "--export-if-defined=__main_argc_argv"${library},
409
490
  ]),
410
491
  .unsafeFlags(["-Xlinker", "--strip-all"], .when(configuration: .release)),
411
492
  ]` : "";
@@ -426,7 +507,7 @@ function emitSwiftPackageManifest(args) {
426
507
  "let package = Package(",
427
508
  ' name: "app",',
428
509
  ` products: [.executable(name: "${executable.name}", targets: ["${executable.name}"])],`,
429
- ` dependencies: [.package(path: "${moduleRoot}")],`,
510
+ ` dependencies: [${distribution ? "" : `.package(path: "${moduleRoot}")`}],`,
430
511
  " targets: [",
431
512
  ...targets.map(stanza),
432
513
  " ]",
@@ -595,7 +676,17 @@ function swiftCodeScan(source) {
595
676
  }
596
677
  var compiledSource = (file, contents) => file.endsWith(".swift") ? swiftSourceAsIOS(contents) : contents;
597
678
  function writeSwiftProject(layout, input, moduleRoot) {
598
- const targets = compileTargets(input);
679
+ const distribution = swiftDistributionAt(moduleRoot);
680
+ const targets = distribution && compileTargets(input).length === 0 ? [
681
+ {
682
+ name: "App",
683
+ path: import_node_path2.default.relative(layout.root, layout.sources),
684
+ executable: true,
685
+ languageMode: 5,
686
+ mainActorIsolation: false,
687
+ resources: false
688
+ }
689
+ ] : compileTargets(input);
599
690
  const files = /* @__PURE__ */ new Map();
600
691
  const moduleFiles = `
601
692
  // sootsim-swift files ${(0, import_node_crypto2.createHash)("sha256").update(swiftModuleInputFiles(moduleRoot).join("\n")).digest("hex").slice(0, 16)}
@@ -622,9 +713,10 @@ function writeSwiftProject(layout, input, moduleRoot) {
622
713
  }
623
714
  files.set(import_node_path2.default.join(layout.root, "Package.swift"), manifest + moduleFiles);
624
715
  } else {
716
+ const base = layout.multi ? layout.root : layout.sources;
625
717
  for (const [file, contents] of Object.entries(input.files)) {
626
718
  if (file === "Package.swift") continue;
627
- files.set(import_node_path2.default.join(layout.root, file), compiledSource(file, contents));
719
+ files.set(import_node_path2.default.join(base, file), compiledSource(file, contents));
628
720
  }
629
721
  for (const target of targets) {
630
722
  if (!target.resources) continue;
@@ -646,7 +738,8 @@ function writeSwiftProject(layout, input, moduleRoot) {
646
738
  targets,
647
739
  siblings: swiftSiblingDependencies(input.files, targets),
648
740
  moduleRoot,
649
- oneModule: input.oneModule
741
+ oneModule: input.oneModule,
742
+ distribution: distribution ?? void 0
650
743
  }) + moduleFiles
651
744
  );
652
745
  }
@@ -757,20 +850,10 @@ function compileSwiftProjectUnit(input, options) {
757
850
  }
758
851
 
759
852
  // src/swift-host.ts
760
- var import_node_crypto3 = require("node:crypto");
761
- var import_node_fs4 = __toESM(require("node:fs"), 1);
762
- var import_node_os4 = __toESM(require("node:os"), 1);
763
- var import_node_path6 = __toESM(require("node:path"), 1);
764
-
765
- // ../../src/compile/swiftToolchain.ts
766
- var import_node_os2 = __toESM(require("node:os"), 1);
767
- var import_node_path3 = __toESM(require("node:path"), 1);
768
- function swiftToolchainBin(release) {
769
- return process.platform === "darwin" ? import_node_path3.default.join(
770
- import_node_os2.default.homedir(),
771
- `Library/Developer/Toolchains/${release}.xctoolchain/usr/bin`
772
- ) : import_node_path3.default.join(process.env.CONTRAST_SWIFT_TOOLCHAINS ?? "/opt/swift", release, "usr/bin");
773
- }
853
+ var import_node_crypto4 = require("node:crypto");
854
+ var import_node_fs7 = __toESM(require("node:fs"), 1);
855
+ var import_node_os5 = __toESM(require("node:os"), 1);
856
+ var import_node_path8 = __toESM(require("node:path"), 1);
774
857
 
775
858
  // ../sootsim-swift/src/bundleAssets.ts
776
859
  var import_svgpath = __toESM(require("svgpath"), 1);
@@ -804,8 +887,8 @@ function pickImagesetFile(images) {
804
887
  scale: pick.scale === "2x" ? 2 : pick.scale === "3x" ? 3 : 1
805
888
  };
806
889
  }
807
- function flatScale(path7) {
808
- const match = /@([23])x\.[^./]+$/.exec(path7);
890
+ function flatScale(path9) {
891
+ const match = /@([23])x\.[^./]+$/.exec(path9);
809
892
  return match ? Number(match[1]) : 1;
810
893
  }
811
894
  function providesNamespace(text) {
@@ -832,13 +915,13 @@ function catalogEntryName(contentsPath, kind, readText) {
832
915
  }
833
916
  return segments.join("/");
834
917
  }
835
- function isFlatResourceImage(path7) {
836
- return path7.split("/").includes("Resources") && RASTER_EXTENSIONS.has(extOf(path7));
918
+ function isFlatResourceImage(path9) {
919
+ return path9.split("/").includes("Resources") && RASTER_EXTENSIONS.has(extOf(path9));
837
920
  }
838
921
  function enumerateBundleImages(paths, readText) {
839
922
  const table = [];
840
923
  const seen = /* @__PURE__ */ new Set();
841
- const catalogs = paths.filter((path7) => baseOf(path7) === "Contents.json");
924
+ const catalogs = paths.filter((path9) => baseOf(path9) === "Contents.json");
842
925
  for (const contentsPath of catalogs) {
843
926
  const name = catalogEntryName(contentsPath, ".imageset", readText);
844
927
  if (name === null || seen.has(name)) continue;
@@ -859,12 +942,12 @@ function enumerateBundleImages(paths, readText) {
859
942
  seen.add(name);
860
943
  table.push({ name, file: `${dir}/${pick.filename}`, scale: pick.scale });
861
944
  }
862
- for (const path7 of paths) {
863
- if (!isFlatResourceImage(path7)) continue;
864
- const name = baseOf(path7).slice(0, -extOf(path7).length);
945
+ for (const path9 of paths) {
946
+ if (!isFlatResourceImage(path9)) continue;
947
+ const name = baseOf(path9).slice(0, -extOf(path9).length);
865
948
  if (name === "" || seen.has(name)) continue;
866
949
  seen.add(name);
867
- table.push({ name, file: path7, scale: flatScale(path7) });
950
+ table.push({ name, file: path9, scale: flatScale(path9) });
868
951
  }
869
952
  return table;
870
953
  }
@@ -893,7 +976,7 @@ function colorsetValue(color) {
893
976
  }
894
977
  function enumerateBundleColors(paths, readText) {
895
978
  const table = {};
896
- for (const contentsPath of paths.filter((path7) => baseOf(path7) === "Contents.json")) {
979
+ for (const contentsPath of paths.filter((path9) => baseOf(path9) === "Contents.json")) {
897
980
  const name = catalogEntryName(contentsPath, ".colorset", readText);
898
981
  if (name === null || name in table) continue;
899
982
  let colors;
@@ -958,8 +1041,8 @@ function axisExtremes(points) {
958
1041
  function pathBounds(d) {
959
1042
  const xs = [];
960
1043
  const ys = [];
961
- for (const path7 of d)
962
- (0, import_svgpath.default)(path7).abs().unshort().unarc().iterate((segment, _index, x, y) => {
1044
+ for (const path9 of d)
1045
+ (0, import_svgpath.default)(path9).abs().unshort().unarc().iterate((segment, _index, x, y) => {
963
1046
  const [command, ...args] = segment;
964
1047
  if (command === "M" || command === "L") {
965
1048
  xs.push(Number(args[0]));
@@ -986,7 +1069,7 @@ function guide(svg, id, axis) {
986
1069
  }
987
1070
  function enumerateBundleSymbols(paths, readText) {
988
1071
  const table = {};
989
- for (const contentsPath of paths.filter((path7) => baseOf(path7) === "Contents.json")) {
1072
+ for (const contentsPath of paths.filter((path9) => baseOf(path9) === "Contents.json")) {
990
1073
  const name = catalogEntryName(contentsPath, ".symbolset", readText);
991
1074
  if (name === null || name in table) continue;
992
1075
  let symbols;
@@ -1019,8 +1102,8 @@ function enumerateBundleSymbols(paths, readText) {
1019
1102
  viewBox: "0 0 24 24",
1020
1103
  advance,
1021
1104
  box: [12 - advance / 2, 12 - tall / 2, advance, tall],
1022
- layers: d.map((path7) => ({
1023
- d: (0, import_svgpath.default)(path7).abs().scale(scale).translate(translateX, translateY).round(3).toString()
1105
+ layers: d.map((path9) => ({
1106
+ d: (0, import_svgpath.default)(path9).abs().scale(scale).translate(translateX, translateY).round(3).toString()
1024
1107
  }))
1025
1108
  };
1026
1109
  }
@@ -1030,7 +1113,7 @@ function enumerateBundleJson(paths) {
1030
1113
  const found = [];
1031
1114
  const seen = /* @__PURE__ */ new Set();
1032
1115
  const ordered = [...paths].filter(
1033
- (path7) => path7.split("/").includes("Resources") && path7.split("/").every((segment) => segment !== "" && segment !== "..") && (extOf(path7) === ".json" || extOf(path7) === ".xcstrings")
1116
+ (path9) => path9.split("/").includes("Resources") && path9.split("/").every((segment) => segment !== "" && segment !== "..") && (extOf(path9) === ".json" || extOf(path9) === ".xcstrings")
1034
1117
  ).sort((a, b) => {
1035
1118
  const aDepth = a.split("/").length;
1036
1119
  const bDepth = b.split("/").length;
@@ -1047,22 +1130,22 @@ function enumerateBundleJson(paths) {
1047
1130
 
1048
1131
  // src/auth/shared-session.ts
1049
1132
  var import_node_fs3 = require("node:fs");
1050
- var import_node_path5 = require("node:path");
1133
+ var import_node_path4 = require("node:path");
1051
1134
 
1052
1135
  // src/home-paths.ts
1053
- var import_node_os3 = require("node:os");
1054
- var import_node_path4 = __toESM(require("node:path"), 1);
1136
+ var import_node_os2 = require("node:os");
1137
+ var import_node_path3 = __toESM(require("node:path"), 1);
1055
1138
  var PEACH_HOME_ENV = "PEACH_HOME";
1056
1139
  function rnxHomeDir() {
1057
1140
  const override = process.env[PEACH_HOME_ENV];
1058
- if (override && override.length > 0) return import_node_path4.default.resolve(override);
1059
- return import_node_path4.default.join((0, import_node_os3.homedir)(), ".peach");
1141
+ if (override && override.length > 0) return import_node_path3.default.resolve(override);
1142
+ return import_node_path3.default.join((0, import_node_os2.homedir)(), ".peach");
1060
1143
  }
1061
1144
  function electronDir() {
1062
- return import_node_path4.default.join(rnxHomeDir(), "electron");
1145
+ return import_node_path3.default.join(rnxHomeDir(), "electron");
1063
1146
  }
1064
1147
  function electronUserDataDir() {
1065
- return import_node_path4.default.join(electronDir(), "userData");
1148
+ return import_node_path3.default.join(electronDir(), "userData");
1066
1149
  }
1067
1150
  var DAEMON_LOCKFILE_MAX_BYTES = 16 * 1024;
1068
1151
 
@@ -1079,14 +1162,14 @@ var DEFAULT_ORIGIN = "https://contrast.dev";
1079
1162
  function getBaseDir() {
1080
1163
  const explicit = process.env[SESSION_FILE_ENV];
1081
1164
  if (explicit?.trim()) {
1082
- return (0, import_node_path5.dirname)((0, import_node_path5.resolve)(explicit));
1165
+ return (0, import_node_path4.dirname)((0, import_node_path4.resolve)(explicit));
1083
1166
  }
1084
1167
  return electronUserDataDir();
1085
1168
  }
1086
1169
  function getSharedDesktopAuthFilePath() {
1087
1170
  const explicit = process.env[SESSION_FILE_ENV];
1088
- if (explicit?.trim()) return (0, import_node_path5.resolve)(explicit);
1089
- return (0, import_node_path5.join)(getBaseDir(), "desktop-auth.json");
1171
+ if (explicit?.trim()) return (0, import_node_path4.resolve)(explicit);
1172
+ return (0, import_node_path4.join)(getBaseDir(), "desktop-auth.json");
1090
1173
  }
1091
1174
  function normalizeUser(input) {
1092
1175
  if (!input || typeof input !== "object") return null;
@@ -1245,6 +1328,259 @@ function resolveContrastBackendOrigin(currentOrigin) {
1245
1328
  return DEFAULT_CONTRAST_BACKEND_ORIGIN;
1246
1329
  }
1247
1330
 
1331
+ // src/swift-distribution.ts
1332
+ var import_node_fs6 = __toESM(require("node:fs"), 1);
1333
+ var import_node_path7 = __toESM(require("node:path"), 1);
1334
+
1335
+ // ../contrast-runtime-delivery/src/index.ts
1336
+ var import_node_child_process3 = require("node:child_process");
1337
+ var import_node_crypto3 = __toESM(require("node:crypto"), 1);
1338
+ var import_node_fs4 = __toESM(require("node:fs"), 1);
1339
+ var import_node_os3 = __toESM(require("node:os"), 1);
1340
+ var import_node_path5 = __toESM(require("node:path"), 1);
1341
+ var import_node_stream = require("node:stream");
1342
+ var import_promises = require("node:stream/promises");
1343
+ async function installVerifiedTarball(tarball) {
1344
+ const { url, digest, destDir, installedMarker, label } = tarball;
1345
+ const downloadDir = import_node_fs4.default.mkdtempSync(import_node_path5.default.join(import_node_os3.default.tmpdir(), "runtime-delivery-download-"));
1346
+ const archivePath = import_node_path5.default.join(downloadDir, "archive.tar.gz");
1347
+ import_node_fs4.default.mkdirSync(import_node_path5.default.dirname(destDir), { recursive: true });
1348
+ const tmpDir = import_node_fs4.default.mkdtempSync(
1349
+ import_node_path5.default.join(import_node_path5.default.dirname(destDir), `.installing-${import_node_path5.default.basename(destDir)}-`)
1350
+ );
1351
+ try {
1352
+ await downloadToFile(url, archivePath);
1353
+ const actual = await digestFile(archivePath, digest.algorithm, digest.encoding);
1354
+ if (actual !== digest.value) {
1355
+ throw new Error(
1356
+ `${digest.algorithm} mismatch for ${label}: expected ${digest.value}, actual ${actual}`
1357
+ );
1358
+ }
1359
+ await extractTarball(archivePath, tmpDir, tarball.stripComponents ?? 0);
1360
+ if (!import_node_fs4.default.existsSync(import_node_path5.default.join(tmpDir, installedMarker))) {
1361
+ throw new Error(`extracted tarball for ${label} is missing ${installedMarker}`);
1362
+ }
1363
+ try {
1364
+ import_node_fs4.default.renameSync(tmpDir, destDir);
1365
+ } catch (err) {
1366
+ if (!isErrnoCode(err, "ENOTEMPTY", "EEXIST")) throw err;
1367
+ const aside = `${tmpDir}-replaced`;
1368
+ try {
1369
+ import_node_fs4.default.renameSync(destDir, aside);
1370
+ } catch (moveErr) {
1371
+ if (!isErrnoCode(moveErr, "ENOENT")) throw moveErr;
1372
+ }
1373
+ try {
1374
+ import_node_fs4.default.renameSync(tmpDir, destDir);
1375
+ } catch (landErr) {
1376
+ if (!isErrnoCode(landErr, "ENOTEMPTY", "EEXIST") || !import_node_fs4.default.existsSync(import_node_path5.default.join(destDir, installedMarker))) {
1377
+ throw landErr;
1378
+ }
1379
+ } finally {
1380
+ import_node_fs4.default.rmSync(aside, { recursive: true, force: true });
1381
+ }
1382
+ }
1383
+ } finally {
1384
+ import_node_fs4.default.rmSync(tmpDir, { recursive: true, force: true });
1385
+ import_node_fs4.default.rmSync(downloadDir, { recursive: true, force: true });
1386
+ }
1387
+ }
1388
+ function isErrnoCode(err, ...codes) {
1389
+ return err instanceof Error && "code" in err && codes.includes(String(err.code));
1390
+ }
1391
+ async function downloadToFile(url, destPath) {
1392
+ const res = await fetch(url);
1393
+ if (!res.ok || !res.body) {
1394
+ throw new Error(`download failed: ${res.status} ${res.statusText} (${url})`);
1395
+ }
1396
+ import_node_fs4.default.mkdirSync(import_node_path5.default.dirname(destPath), { recursive: true });
1397
+ const tmp = `${destPath}.partial`;
1398
+ try {
1399
+ await (0, import_promises.pipeline)(
1400
+ import_node_stream.Readable.fromWeb(res.body),
1401
+ import_node_fs4.default.createWriteStream(tmp)
1402
+ );
1403
+ import_node_fs4.default.renameSync(tmp, destPath);
1404
+ } catch (err) {
1405
+ try {
1406
+ import_node_fs4.default.unlinkSync(tmp);
1407
+ } catch {
1408
+ }
1409
+ throw err;
1410
+ }
1411
+ }
1412
+ function digestFile(filePath, algorithm, encoding) {
1413
+ return new Promise((resolve2, reject) => {
1414
+ const hash = import_node_crypto3.default.createHash(algorithm);
1415
+ const stream = import_node_fs4.default.createReadStream(filePath);
1416
+ stream.on("data", (chunk) => hash.update(chunk));
1417
+ stream.on("error", reject);
1418
+ stream.on("end", () => resolve2(hash.digest(encoding)));
1419
+ });
1420
+ }
1421
+ function extractTarball(tarPath, destDir, stripComponents) {
1422
+ return new Promise((resolve2, reject) => {
1423
+ const args = ["-xzf", tarPath, "-C", destDir];
1424
+ if (stripComponents > 0) args.push(`--strip-components=${stripComponents}`);
1425
+ const child = (0, import_node_child_process3.spawn)("tar", args, {
1426
+ stdio: ["ignore", "inherit", "inherit"]
1427
+ });
1428
+ child.on("error", reject);
1429
+ child.on("exit", (code) => {
1430
+ if (code === 0) resolve2();
1431
+ else reject(new Error(`tar exited with code ${code}`));
1432
+ });
1433
+ });
1434
+ }
1435
+
1436
+ // src/swift-distribution.lock.json
1437
+ var swift_distribution_lock_default = {
1438
+ id: "6f2d91274094c8af",
1439
+ release: "swift-6.3-RELEASE",
1440
+ wasmSdkChecksum: "9fa4016ee632c7e9e906608ec3b55cf13dfc4dff44e47574c5af58064dc33fd9",
1441
+ source: "27df8ca4ecdc5369d51f08fe54ac32a1f21c5949",
1442
+ hosts: {
1443
+ "darwin-arm64": {
1444
+ sha256: "606751627cfeafedfeb6a0abefc7f9a734935b7fd222d93ead096a6d89695a98",
1445
+ size: 4551053
1446
+ },
1447
+ "linux-x64": {
1448
+ sha256: "7d7cb0adc43af4b83576979693a9a4994abca5d773e5550f4f154939fe08b091",
1449
+ size: 4556463
1450
+ },
1451
+ "linux-arm64": {
1452
+ sha256: "78c7c76b8a29a3ec797cd410fd882a6f1dfb349f1785e0cf5cf0d8aebb2d96a9",
1453
+ size: 4555726
1454
+ }
1455
+ }
1456
+ };
1457
+
1458
+ // src/swift-toolchain.ts
1459
+ var import_node_child_process4 = require("node:child_process");
1460
+ var import_node_fs5 = __toESM(require("node:fs"), 1);
1461
+ var import_node_os4 = __toESM(require("node:os"), 1);
1462
+ var import_node_path6 = __toESM(require("node:path"), 1);
1463
+ function swiftToolchainBin(release) {
1464
+ if (process.platform === "darwin") {
1465
+ const dirs = [import_node_os4.default.homedir(), "/"].map(
1466
+ (base) => import_node_path6.default.join(base, `Library/Developer/Toolchains/${release}.xctoolchain/usr/bin`)
1467
+ );
1468
+ return dirs.find((dir) => import_node_fs5.default.existsSync(import_node_path6.default.join(dir, "swift"))) ?? dirs[0];
1469
+ }
1470
+ if (process.env.CONTRAST_SWIFT_TOOLCHAINS) {
1471
+ return import_node_path6.default.join(process.env.CONTRAST_SWIFT_TOOLCHAINS, release, "usr/bin");
1472
+ }
1473
+ const image = import_node_path6.default.join("/opt/swift", release, "usr/bin");
1474
+ if (import_node_fs5.default.existsSync(import_node_path6.default.join(image, "swift"))) return image;
1475
+ return (process.env.PATH ?? "").split(import_node_path6.default.delimiter).find((dir) => dir && import_node_fs5.default.existsSync(import_node_path6.default.join(dir, "swift"))) ?? image;
1476
+ }
1477
+ var verified = /* @__PURE__ */ new Map();
1478
+ function swiftToolchain(release, wasmSdkChecksum) {
1479
+ const cached = verified.get(release);
1480
+ if (cached) return cached;
1481
+ const bin = swiftToolchainBin(release);
1482
+ const swift = import_node_path6.default.join(bin, "swift");
1483
+ const version = import_node_fs5.default.existsSync(swift) ? (0, import_node_child_process4.execFileSync)(swift, ["--version"], {
1484
+ encoding: "utf8",
1485
+ stdio: ["ignore", "pipe", "pipe"]
1486
+ }) : "";
1487
+ if (!version.includes(`(${release})`)) {
1488
+ const found = version ? `found ${version.split("\n")[0]?.trim()} at ${swift}` : process.platform === "darwin" ? `found no ${release}.xctoolchain in ~/Library/Developer/Toolchains or /Library/Developer/Toolchains` : "found no swift on PATH";
1489
+ throw new Error(
1490
+ `peach compiles Swift with the swift.org toolchain ${release} and its wasm SDK; ${found}.
1491
+ ${swiftInstallSteps(release, wasmSdkChecksum)}`
1492
+ );
1493
+ }
1494
+ const sdks = (0, import_node_child_process4.execFileSync)(swift, ["sdk", "list"], {
1495
+ encoding: "utf8",
1496
+ stdio: ["ignore", "pipe", "pipe"]
1497
+ });
1498
+ if (!sdks.split("\n").some((line) => line.trim() === `${release}_wasm`)) {
1499
+ throw new Error(
1500
+ `peach compiles Swift with the ${release}_wasm SDK, which ${swift} does not have.
1501
+ ${swiftInstallSteps(release, wasmSdkChecksum)}`
1502
+ );
1503
+ }
1504
+ verified.set(release, bin);
1505
+ return bin;
1506
+ }
1507
+ function swiftInstallSteps(release, wasmSdkChecksum) {
1508
+ const version = release.replace(/^swift-/, "").toLowerCase();
1509
+ const downloads = `https://download.swift.org/swift-${version}`;
1510
+ const sdk = `swift sdk install ${downloads}/wasm-sdk/${release}/${release}_wasm.artifactbundle.tar.gz --checksum ${wasmSdkChecksum}`;
1511
+ if (process.platform === "darwin") {
1512
+ const swift = `~/Library/Developer/Toolchains/${release}.xctoolchain/usr/bin/swift`;
1513
+ return [
1514
+ "install it:",
1515
+ ` curl -fsSLO ${downloads}/xcode/${release}/${release}-osx.pkg`,
1516
+ ` installer -pkg ${release}-osx.pkg -target CurrentUserHomeDirectory`,
1517
+ ` ${swift} ${sdk.replace(/^swift /, "")}`
1518
+ ].join("\n");
1519
+ }
1520
+ const platform = `debian12${process.arch === "arm64" ? "-aarch64" : ""}`;
1521
+ const name = `${release}-${platform}`;
1522
+ return [
1523
+ "install it (Debian 12 shown; other distributions: https://www.swift.org/install/linux/):",
1524
+ ` curl -fsSL ${downloads}/${platform}/${release}/${name}.tar.gz | tar -xz -C /opt`,
1525
+ ` export PATH=/opt/${name}/usr/bin:$PATH`,
1526
+ ` ${sdk}`
1527
+ ].join("\n");
1528
+ }
1529
+
1530
+ // src/swift-distribution.ts
1531
+ var SWIFT_ENDPOINT_ENV = "PEACH_SWIFT_ENDPOINT";
1532
+ var installs = /* @__PURE__ */ new Map();
1533
+ function swiftDistributionRoot() {
1534
+ const endpoint = process.env[SWIFT_ENDPOINT_ENV]?.trim().replace(/\/+$/, "");
1535
+ if (!endpoint) return Promise.resolve(null);
1536
+ const lock = parseSwiftDistributionLock(swift_distribution_lock_default);
1537
+ const host2 = swiftDistributionHost(process.platform, process.arch);
1538
+ if (!host2) {
1539
+ throw new Error(
1540
+ `peach has no Swift distribution for ${process.platform}-${process.arch}; it ships for macOS arm64 and Linux x64 and arm64`
1541
+ );
1542
+ }
1543
+ swiftToolchain(lock.release, lock.wasmSdkChecksum);
1544
+ const dir = import_node_path7.default.join(rnxHomeDir(), "swift", `${lock.id}-${host2}`);
1545
+ let pending = installs.get(dir);
1546
+ if (!pending) {
1547
+ pending = (async () => {
1548
+ if (!import_node_fs6.default.existsSync(import_node_path7.default.join(dir, SWIFT_DISTRIBUTION_MANIFEST))) {
1549
+ process.stderr.write(
1550
+ `peach: downloading Swift distribution ${lock.id} (${host2})\u2026
1551
+ `
1552
+ );
1553
+ await installVerifiedTarball({
1554
+ url: `${endpoint}/${swiftDistributionKey(lock.id, host2)}`,
1555
+ digest: {
1556
+ algorithm: "sha256",
1557
+ encoding: "hex",
1558
+ value: lock.hosts[host2].sha256
1559
+ },
1560
+ destDir: dir,
1561
+ installedMarker: SWIFT_DISTRIBUTION_MANIFEST,
1562
+ label: `Swift distribution ${lock.id} (${host2})`
1563
+ });
1564
+ }
1565
+ const manifest = swiftDistributionAt(dir);
1566
+ if (manifest?.id !== lock.id || manifest.host !== host2) {
1567
+ throw new Error(`${dir} does not hold Swift distribution ${lock.id} (${host2})`);
1568
+ }
1569
+ return dir;
1570
+ })();
1571
+ pending.catch(() => installs.delete(dir));
1572
+ installs.set(dir, pending);
1573
+ }
1574
+ return pending;
1575
+ }
1576
+ function swiftModuleToolchain(root) {
1577
+ const pin = swiftDistributionAt(root) ?? JSON.parse(import_node_fs6.default.readFileSync(import_node_path7.default.join(root, "toolchain.json"), "utf8"));
1578
+ return {
1579
+ release: pin.release,
1580
+ toolchainBin: swiftToolchain(pin.release, pin.wasmSdkChecksum)
1581
+ };
1582
+ }
1583
+
1248
1584
  // src/swift-submit.ts
1249
1585
  var SWIFT_COMPILE_PATH = "/api/swift-compile";
1250
1586
  var MAX_SWIFT_COMPILE_FILES = 256;
@@ -1306,19 +1642,19 @@ function httpSwiftCompileSubmit(context) {
1306
1642
  return outcome;
1307
1643
  };
1308
1644
  }
1309
- function isRecord(value) {
1645
+ function isRecord2(value) {
1310
1646
  return typeof value === "object" && value !== null && !Array.isArray(value);
1311
1647
  }
1312
1648
  function isSwiftNativeModules(value) {
1313
- return isRecord(value) && typeof value.packageId === "string" && typeof value.hash === "string" && isRecord(value.files) && isRecord(value.modules) && [...Object.values(value.files), ...Object.values(value.modules)].every(
1649
+ return isRecord2(value) && typeof value.packageId === "string" && typeof value.hash === "string" && isRecord2(value.files) && isRecord2(value.modules) && [...Object.values(value.files), ...Object.values(value.modules)].every(
1314
1650
  (names) => Array.isArray(names) && names.every((name) => typeof name === "string")
1315
1651
  ) && Array.isArray(value.defaultViewFiles) && value.defaultViewFiles.every((file) => typeof file === "string");
1316
1652
  }
1317
1653
  function isSwiftCompileOutcome(value) {
1318
- if (!isRecord(value)) return false;
1654
+ if (!isRecord2(value)) return false;
1319
1655
  switch (value.status) {
1320
1656
  case "published":
1321
- return typeof value.artifactUrl === "string" && typeof value.icuUrl === "string" && typeof value.hash === "string" && /^[a-f0-9]{64}$/.test(value.hash) && (value.imageUrls === void 0 || isRecord(value.imageUrls) && Object.values(value.imageUrls).every((url) => typeof url === "string")) && (value.native === void 0 || isSwiftNativeModules(value.native));
1657
+ return typeof value.artifactUrl === "string" && typeof value.icuUrl === "string" && typeof value.hash === "string" && /^[a-f0-9]{64}$/.test(value.hash) && (value.imageUrls === void 0 || isRecord2(value.imageUrls) && Object.values(value.imageUrls).every((url) => typeof url === "string")) && (value.native === void 0 || isSwiftNativeModules(value.native));
1322
1658
  case "compiling":
1323
1659
  return typeof value.hash === "string" && /^[a-f0-9]{64}$/.test(value.hash);
1324
1660
  case "refused":
@@ -1396,17 +1732,17 @@ var SKIP_SOURCE_DIRS = /* @__PURE__ */ new Set([
1396
1732
  var NATIVE_DESCRIPTOR = ".one-native-source.json";
1397
1733
  var NATIVE_GLUE = ".one-native-source.swift.txt";
1398
1734
  function swiftPackageId(packagePath) {
1399
- return import_node_path6.default.basename(packagePath).replace(/[^A-Za-z0-9_]/g, "_").replace(/^(\d)/, "_$1");
1735
+ return import_node_path8.default.basename(packagePath).replace(/[^A-Za-z0-9_]/g, "_").replace(/^(\d)/, "_$1");
1400
1736
  }
1401
1737
  function nativeSourceDescriptor(packagePath) {
1402
- packagePath = import_node_fs4.default.realpathSync(packagePath);
1403
- const file = import_node_path6.default.join(packagePath, NATIVE_DESCRIPTOR);
1404
- if (!import_node_fs4.default.existsSync(file)) return null;
1738
+ packagePath = import_node_fs7.default.realpathSync(packagePath);
1739
+ const file = import_node_path8.default.join(packagePath, NATIVE_DESCRIPTOR);
1740
+ if (!import_node_fs7.default.existsSync(file)) return null;
1405
1741
  const value = JSON.parse(
1406
1742
  readPackageFile(packagePath, file, MAX_SWIFT_COMPILE_SOURCE_BYTES).toString("utf8")
1407
1743
  );
1408
1744
  const invalid = () => new Error(`${file}: invalid One native source descriptor; run one typegen`);
1409
- if (!value || typeof value !== "object" || Reflect.get(value, "generatedBy") !== "one typegen" || !import_node_fs4.default.existsSync(import_node_path6.default.join(packagePath, NATIVE_GLUE))) {
1745
+ if (!value || typeof value !== "object" || Reflect.get(value, "generatedBy") !== "one typegen" || !import_node_fs7.default.existsSync(import_node_path8.default.join(packagePath, NATIVE_GLUE))) {
1410
1746
  throw invalid();
1411
1747
  }
1412
1748
  if (!isSwiftNativeModules(value) || value.packageId !== swiftPackageId(packagePath)) {
@@ -1415,12 +1751,12 @@ function nativeSourceDescriptor(packagePath) {
1415
1751
  return value;
1416
1752
  }
1417
1753
  function nativeSourceFiles(packagePath) {
1418
- packagePath = import_node_fs4.default.realpathSync(packagePath);
1419
- return [NATIVE_DESCRIPTOR, NATIVE_GLUE].map((name) => import_node_path6.default.join(packagePath, name)).filter((file) => import_node_fs4.default.existsSync(file));
1754
+ packagePath = import_node_fs7.default.realpathSync(packagePath);
1755
+ return [NATIVE_DESCRIPTOR, NATIVE_GLUE].map((name) => import_node_path8.default.join(packagePath, name)).filter((file) => import_node_fs7.default.existsSync(file));
1420
1756
  }
1421
1757
  var projects = /* @__PURE__ */ new Map();
1422
1758
  function projectFor(packagePath, hosted) {
1423
- packagePath = import_node_fs4.default.realpathSync(packagePath);
1759
+ packagePath = import_node_fs7.default.realpathSync(packagePath);
1424
1760
  const existing = projects.get(packagePath);
1425
1761
  if (existing) {
1426
1762
  if (hosted && !existing.hosted) {
@@ -1441,21 +1777,21 @@ function projectFor(packagePath, hosted) {
1441
1777
  return created;
1442
1778
  }
1443
1779
  function packageFiles(root) {
1444
- const canonicalRoot = import_node_fs4.default.realpathSync(root);
1780
+ const canonicalRoot = import_node_fs7.default.realpathSync(root);
1445
1781
  const found = [];
1446
1782
  const walk = (dir) => {
1447
- for (const entry of import_node_fs4.default.readdirSync(dir, { withFileTypes: true }).sort((left, right) => left.name.localeCompare(right.name))) {
1783
+ for (const entry of import_node_fs7.default.readdirSync(dir, { withFileTypes: true }).sort((left, right) => left.name.localeCompare(right.name))) {
1448
1784
  if (entry.name.startsWith(".") && entry.name !== NATIVE_DESCRIPTOR && entry.name !== NATIVE_GLUE || SKIP_SOURCE_DIRS.has(entry.name))
1449
1785
  continue;
1450
- const full = import_node_path6.default.join(dir, entry.name);
1786
+ const full = import_node_path8.default.join(dir, entry.name);
1451
1787
  if (entry.isSymbolicLink()) throw new Error(`swift input is a symlink: ${full}`);
1452
- const real = import_node_fs4.default.realpathSync(full);
1453
- const relative = import_node_path6.default.relative(canonicalRoot, real);
1454
- if (relative.startsWith(`..${import_node_path6.default.sep}`) || relative === ".." || import_node_path6.default.isAbsolute(relative)) {
1788
+ const real = import_node_fs7.default.realpathSync(full);
1789
+ const relative = import_node_path8.default.relative(canonicalRoot, real);
1790
+ if (relative.startsWith(`..${import_node_path8.default.sep}`) || relative === ".." || import_node_path8.default.isAbsolute(relative)) {
1455
1791
  throw new Error(`swift input escapes the selected package: ${full}`);
1456
1792
  }
1457
1793
  if (entry.isDirectory()) {
1458
- if (import_node_fs4.default.existsSync(import_node_path6.default.join(full, "Package.swift"))) continue;
1794
+ if (import_node_fs7.default.existsSync(import_node_path8.default.join(full, "Package.swift"))) continue;
1459
1795
  walk(full);
1460
1796
  } else if (entry.isFile()) {
1461
1797
  found.push(full);
@@ -1467,25 +1803,25 @@ function packageFiles(root) {
1467
1803
  return found;
1468
1804
  }
1469
1805
  function readPackageFile(root, file, maxBytes) {
1470
- const canonicalRoot = import_node_fs4.default.realpathSync(root);
1471
- const relative = import_node_path6.default.relative(canonicalRoot, import_node_fs4.default.realpathSync(file));
1472
- if (relative === ".." || relative.startsWith(`..${import_node_path6.default.sep}`) || import_node_path6.default.isAbsolute(relative)) {
1806
+ const canonicalRoot = import_node_fs7.default.realpathSync(root);
1807
+ const relative = import_node_path8.default.relative(canonicalRoot, import_node_fs7.default.realpathSync(file));
1808
+ if (relative === ".." || relative.startsWith(`..${import_node_path8.default.sep}`) || import_node_path8.default.isAbsolute(relative)) {
1473
1809
  throw new Error(`swift input escapes the selected package: ${file}`);
1474
1810
  }
1475
- let ancestor = import_node_path6.default.resolve(file);
1811
+ let ancestor = import_node_path8.default.resolve(file);
1476
1812
  while (ancestor !== canonicalRoot) {
1477
- if (import_node_fs4.default.lstatSync(ancestor).isSymbolicLink()) {
1813
+ if (import_node_fs7.default.lstatSync(ancestor).isSymbolicLink()) {
1478
1814
  throw new Error(`swift input is a symlink: ${ancestor}`);
1479
1815
  }
1480
- const parent = import_node_path6.default.dirname(ancestor);
1816
+ const parent = import_node_path8.default.dirname(ancestor);
1481
1817
  if (parent === ancestor)
1482
1818
  throw new Error(`swift input escapes the selected package: ${file}`);
1483
1819
  ancestor = parent;
1484
1820
  }
1485
- const expected = import_node_fs4.default.statSync(file);
1486
- const fd = import_node_fs4.default.openSync(file, import_node_fs4.default.constants.O_RDONLY | import_node_fs4.default.constants.O_NOFOLLOW);
1821
+ const expected = import_node_fs7.default.statSync(file);
1822
+ const fd = import_node_fs7.default.openSync(file, import_node_fs7.default.constants.O_RDONLY | import_node_fs7.default.constants.O_NOFOLLOW);
1487
1823
  try {
1488
- const stat = import_node_fs4.default.fstatSync(fd);
1824
+ const stat = import_node_fs7.default.fstatSync(fd);
1489
1825
  if (stat.dev !== expected.dev || stat.ino !== expected.ino) {
1490
1826
  throw new Error(`swift input changed while opening: ${file}`);
1491
1827
  }
@@ -1495,21 +1831,21 @@ function readPackageFile(root, file, maxBytes) {
1495
1831
  const bytes = Buffer.alloc(stat.size + 1);
1496
1832
  let offset = 0;
1497
1833
  while (offset < bytes.length) {
1498
- const count = import_node_fs4.default.readSync(fd, bytes, offset, bytes.length - offset, null);
1834
+ const count = import_node_fs7.default.readSync(fd, bytes, offset, bytes.length - offset, null);
1499
1835
  if (count === 0) break;
1500
1836
  offset += count;
1501
1837
  }
1502
- if (offset !== stat.size || import_node_fs4.default.fstatSync(fd).size !== stat.size) {
1838
+ if (offset !== stat.size || import_node_fs7.default.fstatSync(fd).size !== stat.size) {
1503
1839
  throw new Error(`swift input changed while reading: ${file}`);
1504
1840
  }
1505
1841
  return bytes.subarray(0, offset);
1506
1842
  } finally {
1507
- import_node_fs4.default.closeSync(fd);
1843
+ import_node_fs7.default.closeSync(fd);
1508
1844
  }
1509
1845
  }
1510
1846
  function sourceFiles(root) {
1511
1847
  const files = packageFiles(root).filter((file) => file.endsWith(".swift"));
1512
- if (files.length > MAX_SWIFT_COMPILE_FILES || files.reduce((total, file) => total + import_node_fs4.default.statSync(file).size, 0) > MAX_SWIFT_COMPILE_SOURCE_BYTES) {
1848
+ if (files.length > MAX_SWIFT_COMPILE_FILES || files.reduce((total, file) => total + import_node_fs7.default.statSync(file).size, 0) > MAX_SWIFT_COMPILE_SOURCE_BYTES) {
1513
1849
  throw new Error("swift sources exceed the compile service caps");
1514
1850
  }
1515
1851
  return files;
@@ -1530,7 +1866,7 @@ var RESOURCE_CONTENT_TYPES = {
1530
1866
  function buildSwiftResourceTable(project, baseUrl) {
1531
1867
  const absolute = resourceCandidateFiles(project.packagePath);
1532
1868
  const relative = absolute.map(
1533
- (file) => import_node_path6.default.relative(project.packagePath, file).split(import_node_path6.default.sep).join(import_node_path6.default.posix.sep)
1869
+ (file) => import_node_path8.default.relative(project.packagePath, file).split(import_node_path8.default.sep).join(import_node_path8.default.posix.sep)
1534
1870
  );
1535
1871
  const byRelative = new Map(absolute.map((file, index) => [relative[index], file]));
1536
1872
  const readContents = (candidate) => {
@@ -1554,7 +1890,7 @@ function buildSwiftResourceTable(project, baseUrl) {
1554
1890
  for (const { name, file, scale } of found) {
1555
1891
  const disk = byRelative.get(file);
1556
1892
  if (!disk) continue;
1557
- if (Object.keys(images).length >= MAX_SWIFT_COMPILE_IMAGES || imageBytes + import_node_fs4.default.statSync(disk).size > MAX_SWIFT_COMPILE_IMAGE_TOTAL_BYTES) {
1893
+ if (Object.keys(images).length >= MAX_SWIFT_COMPILE_IMAGES || imageBytes + import_node_fs7.default.statSync(disk).size > MAX_SWIFT_COMPILE_IMAGE_TOTAL_BYTES) {
1558
1894
  throw new Error("swift image pack exceeds the compile service caps");
1559
1895
  }
1560
1896
  const bytes = readPackageFile(
@@ -1563,11 +1899,11 @@ function buildSwiftResourceTable(project, baseUrl) {
1563
1899
  MAX_SWIFT_COMPILE_IMAGE_BYTES
1564
1900
  );
1565
1901
  imageBytes += bytes.length;
1566
- const hash = (0, import_node_crypto3.createHash)("sha256").update(bytes).digest("hex").slice(0, 16);
1567
- const ext = import_node_path6.default.posix.extname(file).toLowerCase();
1902
+ const hash = (0, import_node_crypto4.createHash)("sha256").update(bytes).digest("hex").slice(0, 16);
1903
+ const ext = import_node_path8.default.posix.extname(file).toLowerCase();
1568
1904
  table[name] = { uri: `${baseUrl}${RESOURCE_PATH}${hash}${ext}`, scale };
1569
1905
  images[name] = {
1570
- file: import_node_path6.default.posix.basename(file),
1906
+ file: import_node_path8.default.posix.basename(file),
1571
1907
  data: bytes.toString("base64")
1572
1908
  };
1573
1909
  watched.push(file);
@@ -1594,17 +1930,17 @@ var BUNDLE_MAX_FILES = MAX_SWIFT_COMPILE_RESOURCES;
1594
1930
  var BUNDLE_MAX_FILE_BYTES = MAX_SWIFT_COMPILE_RESOURCE_BYTES;
1595
1931
  var BUNDLE_MAX_TOTAL_BYTES = MAX_SWIFT_COMPILE_RESOURCE_TOTAL_BYTES;
1596
1932
  function buildSwiftBundleFiles(packagePath) {
1597
- packagePath = import_node_fs4.default.realpathSync(packagePath);
1933
+ packagePath = import_node_fs7.default.realpathSync(packagePath);
1598
1934
  const relative = resourceCandidateFiles(packagePath).map(
1599
- (file) => import_node_path6.default.relative(packagePath, file).split(import_node_path6.default.sep).join(import_node_path6.default.posix.sep)
1935
+ (file) => import_node_path8.default.relative(packagePath, file).split(import_node_path8.default.sep).join(import_node_path8.default.posix.sep)
1600
1936
  );
1601
1937
  const files = {};
1602
1938
  const watched = [];
1603
1939
  let total = 0;
1604
1940
  for (const { base, file } of enumerateBundleJson(relative)) {
1605
1941
  watched.push(file);
1606
- const disk = import_node_path6.default.join(packagePath, ...file.split("/"));
1607
- if (Object.keys(files).length >= BUNDLE_MAX_FILES || total + import_node_fs4.default.statSync(disk).size > BUNDLE_MAX_TOTAL_BYTES) {
1942
+ const disk = import_node_path8.default.join(packagePath, ...file.split("/"));
1943
+ if (Object.keys(files).length >= BUNDLE_MAX_FILES || total + import_node_fs7.default.statSync(disk).size > BUNDLE_MAX_TOTAL_BYTES) {
1608
1944
  throw new Error(
1609
1945
  `swift bundle pack exceeds ${BUNDLE_MAX_FILES} files / ${BUNDLE_MAX_TOTAL_BYTES} bytes`
1610
1946
  );
@@ -1619,12 +1955,12 @@ function serveSwiftResource(project, key) {
1619
1955
  return project.resourceFiles.get(key) ?? project.resourcesPrevious.get(key) ?? null;
1620
1956
  }
1621
1957
  function linkedModuleRoots(packagePath) {
1622
- packagePath = import_node_fs4.default.realpathSync(packagePath);
1958
+ packagePath = import_node_fs7.default.realpathSync(packagePath);
1623
1959
  let manifest;
1624
1960
  try {
1625
1961
  manifest = readPackageFile(
1626
1962
  packagePath,
1627
- import_node_path6.default.join(packagePath, "Package.swift"),
1963
+ import_node_path8.default.join(packagePath, "Package.swift"),
1628
1964
  MAX_SWIFT_COMPILE_SOURCE_BYTES
1629
1965
  ).toString("utf8");
1630
1966
  } catch {
@@ -1633,35 +1969,35 @@ function linkedModuleRoots(packagePath) {
1633
1969
  const roots = /* @__PURE__ */ new Set();
1634
1970
  const dependency = /\.package\(\s*path:\s*"([^"]+)"\s*\)/g;
1635
1971
  for (const match of manifest.replace(/^\s*\/\/.*$/gm, "").matchAll(dependency)) {
1636
- const root = import_node_path6.default.resolve(packagePath, match[1]);
1637
- if (import_node_fs4.default.existsSync(import_node_path6.default.join(root, "Package.swift"))) roots.add(root);
1972
+ const root = import_node_path8.default.resolve(packagePath, match[1]);
1973
+ if (import_node_fs7.default.existsSync(import_node_path8.default.join(root, "Package.swift"))) roots.add(root);
1638
1974
  }
1639
1975
  return [...roots].sort();
1640
1976
  }
1641
1977
  function sourceStamp(packagePath, moduleRootOverride, hosted = false) {
1642
- const hash = (0, import_node_crypto3.createHash)("sha256");
1978
+ const hash = (0, import_node_crypto4.createHash)("sha256");
1643
1979
  hash.update(packagePath);
1644
1980
  const projectInputs = new Set(packageFiles(packagePath));
1645
1981
  for (const file of [...projectInputs].sort()) {
1646
- hash.update(import_node_path6.default.relative(packagePath, file));
1647
- const stat = import_node_fs4.default.statSync(file);
1982
+ hash.update(import_node_path8.default.relative(packagePath, file));
1983
+ const stat = import_node_fs7.default.statSync(file);
1648
1984
  hash.update(`${stat.mtimeMs}/${stat.ctimeMs}/${stat.size}`);
1649
1985
  }
1650
1986
  const moduleRoot = hosted ? void 0 : moduleRootOverride ?? linkedModuleRoots(packagePath).find(
1651
- (root) => import_node_fs4.default.existsSync(import_node_path6.default.join(root, "toolchain.json"))
1987
+ (root) => import_node_fs7.default.existsSync(import_node_path8.default.join(root, "toolchain.json"))
1652
1988
  );
1653
1989
  if (moduleRoot) {
1654
1990
  hash.update(moduleRoot);
1655
1991
  for (const relative of swiftModuleInputFiles(moduleRoot)) {
1656
1992
  hash.update(relative);
1657
- hash.update(String(import_node_fs4.default.statSync(import_node_path6.default.join(moduleRoot, relative)).mtimeMs));
1993
+ hash.update(String(import_node_fs7.default.statSync(import_node_path8.default.join(moduleRoot, relative)).mtimeMs));
1658
1994
  }
1659
1995
  }
1660
1996
  return hash.digest("hex").slice(0, 16);
1661
1997
  }
1662
1998
  function entryRootId(packagePath, file) {
1663
- const relative = import_node_path6.default.relative(packagePath, file).split(import_node_path6.default.sep).join(import_node_path6.default.posix.sep);
1664
- return `${import_node_path6.default.basename(packagePath)}${import_node_path6.default.posix.sep}${relative}`;
1999
+ const relative = import_node_path8.default.relative(packagePath, file).split(import_node_path8.default.sep).join(import_node_path8.default.posix.sep);
2000
+ return `${import_node_path8.default.basename(packagePath)}${import_node_path8.default.posix.sep}${relative}`;
1665
2001
  }
1666
2002
  function icuUrl(origin, artifact) {
1667
2003
  return "url" in artifact.icu ? artifact.icu.url : `${origin}${ICU_PATH}${artifact.icu.sha256}`;
@@ -1671,12 +2007,12 @@ function packageSources(packagePath) {
1671
2007
  if (sources.length > MAX_SWIFT_COMPILE_FILES)
1672
2008
  throw new Error("swift source file cap exceeded");
1673
2009
  let total = 0;
1674
- for (const file of sources) total += import_node_fs4.default.statSync(file).size;
2010
+ for (const file of sources) total += import_node_fs7.default.statSync(file).size;
1675
2011
  if (total > MAX_SWIFT_COMPILE_SOURCE_BYTES)
1676
2012
  throw new Error("swift source byte cap exceeded");
1677
2013
  const files = {};
1678
2014
  for (const file of sources) {
1679
- const relative = import_node_path6.default.relative(packagePath, file).split(import_node_path6.default.sep).join(import_node_path6.default.posix.sep);
2015
+ const relative = import_node_path8.default.relative(packagePath, file).split(import_node_path8.default.sep).join(import_node_path8.default.posix.sep);
1680
2016
  files[relative] = readPackageFile(
1681
2017
  packagePath,
1682
2018
  file,
@@ -1696,7 +2032,7 @@ function packageSnapshot(project) {
1696
2032
  ...native ? {
1697
2033
  glue: readPackageFile(
1698
2034
  project.packagePath,
1699
- import_node_path6.default.join(project.packagePath, NATIVE_GLUE),
2035
+ import_node_path8.default.join(project.packagePath, NATIVE_GLUE),
1700
2036
  MAX_SWIFT_COMPILE_SOURCE_BYTES
1701
2037
  ).toString("utf8")
1702
2038
  } : {}
@@ -1734,51 +2070,36 @@ async function compile(packagePath, entry, stamp, moduleRootOverride, hosted, sn
1734
2070
  package: content
1735
2071
  };
1736
2072
  const moduleRoot = moduleRootOverride ?? linkedModuleRoots(packagePath).find(
1737
- (root) => import_node_fs4.default.existsSync(import_node_path6.default.join(root, "toolchain.json"))
1738
- );
2073
+ (root) => import_node_fs7.default.existsSync(import_node_path8.default.join(root, "toolchain.json"))
2074
+ ) ?? await swiftDistributionRoot();
1739
2075
  if (!moduleRoot)
1740
2076
  return {
1741
2077
  ...await compileRemote(packagePath, entry, snapshot),
1742
2078
  stamp,
1743
2079
  package: content
1744
2080
  };
1745
- const toolchain = localSwiftToolchain(moduleRoot);
1746
- if (!toolchain)
1747
- throw new Error(
1748
- `the Swift toolchain ${moduleRoot}/toolchain.json names is not installed under ~/Library/Developer/Toolchains`
1749
- );
2081
+ const toolchain = swiftModuleToolchain(moduleRoot);
1750
2082
  const artifact = await compileSwiftProjectUnit(snapshotCompileInput(snapshot, entry), {
1751
2083
  // the compile rewrites Sources/App in its root before swiftpm builds, and
1752
2084
  // its lock orders one process only: two vites on one root (a lane's dev
1753
2085
  // server and a capture, or two checkouts) build each other's sources. so
1754
2086
  // each app and module checkout gets its own root, which keeps the same
1755
2087
  // app's incremental build across restarts.
1756
- buildRoot: process.env.CONTRAST_SWIFT_BUILD_ROOT ?? import_node_path6.default.join(
1757
- import_node_os4.default.tmpdir(),
2088
+ buildRoot: process.env.CONTRAST_SWIFT_BUILD_ROOT ?? import_node_path8.default.join(
2089
+ import_node_os5.default.tmpdir(),
1758
2090
  "contrast-swift-build",
1759
- (0, import_node_crypto3.createHash)("sha256").update(`${moduleRoot}\0${import_node_path6.default.resolve(packagePath)}`).digest("hex").slice(0, 16)
2091
+ (0, import_node_crypto4.createHash)("sha256").update(`${moduleRoot}\0${import_node_path8.default.resolve(packagePath)}`).digest("hex").slice(0, 16)
1760
2092
  ),
1761
2093
  moduleRoot,
1762
2094
  ...toolchain
1763
2095
  });
1764
2096
  return { ...artifact, stamp, package: content };
1765
2097
  }
1766
- function localSwiftToolchain(moduleRoot) {
1767
- const manifest = import_node_path6.default.join(moduleRoot, "toolchain.json");
1768
- if (!import_node_fs4.default.existsSync(manifest)) return null;
1769
- const toolchain = JSON.parse(import_node_fs4.default.readFileSync(manifest, "utf8"));
1770
- const release = toolchain && typeof toolchain === "object" ? Reflect.get(toolchain, "release") : void 0;
1771
- if (typeof release !== "string") {
1772
- throw new Error(`swift toolchain manifest at ${moduleRoot} has no release`);
1773
- }
1774
- const toolchainBin = swiftToolchainBin(release);
1775
- return import_node_fs4.default.existsSync(import_node_path6.default.join(toolchainBin, "swift")) ? { release, toolchainBin } : null;
1776
- }
1777
2098
  async function compileRemote(packagePath, entry, snapshot, hosted) {
1778
2099
  const auth = hosted ? null : resolveCliAuth();
1779
2100
  if (!hosted && (!auth || auth.kind === "github")) {
1780
2101
  throw new Error(
1781
- `compiling ${import_node_path6.default.basename(packagePath)} for Peach needs \`peach login\` or PEACH_API_KEY: this peachsim has no local SwiftUI module, so Contrast compiles it`
2102
+ `compiling ${import_node_path8.default.basename(packagePath)} for Peach needs \`peach login\` or PEACH_API_KEY: this peachsim has no local SwiftUI module, so Contrast compiles it`
1782
2103
  );
1783
2104
  }
1784
2105
  const origin = hosted?.origin ?? resolveContrastBackendOrigin(auth?.kind === "session" ? auth.origin : null);
@@ -1808,7 +2129,7 @@ async function compileRemote(packagePath, entry, snapshot, hosted) {
1808
2129
  );
1809
2130
  if (descriptor && address.native?.hash !== descriptor.hash) {
1810
2131
  throw new Error(
1811
- `${import_node_path6.default.basename(packagePath)}: Contrast compiled native contract ${address.native?.hash ?? "none"} but one typegen wrote ${descriptor.hash}; the app's One and the compile host's differ, or the compile host is older than this peachsim`
2132
+ `${import_node_path8.default.basename(packagePath)}: Contrast compiled native contract ${address.native?.hash ?? "none"} but one typegen wrote ${descriptor.hash}; the app's One and the compile host's differ, or the compile host is older than this peachsim`
1812
2133
  );
1813
2134
  }
1814
2135
  const response = await fetch(address.url, { signal });
@@ -1881,17 +2202,17 @@ function artifactFor(project, entry, moduleRoot) {
1881
2202
  return fresh;
1882
2203
  }
1883
2204
  function swiftPackageWatchFiles(packagePath, moduleRoot) {
1884
- packagePath = import_node_fs4.default.realpathSync(packagePath);
2205
+ packagePath = import_node_fs7.default.realpathSync(packagePath);
1885
2206
  return [
1886
- import_node_path6.default.join(packagePath, "Package.swift"),
2207
+ import_node_path8.default.join(packagePath, "Package.swift"),
1887
2208
  ...sourceFiles(packagePath),
1888
2209
  ...nativeSourceFiles(packagePath),
1889
2210
  ...resourceCandidateFiles(packagePath),
1890
- ...moduleRoot ? swiftModuleInputFiles(moduleRoot).map((file) => import_node_path6.default.join(moduleRoot, file)) : []
2211
+ ...moduleRoot ? swiftModuleInputFiles(moduleRoot).map((file) => import_node_path8.default.join(moduleRoot, file)) : []
1891
2212
  ];
1892
2213
  }
1893
2214
  async function swiftPackageMetadata(packagePath, packageName, moduleRoot, origin, hosted) {
1894
- packagePath = import_node_fs4.default.realpathSync(packagePath);
2215
+ packagePath = import_node_fs7.default.realpathSync(packagePath);
1895
2216
  const mains = sourceFiles(packagePath).filter(
1896
2217
  (file) => /@main\s+(?:public\s+)?struct\s+\w+\s*:/.test(
1897
2218
  readPackageFile(packagePath, file, MAX_SWIFT_COMPILE_SOURCE_BYTES).toString("utf8")
@@ -1904,7 +2225,7 @@ async function swiftPackageMetadata(packagePath, packageName, moduleRoot, origin
1904
2225
  );
1905
2226
  }
1906
2227
  const project = projectFor(packagePath, hosted);
1907
- const entry = mains.length === 1 ? import_node_path6.default.relative(packagePath, mains[0]).split(import_node_path6.default.sep).join(import_node_path6.default.posix.sep) : Object.entries(native?.files ?? {}).find(
2228
+ const entry = mains.length === 1 ? import_node_path8.default.relative(packagePath, mains[0]).split(import_node_path8.default.sep).join(import_node_path8.default.posix.sep) : Object.entries(native?.files ?? {}).find(
1908
2229
  ([_file, names]) => names.length > 0
1909
2230
  )?.[0];
1910
2231
  if (!entry) throw new Error(`swift package ${packageName} has no native module source`);
@@ -1993,12 +2314,12 @@ function artifactUrl(project, artifact) {
1993
2314
  return `${serverOrigin()}${ARTIFACT_PATH2}${artifact.hash}.wasm`;
1994
2315
  }
1995
2316
  function packageFor(file) {
1996
- let dir = import_node_path7.default.dirname(file);
2317
+ let dir = import_node_path9.default.dirname(file);
1997
2318
  const stop = devServer?.config.root;
1998
2319
  for (; ; ) {
1999
- if (import_node_fs5.default.existsSync(import_node_path7.default.join(dir, "Package.swift"))) return dir;
2000
- if (stop !== void 0 && dir === stop || import_node_path7.default.dirname(dir) === dir) break;
2001
- dir = import_node_path7.default.dirname(dir);
2320
+ if (import_node_fs8.default.existsSync(import_node_path9.default.join(dir, "Package.swift"))) return dir;
2321
+ if (stop !== void 0 && dir === stop || import_node_path9.default.dirname(dir) === dir) break;
2322
+ dir = import_node_path9.default.dirname(dir);
2002
2323
  }
2003
2324
  throw new Error(
2004
2325
  `no Package.swift above ${file}${stop === void 0 ? "" : ` (searched up to ${stop})`}; a .swift import needs a swiftpm package like the one in packages/sootsim-swift/example`
@@ -2019,9 +2340,9 @@ function swiftPlugin(options = {}) {
2019
2340
  if (!resolved) throw new Error(`cannot resolve swift source ${source}`);
2020
2341
  let id = resolved.id;
2021
2342
  if (importer && (source.startsWith("./") || source.startsWith("../"))) {
2022
- const raw2 = import_node_path7.default.resolve(import_node_path7.default.dirname(importer.split("?")[0] ?? importer), source);
2343
+ const raw2 = import_node_path9.default.resolve(import_node_path9.default.dirname(importer.split("?")[0] ?? importer), source);
2023
2344
  try {
2024
- if (import_node_fs5.default.realpathSync(raw2) === import_node_fs5.default.realpathSync(resolved.id)) id = raw2;
2345
+ if (import_node_fs8.default.realpathSync(raw2) === import_node_fs8.default.realpathSync(resolved.id)) id = raw2;
2025
2346
  } catch {
2026
2347
  }
2027
2348
  }
@@ -2030,22 +2351,22 @@ function swiftPlugin(options = {}) {
2030
2351
  async load(id) {
2031
2352
  if (!id.startsWith(VIRTUAL_PREFIX)) return null;
2032
2353
  const file = id.slice(VIRTUAL_PREFIX.length);
2033
- if (!import_node_fs5.default.existsSync(file)) throw new Error(`swift source ${file} no longer exists`);
2354
+ if (!import_node_fs8.default.existsSync(file)) throw new Error(`swift source ${file} no longer exists`);
2034
2355
  const packagePath = options.packagePath ?? packageFor(file);
2035
2356
  const project = projectFor(packagePath);
2036
- const entry = import_node_path7.default.relative(packagePath, file).split(import_node_path7.default.sep).join(import_node_path7.default.posix.sep);
2357
+ const entry = import_node_path9.default.relative(packagePath, file).split(import_node_path9.default.sep).join(import_node_path9.default.posix.sep);
2037
2358
  for (const source of [
2038
2359
  ...sourceFiles(packagePath),
2039
2360
  ...nativeSourceFiles(packagePath)
2040
2361
  ])
2041
2362
  this.addWatchFile(source);
2042
- this.addWatchFile(import_node_path7.default.join(packagePath, "Package.swift"));
2363
+ this.addWatchFile(import_node_path9.default.join(packagePath, "Package.swift"));
2043
2364
  const moduleRoot = linkedModuleRoots(packagePath).find(
2044
- (root) => import_node_fs5.default.existsSync(import_node_path7.default.join(root, "toolchain.json"))
2365
+ (root) => import_node_fs8.default.existsSync(import_node_path9.default.join(root, "toolchain.json"))
2045
2366
  );
2046
2367
  if (moduleRoot)
2047
2368
  for (const relative of swiftModuleInputFiles(moduleRoot))
2048
- this.addWatchFile(import_node_path7.default.join(moduleRoot, relative));
2369
+ this.addWatchFile(import_node_path9.default.join(moduleRoot, relative));
2049
2370
  let artifact;
2050
2371
  try {
2051
2372
  artifact = await artifactFor(project, entry);
@@ -2064,7 +2385,7 @@ function swiftPlugin(options = {}) {
2064
2385
  ...artifact.package.resources.watched,
2065
2386
  ...artifact.package.bundleFiles.watched
2066
2387
  ])
2067
- this.addWatchFile(import_node_path7.default.join(packagePath, ...watched.split(import_node_path7.default.posix.sep)));
2388
+ this.addWatchFile(import_node_path9.default.join(packagePath, ...watched.split(import_node_path9.default.posix.sep)));
2068
2389
  const colors = artifact.package.resources.colors;
2069
2390
  const symbols = artifact.package.resources.symbols;
2070
2391
  const bundleFiles = artifact.package.bundleFiles.files;