vxrn 2.0.0-beta.99.1 → 2.6.1

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 (210) hide show
  1. package/dist/backgroundComputation.mjs +145 -0
  2. package/dist/backgroundComputation.mjs.map +1 -0
  3. package/dist/backgroundComputation.native.js +163 -0
  4. package/dist/backgroundComputation.native.js.map +1 -0
  5. package/dist/backgroundComputationNative.mjs +16 -0
  6. package/dist/backgroundComputationNative.mjs.map +1 -0
  7. package/dist/backgroundComputationNative.native.js +18 -0
  8. package/dist/backgroundComputationNative.native.js.map +1 -0
  9. package/dist/config/getBaseViteConfigOnly.mjs +6 -10
  10. package/dist/config/getBaseViteConfigOnly.mjs.map +1 -1
  11. package/dist/config/getBaseViteConfigOnly.native.js +6 -10
  12. package/dist/config/getBaseViteConfigOnly.native.js.map +1 -1
  13. package/dist/config/getOptimizeDeps.mjs +2 -1
  14. package/dist/config/getOptimizeDeps.mjs.map +1 -1
  15. package/dist/config/getOptimizeDeps.native.js +2 -1
  16. package/dist/config/getOptimizeDeps.native.js.map +1 -1
  17. package/dist/config/getViteServerConfig.mjs +13 -0
  18. package/dist/config/getViteServerConfig.mjs.map +1 -1
  19. package/dist/config/getViteServerConfig.native.js +15 -1
  20. package/dist/config/getViteServerConfig.native.js.map +1 -1
  21. package/dist/constants/defaults.mjs +4 -0
  22. package/dist/constants/defaults.mjs.map +1 -1
  23. package/dist/constants/defaults.native.js +4 -0
  24. package/dist/constants/defaults.native.js.map +1 -1
  25. package/dist/exports/build.native.js +1 -1
  26. package/dist/exports/build.native.js.map +1 -1
  27. package/dist/exports/clean.native.js +1 -1
  28. package/dist/exports/clean.native.js.map +1 -1
  29. package/dist/exports/createServer.native.js +2 -2
  30. package/dist/exports/createServer.native.js.map +1 -1
  31. package/dist/exports/dev.mjs +3 -0
  32. package/dist/exports/dev.mjs.map +1 -1
  33. package/dist/exports/dev.native.js +6 -3
  34. package/dist/exports/dev.native.js.map +1 -1
  35. package/dist/exports/loadEnv.native.js +1 -1
  36. package/dist/exports/loadEnv.native.js.map +1 -1
  37. package/dist/exports/patch.native.js +1 -1
  38. package/dist/exports/patch.native.js.map +1 -1
  39. package/dist/exports/prebuild.mjs +0 -22
  40. package/dist/exports/prebuild.mjs.map +1 -1
  41. package/dist/exports/prebuild.native.js +1 -23
  42. package/dist/exports/prebuild.native.js.map +1 -1
  43. package/dist/exports/prebuildWithoutExpo.mjs +1116 -178
  44. package/dist/exports/prebuildWithoutExpo.mjs.map +1 -1
  45. package/dist/exports/prebuildWithoutExpo.native.js +1592 -243
  46. package/dist/exports/prebuildWithoutExpo.native.js.map +1 -1
  47. package/dist/exports/runAndroid.native.js +1 -1
  48. package/dist/exports/runAndroid.native.js.map +1 -1
  49. package/dist/exports/runIos.native.js +1 -1
  50. package/dist/exports/runIos.native.js.map +1 -1
  51. package/dist/exports/serve.native.js +1 -1
  52. package/dist/exports/serve.native.js.map +1 -1
  53. package/dist/exports/serveStaticAssets.native.js +1 -1
  54. package/dist/exports/serveStaticAssets.native.js.map +1 -1
  55. package/dist/index.js +4 -1
  56. package/dist/index.mjs +4 -1
  57. package/dist/index.native.js +4 -1
  58. package/dist/native-source-contract.mjs +3 -0
  59. package/dist/native-source-contract.native.js +3 -0
  60. package/dist/patches/builtInDepPatches.mjs +0 -13
  61. package/dist/patches/builtInDepPatches.mjs.map +1 -1
  62. package/dist/patches/builtInDepPatches.native.js +0 -13
  63. package/dist/patches/builtInDepPatches.native.js.map +1 -1
  64. package/dist/plugins/autoDepOptimizePlugin.mjs +3 -2
  65. package/dist/plugins/autoDepOptimizePlugin.mjs.map +1 -1
  66. package/dist/plugins/autoDepOptimizePlugin.native.js +6 -3
  67. package/dist/plugins/autoDepOptimizePlugin.native.js.map +1 -1
  68. package/dist/plugins/backgroundComputationPlugin.mjs +27 -0
  69. package/dist/plugins/backgroundComputationPlugin.mjs.map +1 -0
  70. package/dist/plugins/backgroundComputationPlugin.native.js +32 -0
  71. package/dist/plugins/backgroundComputationPlugin.native.js.map +1 -0
  72. package/dist/plugins/reactNativeCommonJsPlugin.native.js +3 -3
  73. package/dist/plugins/reactNativeCommonJsPlugin.native.js.map +1 -1
  74. package/dist/plugins/reactNativeDevAssetPlugin.mjs +2 -1
  75. package/dist/plugins/reactNativeDevAssetPlugin.mjs.map +1 -1
  76. package/dist/plugins/reactNativeDevAssetPlugin.native.js +3 -2
  77. package/dist/plugins/reactNativeDevAssetPlugin.native.js.map +1 -1
  78. package/dist/plugins/reactNativeDevServer.mjs +87 -24
  79. package/dist/plugins/reactNativeDevServer.mjs.map +1 -1
  80. package/dist/plugins/reactNativeDevServer.native.js +162 -45
  81. package/dist/plugins/reactNativeDevServer.native.js.map +1 -1
  82. package/dist/plugins/workletImportsPlugin.mjs +9 -30
  83. package/dist/plugins/workletImportsPlugin.mjs.map +1 -1
  84. package/dist/plugins/workletImportsPlugin.native.js +10 -35
  85. package/dist/plugins/workletImportsPlugin.native.js.map +1 -1
  86. package/dist/rn-commands/bundle/buildBundle.mjs +3 -3
  87. package/dist/rn-commands/bundle/buildBundle.mjs.map +1 -1
  88. package/dist/rn-commands/bundle/buildBundle.native.js +3 -3
  89. package/dist/rn-commands/bundle/buildBundle.native.js.map +1 -1
  90. package/dist/runtime/hmr-client.native.js +3 -7
  91. package/dist/runtime/hmr-client.native.js.map +1 -1
  92. package/dist/runtime/hmr-runtime.native.js +32 -40
  93. package/dist/runtime/hmr-runtime.native.js.map +1 -1
  94. package/dist/serve/node.native.js +2 -2
  95. package/dist/serve/node.native.js.map +1 -1
  96. package/dist/swift-package-id.mjs +3 -0
  97. package/dist/swift-package-id.native.js +3 -0
  98. package/dist/user-interface/index.native.js +6 -6
  99. package/dist/user-interface/index.native.js.map +1 -1
  100. package/dist/utils/compileNativeDevBytecode.mjs +93 -0
  101. package/dist/utils/compileNativeDevBytecode.mjs.map +1 -0
  102. package/dist/utils/compileNativeDevBytecode.native.js +98 -0
  103. package/dist/utils/compileNativeDevBytecode.native.js.map +1 -0
  104. package/dist/utils/createNativeDevEngine.mjs +227 -20
  105. package/dist/utils/createNativeDevEngine.mjs.map +1 -1
  106. package/dist/utils/createNativeDevEngine.native.js +249 -37
  107. package/dist/utils/createNativeDevEngine.native.js.map +1 -1
  108. package/dist/utils/execSync.native.js +1 -1
  109. package/dist/utils/execSync.native.js.map +1 -1
  110. package/dist/utils/getServerEntry.native.js +2 -2
  111. package/dist/utils/getServerEntry.native.js.map +1 -1
  112. package/dist/utils/nativeRun.mjs +32 -16
  113. package/dist/utils/nativeRun.mjs.map +1 -1
  114. package/dist/utils/nativeRun.native.js +43 -18
  115. package/dist/utils/nativeRun.native.js.map +1 -1
  116. package/dist/utils/nativeSourceContract.mjs +1823 -0
  117. package/dist/utils/nativeSourceContract.mjs.map +1 -0
  118. package/dist/utils/nativeSourceContract.native.js +2425 -0
  119. package/dist/utils/nativeSourceContract.native.js.map +1 -0
  120. package/dist/utils/patches.native.js +15 -24
  121. package/dist/utils/patches.native.js.map +1 -1
  122. package/dist/utils/printServerUrls.native.js +1 -1
  123. package/dist/utils/printServerUrls.native.js.map +1 -1
  124. package/dist/utils/scanDepsToOptimize.mjs +7 -1
  125. package/dist/utils/scanDepsToOptimize.mjs.map +1 -1
  126. package/dist/utils/scanDepsToOptimize.native.js +27 -2
  127. package/dist/utils/scanDepsToOptimize.native.js.map +1 -1
  128. package/dist/utils/swiftPackageId.mjs +31 -2
  129. package/dist/utils/swiftPackageId.mjs.map +1 -1
  130. package/dist/utils/swiftPackageId.native.js +50 -2
  131. package/dist/utils/swiftPackageId.native.js.map +1 -1
  132. package/dist/vxrn-vite-plugin.native.js +1 -1
  133. package/dist/vxrn-vite-plugin.native.js.map +1 -1
  134. package/expo-plugin.cjs +792 -2
  135. package/native-project-patches.cjs +201 -10
  136. package/package.json +34 -15
  137. package/src/backgroundComputation.ts +220 -0
  138. package/src/backgroundComputationNative.ts +23 -0
  139. package/src/config/getBaseViteConfigOnly.ts +8 -9
  140. package/src/config/getOptimizeDeps.ts +3 -1
  141. package/src/config/getViteServerConfig.ts +16 -0
  142. package/src/config/glbAssets.test.ts +228 -0
  143. package/src/constants/defaults.ts +6 -0
  144. package/src/exports/dev.ts +5 -1
  145. package/src/exports/expoPlugin.test.mjs +337 -15
  146. package/src/exports/prebuild.ts +0 -31
  147. package/src/exports/prebuildWithoutExpo.test.ts +1588 -48
  148. package/src/exports/prebuildWithoutExpo.ts +1573 -213
  149. package/src/index.ts +8 -0
  150. package/src/native-source-contract.ts +16 -0
  151. package/src/patches/builtInDepPatches.ts +0 -21
  152. package/src/plugins/autoDepOptimizePlugin.ts +7 -2
  153. package/src/plugins/backgroundComputationPlugin.test.ts +77 -0
  154. package/src/plugins/backgroundComputationPlugin.ts +29 -0
  155. package/src/plugins/reactNativeDevAssetPlugin.ts +5 -1
  156. package/src/plugins/reactNativeDevServer.test.ts +74 -0
  157. package/src/plugins/reactNativeDevServer.ts +145 -28
  158. package/src/plugins/rnCodegenPlugin.test.ts +30 -0
  159. package/src/plugins/workletImportsPlugin.ts +19 -37
  160. package/src/rn-commands/bundle/buildBundle.ts +5 -3
  161. package/src/swift-package-id.ts +1 -0
  162. package/src/utils/compileNativeDevBytecode.test.ts +168 -0
  163. package/src/utils/compileNativeDevBytecode.ts +117 -0
  164. package/src/utils/createNativeDevEngine.test.ts +643 -18
  165. package/src/utils/createNativeDevEngine.ts +278 -48
  166. package/src/utils/nativeRun.test.ts +125 -23
  167. package/src/utils/nativeRun.ts +51 -23
  168. package/src/utils/nativeSourceArtifacts.test.ts +39 -0
  169. package/src/utils/nativeSourceContract.test.ts +600 -0
  170. package/src/utils/nativeSourceContract.ts +1897 -0
  171. package/src/utils/scanDepsToOptimize.test.ts +80 -0
  172. package/src/utils/scanDepsToOptimize.ts +18 -7
  173. package/src/utils/swiftPackageId.ts +25 -1
  174. package/types/backgroundComputation.d.ts +28 -0
  175. package/types/backgroundComputation.d.ts.map +1 -0
  176. package/types/backgroundComputationNative.d.ts +2 -0
  177. package/types/backgroundComputationNative.d.ts.map +1 -0
  178. package/types/config/getBaseViteConfigOnly.d.ts.map +1 -1
  179. package/types/config/getOptimizeDeps.d.ts.map +1 -1
  180. package/types/config/getViteServerConfig.d.ts.map +1 -1
  181. package/types/constants/defaults.d.ts.map +1 -1
  182. package/types/exports/dev.d.ts.map +1 -1
  183. package/types/exports/prebuild.d.ts.map +1 -1
  184. package/types/exports/prebuildWithoutExpo.d.ts +6 -0
  185. package/types/exports/prebuildWithoutExpo.d.ts.map +1 -1
  186. package/types/index.d.ts +2 -0
  187. package/types/index.d.ts.map +1 -1
  188. package/types/native-source-contract.d.ts +2 -0
  189. package/types/native-source-contract.d.ts.map +1 -0
  190. package/types/patches/builtInDepPatches.d.ts.map +1 -1
  191. package/types/plugins/autoDepOptimizePlugin.d.ts.map +1 -1
  192. package/types/plugins/backgroundComputationPlugin.d.ts +3 -0
  193. package/types/plugins/backgroundComputationPlugin.d.ts.map +1 -0
  194. package/types/plugins/reactNativeDevAssetPlugin.d.ts.map +1 -1
  195. package/types/plugins/reactNativeDevServer.d.ts.map +1 -1
  196. package/types/plugins/workletImportsPlugin.d.ts.map +1 -1
  197. package/types/rn-commands/bundle/buildBundle.d.ts.map +1 -1
  198. package/types/swift-package-id.d.ts +2 -0
  199. package/types/swift-package-id.d.ts.map +1 -0
  200. package/types/utils/compileNativeDevBytecode.d.ts +3 -0
  201. package/types/utils/compileNativeDevBytecode.d.ts.map +1 -0
  202. package/types/utils/createNativeDevEngine.d.ts +7 -22
  203. package/types/utils/createNativeDevEngine.d.ts.map +1 -1
  204. package/types/utils/nativeRun.d.ts.map +1 -1
  205. package/types/utils/nativeSourceContract.d.ts +121 -0
  206. package/types/utils/nativeSourceContract.d.ts.map +1 -0
  207. package/types/utils/scanDepsToOptimize.d.ts +1 -0
  208. package/types/utils/scanDepsToOptimize.d.ts.map +1 -1
  209. package/types/utils/swiftPackageId.d.ts +1 -0
  210. package/types/utils/swiftPackageId.d.ts.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"reactNativeDevServer.native.js","names":[],"sources":["plugins/reactNativeDevServer.native.js"],"sourcesContent":["import { WebSocketServer } from \"ws\";\nimport { createMessageSocket } from \"@vxrn/utils\";\nimport { addConnectedNativeClient, removeConnectedNativeClient } from \"../utils/connectedNativeClients\";\nimport { URL } from \"url\";\nimport { createRequire } from \"module\";\nimport { join } from \"path\";\nimport { randomUUID } from \"crypto\";\nimport { readFile } from \"fs/promises\";\nimport { createDevMiddleware } from \"@react-native/dev-middleware\";\nimport { createNativeDevEngine } from \"../utils/createNativeDevEngine\";\nimport { getBoundPort } from \"../utils/getBoundPort\";\nimport { getNativeFramePlatform, isNativeBundleFrame, symbolicateNativeStack } from \"../utils/symbolicateNativeStack\";\nfunction _type_of(obj) {\n \"@swc/helpers - typeof\";\n return obj && typeof Symbol !== \"undefined\" && obj.constructor === Symbol ? \"symbol\" : typeof obj;\n}\nfunction getNativeAssetContentType(type) {\n switch (type.toLowerCase()) {\n case \"bmp\":\n return \"image/bmp\";\n case \"gif\":\n return \"image/gif\";\n case \"jpeg\":\n case \"jpg\":\n return \"image/jpeg\";\n case \"json\":\n return \"application/json\";\n case \"otf\":\n return \"font/otf\";\n case \"png\":\n return \"image/png\";\n case \"svg\":\n return \"image/svg+xml\";\n case \"ttf\":\n return \"font/ttf\";\n case \"webp\":\n return \"image/webp\";\n case \"woff\":\n return \"font/woff\";\n case \"woff2\":\n return \"font/woff2\";\n default:\n return \"application/octet-stream\";\n }\n}\nfunction createReactNativeDevServerPlugin(options) {\n return {\n name: \"vite-plugin-react-native-server\",\n configureServer(server) {\n var _server_httpServer;\n var { host } = server.config.server;\n var { root } = server.config;\n var hmrWSS = new WebSocketServer({\n noServer: true\n });\n var clientWSS = new WebSocketServer({\n noServer: true\n });\n var messageWSS = createMessageSocket();\n var validPlatforms = {\n ios: \"ios\",\n android: \"android\"\n };\n var devEngines = {};\n var devEngineCreating = {};\n var warnedProdBundleRequest = /* @__PURE__ */ new Set();\n var pendingReloadPlatforms = /* @__PURE__ */ new Set();\n var devToolsSocketEndpoints = [\n \"/inspector/device\",\n \"/inspector/debug\"\n ];\n var reactNativeDevToolsUrl = `http://${host}:${getBoundPort(server)}`;\n var { middleware, websocketEndpoints } = createDevMiddleware({\n serverBaseUrl: reactNativeDevToolsUrl,\n logger: console,\n unstable_experiments: {\n enableStandaloneFuseboxShell: false\n }\n });\n var projectRequire = createRequire(join(root, \"package.json\"));\n var anonymousScopeId = randomUUID();\n server.middlewares.use(async function(req, res, next) {\n if (req.method !== \"GET\" && req.method !== \"HEAD\") return next();\n var url = new URL(req.url || \"/\", `http://${req.headers.host || \"localhost\"}`);\n if (url.pathname !== \"/\" && url.pathname !== \"/manifest\" && url.pathname !== \"/index.exp\") {\n return next();\n }\n var header = req.headers[\"expo-platform\"] || req.headers[\"exponent-platform\"];\n var platform = validPlatforms[url.searchParams.get(\"platform\") || String(header || \"\")];\n if (!platform) return next();\n var expoConfigPath;\n try {\n expoConfigPath = projectRequire.resolve(\"@expo/config\");\n } catch (unused) {\n return next();\n }\n var expoRequire = createRequire(expoConfigPath);\n var { getConfig } = expoRequire(\"@expo/config\");\n var { resolveRelativeEntryPoint } = expoRequire(\"@expo/config/paths\");\n var { Updates } = expoRequire(\"@expo/config-plugins\");\n try {\n var _exp_runtimeVersion, _ref;\n var _exp_extra_eas, _exp_extra;\n var { exp, pkg } = getConfig(root);\n var hostUri = req.headers.host || `localhost:${getBoundPort(server)}`;\n var mainModuleName = resolveRelativeEntryPoint(root, {\n platform,\n pkg\n });\n var runtimeVersion = await Updates.getRuntimeVersionAsync(root, {\n ...exp,\n runtimeVersion: (_exp_runtimeVersion = exp.runtimeVersion) !== null && _exp_runtimeVersion !== void 0 ? _exp_runtimeVersion : {\n policy: \"sdkVersion\"\n }\n }, platform);\n var manifest = JSON.stringify({\n id: randomUUID(),\n createdAt: (/* @__PURE__ */ new Date()).toISOString(),\n runtimeVersion,\n launchAsset: {\n key: \"bundle\",\n contentType: \"application/javascript\",\n url: `http://${hostUri}/${encodeURI(mainModuleName.replace(/^\\/+/, \"\"))}.bundle?platform=${platform}&dev=true&hot=false`\n },\n assets: [],\n metadata: {},\n extra: {\n eas: {\n projectId: (_ref = (_exp_extra = exp.extra) === null || _exp_extra === void 0 ? void 0 : (_exp_extra_eas = _exp_extra.eas) === null || _exp_extra_eas === void 0 ? void 0 : _exp_extra_eas.projectId) !== null && _ref !== void 0 ? _ref : void 0\n },\n expoClient: {\n ...exp,\n hostUri\n },\n expoGo: {\n debuggerHost: hostUri,\n developer: {\n tool: \"expo-cli\",\n projectRoot: root\n },\n packagerOpts: {\n dev: true\n },\n mainModuleName\n },\n scopeKey: `@anonymous/${exp.slug}-${anonymousScopeId}`\n }\n });\n var headers = {\n \"expo-protocol-version\": \"0\",\n \"expo-sfv-version\": \"0\",\n \"cache-control\": \"private, max-age=0\"\n };\n var accept = String(req.headers.accept || \"\");\n if (accept.includes(\"multipart/mixed\")) {\n var boundary = `vxrn-${randomUUID()}`;\n res.writeHead(200, {\n ...headers,\n \"content-type\": `multipart/mixed; boundary=${boundary}`\n });\n res.end(`--${boundary}\\r\ncontent-disposition: form-data; name=\"manifest\"\\r\ncontent-type: application/json\\r\n\\r\n${manifest}\\r\n--${boundary}--\\r\n`);\n return;\n }\n var contentType = accept.includes(\"application/expo+json\") ? \"application/expo+json\" : accept.includes(\"application/json\") ? \"application/json\" : \"text/plain\";\n res.writeHead(200, {\n ...headers,\n \"content-type\": contentType\n });\n res.end(req.method === \"HEAD\" ? void 0 : manifest);\n } catch (error) {\n res.writeHead(500, {\n \"Content-Type\": \"text/plain\"\n });\n res.end(error instanceof Error ? error.stack || error.message : String(error));\n }\n });\n server.middlewares.use(async function(req, res, next) {\n if (req.method !== \"GET\" && req.method !== \"HEAD\") return next();\n var rawUrl = req.url || \"/\";\n var rawPathname = rawUrl.split(\"?\", 1)[0];\n if (!rawPathname.startsWith(\"/assets/\")) return next();\n var url = new URL(rawUrl, `http://${req.headers.host || \"localhost\"}`);\n var platform = validPlatforms[url.searchParams.get(\"platform\") || \"\"];\n var engine = platform ? devEngines[platform] : void 0;\n if (!engine) return next();\n var pathname;\n try {\n pathname = decodeURIComponent(rawPathname);\n } catch (unused) {\n res.writeHead(400, {\n \"Content-Type\": \"text/plain\"\n });\n res.end(\"Invalid native asset path\");\n return;\n }\n var asset = engine.getAsset(pathname, url.searchParams.get(\"hash\") || void 0);\n if (!asset) {\n res.writeHead(404, {\n \"Content-Type\": \"text/plain\"\n });\n res.end(\"Native asset not found\");\n return;\n }\n try {\n var contents = await readFile(asset.filePath);\n res.writeHead(200, {\n \"Cache-Control\": \"no-cache\",\n \"Content-Length\": String(contents.byteLength),\n \"Content-Type\": getNativeAssetContentType(asset.type)\n });\n res.end(req.method === \"HEAD\" ? void 0 : contents);\n } catch (error) {\n console.error(`[vxrn] failed to serve native asset ${pathname}: ${error instanceof Error ? error.message : String(error)}`);\n res.writeHead(500, {\n \"Content-Type\": \"text/plain\"\n });\n res.end(\"Failed to read native asset\");\n }\n });\n server.middlewares.use(middleware);\n (_server_httpServer = server.httpServer) === null || _server_httpServer === void 0 ? void 0 : _server_httpServer.on(\"upgrade\", function(req, socket, head) {\n var url = req.url || \"\";\n var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;\n try {\n var _loop = function() {\n var endpoint = _step.value;\n if (url.startsWith(endpoint)) {\n var wss = websocketEndpoints[endpoint];\n wss.handleUpgrade(req, socket, head, function(ws) {\n wss.emit(\"connection\", ws, req);\n });\n return {\n v: void 0\n };\n }\n };\n for (var _iterator = devToolsSocketEndpoints[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {\n var _ret = _loop();\n if (_type_of(_ret) === \"object\") return _ret.v;\n }\n } catch (err) {\n _didIteratorError = true;\n _iteratorError = err;\n } finally {\n try {\n if (!_iteratorNormalCompletion && _iterator.return != null) {\n _iterator.return();\n }\n } finally {\n if (_didIteratorError) {\n throw _iteratorError;\n }\n }\n }\n if (url.startsWith(\"/hot\")) {\n var hmrUrl = new URL(url, `http://${req.headers.host || \"localhost\"}`);\n var platform = validPlatforms[hmrUrl.searchParams.get(\"platform\") || \"\"];\n var clientId = hmrUrl.searchParams.get(\"clientId\");\n if (!platform || !clientId) {\n socket.destroy();\n return;\n }\n hmrWSS.handleUpgrade(req, socket, head, function(ws) {\n Object.assign(ws, {\n vxrnClientId: clientId,\n vxrnPlatform: platform\n });\n hmrWSS.emit(\"connection\", ws, req);\n });\n return;\n }\n if (url === \"/message\" || url.startsWith(\"/message?\")) {\n messageWSS.handleUpgrade(req, socket, head, function(ws) {\n messageWSS.emit(\"connection\", ws, req);\n });\n return;\n }\n if (url === \"/__client\") {\n clientWSS.handleUpgrade(req, socket, head, function(ws) {\n clientWSS.emit(\"connection\", ws, req);\n });\n }\n });\n hmrWSS.on(\"connection\", async function(socket) {\n var currentEngine = devEngines[socket.vxrnPlatform];\n if (!currentEngine) {\n socket.close(1013, \"native dev engine unavailable\");\n return;\n }\n try {\n await currentEngine.engine.registerClient(socket.vxrnClientId);\n } catch (error) {\n console.error(\"[hmr] failed to register native client\", error);\n socket.close(1011, \"native HMR registration failed\");\n return;\n }\n addConnectedNativeClient();\n if (pendingReloadPlatforms.has(socket.vxrnPlatform)) {\n socket.send(JSON.stringify({\n type: \"hmr:reload\"\n }));\n }\n socket.on(\"message\", function(message) {\n var value = message.toString();\n if (value === \"ping\") {\n socket.send(\"pong\");\n return;\n }\n var update;\n try {\n update = JSON.parse(value);\n } catch (unused) {\n return;\n }\n if (update.type === \"hmr:invalidate\") {\n socket.send(JSON.stringify({\n type: \"hmr:reload\"\n }));\n }\n });\n socket.on(\"close\", function() {\n removeConnectedNativeClient();\n currentEngine.engine.removeClient(socket.vxrnClientId).catch(function(error) {\n console.error(\"[hmr] failed to remove native client\", error);\n });\n });\n socket.on(\"error\", function(error) {\n console.error(\"[hmr] error\", error);\n });\n });\n clientWSS.on(\"connection\", function(socket) {\n socket.on(\"message\", function(messageRaw) {\n var message = JSON.parse(messageRaw.toString());\n switch (message.type) {\n case \"client-log\": {\n var _message_data_;\n if (message.level === \"warn\" && ((_message_data_ = message.data[0]) === null || _message_data_ === void 0 ? void 0 : _message_data_.startsWith(\"Sending `appearanceChanged` with no listeners registered.\"))) {\n return;\n }\n console.info(` \\u2460 ${message.level === \"info\" ? \"\" : ` [${message.level}]`}`, ...message.data);\n return;\n }\n default: {\n console.warn(` \\u2460 Unknown message type`, message);\n }\n }\n });\n });\n var getDevEngine = async function(platform) {\n while (!devEngines[platform]) {\n if (!devEngineCreating[platform]) {\n var creating = (async function() {\n try {\n console.info(`[vxrn] creating rolldown DevEngine for ${platform}...`);\n devEngines[platform] = await createNativeDevEngine({\n root,\n port: getBoundPort(server),\n host: typeof host === \"string\" ? host : \"localhost\",\n platform,\n serverUrl: `http://${typeof host === \"string\" && host !== \"0.0.0.0\" ? host : \"localhost\"}:${getBoundPort(server)}`,\n onHmrUpdate: function(update) {\n var msg = JSON.stringify(update);\n var target = \"clientId\" in update ? update.clientId : void 0;\n if (update.type === \"hmr:reload\" && !target) {\n pendingReloadPlatforms.add(platform);\n }\n hmrWSS.clients.forEach(function(client) {\n var nativeClient = client;\n if (nativeClient.readyState === 1 && nativeClient.vxrnPlatform === platform && (!target || nativeClient.vxrnClientId === target)) {\n client.send(msg);\n }\n });\n }\n });\n console.info(`[vxrn] rolldown DevEngine ready for ${platform}`);\n } finally {\n devEngineCreating[platform] = null;\n }\n })();\n devEngineCreating[platform] = creating;\n }\n await devEngineCreating[platform];\n }\n return devEngines[platform];\n };\n var handleRNBundle = async function(req, res) {\n var url = new URL(req.url, `http://${req.headers.host}`);\n var platformString = url.searchParams.get(\"platform\") || \"\";\n var platform = validPlatforms[platformString];\n if (!platform) {\n return;\n }\n if (url.searchParams.get(\"dev\") === \"false\" && !warnedProdBundleRequest.has(platform)) {\n warnedProdBundleRequest.add(platform);\n console.warn(`[vxrn] ${platform} bundle requested with dev=false, but the dev server only builds dev bundles. Serving a dev bundle. Use the build command for a production one.`);\n }\n try {\n var bundle = await (await getDevEngine(platform)).getBundle();\n res.once(\"finish\", function() {\n return pendingReloadPlatforms.delete(platform);\n });\n res.writeHead(200, {\n \"Cache-Control\": \"no-store\",\n \"Content-Type\": \"text/javascript\"\n });\n res.end(bundle.code);\n } catch (err) {\n console.error(` Error building React Native bundle`);\n console.error(err);\n console.error(`\n\n Note, some errors may happen due to a stale Vite cache, you may want to try re-running with the \"--clean\" flag`);\n res.writeHead(500, {\n \"Content-Type\": \"text/plain\"\n });\n res.end(err instanceof Error ? err.stack || err.message : String(err));\n }\n };\n server.middlewares.use(function(req, res, next) {\n var _req_url;\n if ((_req_url = req.url) === null || _req_url === void 0 ? void 0 : _req_url.split(\"?\")[0].endsWith(\".bundle\")) {\n handleRNBundle(req, res, next);\n } else {\n next();\n }\n });\n server.middlewares.use(\"/symbolicate\", async function(req, res) {\n try {\n var chunks = [];\n var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;\n try {\n for (var _iterator = req[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {\n var chunk = _step.value;\n chunks.push(chunk);\n }\n } catch (err) {\n _didIteratorError = true;\n _iteratorError = err;\n } finally {\n try {\n if (!_iteratorNormalCompletion && _iterator.return != null) {\n _iterator.return();\n }\n } finally {\n if (_didIteratorError) {\n throw _iteratorError;\n }\n }\n }\n var body = JSON.parse(Buffer.concat(chunks).toString(\"utf8\"));\n var stack = body.stack;\n if (!Array.isArray(stack)) {\n throw new Error(\"expected a `stack` array in the request body\");\n }\n var bundleFrame = stack.find(function(frame) {\n return isNativeBundleFrame(frame.file);\n });\n if (!bundleFrame) {\n res.writeHead(200, {\n \"Content-Type\": \"application/json\"\n });\n res.end(JSON.stringify({\n stack,\n codeFrame: null\n }));\n return;\n }\n var framePlatform = getNativeFramePlatform(bundleFrame.file);\n var platform = validPlatforms[framePlatform !== null && framePlatform !== void 0 ? framePlatform : \"\"];\n if (!platform) {\n throw new Error(`could not tell which platform \"${bundleFrame.file}\" was bundled for`);\n }\n var bundle = await (await getDevEngine(platform)).getBundle();\n res.writeHead(200, {\n \"Content-Type\": \"application/json\"\n });\n res.end(JSON.stringify(symbolicateNativeStack(stack, bundle.map)));\n } catch (err) {\n console.error(`[vxrn] symbolicate failed`, err);\n res.writeHead(500, {\n \"Content-Type\": \"application/json\"\n });\n res.end(JSON.stringify({\n error: err instanceof Error ? err.message : String(err)\n }));\n }\n });\n }\n };\n}\nexport {\n createReactNativeDevServerPlugin,\n getNativeAssetContentType\n};\n//# sourceMappingURL=reactNativeDevServer.js.map\n"],"mappings":";;;;;;;;;;;;;;AAYA,SAAS,SAAS,KAAK;CACrB;CACA,OAAO,OAAO,OAAO,WAAW,eAAe,IAAI,gBAAgB,SAAS,WAAW,OAAO;AAChG;AACA,SAAS,0BAA0B,MAAM;CACvC,QAAQ,KAAK,YAAY,GAAzB;EACE,KAAK,OACH,OAAO;EACT,KAAK,OACH,OAAO;EACT,KAAK;EACL,KAAK,OACH,OAAO;EACT,KAAK,QACH,OAAO;EACT,KAAK,OACH,OAAO;EACT,KAAK,OACH,OAAO;EACT,KAAK,OACH,OAAO;EACT,KAAK,OACH,OAAO;EACT,KAAK,QACH,OAAO;EACT,KAAK,QACH,OAAO;EACT,KAAK,SACH,OAAO;EACT,SACE,OAAO;CACX;AACF;AACA,SAAS,iCAAiC,SAAS;CACjD,OAAO;EACL,MAAM;EACN,gBAAgB,QAAQ;GACtB,IAAI;GACJ,IAAI,EAAE,SAAS,OAAO,OAAO;GAC7B,IAAI,EAAE,SAAS,OAAO;GACtB,IAAI,SAAS,IAAI,gBAAgB,EAC/B,UAAU,KACZ,CAAC;GACD,IAAI,YAAY,IAAI,gBAAgB,EAClC,UAAU,KACZ,CAAC;GACD,IAAI,aAAa,oBAAoB;GACrC,IAAI,iBAAiB;IACnB,KAAK;IACL,SAAS;GACX;GACA,IAAI,aAAa,CAAC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SAAS,OAAO;MAC3C,OAAO,oBAAoB,MAAM,IAAI;KACvC,CAAC;KACD,IAAI,CAAC,aAAa;MAChB,IAAI,UAAU,KAAK,EACjB,gBAAgB,mBAClB,CAAC;MACD,IAAI,IAAI,KAAK,UAAU;OACrB;OACA,WAAW;MACb,CAAC,CAAC;MACF;KACF;KACA,IAAI,gBAAgB,uBAAuB,YAAY,IAAI;KAC3D,IAAI,WAAW,eAAe,kBAAkB,QAAQ,kBAAkB,KAAK,IAAI,gBAAgB;KACnG,IAAI,CAAC,UAAU;MACb,MAAM,IAAI,MAAM,kCAAkC,YAAY,KAAK,kBAAkB;KACvF;KACA,IAAI,SAAS,OAAO,MAAM,aAAa,QAAQ,EAAC,CAAE,UAAU;KAC5D,IAAI,UAAU,KAAK,EACjB,gBAAgB,mBAClB,CAAC;KACD,IAAI,IAAI,KAAK,UAAU,uBAAuB,OAAO,OAAO,GAAG,CAAC,CAAC;IACnE,SAAS,KAAK;KACZ,QAAQ,MAAM,6BAA6B,GAAG;KAC9C,IAAI,UAAU,KAAK,EACjB,gBAAgB,mBAClB,CAAC;KACD,IAAI,IAAI,KAAK,UAAU,EACrB,OAAO,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG,EACxD,CAAC,CAAC;IACJ;GACF,CAAC;EACH;CACF;AACF"}
