@atlaspack/core 2.16.2-canary.37 → 2.16.2-canary.371

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 (367) hide show
  1. package/CHANGELOG.md +941 -0
  2. package/dist/AssetGraph.js +591 -0
  3. package/dist/Atlaspack.js +666 -0
  4. package/dist/AtlaspackConfig.js +324 -0
  5. package/dist/AtlaspackConfig.schema.js +117 -0
  6. package/dist/BundleGraph.js +1740 -0
  7. package/dist/CommittedAsset.js +142 -0
  8. package/dist/Dependency.js +125 -0
  9. package/dist/Environment.js +132 -0
  10. package/dist/EnvironmentManager.js +108 -0
  11. package/dist/IdentifierRegistry.js +38 -0
  12. package/dist/InternalConfig.js +37 -0
  13. package/dist/PackagerRunner.js +545 -0
  14. package/dist/ReporterRunner.js +151 -0
  15. package/dist/RequestTracker.js +1360 -0
  16. package/dist/SymbolPropagation.js +620 -0
  17. package/dist/TargetDescriptor.schema.js +143 -0
  18. package/dist/Transformation.js +514 -0
  19. package/dist/UncommittedAsset.js +315 -0
  20. package/dist/Validation.js +196 -0
  21. package/dist/applyRuntimes.js +383 -0
  22. package/dist/assetUtils.js +169 -0
  23. package/dist/atlaspack-v3/AtlaspackV3.js +74 -0
  24. package/dist/atlaspack-v3/NapiWorkerPool.js +81 -0
  25. package/dist/atlaspack-v3/fs.js +52 -0
  26. package/dist/atlaspack-v3/index.js +25 -0
  27. package/dist/atlaspack-v3/jsCallable.js +16 -0
  28. package/dist/atlaspack-v3/worker/compat/asset-symbols.js +190 -0
  29. package/dist/atlaspack-v3/worker/compat/bitflags.js +98 -0
  30. package/dist/atlaspack-v3/worker/compat/dependency.js +43 -0
  31. package/dist/atlaspack-v3/worker/compat/environment.js +57 -0
  32. package/dist/atlaspack-v3/worker/compat/index.js +25 -0
  33. package/dist/atlaspack-v3/worker/compat/mutable-asset.js +152 -0
  34. package/dist/atlaspack-v3/worker/compat/plugin-config.js +64 -0
  35. package/dist/atlaspack-v3/worker/compat/plugin-logger.js +26 -0
  36. package/dist/atlaspack-v3/worker/compat/plugin-options.js +137 -0
  37. package/dist/atlaspack-v3/worker/compat/plugin-tracer.js +10 -0
  38. package/dist/atlaspack-v3/worker/compat/target.js +14 -0
  39. package/dist/atlaspack-v3/worker/side-effect-detector.js +243 -0
  40. package/dist/atlaspack-v3/worker/worker.js +381 -0
  41. package/dist/constants.js +17 -0
  42. package/dist/dumpGraphToGraphViz.js +281 -0
  43. package/dist/index.js +62 -0
  44. package/dist/loadAtlaspackPlugin.js +128 -0
  45. package/dist/loadDotEnv.js +41 -0
  46. package/dist/projectPath.js +83 -0
  47. package/dist/public/Asset.js +279 -0
  48. package/dist/public/Bundle.js +224 -0
  49. package/dist/public/BundleGraph.js +371 -0
  50. package/dist/public/BundleGroup.js +53 -0
  51. package/dist/public/Config.js +286 -0
  52. package/dist/public/Dependency.js +138 -0
  53. package/dist/public/Environment.js +278 -0
  54. package/dist/public/MutableBundleGraph.js +277 -0
  55. package/dist/public/PluginOptions.js +80 -0
  56. package/dist/public/Symbols.js +248 -0
  57. package/dist/public/Target.js +69 -0
  58. package/dist/registerCoreWithSerializer.js +38 -0
  59. package/dist/requests/AssetGraphRequest.js +439 -0
  60. package/dist/requests/AssetGraphRequestRust.js +273 -0
  61. package/dist/requests/AssetRequest.js +130 -0
  62. package/dist/requests/AtlaspackBuildRequest.js +92 -0
  63. package/dist/requests/AtlaspackConfigRequest.js +493 -0
  64. package/dist/requests/BundleGraphRequest.js +447 -0
  65. package/dist/requests/ConfigRequest.js +246 -0
  66. package/dist/requests/DevDepRequest.js +204 -0
  67. package/dist/requests/EntryRequest.js +314 -0
  68. package/dist/requests/PackageRequest.js +72 -0
  69. package/dist/requests/PathRequest.js +349 -0
  70. package/dist/requests/TargetRequest.js +1311 -0
  71. package/dist/requests/ValidationRequest.js +49 -0
  72. package/dist/requests/WriteBundleRequest.js +254 -0
  73. package/dist/requests/WriteBundlesRequest.js +184 -0
  74. package/dist/requests/asset-graph-diff.js +128 -0
  75. package/dist/requests/asset-graph-dot.js +131 -0
  76. package/dist/resolveOptions.js +269 -0
  77. package/dist/rustWorkerThreadDylibHack.js +19 -0
  78. package/dist/serializerCore.browser.js +43 -0
  79. package/dist/summarizeRequest.js +39 -0
  80. package/dist/types.js +31 -0
  81. package/dist/utils.js +172 -0
  82. package/dist/worker.js +123 -0
  83. package/lib/AssetGraph.js +111 -14
  84. package/lib/Atlaspack.js +94 -41
  85. package/lib/AtlaspackConfig.js +15 -3
  86. package/lib/AtlaspackConfig.schema.js +16 -5
  87. package/lib/BundleGraph.js +197 -32
  88. package/lib/CommittedAsset.js +7 -1
  89. package/lib/Dependency.js +8 -2
  90. package/lib/Environment.js +15 -8
  91. package/lib/EnvironmentManager.js +143 -0
  92. package/lib/IdentifierRegistry.js +1 -3
  93. package/lib/InternalConfig.js +3 -2
  94. package/lib/PackagerRunner.js +90 -27
  95. package/lib/ReporterRunner.js +6 -9
  96. package/lib/RequestTracker.js +266 -156
  97. package/lib/SymbolPropagation.js +42 -18
  98. package/lib/TargetDescriptor.schema.js +7 -1
  99. package/lib/Transformation.js +66 -15
  100. package/lib/UncommittedAsset.js +33 -12
  101. package/lib/Validation.js +18 -2
  102. package/lib/applyRuntimes.js +96 -4
  103. package/lib/assetUtils.js +15 -5
  104. package/lib/atlaspack-v3/AtlaspackV3.js +52 -14
  105. package/lib/atlaspack-v3/NapiWorkerPool.js +28 -1
  106. package/lib/atlaspack-v3/fs.js +3 -1
  107. package/lib/atlaspack-v3/index.js +28 -1
  108. package/lib/atlaspack-v3/jsCallable.js +0 -2
  109. package/lib/atlaspack-v3/worker/compat/asset-symbols.js +7 -4
  110. package/lib/atlaspack-v3/worker/compat/bitflags.js +31 -25
  111. package/lib/atlaspack-v3/worker/compat/dependency.js +4 -1
  112. package/lib/atlaspack-v3/worker/compat/environment.js +10 -7
  113. package/lib/atlaspack-v3/worker/compat/mutable-asset.js +15 -10
  114. package/lib/atlaspack-v3/worker/compat/plugin-config.js +13 -34
  115. package/lib/atlaspack-v3/worker/compat/plugin-options.js +16 -0
  116. package/lib/atlaspack-v3/worker/compat/plugin-tracer.js +3 -0
  117. package/lib/atlaspack-v3/worker/compat/target.js +2 -0
  118. package/lib/atlaspack-v3/worker/index.js +3 -0
  119. package/lib/atlaspack-v3/worker/side-effect-detector.js +215 -0
  120. package/lib/atlaspack-v3/worker/worker.js +199 -71
  121. package/lib/constants.js +0 -1
  122. package/lib/dumpGraphToGraphViz.js +71 -16
  123. package/lib/index.js +45 -1
  124. package/lib/loadDotEnv.js +4 -1
  125. package/lib/projectPath.js +5 -0
  126. package/lib/public/Asset.js +21 -11
  127. package/lib/public/Bundle.js +15 -16
  128. package/lib/public/BundleGraph.js +25 -22
  129. package/lib/public/BundleGroup.js +4 -5
  130. package/lib/public/Config.js +118 -17
  131. package/lib/public/Dependency.js +8 -6
  132. package/lib/public/Environment.js +12 -7
  133. package/lib/public/MutableBundleGraph.js +54 -12
  134. package/lib/public/PluginOptions.js +2 -2
  135. package/lib/public/Symbols.js +11 -11
  136. package/lib/public/Target.js +7 -6
  137. package/lib/registerCoreWithSerializer.js +5 -3
  138. package/lib/requests/AssetGraphRequest.js +74 -27
  139. package/lib/requests/AssetGraphRequestRust.js +140 -64
  140. package/lib/requests/AssetRequest.js +23 -6
  141. package/lib/requests/AtlaspackBuildRequest.js +43 -4
  142. package/lib/requests/AtlaspackConfigRequest.js +27 -16
  143. package/lib/requests/BundleGraphRequest.js +41 -24
  144. package/lib/requests/ConfigRequest.js +53 -4
  145. package/lib/requests/DevDepRequest.js +31 -5
  146. package/lib/requests/EntryRequest.js +2 -0
  147. package/lib/requests/PackageRequest.js +16 -2
  148. package/lib/requests/PathRequest.js +24 -3
  149. package/lib/requests/TargetRequest.js +122 -57
  150. package/lib/requests/ValidationRequest.js +5 -1
  151. package/lib/requests/WriteBundleRequest.js +39 -11
  152. package/lib/requests/WriteBundlesRequest.js +51 -4
  153. package/lib/requests/asset-graph-diff.js +12 -7
  154. package/lib/requests/asset-graph-dot.js +1 -7
  155. package/lib/resolveOptions.js +38 -11
  156. package/lib/rustWorkerThreadDylibHack.js +0 -1
  157. package/lib/types/AssetGraph.d.ts +80 -0
  158. package/lib/types/Atlaspack.d.ts +52 -0
  159. package/lib/types/AtlaspackConfig.d.ts +65 -0
  160. package/lib/types/AtlaspackConfig.schema.d.ts +53 -0
  161. package/lib/types/BundleGraph.d.ts +184 -0
  162. package/lib/types/CommittedAsset.d.ts +23 -0
  163. package/lib/types/Dependency.d.ts +44 -0
  164. package/lib/types/Environment.d.ts +11 -0
  165. package/lib/types/EnvironmentManager.d.ts +37 -0
  166. package/lib/types/IdentifierRegistry.d.ts +6 -0
  167. package/lib/types/InternalConfig.d.ts +23 -0
  168. package/lib/types/PackagerRunner.d.ts +85 -0
  169. package/lib/types/ReporterRunner.d.ts +25 -0
  170. package/lib/types/RequestTracker.d.ts +385 -0
  171. package/lib/types/SymbolPropagation.d.ts +11 -0
  172. package/lib/types/TargetDescriptor.schema.d.ts +5 -0
  173. package/lib/types/Transformation.d.ts +72 -0
  174. package/lib/types/UncommittedAsset.d.ts +61 -0
  175. package/lib/types/Validation.d.ts +37 -0
  176. package/lib/types/applyRuntimes.d.ts +25 -0
  177. package/lib/types/assetUtils.d.ts +42 -0
  178. package/lib/types/atlaspack-v3/AtlaspackV3.d.ts +34 -0
  179. package/lib/types/atlaspack-v3/NapiWorkerPool.d.ts +13 -0
  180. package/lib/types/atlaspack-v3/fs.d.ts +12 -0
  181. package/lib/types/atlaspack-v3/index.d.ts +6 -0
  182. package/lib/types/atlaspack-v3/jsCallable.d.ts +1 -0
  183. package/lib/types/atlaspack-v3/worker/compat/asset-symbols.d.ts +51 -0
  184. package/lib/types/atlaspack-v3/worker/compat/bitflags.d.ts +14 -0
  185. package/lib/types/atlaspack-v3/worker/compat/dependency.d.ts +25 -0
  186. package/lib/types/atlaspack-v3/worker/compat/environment.d.ts +27 -0
  187. package/{src/atlaspack-v3/worker/compat/index.js → lib/types/atlaspack-v3/worker/compat/index.d.ts} +0 -1
  188. package/lib/types/atlaspack-v3/worker/compat/mutable-asset.d.ts +49 -0
  189. package/lib/types/atlaspack-v3/worker/compat/plugin-config.d.ts +29 -0
  190. package/lib/types/atlaspack-v3/worker/compat/plugin-logger.d.ts +9 -0
  191. package/lib/types/atlaspack-v3/worker/compat/plugin-options.d.ts +23 -0
  192. package/lib/types/atlaspack-v3/worker/compat/plugin-tracer.d.ts +5 -0
  193. package/lib/types/atlaspack-v3/worker/compat/target.d.ts +11 -0
  194. package/lib/types/atlaspack-v3/worker/side-effect-detector.d.ts +76 -0
  195. package/lib/types/atlaspack-v3/worker/worker.d.ts +80 -0
  196. package/lib/types/constants.d.ts +13 -0
  197. package/lib/types/dumpGraphToGraphViz.d.ts +10 -0
  198. package/lib/types/index.d.ts +8 -0
  199. package/lib/types/loadAtlaspackPlugin.d.ts +8 -0
  200. package/lib/types/loadDotEnv.d.ts +3 -0
  201. package/lib/types/projectPath.d.ts +19 -0
  202. package/lib/types/public/Asset.d.ts +74 -0
  203. package/lib/types/public/Bundle.d.ts +45 -0
  204. package/lib/types/public/BundleGraph.d.ts +72 -0
  205. package/lib/types/public/BundleGroup.d.ts +12 -0
  206. package/lib/types/public/Config.d.ts +75 -0
  207. package/lib/types/public/Dependency.d.ts +32 -0
  208. package/lib/types/public/Environment.d.ts +34 -0
  209. package/lib/types/public/MutableBundleGraph.d.ts +26 -0
  210. package/lib/types/public/PluginOptions.d.ts +25 -0
  211. package/lib/types/public/Symbols.d.ts +81 -0
  212. package/lib/types/public/Target.d.ts +16 -0
  213. package/lib/types/registerCoreWithSerializer.d.ts +2 -0
  214. package/lib/types/requests/AssetGraphRequest.d.ts +76 -0
  215. package/lib/types/requests/AssetGraphRequestRust.d.ts +21 -0
  216. package/lib/types/requests/AssetRequest.d.ts +16 -0
  217. package/lib/types/requests/AtlaspackBuildRequest.d.ts +33 -0
  218. package/lib/types/requests/AtlaspackConfigRequest.d.ts +45 -0
  219. package/lib/types/requests/BundleGraphRequest.d.ts +28 -0
  220. package/lib/types/requests/ConfigRequest.d.ts +67 -0
  221. package/lib/types/requests/DevDepRequest.d.ts +30 -0
  222. package/lib/types/requests/EntryRequest.d.ts +36 -0
  223. package/lib/types/requests/PackageRequest.d.ts +27 -0
  224. package/lib/types/requests/PathRequest.d.ts +48 -0
  225. package/lib/types/requests/TargetRequest.d.ts +48 -0
  226. package/lib/types/requests/ValidationRequest.d.ts +20 -0
  227. package/lib/types/requests/WriteBundleRequest.d.ts +28 -0
  228. package/lib/types/requests/WriteBundlesRequest.d.ts +32 -0
  229. package/lib/types/requests/asset-graph-diff.d.ts +1 -0
  230. package/lib/types/requests/asset-graph-dot.d.ts +9 -0
  231. package/lib/types/resolveOptions.d.ts +3 -0
  232. package/lib/types/rustWorkerThreadDylibHack.d.ts +9 -0
  233. package/lib/types/serializerCore.browser.d.ts +3 -0
  234. package/lib/types/summarizeRequest.d.ts +10 -0
  235. package/lib/types/types.d.ts +495 -0
  236. package/lib/types/utils.d.ts +23 -0
  237. package/lib/types/worker.d.ts +44 -0
  238. package/lib/types.js +8 -1
  239. package/lib/utils.js +17 -2
  240. package/lib/worker.js +30 -14
  241. package/package.json +25 -35
  242. package/src/{AssetGraph.js → AssetGraph.ts} +156 -52
  243. package/src/{Atlaspack.js → Atlaspack.ts} +134 -67
  244. package/src/{AtlaspackConfig.schema.js → AtlaspackConfig.schema.ts} +25 -19
  245. package/src/{AtlaspackConfig.js → AtlaspackConfig.ts} +78 -54
  246. package/src/{BundleGraph.js → BundleGraph.ts} +383 -140
  247. package/src/{CommittedAsset.js → CommittedAsset.ts} +15 -13
  248. package/src/{Dependency.js → Dependency.ts} +59 -42
  249. package/src/{Environment.js → Environment.ts} +24 -15
  250. package/src/EnvironmentManager.ts +154 -0
  251. package/src/{IdentifierRegistry.js → IdentifierRegistry.ts} +1 -4
  252. package/src/{InternalConfig.js → InternalConfig.ts} +22 -23
  253. package/src/{PackagerRunner.js → PackagerRunner.ts} +179 -87
  254. package/src/{ReporterRunner.js → ReporterRunner.ts} +13 -18
  255. package/src/{RequestTracker.js → RequestTracker.ts} +572 -357
  256. package/src/{SymbolPropagation.js → SymbolPropagation.ts} +165 -57
  257. package/src/{TargetDescriptor.schema.js → TargetDescriptor.schema.ts} +7 -1
  258. package/src/{Transformation.js → Transformation.ts} +110 -65
  259. package/src/{UncommittedAsset.js → UncommittedAsset.ts} +60 -39
  260. package/src/{Validation.js → Validation.ts} +32 -17
  261. package/src/{applyRuntimes.js → applyRuntimes.ts} +133 -26
  262. package/src/{assetUtils.js → assetUtils.ts} +49 -36
  263. package/src/atlaspack-v3/AtlaspackV3.ts +143 -0
  264. package/src/atlaspack-v3/NapiWorkerPool.ts +91 -0
  265. package/src/atlaspack-v3/{fs.js → fs.ts} +3 -4
  266. package/src/atlaspack-v3/{index.js → index.ts} +3 -4
  267. package/src/atlaspack-v3/jsCallable.ts +14 -0
  268. package/src/atlaspack-v3/worker/compat/{asset-symbols.js → asset-symbols.ts} +40 -30
  269. package/src/atlaspack-v3/worker/compat/bitflags.ts +102 -0
  270. package/src/atlaspack-v3/worker/compat/{dependency.js → dependency.ts} +13 -13
  271. package/src/atlaspack-v3/worker/compat/{environment.js → environment.ts} +13 -9
  272. package/src/atlaspack-v3/worker/compat/index.ts +9 -0
  273. package/src/atlaspack-v3/worker/compat/{mutable-asset.js → mutable-asset.ts} +21 -20
  274. package/src/atlaspack-v3/worker/compat/{plugin-config.js → plugin-config.ts} +25 -56
  275. package/src/atlaspack-v3/worker/compat/{plugin-logger.js → plugin-logger.ts} +0 -2
  276. package/src/atlaspack-v3/worker/compat/{plugin-options.js → plugin-options.ts} +19 -5
  277. package/src/atlaspack-v3/worker/compat/{plugin-tracer.js → plugin-tracer.ts} +2 -2
  278. package/src/atlaspack-v3/worker/compat/{target.js → target.ts} +3 -4
  279. package/src/atlaspack-v3/worker/index.js +2 -1
  280. package/src/atlaspack-v3/worker/side-effect-detector.ts +298 -0
  281. package/src/atlaspack-v3/worker/worker.ts +531 -0
  282. package/src/{constants.js → constants.ts} +0 -3
  283. package/src/{dumpGraphToGraphViz.js → dumpGraphToGraphViz.ts} +73 -28
  284. package/src/index.ts +18 -0
  285. package/src/{loadAtlaspackPlugin.js → loadAtlaspackPlugin.ts} +8 -9
  286. package/src/{loadDotEnv.js → loadDotEnv.ts} +2 -2
  287. package/src/{projectPath.js → projectPath.ts} +20 -9
  288. package/src/public/{Asset.js → Asset.ts} +41 -28
  289. package/src/public/{Bundle.js → Bundle.ts} +28 -29
  290. package/src/public/{BundleGraph.js → BundleGraph.ts} +103 -68
  291. package/src/public/{BundleGroup.js → BundleGroup.ts} +7 -10
  292. package/src/public/{Config.js → Config.ts} +171 -33
  293. package/src/public/{Dependency.js → Dependency.ts} +20 -17
  294. package/src/public/{Environment.js → Environment.ts} +28 -17
  295. package/src/public/{MutableBundleGraph.js → MutableBundleGraph.ts} +55 -24
  296. package/src/public/{PluginOptions.js → PluginOptions.ts} +6 -6
  297. package/src/public/{Symbols.js → Symbols.ts} +75 -36
  298. package/src/public/{Target.js → Target.ts} +10 -8
  299. package/src/{registerCoreWithSerializer.js → registerCoreWithSerializer.ts} +9 -7
  300. package/src/requests/{AssetGraphRequest.js → AssetGraphRequest.ts} +129 -80
  301. package/src/requests/AssetGraphRequestRust.ts +364 -0
  302. package/src/requests/{AssetRequest.js → AssetRequest.ts} +24 -18
  303. package/src/requests/AtlaspackBuildRequest.ts +163 -0
  304. package/src/requests/{AtlaspackConfigRequest.js → AtlaspackConfigRequest.ts} +72 -58
  305. package/src/requests/{BundleGraphRequest.js → BundleGraphRequest.ts} +97 -79
  306. package/src/requests/{ConfigRequest.js → ConfigRequest.ts} +110 -50
  307. package/src/requests/{DevDepRequest.js → DevDepRequest.ts} +60 -35
  308. package/src/requests/{EntryRequest.js → EntryRequest.ts} +36 -31
  309. package/src/requests/{PackageRequest.js → PackageRequest.ts} +34 -22
  310. package/src/requests/{PathRequest.js → PathRequest.ts} +47 -37
  311. package/src/requests/{TargetRequest.js → TargetRequest.ts} +260 -179
  312. package/src/requests/{ValidationRequest.js → ValidationRequest.ts} +18 -17
  313. package/src/requests/{WriteBundleRequest.js → WriteBundleRequest.ts} +77 -49
  314. package/src/requests/{WriteBundlesRequest.js → WriteBundlesRequest.ts} +109 -37
  315. package/src/requests/{asset-graph-diff.js → asset-graph-diff.ts} +25 -21
  316. package/src/requests/{asset-graph-dot.js → asset-graph-dot.ts} +8 -12
  317. package/src/{resolveOptions.js → resolveOptions.ts} +59 -25
  318. package/src/{rustWorkerThreadDylibHack.js → rustWorkerThreadDylibHack.ts} +1 -4
  319. package/src/{serializerCore.browser.js → serializerCore.browser.ts} +2 -3
  320. package/src/{summarizeRequest.js → summarizeRequest.ts} +17 -5
  321. package/src/types.ts +650 -0
  322. package/src/{utils.js → utils.ts} +52 -21
  323. package/src/{worker.js → worker.ts} +50 -42
  324. package/test/{AssetGraph.test.js → AssetGraph.test.ts} +37 -8
  325. package/test/{Atlaspack.test.js → Atlaspack.test.ts} +5 -10
  326. package/test/{AtlaspackConfig.test.js → AtlaspackConfig.test.ts} +0 -5
  327. package/test/{AtlaspackConfigRequest.test.js → AtlaspackConfigRequest.test.ts} +76 -16
  328. package/test/{BundleGraph.test.js → BundleGraph.test.ts} +8 -13
  329. package/test/{Dependency.test.js → Dependency.test.ts} +2 -3
  330. package/test/{EntryRequest.test.js → EntryRequest.test.ts} +1 -6
  331. package/test/Environment.test.ts +153 -0
  332. package/test/EnvironmentManager.test.ts +188 -0
  333. package/test/{IdentifierRegistry.test.js → IdentifierRegistry.test.ts} +2 -4
  334. package/test/{InternalAsset.test.js → InternalAsset.test.ts} +2 -7
  335. package/test/PackagerRunner.test.ts +0 -0
  336. package/test/{PublicAsset.test.js → PublicAsset.test.ts} +2 -7
  337. package/test/{PublicBundle.test.js → PublicBundle.test.ts} +1 -2
  338. package/test/{PublicDependency.test.js → PublicDependency.test.ts} +0 -2
  339. package/test/PublicEnvironment.test.ts +49 -0
  340. package/test/{PublicMutableBundleGraph.test.js → PublicMutableBundleGraph.test.ts} +6 -11
  341. package/test/{RequestTracker.test.js → RequestTracker.test.ts} +314 -59
  342. package/test/{SymbolPropagation.test.js → SymbolPropagation.test.ts} +124 -74
  343. package/test/{TargetRequest.test.js → TargetRequest.test.ts} +66 -92
  344. package/test/fixtures/config-with-reporters/.parcelrc +7 -0
  345. package/test/fixtures/custom-targets/package.json +6 -0
  346. package/test/public/Config.test.ts +104 -0
  347. package/test/requests/AssetGraphRequestRust.test.ts +443 -0
  348. package/test/requests/{ConfigRequest.test.js → ConfigRequest.test.ts} +202 -13
  349. package/test/requests/{DevDepRequest.test.js → DevDepRequest.test.ts} +0 -2
  350. package/test/{test-utils.js → test-utils.ts} +4 -11
  351. package/test/{utils.test.js → utils.test.ts} +1 -3
  352. package/tsconfig.json +60 -0
  353. package/tsconfig.tsbuildinfo +1 -0
  354. package/index.d.ts +0 -30
  355. package/src/atlaspack-v3/AtlaspackV3.js +0 -87
  356. package/src/atlaspack-v3/NapiWorkerPool.js +0 -53
  357. package/src/atlaspack-v3/jsCallable.js +0 -18
  358. package/src/atlaspack-v3/worker/compat/bitflags.js +0 -100
  359. package/src/atlaspack-v3/worker/worker.js +0 -362
  360. package/src/index.js +0 -13
  361. package/src/requests/AssetGraphRequestRust.js +0 -263
  362. package/src/requests/AtlaspackBuildRequest.js +0 -111
  363. package/src/types.js +0 -600
  364. package/test/Environment.test.js +0 -119
  365. package/test/PackagerRunner.test.js +0 -27
  366. package/test/PublicEnvironment.test.js +0 -27
  367. package/test/requests/AssetGraphRequestRust.test.js +0 -411
