peachsim 0.1.2480 → 0.1.2482
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/inspect.ts +2 -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 +3057 -2952
- 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 +2 -2
- package/dist-lib/dev-bundle-resolution.cjs +1 -1
- package/dist-lib/esm-chunks/{acorn-RHJLDFQ6.mjs → acorn-3RG2YV22.mjs} +3 -3
- package/dist-lib/esm-chunks/{chunk-KPDAPPKX.mjs → chunk-5VLHG64M.mjs} +5 -5
- package/dist-lib/esm-chunks/{chunk-QWPRWZCR.mjs → chunk-7I4VWI2V.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-HHXID6CS.mjs → chunk-CEQOCRNV.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-5VNECNVL.mjs → chunk-D5LOEF4I.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-LIULVSRG.mjs → chunk-DJKPHL72.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-IAQ6RFFI.mjs → chunk-DYN7524Z.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-OW2NZLWH.mjs → chunk-FKS6QFGF.mjs} +5 -5
- package/dist-lib/esm-chunks/{chunk-QNFDJM4V.mjs → chunk-GVLSR652.mjs} +12 -12
- package/dist-lib/esm-chunks/{chunk-AN4RNKME.mjs → chunk-JNQJMRSO.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-VYP6I44Y.mjs → chunk-MDEXPYPS.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-PPI4PXUE.mjs → chunk-NFRYA23T.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-JW6P2F6T.mjs → chunk-RUKQSGNO.mjs} +4 -4
- package/dist-lib/esm-chunks/{chunk-IMJ6FVRR.mjs → chunk-V7WDCR3N.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-X7K3JLJ3.mjs → chunk-WC3CBCQF.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-43UZGHLJ.mjs → chunk-WJCPHHTA.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-PB53B3G3.mjs → chunk-WPW4V4XH.mjs} +2 -2
- package/dist-lib/esm-chunks/{chunk-IGQJDRVL.mjs → chunk-YC2PEM6U.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-NZYUWM5K.mjs → chunk-YOKV3RRM.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-U5UJRFVB.mjs → chunk-YSTOPLNH.mjs} +3 -3
- package/dist-lib/esm-chunks/{chunk-LNLVUOIL.mjs → chunk-Z2NSDMD7.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-K633NA6X.mjs → chunk-ZXAHJ6YC.mjs} +1 -1
- package/dist-lib/esm-chunks/{metro-layout-parser-K64IERC5.mjs → metro-layout-parser-OPFP36W3.mjs} +3 -3
- package/dist-lib/esm-chunks/{swift-package-prebuilt-4B2KGEQL.mjs → swift-package-prebuilt-S7ECXF7I.mjs} +10 -10
- package/dist-lib/esm-chunks/{swift-sdk-app-module-SUCFPPKO.mjs → swift-sdk-app-module-7WOLAFJ6.mjs} +13 -13
- package/dist-lib/esm-chunks/{swift-sdk-image-YX5FMNXN.mjs → swift-sdk-image-WDWMRJ76.mjs} +13 -13
- package/dist-lib/esm-chunks/{swift-sdk-image-producer-WFJBSXZG.mjs → swift-sdk-image-producer-ZXAKVKXN.mjs} +4 -4
- package/dist-lib/expo-swift-bundle.cjs +2004 -1889
- 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 +2840 -2769
- package/dist-lib/host/fetch-proxy-handler.cjs +427 -297
- 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 +76 -76
- 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 +3412 -3316
- 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/core-abi/style/style-schema.d.ts +4 -0
- package/dist-types/packages/peach-engine/src/engine/types.d.ts +2 -2
- package/package.json +1 -1
- package/src/canvas-agent-note-delivery.ts +36 -6
- package/src/expo-swift-host.ts +36 -47
- package/src/expo-widgets-bundle.ts +7 -0
- package/src/host/bridge-host.ts +4 -25
- package/src/host/staged-host-files.ts +7 -0
- package/src/native-preparation.ts +134 -6
- package/src/nitro-bundle.ts +29 -41
- package/src/one-sdk-bundle.ts +1 -0
- package/src/swift-host.ts +13 -0
- package/src/turbo-bundle.ts +6 -1
package/src/host/bridge-host.ts
CHANGED
|
@@ -1644,25 +1644,19 @@ export class SootSimBridgeHost {
|
|
|
1644
1644
|
}
|
|
1645
1645
|
if (route === ONE_SDK_ROUTE) {
|
|
1646
1646
|
void import('../one-sdk-bundle.ts')
|
|
1647
|
-
.then(({ handleOneSDKRequest }) =>
|
|
1648
|
-
withRequestNativeSources(req, () => handleOneSDKRequest(req, res)),
|
|
1649
|
-
)
|
|
1647
|
+
.then(({ handleOneSDKRequest }) => handleOneSDKRequest(req, res))
|
|
1650
1648
|
.catch(failLazyRoute)
|
|
1651
1649
|
return
|
|
1652
1650
|
}
|
|
1653
1651
|
if (route === NITRO_ROUTE) {
|
|
1654
1652
|
void import('../nitro-bundle.ts')
|
|
1655
|
-
.then(({ handleNitroRequest }) =>
|
|
1656
|
-
withRequestNativeSources(req, () => handleNitroRequest(req, res)),
|
|
1657
|
-
)
|
|
1653
|
+
.then(({ handleNitroRequest }) => handleNitroRequest(req, res))
|
|
1658
1654
|
.catch(failLazyRoute)
|
|
1659
1655
|
return
|
|
1660
1656
|
}
|
|
1661
1657
|
if (route === TURBO_ROUTE) {
|
|
1662
1658
|
void import('../turbo-bundle.ts')
|
|
1663
|
-
.then(({ handleTurboRequest }) =>
|
|
1664
|
-
withRequestNativeSources(req, () => handleTurboRequest(req, res)),
|
|
1665
|
-
)
|
|
1659
|
+
.then(({ handleTurboRequest }) => handleTurboRequest(req, res))
|
|
1666
1660
|
.catch(failLazyRoute)
|
|
1667
1661
|
return
|
|
1668
1662
|
}
|
|
@@ -1683,9 +1677,7 @@ export class SootSimBridgeHost {
|
|
|
1683
1677
|
req.url?.startsWith('/__peach/swift')
|
|
1684
1678
|
) {
|
|
1685
1679
|
void import('../expo-swift-host.ts')
|
|
1686
|
-
.then(({ handleExpoSwiftRequest }) =>
|
|
1687
|
-
withRequestNativeSources(req, () => handleExpoSwiftRequest(req, res)),
|
|
1688
|
-
)
|
|
1680
|
+
.then(({ handleExpoSwiftRequest }) => handleExpoSwiftRequest(req, res))
|
|
1689
1681
|
.then((handled) => {
|
|
1690
1682
|
if (!handled) {
|
|
1691
1683
|
res.writeHead(404)
|
|
@@ -3022,16 +3014,3 @@ export class SootSimBridgeHost {
|
|
|
3022
3014
|
}
|
|
3023
3015
|
}
|
|
3024
3016
|
}
|
|
3025
|
-
|
|
3026
|
-
// a native build compiles the packages its app names in `compileNative` from
|
|
3027
|
-
// source; the handler itself refuses a request without an absolute root
|
|
3028
|
-
function withRequestNativeSources<T>(
|
|
3029
|
-
req: IncomingMessage,
|
|
3030
|
-
serve: () => Promise<T>,
|
|
3031
|
-
): Promise<T> {
|
|
3032
|
-
const root = new URL(req.url ?? '/', 'http://localhost').searchParams.get('root')
|
|
3033
|
-
if (!root || !path.isAbsolute(root)) return serve()
|
|
3034
|
-
return import('../app-config').then(({ withConfiguredNativeSources }) =>
|
|
3035
|
-
withConfiguredNativeSources(root, serve),
|
|
3036
|
-
)
|
|
3037
|
-
}
|
|
@@ -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,25 +1,153 @@
|
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
import path from 'node:path'
|
|
1
3
|
import { clearTimeout, setTimeout } from 'node:timers'
|
|
4
|
+
import {
|
|
5
|
+
NATIVE_PREPARE_QUERY_PARAM,
|
|
6
|
+
NATIVE_PREPARED_QUERY_PARAM,
|
|
7
|
+
} from './nativePreparationContract'
|
|
8
|
+
import { resolveActiveRuntimeRoot } from './runtime-assets'
|
|
9
|
+
import { findWorkspaceRoot } from './workspace-root'
|
|
2
10
|
|
|
3
11
|
const setTimeoutNode: (fn: () => void, ms: number) => NodeJS.Timeout = setTimeout
|
|
12
|
+
const RETENTION_MS = 30 * 60 * 1000
|
|
4
13
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
14
|
+
type NativeInputs = { expiry: NodeJS.Timeout }
|
|
15
|
+
type Preparation<T> = { result: Promise<T>; ready?: { value: T } }
|
|
16
|
+
const watchedInputs = new Map<string, NativeInputs>()
|
|
17
|
+
|
|
18
|
+
function ignoredChange(relative: string) {
|
|
19
|
+
const parts = relative.split(path.sep)
|
|
20
|
+
return (
|
|
21
|
+
relative === path.join('.git', 'index') ||
|
|
22
|
+
parts.includes('.cache') ||
|
|
23
|
+
parts.includes('.expo') ||
|
|
24
|
+
/(?:^|[\\/])node_modules[\\/]expo-widgets[\\/]bundle[\\/]build(?:[\\/]|$)/.test(
|
|
25
|
+
relative,
|
|
26
|
+
)
|
|
27
|
+
)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function watchNativeInputs(root: string): NativeInputs | undefined {
|
|
31
|
+
const workspace = findWorkspaceRoot(root)
|
|
32
|
+
const existing = watchedInputs.get(workspace)
|
|
33
|
+
if (existing) {
|
|
34
|
+
existing.expiry.refresh()
|
|
35
|
+
return existing
|
|
36
|
+
}
|
|
37
|
+
const watchers: fs.FSWatcher[] = []
|
|
38
|
+
const visited = new Set<string>()
|
|
39
|
+
const expiry = setTimeoutNode(close, RETENTION_MS)
|
|
40
|
+
expiry.unref()
|
|
41
|
+
function close() {
|
|
42
|
+
if (watchedInputs.get(workspace) === inputs) watchedInputs.delete(workspace)
|
|
43
|
+
clearTimeout(expiry)
|
|
44
|
+
for (const watcher of watchers) watcher.close()
|
|
45
|
+
}
|
|
46
|
+
const inputs = { expiry }
|
|
47
|
+
const watch = (directory: string, recursive: boolean, name?: string) => {
|
|
48
|
+
const watcher = fs.watch(
|
|
49
|
+
directory,
|
|
50
|
+
{ recursive, persistent: false },
|
|
51
|
+
(_event, file) => {
|
|
52
|
+
if (!file || (name ? file === name : !ignoredChange(file))) close()
|
|
53
|
+
},
|
|
54
|
+
)
|
|
55
|
+
watchers.push(watcher)
|
|
56
|
+
watcher.on('error', close)
|
|
57
|
+
}
|
|
58
|
+
// recursive watchers cover the install tree but do not descend through
|
|
59
|
+
// symlinks. arm the real external targets before any compiler reads them.
|
|
60
|
+
const scan = (directory: string, watchRoot: string) => {
|
|
61
|
+
if (visited.has(directory)) return
|
|
62
|
+
visited.add(directory)
|
|
63
|
+
for (const entry of fs.readdirSync(directory, { withFileTypes: true })) {
|
|
64
|
+
const file = path.join(directory, entry.name)
|
|
65
|
+
if (ignoredChange(path.relative(watchRoot, file)) || entry.name === '.git') continue
|
|
66
|
+
if (entry.isDirectory()) scan(file, watchRoot)
|
|
67
|
+
if (!entry.isSymbolicLink()) continue
|
|
68
|
+
const target = path.resolve(directory, fs.readlinkSync(file))
|
|
69
|
+
if (target === workspace || target.startsWith(workspace + path.sep)) continue
|
|
70
|
+
const real = fs.realpathSync(file)
|
|
71
|
+
if (visited.has(real)) continue
|
|
72
|
+
watch(path.dirname(real), false, path.basename(real))
|
|
73
|
+
if (fs.statSync(real).isDirectory()) {
|
|
74
|
+
watch(real, true)
|
|
75
|
+
scan(real, real)
|
|
76
|
+
} else visited.add(real)
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
try {
|
|
80
|
+
watch(workspace, true)
|
|
81
|
+
scan(workspace, workspace)
|
|
82
|
+
} catch {
|
|
83
|
+
// an unobservable input leaves this request on the fresh preparation path.
|
|
84
|
+
close()
|
|
85
|
+
return undefined
|
|
86
|
+
}
|
|
87
|
+
watchedInputs.set(workspace, inputs)
|
|
88
|
+
return inputs
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// an open can reuse preparation from the current workspace. its token hands
|
|
92
|
+
// that same result to the first tenant request, even if the workspace changes.
|
|
93
|
+
export class NativePreparation<T> {
|
|
94
|
+
private readonly compiling = new Map<string, Preparation<T>>()
|
|
95
|
+
private readonly prepared = new WeakMap<NativeInputs, Map<string, Preparation<T>>>()
|
|
8
96
|
private readonly receipts = new Map<
|
|
9
97
|
string,
|
|
10
98
|
{ owner: string; value: T; expiry: NodeJS.Timeout }
|
|
11
99
|
>()
|
|
12
100
|
|
|
13
|
-
|
|
101
|
+
async resolve(
|
|
102
|
+
root: string,
|
|
103
|
+
owner: string,
|
|
104
|
+
params: URLSearchParams,
|
|
105
|
+
compile: () => Promise<T>,
|
|
106
|
+
reusable: (value: T) => boolean = () => true,
|
|
107
|
+
): Promise<T> {
|
|
108
|
+
const receipt = this.take(owner, params.get(NATIVE_PREPARED_QUERY_PARAM))
|
|
109
|
+
if (receipt) return receipt.value
|
|
110
|
+
|
|
111
|
+
const token = params.get(NATIVE_PREPARE_QUERY_PARAM)
|
|
112
|
+
const inputs = token ? watchNativeInputs(root) : undefined
|
|
113
|
+
const key = inputs ? `${owner}\0${resolveActiveRuntimeRoot() ?? ''}` : owner
|
|
114
|
+
let pending = this.compiling
|
|
115
|
+
if (inputs) {
|
|
116
|
+
const prepared = this.prepared.get(inputs)
|
|
117
|
+
if (prepared) pending = prepared
|
|
118
|
+
else {
|
|
119
|
+
pending = new Map()
|
|
120
|
+
this.prepared.set(inputs, pending)
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
let preparation = pending.get(key)
|
|
124
|
+
if (!preparation || (preparation.ready && !reusable(preparation.ready.value))) {
|
|
125
|
+
const next: Preparation<T> = { result: Promise.resolve().then(compile) }
|
|
126
|
+
preparation = next
|
|
127
|
+
pending.set(key, next)
|
|
128
|
+
void next.result.then(
|
|
129
|
+
(value) => {
|
|
130
|
+
if (!inputs || !reusable(value)) pending.delete(key)
|
|
131
|
+
else next.ready = { value }
|
|
132
|
+
},
|
|
133
|
+
() => pending.delete(key),
|
|
134
|
+
)
|
|
135
|
+
}
|
|
136
|
+
const value = await preparation.result
|
|
137
|
+
this.store(owner, token, value)
|
|
138
|
+
return value
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
private store(owner: string, token: string | null, value: T): void {
|
|
14
142
|
if (!token) return
|
|
15
143
|
const previous = this.receipts.get(token)
|
|
16
144
|
if (previous) clearTimeout(previous.expiry)
|
|
17
|
-
const expiry = setTimeoutNode(() => this.receipts.delete(token),
|
|
145
|
+
const expiry = setTimeoutNode(() => this.receipts.delete(token), RETENTION_MS)
|
|
18
146
|
expiry.unref()
|
|
19
147
|
this.receipts.set(token, { owner, value, expiry })
|
|
20
148
|
}
|
|
21
149
|
|
|
22
|
-
take(owner: string, token: string | null): { value: T } | undefined {
|
|
150
|
+
private take(owner: string, token: string | null): { value: T } | undefined {
|
|
23
151
|
if (!token) return
|
|
24
152
|
const receipt = this.receipts.get(token)
|
|
25
153
|
if (!receipt || receipt.owner !== owner) return
|
package/src/nitro-bundle.ts
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
import fs from 'node:fs'
|
|
2
2
|
import path from 'node:path'
|
|
3
|
+
import { withConfiguredNativeSources } from './app-config'
|
|
3
4
|
import { isLoopbackHost } from './backend-origin'
|
|
4
5
|
import { prepareNativeAppRoot } from './expo-native-workspace'
|
|
5
6
|
import { readIosAppTarget } from './native-app-identity-project'
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
NATIVE_PREPARE_QUERY_PARAM,
|
|
9
|
-
NATIVE_PREPARED_QUERY_PARAM,
|
|
10
|
-
} from './nativePreparationContract'
|
|
7
|
+
import { NativePreparation } from './native-preparation'
|
|
11
8
|
import { selectCompiledNitroProviders } from './nitro-app-providers'
|
|
12
9
|
import { compileNitroModule } from './nitro-compile'
|
|
13
10
|
import { swiftDistributionRoot } from './swift-distribution'
|
|
14
|
-
import { icuUrl, type SwiftArtifact } from './swift-host'
|
|
11
|
+
import { icuUrl, swiftArtifactIsAvailable, type SwiftArtifact } from './swift-host'
|
|
15
12
|
import { swiftIcuBundleAsset } from './swift-icu'
|
|
16
13
|
import type { NitroBuildConfiguration, NitroCompiledModule } from './nitroContract'
|
|
17
14
|
import type { IncomingMessage, ServerResponse } from 'node:http'
|
|
@@ -132,10 +129,8 @@ export async function buildNitroBundle(
|
|
|
132
129
|
}
|
|
133
130
|
|
|
134
131
|
// the dev server's build of one kind of an app's installed native modules.
|
|
135
|
-
//
|
|
136
|
-
//
|
|
137
|
-
// check. its wasm and ICU are served from the same host by the Swift artifact
|
|
138
|
-
// route.
|
|
132
|
+
// concurrent boots share one build, and subsequent opens reuse its result
|
|
133
|
+
// while the inputs are unchanged. wasm and ICU use the Swift artifact route.
|
|
139
134
|
export function compiledModuleRequestHandler<Metadata>(
|
|
140
135
|
label: string,
|
|
141
136
|
compile: (
|
|
@@ -144,9 +139,12 @@ export function compiledModuleRequestHandler<Metadata>(
|
|
|
144
139
|
iosTarget: string | undefined,
|
|
145
140
|
params: URLSearchParams,
|
|
146
141
|
) => Promise<{ metadata: Metadata } | null>,
|
|
142
|
+
options?: {
|
|
143
|
+
configuredNativeSources?: boolean
|
|
144
|
+
reusable?: (origin: string, metadata: Metadata) => boolean
|
|
145
|
+
},
|
|
147
146
|
): (req: IncomingMessage, res: ServerResponse) => Promise<void> {
|
|
148
|
-
const
|
|
149
|
-
const openPreparations = new NativePreparationReceipts<Metadata | null>()
|
|
147
|
+
const preparations = new NativePreparation<Metadata | null>()
|
|
150
148
|
return async (req, res) => {
|
|
151
149
|
const url = new URL(req.url ?? '/', 'http://localhost')
|
|
152
150
|
const remote = req.socket.remoteAddress?.replace(/^::ffff:/, '')
|
|
@@ -172,38 +170,24 @@ export function compiledModuleRequestHandler<Metadata>(
|
|
|
172
170
|
}
|
|
173
171
|
try {
|
|
174
172
|
const iosTarget = url.searchParams.get('iosTarget') ?? undefined
|
|
175
|
-
const
|
|
176
|
-
const
|
|
173
|
+
const app = fs.realpathSync(root)
|
|
174
|
+
const key = `${host}\0${app}\0${iosTarget ?? ''}\0${url.searchParams.get('configuration') ?? ''}`
|
|
175
|
+
const assetOrigin = `http://${host}`
|
|
176
|
+
const build = () => compile(app, assetOrigin, iosTarget, url.searchParams)
|
|
177
|
+
const metadata = await preparations.resolve(
|
|
178
|
+
app,
|
|
177
179
|
key,
|
|
178
|
-
url.searchParams
|
|
180
|
+
url.searchParams,
|
|
181
|
+
async () => {
|
|
182
|
+
const built = await (options?.configuredNativeSources
|
|
183
|
+
? withConfiguredNativeSources(app, build)
|
|
184
|
+
: build())
|
|
185
|
+
return built?.metadata ?? null
|
|
186
|
+
},
|
|
187
|
+
(metadata) =>
|
|
188
|
+
metadata === null || (options?.reusable?.(assetOrigin, metadata) ?? true),
|
|
179
189
|
)
|
|
180
|
-
if (prepared) {
|
|
181
|
-
res.writeHead(200, {
|
|
182
|
-
'Content-Type': 'application/json',
|
|
183
|
-
'Cache-Control': 'no-store',
|
|
184
|
-
})
|
|
185
|
-
res.end(JSON.stringify(prepared.value))
|
|
186
|
-
return
|
|
187
|
-
}
|
|
188
|
-
let pending = compiling.get(key)
|
|
189
|
-
if (!pending) {
|
|
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
190
|
if (res.destroyed) return
|
|
202
|
-
openPreparations.store(
|
|
203
|
-
key,
|
|
204
|
-
url.searchParams.get(NATIVE_PREPARE_QUERY_PARAM),
|
|
205
|
-
metadata,
|
|
206
|
-
)
|
|
207
191
|
res.writeHead(200, {
|
|
208
192
|
'Content-Type': 'application/json',
|
|
209
193
|
'Cache-Control': 'no-store',
|
|
@@ -225,4 +209,8 @@ export const handleNitroRequest = compiledModuleRequestHandler(
|
|
|
225
209
|
throw new Error('Nitro compilation needs configuration=Debug or Release')
|
|
226
210
|
return compileNitroApp(root, origin, configuration, undefined, true, iosTarget)
|
|
227
211
|
},
|
|
212
|
+
{
|
|
213
|
+
configuredNativeSources: true,
|
|
214
|
+
reusable: (origin, { url, hash }) => swiftArtifactIsAvailable(origin, url, hash),
|
|
215
|
+
},
|
|
228
216
|
)
|
package/src/one-sdk-bundle.ts
CHANGED
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,9 @@ export async function buildTurboBundle(
|
|
|
152
152
|
export const handleTurboRequest = compiledModuleRequestHandler(
|
|
153
153
|
'TurboModule',
|
|
154
154
|
(root, origin, iosTarget) => compileTurboApp(root, origin, undefined, iosTarget),
|
|
155
|
+
{
|
|
156
|
+
configuredNativeSources: true,
|
|
157
|
+
reusable: (origin, { unavailable, url, hash }) =>
|
|
158
|
+
!unavailable?.length && swiftArtifactIsAvailable(origin, url, hash),
|
|
159
|
+
},
|
|
155
160
|
)
|