@granite-js/mpack 0.0.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 (397) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/LICENSE +202 -0
  3. package/README.md +24 -0
  4. package/dist/bundler/Bundler.d.ts +24 -0
  5. package/dist/bundler/Bundler.js +175 -0
  6. package/dist/bundler/PluginDriver.d.ts +9 -0
  7. package/dist/bundler/PluginDriver.js +47 -0
  8. package/dist/bundler/index.d.ts +1 -0
  9. package/dist/bundler/index.js +22 -0
  10. package/dist/bundler/plugins/buildStatusPlugin/buildStatusPlugin.d.ts +12 -0
  11. package/dist/bundler/plugins/buildStatusPlugin/buildStatusPlugin.js +75 -0
  12. package/dist/bundler/plugins/buildStatusPlugin/index.d.ts +1 -0
  13. package/dist/bundler/plugins/buildStatusPlugin/index.js +28 -0
  14. package/dist/bundler/plugins/dependencyAliasPlugin/aliasResolver.d.ts +3 -0
  15. package/dist/bundler/plugins/dependencyAliasPlugin/aliasResolver.js +89 -0
  16. package/dist/bundler/plugins/dependencyAliasPlugin/dependencyAliasPlugin.d.ts +3 -0
  17. package/dist/bundler/plugins/dependencyAliasPlugin/dependencyAliasPlugin.js +43 -0
  18. package/dist/bundler/plugins/dependencyAliasPlugin/index.d.ts +1 -0
  19. package/dist/bundler/plugins/dependencyAliasPlugin/index.js +28 -0
  20. package/dist/bundler/plugins/dependencyAliasPlugin/protocolResolver.d.ts +3 -0
  21. package/dist/bundler/plugins/dependencyAliasPlugin/protocolResolver.js +53 -0
  22. package/dist/bundler/plugins/index.d.ts +4 -0
  23. package/dist/bundler/plugins/index.js +28 -0
  24. package/dist/bundler/plugins/requireContextPlugin/index.d.ts +1 -0
  25. package/dist/bundler/plugins/requireContextPlugin/index.js +28 -0
  26. package/dist/bundler/plugins/requireContextPlugin/requireContextPlugin.d.ts +6 -0
  27. package/dist/bundler/plugins/requireContextPlugin/requireContextPlugin.js +101 -0
  28. package/dist/bundler/plugins/requireContextPlugin/scripts.d.ts +56 -0
  29. package/dist/bundler/plugins/requireContextPlugin/scripts.js +65 -0
  30. package/dist/bundler/plugins/shared/swc.d.ts +11 -0
  31. package/dist/bundler/plugins/shared/swc.js +70 -0
  32. package/dist/bundler/plugins/transformPlugin/helpers/preludeScript.d.ts +23 -0
  33. package/dist/bundler/plugins/transformPlugin/helpers/preludeScript.js +79 -0
  34. package/dist/bundler/plugins/transformPlugin/index.d.ts +1 -0
  35. package/dist/bundler/plugins/transformPlugin/index.js +28 -0
  36. package/dist/bundler/plugins/transformPlugin/steps/createCacheSteps.d.ts +10 -0
  37. package/dist/bundler/plugins/transformPlugin/steps/createCacheSteps.js +56 -0
  38. package/dist/bundler/plugins/transformPlugin/steps/createFullyTransformStep.d.ts +8 -0
  39. package/dist/bundler/plugins/transformPlugin/steps/createFullyTransformStep.js +120 -0
  40. package/dist/bundler/plugins/transformPlugin/steps/createStripFlowStep.d.ts +6 -0
  41. package/dist/bundler/plugins/transformPlugin/steps/createStripFlowStep.js +91 -0
  42. package/dist/bundler/plugins/transformPlugin/steps/createTransformToHermesSyntaxStep.d.ts +8 -0
  43. package/dist/bundler/plugins/transformPlugin/steps/createTransformToHermesSyntaxStep.js +100 -0
  44. package/dist/bundler/plugins/transformPlugin/transformPlugin.d.ts +8 -0
  45. package/dist/bundler/plugins/transformPlugin/transformPlugin.js +88 -0
  46. package/dist/bundler/plugins/types.d.ts +7 -0
  47. package/dist/bundler/plugins/types.js +16 -0
  48. package/dist/bundler/types.d.ts +17 -0
  49. package/dist/bundler/types.js +16 -0
  50. package/dist/cache/Cache.d.ts +25 -0
  51. package/dist/cache/Cache.js +87 -0
  52. package/dist/cache/index.d.ts +1 -0
  53. package/dist/cache/index.js +22 -0
  54. package/dist/constants/index.d.ts +20 -0
  55. package/dist/constants/index.js +91 -0
  56. package/dist/index.d.ts +11 -0
  57. package/dist/index.js +60 -0
  58. package/dist/logger/Logger.d.ts +17 -0
  59. package/dist/logger/Logger.js +115 -0
  60. package/dist/logger/clientLogger.d.ts +2 -0
  61. package/dist/logger/clientLogger.js +49 -0
  62. package/dist/logger/index.d.ts +3 -0
  63. package/dist/logger/index.js +31 -0
  64. package/dist/metro/assetRegistry.d.ts +12 -0
  65. package/dist/metro/assetRegistry.js +57 -0
  66. package/dist/metro/enhancedResolver.d.ts +7 -0
  67. package/dist/metro/enhancedResolver.js +127 -0
  68. package/dist/metro/getMetroConfig.d.ts +12 -0
  69. package/dist/metro/getMetroConfig.js +138 -0
  70. package/dist/metro/getMonorepoRoot.d.ts +4 -0
  71. package/dist/metro/getMonorepoRoot.js +80 -0
  72. package/dist/metro/index.d.ts +3 -0
  73. package/dist/metro/index.js +24 -0
  74. package/dist/metro/pnpapi.d.ts +6 -0
  75. package/dist/metro/pnpapi.js +32 -0
  76. package/dist/metro/runBuild.d.ts +12 -0
  77. package/dist/metro/runBuild.js +66 -0
  78. package/dist/metro/runtime.d.ts +3 -0
  79. package/dist/metro/runtime.js +56 -0
  80. package/dist/metro/types.d.ts +88 -0
  81. package/dist/metro/types.js +16 -0
  82. package/dist/operations/constants.d.ts +3 -0
  83. package/dist/operations/constants.js +34 -0
  84. package/dist/operations/createDebuggerMiddleware.d.ts +11 -0
  85. package/dist/operations/createDebuggerMiddleware.js +128 -0
  86. package/dist/operations/experimental/StartMenuHandler.d.ts +13 -0
  87. package/dist/operations/experimental/StartMenuHandler.js +86 -0
  88. package/dist/operations/experimental/runServer.d.ts +16 -0
  89. package/dist/operations/experimental/runServer.js +137 -0
  90. package/dist/operations/index.d.ts +3 -0
  91. package/dist/operations/index.js +26 -0
  92. package/dist/operations/openDebugger.d.ts +1 -0
  93. package/dist/operations/openDebugger.js +73 -0
  94. package/dist/operations/runBundle.d.ts +12 -0
  95. package/dist/operations/runBundle.js +97 -0
  96. package/dist/operations/runServer.d.ts +15 -0
  97. package/dist/operations/runServer.js +134 -0
  98. package/dist/performance/Performance.d.ts +23 -0
  99. package/dist/performance/Performance.js +121 -0
  100. package/dist/performance/index.d.ts +2 -0
  101. package/dist/performance/index.js +31 -0
  102. package/dist/performance/printSummary.d.ts +5 -0
  103. package/dist/performance/printSummary.js +58 -0
  104. package/dist/plugins/index.d.ts +1 -0
  105. package/dist/plugins/index.js +22 -0
  106. package/dist/plugins/statusPlugin.d.ts +2 -0
  107. package/dist/plugins/statusPlugin.js +64 -0
  108. package/dist/server/DevServer.d.ts +23 -0
  109. package/dist/server/DevServer.js +216 -0
  110. package/dist/server/constants.d.ts +1 -0
  111. package/dist/server/constants.js +28 -0
  112. package/dist/server/debugger/DebuggerEventHandler.d.ts +41 -0
  113. package/dist/server/debugger/DebuggerEventHandler.js +169 -0
  114. package/dist/server/debugger/parseDomain.d.ts +1 -0
  115. package/dist/server/debugger/parseDomain.js +30 -0
  116. package/dist/server/helpers/createBundlerForDevServer.d.ts +10 -0
  117. package/dist/server/helpers/createBundlerForDevServer.js +75 -0
  118. package/dist/server/helpers/mergeBundles.d.ts +7 -0
  119. package/dist/server/helpers/mergeBundles.js +129 -0
  120. package/dist/server/index.d.ts +1 -0
  121. package/dist/server/index.js +22 -0
  122. package/dist/server/middlewares/createLiveReloadMiddleware.d.ts +10 -0
  123. package/dist/server/middlewares/createLiveReloadMiddleware.js +129 -0
  124. package/dist/server/middlewares/index.d.ts +1 -0
  125. package/dist/server/middlewares/index.js +22 -0
  126. package/dist/server/plugins/debuggerPlugin.d.ts +7 -0
  127. package/dist/server/plugins/debuggerPlugin.js +68 -0
  128. package/dist/server/plugins/index.d.ts +5 -0
  129. package/dist/server/plugins/index.js +30 -0
  130. package/dist/server/plugins/indexPagePlugin.d.ts +4 -0
  131. package/dist/server/plugins/indexPagePlugin.js +52 -0
  132. package/dist/server/plugins/reply.d.ts +3 -0
  133. package/dist/server/plugins/reply.js +38 -0
  134. package/dist/server/plugins/serveBundlePlugin.d.ts +8 -0
  135. package/dist/server/plugins/serveBundlePlugin.js +118 -0
  136. package/dist/server/plugins/statusPlugin.d.ts +7 -0
  137. package/dist/server/plugins/statusPlugin.js +50 -0
  138. package/dist/server/plugins/symbolicatePlugin/index.d.ts +1 -0
  139. package/dist/server/plugins/symbolicatePlugin/index.js +28 -0
  140. package/dist/server/plugins/symbolicatePlugin/parseStackFrame.d.ts +25 -0
  141. package/dist/server/plugins/symbolicatePlugin/parseStackFrame.js +51 -0
  142. package/dist/server/plugins/symbolicatePlugin/symbolicate.d.ts +25 -0
  143. package/dist/server/plugins/symbolicatePlugin/symbolicate.js +84 -0
  144. package/dist/server/plugins/symbolicatePlugin/symbolicatePlugin.d.ts +8 -0
  145. package/dist/server/plugins/symbolicatePlugin/symbolicatePlugin.js +77 -0
  146. package/dist/server/types.d.ts +97 -0
  147. package/dist/server/types.js +16 -0
  148. package/dist/server/wss/WebSocketServerDelegate.d.ts +23 -0
  149. package/dist/server/wss/WebSocketServerDelegate.js +50 -0
  150. package/dist/server/wss/WebSocketServerRouter.d.ts +8 -0
  151. package/dist/server/wss/WebSocketServerRouter.js +66 -0
  152. package/dist/server/wss/index.d.ts +2 -0
  153. package/dist/server/wss/index.js +24 -0
  154. package/dist/shared/PersistentStorage.d.ts +21 -0
  155. package/dist/shared/PersistentStorage.js +68 -0
  156. package/dist/transformer/AsyncTransformPipeline.d.ts +4 -0
  157. package/dist/transformer/AsyncTransformPipeline.js +58 -0
  158. package/dist/transformer/TransformPipeline.d.ts +37 -0
  159. package/dist/transformer/TransformPipeline.js +64 -0
  160. package/dist/transformer/index.d.ts +1 -0
  161. package/dist/transformer/index.js +28 -0
  162. package/dist/types/BuildConfig.d.ts +183 -0
  163. package/dist/types/BuildConfig.js +16 -0
  164. package/dist/types/BundlerConfig.d.ts +56 -0
  165. package/dist/types/BundlerConfig.js +16 -0
  166. package/dist/types/Config.d.ts +12 -0
  167. package/dist/types/Config.js +16 -0
  168. package/dist/types/DevServerConfig.d.ts +9 -0
  169. package/dist/types/DevServerConfig.js +16 -0
  170. package/dist/types/Plugin.d.ts +28 -0
  171. package/dist/types/Plugin.js +16 -0
  172. package/dist/types/Preset.d.ts +3 -0
  173. package/dist/types/Preset.js +16 -0
  174. package/dist/types/PresetContext.d.ts +2 -0
  175. package/dist/types/PresetContext.js +16 -0
  176. package/dist/types/ServicesConfig.d.ts +2 -0
  177. package/dist/types/ServicesConfig.js +16 -0
  178. package/dist/types/TaskConfig.d.ts +16 -0
  179. package/dist/types/TaskConfig.js +16 -0
  180. package/dist/types/index.d.ts +9 -0
  181. package/dist/types/index.js +38 -0
  182. package/dist/types/schemas/buildConfigSchema.d.ts +235 -0
  183. package/dist/types/schemas/buildConfigSchema.js +79 -0
  184. package/dist/types/schemas/bundlerConfigSchema.d.ts +3 -0
  185. package/dist/types/schemas/bundlerConfigSchema.js +51 -0
  186. package/dist/types/schemas/configSchema.d.ts +3 -0
  187. package/dist/types/schemas/configSchema.js +50 -0
  188. package/dist/types/schemas/devServerConfigSchema.d.ts +3 -0
  189. package/dist/types/schemas/devServerConfigSchema.js +43 -0
  190. package/dist/types/schemas/index.d.ts +6 -0
  191. package/dist/types/schemas/index.js +32 -0
  192. package/dist/types/schemas/servicesConfigSchema.d.ts +3 -0
  193. package/dist/types/schemas/servicesConfigSchema.js +48 -0
  194. package/dist/types/schemas/taskConfigSchema.d.ts +3 -0
  195. package/dist/types/schemas/taskConfigSchema.js +45 -0
  196. package/dist/utils/cleanupOutputDirectory.d.ts +1 -0
  197. package/dist/utils/cleanupOutputDirectory.js +53 -0
  198. package/dist/utils/defineStepName.d.ts +2 -0
  199. package/dist/utils/defineStepName.js +30 -0
  200. package/dist/utils/esbuildUtils.d.ts +1 -0
  201. package/dist/utils/esbuildUtils.js +45 -0
  202. package/dist/utils/getBundleName.d.ts +1 -0
  203. package/dist/utils/getBundleName.js +30 -0
  204. package/dist/utils/getBundleOutputs.d.ts +5 -0
  205. package/dist/utils/getBundleOutputs.js +49 -0
  206. package/dist/utils/getId.d.ts +2 -0
  207. package/dist/utils/getId.js +41 -0
  208. package/dist/utils/getSourcemapName.d.ts +1 -0
  209. package/dist/utils/getSourcemapName.js +30 -0
  210. package/dist/utils/isDebugMode.d.ts +1 -0
  211. package/dist/utils/isDebugMode.js +30 -0
  212. package/dist/utils/loadConfig.d.ts +2 -0
  213. package/dist/utils/loadConfig.js +37 -0
  214. package/dist/utils/loadPresets.d.ts +2 -0
  215. package/dist/utils/loadPresets.js +40 -0
  216. package/dist/utils/md5.d.ts +1 -0
  217. package/dist/utils/md5.js +41 -0
  218. package/dist/utils/mergeBanners.d.ts +6 -0
  219. package/dist/utils/mergeBanners.js +35 -0
  220. package/dist/utils/mergeBuildConfigs.d.ts +2 -0
  221. package/dist/utils/mergeBuildConfigs.js +59 -0
  222. package/dist/utils/mergeInject.d.ts +3 -0
  223. package/dist/utils/mergeInject.js +30 -0
  224. package/dist/utils/printLogo.d.ts +1 -0
  225. package/dist/utils/printLogo.js +56 -0
  226. package/dist/utils/printSummary.d.ts +7 -0
  227. package/dist/utils/printSummary.js +55 -0
  228. package/dist/utils/progressBar.d.ts +9 -0
  229. package/dist/utils/progressBar.js +97 -0
  230. package/dist/utils/promiseHandler.d.ts +12 -0
  231. package/dist/utils/promiseHandler.js +54 -0
  232. package/dist/utils/replaceModulePath.d.ts +1 -0
  233. package/dist/utils/replaceModulePath.js +31 -0
  234. package/dist/utils/replacePlaceholders.d.ts +1 -0
  235. package/dist/utils/replacePlaceholders.js +33 -0
  236. package/dist/utils/stripExtension.d.ts +1 -0
  237. package/dist/utils/stripExtension.js +41 -0
  238. package/dist/utils/writeBundle.d.ts +2 -0
  239. package/dist/utils/writeBundle.js +52 -0
  240. package/dist/vendors/@react-native/dev-middleware/Device.d.ts +5 -0
  241. package/dist/vendors/@react-native/dev-middleware/Device.js +33 -0
  242. package/dist/vendors/@react-native/dev-middleware/InspectorProxy.d.ts +31 -0
  243. package/dist/vendors/@react-native/dev-middleware/InspectorProxy.js +169 -0
  244. package/dist/vendors/@react-native/dev-middleware/index.d.ts +3 -0
  245. package/dist/vendors/@react-native/dev-middleware/index.js +26 -0
  246. package/dist/vendors/@react-native/dev-middleware/types.d.ts +54 -0
  247. package/dist/vendors/@react-native/dev-middleware/types.js +16 -0
  248. package/dist/vendors/@react-native-community/cli-server-api/createWebSocketEndpoints.d.ts +23 -0
  249. package/dist/vendors/@react-native-community/cli-server-api/createWebSocketEndpoints.js +47 -0
  250. package/dist/vendors/@react-native-community/cli-server-api/index.d.ts +1 -0
  251. package/dist/vendors/@react-native-community/cli-server-api/index.js +22 -0
  252. package/dist/vendors/index.d.ts +27 -0
  253. package/dist/vendors/index.js +63 -0
  254. package/dist/vendors/metro/src/Assets.js +159 -0
  255. package/dist/vendors/metro/src/Bundler/util.js +131 -0
  256. package/dist/vendors/metro/src/Bundler.js +43 -0
  257. package/dist/vendors/metro/src/DeltaBundler/DeltaCalculator.js +176 -0
  258. package/dist/vendors/metro/src/DeltaBundler/Serializers/baseBytecodeBundle.js +61 -0
  259. package/dist/vendors/metro/src/DeltaBundler/Serializers/baseJSBundle.js +45 -0
  260. package/dist/vendors/metro/src/DeltaBundler/Serializers/getAllFiles.js +30 -0
  261. package/dist/vendors/metro/src/DeltaBundler/Serializers/getAssets.js +23 -0
  262. package/dist/vendors/metro/src/DeltaBundler/Serializers/getExplodedSourceMap.js +17 -0
  263. package/dist/vendors/metro/src/DeltaBundler/Serializers/getRamBundleInfo.js +87 -0
  264. package/dist/vendors/metro/src/DeltaBundler/Serializers/helpers/bytecode.js +51 -0
  265. package/dist/vendors/metro/src/DeltaBundler/Serializers/helpers/getInlineSourceMappingURL.js +6 -0
  266. package/dist/vendors/metro/src/DeltaBundler/Serializers/helpers/getSourceMapInfo.js +16 -0
  267. package/dist/vendors/metro/src/DeltaBundler/Serializers/helpers/getTransitiveDependencies.js +21 -0
  268. package/dist/vendors/metro/src/DeltaBundler/Serializers/helpers/js.js +43 -0
  269. package/dist/vendors/metro/src/DeltaBundler/Serializers/helpers/processBytecodeModules.js +13 -0
  270. package/dist/vendors/metro/src/DeltaBundler/Serializers/helpers/processModules.js +13 -0
  271. package/dist/vendors/metro/src/DeltaBundler/Serializers/hmrJSBundle.js +66 -0
  272. package/dist/vendors/metro/src/DeltaBundler/Serializers/sourceMapGenerator.js +63 -0
  273. package/dist/vendors/metro/src/DeltaBundler/Serializers/sourceMapObject.js +18 -0
  274. package/dist/vendors/metro/src/DeltaBundler/Serializers/sourceMapString.js +8 -0
  275. package/dist/vendors/metro/src/DeltaBundler/Transformer.js +133 -0
  276. package/dist/vendors/metro/src/DeltaBundler/Worker.flow.js +64 -0
  277. package/dist/vendors/metro/src/DeltaBundler/Worker.js +6 -0
  278. package/dist/vendors/metro/src/DeltaBundler/WorkerFarm.js +128 -0
  279. package/dist/vendors/metro/src/DeltaBundler/getTransformCacheKey.js +20 -0
  280. package/dist/vendors/metro/src/DeltaBundler/graphOperations.js +420 -0
  281. package/dist/vendors/metro/src/DeltaBundler/mergeDeltas.js +52 -0
  282. package/dist/vendors/metro/src/DeltaBundler/types.flow.js +24 -0
  283. package/dist/vendors/metro/src/DeltaBundler.js +56 -0
  284. package/dist/vendors/metro/src/HmrServer.js +224 -0
  285. package/dist/vendors/metro/src/IncrementalBundler/GraphNotFoundError.js +9 -0
  286. package/dist/vendors/metro/src/IncrementalBundler/ResourceNotFoundError.js +9 -0
  287. package/dist/vendors/metro/src/IncrementalBundler/RevisionNotFoundError.js +9 -0
  288. package/dist/vendors/metro/src/IncrementalBundler.js +213 -0
  289. package/dist/vendors/metro/src/ModuleGraph/module.js +14 -0
  290. package/dist/vendors/metro/src/ModuleGraph/node-haste/HasteFS.js +66 -0
  291. package/dist/vendors/metro/src/ModuleGraph/node-haste/Module.js +22 -0
  292. package/dist/vendors/metro/src/ModuleGraph/node-haste/ModuleCache.js +43 -0
  293. package/dist/vendors/metro/src/ModuleGraph/node-haste/Package.js +81 -0
  294. package/dist/vendors/metro/src/ModuleGraph/node-haste/node-haste.flow.js +1 -0
  295. package/dist/vendors/metro/src/ModuleGraph/node-haste/node-haste.js +127 -0
  296. package/dist/vendors/metro/src/ModuleGraph/output/indexed-ram-bundle.js +71 -0
  297. package/dist/vendors/metro/src/ModuleGraph/output/multiple-files-ram-bundle.js +53 -0
  298. package/dist/vendors/metro/src/ModuleGraph/output/plain-bundle.js +36 -0
  299. package/dist/vendors/metro/src/ModuleGraph/output/reverse-dependency-map-references.js +53 -0
  300. package/dist/vendors/metro/src/ModuleGraph/output/util.js +168 -0
  301. package/dist/vendors/metro/src/ModuleGraph/silent-console.js +5 -0
  302. package/dist/vendors/metro/src/ModuleGraph/types.flow.js +1 -0
  303. package/dist/vendors/metro/src/ModuleGraph/worker/JsFileWrapping.js +87 -0
  304. package/dist/vendors/metro/src/ModuleGraph/worker/Platforms.js +3 -0
  305. package/dist/vendors/metro/src/ModuleGraph/worker/collectDependencies.js +440 -0
  306. package/dist/vendors/metro/src/ModuleGraph/worker/generate.js +21 -0
  307. package/dist/vendors/metro/src/ModuleGraph/worker/generateImportNames.js +19 -0
  308. package/dist/vendors/metro/src/ModuleGraph/worker/mergeSourceMaps.js +29 -0
  309. package/dist/vendors/metro/src/Server/MultipartResponse.js +57 -0
  310. package/dist/vendors/metro/src/Server/symbolicate.js +109 -0
  311. package/dist/vendors/metro/src/Server.js +855 -0
  312. package/dist/vendors/metro/src/cli-utils.js +14 -0
  313. package/dist/vendors/metro/src/cli.js +9 -0
  314. package/dist/vendors/metro/src/commands/build.js +67 -0
  315. package/dist/vendors/metro/src/commands/dependencies.js +75 -0
  316. package/dist/vendors/metro/src/commands/serve.js +56 -0
  317. package/dist/vendors/metro/src/index.d.ts +8 -0
  318. package/dist/vendors/metro/src/index.flow.js +279 -0
  319. package/dist/vendors/metro/src/index.js +6 -0
  320. package/dist/vendors/metro/src/isPnP.js +13 -0
  321. package/dist/vendors/metro/src/lib/BatchProcessor.js +69 -0
  322. package/dist/vendors/metro/src/lib/CountingSet.js +98 -0
  323. package/dist/vendors/metro/src/lib/JsonReporter.js +21 -0
  324. package/dist/vendors/metro/src/lib/RamBundleParser.js +36 -0
  325. package/dist/vendors/metro/src/lib/TerminalReporter.d.ts +18 -0
  326. package/dist/vendors/metro/src/lib/TerminalReporter.js +258 -0
  327. package/dist/vendors/metro/src/lib/bundleToBytecode.js +40 -0
  328. package/dist/vendors/metro/src/lib/bundleToString.js +22 -0
  329. package/dist/vendors/metro/src/lib/contextModule.js +73 -0
  330. package/dist/vendors/metro/src/lib/contextModuleTemplates.js +116 -0
  331. package/dist/vendors/metro/src/lib/countLines.js +4 -0
  332. package/dist/vendors/metro/src/lib/createModuleIdFactory.js +14 -0
  333. package/dist/vendors/metro/src/lib/createWebsocketServer.js +54 -0
  334. package/dist/vendors/metro/src/lib/debounceAsyncQueue.js +33 -0
  335. package/dist/vendors/metro/src/lib/formatBundlingError.js +76 -0
  336. package/dist/vendors/metro/src/lib/getAppendScripts.js +131 -0
  337. package/dist/vendors/metro/src/lib/getGraphId.js +27 -0
  338. package/dist/vendors/metro/src/lib/getMaxWorkers.js +6 -0
  339. package/dist/vendors/metro/src/lib/getPreludeCode.js +32 -0
  340. package/dist/vendors/metro/src/lib/getPrependedScripts.js +93 -0
  341. package/dist/vendors/metro/src/lib/logToConsole.js +46 -0
  342. package/dist/vendors/metro/src/lib/parseCustomResolverOptions.js +13 -0
  343. package/dist/vendors/metro/src/lib/parseCustomTransformOptions.js +13 -0
  344. package/dist/vendors/metro/src/lib/parseOptionsFromUrl.js +50 -0
  345. package/dist/vendors/metro/src/lib/relativizeSourceMap.js +14 -0
  346. package/dist/vendors/metro/src/lib/reporting.js +26 -0
  347. package/dist/vendors/metro/src/lib/splitBundleOptions.js +32 -0
  348. package/dist/vendors/metro/src/lib/transformHelpers.js +112 -0
  349. package/dist/vendors/metro/src/node-haste/DependencyGraph/ModuleResolution.js +221 -0
  350. package/dist/vendors/metro/src/node-haste/DependencyGraph/createHasteMap.js +71 -0
  351. package/dist/vendors/metro/src/node-haste/DependencyGraph.js +223 -0
  352. package/dist/vendors/metro/src/node-haste/Module.js +21 -0
  353. package/dist/vendors/metro/src/node-haste/ModuleCache.js +81 -0
  354. package/dist/vendors/metro/src/node-haste/Package.js +98 -0
  355. package/dist/vendors/metro/src/node-haste/lib/AssetPaths.js +41 -0
  356. package/dist/vendors/metro/src/node-haste/lib/parsePlatformFilePath.js +19 -0
  357. package/dist/vendors/metro/src/shared/output/RamBundle/as-assets.js +61 -0
  358. package/dist/vendors/metro/src/shared/output/RamBundle/as-indexed-file.js +115 -0
  359. package/dist/vendors/metro/src/shared/output/RamBundle/buildSourcemapWithMetadata.js +23 -0
  360. package/dist/vendors/metro/src/shared/output/RamBundle/magic-number.js +2 -0
  361. package/dist/vendors/metro/src/shared/output/RamBundle/util.js +94 -0
  362. package/dist/vendors/metro/src/shared/output/RamBundle/write-sourcemap.js +12 -0
  363. package/dist/vendors/metro/src/shared/output/RamBundle.js +18 -0
  364. package/dist/vendors/metro/src/shared/output/bundle.flow.js +42 -0
  365. package/dist/vendors/metro/src/shared/output/bundle.js +6 -0
  366. package/dist/vendors/metro/src/shared/output/meta.js +31 -0
  367. package/dist/vendors/metro/src/shared/output/unbundle.js +2 -0
  368. package/dist/vendors/metro/src/shared/output/writeFile.js +6 -0
  369. package/dist/vendors/metro/src/shared/types.flow.js +1 -0
  370. package/dist/vendors/metro-config/src/configTypes.flow.js +1 -0
  371. package/dist/vendors/metro-config/src/defaults/defaults.js +66 -0
  372. package/dist/vendors/metro-config/src/defaults/exclusionList.d.ts +3 -0
  373. package/dist/vendors/metro-config/src/defaults/exclusionList.js +17 -0
  374. package/dist/vendors/metro-config/src/defaults/index.d.ts +5 -0
  375. package/dist/vendors/metro-config/src/defaults/index.js +161 -0
  376. package/dist/vendors/metro-config/src/defaults/validConfig.js +28 -0
  377. package/dist/vendors/metro-config/src/index.js +9 -0
  378. package/dist/vendors/metro-config/src/loadConfig.d.ts +4 -0
  379. package/dist/vendors/metro-config/src/loadConfig.js +188 -0
  380. package/dist/vendors/metro-core/src/Logger.js +62 -0
  381. package/dist/vendors/metro-core/src/Terminal.d.ts +30 -0
  382. package/dist/vendors/metro-core/src/Terminal.js +100 -0
  383. package/dist/vendors/metro-core/src/canonicalize.js +17 -0
  384. package/dist/vendors/metro-core/src/errors/AmbiguousModuleResolutionError.js +11 -0
  385. package/dist/vendors/metro-core/src/errors/PackageResolutionError.js +18 -0
  386. package/dist/vendors/metro-core/src/errors.js +7 -0
  387. package/dist/vendors/metro-core/src/index.js +11 -0
  388. package/dist/vendors/metro-inspector-proxy/src/Device.js +398 -0
  389. package/dist/vendors/metro-inspector-proxy/src/InspectorProxy.d.ts +21 -0
  390. package/dist/vendors/metro-inspector-proxy/src/InspectorProxy.js +153 -0
  391. package/dist/vendors/metro-inspector-proxy/src/cli.js +15 -0
  392. package/dist/vendors/metro-inspector-proxy/src/index.js +23 -0
  393. package/dist/vendors/metro-inspector-proxy/src/types.js +1 -0
  394. package/dist/vendors/metro-transform-worker/src/index.js +430 -0
  395. package/dist/vendors/metro-transform-worker/src/utils/assetTransformer.js +20 -0
  396. package/dist/vendors/metro-transform-worker/src/utils/getMinifier.js +11 -0
  397. package/package.json +162 -0
