peachsim 0.1.796 → 0.1.798

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 (86) hide show
  1. package/cli/cloud-test-tunnel.ts +1 -1
  2. package/cli/outbound-endpoints.ts +6 -1
  3. package/dist-lib/agent-daemon-client.cjs +1 -1
  4. package/dist-lib/agent-events.cjs +1 -1
  5. package/dist-lib/agent-identity.cjs +1 -1
  6. package/dist-lib/agent-sessions.cjs +1 -1
  7. package/dist-lib/attached-projects.cjs +1 -1
  8. package/dist-lib/auth/shared-session.cjs +1 -1
  9. package/dist-lib/backend-origin.cjs +1 -1
  10. package/dist-lib/beta.cjs +1 -1
  11. package/dist-lib/beta.mjs +1 -1
  12. package/dist-lib/bridge-constants.cjs +1 -1
  13. package/dist-lib/bridge-contract-input.cjs +1 -1
  14. package/dist-lib/bridge-contract-input.mjs +1 -1
  15. package/dist-lib/bridge-contract.cjs +1 -1
  16. package/dist-lib/bridge-contract.mjs +1 -1
  17. package/dist-lib/bundle-channel.cjs +383 -346
  18. package/dist-lib/capture-contract.cjs +1 -1
  19. package/dist-lib/capture-contract.mjs +1 -1
  20. package/dist-lib/cli-constants.cjs +1 -1
  21. package/dist-lib/cloud-contract.cjs +1 -1
  22. package/dist-lib/cloud-contract.mjs +1 -1
  23. package/dist-lib/cloud-test-args.cjs +1 -1
  24. package/dist-lib/cloud-test-args.mjs +1 -1
  25. package/dist-lib/cloud.cjs +1 -1
  26. package/dist-lib/cloud.mjs +1 -1
  27. package/dist-lib/config.cjs +1 -1
  28. package/dist-lib/detox/index.cjs +1 -1
  29. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  30. package/dist-lib/expo-swift-bundle.cjs +356 -326
  31. package/dist-lib/expo-swift-metadata.cjs +1 -1
  32. package/dist-lib/expo-swift-metadata.mjs +1 -1
  33. package/dist-lib/home-paths.cjs +1 -1
  34. package/dist-lib/host/bridge-host.cjs +679 -565
  35. package/dist-lib/host/fetch-proxy-handler.cjs +1 -1
  36. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  37. package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
  38. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  39. package/dist-lib/host/websocket-proxy.cjs +1 -1
  40. package/dist-lib/index.cjs +401 -178
  41. package/dist-lib/jump-to-source-babel.cjs +1 -1
  42. package/dist-lib/jump-to-source-native.cjs +1 -1
  43. package/dist-lib/kotlin-host.cjs +1 -1
  44. package/dist-lib/menu.cjs +1 -1
  45. package/dist-lib/menu.mjs +1 -1
  46. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  47. package/dist-lib/metro-fingerprint-registry.mjs +1 -1
  48. package/dist-lib/metro-production-bundle.cjs +1 -1
  49. package/dist-lib/metro-production-bundle.mjs +1 -1
  50. package/dist-lib/metro.cjs +1 -1
  51. package/dist-lib/native-app-identity.cjs +1 -1
  52. package/dist-lib/native-app-identity.mjs +1 -1
  53. package/dist-lib/native-firebase-metadata.cjs +1 -1
  54. package/dist-lib/native-firebase-metadata.mjs +1 -1
  55. package/dist-lib/plist.cjs +1 -1
  56. package/dist-lib/plist.mjs +1 -1
  57. package/dist-lib/profiles.cjs +1 -1
  58. package/dist-lib/public-brand.cjs +1 -1
  59. package/dist-lib/react-native-host-modules.cjs +1 -1
  60. package/dist-lib/react-native-host-modules.mjs +1 -1
  61. package/dist-lib/render-mode.cjs +1 -1
  62. package/dist-lib/scripts/dev-server-scanner.cjs +85 -1
  63. package/dist-lib/sdk.cjs +1 -1
  64. package/dist-lib/sdk.mjs +1 -1
  65. package/dist-lib/skills.cjs +976 -842
  66. package/dist-lib/swift-compile.cjs +30 -5
  67. package/dist-lib/swift-compile.mjs +29 -5
  68. package/dist-lib/swift-package.cjs +1 -1
  69. package/dist-lib/swift-package.mjs +1 -1
  70. package/dist-lib/swift-submit.cjs +1 -1
  71. package/dist-lib/swift-submit.mjs +1 -1
  72. package/dist-lib/swift-toolchain.cjs +1 -1
  73. package/dist-lib/swift.cjs +1 -1
  74. package/dist-lib/vite-swift.cjs +415 -358
  75. package/dist-lib/vite.cjs +240 -15
  76. package/package.json +1 -1
  77. package/scripts/dev-server-scanner.ts +16 -5
  78. package/src/expo-swift-host.ts +8 -4
  79. package/src/one-widget-discovery.ts +17 -0
  80. package/src/one-widget-metadata.ts +208 -0
  81. package/src/one-widget-package.ts +11 -165
  82. package/src/oneWidgetContract.ts +122 -0
  83. package/src/swift-compile.ts +31 -5
  84. package/src/swift-host.ts +2 -48
  85. package/src/swift-source-file.ts +48 -0
  86. package/src/vite-plugin-one.ts +18 -1
