peachsim 0.1.781 → 0.1.783
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli/commands/detox.ts +6 -0
- package/cli/main.ts +1 -0
- 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 +3534 -134
- package/dist-lib/dev-bundle-resolution.cjs +1 -1
- package/dist-lib/home-paths.cjs +1 -1
- package/dist-lib/host/bridge-host.cjs +6975 -2893
- 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 +8560 -166
- 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 +1810 -413
- 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-standin-emit.ts +149 -39
- 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.783 | (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 (
|
|
@@ -55,6 +55,10 @@ export type StandinOptions = {
|
|
|
55
55
|
omit?: ReadonlyMap<string, string>
|
|
56
56
|
/** paths the graph says override but the compiler finds nothing to override */
|
|
57
57
|
plain?: ReadonlySet<string>
|
|
58
|
+
/** paths the compiler says must be marked override */
|
|
59
|
+
forcedOverride?: ReadonlySet<string>
|
|
60
|
+
/** operator token → prefix, infix, or postfix, from the swiftinterface */
|
|
61
|
+
operators?: ReadonlyMap<string, string>
|
|
58
62
|
/** class path → its generic superclass with arguments, from the swiftinterface */
|
|
59
63
|
superclasses?: ReadonlyMap<string, string>
|
|
60
64
|
}
|
|
@@ -79,7 +83,7 @@ export type StandinResult = {
|
|
|
79
83
|
}
|
|
80
84
|
|
|
81
85
|
/** bump when emitted source changes: the stand-in cache keys on it. */
|
|
82
|
-
export const STANDIN_EMIT_VERSION = '
|
|
86
|
+
export const STANDIN_EMIT_VERSION = '2'
|
|
83
87
|
|
|
84
88
|
const TYPE_KINDS = new Set([
|
|
85
89
|
'swift.class',
|
|
@@ -98,7 +102,20 @@ const MEMBER_KINDS = new Set([
|
|
|
98
102
|
'swift.subscript',
|
|
99
103
|
'swift.type.subscript',
|
|
100
104
|
])
|
|
101
|
-
const
|
|
105
|
+
const ACCESSOR_WORD =
|
|
106
|
+
/^(?:get|set|nonmutating|mutating|async|throws|rethrows|_read|_modify)$/
|
|
107
|
+
// `{ get }`, `{ get set }`, `{ get nonmutating set }`, `{ get async throws }`
|
|
108
|
+
function splitAccessors(core: string) {
|
|
109
|
+
const match = /\{\s*([^}]*)\}\s*$/.exec(core)
|
|
110
|
+
const words = match ? match[1]!.trim().split(/\s+/).filter(Boolean) : []
|
|
111
|
+
const accessors = words.length > 0 && words.every((word) => ACCESSOR_WORD.test(word))
|
|
112
|
+
return {
|
|
113
|
+
decl: accessors ? core.slice(0, match!.index).trimEnd() : core,
|
|
114
|
+
effects: `${words.includes('async') ? ' async' : ''}${words.includes('throws') ? ' throws' : words.includes('rethrows') ? ' rethrows' : ''}`,
|
|
115
|
+
settable: accessors ? words.includes('set') : /^(?:static |class )?var /.test(core),
|
|
116
|
+
nonmutating: words.includes('nonmutating'),
|
|
117
|
+
}
|
|
118
|
+
}
|
|
102
119
|
// standard protocols a declaration keeps when the graph names them directly;
|
|
103
120
|
// anything else from outside the family drops with a reason (a missing
|
|
104
121
|
// capability, never a trap).
|
|
@@ -136,9 +153,15 @@ const unavailable = (symbol: GraphSymbol) =>
|
|
|
136
153
|
(symbol.availability ?? []).some(
|
|
137
154
|
(entry) => entry.isUnconditionallyUnavailable || entry.obsoleted !== undefined,
|
|
138
155
|
)
|
|
139
|
-
// a witness matches by
|
|
156
|
+
// a witness matches by side and signature. overloads share a leaf (`pow(_:)`).
|
|
140
157
|
const witnessKey = (symbol: GraphSymbol) =>
|
|
141
|
-
`${symbol.kind.identifier.startsWith('swift.type.') ? 'type' : 'instance'}|${
|
|
158
|
+
`${symbol.kind.identifier.startsWith('swift.type.') ? 'type' : 'instance'}|${stripDefaults(
|
|
159
|
+
splitAccessors(text(symbol)).decl,
|
|
160
|
+
)
|
|
161
|
+
.replace(/\s+/g, ' ')
|
|
162
|
+
.trim()}`
|
|
163
|
+
const sideLeaf = (symbol: GraphSymbol) =>
|
|
164
|
+
`${symbol.kind.identifier.startsWith('swift.type.') ? 'type' : 'instance'}|leaf|${leaf(symbol)}`
|
|
142
165
|
const isObjC = (symbol: GraphSymbol) => symbol.identifier.precise.startsWith('c:')
|
|
143
166
|
const trap = (path: string) =>
|
|
144
167
|
`fatalError("${path} is a binary framework peach cannot run")`
|
|
@@ -181,13 +204,12 @@ export function emitSwiftStandin(
|
|
|
181
204
|
if (local) return { name: pathOf(local), local: true }
|
|
182
205
|
if (!fallback) return null
|
|
183
206
|
const parts = fallback.split('.')
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
}
|
|
207
|
+
// swiftinterfaces spell SwiftUI types as SwiftUICore; the import is SwiftUI
|
|
208
|
+
const module = parts[0] === 'SwiftUICore' ? 'SwiftUI' : parts[0]!
|
|
209
|
+
const unqualified = parts.slice(1).join('.') || parts[0]!
|
|
210
|
+
const name =
|
|
211
|
+
family.has(parts[0]!) && parts[0] !== 'SwiftUICore' ? parts.join('.') : unqualified
|
|
212
|
+
return { name, module, local: false }
|
|
191
213
|
}
|
|
192
214
|
for (const graph of graphs)
|
|
193
215
|
for (const edge of graph.relationships) {
|
|
@@ -247,8 +269,52 @@ export function emitSwiftStandin(
|
|
|
247
269
|
case 'overrides':
|
|
248
270
|
overrides.add(edge.source)
|
|
249
271
|
break
|
|
272
|
+
case 'defaultImplementationOf':
|
|
273
|
+
// recorded below, once requirementOf has named each protocol
|
|
274
|
+
break
|
|
250
275
|
}
|
|
251
276
|
}
|
|
277
|
+
// a protocol extension method's edge points at the requirement, not the protocol
|
|
278
|
+
const requirementProtocol = new Map<string, string>()
|
|
279
|
+
const hasDefault = new Set<string>()
|
|
280
|
+
for (const graph of graphs)
|
|
281
|
+
for (const edge of graph.relationships) {
|
|
282
|
+
if (
|
|
283
|
+
(edge.kind === 'requirementOf' || edge.kind === 'optionalRequirementOf') &&
|
|
284
|
+
byId.has(edge.target)
|
|
285
|
+
)
|
|
286
|
+
requirementProtocol.set(edge.source, edge.target)
|
|
287
|
+
if (edge.kind === 'defaultImplementationOf') hasDefault.add(edge.target)
|
|
288
|
+
}
|
|
289
|
+
for (const graph of graphs)
|
|
290
|
+
for (const edge of graph.relationships) {
|
|
291
|
+
if (
|
|
292
|
+
edge.kind !== 'defaultImplementationOf' ||
|
|
293
|
+
!byId.has(edge.source) ||
|
|
294
|
+
owner.has(edge.source)
|
|
295
|
+
)
|
|
296
|
+
continue
|
|
297
|
+
const protocolId = requirementProtocol.get(edge.target)
|
|
298
|
+
if (!protocolId) continue
|
|
299
|
+
owner.set(edge.source, protocolId)
|
|
300
|
+
children.set(protocolId, [...(children.get(protocolId) ?? []), ...all(edge.source)])
|
|
301
|
+
}
|
|
302
|
+
// a member whose extension block the extractor omitted still names its type
|
|
303
|
+
const typeByPath = new Map<string, string>()
|
|
304
|
+
for (const symbol of byId.values())
|
|
305
|
+
if (TYPE_KINDS.has(symbol.kind.identifier))
|
|
306
|
+
typeByPath.set(pathOf(symbol), symbol.identifier.precise)
|
|
307
|
+
for (const symbol of byId.values()) {
|
|
308
|
+
if (owner.has(symbol.identifier.precise) || symbol.pathComponents.length < 2) continue
|
|
309
|
+
if (TYPE_KINDS.has(symbol.kind.identifier)) continue
|
|
310
|
+
const parent = typeByPath.get(symbol.pathComponents.slice(0, -1).join('.'))
|
|
311
|
+
if (!parent) continue
|
|
312
|
+
owner.set(symbol.identifier.precise, parent)
|
|
313
|
+
children.set(parent, [
|
|
314
|
+
...(children.get(parent) ?? []),
|
|
315
|
+
...all(symbol.identifier.precise),
|
|
316
|
+
])
|
|
317
|
+
}
|
|
252
318
|
|
|
253
319
|
const lines: string[] = []
|
|
254
320
|
const owners: string[] = []
|
|
@@ -279,7 +345,8 @@ export function emitSwiftStandin(
|
|
|
279
345
|
const seen = new Set<string>()
|
|
280
346
|
return (children.get(id) ?? []).filter((member) => {
|
|
281
347
|
if (unavailable(member)) return false
|
|
282
|
-
|
|
348
|
+
// a requirement and its protocol-extension default share a spelling and both stay
|
|
349
|
+
const key = `${member.kind.identifier}|${requirement.has(member.identifier.precise) ? 'req' : 'ext'}|${text(member)}`
|
|
283
350
|
if (seen.has(key)) return false
|
|
284
351
|
seen.add(key)
|
|
285
352
|
return true
|
|
@@ -324,13 +391,15 @@ export function emitSwiftStandin(
|
|
|
324
391
|
: flags.has('nonmutating')
|
|
325
392
|
? 'nonmutating '
|
|
326
393
|
: ''
|
|
327
|
-
|
|
394
|
+
// the graph already spelled convenience; an external class extension is not inClass
|
|
395
|
+
let core = `${flags.has('convenience') ? 'convenience ' : ''}${modifiers[2]!}`
|
|
328
396
|
// a class's init() always overrides NSObject's in an objective-c class
|
|
329
397
|
const override =
|
|
330
398
|
context.inClass &&
|
|
331
399
|
!options.plain?.has(path) &&
|
|
332
400
|
(flags.has('override') ||
|
|
333
401
|
overrides.has(member.identifier.precise) ||
|
|
402
|
+
options.forcedOverride?.has(path) ||
|
|
334
403
|
(isObjC(member) && path.endsWith('.init()')))
|
|
335
404
|
? 'override '
|
|
336
405
|
: ''
|
|
@@ -348,12 +417,10 @@ export function emitSwiftStandin(
|
|
|
348
417
|
case 'swift.type.property':
|
|
349
418
|
case 'swift.subscript':
|
|
350
419
|
case 'swift.type.subscript': {
|
|
351
|
-
const
|
|
352
|
-
const decl =
|
|
353
|
-
const effects =
|
|
354
|
-
const settable =
|
|
355
|
-
? Boolean(accessors[3])
|
|
356
|
-
: /^(?:static |class )?var /.test(core)
|
|
420
|
+
const parsed = splitAccessors(core)
|
|
421
|
+
const decl = parsed.decl
|
|
422
|
+
const effects = parsed.effects
|
|
423
|
+
const settable = parsed.settable
|
|
357
424
|
const computed = decl.replace(/^((?:static |class )*)let /, '$1var ')
|
|
358
425
|
if (measured?.stored !== undefined) {
|
|
359
426
|
// a read-only sdk property stays read-only outside the module
|
|
@@ -370,7 +437,7 @@ export function emitSwiftStandin(
|
|
|
370
437
|
return
|
|
371
438
|
}
|
|
372
439
|
emit(
|
|
373
|
-
`${head}${computed} { get${effects} { ${body} }${settable && !effects ? ` set { ${measured?.set ?? trap(path)} }` : ''} }`,
|
|
440
|
+
`${head}${computed} { get${effects} { ${body} }${settable && !effects ? ` ${parsed.nonmutating ? 'nonmutating ' : ''}set { ${measured?.set ?? trap(path)} }` : ''} }`,
|
|
374
441
|
)
|
|
375
442
|
return
|
|
376
443
|
}
|
|
@@ -498,9 +565,25 @@ export function emitSwiftStandin(
|
|
|
498
565
|
// an objective-c class implements its protocols' requirements in the
|
|
499
566
|
// binary without restating them in its header; swift needs a
|
|
500
567
|
// witness, which traps like every other member.
|
|
568
|
+
// a class restates a requirement with its own modifiers, parameter
|
|
569
|
+
// names and Self, so a name on the same side meets it; only overloads
|
|
570
|
+
// sharing that name (`pow(_:)`) need the whole signature to match.
|
|
501
571
|
const have = new Set<string>()
|
|
502
572
|
for (let at: string | undefined = id; at; at = superId.get(at))
|
|
503
|
-
for (const member of children.get(at) ?? [])
|
|
573
|
+
for (const member of children.get(at) ?? []) {
|
|
574
|
+
have.add(witnessKey(member))
|
|
575
|
+
have.add(sideLeaf(member))
|
|
576
|
+
}
|
|
577
|
+
// a superclass that already conforms supplies the requirements, including
|
|
578
|
+
// ones a protocol extension implements, so a subclass does not restate them
|
|
579
|
+
const covered = new Set<string>()
|
|
580
|
+
const cover = (protocolId: string) => {
|
|
581
|
+
if (covered.has(protocolId)) return
|
|
582
|
+
covered.add(protocolId)
|
|
583
|
+
for (const edge of protocolParents.get(protocolId) ?? []) cover(edge)
|
|
584
|
+
}
|
|
585
|
+
for (let at = superId.get(id); at; at = superId.get(at))
|
|
586
|
+
for (const protocolId of conformIds.get(at) ?? []) cover(protocolId)
|
|
504
587
|
const protocols: string[] = []
|
|
505
588
|
const visit = (protocolId: string) => {
|
|
506
589
|
if (protocols.includes(protocolId)) return
|
|
@@ -508,22 +591,33 @@ export function emitSwiftStandin(
|
|
|
508
591
|
for (const edge of protocolParents.get(protocolId) ?? []) visit(edge)
|
|
509
592
|
}
|
|
510
593
|
for (const protocolId of conformIds.get(id) ?? []) visit(protocolId)
|
|
594
|
+
const overloaded = new Set<string>()
|
|
595
|
+
const named = new Set<string>()
|
|
511
596
|
for (const protocolId of protocols)
|
|
597
|
+
for (const member of children.get(protocolId) ?? []) {
|
|
598
|
+
if (!requirement.has(member.identifier.precise)) continue
|
|
599
|
+
if (named.has(sideLeaf(member))) overloaded.add(sideLeaf(member))
|
|
600
|
+
named.add(sideLeaf(member))
|
|
601
|
+
}
|
|
602
|
+
const met = (member: GraphSymbol) =>
|
|
603
|
+
have.has(witnessKey(member)) ||
|
|
604
|
+
(!overloaded.has(sideLeaf(member)) && have.has(sideLeaf(member)))
|
|
605
|
+
for (const protocolId of protocols) {
|
|
606
|
+
if (covered.has(protocolId)) continue
|
|
512
607
|
for (const member of children.get(protocolId) ?? []) {
|
|
513
608
|
if (
|
|
514
609
|
!requirement.has(member.identifier.precise) ||
|
|
515
610
|
optional.has(member.identifier.precise)
|
|
516
611
|
)
|
|
517
612
|
continue
|
|
613
|
+
if (hasDefault.has(member.identifier.precise)) continue
|
|
518
614
|
if (isObjC(member) && / async\b/.test(text(member))) continue
|
|
519
|
-
if (
|
|
520
|
-
have.has(witnessKey(member)) ||
|
|
521
|
-
member.kind.identifier === 'swift.associatedtype'
|
|
522
|
-
)
|
|
523
|
-
continue
|
|
615
|
+
if (met(member) || member.kind.identifier === 'swift.associatedtype') continue
|
|
524
616
|
have.add(witnessKey(member))
|
|
617
|
+
have.add(sideLeaf(member))
|
|
525
618
|
emitWitness(member, inner, path)
|
|
526
619
|
}
|
|
620
|
+
}
|
|
527
621
|
const coder = members.some((member) => leaf(member) === 'init(coder:)')
|
|
528
622
|
if (
|
|
529
623
|
designated &&
|
|
@@ -659,7 +753,11 @@ export function emitSwiftStandin(
|
|
|
659
753
|
continue
|
|
660
754
|
}
|
|
661
755
|
emitRequirement(member, inner)
|
|
662
|
-
if (
|
|
756
|
+
if (
|
|
757
|
+
optional.has(member.identifier.precise) &&
|
|
758
|
+
!hasDefault.has(member.identifier.precise)
|
|
759
|
+
)
|
|
760
|
+
defaults.push(member)
|
|
663
761
|
}
|
|
664
762
|
emit(`${indent}}`)
|
|
665
763
|
if (defaults.length > 0) {
|
|
@@ -701,11 +799,11 @@ export function emitSwiftStandin(
|
|
|
701
799
|
member.kind.identifier === 'swift.property' ||
|
|
702
800
|
member.kind.identifier === 'swift.type.property'
|
|
703
801
|
) {
|
|
704
|
-
const
|
|
705
|
-
const
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
)
|
|
802
|
+
const parsed = splitAccessors(decl)
|
|
803
|
+
const setter = parsed.settable
|
|
804
|
+
? ` ${parsed.nonmutating ? 'nonmutating ' : ''}set { ${body} }`
|
|
805
|
+
: ''
|
|
806
|
+
emit(`${indent}public ${parsed.decl} { get${parsed.effects} { ${body} }${setter} }`)
|
|
709
807
|
} else
|
|
710
808
|
emit(
|
|
711
809
|
`${indent}public ${member.kind.identifier === 'swift.init' ? 'required ' : ''}${stripDefaults(decl)} { ${body} }`,
|
|
@@ -731,20 +829,32 @@ export function emitSwiftStandin(
|
|
|
731
829
|
|
|
732
830
|
const emitGlobal = scoped((symbol: GraphSymbol) => {
|
|
733
831
|
const path = pathOf(symbol)
|
|
832
|
+
const kind = symbol.kind.identifier
|
|
734
833
|
if (
|
|
735
|
-
|
|
736
|
-
|
|
834
|
+
kind === 'swift.func' ||
|
|
835
|
+
kind === 'swift.func.op' ||
|
|
836
|
+
kind === 'swift.method' ||
|
|
837
|
+
kind === 'swift.type.method'
|
|
737
838
|
) {
|
|
738
839
|
const { 1: attrs, 2: rest } = LEADING_ATTRS.exec(text(symbol))!
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
840
|
+
let spelled = rest!
|
|
841
|
+
if (kind === 'swift.func.op') {
|
|
842
|
+
const token = /func\s+(\S+)/.exec(spelled)?.[1]
|
|
843
|
+
const fix = token ? options.operators?.get(token) : undefined
|
|
844
|
+
if (fix && !/^(?:prefix|infix|postfix)\b/.test(spelled))
|
|
845
|
+
spelled = `${fix} ${spelled}`
|
|
846
|
+
}
|
|
847
|
+
emit(`${attrs}public ${spelled} { ${trap(path)} }`)
|
|
848
|
+
} else if (kind === 'swift.var') {
|
|
849
|
+
const parsed = splitAccessors(text(symbol).replace(/^let /, 'var '))
|
|
742
850
|
// a measured global keeps the sdk's declaration with a working getter,
|
|
743
851
|
// the same way a member keeps its declaration with a working body.
|
|
852
|
+
// a top-level var stays get-only: the graph often spells a constant
|
|
853
|
+
// as `var` with no setter.
|
|
744
854
|
const measured = behavior.get(path)
|
|
745
855
|
if (measured) used.add(path)
|
|
746
|
-
emit(`public ${decl} { ${measured?.body ?? trap(path)} }`)
|
|
747
|
-
} else skipped.push({ path, reason: `unhandled top-level ${
|
|
856
|
+
emit(`public ${parsed.decl} { ${measured?.body ?? trap(path)} }`)
|
|
857
|
+
} else skipped.push({ path, reason: `unhandled top-level ${kind}` })
|
|
748
858
|
})
|
|
749
859
|
|
|
750
860
|
const roots = [...byId.values()]
|