@atlaspack/core 2.16.2-canary.48 → 2.16.2-canary.481

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 (380) hide show
  1. package/CHANGELOG.md +1324 -0
  2. package/dist/AssetGraph.js +523 -0
  3. package/dist/Atlaspack.js +701 -0
  4. package/dist/AtlaspackConfig.js +324 -0
  5. package/dist/AtlaspackConfig.schema.js +117 -0
  6. package/dist/BundleGraph.js +1906 -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 +470 -0
  14. package/dist/ReporterRunner.js +151 -0
  15. package/dist/RequestTracker.js +1297 -0
  16. package/dist/SymbolPropagation.js +624 -0
  17. package/dist/TargetDescriptor.schema.js +146 -0
  18. package/dist/Transformation.js +514 -0
  19. package/dist/UncommittedAsset.js +310 -0
  20. package/dist/Validation.js +196 -0
  21. package/dist/applyRuntimes.js +384 -0
  22. package/dist/assetUtils.js +169 -0
  23. package/dist/atlaspack-v3/AtlaspackV3.js +83 -0
  24. package/dist/atlaspack-v3/NapiWorkerPool.js +114 -0
  25. package/dist/atlaspack-v3/fs.js +53 -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 +24 -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-options.js +137 -0
  36. package/dist/atlaspack-v3/worker/compat/plugin-tracer.js +10 -0
  37. package/dist/atlaspack-v3/worker/compat/target.js +14 -0
  38. package/dist/atlaspack-v3/worker/side-effect-detector.js +243 -0
  39. package/dist/atlaspack-v3/worker/worker.js +398 -0
  40. package/dist/constants.js +17 -0
  41. package/dist/dumpGraphToGraphViz.js +281 -0
  42. package/dist/index.js +62 -0
  43. package/dist/loadAtlaspackPlugin.js +128 -0
  44. package/dist/loadDotEnv.js +41 -0
  45. package/dist/projectPath.js +83 -0
  46. package/dist/public/Asset.js +279 -0
  47. package/dist/public/Bundle.js +224 -0
  48. package/dist/public/BundleGraph.js +371 -0
  49. package/dist/public/BundleGroup.js +53 -0
  50. package/dist/public/Config.js +286 -0
  51. package/dist/public/Dependency.js +138 -0
  52. package/dist/public/Environment.js +278 -0
  53. package/dist/public/MutableBundleGraph.js +277 -0
  54. package/dist/public/PluginOptions.js +80 -0
  55. package/dist/public/Symbols.js +248 -0
  56. package/dist/public/Target.js +69 -0
  57. package/dist/registerCoreWithSerializer.js +38 -0
  58. package/dist/requests/AssetGraphRequest.js +430 -0
  59. package/dist/requests/AssetGraphRequestRust.js +471 -0
  60. package/dist/requests/AssetRequest.js +130 -0
  61. package/dist/requests/AtlaspackBuildRequest.js +98 -0
  62. package/dist/requests/AtlaspackConfigRequest.js +493 -0
  63. package/dist/requests/BundleGraphRequest.js +381 -0
  64. package/dist/requests/BundleGraphRequestRust.js +324 -0
  65. package/dist/requests/BundleGraphRequestUtils.js +262 -0
  66. package/dist/requests/ConfigRequest.js +246 -0
  67. package/dist/requests/DevDepRequest.js +204 -0
  68. package/dist/requests/EntryRequest.js +314 -0
  69. package/dist/requests/PackageRequest.js +89 -0
  70. package/dist/requests/PathRequest.js +349 -0
  71. package/dist/requests/TargetRequest.js +1316 -0
  72. package/dist/requests/ValidationRequest.js +49 -0
  73. package/dist/requests/WriteBundleRequest.js +522 -0
  74. package/dist/requests/WriteBundlesRequest.js +190 -0
  75. package/dist/requests/asset-graph-diff.js +128 -0
  76. package/dist/requests/asset-graph-dot.js +131 -0
  77. package/dist/resolveOptions.js +267 -0
  78. package/dist/rustWorkerThreadDylibHack.js +19 -0
  79. package/dist/serializerCore.browser.js +43 -0
  80. package/dist/summarizeRequest.js +39 -0
  81. package/dist/types.js +31 -0
  82. package/dist/utils.js +172 -0
  83. package/dist/worker.js +123 -0
  84. package/lib/AssetGraph.js +53 -15
  85. package/lib/Atlaspack.js +140 -56
  86. package/lib/AtlaspackConfig.js +17 -6
  87. package/lib/AtlaspackConfig.schema.js +16 -5
  88. package/lib/BundleGraph.js +390 -43
  89. package/lib/CommittedAsset.js +8 -2
  90. package/lib/Dependency.js +9 -3
  91. package/lib/Environment.js +16 -10
  92. package/lib/EnvironmentManager.js +143 -0
  93. package/lib/IdentifierRegistry.js +2 -4
  94. package/lib/InternalConfig.js +3 -2
  95. package/lib/PackagerRunner.js +46 -82
  96. package/lib/ReporterRunner.js +8 -12
  97. package/lib/RequestTracker.js +191 -152
  98. package/lib/SymbolPropagation.js +52 -29
  99. package/lib/TargetDescriptor.schema.js +10 -1
  100. package/lib/Transformation.js +68 -19
  101. package/lib/UncommittedAsset.js +17 -24
  102. package/lib/Validation.js +20 -5
  103. package/lib/applyRuntimes.js +98 -7
  104. package/lib/assetUtils.js +16 -6
  105. package/lib/atlaspack-v3/AtlaspackV3.js +58 -15
  106. package/lib/atlaspack-v3/NapiWorkerPool.js +63 -2
  107. package/lib/atlaspack-v3/fs.js +4 -1
  108. package/lib/atlaspack-v3/index.js +28 -1
  109. package/lib/atlaspack-v3/jsCallable.js +0 -2
  110. package/lib/atlaspack-v3/worker/compat/asset-symbols.js +7 -4
  111. package/lib/atlaspack-v3/worker/compat/bitflags.js +31 -25
  112. package/lib/atlaspack-v3/worker/compat/dependency.js +4 -1
  113. package/lib/atlaspack-v3/worker/compat/environment.js +10 -7
  114. package/lib/atlaspack-v3/worker/compat/index.js +0 -11
  115. package/lib/atlaspack-v3/worker/compat/mutable-asset.js +16 -11
  116. package/lib/atlaspack-v3/worker/compat/plugin-config.js +14 -35
  117. package/lib/atlaspack-v3/worker/compat/plugin-options.js +16 -2
  118. package/lib/atlaspack-v3/worker/compat/plugin-tracer.js +3 -0
  119. package/lib/atlaspack-v3/worker/compat/target.js +2 -0
  120. package/lib/atlaspack-v3/worker/index.js +3 -0
  121. package/lib/atlaspack-v3/worker/side-effect-detector.js +214 -0
  122. package/lib/atlaspack-v3/worker/worker.js +231 -79
  123. package/lib/constants.js +0 -1
  124. package/lib/dumpGraphToGraphViz.js +72 -17
  125. package/lib/index.js +46 -3
  126. package/lib/loadAtlaspackPlugin.js +2 -3
  127. package/lib/loadDotEnv.js +5 -2
  128. package/lib/projectPath.js +6 -1
  129. package/lib/public/Asset.js +22 -12
  130. package/lib/public/Bundle.js +16 -18
  131. package/lib/public/BundleGraph.js +27 -25
  132. package/lib/public/BundleGroup.js +5 -6
  133. package/lib/public/Config.js +118 -18
  134. package/lib/public/Dependency.js +9 -7
  135. package/lib/public/Environment.js +13 -8
  136. package/lib/public/MutableBundleGraph.js +56 -15
  137. package/lib/public/PluginOptions.js +2 -2
  138. package/lib/public/Symbols.js +12 -12
  139. package/lib/public/Target.js +8 -7
  140. package/lib/registerCoreWithSerializer.js +7 -4
  141. package/lib/requests/AssetGraphRequest.js +61 -40
  142. package/lib/requests/AssetGraphRequestRust.js +314 -82
  143. package/lib/requests/AssetRequest.js +24 -7
  144. package/lib/requests/AtlaspackBuildRequest.js +53 -7
  145. package/lib/requests/AtlaspackConfigRequest.js +29 -19
  146. package/lib/requests/BundleGraphRequest.js +61 -130
  147. package/lib/requests/BundleGraphRequestRust.js +381 -0
  148. package/lib/requests/BundleGraphRequestUtils.js +280 -0
  149. package/lib/requests/ConfigRequest.js +55 -7
  150. package/lib/requests/DevDepRequest.js +32 -6
  151. package/lib/requests/EntryRequest.js +4 -3
  152. package/lib/requests/PackageRequest.js +56 -12
  153. package/lib/requests/PathRequest.js +26 -6
  154. package/lib/requests/TargetRequest.js +129 -60
  155. package/lib/requests/ValidationRequest.js +6 -2
  156. package/lib/requests/WriteBundleRequest.js +329 -20
  157. package/lib/requests/WriteBundlesRequest.js +64 -10
  158. package/lib/requests/asset-graph-diff.js +13 -8
  159. package/lib/requests/asset-graph-dot.js +2 -8
  160. package/lib/resolveOptions.js +37 -14
  161. package/lib/rustWorkerThreadDylibHack.js +0 -1
  162. package/lib/serializerCore.browser.js +1 -2
  163. package/lib/summarizeRequest.js +1 -1
  164. package/lib/types/AssetGraph.d.ts +55 -0
  165. package/lib/types/Atlaspack.d.ts +52 -0
  166. package/lib/types/AtlaspackConfig.d.ts +65 -0
  167. package/lib/types/AtlaspackConfig.schema.d.ts +53 -0
  168. package/lib/types/BundleGraph.d.ts +232 -0
  169. package/lib/types/CommittedAsset.d.ts +23 -0
  170. package/lib/types/Dependency.d.ts +44 -0
  171. package/lib/types/Environment.d.ts +11 -0
  172. package/lib/types/EnvironmentManager.d.ts +37 -0
  173. package/lib/types/IdentifierRegistry.d.ts +6 -0
  174. package/lib/types/InternalConfig.d.ts +23 -0
  175. package/lib/types/PackagerRunner.d.ts +85 -0
  176. package/lib/types/ReporterRunner.d.ts +25 -0
  177. package/lib/types/RequestTracker.d.ts +385 -0
  178. package/lib/types/SymbolPropagation.d.ts +11 -0
  179. package/lib/types/TargetDescriptor.schema.d.ts +5 -0
  180. package/lib/types/Transformation.d.ts +72 -0
  181. package/lib/types/UncommittedAsset.d.ts +61 -0
  182. package/lib/types/Validation.d.ts +37 -0
  183. package/lib/types/applyRuntimes.d.ts +25 -0
  184. package/lib/types/assetUtils.d.ts +42 -0
  185. package/lib/types/atlaspack-v3/AtlaspackV3.d.ts +35 -0
  186. package/lib/types/atlaspack-v3/NapiWorkerPool.d.ts +13 -0
  187. package/lib/types/atlaspack-v3/fs.d.ts +13 -0
  188. package/lib/types/atlaspack-v3/index.d.ts +6 -0
  189. package/lib/types/atlaspack-v3/jsCallable.d.ts +1 -0
  190. package/lib/types/atlaspack-v3/worker/compat/asset-symbols.d.ts +51 -0
  191. package/lib/types/atlaspack-v3/worker/compat/bitflags.d.ts +14 -0
  192. package/lib/types/atlaspack-v3/worker/compat/dependency.d.ts +25 -0
  193. package/lib/types/atlaspack-v3/worker/compat/environment.d.ts +27 -0
  194. package/{src/atlaspack-v3/worker/compat/index.js → lib/types/atlaspack-v3/worker/compat/index.d.ts} +0 -2
  195. package/lib/types/atlaspack-v3/worker/compat/mutable-asset.d.ts +49 -0
  196. package/lib/types/atlaspack-v3/worker/compat/plugin-config.d.ts +29 -0
  197. package/lib/types/atlaspack-v3/worker/compat/plugin-options.d.ts +23 -0
  198. package/lib/types/atlaspack-v3/worker/compat/plugin-tracer.d.ts +5 -0
  199. package/lib/types/atlaspack-v3/worker/compat/target.d.ts +11 -0
  200. package/lib/types/atlaspack-v3/worker/side-effect-detector.d.ts +76 -0
  201. package/lib/types/atlaspack-v3/worker/worker.d.ts +81 -0
  202. package/lib/types/constants.d.ts +13 -0
  203. package/lib/types/dumpGraphToGraphViz.d.ts +10 -0
  204. package/lib/types/index.d.ts +8 -0
  205. package/lib/types/loadAtlaspackPlugin.d.ts +8 -0
  206. package/lib/types/loadDotEnv.d.ts +3 -0
  207. package/lib/types/projectPath.d.ts +19 -0
  208. package/lib/types/public/Asset.d.ts +74 -0
  209. package/lib/types/public/Bundle.d.ts +45 -0
  210. package/lib/types/public/BundleGraph.d.ts +72 -0
  211. package/lib/types/public/BundleGroup.d.ts +12 -0
  212. package/lib/types/public/Config.d.ts +75 -0
  213. package/lib/types/public/Dependency.d.ts +32 -0
  214. package/lib/types/public/Environment.d.ts +34 -0
  215. package/lib/types/public/MutableBundleGraph.d.ts +26 -0
  216. package/lib/types/public/PluginOptions.d.ts +25 -0
  217. package/lib/types/public/Symbols.d.ts +81 -0
  218. package/lib/types/public/Target.d.ts +16 -0
  219. package/lib/types/registerCoreWithSerializer.d.ts +2 -0
  220. package/lib/types/requests/AssetGraphRequest.d.ts +76 -0
  221. package/lib/types/requests/AssetGraphRequestRust.d.ts +21 -0
  222. package/lib/types/requests/AssetRequest.d.ts +16 -0
  223. package/lib/types/requests/AtlaspackBuildRequest.d.ts +33 -0
  224. package/lib/types/requests/AtlaspackConfigRequest.d.ts +45 -0
  225. package/lib/types/requests/BundleGraphRequest.d.ts +28 -0
  226. package/lib/types/requests/BundleGraphRequestRust.d.ts +34 -0
  227. package/lib/types/requests/BundleGraphRequestUtils.d.ts +38 -0
  228. package/lib/types/requests/ConfigRequest.d.ts +67 -0
  229. package/lib/types/requests/DevDepRequest.d.ts +30 -0
  230. package/lib/types/requests/EntryRequest.d.ts +36 -0
  231. package/lib/types/requests/PackageRequest.d.ts +27 -0
  232. package/lib/types/requests/PathRequest.d.ts +48 -0
  233. package/lib/types/requests/TargetRequest.d.ts +48 -0
  234. package/lib/types/requests/ValidationRequest.d.ts +20 -0
  235. package/lib/types/requests/WriteBundleRequest.d.ts +80 -0
  236. package/lib/types/requests/WriteBundlesRequest.d.ts +32 -0
  237. package/lib/types/requests/asset-graph-diff.d.ts +1 -0
  238. package/lib/types/requests/asset-graph-dot.d.ts +9 -0
  239. package/lib/types/resolveOptions.d.ts +3 -0
  240. package/lib/types/rustWorkerThreadDylibHack.d.ts +9 -0
  241. package/lib/types/serializerCore.browser.d.ts +3 -0
  242. package/lib/types/summarizeRequest.d.ts +10 -0
  243. package/lib/types/types.d.ts +496 -0
  244. package/lib/types/utils.d.ts +23 -0
  245. package/lib/types/worker.d.ts +44 -0
  246. package/lib/types.js +8 -1
  247. package/lib/utils.js +18 -3
  248. package/lib/worker.js +32 -15
  249. package/package.json +26 -36
  250. package/src/{AssetGraph.js → AssetGraph.ts} +87 -51
  251. package/src/{Atlaspack.js → Atlaspack.ts} +181 -72
  252. package/src/{AtlaspackConfig.schema.js → AtlaspackConfig.schema.ts} +25 -19
  253. package/src/{AtlaspackConfig.js → AtlaspackConfig.ts} +78 -54
  254. package/src/{BundleGraph.js → BundleGraph.ts} +575 -145
  255. package/src/{CommittedAsset.js → CommittedAsset.ts} +15 -13
  256. package/src/{Dependency.js → Dependency.ts} +59 -42
  257. package/src/{Environment.js → Environment.ts} +24 -15
  258. package/src/EnvironmentManager.ts +154 -0
  259. package/src/{IdentifierRegistry.js → IdentifierRegistry.ts} +1 -4
  260. package/src/{InternalConfig.js → InternalConfig.ts} +22 -23
  261. package/src/{PackagerRunner.js → PackagerRunner.ts} +114 -159
  262. package/src/{ReporterRunner.js → ReporterRunner.ts} +13 -18
  263. package/src/{RequestTracker.js → RequestTracker.ts} +444 -355
  264. package/src/{SymbolPropagation.js → SymbolPropagation.ts} +178 -61
  265. package/src/{TargetDescriptor.schema.js → TargetDescriptor.schema.ts} +10 -1
  266. package/src/{Transformation.js → Transformation.ts} +110 -65
  267. package/src/{UncommittedAsset.js → UncommittedAsset.ts} +45 -49
  268. package/src/{Validation.js → Validation.ts} +32 -17
  269. package/src/{applyRuntimes.js → applyRuntimes.ts} +135 -26
  270. package/src/{assetUtils.js → assetUtils.ts} +49 -36
  271. package/src/atlaspack-v3/AtlaspackV3.ts +183 -0
  272. package/src/atlaspack-v3/NapiWorkerPool.ts +129 -0
  273. package/src/atlaspack-v3/{fs.js → fs.ts} +8 -4
  274. package/src/atlaspack-v3/{index.js → index.ts} +3 -4
  275. package/src/atlaspack-v3/jsCallable.ts +14 -0
  276. package/src/atlaspack-v3/worker/compat/{asset-symbols.js → asset-symbols.ts} +40 -30
  277. package/src/atlaspack-v3/worker/compat/bitflags.ts +102 -0
  278. package/src/atlaspack-v3/worker/compat/{dependency.js → dependency.ts} +13 -13
  279. package/src/atlaspack-v3/worker/compat/{environment.js → environment.ts} +13 -9
  280. package/src/atlaspack-v3/worker/compat/index.ts +8 -0
  281. package/src/atlaspack-v3/worker/compat/{mutable-asset.js → mutable-asset.ts} +21 -20
  282. package/src/atlaspack-v3/worker/compat/{plugin-config.js → plugin-config.ts} +25 -56
  283. package/src/atlaspack-v3/worker/compat/{plugin-options.js → plugin-options.ts} +19 -5
  284. package/src/atlaspack-v3/worker/compat/{plugin-tracer.js → plugin-tracer.ts} +2 -2
  285. package/src/atlaspack-v3/worker/compat/{target.js → target.ts} +3 -4
  286. package/src/atlaspack-v3/worker/index.js +2 -1
  287. package/src/atlaspack-v3/worker/side-effect-detector.ts +298 -0
  288. package/src/atlaspack-v3/worker/worker.ts +548 -0
  289. package/src/{constants.js → constants.ts} +0 -3
  290. package/src/{dumpGraphToGraphViz.js → dumpGraphToGraphViz.ts} +73 -28
  291. package/src/index.ts +18 -0
  292. package/src/{loadAtlaspackPlugin.js → loadAtlaspackPlugin.ts} +8 -9
  293. package/src/{loadDotEnv.js → loadDotEnv.ts} +2 -2
  294. package/src/{projectPath.js → projectPath.ts} +20 -9
  295. package/src/public/{Asset.js → Asset.ts} +41 -28
  296. package/src/public/{Bundle.js → Bundle.ts} +28 -29
  297. package/src/public/{BundleGraph.js → BundleGraph.ts} +103 -68
  298. package/src/public/{BundleGroup.js → BundleGroup.ts} +7 -10
  299. package/src/public/{Config.js → Config.ts} +171 -33
  300. package/src/public/{Dependency.js → Dependency.ts} +20 -17
  301. package/src/public/{Environment.js → Environment.ts} +28 -17
  302. package/src/public/{MutableBundleGraph.js → MutableBundleGraph.ts} +55 -24
  303. package/src/public/{PluginOptions.js → PluginOptions.ts} +6 -6
  304. package/src/public/{Symbols.js → Symbols.ts} +75 -36
  305. package/src/public/{Target.js → Target.ts} +10 -8
  306. package/src/{registerCoreWithSerializer.js → registerCoreWithSerializer.ts} +9 -7
  307. package/src/requests/{AssetGraphRequest.js → AssetGraphRequest.ts} +117 -90
  308. package/src/requests/AssetGraphRequestRust.ts +557 -0
  309. package/src/requests/{AssetRequest.js → AssetRequest.ts} +24 -18
  310. package/src/requests/AtlaspackBuildRequest.ts +168 -0
  311. package/src/requests/{AtlaspackConfigRequest.js → AtlaspackConfigRequest.ts} +72 -58
  312. package/src/requests/{BundleGraphRequest.js → BundleGraphRequest.ts} +119 -199
  313. package/src/requests/BundleGraphRequestRust.ts +470 -0
  314. package/src/requests/BundleGraphRequestUtils.ts +323 -0
  315. package/src/requests/{ConfigRequest.js → ConfigRequest.ts} +110 -50
  316. package/src/requests/{DevDepRequest.js → DevDepRequest.ts} +60 -35
  317. package/src/requests/{EntryRequest.js → EntryRequest.ts} +36 -31
  318. package/src/requests/{PackageRequest.js → PackageRequest.ts} +52 -25
  319. package/src/requests/{PathRequest.js → PathRequest.ts} +47 -37
  320. package/src/requests/{TargetRequest.js → TargetRequest.ts} +265 -179
  321. package/src/requests/{ValidationRequest.js → ValidationRequest.ts} +18 -17
  322. package/src/requests/WriteBundleRequest.ts +734 -0
  323. package/src/requests/{WriteBundlesRequest.js → WriteBundlesRequest.ts} +134 -50
  324. package/src/requests/{asset-graph-diff.js → asset-graph-diff.ts} +25 -21
  325. package/src/requests/{asset-graph-dot.js → asset-graph-dot.ts} +8 -12
  326. package/src/{resolveOptions.js → resolveOptions.ts} +57 -27
  327. package/src/{rustWorkerThreadDylibHack.js → rustWorkerThreadDylibHack.ts} +1 -4
  328. package/src/{serializerCore.browser.js → serializerCore.browser.ts} +2 -3
  329. package/src/{summarizeRequest.js → summarizeRequest.ts} +17 -5
  330. package/src/types.ts +651 -0
  331. package/src/{utils.js → utils.ts} +52 -21
  332. package/src/{worker.js → worker.ts} +50 -42
  333. package/test/{AssetGraph.test.js → AssetGraph.test.ts} +5 -8
  334. package/test/{Atlaspack.test.js → Atlaspack.test.ts} +5 -10
  335. package/test/{AtlaspackConfig.test.js → AtlaspackConfig.test.ts} +0 -5
  336. package/test/{AtlaspackConfigRequest.test.js → AtlaspackConfigRequest.test.ts} +76 -16
  337. package/test/{BundleGraph.test.js → BundleGraph.test.ts} +8 -13
  338. package/test/{Dependency.test.js → Dependency.test.ts} +2 -3
  339. package/test/{EntryRequest.test.js → EntryRequest.test.ts} +1 -6
  340. package/test/Environment.test.ts +153 -0
  341. package/test/EnvironmentManager.test.ts +188 -0
  342. package/test/{IdentifierRegistry.test.js → IdentifierRegistry.test.ts} +2 -4
  343. package/test/{InternalAsset.test.js → InternalAsset.test.ts} +2 -7
  344. package/test/PackagerRunner.test.ts +0 -0
  345. package/test/{PublicAsset.test.js → PublicAsset.test.ts} +2 -7
  346. package/test/{PublicBundle.test.js → PublicBundle.test.ts} +1 -2
  347. package/test/{PublicDependency.test.js → PublicDependency.test.ts} +0 -2
  348. package/test/PublicEnvironment.test.ts +49 -0
  349. package/test/{PublicMutableBundleGraph.test.js → PublicMutableBundleGraph.test.ts} +6 -11
  350. package/test/{RequestTracker.test.js → RequestTracker.test.ts} +136 -58
  351. package/test/{SymbolPropagation.test.js → SymbolPropagation.test.ts} +124 -74
  352. package/test/{TargetRequest.test.js → TargetRequest.test.ts} +91 -92
  353. package/test/fixtures/config-with-reporters/.parcelrc +7 -0
  354. package/test/fixtures/custom-targets/package.json +6 -0
  355. package/test/public/Config.test.ts +104 -0
  356. package/test/requests/AssetGraphRequestRust.test.ts +443 -0
  357. package/test/requests/{ConfigRequest.test.js → ConfigRequest.test.ts} +202 -13
  358. package/test/requests/{DevDepRequest.test.js → DevDepRequest.test.ts} +0 -2
  359. package/test/requests/WriteBundleRequest.test.ts +602 -0
  360. package/test/{test-utils.js → test-utils.ts} +3 -4
  361. package/test/{utils.test.js → utils.test.ts} +1 -3
  362. package/tsconfig.json +60 -0
  363. package/tsconfig.tsbuildinfo +1 -0
  364. package/index.d.ts +0 -30
  365. package/lib/atlaspack-v3/worker/compat/plugin-logger.js +0 -29
  366. package/src/atlaspack-v3/AtlaspackV3.js +0 -87
  367. package/src/atlaspack-v3/NapiWorkerPool.js +0 -53
  368. package/src/atlaspack-v3/jsCallable.js +0 -18
  369. package/src/atlaspack-v3/worker/compat/bitflags.js +0 -100
  370. package/src/atlaspack-v3/worker/compat/plugin-logger.js +0 -47
  371. package/src/atlaspack-v3/worker/worker.js +0 -369
  372. package/src/index.js +0 -13
  373. package/src/requests/AssetGraphRequestRust.js +0 -263
  374. package/src/requests/AtlaspackBuildRequest.js +0 -111
  375. package/src/requests/WriteBundleRequest.js +0 -369
  376. package/src/types.js +0 -600
  377. package/test/Environment.test.js +0 -119
  378. package/test/PackagerRunner.test.js +0 -27
  379. package/test/PublicEnvironment.test.js +0 -27
  380. package/test/requests/AssetGraphRequestRust.test.js +0 -411