1
+ {"version":3,"file":"reactNativeDevServer.native.js","names":[],"sources":["plugins/reactNativeDevServer.native.js"],"sourcesContent":["import { WebSocketServer } from \"ws\";\nimport { createMessageSocket } from \"@vxrn/utils\";\nimport { expoClientFromNativeApp } from \"@vxrn/utils/nativeAppManifest\";\nimport { addConnectedNativeClient, removeConnectedNativeClient } from \"../utils/connectedNativeClients\";\nimport { URL } from \"url\";\nimport { createRequire } from \"module\";\nimport { extname, join, resolve, sep } from \"path\";\nimport { randomUUID } from \"crypto\";\nimport { existsSync, readFileSync, statSync } from \"fs\";\nimport { readFile } from \"fs/promises\";\nimport { createDevMiddleware } from \"@react-native/dev-middleware\";\nimport { createNativeDevEngine } from \"../utils/createNativeDevEngine\";\nimport { nativeDevBytecodeCompiler } from \"../utils/compileNativeDevBytecode\";\nimport { getBoundPort } from \"../utils/getBoundPort\";\nimport { getNativeFramePlatform, isNativeBundleFrame, symbolicateNativeStack } from \"../utils/symbolicateNativeStack\";\nfunction _async_iterator(iterable) {\n var method, async, sync, retry = 2;\n for (\"undefined\" != typeof Symbol && (async = Symbol.asyncIterator, sync = Symbol.iterator); retry--; ) {\n if (async && null != (method = iterable[async])) return method.call(iterable);\n if (sync && null != (method = iterable[sync])) return new AsyncFromSyncIterator(method.call(iterable));\n async = \"@@asyncIterator\", sync = \"@@iterator\";\n }\n throw new TypeError(\"Object is not async iterable\");\n}\nfunction AsyncFromSyncIterator(s) {\n function AsyncFromSyncIteratorContinuation(r) {\n if (Object(r) !== r) return Promise.reject(new TypeError(r + \" is not an object.\"));\n var done = r.done;\n return Promise.resolve(r.value).then(function(value) {\n return {\n value,\n done\n };\n });\n }\n return AsyncFromSyncIterator = function(s2) {\n this.s = s2, this.n = s2.next;\n }, AsyncFromSyncIterator.prototype = {\n s: null,\n n: null,\n next: function() {\n return AsyncFromSyncIteratorContinuation(this.n.apply(this.s, arguments));\n },\n return: function(value) {\n var ret = this.s.return;\n return void 0 === ret ? Promise.resolve({\n value,\n done: true\n }) : AsyncFromSyncIteratorContinuation(ret.apply(this.s, arguments));\n },\n throw: function(value) {\n var thr = this.s.return;\n return void 0 === thr ? Promise.reject(value) : AsyncFromSyncIteratorContinuation(thr.apply(this.s, arguments));\n }\n }, new AsyncFromSyncIterator(s);\n}\nfunction _type_of(obj) {\n \"@swc/helpers - typeof\";\n return obj && typeof Symbol !== \"undefined\" && obj.constructor === Symbol ? \"symbol\" : typeof obj;\n}\nfunction getProjectAssetFile(root, pathname) {\n var filePath = resolve(root, pathname.slice(\"/assets/\".length));\n if (!filePath.startsWith(resolve(root) + sep)) return;\n var type = extname(filePath).slice(1);\n if (getNativeAssetContentType(type) === \"application/octet-stream\") return;\n if (!existsSync(filePath) || !statSync(filePath).isFile()) return;\n return {\n filePath,\n type\n };\n}\nfunction getNativeAssetContentType(type) {\n switch (type.toLowerCase()) {\n case \"bmp\":\n return \"image/bmp\";\n case \"gif\":\n return \"image/gif\";\n case \"glb\":\n return \"model/gltf-binary\";\n case \"jpeg\":\n case \"jpg\":\n return \"image/jpeg\";\n case \"json\":\n return \"application/json\";\n case \"mp4\":\n return \"video/mp4\";\n case \"otf\":\n return \"font/otf\";\n case \"png\":\n return \"image/png\";\n case \"svg\":\n return \"image/svg+xml\";\n case \"ttf\":\n return \"font/ttf\";\n case \"txt\":\n return \"text/plain\";\n case \"webp\":\n return \"image/webp\";\n case \"woff\":\n return \"font/woff\";\n case \"woff2\":\n return \"font/woff2\";\n default:\n return \"application/octet-stream\";\n }\n}\nfunction createReactNativeDevServerPlugin(options) {\n return {\n name: \"vite-plugin-react-native-server\",\n configureServer(server) {\n var _packageJson_dependencies, _packageJson_devDependencies;\n var _globalThis___vxrnNativeEntryConfig, _server_httpServer;\n var { host } = server.config.server;\n var { root } = server.config;\n var hmrWSS = new WebSocketServer({\n noServer: true\n });\n var clientWSS = new WebSocketServer({\n noServer: true\n });\n var messageWSS = createMessageSocket();\n var validPlatforms = {\n ios: \"ios\",\n android: \"android\"\n };\n var devEngines = {};\n var devEngineCreating = {};\n var warnedProdBundleRequest = /* @__PURE__ */ new Set();\n var pendingReloadPlatforms = /* @__PURE__ */ new Set();\n var compileBytecode;\n var devToolsSocketEndpoints = [\n \"/inspector/device\",\n \"/inspector/debug\"\n ];\n var reactNativeDevToolsUrl = `http://${host}:${getBoundPort(server)}`;\n var { middleware, websocketEndpoints } = createDevMiddleware({\n serverBaseUrl: reactNativeDevToolsUrl,\n logger: console,\n unstable_experiments: {\n enableStandaloneFuseboxShell: false\n }\n });\n var projectRequire = createRequire(join(root, \"package.json\"));\n var packageJsonPath = join(root, \"package.json\");\n var packageJson = existsSync(packageJsonPath) ? JSON.parse(readFileSync(packageJsonPath, \"utf8\")) : {};\n var hasExpo = Object.hasOwn((_packageJson_dependencies = packageJson.dependencies) !== null && _packageJson_dependencies !== void 0 ? _packageJson_dependencies : {}, \"expo\") || Object.hasOwn((_packageJson_devDependencies = packageJson.devDependencies) !== null && _packageJson_devDependencies !== void 0 ? _packageJson_devDependencies : {}, \"expo\");\n var nativeApp = hasExpo ? void 0 : (_globalThis___vxrnNativeEntryConfig = globalThis.__vxrnNativeEntryConfig) === null || _globalThis___vxrnNativeEntryConfig === void 0 ? void 0 : _globalThis___vxrnNativeEntryConfig.app;\n var anonymousScopeId = randomUUID();\n server.middlewares.use(async function(req, res, next) {\n if (!hasExpo && !nativeApp) return next();\n if (req.method !== \"GET\" && req.method !== \"HEAD\") return next();\n var url = new URL(req.url || \"/\", `http://${req.headers.host || \"localhost\"}`);\n if (url.pathname !== \"/\" && url.pathname !== \"/manifest\" && url.pathname !== \"/index.exp\") {\n return next();\n }\n var header = req.headers[\"expo-platform\"] || req.headers[\"exponent-platform\"];\n var platform = validPlatforms[url.searchParams.get(\"platform\") || String(header || \"\")];\n if (!platform) return next();\n var expoConfigPath;\n if (!nativeApp) {\n try {\n expoConfigPath = projectRequire.resolve(\"@expo/config\");\n } catch (unused) {\n return next();\n }\n }\n try {\n var _ref, _ref1;\n var _nativeApp_updates, _exp_extra_eas, _exp_extra;\n var hostUri = req.headers.host || `localhost:${getBoundPort(server)}`;\n var { exp, mainModuleName, runtimeVersion } = nativeApp ? {\n exp: expoClientFromNativeApp(nativeApp),\n // the vite native server answers any `.bundle` path with the\n // app entry, so `index` is what a one app's native build loads.\n mainModuleName: \"index\",\n runtimeVersion: (_ref = (_nativeApp_updates = nativeApp.updates) === null || _nativeApp_updates === void 0 ? void 0 : _nativeApp_updates.runtimeVersion) !== null && _ref !== void 0 ? _ref : null\n } : await (async function() {\n var _exp_runtimeVersion;\n var expoRequire = createRequire(expoConfigPath);\n var { getConfig } = expoRequire(\"@expo/config\");\n var { resolveRelativeEntryPoint } = expoRequire(\"@expo/config/paths\");\n var { Updates } = expoRequire(\"@expo/config-plugins\");\n var { exp: exp2, pkg } = getConfig(root);\n return {\n exp: exp2,\n mainModuleName: resolveRelativeEntryPoint(root, {\n platform,\n pkg\n }),\n runtimeVersion: await Updates.getRuntimeVersionAsync(root, {\n ...exp2,\n runtimeVersion: (_exp_runtimeVersion = exp2.runtimeVersion) !== null && _exp_runtimeVersion !== void 0 ? _exp_runtimeVersion : {\n policy: \"sdkVersion\"\n }\n }, platform)\n };\n })();\n var manifest = JSON.stringify({\n id: randomUUID(),\n createdAt: (/* @__PURE__ */ new Date()).toISOString(),\n runtimeVersion,\n launchAsset: {\n key: \"bundle\",\n contentType: \"application/javascript\",\n url: `http://${hostUri}/${encodeURI(mainModuleName.replace(/^\\/+/, \"\"))}.bundle?platform=${platform}&dev=true&hot=false`\n },\n assets: [],\n metadata: nativeApp ? {\n oneNativeApp: true\n } : {},\n extra: {\n eas: {\n projectId: (_ref1 = (_exp_extra = exp.extra) === null || _exp_extra === void 0 ? void 0 : (_exp_extra_eas = _exp_extra.eas) === null || _exp_extra_eas === void 0 ? void 0 : _exp_extra_eas.projectId) !== null && _ref1 !== void 0 ? _ref1 : void 0\n },\n expoClient: {\n ...exp,\n hostUri\n },\n expoGo: {\n debuggerHost: hostUri,\n developer: {\n tool: \"expo-cli\",\n projectRoot: root\n },\n packagerOpts: {\n dev: true\n },\n mainModuleName\n },\n scopeKey: `@anonymous/${exp.slug}-${anonymousScopeId}`\n }\n });\n var headers = {\n \"expo-protocol-version\": \"0\",\n \"expo-sfv-version\": \"0\",\n \"cache-control\": \"private, max-age=0\"\n };\n var accept = String(req.headers.accept || \"\");\n if (accept.includes(\"multipart/mixed\")) {\n var boundary = `vxrn-${randomUUID()}`;\n res.writeHead(200, {\n ...headers,\n \"content-type\": `multipart/mixed; boundary=${boundary}`\n });\n res.end(`--${boundary}\\r\ncontent-disposition: form-data; name=\"manifest\"\\r\ncontent-type: application/json\\r\n\\r\n${manifest}\\r\n--${boundary}--\\r\n`);\n return;\n }\n var contentType = accept.includes(\"application/expo+json\") ? \"application/expo+json\" : accept.includes(\"application/json\") ? \"application/json\" : \"text/plain\";\n res.writeHead(200, {\n ...headers,\n \"content-type\": contentType\n });\n res.end(req.method === \"HEAD\" ? void 0 : manifest);\n } catch (error) {\n res.writeHead(500, {\n \"Content-Type\": \"text/plain\"\n });\n res.end(error instanceof Error ? error.stack || error.message : String(error));\n }\n });\n server.middlewares.use(async function(req, res, next) {\n var _ref;\n if (req.method !== \"GET\" && req.method !== \"HEAD\") return next();\n var rawUrl = req.url || \"/\";\n var rawPathname = rawUrl.split(\"?\", 1)[0];\n if (!rawPathname.startsWith(\"/assets/\")) return next();\n var url = new URL(rawUrl, `http://${req.headers.host || \"localhost\"}`);\n var platform = validPlatforms[url.searchParams.get(\"platform\") || \"\"];\n var engine = platform ? devEngines[platform] : void 0;\n var pathname;\n try {\n pathname = decodeURIComponent(rawPathname);\n } catch (unused) {\n res.writeHead(400, {\n \"Content-Type\": \"text/plain\"\n });\n res.end(\"Invalid native asset path\");\n return;\n }\n var asset = (_ref = engine === null || engine === void 0 ? void 0 : engine.getAsset(pathname, url.searchParams.get(\"hash\") || void 0)) !== null && _ref !== void 0 ? _ref : getProjectAssetFile(root, pathname);\n if (!asset) {\n if (!engine) return next();\n res.writeHead(404, {\n \"Content-Type\": \"text/plain\"\n });\n res.end(\"Native asset not found\");\n return;\n }\n try {\n var contents = await readFile(asset.filePath);\n var headers = {\n \"Cache-Control\": \"no-cache\",\n \"Accept-Ranges\": \"bytes\",\n \"Content-Length\": String(contents.byteLength),\n \"Content-Type\": getNativeAssetContentType(asset.type)\n };\n var range = req.method === \"GET\" && !req.headers[\"if-range\"] && /^bytes=(\\d*)-(\\d*)$/.exec(req.headers.range || \"\");\n if (range && (range[1] || range[2])) {\n var size = contents.byteLength;\n var start = range[1] ? Number(range[1]) : Math.max(0, size - Number(range[2]));\n var end = range[1] && range[2] ? Math.min(Number(range[2]), size - 1) : size - 1;\n if (!Number.isSafeInteger(start) || !Number.isSafeInteger(end) || start > end || start >= size) {\n res.writeHead(416, {\n ...headers,\n \"Content-Length\": \"0\",\n \"Content-Range\": `bytes */${size}`\n });\n res.end();\n return;\n }\n res.writeHead(206, {\n ...headers,\n \"Content-Length\": String(end - start + 1),\n \"Content-Range\": `bytes ${start}-${end}/${size}`\n });\n res.end(contents.subarray(start, end + 1));\n return;\n }\n res.writeHead(200, headers);\n res.end(req.method === \"HEAD\" ? void 0 : contents);\n } catch (error) {\n console.error(`[vxrn] failed to serve native asset ${pathname}: ${error instanceof Error ? error.message : String(error)}`);\n res.writeHead(500, {\n \"Content-Type\": \"text/plain\"\n });\n res.end(\"Failed to read native asset\");\n }\n });\n server.middlewares.use(middleware);\n (_server_httpServer = server.httpServer) === null || _server_httpServer === void 0 ? void 0 : _server_httpServer.on(\"upgrade\", function(req, socket, head) {\n var url = req.url || \"\";\n var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;\n try {\n var _loop = function() {\n var endpoint = _step.value;\n if (url.startsWith(endpoint)) {\n var wss = websocketEndpoints[endpoint];\n wss.handleUpgrade(req, socket, head, function(ws) {\n wss.emit(\"connection\", ws, req);\n });\n return {\n v: void 0\n };\n }\n };\n for (var _iterator = devToolsSocketEndpoints[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {\n var _ret = _loop();\n if (_type_of(_ret) === \"object\") return _ret.v;\n }\n } catch (err) {\n _didIteratorError = true;\n _iteratorError = err;\n } finally {\n try {\n if (!_iteratorNormalCompletion && _iterator.return != null) {\n _iterator.return();\n }\n } finally {\n if (_didIteratorError) {\n throw _iteratorError;\n }\n }\n }\n if (url.startsWith(\"/hot\")) {\n var hmrUrl = new URL(url, `http://${req.headers.host || \"localhost\"}`);\n var platform = validPlatforms[hmrUrl.searchParams.get(\"platform\") || \"\"];\n var clientId = hmrUrl.searchParams.get(\"clientId\");\n if (!platform || !clientId) {\n socket.destroy();\n return;\n }\n hmrWSS.handleUpgrade(req, socket, head, function(ws) {\n Object.assign(ws, {\n vxrnClientId: clientId,\n vxrnPlatform: platform\n });\n hmrWSS.emit(\"connection\", ws, req);\n });\n return;\n }\n if (url === \"/message\" || url.startsWith(\"/message?\")) {\n messageWSS.handleUpgrade(req, socket, head, function(ws) {\n messageWSS.emit(\"connection\", ws, req);\n });\n return;\n }\n if (url === \"/__client\") {\n clientWSS.handleUpgrade(req, socket, head, function(ws) {\n clientWSS.emit(\"connection\", ws, req);\n });\n }\n });\n hmrWSS.on(\"connection\", async function(socket) {\n var currentEngine = devEngines[socket.vxrnPlatform];\n if (!currentEngine) {\n socket.close(1013, \"native dev engine unavailable\");\n return;\n }\n try {\n await currentEngine.engine.registerClient(socket.vxrnClientId);\n } catch (error) {\n console.error(\"[hmr] failed to register native client\", error);\n socket.close(1011, \"native HMR registration failed\");\n return;\n }\n addConnectedNativeClient();\n if (pendingReloadPlatforms.has(socket.vxrnPlatform)) {\n socket.send(JSON.stringify({\n type: \"hmr:reload\"\n }));\n }\n socket.on(\"message\", function(message) {\n var value = message.toString();\n if (value === \"ping\") {\n socket.send(\"pong\");\n return;\n }\n var update;\n try {\n update = JSON.parse(value);\n } catch (unused) {\n return;\n }\n if (update.type === \"hmr:invalidate\") {\n socket.send(JSON.stringify({\n type: \"hmr:reload\"\n }));\n }\n });\n socket.on(\"close\", function() {\n removeConnectedNativeClient();\n currentEngine.engine.removeClient(socket.vxrnClientId).catch(function(error) {\n console.error(\"[hmr] failed to remove native client\", error);\n });\n });\n socket.on(\"error\", function(error) {\n console.error(\"[hmr] error\", error);\n });\n });\n clientWSS.on(\"connection\", function(socket) {\n socket.on(\"message\", function(messageRaw) {\n var message = JSON.parse(messageRaw.toString());\n switch (message.type) {\n case \"client-log\": {\n var _message_data_;\n if (message.level === \"warn\" && ((_message_data_ = message.data[0]) === null || _message_data_ === void 0 ? void 0 : _message_data_.startsWith(\"Sending `appearanceChanged` with no listeners registered.\"))) {\n return;\n }\n console.info(` \\u2460 ${message.level === \"info\" ? \"\" : ` [${message.level}]`}`, ...message.data);\n return;\n }\n default: {\n console.warn(` \\u2460 Unknown message type`, message);\n }\n }\n });\n });\n var getDevEngine = async function getDevEngine2(platform) {\n while (!devEngines[platform]) {\n if (!devEngineCreating[platform]) {\n var creating = (async function() {\n try {\n console.info(`[vxrn] creating rolldown DevEngine for ${platform}...`);\n devEngines[platform] = await createNativeDevEngine({\n root,\n port: getBoundPort(server),\n host: typeof host === \"string\" ? host : \"localhost\",\n platform,\n serverUrl: `http://${typeof host === \"string\" && host !== \"0.0.0.0\" ? host : \"localhost\"}:${getBoundPort(server)}`,\n onHmrUpdate: function onHmrUpdate(update) {\n var msg = JSON.stringify(update);\n var target = \"clientId\" in update ? update.clientId : void 0;\n if (update.type === \"hmr:reload\" && !target) {\n pendingReloadPlatforms.add(platform);\n }\n hmrWSS.clients.forEach(function(client) {\n var nativeClient = client;\n if (nativeClient.readyState === 1 && nativeClient.vxrnPlatform === platform && (!target || nativeClient.vxrnClientId === target)) {\n client.send(msg);\n }\n });\n }\n });\n console.info(`[vxrn] rolldown DevEngine ready for ${platform}`);\n } finally {\n devEngineCreating[platform] = null;\n }\n })();\n devEngineCreating[platform] = creating;\n }\n await devEngineCreating[platform];\n }\n return devEngines[platform];\n };\n var handleRNBundle = async function handleRNBundle2(req, res) {\n var url = new URL(req.url, `http://${req.headers.host}`);\n var platformString = url.searchParams.get(\"platform\") || \"\";\n var platform = validPlatforms[platformString];\n if (!platform) {\n return;\n }\n if (url.searchParams.get(\"dev\") === \"false\" && !warnedProdBundleRequest.has(platform)) {\n warnedProdBundleRequest.add(platform);\n console.warn(`[vxrn] ${platform} bundle requested with dev=false, but the dev server only builds dev bundles. Serving a dev bundle. Use the build command for a production one.`);\n }\n try {\n var bundle = await (await getDevEngine(platform)).getBundle();\n var body = bundle.code;\n if (platform === \"ios\" && url.searchParams.get(\"bytecode\") === \"hermes\") {\n compileBytecode || (compileBytecode = nativeDevBytecodeCompiler(root));\n body = await compileBytecode(bundle, `${url.origin}/index.bundle?platform=${platform}`);\n }\n res.once(\"finish\", function() {\n return pendingReloadPlatforms.delete(platform);\n });\n res.writeHead(200, {\n \"Cache-Control\": \"no-store\",\n \"Content-Type\": \"text/javascript\"\n });\n res.end(body);\n } catch (err) {\n console.error(` Error building React Native bundle`);\n console.error(err);\n console.error(`\n\n Note, some errors may happen due to a stale Vite cache, you may want to try re-running with the \"--clean\" flag`);\n res.writeHead(500, {\n \"Content-Type\": \"text/plain\"\n });\n res.end(err instanceof Error ? err.stack || err.message : String(err));\n }\n };\n server.middlewares.use(function(req, res, next) {\n var _req_url;\n if ((_req_url = req.url) === null || _req_url === void 0 ? void 0 : _req_url.split(\"?\")[0].endsWith(\".bundle\")) {\n handleRNBundle(req, res, next);\n } else {\n next();\n }\n });\n server.middlewares.use(\"/symbolicate\", async function(req, res) {\n try {\n var chunks = [];\n {\n var _iteratorAbruptCompletion = false, _didIteratorError = false, _iteratorError, _return;\n try {\n var _iterator = _async_iterator(req);\n if (_iterator === null || typeof _iterator !== \"object\" && typeof _iterator !== \"function\") throw new TypeError(\"Iterator result is not an object\");\n for (var _next = _iterator.next, _step; ; _iteratorAbruptCompletion = false) {\n _step = await Reflect.apply(_next, _iterator, []);\n if (_step === null || typeof _step !== \"object\" && typeof _step !== \"function\") throw new TypeError(\"Iterator result is not an object\");\n _iteratorAbruptCompletion = !_step.done;\n if (!_iteratorAbruptCompletion) break;\n var _value = _step.value;\n var chunk = _value;\n chunks.push(chunk);\n }\n } catch (err) {\n _didIteratorError = true;\n _iteratorError = err;\n } finally {\n try {\n if (_iteratorAbruptCompletion && (_return = _iterator.return) != null) {\n _step = await Reflect.apply(_return, _iterator, []);\n if (_step === null || typeof _step !== \"object\" && typeof _step !== \"function\") throw new TypeError(\"Iterator result is not an object\");\n }\n } finally {\n if (_didIteratorError) {\n throw _iteratorError;\n }\n }\n }\n }\n var body = JSON.parse(Buffer.concat(chunks).toString(\"utf8\"));\n var stack = body.stack;\n if (!Array.isArray(stack)) {\n throw new Error(\"expected a `stack` array in the request body\");\n }\n var bundleFrame = stack.find(function(frame) {\n return isNativeBundleFrame(frame.file);\n });\n if (!bundleFrame) {\n res.writeHead(200, {\n \"Content-Type\": \"application/json\"\n });\n res.end(JSON.stringify({\n stack,\n codeFrame: null\n }));\n return;\n }\n var framePlatform = getNativeFramePlatform(bundleFrame.file);\n var platform = validPlatforms[framePlatform !== null && framePlatform !== void 0 ? framePlatform : \"\"];\n if (!platform) {\n throw new Error(`could not tell which platform \"${bundleFrame.file}\" was bundled for`);\n }\n var bundle = await (await getDevEngine(platform)).getBundle();\n res.writeHead(200, {\n \"Content-Type\": \"application/json\"\n });\n res.end(JSON.stringify(symbolicateNativeStack(stack, bundle.map)));\n } catch (err) {\n console.error(`[vxrn] symbolicate failed`, err);\n res.writeHead(500, {\n \"Content-Type\": \"application/json\"\n });\n res.end(JSON.stringify({\n error: err instanceof Error ? err.message : String(err)\n }));\n }\n });\n }\n };\n}\nexport {\n createReactNativeDevServerPlugin,\n getNativeAssetContentType\n};\n//# sourceMappingURL=reactNativeDevServer.js.map\n"],"mappings":";;;;;;;;;;;;;;;;;AAeA,SAAS,gBAAgB,UAAU;CACjC,IAAI,QAAQ,OAAO,MAAM,QAAQ;CACjC,KAAK,eAAe,OAAO,WAAW,QAAQ,OAAO,eAAe,OAAO,OAAO,WAAW,UAAW;EACtG,IAAI,SAAS,SAAS,SAAS,SAAS,SAAS,OAAO,OAAO,KAAK,QAAQ;EAC5E,IAAI,QAAQ,SAAS,SAAS,SAAS,QAAQ,OAAO,IAAI,sBAAsB,OAAO,KAAK,QAAQ,CAAC;EACrG,QAAQ,mBAAmB,OAAO;CACpC;CACA,MAAM,IAAI,UAAU,8BAA8B;AACpD;AACA,SAAS,sBAAsB,GAAG;CAChC,SAAS,kCAAkC,GAAG;EAC5C,IAAI,OAAO,CAAC,MAAM,GAAG,OAAO,QAAQ,OAAO,IAAI,UAAU,IAAI,oBAAoB,C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,GAAG,CAAC,CAAC;IACnE,SAAS,KAAK;KACZ,QAAQ,MAAM,6BAA6B,GAAG;KAC9C,IAAI,UAAU,KAAK,EACjB,gBAAgB,mBAClB,CAAC;KACD,IAAI,IAAI,KAAK,UAAU,EACrB,OAAO,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG,EACxD,CAAC,CAAC;IACJ;GACF,CAAC;EACH;CACF;AACF"}
@@ -4,7 +4,8 @@ import { dirname, isAbsolute, join } from "node:path";
4
4
  import { statSync } from "node:fs";
