@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
@@ -3,6 +3,10 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.SourceMapHashRefRewriteStream = void 0;
7
+ exports.applyReplacementsToSourceMap = applyReplacementsToSourceMap;
8
+ exports.applyReplacementsToVLQMappings = applyReplacementsToVLQMappings;
9
+ exports.computeSourceMapRoot = computeSourceMapRoot;
6
10
  exports.default = createWriteBundleRequest;
7
11
  var _constants = require("../constants");
8
12
  function _nullthrows() {
@@ -19,6 +23,13 @@ function _path() {
19
23
  };
20
24
  return data;
21
25
  }
26
+ function _url() {
27
+ const data = _interopRequireDefault(require("url"));
28
+ _url = function () {
29
+ return data;
30
+ };
31
+ return data;
32
+ }
22
33
  var _Bundle = require("../public/Bundle");
23
34
  function _utils() {
24
35
  const data = require("@atlaspack/utils");
@@ -45,7 +56,6 @@ function _logger() {
45
56
  return data;
46
57
  }
47
58
  var _DevDepRequest = require("./DevDepRequest");
48
- var _AtlaspackConfig = require("../AtlaspackConfig");
49
59
  function _diagnostic() {
50
60
  const data = _interopRequireWildcard(require("@atlaspack/diagnostic"));
51
61
  _diagnostic = function () {
@@ -68,11 +78,22 @@ function _featureFlags() {
68
78
  };
69
79
  return data;
70
80
  }
71
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
72
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
73
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
81
+ var _EnvironmentManager = require("../EnvironmentManager");
82
+ function _sourceMap() {
83
+ const data = require("@atlaspack/source-map");
84
+ _sourceMap = function () {
85
+ return data;
86
+ };
87
+ return data;
88
+ }
89
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
90
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
74
91
  const HASH_REF_PREFIX_LEN = _constants.HASH_REF_PREFIX.length;
75
92
  const BOUNDARY_LENGTH = _constants.HASH_REF_PREFIX.length + 32 - 1;
93
+ const HASH_REF_PLACEHOLDER_LEN = HASH_REF_PREFIX_LEN + _constants.HASH_REF_HASH_LEN;
94
+
95
+ // The JSON key prefix we scan for in the source map stream.
96
+ const MAPPINGS_KEY_BUF = Buffer.from('"mappings":"');
76
97
  /**
77
98
  * Writes a bundle to the dist directory, replacing hash references with the final content hashes.
78
99
  */
@@ -86,6 +107,8 @@ function createWriteBundleRequest(input) {
86
107
  input
87
108
  };
88
109
  }
110
+
111
+ // @ts-expect-error TS7031
89
112
  async function run({
90
113
  input,
91
114
  options,
@@ -121,7 +144,8 @@ async function run({
121
144
  let cacheKeys = info.cacheKeys;
122
145
  let mapKey = cacheKeys.map;
123
146
  let fullPath = (0, _projectPath.fromProjectPath)(options.projectRoot, filePath);
124
- if (mapKey && bundle.env.sourceMap && !bundle.env.sourceMap.inline) {
147
+ const env = (0, _EnvironmentManager.fromEnvironmentId)(bundle.env);
148
+ if (mapKey && env.sourceMap && !env.sourceMap.inline) {
125
149
  api.invalidateOnFileDelete((0, _projectPath.toProjectPath)(options.projectRoot, fullPath + '.map'));
126
150
  }
127
151
  let dir = _path().default.dirname(fullPath);
@@ -141,24 +165,36 @@ async function run({
141
165
  contentStream = (0, _utils().blobToStream)(await options.cache.getBlob(cacheKeys.content));
142
166
  }
143
167
  let size = 0;
144
- contentStream = contentStream.pipe(new (_utils().TapStream)(buf => {
168
+ contentStream = contentStream.pipe(
169
+ // @ts-expect-error TS2554
170
+ new (_utils().TapStream)(buf => {
145
171
  size += buf.length;
146
172
  }));
147
- let configResult = (0, _nullthrows().default)(await api.runRequest((0, _AtlaspackConfigRequest.default)()));
173
+ let configResult = (0, _nullthrows().default)(
174
+ // @ts-expect-error TS2347
175
+ await api.runRequest((0, _AtlaspackConfigRequest.default)()));
148
176
  let config = (0, _AtlaspackConfigRequest.getCachedAtlaspackConfig)(configResult, options);
149
177
  let {
150
178
  devDeps,
151
179
  invalidDevDeps
152
180
  } = await (0, _DevDepRequest.getDevDepRequests)(api);
153
181
  (0, _DevDepRequest.invalidateDevDeps)(invalidDevDeps, options, config);
154
- await writeFiles(contentStream, info, hashRefToNameHash, options, config, outputFS, filePath, writeOptions, devDeps, api);
155
- const hasSourceMap = (0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements') ? await options.cache.hasLargeBlob(mapKey) : await options.cache.has(mapKey);
156
- if (mapKey && bundle.env.sourceMap && !bundle.env.sourceMap.inline && hasSourceMap) {
157
- const mapEntry = (0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements') ? await options.cache.getLargeBlob(mapKey) : await options.cache.getBlob(mapKey);
158
- await writeFiles((0, _utils().blobToStream)(mapEntry), info, hashRefToNameHash, options, config, outputFS, (0, _projectPath.toProjectPathUnsafe)((0, _projectPath.fromProjectPathRelative)(filePath) + '.map'), writeOptions, devDeps, api);
182
+ const bundleReplacements = (0, _featureFlags().getFeatureFlag)('fixSourceMapHashRefs') ? [] : undefined;
183
+ await writeFiles(contentStream, info, hashRefToNameHash, options, config, outputFS, filePath, writeOptions, devDeps, api, bundleReplacements);
184
+ const hasSourceMap = await options.cache.has(mapKey);
185
+ if (mapKey && env.sourceMap && !env.sourceMap.inline && hasSourceMap) {
186
+ const mapEntry = await options.cache.getBlob(mapKey);
187
+ let mapStream;
188
+ if ((0, _featureFlags().getFeatureFlag)('fixSourceMapHashRefs') && bundleReplacements && bundleReplacements.length > 0) {
189
+ mapStream = (0, _utils().blobToStream)(mapEntry).pipe(new SourceMapHashRefRewriteStream(bundleReplacements));
190
+ } else {
191
+ mapStream = (0, _utils().blobToStream)(mapEntry);
192
+ }
193
+ await writeFiles(mapStream, info, hashRefToNameHash, options, config, outputFS, (0, _projectPath.toProjectPathUnsafe)((0, _projectPath.fromProjectPathRelative)(filePath) + '.map'), writeOptions, devDeps, api);
159
194
  }
160
195
  let res = {
161
196
  filePath,
197
+ bundleId: bundle.id,
162
198
  type: info.type,
163
199
  stats: {
164
200
  size,
@@ -168,17 +204,255 @@ async function run({
168
204
  api.storeResult(res);
169
205
  return res;
170
206
  }
171
- async function writeFiles(inputStream, info, hashRefToNameHash, options, config, outputFS, filePath, writeOptions, devDeps, api) {
207
+ function applyReplacementsToSourceMap(sourceMap, replacements) {
208
+ if (replacements.length === 0) return;
209
+ const sorted = [...replacements].sort((a, b) => a.line - b.line || a.column - b.column);
210
+ for (const r of sorted) {
211
+ const delta = r.newLength - r.originalLength;
212
+ if (delta !== 0) {
213
+ // r.column is in post-replacement coordinates (matching the already-shifted
214
+ // source map state after previous offsetColumns calls). The end of the
215
+ // placeholder in these coordinates is simply r.column + r.originalLength.
216
+ const offsetStartColumn = r.column + r.originalLength;
217
+ const line1Based = r.line + 1;
218
+ if (line1Based >= 1 && offsetStartColumn + delta >= 0) {
219
+ sourceMap.offsetColumns(line1Based, offsetStartColumn, delta);
220
+ }
221
+ }
222
+ }
223
+ }
224
+
225
+ /**
226
+ * Applies hash-ref replacement column offsets directly to a VLQ mappings
227
+ * string without deserializing the full source map into a native struct.
228
+ *
229
+ * Each replacement r describes a hash-ref that was substituted in the output
230
+ * file. r.column is in the progressively-shifted post-replacement coordinate
231
+ * space (matching the already-shifted source map state after all previous
232
+ * offsetColumns calls), so thresholds are applied sequentially against the
233
+ * running absCol values exactly as the native offsetColumns implementation does.
234
+ */
235
+ function applyReplacementsToVLQMappings(mappings, replacements) {
236
+ if (replacements.length === 0) return mappings;
237
+
238
+ // Group replacements by line (0-indexed), sorted by column ascending.
239
+ const byLine = new Map();
240
+ for (const r of replacements) {
241
+ let arr = byLine.get(r.line);
242
+ if (!arr) {
243
+ arr = [];
244
+ byLine.set(r.line, arr);
245
+ }
246
+ arr.push(r);
247
+ }
248
+ for (const arr of byLine.values()) {
249
+ arr.sort((a, b) => a.column - b.column);
250
+ }
251
+ const lines = mappings.split(';');
252
+ const resultLines = [];
253
+ for (let lineIdx = 0; lineIdx < lines.length; lineIdx++) {
254
+ const lineReps = byLine.get(lineIdx);
255
+ if (!lineReps || lineReps.length === 0) {
256
+ resultLines.push(lines[lineIdx]);
257
+ continue;
258
+ }
259
+ const line = lines[lineIdx];
260
+ if (!line) {
261
+ resultLines.push('');
262
+ continue;
263
+ }
264
+
265
+ // Decode segment column deltas to absolute columns.
266
+ const segments = line.split(',');
267
+ const colVlqEnds = [];
268
+ const absCols = [];
269
+ let absCol = 0;
270
+ for (const seg of segments) {
271
+ const {
272
+ value: colDelta,
273
+ nextPos
274
+ } = (0, _sourceMap().decodeVLQ)(seg, 0);
275
+ absCol += colDelta;
276
+ colVlqEnds.push(nextPos);
277
+ absCols.push(absCol);
278
+ }
279
+
280
+ // Apply each replacement's column shift sequentially against the
281
+ // current absCol values (which have already been adjusted by previous
282
+ // replacements on this line), mirroring the sequential offsetColumns calls.
283
+ for (const r of lineReps) {
284
+ const delta = r.newLength - r.originalLength;
285
+ if (delta === 0) continue;
286
+ const threshold = r.column + r.originalLength;
287
+ for (let i = 0; i < absCols.length; i++) {
288
+ if (absCols[i] >= threshold) {
289
+ absCols[i] += delta;
290
+ }
291
+ }
292
+ }
293
+
294
+ // Re-encode with updated absolute columns; only the leading column VLQ
295
+ // field of each segment changes – the tail bytes are sliced unchanged.
296
+ const resultSegments = [];
297
+ let prevAbsCol = 0;
298
+ for (let i = 0; i < segments.length; i++) {
299
+ const newDelta = absCols[i] - prevAbsCol;
300
+ prevAbsCol = absCols[i];
301
+ resultSegments.push((0, _sourceMap().encodeVLQ)(newDelta) + segments[i].slice(colVlqEnds[i]));
302
+ }
303
+ resultLines.push(resultSegments.join(','));
304
+ }
305
+ return resultLines.join(';');
306
+ }
307
+ /**
308
+ * A Transform stream that rewrites the "mappings" VLQ field of a source map
309
+ * JSON to account for hash-ref replacements, without ever loading the full
310
+ * JSON object or the native Rust SourceMapInner into memory.
311
+ *
312
+ * Field order in cached source maps (from partialVlqMapToSourceMap / toVLQ):
313
+ * mappings → sources → sourcesContent → names → version → file → sourceRoot
314
+ *
315
+ * "mappings" is the very first field, so we scan only a tiny header before
316
+ * switching to zero-copy passthrough for the bulk sourcesContent bytes.
317
+ */
318
+ class SourceMapHashRefRewriteStream extends _stream().Transform {
319
+ constructor(replacements) {
320
+ super();
321
+ this.replacements = replacements;
322
+ this.state = 'scanning';
323
+ this.scanBuf = Buffer.alloc(0);
324
+ this.mappingsBufs = [];
325
+ }
326
+
327
+ // @ts-expect-error TS7006
328
+ _transform(chunk, _encoding, cb) {
329
+ if (this.state === 'passthrough') {
330
+ this.push(chunk);
331
+ cb();
332
+ return;
333
+ }
334
+ if (this.state === 'scanning') {
335
+ const combined = Buffer.concat([this.scanBuf, chunk]);
336
+ const idx = combined.indexOf(MAPPINGS_KEY_BUF);
337
+ if (idx === -1) {
338
+ // Key not yet found – hold back enough bytes to handle a split key.
339
+ const keepLen = Math.min(combined.length, MAPPINGS_KEY_BUF.length - 1);
340
+ if (combined.length > keepLen) {
341
+ this.push(combined.slice(0, combined.length - keepLen));
342
+ }
343
+ this.scanBuf = combined.slice(combined.length - keepLen);
344
+ cb();
345
+ return;
346
+ }
347
+
348
+ // Emit everything up to and including the key.
349
+ const keyEnd = idx + MAPPINGS_KEY_BUF.length;
350
+ this.push(combined.slice(0, keyEnd));
351
+ this.scanBuf = Buffer.alloc(0);
352
+ this.state = 'buffering';
353
+ this._bufferingTransform(combined.slice(keyEnd), cb);
354
+ return;
355
+ }
356
+
357
+ // state === 'buffering'
358
+ this._bufferingTransform(chunk, cb);
359
+ }
360
+
361
+ // @ts-expect-error TS7006
362
+ _bufferingTransform(chunk, cb) {
363
+ // Mappings values contain only base64 chars, ';', and ',' – no escaping –
364
+ // so scanning for the closing '"' (0x22) is safe.
365
+ const closeIdx = chunk.indexOf(0x22);
366
+ if (closeIdx === -1) {
367
+ this.mappingsBufs.push(chunk);
368
+ cb();
369
+ return;
370
+ }
371
+ this.mappingsBufs.push(chunk.slice(0, closeIdx));
372
+
373
+ // VLQ chars are all ASCII (<128), so latin1 round-trips without loss.
374
+ const mappingsStr = Buffer.concat(this.mappingsBufs).toString('latin1');
375
+ const rewritten = applyReplacementsToVLQMappings(mappingsStr, this.replacements);
376
+ this.push(Buffer.from(rewritten, 'latin1'));
377
+
378
+ // Emit the closing '"' and everything remaining in one push.
379
+ this.push(chunk.slice(closeIdx));
380
+ this.state = 'passthrough';
381
+ this.mappingsBufs = [];
382
+ cb();
383
+ }
384
+
385
+ // @ts-expect-error TS7006
386
+ _flush(cb) {
387
+ if (this.state === 'scanning' && this.scanBuf.length > 0) {
388
+ this.push(this.scanBuf);
389
+ } else if (this.state === 'buffering') {
390
+ // Malformed JSON – flush whatever we buffered as-is.
391
+ this.push(Buffer.concat(this.mappingsBufs));
392
+ }
393
+ cb();
394
+ }
395
+ }
396
+
397
+ /**
398
+ * Computes the sourceRoot for a source map file. This is the relative path from
399
+ * the output directory back to the project root, so that source paths (stored
400
+ * relative to projectRoot) resolve correctly from the .map file location.
401
+ *
402
+ * Returns undefined when sources are inlined (inlineSources), since the browser
403
+ * doesn't need to fetch them and sourceRoot would be unnecessary.
404
+ *
405
+ * This logic must stay in sync with PackagerRunner.generateSourceMap.
406
+ */
407
+ exports.SourceMapHashRefRewriteStream = SourceMapHashRefRewriteStream;
408
+ function computeSourceMapRoot(bundle, options) {
409
+ let name = (0, _nullthrows().default)(bundle.name);
410
+ let filePath = (0, _projectPath.joinProjectPath)(bundle.target.distDir, name);
411
+ let fullPath = (0, _projectPath.fromProjectPath)(options.projectRoot, filePath);
412
+ let sourceRoot = _path().default.relative(_path().default.dirname(fullPath), options.projectRoot);
413
+ let inlineSources = false;
414
+ const bundleEnv = (0, _EnvironmentManager.fromEnvironmentId)(bundle.env);
415
+ if (bundle.target) {
416
+ const bundleTargetEnv = (0, _EnvironmentManager.fromEnvironmentId)(bundle.target.env);
417
+ if (bundleEnv.sourceMap && bundleEnv.sourceMap.sourceRoot !== undefined) {
418
+ sourceRoot = bundleEnv.sourceMap.sourceRoot;
419
+ } else if (options.serveOptions && bundleTargetEnv.context === 'browser') {
420
+ sourceRoot = '/__parcel_source_root';
421
+ }
422
+ if (bundleEnv.sourceMap && bundleEnv.sourceMap.inlineSources !== undefined) {
423
+ inlineSources = bundleEnv.sourceMap.inlineSources;
424
+ } else if (bundleTargetEnv.context !== 'node') {
425
+ inlineSources = options.mode === 'production';
426
+ }
427
+ }
428
+ let isInlineMap = bundleEnv.sourceMap && bundleEnv.sourceMap.inline;
429
+ if ((0, _featureFlags().getFeatureFlag)('omitSourcesContentInMemory') && !isInlineMap) {
430
+ if (!(bundleEnv.sourceMap && bundleEnv.sourceMap.inlineSources === false)) {
431
+ inlineSources = true;
432
+ }
433
+ }
434
+ if (inlineSources) {
435
+ return undefined;
436
+ }
437
+ return _url().default.format(_url().default.parse(sourceRoot + '/'));
438
+ }
439
+ async function writeFiles(
440
+ // @ts-expect-error TS2503
441
+ inputStream, info, hashRefToNameHash, options, config, outputFS, filePath, writeOptions, devDeps, api, bundleReplacements) {
172
442
  let compressors = await config.getCompressors((0, _projectPath.fromProjectPathRelative)(filePath));
173
443
  let fullPath = (0, _projectPath.fromProjectPath)(options.projectRoot, filePath);
174
- let stream = info.hashReferences.length ? inputStream.pipe(replaceStream(hashRefToNameHash)) : inputStream;
444
+ let stream = info.hashReferences.length ? inputStream.pipe(replaceStream(hashRefToNameHash, bundleReplacements)) : inputStream;
175
445
  let promises = [];
176
446
  for (let compressor of compressors) {
177
- promises.push(runCompressor(compressor, cloneStream(stream), options, outputFS, fullPath, writeOptions, devDeps, api));
447
+ promises.push(
448
+ // @ts-expect-error TS2345
449
+ runCompressor(compressor, cloneStream(stream), options, outputFS, fullPath, writeOptions, devDeps, api));
178
450
  }
179
451
  await Promise.all(promises);
180
452
  }
181
- async function runCompressor(compressor, stream, options, outputFS, filePath, writeOptions, devDeps, api) {
453
+ async function runCompressor(compressor,
454
+ // @ts-expect-error TS2503
455
+ stream, options, outputFS, filePath, writeOptions, devDeps, api) {
182
456
  let measurement;
183
457
  try {
184
458
  measurement = _profiler().tracer.createMeasurement(compressor.name, 'compress', _path().default.relative(options.projectRoot, filePath));
@@ -195,7 +469,9 @@ async function runCompressor(compressor, stream, options, outputFS, filePath, wr
195
469
  });
196
470
  if (res != null) {
197
471
  await new Promise((resolve, reject) => (0, _stream().pipeline)(res.stream, outputFS.createWriteStream(filePath + (res.type != null ? '.' + res.type : ''), writeOptions), err => {
198
- if (err) reject(err);else resolve();
472
+ if (err) reject(err);
473
+ // @ts-expect-error TS2794
474
+ else resolve();
199
475
  }));
200
476
  }
201
477
  } catch (err) {
@@ -214,9 +490,25 @@ async function runCompressor(compressor, stream, options, outputFS, filePath, wr
214
490
  await (0, _DevDepRequest.runDevDepRequest)(api, devDepRequest);
215
491
  }
216
492
  }
217
- function replaceStream(hashRefToNameHash) {
493
+ function advanceLineColumn(line, column, buf) {
494
+ for (let i = 0; i < buf.length; i++) {
495
+ if (buf[i] === 0x0a) {
496
+ line++;
497
+ column = 0;
498
+ } else {
499
+ column++;
500
+ }
501
+ }
502
+ return {
503
+ line,
504
+ column
505
+ };
506
+ }
507
+ function replaceStream(hashRefToNameHash, replacements) {
218
508
  let boundaryStr = Buffer.alloc(0);
219
509
  let replaced = Buffer.alloc(0);
510
+ let outputLine = 0;
511
+ let outputColumn = 0;
220
512
  return new (_stream().Transform)({
221
513
  transform(chunk, encoding, cb) {
222
514
  let str = Buffer.concat([boundaryStr, Buffer.from(chunk)]);
@@ -234,15 +526,29 @@ function replaceStream(hashRefToNameHash) {
234
526
  } else {
235
527
  let match = str.subarray(matchI, matchI + HASH_REF_PREFIX_LEN + _constants.HASH_REF_HASH_LEN).toString();
236
528
  let replacement = Buffer.from(hashRefToNameHash.get(match) ?? match);
529
+ // Copy pre-match content FIRST so position calculation includes it
237
530
  replaced.set(str.subarray(lastMatchI, matchI), replacedLength);
238
531
  replacedLength += matchI - lastMatchI;
532
+ if (replacements) {
533
+ const pos = advanceLineColumn(outputLine, outputColumn, replaced.subarray(0, replacedLength));
534
+ replacements.push({
535
+ line: pos.line,
536
+ column: pos.column,
537
+ originalLength: HASH_REF_PLACEHOLDER_LEN,
538
+ newLength: replacement.byteLength
539
+ });
540
+ }
239
541
  replaced.set(replacement, replacedLength);
240
542
  replacedLength += replacement.byteLength;
241
543
  lastMatchI = matchI + HASH_REF_PREFIX_LEN + _constants.HASH_REF_HASH_LEN;
242
544
  }
243
545
  }
546
+ const pushLen = replacedLength - BOUNDARY_LENGTH;
547
+ const pushed = advanceLineColumn(outputLine, outputColumn, replaced.subarray(0, pushLen));
548
+ outputLine = pushed.line;
549
+ outputColumn = pushed.column;
244
550
  boundaryStr = replaced.subarray(replacedLength - BOUNDARY_LENGTH, replacedLength);
245
- let strUpToBoundary = replaced.subarray(0, replacedLength - BOUNDARY_LENGTH);
551
+ let strUpToBoundary = replaced.subarray(0, pushLen);
246
552
  cb(null, strUpToBoundary);
247
553
  },
248
554
  flush(cb) {
@@ -250,12 +556,15 @@ function replaceStream(hashRefToNameHash) {
250
556
  }
251
557
  });
252
558
  }
559
+
560
+ // @ts-expect-error TS2503
253
561
  function cloneStream(readable) {
254
562
  let res = new (_stream().Readable)();
255
- // $FlowFixMe
256
563
  res._read = () => {};
564
+ // @ts-expect-error TS7006
257
565
  readable.on('data', chunk => res.push(chunk));
258
566
  readable.on('end', () => res.push(null));
567
+ // @ts-expect-error TS7006
259
568
  readable.on('error', err => res.emit('error', err));
260
569
  return res;
261
570
  }
@@ -12,6 +12,8 @@ function _featureFlags() {
12
12
  return data;
13
13
  }
14
14
  var _RequestTracker = require("../RequestTracker");
15
+ var _types = require("../types");
16
+ var _ReporterRunner = require("../ReporterRunner");
15
17
  var _constants = require("../constants");
16
18
  var _projectPath = require("../projectPath");
17
19
  function _nullthrows() {
@@ -30,7 +32,33 @@ function _rust() {
30
32
  }
31
33
  var _PackageRequest = require("./PackageRequest");
32
34
  var _WriteBundleRequest = _interopRequireDefault(require("./WriteBundleRequest"));
33
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
35
+ function _utils() {
36
+ const data = require("@atlaspack/utils");
37
+ _utils = function () {
38
+ return data;
39
+ };
40
+ return data;
41
+ }
42
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
43
+ /** Length of the hash suffix in output filenames (e.g. .runtime.13dc01ac.js). */
44
+ const NAME_HASH_DISPLAY_LEN = 8;
45
+
46
+ /** Use at most NAME_HASH_DISPLAY_LEN chars for the name hash so filenames stay short. */
47
+ function nameHashForFilename(hash) {
48
+ return hash.length <= NAME_HASH_DISPLAY_LEN ? hash : hash.slice(-NAME_HASH_DISPLAY_LEN);
49
+ }
50
+ function reportPackagingProgress(completeBundles, totalBundles) {
51
+ if (!(0, _featureFlags().getFeatureFlag)('cliProgressReportingImprovements')) {
52
+ return;
53
+ }
54
+ (0, _ReporterRunner.report)({
55
+ type: 'buildProgress',
56
+ phase: 'packagingAndOptimizing',
57
+ totalBundles,
58
+ completeBundles
59
+ });
60
+ }
61
+
34
62
  /**
35
63
  * Packages, optimizes, and writes all bundles to the dist directory.
36
64
  */
@@ -67,15 +95,16 @@ async function run({
67
95
  const allBundles = bundleGraph.getBundles({
68
96
  includeInline: (0, _featureFlags().getFeatureFlag)('inlineBundlesSourceMapFixes')
69
97
  });
70
- const bundles = allBundles.filter(bundle => bundle.bundleBehavior !== 'inline').filter(bundle => {
98
+ const bundles = allBundles.filter(bundle => bundle.bundleBehavior !== _types.BundleBehavior.inline && bundle.bundleBehavior !== _types.BundleBehavior.inlineIsolated).filter(bundle => {
71
99
  // Do not package and write placeholder bundles to disk. We just
72
100
  // need to update the name so other bundles can reference it.
73
101
  if (bundle.isPlaceholder) {
74
- let hash = bundle.id.slice(-8);
75
- hashRefToNameHash.set(bundle.hashReference, hash);
76
- let name = (0, _nullthrows().default)(bundle.name, `Expected ${bundle.type} bundle to have a name`).replace(bundle.hashReference, hash);
102
+ const nameHash = nameHashForFilename(bundle.id);
103
+ hashRefToNameHash.set(bundle.hashReference, nameHash);
104
+ let name = (0, _nullthrows().default)(bundle.name, `Expected ${bundle.type} bundle to have a name`).replace(bundle.hashReference, nameHash);
77
105
  res.set(bundle.id, {
78
106
  filePath: (0, _projectPath.joinProjectPath)(bundle.target.distDir, name),
107
+ bundleId: bundle.id,
79
108
  type: bundle.type,
80
109
  // FIXME: this is wrong if the packager changes the type...
81
110
  stats: {
@@ -87,11 +116,14 @@ async function run({
87
116
  }
88
117
  return true;
89
118
  });
119
+ let cachedBundles = new Set(bundles.filter(b => api.canSkipSubrequest(bundleGraph.getHash(b))));
90
120
 
91
121
  // Package on the main thread if there is only one bundle to package.
92
122
  // This avoids the cost of serializing the bundle graph for single file change builds.
93
- let useMainThread = bundles.length === 1 || bundles.filter(b => !api.canSkipSubrequest(bundleGraph.getHash(b))).length === 1;
123
+ let useMainThread = bundles.length === 1 || bundles.length - cachedBundles.size <= 1;
94
124
  try {
125
+ let completeBundles = cachedBundles.size;
126
+ reportPackagingProgress(completeBundles, bundles.length);
95
127
  await Promise.all(bundles.map(async bundle => {
96
128
  let request = (0, _PackageRequest.createPackageRequest)({
97
129
  bundle,
@@ -101,6 +133,10 @@ async function run({
101
133
  useMainThread
102
134
  });
103
135
  let info = await api.runRequest(request);
136
+ if (!cachedBundles.has(bundle)) {
137
+ completeBundles++;
138
+ reportPackagingProgress(completeBundles, bundles.length);
139
+ }
104
140
  if (!useMainThread) {
105
141
  // Force a refresh of the cache to avoid a race condition
106
142
  // between threaded reads and writes that can result in an LMDB cache miss:
@@ -114,7 +150,7 @@ async function run({
114
150
  }
115
151
  bundleInfoMap[bundle.id] = info;
116
152
  if (!info.hashReferences.length) {
117
- hashRefToNameHash.set(bundle.hashReference, options.shouldContentHash ? info.hash.slice(-8) : bundle.id.slice(-8));
153
+ hashRefToNameHash.set(bundle.hashReference, nameHashForFilename(options.shouldContentHash ? info.hash : bundle.id));
118
154
  let writeBundleRequest = (0, _WriteBundleRequest.default)({
119
155
  bundle,
120
156
  info,
@@ -137,8 +173,26 @@ async function run({
137
173
  }));
138
174
  return promise.then(r => res.set(bundle.id, r));
139
175
  }));
140
- api.storeResult(res);
141
- return res;
176
+ let result = {
177
+ bundleInfo: res
178
+ };
179
+ if (_utils().debugTools['scope-hoisting-stats']) {
180
+ // Aggregate scope hoisting stats from all bundles
181
+ let aggregatedScopeHoistingStats = {
182
+ totalAssets: 0,
183
+ wrappedAssets: 0
184
+ };
185
+ for (let bundle of bundles) {
186
+ let bundleInfo = bundleInfoMap[bundle.id];
187
+ if (bundleInfo !== null && bundleInfo !== void 0 && bundleInfo.scopeHoistingStats) {
188
+ aggregatedScopeHoistingStats.totalAssets += bundleInfo.scopeHoistingStats.totalAssets;
189
+ aggregatedScopeHoistingStats.wrappedAssets += bundleInfo.scopeHoistingStats.wrappedAssets;
190
+ }
191
+ }
192
+ result.scopeHoistingStats = aggregatedScopeHoistingStats;
193
+ }
194
+ api.storeResult(result);
195
+ return result;
142
196
  } finally {
143
197
  await dispose();
144
198
  }
@@ -148,7 +202,7 @@ function assignComplexNameHashes(hashRefToNameHash, bundles, bundleInfoMap, opti
148
202
  if (hashRefToNameHash.get(bundle.hashReference) != null) {
149
203
  continue;
150
204
  }
151
- hashRefToNameHash.set(bundle.hashReference, options.shouldContentHash ? (0, _rust().hashString)([...getBundlesIncludedInHash(bundle.id, bundleInfoMap)].map(bundleId => bundleInfoMap[bundleId].hash).join(':')).slice(-8) : bundle.id.slice(-8));
205
+ hashRefToNameHash.set(bundle.hashReference, nameHashForFilename(options.shouldContentHash ? (0, _rust().hashString)([...getBundlesIncludedInHash(bundle.id, bundleInfoMap)].map(bundleId => bundleInfoMap[bundleId].hash).join(':')) : bundle.id));
152
206
  }
153
207
  }
154
208
  function getBundlesIncludedInHash(bundleId, bundleInfoMap, included = new Set()) {
@@ -14,11 +14,11 @@ function _jestDiff() {
14
14
  };
15
15
  return data;
16
16
  }
17
- var _AssetGraph = _interopRequireDefault(require("../AssetGraph"));
18
17
  var _projectPath = require("../projectPath");
19
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
20
- /* eslint-disable no-console */ // $FlowFixMe
21
- // $FlowFixMe
18
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
19
+ /* eslint-disable no-console */
20
+ // @ts-expect-error missing types
21
+
22
22
  function filterNode(node) {
23
23
  let clone = (0, _default().default)(node);
24
24
 
@@ -43,6 +43,8 @@ function filterNode(node) {
43
43
  delete clone.value.dependencies;
44
44
  return clone;
45
45
  }
46
+
47
+ // @ts-expect-error missing return type
46
48
  function compactDeep(obj, ignoredPatterns = [], currentPath = '$') {
47
49
  if (obj instanceof Map) {
48
50
  const copy = {};
@@ -53,6 +55,7 @@ function compactDeep(obj, ignoredPatterns = [], currentPath = '$') {
53
55
  });
54
56
  return copy;
55
57
  } else if (Array.isArray(obj)) {
58
+ // @ts-expect-error implicit any
56
59
  return obj.map(v => compactDeep(v, ignoredPatterns, `${currentPath}[]`));
57
60
  } else if (typeof obj === 'object') {
58
61
  const copy = {};
@@ -74,17 +77,19 @@ function compactDeep(obj, ignoredPatterns = [], currentPath = '$') {
74
77
  return obj;
75
78
  }
76
79
  }
77
- function assetGraphDiff(jsAssetGraph, rustAssetGraph) {
80
+ function assetGraphDiff(jsAssetGraph, rustAssetGraph, projectRoot) {
78
81
  const getNodes = graph => {
79
82
  let nodes = {};
83
+
84
+ // @ts-expect-error implicit any
80
85
  graph.traverse(nodeId => {
81
86
  let node = graph.getNode(nodeId) ?? null;
82
87
  if (!node) return;
83
88
  if (node.type === 'dependency') {
84
- let sourcePath = node.value.sourcePath ?? (0, _projectPath.toProjectPath)('', 'entry');
85
- nodes[`dep:${(0, _projectPath.fromProjectPathRelative)(sourcePath)}:${node.value.specifier}`] = filterNode(node);
89
+ let sourcePath = node.value.sourcePath ? (0, _projectPath.toProjectPath)(projectRoot, node.value.sourcePath) : (0, _projectPath.toProjectPath)(projectRoot, 'entry');
90
+ nodes[`dep:${sourcePath}:${node.value.specifier}`] = filterNode(node);
86
91
  } else if (node.type === 'asset') {
87
- nodes[`asset:${(0, _projectPath.fromProjectPathRelative)(node.value.filePath)}`] = filterNode(node);
92
+ nodes[`asset:${(0, _projectPath.toProjectPath)(projectRoot, node.value.filePath)}`] = filterNode(node);
88
93
  }
89
94
  });
90
95
  return nodes;