@@ -0,0 +1,666 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
36
+ if (kind === "m") throw new TypeError("Private method is not writable");
37
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
38
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
39
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
40
+ };
41
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
42
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
43
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
44
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
45
+ };
46
+ var __importDefault = (this && this.__importDefault) || function (mod) {
47
+ return (mod && mod.__esModule) ? mod : { "default": mod };
48
+ };
49
+ var _Atlaspack_requestTracker, _Atlaspack_config, _Atlaspack_farm, _Atlaspack_initialized, _Atlaspack_disposable, _Atlaspack_initialOptions, _Atlaspack_reporterRunner, _Atlaspack_resolvedOptions, _Atlaspack_optionsRef, _Atlaspack_watchAbortController, _Atlaspack_watchQueue, _Atlaspack_watchEvents, _Atlaspack_watcherSubscription, _Atlaspack_watcherCount, _Atlaspack_requestedAssetIds;
50
+ Object.defineProperty(exports, "__esModule", { value: true });
51
+ exports.BuildError = exports.WORKER_PATH = exports.INTERNAL_RESOLVE = exports.INTERNAL_TRANSFORM = void 0;
52
+ exports.createWorkerFarm = createWorkerFarm;
53
+ const path_1 = __importDefault(require("path"));
54
+ const assert_1 = __importDefault(require("assert"));
55
+ const diagnostic_1 = __importStar(require("@atlaspack/diagnostic"));
56
+ const Asset_1 = require("./public/Asset");
57
+ const Bundle_1 = require("./public/Bundle");
58
+ const BundleGraph_1 = __importDefault(require("./public/BundleGraph"));
59
+ const workers_1 = __importDefault(require("@atlaspack/workers"));
60
+ const nullthrows_1 = __importDefault(require("nullthrows"));
61
+ const utils_1 = require("./utils");
62
+ const AtlaspackConfigRequest_1 = require("./requests/AtlaspackConfigRequest");
63
+ const ReporterRunner_1 = __importDefault(require("./ReporterRunner"));
64
+ const dumpGraphToGraphViz_1 = __importDefault(require("./dumpGraphToGraphViz"));
65
+ const resolveOptions_1 = __importDefault(require("./resolveOptions"));
66
+ const events_1 = require("@atlaspack/events");
67
+ const registerCoreWithSerializer_1 = require("./registerCoreWithSerializer");
68
+ const utils_2 = require("@atlaspack/utils");
69
+ const AtlaspackConfig_1 = require("./AtlaspackConfig");
70
+ const logger_1 = __importDefault(require("@atlaspack/logger"));
71
+ const RequestTracker_1 = __importStar(require("./RequestTracker"));
72
+ const ValidationRequest_1 = __importDefault(require("./requests/ValidationRequest"));
73
+ const AtlaspackBuildRequest_1 = __importDefault(require("./requests/AtlaspackBuildRequest"));
74
+ const AssetRequest_1 = __importDefault(require("./requests/AssetRequest"));
75
+ const PathRequest_1 = __importDefault(require("./requests/PathRequest"));
76
+ const Environment_1 = require("./Environment");
77
+ const Dependency_1 = require("./Dependency");
78
+ const events_2 = require("@atlaspack/events");
79
+ const source_map_1 = require("@atlaspack/source-map");
80
+ const cache_1 = require("@atlaspack/cache");
81
+ const rust_1 = require("@atlaspack/rust");
82
+ const projectPath_1 = require("./projectPath");
83
+ const profiler_1 = require("@atlaspack/profiler");
84
+ const feature_flags_1 = require("@atlaspack/feature-flags");
85
+ const atlaspack_v3_1 = require("./atlaspack-v3");
86
+ const AssetGraphRequest_1 = __importDefault(require("./requests/AssetGraphRequest"));
87
+ const AssetGraphRequestRust_1 = require("./requests/AssetGraphRequestRust");
88
+ const rustWorkerThreadDylibHack_1 = require("./rustWorkerThreadDylibHack");
89
+ (0, registerCoreWithSerializer_1.registerCoreWithSerializer)();
90
+ exports.INTERNAL_TRANSFORM = Symbol('internal_transform');
91
+ exports.INTERNAL_RESOLVE = Symbol('internal_resolve');
92
+ exports.WORKER_PATH = path_1.default.join(__dirname, 'worker.js');
93
+ if (__filename.endsWith('.ts')) {
94
+ exports.WORKER_PATH = path_1.default.join(__dirname, 'worker.ts');
95
+ }
96
+ class Atlaspack {
97
+ constructor(options) {
98
+ // @ts-expect-error TS2564
99
+ _Atlaspack_requestTracker.set(this, void 0);
100
+ // @ts-expect-error TS2564
101
+ _Atlaspack_config.set(this, void 0);
102
+ // @ts-expect-error TS2564
103
+ _Atlaspack_farm.set(this, void 0);
104
+ _Atlaspack_initialized.set(this, false);
105
+ // @ts-expect-error TS2564
106
+ _Atlaspack_disposable.set(this, void 0);
107
+ _Atlaspack_initialOptions.set(this, void 0);
108
+ // @ts-expect-error TS2564
109
+ _Atlaspack_reporterRunner.set(this, void 0);
110
+ _Atlaspack_resolvedOptions.set(this, null);
111
+ // @ts-expect-error TS2564
112
+ _Atlaspack_optionsRef.set(this, void 0);
113
+ // @ts-expect-error TS2564
114
+ _Atlaspack_watchAbortController.set(this, void 0);
115
+ _Atlaspack_watchQueue.set(this, new utils_2.PromiseQueue({
116
+ maxConcurrent: 1,
117
+ }));
118
+ // @ts-expect-error TS2564
119
+ _Atlaspack_watchEvents.set(this, void 0);
120
+ _Atlaspack_watcherSubscription.set(this, void 0);
121
+ _Atlaspack_watcherCount.set(this, 0);
122
+ _Atlaspack_requestedAssetIds.set(this, new Set());
123
+ __classPrivateFieldSet(this, _Atlaspack_initialOptions, options, "f");
124
+ }
125
+ async _init() {
126
+ if (__classPrivateFieldGet(this, _Atlaspack_initialized, "f")) {
127
+ return;
128
+ }
129
+ const featureFlags = {
130
+ ...feature_flags_1.DEFAULT_FEATURE_FLAGS,
131
+ ...__classPrivateFieldGet(this, _Atlaspack_initialOptions, "f").featureFlags,
132
+ };
133
+ (0, feature_flags_1.setFeatureFlags)(featureFlags);
134
+ (0, rustWorkerThreadDylibHack_1.loadRustWorkerThreadDylibHack)();
135
+ await source_map_1.init;
136
+ await (0, rust_1.init)?.();
137
+ __classPrivateFieldSet(this, _Atlaspack_disposable, new events_2.Disposable(), "f");
138
+ try {
139
+ (0, rust_1.initializeMonitoring)?.();
140
+ const onExit = () => {
141
+ (0, rust_1.closeMonitoring)?.();
142
+ };
143
+ process.on('exit', onExit);
144
+ __classPrivateFieldGet(this, _Atlaspack_disposable, "f").add(() => {
145
+ process.off('exit', onExit);
146
+ onExit();
147
+ });
148
+ }
149
+ catch (e) {
150
+ // Fallthrough
151
+ // eslint-disable-next-line no-console
152
+ console.warn(e);
153
+ }
154
+ let resolvedOptions = await (0, resolveOptions_1.default)({
155
+ ...__classPrivateFieldGet(this, _Atlaspack_initialOptions, "f"),
156
+ featureFlags,
157
+ });
158
+ __classPrivateFieldSet(this, _Atlaspack_resolvedOptions, resolvedOptions, "f");
159
+ let rustAtlaspack;
160
+ if (resolvedOptions.featureFlags.atlaspackV3 ||
161
+ resolvedOptions.featureFlags.nativePackager) {
162
+ // eslint-disable-next-line no-unused-vars
163
+ let { entries, inputFS, outputFS, ...options } = __classPrivateFieldGet(this, _Atlaspack_initialOptions, "f");
164
+ if (!(resolvedOptions.cache instanceof cache_1.LMDBLiteCache)) {
165
+ throw new Error('Atlaspack v3 must be run with lmdb lite cache');
166
+ }
167
+ const lmdb = resolvedOptions.cache.getNativeRef();
168
+ const version = require('../package.json').version;
169
+ await lmdb.put('current_session_version', Buffer.from(version));
170
+ let threads = undefined;
171
+ if (process.env.ATLASPACK_NATIVE_THREADS !== undefined) {
172
+ threads = parseInt(process.env.ATLASPACK_NATIVE_THREADS, 10);
173
+ }
174
+ else if (process.env.NODE_ENV === 'test') {
175
+ threads = 2;
176
+ }
177
+ rustAtlaspack = await atlaspack_v3_1.AtlaspackV3.create({
178
+ ...options,
179
+ // @ts-expect-error TS2353
180
+ corePath: path_1.default.join(__dirname, '..'),
181
+ threads,
182
+ entries: Array.isArray(entries)
183
+ ? entries
184
+ : entries == null
185
+ ? undefined
186
+ : [entries],
187
+ env: resolvedOptions.env,
188
+ fs: inputFS && new atlaspack_v3_1.FileSystemV3(inputFS),
189
+ defaultTargetOptions: resolvedOptions.defaultTargetOptions,
190
+ serveOptions: resolvedOptions.serveOptions,
191
+ lmdb,
192
+ featureFlags: resolvedOptions.featureFlags,
193
+ });
194
+ __classPrivateFieldGet(this, _Atlaspack_disposable, "f").add(() => {
195
+ rustAtlaspack.end();
196
+ });
197
+ }
198
+ // @ts-expect-error TS2454
199
+ this.rustAtlaspack = rustAtlaspack;
200
+ let { config } = await (0, AtlaspackConfigRequest_1.loadAtlaspackConfig)(resolvedOptions);
201
+ __classPrivateFieldSet(this, _Atlaspack_config, new AtlaspackConfig_1.AtlaspackConfig(config, resolvedOptions), "f");
202
+ if (__classPrivateFieldGet(this, _Atlaspack_initialOptions, "f").workerFarm) {
203
+ if (__classPrivateFieldGet(this, _Atlaspack_initialOptions, "f").workerFarm.ending) {
204
+ throw new Error('Supplied WorkerFarm is ending');
205
+ }
206
+ __classPrivateFieldSet(this, _Atlaspack_farm, __classPrivateFieldGet(this, _Atlaspack_initialOptions, "f").workerFarm, "f");
207
+ }
208
+ else {
209
+ __classPrivateFieldSet(this, _Atlaspack_farm, createWorkerFarm({
210
+ shouldPatchConsole: resolvedOptions.shouldPatchConsole,
211
+ shouldTrace: resolvedOptions.shouldTrace,
212
+ }), "f");
213
+ }
214
+ await resolvedOptions.cache.ensure();
215
+ let { dispose: disposeOptions, ref: optionsRef } = await __classPrivateFieldGet(this, _Atlaspack_farm, "f").createSharedReference(resolvedOptions, false);
216
+ __classPrivateFieldSet(this, _Atlaspack_optionsRef, optionsRef, "f");
217
+ if (__classPrivateFieldGet(this, _Atlaspack_initialOptions, "f").workerFarm) {
218
+ // If we don't own the farm, dispose of only these references when
219
+ // Atlaspack ends.
220
+ __classPrivateFieldGet(this, _Atlaspack_disposable, "f").add(disposeOptions);
221
+ }
222
+ else {
223
+ // Otherwise, when shutting down, end the entire farm we created.
224
+ __classPrivateFieldGet(this, _Atlaspack_disposable, "f").add(() => __classPrivateFieldGet(this, _Atlaspack_farm, "f").end());
225
+ }
226
+ __classPrivateFieldSet(this, _Atlaspack_watchEvents, new events_1.ValueEmitter(), "f");
227
+ __classPrivateFieldGet(this, _Atlaspack_disposable, "f").add(() => __classPrivateFieldGet(this, _Atlaspack_watchEvents, "f").dispose());
228
+ __classPrivateFieldSet(this, _Atlaspack_reporterRunner, new ReporterRunner_1.default({
229
+ options: resolvedOptions,
230
+ reporters: await __classPrivateFieldGet(this, _Atlaspack_config, "f").getReporters(),
231
+ workerFarm: __classPrivateFieldGet(this, _Atlaspack_farm, "f"),
232
+ }), "f");
233
+ __classPrivateFieldGet(this, _Atlaspack_disposable, "f").add(__classPrivateFieldGet(this, _Atlaspack_reporterRunner, "f"));
234
+ logger_1.default.verbose({
235
+ origin: '@atlaspack/core',
236
+ message: 'Intializing request tracker...',
237
+ });
238
+ __classPrivateFieldSet(this, _Atlaspack_requestTracker, await RequestTracker_1.default.init({
239
+ farm: __classPrivateFieldGet(this, _Atlaspack_farm, "f"),
240
+ options: resolvedOptions,
241
+ // @ts-expect-error TS2454
242
+ rustAtlaspack,
243
+ }), "f");
244
+ __classPrivateFieldSet(this, _Atlaspack_initialized, true, "f");
245
+ }
246
+ async run() {
247
+ let startTime = Date.now();
248
+ if (!__classPrivateFieldGet(this, _Atlaspack_initialized, "f")) {
249
+ await this._init();
250
+ }
251
+ let result = await this._build({ startTime });
252
+ await __classPrivateFieldGet(this, _Atlaspack_requestTracker, "f").writeToCache();
253
+ await this._end();
254
+ if (result.type === 'buildFailure') {
255
+ throw new BuildError(result.diagnostics);
256
+ }
257
+ return result;
258
+ }
259
+ async _end() {
260
+ __classPrivateFieldSet(this, _Atlaspack_initialized, false, "f");
261
+ await __classPrivateFieldGet(this, _Atlaspack_disposable, "f").dispose();
262
+ }
263
+ async writeRequestTrackerToCache() {
264
+ if (__classPrivateFieldGet(this, _Atlaspack_watchQueue, "f").getNumWaiting() === 0) {
265
+ // If there's no queued events, we are safe to write the request graph to disk
266
+ const abortController = new AbortController();
267
+ const unsubscribe = __classPrivateFieldGet(this, _Atlaspack_watchQueue, "f").subscribeToAdd(() => {
268
+ abortController.abort();
269
+ });
270
+ try {
271
+ await __classPrivateFieldGet(this, _Atlaspack_requestTracker, "f").writeToCache(abortController.signal);
272
+ }
273
+ catch (err) {
274
+ if (!abortController.signal.aborted) {
275
+ // We expect abort errors if we interrupt the cache write
276
+ throw err;
277
+ }
278
+ }
279
+ unsubscribe();
280
+ }
281
+ }
282
+ async _startNextBuild() {
283
+ __classPrivateFieldSet(this, _Atlaspack_watchAbortController, new AbortController(), "f");
284
+ await this.clearBuildCaches();
285
+ try {
286
+ let buildEvent = await this._build({
287
+ signal: __classPrivateFieldGet(this, _Atlaspack_watchAbortController, "f").signal,
288
+ });
289
+ __classPrivateFieldGet(this, _Atlaspack_watchEvents, "f").emit({
290
+ buildEvent,
291
+ });
292
+ return buildEvent;
293
+ }
294
+ catch (err) {
295
+ // Ignore BuildAbortErrors and only emit critical errors.
296
+ if (!(err instanceof utils_1.BuildAbortError)) {
297
+ throw err;
298
+ }
299
+ }
300
+ finally {
301
+ // If the build passes or fails, we want to cache the request graph
302
+ await this.writeRequestTrackerToCache();
303
+ }
304
+ }
305
+ async watch(cb) {
306
+ var _a;
307
+ if (!__classPrivateFieldGet(this, _Atlaspack_initialized, "f")) {
308
+ await this._init();
309
+ }
310
+ // @ts-expect-error TS7034
311
+ let watchEventsDisposable;
312
+ if (cb) {
313
+ watchEventsDisposable = __classPrivateFieldGet(this, _Atlaspack_watchEvents, "f").addListener(({ error, buildEvent }) => cb(error, buildEvent));
314
+ }
315
+ if (__classPrivateFieldGet(this, _Atlaspack_watcherCount, "f") === 0) {
316
+ __classPrivateFieldSet(this, _Atlaspack_watcherSubscription, await this._getWatcherSubscription(), "f");
317
+ await __classPrivateFieldGet(this, _Atlaspack_reporterRunner, "f").report({ type: 'watchStart' });
318
+ // Kick off a first build, but don't await its results. Its results will
319
+ // be provided to the callback.
320
+ __classPrivateFieldGet(this, _Atlaspack_watchQueue, "f").add(() => this._startNextBuild());
321
+ __classPrivateFieldGet(this, _Atlaspack_watchQueue, "f").run();
322
+ }
323
+ __classPrivateFieldSet(this, _Atlaspack_watcherCount, (_a = __classPrivateFieldGet(this, _Atlaspack_watcherCount, "f"), _a++, _a), "f");
324
+ // @ts-expect-error TS7034
325
+ let unsubscribePromise;
326
+ const unsubscribe = async () => {
327
+ var _a;
328
+ // @ts-expect-error TS7005
329
+ if (watchEventsDisposable) {
330
+ watchEventsDisposable.dispose();
331
+ }
332
+ __classPrivateFieldSet(this, _Atlaspack_watcherCount, (_a = __classPrivateFieldGet(this, _Atlaspack_watcherCount, "f"), _a--, _a), "f");
333
+ if (__classPrivateFieldGet(this, _Atlaspack_watcherCount, "f") === 0) {
334
+ await (0, nullthrows_1.default)(__classPrivateFieldGet(this, _Atlaspack_watcherSubscription, "f")).unsubscribe();
335
+ __classPrivateFieldSet(this, _Atlaspack_watcherSubscription, null, "f");
336
+ await __classPrivateFieldGet(this, _Atlaspack_reporterRunner, "f").report({ type: 'watchEnd' });
337
+ __classPrivateFieldGet(this, _Atlaspack_watchAbortController, "f").abort();
338
+ await __classPrivateFieldGet(this, _Atlaspack_watchQueue, "f").run();
339
+ await this._end();
340
+ }
341
+ };
342
+ return {
343
+ unsubscribe() {
344
+ // @ts-expect-error TS7005
345
+ if (unsubscribePromise == null) {
346
+ unsubscribePromise = unsubscribe();
347
+ }
348
+ // @ts-expect-error TS7005
349
+ return unsubscribePromise;
350
+ },
351
+ };
352
+ }
353
+ async _build({ signal, startTime = Date.now(), } = {
354
+ /*::...null*/
355
+ }) {
356
+ let options = (0, nullthrows_1.default)(__classPrivateFieldGet(this, _Atlaspack_resolvedOptions, "f"));
357
+ try {
358
+ if (options.shouldProfile) {
359
+ await this.startProfiling();
360
+ }
361
+ if (options.nativeProfiler) {
362
+ const nativeProfiler = new profiler_1.NativeProfiler();
363
+ await nativeProfiler.startProfiling(options.nativeProfiler);
364
+ }
365
+ if (options.shouldTrace) {
366
+ profiler_1.tracer.enable();
367
+ // We need to ensure the tracer is disabled when Atlaspack is disposed as it is a module level object.
368
+ // While rare (except for tests), if another instance is created later it should not have tracing enabled.
369
+ __classPrivateFieldGet(this, _Atlaspack_disposable, "f").add(() => {
370
+ profiler_1.tracer.disable();
371
+ });
372
+ }
373
+ await __classPrivateFieldGet(this, _Atlaspack_reporterRunner, "f").report({
374
+ type: 'buildStart',
375
+ });
376
+ __classPrivateFieldGet(this, _Atlaspack_requestTracker, "f").graph.invalidateOnBuildNodes();
377
+ let request = (0, AtlaspackBuildRequest_1.default)({
378
+ optionsRef: __classPrivateFieldGet(this, _Atlaspack_optionsRef, "f"),
379
+ requestedAssetIds: __classPrivateFieldGet(this, _Atlaspack_requestedAssetIds, "f"),
380
+ signal,
381
+ });
382
+ let { bundleGraph, bundleInfo, changedAssets, assetRequests, scopeHoistingStats, } = await __classPrivateFieldGet(this, _Atlaspack_requestTracker, "f").runRequest(request, { force: true });
383
+ __classPrivateFieldGet(this, _Atlaspack_requestedAssetIds, "f").clear();
384
+ await (0, dumpGraphToGraphViz_1.default)(
385
+ // @ts-expect-error TS2345
386
+ __classPrivateFieldGet(this, _Atlaspack_requestTracker, "f").graph, 'RequestGraph', RequestTracker_1.requestGraphEdgeTypes);
387
+ let event = {
388
+ type: 'buildSuccess',
389
+ changedAssets: new Map(Array.from(changedAssets).map(([id, asset]) => [
390
+ id,
391
+ (0, Asset_1.assetFromValue)(asset, options),
392
+ ])),
393
+ bundleGraph: new BundleGraph_1.default(bundleGraph, (
394
+ // @ts-expect-error TS2304
395
+ bundle,
396
+ // @ts-expect-error TS2314
397
+ bundleGraph, options) => Bundle_1.PackagedBundle.getWithInfo(bundle, bundleGraph, options, bundleInfo.get(bundle.id)), options),
398
+ buildTime: Date.now() - startTime,
399
+ // @ts-expect-error TS7006
400
+ requestBundle: async (bundle) => {
401
+ let bundleNode = bundleGraph._graph.getNodeByContentKey(bundle.id);
402
+ (0, assert_1.default)(bundleNode?.type === 'bundle', 'Bundle does not exist');
403
+ if (!bundleNode.value.isPlaceholder) {
404
+ // Nothing to do.
405
+ return {
406
+ type: 'buildSuccess',
407
+ changedAssets: new Map(),
408
+ bundleGraph: event.bundleGraph,
409
+ buildTime: 0,
410
+ requestBundle: event.requestBundle,
411
+ unstable_requestStats: {},
412
+ scopeHoistingStats: event.scopeHoistingStats,
413
+ };
414
+ }
415
+ for (let assetId of bundleNode.value.entryAssetIds) {
416
+ __classPrivateFieldGet(this, _Atlaspack_requestedAssetIds, "f").add(assetId);
417
+ }
418
+ if (__classPrivateFieldGet(this, _Atlaspack_watchQueue, "f").getNumWaiting() === 0) {
419
+ if (__classPrivateFieldGet(this, _Atlaspack_watchAbortController, "f")) {
420
+ __classPrivateFieldGet(this, _Atlaspack_watchAbortController, "f").abort();
421
+ }
422
+ __classPrivateFieldGet(this, _Atlaspack_watchQueue, "f").add(() => this._startNextBuild());
423
+ }
424
+ let results = await __classPrivateFieldGet(this, _Atlaspack_watchQueue, "f").run();
425
+ let result = results.filter(Boolean).pop();
426
+ // @ts-expect-error TS18049
427
+ if (result.type === 'buildFailure') {
428
+ // @ts-expect-error TS18049
429
+ throw new BuildError(result.diagnostics);
430
+ }
431
+ return result;
432
+ },
433
+ unstable_requestStats: __classPrivateFieldGet(this, _Atlaspack_requestTracker, "f").flushStats(),
434
+ nativeCacheStats: await this.rustAtlaspack?.completeCacheSession(),
435
+ scopeHoistingStats,
436
+ };
437
+ // @ts-expect-error TS2345
438
+ await __classPrivateFieldGet(this, _Atlaspack_reporterRunner, "f").report(event);
439
+ await __classPrivateFieldGet(this, _Atlaspack_requestTracker, "f").runRequest(
440
+ // @ts-expect-error TS2345
441
+ (0, ValidationRequest_1.default)({ optionsRef: __classPrivateFieldGet(this, _Atlaspack_optionsRef, "f"), assetRequests }), { force: assetRequests.length > 0 });
442
+ if (__classPrivateFieldGet(this, _Atlaspack_reporterRunner, "f").errors.length) {
443
+ throw __classPrivateFieldGet(this, _Atlaspack_reporterRunner, "f").errors;
444
+ }
445
+ // @ts-expect-error TS2322
446
+ return event;
447
+ }
448
+ catch (e) {
449
+ if (e instanceof utils_1.BuildAbortError) {
450
+ throw e;
451
+ }
452
+ let diagnostic = (0, diagnostic_1.anyToDiagnostic)(e);
453
+ let event = {
454
+ type: 'buildFailure',
455
+ diagnostics: Array.isArray(diagnostic) ? diagnostic : [diagnostic],
456
+ unstable_requestStats: __classPrivateFieldGet(this, _Atlaspack_requestTracker, "f").flushStats(),
457
+ nativeCacheStats: await this.rustAtlaspack?.completeCacheSession(),
458
+ };
459
+ // @ts-expect-error TS2345
460
+ await __classPrivateFieldGet(this, _Atlaspack_reporterRunner, "f").report(event);
461
+ // @ts-expect-error TS2322
462
+ return event;
463
+ }
464
+ finally {
465
+ if (this.isProfiling) {
466
+ await this.stopProfiling();
467
+ }
468
+ await this.clearBuildCaches();
469
+ }
470
+ }
471
+ async _getWatcherSubscription() {
472
+ (0, assert_1.default)(__classPrivateFieldGet(this, _Atlaspack_watcherSubscription, "f") == null);
473
+ let resolvedOptions = (0, nullthrows_1.default)(__classPrivateFieldGet(this, _Atlaspack_resolvedOptions, "f"));
474
+ let opts = (0, RequestTracker_1.getWatcherOptions)(resolvedOptions);
475
+ let sub = await resolvedOptions.inputFS.watch(resolvedOptions.watchDir, async (err, events) => {
476
+ if (err) {
477
+ logger_1.default.warn({
478
+ message: `File watch event error occured`,
479
+ meta: {
480
+ err,
481
+ trackableEvent: 'watcher_error',
482
+ },
483
+ });
484
+ __classPrivateFieldGet(this, _Atlaspack_watchEvents, "f").emit({ error: err });
485
+ return;
486
+ }
487
+ logger_1.default.verbose({
488
+ message: `File watch event emitted with ${events.length} events. Sample event: [${events[0]?.type}] ${events[0]?.path}`,
489
+ });
490
+ let nativeInvalid = false;
491
+ if ((0, feature_flags_1.getFeatureFlag)('atlaspackV3') && this.rustAtlaspack) {
492
+ nativeInvalid = await this.rustAtlaspack.respondToFsEvents(events);
493
+ }
494
+ let { didInvalidate: isInvalid } = await __classPrivateFieldGet(this, _Atlaspack_requestTracker, "f").respondToFSEvents(events, Number.POSITIVE_INFINITY);
495
+ if ((nativeInvalid || isInvalid) &&
496
+ __classPrivateFieldGet(this, _Atlaspack_watchQueue, "f").getNumWaiting() === 0) {
497
+ if (__classPrivateFieldGet(this, _Atlaspack_watchAbortController, "f")) {
498
+ __classPrivateFieldGet(this, _Atlaspack_watchAbortController, "f").abort();
499
+ }
500
+ __classPrivateFieldGet(this, _Atlaspack_watchQueue, "f").add(() => this._startNextBuild());
501
+ __classPrivateFieldGet(this, _Atlaspack_watchQueue, "f").run();
502
+ }
503
+ }, opts);
504
+ return { unsubscribe: () => sub.unsubscribe() };
505
+ }
506
+ // This is mainly for integration tests and it not public api!
507
+ _getResolvedAtlaspackOptions() {
508
+ return (0, nullthrows_1.default)(__classPrivateFieldGet(this, _Atlaspack_resolvedOptions, "f"), 'Resolved options is null, please let atlaspack initialize before accessing this.');
509
+ }
510
+ async startProfiling() {
511
+ if (this.isProfiling) {
512
+ throw new Error('Atlaspack is already profiling');
513
+ }
514
+ logger_1.default.info({ origin: '@atlaspack/core', message: 'Starting profiling...' });
515
+ this.isProfiling = true;
516
+ await __classPrivateFieldGet(this, _Atlaspack_farm, "f").startProfile();
517
+ }
518
+ stopProfiling() {
519
+ if (!this.isProfiling) {
520
+ throw new Error('Atlaspack is not profiling');
521
+ }
522
+ logger_1.default.info({ origin: '@atlaspack/core', message: 'Stopping profiling...' });
523
+ this.isProfiling = false;
524
+ return __classPrivateFieldGet(this, _Atlaspack_farm, "f").endProfile();
525
+ }
526
+ takeHeapSnapshot() {
527
+ logger_1.default.info({
528
+ origin: '@atlaspack/core',
529
+ message: 'Taking heap snapshot...',
530
+ });
531
+ return __classPrivateFieldGet(this, _Atlaspack_farm, "f").takeHeapSnapshot();
532
+ }
533
+ /**
534
+ * Must be called between builds otherwise there is global state that will
535
+ * break things unexpectedly.
536
+ */
537
+ async clearBuildCaches() {
538
+ await __classPrivateFieldGet(this, _Atlaspack_farm, "f")?.callAllWorkers('clearWorkerBuildCaches', []);
539
+ }
540
+ async unstable_invalidate() {
541
+ await this._init();
542
+ }
543
+ /**
544
+ * Build the asset graph
545
+ */
546
+ async unstable_buildAssetGraph(writeToCache = true) {
547
+ await this._init();
548
+ const origin = '@atlaspack/core';
549
+ const input = {
550
+ optionsRef: __classPrivateFieldGet(this, _Atlaspack_optionsRef, "f"),
551
+ name: 'Main',
552
+ entries: __classPrivateFieldGet(this, _Atlaspack_config, "f").options.entries,
553
+ shouldBuildLazily: false,
554
+ lazyIncludes: [],
555
+ lazyExcludes: [],
556
+ requestedAssetIds: __classPrivateFieldGet(this, _Atlaspack_requestedAssetIds, "f"),
557
+ };
558
+ const start = Date.now();
559
+ const result = await __classPrivateFieldGet(this, _Atlaspack_requestTracker, "f").runRequest((0, feature_flags_1.getFeatureFlag)('atlaspackV3') && this.rustAtlaspack != null
560
+ ? // @ts-expect-error TS2345
561
+ (0, AssetGraphRequestRust_1.createAssetGraphRequestRust)(this.rustAtlaspack)(input)
562
+ : // @ts-expect-error TS2345
563
+ (0, AssetGraphRequest_1.default)(input), { force: true });
564
+ const duration = Date.now() - start;
565
+ logger_1.default.info({
566
+ message: `Done building asset graph in ${duration / 1000}s!`,
567
+ origin,
568
+ });
569
+ if (writeToCache) {
570
+ logger_1.default.info({ message: 'Write request tracker to cache', origin });
571
+ await this.writeRequestTrackerToCache();
572
+ logger_1.default.info({ message: 'Done writing request tracker to cache', origin });
573
+ }
574
+ return result;
575
+ }
576
+ /**
577
+ * Copy the cache to a new directory and compact it.
578
+ */
579
+ async unstable_compactCache() {
580
+ await this._init();
581
+ const cache = (0, nullthrows_1.default)(__classPrivateFieldGet(this, _Atlaspack_resolvedOptions, "f")).cache;
582
+ if (cache instanceof cache_1.LMDBLiteCache) {
583
+ await cache.compact('parcel-cache-compacted');
584
+ }
585
+ else {
586
+ throw new Error('Cache is not an LMDBLiteCache');
587
+ }
588
+ }
589
+ async unstable_transform(options) {
590
+ if (!__classPrivateFieldGet(this, _Atlaspack_initialized, "f")) {
591
+ await this._init();
592
+ }
593
+ let projectRoot = (0, nullthrows_1.default)(__classPrivateFieldGet(this, _Atlaspack_resolvedOptions, "f")).projectRoot;
594
+ let request = (0, AssetRequest_1.default)({
595
+ ...options,
596
+ filePath: (0, projectPath_1.toProjectPath)(projectRoot, options.filePath),
597
+ optionsRef: __classPrivateFieldGet(this, _Atlaspack_optionsRef, "f"),
598
+ env: (0, Environment_1.createEnvironment)({
599
+ ...options.env,
600
+ loc: options.env?.loc != null
601
+ ? {
602
+ ...options.env.loc,
603
+ filePath: (0, projectPath_1.toProjectPath)(projectRoot, options.env.loc.filePath),
604
+ }
605
+ : undefined,
606
+ }),
607
+ });
608
+ let res = await __classPrivateFieldGet(this, _Atlaspack_requestTracker, "f").runRequest(request, {
609
+ force: true,
610
+ });
611
+ return res.map((asset) => (0, Asset_1.assetFromValue)(asset, (0, nullthrows_1.default)(__classPrivateFieldGet(this, _Atlaspack_resolvedOptions, "f"))));
612
+ }
613
+ async unstable_resolve(request) {
614
+ if (!__classPrivateFieldGet(this, _Atlaspack_initialized, "f")) {
615
+ await this._init();
616
+ }
617
+ let projectRoot = (0, nullthrows_1.default)(__classPrivateFieldGet(this, _Atlaspack_resolvedOptions, "f")).projectRoot;
618
+ if (request.resolveFrom == null && path_1.default.isAbsolute(request.specifier)) {
619
+ request.specifier = (0, projectPath_1.fromProjectPathRelative)((0, projectPath_1.toProjectPath)(projectRoot, request.specifier));
620
+ }
621
+ let dependency = (0, Dependency_1.createDependency)(projectRoot, {
622
+ ...request,
623
+ env: (0, Environment_1.createEnvironment)({
624
+ ...request.env,
625
+ loc: request.env?.loc != null
626
+ ? {
627
+ ...request.env.loc,
628
+ filePath: (0, projectPath_1.toProjectPath)(projectRoot, request.env.loc.filePath),
629
+ }
630
+ : undefined,
631
+ }),
632
+ });
633
+ let req = (0, PathRequest_1.default)({
634
+ dependency,
635
+ name: request.specifier,
636
+ });
637
+ let res = await __classPrivateFieldGet(this, _Atlaspack_requestTracker, "f").runRequest(req, {
638
+ force: true,
639
+ });
640
+ if (!res) {
641
+ return null;
642
+ }
643
+ return {
644
+ // @ts-expect-error TS2322
645
+ filePath: (0, projectPath_1.fromProjectPath)(projectRoot, res.filePath),
646
+ code: res.code,
647
+ query: res.query,
648
+ sideEffects: res.sideEffects,
649
+ };
650
+ }
651
+ }
652
+ _Atlaspack_requestTracker = new WeakMap(), _Atlaspack_config = new WeakMap(), _Atlaspack_farm = new WeakMap(), _Atlaspack_initialized = new WeakMap(), _Atlaspack_disposable = new WeakMap(), _Atlaspack_initialOptions = new WeakMap(), _Atlaspack_reporterRunner = new WeakMap(), _Atlaspack_resolvedOptions = new WeakMap(), _Atlaspack_optionsRef = new WeakMap(), _Atlaspack_watchAbortController = new WeakMap(), _Atlaspack_watchQueue = new WeakMap(), _Atlaspack_watchEvents = new WeakMap(), _Atlaspack_watcherSubscription = new WeakMap(), _Atlaspack_watcherCount = new WeakMap(), _Atlaspack_requestedAssetIds = new WeakMap();
653
+ exports.default = Atlaspack;
654
+ class BuildError extends diagnostic_1.default {
655
+ constructor(diagnostic) {
656
+ super({ diagnostic });
657
+ this.name = 'BuildError';
658
+ }
659
+ }
660
+ exports.BuildError = BuildError;
661
+ function createWorkerFarm(options = {}) {
662
+ return new workers_1.default({
663
+ ...options,
664
+ workerPath: exports.WORKER_PATH,
665
+ });
666
+ }