peachsim 0.1.730 → 0.1.745
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/bridge-flow-runner.ts +15 -2
- package/cli/commands/control.ts +13 -3
- package/cli/commands/desktop.ts +1 -0
- package/cli/commands/electron.ts +12 -8
- package/cli/commands/flow.ts +1 -3
- package/cli/commands/install-desktop.ts +105 -66
- package/cli/commands/logout.ts +5 -1
- package/cli/commands/no-bridge-hint.ts +2 -2
- package/cli/commands/swift.ts +26 -9
- package/cli/desktop-companion.ts +36 -9
- package/cli/drivers/desktop.ts +65 -0
- package/cli/drivers/electron.ts +4 -66
- package/cli/drivers/index.ts +1 -0
- package/cli/drivers/playwright.ts +3 -3
- package/cli/drivers/registry.ts +7 -2
- package/cli/drivers/types.ts +4 -3
- package/cli/maestro-js.ts +10 -0
- package/cli/outbound-endpoints.ts +2 -2
- 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 +39 -9
- 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 +13 -19
- package/dist-lib/capture-contract.mjs +13 -19
- 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 +20 -2
- package/dist-lib/dev-bundle-resolution.cjs +1 -1
- package/dist-lib/home-paths.cjs +32 -1
- package/dist-lib/host/bridge-host.cjs +1616 -532
- 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 +14 -19
- 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 +1 -1
- 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 +2 -1
- package/dist-lib/sdk.mjs +2 -1
- package/dist-lib/skills.cjs +2306 -1067
- package/dist-lib/swift-compile.cjs +317 -60
- package/dist-lib/swift-compile.mjs +313 -61
- package/dist-lib/swift-package.cjs +146 -9
- package/dist-lib/swift-package.mjs +144 -9
- package/dist-lib/swift-submit.cjs +2 -2
- package/dist-lib/swift-submit.mjs +2 -2
- package/dist-lib/swift-toolchain.cjs +1 -1
- package/dist-lib/swift.cjs +1 -1
- package/dist-lib/vite-swift.cjs +1310 -226
- package/dist-lib/vite.cjs +1 -1
- package/package.json +1 -1
- package/skills/contrast/SKILL.md +1 -1
- package/src/auth/shared-session.ts +45 -9
- package/src/bridge-constants.ts +7 -7
- package/src/capture-contract.ts +18 -33
- package/src/desktop-host-delivery.ts +81 -0
- package/src/home-paths.ts +30 -0
- package/src/host/bridge-host.ts +11 -6
- package/src/native-seam-manifest.ts +0 -11
- package/src/sim-client.ts +1 -0
- package/src/swift-compile.ts +403 -68
- package/src/swift-distribution.lock.json +11 -11
- package/src/swift-host.ts +316 -43
- package/src/swift-package.ts +204 -19
- package/src/swift-remote-packages.ts +255 -0
- package/src/swift-submit.ts +4 -1
- package/src/vite-plugin.ts +19 -8
- package/src/xcode-project.ts +527 -0
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
{
|
|
2
|
-
"id": "
|
|
2
|
+
"id": "d27a9b6d2aee64d4",
|
|
3
3
|
"release": "swift-6.3-RELEASE",
|
|
4
|
-
"wasmSdkId": "swift-6.3-RELEASE_wasm-peach-
|
|
5
|
-
"wasmSdkUrl": "https://r2.sootsim.com/swift-wasm-sdk/swift-6.3-RELEASE_wasm-peach-
|
|
6
|
-
"wasmSdkChecksum": "
|
|
7
|
-
"source": "
|
|
4
|
+
"wasmSdkId": "swift-6.3-RELEASE_wasm-peach-41921598-peach-26be2317",
|
|
5
|
+
"wasmSdkUrl": "https://r2.sootsim.com/swift-wasm-sdk/swift-6.3-RELEASE_wasm-peach-41921598-peach-26be2317.artifactbundle.tar.gz",
|
|
6
|
+
"wasmSdkChecksum": "f34f29d9426f42b04d1c38585d61cf38ecb5357f4287c4843870bec63de6b08c",
|
|
7
|
+
"source": "8f9873608a950d832ec49cf4bbc32fb65689e5f7",
|
|
8
8
|
"hosts": {
|
|
9
9
|
"darwin-arm64": {
|
|
10
|
-
"sha256": "
|
|
11
|
-
"size":
|
|
10
|
+
"sha256": "b7fa68565ae1be6ee7964390b4d07949228894ac4a06fe7f58e4238dd0650197",
|
|
11
|
+
"size": 19319227
|
|
12
12
|
},
|
|
13
13
|
"linux-x64": {
|
|
14
|
-
"sha256": "
|
|
15
|
-
"size":
|
|
14
|
+
"sha256": "733ebee3a16142c97575532daf49990df57171ede17de6530a9c5906471d96ca",
|
|
15
|
+
"size": 19324099
|
|
16
16
|
},
|
|
17
17
|
"linux-arm64": {
|
|
18
|
-
"sha256": "
|
|
19
|
-
"size":
|
|
18
|
+
"sha256": "84b258d95a71536392f25d2afb8c40835df771594a2c0e42049ee33781ce78ad",
|
|
19
|
+
"size": 19323438
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
}
|
package/src/swift-host.ts
CHANGED
|
@@ -15,11 +15,20 @@ import { authHeaderValue, resolveCliAuth } from '../cli/auth'
|
|
|
15
15
|
import { resolveContrastBackendOrigin } from './backend-origin'
|
|
16
16
|
import {
|
|
17
17
|
compileSwiftProjectUnit,
|
|
18
|
+
compileTargets,
|
|
19
|
+
missingSwiftModules,
|
|
20
|
+
swiftAvailableModules,
|
|
21
|
+
swiftPeachModules,
|
|
18
22
|
withNativeSourceGlue,
|
|
19
23
|
swiftModuleInputFiles,
|
|
20
24
|
} from './swift-compile'
|
|
21
25
|
import { swiftDistributionRoot, swiftModuleToolchain } from './swift-distribution'
|
|
22
|
-
import { swiftImplicitResourcePaths } from './swift-package'
|
|
26
|
+
import { swiftImplicitResourcePaths, swiftManifestTargets } from './swift-package'
|
|
27
|
+
import {
|
|
28
|
+
REMOTE_CHECKOUTS,
|
|
29
|
+
resolveRemotePackages,
|
|
30
|
+
type RemotePackages,
|
|
31
|
+
} from './swift-remote-packages'
|
|
23
32
|
import {
|
|
24
33
|
MAX_SWIFT_COMPILE_FILES,
|
|
25
34
|
MAX_SWIFT_COMPILE_SOURCE_BYTES,
|
|
@@ -36,6 +45,7 @@ import {
|
|
|
36
45
|
type SwiftImageUpload,
|
|
37
46
|
type SwiftNativeModules,
|
|
38
47
|
} from './swift-submit'
|
|
48
|
+
import { readXcodeAppTarget, type XcodeAppTarget } from './xcode-project'
|
|
39
49
|
import type { SwiftEntryModuleArgs } from '../../sootsim-swift/src/entryModule'
|
|
40
50
|
import type {
|
|
41
51
|
AppCatalogColor,
|
|
@@ -162,10 +172,151 @@ export function projectFor(
|
|
|
162
172
|
return created
|
|
163
173
|
}
|
|
164
174
|
|
|
175
|
+
// an xcode project compiles its application target, not its directory: the
|
|
176
|
+
// project directory is the package path, and the target's member files, plus
|
|
177
|
+
// the local packages it links, are the input tree.
|
|
178
|
+
interface XcodeProjectEntry {
|
|
179
|
+
xcodeproj: string
|
|
180
|
+
target?: string
|
|
181
|
+
/** peach's own modules: a remote product named one links it, never its source. */
|
|
182
|
+
provided: ReadonlySet<string> | null
|
|
183
|
+
remote?: { key: string; packages: RemotePackages }
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const xcodeProjects = new Map<string, XcodeProjectEntry>()
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* registers an xcode project's application target as a compile unit and
|
|
190
|
+
* returns the package path that names it. compiling locally against
|
|
191
|
+
* `moduleRoot`, its remote package products compile from their pinned source;
|
|
192
|
+
* a hosted compile has no local module to tell which products peach provides.
|
|
193
|
+
*/
|
|
194
|
+
export function openXcodeProject(
|
|
195
|
+
xcodeproj: string,
|
|
196
|
+
target: string | undefined,
|
|
197
|
+
moduleRoot: string | undefined,
|
|
198
|
+
): string {
|
|
199
|
+
const app = readXcodeAppTarget(xcodeproj, target)
|
|
200
|
+
const root = fs.realpathSync(app.projectDir)
|
|
201
|
+
xcodeProjects.set(root, {
|
|
202
|
+
xcodeproj,
|
|
203
|
+
target: app.name,
|
|
204
|
+
provided: moduleRoot ? new Set(swiftPeachModules(moduleRoot)) : null,
|
|
205
|
+
})
|
|
206
|
+
return root
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// remote packages resolve once per set of linked products and pins.
|
|
210
|
+
function remotePackages(entry: XcodeProjectEntry, app: XcodeAppTarget): RemotePackages {
|
|
211
|
+
if (!entry.provided) return { targets: [], unavailable: new Map() }
|
|
212
|
+
const key = JSON.stringify([
|
|
213
|
+
app.remoteProducts,
|
|
214
|
+
app.packageResolved,
|
|
215
|
+
app.packageResolved ? fs.statSync(app.packageResolved).mtimeMs : 0,
|
|
216
|
+
])
|
|
217
|
+
if (entry.remote?.key !== key) {
|
|
218
|
+
entry.remote = {
|
|
219
|
+
key,
|
|
220
|
+
packages: resolveRemotePackages(
|
|
221
|
+
fs.realpathSync(app.projectDir),
|
|
222
|
+
app.packageResolved,
|
|
223
|
+
app.remoteProducts,
|
|
224
|
+
entry.provided,
|
|
225
|
+
),
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
return entry.remote.packages
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// the app target's sources compile as one executable target under this
|
|
232
|
+
// directory, each at its project-relative path, so a diagnostic still names
|
|
233
|
+
// the file; local package targets keep their own project-relative paths.
|
|
234
|
+
export const XCODE_APP_DIR = '__app__'
|
|
235
|
+
// remote package checkouts compile here: swiftpm owns `.build` in the
|
|
236
|
+
// compile's package root as its scratch directory.
|
|
237
|
+
const XCODE_PACKAGES_DIR = '__packages__'
|
|
238
|
+
const CHECKOUTS_PREFIX = `${REMOTE_CHECKOUTS.split(path.sep).join(path.posix.sep)}/`
|
|
239
|
+
|
|
240
|
+
// the compile input key of a project-relative path in an xcode layout.
|
|
241
|
+
function xcodeInputKey(appSources: Set<string>, file: string, relative: string): string {
|
|
242
|
+
if (appSources.has(file)) return path.posix.join(XCODE_APP_DIR, relative)
|
|
243
|
+
return relative.startsWith(CHECKOUTS_PREFIX)
|
|
244
|
+
? path.posix.join(XCODE_PACKAGES_DIR, relative.slice(CHECKOUTS_PREFIX.length))
|
|
245
|
+
: relative
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
interface XcodeLayout {
|
|
249
|
+
app: XcodeAppTarget
|
|
250
|
+
/** the local and remote package targets the app links, with project-relative paths. */
|
|
251
|
+
targets: ReturnType<typeof swiftManifestTargets>
|
|
252
|
+
/** remote products that cannot compile, with why. */
|
|
253
|
+
unavailable: RemotePackages['unavailable']
|
|
254
|
+
files: string[]
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
function xcodeLayout(root: string): XcodeLayout | null {
|
|
258
|
+
const registered = xcodeProjects.get(root)
|
|
259
|
+
if (!registered) return null
|
|
260
|
+
const app = readXcodeAppTarget(registered.xcodeproj, registered.target)
|
|
261
|
+
const files = new Set([app.pbxproj, ...app.sources, ...app.resources])
|
|
262
|
+
const targets: XcodeLayout['targets'] = []
|
|
263
|
+
for (const dir of app.localPackages) {
|
|
264
|
+
const manifest = path.join(dir, 'Package.swift')
|
|
265
|
+
files.add(manifest)
|
|
266
|
+
const prefix = path.relative(root, dir).split(path.sep).join(path.posix.sep)
|
|
267
|
+
const all = packageFiles(dir).map((file) =>
|
|
268
|
+
path.relative(dir, file).split(path.sep).join(path.posix.sep),
|
|
269
|
+
)
|
|
270
|
+
for (const target of swiftManifestTargets(fs.readFileSync(manifest, 'utf8'), all)) {
|
|
271
|
+
if (target.executable) continue
|
|
272
|
+
targets.push({ ...target, path: path.posix.join(prefix, target.path) })
|
|
273
|
+
for (const relative of all) {
|
|
274
|
+
if (relative.startsWith(`${target.path}/`)) files.add(path.join(dir, relative))
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
const remote = remotePackages(registered, app)
|
|
279
|
+
for (const target of remote.targets) {
|
|
280
|
+
targets.push({
|
|
281
|
+
...target,
|
|
282
|
+
path: path.posix.join(
|
|
283
|
+
XCODE_PACKAGES_DIR,
|
|
284
|
+
path
|
|
285
|
+
.relative(path.join(root, REMOTE_CHECKOUTS), target.dir)
|
|
286
|
+
.split(path.sep)
|
|
287
|
+
.join(path.posix.sep),
|
|
288
|
+
),
|
|
289
|
+
})
|
|
290
|
+
for (const file of target.files) files.add(file)
|
|
291
|
+
}
|
|
292
|
+
return { app, targets, unavailable: remote.unavailable, files: [...files].sort() }
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// the manifest the compile reads for an xcode app: the app target and each
|
|
296
|
+
// linked local package target, in the forms swiftManifestTargets scans.
|
|
297
|
+
function xcodeManifest(layout: XcodeLayout): string {
|
|
298
|
+
const settings = (mode: number, mainActor: boolean) =>
|
|
299
|
+
`swiftSettings: [.swiftLanguageMode(.v${mode})${mainActor ? ', .defaultIsolation(MainActor.self)' : ''}]`
|
|
300
|
+
return [
|
|
301
|
+
'// swift-tools-version: 6.2',
|
|
302
|
+
'import PackageDescription',
|
|
303
|
+
'let package = Package(name: "app", targets: [',
|
|
304
|
+
` .executableTarget(name: "${layout.app.moduleName}", path: "${XCODE_APP_DIR}", ${settings(layout.app.languageMode, layout.app.mainActorIsolation)}),`,
|
|
305
|
+
...layout.targets.map(
|
|
306
|
+
(target) =>
|
|
307
|
+
` .target(name: "${target.name}", path: "${target.path}", ${target.resources ? 'resources: [], ' : ''}${settings(target.languageMode, target.mainActorIsolation)}),`,
|
|
308
|
+
),
|
|
309
|
+
'])',
|
|
310
|
+
'',
|
|
311
|
+
].join('\n')
|
|
312
|
+
}
|
|
313
|
+
|
|
165
314
|
// preflight the entire input tree before reading any source or resource bytes.
|
|
166
315
|
// a nested package is a separate compile unit; ignored build trees never enter it.
|
|
167
316
|
function packageFiles(root: string): string[] {
|
|
168
317
|
const canonicalRoot = fs.realpathSync(root)
|
|
318
|
+
const xcode = xcodeLayout(canonicalRoot)
|
|
319
|
+
if (xcode) return xcode.files
|
|
169
320
|
const found: string[] = []
|
|
170
321
|
const walk = (dir: string): void => {
|
|
171
322
|
for (const entry of fs
|
|
@@ -249,21 +400,35 @@ function readPackageFile(root: string, file: string, maxBytes: number): Buffer {
|
|
|
249
400
|
}
|
|
250
401
|
|
|
251
402
|
export function sourceFiles(root: string): string[] {
|
|
252
|
-
|
|
253
|
-
if (
|
|
254
|
-
files.length > MAX_SWIFT_COMPILE_FILES ||
|
|
255
|
-
files.reduce((total, file) => total + fs.statSync(file).size, 0) >
|
|
256
|
-
MAX_SWIFT_COMPILE_SOURCE_BYTES
|
|
257
|
-
) {
|
|
258
|
-
throw new Error('swift sources exceed the compile service caps')
|
|
259
|
-
}
|
|
260
|
-
return files
|
|
403
|
+
return packageFiles(root).filter((file) => file.endsWith('.swift'))
|
|
261
404
|
}
|
|
262
405
|
|
|
263
406
|
function resourceCandidateFiles(root: string): string[] {
|
|
264
|
-
return packageFiles(root).filter(
|
|
407
|
+
return packageFiles(root).filter(
|
|
408
|
+
(file) => !file.endsWith('.swift') && path.basename(file) !== 'project.pbxproj',
|
|
409
|
+
)
|
|
265
410
|
}
|
|
266
411
|
|
|
412
|
+
// the hosted compile service caps what a project sends it; a local compile
|
|
413
|
+
// reads the author's own files, so nothing caps them there.
|
|
414
|
+
const HOSTED_LIMITS = {
|
|
415
|
+
resources: MAX_SWIFT_COMPILE_RESOURCES,
|
|
416
|
+
resourceBytes: MAX_SWIFT_COMPILE_RESOURCE_BYTES,
|
|
417
|
+
resourceTotalBytes: MAX_SWIFT_COMPILE_RESOURCE_TOTAL_BYTES,
|
|
418
|
+
images: MAX_SWIFT_COMPILE_IMAGES,
|
|
419
|
+
imageBytes: MAX_SWIFT_COMPILE_IMAGE_BYTES,
|
|
420
|
+
imageTotalBytes: MAX_SWIFT_COMPILE_IMAGE_TOTAL_BYTES,
|
|
421
|
+
}
|
|
422
|
+
const LOCAL_LIMITS: typeof HOSTED_LIMITS = {
|
|
423
|
+
resources: Infinity,
|
|
424
|
+
resourceBytes: Infinity,
|
|
425
|
+
resourceTotalBytes: Infinity,
|
|
426
|
+
images: Infinity,
|
|
427
|
+
imageBytes: Infinity,
|
|
428
|
+
imageTotalBytes: Infinity,
|
|
429
|
+
}
|
|
430
|
+
const inputLimits = (hosted: boolean) => (hosted ? HOSTED_LIMITS : LOCAL_LIMITS)
|
|
431
|
+
|
|
267
432
|
const RESOURCE_CONTENT_TYPES: Record<string, string> = {
|
|
268
433
|
'.avif': 'image/avif',
|
|
269
434
|
'.bmp': 'image/bmp',
|
|
@@ -295,6 +460,7 @@ export function buildSwiftResourceTable(
|
|
|
295
460
|
project: SwiftProject,
|
|
296
461
|
baseUrl: string,
|
|
297
462
|
): SwiftResourceTable {
|
|
463
|
+
const limits = inputLimits(Boolean(project.hosted))
|
|
298
464
|
const absolute = resourceCandidateFiles(project.packagePath)
|
|
299
465
|
const relative = absolute.map((file) =>
|
|
300
466
|
path.relative(project.packagePath, file).split(path.sep).join(path.posix.sep),
|
|
@@ -305,11 +471,9 @@ export function buildSwiftResourceTable(
|
|
|
305
471
|
// catalog json, and the glyph template a symbolset names
|
|
306
472
|
if (!file || !/(^|\/)Contents\.json$|\.symbolset\/[^/]+\.svg$/.test(candidate))
|
|
307
473
|
return null
|
|
308
|
-
return readPackageFile(
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
MAX_SWIFT_COMPILE_RESOURCE_BYTES,
|
|
312
|
-
).toString('utf8')
|
|
474
|
+
return readPackageFile(project.packagePath, file, limits.resourceBytes).toString(
|
|
475
|
+
'utf8',
|
|
476
|
+
)
|
|
313
477
|
}
|
|
314
478
|
const found = enumerateBundleImages(relative, readContents)
|
|
315
479
|
const colors = enumerateBundleColors(relative, readContents)
|
|
@@ -323,16 +487,12 @@ export function buildSwiftResourceTable(
|
|
|
323
487
|
const disk = byRelative.get(file)
|
|
324
488
|
if (!disk) continue
|
|
325
489
|
if (
|
|
326
|
-
Object.keys(images).length >=
|
|
327
|
-
imageBytes + fs.statSync(disk).size >
|
|
490
|
+
Object.keys(images).length >= limits.images ||
|
|
491
|
+
imageBytes + fs.statSync(disk).size > limits.imageTotalBytes
|
|
328
492
|
) {
|
|
329
493
|
throw new Error('swift image pack exceeds the compile service caps')
|
|
330
494
|
}
|
|
331
|
-
const bytes = readPackageFile(
|
|
332
|
-
project.packagePath,
|
|
333
|
-
disk,
|
|
334
|
-
MAX_SWIFT_COMPILE_IMAGE_BYTES,
|
|
335
|
-
)
|
|
495
|
+
const bytes = readPackageFile(project.packagePath, disk, limits.imageBytes)
|
|
336
496
|
imageBytes += bytes.length
|
|
337
497
|
const hash = createHash('sha256').update(bytes).digest('hex').slice(0, 16)
|
|
338
498
|
const ext = path.posix.extname(file).toLowerCase()
|
|
@@ -374,9 +534,6 @@ export function buildSwiftResourceTable(
|
|
|
374
534
|
// paths pack first (the Resources root is the bundle root) with a lexical
|
|
375
535
|
// tiebreak, and the first spelling of a basename wins a collision. data json
|
|
376
536
|
// bundle caps match the hosted compiler; oversized input refuses before reading.
|
|
377
|
-
const BUNDLE_MAX_FILES = MAX_SWIFT_COMPILE_RESOURCES
|
|
378
|
-
const BUNDLE_MAX_FILE_BYTES = MAX_SWIFT_COMPILE_RESOURCE_BYTES
|
|
379
|
-
const BUNDLE_MAX_TOTAL_BYTES = MAX_SWIFT_COMPILE_RESOURCE_TOTAL_BYTES
|
|
380
537
|
|
|
381
538
|
export interface SwiftBundlePack {
|
|
382
539
|
/** basename to base64 bytes for the mount's /res. */
|
|
@@ -385,8 +542,12 @@ export interface SwiftBundlePack {
|
|
|
385
542
|
watched: string[]
|
|
386
543
|
}
|
|
387
544
|
|
|
388
|
-
export function buildSwiftBundleFiles(
|
|
545
|
+
export function buildSwiftBundleFiles(
|
|
546
|
+
packagePath: string,
|
|
547
|
+
hosted: boolean,
|
|
548
|
+
): SwiftBundlePack {
|
|
389
549
|
packagePath = fs.realpathSync(packagePath)
|
|
550
|
+
const limits = inputLimits(hosted)
|
|
390
551
|
// resourceCandidateFiles walks every non-ignored file with the nested
|
|
391
552
|
// package exclusion; the shared enumeration decides namespace, order and
|
|
392
553
|
// collisions, identically for every host that packs.
|
|
@@ -400,14 +561,14 @@ export function buildSwiftBundleFiles(packagePath: string): SwiftBundlePack {
|
|
|
400
561
|
watched.push(file)
|
|
401
562
|
const disk = path.join(packagePath, ...file.split('/'))
|
|
402
563
|
if (
|
|
403
|
-
Object.keys(files).length >=
|
|
404
|
-
total + fs.statSync(disk).size >
|
|
564
|
+
Object.keys(files).length >= limits.resources ||
|
|
565
|
+
total + fs.statSync(disk).size > limits.resourceTotalBytes
|
|
405
566
|
) {
|
|
406
567
|
throw new Error(
|
|
407
|
-
`swift bundle pack exceeds ${
|
|
568
|
+
`swift bundle pack exceeds ${limits.resources} files / ${limits.resourceTotalBytes} bytes`,
|
|
408
569
|
)
|
|
409
570
|
}
|
|
410
|
-
const bytes = readPackageFile(packagePath, disk,
|
|
571
|
+
const bytes = readPackageFile(packagePath, disk, limits.resourceBytes)
|
|
411
572
|
files[base] = bytes.toString('base64')
|
|
412
573
|
total += bytes.length
|
|
413
574
|
}
|
|
@@ -501,22 +662,19 @@ export function icuUrl(origin: string, artifact: SwiftArtifact): string {
|
|
|
501
662
|
}
|
|
502
663
|
|
|
503
664
|
function packageSources(packagePath: string): Record<string, string> {
|
|
504
|
-
const
|
|
505
|
-
|
|
506
|
-
throw new Error('swift source file cap exceeded')
|
|
507
|
-
let total = 0
|
|
508
|
-
for (const file of sources) total += fs.statSync(file).size
|
|
509
|
-
if (total > MAX_SWIFT_COMPILE_SOURCE_BYTES)
|
|
510
|
-
throw new Error('swift source byte cap exceeded')
|
|
665
|
+
const xcode = xcodeLayout(packagePath)
|
|
666
|
+
const appSources = new Set(xcode?.app.sources)
|
|
511
667
|
const files: Record<string, string> = {}
|
|
512
|
-
for (const file of
|
|
668
|
+
for (const file of sourceFiles(packagePath)) {
|
|
513
669
|
const relative = path.relative(packagePath, file).split(path.sep).join(path.posix.sep)
|
|
514
|
-
|
|
670
|
+
if (xcode && path.basename(file) === 'Package.swift') continue
|
|
671
|
+
files[xcode ? xcodeInputKey(appSources, file, relative) : relative] = readPackageFile(
|
|
515
672
|
packagePath,
|
|
516
673
|
file,
|
|
517
674
|
MAX_SWIFT_COMPILE_SOURCE_BYTES,
|
|
518
675
|
).toString('utf8')
|
|
519
676
|
}
|
|
677
|
+
if (xcode) files['Package.swift'] = xcodeManifest(xcode)
|
|
520
678
|
return files
|
|
521
679
|
}
|
|
522
680
|
|
|
@@ -540,7 +698,7 @@ function packageSnapshot(project: SwiftProject): SwiftPackageSnapshot {
|
|
|
540
698
|
),
|
|
541
699
|
),
|
|
542
700
|
resources: buildSwiftResourceTable(project, ''),
|
|
543
|
-
bundleFiles: buildSwiftBundleFiles(project.packagePath),
|
|
701
|
+
bundleFiles: buildSwiftBundleFiles(project.packagePath, Boolean(project.hosted)),
|
|
544
702
|
native,
|
|
545
703
|
...(native
|
|
546
704
|
? {
|
|
@@ -613,7 +771,18 @@ async function compile(
|
|
|
613
771
|
package: content,
|
|
614
772
|
}
|
|
615
773
|
const toolchain = swiftModuleToolchain(moduleRoot)
|
|
616
|
-
const
|
|
774
|
+
const input = snapshotCompileInput(snapshot, entry)
|
|
775
|
+
const targets = compileTargets(input).map((target) => target.name)
|
|
776
|
+
const missing = missingSwiftModules(
|
|
777
|
+
input.files,
|
|
778
|
+
new Set([
|
|
779
|
+
...swiftAvailableModules(moduleRoot, toolchain.toolchainBin),
|
|
780
|
+
// a project without a manifest compiles as the template's one App target
|
|
781
|
+
...(targets.length > 0 ? targets : ['App']),
|
|
782
|
+
]),
|
|
783
|
+
)
|
|
784
|
+
if (missing.size > 0) throw new Error(missingModulesMessage(packagePath, missing))
|
|
785
|
+
const artifact = await compileSwiftProjectUnit(input, {
|
|
617
786
|
// the compile rewrites Sources/App in its root before swiftpm builds, and
|
|
618
787
|
// its lock orders one process only: two vites on one root (a lane's dev
|
|
619
788
|
// server and a capture, or two checkouts) build each other's sources. so
|
|
@@ -631,6 +800,13 @@ async function compile(
|
|
|
631
800
|
),
|
|
632
801
|
moduleRoot,
|
|
633
802
|
...toolchain,
|
|
803
|
+
}).catch((error: unknown) => {
|
|
804
|
+
const report = error instanceof Error ? swiftApiGapReport(error.message) : null
|
|
805
|
+
throw report
|
|
806
|
+
? new Error(`${error instanceof Error ? error.message : ''}\n\n${report}`, {
|
|
807
|
+
cause: error,
|
|
808
|
+
})
|
|
809
|
+
: error
|
|
634
810
|
})
|
|
635
811
|
return { ...artifact, stamp, package: content }
|
|
636
812
|
}
|
|
@@ -642,6 +818,92 @@ async function compile(
|
|
|
642
818
|
// public content address, which is fetched once and served from this dev
|
|
643
819
|
// server like a local build. resource bytes share the compile snapshot and
|
|
644
820
|
// immutable local asset addresses.
|
|
821
|
+
// the compiler stops a file at its errors, so its output reads one site at a
|
|
822
|
+
// time. this groups every error by the api it names, so a project learns
|
|
823
|
+
// which symbols Peach lacks, how often and where, from one run. paths are the
|
|
824
|
+
// project's own: app sources lose their compile directory, a remote package
|
|
825
|
+
// keeps its identity.
|
|
826
|
+
const API_GAP_PATTERNS: [RegExp, (match: RegExpExecArray) => string][] = [
|
|
827
|
+
[/^cannot find (?:type )?'([^']+)' in scope/, (match) => match[1]!],
|
|
828
|
+
// a typealias reports its aliased type after `aka`, which is the api's owner
|
|
829
|
+
[
|
|
830
|
+
/^(?:value of )?type '([^']+)'(?: \(aka '([^']+)'\))? has no member '([^']+)'/,
|
|
831
|
+
(match) =>
|
|
832
|
+
`${(match[2] ?? match[1]!).replace(/^Optional<(.+)>$/, '$1').replace(/\?$/, '')}.${match[3]}`,
|
|
833
|
+
],
|
|
834
|
+
[
|
|
835
|
+
/^module '([^']+)' has no member named '([^']+)'/,
|
|
836
|
+
(match) => `${match[1]}.${match[2]}`,
|
|
837
|
+
],
|
|
838
|
+
[/^'([^']+)' is unavailable/, (match) => match[1]!],
|
|
839
|
+
[/^no such module '([^']+)'/, (match) => `module ${match[1]}`],
|
|
840
|
+
]
|
|
841
|
+
|
|
842
|
+
export function swiftApiGapReport(output: string): string | null {
|
|
843
|
+
const gaps = new Map<string, { errors: number; files: Set<string> }>()
|
|
844
|
+
const other = new Map<string, { errors: number; files: Set<string> }>()
|
|
845
|
+
const seen = new Set<string>()
|
|
846
|
+
for (const line of output.split('\n')) {
|
|
847
|
+
const diagnostic = /^(\S[^:]*\.swift):(\d+):(\d+): error: (.+)$/.exec(line)
|
|
848
|
+
if (!diagnostic || seen.has(line)) continue
|
|
849
|
+
seen.add(line)
|
|
850
|
+
const file = diagnostic[1]!
|
|
851
|
+
.replace(new RegExp(`^${XCODE_APP_DIR}/`), '')
|
|
852
|
+
.replace(new RegExp(`^${XCODE_PACKAGES_DIR}/`), '')
|
|
853
|
+
const message = diagnostic[4]!
|
|
854
|
+
const rule = API_GAP_PATTERNS.find(([pattern]) => pattern.test(message))
|
|
855
|
+
const key = rule ? rule[1](rule[0].exec(message)!) : message
|
|
856
|
+
const table = rule ? gaps : other
|
|
857
|
+
const entry = table.get(key) ?? { errors: 0, files: new Set<string>() }
|
|
858
|
+
entry.errors++
|
|
859
|
+
entry.files.add(file)
|
|
860
|
+
table.set(key, entry)
|
|
861
|
+
}
|
|
862
|
+
if (gaps.size === 0) return null
|
|
863
|
+
const rows = (table: typeof gaps) => {
|
|
864
|
+
const sorted = [...table].sort(
|
|
865
|
+
([left, a], [right, b]) => b.errors - a.errors || left.localeCompare(right),
|
|
866
|
+
)
|
|
867
|
+
const width = Math.min(48, Math.max(...sorted.map(([key]) => key.length)))
|
|
868
|
+
return sorted.map(
|
|
869
|
+
([key, entry]) =>
|
|
870
|
+
` ${key.padEnd(width)} ${String(entry.errors).padStart(3)} error${entry.errors === 1 ? ' ' : 's'} ${[...entry.files].sort().join(', ')}`,
|
|
871
|
+
)
|
|
872
|
+
}
|
|
873
|
+
const errors = [...gaps.values()].reduce((sum, entry) => sum + entry.errors, 0)
|
|
874
|
+
return [
|
|
875
|
+
`Peach lacks ${gaps.size} API${gaps.size === 1 ? '' : 's'} this app uses (${errors} error${errors === 1 ? '' : 's'}):`,
|
|
876
|
+
...rows(gaps),
|
|
877
|
+
...(other.size > 0
|
|
878
|
+
? ['other errors, often caused by the ones above:', ...rows(other)]
|
|
879
|
+
: []),
|
|
880
|
+
].join('\n')
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
// one report of every module the app imports that Peach lacks, so a project
|
|
884
|
+
// learns its whole gap from one run instead of one compile error at a time.
|
|
885
|
+
function missingModulesMessage(
|
|
886
|
+
packagePath: string,
|
|
887
|
+
missing: Map<string, string[]>,
|
|
888
|
+
): string {
|
|
889
|
+
const layout = xcodeLayout(packagePath)
|
|
890
|
+
const remote = new Map(
|
|
891
|
+
(layout?.app.remoteProducts ?? []).map((entry) => [
|
|
892
|
+
entry.product,
|
|
893
|
+
entry.repositoryURL,
|
|
894
|
+
]),
|
|
895
|
+
)
|
|
896
|
+
const width = Math.max(...[...missing.keys()].map((name) => name.length))
|
|
897
|
+
return [
|
|
898
|
+
`Peach does not provide ${missing.size} module${missing.size === 1 ? '' : 's'} this app imports:`,
|
|
899
|
+
...[...missing].map(([name, files]) => {
|
|
900
|
+
const source = remote.get(name)
|
|
901
|
+
const reason = layout?.unavailable.get(name)?.reason
|
|
902
|
+
return ` ${name.padEnd(width)} ${files.length} file${files.length === 1 ? '' : 's'}${source ? `, package ${source}` : ''}${reason ? ` (${reason})` : ''}`
|
|
903
|
+
}),
|
|
904
|
+
].join('\n')
|
|
905
|
+
}
|
|
906
|
+
|
|
645
907
|
async function compileRemote(
|
|
646
908
|
packagePath: string,
|
|
647
909
|
entry: string,
|
|
@@ -669,6 +931,16 @@ async function compileRemote(
|
|
|
669
931
|
signal,
|
|
670
932
|
})
|
|
671
933
|
if (!submit) throw new Error('swift compile: no credential to submit with')
|
|
934
|
+
const sources = Object.values(snapshot.files)
|
|
935
|
+
const bytes = sources.reduce((total, text) => total + Buffer.byteLength(text), 0)
|
|
936
|
+
if (
|
|
937
|
+
sources.length > MAX_SWIFT_COMPILE_FILES ||
|
|
938
|
+
bytes > MAX_SWIFT_COMPILE_SOURCE_BYTES
|
|
939
|
+
) {
|
|
940
|
+
throw new Error(
|
|
941
|
+
`${path.basename(packagePath)} has ${sources.length} Swift files (${bytes} bytes), over Contrast's compile limits of ${MAX_SWIFT_COMPILE_FILES} files and ${MAX_SWIFT_COMPILE_SOURCE_BYTES} bytes; compile it on this machine with the Swift distribution instead`,
|
|
942
|
+
)
|
|
943
|
+
}
|
|
672
944
|
const descriptor = snapshot.native
|
|
673
945
|
const address = await compileSwiftProject(
|
|
674
946
|
submit,
|
|
@@ -781,7 +1053,7 @@ export function swiftPackageWatchFiles(
|
|
|
781
1053
|
): string[] {
|
|
782
1054
|
packagePath = fs.realpathSync(packagePath)
|
|
783
1055
|
return [
|
|
784
|
-
path.join(packagePath, 'Package.swift'),
|
|
1056
|
+
...(xcodeProjects.has(packagePath) ? [] : [path.join(packagePath, 'Package.swift')]),
|
|
785
1057
|
...sourceFiles(packagePath),
|
|
786
1058
|
...nativeSourceFiles(packagePath),
|
|
787
1059
|
...resourceCandidateFiles(packagePath),
|
|
@@ -897,4 +1169,5 @@ export function serveSwiftPackageAsset(pathname: string, res: ServerResponse): b
|
|
|
897
1169
|
|
|
898
1170
|
export function disposeSwiftProject(packagePath: string): void {
|
|
899
1171
|
projects.delete(fs.realpathSync(packagePath))
|
|
1172
|
+
xcodeProjects.delete(fs.realpathSync(packagePath))
|
|
900
1173
|
}
|