peachsim 0.1.2479 → 0.1.2481
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/agent-note.ts +50 -21
- package/cli/commands/perf-native.ts +886 -0
- package/cli/commands/perf.ts +6 -1
- package/cli/commands/stream.ts +33 -12
- package/detox/index.ts +5 -4
- package/dist-lib/agent-daemon-client.cjs +1 -1
- package/dist-lib/agent-events.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 +2 -2
- package/dist-lib/bridge-constants.cjs +1 -1
- package/dist-lib/bridge-contract-input.cjs +1 -1
- package/dist-lib/bridge-contract-input.mjs +5 -5
- package/dist-lib/bridge-contract.cjs +1 -1
- package/dist-lib/bridge-contract.mjs +3 -3
- package/dist-lib/bundle-channel.cjs +3148 -3026
- package/dist-lib/capture-contract.cjs +1 -1
- package/dist-lib/capture-contract.mjs +3 -3
- package/dist-lib/cloud-contract.cjs +1 -1
- package/dist-lib/cloud-contract.mjs +3 -3
- package/dist-lib/cloud-test-args.cjs +1 -1
- package/dist-lib/cloud-test-args.mjs +2 -2
- package/dist-lib/cloud.cjs +1 -1
- package/dist-lib/cloud.mjs +7 -7
- package/dist-lib/config.cjs +1 -1
- package/dist-lib/config.mjs +5 -5
- package/dist-lib/detox/index.cjs +3 -3
- package/dist-lib/dev-bundle-resolution.cjs +1 -1
- package/dist-lib/esm-chunks/{acorn-6T74WJEH.mjs → acorn-FYDDLFH7.mjs} +3 -3
- package/dist-lib/esm-chunks/{chunk-MQX3VV72.mjs → chunk-3AHKFCTP.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-UWPIIUE4.mjs → chunk-55FEZERB.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-BZT6SR75.mjs → chunk-56VSEMVW.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-AEZPI62A.mjs → chunk-6ALMBFOB.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-G4WYTA67.mjs → chunk-CIRF7MUH.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-TVVDHHO3.mjs → chunk-DILJLCVN.mjs} +12 -12
- package/dist-lib/esm-chunks/{chunk-GPU6YJ5I.mjs → chunk-DOTVMR2R.mjs} +5 -5
- package/dist-lib/esm-chunks/{chunk-RQYBISJH.mjs → chunk-DR66BWZR.mjs} +4 -4
- package/dist-lib/esm-chunks/{chunk-V4TJGQ5E.mjs → chunk-HK2YIUS3.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-2LPGM53Y.mjs → chunk-I2KV5OCI.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-3ZA6FTBR.mjs → chunk-IKMY4F25.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-AYJWQFTP.mjs → chunk-MTWECGVY.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-PFCYY52I.mjs → chunk-MYAC4QOH.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-OER7EEIH.mjs → chunk-OMWELJZM.mjs} +5 -5
- package/dist-lib/esm-chunks/{chunk-R2TIEVD6.mjs → chunk-RRHGYD5I.mjs} +2 -2
- package/dist-lib/esm-chunks/{chunk-QHX5XHZQ.mjs → chunk-V27M6XEI.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-D7WY4WGU.mjs → chunk-VGOJCWU3.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-FNLQ2DEH.mjs → chunk-XVGPPYRC.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-IHHNYCWO.mjs → chunk-YBJYSS46.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-C4R3TCHX.mjs → chunk-YY4T7YSR.mjs} +3 -3
- package/dist-lib/esm-chunks/{chunk-XWTX6G5Q.mjs → chunk-ZNG6GMUS.mjs} +1 -1
- package/dist-lib/esm-chunks/{metro-layout-parser-LMCYOPJD.mjs → metro-layout-parser-EEI7OVUC.mjs} +3 -3
- package/dist-lib/esm-chunks/{swift-package-prebuilt-NSH43QDM.mjs → swift-package-prebuilt-V5QMDVKG.mjs} +10 -10
- package/dist-lib/esm-chunks/{swift-sdk-app-module-RZ5BXP7S.mjs → swift-sdk-app-module-QEWCSQWL.mjs} +13 -13
- package/dist-lib/esm-chunks/{swift-sdk-image-3TJP3PYO.mjs → swift-sdk-image-XH4JSUEA.mjs} +13 -13
- package/dist-lib/esm-chunks/{swift-sdk-image-producer-SZLGEC7P.mjs → swift-sdk-image-producer-HQJ5Z6TE.mjs} +4 -4
- package/dist-lib/expo-swift-bundle.cjs +2078 -1952
- package/dist-lib/expo-swift-metadata.cjs +1 -1
- package/dist-lib/expo-swift-metadata.mjs +7 -7
- package/dist-lib/home-paths.cjs +1 -1
- package/dist-lib/host/bridge-host.cjs +2978 -2853
- package/dist-lib/host/fetch-proxy-handler.cjs +631 -331
- package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
- package/dist-lib/host/fetch-proxy-overrides.mjs +2 -2
- package/dist-lib/host/replacement-module-handler.cjs +1 -1
- package/dist-lib/host/websocket-proxy.cjs +1 -1
- package/dist-lib/index.cjs +1 -1
- package/dist-lib/kotlin-host.cjs +1 -1
- package/dist-lib/menu.cjs +1 -1
- package/dist-lib/menu.mjs +3 -3
- package/dist-lib/metro-fingerprint-registry.cjs +1 -1
- package/dist-lib/metro-fingerprint-registry.mjs +3 -3
- package/dist-lib/metro-production-bundle.cjs +1 -1
- package/dist-lib/metro-production-bundle.mjs +4 -4
- package/dist-lib/native-app-identity-project.cjs +1 -1
- package/dist-lib/native-app-identity-project.mjs +15 -15
- package/dist-lib/native-app-identity.cjs +1 -1
- package/dist-lib/native-app-identity.mjs +6 -6
- package/dist-lib/native-firebase-metadata.cjs +1 -1
- package/dist-lib/native-firebase-metadata.mjs +3 -3
- package/dist-lib/pdfium-raster.cjs +1 -1
- package/dist-lib/pdfium-raster.mjs +2 -2
- package/dist-lib/plist.cjs +1 -1
- package/dist-lib/plist.mjs +3 -3
- package/dist-lib/profiles.cjs +1 -1
- package/dist-lib/public-brand.cjs +1 -1
- package/dist-lib/public-origins-lib-esm.json +79 -79
- package/dist-lib/public-origins-lib.json +70 -70
- package/dist-lib/react-native-host-modules.cjs +1 -1
- package/dist-lib/react-native-host-modules.mjs +2 -2
- package/dist-lib/reap-browser.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 +7 -7
- package/dist-lib/skills.cjs +3588 -3442
- package/dist-lib/swift-compile.cjs +1 -1
- package/dist-lib/swift-compile.mjs +10 -10
- package/dist-lib/swift-package.cjs +1 -1
- package/dist-lib/swift-package.mjs +3 -3
- package/dist-lib/swift-submit.cjs +1 -1
- package/dist-lib/swift-submit.mjs +5 -5
- package/dist-lib/swift-svg-raster.cjs +1 -1
- package/dist-lib/swift-svg-raster.mjs +2 -2
- package/dist-lib/swift-toolchain.cjs +1 -1
- package/dist-lib/swift.cjs +1 -1
- package/dist-lib/vendor/@peculiar/x509.cjs +1 -1
- package/dist-lib/vendor/@ruby/prism/src/nodes.js.cjs +1 -1
- package/dist-lib/vendor/@ruby/prism/src/parsePrism.js.cjs +1 -1
- package/dist-lib/vendor/@xmldom/xmldom.cjs +1 -1
- package/dist-lib/vendor/acorn.cjs +1 -1
- package/dist-lib/vendor/bplist-parser.cjs +1 -1
- package/dist-lib/vendor/ignore.cjs +1 -1
- package/dist-lib/vendor/magic-string.cjs +1 -1
- package/dist-lib/vendor/plist.cjs +1 -1
- package/dist-lib/vendor/smol-toml.cjs +1 -1
- package/dist-lib/vendor/stream-json.cjs +1 -1
- package/dist-lib/vendor/sucrase/dist/index.js.cjs +1 -1
- package/dist-lib/vendor/sucrase/dist/parser/index.js.cjs +1 -1
- package/dist-lib/vendor/sucrase/dist/parser/tokenizer/index.js.cjs +1 -1
- package/dist-lib/vendor/sucrase/dist/parser/tokenizer/types.js.cjs +1 -1
- package/dist-lib/vendor/sucrase.cjs +1 -1
- package/dist-lib/vendor/terser.cjs +1 -1
- package/dist-lib/vendor/valibot.cjs +1 -1
- package/dist-lib/vendor/ws.cjs +1 -1
- package/dist-lib/vendor/zod.cjs +1 -1
- package/dist-lib/worklet-executable.cjs +1 -1
- package/dist-lib/worklet-executable.mjs +3 -3
- package/dist-types/packages/peach-engine/src/engine/image-host.d.ts +1 -1
- package/dist-types/packages/peach-engine/src/engine/remote-display-protocol.d.ts +3 -2
- package/dist-types/packages/peach-engine/src/observability/diagnostics-sample.d.ts +2 -1
- package/dist-types/packages/peach-engine/src/observability/types.d.ts +6 -0
- package/dist-types/packages/peach-engine/src/remote-stream/agent-action.d.ts +4 -0
- package/dist-types/packages/peach-engine/src/remote-stream/client-config.d.ts +1 -0
- package/dist-types/packages/peach-engine/src/render-worker/app-load.d.ts +0 -1
- package/package.json +1 -1
- package/runtime-companion.json +1 -1
- package/src/canvas-agent-note-delivery.ts +38 -8
- package/src/expo-swift-host.ts +27 -20
- package/src/expo-widgets-bundle.ts +5 -0
- package/src/host/staged-host-files.ts +7 -0
- package/src/native-preparation.ts +139 -3
- package/src/nitro-bundle.ts +17 -20
- package/src/swift-host.ts +13 -0
- package/src/turbo-bundle.ts +2 -1
package/src/expo-swift-host.ts
CHANGED
|
@@ -71,6 +71,7 @@ import {
|
|
|
71
71
|
projectFor,
|
|
72
72
|
serveSwiftPackageAsset,
|
|
73
73
|
sourceContentStamp,
|
|
74
|
+
swiftArtifactIsAvailable,
|
|
74
75
|
swiftProjectAppInfo,
|
|
75
76
|
standinLibraries,
|
|
76
77
|
SwiftMissingModulesError,
|
|
@@ -662,6 +663,16 @@ function retarget(cached: PreparedEntry, base: string): ExpoSwiftCompilationResu
|
|
|
662
663
|
return result
|
|
663
664
|
}
|
|
664
665
|
|
|
666
|
+
function expoSwiftArtifactsAreAvailable(
|
|
667
|
+
base: string,
|
|
668
|
+
result: ExpoSwiftCompilationResult | null,
|
|
669
|
+
): boolean {
|
|
670
|
+
return (
|
|
671
|
+
result === null ||
|
|
672
|
+
result.modules.every(({ url, hash }) => swiftArtifactIsAvailable(base, url, hash))
|
|
673
|
+
)
|
|
674
|
+
}
|
|
675
|
+
|
|
665
676
|
// only omit a class when its module and every declared view have app-owned
|
|
666
677
|
// answers. an unresolved definition stays native, including partial overrides.
|
|
667
678
|
function configuredExpoSwiftModule(
|
|
@@ -2303,9 +2314,6 @@ export function expoEntry(units: ExpoSwiftSourceUnit[], oneSDK = false): string
|
|
|
2303
2314
|
return `import SwiftUI\nimport PeachJSON\ninternal import ExpoModulesCore\n${bridgeModules.length ? 'import React\n' : ''}${oneSDK ? 'import One\nimport OneSDKBindings\n' : ''}${namespaces.map((namespace) => `import ${namespace}`).join('\n')}\n\n@main struct PeachExpoApp: PeachPackage {\n init() { MainActor.assumeIsolated { PeachExpoRuntime.register([${units.flatMap((unit) => unit.classes).join(', ')}])${delegates}${bridgeModules.length ? `; RCTModuleHost.register([${bridgeModules.join(', ')}])` : ''} } }\n ${view}\n}\n\n@_expose(wasm, "peach_expo_call")\n@_cdecl("peach_expo_call")\n@MainActor public func peachExpoCall(_ payload: UnsafePointer<UInt8>?, _ length: Int32) -> UnsafeMutablePointer<UInt8>? {\n PeachExpoRuntime.dispatch(payload, length)\n}\n`
|
|
2304
2315
|
}
|
|
2305
2316
|
|
|
2306
|
-
// a compile outlives its client: a dropped open leaves the work running so the
|
|
2307
|
-
// next open joins it, or reuses its result, instead of starting over.
|
|
2308
|
-
const compiling = new Map<string, Promise<ExpoSwiftCompilationResult | null>>()
|
|
2309
2317
|
// identical sources already produced a wasm that is still registered on its
|
|
2310
2318
|
// project. a second caller otherwise relinks namespaces whose failure records
|
|
2311
2319
|
// did not stick, and that link blows the flow's ready bound.
|
|
@@ -2443,7 +2451,11 @@ export async function compileExpoSwiftModules(
|
|
|
2443
2451
|
return compileExpoSwiftModulesTraced(root, base, publishArtifact, options)
|
|
2444
2452
|
}
|
|
2445
2453
|
const cached = preparedCache.get(key)
|
|
2446
|
-
if (
|
|
2454
|
+
if (
|
|
2455
|
+
cached &&
|
|
2456
|
+
expoSwiftArtifactsAreAvailable(cached.base, cached.result) &&
|
|
2457
|
+
(await witnessMatches(cached.witness))
|
|
2458
|
+
) {
|
|
2447
2459
|
signal.throwIfAborted()
|
|
2448
2460
|
report('reusing prepared expo swift artifact')
|
|
2449
2461
|
return retarget(cached, base)
|
|
@@ -2975,7 +2987,7 @@ async function compileExpoSwiftModulesTraced(
|
|
|
2975
2987
|
)
|
|
2976
2988
|
if (!publishArtifact) {
|
|
2977
2989
|
const prepared = preparedExpoSwift.get(preparedKey)
|
|
2978
|
-
if (prepared) {
|
|
2990
|
+
if (prepared && expoSwiftArtifactsAreAvailable(base, prepared)) {
|
|
2979
2991
|
report('reusing prepared expo swift artifact')
|
|
2980
2992
|
return prepared
|
|
2981
2993
|
}
|
|
@@ -3309,23 +3321,18 @@ export async function handleExpoSwiftRequest(
|
|
|
3309
3321
|
res.end(JSON.stringify(prepared.value))
|
|
3310
3322
|
return true
|
|
3311
3323
|
}
|
|
3312
|
-
let pending = compiling.get(flightKey)
|
|
3313
|
-
if (!pending) {
|
|
3314
|
-
pending = compileExpoSwiftModules(key, `http://${host}`, undefined, {
|
|
3315
|
-
iosTarget,
|
|
3316
|
-
}).finally(() => {
|
|
3317
|
-
compiling.delete(flightKey)
|
|
3318
|
-
})
|
|
3319
|
-
compiling.set(flightKey, pending)
|
|
3320
|
-
}
|
|
3321
3324
|
try {
|
|
3322
|
-
const
|
|
3325
|
+
const token = url.searchParams.get(NATIVE_PREPARE_QUERY_PARAM)
|
|
3326
|
+
const assetOrigin = `http://${host}`
|
|
3327
|
+
const metadata = await openPreparations.prepare(
|
|
3328
|
+
flightKey,
|
|
3329
|
+
key,
|
|
3330
|
+
token,
|
|
3331
|
+
() => compileExpoSwiftModules(key, assetOrigin, undefined, { iosTarget }),
|
|
3332
|
+
(value) => expoSwiftArtifactsAreAvailable(assetOrigin, value),
|
|
3333
|
+
)
|
|
3323
3334
|
if (!res.destroyed) {
|
|
3324
|
-
openPreparations.store(
|
|
3325
|
-
flightKey,
|
|
3326
|
-
url.searchParams.get(NATIVE_PREPARE_QUERY_PARAM),
|
|
3327
|
-
metadata,
|
|
3328
|
-
)
|
|
3335
|
+
openPreparations.store(flightKey, token, metadata)
|
|
3329
3336
|
res.writeHead(200, {
|
|
3330
3337
|
'Content-Type': 'application/json',
|
|
3331
3338
|
'Cache-Control': 'no-store',
|
|
@@ -4,6 +4,7 @@ import { createRequire } from 'node:module'
|
|
|
4
4
|
import path from 'node:path'
|
|
5
5
|
import { promisify } from 'node:util'
|
|
6
6
|
import { stageExpoWidgetAssets } from './expo-widget-assets'
|
|
7
|
+
import { hasStagedHostFile } from './host/staged-host-files'
|
|
7
8
|
import { compiledModuleRequestHandler } from './nitro-bundle'
|
|
8
9
|
import { withSwiftRootLock } from './swift-root-lock'
|
|
9
10
|
import type { ExpoWidgetExtension } from '../../peach-engine/src/render-worker/expo-widgetContract'
|
|
@@ -53,4 +54,8 @@ export async function buildExpoWidgetsBundle(
|
|
|
53
54
|
export const handleExpoWidgetsRequest = compiledModuleRequestHandler(
|
|
54
55
|
'Expo widget extension',
|
|
55
56
|
buildExpoWidgetsBundle,
|
|
57
|
+
(origin, { images }) =>
|
|
58
|
+
Object.values(images).every((variants) =>
|
|
59
|
+
variants.every(({ uri }) => hasStagedHostFile(origin, uri)),
|
|
60
|
+
),
|
|
56
61
|
)
|
|
@@ -245,6 +245,13 @@ export function isStagedHostFileRequest(rawUrl: string | undefined): boolean {
|
|
|
245
245
|
return index !== null && fs.existsSync(path.join(stagedDir(), index))
|
|
246
246
|
}
|
|
247
247
|
|
|
248
|
+
export function hasStagedHostFile(origin: string, uri: string): boolean {
|
|
249
|
+
const prefix = origin + STAGED_PREFIX
|
|
250
|
+
if (!uri.startsWith(prefix)) return false
|
|
251
|
+
const name = uri.slice(prefix.length)
|
|
252
|
+
return STAGED_NAME.test(name) && fs.existsSync(path.join(stagedDir(), name))
|
|
253
|
+
}
|
|
254
|
+
|
|
248
255
|
export async function handleStagedHostFileRequest(
|
|
249
256
|
req: IncomingMessage,
|
|
250
257
|
res: ServerResponse,
|
|
@@ -1,20 +1,156 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto'
|
|
2
|
+
import fs from 'node:fs'
|
|
3
|
+
import { createRequire } from 'node:module'
|
|
4
|
+
import path from 'node:path'
|
|
1
5
|
import { clearTimeout, setTimeout } from 'node:timers'
|
|
6
|
+
import { setImmediate } from 'node:timers/promises'
|
|
7
|
+
import { workspaceExclusion } from './expo-workspace-exclusion'
|
|
8
|
+
import { readExpoConfigAsync } from './native-firebase-config'
|
|
9
|
+
import {
|
|
10
|
+
resolveActiveRuntimeRoot,
|
|
11
|
+
resolveDevCheckoutRuntimeAssetRoot,
|
|
12
|
+
} from './runtime-assets'
|
|
13
|
+
import { findWorkspaceRoot } from './workspace-root'
|
|
2
14
|
|
|
3
15
|
const setTimeoutNode: (fn: () => void, ms: number) => NodeJS.Timeout = setTimeout
|
|
16
|
+
const OPEN_RECEIPT_MS = 30 * 60 * 1000
|
|
17
|
+
const openRevisions = new Map<string, Promise<string | null>>()
|
|
18
|
+
|
|
19
|
+
function openRevision(app: string, token: string): Promise<string | null> {
|
|
20
|
+
const key = `${app}\0${token}`
|
|
21
|
+
let revision = openRevisions.get(key)
|
|
22
|
+
if (!revision) {
|
|
23
|
+
revision = nativeInputRevision(app).catch(() => null)
|
|
24
|
+
openRevisions.set(key, revision)
|
|
25
|
+
setTimeoutNode(() => openRevisions.delete(key), OPEN_RECEIPT_MS).unref()
|
|
26
|
+
}
|
|
27
|
+
return revision
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async function nativeInputRevision(app: string): Promise<string> {
|
|
31
|
+
const root = findWorkspaceRoot(app)
|
|
32
|
+
const [excluded, config] = await Promise.all([
|
|
33
|
+
workspaceExclusion(root),
|
|
34
|
+
readExpoConfigAsync(app),
|
|
35
|
+
])
|
|
36
|
+
const require = createRequire(path.join(app, 'package.json'))
|
|
37
|
+
let widgetsOutput: string | undefined
|
|
38
|
+
try {
|
|
39
|
+
widgetsOutput = path.join(
|
|
40
|
+
path.dirname(require.resolve('expo-widgets/package.json')),
|
|
41
|
+
'bundle',
|
|
42
|
+
'build',
|
|
43
|
+
)
|
|
44
|
+
} catch (error) {
|
|
45
|
+
if (!(error instanceof Error && 'code' in error && error.code === 'MODULE_NOT_FOUND'))
|
|
46
|
+
throw error
|
|
47
|
+
}
|
|
48
|
+
const hash = createHash('sha256')
|
|
49
|
+
hash.update(
|
|
50
|
+
JSON.stringify([
|
|
51
|
+
config,
|
|
52
|
+
resolveActiveRuntimeRoot(),
|
|
53
|
+
resolveDevCheckoutRuntimeAssetRoot(),
|
|
54
|
+
]),
|
|
55
|
+
)
|
|
56
|
+
// use file identities for this bridge's lifetime; artifact digests still name the bytes.
|
|
57
|
+
const visited = new Set<string>()
|
|
58
|
+
const directories: { file: string; installed: boolean }[] = [
|
|
59
|
+
{ file: root, installed: false },
|
|
60
|
+
]
|
|
61
|
+
for (const { file: directory, installed } of directories) {
|
|
62
|
+
if (visited.has(directory)) continue
|
|
63
|
+
visited.add(directory)
|
|
64
|
+
const entries = fs.readdirSync(directory, { withFileTypes: true })
|
|
65
|
+
entries.sort((a, b) => (a.name < b.name ? -1 : Number(a.name !== b.name)))
|
|
66
|
+
for (const entry of entries) {
|
|
67
|
+
const file = path.join(directory, entry.name)
|
|
68
|
+
const dependency = installed || entry.name === 'node_modules'
|
|
69
|
+
if (file === widgetsOutput || entry.name === '.git') continue
|
|
70
|
+
if (!dependency && excluded(path.relative(root, file), entry.isDirectory()))
|
|
71
|
+
continue
|
|
72
|
+
hash.update(file).update('\0')
|
|
73
|
+
if (entry.isDirectory()) {
|
|
74
|
+
directories.push({ file, installed: dependency })
|
|
75
|
+
continue
|
|
76
|
+
}
|
|
77
|
+
const stat = fs.lstatSync(file)
|
|
78
|
+
hash.update(
|
|
79
|
+
`${stat.dev}:${stat.ino}:${stat.size}:${stat.ctimeMs}:${stat.mtimeMs}\0`,
|
|
80
|
+
)
|
|
81
|
+
if (!entry.isSymbolicLink()) continue
|
|
82
|
+
const target = fs.statSync(file, { throwIfNoEntry: false })
|
|
83
|
+
if (target?.isDirectory()) {
|
|
84
|
+
directories.push({ file: fs.realpathSync(file), installed: dependency })
|
|
85
|
+
} else if (target) {
|
|
86
|
+
hash.update(
|
|
87
|
+
`${target.dev}:${target.ino}:${target.size}:${target.ctimeMs}:${target.mtimeMs}\0`,
|
|
88
|
+
)
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (visited.size % 256 === 0) await setImmediate()
|
|
92
|
+
}
|
|
93
|
+
return hash.digest('hex')
|
|
94
|
+
}
|
|
4
95
|
|
|
5
|
-
// a completed open retains its result for the first tenant request only.
|
|
6
|
-
// reloads make a fresh request so edited native sources are observed.
|
|
7
96
|
export class NativePreparationReceipts<T> {
|
|
97
|
+
private readonly compiling = new Map<
|
|
98
|
+
string,
|
|
99
|
+
{ revision: string | null; result: Promise<T> }
|
|
100
|
+
>()
|
|
101
|
+
private readonly prepared = new Map<
|
|
102
|
+
string,
|
|
103
|
+
{ revision: string; value: T; expiry: NodeJS.Timeout }
|
|
104
|
+
>()
|
|
8
105
|
private readonly receipts = new Map<
|
|
9
106
|
string,
|
|
10
107
|
{ owner: string; value: T; expiry: NodeJS.Timeout }
|
|
11
108
|
>()
|
|
12
109
|
|
|
110
|
+
async prepare(
|
|
111
|
+
owner: string,
|
|
112
|
+
root: string,
|
|
113
|
+
token: string | null,
|
|
114
|
+
compile: () => Promise<T>,
|
|
115
|
+
isAvailable?: (value: T) => boolean,
|
|
116
|
+
): Promise<T> {
|
|
117
|
+
const revision = token && isAvailable ? await openRevision(root, token) : null
|
|
118
|
+
let pending = this.compiling.get(owner)
|
|
119
|
+
while (pending) {
|
|
120
|
+
if (pending.revision === revision) return pending.result
|
|
121
|
+
await pending.result.catch(() => undefined)
|
|
122
|
+
pending = this.compiling.get(owner)
|
|
123
|
+
}
|
|
124
|
+
const prepared = this.prepared.get(owner)
|
|
125
|
+
if (prepared && prepared.revision === revision && isAvailable?.(prepared.value)) {
|
|
126
|
+
prepared.expiry.refresh()
|
|
127
|
+
return prepared.value
|
|
128
|
+
}
|
|
129
|
+
if (prepared) clearTimeout(prepared.expiry)
|
|
130
|
+
this.prepared.delete(owner)
|
|
131
|
+
const result = compile()
|
|
132
|
+
.then((value) => {
|
|
133
|
+
if (revision) {
|
|
134
|
+
const expiry = setTimeoutNode(
|
|
135
|
+
() => this.prepared.delete(owner),
|
|
136
|
+
OPEN_RECEIPT_MS,
|
|
137
|
+
)
|
|
138
|
+
expiry.unref()
|
|
139
|
+
this.prepared.set(owner, { revision, value, expiry })
|
|
140
|
+
}
|
|
141
|
+
return value
|
|
142
|
+
})
|
|
143
|
+
.finally(() => this.compiling.delete(owner))
|
|
144
|
+
this.compiling.set(owner, { revision, result })
|
|
145
|
+
return result
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// each open hands its own response to the first tenant request, including null.
|
|
13
149
|
store(owner: string, token: string | null, value: T): void {
|
|
14
150
|
if (!token) return
|
|
15
151
|
const previous = this.receipts.get(token)
|
|
16
152
|
if (previous) clearTimeout(previous.expiry)
|
|
17
|
-
const expiry = setTimeoutNode(() => this.receipts.delete(token),
|
|
153
|
+
const expiry = setTimeoutNode(() => this.receipts.delete(token), OPEN_RECEIPT_MS)
|
|
18
154
|
expiry.unref()
|
|
19
155
|
this.receipts.set(token, { owner, value, expiry })
|
|
20
156
|
}
|
package/src/nitro-bundle.ts
CHANGED
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
import { selectCompiledNitroProviders } from './nitro-app-providers'
|
|
12
12
|
import { compileNitroModule } from './nitro-compile'
|
|
13
13
|
import { swiftDistributionRoot } from './swift-distribution'
|
|
14
|
-
import { icuUrl, type SwiftArtifact } from './swift-host'
|
|
14
|
+
import { icuUrl, swiftArtifactIsAvailable, type SwiftArtifact } from './swift-host'
|
|
15
15
|
import { swiftIcuBundleAsset } from './swift-icu'
|
|
16
16
|
import type { NitroBuildConfiguration, NitroCompiledModule } from './nitroContract'
|
|
17
17
|
import type { IncomingMessage, ServerResponse } from 'node:http'
|
|
@@ -144,8 +144,8 @@ export function compiledModuleRequestHandler<Metadata>(
|
|
|
144
144
|
iosTarget: string | undefined,
|
|
145
145
|
params: URLSearchParams,
|
|
146
146
|
) => Promise<{ metadata: Metadata } | null>,
|
|
147
|
+
isAvailable?: (origin: string, metadata: Metadata) => boolean,
|
|
147
148
|
): (req: IncomingMessage, res: ServerResponse) => Promise<void> {
|
|
148
|
-
const compiling = new Map<string, Promise<Metadata | null>>()
|
|
149
149
|
const openPreparations = new NativePreparationReceipts<Metadata | null>()
|
|
150
150
|
return async (req, res) => {
|
|
151
151
|
const url = new URL(req.url ?? '/', 'http://localhost')
|
|
@@ -172,7 +172,9 @@ export function compiledModuleRequestHandler<Metadata>(
|
|
|
172
172
|
}
|
|
173
173
|
try {
|
|
174
174
|
const iosTarget = url.searchParams.get('iosTarget') ?? undefined
|
|
175
|
-
const
|
|
175
|
+
const app = fs.realpathSync(root)
|
|
176
|
+
const assetOrigin = `http://${host}`
|
|
177
|
+
const key = `${host}\0${app}\0${iosTarget ?? ''}\0${url.searchParams.get('configuration') ?? ''}`
|
|
176
178
|
const prepared = openPreparations.take(
|
|
177
179
|
key,
|
|
178
180
|
url.searchParams.get(NATIVE_PREPARED_QUERY_PARAM),
|
|
@@ -185,25 +187,19 @@ export function compiledModuleRequestHandler<Metadata>(
|
|
|
185
187
|
res.end(JSON.stringify(prepared.value))
|
|
186
188
|
return
|
|
187
189
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
pending = compile(
|
|
191
|
-
fs.realpathSync(root),
|
|
192
|
-
`http://${host}`,
|
|
193
|
-
iosTarget,
|
|
194
|
-
url.searchParams,
|
|
195
|
-
)
|
|
196
|
-
.then((compiled) => compiled?.metadata ?? null)
|
|
197
|
-
.finally(() => compiling.delete(key))
|
|
198
|
-
compiling.set(key, pending)
|
|
199
|
-
}
|
|
200
|
-
const metadata = await pending
|
|
201
|
-
if (res.destroyed) return
|
|
202
|
-
openPreparations.store(
|
|
190
|
+
const token = url.searchParams.get(NATIVE_PREPARE_QUERY_PARAM)
|
|
191
|
+
const metadata = await openPreparations.prepare(
|
|
203
192
|
key,
|
|
204
|
-
|
|
205
|
-
|
|
193
|
+
app,
|
|
194
|
+
token,
|
|
195
|
+
async () =>
|
|
196
|
+
(await compile(app, assetOrigin, iosTarget, url.searchParams))?.metadata ??
|
|
197
|
+
null,
|
|
198
|
+
isAvailable &&
|
|
199
|
+
((metadata) => metadata === null || isAvailable(assetOrigin, metadata)),
|
|
206
200
|
)
|
|
201
|
+
if (res.destroyed) return
|
|
202
|
+
openPreparations.store(key, token, metadata)
|
|
207
203
|
res.writeHead(200, {
|
|
208
204
|
'Content-Type': 'application/json',
|
|
209
205
|
'Cache-Control': 'no-store',
|
|
@@ -225,4 +221,5 @@ export const handleNitroRequest = compiledModuleRequestHandler(
|
|
|
225
221
|
throw new Error('Nitro compilation needs configuration=Debug or Release')
|
|
226
222
|
return compileNitroApp(root, origin, configuration, undefined, true, iosTarget)
|
|
227
223
|
},
|
|
224
|
+
(origin, { url, hash }) => swiftArtifactIsAvailable(origin, url, hash),
|
|
228
225
|
)
|
package/src/swift-host.ts
CHANGED
|
@@ -4264,6 +4264,19 @@ function endImmutableRanges(res: ServerResponse, bytes: Buffer) {
|
|
|
4264
4264
|
res.end(bytes.subarray(start, end + 1))
|
|
4265
4265
|
}
|
|
4266
4266
|
|
|
4267
|
+
export function swiftArtifactIsAvailable(
|
|
4268
|
+
origin: string,
|
|
4269
|
+
url: string,
|
|
4270
|
+
hash: string,
|
|
4271
|
+
): boolean {
|
|
4272
|
+
return (
|
|
4273
|
+
!url.startsWith(`${origin}${ARTIFACT_PATH}`) ||
|
|
4274
|
+
[...projects().values()].some((project) =>
|
|
4275
|
+
project.artifacts.some((artifact) => artifact.hash === hash),
|
|
4276
|
+
)
|
|
4277
|
+
)
|
|
4278
|
+
}
|
|
4279
|
+
|
|
4267
4280
|
export async function serveSwiftPackageAsset(
|
|
4268
4281
|
pathname: string,
|
|
4269
4282
|
res: ServerResponse,
|
package/src/turbo-bundle.ts
CHANGED
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
type CompiledModuleAsset,
|
|
13
13
|
} from './nitro-bundle'
|
|
14
14
|
import { swiftDistributionRoot } from './swift-distribution'
|
|
15
|
-
import { icuUrl, type SwiftArtifact } from './swift-host'
|
|
15
|
+
import { icuUrl, swiftArtifactIsAvailable, type SwiftArtifact } from './swift-host'
|
|
16
16
|
import { compileTurboModule } from './turbo-compile'
|
|
17
17
|
import { discoverTurboProviders, turboProviderCandidates } from './turbo-source'
|
|
18
18
|
import { installedXcodeWorkspace } from './xcode-project'
|
|
@@ -152,4 +152,5 @@ export async function buildTurboBundle(
|
|
|
152
152
|
export const handleTurboRequest = compiledModuleRequestHandler(
|
|
153
153
|
'TurboModule',
|
|
154
154
|
(root, origin, iosTarget) => compileTurboApp(root, origin, undefined, iosTarget),
|
|
155
|
+
(origin, { url, hash }) => swiftArtifactIsAvailable(origin, url, hash),
|
|
155
156
|
)
|