5
5
  import { rolldown } from "rolldown";
6
6
  import { parseSync } from "oxc-parser";
7
- import { JS_GLOBALS, getClosureVariables, transformHermesLoops } from "@vxrn/compiler";
7
+ import { createBackgroundWorkletModule } from "../backgroundComputation.mjs";
8
+ import { prepareBackgroundWorkletModule } from "../backgroundComputationNative.mjs";
8
9
  import { hermesCompatSWCPlugin, hermesLoopsPlugin } from "../utils/createNativeDevEngine.mjs";
9
10
 
10
11
  function workletImportsPlugin(imports) {
@@ -22,14 +23,16 @@ function workletImportsPlugin(imports) {
22
23
  const instance = {
23
24
  name: "vxrn:worklet-imports:bundle",
24
25
  async resolveId(source, importer, options) {
25
- const names = selections.get(source);
26
+ const marker = "?one-background=";
27
+ const selected = source.indexOf(marker);
28
+ const names = selected < 0 ? selections.get(source) : [decodeURIComponent(source.slice(selected + marker.length))];
26
29
  if (!names) return;
27
30
  if (!names.length) throw new Error(`[worklet imports] no exports selected for ${source}`);
28
31
  if (options.kind !== "import-statement") {
29
32
  throw new Error(`[worklet imports] ${source} requires a static ESM import`);
30
33
  }
31
34
  rejectRuntimeDependency(source);
32
- const resolved = await this.resolve(source, importer, { skipSelf: true });
35
+ const resolved = await this.resolve(selected < 0 ? source : source.slice(0, selected), importer, { skipSelf: true });
33
36
  if (!resolved || resolved.external || !isAbsolute(resolved.id) || !statSync(resolved.id, { throwIfNoEntry: false })?.isFile()) {
34
37
  throw new Error(`[worklet imports] ${source} must resolve to a JavaScript file`);
35
38
  }
@@ -108,39 +111,15 @@ function workletImportsPlugin(imports) {
108
111
  if (output.output.length !== 1 || chunk.type !== "chunk" || chunk.imports.length || chunk.dynamicImports.length) {
109
112
  throw new Error(`[worklet imports] ${selected.entry} must produce one self-contained JavaScript module`);
110
113
  }
111
- code = transformHermesLoops(chunk.code, id)?.code ?? chunk.code;
114
+ code = chunk.code;
112
115
  for (const file of await bundle.watchFiles) {
113
116
  if (isAbsolute(file)) outerContext.addWatchFile(file);
114
117
  }
115
118
  } finally {
116
119
  await bundle.close();
117
120
  }
118
- const loader = `__oneLoadWorkletModule_${selected.key}`;
119
- const loaderCode = `function ${loader}() {
120
- 'worklet';
121
- const cache = globalThis.__oneWorkletImportCache || (globalThis.__oneWorkletImportCache = new WeakMap());
122
- let namespace = cache.get(${loader});
123
- if (namespace === undefined) {
124
- ${code}
125
- namespace = __oneWorkletBundle;
126
- cache.set(${loader}, namespace);
127
- }
128
- return namespace;
129
- }`;
130
- const parsed = parseSync(id, loaderCode, { lang: "js" });
131
- if (parsed.errors.length) throw new Error(parsed.errors[0].message);
132
- const captures = getClosureVariables(parsed.program.body[0], /* @__PURE__ */ new Set([...JS_GLOBALS, "arguments"]));
133
- if (captures.length) {
134
- throw new Error(`[worklet imports] ${selected.entry} requires unsupported runtime globals: ${captures.join(", ")}`);
135
- }
136
- return `${loaderCode}
137
- ${selected.names.map((name, index) => `
138
- function __oneExport${index}(...args) {
139
- 'worklet';
140
- return (0, ${loader}().__export${index})(...args);
141
- }
142
- export { __oneExport${index} as ${JSON.stringify(name)} };
143
- `).join("\n")}`;
121
+ const moduleSource = createBackgroundWorkletModule(code, selected.names, selected.key);
122
+ return prepareBackgroundWorkletModule(moduleSource, selected.entry);
144
123
  }
145
124
  };
146
125
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"workletImportsPlugin.js","names":[],"sources":["plugins/workletImportsPlugin.js"],"sourcesContent":["import { createHash } from \"node:crypto\";\nimport { isBuiltin } from \"node:module\";\nimport { dirname, isAbsolute, join } from \"node:path\";\nimport { statSync } from \"node:fs\";\nimport { rolldown } from \"rolldown\";\nimport { parseSync } from \"oxc-parser\";\nimport { getClosureVariables, JS_GLOBALS, transformHermesLoops } from \"@vxrn/compiler\";\nimport { hermesCompatSWCPlugin, hermesLoopsPlugin } from \"../utils/createNativeDevEngine\";\nfunction workletImportsPlugin(imports) {\n const selections = new Map(\n Object.entries(imports).map(([source, names]) => [source, [...new Set(names)]])\n );\n const rejectRuntimeDependency = (source) => {\n const normalized = source.replace(/\\\\/g, \"/\");\n if (isBuiltin(source) || /(?:^|\\/node_modules\\/)(?:react|react-native|react-native-worklets|react-native-reanimated)(?:\\/|$)/.test(\n normalized\n ) || /(?:^|\\/node_modules\\/)@react-native\\//.test(normalized)) {\n throw new Error(\n `[worklet imports] runtime dependency ${source} is not pure JavaScript`\n );\n }\n };\n return {\n name: \"vxrn:worklet-imports\",\n options(nativeOptions) {\n const modules = /* @__PURE__ */ new Map();\n const instance = {\n name: \"vxrn:worklet-imports:bundle\",\n async resolveId(source, importer, options) {\n const names = selections.get(source);\n if (!names) return;\n if (!names.length)\n throw new Error(`[worklet imports] no exports selected for ${source}`);\n if (options.kind !== \"import-statement\") {\n throw new Error(`[worklet imports] ${source} requires a static ESM import`);\n }\n rejectRuntimeDependency(source);\n const resolved = await this.resolve(source, importer, { skipSelf: true });\n if (!resolved || resolved.external || !isAbsolute(resolved.id) || !statSync(resolved.id, { throwIfNoEntry: false })?.isFile()) {\n throw new Error(\n `[worklet imports] ${source} must resolve to a JavaScript file`\n );\n }\n rejectRuntimeDependency(resolved.id);\n const key = createHash(\"sha256\").update(JSON.stringify([resolved.id, names])).digest(\"hex\").slice(0, 16);\n const id = join(dirname(resolved.id), `__one_worklet_imports_${key}.js`);\n modules.set(id, { entry: resolved.id, names, key });\n return id;\n },\n moduleParsed(info) {\n if (!info.code || ![...selections.keys()].some((source) => info.code.includes(source)))\n return;\n const { program, errors } = parseSync(info.id, info.code, {\n lang: /\\.[cm]?ts$/.test(info.id) ? \"ts\" : info.id.endsWith(\".tsx\") ? \"tsx\" : \"jsx\"\n });\n if (errors.length) throw new Error(errors[0].message);\n for (const node of program.body) {\n if (node.type !== \"ImportDeclaration\" && node.type !== \"ExportNamedDeclaration\")\n continue;\n const source = node.source?.value;\n if (!source) continue;\n const names = selections.get(source);\n if (!names) continue;\n for (const specifier of node.specifiers) {\n const imported = specifier.type === \"ImportDefaultSpecifier\" ? \"default\" : specifier.type === \"ImportSpecifier\" ? specifier.imported.type === \"Identifier\" ? specifier.imported.name : specifier.imported.value : specifier.type === \"ExportSpecifier\" ? specifier.local.type === \"Identifier\" ? specifier.local.name : specifier.local.value : void 0;\n if (imported !== void 0 && !names.includes(imported)) {\n throw new Error(\n `[worklet imports] ${info.id} imports unselected export ${imported} from ${source}`\n );\n }\n }\n }\n },\n async load(id) {\n const selected = modules.get(id);\n if (!selected) return;\n const outerContext = this;\n const innerEntry = \"\\0one-worklet-import-entry\";\n const bundle = await rolldown({\n cwd: nativeOptions.cwd,\n input: innerEntry,\n platform: \"neutral\",\n resolve: nativeOptions.resolve,\n transform: nativeOptions.transform,\n shimMissingExports: false,\n plugins: [\n {\n name: \"vxrn:pure-worklet-module\",\n resolveId(source, _importer, options) {\n if (source === innerEntry) return source;\n if (options.kind === \"dynamic-import\") {\n throw new Error(\n `[worklet imports] dynamic imports are unsupported in ${selected.entry}`\n );\n }\n rejectRuntimeDependency(source);\n },\n load(source) {\n if (source === innerEntry) {\n return `export { ${selected.names.map((name, index) => `${JSON.stringify(name)} as __export${index}`).join(\", \")} } from ${JSON.stringify(selected.entry)};`;\n }\n },\n moduleParsed(info) {\n rejectRuntimeDependency(info.id);\n if (isAbsolute(info.id)) outerContext.addWatchFile(info.id);\n if (info.packageJsonPath)\n outerContext.addWatchFile(info.packageJsonPath);\n }\n },\n hermesCompatSWCPlugin(false),\n hermesLoopsPlugin()\n ]\n });\n let code;\n try {\n const output = await bundle.generate({\n format: \"iife\",\n name: \"__oneWorkletBundle\"\n });\n const chunk = output.output[0];\n if (output.output.length !== 1 || chunk.type !== \"chunk\" || chunk.imports.length || chunk.dynamicImports.length) {\n throw new Error(\n `[worklet imports] ${selected.entry} must produce one self-contained JavaScript module`\n );\n }\n code = transformHermesLoops(chunk.code, id)?.code ?? chunk.code;\n for (const file of await bundle.watchFiles) {\n if (isAbsolute(file)) outerContext.addWatchFile(file);\n }\n } finally {\n await bundle.close();\n }\n const loader = `__oneLoadWorkletModule_${selected.key}`;\n const loaderCode = `function ${loader}() {\n 'worklet';\n const cache = globalThis.__oneWorkletImportCache || (globalThis.__oneWorkletImportCache = new WeakMap());\n let namespace = cache.get(${loader});\n if (namespace === undefined) {\n ${code}\n namespace = __oneWorkletBundle;\n cache.set(${loader}, namespace);\n }\n return namespace;\n}`;\n const parsed = parseSync(id, loaderCode, { lang: \"js\" });\n if (parsed.errors.length) throw new Error(parsed.errors[0].message);\n const captures = getClosureVariables(\n parsed.program.body[0],\n /* @__PURE__ */ new Set([...JS_GLOBALS, \"arguments\"])\n );\n if (captures.length) {\n throw new Error(\n `[worklet imports] ${selected.entry} requires unsupported runtime globals: ${captures.join(\", \")}`\n );\n }\n return `${loaderCode}\n${selected.names.map(\n (name, index) => `\nfunction __oneExport${index}(...args) {\n 'worklet';\n return (0, ${loader}().__export${index})(...args);\n}\nexport { __oneExport${index} as ${JSON.stringify(name)} };\n`\n ).join(\"\\n\")}`;\n }\n };\n return {\n ...nativeOptions,\n plugins: [instance, nativeOptions.plugins]\n };\n }\n };\n}\nexport {\n workletImportsPlugin\n};\n//# sourceMappingURL=workletImportsPlugin.js.map\n"],"mappings":";;;;;;;;;;AAQA,SAAS,qBAAqB,SAAS;CACrC,MAAM,aAAa,IAAI,IACrB,OAAO,QAAQ,OAAO,CAAC,CAAC,KAAK,CAAC,QAAQ,WAAW,CAAC,QAAQ,CAAC,GAAG,IAAI,IAAI,KAAK,CAAC,CAAC,CAAC,CAChF;CACA,MAAM,2BAA2B,WAAW;EAC1C,MAAM,aAAa,OAAO,Q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,MAAM,WAAW,oBACf,OAAO,QAAQ,KAAK,oBACJ,IAAI,IAAI,CAAC,GAAG,YAAY,WAAW,CAAC,CACtD;KACA,IAAI,SAAS,QAAQ;MACnB,MAAM,IAAI,MACR,qBAAqB,SAAS,MAAM,yCAAyC,SAAS,KAAK,IAAI,GACjG;KACF;KACA,OAAO,GAAG,WAAW;EAC7B,SAAS,MAAM,KACJ,MAAM,UAAU;sBACP,MAAM;;eAEb,OAAO,aAAa,MAAM;;sBAEnB,MAAM,MAAM,KAAK,UAAU,IAAI,EAAE;CAE7C,CAAC,CAAC,KAAK,IAAI;IACb;GACF;GACA,OAAO;IACL,GAAG;IACH,SAAS,CAAC,UAAU,cAAc,OAAO;GAC3C;EACF;CACF;AACF"}
1
+ {"version":3,"file":"workletImportsPlugin.js","names":[],"sources":["plugins/workletImportsPlugin.js"],"sourcesContent":["import { createHash } from \"node:crypto\";\nimport { isBuiltin } from \"node:module\";\nimport { dirname, isAbsolute, join } from \"node:path\";\nimport { statSync } from \"node:fs\";\nimport { rolldown } from \"rolldown\";\nimport { parseSync } from \"oxc-parser\";\nimport { createBackgroundWorkletModule } from \"../backgroundComputation\";\nimport { prepareBackgroundWorkletModule } from \"../backgroundComputationNative\";\nimport { hermesCompatSWCPlugin, hermesLoopsPlugin } from \"../utils/createNativeDevEngine\";\nfunction workletImportsPlugin(imports) {\n const selections = new Map(\n Object.entries(imports).map(([source, names]) => [source, [...new Set(names)]])\n );\n const rejectRuntimeDependency = (source) => {\n const normalized = source.replace(/\\\\/g, \"/\");\n if (isBuiltin(source) || /(?:^|\\/node_modules\\/)(?:react|react-native|react-native-worklets|react-native-reanimated)(?:\\/|$)/.test(\n normalized\n ) || /(?:^|\\/node_modules\\/)@react-native\\//.test(normalized)) {\n throw new Error(\n `[worklet imports] runtime dependency ${source} is not pure JavaScript`\n );\n }\n };\n return {\n name: \"vxrn:worklet-imports\",\n options(nativeOptions) {\n const modules = /* @__PURE__ */ new Map();\n const instance = {\n name: \"vxrn:worklet-imports:bundle\",\n async resolveId(source, importer, options) {\n const marker = \"?one-background=\";\n const selected = source.indexOf(marker);\n const names = selected < 0 ? selections.get(source) : [decodeURIComponent(source.slice(selected + marker.length))];\n if (!names) return;\n if (!names.length)\n throw new Error(`[worklet imports] no exports selected for ${source}`);\n if (options.kind !== \"import-statement\") {\n throw new Error(`[worklet imports] ${source} requires a static ESM import`);\n }\n rejectRuntimeDependency(source);\n const resolved = await this.resolve(\n selected < 0 ? source : source.slice(0, selected),\n importer,\n { skipSelf: true }\n );\n if (!resolved || resolved.external || !isAbsolute(resolved.id) || !statSync(resolved.id, { throwIfNoEntry: false })?.isFile()) {\n throw new Error(\n `[worklet imports] ${source} must resolve to a JavaScript file`\n );\n }\n rejectRuntimeDependency(resolved.id);\n const key = createHash(\"sha256\").update(JSON.stringify([resolved.id, names])).digest(\"hex\").slice(0, 16);\n const id = join(dirname(resolved.id), `__one_worklet_imports_${key}.js`);\n modules.set(id, { entry: resolved.id, names, key });\n return id;\n },\n moduleParsed(info) {\n if (!info.code || ![...selections.keys()].some((source) => info.code.includes(source)))\n return;\n const { program, errors } = parseSync(info.id, info.code, {\n lang: /\\.[cm]?ts$/.test(info.id) ? \"ts\" : info.id.endsWith(\".tsx\") ? \"tsx\" : \"jsx\"\n });\n if (errors.length) throw new Error(errors[0].message);\n for (const node of program.body) {\n if (node.type !== \"ImportDeclaration\" && node.type !== \"ExportNamedDeclaration\")\n continue;\n const source = node.source?.value;\n if (!source) continue;\n const names = selections.get(source);\n if (!names) continue;\n for (const specifier of node.specifiers) {\n const imported = specifier.type === \"ImportDefaultSpecifier\" ? \"default\" : specifier.type === \"ImportSpecifier\" ? specifier.imported.type === \"Identifier\" ? specifier.imported.name : specifier.imported.value : specifier.type === \"ExportSpecifier\" ? specifier.local.type === \"Identifier\" ? specifier.local.name : specifier.local.value : void 0;\n if (imported !== void 0 && !names.includes(imported)) {\n throw new Error(\n `[worklet imports] ${info.id} imports unselected export ${imported} from ${source}`\n );\n }\n }\n }\n },\n async load(id) {\n const selected = modules.get(id);\n if (!selected) return;\n const outerContext = this;\n const innerEntry = \"\\0one-worklet-import-entry\";\n const bundle = await rolldown({\n cwd: nativeOptions.cwd,\n input: innerEntry,\n platform: \"neutral\",\n resolve: nativeOptions.resolve,\n transform: nativeOptions.transform,\n shimMissingExports: false,\n plugins: [\n {\n name: \"vxrn:pure-worklet-module\",\n resolveId(source, _importer, options) {\n if (source === innerEntry) return source;\n if (options.kind === \"dynamic-import\") {\n throw new Error(\n `[worklet imports] dynamic imports are unsupported in ${selected.entry}`\n );\n }\n rejectRuntimeDependency(source);\n },\n load(source) {\n if (source === innerEntry) {\n return `export { ${selected.names.map((name, index) => `${JSON.stringify(name)} as __export${index}`).join(\", \")} } from ${JSON.stringify(selected.entry)};`;\n }\n },\n moduleParsed(info) {\n rejectRuntimeDependency(info.id);\n if (isAbsolute(info.id)) outerContext.addWatchFile(info.id);\n if (info.packageJsonPath)\n outerContext.addWatchFile(info.packageJsonPath);\n }\n },\n hermesCompatSWCPlugin(false),\n hermesLoopsPlugin()\n ]\n });\n let code;\n try {\n const output = await bundle.generate({\n format: \"iife\",\n name: \"__oneWorkletBundle\"\n });\n const chunk = output.output[0];\n if (output.output.length !== 1 || chunk.type !== \"chunk\" || chunk.imports.length || chunk.dynamicImports.length) {\n throw new Error(\n `[worklet imports] ${selected.entry} must produce one self-contained JavaScript module`\n );\n }\n code = chunk.code;\n for (const file of await bundle.watchFiles) {\n if (isAbsolute(file)) outerContext.addWatchFile(file);\n }\n } finally {\n await bundle.close();\n }\n const moduleSource = createBackgroundWorkletModule(\n code,\n selected.names,\n selected.key\n );\n return prepareBackgroundWorkletModule(moduleSource, selected.entry);\n }\n };\n return {\n ...nativeOptions,\n plugins: [instance, nativeOptions.plugins]\n };\n }\n };\n}\nexport {\n workletImportsPlugin\n};\n//# sourceMappingURL=workletImportsPlugin.js.map\n"],"mappings":";;;;;;;;;;;AASA,SAAS,qBAAqB,SAAS;CACrC,MAAM,a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aAAa,IAAI;MACtD;KACF,UAAU;MACR,MAAM,OAAO,MAAM;KACrB;KACA,MAAM,eAAe,8BACnB,MACA,SAAS,OACT,SAAS,GACX;KACA,OAAO,+BAA+B,cAAc,SAAS,KAAK;IACpE;GACF;GACA,OAAO;IACL,GAAG;IACH,SAAS,CAAC,UAAU,cAAc,OAAO;GAC3C;EACF;CACF;AACF"}
@@ -4,7 +4,8 @@ import { dirname, isAbsolute, join } from "path";
4
4
  import { statSync } from "fs";
5
5
  import { rolldown } from "rolldown";
6
6
  import { parseSync } from "oxc-parser";
7
- import { JS_GLOBALS, getClosureVariables, transformHermesLoops } from "@vxrn/compiler";
7
+ import { createBackgroundWorkletModule } from "../backgroundComputation.native.js";
8
+ import { prepareBackgroundWorkletModule } from "../backgroundComputationNative.native.js";
8
9
  import { hermesCompatSWCPlugin, hermesLoopsPlugin } from "../utils/createNativeDevEngine.native.js";
9
10
 
10
11
  function workletImportsPlugin(imports) {
@@ -12,7 +13,7 @@ function workletImportsPlugin(imports) {
12
13
  var [source, names] = param;
13
14
  return [source, [...new Set(names)]];
14
15
  }));
