peachsim 0.1.781 → 0.1.782
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/detox/expectations.ts +1 -1
- package/detox/gestures.ts +1 -1
- package/detox/index.ts +27 -3
- package/detox/navigation-lifecycle.ts +1 -1
- package/dist-lib/agent-daemon-client.cjs +1 -1
- package/dist-lib/agent-events.cjs +1 -1
- package/dist-lib/agent-identity.cjs +1 -1
- package/dist-lib/agent-sessions.cjs +1 -1
- package/dist-lib/attached-projects.cjs +1 -1
- package/dist-lib/auth/shared-session.cjs +1 -1
- package/dist-lib/backend-origin.cjs +1 -1
- package/dist-lib/beta.cjs +1 -1
- package/dist-lib/beta.mjs +1 -1
- package/dist-lib/bridge-constants.cjs +1 -1
- package/dist-lib/bridge-contract-input.cjs +1 -1
- package/dist-lib/bridge-contract-input.mjs +1 -1
- package/dist-lib/bridge-contract.cjs +1 -1
- package/dist-lib/bridge-contract.mjs +1 -1
- package/dist-lib/capture-contract.cjs +1 -1
- package/dist-lib/capture-contract.mjs +1 -1
- package/dist-lib/cli-constants.cjs +1 -1
- package/dist-lib/cloud-contract.cjs +1 -1
- package/dist-lib/cloud-contract.mjs +1 -1
- package/dist-lib/cloud-test-args.cjs +1 -1
- package/dist-lib/cloud-test-args.mjs +1 -1
- package/dist-lib/cloud.cjs +1 -1
- package/dist-lib/cloud.mjs +1 -1
- package/dist-lib/config.cjs +1 -1
- package/dist-lib/detox/index.cjs +3533 -133
- package/dist-lib/dev-bundle-resolution.cjs +1 -1
- package/dist-lib/home-paths.cjs +1 -1
- package/dist-lib/host/bridge-host.cjs +5991 -1986
- package/dist-lib/host/fetch-proxy-handler.cjs +1 -1
- package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
- package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
- package/dist-lib/host/replacement-module-handler.cjs +1 -1
- package/dist-lib/host/websocket-proxy.cjs +1 -1
- package/dist-lib/index.cjs +4664 -1266
- package/dist-lib/jump-to-source-babel.cjs +1 -1
- package/dist-lib/jump-to-source-native.cjs +1 -1
- package/dist-lib/kotlin-host.cjs +1 -1
- package/dist-lib/menu.cjs +1 -1
- package/dist-lib/menu.mjs +1 -1
- package/dist-lib/metro-fingerprint-registry.cjs +1 -1
- package/dist-lib/metro-fingerprint-registry.mjs +1 -1
- package/dist-lib/metro-production-bundle.cjs +1 -1
- package/dist-lib/metro-production-bundle.mjs +1 -1
- package/dist-lib/metro.cjs +1114 -2
- package/dist-lib/native-app-identity.cjs +1 -1
- package/dist-lib/native-app-identity.mjs +1 -1
- package/dist-lib/native-firebase-metadata.cjs +1 -1
- package/dist-lib/native-firebase-metadata.mjs +1 -1
- package/dist-lib/plist.cjs +1 -1
- package/dist-lib/plist.mjs +1 -1
- package/dist-lib/profiles.cjs +1 -1
- package/dist-lib/public-brand.cjs +1 -1
- package/dist-lib/react-native-host-modules.cjs +1 -1
- package/dist-lib/react-native-host-modules.mjs +1 -1
- package/dist-lib/render-mode.cjs +1 -1
- package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
- package/dist-lib/sdk.cjs +1 -1
- package/dist-lib/sdk.mjs +1 -1
- package/dist-lib/skills.cjs +8450 -133
- package/dist-lib/swift-compile.cjs +1 -1
- package/dist-lib/swift-compile.mjs +1 -1
- package/dist-lib/swift-package.cjs +1 -1
- package/dist-lib/swift-package.mjs +1 -1
- package/dist-lib/swift-submit.cjs +1 -1
- package/dist-lib/swift-submit.mjs +1 -1
- package/dist-lib/swift-toolchain.cjs +1 -1
- package/dist-lib/swift.cjs +1 -1
- package/dist-lib/vite-swift.cjs +1707 -387
- package/dist-lib/vite.cjs +38 -16
- package/package.json +1 -1
- package/skills/contrast/SKILL.md +2 -0
- package/src/one-widget-package.ts +202 -0
- package/src/oneWidgetContract.ts +16 -0
- package/src/swift-host.ts +1 -1
- package/src/swift-standins.ts +3 -0
- package/src/vite-plugin-one.ts +45 -17
- package/src/vite-plugin-swift.ts +2 -0
package/dist-lib/vite.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! rnx v0.1.
|
|
1
|
+
/*! rnx v0.1.782 | (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;
|
|
@@ -901,6 +901,36 @@ function rnxPlugin(options = {}) {
|
|
|
901
901
|
swiftPackages ??= swiftPackageDirectories(server.config.root);
|
|
902
902
|
return swiftPackages;
|
|
903
903
|
};
|
|
904
|
+
let widgetPackage = null;
|
|
905
|
+
const servedPackage = async (packageName) => {
|
|
906
|
+
const host = await loadSwiftHost();
|
|
907
|
+
const existing = packageMap().get(packageName);
|
|
908
|
+
if (packageName !== host.ONE_WIDGET_PACKAGE) return existing;
|
|
909
|
+
widgetPackage = await host.oneWidgetPackage(server.config.root);
|
|
910
|
+
if (!widgetPackage) return existing;
|
|
911
|
+
if (existing)
|
|
912
|
+
throw new Error(
|
|
913
|
+
`swift package ${packageName} conflicts with One's generated widget extension`
|
|
914
|
+
);
|
|
915
|
+
server.watcher.add(widgetPackage.watched);
|
|
916
|
+
return widgetPackage.packagePath;
|
|
917
|
+
};
|
|
918
|
+
const packageMetadata = async (packageName, moduleRoot) => {
|
|
919
|
+
const packagePath = await servedPackage(packageName);
|
|
920
|
+
if (!packagePath) throw new Error(`swift package ${packageName} was not found`);
|
|
921
|
+
const host = await loadSwiftHost();
|
|
922
|
+
const metadata = await host.swiftPackageMetadata(
|
|
923
|
+
packagePath,
|
|
924
|
+
packageName,
|
|
925
|
+
moduleRoot,
|
|
926
|
+
devOrigin()
|
|
927
|
+
);
|
|
928
|
+
return {
|
|
929
|
+
...metadata,
|
|
930
|
+
hmrPath,
|
|
931
|
+
...packageName === host.ONE_WIDGET_PACKAGE && widgetPackage ? { widget: widgetPackage.widget } : {}
|
|
932
|
+
};
|
|
933
|
+
};
|
|
904
934
|
const wsOptions = server.config.server.ws;
|
|
905
935
|
const httpServer = server.httpServer ?? (wsOptions && typeof wsOptions === "object" ? wsOptions.server : void 0);
|
|
906
936
|
const swiftSockets = httpServer ? new import_ws.WebSocketServer({ noServer: true }) : void 0;
|
|
@@ -967,28 +997,20 @@ function rnxPlugin(options = {}) {
|
|
|
967
997
|
try {
|
|
968
998
|
packages = packageMap();
|
|
969
999
|
} catch (error) {
|
|
970
|
-
for (const packageName of activeSwiftPackages)
|
|
1000
|
+
for (const packageName of activeSwiftPackages)
|
|
971
1001
|
sendSwiftChange({
|
|
972
1002
|
type: "error",
|
|
973
1003
|
packageName,
|
|
974
1004
|
message: error instanceof Error ? error.message : String(error)
|
|
975
1005
|
});
|
|
976
|
-
}
|
|
977
1006
|
return;
|
|
978
1007
|
}
|
|
979
1008
|
for (const packageName of activeSwiftPackages) {
|
|
980
1009
|
const packagePath = packages.get(packageName);
|
|
981
|
-
|
|
982
|
-
if (!file.startsWith(`${packagePath}${import_path2.default.sep}`) && !(moduleRoot && file.startsWith(`${moduleRoot}${import_path2.default.sep}`)))
|
|
1010
|
+
const widgetChanged = packageName === "OneWidgets" && widgetPackage?.watched.includes(file);
|
|
1011
|
+
if (!widgetChanged && !(packagePath && file.startsWith(`${packagePath}${import_path2.default.sep}`)) && !(moduleRoot && file.startsWith(`${moduleRoot}${import_path2.default.sep}`)))
|
|
983
1012
|
continue;
|
|
984
|
-
void
|
|
985
|
-
(host) => host.swiftPackageMetadata(
|
|
986
|
-
packagePath,
|
|
987
|
-
packageName,
|
|
988
|
-
moduleRoot,
|
|
989
|
-
devOrigin()
|
|
990
|
-
)
|
|
991
|
-
).then((metadata) => {
|
|
1013
|
+
void packageMetadata(packageName, moduleRoot).then((metadata) => {
|
|
992
1014
|
sendSwiftChange({
|
|
993
1015
|
type: "package",
|
|
994
1016
|
packageName,
|
|
@@ -1006,7 +1028,7 @@ function rnxPlugin(options = {}) {
|
|
|
1006
1028
|
server.middlewares.use((req, res, next) => {
|
|
1007
1029
|
const pathname = (req.url ?? "").split("?")[0];
|
|
1008
1030
|
if (!pathname.startsWith(SWIFT_ROUTE_PREFIX)) return next();
|
|
1009
|
-
loadSwiftHost().then((host) => {
|
|
1031
|
+
loadSwiftHost().then(async (host) => {
|
|
1010
1032
|
if (host.serveSwiftPackageAsset(pathname, res)) return;
|
|
1011
1033
|
const prefix2 = SWIFT_PACKAGE_PATH;
|
|
1012
1034
|
if (!pathname.startsWith(prefix2)) return next();
|
|
@@ -1018,7 +1040,7 @@ function rnxPlugin(options = {}) {
|
|
|
1018
1040
|
const packageName = pathname.slice(prefix2.length);
|
|
1019
1041
|
let packagePath;
|
|
1020
1042
|
try {
|
|
1021
|
-
packagePath =
|
|
1043
|
+
packagePath = await servedPackage(packageName);
|
|
1022
1044
|
} catch (error) {
|
|
1023
1045
|
res.statusCode = 500;
|
|
1024
1046
|
res.end(error instanceof Error ? error.message : String(error));
|
|
@@ -1032,7 +1054,7 @@ function rnxPlugin(options = {}) {
|
|
|
1032
1054
|
const moduleRoot = moduleRootFor();
|
|
1033
1055
|
activeSwiftPackages.add(packageName);
|
|
1034
1056
|
server.watcher.add(host.swiftPackageWatchFiles(packagePath, moduleRoot));
|
|
1035
|
-
void
|
|
1057
|
+
void packageMetadata(packageName, moduleRoot).then((metadata) => {
|
|
1036
1058
|
res.setHeader("access-control-allow-origin", "*");
|
|
1037
1059
|
res.setHeader("content-type", "application/json");
|
|
1038
1060
|
res.end(JSON.stringify({ ...metadata, hmrPath }));
|
package/package.json
CHANGED
package/skills/contrast/SKILL.md
CHANGED
|
@@ -21,6 +21,7 @@ automation, inspecting the render tree, and managing sims.
|
|
|
21
21
|
| --- | --- |
|
|
22
22
|
| `peach swift` | preview a SwiftPM or Xcode app with live Swift edits, compiled on this machine |
|
|
23
23
|
| `peach kotlin` | run an Android Compose app module from its launcher activity |
|
|
24
|
+
| `peach test` | run a Maestro flow or Detox suite against a peach app bundle |
|
|
24
25
|
| `peach maestro` | author, generate, and run Maestro YAML flows against peach |
|
|
25
26
|
| `peach detox` | run existing Detox suites against peach on headless Chromium |
|
|
26
27
|
| `peach cleanup` | inspect and reclaim local peach disk usage |
|
|
@@ -48,6 +49,7 @@ automation, inspecting the render tree, and managing sims.
|
|
|
48
49
|
| `peach box` | start a local Box or create a cloud Box |
|
|
49
50
|
| `peach ios` | start an iOS simulator |
|
|
50
51
|
| `peach android` | start an Android simulator |
|
|
52
|
+
| `peach remote` | run a prebuilt bundle on a remote simulator |
|
|
51
53
|
| `peach open` | load a target into the current sim or open a new one |
|
|
52
54
|
| `peach list` | list connected sims or available launch drivers |
|
|
53
55
|
| `peach use` | select a connected sim |
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
// One's own config loader runs in the app's process; prebuild owns every source byte.
|
|
2
|
+
import { execFile } from 'node:child_process'
|
|
3
|
+
import { createHash } from 'node:crypto'
|
|
4
|
+
import fs from 'node:fs'
|
|
5
|
+
import { createRequire } from 'node:module'
|
|
6
|
+
import os from 'node:os'
|
|
7
|
+
import path from 'node:path'
|
|
8
|
+
import { promisify } from 'node:util'
|
|
9
|
+
import { RNX_FORKED_SCRIPT_ENV } from '../cli/internal-child'
|
|
10
|
+
import { isRecord } from './is-record'
|
|
11
|
+
import { syncSwiftTree } from './swift-compile'
|
|
12
|
+
import { readPackageFile } from './swift-host'
|
|
13
|
+
import { MAX_SWIFT_COMPILE_SOURCE_BYTES } from './swift-submit'
|
|
14
|
+
import type { OneWidgetMetadata, OneWidgetPackage } from './oneWidgetContract'
|
|
15
|
+
|
|
16
|
+
const run = promisify(execFile)
|
|
17
|
+
export const ONE_WIDGET_PACKAGE = 'OneWidgets'
|
|
18
|
+
|
|
19
|
+
type WidgetConfig = Omit<OneWidgetMetadata, 'sources'>
|
|
20
|
+
|
|
21
|
+
interface ConfigRead {
|
|
22
|
+
widget: WidgetConfig | null
|
|
23
|
+
watched: string[]
|
|
24
|
+
stamp: string
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const configs = new Map<string, ConfigRead>()
|
|
28
|
+
const reads = new Map<string, Promise<ConfigRead>>()
|
|
29
|
+
const CONFIG_CHILD = `
|
|
30
|
+
import fs from 'node:fs';
|
|
31
|
+
import { loadUserOneOptions } from 'one/vite';
|
|
32
|
+
const { config, oneOptions } = await loadUserOneOptions('serve', true);
|
|
33
|
+
const app = oneOptions.native?.app;
|
|
34
|
+
const widgets = app?.ios?.widgets;
|
|
35
|
+
fs.writeFileSync(process.argv[2], JSON.stringify({
|
|
36
|
+
widget: widgets ? { appName: app.name, bundleId: app.ios.bundleId,
|
|
37
|
+
suite: widgets.appGroup, kind: widgets.kind, displayName: widgets.displayName,
|
|
38
|
+
description: widgets.description } : null,
|
|
39
|
+
watched: [config.path, ...config.dependencies]
|
|
40
|
+
}));
|
|
41
|
+
`
|
|
42
|
+
|
|
43
|
+
function configStamp(files: string[]): string {
|
|
44
|
+
return JSON.stringify(
|
|
45
|
+
files.map((file) => {
|
|
46
|
+
if (!fs.existsSync(file)) return [file, null]
|
|
47
|
+
const stat = fs.statSync(file)
|
|
48
|
+
return [file, stat.mtimeMs, stat.ctimeMs, stat.size]
|
|
49
|
+
}),
|
|
50
|
+
)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async function readConfig(root: string): Promise<ConfigRead> {
|
|
54
|
+
const cached = configs.get(root)
|
|
55
|
+
if (cached && cached.stamp === configStamp(cached.watched)) return cached
|
|
56
|
+
const reading = reads.get(root)
|
|
57
|
+
if (reading) return reading
|
|
58
|
+
const promise = (async () => {
|
|
59
|
+
// resolve before launching: an app without One is not a configured One app.
|
|
60
|
+
createRequire(path.join(root, 'package.json')).resolve('one/vite')
|
|
61
|
+
const cache = path.join(root, 'node_modules/.cache/peach-widget-config')
|
|
62
|
+
fs.mkdirSync(cache, { recursive: true })
|
|
63
|
+
const directory = fs.mkdtempSync(path.join(cache, 'read-'))
|
|
64
|
+
const script = path.join(directory, 'read.mjs')
|
|
65
|
+
const result = path.join(directory, 'result.json')
|
|
66
|
+
fs.writeFileSync(script, CONFIG_CHILD)
|
|
67
|
+
try {
|
|
68
|
+
await run(process.execPath, [script, result], {
|
|
69
|
+
cwd: root,
|
|
70
|
+
env: { ...process.env, [RNX_FORKED_SCRIPT_ENV]: '1' },
|
|
71
|
+
timeout: 30_000,
|
|
72
|
+
maxBuffer: 1024 * 1024,
|
|
73
|
+
})
|
|
74
|
+
const value: unknown = JSON.parse(fs.readFileSync(result, 'utf8'))
|
|
75
|
+
if (
|
|
76
|
+
!isRecord(value) ||
|
|
77
|
+
!Array.isArray(value.watched) ||
|
|
78
|
+
!value.watched.every((file): file is string => typeof file === 'string')
|
|
79
|
+
)
|
|
80
|
+
throw new Error('One config loader returned invalid dependencies')
|
|
81
|
+
let widget: WidgetConfig | null = null
|
|
82
|
+
if (value.widget !== null) {
|
|
83
|
+
const entry = value.widget
|
|
84
|
+
if (
|
|
85
|
+
!isRecord(entry) ||
|
|
86
|
+
typeof entry.appName !== 'string' ||
|
|
87
|
+
!/^[A-Za-z][A-Za-z0-9_]*$/.test(entry.appName) ||
|
|
88
|
+
typeof entry.bundleId !== 'string' ||
|
|
89
|
+
!entry.bundleId ||
|
|
90
|
+
typeof entry.suite !== 'string' ||
|
|
91
|
+
!entry.suite ||
|
|
92
|
+
typeof entry.kind !== 'string' ||
|
|
93
|
+
!entry.kind ||
|
|
94
|
+
typeof entry.displayName !== 'string' ||
|
|
95
|
+
!entry.displayName ||
|
|
96
|
+
typeof entry.description !== 'string' ||
|
|
97
|
+
!entry.description
|
|
98
|
+
)
|
|
99
|
+
throw new Error('One config loader returned invalid native.app.ios.widgets')
|
|
100
|
+
widget = {
|
|
101
|
+
appName: entry.appName,
|
|
102
|
+
bundleId: entry.bundleId,
|
|
103
|
+
suite: entry.suite,
|
|
104
|
+
kind: entry.kind,
|
|
105
|
+
displayName: entry.displayName,
|
|
106
|
+
description: entry.description,
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
const watched = [
|
|
110
|
+
...new Set([
|
|
111
|
+
path.join(root, 'package.json'),
|
|
112
|
+
...value.watched.map((file) => path.resolve(root, file)),
|
|
113
|
+
]),
|
|
114
|
+
]
|
|
115
|
+
const loaded = { widget, watched, stamp: configStamp(watched) }
|
|
116
|
+
configs.set(root, loaded)
|
|
117
|
+
return loaded
|
|
118
|
+
} finally {
|
|
119
|
+
fs.rmSync(directory, { recursive: true, force: true })
|
|
120
|
+
}
|
|
121
|
+
})()
|
|
122
|
+
reads.set(root, promise)
|
|
123
|
+
try {
|
|
124
|
+
return await promise
|
|
125
|
+
} finally {
|
|
126
|
+
reads.delete(root)
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export async function oneWidgetPackage(
|
|
131
|
+
appRoot: string,
|
|
132
|
+
): Promise<OneWidgetPackage | null> {
|
|
133
|
+
const root = fs.realpathSync(appRoot)
|
|
134
|
+
const config = await readConfig(root)
|
|
135
|
+
if (!config.widget) return null
|
|
136
|
+
const widget = config.widget
|
|
137
|
+
const sourceFiles = {
|
|
138
|
+
'OneWidget.swift': path.join(root, 'ios/OneWidgets/OneWidget.swift'),
|
|
139
|
+
'OneWidgetContract.swift': path.join(
|
|
140
|
+
root,
|
|
141
|
+
'ios',
|
|
142
|
+
widget.appName,
|
|
143
|
+
'OneWidgetContract.swift',
|
|
144
|
+
),
|
|
145
|
+
}
|
|
146
|
+
const files = new Map<string, string>()
|
|
147
|
+
const sources: Record<string, string> = {}
|
|
148
|
+
for (const [name, file] of Object.entries(sourceFiles)) {
|
|
149
|
+
if (!fs.existsSync(file))
|
|
150
|
+
throw new Error(`missing One widget prebuild source ${file}; run one prebuild`)
|
|
151
|
+
const bytes = readPackageFile(root, file, MAX_SWIFT_COMPILE_SOURCE_BYTES)
|
|
152
|
+
const text = bytes.toString('utf8')
|
|
153
|
+
if (!Buffer.from(text).equals(bytes))
|
|
154
|
+
throw new Error(`One widget prebuild source is not UTF-8: ${file}`)
|
|
155
|
+
files.set(name, text)
|
|
156
|
+
sources[path.relative(root, file).split(path.sep).join('/')] = createHash('sha256')
|
|
157
|
+
.update(bytes)
|
|
158
|
+
.digest('hex')
|
|
159
|
+
}
|
|
160
|
+
const contract = files.get('OneWidgetContract.swift') ?? ''
|
|
161
|
+
const source = files.get('OneWidget.swift') ?? ''
|
|
162
|
+
if (
|
|
163
|
+
!contract.includes(`static let appGroup = ${JSON.stringify(widget.suite)}`) ||
|
|
164
|
+
!contract.includes(`static let kind = ${JSON.stringify(widget.kind)}`) ||
|
|
165
|
+
!source.includes(
|
|
166
|
+
`.configurationDisplayName(${JSON.stringify(widget.displayName)})`,
|
|
167
|
+
) ||
|
|
168
|
+
!source.includes(`.description(${JSON.stringify(widget.description)})`)
|
|
169
|
+
)
|
|
170
|
+
throw new Error(
|
|
171
|
+
'One widget prebuild sources disagree with native.app.ios.widgets; run one prebuild',
|
|
172
|
+
)
|
|
173
|
+
// configuration participates in the existing package stamp and compile address.
|
|
174
|
+
files.set(
|
|
175
|
+
'Package.swift',
|
|
176
|
+
[
|
|
177
|
+
'// swift-tools-version: 6.2',
|
|
178
|
+
`// One widget config ${JSON.stringify(widget)}`,
|
|
179
|
+
'import PackageDescription',
|
|
180
|
+
'let package = Package(name: "OneWidgets", targets: [',
|
|
181
|
+
' .executableTarget(name: "OneWidgets", path: ".", swiftSettings: [.swiftLanguageMode(.v5)]),',
|
|
182
|
+
'])',
|
|
183
|
+
'',
|
|
184
|
+
].join('\n'),
|
|
185
|
+
)
|
|
186
|
+
const packagePath = path.join(
|
|
187
|
+
os.tmpdir(),
|
|
188
|
+
'peach-one-widgets',
|
|
189
|
+
createHash('sha256').update(root).digest('hex'),
|
|
190
|
+
ONE_WIDGET_PACKAGE,
|
|
191
|
+
)
|
|
192
|
+
fs.mkdirSync(packagePath, { recursive: true })
|
|
193
|
+
syncSwiftTree(
|
|
194
|
+
packagePath,
|
|
195
|
+
new Map([...files].map(([file, text]) => [path.join(packagePath, file), text])),
|
|
196
|
+
)
|
|
197
|
+
return {
|
|
198
|
+
packagePath,
|
|
199
|
+
watched: [...config.watched, ...Object.values(sourceFiles)],
|
|
200
|
+
widget: { ...widget, sources },
|
|
201
|
+
}
|
|
202
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// generated One widget package metadata carried by the Swift serving host.
|
|
2
|
+
export interface OneWidgetMetadata {
|
|
3
|
+
appName: string
|
|
4
|
+
bundleId: string
|
|
5
|
+
kind: string
|
|
6
|
+
suite: string
|
|
7
|
+
displayName: string
|
|
8
|
+
description: string
|
|
9
|
+
sources: Record<string, string>
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface OneWidgetPackage {
|
|
13
|
+
packagePath: string
|
|
14
|
+
watched: string[]
|
|
15
|
+
widget: OneWidgetMetadata
|
|
16
|
+
}
|
package/src/swift-host.ts
CHANGED
|
@@ -465,7 +465,7 @@ function sourceTreeFiles(dir: string, canonicalRoot: string): string[] {
|
|
|
465
465
|
return found
|
|
466
466
|
}
|
|
467
467
|
|
|
468
|
-
function readPackageFile(root: string, file: string, maxBytes: number): Buffer {
|
|
468
|
+
export function readPackageFile(root: string, file: string, maxBytes: number): Buffer {
|
|
469
469
|
const canonicalRoot = fs.realpathSync(root)
|
|
470
470
|
const relative = path.relative(canonicalRoot, fs.realpathSync(file))
|
|
471
471
|
if (
|
package/src/swift-standins.ts
CHANGED
|
@@ -14,6 +14,7 @@ import { createHash } from 'node:crypto'
|
|
|
14
14
|
import fs from 'node:fs'
|
|
15
15
|
import os from 'node:os'
|
|
16
16
|
import path from 'node:path'
|
|
17
|
+
import { getCliVersion } from './cli-version'
|
|
17
18
|
import {
|
|
18
19
|
swiftDistributionAt,
|
|
19
20
|
swiftMacroPlugins,
|
|
@@ -677,6 +678,8 @@ export function standinGenerationInputs(
|
|
|
677
678
|
swiftModuleSdk(moduleRoot).wasmSdkId,
|
|
678
679
|
swiftModuleDigest(moduleRoot).toString('hex'),
|
|
679
680
|
`emit/${STANDIN_EMIT_VERSION}`,
|
|
681
|
+
// a released cli can change the emitter without anyone bumping the constant
|
|
682
|
+
`cli/${getCliVersion()}`,
|
|
680
683
|
]
|
|
681
684
|
for (const binary of binaries) {
|
|
682
685
|
try {
|
package/src/vite-plugin-one.ts
CHANGED
|
@@ -28,6 +28,7 @@ import {
|
|
|
28
28
|
SOOTSIM_RUNTIME_MISSING_MESSAGE,
|
|
29
29
|
} from './runtime-assets'
|
|
30
30
|
import { SWIFT_HMR_PATH, SWIFT_PACKAGE_PATH } from './swift-submit'
|
|
31
|
+
import type { OneWidgetPackage } from './oneWidgetContract'
|
|
31
32
|
import type { PeachPluginOptions } from './vite'
|
|
32
33
|
import type { Plugin } from 'vite'
|
|
33
34
|
|
|
@@ -88,6 +89,41 @@ export function rnxPlugin(options: PeachPluginOptions = {}): Plugin {
|
|
|
88
89
|
swiftPackages ??= swiftPackageDirectories(server.config.root)
|
|
89
90
|
return swiftPackages
|
|
90
91
|
}
|
|
92
|
+
let widgetPackage: OneWidgetPackage | null = null
|
|
93
|
+
const servedPackage = async (packageName: string) => {
|
|
94
|
+
const host = await loadSwiftHost()
|
|
95
|
+
const existing = packageMap().get(packageName)
|
|
96
|
+
if (packageName !== host.ONE_WIDGET_PACKAGE) return existing
|
|
97
|
+
widgetPackage = await host.oneWidgetPackage(server.config.root)
|
|
98
|
+
if (!widgetPackage) return existing
|
|
99
|
+
if (existing)
|
|
100
|
+
throw new Error(
|
|
101
|
+
`swift package ${packageName} conflicts with One's generated widget extension`,
|
|
102
|
+
)
|
|
103
|
+
server.watcher.add(widgetPackage.watched)
|
|
104
|
+
return widgetPackage.packagePath
|
|
105
|
+
}
|
|
106
|
+
const packageMetadata = async (
|
|
107
|
+
packageName: string,
|
|
108
|
+
moduleRoot: string | undefined,
|
|
109
|
+
) => {
|
|
110
|
+
const packagePath = await servedPackage(packageName)
|
|
111
|
+
if (!packagePath) throw new Error(`swift package ${packageName} was not found`)
|
|
112
|
+
const host = await loadSwiftHost()
|
|
113
|
+
const metadata = await host.swiftPackageMetadata(
|
|
114
|
+
packagePath,
|
|
115
|
+
packageName,
|
|
116
|
+
moduleRoot,
|
|
117
|
+
devOrigin(),
|
|
118
|
+
)
|
|
119
|
+
return {
|
|
120
|
+
...metadata,
|
|
121
|
+
hmrPath,
|
|
122
|
+
...(packageName === host.ONE_WIDGET_PACKAGE && widgetPackage
|
|
123
|
+
? { widget: widgetPackage.widget }
|
|
124
|
+
: {}),
|
|
125
|
+
}
|
|
126
|
+
}
|
|
91
127
|
const wsOptions = server.config.server.ws
|
|
92
128
|
const httpServer =
|
|
93
129
|
server.httpServer ??
|
|
@@ -162,32 +198,25 @@ export function rnxPlugin(options: PeachPluginOptions = {}): Plugin {
|
|
|
162
198
|
try {
|
|
163
199
|
packages = packageMap()
|
|
164
200
|
} catch (error) {
|
|
165
|
-
for (const packageName of activeSwiftPackages)
|
|
201
|
+
for (const packageName of activeSwiftPackages)
|
|
166
202
|
sendSwiftChange({
|
|
167
203
|
type: 'error',
|
|
168
204
|
packageName,
|
|
169
205
|
message: error instanceof Error ? error.message : String(error),
|
|
170
206
|
})
|
|
171
|
-
}
|
|
172
207
|
return
|
|
173
208
|
}
|
|
174
209
|
for (const packageName of activeSwiftPackages) {
|
|
175
210
|
const packagePath = packages.get(packageName)
|
|
176
|
-
|
|
211
|
+
const widgetChanged =
|
|
212
|
+
packageName === 'OneWidgets' && widgetPackage?.watched.includes(file)
|
|
177
213
|
if (
|
|
178
|
-
!
|
|
214
|
+
!widgetChanged &&
|
|
215
|
+
!(packagePath && file.startsWith(`${packagePath}${path.sep}`)) &&
|
|
179
216
|
!(moduleRoot && file.startsWith(`${moduleRoot}${path.sep}`))
|
|
180
217
|
)
|
|
181
218
|
continue
|
|
182
|
-
void
|
|
183
|
-
.then((host) =>
|
|
184
|
-
host.swiftPackageMetadata(
|
|
185
|
-
packagePath,
|
|
186
|
-
packageName,
|
|
187
|
-
moduleRoot,
|
|
188
|
-
devOrigin(),
|
|
189
|
-
),
|
|
190
|
-
)
|
|
219
|
+
void packageMetadata(packageName, moduleRoot)
|
|
191
220
|
.then((metadata) => {
|
|
192
221
|
sendSwiftChange({
|
|
193
222
|
type: 'package',
|
|
@@ -208,7 +237,7 @@ export function rnxPlugin(options: PeachPluginOptions = {}): Plugin {
|
|
|
208
237
|
const pathname = (req.url ?? '').split('?')[0]
|
|
209
238
|
if (!pathname.startsWith(SWIFT_ROUTE_PREFIX)) return next()
|
|
210
239
|
loadSwiftHost()
|
|
211
|
-
.then((host) => {
|
|
240
|
+
.then(async (host) => {
|
|
212
241
|
if (host.serveSwiftPackageAsset(pathname, res)) return
|
|
213
242
|
const prefix = SWIFT_PACKAGE_PATH
|
|
214
243
|
if (!pathname.startsWith(prefix)) return next()
|
|
@@ -220,7 +249,7 @@ export function rnxPlugin(options: PeachPluginOptions = {}): Plugin {
|
|
|
220
249
|
const packageName = pathname.slice(prefix.length)
|
|
221
250
|
let packagePath: string | undefined
|
|
222
251
|
try {
|
|
223
|
-
packagePath =
|
|
252
|
+
packagePath = await servedPackage(packageName)
|
|
224
253
|
} catch (error) {
|
|
225
254
|
res.statusCode = 500
|
|
226
255
|
res.end(error instanceof Error ? error.message : String(error))
|
|
@@ -234,8 +263,7 @@ export function rnxPlugin(options: PeachPluginOptions = {}): Plugin {
|
|
|
234
263
|
const moduleRoot = moduleRootFor()
|
|
235
264
|
activeSwiftPackages.add(packageName)
|
|
236
265
|
server.watcher.add(host.swiftPackageWatchFiles(packagePath, moduleRoot))
|
|
237
|
-
void
|
|
238
|
-
.swiftPackageMetadata(packagePath, packageName, moduleRoot, devOrigin())
|
|
266
|
+
void packageMetadata(packageName, moduleRoot)
|
|
239
267
|
.then((metadata) => {
|
|
240
268
|
res.setHeader('access-control-allow-origin', '*')
|
|
241
269
|
res.setHeader('content-type', 'application/json')
|
package/src/vite-plugin-swift.ts
CHANGED
|
@@ -34,6 +34,8 @@ export {
|
|
|
34
34
|
type SwiftResourceTable,
|
|
35
35
|
} from './swift-host'
|
|
36
36
|
|
|
37
|
+
export { oneWidgetPackage, ONE_WIDGET_PACKAGE } from './one-widget-package'
|
|
38
|
+
|
|
37
39
|
const ARTIFACT_PATH = '/__peach/swift/'
|
|
38
40
|
const VIRTUAL_PREFIX = '\0peach-swift:'
|
|
39
41
|
let devServer: ViteDevServer | undefined
|