@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,98 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var CountingSet_exports = {};
20
+ __export(CountingSet_exports, {
21
+ default: () => CountingSet
22
+ });
23
+ module.exports = __toCommonJS(CountingSet_exports);
24
+ class CountingSet {
25
+ #map = /* @__PURE__ */ new Map();
26
+ constructor(items) {
27
+ if (items) {
28
+ if (items instanceof CountingSet) {
29
+ this.#map = new Map(items.#map);
30
+ } else {
31
+ for (const item of items) {
32
+ this.add(item);
33
+ }
34
+ }
35
+ }
36
+ }
37
+ has(item) {
38
+ return this.#map.has(item);
39
+ }
40
+ add(item) {
41
+ const newCount = this.count(item) + 1;
42
+ this.#map.set(item, newCount);
43
+ }
44
+ delete(item) {
45
+ const newCount = this.count(item) - 1;
46
+ if (newCount <= 0) {
47
+ this.#map.delete(item);
48
+ } else {
49
+ this.#map.set(item, newCount);
50
+ }
51
+ }
52
+ keys() {
53
+ return this.#map.keys();
54
+ }
55
+ values() {
56
+ return this.#map.keys();
57
+ }
58
+ *entries() {
59
+ for (const item of this) {
60
+ yield [item, item];
61
+ }
62
+ }
63
+ // Iterate over unique entries
64
+ // $FlowIssue[unsupported-syntax]
65
+ [Symbol.iterator]() {
66
+ return this.values();
67
+ }
68
+ /*::
69
+ // For Flow's benefit
70
+ @@iterator(): Iterator<T> {
71
+ return this.values();
72
+ }
73
+ */
74
+ // Number of unique entries
75
+ // $FlowIssue[unsafe-getters-setters]
76
+ get size() {
77
+ return this.#map.size;
78
+ }
79
+ count(item) {
80
+ return this.#map.get(item) ?? 0;
81
+ }
82
+ clear() {
83
+ this.#map.clear();
84
+ }
85
+ forEach(callbackFn, thisArg) {
86
+ for (const item of this) {
87
+ callbackFn.call(thisArg, item, item, this);
88
+ }
89
+ }
90
+ // For Jest purposes. Ideally a custom serializer would be enough, but in
91
+ // practice there is hardcoded magic for Set in toEqual (etc) that we cannot
92
+ // extend to custom collection classes. Instead let's assume values are
93
+ // sortable ( = strings) and make this look like an array with some stable
94
+ // order.
95
+ toJSON() {
96
+ return [...this].sort();
97
+ }
98
+ }
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ class JsonReporter {
3
+ _stream;
4
+ constructor(stream) {
5
+ this._stream = stream;
6
+ }
7
+ /**
8
+ * There is a special case for errors because they have non-enumerable fields.
9
+ * (Perhaps we should switch in favor of plain object?)
10
+ */
11
+ update(event) {
12
+ if (Object.prototype.toString.call(event.error) === "[object Error]") {
13
+ event = Object.assign(event, {
14
+ message: event.error.message,
15
+ stack: event.error.stack
16
+ });
17
+ }
18
+ this._stream.write(JSON.stringify(event) + "\n");
19
+ }
20
+ }
21
+ module.exports = JsonReporter;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ const MAGIC_NUMBER = require("../shared/output/RamBundle/magic-number");
3
+ const SIZEOF_UINT32 = 4;
4
+ const HEADER_SIZE = 3;
5
+ class RamBundleParser {
6
+ _buffer;
7
+ _numModules;
8
+ _startupCodeLength;
9
+ _startOffset;
10
+ // $FlowFixMe[missing-local-annot]
11
+ constructor(buffer) {
12
+ this._buffer = buffer;
13
+ if (this._readPosition(0) !== MAGIC_NUMBER) {
14
+ throw new Error("File is not a RAM bundle file");
15
+ }
16
+ this._numModules = this._readPosition(1);
17
+ this._startupCodeLength = this._readPosition(2);
18
+ this._startOffset = (HEADER_SIZE + this._numModules * 2) * SIZEOF_UINT32;
19
+ }
20
+ _readPosition(pos) {
21
+ return this._buffer.readUInt32LE(pos * SIZEOF_UINT32);
22
+ }
23
+ getStartupCode() {
24
+ const start = this._startOffset;
25
+ const end = start + this._startupCodeLength - 1;
26
+ return this._buffer.toString("utf8", start, end);
27
+ }
28
+ getModule(id) {
29
+ const moduleOffset = this._readPosition(HEADER_SIZE + id * 2);
30
+ const moduleLength = this._readPosition(HEADER_SIZE + id * 2 + 1);
31
+ const start = this._startOffset + moduleOffset;
32
+ const end = start + moduleLength - 1;
33
+ return this._buffer.toString("utf8", start, end);
34
+ }
35
+ }
36
+ module.exports = RamBundleParser;
@@ -0,0 +1,18 @@
1
+ type Terminal = any;
2
+ type ReportableEvent = any;
3
+ type TerminalReportableEvent =
4
+ | ReportableEvent
5
+ | {
6
+ buildID: string;
7
+ type: 'bundle_transform_progressed_throttled';
8
+ transformedFileCount: number;
9
+ totalFileCount: number;
10
+ };
11
+
12
+ declare class TerminalReporter {
13
+ readonly terminal: Terminal;
14
+ constructor(terminal: Terminal);
15
+ update(event: TerminalReportableEvent): void;
16
+ }
17
+
18
+ export default TerminalReporter;
@@ -0,0 +1,258 @@
1
+ "use strict";
2
+ const logToConsole = require("./logToConsole");
3
+ const reporting = require("./reporting");
4
+ const chalk = require("chalk");
5
+ const throttle = require("lodash.throttle");
6
+ const { AmbiguousModuleResolutionError } = require("../../../metro-core/src");
7
+ const path = require("path");
8
+ const debug = require("debug")("metro");
9
+ const GLOBAL_CACHE_DISABLED_MESSAGE_FORMAT = "The global cache is now disabled because %s";
10
+ const DARK_BLOCK_CHAR = "\u2593";
11
+ const LIGHT_BLOCK_CHAR = "\u2591";
12
+ const MAX_PROGRESS_BAR_CHAR_WIDTH = 16;
13
+ class TerminalReporter {
14
+ /**
15
+ * The bundle builds for which we are actively maintaining the status on the
16
+ * terminal, ie. showing a progress bar. There can be several bundles being
17
+ * built at the same time.
18
+ */
19
+ _activeBundles;
20
+ _scheduleUpdateBundleProgress;
21
+ terminal;
22
+ constructor(terminal) {
23
+ this._activeBundles = /* @__PURE__ */ new Map();
24
+ this._scheduleUpdateBundleProgress = throttle((data) => {
25
+ this.update({ ...data, type: "bundle_transform_progressed_throttled" });
26
+ }, 100);
27
+ this.terminal = terminal;
28
+ }
29
+ /**
30
+ * Construct a message that represents the progress of a
31
+ * single bundle build, for example:
32
+ *
33
+ * BUNDLE path/to/bundle.js ▓▓▓▓▓░░░░░░░░░░░ 36.6% (4790/7922)
34
+ */
35
+ _getBundleStatusMessage({ bundleDetails: { entryFile, bundleType, runtimeBytecodeVersion }, transformedFileCount, totalFileCount, ratio }, phase) {
36
+ if (runtimeBytecodeVersion) {
37
+ bundleType = "bytecodebundle";
38
+ }
39
+ const localPath = path.relative(".", entryFile);
40
+ const filledBar = Math.floor(ratio * MAX_PROGRESS_BAR_CHAR_WIDTH);
41
+ const bundleTypeColor = phase === "done" ? chalk.green : phase === "failed" ? chalk.red : chalk.yellow;
42
+ const progress = phase === "in_progress" ? chalk.green.bgGreen(DARK_BLOCK_CHAR.repeat(filledBar)) + chalk.bgWhite.white(LIGHT_BLOCK_CHAR.repeat(MAX_PROGRESS_BAR_CHAR_WIDTH - filledBar)) + chalk.bold(` ${(100 * ratio).toFixed(1)}% `) + chalk.dim(`(${transformedFileCount}/${totalFileCount})`) : "";
43
+ return bundleTypeColor.inverse.bold(` ${bundleType.toUpperCase()} `) + chalk.reset.dim(` ${path.dirname(localPath)}/`) + chalk.bold(path.basename(localPath)) + " " + progress + "\n";
44
+ }
45
+ _logCacheDisabled(reason) {
46
+ const format = GLOBAL_CACHE_DISABLED_MESSAGE_FORMAT;
47
+ switch (reason) {
48
+ case "too_many_errors":
49
+ reporting.logWarning(this.terminal, format, "it has been failing too many times.");
50
+ break;
51
+ case "too_many_misses":
52
+ reporting.logWarning(this.terminal, format, "it has been missing too many consecutive keys.");
53
+ break;
54
+ }
55
+ }
56
+ _logBundleBuildDone(buildID) {
57
+ const progress = this._activeBundles.get(buildID);
58
+ if (progress != null) {
59
+ const msg = this._getBundleStatusMessage(
60
+ {
61
+ ...progress,
62
+ ratio: 1,
63
+ transformedFileCount: progress.totalFileCount
64
+ },
65
+ "done"
66
+ );
67
+ this.terminal.log(msg);
68
+ this._activeBundles.delete(buildID);
69
+ }
70
+ }
71
+ _logBundleBuildFailed(buildID) {
72
+ const progress = this._activeBundles.get(buildID);
73
+ if (progress != null) {
74
+ const msg = this._getBundleStatusMessage(progress, "failed");
75
+ this.terminal.log(msg);
76
+ }
77
+ }
78
+ _logInitializing(port, hasReducedPerformance) {
79
+ }
80
+ _logInitializingFailed(port, error) {
81
+ if (error.code === "EADDRINUSE") {
82
+ this.terminal.log(chalk.bgRed.bold(" ERROR "), chalk.red("Metro can't listen on port", chalk.bold(String(port))));
83
+ this.terminal.log("Most likely another process is already using this port");
84
+ this.terminal.log("Run the following command to find out which process:");
85
+ this.terminal.log("\n ", chalk.bold("lsof -i :" + port), "\n");
86
+ this.terminal.log("Then, you can either shut down the other process:");
87
+ this.terminal.log("\n ", chalk.bold("kill -9 <PID>"), "\n");
88
+ this.terminal.log("or run Metro on different port.");
89
+ } else {
90
+ this.terminal.log(chalk.bgRed.bold(" ERROR "), chalk.red(error.message));
91
+ const errorAttributes = JSON.stringify(error);
92
+ if (errorAttributes !== "{}") {
93
+ this.terminal.log(chalk.red(errorAttributes));
94
+ }
95
+ this.terminal.log(chalk.red(error.stack));
96
+ }
97
+ }
98
+ /**
99
+ * This function is only concerned with logging and should not do state
100
+ * or terminal status updates.
101
+ */
102
+ _log(event) {
103
+ switch (event.type) {
104
+ case "initialize_started":
105
+ this._logInitializing(event.port, event.hasReducedPerformance);
106
+ break;
107
+ case "initialize_failed":
108
+ this._logInitializingFailed(event.port, event.error);
109
+ break;
110
+ case "bundle_build_done":
111
+ this._logBundleBuildDone(event.buildID);
112
+ break;
113
+ case "bundle_build_failed":
114
+ this._logBundleBuildFailed(event.buildID);
115
+ break;
116
+ case "bundling_error":
117
+ this._logBundlingError(event.error);
118
+ break;
119
+ case "global_cache_disabled":
120
+ this._logCacheDisabled(event.reason);
121
+ break;
122
+ case "transform_cache_reset":
123
+ debug("the transform cache was reset.");
124
+ break;
125
+ case "worker_stdout_chunk":
126
+ this._logWorkerChunk("stdout", event.chunk);
127
+ break;
128
+ case "worker_stderr_chunk":
129
+ this._logWorkerChunk("stderr", event.chunk);
130
+ break;
131
+ case "hmr_client_error":
132
+ this._logHmrClientError(event.error);
133
+ break;
134
+ case "client_log":
135
+ logToConsole(this.terminal, event.level, event.mode, ...event.data);
136
+ break;
137
+ case "dep_graph_loading":
138
+ if (event.hasReducedPerformance) {
139
+ this.terminal.log(
140
+ chalk.red(
141
+ "Metro is operating with reduced performance.\nPlease fix the problem above and restart Metro.\n\n"
142
+ )
143
+ );
144
+ }
145
+ break;
146
+ }
147
+ }
148
+ /**
149
+ * We do not want to log the whole stacktrace for bundling error, because
150
+ * these are operational errors, not programming errors, and the stacktrace
151
+ * is not actionable to end users.
152
+ */
153
+ _logBundlingError(error) {
154
+ if (error instanceof AmbiguousModuleResolutionError) {
155
+ const he = error.hasteError;
156
+ const message2 = `ambiguous resolution: module \`${error.fromModulePath}\` tries to require \`${he.hasteName}\`, but there are several files providing this module. You can delete or fix them:
157
+
158
+ ` + Object.keys(he.duplicatesSet).sort().map((dupFilePath) => ` * \`${dupFilePath}\`
159
+ `).join("");
160
+ reporting.logError(this.terminal, message2);
161
+ return;
162
+ }
163
+ let { message } = error;
164
+ if (!(error instanceof SyntaxError)) {
165
+ if (error.snippet == null && error.stack != null) {
166
+ message = error.stack;
167
+ }
168
+ }
169
+ if (error.filename && !message.includes(error.filename)) {
170
+ message += ` [${error.filename}]`;
171
+ }
172
+ if (error.snippet != null) {
173
+ message += "\n" + error.snippet;
174
+ }
175
+ reporting.logError(this.terminal, message);
176
+ }
177
+ _logWorkerChunk(origin, chunk) {
178
+ const lines = chunk.split("\n");
179
+ if (lines.length >= 1 && lines[lines.length - 1] === "") {
180
+ lines.splice(lines.length - 1, 1);
181
+ }
182
+ lines.forEach((line) => {
183
+ this.terminal.log(`transform[${origin}]: ${line}`);
184
+ });
185
+ }
186
+ /**
187
+ * We use Math.pow(ratio, 2) to as a conservative measure of progress because
188
+ * we know the `totalCount` is going to progressively increase as well. We
189
+ * also prevent the ratio from going backwards.
190
+ */
191
+ _updateBundleProgress({ buildID, transformedFileCount, totalFileCount }) {
192
+ const currentProgress = this._activeBundles.get(buildID);
193
+ if (currentProgress == null) {
194
+ return;
195
+ }
196
+ const rawRatio = transformedFileCount / totalFileCount;
197
+ const conservativeRatio = Math.pow(rawRatio, 2);
198
+ const ratio = Math.max(conservativeRatio, currentProgress.ratio);
199
+ Object.assign(currentProgress, {
200
+ ratio,
201
+ transformedFileCount,
202
+ totalFileCount
203
+ });
204
+ }
205
+ /**
206
+ * This function is exclusively concerned with updating the internal state.
207
+ * No logging or status updates should be done at this point.
208
+ */
209
+ _updateState(event) {
210
+ switch (event.type) {
211
+ case "bundle_build_done":
212
+ case "bundle_build_failed":
213
+ this._activeBundles.delete(event.buildID);
214
+ break;
215
+ case "bundle_build_started":
216
+ const bundleProgress = {
217
+ bundleDetails: event.bundleDetails,
218
+ transformedFileCount: 0,
219
+ totalFileCount: 1,
220
+ ratio: 0
221
+ };
222
+ this._activeBundles.set(event.buildID, bundleProgress);
223
+ break;
224
+ case "bundle_transform_progressed_throttled":
225
+ this._updateBundleProgress(event);
226
+ break;
227
+ }
228
+ }
229
+ /**
230
+ * Return a status message that is always consistent with the current state
231
+ * of the application. Having this single function ensures we don't have
232
+ * different callsites overriding each other status messages.
233
+ */
234
+ _getStatusMessage() {
235
+ return Array.from(this._activeBundles.entries()).map(([_, progress]) => this._getBundleStatusMessage(progress, "in_progress")).filter((str) => str != null).join("\n");
236
+ }
237
+ _logHmrClientError(e) {
238
+ reporting.logError(
239
+ this.terminal,
240
+ "A WebSocket client got a connection error. Please reload your device to get HMR working again: %s",
241
+ e
242
+ );
243
+ }
244
+ /**
245
+ * Single entry point for reporting events. That allows us to implement the
246
+ * corresponding JSON reporter easily and have a consistent repor∏ting.
247
+ */
248
+ update(event) {
249
+ if (event.type === "bundle_transform_progressed") {
250
+ this._scheduleUpdateBundleProgress(event);
251
+ return;
252
+ }
253
+ this._log(event);
254
+ this._updateState(event);
255
+ this.terminal.status(this._getStatusMessage());
256
+ }
257
+ }
258
+ module.exports = TerminalReporter;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ const MAGIC_NUMBER = 4293379011;
3
+ function getFileHeader(moduleCount) {
4
+ const buffer = Buffer.alloc(8);
5
+ buffer.writeUInt32LE(MAGIC_NUMBER, 0);
6
+ buffer.writeUInt32LE(moduleCount, 4);
7
+ return buffer;
8
+ }
9
+ function addModuleHeader(buffer) {
10
+ const { getFileLength } = require("metro-hermes-compiler");
11
+ const fileLength = getFileLength(buffer, 0);
12
+ const header = Buffer.alloc(4);
13
+ header.writeUInt32LE(fileLength, 0);
14
+ return [header, buffer];
15
+ }
16
+ function bundleToBytecode(bundle) {
17
+ const buffers = [];
18
+ if (bundle.pre.length) {
19
+ buffers.push(...bundle.pre);
20
+ }
21
+ const modules = [];
22
+ const sortedModules = bundle.modules.slice().sort((a, b) => a[0] - b[0]);
23
+ for (const [id, bytecodeBundle] of sortedModules) {
24
+ buffers.push(...bytecodeBundle);
25
+ modules.push([id, bytecodeBundle[bytecodeBundle.length - 1].length]);
26
+ }
27
+ if (bundle.post.length) {
28
+ buffers.push(...bundle.post);
29
+ }
30
+ return {
31
+ bytecode: Buffer.concat([getFileHeader(buffers.length), ...buffers.flatMap(addModuleHeader)]),
32
+ metadata: {
33
+ pre: bundle.pre ? bundle.pre.length : 0,
34
+ post: bundle.post.length,
35
+ modules
36
+ }
37
+ };
38
+ }
39
+ module.exports = bundleToBytecode;
40
+ module.exports.MAGIC_NUMBER = MAGIC_NUMBER;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ function bundleToString(bundle) {
3
+ let code = bundle.pre.length > 0 ? bundle.pre + "\n" : "";
4
+ const modules = [];
5
+ const sortedModules = bundle.modules.slice().sort((a, b) => a[0] - b[0]);
6
+ for (const [id, moduleCode] of sortedModules) {
7
+ if (moduleCode.length > 0) {
8
+ code += moduleCode + "\n";
9
+ }
10
+ modules.push([id, moduleCode.length]);
11
+ }
12
+ if (bundle.post.length > 0) {
13
+ code += bundle.post;
14
+ } else {
15
+ code = code.slice(0, -1);
16
+ }
17
+ return {
18
+ code,
19
+ metadata: { pre: bundle.pre.length, post: bundle.post.length, modules }
20
+ };
21
+ }
22
+ module.exports = bundleToString;
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var contextModule_exports = {};
30
+ __export(contextModule_exports, {
31
+ deriveAbsolutePathFromContext: () => deriveAbsolutePathFromContext,
32
+ fileMatchesContext: () => fileMatchesContext
33
+ });
34
+ module.exports = __toCommonJS(contextModule_exports);
35
+ var import_crypto = __toESM(require("crypto"));
36
+ var import_path = __toESM(require("path"));
37
+ var import_nullthrows = __toESM(require("nullthrows"));
38
+ function toHash(value) {
39
+ return import_crypto.default.createHash("sha1").update(value).digest("hex");
40
+ }
41
+ function deriveAbsolutePathFromContext(from, context) {
42
+ const filePath = from.endsWith(import_path.default.sep) ? from.slice(0, -1) : from;
43
+ return filePath + "?ctx=" + toHash(
44
+ [
45
+ context.mode,
46
+ context.recursive ? "recursive" : "",
47
+ new RegExp(context.filter.pattern, context.filter.flags).toString()
48
+ ].filter(Boolean).join(" ")
49
+ );
50
+ }
51
+ function fileMatchesContext(testPath, context) {
52
+ const filePath = import_path.default.relative((0, import_nullthrows.default)(context.from), testPath);
53
+ const filter = context.filter;
54
+ if (
55
+ // Ignore everything outside of the provided `root`.
56
+ !(filePath && !filePath.startsWith("..")) || // Prevent searching in child directories during a non-recursive search.
57
+ !context.recursive && filePath.includes(import_path.default.sep) || // Test against the filter.
58
+ !filter.test(
59
+ // NOTE(EvanBacon): Ensure files start with `./` for matching purposes
60
+ // this ensures packages work across Metro and Webpack (ex: Storybook for React DOM / React Native).
61
+ // `a/b.js` -> `./a/b.js`
62
+ "./" + filePath.replace(/\\/g, "/")
63
+ )
64
+ ) {
65
+ return false;
66
+ }
67
+ return true;
68
+ }
69
+ // Annotate the CommonJS export names for ESM import in node:
70
+ 0 && (module.exports = {
71
+ deriveAbsolutePathFromContext,
72
+ fileMatchesContext
73
+ });
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var contextModuleTemplates_exports = {};
30
+ __export(contextModuleTemplates_exports, {
31
+ getContextModuleTemplate: () => getContextModuleTemplate
32
+ });
33
+ module.exports = __toCommonJS(contextModuleTemplates_exports);
34
+ var path = __toESM(require("path"));
35
+ function createFileMap(modulePath, files, processModule) {
36
+ let mapString = "\n";
37
+ files.slice().sort().forEach((file) => {
38
+ let filePath = path.relative(modulePath, file);
39
+ if (!filePath.startsWith(".")) {
40
+ filePath = `.${path.sep}` + filePath;
41
+ }
42
+ const key = JSON.stringify(filePath);
43
+ mapString += ` ${key}: { enumerable: true, get() { return ${processModule(file)}; } },
44
+ `;
45
+ });
46
+ return `Object.defineProperties({}, {${mapString}})`;
47
+ }
48
+ function getEmptyContextModuleTemplate(modulePath) {
49
+ return `
50
+ function metroEmptyContext(request) {
51
+ let e = new Error('No modules in context');
52
+ e.code = 'MODULE_NOT_FOUND';
53
+ throw e;
54
+ }
55
+
56
+ // Return the keys that can be resolved.
57
+ metroEmptyContext.keys = () => ([]);
58
+
59
+ // Return the module identifier for a user request.
60
+ metroEmptyContext.resolve = function metroContextResolve(request) {
61
+ throw new Error('Unimplemented Metro module context functionality');
62
+ }
63
+
64
+ module.exports = metroEmptyContext;`;
65
+ }
66
+ function getLoadableContextModuleTemplate(modulePath, files, importSyntax, getContextTemplate) {
67
+ return `// All of the requested modules are loaded behind enumerable getters.
68
+ const map = ${createFileMap(modulePath, files, (moduleId) => `${importSyntax}(${JSON.stringify(moduleId)})`)};
69
+
70
+ function metroContext(request) {
71
+ ${getContextTemplate}
72
+ }
73
+
74
+ // Return the keys that can be resolved.
75
+ metroContext.keys = function metroContextKeys() {
76
+ return Object.keys(map);
77
+ };
78
+
79
+ // Return the module identifier for a user request.
80
+ metroContext.resolve = function metroContextResolve(request) {
81
+ throw new Error('Unimplemented Metro module context functionality');
82
+ }
83
+
84
+ module.exports = metroContext;`;
85
+ }
86
+ function getContextModuleTemplate(mode, modulePath, files) {
87
+ if (!files.length) {
88
+ return getEmptyContextModuleTemplate(modulePath);
89
+ }
90
+ switch (mode) {
91
+ case "eager":
92
+ return getLoadableContextModuleTemplate(
93
+ modulePath,
94
+ files,
95
+ // NOTE(EvanBacon): It's unclear if we should use `import` or `require` here so sticking
96
+ // with the more stable option (`require`) for now.
97
+ "require",
98
+ [
99
+ " // Here Promise.resolve().then() is used instead of new Promise() to prevent",
100
+ " // uncaught exception popping up in devtools",
101
+ " return Promise.resolve().then(() => map[request]);"
102
+ ].join("\n")
103
+ );
104
+ case "sync":
105
+ return getLoadableContextModuleTemplate(modulePath, files, "require", " return map[request];");
106
+ case "lazy":
107
+ case "lazy-once":
108
+ return getLoadableContextModuleTemplate(modulePath, files, "import", " return map[request];");
109
+ default:
110
+ throw new Error(`Metro context mode "${mode}" is unimplemented`);
111
+ }
112
+ }
113
+ // Annotate the CommonJS export names for ESM import in node:
114
+ 0 && (module.exports = {
115
+ getContextModuleTemplate
116
+ });
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ const newline = /\r\n?|\n|\u2028|\u2029/g;
3
+ const countLines = (string) => (string.match(newline) || []).length + 1;
4
+ module.exports = countLines;