15
- var rejectRuntimeDependency = function(source) {
16
+ var rejectRuntimeDependency = function rejectRuntimeDependency2(source) {
16
17
  var normalized = source.replace(/\\/g, "/");
17
18
  if (isBuiltin(source) || /(?:^|\/node_modules\/)(?:react|react-native|react-native-worklets|react-native-reanimated)(?:\/|$)/.test(normalized) || /(?:^|\/node_modules\/)@react-native\//.test(normalized)) {
18
19
  throw new Error(`[worklet imports] runtime dependency ${source} is not pure JavaScript`);
@@ -26,14 +27,16 @@ function workletImportsPlugin(imports) {
26
27
  name: "vxrn:worklet-imports:bundle",
27
28
  async resolveId(source, importer, options) {
28
29
  var _statSync;
29
- var names = selections.get(source);
30
+ var marker = "?one-background=";
31
+ var selected = source.indexOf(marker);
32
+ var names = selected < 0 ? selections.get(source) : [decodeURIComponent(source.slice(selected + marker.length))];
30
33
  if (!names) return;
31
34
  if (!names.length) throw new Error(`[worklet imports] no exports selected for ${source}`);
32
35
  if (options.kind !== "import-statement") {
33
36
  throw new Error(`[worklet imports] ${source} requires a static ESM import`);
34
37
  }
35
38
  rejectRuntimeDependency(source);
36
- var resolved = await this.resolve(source, importer, { skipSelf: true });
39
+ var resolved = await this.resolve(selected < 0 ? source : source.slice(0, selected), importer, { skipSelf: true });
37
40
  if (!resolved || resolved.external || !isAbsolute(resolved.id) || !((_statSync = statSync(resolved.id, { throwIfNoEntry: false })) === null || _statSync === void 0 ? void 0 : _statSync.isFile())) {
38
41
  throw new Error(`[worklet imports] ${source} must resolve to a JavaScript file`);
39
42
  }
@@ -143,8 +146,6 @@ function workletImportsPlugin(imports) {
143
146
  });
144
147
  var code;
145
148
  try {
146
- var _ref;
147
- var _transformHermesLoops;
148
149
  var output = await bundle.generate({
149
150
  format: "iife",
150
151
  name: "__oneWorkletBundle"
@@ -153,7 +154,7 @@ function workletImportsPlugin(imports) {
153
154
  if (output.output.length !== 1 || chunk.type !== "chunk" || chunk.imports.length || chunk.dynamicImports.length) {
154
155
  throw new Error(`[worklet imports] ${selected.entry} must produce one self-contained JavaScript module`);
155
156
  }
156
- code = (_ref = (_transformHermesLoops = transformHermesLoops(chunk.code, id)) === null || _transformHermesLoops === void 0 ? void 0 : _transformHermesLoops.code) !== null && _ref !== void 0 ? _ref : chunk.code;
157
+ code = chunk.code;
157
158
  var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
158
159
  try {
159
160
  for (var _iterator = (await bundle.watchFiles)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
@@ -177,34 +178,8 @@ function workletImportsPlugin(imports) {
177
178
  } finally {
178
179
  await bundle.close();
179
180
  }
180
- var loader = `__oneLoadWorkletModule_${selected.key}`;
181
- var loaderCode = `function ${loader}() {
182
- 'worklet';
183
- const cache = globalThis.__oneWorkletImportCache || (globalThis.__oneWorkletImportCache = new WeakMap());
184
- let namespace = cache.get(${loader});
185
- if (namespace === undefined) {
186
- ${code}
187
- namespace = __oneWorkletBundle;
188
- cache.set(${loader}, namespace);
189
- }
190
- return namespace;
191
- }`;
192
- var parsed = parseSync(id, loaderCode, { lang: "js" });
193
- if (parsed.errors.length) throw new Error(parsed.errors[0].message);
194
- var captures = getClosureVariables(parsed.program.body[0], /* @__PURE__ */ new Set([...JS_GLOBALS, "arguments"]));
195
- if (captures.length) {
196
- throw new Error(`[worklet imports] ${selected.entry} requires unsupported runtime globals: ${captures.join(", ")}`);
197
- }
198
- return `${loaderCode}
199
- ${selected.names.map(function(name, index) {
200
- return `
201
- function __oneExport${index}(...args) {
202
- 'worklet';
203
- return (0, ${loader}().__export${index})(...args);
204
- }
205
- export { __oneExport${index} as ${JSON.stringify(name)} };
206
- `;
207
- }).join("\n")}`;
181
+ var moduleSource = createBackgroundWorkletModule(code, selected.names, selected.key);
182
+ return prepareBackgroundWorkletModule(moduleSource, selected.entry);
208
183
  }
209
184
  };
210
185
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"workletImportsPlugin.native.js","names":[],"sources":["plugins/workletImportsPlugin.native.js"],"sourcesContent":["import { createHash } from \"crypto\";\nimport { isBuiltin } from \"module\";\nimport { dirname, isAbsolute, join } from \"path\";\nimport { statSync } from \"fs\";\nimport { rolldown } from \"rolldown\";\nimport { parseSync } from \"oxc-parser\";\nimport { getClosureVariables, JS_GLOBALS, transformHermesLoops } from \"@vxrn/compiler\";\nimport { hermesCompatSWCPlugin, hermesLoopsPlugin } from \"../utils/createNativeDevEngine\";\nfunction workletImportsPlugin(imports) {\n var selections = new Map(Object.entries(imports).map(function(param) {\n var [source, names] = param;\n return [\n source,\n [\n ...new Set(names)\n ]\n ];\n }));\n var rejectRuntimeDependency = function(source) {\n var normalized = source.replace(/\\\\/g, \"/\");\n if (isBuiltin(source) || /(?:^|\\/node_modules\\/)(?:react|react-native|react-native-worklets|react-native-reanimated)(?:\\/|$)/.test(normalized) || /(?:^|\\/node_modules\\/)@react-native\\//.test(normalized)) {\n throw new Error(`[worklet imports] runtime dependency ${source} is not pure JavaScript`);\n }\n };\n return {\n name: \"vxrn:worklet-imports\",\n options(nativeOptions) {\n var modules = /* @__PURE__ */ new Map();\n var instance = {\n name: \"vxrn:worklet-imports:bundle\",\n async resolveId(source, importer, options) {\n var _statSync;\n var names = selections.get(source);\n if (!names) return;\n if (!names.length) throw new Error(`[worklet imports] no exports selected for ${source}`);\n if (options.kind !== \"import-statement\") {\n throw new Error(`[worklet imports] ${source} requires a static ESM import`);\n }\n rejectRuntimeDependency(source);\n var resolved = await this.resolve(source, importer, {\n skipSelf: true\n });\n if (!resolved || resolved.external || !isAbsolute(resolved.id) || !((_statSync = statSync(resolved.id, {\n throwIfNoEntry: false\n })) === null || _statSync === void 0 ? void 0 : _statSync.isFile())) {\n throw new Error(`[worklet imports] ${source} must resolve to a JavaScript file`);\n }\n rejectRuntimeDependency(resolved.id);\n var key = createHash(\"sha256\").update(JSON.stringify([\n resolved.id,\n names\n ])).digest(\"hex\").slice(0, 16);\n var id = join(dirname(resolved.id), `__one_worklet_imports_${key}.js`);\n modules.set(id, {\n entry: resolved.id,\n names,\n key\n });\n return id;\n },\n moduleParsed(info) {\n if (!info.code || ![\n ...selections.keys()\n ].some(function(source2) {\n return info.code.includes(source2);\n })) return;\n var { program, errors } = parseSync(info.id, info.code, {\n lang: /\\.[cm]?ts$/.test(info.id) ? \"ts\" : info.id.endsWith(\".tsx\") ? \"tsx\" : \"jsx\"\n });\n if (errors.length) throw new Error(errors[0].message);\n var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;\n try {\n for (var _iterator = program.body[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {\n var node = _step.value;\n var _node_source;\n if (node.type !== \"ImportDeclaration\" && node.type !== \"ExportNamedDeclaration\") continue;\n var source = (_node_source = node.source) === null || _node_source === void 0 ? void 0 : _node_source.value;\n if (!source) continue;\n var names = selections.get(source);\n if (!names) continue;\n var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = void 0;\n try {\n for (var _iterator1 = node.specifiers[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true) {\n var specifier = _step1.value;\n var imported = specifier.type === \"ImportDefaultSpecifier\" ? \"default\" : specifier.type === \"ImportSpecifier\" ? specifier.imported.type === \"Identifier\" ? specifier.imported.name : specifier.imported.value : specifier.type === \"ExportSpecifier\" ? specifier.local.type === \"Identifier\" ? specifier.local.name : specifier.local.value : void 0;\n if (imported !== void 0 && !names.includes(imported)) {\n throw new Error(`[worklet imports] ${info.id} imports unselected export ${imported} from ${source}`);\n }\n }\n } catch (err) {\n _didIteratorError1 = true;\n _iteratorError1 = err;\n } finally {\n try {\n if (!_iteratorNormalCompletion1 && _iterator1.return != null) {\n _iterator1.return();\n }\n } finally {\n if (_didIteratorError1) {\n throw _iteratorError1;\n }\n }\n }\n }\n } catch (err) {\n _didIteratorError = true;\n _iteratorError = err;\n } finally {\n try {\n if (!_iteratorNormalCompletion && _iterator.return != null) {\n _iterator.return();\n }\n } finally {\n if (_didIteratorError) {\n throw _iteratorError;\n }\n }\n }\n },\n async load(id) {\n var selected = modules.get(id);\n if (!selected) return;\n var outerContext = this;\n var innerEntry = \"\\0one-worklet-import-entry\";\n var bundle = await rolldown({\n cwd: nativeOptions.cwd,\n input: innerEntry,\n platform: \"neutral\",\n resolve: nativeOptions.resolve,\n transform: nativeOptions.transform,\n shimMissingExports: false,\n plugins: [\n {\n name: \"vxrn:pure-worklet-module\",\n resolveId(source, _importer, options) {\n if (source === innerEntry) return source;\n if (options.kind === \"dynamic-import\") {\n throw new Error(`[worklet imports] dynamic imports are unsupported in ${selected.entry}`);\n }\n rejectRuntimeDependency(source);\n },\n load(source) {\n if (source === innerEntry) {\n return `export { ${selected.names.map(function(name, index) {\n return `${JSON.stringify(name)} as __export${index}`;\n }).join(\", \")} } from ${JSON.stringify(selected.entry)};`;\n }\n },\n moduleParsed(info) {\n rejectRuntimeDependency(info.id);\n if (isAbsolute(info.id)) outerContext.addWatchFile(info.id);\n if (info.packageJsonPath) outerContext.addWatchFile(info.packageJsonPath);\n }\n },\n hermesCompatSWCPlugin(false),\n hermesLoopsPlugin()\n ]\n });\n var code;\n try {\n var _ref;\n var _transformHermesLoops;\n var output = await bundle.generate({\n format: \"iife\",\n name: \"__oneWorkletBundle\"\n });\n var chunk = output.output[0];\n if (output.output.length !== 1 || chunk.type !== \"chunk\" || chunk.imports.length || chunk.dynamicImports.length) {\n throw new Error(`[worklet imports] ${selected.entry} must produce one self-contained JavaScript module`);\n }\n code = (_ref = (_transformHermesLoops = transformHermesLoops(chunk.code, id)) === null || _transformHermesLoops === void 0 ? void 0 : _transformHermesLoops.code) !== null && _ref !== void 0 ? _ref : chunk.code;\n var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;\n try {\n for (var _iterator = (await bundle.watchFiles)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {\n var file = _step.value;\n if (isAbsolute(file)) outerContext.addWatchFile(file);\n }\n } catch (err) {\n _didIteratorError = true;\n _iteratorError = err;\n } finally {\n try {\n if (!_iteratorNormalCompletion && _iterator.return != null) {\n _iterator.return();\n }\n } finally {\n if (_didIteratorError) {\n throw _iteratorError;\n }\n }\n }\n } finally {\n await bundle.close();\n }\n var loader = `__oneLoadWorkletModule_${selected.key}`;\n var loaderCode = `function ${loader}() {\n 'worklet';\n const cache = globalThis.__oneWorkletImportCache || (globalThis.__oneWorkletImportCache = new WeakMap());\n let namespace = cache.get(${loader});\n if (namespace === undefined) {\n ${code}\n namespace = __oneWorkletBundle;\n cache.set(${loader}, namespace);\n }\n return namespace;\n}`;\n var parsed = parseSync(id, loaderCode, {\n lang: \"js\"\n });\n if (parsed.errors.length) throw new Error(parsed.errors[0].message);\n var captures = getClosureVariables(parsed.program.body[0], /* @__PURE__ */ new Set([\n ...JS_GLOBALS,\n \"arguments\"\n ]));\n if (captures.length) {\n throw new Error(`[worklet imports] ${selected.entry} requires unsupported runtime globals: ${captures.join(\", \")}`);\n }\n return `${loaderCode}\n${selected.names.map(function(name, index) {\n return `\nfunction __oneExport${index}(...args) {\n 'worklet';\n return (0, ${loader}().__export${index})(...args);\n}\nexport { __oneExport${index} as ${JSON.stringify(name)} };\n`;\n }).join(\"\\n\")}`;\n }\n };\n return {\n ...nativeOptions,\n plugins: [\n instance,\n nativeOptions.plugins\n ]\n };\n }\n };\n}\nexport {\n workletImportsPlugin\n};\n//# sourceMappingURL=workletImportsPlugin.js.map\n"],"mappings":";;;;;;;;;;AAQA,SAAS,qBAAqB,SAAS;CACrC,IAAI,aAAa,IAAI,IAAI,OAAO,QAAQ,OAAO,CAAC,CAAC,IAAI,SAAS,OAAO;EACnE,IAAI,CAAC,QAAQ,SAAS;EACtB,OAAO,CACL,QACA,CACE,GAAG,IAAI,IAAI,KAAK,CAClB,CACF;CACF,CAAC,CAAC;CACF,IAAI,0BAA0B,SAAS,QAAQ;EAC7C,IAAI,aAAa,OAAO,QAAQ,OAAO,GAAG;EAC1C,IAAI,UAAU,MAAM,KAAK,qGAAqG,KAAK,UAAU,KAAK,wCAAwC,KAAK,UAAU,GAAG;GAC1M,MAAM,IAAI,MAAM,wCAAwC,OAAO,wBAAwB;EACzF;CACF;CACA,OAAO;EACL,MAAM;EACN,QAAQ,eAAe;GACrB,IAAI,0BAA0B,IAAI,IAAI;GACtC,IAAI,WAAW;IACb,MAAM;IACN,MAAM,UAAU,QAAQ,UAAU,SAAS;KACzC,IAAI;KACJ,IAAI,QAAQ,WAAW,IAAI,MAAM;KACjC,IAAI,CAAC,OAAO;KACZ,IAAI,CAAC,MAAM,QAAQ,MAAM,IAAI,MAAM,6CAA6C,QAAQ;KACxF,IAAI,QAAQ,SAAS,oBAAoB;MACvC,MAAM,IAAI,MAAM,qBAAqB,OAAO,8BAA8B;KAC5E;KACA,wBAAw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MAAM,MAAM,KAAK,UAAU,IAAI,EAAE;;KAE7C,CAAC,CAAC,CAAC,KAAK,IAAI;IACd;GACF;GACA,OAAO;IACL,GAAG;IACH,SAAS,CACP,UACA,cAAc,OAChB;GACF;EACF;CACF;AACF"}
1
+ {"version":3,"file":"workletImportsPlugin.native.js","names":[],"sources":["plugins/workletImportsPlugin.native.js"],"sourcesContent":["import { createHash } from \"crypto\";\nimport { isBuiltin } from \"module\";\nimport { dirname, isAbsolute, join } from \"path\";\nimport { statSync } from \"fs\";\nimport { rolldown } from \"rolldown\";\nimport { parseSync } from \"oxc-parser\";\nimport { createBackgroundWorkletModule } from \"../backgroundComputation\";\nimport { prepareBackgroundWorkletModule } from \"../backgroundComputationNative\";\nimport { hermesCompatSWCPlugin, hermesLoopsPlugin } from \"../utils/createNativeDevEngine\";\nfunction workletImportsPlugin(imports) {\n var selections = new Map(Object.entries(imports).map(function(param) {\n var [source, names] = param;\n return [\n source,\n [\n ...new Set(names)\n ]\n ];\n }));\n var rejectRuntimeDependency = function rejectRuntimeDependency2(source) {\n var normalized = source.replace(/\\\\/g, \"/\");\n if (isBuiltin(source) || /(?:^|\\/node_modules\\/)(?:react|react-native|react-native-worklets|react-native-reanimated)(?:\\/|$)/.test(normalized) || /(?:^|\\/node_modules\\/)@react-native\\//.test(normalized)) {\n throw new Error(`[worklet imports] runtime dependency ${source} is not pure JavaScript`);\n }\n };\n return {\n name: \"vxrn:worklet-imports\",\n options(nativeOptions) {\n var modules = /* @__PURE__ */ new Map();\n var instance = {\n name: \"vxrn:worklet-imports:bundle\",\n async resolveId(source, importer, options) {\n var _statSync;\n var marker = \"?one-background=\";\n var selected = source.indexOf(marker);\n var names = selected < 0 ? selections.get(source) : [\n decodeURIComponent(source.slice(selected + marker.length))\n ];\n if (!names) return;\n if (!names.length) throw new Error(`[worklet imports] no exports selected for ${source}`);\n if (options.kind !== \"import-statement\") {\n throw new Error(`[worklet imports] ${source} requires a static ESM import`);\n }\n rejectRuntimeDependency(source);\n var resolved = await this.resolve(selected < 0 ? source : source.slice(0, selected), importer, {\n skipSelf: true\n });\n if (!resolved || resolved.external || !isAbsolute(resolved.id) || !((_statSync = statSync(resolved.id, {\n throwIfNoEntry: false\n })) === null || _statSync === void 0 ? void 0 : _statSync.isFile())) {\n throw new Error(`[worklet imports] ${source} must resolve to a JavaScript file`);\n }\n rejectRuntimeDependency(resolved.id);\n var key = createHash(\"sha256\").update(JSON.stringify([\n resolved.id,\n names\n ])).digest(\"hex\").slice(0, 16);\n var id = join(dirname(resolved.id), `__one_worklet_imports_${key}.js`);\n modules.set(id, {\n entry: resolved.id,\n names,\n key\n });\n return id;\n },\n moduleParsed(info) {\n if (!info.code || ![\n ...selections.keys()\n ].some(function(source2) {\n return info.code.includes(source2);\n })) return;\n var { program, errors } = parseSync(info.id, info.code, {\n lang: /\\.[cm]?ts$/.test(info.id) ? \"ts\" : info.id.endsWith(\".tsx\") ? \"tsx\" : \"jsx\"\n });\n if (errors.length) throw new Error(errors[0].message);\n var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;\n try {\n for (var _iterator = program.body[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {\n var node = _step.value;\n var _node_source;\n if (node.type !== \"ImportDeclaration\" && node.type !== \"ExportNamedDeclaration\") continue;\n var source = (_node_source = node.source) === null || _node_source === void 0 ? void 0 : _node_source.value;\n if (!source) continue;\n var names = selections.get(source);\n if (!names) continue;\n var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = void 0;\n try {\n for (var _iterator1 = node.specifiers[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true) {\n var specifier = _step1.value;\n var imported = specifier.type === \"ImportDefaultSpecifier\" ? \"default\" : specifier.type === \"ImportSpecifier\" ? specifier.imported.type === \"Identifier\" ? specifier.imported.name : specifier.imported.value : specifier.type === \"ExportSpecifier\" ? specifier.local.type === \"Identifier\" ? specifier.local.name : specifier.local.value : void 0;\n if (imported !== void 0 && !names.includes(imported)) {\n throw new Error(`[worklet imports] ${info.id} imports unselected export ${imported} from ${source}`);\n }\n }\n } catch (err) {\n _didIteratorError1 = true;\n _iteratorError1 = err;\n } finally {\n try {\n if (!_iteratorNormalCompletion1 && _iterator1.return != null) {\n _iterator1.return();\n }\n } finally {\n if (_didIteratorError1) {\n throw _iteratorError1;\n }\n }\n }\n }\n } catch (err) {\n _didIteratorError = true;\n _iteratorError = err;\n } finally {\n try {\n if (!_iteratorNormalCompletion && _iterator.return != null) {\n _iterator.return();\n }\n } finally {\n if (_didIteratorError) {\n throw _iteratorError;\n }\n }\n }\n },\n async load(id) {\n var selected = modules.get(id);\n if (!selected) return;\n var outerContext = this;\n var innerEntry = \"\\0one-worklet-import-entry\";\n var bundle = await rolldown({\n cwd: nativeOptions.cwd,\n input: innerEntry,\n platform: \"neutral\",\n resolve: nativeOptions.resolve,\n transform: nativeOptions.transform,\n shimMissingExports: false,\n plugins: [\n {\n name: \"vxrn:pure-worklet-module\",\n resolveId(source, _importer, options) {\n if (source === innerEntry) return source;\n if (options.kind === \"dynamic-import\") {\n throw new Error(`[worklet imports] dynamic imports are unsupported in ${selected.entry}`);\n }\n rejectRuntimeDependency(source);\n },\n load(source) {\n if (source === innerEntry) {\n return `export { ${selected.names.map(function(name, index) {\n return `${JSON.stringify(name)} as __export${index}`;\n }).join(\", \")} } from ${JSON.stringify(selected.entry)};`;\n }\n },\n moduleParsed(info) {\n rejectRuntimeDependency(info.id);\n if (isAbsolute(info.id)) outerContext.addWatchFile(info.id);\n if (info.packageJsonPath) outerContext.addWatchFile(info.packageJsonPath);\n }\n },\n hermesCompatSWCPlugin(false),\n hermesLoopsPlugin()\n ]\n });\n var code;\n try {\n var output = await bundle.generate({\n format: \"iife\",\n name: \"__oneWorkletBundle\"\n });\n var chunk = output.output[0];\n if (output.output.length !== 1 || chunk.type !== \"chunk\" || chunk.imports.length || chunk.dynamicImports.length) {\n throw new Error(`[worklet imports] ${selected.entry} must produce one self-contained JavaScript module`);\n }\n code = chunk.code;\n var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;\n try {\n for (var _iterator = (await bundle.watchFiles)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {\n var file = _step.value;\n if (isAbsolute(file)) outerContext.addWatchFile(file);\n }\n } catch (err) {\n _didIteratorError = true;\n _iteratorError = err;\n } finally {\n try {\n if (!_iteratorNormalCompletion && _iterator.return != null) {\n _iterator.return();\n }\n } finally {\n if (_didIteratorError) {\n throw _iteratorError;\n }\n }\n }\n } finally {\n await bundle.close();\n }\n var moduleSource = createBackgroundWorkletModule(code, selected.names, selected.key);\n return prepareBackgroundWorkletModule(moduleSource, selected.entry);\n }\n };\n return {\n ...nativeOptions,\n plugins: [\n instance,\n nativeOptions.plugins\n ]\n };\n }\n };\n}\nexport {\n workletImportsPlugin\n};\n//# sourceMappingURL=workletImportsPlugin.js.map\n"],"mappings":";;;;;;;;;;;AASA,SAAS,qBAAqB,SAAS;CACrC,IAAI,aAAa,IAAI,IAAI,OAAO,QAAQ,OAAO,CAAC,CAAC,IAAI,SAAS,OAAO;EACnE,IAAI,CAAC,QAAQ,SAAS;EACtB,OAAO,CACL,QACA,CACE,GAAG,IAAI,IAAI,KAAK,CAClB,CACF;CACF,CAAC,CAAC;CACF,IAAI,0BAA0B,SAAS,yBAAyB,QAAQ;EACtE,IAAI,aAAa,OAAO,QAAQ,OAAO,GAAG;EAC1C,IAAI,UAAU,MAAM,KAAK,qGAAqG,KAAK,UAAU,KAAK,wCAAwC,KAAK,UAAU,GAAG;GAC1M,MAAM,IAAI,MAAM,wCAAwC,OAAO,wBAAwB;EACzF;CACF;CACA,OAAO;EACL,MAAM;EACN,QAAQ,eAAe;GACrB,IAAI,0BAA0B,IAAI,IAAI;GACtC,IAAI,WAAW;IACb,MAAM;IACN,MAAM,U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AAI,KAAK,iBAAiB,aAAa,aAAa,KAAK,eAAe;QAC1E;OACF;OACA,sBAAsB,KAAK;OAC3B,kBAAkB;MACpB;KACF,CAAC;KACD,IAAI;KACJ,IAAI;MACF,IAAI,SAAS,MAAM,OAAO,SAAS;OACjC,QAAQ;OACR,MAAM;MACR,CAAC;MACD,IAAI,QAAQ,OAAO,OAAO;MAC1B,IAAI,OAAO,OAAO,WAAW,KAAK,MAAM,SAAS,WAAW,MAAM,QAAQ,UAAU,MAAM,eAAe,QAAQ;OAC/G,MAAM,IAAI,MAAM,qBAAqB,SAAS,MAAM,mDAAmD;MACzG;MACA,OAAO,MAAM;MACb,IAAI,4BAA4B,MAAM,oBAAoB,OAAO,iBAAiB,KAAK;MACvF,IAAI;OACF,KAAK,IAAI,aAAa,MAAM,OAAO,WAAU,CAAE,OAAO,SAAS,CAAC,GAAG,OAAO,EAAE,6BAA6B,QAAQ,UAAU,KAAK,EAAC,CAAE,OAAO,4BAA4B,MAAM;QAC1K,IAAI,OAAO,MAAM;QACjB,IAAI,WAAW,IAAI,GAAG,aAAa,aAAa,IAAI;OACtD;MACF,SAAS,KAAK;OACZ,oBAAoB;OACpB,iBAAiB;MACnB,UAAU;OACR,IAAI;QACF,IAAI,CAAC,6BAA6B,UAAU,UAAU,MAAM;SAC1D,UAAU,OAAO;QACnB;OACF,UAAU;QACR,IAAI,mBAAmB;SACrB,MAAM;QACR;OACF;MACF;KACF,UAAU;MACR,MAAM,OAAO,MAAM;KACrB;KACA,IAAI,eAAe,8BAA8B,MAAM,SAAS,OAAO,SAAS,GAAG;KACnF,OAAO,+BAA+B,cAAc,SAAS,KAAK;IACpE;GACF;GACA,OAAO;IACL,GAAG;IACH,SAAS,CACP,UACA,cAAc,OAChB;GACF;EACF;CACF;AACF"}
@@ -41,15 +41,15 @@ async function buildBundle(_argv, ctx, args, bundleImpl = null) {
41
41
  });
42
42
  const builtBundle = result.code;
43
43
  if (result.map && args.sourcemapOutput) {
44
- FSExtra.writeFileSync(args.sourcemapOutput, result.map, { encoding: "utf8" });
44
+ FSExtra.outputFileSync(args.sourcemapOutput, result.map, { encoding: "utf8" });
45
45
  }
46
46
  console.info(`Writing bundle to ${bundleOutput}...`);
47
- FSExtra.writeFileSync(bundleOutput, builtBundle, { encoding: bundleEncoding });
47
+ FSExtra.outputFileSync(bundleOutput, builtBundle, { encoding: bundleEncoding });
48
48
  console.info("Done.");
49
49
  setTimeout(() => {
50
50
  console.info("Exiting process to prevent hanging.");
51
51
  process.exit();
52
- }, 3e4);
52
+ }, 3e4).unref();
53
53
  }
54
54
 
55
55
  export { buildBundle };
@@ -1 +1 @@
1
- {"version":3,"file":"buildBundle.js","names":["metroBundle"],"sources":["rn-commands/bundle/buildBundle.js"],"sourcesContent":["import FSExtra from \"fs-extra\";\nimport { clearTransformCache } from \"@vxrn/compiler\";\nimport {\n bundle as metroBundle\n} from \"@vxrn/vite-plugin-metro/rn-commands\";\nimport { loadEnv } from \"../../exports/loadEnv\";\nimport { buildNativeBundle } from \"../../utils/createNativeDevEngine\";\nasync function buildBundle(_argv, ctx, args, bundleImpl = null) {\n const {\n platform,\n // Android is not supported yet.\n dev,\n bundleOutput,\n // React Native's `--bundle-encoding` names a Node Buffer encoding.\n bundleEncoding = \"utf8\",\n assetsDest,\n // `--minify` overrides React Native's default of \"minify unless this is a\n // dev bundle\". undefined means the flag was not passed.\n minify,\n // `--reset-cache` drops the compiler's transform cache, the only cache a\n // rolldown production build reads.\n resetCache\n // `--entry-file` is a placeholder in generated native projects. VxRN apps\n // configure entries.native through vxrn/react-native-commands, while One\n // generates its native entry from the route tree.\n // `--read-global-cache` / `--max-workers` / `--config` / `--transformer` /\n // `--resolver-option` configure Metro's global cache, worker pool and\n // resolver. A rolldown production build has none of them: it transforms\n // from source in-process. React Native's own bundle command ignores\n // `--read-global-cache` too.\n // `--unstable-transform-profile` picks a JS engine to target. This pipeline\n // always downlevels for Hermes, which is what every profile it accepts\n // ('default', 'hermes', 'hermes-canary') can run.\n // `--sourcemap-use-absolute-path`, `--sourcemap-sources-root`,\n // `--asset-catalog-dest` and `--indexed-ram-bundle` are not implemented.\n } = args;\n const { root } = ctx;\n if (typeof root !== \"string\") {\n throw new Error(`Expected ctx.root to be a string, but got ${typeof root}`);\n }\n const metroBuildBundleFn = await metroBundle.getBuildBundleFn();\n if (metroBuildBundleFn) {\n console.info(\"Using @vxrn/vite-plugin-metro to build the bundle.\");\n await metroBuildBundleFn(_argv, ctx, args, bundleImpl);\n return;\n }\n process.env.IS_VXRN_CLI = \"true\";\n loadEnv(dev ? \"development\" : \"production\", root);\n if (!dev) {\n process.env.NODE_ENV = \"production\";\n }\n if (resetCache) {\n clearTransformCache();\n }\n console.info(`[vxrn] building native bundle for ${platform}...`);\n const nativeEntryFile = ctx.vxrnEntries?.native;\n if (nativeEntryFile !== void 0 && typeof nativeEntryFile !== \"string\") {\n throw new Error(\"Expected entries.native to be a string\");\n }\n const result = await buildNativeBundle({\n root,\n platform,\n dev,\n entryFile: nativeEntryFile,\n // pass through ONE_SERVER_URL so the native prelude can inject it into\n // process.env. without this, getURL.native falls back to the dummy\n // 'http://one-server.example.com' and runtime loader fetches fail in prod.\n serverUrl: process.env.ONE_SERVER_URL,\n assetsDest,\n sourcemap: !!args.sourcemapOutput,\n minify\n });\n const builtBundle = result.code;\n if (result.map && args.sourcemapOutput) {\n FSExtra.writeFileSync(args.sourcemapOutput, result.map, { encoding: \"utf8\" });\n }\n console.info(`Writing bundle to ${bundleOutput}...`);\n FSExtra.writeFileSync(bundleOutput, builtBundle, { encoding: bundleEncoding });\n console.info(\"Done.\");\n setTimeout(() => {\n console.info(\"Exiting process to prevent hanging.\");\n process.exit();\n }, 3e4);\n}\nexport {\n buildBundle\n};\n//# sourceMappingURL=buildBundle.js.map\n"],"mappings":";;;;;;;AAOA,eAAe,YAAY,OAAO,KAAK,MAAM,aAAa,MAAM;CAC9D,MAAM,EACJ,UAEA,KACA,cAEA,iBAAiB,QACjB,YAGA,QAGA,eAcE;CACJ,MAAM,EAAE,SAAS;CACjB,IAAI,OAAO,SAAS,UAAU;EAC5B,MAAM,IAAI,MAAM,6CAA6C,OAAO,MAAM;CAC5E;CACA,MAAM,qBAAqB,MAAMA,OAAY,iBAAiB;CAC9D,IAAI,oBAAoB;EACtB,QAAQ,KAAK,oDAAoD;EACjE,MAAM,mBAAmB,OAAO,KAAK,MAAM,UAAU;EACrD;CACF;CACA,QAAQ,IAAI,cAAc;CAC1B,QAAQ,MAAM,gBAAgB,cAAc,IAAI;CAChD,IAAI,CAAC,KAAK;EACR,QAAQ,IAAI,WAAW;CACzB;CACA,IAAI,YAAY;EACd,oBAAoB;CACtB;CACA,QAAQ,KAAK,qCAAqC,SAAS,IAAI;CAC/D,MAAM,kBAAkB,IAAI,aAAa;CACzC,IAAI,oBAAoB,KAAK,KAAK,OAAO,oBAAoB,UAAU;EACrE,MAAM,IAAI,MAAM,wCAAwC;CAC1D;CACA,MAAM,SAAS,MAAM,kBAAkB;EACrC;EACA;EACA;EACA,WAAW;EAIX,WAAW,QAAQ,IAAI;EACvB;EACA,WAAW,CAAC,CAAC,KAAK;EAClB;CACF,CAAC;CACD,MAAM,cAAc,OAAO;CAC3B,IAAI,OAAO,OAAO,KAAK,iBAAiB;EACtC,QAAQ,cAAc,KAAK,iBAAiB,OAAO,KAAK,EAAE,UAAU,OAAO,CAAC;CAC9E;CACA,QAAQ,KAAK,qBAAqB,aAAa,IAAI;CACnD,QAAQ,cAAc,cAAc,aAAa,EAAE,UAAU,eAAe,CAAC;CAC7E,QAAQ,KAAK,OAAO;CACpB,iBAAiB;EACf,QAAQ,KAAK,qCAAqC;EAClD,QAAQ,KAAK;CACf,GAAG,GAAG;AACR"}
1
+ {"version":3,"file":"buildBundle.js","names":["metroBundle"],"sources":["rn-commands/bundle/buildBundle.js"],"sourcesContent":["import FSExtra from \"fs-extra\";\nimport { clearTransformCache } from \"@vxrn/compiler\";\nimport {\n bundle as metroBundle\n} from \"@vxrn/vite-plugin-metro/rn-commands\";\nimport { loadEnv } from \"../../exports/loadEnv\";\nimport { buildNativeBundle } from \"../../utils/createNativeDevEngine\";\nasync function buildBundle(_argv, ctx, args, bundleImpl = null) {\n const {\n platform,\n // Android is not supported yet.\n dev,\n bundleOutput,\n // React Native's `--bundle-encoding` names a Node Buffer encoding.\n bundleEncoding = \"utf8\",\n assetsDest,\n // `--minify` overrides React Native's default of \"minify unless this is a\n // dev bundle\". undefined means the flag was not passed.\n minify,\n // `--reset-cache` drops the compiler's transform cache, the only cache a\n // rolldown production build reads.\n resetCache\n // `--entry-file` is a placeholder in generated native projects. VxRN apps\n // configure entries.native through vxrn/react-native-commands, while One\n // generates its native entry from the route tree.\n // `--read-global-cache` / `--max-workers` / `--config` / `--transformer` /\n // `--resolver-option` configure Metro's global cache, worker pool and\n // resolver. A rolldown production build has none of them: it transforms\n // from source in-process. React Native's own bundle command ignores\n // `--read-global-cache` too.\n // `--unstable-transform-profile` picks a JS engine to target. This pipeline\n // always downlevels for Hermes, which is what every profile it accepts\n // ('default', 'hermes', 'hermes-canary') can run.\n // `--sourcemap-use-absolute-path`, `--sourcemap-sources-root`,\n // `--asset-catalog-dest` and `--indexed-ram-bundle` are not implemented.\n } = args;\n const { root } = ctx;\n if (typeof root !== \"string\") {\n throw new Error(`Expected ctx.root to be a string, but got ${typeof root}`);\n }\n const metroBuildBundleFn = await metroBundle.getBuildBundleFn();\n if (metroBuildBundleFn) {\n console.info(\"Using @vxrn/vite-plugin-metro to build the bundle.\");\n await metroBuildBundleFn(_argv, ctx, args, bundleImpl);\n return;\n }\n process.env.IS_VXRN_CLI = \"true\";\n loadEnv(dev ? \"development\" : \"production\", root);\n if (!dev) {\n process.env.NODE_ENV = \"production\";\n }\n if (resetCache) {\n clearTransformCache();\n }\n console.info(`[vxrn] building native bundle for ${platform}...`);\n const nativeEntryFile = ctx.vxrnEntries?.native;\n if (nativeEntryFile !== void 0 && typeof nativeEntryFile !== \"string\") {\n throw new Error(\"Expected entries.native to be a string\");\n }\n const result = await buildNativeBundle({\n root,\n platform,\n dev,\n entryFile: nativeEntryFile,\n // pass through ONE_SERVER_URL so the native prelude can inject it into\n // process.env. without this, getURL.native falls back to the dummy\n // 'http://one-server.example.com' and runtime loader fetches fail in prod.\n serverUrl: process.env.ONE_SERVER_URL,\n assetsDest,\n sourcemap: !!args.sourcemapOutput,\n minify\n });\n const builtBundle = result.code;\n if (result.map && args.sourcemapOutput) {\n FSExtra.outputFileSync(args.sourcemapOutput, result.map, { encoding: \"utf8\" });\n }\n console.info(`Writing bundle to ${bundleOutput}...`);\n FSExtra.outputFileSync(bundleOutput, builtBundle, { encoding: bundleEncoding });\n console.info(\"Done.\");\n setTimeout(() => {\n console.info(\"Exiting process to prevent hanging.\");\n process.exit();\n }, 3e4).unref();\n}\nexport {\n buildBundle\n};\n//# sourceMappingURL=buildBundle.js.map\n"],"mappings":";;;;;;;AAOA,eAAe,YAAY,OAAO,KAAK,MAAM,aAAa,MAAM;CAC9D,MAAM,EACJ,UAEA,KACA,cAEA,iBAAiB,QACjB,YAGA,QAGA,eAcE;CACJ,MAAM,EAAE,SAAS;CACjB,IAAI,OAAO,SAAS,UAAU;EAC5B,MAAM,IAAI,MAAM,6CAA6C,OAAO,MAAM;CAC5E;CACA,MAAM,qBAAqB,MAAMA,OAAY,iBAAiB;CAC9D,IAAI,oBAAoB;EACtB,QAAQ,KAAK,oDAAoD;EACjE,MAAM,mBAAmB,OAAO,KAAK,MAAM,UAAU;EACrD;CACF;CACA,QAAQ,IAAI,cAAc;CAC1B,QAAQ,MAAM,gBAAgB,cAAc,IAAI;CAChD,IAAI,CAAC,KAAK;EACR,QAAQ,IAAI,WAAW;CACzB;CACA,IAAI,YAAY;EACd,oBAAoB;CACtB;CACA,QAAQ,KAAK,qCAAqC,SAAS,IAAI;CAC/D,MAAM,kBAAkB,IAAI,aAAa;CACzC,IAAI,oBAAoB,KAAK,KAAK,OAAO,oBAAoB,UAAU;EACrE,MAAM,IAAI,MAAM,wCAAwC;CAC1D;CACA,MAAM,SAAS,MAAM,kBAAkB;EACrC;EACA;EACA;EACA,WAAW;EAIX,WAAW,QAAQ,IAAI;EACvB;EACA,WAAW,CAAC,CAAC,KAAK;EAClB;CACF,CAAC;CACD,MAAM,cAAc,OAAO;CAC3B,IAAI,OAAO,OAAO,KAAK,iBAAiB;EACtC,QAAQ,eAAe,KAAK,iBAAiB,OAAO,KAAK,EAAE,UAAU,OAAO,CAAC;CAC/E;CACA,QAAQ,KAAK,qBAAqB,aAAa,IAAI;CACnD,QAAQ,eAAe,cAAc,aAAa,EAAE,UAAU,eAAe,CAAC;CAC9E,QAAQ,KAAK,OAAO;CACpB,iBAAiB;EACf,QAAQ,KAAK,qCAAqC;EAClD,QAAQ,KAAK;CACf,GAAG,GAAG,CAAC,CAAC,MAAM;AAChB"}
@@ -43,15 +43,15 @@ async function buildBundle(_argv, ctx, args) {
43
43
  });
44
44
  var builtBundle = result.code;
45
45
  if (result.map && args.sourcemapOutput) {
46
- FSExtra.writeFileSync(args.sourcemapOutput, result.map, { encoding: "utf8" });
46
+ FSExtra.outputFileSync(args.sourcemapOutput, result.map, { encoding: "utf8" });
47
47
  }
48
48
  console.info(`Writing bundle to ${bundleOutput}...`);
49
- FSExtra.writeFileSync(bundleOutput, builtBundle, { encoding: bundleEncoding });
49
+ FSExtra.outputFileSync(bundleOutput, builtBundle, { encoding: bundleEncoding });
50
50
  console.info("Done.");
51
51
  setTimeout(function() {
52
52
  console.info("Exiting process to prevent hanging.");
53
53
  process.exit();
54
- }, 3e4);
54
+ }, 3e4).unref();
55
55
  }