package/dist-lib/vite.cjs CHANGED
@@ -1,4 +1,4 @@
1
- /*! rnx v0.1.796 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
1
+ /*! rnx v0.1.798 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
2
2
  let __sootsim_import_meta_url = '', __sootsim_import_meta_dirname = ''; try { __sootsim_import_meta_url = require('url').pathToFileURL(__filename).href; __sootsim_import_meta_dirname = __dirname; } catch {}
3
3
  "use strict";
4
4
  var __create = Object.create;
@@ -38,8 +38,8 @@ __export(vite_plugin_one_exports, {
38
38
  });
39
39
  module.exports = __toCommonJS(vite_plugin_one_exports);
40
40
  var import_fs2 = __toESM(require("fs"), 1);
41
- var import_node_crypto2 = require("node:crypto");
42
- var import_node_module = require("node:module");
41
+ var import_node_crypto3 = require("node:crypto");
42
+ var import_node_module2 = require("node:module");
43
43
  var import_path2 = __toESM(require("path"), 1);
44
44
  var import_ws = require("ws");
45
45
 
@@ -653,6 +653,224 @@ async function handleReplacementModuleRequest(req, res, options = {}) {
653
653
  return true;
654
654
  }
655
655
 
656
+ // src/one-widget-metadata.ts
657
+ var import_node_child_process2 = require("node:child_process");
658
+ var import_node_crypto2 = require("node:crypto");
659
+ var import_node_fs5 = __toESM(require("node:fs"), 1);
660
+ var import_node_module = require("node:module");
661
+ var import_node_path5 = __toESM(require("node:path"), 1);
662
+ var import_node_util = require("node:util");
663
+
664
+ // cli/internal-child.ts
665
+ var RNX_FORKED_SCRIPT_ENV = "PEACH_RUNS_FORKED_SCRIPTS";
666
+
667
+ // src/is-record.ts
668
+ function isRecord(value) {
669
+ return typeof value === "object" && value !== null && !Array.isArray(value);
670
+ }
671
+
672
+ // src/swift-source-file.ts
673
+ var import_node_fs4 = __toESM(require("node:fs"), 1);
674
+ var import_node_path4 = __toESM(require("node:path"), 1);
675
+ function readPackageFile(root, file, maxBytes) {
676
+ const canonicalRoot = import_node_fs4.default.realpathSync(root);
677
+ const relative2 = import_node_path4.default.relative(canonicalRoot, import_node_fs4.default.realpathSync(file));
678
+ if (relative2 === ".." || relative2.startsWith(`..${import_node_path4.default.sep}`) || import_node_path4.default.isAbsolute(relative2)) {
679
+ throw new Error(`swift input escapes the selected package: ${file}`);
680
+ }
681
+ let ancestor = import_node_path4.default.resolve(file);
682
+ while (ancestor !== canonicalRoot) {
683
+ if (import_node_fs4.default.lstatSync(ancestor).isSymbolicLink()) {
684
+ throw new Error(`swift input is a symlink: ${ancestor}`);
685
+ }
686
+ const parent = import_node_path4.default.dirname(ancestor);
687
+ if (parent === ancestor)
688
+ throw new Error(`swift input escapes the selected package: ${file}`);
689
+ ancestor = parent;
690
+ }
691
+ const expected = import_node_fs4.default.statSync(file);
692
+ const fd = import_node_fs4.default.openSync(file, import_node_fs4.default.constants.O_RDONLY | import_node_fs4.default.constants.O_NOFOLLOW);
693
+ try {
694
+ const stat = import_node_fs4.default.fstatSync(fd);
695
+ if (stat.dev !== expected.dev || stat.ino !== expected.ino) {
696
+ throw new Error(`swift input changed while opening: ${file}`);
697
+ }
698
+ if (!stat.isFile() || stat.size > maxBytes) {
699
+ throw new Error(`swift input exceeds ${maxBytes} bytes: ${file}`);
700
+ }
701
+ const bytes = Buffer.alloc(stat.size + 1);
702
+ let offset = 0;
703
+ while (offset < bytes.length) {
704
+ const count = import_node_fs4.default.readSync(fd, bytes, offset, bytes.length - offset, null);
705
+ if (count === 0) break;
706
+ offset += count;
707
+ }
708
+ if (offset !== stat.size || import_node_fs4.default.fstatSync(fd).size !== stat.size) {
709
+ throw new Error(`swift input changed while reading: ${file}`);
710
+ }
711
+ return bytes.subarray(0, offset);
712
+ } finally {
713
+ import_node_fs4.default.closeSync(fd);
714
+ }
715
+ }
716
+
717
+ // src/swift-submit.ts
718
+ var SWIFT_PACKAGE_PATH = "/__peach/swift-package/";
719
+ var SWIFT_HMR_PATH = "/__peach/swift-hmr";
720
+ var MAX_SWIFT_COMPILE_SOURCE_BYTES = 2 * 1024 * 1024;
721
+ var MAX_SWIFT_COMPILE_RESOURCE_BYTES = 2 * 1024 * 1024;
722
+ var MAX_SWIFT_COMPILE_RESOURCE_TOTAL_BYTES = 8 * 1024 * 1024;
723
+ var MAX_SWIFT_COMPILE_IMAGE_BYTES = 4 * 1024 * 1024;
724
+ var MAX_SWIFT_COMPILE_IMAGE_TOTAL_BYTES = 16 * 1024 * 1024;
725
+
726
+ // src/one-widget-metadata.ts
727
+ var run = (0, import_node_util.promisify)(import_node_child_process2.execFile);
728
+ var configs = /* @__PURE__ */ new Map();
729
+ var reads = /* @__PURE__ */ new Map();
730
+ var CONFIG_CHILD = `
731
+ import fs from 'node:fs';
732
+ import { loadUserOneOptions } from 'one/vite';
733
+ const { config, oneOptions } = await loadUserOneOptions('serve', true);
734
+ const app = oneOptions.native?.app;
735
+ const widgets = app?.ios?.widgets;
736
+ fs.writeFileSync(process.argv[2], JSON.stringify({
737
+ widget: widgets ? { appName: app.name, bundleId: app.ios.bundleId,
738
+ suite: widgets.appGroup, kind: widgets.kind, displayName: widgets.displayName,
739
+ description: widgets.description } : null,
740
+ urlSchemes: app?.scheme === undefined ? [] : Array.isArray(app.scheme) ? app.scheme : [app.scheme],
741
+ watched: [config.path, ...config.dependencies]
742
+ }));
743
+ `;
744
+ function configStamp(files) {
745
+ return JSON.stringify(
746
+ files.map((file) => {
747
+ if (!import_node_fs5.default.existsSync(file)) return [file, null];
748
+ const stat = import_node_fs5.default.statSync(file);
749
+ return [file, stat.mtimeMs, stat.ctimeMs, stat.size];
750
+ })
751
+ );
752
+ }
753
+ async function readConfig(root) {
754
+ const cached = configs.get(root);
755
+ if (cached && cached.stamp === configStamp(cached.watched)) return cached;
756
+ const reading = reads.get(root);
757
+ if (reading) return reading;
758
+ const promise = (async () => {
759
+ (0, import_node_module.createRequire)(import_node_path5.default.join(root, "package.json")).resolve("one/vite");
760
+ const cache = import_node_path5.default.join(root, "node_modules/.cache/peach-widget-config");
761
+ import_node_fs5.default.mkdirSync(cache, { recursive: true });
762
+ const directory = import_node_fs5.default.mkdtempSync(import_node_path5.default.join(cache, "read-"));
763
+ const script = import_node_path5.default.join(directory, "read.mjs");
764
+ const result = import_node_path5.default.join(directory, "result.json");
765
+ import_node_fs5.default.writeFileSync(script, CONFIG_CHILD);
766
+ try {
767
+ await run(process.execPath, [script, result], {
768
+ cwd: root,
769
+ env: { ...process.env, [RNX_FORKED_SCRIPT_ENV]: "1" },
770
+ timeout: 3e4,
771
+ maxBuffer: 1024 * 1024
772
+ });
773
+ const value = JSON.parse(import_node_fs5.default.readFileSync(result, "utf8"));
774
+ if (!isRecord(value) || !Array.isArray(value.watched) || !value.watched.every((file) => typeof file === "string"))
775
+ throw new Error("One config loader returned invalid dependencies");
776
+ if (!Array.isArray(value.urlSchemes) || !value.urlSchemes.every(
777
+ (scheme) => typeof scheme === "string" && /^[A-Za-z][A-Za-z0-9+.-]*$/.test(scheme)
778
+ ))
779
+ throw new Error("One config loader returned invalid native.app.scheme");
780
+ let widget = null;
781
+ if (value.widget !== null) {
782
+ const entry = value.widget;
783
+ if (!isRecord(entry) || typeof entry.appName !== "string" || !/^[A-Za-z][A-Za-z0-9_]*$/.test(entry.appName) || typeof entry.bundleId !== "string" || !entry.bundleId || typeof entry.suite !== "string" || !entry.suite || typeof entry.kind !== "string" || !entry.kind || typeof entry.displayName !== "string" || !entry.displayName || typeof entry.description !== "string" || !entry.description)
784
+ throw new Error("One config loader returned invalid native.app.ios.widgets");
785
+ widget = {
786
+ appName: entry.appName,
787
+ bundleId: entry.bundleId,
788
+ suite: entry.suite,
789
+ kind: entry.kind,
790
+ displayName: entry.displayName,
791
+ description: entry.description
792
+ };
793
+ }
794
+ const watched = [
795
+ .../* @__PURE__ */ new Set([
796
+ import_node_path5.default.join(root, "package.json"),
797
+ ...value.watched.map((file) => import_node_path5.default.resolve(root, file))
798
+ ])
799
+ ];
800
+ const loaded = {
801
+ widget,
802
+ urlSchemes: value.urlSchemes,
803
+ watched,
804
+ stamp: configStamp(watched)
805
+ };
806
+ configs.set(root, loaded);
807
+ return loaded;
808
+ } finally {
809
+ import_node_fs5.default.rmSync(directory, { recursive: true, force: true });
810
+ }
811
+ })();
812
+ reads.set(root, promise);
813
+ try {
814
+ return await promise;
815
+ } finally {
816
+ reads.delete(root);
817
+ }
818
+ }
819
+ async function readOneWidgetSources(appRoot) {
820
+ const root = import_node_fs5.default.realpathSync(appRoot);
821
+ const config = await readConfig(root);
822
+ if (!config.widget) return null;
823
+ const widget = config.widget;
824
+ const sourceFiles = {
825
+ "OneWidget.swift": import_node_path5.default.join(root, "ios/OneWidgets/OneWidget.swift"),
826
+ "OneWidgetContract.swift": import_node_path5.default.join(
827
+ root,
828
+ "ios",
829
+ widget.appName,
830
+ "OneWidgetContract.swift"
831
+ )
832
+ };
833
+ const files = /* @__PURE__ */ new Map();
834
+ const sources = {};
835
+ for (const [name, file] of Object.entries(sourceFiles)) {
836
+ if (!import_node_fs5.default.existsSync(file))
837
+ throw new Error(`missing One widget prebuild source ${file}; run one prebuild`);
838
+ const bytes = readPackageFile(root, file, MAX_SWIFT_COMPILE_SOURCE_BYTES);
839
+ const text = bytes.toString("utf8");
840
+ if (!Buffer.from(text).equals(bytes))
841
+ throw new Error(`One widget prebuild source is not UTF-8: ${file}`);
842
+ files.set(name, text);
843
+ sources[import_node_path5.default.relative(root, file).split(import_node_path5.default.sep).join("/")] = (0, import_node_crypto2.createHash)("sha256").update(bytes).digest("hex");
844
+ }
845
+ const contract = files.get("OneWidgetContract.swift") ?? "";
846
+ const source = files.get("OneWidget.swift") ?? "";
847
+ if (!contract.includes(`static let appGroup = ${JSON.stringify(widget.suite)}`) || !contract.includes(`static let kind = ${JSON.stringify(widget.kind)}`) || !source.includes(
848
+ `.configurationDisplayName(${JSON.stringify(widget.displayName)})`
849
+ ) || !source.includes(`.description(${JSON.stringify(widget.description)})`))
850
+ throw new Error(
851
+ "One widget prebuild sources disagree with native.app.ios.widgets; run one prebuild"
852
+ );
853
+ return {
854
+ root,
855
+ files,
856
+ watched: [...config.watched, ...Object.values(sourceFiles)],
857
+ widget: { ...widget, sources },
858
+ urlSchemes: config.urlSchemes
859
+ };
860
+ }
861
+ async function configuredOneWidget(appRoot, bundleUrl) {
862
+ const source = await readOneWidgetSources(appRoot);
863
+ if (!source) return null;
864
+ return {
865
+ metadata: source.widget,
866
+ projectRoot: source.root,
867
+ appIdentity: (0, import_node_crypto2.createHash)("sha256").update(JSON.stringify([source.root, source.widget.bundleId])).digest("hex"),
868
+ bundleUrl,
869
+ packageUrl: new URL(`${SWIFT_PACKAGE_PATH}OneWidgets`, bundleUrl).href,
870
+ urlSchemes: source.urlSchemes
871
+ };
872
+ }
873
+
656
874
  // src/runtime-assets.ts