@@ -0,0 +1,855 @@
1
+ "use strict";
2
+ const { getAsset } = require("./Assets");
3
+ const baseBytecodeBundle = require("./DeltaBundler/Serializers/baseBytecodeBundle");
4
+ const baseJSBundle = require("./DeltaBundler/Serializers/baseJSBundle");
5
+ const getAllFiles = require("./DeltaBundler/Serializers/getAllFiles");
6
+ const getAssets = require("./DeltaBundler/Serializers/getAssets");
7
+ const { getExplodedSourceMap } = require("./DeltaBundler/Serializers/getExplodedSourceMap");
8
+ const getRamBundleInfo = require("./DeltaBundler/Serializers/getRamBundleInfo");
9
+ const sourceMapString = require("./DeltaBundler/Serializers/sourceMapString");
10
+ const IncrementalBundler = require("./IncrementalBundler");
11
+ const ResourceNotFoundError = require("./IncrementalBundler/ResourceNotFoundError");
12
+ const bundleToBytecode = require("./lib/bundleToBytecode");
13
+ const bundleToString = require("./lib/bundleToString");
14
+ const formatBundlingError = require("./lib/formatBundlingError");
15
+ const getGraphId = require("./lib/getGraphId");
16
+ const parseOptionsFromUrl = require("./lib/parseOptionsFromUrl");
17
+ const splitBundleOptions = require("./lib/splitBundleOptions");
18
+ const transformHelpers = require("./lib/transformHelpers");
19
+ const parsePlatformFilePath = require("./node-haste/lib/parsePlatformFilePath");
20
+ const symbolicate = require("./Server/symbolicate");
21
+ const { codeFrameColumns } = require("@babel/code-frame");
22
+ const MultipartResponse = require("./Server/MultipartResponse");
23
+ const debug = require("debug")("Metro:Server");
24
+ const fs = require("graceful-fs");
25
+ const {
26
+ Logger,
27
+ Logger: { createActionStartEntry, createActionEndEntry, log }
28
+ } = require("../../metro-core/src");
29
+ const mime = require("mime-types");
30
+ const nullthrows = require("nullthrows");
31
+ const path = require("path");
32
+ const querystring = require("querystring");
33
+ const url = require("url");
34
+ const DELTA_ID_HEADER = "X-Metro-Delta-ID";
35
+ const FILES_CHANGED_COUNT_HEADER = "X-Metro-Files-Changed-Count";
36
+ function getBytecodeVersion() {
37
+ return require("metro-hermes-compiler").VERSION;
38
+ }
39
+ class Server {
40
+ _bundler;
41
+ _config;
42
+ _createModuleId;
43
+ _isEnded;
44
+ _logger;
45
+ _nextBundleBuildID;
46
+ _platforms;
47
+ _reporter;
48
+ _serverOptions;
49
+ constructor(config, options) {
50
+ this._config = config;
51
+ this._serverOptions = options;
52
+ if (this._config.resetCache) {
53
+ this._config.cacheStores.forEach((store) => store.clear());
54
+ this._config.reporter.update({ type: "transform_cache_reset" });
55
+ }
56
+ this._reporter = config.reporter;
57
+ this._logger = Logger;
58
+ this._platforms = new Set(this._config.resolver.platforms);
59
+ this._isEnded = false;
60
+ this._createModuleId = config.serializer.createModuleIdFactory();
61
+ this._bundler = new IncrementalBundler(config, {
62
+ hasReducedPerformance: options && options.hasReducedPerformance,
63
+ watch: options ? options.watch : void 0
64
+ });
65
+ this._nextBundleBuildID = 1;
66
+ }
67
+ end() {
68
+ if (!this._isEnded) {
69
+ this._bundler.end();
70
+ this._isEnded = true;
71
+ }
72
+ }
73
+ getBundler() {
74
+ return this._bundler;
75
+ }
76
+ getCreateModuleId() {
77
+ return this._createModuleId;
78
+ }
79
+ async build(options) {
80
+ const { entryFile, graphOptions, onProgress, resolverOptions, serializerOptions, transformOptions } = splitBundleOptions(options);
81
+ const { prepend, graph } = await this._bundler.buildGraph(entryFile, transformOptions, resolverOptions, {
82
+ onProgress,
83
+ shallow: graphOptions.shallow
84
+ });
85
+ const entryPoint = this._getEntryPointAbsolutePath(entryFile);
86
+ const bundleOptions = {
87
+ asyncRequireModulePath: await this._resolveRelativePath(this._config.transformer.asyncRequireModulePath, {
88
+ relativeTo: "project",
89
+ resolverOptions,
90
+ transformOptions
91
+ }),
92
+ processModuleFilter: this._config.serializer.processModuleFilter,
93
+ createModuleId: this._createModuleId,
94
+ getRunModuleStatement: this._config.serializer.getRunModuleStatement,
95
+ dev: transformOptions.dev,
96
+ projectRoot: this._config.projectRoot,
97
+ modulesOnly: serializerOptions.modulesOnly,
98
+ runBeforeMainModule: this._config.serializer.getModulesRunBeforeMainModule(
99
+ path.relative(this._config.projectRoot, entryPoint)
100
+ ),
101
+ runModule: serializerOptions.runModule,
102
+ sourceMapUrl: serializerOptions.sourceMapUrl,
103
+ sourceUrl: serializerOptions.sourceUrl,
104
+ inlineSourceMap: serializerOptions.inlineSourceMap,
105
+ serverRoot: this._config.server.unstable_serverRoot ?? this._config.projectRoot
106
+ };
107
+ let bundleCode = null;
108
+ let bundleMap = null;
109
+ if (this._config.serializer.customSerializer) {
110
+ const bundle = await this._config.serializer.customSerializer(entryPoint, prepend, graph, bundleOptions);
111
+ if (typeof bundle === "string") {
112
+ bundleCode = bundle;
113
+ } else {
114
+ bundleCode = bundle.code;
115
+ bundleMap = bundle.map;
116
+ }
117
+ } else {
118
+ bundleCode = bundleToString(baseJSBundle(entryPoint, prepend, graph, bundleOptions)).code;
119
+ }
120
+ if (!bundleMap) {
121
+ bundleMap = sourceMapString([...prepend, ...this._getSortedModules(graph)], {
122
+ excludeSource: serializerOptions.excludeSource,
123
+ processModuleFilter: this._config.serializer.processModuleFilter
124
+ });
125
+ }
126
+ return {
127
+ code: bundleCode,
128
+ map: bundleMap
129
+ };
130
+ }
131
+ async getRamBundleInfo(options) {
132
+ const { entryFile, graphOptions, onProgress, resolverOptions, serializerOptions, transformOptions } = splitBundleOptions(options);
133
+ const { prepend, graph } = await this._bundler.buildGraph(entryFile, transformOptions, resolverOptions, {
134
+ onProgress,
135
+ shallow: graphOptions.shallow
136
+ });
137
+ const entryPoint = this._getEntryPointAbsolutePath(entryFile);
138
+ return await getRamBundleInfo(entryPoint, prepend, graph, {
139
+ asyncRequireModulePath: await this._resolveRelativePath(this._config.transformer.asyncRequireModulePath, {
140
+ relativeTo: "project",
141
+ resolverOptions,
142
+ transformOptions
143
+ }),
144
+ processModuleFilter: this._config.serializer.processModuleFilter,
145
+ createModuleId: this._createModuleId,
146
+ dev: transformOptions.dev,
147
+ excludeSource: serializerOptions.excludeSource,
148
+ getRunModuleStatement: this._config.serializer.getRunModuleStatement,
149
+ getTransformOptions: this._config.transformer.getTransformOptions,
150
+ platform: transformOptions.platform,
151
+ projectRoot: this._config.projectRoot,
152
+ modulesOnly: serializerOptions.modulesOnly,
153
+ runBeforeMainModule: this._config.serializer.getModulesRunBeforeMainModule(
154
+ path.relative(this._config.projectRoot, entryPoint)
155
+ ),
156
+ runModule: serializerOptions.runModule,
157
+ sourceMapUrl: serializerOptions.sourceMapUrl,
158
+ sourceUrl: serializerOptions.sourceUrl,
159
+ inlineSourceMap: serializerOptions.inlineSourceMap,
160
+ serverRoot: this._config.server.unstable_serverRoot ?? this._config.projectRoot
161
+ });
162
+ }
163
+ async getAssets(options) {
164
+ const { entryFile, onProgress, resolverOptions, transformOptions } = splitBundleOptions(options);
165
+ const dependencies = await this._bundler.getDependencies([entryFile], transformOptions, resolverOptions, {
166
+ onProgress,
167
+ shallow: false
168
+ });
169
+ return await getAssets(dependencies, {
170
+ processModuleFilter: this._config.serializer.processModuleFilter,
171
+ assetPlugins: this._config.transformer.assetPlugins,
172
+ platform: transformOptions.platform,
173
+ projectRoot: this._getServerRootDir(),
174
+ publicPath: this._config.transformer.publicPath
175
+ });
176
+ }
177
+ async getOrderedDependencyPaths(options) {
178
+ const {
179
+ entryFile,
180
+ onProgress,
181
+ resolverOptions,
182
+ transformOptions
183
+ /* $FlowFixMe(>=0.122.0 site=react_native_fb) This comment suppresses an
184
+ * error found when Flow v0.122.0 was deployed. To see the error, delete
185
+ * this comment and run Flow. */
186
+ } = splitBundleOptions({
187
+ ...Server.DEFAULT_BUNDLE_OPTIONS,
188
+ ...options,
189
+ bundleType: "bundle"
190
+ });
191
+ const { prepend, graph } = await this._bundler.buildGraph(entryFile, transformOptions, resolverOptions, {
192
+ onProgress,
193
+ shallow: false
194
+ });
195
+ const platform = transformOptions.platform || parsePlatformFilePath(entryFile, this._platforms).platform;
196
+ return await getAllFiles(prepend, graph, {
197
+ platform,
198
+ processModuleFilter: this._config.serializer.processModuleFilter
199
+ });
200
+ }
201
+ _rangeRequestMiddleware(req, res, data, assetPath) {
202
+ if (req.headers && req.headers.range) {
203
+ const [rangeStart, rangeEnd] = req.headers.range.replace(/bytes=/, "").split("-");
204
+ const dataStart = parseInt(rangeStart, 10);
205
+ const dataEnd = rangeEnd ? parseInt(rangeEnd, 10) : data.length - 1;
206
+ const chunksize = dataEnd - dataStart + 1;
207
+ res.writeHead(206, {
208
+ "Accept-Ranges": "bytes",
209
+ "Content-Length": chunksize.toString(),
210
+ "Content-Range": `bytes ${dataStart}-${dataEnd}/${data.length}`,
211
+ "Content-Type": mime.lookup(path.basename(assetPath))
212
+ });
213
+ return data.slice(dataStart, dataEnd + 1);
214
+ }
215
+ return data;
216
+ }
217
+ async _processSingleAssetRequest(req, res) {
218
+ const urlObj = url.parse(decodeURI(req.url), true);
219
+ let [, assetPath] = urlObj && urlObj.pathname && urlObj.pathname.match(/^\/assets\/(.+)$/) || [];
220
+ if (!assetPath && urlObj && urlObj.query && urlObj.query.unstable_path) {
221
+ const [, actualPath, secondaryQuery] = nullthrows(urlObj.query.unstable_path.match(/^([^?]*)\??(.*)$/));
222
+ if (secondaryQuery) {
223
+ Object.assign(urlObj.query, querystring.parse(secondaryQuery));
224
+ }
225
+ assetPath = actualPath;
226
+ }
227
+ if (!assetPath) {
228
+ throw new Error("Could not extract asset path from URL");
229
+ }
230
+ const processingAssetRequestLogEntry = log(
231
+ createActionStartEntry({
232
+ action_name: "Processing asset request",
233
+ asset: assetPath[1]
234
+ })
235
+ );
236
+ try {
237
+ const data = await getAsset(
238
+ assetPath,
239
+ this._config.projectRoot,
240
+ this._config.watchFolders,
241
+ urlObj.query.platform,
242
+ this._config.resolver.assetExts
243
+ );
244
+ if (process.env.REACT_NATIVE_ENABLE_ASSET_CACHING === true) {
245
+ res.setHeader("Cache-Control", "max-age=31536000");
246
+ }
247
+ res.end(this._rangeRequestMiddleware(req, res, data, assetPath));
248
+ process.nextTick(() => {
249
+ log(createActionEndEntry(processingAssetRequestLogEntry));
250
+ });
251
+ } catch (error) {
252
+ console.error(error.stack);
253
+ res.writeHead(404);
254
+ res.end("Asset not found");
255
+ }
256
+ }
257
+ processRequest = (req, res, next) => {
258
+ this._processRequest(req, res, next).catch(next);
259
+ };
260
+ _parseOptions(url2) {
261
+ return parseOptionsFromUrl(url2, new Set(this._config.resolver.platforms), getBytecodeVersion());
262
+ }
263
+ async _processRequest(req, res, next) {
264
+ const originalUrl = req.url;
265
+ req.url = this._config.server.rewriteRequestUrl(req.url);
266
+ const urlObj = url.parse(req.url, true);
267
+ const { host } = req.headers;
268
+ debug(
269
+ `Handling request: ${host ? "http://" + host : ""}${req.url}` + (originalUrl !== req.url ? ` (rewritten from ${originalUrl})` : "")
270
+ );
271
+ const formattedUrl = url.format({
272
+ ...urlObj,
273
+ host,
274
+ protocol: "http"
275
+ });
276
+ const pathname = urlObj.pathname || "";
277
+ if (pathname.endsWith(".bundle")) {
278
+ const options = this._parseOptions(formattedUrl);
279
+ if (options.runtimeBytecodeVersion) {
280
+ await this._processBytecodeBundleRequest(req, res, options);
281
+ } else {
282
+ await this._processBundleRequest(req, res, options);
283
+ }
284
+ if (this._serverOptions && this._serverOptions.onBundleBuilt) {
285
+ this._serverOptions.onBundleBuilt(pathname);
286
+ }
287
+ } else if (pathname.endsWith(".map")) {
288
+ res.setHeader("Access-Control-Allow-Origin", "devtools://devtools");
289
+ await this._processSourceMapRequest(req, res, this._parseOptions(formattedUrl));
290
+ } else if (pathname.endsWith(".assets")) {
291
+ await this._processAssetsRequest(req, res, this._parseOptions(formattedUrl));
292
+ } else if (pathname.startsWith("/assets/") || pathname === "/assets") {
293
+ await this._processSingleAssetRequest(req, res);
294
+ } else if (pathname === "/symbolicate") {
295
+ await this._symbolicate(req, res);
296
+ } else {
297
+ next();
298
+ }
299
+ }
300
+ _createRequestProcessor({ createStartEntry, createEndEntry, build, delete: deleteFn, finish }) {
301
+ return async function requestProcessor(req, res, bundleOptions) {
302
+ const { entryFile, graphOptions, resolverOptions, serializerOptions, transformOptions } = splitBundleOptions(bundleOptions);
303
+ const resolvedEntryFilePath = await this._resolveRelativePath(entryFile, {
304
+ relativeTo: "server",
305
+ resolverOptions,
306
+ transformOptions
307
+ });
308
+ const graphId = getGraphId(resolvedEntryFilePath, transformOptions, {
309
+ experimentalImportBundleSupport: this._config.transformer.experimentalImportBundleSupport,
310
+ unstable_allowRequireContext: this._config.transformer.unstable_allowRequireContext,
311
+ resolverOptions,
312
+ shallow: graphOptions.shallow
313
+ });
314
+ if (deleteFn && req.method === "DELETE") {
315
+ const deleteContext = {
316
+ graphId,
317
+ req,
318
+ res
319
+ };
320
+ try {
321
+ await deleteFn(deleteContext);
322
+ } catch (error) {
323
+ const formattedError = formatBundlingError(error);
324
+ const status = error instanceof ResourceNotFoundError ? 404 : 500;
325
+ res.writeHead(status, {
326
+ "Content-Type": "application/json; charset=UTF-8"
327
+ });
328
+ res.end(JSON.stringify(formattedError));
329
+ }
330
+ return;
331
+ }
332
+ const mres = MultipartResponse.wrapIfSupported(req, res);
333
+ const buildID = this.getNewBuildID();
334
+ let onProgress = null;
335
+ let lastProgress = -1;
336
+ if (this._config.reporter) {
337
+ onProgress = (transformedFileCount, totalFileCount) => {
338
+ const currentProgress = parseInt(transformedFileCount / totalFileCount * 100, 10);
339
+ if (currentProgress > lastProgress || totalFileCount < 10) {
340
+ if (mres instanceof MultipartResponse) {
341
+ mres.writeChunk(
342
+ { "Content-Type": "application/json" },
343
+ JSON.stringify({
344
+ done: transformedFileCount,
345
+ total: totalFileCount
346
+ })
347
+ );
348
+ }
349
+ if (res.socket != null && res.socket.uncork != null) {
350
+ res.socket.uncork();
351
+ }
352
+ lastProgress = currentProgress;
353
+ }
354
+ this._reporter.update({
355
+ buildID,
356
+ type: "bundle_transform_progressed",
357
+ transformedFileCount,
358
+ totalFileCount
359
+ });
360
+ };
361
+ }
362
+ this._reporter.update({
363
+ buildID,
364
+ bundleDetails: {
365
+ bundleType: bundleOptions.bundleType,
366
+ dev: transformOptions.dev,
367
+ entryFile: resolvedEntryFilePath,
368
+ minify: transformOptions.minify,
369
+ platform: transformOptions.platform,
370
+ runtimeBytecodeVersion: transformOptions.runtimeBytecodeVersion
371
+ },
372
+ type: "bundle_build_started"
373
+ });
374
+ const startContext = {
375
+ buildID,
376
+ bundleOptions,
377
+ entryFile: resolvedEntryFilePath,
378
+ graphId,
379
+ graphOptions,
380
+ mres,
381
+ onProgress,
382
+ req,
383
+ resolverOptions,
384
+ serializerOptions,
385
+ transformOptions
386
+ };
387
+ const logEntry = log(createActionStartEntry(createStartEntry(startContext)));
388
+ let result;
389
+ try {
390
+ result = await build(startContext);
391
+ } catch (error) {
392
+ const formattedError = formatBundlingError(error);
393
+ const status = error instanceof ResourceNotFoundError ? 404 : 500;
394
+ mres.writeHead(status, {
395
+ "Content-Type": "application/json; charset=UTF-8"
396
+ });
397
+ mres.end(JSON.stringify(formattedError));
398
+ this._reporter.update({
399
+ buildID,
400
+ type: "bundle_build_failed",
401
+ bundleOptions
402
+ });
403
+ this._reporter.update({ error, type: "bundling_error" });
404
+ log({
405
+ action_name: "bundling_error",
406
+ error_type: formattedError.type,
407
+ log_entry_label: "bundling_error",
408
+ bundle_id: graphId,
409
+ build_id: buildID,
410
+ stack: formattedError.message
411
+ });
412
+ debug("Bundling error", error);
413
+ return;
414
+ }
415
+ const endContext = {
416
+ ...startContext,
417
+ result
418
+ };
419
+ finish(endContext);
420
+ this._reporter.update({
421
+ buildID,
422
+ type: "bundle_build_done"
423
+ });
424
+ log(
425
+ /* $FlowFixMe(>=0.122.0 site=react_native_fb) This comment suppresses
426
+ * an error found when Flow v0.122.0 was deployed. To see the error,
427
+ * delete this comment and run Flow. */
428
+ createActionEndEntry({
429
+ ...logEntry,
430
+ ...createEndEntry(endContext)
431
+ })
432
+ );
433
+ };
434
+ }
435
+ _processBundleRequest = this._createRequestProcessor({
436
+ createStartEntry(context) {
437
+ return {
438
+ action_name: "Requesting bundle",
439
+ bundle_url: context.req.url,
440
+ entry_point: context.entryFile,
441
+ bundler: "delta",
442
+ build_id: context.buildID,
443
+ bundle_options: context.bundleOptions,
444
+ bundle_hash: context.graphId
445
+ };
446
+ },
447
+ createEndEntry(context) {
448
+ return {
449
+ outdated_modules: context.result.numModifiedFiles
450
+ };
451
+ },
452
+ build: async ({
453
+ entryFile,
454
+ graphId,
455
+ graphOptions,
456
+ onProgress,
457
+ resolverOptions,
458
+ serializerOptions,
459
+ transformOptions
460
+ }) => {
461
+ const revPromise = this._bundler.getRevisionByGraphId(graphId);
462
+ const { delta, revision } = await (revPromise != null ? this._bundler.updateGraph(await revPromise, false) : this._bundler.initializeGraph(entryFile, transformOptions, resolverOptions, {
463
+ onProgress,
464
+ shallow: graphOptions.shallow
465
+ }));
466
+ const serializer = this._config.serializer.customSerializer || ((...args) => bundleToString(baseJSBundle(...args)).code);
467
+ const bundle = await serializer(entryFile, revision.prepend, revision.graph, {
468
+ asyncRequireModulePath: await this._resolveRelativePath(this._config.transformer.asyncRequireModulePath, {
469
+ relativeTo: "project",
470
+ resolverOptions,
471
+ transformOptions
472
+ }),
473
+ processModuleFilter: this._config.serializer.processModuleFilter,
474
+ createModuleId: this._createModuleId,
475
+ getRunModuleStatement: this._config.serializer.getRunModuleStatement,
476
+ dev: transformOptions.dev,
477
+ projectRoot: this._config.projectRoot,
478
+ modulesOnly: serializerOptions.modulesOnly,
479
+ runBeforeMainModule: this._config.serializer.getModulesRunBeforeMainModule(
480
+ path.relative(this._config.projectRoot, entryFile)
481
+ ),
482
+ runModule: serializerOptions.runModule,
483
+ sourceMapUrl: serializerOptions.sourceMapUrl,
484
+ sourceUrl: serializerOptions.sourceUrl,
485
+ inlineSourceMap: serializerOptions.inlineSourceMap,
486
+ serverRoot: this._config.server.unstable_serverRoot ?? this._config.projectRoot
487
+ });
488
+ const bundleCode = typeof bundle === "string" ? bundle : bundle.code;
489
+ return {
490
+ numModifiedFiles: delta.reset ? delta.added.size + revision.prepend.length : delta.added.size + delta.modified.size + delta.deleted.size,
491
+ lastModifiedDate: revision.date,
492
+ nextRevId: revision.id,
493
+ bundle: bundleCode
494
+ };
495
+ },
496
+ finish({ req, mres, result }) {
497
+ if (
498
+ // We avoid parsing the dates since the client should never send a more
499
+ // recent date than the one returned by the Delta Bundler (if that's the
500
+ // case it's fine to return the whole bundle).
501
+ req.headers["if-modified-since"] === result.lastModifiedDate.toUTCString()
502
+ ) {
503
+ debug("Responding with 304");
504
+ mres.writeHead(304);
505
+ mres.end();
506
+ } else {
507
+ mres.setHeader(FILES_CHANGED_COUNT_HEADER, String(result.numModifiedFiles));
508
+ mres.setHeader(DELTA_ID_HEADER, String(result.nextRevId));
509
+ mres.setHeader("Content-Type", "application/javascript; charset=UTF-8");
510
+ mres.setHeader("Last-Modified", result.lastModifiedDate.toUTCString());
511
+ mres.setHeader("Content-Length", String(Buffer.byteLength(result.bundle)));
512
+ mres.end(result.bundle);
513
+ }
514
+ },
515
+ delete: async ({ graphId, res }) => {
516
+ await this._bundler.endGraph(graphId);
517
+ res.statusCode = 204;
518
+ res.end();
519
+ }
520
+ });
521
+ _processBytecodeBundleRequest = this._createRequestProcessor({
522
+ createStartEntry(context) {
523
+ return {
524
+ action_name: "Requesting bundle",
525
+ bundle_url: context.req.url,
526
+ entry_point: context.entryFile,
527
+ bundler: "delta",
528
+ build_id: context.buildID,
529
+ bundle_options: context.bundleOptions,
530
+ bundle_hash: context.graphId
531
+ };
532
+ },
533
+ createEndEntry(context) {
534
+ return {
535
+ outdated_modules: context.result.numModifiedFiles
536
+ };
537
+ },
538
+ build: async ({
539
+ entryFile,
540
+ graphId,
541
+ graphOptions,
542
+ onProgress,
543
+ resolverOptions,
544
+ serializerOptions,
545
+ transformOptions
546
+ }) => {
547
+ const revPromise = this._bundler.getRevisionByGraphId(graphId);
548
+ const { delta, revision } = await (revPromise != null ? this._bundler.updateGraph(await revPromise, false) : this._bundler.initializeGraph(entryFile, transformOptions, resolverOptions, {
549
+ onProgress,
550
+ shallow: graphOptions.shallow
551
+ }));
552
+ const bundle = bundleToBytecode(
553
+ baseBytecodeBundle(entryFile, revision.prepend, revision.graph, {
554
+ asyncRequireModulePath: await this._resolveRelativePath(this._config.transformer.asyncRequireModulePath, {
555
+ relativeTo: "project",
556
+ resolverOptions,
557
+ transformOptions
558
+ }),
559
+ processModuleFilter: this._config.serializer.processModuleFilter,
560
+ createModuleId: this._createModuleId,
561
+ getRunModuleStatement: this._config.serializer.getRunModuleStatement,
562
+ dev: transformOptions.dev,
563
+ projectRoot: this._config.projectRoot,
564
+ modulesOnly: serializerOptions.modulesOnly,
565
+ runBeforeMainModule: this._config.serializer.getModulesRunBeforeMainModule(
566
+ path.relative(this._config.projectRoot, entryFile)
567
+ ),
568
+ runModule: serializerOptions.runModule,
569
+ sourceMapUrl: serializerOptions.sourceMapUrl,
570
+ sourceUrl: serializerOptions.sourceUrl,
571
+ inlineSourceMap: serializerOptions.inlineSourceMap,
572
+ serverRoot: this._config.server.unstable_serverRoot ?? this._config.projectRoot
573
+ })
574
+ );
575
+ return {
576
+ numModifiedFiles: delta.reset ? delta.added.size + revision.prepend.length : delta.added.size + delta.modified.size + delta.deleted.size,
577
+ lastModifiedDate: revision.date,
578
+ nextRevId: revision.id,
579
+ bytecode: bundle.bytecode
580
+ };
581
+ },
582
+ finish({ req, mres, result }) {
583
+ if (
584
+ // We avoid parsing the dates since the client should never send a more
585
+ // recent date than the one returned by the Delta Bundler (if that's the
586
+ // case it's fine to return the whole bundle).
587
+ req.headers["if-modified-since"] === result.lastModifiedDate.toUTCString()
588
+ ) {
589
+ debug("Responding with 304");
590
+ mres.writeHead(304);
591
+ mres.end();
592
+ } else {
593
+ mres.setHeader(FILES_CHANGED_COUNT_HEADER, String(result.numModifiedFiles));
594
+ mres.setHeader(DELTA_ID_HEADER, String(result.nextRevId));
595
+ mres.setHeader("Content-Type", "application/x-metro-bytecode-bundle");
596
+ mres.setHeader("Last-Modified", result.lastModifiedDate.toUTCString());
597
+ mres.setHeader("Content-Length", String(Buffer.byteLength(result.bytecode)));
598
+ mres.end(result.bytecode);
599
+ }
600
+ }
601
+ });
602
+ // This function ensures that modules in source maps are sorted in the same
603
+ // order as in a plain JS bundle.
604
+ _getSortedModules(graph) {
605
+ const modules = [...graph.dependencies.values()];
606
+ for (const module2 of modules) {
607
+ this._createModuleId(module2.path);
608
+ }
609
+ return modules.sort((a, b) => this._createModuleId(a.path) - this._createModuleId(b.path));
610
+ }
611
+ _processSourceMapRequest = this._createRequestProcessor({
612
+ createStartEntry(context) {
613
+ return {
614
+ action_name: "Requesting sourcemap",
615
+ bundle_url: context.req.url,
616
+ entry_point: context.entryFile,
617
+ bundler: "delta"
618
+ };
619
+ },
620
+ createEndEntry(context) {
621
+ return {
622
+ bundler: "delta"
623
+ };
624
+ },
625
+ build: async ({
626
+ entryFile,
627
+ graphId,
628
+ graphOptions,
629
+ onProgress,
630
+ resolverOptions,
631
+ serializerOptions,
632
+ transformOptions
633
+ }) => {
634
+ let revision;
635
+ const revPromise = this._bundler.getRevisionByGraphId(graphId);
636
+ if (revPromise == null) {
637
+ ({ revision } = await this._bundler.initializeGraph(entryFile, transformOptions, resolverOptions, {
638
+ onProgress,
639
+ shallow: graphOptions.shallow
640
+ }));
641
+ } else {
642
+ ({ revision } = await this._bundler.updateGraph(await revPromise, false));
643
+ }
644
+ let { prepend, graph } = revision;
645
+ if (serializerOptions.modulesOnly) {
646
+ prepend = [];
647
+ }
648
+ return sourceMapString([...prepend, ...this._getSortedModules(graph)], {
649
+ excludeSource: serializerOptions.excludeSource,
650
+ processModuleFilter: this._config.serializer.processModuleFilter
651
+ });
652
+ },
653
+ finish({ mres, result }) {
654
+ mres.setHeader("Content-Type", "application/json");
655
+ mres.end(result.toString());
656
+ }
657
+ });
658
+ _processAssetsRequest = this._createRequestProcessor({
659
+ createStartEntry(context) {
660
+ return {
661
+ action_name: "Requesting assets",
662
+ bundle_url: context.req.url,
663
+ entry_point: context.entryFile,
664
+ bundler: "delta"
665
+ };
666
+ },
667
+ createEndEntry(context) {
668
+ return {
669
+ bundler: "delta"
670
+ };
671
+ },
672
+ build: async ({ entryFile, onProgress, resolverOptions, transformOptions }) => {
673
+ const dependencies = await this._bundler.getDependencies([entryFile], transformOptions, resolverOptions, {
674
+ onProgress,
675
+ shallow: false
676
+ });
677
+ return await getAssets(dependencies, {
678
+ processModuleFilter: this._config.serializer.processModuleFilter,
679
+ assetPlugins: this._config.transformer.assetPlugins,
680
+ platform: transformOptions.platform,
681
+ publicPath: this._config.transformer.publicPath,
682
+ projectRoot: this._config.projectRoot
683
+ });
684
+ },
685
+ finish({ mres, result }) {
686
+ mres.setHeader("Content-Type", "application/json");
687
+ mres.end(JSON.stringify(result));
688
+ }
689
+ });
690
+ async _symbolicate(req, res) {
691
+ const getCodeFrame = (urls, symbolicatedStack) => {
692
+ for (let i = 0; i < symbolicatedStack.length; i++) {
693
+ const { collapse, column, file, lineNumber } = symbolicatedStack[i];
694
+ const fileAbsolute = path.resolve(this._config.projectRoot, file ?? "");
695
+ if (collapse || lineNumber == null || urls.has(fileAbsolute)) {
696
+ continue;
697
+ }
698
+ try {
699
+ return {
700
+ content: codeFrameColumns(
701
+ fs.readFileSync(fileAbsolute, "utf8"),
702
+ {
703
+ // Metro returns 0 based columns but codeFrameColumns expects 1-based columns
704
+ // $FlowFixMe[unsafe-addition]
705
+ start: { column: column + 1, line: lineNumber }
706
+ },
707
+ { forceColor: true }
708
+ ),
709
+ location: {
710
+ row: lineNumber,
711
+ column
712
+ },
713
+ fileName: file
714
+ };
715
+ } catch (error) {
716
+ console.error(error);
717
+ }
718
+ }
719
+ return null;
720
+ };
721
+ try {
722
+ const symbolicatingLogEntry = log(createActionStartEntry("Symbolicating"));
723
+ debug("Start symbolication");
724
+ const body = await req.rawBody;
725
+ const stack = JSON.parse(body).stack.map((frame) => {
726
+ if (frame.file && frame.file.includes("://")) {
727
+ return {
728
+ ...frame,
729
+ file: this._config.server.rewriteRequestUrl(frame.file)
730
+ };
731
+ }
732
+ return frame;
733
+ });
734
+ const urls = /* @__PURE__ */ new Set();
735
+ stack.forEach((frame) => {
736
+ const sourceUrl = frame.file;
737
+ if (sourceUrl != null && !urls.has(sourceUrl) && !sourceUrl.endsWith("/debuggerWorker.js") && sourceUrl.startsWith("http")) {
738
+ urls.add(sourceUrl);
739
+ }
740
+ });
741
+ debug("Getting source maps for symbolication");
742
+ const sourceMaps = await Promise.all(
743
+ // $FlowFixMe[method-unbinding] added when improving typing for this parameters
744
+ Array.from(urls.values()).map(this._explodedSourceMapForURL, this)
745
+ );
746
+ debug("Performing fast symbolication");
747
+ const symbolicatedStack = await await symbolicate(stack, zip(urls.values(), sourceMaps), this._config);
748
+ debug("Symbolication done");
749
+ res.end(
750
+ JSON.stringify({
751
+ codeFrame: getCodeFrame(urls, symbolicatedStack),
752
+ stack: symbolicatedStack
753
+ })
754
+ );
755
+ process.nextTick(() => {
756
+ log(createActionEndEntry(symbolicatingLogEntry));
757
+ });
758
+ } catch (error) {
759
+ console.error(error.stack || error);
760
+ res.statusCode = 500;
761
+ res.end(JSON.stringify({ error: error.message }));
762
+ }
763
+ }
764
+ async _explodedSourceMapForURL(reqUrl) {
765
+ const options = parseOptionsFromUrl(reqUrl, new Set(this._config.resolver.platforms), getBytecodeVersion());
766
+ const { entryFile, graphOptions, onProgress, resolverOptions, serializerOptions, transformOptions } = splitBundleOptions(options);
767
+ const resolvedEntryFilePath = await this._resolveRelativePath(entryFile, {
768
+ relativeTo: "server",
769
+ resolverOptions,
770
+ transformOptions
771
+ });
772
+ const graphId = getGraphId(resolvedEntryFilePath, transformOptions, {
773
+ experimentalImportBundleSupport: this._config.transformer.experimentalImportBundleSupport,
774
+ unstable_allowRequireContext: this._config.transformer.unstable_allowRequireContext,
775
+ resolverOptions,
776
+ shallow: graphOptions.shallow
777
+ });
778
+ let revision;
779
+ const revPromise = this._bundler.getRevisionByGraphId(graphId);
780
+ if (revPromise == null) {
781
+ ({ revision } = await this._bundler.initializeGraph(resolvedEntryFilePath, transformOptions, resolverOptions, {
782
+ onProgress,
783
+ shallow: graphOptions.shallow
784
+ }));
785
+ } else {
786
+ ({ revision } = await this._bundler.updateGraph(await revPromise, false));
787
+ }
788
+ let { prepend, graph } = revision;
789
+ if (serializerOptions.modulesOnly) {
790
+ prepend = [];
791
+ }
792
+ return getExplodedSourceMap([...prepend, ...this._getSortedModules(graph)], {
793
+ processModuleFilter: this._config.serializer.processModuleFilter
794
+ });
795
+ }
796
+ async _resolveRelativePath(filePath, { relativeTo, resolverOptions, transformOptions }) {
797
+ const resolutionFn = await transformHelpers.getResolveDependencyFn(
798
+ this._bundler.getBundler(),
799
+ transformOptions.platform,
800
+ resolverOptions
801
+ );
802
+ const rootDir = relativeTo === "server" ? this._getServerRootDir() : this._config.projectRoot;
803
+ return resolutionFn(`${rootDir}/.`, filePath);
804
+ }
805
+ getNewBuildID() {
806
+ return (this._nextBundleBuildID++).toString(36);
807
+ }
808
+ getPlatforms() {
809
+ return this._config.resolver.platforms;
810
+ }
811
+ getWatchFolders() {
812
+ return this._config.watchFolders;
813
+ }
814
+ static DEFAULT_GRAPH_OPTIONS = {
815
+ customResolverOptions: /* @__PURE__ */ Object.create(null),
816
+ customTransformOptions: /* @__PURE__ */ Object.create(null),
817
+ dev: true,
818
+ hot: false,
819
+ minify: false,
820
+ runtimeBytecodeVersion: null,
821
+ unstable_transformProfile: "default"
822
+ };
823
+ static DEFAULT_BUNDLE_OPTIONS = {
824
+ ...Server.DEFAULT_GRAPH_OPTIONS,
825
+ excludeSource: false,
826
+ inlineSourceMap: false,
827
+ modulesOnly: false,
828
+ onProgress: null,
829
+ runModule: true,
830
+ shallow: false,
831
+ sourceMapUrl: null,
832
+ sourceUrl: null
833
+ };
834
+ _getServerRootDir() {
835
+ return this._config.server.unstable_serverRoot ?? this._config.projectRoot;
836
+ }
837
+ _getEntryPointAbsolutePath(entryFile) {
838
+ return path.resolve(this._getServerRootDir(), entryFile);
839
+ }
840
+ // Wait for the server to finish initializing.
841
+ async ready() {
842
+ await this._bundler.ready();
843
+ }
844
+ }
845
+ function* zip(xs, ys) {
846
+ const ysIter = ys[Symbol.iterator]();
847
+ for (const x of xs) {
848
+ const y = ysIter.next();
849
+ if (y.done) {
850
+ return;
851
+ }
852
+ yield [x, y.value];
853
+ }
854
+ }
855
+ module.exports = Server;