peachsim 0.1.1654 → 0.1.1659

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.
Files changed (236) hide show
  1. package/cli/app-config.ts +4 -0
  2. package/cli/app-stubs.ts +43 -6
  3. package/cli/commands/inspect/shared.ts +5 -2
  4. package/cli/commands/inspect/url.ts +2 -1
  5. package/cli/commands/screenshot.ts +5 -5
  6. package/cli/commands/state.ts +9 -6
  7. package/cli/outbound-endpoints.ts +9 -1
  8. package/cli/output-redaction.ts +49 -0
  9. package/dist-lib/agent-daemon-client.cjs +1 -1
  10. package/dist-lib/agent-events.cjs +1 -1
  11. package/dist-lib/attached-projects.cjs +1 -1
  12. package/dist-lib/auth/shared-session.cjs +1 -1
  13. package/dist-lib/backend-origin.cjs +1 -1
  14. package/dist-lib/beta.cjs +1 -1
  15. package/dist-lib/beta.mjs +1 -1
  16. package/dist-lib/bridge-constants.cjs +1 -1
  17. package/dist-lib/bridge-contract-input.cjs +1 -1
  18. package/dist-lib/bridge-contract-input.mjs +1 -1
  19. package/dist-lib/bridge-contract.cjs +1 -1
  20. package/dist-lib/bridge-contract.mjs +1 -1
  21. package/dist-lib/bundle-channel.cjs +11485 -1316
  22. package/dist-lib/capture-contract.cjs +1 -1
  23. package/dist-lib/capture-contract.mjs +1 -1
  24. package/dist-lib/cloud-contract.cjs +1 -1
  25. package/dist-lib/cloud-contract.mjs +1 -1
  26. package/dist-lib/cloud-test-args.cjs +1 -1
  27. package/dist-lib/cloud-test-args.mjs +1 -1
  28. package/dist-lib/cloud.cjs +1 -1
  29. package/dist-lib/cloud.mjs +1 -1
  30. package/dist-lib/config.cjs +29 -5
  31. package/dist-lib/config.mjs +29 -5
  32. package/dist-lib/detox/index.cjs +19 -5
  33. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  34. package/dist-lib/expo-swift-bundle.cjs +9194 -327
  35. package/dist-lib/expo-swift-metadata.cjs +1 -1
  36. package/dist-lib/expo-swift-metadata.mjs +1 -1
  37. package/dist-lib/home-paths.cjs +1 -1
  38. package/dist-lib/host/bridge-host.cjs +10137 -1043
  39. package/dist-lib/host/fetch-proxy-handler.cjs +260 -182
  40. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  41. package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
  42. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  43. package/dist-lib/host/websocket-proxy.cjs +1 -1
  44. package/dist-lib/index.cjs +653 -338
  45. package/dist-lib/jump-to-source-babel.cjs +1 -1
  46. package/dist-lib/jump-to-source-native.cjs +1 -1
  47. package/dist-lib/kotlin-host.cjs +443 -312
  48. package/dist-lib/menu.cjs +1 -1
  49. package/dist-lib/menu.mjs +1 -1
  50. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  51. package/dist-lib/metro-fingerprint-registry.mjs +1 -1
  52. package/dist-lib/metro-production-bundle.cjs +1 -1
  53. package/dist-lib/metro-production-bundle.mjs +1 -1
  54. package/dist-lib/metro.cjs +548 -163
  55. package/dist-lib/native-app-identity-project.cjs +179 -33
  56. package/dist-lib/native-app-identity-project.mjs +179 -33
  57. package/dist-lib/native-app-identity.cjs +1 -1
  58. package/dist-lib/native-app-identity.mjs +1 -1
  59. package/dist-lib/native-firebase-metadata.cjs +1 -1
  60. package/dist-lib/native-firebase-metadata.mjs +1 -1
  61. package/dist-lib/plist.cjs +1 -1
  62. package/dist-lib/plist.mjs +1 -1
  63. package/dist-lib/profiles.cjs +1 -1
  64. package/dist-lib/public-brand.cjs +1 -1
  65. package/dist-lib/public-origins-lib-esm.json +23 -23
  66. package/dist-lib/public-origins-lib.json +96 -63
  67. package/dist-lib/react-native-host-modules.cjs +1 -1
  68. package/dist-lib/react-native-host-modules.mjs +1 -1
  69. package/dist-lib/scripts/dev-server-scanner.cjs +2 -2
  70. package/dist-lib/sdk.cjs +1 -1
  71. package/dist-lib/sdk.mjs +1 -1
  72. package/dist-lib/skills.cjs +10885 -1596
  73. package/dist-lib/swift-compile.cjs +9036 -331
  74. package/dist-lib/swift-compile.mjs +9036 -331
  75. package/dist-lib/swift-package.cjs +1 -1
  76. package/dist-lib/swift-package.mjs +1 -1
  77. package/dist-lib/swift-submit.cjs +1 -1
  78. package/dist-lib/swift-submit.mjs +1 -1
  79. package/dist-lib/swift-toolchain.cjs +1 -1
  80. package/dist-lib/swift.cjs +1 -1
  81. package/dist-lib/vite-swift.cjs +9194 -327
  82. package/dist-lib/vite.cjs +149 -163
  83. package/dist-lib/worklet-executable.cjs +1 -1
  84. package/dist-lib/worklet-executable.mjs +1 -1
  85. package/dist-types/packages/peach-compat/src/stubs/native-seams/react-native-gesture-handler.d.ts +1 -0
  86. package/dist-types/packages/peach-engine/src/engine/app-font-registry.d.ts +14 -0
  87. package/dist-types/packages/peach-engine/src/engine/image-loader.d.ts +8 -0
  88. package/dist-types/packages/peach-engine/src/engine/node.d.ts +3 -0
  89. package/dist-types/packages/peach-engine/src/render-worker/compositor-protocol.d.ts +21 -0
  90. package/dist-types/packages/peach-engine/src/render-worker/gesture-seam-protocol.d.ts +2 -1
  91. package/dist-types/packages/peach-engine/src/render-worker/test-bridge-protocol.d.ts +1 -1
  92. package/dist-types/packages/peach-engine/src/rolldown-bundle-inventory.d.ts +5 -0
  93. package/dist-types/packages/peach-globals/src/index.d.ts +25 -0
  94. package/kotlin/README.md +38 -23
  95. package/kotlin/sdk.tar.gz +0 -0
  96. package/package.json +2 -12
  97. package/runtime-companion.json +1 -1
  98. package/src/bundleGlobalFooter.ts +0 -2
  99. package/src/config.ts +54 -2
  100. package/src/configured-bundle-producer.ts +7 -1
  101. package/src/host/fetch-proxy-handler.ts +14 -33
  102. package/src/host/rolldown-bundle-forward.ts +71 -0
  103. package/src/installed-package-versions.ts +54 -2
  104. package/src/kotlin-host.ts +138 -285
  105. package/src/kotlin-module.ts +4 -7
  106. package/src/kotlin-sdk.ts +81 -0
  107. package/src/kotlin-toolchain.ts +152 -0
  108. package/src/kotlin-view-models.ts +1 -1
  109. package/src/kotlinSdkContract.ts +113 -0
  110. package/src/nitro-adapter.lock.json +3 -3
  111. package/src/nitro-bundle.ts +18 -4
  112. package/src/nitro-compile.ts +5 -1
  113. package/src/nitro-source.ts +112 -28
  114. package/src/nitroContract.ts +16 -4
  115. package/src/swift-compile.ts +295 -237
  116. package/src/swift-host.ts +2 -1
  117. package/src/swift-objc-compile.ts +117 -4
  118. package/src/swift-objc-sdk.ts +8792 -135
  119. package/src/swift-objc-standin.ts +1 -0
  120. package/src/swiftContract.ts +2 -0
  121. package/src/vite-plugin-one.ts +73 -134
  122. package/src/worker-system-chunks.ts +14 -4
  123. package/src/xcode-project.ts +261 -34
  124. package/kotlin/AndroidViewSources/android/content/Context.kt +0 -22
  125. package/kotlin/AndroidViewSources/android/content/res/Configuration.kt +0 -25
  126. package/kotlin/AndroidViewSources/android/content/res/Resources.kt +0 -72
  127. package/kotlin/AndroidViewSources/android/graphics/Canvas.kt +0 -22
  128. package/kotlin/AndroidViewSources/android/graphics/Color.kt +0 -13
  129. package/kotlin/AndroidViewSources/android/graphics/Paint.kt +0 -18
  130. package/kotlin/AndroidViewSources/android/util/DisplayMetrics.kt +0 -12
  131. package/kotlin/AndroidViewSources/android/view/View.kt +0 -211
  132. package/kotlin/AndroidViewSources/android/widget/FrameLayout.kt +0 -61
  133. package/kotlin/AndroidViewSources/android/widget/LinearLayout.kt +0 -49
  134. package/kotlin/AndroidViewSources/dev/peach/app/JavaFormat.kt +0 -272
  135. package/kotlin/AppSources/android/app/Activity.kt +0 -174
  136. package/kotlin/AppSources/android/app/Application.kt +0 -11
  137. package/kotlin/AppSources/android/app/UiModeManager.kt +0 -9
  138. package/kotlin/AppSources/android/content/Intent.kt +0 -16
  139. package/kotlin/AppSources/android/os/Bundle.kt +0 -11
  140. package/kotlin/AppSources/android/util/SuperNotCalledException.kt +0 -3
  141. package/kotlin/AppSources/android/view/Window.kt +0 -182
  142. package/kotlin/AppSources/android/view/WindowInsets.kt +0 -9
  143. package/kotlin/AppSources/android/view/WindowInsetsController.kt +0 -17
  144. package/kotlin/AppSources/android/view/WindowManager.kt +0 -16
  145. package/kotlin/AppSources/android/window/BackEvent.kt +0 -24
  146. package/kotlin/AppSources/android/window/OnBackAnimationCallback.kt +0 -7
  147. package/kotlin/AppSources/android/window/OnBackInvokedDispatcher.kt +0 -84
  148. package/kotlin/AppSources/androidx/activity/ActivityFlags.kt +0 -9
  149. package/kotlin/AppSources/androidx/activity/ActivityViewModelLazy.kt +0 -21
  150. package/kotlin/AppSources/androidx/activity/BackEventCompat.kt +0 -43
  151. package/kotlin/AppSources/androidx/activity/ComponentActivity.kt +0 -122
  152. package/kotlin/AppSources/androidx/activity/EdgeToEdge.kt +0 -75
  153. package/kotlin/AppSources/androidx/activity/ExperimentalActivityApi.kt +0 -6
  154. package/kotlin/AppSources/androidx/activity/OnBackPressedCallback.kt +0 -69
  155. package/kotlin/AppSources/androidx/activity/OnBackPressedDispatcher.kt +0 -144
  156. package/kotlin/AppSources/androidx/activity/OnBackPressedDispatcherOwner.kt +0 -7
  157. package/kotlin/AppSources/androidx/activity/compose/BackHandler.kt +0 -86
  158. package/kotlin/AppSources/androidx/activity/compose/ComponentActivity.kt +0 -29
  159. package/kotlin/AppSources/androidx/activity/compose/internal/BackHandlerCompat.kt +0 -38
  160. package/kotlin/AppSources/androidx/activity/compose/internal/BackHandlerDispatcherCompat.kt +0 -27
  161. package/kotlin/AppSources/androidx/compose/foundation/layout/WindowInsets.kt +0 -15
  162. package/kotlin/AppSources/androidx/compose/ui/platform/AndroidCompositionLocals.kt +0 -27
  163. package/kotlin/AppSources/androidx/compose/ui/platform/ComposeView.kt +0 -68
  164. package/kotlin/AppSources/androidx/compose/ui/res/ColorResources.kt +0 -16
  165. package/kotlin/AppSources/androidx/compose/ui/res/PainterResources.kt +0 -70
  166. package/kotlin/AppSources/androidx/compose/ui/res/StringResources.kt +0 -38
  167. package/kotlin/AppSources/androidx/core/view/WindowCompat.kt +0 -32
  168. package/kotlin/AppSources/androidx/lifecycle/AndroidViewModel.kt +0 -10
  169. package/kotlin/AppSources/dev/peach/app/PeachApp.kt +0 -388
  170. package/kotlin/AppSources/dev/peach/app/PeachDrawable.kt +0 -102
  171. package/kotlin/AppSources/dev/peach/app/PeachWindowHost.kt +0 -14
  172. package/kotlin/CompilerSources/META-INF/services/org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar +0 -1
  173. package/kotlin/CompilerSources/PeachJniIncoming.kt +0 -243
  174. package/kotlin/CompilerSources/PeachJniPlugin.kt +0 -116
  175. package/kotlin/ComposeSources/PeachComposeHost.kt +0 -724
  176. package/kotlin/ComposeSources/PeachMagnifier.kt +0 -185
  177. package/kotlin/ComposeSources/PeachSemantics.kt +0 -127
  178. package/kotlin/ExpoComposeSources/PeachAndroidView.kt +0 -103
  179. package/kotlin/ExpoComposeSources/PeachExpoViewMount.kt +0 -24
  180. package/kotlin/ExpoComposeSources/dev/peach/expo/PeachExpoCompose.kt +0 -28
  181. package/kotlin/ExpoComposeSources/expo/modules/kotlin/views/ExpoComposeView.kt +0 -70
  182. package/kotlin/ExpoSources/dev/peach/expo/PeachExpoRuntime.kt +0 -516
  183. package/kotlin/ExpoSources/dev/peach/expo/PeachExpoTypes.kt +0 -173
  184. package/kotlin/ExpoSources/expo/modules/kotlin/AppContext.kt +0 -20
  185. package/kotlin/ExpoSources/expo/modules/kotlin/Promise.kt +0 -19
  186. package/kotlin/ExpoSources/expo/modules/kotlin/classcomponent/ClassComponentBuilder.kt +0 -198
  187. package/kotlin/ExpoSources/expo/modules/kotlin/exception/CodedException.kt +0 -126
  188. package/kotlin/ExpoSources/expo/modules/kotlin/functions/Functions.kt +0 -132
  189. package/kotlin/ExpoSources/expo/modules/kotlin/jni/JavaScriptTypedArray.kt +0 -81
  190. package/kotlin/ExpoSources/expo/modules/kotlin/modules/Module.kt +0 -98
  191. package/kotlin/ExpoSources/expo/modules/kotlin/objects/ObjectDefinitionBuilder.kt +0 -236
  192. package/kotlin/ExpoSources/expo/modules/kotlin/records/Record.kt +0 -12
  193. package/kotlin/ExpoSources/expo/modules/kotlin/runtime/Runtime.kt +0 -9
  194. package/kotlin/ExpoSources/expo/modules/kotlin/sharedobjects/SharedObject.kt +0 -50
  195. package/kotlin/ExpoSources/expo/modules/kotlin/sharedobjects/SharedObjectRegistry.kt +0 -57
  196. package/kotlin/ExpoSources/expo/modules/kotlin/sharedobjects/SharedRef.kt +0 -19
  197. package/kotlin/ExpoSources/expo/modules/kotlin/typedarray/ConcreteTypedArrays.kt +0 -158
  198. package/kotlin/ExpoSources/expo/modules/kotlin/typedarray/GenericTypedArray.kt +0 -8
  199. package/kotlin/ExpoSources/expo/modules/kotlin/typedarray/TypedArray.kt +0 -29
  200. package/kotlin/ExpoSources/expo/modules/kotlin/typedarray/TypedArrayIterator.kt +0 -9
  201. package/kotlin/ExpoSources/expo/modules/kotlin/types/AnyType.kt +0 -155
  202. package/kotlin/ExpoSources/expo/modules/kotlin/types/Either.kt +0 -91
  203. package/kotlin/ExpoSources/expo/modules/kotlin/types/Enumerable.kt +0 -6
  204. package/kotlin/ExpoSources/expo/modules/kotlin/viewevent/ViewEvent.kt +0 -68
  205. package/kotlin/ExpoSources/expo/modules/kotlin/views/ExpoView.kt +0 -20
  206. package/kotlin/ExpoSources/expo/modules/kotlin/views/ViewDefinitionBuilder.kt +0 -72
  207. package/kotlin/ExpoSources/expo/modules/kotlin/views/ViewProps.kt +0 -36
  208. package/kotlin/JniPlatformSources/androidx/annotation/CallSuper.kt +0 -5
  209. package/kotlin/JniPlatformSources/com/facebook/proguard/annotations/DoNotStrip.kt +0 -5
  210. package/kotlin/JniPlatformSources/dalvik/annotation/optimization/FastNative.kt +0 -5
  211. package/kotlin/JniPlatformSources/kotlin/Synchronized.kt +0 -6
  212. package/kotlin/JniPlatformSources/kotlin/jvm/JvmField.kt +0 -5
  213. package/kotlin/JniPlatformSources/kotlin/jvm/JvmStatic.kt +0 -5
  214. package/kotlin/JniSources/com/facebook/jni/HybridData.kt +0 -66
  215. package/kotlin/JniSources/dev/peach/jni/IncomingBindings.kt +0 -157
  216. package/kotlin/JniSources/dev/peach/jni/NativeBindings.kt +0 -77
  217. package/kotlin/JniTransportSources/dev/peach/jni/integration/JniTransport.kt +0 -89
  218. package/kotlin/Sources/android/os/Build.kt +0 -17
  219. package/kotlin/Sources/android/os/Handler.kt +0 -35
  220. package/kotlin/Sources/android/os/Looper.kt +0 -17
  221. package/kotlin/Sources/android/os/MessageQueue.kt +0 -56
  222. package/kotlin/Sources/android/os/SystemClock.kt +0 -14
  223. package/kotlin/Sources/android/util/Log.kt +0 -64
  224. package/kotlin/Sources/androidx/annotation/DrawableRes.kt +0 -14
  225. package/kotlin/Sources/androidx/annotation/Keep.kt +0 -4
  226. package/kotlin/Sources/dev/onejs/one/OneNativeSourceDispatch.kt +0 -7
  227. package/kotlin/Sources/dev/onejs/one/OneNativeSourceViewDispatch.kt +0 -13
  228. package/kotlin/Sources/dev/onejs/one/source/OneModule.kt +0 -4
  229. package/kotlin/Sources/java/lang/Runnable.kt +0 -6
  230. package/kotlin/Sources/java/security/MessageDigest.kt +0 -114
  231. package/kotlin/Sources/java/util/IllegalFormatCodePointException.kt +0 -10
  232. package/kotlin/Sources/java/util/IllegalFormatException.kt +0 -5
  233. package/kotlin/Sources/kotlin/text/StringFormat.kt +0 -9
  234. package/kotlin/Sources/org/json/JSON.kt +0 -307
  235. package/kotlin/tools/abi-classes.main.kts +0 -41
  236. package/kotlin/tools/expo-types.main.kts +0 -127
