peachsim 0.1.2438 → 0.1.2439
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/README.md +30 -98
- package/cli/app-catalog.ts +4 -73
- package/cli/catalog/content.ts +1 -1
- package/cli/cloud-box-artifact.ts +26 -39
- package/cli/cloud-client.ts +69 -117
- package/cli/cloud-session.ts +2 -9
- package/cli/commands/box.ts +6 -6
- package/cli/commands/control.ts +4 -11
- package/cli/commands/flow.ts +5 -9
- package/cli/commands/kotlin.ts +2 -1
- package/cli/commands/platform.ts +21 -39
- package/cli/commands/record-three.ts +1 -1
- package/cli/commands/shell-url.ts +29 -23
- package/cli/dev-build-freshness.ts +4 -3
- package/cli/native-input.ts +2 -2
- package/cli/outbound-endpoints.ts +20 -45
- package/cli/remote-project-bundle.ts +8 -14
- package/cli/remote-simulators.ts +1 -1
- package/cli/send-to-box.ts +2 -1
- package/detox/jest-preset.cjs +1 -1
- package/detox/jest-transform.cjs +40 -2
- package/dist-lib/agent-daemon-client.cjs +34 -24
- package/dist-lib/agent-events.cjs +1 -1
- package/dist-lib/attached-projects.cjs +19 -17
- package/dist-lib/auth/shared-session.cjs +18 -16
- package/dist-lib/backend-origin.cjs +1 -1
- package/dist-lib/beta.cjs +1 -1
- package/dist-lib/beta.mjs +2 -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 +20 -583
- package/dist-lib/bridge-contract.cjs +1 -1
- package/dist-lib/bridge-contract.mjs +17 -99
- package/dist-lib/bundle-channel.cjs +8718 -5552
- package/dist-lib/capture-contract.cjs +1 -1
- package/dist-lib/capture-contract.mjs +13 -363
- package/dist-lib/cloud-contract.cjs +1 -1
- package/dist-lib/cloud-contract.mjs +34 -155
- package/dist-lib/cloud-test-args.cjs +1 -1
- package/dist-lib/cloud-test-args.mjs +2 -1
- package/dist-lib/cloud.cjs +1 -1
- package/dist-lib/cloud.mjs +26 -155
- package/dist-lib/config.cjs +1 -4
- package/dist-lib/config.mjs +11 -30
- package/dist-lib/detox/index.cjs +2554 -230
- package/dist-lib/detox/jest-preset.cjs +1 -1
- package/dist-lib/detox/jest-transform.cjs +40 -2
- package/dist-lib/dev-bundle-resolution.cjs +1 -1
- package/dist-lib/esm-chunks/acorn-FGE4PYDJ.mjs +50 -0
- package/dist-lib/esm-chunks/chunk-2EUHEBIJ.mjs +664 -0
- package/dist-lib/esm-chunks/chunk-2NPABFPN.mjs +5719 -0
- package/dist-lib/esm-chunks/chunk-4ZFNH7TU.mjs +10 -0
- package/dist-lib/esm-chunks/chunk-5T4XBUJP.mjs +1353 -0
- package/dist-lib/esm-chunks/chunk-6VY6HTJC.mjs +18951 -0
- package/dist-lib/esm-chunks/chunk-7HANEMO4.mjs +188 -0
- package/dist-lib/esm-chunks/chunk-C3WBGYP6.mjs +186 -0
- package/dist-lib/esm-chunks/chunk-CVGDRROP.mjs +57 -0
- package/dist-lib/esm-chunks/chunk-DADGQELM.mjs +375 -0
- package/dist-lib/esm-chunks/chunk-DEGYKHN7.mjs +12 -0
- package/dist-lib/esm-chunks/chunk-HIDNO3RP.mjs +10992 -0
- package/dist-lib/esm-chunks/chunk-HSADZOVN.mjs +30 -0
- package/dist-lib/esm-chunks/chunk-IWJUYJQO.mjs +42 -0
- package/dist-lib/esm-chunks/chunk-JCKI3VZ6.mjs +10 -0
- package/dist-lib/esm-chunks/chunk-KSQ5KM5Y.mjs +17 -0
- package/dist-lib/esm-chunks/chunk-KVTIDLBK.mjs +598 -0
- package/dist-lib/esm-chunks/chunk-MIQSRBVU.mjs +10 -0
- package/dist-lib/esm-chunks/chunk-YB27R6JG.mjs +115 -0
- package/dist-lib/esm-chunks/metro-layout-parser-MVUAXRUJ.mjs +58 -0
- package/dist-lib/expo-swift-bundle.cjs +7856 -4707
- package/dist-lib/expo-swift-metadata.cjs +1 -1
- package/dist-lib/expo-swift-metadata.mjs +16 -165
- package/dist-lib/home-paths.cjs +1 -1
- package/dist-lib/host/bridge-host.cjs +15658 -11404
- package/dist-lib/host/fetch-proxy-handler.cjs +3927 -342
- package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
- package/dist-lib/host/fetch-proxy-overrides.mjs +2 -1
- package/dist-lib/host/replacement-module-handler.cjs +4 -4
- package/dist-lib/host/websocket-proxy.cjs +1 -1
- package/dist-lib/index.cjs +9145 -32150
- package/dist-lib/jump-to-source-babel.cjs +1 -1
- package/dist-lib/jump-to-source-native.cjs +2 -2
- package/dist-lib/kotlin-host.cjs +260 -253
- package/dist-lib/menu.cjs +1 -1
- package/dist-lib/menu.mjs +5 -13
- package/dist-lib/metro-fingerprint-registry.cjs +1 -1
- package/dist-lib/metro-fingerprint-registry.mjs +5 -6
- package/dist-lib/metro-production-bundle.cjs +22 -3
- package/dist-lib/metro-production-bundle.mjs +26 -92
- package/dist-lib/native-app-identity-project.cjs +663 -451
- package/dist-lib/native-app-identity-project.mjs +509 -2318
- package/dist-lib/native-app-identity.cjs +1 -1
- package/dist-lib/native-app-identity.mjs +27 -1340
- package/dist-lib/native-firebase-metadata.cjs +1 -1
- package/dist-lib/native-firebase-metadata.mjs +5 -18
- package/dist-lib/pdfium-raster.cjs +1 -1
- package/dist-lib/pdfium-raster.mjs +2 -1
- package/dist-lib/plist.cjs +2 -2
- package/dist-lib/plist.mjs +5 -7
- package/dist-lib/profiles.cjs +2 -1
- package/dist-lib/public-brand.cjs +1 -1
- package/dist-lib/public-origins-lib-esm.json +246 -187
- package/dist-lib/public-origins-lib-static.json +1 -1
- package/dist-lib/public-origins-lib.json +1059 -1238
- package/dist-lib/react-native-host-modules.cjs +1 -1
- package/dist-lib/react-native-host-modules.mjs +2 -1
- package/dist-lib/reap-browser.cjs +18 -7
- package/dist-lib/scripts/dev-server-scanner.cjs +6 -230
- package/dist-lib/sdk.cjs +1 -1
- package/dist-lib/sdk.mjs +22 -78
- package/dist-lib/skills.cjs +21657 -17374
- package/dist-lib/swift-compile.cjs +1343 -1318
- package/dist-lib/swift-compile.mjs +68 -19013
- package/dist-lib/swift-package.cjs +1 -1
- package/dist-lib/swift-package.mjs +35 -630
- package/dist-lib/swift-submit.cjs +1 -1
- package/dist-lib/swift-submit.mjs +9 -24
- package/dist-lib/swift-toolchain.cjs +1 -1
- package/dist-lib/swift.cjs +1 -1
- package/dist-lib/vendor/@peculiar/x509.cjs +18061 -0
- package/dist-lib/vendor/acorn.cjs +5699 -0
- package/dist-lib/vendor/bplist-parser.cjs +1589 -0
- package/dist-lib/vendor/ignore.cjs +455 -0
- package/dist-lib/vendor/magic-string.cjs +1693 -0
- package/dist-lib/vendor/plist.cjs +10978 -0
- package/dist-lib/vendor/smol-toml.cjs +768 -0
- package/dist-lib/vendor/stream-json.cjs +1997 -0
- package/dist-lib/vendor/sucrase/dist/index.js.cjs +23593 -0
- package/dist-lib/vendor/sucrase/dist/parser/index.js.cjs +15750 -0
- package/dist-lib/vendor/sucrase/dist/parser/tokenizer/index.js.cjs +11316 -0
- package/dist-lib/vendor/sucrase/dist/parser/tokenizer/types.js.cjs +482 -0
- package/dist-lib/vendor/sucrase.cjs +23593 -0
- package/dist-lib/vendor/terser.cjs +36874 -0
- package/dist-lib/vendor/valibot.cjs +6253 -0
- package/dist-lib/vendor/zod.cjs +23262 -0
- package/dist-lib/worklet-executable.cjs +3 -3
- package/dist-lib/worklet-executable.mjs +11 -16
- package/dist-types/packages/peach-engine/src/config.d.ts +1 -1
- package/kotlin/fork/NOTICE +3 -0
- package/kotlin/sdk.tar.gz +0 -0
- package/kotlin/toolchain.json +6 -6
- package/package.json +17 -121
- package/runtime-companion.json +1 -1
- package/scripts/dev-server-scanner.ts +13 -223
- package/src/android-autolinking.ts +2 -2
- package/src/bundle-channel.mjs +3 -15
- package/src/cloud-contract.ts +3 -4
- package/src/config.ts +0 -5
- package/src/host/bridge-host.ts +19 -1
- package/src/host/server-scan-handler.ts +1 -9
- package/src/index.ts +0 -2
- package/src/kotlin-host.ts +1 -2
- package/src/kotlinDiscoveryContract.ts +1 -0
- package/src/metro-production-bundle.ts +28 -6
- package/src/native-seam-manifest.ts +0 -13
- package/src/one-native-app-catalog.ts +8 -27
- package/src/one-native-app-config.ts +95 -0
- package/src/one-native-source.ts +250 -0
- package/src/one-widget-metadata.ts +45 -126
- package/src/oneWidgetContract.ts +80 -117
- package/src/serverDiscoveryContract.ts +0 -1
- package/src/simulator-route.ts +8 -0
- package/src/vite-plugin.ts +2 -2
- package/src/xcode-project.ts +1 -1
- package/dist-lib/metro.cjs +0 -27984
- package/dist-lib/vite-swift.cjs +0 -43376
- package/dist-lib/vite.cjs +0 -21456
- package/src/androidAutolinkingContract.ts +0 -48
- package/src/androidRootModuleContract.ts +0 -39
- package/src/dev-server-open.ts +0 -92
- package/src/metro-plugin.ts +0 -578
- package/src/one-widget-discovery.ts +0 -23
- package/src/swift-vite-lifetime.ts +0 -42
- package/src/vite-plugin-one.ts +0 -746
- package/src/vite-plugin-swift.ts +0 -225
- package/src/vite.d.ts +0 -10
package/src/metro-plugin.ts
DELETED
|
@@ -1,578 +0,0 @@
|
|
|
1
|
-
// peach metro plugin for dev shell and bundle identity metadata.
|
|
2
|
-
// shell assets come from an engine runtime under ~/.peach/runtimes/, fetched
|
|
3
|
-
// by `peach runtime install`. ordinary localhost requests
|
|
4
|
-
// follow active; a version-owned localhost origin stays on its exact directory
|
|
5
|
-
// when active changes, so one loaded shell cannot mix runtime chunk trees.
|
|
6
|
-
//
|
|
7
|
-
// usage in metro.config.js:
|
|
8
|
-
// const { withPeach } = require('peachsim/metro')
|
|
9
|
-
// module.exports = withPeach(getDefaultConfig(__dirname))
|
|
10
|
-
|
|
11
|
-
import fs from 'fs'
|
|
12
|
-
import { createRequire } from 'module'
|
|
13
|
-
import { randomUUID } from 'node:crypto'
|
|
14
|
-
import path from 'path'
|
|
15
|
-
import { insertPackageVersionsFooter } from '@peach/globals/package-versions'
|
|
16
|
-
import { resolveAppProject } from '../cli/app-project'
|
|
17
|
-
import { collectAndroidAutolinkedPackages } from './android-autolinking'
|
|
18
|
-
import { readAndroidLauncherRootModuleName } from './android-root-module'
|
|
19
|
-
import { insertAndroidAutolinkingFooter } from './androidAutolinkingContract'
|
|
20
|
-
import { insertAndroidRootModuleFooter } from './androidRootModuleContract'
|
|
21
|
-
import { tagRnxBundleForPlugin } from './dev-server-open'
|
|
22
|
-
import { serveBrowserProxyRoute } from './host/fetch-proxy-handler'
|
|
23
|
-
import {
|
|
24
|
-
handleReplacementModuleRequest,
|
|
25
|
-
isReplacementModuleRequestUrl,
|
|
26
|
-
} from './host/replacement-module-handler'
|
|
27
|
-
import { readInstalledPackageVersions } from './installed-package-versions'
|
|
28
|
-
import {
|
|
29
|
-
appendRNXMetroModuleIdentityFooter,
|
|
30
|
-
RNX_METRO_MODULE_IDENTITY_VERSION,
|
|
31
|
-
toPeachDevelopmentBundleUrl,
|
|
32
|
-
toPeachProductionBundleUrl,
|
|
33
|
-
type RNXMetroModuleIdentityMetadata,
|
|
34
|
-
} from './metro-production-bundle'
|
|
35
|
-
import { insertNativeAppIdentityFooter } from './native-app-identity'
|
|
36
|
-
import {
|
|
37
|
-
readNativeAppIdentityFromProject,
|
|
38
|
-
readNativeAppIdentityFromSources,
|
|
39
|
-
} from './native-app-identity-project'
|
|
40
|
-
import { readNativeFirebaseConfig } from './native-firebase-config'
|
|
41
|
-
import {
|
|
42
|
-
insertNativeFirebaseFooter,
|
|
43
|
-
readNativeFirebaseMetadata,
|
|
44
|
-
} from './native-firebase-metadata'
|
|
45
|
-
import { parsePlistSource } from './plist'
|
|
46
|
-
import {
|
|
47
|
-
isRootRuntimeAssetPath,
|
|
48
|
-
resolveRuntimeFilePath,
|
|
49
|
-
resolveRuntimeRootForRequestHost,
|
|
50
|
-
sendShellHtml,
|
|
51
|
-
serveRuntimeFile,
|
|
52
|
-
SOOTSIM_RUNTIME_MISSING_MESSAGE,
|
|
53
|
-
} from './runtime-assets'
|
|
54
|
-
import { ensureRuntimePackFor } from './runtime-packs'
|
|
55
|
-
import {
|
|
56
|
-
getRuntimePlatformAdapter,
|
|
57
|
-
isRuntimePlatform,
|
|
58
|
-
} from './runtimePlatformContract.ts'
|
|
59
|
-
|
|
60
|
-
const prefix = '/__peachsim'
|
|
61
|
-
export { toPeachDevelopmentBundleUrl, toPeachProductionBundleUrl }
|
|
62
|
-
|
|
63
|
-
type MetroSerializerModule = {
|
|
64
|
-
path: string
|
|
65
|
-
dependencies?: ReadonlyMap<
|
|
66
|
-
string,
|
|
67
|
-
{
|
|
68
|
-
absolutePath?: string
|
|
69
|
-
data?: { name?: string }
|
|
70
|
-
}
|
|
71
|
-
>
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
type MetroSerializerGraph = {
|
|
75
|
-
dependencies?: ReadonlyMap<unknown, MetroSerializerModule>
|
|
76
|
-
transformOptions?: { platform?: string | null }
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
type MetroSerializerOptions = {
|
|
80
|
-
asyncRequireModulePath: string
|
|
81
|
-
createModuleId?: (modulePath: string) => number
|
|
82
|
-
dev?: boolean
|
|
83
|
-
sourceUrl?: string
|
|
84
|
-
serializerOptions?: { output?: string }
|
|
85
|
-
[key: string]: unknown
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
type MetroSerializerArtifact = {
|
|
89
|
-
type: string
|
|
90
|
-
source: string
|
|
91
|
-
[key: string]: unknown
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
type MetroSerializerArtifacts = {
|
|
95
|
-
artifacts: readonly MetroSerializerArtifact[]
|
|
96
|
-
assets: readonly unknown[]
|
|
97
|
-
[key: string]: unknown
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
type MetroSerializerResult =
|
|
101
|
-
| string
|
|
102
|
-
| { code: string; map: string }
|
|
103
|
-
| MetroSerializerArtifacts
|
|
104
|
-
|
|
105
|
-
function isMetroSerializerArtifacts(value: unknown): value is MetroSerializerArtifacts {
|
|
106
|
-
return (
|
|
107
|
-
typeof value === 'object' &&
|
|
108
|
-
value !== null &&
|
|
109
|
-
'artifacts' in value &&
|
|
110
|
-
Array.isArray(value.artifacts) &&
|
|
111
|
-
value.artifacts.every(
|
|
112
|
-
(artifact: unknown) =>
|
|
113
|
-
typeof artifact === 'object' &&
|
|
114
|
-
artifact !== null &&
|
|
115
|
-
'type' in artifact &&
|
|
116
|
-
typeof artifact.type === 'string' &&
|
|
117
|
-
'source' in artifact &&
|
|
118
|
-
typeof artifact.source === 'string',
|
|
119
|
-
) &&
|
|
120
|
-
'assets' in value &&
|
|
121
|
-
Array.isArray(value.assets)
|
|
122
|
-
)
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
async function mapMetroSerializerCode(
|
|
126
|
-
result: MetroSerializerResult,
|
|
127
|
-
transform: (code: string) => string | Promise<string>,
|
|
128
|
-
): Promise<MetroSerializerResult> {
|
|
129
|
-
if (typeof result === 'string') return transform(result)
|
|
130
|
-
if (isMetroSerializerArtifacts(result)) {
|
|
131
|
-
return {
|
|
132
|
-
...result,
|
|
133
|
-
artifacts: await Promise.all(
|
|
134
|
-
result.artifacts.map(async (artifact) =>
|
|
135
|
-
artifact.type === 'js'
|
|
136
|
-
? { ...artifact, source: await transform(artifact.source) }
|
|
137
|
-
: artifact,
|
|
138
|
-
),
|
|
139
|
-
),
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
if ('code' in result && typeof result.code === 'string') {
|
|
143
|
-
return { ...result, code: await transform(result.code) }
|
|
144
|
-
}
|
|
145
|
-
throw new Error('peachsim: Metro serializer returned no JavaScript source')
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
type MetroSerializer = (
|
|
149
|
-
entryPoint: string,
|
|
150
|
-
preModules: readonly unknown[],
|
|
151
|
-
graph: MetroSerializerGraph,
|
|
152
|
-
options: MetroSerializerOptions,
|
|
153
|
-
) => MetroSerializerResult | Promise<MetroSerializerResult>
|
|
154
|
-
|
|
155
|
-
type MetroConfigWithServer = {
|
|
156
|
-
projectRoot?: string
|
|
157
|
-
watchFolders?: readonly string[]
|
|
158
|
-
serializer?: {
|
|
159
|
-
customSerializer?: MetroSerializer
|
|
160
|
-
[key: string]: unknown
|
|
161
|
-
}
|
|
162
|
-
resolver?: {
|
|
163
|
-
emptyModulePath?: string
|
|
164
|
-
[key: string]: unknown
|
|
165
|
-
}
|
|
166
|
-
server?: {
|
|
167
|
-
enhanceMiddleware?: (middleware: unknown, server: unknown) => unknown
|
|
168
|
-
port?: number
|
|
169
|
-
[key: string]: unknown
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
function readCallableMetroExport(
|
|
174
|
-
moduleValue: unknown,
|
|
175
|
-
label: string,
|
|
176
|
-
): (...args: readonly unknown[]) => unknown {
|
|
177
|
-
const callable =
|
|
178
|
-
typeof moduleValue === 'function'
|
|
179
|
-
? moduleValue
|
|
180
|
-
: typeof moduleValue === 'object' && moduleValue !== null
|
|
181
|
-
? Reflect.get(moduleValue, 'default')
|
|
182
|
-
: undefined
|
|
183
|
-
if (typeof callable !== 'function') {
|
|
184
|
-
throw new Error(`peachsim: Metro ${label} module did not export a function`)
|
|
185
|
-
}
|
|
186
|
-
return (...args) => Reflect.apply(callable, undefined, args)
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
function createMetroDefaultSerializer(asyncRequireModulePath: string): MetroSerializer {
|
|
190
|
-
// metro supplies this absolute runtime path from its resolved configuration.
|
|
191
|
-
const projectRequire = createRequire(asyncRequireModulePath)
|
|
192
|
-
const metroRoot = path.dirname(projectRequire.resolve('metro/package.json'))
|
|
193
|
-
const baseJSBundle = readCallableMetroExport(
|
|
194
|
-
projectRequire(path.join(metroRoot, 'src/DeltaBundler/Serializers/baseJSBundle.js')),
|
|
195
|
-
'baseJSBundle',
|
|
196
|
-
)
|
|
197
|
-
const bundleToString = readCallableMetroExport(
|
|
198
|
-
projectRequire(path.join(metroRoot, 'src/lib/bundleToString.js')),
|
|
199
|
-
'bundleToString',
|
|
200
|
-
)
|
|
201
|
-
|
|
202
|
-
return (entryPoint, preModules, graph, options) => {
|
|
203
|
-
const serialized = bundleToString(
|
|
204
|
-
baseJSBundle(entryPoint, preModules, graph, options),
|
|
205
|
-
)
|
|
206
|
-
const code =
|
|
207
|
-
typeof serialized === 'object' && serialized !== null
|
|
208
|
-
? Reflect.get(serialized, 'code')
|
|
209
|
-
: undefined
|
|
210
|
-
if (typeof code !== 'string') {
|
|
211
|
-
throw new Error('peachsim: Metro bundleToString did not return bundle code')
|
|
212
|
-
}
|
|
213
|
-
return code
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
// module identity accompanies an ordinary Metro bundle. production needs the
|
|
218
|
-
// footer because Metro drops the fourth `__d` argument when `dev` is false;
|
|
219
|
-
// development keeps that verbose name and receives the same identity without
|
|
220
|
-
// changing resolution, transforms, or the trailing source map.
|
|
221
|
-
async function appendRNXModulePaths(
|
|
222
|
-
result: MetroSerializerResult,
|
|
223
|
-
graph: MetroSerializerGraph,
|
|
224
|
-
options: MetroSerializerOptions,
|
|
225
|
-
projectRoot: string,
|
|
226
|
-
emptyModulePath: string,
|
|
227
|
-
): Promise<MetroSerializerResult> {
|
|
228
|
-
const dependencies = graph.dependencies
|
|
229
|
-
const createModuleId = options.createModuleId
|
|
230
|
-
if (!dependencies || !createModuleId) {
|
|
231
|
-
return result
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
const modulePaths: Record<string, string> = {}
|
|
235
|
-
for (const module of dependencies.values()) {
|
|
236
|
-
modulePaths[String(createModuleId(module.path))] = path
|
|
237
|
-
.relative(projectRoot, module.path)
|
|
238
|
-
.replaceAll(path.sep, '/')
|
|
239
|
-
}
|
|
240
|
-
if (Object.keys(modulePaths).length !== dependencies.size) {
|
|
241
|
-
throw new Error('peachsim: bundle module IDs were not unique')
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
const specifiersByModuleId = new Map<string, Set<string>>()
|
|
245
|
-
for (const module of dependencies.values()) {
|
|
246
|
-
for (const [dependencyKey, dependency] of module.dependencies ?? []) {
|
|
247
|
-
const specifier = dependency.data?.name ?? dependencyKey
|
|
248
|
-
if (
|
|
249
|
-
specifier.length === 0 ||
|
|
250
|
-
specifier.startsWith('.') ||
|
|
251
|
-
specifier.startsWith('/') ||
|
|
252
|
-
typeof dependency.absolutePath !== 'string' ||
|
|
253
|
-
// a resolver that returns `{ type: 'empty' }` gives every such
|
|
254
|
-
// specifier metro's one empty module, on native too; the specifier
|
|
255
|
-
// names nothing the bundle contains, so it carries no identity
|
|
256
|
-
dependency.absolutePath === emptyModulePath
|
|
257
|
-
) {
|
|
258
|
-
continue
|
|
259
|
-
}
|
|
260
|
-
const moduleId = String(createModuleId(dependency.absolutePath))
|
|
261
|
-
if (!Object.prototype.hasOwnProperty.call(modulePaths, moduleId)) continue
|
|
262
|
-
const found = specifiersByModuleId.get(moduleId)
|
|
263
|
-
if (found) found.add(specifier)
|
|
264
|
-
else specifiersByModuleId.set(moduleId, new Set([specifier]))
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
const logicalSpecifiers = Object.fromEntries(
|
|
268
|
-
[...specifiersByModuleId]
|
|
269
|
-
.sort(([left], [right]) => Number(left) - Number(right))
|
|
270
|
-
.map(([moduleId, specifiers]) => [moduleId, [...specifiers].sort()]),
|
|
271
|
-
)
|
|
272
|
-
const identity: RNXMetroModuleIdentityMetadata = {
|
|
273
|
-
version: RNX_METRO_MODULE_IDENTITY_VERSION,
|
|
274
|
-
identitySource: 'rnx-plugin',
|
|
275
|
-
modulePaths,
|
|
276
|
-
logicalSpecifiers,
|
|
277
|
-
}
|
|
278
|
-
const versions = readInstalledPackageVersions(
|
|
279
|
-
projectRoot,
|
|
280
|
-
Array.from(dependencies.values(), (module) => module.path),
|
|
281
|
-
)
|
|
282
|
-
const annotate = (code: string) =>
|
|
283
|
-
insertPackageVersionsFooter(
|
|
284
|
-
appendRNXMetroModuleIdentityFooter(code, identity),
|
|
285
|
-
versions,
|
|
286
|
-
)
|
|
287
|
-
return mapMetroSerializerCode(result, annotate)
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
export function withPeach<T extends Record<string, unknown>>(
|
|
291
|
-
config: T,
|
|
292
|
-
options: { iosTarget?: string; androidMergedManifest?: string } = {},
|
|
293
|
-
): T {
|
|
294
|
-
const cfgProjectRoot = (config as MetroConfigWithServer).projectRoot || process.cwd()
|
|
295
|
-
const cfgWatchFolders = (config as MetroConfigWithServer).watchFolders ?? []
|
|
296
|
-
const configuredBundleUrl = '/index.bundle?platform=ios&dev=true&hot=true&minify=false'
|
|
297
|
-
|
|
298
|
-
const cfgServer = (config as MetroConfigWithServer).server
|
|
299
|
-
const port = resolveMetroPort(cfgServer)
|
|
300
|
-
const metroServerId = randomUUID()
|
|
301
|
-
const bundleUrl = tagRnxBundleForPlugin(
|
|
302
|
-
configuredBundleUrl,
|
|
303
|
-
`http://localhost:${port}`,
|
|
304
|
-
metroServerId,
|
|
305
|
-
cfgProjectRoot,
|
|
306
|
-
)
|
|
307
|
-
const cfgSerializer = (config as MetroConfigWithServer).serializer
|
|
308
|
-
const existingEnhance = cfgServer?.enhanceMiddleware
|
|
309
|
-
const existingSerializer = cfgSerializer?.customSerializer
|
|
310
|
-
// metro's default empty module sits beside its default asyncRequire in the
|
|
311
|
-
// same metro-runtime, so only a configured path needs reading here
|
|
312
|
-
const configuredEmptyModulePath = (config as MetroConfigWithServer).resolver
|
|
313
|
-
?.emptyModulePath
|
|
314
|
-
|
|
315
|
-
let defaultSerializer: MetroSerializer | undefined
|
|
316
|
-
|
|
317
|
-
const serializerConfig = {
|
|
318
|
-
serializer: {
|
|
319
|
-
...cfgSerializer,
|
|
320
|
-
customSerializer: async (
|
|
321
|
-
entryPoint: string,
|
|
322
|
-
preModules: readonly unknown[],
|
|
323
|
-
graph: MetroSerializerGraph,
|
|
324
|
-
serializerOptions: MetroSerializerOptions,
|
|
325
|
-
) => {
|
|
326
|
-
const serializer =
|
|
327
|
-
existingSerializer ||
|
|
328
|
-
(defaultSerializer ||= createMetroDefaultSerializer(
|
|
329
|
-
serializerOptions.asyncRequireModulePath,
|
|
330
|
-
))
|
|
331
|
-
const bundlePlatform = graph.transformOptions?.platform
|
|
332
|
-
const [result, androidAutolinkedPackages] = await Promise.all([
|
|
333
|
-
serializer(entryPoint, preModules, graph, serializerOptions),
|
|
334
|
-
isRuntimePlatform(bundlePlatform) &&
|
|
335
|
-
getRuntimePlatformAdapter(bundlePlatform).isAndroid
|
|
336
|
-
? collectAndroidAutolinkedPackages(cfgProjectRoot)
|
|
337
|
-
: Promise.resolve(null),
|
|
338
|
-
])
|
|
339
|
-
const staticJson =
|
|
340
|
-
typeof result === 'string' &&
|
|
341
|
-
(serializerOptions.serializerOptions?.output === 'static' ||
|
|
342
|
-
new URL(
|
|
343
|
-
serializerOptions.sourceUrl ?? configuredBundleUrl,
|
|
344
|
-
'http://localhost',
|
|
345
|
-
).searchParams.get('serializer.output') === 'static')
|
|
346
|
-
let serialized = result
|
|
347
|
-
if (staticJson && typeof result === 'string') {
|
|
348
|
-
const decoded: unknown = JSON.parse(result)
|
|
349
|
-
if (!isMetroSerializerArtifacts(decoded)) {
|
|
350
|
-
throw new Error(
|
|
351
|
-
'peachsim: Metro static serializer returned invalid artifacts',
|
|
352
|
-
)
|
|
353
|
-
}
|
|
354
|
-
serialized = decoded
|
|
355
|
-
}
|
|
356
|
-
let annotated = await appendRNXModulePaths(
|
|
357
|
-
serialized,
|
|
358
|
-
graph,
|
|
359
|
-
serializerOptions,
|
|
360
|
-
cfgProjectRoot,
|
|
361
|
-
configuredEmptyModulePath ??
|
|
362
|
-
path.join(
|
|
363
|
-
path.dirname(serializerOptions.asyncRequireModulePath),
|
|
364
|
-
'empty-module.js',
|
|
365
|
-
),
|
|
366
|
-
)
|
|
367
|
-
if (androidAutolinkedPackages !== null) {
|
|
368
|
-
annotated = await mapMetroSerializerCode(annotated, (code) =>
|
|
369
|
-
insertAndroidAutolinkingFooter(code, androidAutolinkedPackages),
|
|
370
|
-
)
|
|
371
|
-
const rootModuleName = readAndroidLauncherRootModuleName(cfgProjectRoot)
|
|
372
|
-
if (rootModuleName !== undefined) {
|
|
373
|
-
annotated = await mapMetroSerializerCode(annotated, (code) =>
|
|
374
|
-
insertAndroidRootModuleFooter(code, rootModuleName),
|
|
375
|
-
)
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
const identity =
|
|
379
|
-
readNativeAppIdentityFromProject(
|
|
380
|
-
cfgProjectRoot,
|
|
381
|
-
bundlePlatform,
|
|
382
|
-
parsePlistSource,
|
|
383
|
-
options.iosTarget,
|
|
384
|
-
options.androidMergedManifest,
|
|
385
|
-
) ??
|
|
386
|
-
readNativeAppIdentityFromSources(
|
|
387
|
-
cfgProjectRoot,
|
|
388
|
-
bundlePlatform,
|
|
389
|
-
parsePlistSource,
|
|
390
|
-
options.iosTarget,
|
|
391
|
-
)
|
|
392
|
-
if (identity) {
|
|
393
|
-
annotated = await mapMetroSerializerCode(annotated, (code) =>
|
|
394
|
-
insertNativeAppIdentityFooter(code, identity),
|
|
395
|
-
)
|
|
396
|
-
}
|
|
397
|
-
if (
|
|
398
|
-
[...(graph.dependencies?.values() ?? [])].some((module) =>
|
|
399
|
-
module.path.replace(/\\/g, '/').includes('/@react-native-firebase/app/'),
|
|
400
|
-
)
|
|
401
|
-
) {
|
|
402
|
-
const firebase = readNativeFirebaseMetadata(
|
|
403
|
-
readNativeFirebaseConfig(
|
|
404
|
-
cfgProjectRoot,
|
|
405
|
-
typeof bundlePlatform === 'string' ? [bundlePlatform] : undefined,
|
|
406
|
-
options.iosTarget,
|
|
407
|
-
),
|
|
408
|
-
)
|
|
409
|
-
if (firebase)
|
|
410
|
-
annotated = await mapMetroSerializerCode(annotated, (code) =>
|
|
411
|
-
insertNativeFirebaseFooter(code, firebase),
|
|
412
|
-
)
|
|
413
|
-
}
|
|
414
|
-
const project = resolveAppProject(cfgProjectRoot)
|
|
415
|
-
const appConfig = await (await import('./app-config')).loadRNXAppConfig(project)
|
|
416
|
-
if (appConfig) {
|
|
417
|
-
const { produceConfiguredBundle } = await import('./configured-bundle-producer')
|
|
418
|
-
const runtimePackages = new Set<string>()
|
|
419
|
-
for (const module of graph.dependencies?.values() ?? []) {
|
|
420
|
-
for (const [key, dependency] of module.dependencies ?? []) {
|
|
421
|
-
const specifier = dependency.data?.name ?? key
|
|
422
|
-
if (!specifier.startsWith('.') && !specifier.startsWith('/'))
|
|
423
|
-
runtimePackages.add(specifier)
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
annotated = await mapMetroSerializerCode(annotated, (code) =>
|
|
427
|
-
produceConfiguredBundle(code, appConfig, runtimePackages),
|
|
428
|
-
)
|
|
429
|
-
}
|
|
430
|
-
return staticJson ? JSON.stringify(annotated) : annotated
|
|
431
|
-
},
|
|
432
|
-
},
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
const serverConfig = {
|
|
436
|
-
...cfgServer,
|
|
437
|
-
enhanceMiddleware: (metroMiddleware: any, metroServer: any) => {
|
|
438
|
-
let middleware = metroMiddleware
|
|
439
|
-
if (existingEnhance) {
|
|
440
|
-
middleware = existingEnhance(metroMiddleware, metroServer)
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
let connect: any
|
|
444
|
-
try {
|
|
445
|
-
connect = require('connect')
|
|
446
|
-
} catch {
|
|
447
|
-
console.warn('[peach] connect not available')
|
|
448
|
-
return middleware
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
const server = connect()
|
|
452
|
-
|
|
453
|
-
server.use(async (req: any, res: any, next: any) => {
|
|
454
|
-
if (isReplacementModuleRequestUrl(req.url)) {
|
|
455
|
-
void handleReplacementModuleRequest(req, res, {
|
|
456
|
-
servedRoots: [cfgProjectRoot, ...cfgWatchFolders],
|
|
457
|
-
requestToken: metroServerId,
|
|
458
|
-
requireLoopbackOrigin: true,
|
|
459
|
-
}).then((handled) => {
|
|
460
|
-
if (!handled) next()
|
|
461
|
-
})
|
|
462
|
-
return
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
if ((req.url || '').split('?')[0] === '/__peach-native-firebase-config') {
|
|
466
|
-
try {
|
|
467
|
-
res.setHeader('Content-Type', 'application/json')
|
|
468
|
-
res.setHeader('Cache-Control', 'no-store')
|
|
469
|
-
res.setHeader('Access-Control-Allow-Origin', '*')
|
|
470
|
-
res.end(
|
|
471
|
-
JSON.stringify(
|
|
472
|
-
readNativeFirebaseConfig(cfgProjectRoot, undefined, options.iosTarget),
|
|
473
|
-
),
|
|
474
|
-
)
|
|
475
|
-
} catch (error) {
|
|
476
|
-
res.statusCode = 400
|
|
477
|
-
res.end(
|
|
478
|
-
JSON.stringify({
|
|
479
|
-
error: error instanceof Error ? error.message : String(error),
|
|
480
|
-
}),
|
|
481
|
-
)
|
|
482
|
-
}
|
|
483
|
-
return
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
if (serveBrowserProxyRoute(req, res)) return
|
|
487
|
-
|
|
488
|
-
const url = req.url || ''
|
|
489
|
-
const pathname = url.split('?')[0]
|
|
490
|
-
|
|
491
|
-
const runtimeRoot = resolveRuntimeRootForRequestHost(req.headers?.host)
|
|
492
|
-
|
|
493
|
-
if (!runtimeRoot) {
|
|
494
|
-
if (pathname === prefix || pathname === prefix + '/') {
|
|
495
|
-
res.statusCode = 500
|
|
496
|
-
res.end(SOOTSIM_RUNTIME_MISSING_MESSAGE)
|
|
497
|
-
return
|
|
498
|
-
}
|
|
499
|
-
next()
|
|
500
|
-
return
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
await ensureRuntimePackFor(runtimeRoot, pathname)
|
|
504
|
-
|
|
505
|
-
// root-relative runtime assets emitted by the shell and engine vite
|
|
506
|
-
// builds. if a user app has its own /assets/foo request, we only
|
|
507
|
-
// intercept when that exact file exists in the runtime; otherwise
|
|
508
|
-
// metro handles it normally.
|
|
509
|
-
if (isRootRuntimeAssetPath(pathname)) {
|
|
510
|
-
const fullPath = resolveRuntimeFilePath(runtimeRoot, pathname)
|
|
511
|
-
if (fullPath) {
|
|
512
|
-
serveRuntimeFile(req, res, fullPath)
|
|
513
|
-
return
|
|
514
|
-
}
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
// /__peachsim/* — serve runtime assets
|
|
518
|
-
if (pathname.startsWith(prefix + '/')) {
|
|
519
|
-
const fullPath = resolveRuntimeFilePath(
|
|
520
|
-
runtimeRoot,
|
|
521
|
-
pathname.slice(prefix.length),
|
|
522
|
-
)
|
|
523
|
-
if (fullPath) {
|
|
524
|
-
serveRuntimeFile(req, res, fullPath)
|
|
525
|
-
return
|
|
526
|
-
}
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
// serve HTML shell for /__peachsim and extensionless in-shell routes.
|
|
530
|
-
if (
|
|
531
|
-
pathname === prefix ||
|
|
532
|
-
pathname === prefix + '/' ||
|
|
533
|
-
pathname.startsWith(prefix + '/')
|
|
534
|
-
) {
|
|
535
|
-
const ext = path.extname(pathname)
|
|
536
|
-
if (!ext) {
|
|
537
|
-
const htmlPath = path.join(runtimeRoot, 'index.html')
|
|
538
|
-
let html = fs.readFileSync(htmlPath, 'utf8')
|
|
539
|
-
const script = `<script>(function(){var u=new URL(location.href);if(!u.searchParams.has('bundle'))u.searchParams.set('bundle',${JSON.stringify(bundleUrl)});history.replaceState(null,'','${prefix}/'+u.search)})()</script>`
|
|
540
|
-
html = html.includes('</head>')
|
|
541
|
-
? html.replace('</head>', `${script}</head>`)
|
|
542
|
-
: `${html}${script}`
|
|
543
|
-
sendShellHtml(res, html)
|
|
544
|
-
return
|
|
545
|
-
}
|
|
546
|
-
}
|
|
547
|
-
|
|
548
|
-
next()
|
|
549
|
-
})
|
|
550
|
-
|
|
551
|
-
server.use(middleware)
|
|
552
|
-
|
|
553
|
-
console.log(`[peach] serving at ${prefix}/`)
|
|
554
|
-
return server
|
|
555
|
-
},
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
return {
|
|
559
|
-
...config,
|
|
560
|
-
...serializerConfig,
|
|
561
|
-
server: serverConfig,
|
|
562
|
-
} as T
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
function resolveMetroPort(server: MetroConfigWithServer['server']): number {
|
|
566
|
-
const inlinePort = process.argv.find((arg) => arg.startsWith('--port='))?.slice(7)
|
|
567
|
-
const portIndex = process.argv.indexOf('--port')
|
|
568
|
-
const splitPort = portIndex >= 0 ? process.argv[portIndex + 1] : undefined
|
|
569
|
-
const rawPort =
|
|
570
|
-
inlinePort || splitPort || process.env.RCT_METRO_PORT || server?.port || 8081
|
|
571
|
-
const port = Number(rawPort)
|
|
572
|
-
if (!Number.isInteger(port) || port <= 0) {
|
|
573
|
-
throw new Error(`peach: Metro port must be a positive integer, got ${rawPort}`)
|
|
574
|
-
}
|
|
575
|
-
return port
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
export default withPeach
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { isContrastBackendHost, isLoopbackHost } from './backend-origin'
|
|
2
|
-
import { configuredWidgetFromScan } from './oneWidgetContract'
|
|
3
|
-
import type { ConfiguredOneWidget } from './oneWidgetContract'
|
|
4
|
-
|
|
5
|
-
export async function readConfiguredOneWidget(
|
|
6
|
-
bundleUrl: string,
|
|
7
|
-
fetchScan: (url: string, init: RequestInit) => Promise<Response> = fetch,
|
|
8
|
-
): Promise<ConfiguredOneWidget | null> {
|
|
9
|
-
try {
|
|
10
|
-
const bundle = new URL(bundleUrl)
|
|
11
|
-
// published backend bundles have no development server or widget package to scan.
|
|
12
|
-
if (isContrastBackendHost(bundle.hostname) && !isLoopbackHost(bundle.hostname))
|
|
13
|
-
return null
|
|
14
|
-
const response = await fetchScan(new URL('/__server-scan', bundle).href, {
|
|
15
|
-
signal: AbortSignal.timeout(30_000),
|
|
16
|
-
})
|
|
17
|
-
if (!response.ok || !response.headers.get('content-type')?.includes('json'))
|
|
18
|
-
return null
|
|
19
|
-
return configuredWidgetFromScan(await response.json(), bundleUrl)
|
|
20
|
-
} catch {
|
|
21
|
-
return null
|
|
22
|
-
}
|
|
23
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import type { ViteDevServer } from 'vite'
|
|
2
|
-
|
|
3
|
-
interface SwiftViteLifetime {
|
|
4
|
-
signal: AbortSignal
|
|
5
|
-
compiles: Set<Promise<unknown>>
|
|
6
|
-
projects: Set<string>
|
|
7
|
-
close(): Promise<void>
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
// the adapters ship as separate bundles, so the server carries their shared owner.
|
|
11
|
-
const LIFETIME = Symbol.for('peach.swift-vite-lifetime')
|
|
12
|
-
|
|
13
|
-
export function swiftViteLifetime(
|
|
14
|
-
server: ViteDevServer & { [LIFETIME]?: SwiftViteLifetime },
|
|
15
|
-
): SwiftViteLifetime {
|
|
16
|
-
const existing = server[LIFETIME]
|
|
17
|
-
if (existing && !existing.signal.aborted) return existing
|
|
18
|
-
const controller = new AbortController()
|
|
19
|
-
const compiles = new Set<Promise<unknown>>()
|
|
20
|
-
const projects = new Set<string>()
|
|
21
|
-
let closing: Promise<void> | undefined
|
|
22
|
-
const lifetime: SwiftViteLifetime = {
|
|
23
|
-
signal: controller.signal,
|
|
24
|
-
compiles,
|
|
25
|
-
projects,
|
|
26
|
-
close() {
|
|
27
|
-
closing ??= (async () => {
|
|
28
|
-
controller.abort(new Error('Swift dev server closed'))
|
|
29
|
-
await Promise.allSettled(compiles)
|
|
30
|
-
if (projects.size > 0) {
|
|
31
|
-
const host = await import('peachsim/vite-swift')
|
|
32
|
-
for (const packagePath of projects)
|
|
33
|
-
host.disposeSwiftProject(packagePath, controller.signal)
|
|
34
|
-
projects.clear()
|
|
35
|
-
}
|
|
36
|
-
})()
|
|
37
|
-
return closing
|
|
38
|
-
},
|
|
39
|
-
}
|
|
40
|
-
server[LIFETIME] = lifetime
|
|
41
|
-
return lifetime
|
|
42
|
-
}
|