657
875
  var import_fs = __toESM(require("fs"), 1);
658
876
  var import_path = __toESM(require("path"), 1);
@@ -847,15 +1065,6 @@ function streamFile(res, stream) {
847
1065
  stream.pipe(res);
848
1066
  }
849
1067
 
850
- // src/swift-submit.ts
851
- var SWIFT_PACKAGE_PATH = "/__peach/swift-package/";
852
- var SWIFT_HMR_PATH = "/__peach/swift-hmr";
853
- var MAX_SWIFT_COMPILE_SOURCE_BYTES = 2 * 1024 * 1024;
854
- var MAX_SWIFT_COMPILE_RESOURCE_BYTES = 2 * 1024 * 1024;
855
- var MAX_SWIFT_COMPILE_RESOURCE_TOTAL_BYTES = 8 * 1024 * 1024;
856
- var MAX_SWIFT_COMPILE_IMAGE_BYTES = 4 * 1024 * 1024;
857
- var MAX_SWIFT_COMPILE_IMAGE_TOTAL_BYTES = 16 * 1024 * 1024;
858
-
859
1068
  // src/vite-plugin-one.ts
860
1069
  var SWIFT_ROUTE_PREFIX = "/__peach/swift";
861
1070
  var swiftHost;
@@ -885,7 +1094,7 @@ function rnxPlugin(options = {}) {
885
1094
  let swiftModuleRoot;
886
1095
  const moduleRootFor = () => {
887
1096
  if (swiftModuleRoot === void 0) {
888
- const peachsimPackage = (0, import_node_module.createRequire)(
1097
+ const peachsimPackage = (0, import_node_module2.createRequire)(
889
1098
  import_path2.default.join(server.config.root, "package.json")
890
1099
  ).resolve("peachsim/package.json");
891
1100
  const moduleRoot = import_path2.default.resolve(
@@ -1066,7 +1275,7 @@ function rnxPlugin(options = {}) {
1066
1275
  });
1067
1276
  const bundleUrl = options.bundleUrl || "/node_modules/one/metro-entry.bundle?platform=ios&dev=true&minify=false";
1068
1277
  const appName = resolveRnxDesktopAppName(options.open, server.config.root);
1069
- const replacementToken = (0, import_node_crypto2.randomUUID)();
1278
+ const replacementToken = (0, import_node_crypto3.randomUUID)();
1070
1279
  const bundleForPort = (port2) => {
1071
1280
  const fullBundleUrl = bundleUrl.startsWith("http") ? bundleUrl : `http://localhost:${port2}${bundleUrl.startsWith("/") ? "" : "/"}${bundleUrl}`;
1072
1281
  return tagRnxBundleForPlugin(
@@ -1100,18 +1309,34 @@ function rnxPlugin(options = {}) {
1100
1309
  };
1101
1310
  next();
1102
1311
  });
1103
- server.middlewares.use((req, res, next) => {
1312
+ server.middlewares.use(async (req, res, next) => {
1104
1313
  if ((req.url || "").split("?")[0] !== "/__server-scan") return next();
1105
1314
  const scanPort = listeningPort();
1106
1315
  const pluginBundleUrl = bundleForPort(scanPort);
1107
1316
  const absoluteBundleUrl = pluginBundleUrl.startsWith("http") ? pluginBundleUrl : `http://localhost:${scanPort}${pluginBundleUrl}`;
1108
1317
  res.setHeader("content-type", "application/json");
1318
+ res.setHeader("access-control-allow-origin", "*");
1319
+ res.setHeader("cache-control", "no-store");
1320
+ let widget = null;
1321
+ let widgetError;
1322
+ try {
1323
+ widget = await configuredOneWidget(server.config.root, absoluteBundleUrl);
1324
+ if (widget && packageMap().has("OneWidgets"))
1325
+ throw new Error(
1326
+ "swift package OneWidgets conflicts with One's generated widget extension"
1327
+ );
1328
+ } catch (error) {
1329
+ widget = null;
1330
+ widgetError = String(error);
1331
+ }
1109
1332
  res.end(
1110
1333
  JSON.stringify([
1111
1334
  {
1112
1335
  port: scanPort,
1113
1336
  framework: "one",
1114
1337
  bundleUrl: absoluteBundleUrl,
1338
+ widget,
1339
+ ...widgetError ? { widgetError } : {},
1115
1340
  ...appName ? { projectName: appName } : {},
1116
1341
  lastSeen: Date.now()
1117
1342
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "peachsim",
3
- "version": "0.1.796",
3
+ "version": "0.1.798",
4
4
  "description": "Vite and Metro plugins, testing drivers, and SDK exports for peach.",
5
5
  "author": "Tamagui LLC",
6
6
  "license": "SEE LICENSE IN LICENSE",
@@ -1,3 +1,5 @@
1
+ import { spawn } from 'child_process'
2
+ import { readlink } from 'fs/promises'
1
3
  // shared dev-server scanner used by both the electron main process
2
4
  // (`src-electron/main.ts`) and the vite plugin (`vite.config.ts`). discovers
3
5
  // running dev servers on localhost by listing every node/bun process that's
@@ -10,11 +12,8 @@
10
12
  // 4. sootsim-patched (/__soot/ middleware present) → /__soot/bundle.js
11
13
  //
12
14
  // scans are cached per (port, pid). repeat scans with no process changes issue
13
- // zero HTTP requests; probes only fire when a port appears, disappears, or its
14
- // pid changes. before any HTTP, a TCP connect gate skips unreachable ports.
15
-
16
- import { spawn } from 'child_process'
17
- import { readlink } from 'fs/promises'
15
+ // no signature probes; widget metadata is refreshed from the owning One server
16
+ // on every scan. before signature HTTP, a TCP gate skips unreachable ports.
18
17
  import http from 'http'
19
18
  import net from 'net'
20
19
  import { realpathSync } from 'node:fs'
@@ -31,11 +30,13 @@ import {
31
30
  alignLoopbackBundleUrlWithProbe,
32
31
  normalizeNativeDevBundleUrl,
33
32
  } from '../src/native-dev-bundle-url.ts'
33
+ import { readConfiguredOneWidget } from '../src/one-widget-discovery'
34
34
  import {
35
35
  __resetAppSettingsBundleCacheForTests,
36
36
  readAppSettingsBundle,
37
37
  } from '../src/settings-bundle.ts'
38
38
  import { loadOptionalDemoApps, optionalDemoAppsSync } from './optional-demo-registry.ts'
39
+ import type { ConfiguredOneWidget } from '../src/oneWidgetContract'
39
40
  import type { AppSettingsSpecifier } from '@peach/globals'
40
41
 
41
42
  /** every subprocess in this file goes through here.
@@ -114,6 +115,7 @@ export interface DiscoveredServer {
114
115
  * when the icon is missing entirely. */
115
116
  primaryColor?: string
116
117
  bundleId?: string
118
+ widget?: ConfiguredOneWidget | null
117
119
  settingsBundle?: readonly AppSettingsSpecifier[]
118
120
  settingsStorageScopeUrl?: string
119
121
  patched?: boolean
@@ -1304,6 +1306,15 @@ export async function scanDevServers(
1304
1306
  })
1305
1307
  }
1306
1308
 
1309
+ // the app server's Vite root, rather than a process cwd, owns widget metadata.
1310
+ await Promise.all(
1311
+ results.map(async (result) => {
1312
+ result.widget = null
1313
+ if (result.framework !== 'one' && result.framework !== 'vxrn') return
1314
+ result.widget = await readConfiguredOneWidget(result.bundleUrl)
1315
+ }),
1316
+ )
1317
+
1307
1318
  // attach pid + cwd. pid comes from the listening-process scan; cwd is
1308
1319
  // lsof-resolved and cached per pid. both enable auto-attach of agent
1309
1320
  // sessions to the right project without a manual `sootsim agent attach`.
@@ -288,17 +288,21 @@ export async function compileExpoSwiftModules(
288
288
  const file: unknown = JSON.parse(match[1]!)
289
289
  return typeof file === 'string' ? [file] : []
290
290
  })
291
- const sourceErrors = (
292
- diagnostic.match(/^.+:\d+(?::\d+)?: error:.*$/gm) ?? []
293
- ).filter((line) => appPaths.some((file) => line.startsWith(`${file}:`)))
291
+ const errors = diagnostic.match(/^.+:\d+(?::\d+)?: error:.*$/gm) ?? []
292
+ const sourceErrors = errors.filter(
293
+ (line) =>
294
+ appPaths.some((file) => line.startsWith(`${file}:`)) &&
295
+ !/external macro implementation type|failed to load library plugin/.test(line),
296
+ )
294
297
  if (
295
298
  publishArtifact &&
296
- sourceErrors.length === 0 &&
299
+ (sourceErrors.length === 0 || sourceErrors.length !== errors.length) &&
297
300
  !(error instanceof SwiftMissingModulesError)
298
301
  )
299
302
  throw error
300
303
  if (
301
304
  sourceErrors.length &&
305
+ sourceErrors.length === errors.length &&
302
306
  module &&
303
307
  stamp &&
304
308
  sourceStamp(packagePath, module.root) === stamp
@@ -0,0 +1,17 @@
1
+ import { configuredWidgetFromScan } from './oneWidgetContract'
2
+ import type { ConfiguredOneWidget } from './oneWidgetContract'
3
+
4
+ export async function readConfiguredOneWidget(
5
+ bundleUrl: string,
6
+ ): Promise<ConfiguredOneWidget | null> {
7
+ try {
8
+ const response = await fetch(new URL('/__server-scan', bundleUrl).href, {
9
+ signal: AbortSignal.timeout(30_000),
10
+ })
11
+ if (!response.ok || !response.headers.get('content-type')?.includes('json'))
12
+ return null
13
+ return configuredWidgetFromScan(await response.json(), bundleUrl)
14
+ } catch {
15
+ return null
16
+ }
17
+ }
@@ -0,0 +1,208 @@
1
+ import { execFile } from 'node:child_process'
2
+ import { createHash } from 'node:crypto'
3
+ import fs from 'node:fs'
4
+ import { createRequire } from 'node:module'
5
+ import path from 'node:path'
6
+ import { promisify } from 'node:util'
7
+ import { RNX_FORKED_SCRIPT_ENV } from '../cli/internal-child'
8
+ import { isRecord } from './is-record'
9
+ import { readPackageFile } from './swift-source-file'
10
+ import { MAX_SWIFT_COMPILE_SOURCE_BYTES, SWIFT_PACKAGE_PATH } from './swift-submit'
11
+ import type { ConfiguredOneWidget, OneWidgetMetadata } from './oneWidgetContract'
12
+
13
+ const run = promisify(execFile)
14
+ export const ONE_WIDGET_PACKAGE = 'OneWidgets'
15
+
16
+ type WidgetConfig = Omit<OneWidgetMetadata, 'sources'>
17
+
18
+ interface ConfigRead {
19
+ urlSchemes: string[]
20
+ widget: WidgetConfig | null
21
+ watched: string[]
22
+ stamp: string
23
+ }
24
+
25
+ const configs = new Map<string, ConfigRead>()
26
+ const reads = new Map<string, Promise<ConfigRead>>()
27
+ const CONFIG_CHILD = `
28
+ import fs from 'node:fs';
29
+ import { loadUserOneOptions } from 'one/vite';
30
+ const { config, oneOptions } = await loadUserOneOptions('serve', true);
31
+ const app = oneOptions.native?.app;
32
+ const widgets = app?.ios?.widgets;
33
+ fs.writeFileSync(process.argv[2], JSON.stringify({
34
+ widget: widgets ? { appName: app.name, bundleId: app.ios.bundleId,
35
+ suite: widgets.appGroup, kind: widgets.kind, displayName: widgets.displayName,
36
+ description: widgets.description } : null,
37
+ urlSchemes: app?.scheme === undefined ? [] : Array.isArray(app.scheme) ? app.scheme : [app.scheme],
38
+ watched: [config.path, ...config.dependencies]
39
+ }));
40
+ `
41
+
42
+ function configStamp(files: string[]): string {
43
+ return JSON.stringify(
44
+ files.map((file) => {
45
+ if (!fs.existsSync(file)) return [file, null]
46
+ const stat = fs.statSync(file)
47
+ return [file, stat.mtimeMs, stat.ctimeMs, stat.size]
48
+ }),
49
+ )
50
+ }
51
+
52
+ async function readConfig(root: string): Promise<ConfigRead> {
53
+ const cached = configs.get(root)
54
+ if (cached && cached.stamp === configStamp(cached.watched)) return cached
55
+ const reading = reads.get(root)
56
+ if (reading) return reading
57
+ const promise = (async () => {
58
+ // resolve before launching: an app without One is not a configured One app.
59
+ createRequire(path.join(root, 'package.json')).resolve('one/vite')
60
+ const cache = path.join(root, 'node_modules/.cache/peach-widget-config')
61
+ fs.mkdirSync(cache, { recursive: true })
62
+ const directory = fs.mkdtempSync(path.join(cache, 'read-'))
63
+ const script = path.join(directory, 'read.mjs')
64
+ const result = path.join(directory, 'result.json')
65
+ fs.writeFileSync(script, CONFIG_CHILD)
66
+ try {
67
+ await run(process.execPath, [script, result], {
68
+ cwd: root,
69
+ env: { ...process.env, [RNX_FORKED_SCRIPT_ENV]: '1' },
70
+ timeout: 30_000,
71
+ maxBuffer: 1024 * 1024,
72
+ })
73
+ const value: unknown = JSON.parse(fs.readFileSync(result, 'utf8'))
74
+ if (
75
+ !isRecord(value) ||
76
+ !Array.isArray(value.watched) ||
77
+ !value.watched.every((file): file is string => typeof file === 'string')
78
+ )
79
+ throw new Error('One config loader returned invalid dependencies')
80
+ if (
81
+ !Array.isArray(value.urlSchemes) ||
82
+ !value.urlSchemes.every(
83
+ (scheme): scheme is string =>
84
+ typeof scheme === 'string' && /^[A-Za-z][A-Za-z0-9+.-]*$/.test(scheme),
85
+ )
86
+ )
87
+ throw new Error('One config loader returned invalid native.app.scheme')
88
+ let widget: WidgetConfig | null = null
89
+ if (value.widget !== null) {
90
+ const entry = value.widget
91
+ if (
92
+ !isRecord(entry) ||
93
+ typeof entry.appName !== 'string' ||
94
+ !/^[A-Za-z][A-Za-z0-9_]*$/.test(entry.appName) ||
95
+ typeof entry.bundleId !== 'string' ||
96
+ !entry.bundleId ||
97
+ typeof entry.suite !== 'string' ||
98
+ !entry.suite ||
99
+ typeof entry.kind !== 'string' ||
100
+ !entry.kind ||
101
+ typeof entry.displayName !== 'string' ||
102
+ !entry.displayName ||
103
+ typeof entry.description !== 'string' ||
104
+ !entry.description
105
+ )
106
+ throw new Error('One config loader returned invalid native.app.ios.widgets')
107
+ widget = {
108
+ appName: entry.appName,
109
+ bundleId: entry.bundleId,
110
+ suite: entry.suite,
111
+ kind: entry.kind,
112
+ displayName: entry.displayName,
113
+ description: entry.description,
114
+ }
115
+ }
116
+ const watched = [
117
+ ...new Set([
118
+ path.join(root, 'package.json'),
119
+ ...value.watched.map((file) => path.resolve(root, file)),
120
+ ]),
121
+ ]
122
+ const loaded = {
123
+ widget,
124
+ urlSchemes: value.urlSchemes,
125
+ watched,
126
+ stamp: configStamp(watched),
127
+ }
128
+ configs.set(root, loaded)
129
+ return loaded
130
+ } finally {
131
+ fs.rmSync(directory, { recursive: true, force: true })
132
+ }
133
+ })()
134
+ reads.set(root, promise)
135
+ try {
136
+ return await promise
137
+ } finally {
138
+ reads.delete(root)
139
+ }
140
+ }
141
+
142
+ export async function readOneWidgetSources(appRoot: string) {
143
+ const root = fs.realpathSync(appRoot)
144
+ const config = await readConfig(root)
145
+ if (!config.widget) return null
146
+ const widget = config.widget
147
+ const sourceFiles = {
148
+ 'OneWidget.swift': path.join(root, 'ios/OneWidgets/OneWidget.swift'),
149
+ 'OneWidgetContract.swift': path.join(
150
+ root,
151
+ 'ios',
152
+ widget.appName,
153
+ 'OneWidgetContract.swift',
154
+ ),
155
+ }
156
+ const files = new Map<string, string>()
157
+ const sources: Record<string, string> = {}
158
+ for (const [name, file] of Object.entries(sourceFiles)) {
159
+ if (!fs.existsSync(file))
160
+ throw new Error(`missing One widget prebuild source ${file}; run one prebuild`)
161
+ const bytes = readPackageFile(root, file, MAX_SWIFT_COMPILE_SOURCE_BYTES)
162
+ const text = bytes.toString('utf8')
163
+ if (!Buffer.from(text).equals(bytes))
164
+ throw new Error(`One widget prebuild source is not UTF-8: ${file}`)
165
+ files.set(name, text)
166
+ sources[path.relative(root, file).split(path.sep).join('/')] = createHash('sha256')
167
+ .update(bytes)
168
+ .digest('hex')
169
+ }
170
+ const contract = files.get('OneWidgetContract.swift') ?? ''
171
+ const source = files.get('OneWidget.swift') ?? ''
172
+ if (
173
+ !contract.includes(`static let appGroup = ${JSON.stringify(widget.suite)}`) ||
174
+ !contract.includes(`static let kind = ${JSON.stringify(widget.kind)}`) ||
175
+ !source.includes(
176
+ `.configurationDisplayName(${JSON.stringify(widget.displayName)})`,
177
+ ) ||
178
+ !source.includes(`.description(${JSON.stringify(widget.description)})`)
179
+ )
180
+ throw new Error(
181
+ 'One widget prebuild sources disagree with native.app.ios.widgets; run one prebuild',
182
+ )
183
+ return {
184
+ root,
185
+ files,
186
+ watched: [...config.watched, ...Object.values(sourceFiles)],
187
+ widget: { ...widget, sources },
188
+ urlSchemes: config.urlSchemes,
189
+ }
190
+ }
191
+
192
+ export async function configuredOneWidget(
193
+ appRoot: string,
194
+ bundleUrl: string,
195
+ ): Promise<ConfiguredOneWidget | null> {
196
+ const source = await readOneWidgetSources(appRoot)
197
+ if (!source) return null
198
+ return {
199
+ metadata: source.widget,
200
+ projectRoot: source.root,
201
+ appIdentity: createHash('sha256')
202
+ .update(JSON.stringify([source.root, source.widget.bundleId]))
203
+ .digest('hex'),
204
+ bundleUrl,
205
+ packageUrl: new URL(`${SWIFT_PACKAGE_PATH}OneWidgets`, bundleUrl).href,
206
+ urlSchemes: source.urlSchemes,
207
+ }
208
+ }