56
56
 
57
57
  export { buildBundle };
@@ -1 +1 @@
1
- {"version":3,"file":"buildBundle.native.js","names":["metroBundle"],"sources":["rn-commands/bundle/buildBundle.native.js"],"sourcesContent":["import FSExtra from \"fs-extra\";\nimport { clearTransformCache } from \"@vxrn/compiler\";\nimport { bundle as metroBundle } from \"@vxrn/vite-plugin-metro/rn-commands\";\nimport { loadEnv } from \"../../exports/loadEnv\";\nimport { buildNativeBundle } from \"../../utils/createNativeDevEngine\";\nasync function buildBundle(_argv, ctx, args) {\n var bundleImpl = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : null;\n var _ctx_vxrnEntries;\n var {\n platform,\n // Android is not supported yet.\n dev,\n bundleOutput,\n // React Native's `--bundle-encoding` names a Node Buffer encoding.\n bundleEncoding = \"utf8\",\n assetsDest,\n // `--minify` overrides React Native's default of \"minify unless this is a\n // dev bundle\". undefined means the flag was not passed.\n minify,\n // `--reset-cache` drops the compiler's transform cache, the only cache a\n // rolldown production build reads.\n resetCache\n } = (\n // `--entry-file` is a placeholder in generated native projects. VxRN apps\n // configure entries.native through vxrn/react-native-commands, while One\n // generates its native entry from the route tree.\n // `--read-global-cache` / `--max-workers` / `--config` / `--transformer` /\n // `--resolver-option` configure Metro's global cache, worker pool and\n // resolver. A rolldown production build has none of them: it transforms\n // from source in-process. React Native's own bundle command ignores\n // `--read-global-cache` too.\n // `--unstable-transform-profile` picks a JS engine to target. This pipeline\n // always downlevels for Hermes, which is what every profile it accepts\n // ('default', 'hermes', 'hermes-canary') can run.\n // `--sourcemap-use-absolute-path`, `--sourcemap-sources-root`,\n // `--asset-catalog-dest` and `--indexed-ram-bundle` are not implemented.\n args\n );\n var { root } = ctx;\n if (typeof root !== \"string\") {\n throw new Error(`Expected ctx.root to be a string, but got ${typeof root}`);\n }\n var metroBuildBundleFn = await metroBundle.getBuildBundleFn();\n if (metroBuildBundleFn) {\n console.info(\"Using @vxrn/vite-plugin-metro to build the bundle.\");\n await metroBuildBundleFn(_argv, ctx, args, bundleImpl);\n return;\n }\n process.env.IS_VXRN_CLI = \"true\";\n loadEnv(dev ? \"development\" : \"production\", root);\n if (!dev) {\n process.env.NODE_ENV = \"production\";\n }\n if (resetCache) {\n clearTransformCache();\n }\n console.info(`[vxrn] building native bundle for ${platform}...`);\n var nativeEntryFile = (_ctx_vxrnEntries = ctx.vxrnEntries) === null || _ctx_vxrnEntries === void 0 ? void 0 : _ctx_vxrnEntries.native;\n if (nativeEntryFile !== void 0 && typeof nativeEntryFile !== \"string\") {\n throw new Error(\"Expected entries.native to be a string\");\n }\n var result = await buildNativeBundle({\n root,\n platform,\n dev,\n entryFile: nativeEntryFile,\n // pass through ONE_SERVER_URL so the native prelude can inject it into\n // process.env. without this, getURL.native falls back to the dummy\n // 'http://one-server.example.com' and runtime loader fetches fail in prod.\n serverUrl: process.env.ONE_SERVER_URL,\n assetsDest,\n sourcemap: !!args.sourcemapOutput,\n minify\n });\n var builtBundle = result.code;\n if (result.map && args.sourcemapOutput) {\n FSExtra.writeFileSync(args.sourcemapOutput, result.map, {\n encoding: \"utf8\"\n });\n }\n console.info(`Writing bundle to ${bundleOutput}...`);\n FSExtra.writeFileSync(bundleOutput, builtBundle, {\n encoding: bundleEncoding\n });\n console.info(\"Done.\");\n setTimeout(function() {\n console.info(\"Exiting process to prevent hanging.\");\n process.exit();\n }, 3e4);\n}\nexport {\n buildBundle\n};\n//# sourceMappingURL=buildBundle.js.map\n"],"mappings":";;;;;;;AAKA,eAAe,YAAY,OAAO,KAAK,MAAM;CAC3C,IAAI,aAAa,UAAU,SAAS,KAAK,UAAU,OAAO,KAAK,IAAI,UAAU,KAAK;CAClF,IAAI;CACJ,IAAI,EACF,UAEA,KACA,cAEA,iBAAiB,QACjB,YAGA,QAGA,eAeA;CAEF,IAAI,EAAE,SAAS;CACf,IAAI,OAAO,SAAS,UAAU;EAC5B,MAAM,IAAI,MAAM,6CAA6C,OAAO,MAAM;CAC5E;CACA,IAAI,qBAAqB,MAAMA,OAAY,iBAAiB;CAC5D,IAAI,oBAAoB;EACtB,QAAQ,KAAK,oDAAoD;EACjE,MAAM,mBAAmB,OAAO,KAAK,MAAM,UAAU;EACrD;CACF;CACA,QAAQ,IAAI,cAAc;CAC1B,QAAQ,MAAM,gBAAgB,cAAc,IAAI;CAChD,IAAI,CAAC,KAAK;EACR,QAAQ,IAAI,WAAW;CACzB;CACA,IAAI,YAAY;EACd,oBAAoB;CACtB;CACA,QAAQ,KAAK,qCAAqC,SAAS,IAAI;CAC/D,IAAI,mBAAmB,mBAAmB,IAAI,iBAAiB,QAAQ,qBAAqB,KAAK,IAAI,KAAK,IAAI,iBAAiB;CAC/H,IAAI,oBAAoB,KAAK,KAAK,OAAO,oBAAoB,UAAU;EACrE,MAAM,IAAI,MAAM,wCAAwC;CAC1D;CACA,IAAI,SAAS,MAAM,kBAAkB;EACnC;EACA;EACA;EACA,WAAW;EAIX,WAAW,QAAQ,IAAI;EACvB;EACA,WAAW,CAAC,CAAC,KAAK;EAClB;CACF,CAAC;CACD,IAAI,cAAc,OAAO;CACzB,IAAI,OAAO,OAAO,KAAK,iBAAiB;EACtC,QAAQ,cAAc,KAAK,iBAAiB,OAAO,KAAK,EACtD,UAAU,OACZ,CAAC;CACH;CACA,QAAQ,KAAK,qBAAqB,aAAa,IAAI;CACnD,QAAQ,cAAc,cAAc,aAAa,EAC/C,UAAU,eACZ,CAAC;CACD,QAAQ,KAAK,OAAO;CACpB,WAAW,WAAW;EACpB,QAAQ,KAAK,qCAAqC;EAClD,QAAQ,KAAK;CACf,GAAG,GAAG;AACR"}
1
+ {"version":3,"file":"buildBundle.native.js","names":["metroBundle"],"sources":["rn-commands/bundle/buildBundle.native.js"],"sourcesContent":["import FSExtra from \"fs-extra\";\nimport { clearTransformCache } from \"@vxrn/compiler\";\nimport { bundle as metroBundle } from \"@vxrn/vite-plugin-metro/rn-commands\";\nimport { loadEnv } from \"../../exports/loadEnv\";\nimport { buildNativeBundle } from \"../../utils/createNativeDevEngine\";\nasync function buildBundle(_argv, ctx, args) {\n var bundleImpl = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : null;\n var _ctx_vxrnEntries;\n var {\n platform,\n // Android is not supported yet.\n dev,\n bundleOutput,\n // React Native's `--bundle-encoding` names a Node Buffer encoding.\n bundleEncoding = \"utf8\",\n assetsDest,\n // `--minify` overrides React Native's default of \"minify unless this is a\n // dev bundle\". undefined means the flag was not passed.\n minify,\n // `--reset-cache` drops the compiler's transform cache, the only cache a\n // rolldown production build reads.\n resetCache\n } = (\n // `--entry-file` is a placeholder in generated native projects. VxRN apps\n // configure entries.native through vxrn/react-native-commands, while One\n // generates its native entry from the route tree.\n // `--read-global-cache` / `--max-workers` / `--config` / `--transformer` /\n // `--resolver-option` configure Metro's global cache, worker pool and\n // resolver. A rolldown production build has none of them: it transforms\n // from source in-process. React Native's own bundle command ignores\n // `--read-global-cache` too.\n // `--unstable-transform-profile` picks a JS engine to target. This pipeline\n // always downlevels for Hermes, which is what every profile it accepts\n // ('default', 'hermes', 'hermes-canary') can run.\n // `--sourcemap-use-absolute-path`, `--sourcemap-sources-root`,\n // `--asset-catalog-dest` and `--indexed-ram-bundle` are not implemented.\n args\n );\n var { root } = ctx;\n if (typeof root !== \"string\") {\n throw new Error(`Expected ctx.root to be a string, but got ${typeof root}`);\n }\n var metroBuildBundleFn = await metroBundle.getBuildBundleFn();\n if (metroBuildBundleFn) {\n console.info(\"Using @vxrn/vite-plugin-metro to build the bundle.\");\n await metroBuildBundleFn(_argv, ctx, args, bundleImpl);\n return;\n }\n process.env.IS_VXRN_CLI = \"true\";\n loadEnv(dev ? \"development\" : \"production\", root);\n if (!dev) {\n process.env.NODE_ENV = \"production\";\n }\n if (resetCache) {\n clearTransformCache();\n }\n console.info(`[vxrn] building native bundle for ${platform}...`);\n var nativeEntryFile = (_ctx_vxrnEntries = ctx.vxrnEntries) === null || _ctx_vxrnEntries === void 0 ? void 0 : _ctx_vxrnEntries.native;\n if (nativeEntryFile !== void 0 && typeof nativeEntryFile !== \"string\") {\n throw new Error(\"Expected entries.native to be a string\");\n }\n var result = await buildNativeBundle({\n root,\n platform,\n dev,\n entryFile: nativeEntryFile,\n // pass through ONE_SERVER_URL so the native prelude can inject it into\n // process.env. without this, getURL.native falls back to the dummy\n // 'http://one-server.example.com' and runtime loader fetches fail in prod.\n serverUrl: process.env.ONE_SERVER_URL,\n assetsDest,\n sourcemap: !!args.sourcemapOutput,\n minify\n });\n var builtBundle = result.code;\n if (result.map && args.sourcemapOutput) {\n FSExtra.outputFileSync(args.sourcemapOutput, result.map, {\n encoding: \"utf8\"\n });\n }\n console.info(`Writing bundle to ${bundleOutput}...`);\n FSExtra.outputFileSync(bundleOutput, builtBundle, {\n encoding: bundleEncoding\n });\n console.info(\"Done.\");\n setTimeout(function() {\n console.info(\"Exiting process to prevent hanging.\");\n process.exit();\n }, 3e4).unref();\n}\nexport {\n buildBundle\n};\n//# sourceMappingURL=buildBundle.js.map\n"],"mappings":";;;;;;;AAKA,eAAe,YAAY,OAAO,KAAK,MAAM;CAC3C,IAAI,aAAa,UAAU,SAAS,KAAK,UAAU,OAAO,KAAK,IAAI,UAAU,KAAK;CAClF,IAAI;CACJ,IAAI,EACF,UAEA,KACA,cAEA,iBAAiB,QACjB,YAGA,QAGA,eAeA;CAEF,IAAI,EAAE,SAAS;CACf,IAAI,OAAO,SAAS,UAAU;EAC5B,MAAM,IAAI,MAAM,6CAA6C,OAAO,MAAM;CAC5E;CACA,IAAI,qBAAqB,MAAMA,OAAY,iBAAiB;CAC5D,IAAI,oBAAoB;EACtB,QAAQ,KAAK,oDAAoD;EACjE,MAAM,mBAAmB,OAAO,KAAK,MAAM,UAAU;EACrD;CACF;CACA,QAAQ,IAAI,cAAc;CAC1B,QAAQ,MAAM,gBAAgB,cAAc,IAAI;CAChD,IAAI,CAAC,KAAK;EACR,QAAQ,IAAI,WAAW;CACzB;CACA,IAAI,YAAY;EACd,oBAAoB;CACtB;CACA,QAAQ,KAAK,qCAAqC,SAAS,IAAI;CAC/D,IAAI,mBAAmB,mBAAmB,IAAI,iBAAiB,QAAQ,qBAAqB,KAAK,IAAI,KAAK,IAAI,iBAAiB;CAC/H,IAAI,oBAAoB,KAAK,KAAK,OAAO,oBAAoB,UAAU;EACrE,MAAM,IAAI,MAAM,wCAAwC;CAC1D;CACA,IAAI,SAAS,MAAM,kBAAkB;EACnC;EACA;EACA;EACA,WAAW;EAIX,WAAW,QAAQ,IAAI;EACvB;EACA,WAAW,CAAC,CAAC,KAAK;EAClB;CACF,CAAC;CACD,IAAI,cAAc,OAAO;CACzB,IAAI,OAAO,OAAO,KAAK,iBAAiB;EACtC,QAAQ,eAAe,KAAK,iBAAiB,OAAO,KAAK,EACvD,UAAU,OACZ,CAAC;CACH;CACA,QAAQ,KAAK,qBAAqB,aAAa,IAAI;CACnD,QAAQ,eAAe,cAAc,aAAa,EAChD,UAAU,eACZ,CAAC;CACD,QAAQ,KAAK,OAAO;CACpB,WAAW,WAAW;EACpB,QAAQ,KAAK,qCAAqC;EAClD,QAAQ,KAAK;CACf,GAAG,GAAG,CAAC,CAAC,MAAM;AAChB"}
@@ -1,7 +1,5 @@
1
1
  function _class_call_check(instance2, Constructor) {
2
- if (!(instance2 instanceof Constructor)) {
3
- throw new TypeError("Cannot call a class as a function");
4
- }
2
+ if (!(instance2 instanceof Constructor)) throw new TypeError("Cannot call a class as a function");
5
3
  }
6
4
  function _defineProperties(target, props) {
7
5
  for (var i = 0; i < props.length; i++) {
@@ -25,9 +23,7 @@ function _define_property(obj, key, value) {
25
23
  configurable: true,
26
24
  writable: true
27
25
  });
28
- } else {
29
- obj[key] = value;
30
- }
26
+ } else obj[key] = value;
31
27
  return obj;
32
28
  }
33
29
  var HMRClient = /* @__PURE__ */ (function() {
@@ -230,7 +226,7 @@ Error: ${error.message}`;
230
226
  _define_property(HMRClient, "STARTUP_ERROR", "Expected HMRClient.setup() call at startup");
231
227
  _define_property(HMRClient, "MAX_PENDING_LOGS", 100);
232
228
  var instance = new HMRClient();
233
- var hmr_client_default = Object.defineProperty(instance, "default", { get: function() {
229
+ var hmr_client_default = Object.defineProperty(instance, "default", { get: function get() {
234
230
  return instance;
235
231
  } });
236
232