@@ -65,6 +65,7 @@ export function nativeInterfaceView(
65
65
  if (process.platform !== 'darwin')
66
66
  throw new Error('mixed framework declarations require the pinned native iOS SDK')
67
67
  const xcrun = (args: string[]) =>
68
+ // runner-toolchain-platform: darwin
68
69
  execFileSync('xcrun', args, {
69
70
  encoding: 'utf8',
70
71
  stdio: ['ignore', 'pipe', 'pipe'],
@@ -49,6 +49,8 @@ export interface SwiftObjCImplementationPlan {
49
49
 
50
50
  export interface SwiftProjectPreparation {
51
51
  headerProducers: string[]
52
+ /** targets that could not be prepared; the rest still build. */
53
+ targetFailures: string[]
52
54
  objcImplementations?: SwiftObjCImplementationPlan
53
55
  }
54
56
 
@@ -8,11 +8,13 @@
8
8
 
9
9
  import fs from 'fs'
10
10
  import { randomUUID } from 'node:crypto'
11
+ import http from 'node:http'
12
+ import https from 'node:https'
11
13
  import { fileURLToPath } from 'node:url'
12
14
  import path from 'path'
15
+ import { pipeline } from 'stream/promises'
13
16
  import { WebSocket, WebSocketServer } from 'ws'
14
17
  import { DEFAULT_SOOTSIM_BRIDGE_PORT } from './bridge-constants'
15
- import { ROLLDOWN_INVENTORY_HEADER } from './bundleGlobalFooter'
16
18
  import { getCliRuntime } from './cli-runtime'
17
19
  import {
18
20
  launchRnxDesktop,
@@ -22,6 +24,7 @@ import {
22
24
  } from './dev-server-open'
23
25
  import { isDaemonLockfileFresh, readDaemonLockfile } from './home-paths'
24
26
  import { handleReplacementModuleRequest } from './host/replacement-module-handler'
27
+ import { forwardRolldownBundleResponse } from './host/rolldown-bundle-forward'
25
28
  import { readInstalledNativePackageVersions } from './installed-package-versions'
26
29
  import { configuredOneWidget } from './one-widget-metadata'
27
30
  import {
@@ -49,6 +52,10 @@ function exposeHeader(res: ServerResponse, name: string) {
49
52
  res.setHeader('access-control-expose-headers', [...names, name].join(', '))
50
53
  }
51
54
 
55
+ // marks the plugin's own request for the bundle One builds, so the .bundle
56
+ // route forwards One's response instead of answering itself again.
57
+ const BUNDLE_SOURCE_REQUEST_HEADER = 'x-peach-bundle-source'
58
+
52
59
  // every swift route sits under this prefix. the swift host (compiler client,
53
60
  // resource packer, module glue) loads on the first request for one, so an app
54
61
  // that imports no swift never evaluates it.
@@ -101,7 +108,14 @@ export function peachPlugin(options: PeachPluginOptions = {}): Plugin {
101
108
 
102
109
  async configureServer(server) {
103
110
  if (options.enabled === false) return
104
- // place at the front of server.middlewares.stack so this wrapper runs
111
+ // a native bundle carries the install it was built from, as hosted
112
+ // bundles do: any shell that launches it, including one that found this
113
+ // server by scanning, learns the installed native package versions. a
114
+ // page that fetches the bundle from this server directly (the shell at
115
+ // the plugin prefix, or a hosted page reaching this loopback server)
116
+ // gets the rolldown inventory the bundle proxy attaches for everyone
117
+ // else: the request is answered again by One's own handler and forwarded
118
+ // through the same producer. placed at the front of the stack so it runs
105
119
  // ahead of One's .bundle handler even when one() precedes peachPlugin().
106
120
  server.middlewares.use((req, res, next) => {
107
121
  if (!(req.url ?? '').split('?')[0].endsWith('.bundle')) {
@@ -113,144 +127,66 @@ export function peachPlugin(options: PeachPluginOptions = {}): Plugin {
113
127
  JSON.stringify(readInstalledNativePackageVersions(server.config.root)),
114
128
  )
115
129
  exposeHeader(res, PACKAGE_VERSIONS_HEADER)
116
- res.setHeader(ROLLDOWN_INVENTORY_HEADER, '1')
117
- exposeHeader(res, ROLLDOWN_INVENTORY_HEADER)
118
- const origWriteHead = res.writeHead.bind(res)
119
- const origWrite = res.write.bind(res)
120
- const origEnd = res.end.bind(res)
121
- let pendingStatus: number | undefined
122
- let pendingMessage: string | undefined
123
- const flushHead = () => {
124
- if (pendingStatus !== undefined && !res.headersSent) {
125
- const code = pendingStatus
126
- const msg = pendingMessage
127
- pendingStatus = undefined
128
- pendingMessage = undefined
129
- if (typeof msg === 'string') origWriteHead(code, msg)
130
- else origWriteHead(code)
131
- }
130
+ if (req.method !== 'GET' || req.headers[BUNDLE_SOURCE_REQUEST_HEADER]) {
131
+ next()
132
+ return
132
133
  }
133
- Reflect.set(
134
- res,
135
- 'writeHead',
136
- function (statusCode: number, statusMessage?: unknown, headers?: unknown) {
137
- pendingStatus = statusCode
138
- res.statusCode = statusCode
139
- if (typeof statusMessage === 'string') pendingMessage = statusMessage
140
- const hdrs =
141
- typeof statusMessage === 'object' && statusMessage !== null
142
- ? statusMessage
143
- : headers
144
- if (hdrs && typeof hdrs === 'object' && !Array.isArray(hdrs)) {
145
- for (const [key, value] of Object.entries(hdrs)) {
146
- if (key.toLowerCase() === 'content-length') continue
147
- if (
148
- typeof value === 'string' ||
149
- typeof value === 'number' ||
150
- Array.isArray(value)
151
- ) {
152
- res.setHeader(key, value)
153
- }
154
- }
155
- }
156
- res.removeHeader('content-length')
157
- if (statusCode !== 200) res.removeHeader(ROLLDOWN_INVENTORY_HEADER)
158
- return res
134
+ const address = server.httpServer?.address()
135
+ if (!address || typeof address !== 'object') {
136
+ next()
137
+ return
138
+ }
139
+ const loopback =
140
+ address.address === '::' || address.address === '0.0.0.0'
141
+ ? '127.0.0.1'
142
+ : address.address
143
+ const authority = req.headers[':authority']
144
+ const options: https.RequestOptions = {
145
+ host: loopback,
146
+ port: address.port,
147
+ path: req.url,
148
+ method: 'GET',
149
+ headers: {
150
+ ...Object.fromEntries(
151
+ Object.entries(req.headers).filter(([key]) => !key.startsWith(':')),
152
+ ),
153
+ host:
154
+ req.headers.host ?? (typeof authority === 'string' ? authority : undefined),
155
+ 'accept-encoding': 'identity',
156
+ [BUNDLE_SOURCE_REQUEST_HEADER]: '1',
159
157
  },
160
- )
161
- const chunks: Buffer[] = []
162
- let buffering = false
163
- const isBufferEncoding = (value: unknown): value is BufferEncoding =>
164
- typeof value === 'string' && Buffer.isEncoding(value)
165
- const toBuffer = (chunk: unknown, encoding?: unknown): Buffer | null => {
166
- if (chunk === undefined || chunk === null || typeof chunk === 'function')
167
- return null
168
- if (Buffer.isBuffer(chunk)) return chunk
169
- if (chunk instanceof Uint8Array) return Buffer.from(chunk)
170
- if (typeof chunk === 'string')
171
- return Buffer.from(chunk, isBufferEncoding(encoding) ? encoding : 'utf8')
172
- return null
158
+ rejectUnauthorized: false,
173
159
  }
174
- Reflect.set(res, 'write', function (chunk: unknown, arg1?: unknown) {
175
- const buf = toBuffer(chunk, arg1)
176
- if (!buf) {
177
- flushHead()
178
- return origWrite('')
179
- }
180
- if (!buffering) {
181
- const lower = buf.toString('utf8').toLowerCase()
182
- const contentType = String(res.getHeader('content-type') ?? '').toLowerCase()
160
+ const respond = (upstream: http.IncomingMessage) => {
161
+ res.statusCode = upstream.statusCode ?? 502
162
+ for (const [key, value] of Object.entries(upstream.headers)) {
163
+ const lowerKey = key.toLowerCase()
183
164
  if (
184
- !contentType.includes('multipart/mixed') ||
185
- lower.includes('content-type: text/javascript') ||
186
- lower.includes('content-type: application/javascript')
165
+ value === undefined ||
166
+ lowerKey === 'connection' ||
167
+ lowerKey === 'keep-alive' ||
168
+ lowerKey === 'transfer-encoding'
187
169
  ) {
188
- buffering = true
170
+ continue
189
171
  }
172
+ res.setHeader(key, value)
190
173
  }
191
- if (buffering) {
192
- chunks.push(buf)
193
- return true
194
- }
195
- flushHead()
196
- return origWrite(buf)
174
+ const forward =
175
+ res.statusCode === 200
176
+ ? forwardRolldownBundleResponse(upstream, res)
177
+ : pipeline(upstream, res)
178
+ forward.catch((error: unknown) =>
179
+ res.destroy(error instanceof Error ? error : new Error(String(error))),
180
+ )
181
+ }
182
+ const upstreamReq = server.config.server.https
183
+ ? https.request(options, respond)
184
+ : http.request(options, respond)
185
+ upstreamReq.once('error', next)
186
+ req.once('close', () => {
187
+ if (!res.writableFinished) upstreamReq.destroy()
197
188
  })
198
- Reflect.set(
199
- res,
200
- 'end',
201
- function (chunk?: unknown, arg1?: unknown, arg2?: unknown) {
202
- const callback =
203
- typeof chunk === 'function'
204
- ? chunk
205
- : typeof arg1 === 'function'
206
- ? arg1
207
- : typeof arg2 === 'function'
208
- ? arg2
209
- : undefined
210
- const finish = () => {
211
- flushHead()
212
- if (typeof callback === 'function') {
213
- return origEnd(() => {
214
- Reflect.apply(callback, res, [])
215
- })
216
- }
217
- return origEnd()
218
- }
219
- const buf = toBuffer(chunk, arg1)
220
- if (buf) chunks.push(buf)
221
- if (chunks.length === 0 || (res.statusCode && res.statusCode !== 200)) {
222
- if (!res.headersSent) res.removeHeader(ROLLDOWN_INVENTORY_HEADER)
223
- flushHead()
224
- for (const queued of chunks) origWrite(queued)
225
- return finish()
226
- }
227
- const payload = Buffer.concat(chunks).toString('utf8')
228
- const contentType = String(res.getHeader('content-type') ?? '')
229
- void getCliRuntime()
230
- .rolldown_bundle_inventory.attachRolldownBundleHttpPayload(
231
- payload,
232
- contentType,
233
- )
234
- .then((annotated) => {
235
- if (!res.headersSent) res.removeHeader('content-length')
236
- flushHead()
237
- origWrite(Buffer.from(annotated, 'utf8'))
238
- finish()
239
- })
240
- .catch((error: unknown) => {
241
- console.error('[peach] failed to attach rolldown bundle inventory', error)
242
- if (!res.headersSent) {
243
- res.removeHeader('content-length')
244
- res.removeHeader(ROLLDOWN_INVENTORY_HEADER)
245
- }
246
- flushHead()
247
- origWrite(Buffer.from(payload, 'utf8'))
248
- finish()
249
- })
250
- return res
251
- },
252
- )
253
- next()
189
+ upstreamReq.end()
254
190
  })
255
191
  const bundleLayer = server.middlewares.stack.pop()
256
192
  if (bundleLayer) server.middlewares.stack.unshift(bundleLayer)
@@ -370,8 +306,11 @@ export function peachPlugin(options: PeachPluginOptions = {}): Plugin {
370
306
  loadKotlinHost()
371
307
  .then(async (host) => {
372
308
  if (!kotlinModuleRoot) {
373
- kotlinModuleRoot = host.peachKotlinModuleRoot()
374
- server.watcher.add(path.join(kotlinModuleRoot, 'Sources'))
309
+ const root = host.peachKotlinModuleRoot()
310
+ kotlinModuleRoot = root
311
+ server.watcher.add(
312
+ ['sdk.tar.gz', 'toolchain.json'].map((file) => path.join(root, file)),
313
+ )
375
314
  }
376
315
  const served = await host.serveKotlinRequest(pathname, res, {
377
316
  root: server.config.root,
@@ -8,12 +8,12 @@ const require = createRequire(import.meta.url)
8
8
  const systemRuntime = fs.readFileSync(require.resolve('systemjs/dist/s.min.js'), 'utf8')
9
9
  const minifierModule = require.resolve('rolldown/utils')
10
10
  const rollupModule = require.resolve('rollup')
11
- type MinifiedWorkerChunk = { code: string; map: string }
11
+ type MinifiedWorkerChunk = { code: string; map: string; loweredCode?: string }
12
12
  const minifierWorker = `
13
13
  const { parentPort, workerData } = require('node:worker_threads');
14
14
  const minifier = import(workerData.module);
15
15
  const lowering = import(workerData.rollup);
16
- parentPort.on('message', async ({ code, isEntry, keepNames, measurement, inputMap, entryImports }) => {
16
+ parentPort.on('message', async ({ code, isEntry, keepNames, measurement, inputMap, entryImports, captureStages }) => {
17
17
  try {
18
18
  const { rollup } = await lowering;
19
19
  const entry = 'peach-worker-chunk.js';
@@ -55,7 +55,7 @@ parentPort.on('message', async ({ code, isEntry, keepNames, measurement, inputMa
55
55
  inputMap: JSON.parse(loweredMap),
56
56
  });
57
57
  if (result.errors.length) throw new Error(result.errors.map(error => error.message).join('; '));
58
- parentPort.postMessage({ code: result.code, map: result.map && JSON.stringify(result.map) });
58
+ parentPort.postMessage({ code: result.code, map: result.map && JSON.stringify(result.map), ...(captureStages ? { loweredCode } : {}) });
59
59
  } catch (error) {
60
60
  parentPort.postMessage({ error: error instanceof Error ? error.message : String(error) });
61
61
  }
@@ -67,6 +67,7 @@ type MinifierJob = {
67
67
  keepNames: boolean
68
68
  inputMap: string | undefined
69
69
  entryImports: readonly string[]
70
+ captureStages: boolean
70
71
  resolve: (result: MinifiedWorkerChunk) => void
71
72
  reject: (error: Error) => void
72
73
  }
@@ -119,7 +120,13 @@ function runMinifiers() {
119
120
  message.code &&
120
121
  typeof message.map === 'string'
121
122
  ) {
122
- result = { code: message.code, map: message.map }
123
+ result = {
124
+ code: message.code,
125
+ map: message.map,
126
+ ...(job?.captureStages && typeof message.loweredCode === 'string'
127
+ ? { loweredCode: message.loweredCode }
128
+ : {}),
129
+ }
123
130
  } else {
124
131
  created.failure = new Error(
125
132
  'worker minification produced no code or source map',
@@ -167,6 +174,7 @@ function runMinifiers() {
167
174
  keepNames: job.keepNames,
168
175
  inputMap: job.inputMap,
169
176
  entryImports: job.entryImports,
177
+ captureStages: job.captureStages,
170
178
  measurement: process.env.PEACH_ENGINE_PROFILE === '1',
171
179
  })
172
180
  } catch (error) {
@@ -294,6 +302,7 @@ export function renderWorkerSystemChunk(
294
302
  keepNames = false,
295
303
  inputMap?: string,
296
304
  entryImports: readonly string[] = [],
305
+ captureStages = false,
297
306
  ) {
298
307
  return new Promise<MinifiedWorkerChunk>((resolve, reject) => {
299
308
  pendingMinifiers.push({
@@ -302,6 +311,7 @@ export function renderWorkerSystemChunk(
302
311
  keepNames,
303
312
  inputMap,
304
313
  entryImports,
314
+ captureStages,
305
315
  resolve,
306
316
  reject,
307
317
  })