@@ -0,0 +1,384 @@
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 __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.default = applyRuntimes;
40
+ const path_1 = __importDefault(require("path"));
41
+ const assert_1 = __importDefault(require("assert"));
42
+ const assert_2 = __importDefault(require("assert"));
43
+ const nullthrows_1 = __importDefault(require("nullthrows"));
44
+ const AssetGraph_1 = require("./AssetGraph");
45
+ const BundleGraph_1 = __importDefault(require("./public/BundleGraph"));
46
+ const BundleGraph_2 = __importStar(require("./BundleGraph"));
47
+ const Bundle_1 = require("./public/Bundle");
48
+ const logger_1 = require("@atlaspack/logger");
49
+ const rust_1 = require("@atlaspack/rust");
50
+ const diagnostic_1 = __importStar(require("@atlaspack/diagnostic"));
51
+ const Dependency_1 = require("./public/Dependency");
52
+ const Environment_1 = require("./Environment");
53
+ const AssetGraphRequest_1 = __importDefault(require("./requests/AssetGraphRequest"));
54
+ const DevDepRequest_1 = require("./requests/DevDepRequest");
55
+ const projectPath_1 = require("./projectPath");
56
+ const profiler_1 = require("@atlaspack/profiler");
57
+ const utils_1 = require("@atlaspack/utils");
58
+ const EnvironmentManager_1 = require("./EnvironmentManager");
59
+ const feature_flags_1 = require("@atlaspack/feature-flags");
60
+ function nameRuntimeBundle(bundle, siblingBundle) {
61
+ // We don't run custom namers on runtime bundles as the runtime assumes that they are
62
+ // located at the same nesting level as their owning bundle. Custom naming could
63
+ // be added in future as long as the custom name is validated.
64
+ let { hashReference } = bundle;
65
+ let name = (0, nullthrows_1.default)(siblingBundle.name)
66
+ // Remove the existing hash from standard file patterns
67
+ // e.g. 'main.[hash].js' -> 'main.js' or 'main~[hash].js' -> 'main.js'
68
+ .replace(new RegExp(`[\\.~\\-_]?${siblingBundle.hashReference}`), '')
69
+ // Ensure the file ends with 'runtime.[hash].js'
70
+ .replace(`.${bundle.type}`, `.runtime.${hashReference}.${bundle.type}`);
71
+ bundle.name = name;
72
+ bundle.displayName = name.replace(hashReference, '[hash]');
73
+ }
74
+ /**
75
+ * The applyRuntimes function is responsible for generating all the runtimes
76
+ * (assets created during the build that don't actually exist on disk) and then
77
+ * linking them into the bundle graph.
78
+ *
79
+ * Introduction of manifest bundles: https://github.com/parcel-bundler/parcel/pull/8837
80
+ * Introduction of reverse topology: https://github.com/parcel-bundler/parcel/pull/8981
81
+ */
82
+ async function applyRuntimes({ bundleGraph, config, options, pluginOptions, api, optionsRef, previousDevDeps, devDepRequests, configs, }) {
83
+ let runtimes = await config.getRuntimes();
84
+ /**
85
+ * Usually, the assets returned from a runtime will go in the same bundle. It is
86
+ * possible though, for a runtime to return an asset with a `parallel` priority,
87
+ * which allows it to be moved to a separate bundle. In practice, this is
88
+ * usually used to generate application manifest files.
89
+ *
90
+ * When adding a manifest bundle (a whole new separate bundle) during a runtime,
91
+ * it needs to be added to a bundle group which will be potentially referenced
92
+ * by another bundle group. To avoid trying to reference a manifest entry which
93
+ * hasn't been created yet, we process the bundles from the bottom up (topological
94
+ * order), so that children will always be available when parents try to reference
95
+ * them.
96
+ */
97
+ // @ts-expect-error TS2304
98
+ let bundles = [];
99
+ bundleGraph.traverseBundles({
100
+ // @ts-expect-error TS2304
101
+ exit(bundle) {
102
+ bundles.push(bundle);
103
+ },
104
+ });
105
+ let connectionMap = new utils_1.DefaultMap(() => []);
106
+ for (let bundle of bundles) {
107
+ for (let runtime of runtimes) {
108
+ let measurement;
109
+ try {
110
+ const namedBundle = Bundle_1.NamedBundle.get(bundle, bundleGraph, options);
111
+ measurement = profiler_1.tracer.createMeasurement(runtime.name, 'applyRuntime', namedBundle.displayName);
112
+ let applied = await runtime.plugin.apply({
113
+ bundle: namedBundle,
114
+ bundleGraph: new BundleGraph_1.default(bundleGraph, Bundle_1.NamedBundle.get.bind(Bundle_1.NamedBundle), options),
115
+ config: configs.get(runtime.name)?.result,
116
+ options: pluginOptions,
117
+ logger: new logger_1.PluginLogger({ origin: runtime.name }),
118
+ tracer: new profiler_1.PluginTracer({
119
+ origin: runtime.name,
120
+ category: 'applyRuntime',
121
+ }),
122
+ });
123
+ if (applied) {
124
+ let runtimeAssets = Array.isArray(applied) ? applied : [applied];
125
+ for (let { code, dependency, filePath, isEntry, env, runtimeAssetRequiringExecutionOnLoad, priority, symbolData, } of runtimeAssets) {
126
+ let sourceName = path_1.default.join(path_1.default.dirname(filePath), `runtime-${(0, rust_1.hashString)(code)}.${bundle.type}`);
127
+ let assetGroup = {
128
+ code,
129
+ runtimeAssetRequiringExecutionOnLoad,
130
+ filePath: (0, projectPath_1.toProjectPath)(options.projectRoot, sourceName),
131
+ env: (0, Environment_1.mergeEnvironments)(options.projectRoot, (0, EnvironmentManager_1.fromEnvironmentId)(bundle.env), env),
132
+ // Runtime assets should be considered source, as they should be
133
+ // e.g. compiled to run in the target environment
134
+ isSource: true,
135
+ symbolData,
136
+ };
137
+ let connectionBundle = bundle;
138
+ /**
139
+ * If a runtime asset is marked with a priority of `parallel` this
140
+ * means we need to create a new bundle for the asset and add it to
141
+ * all the same bundle groups.
142
+ */
143
+ if (priority === 'parallel' && !bundle.needsStableName) {
144
+ let bundleGroups = bundleGraph.getBundleGroupsContainingBundle(bundle);
145
+ connectionBundle = (0, nullthrows_1.default)(bundleGraph.createBundle({
146
+ type: bundle.type,
147
+ needsStableName: false,
148
+ env: bundle.env,
149
+ target: bundle.target,
150
+ uniqueKey: 'runtime-manifest:' + bundle.id,
151
+ shouldContentHash: options.shouldContentHash,
152
+ }));
153
+ for (let bundleGroup of bundleGroups) {
154
+ bundleGraph.addBundleToBundleGroup(connectionBundle, bundleGroup);
155
+ }
156
+ bundleGraph.createBundleReference(bundle, connectionBundle);
157
+ // Ensure we name the bundle now as all other bundles have already
158
+ // been named as this point.
159
+ nameRuntimeBundle(connectionBundle, bundle);
160
+ }
161
+ // @ts-expect-error TS2345
162
+ connectionMap.get(connectionBundle).push({
163
+ bundle: connectionBundle,
164
+ assetGroup,
165
+ dependency,
166
+ isEntry,
167
+ });
168
+ }
169
+ }
170
+ }
171
+ catch (e) {
172
+ throw new diagnostic_1.default({
173
+ diagnostic: (0, diagnostic_1.errorToDiagnostic)(e, {
174
+ origin: runtime.name,
175
+ }),
176
+ });
177
+ }
178
+ finally {
179
+ measurement && measurement.end();
180
+ }
181
+ }
182
+ }
183
+ /**
184
+ * When merging the connections in to the bundle graph, the topological
185
+ * order can create module not found errors in some situations, often when HMR
186
+ * is enabled. To fix this, we put the connections into DFS order.
187
+ *
188
+ * Note: While DFS order seems to be the most reliable order to process the
189
+ * connections, this is likely due to it being close to the order that the bundles were
190
+ * inserted into the graph. There is a known issue where runtime assets marked
191
+ * as `isEntry` can create scenarios where there is no correct load order that
192
+ * won't error, as the entry runtime assets are added to many bundles in a
193
+ * single bundle group but their dependencies are not.
194
+ *
195
+ * This issue is almost exclusive to HMR scenarios as the two HMR runtime
196
+ * plugins (@atlaspack/runtime-browser-hmr and @atlaspack/runtime-react-refresh)
197
+ * are the only known cases where a runtime asset is marked as `isEntry`.
198
+ */
199
+ let connections = [];
200
+ bundleGraph.traverseBundles({
201
+ // @ts-expect-error TS2304
202
+ enter(bundle) {
203
+ connections.push(...connectionMap.get(bundle));
204
+ },
205
+ });
206
+ // Add dev deps for runtime plugins AFTER running them, to account for lazy require().
207
+ for (let runtime of runtimes) {
208
+ let devDepRequest = await (0, DevDepRequest_1.createDevDependency)({
209
+ specifier: runtime.name,
210
+ resolveFrom: runtime.resolveFrom,
211
+ }, previousDevDeps, options);
212
+ devDepRequests.set(`${devDepRequest.specifier}:${(0, projectPath_1.fromProjectPathRelative)(devDepRequest.resolveFrom)}`, devDepRequest);
213
+ await (0, DevDepRequest_1.runDevDepRequest)(api, devDepRequest);
214
+ }
215
+ // Create a new AssetGraph from the generated runtime assets which also runs
216
+ // transforms and resolves all dependencies.
217
+ let { assetGraph: runtimesAssetGraph, changedAssets } = await reconcileNewRuntimes(api, connections, optionsRef);
218
+ if ((0, feature_flags_1.getFeatureFlag)('skipRuntimeSymbolProp')) {
219
+ // Apply pre-computed symbol data from runtime assets to skip symbol propagation
220
+ applyRuntimeSymbolData(runtimesAssetGraph, connections);
221
+ }
222
+ // Convert the runtime AssetGraph into a BundleGraph, this includes assigning
223
+ // the assets their public ids
224
+ let runtimesBundleGraph = BundleGraph_2.default.fromAssetGraph(runtimesAssetGraph, options.mode === 'production', bundleGraph._publicIdByAssetId, bundleGraph._assetPublicIds);
225
+ // Merge the runtimes bundle graph into the main bundle graph.
226
+ bundleGraph.merge(runtimesBundleGraph);
227
+ // Add the public id mappings from the runtumes bundlegraph to the main bundle graph
228
+ for (let [assetId, publicId] of runtimesBundleGraph._publicIdByAssetId) {
229
+ bundleGraph._publicIdByAssetId.set(assetId, publicId);
230
+ bundleGraph._assetPublicIds.add(publicId);
231
+ }
232
+ // Connect each of the generated runtime assets to bundles in the main bundle
233
+ // graph. This is like a mini-bundling algorithm for runtime assets.
234
+ for (let { bundle, assetGroup, dependency, isEntry } of connections) {
235
+ let assetGroupNode = (0, AssetGraph_1.nodeFromAssetGroup)(assetGroup);
236
+ let assetGroupAssetNodeIds = runtimesAssetGraph.getNodeIdsConnectedFrom(runtimesAssetGraph.getNodeIdByContentKey(assetGroupNode.id));
237
+ (0, assert_2.default)(assetGroupAssetNodeIds.length === 1);
238
+ let runtimeNodeId = assetGroupAssetNodeIds[0];
239
+ let runtimeNode = (0, nullthrows_1.default)(runtimesAssetGraph.getNode(runtimeNodeId));
240
+ (0, assert_2.default)(runtimeNode.type === 'asset');
241
+ // Find the asset that the runtime asset should be connected from by resolving
242
+ // it's dependency.
243
+ let resolution = dependency &&
244
+ bundleGraph.getResolvedAsset((0, Dependency_1.dependencyToInternalDependency)(dependency), bundle);
245
+ // Walk all the dependencies of the runtime assets and check if they are
246
+ // already reachable from the bundle that the runtime asset is assigned to.
247
+ // If so, we add them to `duplicatedContentKeys` to be skipped when assigning
248
+ // assets to bundles.
249
+ let runtimesBundleGraphRuntimeNodeId = runtimesBundleGraph._graph.getNodeIdByContentKey(runtimeNode.id);
250
+ let duplicatedContentKeys = new Set();
251
+ runtimesBundleGraph._graph.traverse((nodeId, _, actions) => {
252
+ let node = (0, nullthrows_1.default)(runtimesBundleGraph._graph.getNode(nodeId));
253
+ if (node.type !== 'dependency') {
254
+ return;
255
+ }
256
+ let assets = runtimesBundleGraph._graph
257
+ .getNodeIdsConnectedFrom(nodeId)
258
+ .map((assetNodeId) => {
259
+ let assetNode = (0, nullthrows_1.default)(runtimesBundleGraph._graph.getNode(assetNodeId));
260
+ (0, assert_2.default)(assetNode.type === 'asset');
261
+ return assetNode.value;
262
+ });
263
+ for (let asset of assets) {
264
+ if (bundleGraph.isAssetReachableFromBundle(asset, bundle) ||
265
+ resolution?.id === asset.id) {
266
+ duplicatedContentKeys.add(asset.id);
267
+ actions.skipChildren();
268
+ }
269
+ }
270
+ }, runtimesBundleGraphRuntimeNodeId);
271
+ let bundleNodeId = bundleGraph._graph.getNodeIdByContentKey(bundle.id);
272
+ let bundleGraphRuntimeNodeId = bundleGraph._graph.getNodeIdByContentKey(runtimeNode.id); // the node id is not constant between graphs
273
+ // Assign the runtime assets and all of it's depepdencies to the bundle unless
274
+ // we have detected it as already being reachable from this bundle via `duplicatedContentKeys`.
275
+ runtimesBundleGraph._graph.traverse((nodeId, _, actions) => {
276
+ let node = (0, nullthrows_1.default)(runtimesBundleGraph._graph.getNode(nodeId));
277
+ if (node.type === 'asset' || node.type === 'dependency') {
278
+ if (duplicatedContentKeys.has(node.id)) {
279
+ actions.skipChildren();
280
+ return;
281
+ }
282
+ const bundleGraphNodeId = bundleGraph._graph.getNodeIdByContentKey(node.id); // the node id is not constant between graphs
283
+ bundleGraph._graph.addEdge(bundleNodeId, bundleGraphNodeId, BundleGraph_2.bundleGraphEdgeTypes.contains);
284
+ }
285
+ }, runtimesBundleGraphRuntimeNodeId);
286
+ if (isEntry) {
287
+ bundleGraph._graph.addEdge(bundleNodeId, bundleGraphRuntimeNodeId);
288
+ bundle.entryAssetIds.unshift(runtimeNode.id);
289
+ }
290
+ if (dependency == null) {
291
+ // Verify this asset won't become an island
292
+ (0, assert_1.default)(bundleGraph._graph.getNodeIdsConnectedTo(bundleGraphRuntimeNodeId)
293
+ .length > 0, 'Runtime must have an inbound dependency or be an entry');
294
+ }
295
+ else {
296
+ let dependencyNodeId = bundleGraph._graph.getNodeIdByContentKey(dependency.id);
297
+ bundleGraph._graph.addEdge(dependencyNodeId, bundleGraphRuntimeNodeId);
298
+ }
299
+ }
300
+ return changedAssets;
301
+ }
302
+ /**
303
+ * Apply pre-computed symbol data from runtime assets to the asset graph
304
+ * to avoid running symbol propagation on runtime code we control.
305
+ */
306
+ function applyRuntimeSymbolData(assetGraph, connections) {
307
+ for (let { assetGroup } of connections) {
308
+ let assetGroupNode = (0, AssetGraph_1.nodeFromAssetGroup)(assetGroup);
309
+ let assetGroupAssetNodeIds = assetGraph.getNodeIdsConnectedFrom(assetGraph.getNodeIdByContentKey(assetGroupNode.id));
310
+ if (assetGroupAssetNodeIds.length !== 1) {
311
+ continue;
312
+ }
313
+ let runtimeAssetNodeId = assetGroupAssetNodeIds[0];
314
+ let runtimeAssetNode = assetGraph.getNode(runtimeAssetNodeId);
315
+ if (!runtimeAssetNode || runtimeAssetNode.type !== 'asset') {
316
+ continue;
317
+ }
318
+ let symbolData = assetGroup.symbolData;
319
+ if (!symbolData) {
320
+ // We completely skip symbol propagation for runtime assets, so symbolData
321
+ // is required
322
+ throw new Error('Runtime asset is missing symbol data');
323
+ }
324
+ if (symbolData.symbols) {
325
+ // Convert from SymbolData format to internal Asset.symbols format
326
+ let internalSymbols = new Map();
327
+ for (let [symbol, data] of symbolData.symbols) {
328
+ internalSymbols.set(symbol, {
329
+ local: data.local,
330
+ loc: data.loc || null,
331
+ meta: data.meta,
332
+ });
333
+ }
334
+ runtimeAssetNode.value.symbols = internalSymbols;
335
+ }
336
+ if (symbolData.dependencies && symbolData.dependencies.length > 0) {
337
+ let outgoingDeps = assetGraph
338
+ .getNodeIdsConnectedFrom(runtimeAssetNodeId)
339
+ .map((id) => assetGraph.getNode(id))
340
+ .filter((node) => node?.type === 'dependency')
341
+ .map((node) => node);
342
+ for (let depSymbolData of symbolData.dependencies) {
343
+ let matchingDep = outgoingDeps.find((depNode) => depNode.value.specifier === depSymbolData.specifier);
344
+ if (matchingDep) {
345
+ if (depSymbolData.symbols) {
346
+ let internalDepSymbols = new Map();
347
+ for (let [symbol, data] of depSymbolData.symbols) {
348
+ internalDepSymbols.set(symbol, {
349
+ local: data.local,
350
+ loc: data.loc || null,
351
+ isWeak: data.isWeak,
352
+ meta: data.meta,
353
+ });
354
+ }
355
+ matchingDep.value.symbols = internalDepSymbols;
356
+ }
357
+ if (depSymbolData.usedSymbols) {
358
+ matchingDep.usedSymbolsDown = new Set(depSymbolData.usedSymbols);
359
+ // For runtime assets, usedSymbolsUp will be the same as usedSymbolsDown
360
+ // since we know exactly what we're using
361
+ let usedSymbolsUp = new Map();
362
+ for (let symbol of depSymbolData.usedSymbols) {
363
+ // Mark as resolved to external (null) since runtime deps are typically external
364
+ usedSymbolsUp.set(symbol, null);
365
+ }
366
+ matchingDep.usedSymbolsUp = usedSymbolsUp;
367
+ }
368
+ }
369
+ }
370
+ }
371
+ }
372
+ }
373
+ function reconcileNewRuntimes(api, connections, optionsRef) {
374
+ let assetGroups = connections.map((t) => t.assetGroup);
375
+ let request = (0, AssetGraphRequest_1.default)({
376
+ name: 'Runtimes',
377
+ assetGroups,
378
+ optionsRef,
379
+ skipSymbolProp: (0, feature_flags_1.getFeatureFlag)('skipRuntimeSymbolProp') ||
380
+ (0, feature_flags_1.getFeatureFlag)('rustSymbolTracker'),
381
+ });
382
+ // rebuild the graph
383
+ return api.runRequest(request, { force: true });
384
+ }
@@ -0,0 +1,169 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.createAssetIdFromOptions = createAssetIdFromOptions;
7
+ exports.createAsset = createAsset;
8
+ exports.generateFromAST = generateFromAST;
9
+ exports.getInvalidationId = getInvalidationId;
10
+ exports.getInvalidationHash = getInvalidationHash;
11
+ const stream_1 = require("stream");
12
+ const build_cache_1 = require("@atlaspack/build-cache");
13
+ const logger_1 = require("@atlaspack/logger");
14
+ const nullthrows_1 = __importDefault(require("nullthrows"));
15
+ const loadAtlaspackPlugin_1 = __importDefault(require("./loadAtlaspackPlugin"));
16
+ const Asset_1 = require("./public/Asset");
17
+ const PluginOptions_1 = __importDefault(require("./public/PluginOptions"));
18
+ const utils_1 = require("@atlaspack/utils");
19
+ const utils_2 = require("./utils");
20
+ const projectPath_1 = require("./projectPath");
21
+ const rust_1 = require("@atlaspack/rust");
22
+ const types_1 = require("./types");
23
+ const profiler_1 = require("@atlaspack/profiler");
24
+ const IdentifierRegistry_1 = require("./IdentifierRegistry");
25
+ const EnvironmentManager_1 = require("./EnvironmentManager");
26
+ const source_map_1 = __importDefault(require("@atlaspack/source-map"));
27
+ function createAssetIdFromOptions(options) {
28
+ const data = {
29
+ environmentId: (0, EnvironmentManager_1.toEnvironmentId)(options.env),
30
+ filePath: options.filePath,
31
+ code: options.code,
32
+ pipeline: options.pipeline,
33
+ query: options.query,
34
+ uniqueKey: options.uniqueKey,
35
+ fileType: options.type,
36
+ };
37
+ const id = (0, rust_1.createAssetId)(data);
38
+ IdentifierRegistry_1.identifierRegistry.addIdentifier('asset', id, data);
39
+ return id;
40
+ }
41
+ function createAsset(projectRoot, options) {
42
+ return {
43
+ id: options.id != null ? options.id : createAssetIdFromOptions(options),
44
+ committed: options.committed ?? false,
45
+ filePath: options.filePath,
46
+ query: options.query,
47
+ bundleBehavior: options.bundleBehavior
48
+ ? types_1.BundleBehavior[options.bundleBehavior]
49
+ : null,
50
+ isBundleSplittable: options.isBundleSplittable ?? true,
51
+ type: options.type,
52
+ contentKey: options.contentKey,
53
+ mapKey: options.mapKey,
54
+ astKey: options.astKey,
55
+ astGenerator: options.astGenerator,
56
+ dependencies: options.dependencies || new Map(),
57
+ isSource: options.isSource,
58
+ outputHash: options.outputHash,
59
+ pipeline: options.pipeline,
60
+ env: options.env,
61
+ meta: options.meta || {},
62
+ stats: options.stats,
63
+ symbols: options.symbols &&
64
+ new Map([...options.symbols].map(([k, v]) => [
65
+ k,
66
+ {
67
+ local: v.local,
68
+ meta: v.meta,
69
+ loc: (0, utils_2.toInternalSourceLocation)(projectRoot, v.loc),
70
+ },
71
+ ])),
72
+ sideEffects: options.sideEffects ?? true,
73
+ uniqueKey: options.uniqueKey,
74
+ plugin: options.plugin,
75
+ configPath: options.configPath,
76
+ configKeyPath: options.configKeyPath,
77
+ };
78
+ }
79
+ const generateResults = new WeakMap();
80
+ function generateFromAST(asset) {
81
+ let output = generateResults.get(asset.value);
82
+ if (output == null) {
83
+ output = _generateFromAST(asset);
84
+ generateResults.set(asset.value, output);
85
+ }
86
+ return output;
87
+ }
88
+ async function _generateFromAST(asset) {
89
+ let ast = await asset.getAST();
90
+ if (ast == null) {
91
+ throw new Error('Asset has no AST');
92
+ }
93
+ let pluginName = (0, nullthrows_1.default)(asset.value.plugin);
94
+ let { plugin } = await (0, loadAtlaspackPlugin_1.default)(pluginName, (0, projectPath_1.fromProjectPath)(asset.options.projectRoot, (0, nullthrows_1.default)(asset.value.configPath)), (0, nullthrows_1.default)(asset.value.configKeyPath), asset.options);
95
+ let generate = plugin.generate?.bind(plugin);
96
+ if (!generate) {
97
+ throw new Error(`${pluginName} does not have a generate method`);
98
+ }
99
+ let { content, map } = await generate({
100
+ asset: new Asset_1.Asset(asset),
101
+ ast,
102
+ options: new PluginOptions_1.default(asset.options),
103
+ logger: new logger_1.PluginLogger({ origin: pluginName }),
104
+ tracer: new profiler_1.PluginTracer({ origin: pluginName, category: 'asset-generate' }),
105
+ });
106
+ let mapBuffer = source_map_1.default.safeToBuffer(map);
107
+ // Store the results in the cache so we can avoid generating again next time
108
+ await Promise.all([
109
+ asset.options.cache.setStream((0, nullthrows_1.default)(asset.value.contentKey), (0, utils_1.blobToStream)(content)),
110
+ mapBuffer != null &&
111
+ asset.options.cache.setBlob((0, nullthrows_1.default)(asset.value.mapKey), mapBuffer),
112
+ ]);
113
+ return {
114
+ content: content instanceof stream_1.Readable
115
+ ? asset.options.cache.getStream((0, nullthrows_1.default)(asset.value.contentKey))
116
+ : content,
117
+ map,
118
+ };
119
+ }
120
+ function getInvalidationId(invalidation) {
121
+ switch (invalidation.type) {
122
+ case 'file':
123
+ return 'file:' + (0, projectPath_1.fromProjectPathRelative)(invalidation.filePath);
124
+ case 'env':
125
+ return 'env:' + invalidation.key;
126
+ case 'option':
127
+ return 'option:' + invalidation.key;
128
+ default:
129
+ // @ts-expect-error TS2339
130
+ throw new Error('Unknown invalidation type: ' + invalidation.type);
131
+ }
132
+ }
133
+ const hashCache = (0, build_cache_1.createBuildCache)();
134
+ async function getInvalidationHash(invalidations, options) {
135
+ if (invalidations.length === 0) {
136
+ return '';
137
+ }
138
+ let sortedInvalidations = invalidations
139
+ .slice()
140
+ .sort((a, b) => (getInvalidationId(a) < getInvalidationId(b) ? -1 : 1));
141
+ let hashes = '';
142
+ for (let invalidation of sortedInvalidations) {
143
+ switch (invalidation.type) {
144
+ case 'file': {
145
+ // Only recompute the hash of this file if we haven't seen it already during this build.
146
+ let fileHash = hashCache.get(invalidation.filePath);
147
+ if (fileHash == null) {
148
+ fileHash = (0, utils_1.hashFile)(options.inputFS, (0, projectPath_1.fromProjectPath)(options.projectRoot, invalidation.filePath));
149
+ hashCache.set(invalidation.filePath, fileHash);
150
+ }
151
+ hashes += await fileHash;
152
+ break;
153
+ }
154
+ case 'env':
155
+ hashes +=
156
+ invalidation.key + ':' + (options.env[invalidation.key] || '');
157
+ break;
158
+ case 'option':
159
+ hashes +=
160
+ // @ts-expect-error TS7053
161
+ invalidation.key + ':' + (0, utils_2.hashFromOption)(options[invalidation.key]);
162
+ break;
163
+ default:
164
+ // @ts-expect-error TS2339
165
+ throw new Error('Unknown invalidation type: ' + invalidation.type);
166
+ }
167
+ }
168
+ return (0, rust_1.hashString)(hashes);
169
+ }
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.AtlaspackV3 = void 0;
7
+ const rust_1 = require("@atlaspack/rust");
8
+ const NapiWorkerPool_1 = require("./NapiWorkerPool");
9
+ const diagnostic_1 = __importDefault(require("@atlaspack/diagnostic"));
10
+ class AtlaspackV3 {
11
+ constructor(atlaspack_napi, napiWorkerPool, isDefaultNapiWorkerPool) {
12
+ this._atlaspack_napi = atlaspack_napi;
13
+ this._napiWorkerPool = napiWorkerPool;
14
+ this._isDefaultNapiWorkerPool = isDefaultNapiWorkerPool;
15
+ }
16
+ static async create({ fs, packageManager, threads, lmdb, napiWorkerPool, ...options }) {
17
+ // @ts-expect-error TS2339
18
+ options.logLevel = options.logLevel || 'error';
19
+ // @ts-expect-error TS2339
20
+ options.defaultTargetOptions = options.defaultTargetOptions || {};
21
+ // @ts-expect-error TS2339
22
+ options.defaultTargetOptions.engines =
23
+ // @ts-expect-error TS2339
24
+ options.defaultTargetOptions.engines || {};
25
+ let isDefaultNapiWorkerPool = false;
26
+ if (!napiWorkerPool) {
27
+ napiWorkerPool = new NapiWorkerPool_1.NapiWorkerPool();
28
+ isDefaultNapiWorkerPool = true;
29
+ }
30
+ // @ts-expect-error TS2488
31
+ const [internal, error] = await (0, rust_1.atlaspackNapiCreate)({
32
+ fs,
33
+ packageManager,
34
+ threads,
35
+ options,
36
+ napiWorkerPool,
37
+ }, lmdb);
38
+ if (error !== null) {
39
+ throw new diagnostic_1.default({
40
+ diagnostic: error,
41
+ });
42
+ }
43
+ return new AtlaspackV3(internal, napiWorkerPool, isDefaultNapiWorkerPool);
44
+ }
45
+ end() {
46
+ // If the worker pool was provided to us, don't shut it down, it's up to the provider.
47
+ if (this._isDefaultNapiWorkerPool) {
48
+ this._napiWorkerPool.shutdown();
49
+ }
50
+ }
51
+ buildAssetGraph(progressCallback) {
52
+ return (0, rust_1.atlaspackNapiBuildAssetGraph)(this._atlaspack_napi, progressCallback);
53
+ }
54
+ buildBundleGraph(progressCallback) {
55
+ return (0, rust_1.atlaspackNapiBuildBundleGraph)(this._atlaspack_napi, progressCallback);
56
+ }
57
+ build(progressCallback) {
58
+ return (0, rust_1.atlaspackNapiBuild)(this._atlaspack_napi, progressCallback);
59
+ }
60
+ loadBundleGraph(bundleGraph) {
61
+ const { nodesJson, edges, publicIdByAssetId, environmentsJson } = bundleGraph.serializeForNative();
62
+ return (0, rust_1.atlaspackNapiLoadBundleGraph)(this._atlaspack_napi, nodesJson, edges, publicIdByAssetId, environmentsJson);
63
+ }
64
+ updateBundleGraph(bundleGraph, changedAssetIds) {
65
+ const nodesJson = bundleGraph.serializeAssetNodesForNative(changedAssetIds);
66
+ return (0, rust_1.atlaspackNapiUpdateBundleGraph)(this._atlaspack_napi, nodesJson);
67
+ }
68
+ package(bundleId, options) {
69
+ return (0, rust_1.atlaspackNapiPackage)(this._atlaspack_napi, bundleId, options);
70
+ }
71
+ async respondToFsEvents(events) {
72
+ // @ts-expect-error TS2488
73
+ let [needsRebuild, error] = await (0, rust_1.atlaspackNapiRespondToFsEvents)(this._atlaspack_napi, events);
74
+ if (error) {
75
+ throw new Error(error);
76
+ }
77
+ return needsRebuild;
78
+ }
79
+ async completeCacheSession() {
80
+ return (await (0, rust_1.atlaspackNapiCompleteSession)(this._atlaspack_napi));
81
+ }
82
+ }
83
+ exports.AtlaspackV3 = AtlaspackV3;