@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
@@ -6,9 +6,13 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.RequestGraph = void 0;
7
7
  exports.cleanUpOrphans = cleanUpOrphans;
8
8
  exports.default = void 0;
9
+ exports.getBiggestFSEventsInvalidations = getBiggestFSEventsInvalidations;
9
10
  exports.getWatcherOptions = getWatcherOptions;
11
+ exports.invalidateRequestGraph = invalidateRequestGraph;
12
+ exports.invalidateRequestGraphFSEvents = invalidateRequestGraphFSEvents;
10
13
  exports.readAndDeserializeRequestGraph = readAndDeserializeRequestGraph;
11
14
  exports.requestTypes = exports.requestGraphEdgeTypes = void 0;
15
+ exports.runInvalidation = runInvalidation;
12
16
  function _assert() {
13
17
  const data = _interopRequireWildcard(require("assert"));
14
18
  _assert = function () {
@@ -30,13 +34,6 @@ function _buildCache() {
30
34
  };
31
35
  return data;
32
36
  }
33
- function _cache() {
34
- const data = require("@atlaspack/cache");
35
- _cache = function () {
36
- return data;
37
- };
38
- return data;
39
- }
40
37
  function _featureFlags() {
41
38
  const data = require("@atlaspack/feature-flags");
42
39
  _featureFlags = function () {
@@ -52,7 +49,7 @@ function _graph() {
52
49
  return data;
53
50
  }
54
51
  function _logger() {
55
- const data = _interopRequireWildcard(require("@atlaspack/logger"));
52
+ const data = _interopRequireDefault(require("@atlaspack/logger"));
56
53
  _logger = function () {
57
54
  return data;
58
55
  };
@@ -84,9 +81,16 @@ var _projectPath = require("./projectPath");
84
81
  var _ReporterRunner = require("./ReporterRunner");
85
82
  var _ConfigRequest = require("./requests/ConfigRequest");
86
83
  var _utils2 = require("./utils");
87
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
88
- 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); }
89
- 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; }
84
+ function _perf_hooks() {
85
+ const data = require("perf_hooks");
86
+ _perf_hooks = function () {
87
+ return data;
88
+ };
89
+ return data;
90
+ }
91
+ var _EnvironmentManager = require("./EnvironmentManager");
92
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
93
+ 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
94
  const requestGraphEdgeTypes = exports.requestGraphEdgeTypes = {
91
95
  subrequest: 2,
92
96
  invalidated_by_update: 3,
@@ -151,7 +155,7 @@ const nodeFromOption = (option, value) => ({
151
155
  hash: (0, _utils2.hashFromOption)(value)
152
156
  });
153
157
  const nodeFromConfigKey = (fileName, configKey, contentHash) => ({
154
- id: `config_key:${(0, _projectPath.fromProjectPathRelative)(fileName)}:${configKey}`,
158
+ id: `config_key:${(0, _projectPath.fromProjectPathRelative)(fileName)}:${JSON.stringify(configKey)}`,
155
159
  type: CONFIG_KEY,
156
160
  configKey,
157
161
  contentHash
@@ -162,6 +166,8 @@ const keyFromOptionContentKey = contentKey => contentKey.slice('option:'.length)
162
166
  // This constant is chosen by local profiling the time to serialise n nodes and tuning until an average time of ~50 ms per blob.
163
167
  // The goal is to free up the event loop periodically to allow interruption by the user.
164
168
  const NODES_PER_BLOB = 2 ** 14;
169
+
170
+ // @ts-expect-error TS2417
165
171
  class RequestGraph extends _graph().ContentGraph {
166
172
  invalidNodeIds = new Set();
167
173
  incompleteNodeIds = new Set();
@@ -176,10 +182,7 @@ class RequestGraph extends _graph().ContentGraph {
176
182
  cachedRequestChunks = new Set();
177
183
  configKeyNodes = new Map();
178
184
  nodesPerBlob = NODES_PER_BLOB;
179
-
180
- // $FlowFixMe[prop-missing]
181
185
  static deserialize(opts) {
182
- // $FlowFixMe[prop-missing]
183
186
  let deserialized = new RequestGraph(opts);
184
187
  deserialized.invalidNodeIds = opts.invalidNodeIds;
185
188
  deserialized.incompleteNodeIds = opts.incompleteNodeIds;
@@ -192,8 +195,6 @@ class RequestGraph extends _graph().ContentGraph {
192
195
  deserialized.configKeyNodes = opts.configKeyNodes;
193
196
  return deserialized;
194
197
  }
195
-
196
- // $FlowFixMe[prop-missing]
197
198
  serialize() {
198
199
  return {
199
200
  ...super.serialize(),
@@ -333,6 +334,8 @@ class RequestGraph extends _graph().ContentGraph {
333
334
  let node = (0, _nullthrows().default)(this.getNode(nodeId));
334
335
  (0, _assert().default)(node.type === OPTION);
335
336
  const key = keyFromOptionContentKey(node.id);
337
+
338
+ // @ts-expect-error TS7053
336
339
  if ((0, _utils2.hashFromOption)(options[key]) !== node.hash) {
337
340
  invalidatedKeys.push(key);
338
341
  let parentNodes = this.getNodeIdsConnectedTo(nodeId, requestGraphEdgeTypes.invalidated_by_update);
@@ -371,9 +374,13 @@ class RequestGraph extends _graph().ContentGraph {
371
374
  }
372
375
  invalidateOnFileCreate(requestNodeId, input) {
373
376
  let node;
377
+ // @ts-expect-error TS2339
374
378
  if (input.glob != null) {
379
+ // @ts-expect-error TS2339
375
380
  node = nodeFromGlob(input.glob);
381
+ // @ts-expect-error TS2339
376
382
  } else if (input.fileName != null && input.aboveFilePath != null) {
383
+ // @ts-expect-error TS2339
377
384
  let aboveFilePath = input.aboveFilePath;
378
385
 
379
386
  // Create nodes and edges for each part of the filename pattern.
@@ -381,6 +388,7 @@ class RequestGraph extends _graph().ContentGraph {
381
388
  // This creates a sort of trie structure within the graph that can be
382
389
  // quickly matched by following the edges. This is also memory efficient
383
390
  // since common sub-paths (e.g. 'node_modules') are deduplicated.
391
+ // @ts-expect-error TS2339
384
392
  let parts = input.fileName.split('/').reverse();
385
393
  let lastNodeId;
386
394
  for (let part of parts) {
@@ -415,7 +423,9 @@ class RequestGraph extends _graph().ContentGraph {
415
423
  if (!this.hasEdge(lastNodeId, nodeId, requestGraphEdgeTypes.invalidated_by_create_above)) {
416
424
  this.addEdge(lastNodeId, nodeId, requestGraphEdgeTypes.invalidated_by_create_above);
417
425
  }
426
+ // @ts-expect-error TS2339
418
427
  } else if (input.filePath != null) {
428
+ // @ts-expect-error TS2339
419
429
  node = nodeFromFilePath(input.filePath);
420
430
  } else {
421
431
  throw new Error('Invalid invalidation');
@@ -434,8 +444,8 @@ class RequestGraph extends _graph().ContentGraph {
434
444
  this.invalidateOnBuildNodeIds.add(requestNodeId);
435
445
  }
436
446
  invalidateOnEnvChange(requestNodeId, env, value) {
437
- let envNode = nodeFromEnv(env, value);
438
- let envNodeId = this.addNode(envNode);
447
+ const envNode = nodeFromEnv(env, value);
448
+ const envNodeId = this.addNode(envNode);
439
449
  if (!this.hasEdge(requestNodeId, envNodeId, requestGraphEdgeTypes.invalidated_by_update)) {
440
450
  this.addEdge(requestNodeId, envNodeId, requestGraphEdgeTypes.invalidated_by_update);
441
451
  }
@@ -461,6 +471,7 @@ class RequestGraph extends _graph().ContentGraph {
461
471
 
462
472
  // For now just handling updates. Could add creates/deletes later if needed.
463
473
  let invalidations = this.getNodeIdsConnectedFrom(requestNodeId, requestGraphEdgeTypes.invalidated_by_update);
474
+ // @ts-expect-error TS2322
464
475
  return invalidations.map(nodeId => {
465
476
  let node = (0, _nullthrows().default)(this.getNode(nodeId));
466
477
  switch (node.type) {
@@ -582,10 +593,12 @@ class RequestGraph extends _graph().ContentGraph {
582
593
  aboveCache.set(fileNameNodeId, above);
583
594
  return above;
584
595
  };
596
+ const invalidationsByPath = new Map();
585
597
  for (let {
586
598
  path: _path,
587
599
  type
588
600
  } of events) {
601
+ const invalidationsBefore = this.getInvalidNodeCount();
589
602
  if (!enableOptimization && process.env.ATLASPACK_DISABLE_CACHE_TIMEOUT !== 'true' && ++count === 256) {
590
603
  let duration = Date.now() - startTime;
591
604
  predictedTime = duration * (events.length >> 8);
@@ -622,7 +635,10 @@ class RequestGraph extends _graph().ContentGraph {
622
635
  this.invalidNodeIds.add(id);
623
636
  }
624
637
  }
625
- return true;
638
+ return {
639
+ didInvalidate: true,
640
+ invalidationsByPath: new Map()
641
+ };
626
642
  }
627
643
 
628
644
  // sometimes mac os reports update events as create events.
@@ -679,10 +695,17 @@ class RequestGraph extends _graph().ContentGraph {
679
695
  this.removeNode(nodeId, removeOrphans);
680
696
  }
681
697
  let configKeyNodes = this.configKeyNodes.get(_filePath);
682
- if (configKeyNodes && (type === 'delete' || type === 'update')) {
698
+
699
+ // With granular invalidations we will always run this block,
700
+ // so even if we get a create event (for whatever reason), we will still
701
+ // try to limit invalidations from config key changes through hashing.
702
+ //
703
+ // Currently create events can invalidate a large number of nodes due to
704
+ // "create above" invalidations.
705
+ if (configKeyNodes) {
683
706
  for (let nodeId of configKeyNodes) {
684
707
  let isInvalid = type === 'delete';
685
- if (type === 'update') {
708
+ if (type !== 'delete') {
686
709
  let node = this.getNode(nodeId);
687
710
  (0, _assert().default)(node && node.type === CONFIG_KEY);
688
711
  let contentHash = await (0, _ConfigRequest.getConfigKeyContentHash)(_filePath, node.configKey, options);
@@ -697,6 +720,9 @@ class RequestGraph extends _graph().ContentGraph {
697
720
  }
698
721
  }
699
722
  }
723
+ const invalidationsAfter = this.getInvalidNodeCount();
724
+ const invalidationsForEvent = invalidationsAfter - invalidationsBefore;
725
+ invalidationsByPath.set(_path, (invalidationsByPath.get(_path) ?? 0) + invalidationsForEvent);
700
726
  }
701
727
  if ((0, _featureFlags().getFeatureFlag)('fixQuadraticCacheInvalidation')) {
702
728
  cleanUpOrphans(this);
@@ -714,7 +740,10 @@ class RequestGraph extends _graph().ContentGraph {
714
740
  numberOfInvalidatedNodes: invalidatedNodes.size
715
741
  }
716
742
  });
717
- return didInvalidate && this.invalidNodeIds.size > 0;
743
+ return {
744
+ didInvalidate,
745
+ invalidationsByPath
746
+ };
718
747
  }
719
748
  hasCachedRequestChunk(index) {
720
749
  return this.cachedRequestChunks.has(index);
@@ -725,6 +754,13 @@ class RequestGraph extends _graph().ContentGraph {
725
754
  removeCachedRequestChunkForNode(nodeId) {
726
755
  this.cachedRequestChunks.delete(Math.floor(nodeId / this.nodesPerBlob));
727
756
  }
757
+
758
+ /**
759
+ * Returns the number of invalidated nodes in the graph.
760
+ */
761
+ getInvalidNodeCount() {
762
+ return this.invalidNodeIds.size;
763
+ }
728
764
  }
729
765
  exports.RequestGraph = RequestGraph;
730
766
  class RequestTracker {
@@ -740,11 +776,6 @@ class RequestTracker {
740
776
  this.options = options;
741
777
  this.rustAtlaspack = rustAtlaspack;
742
778
  }
743
-
744
- // TODO: refactor (abortcontroller should be created by RequestTracker)
745
- setSignal(signal) {
746
- this.signal = signal;
747
- }
748
779
  startRequest(request) {
749
780
  let didPreviouslyExist = this.graph.hasContentKey(request.id);
750
781
  let requestNodeId;
@@ -762,6 +793,7 @@ class RequestTracker {
762
793
  promise,
763
794
  deferred
764
795
  } = (0, _utils().makeDeferredWithPromise)();
796
+ // @ts-expect-error TS2345
765
797
  this.graph.incompleteNodePromises.set(requestNodeId, promise);
766
798
  return {
767
799
  requestNodeId,
@@ -787,15 +819,12 @@ class RequestTracker {
787
819
  return null;
788
820
  }
789
821
  if (node.result != undefined) {
790
- // $FlowFixMe
791
822
  let result = node.result;
792
823
  return result;
793
824
  } else if (node.resultCacheKey != null && ifMatch == null) {
794
825
  let key = node.resultCacheKey;
795
- if (!(0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements')) {
796
- (0, _assert().default)(this.options.cache.hasLargeBlob(key));
797
- }
798
- let cachedResult = (0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements') ? (0, _nullthrows().default)(await this.options.cache.get(key)) : (0, _buildCache().deserialize)(await this.options.cache.getLargeBlob(key));
826
+ (0, _assert().default)(this.options.cache.hasLargeBlob(key));
827
+ let cachedResult = (0, _buildCache().deserialize)(await this.options.cache.getLargeBlob(key));
799
828
  node.result = cachedResult;
800
829
  return cachedResult;
801
830
  }
@@ -841,7 +870,7 @@ class RequestTracker {
841
870
  let requestId = hasKey ? this.graph.getNodeIdByContentKey(request.id) : undefined;
842
871
  let hasValidResult = requestId != null && this.hasValidResult(requestId);
843
872
  if (!(opts !== null && opts !== void 0 && opts.force) && hasValidResult) {
844
- // $FlowFixMe[incompatible-type]
873
+ // @ts-expect-error TS2322
845
874
  return this.getRequestResult(request.id);
846
875
  }
847
876
  if (requestId != null) {
@@ -850,7 +879,7 @@ class RequestTracker {
850
879
  // There is a another instance of this request already running, wait for its completion and reuse its result
851
880
  try {
852
881
  if (await incompletePromise) {
853
- // $FlowFixMe[incompatible-type]
882
+ // @ts-expect-error TS2322
854
883
  return this.getRequestResult(request.id);
855
884
  }
856
885
  } catch (e) {
@@ -883,7 +912,6 @@ class RequestTracker {
883
912
  options: this.options,
884
913
  rustAtlaspack: this.rustAtlaspack
885
914
  });
886
- (0, _utils2.assertSignalNotAborted)(this.signal);
887
915
  this.completeRequest(requestNodeId);
888
916
  deferred.resolve(true);
889
917
  return result;
@@ -921,65 +949,56 @@ class RequestTracker {
921
949
  }
922
950
  createAPI(requestId, previousInvalidations) {
923
951
  let subRequestContentKeys = new Set();
924
- return {
925
- api: {
926
- invalidateOnFileCreate: input => this.graph.invalidateOnFileCreate(requestId, input),
927
- invalidateOnConfigKeyChange: (filePath, configKey, contentHash) => this.graph.invalidateOnConfigKeyChange(requestId, filePath, configKey, contentHash),
928
- invalidateOnFileDelete: filePath => this.graph.invalidateOnFileDelete(requestId, filePath),
929
- invalidateOnFileUpdate: filePath => this.graph.invalidateOnFileUpdate(requestId, filePath),
930
- invalidateOnStartup: () => this.graph.invalidateOnStartup(requestId),
931
- invalidateOnBuild: () => this.graph.invalidateOnBuild(requestId),
932
- invalidateOnEnvChange: env => this.graph.invalidateOnEnvChange(requestId, env, this.options.env[env]),
933
- invalidateOnOptionChange: option => this.graph.invalidateOnOptionChange(requestId, option, this.options[option]),
934
- getInvalidations: () => previousInvalidations,
935
- storeResult: (result, cacheKey) => {
936
- this.storeResult(requestId, result, cacheKey);
937
- },
938
- getSubRequests: () => this.graph.getSubRequests(requestId),
939
- getInvalidSubRequests: () => this.graph.getInvalidSubRequests(requestId),
940
- getPreviousResult: ifMatch => {
941
- var _this$graph$getNode;
942
- let contentKey = (0, _nullthrows().default)((_this$graph$getNode = this.graph.getNode(requestId)) === null || _this$graph$getNode === void 0 ? void 0 : _this$graph$getNode.id);
943
- return this.getRequestResult(contentKey, ifMatch);
944
- },
945
- getRequestResult: id => this.getRequestResult(id),
946
- canSkipSubrequest: contentKey => {
947
- if (this.graph.hasContentKey(contentKey) && this.hasValidResult(this.graph.getNodeIdByContentKey(contentKey))) {
948
- subRequestContentKeys.add(contentKey);
949
- return true;
950
- }
951
- return false;
952
- },
953
- runRequest: (subRequest, opts) => {
954
- subRequestContentKeys.add(subRequest.id);
955
- return this.runRequest(subRequest, opts);
952
+ let api = {
953
+ invalidateOnFileCreate: input => this.graph.invalidateOnFileCreate(requestId, input),
954
+ invalidateOnConfigKeyChange: (filePath, configKey, contentHash) => this.graph.invalidateOnConfigKeyChange(requestId, filePath, configKey, contentHash),
955
+ invalidateOnFileDelete: filePath => this.graph.invalidateOnFileDelete(requestId, filePath),
956
+ invalidateOnFileUpdate: filePath => this.graph.invalidateOnFileUpdate(requestId, filePath),
957
+ invalidateOnStartup: () => this.graph.invalidateOnStartup(requestId),
958
+ invalidateOnBuild: () => this.graph.invalidateOnBuild(requestId),
959
+ invalidateOnEnvChange: env => this.graph.invalidateOnEnvChange(requestId, env, this.options.env[env]),
960
+ invalidateOnOptionChange: option => this.graph.invalidateOnOptionChange(requestId, option,
961
+ // @ts-expect-error TS7053
962
+ this.options[option]),
963
+ getInvalidations: () => previousInvalidations,
964
+ storeResult: (result, cacheKey) => {
965
+ this.storeResult(requestId, result, cacheKey);
966
+ },
967
+ getSubRequests: () => this.graph.getSubRequests(requestId),
968
+ getInvalidSubRequests: () => this.graph.getInvalidSubRequests(requestId),
969
+ getPreviousResult: ifMatch => {
970
+ var _this$graph$getNode;
971
+ let contentKey = (0, _nullthrows().default)((_this$graph$getNode = this.graph.getNode(requestId)) === null || _this$graph$getNode === void 0 ? void 0 : _this$graph$getNode.id);
972
+ return this.getRequestResult(contentKey, ifMatch);
973
+ },
974
+ getRequestResult: (
975
+ // @ts-expect-error TS7006
976
+ id) => this.getRequestResult(id),
977
+ canSkipSubrequest: contentKey => {
978
+ if (this.graph.hasContentKey(contentKey) && this.hasValidResult(this.graph.getNodeIdByContentKey(contentKey))) {
979
+ subRequestContentKeys.add(contentKey);
980
+ return true;
956
981
  }
982
+ return false;
957
983
  },
984
+ runRequest: (subRequest, opts) => {
985
+ subRequestContentKeys.add(subRequest.id);
986
+ return this.runRequest(subRequest, opts);
987
+ }
988
+ };
989
+ return {
990
+ api,
958
991
  subRequestContentKeys
959
992
  };
960
993
  }
961
994
  async writeToCache(signal) {
962
- const options = this.options;
963
- async function runCacheImprovements(newPath, oldPath) {
964
- if ((0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements')) {
965
- (0, _assert().default)(options.cache instanceof _cache().LMDBLiteCache);
966
- const result = await newPath(options.cache);
967
- return result;
968
- } else {
969
- const result = await oldPath();
970
- return result;
971
- }
972
- }
973
995
  let cacheKey = getCacheKey(this.options);
974
- let requestGraphKey = (0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements') ? `${cacheKey}/RequestGraph` : `requestGraph-${cacheKey}`;
975
- let snapshotKey = (0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements') ? `${cacheKey}/snapshot` : `snapshot-${cacheKey}`;
996
+ let requestGraphKey = `requestGraph-${cacheKey}`;
997
+ let snapshotKey = `snapshot-${cacheKey}`;
976
998
  if (this.options.shouldDisableCache) {
977
999
  return;
978
1000
  }
979
1001
  let total = 0;
980
- await runCacheImprovements(async cache => {
981
- await cache.getNativeRef().startWriteTransaction();
982
- }, () => Promise.resolve());
983
1002
  try {
984
1003
  (0, _ReporterRunner.report)({
985
1004
  type: 'cache',
@@ -987,6 +1006,9 @@ class RequestTracker {
987
1006
  total,
988
1007
  size: this.graph.nodes.length
989
1008
  });
1009
+ if ((0, _featureFlags().getFeatureFlag)('environmentDeduplication')) {
1010
+ await (0, _EnvironmentManager.writeEnvironmentsToCache)(this.options.cache);
1011
+ }
990
1012
  let serialisedGraph = this.graph.serialize();
991
1013
 
992
1014
  // Delete an existing request graph cache, to prevent invalid states
@@ -995,16 +1017,9 @@ class RequestTracker {
995
1017
  if (signal !== null && signal !== void 0 && signal.aborted) {
996
1018
  throw new Error('Serialization was aborted');
997
1019
  }
998
- await runCacheImprovements(cache => {
999
- (0, _logger().instrument)(`RequestTracker::writeToCache::cache.put(${key})`, () => {
1000
- cache.getNativeRef().putNoConfirm(key, (0, _buildCache().serialize)(contents));
1001
- });
1002
- return Promise.resolve();
1003
- }, async () => {
1004
- await this.options.cache.setLargeBlob(key, (0, _buildCache().serialize)(contents), signal ? {
1005
- signal: signal
1006
- } : undefined);
1007
- });
1020
+ await this.options.cache.setLargeBlob(key, (0, _buildCache().serialize)(contents), signal ? {
1021
+ signal: signal
1022
+ } : undefined);
1008
1023
  total += 1;
1009
1024
  (0, _ReporterRunner.report)({
1010
1025
  type: 'cache',
@@ -1021,6 +1036,8 @@ class RequestTracker {
1021
1036
  let cacheableNodes = new Array(serialisedGraph.nodes.length);
1022
1037
  for (let i = 0; i < serialisedGraph.nodes.length; i += 1) {
1023
1038
  let node = serialisedGraph.nodes[i];
1039
+
1040
+ // @ts-expect-error TS2339
1024
1041
  let resultCacheKey = node === null || node === void 0 ? void 0 : node.resultCacheKey;
1025
1042
  if ((node === null || node === void 0 ? void 0 : node.type) === REQUEST && resultCacheKey != null && (node === null || node === void 0 ? void 0 : node.result) != null) {
1026
1043
  queue.add(() => serialiseAndSet(resultCacheKey, node.result));
@@ -1057,23 +1074,12 @@ class RequestTracker {
1057
1074
  nodeCountsPerBlob,
1058
1075
  nodes: undefined
1059
1076
  });
1060
- await runCacheImprovements(() => serialiseAndSet(`${cacheKey}/cache_metadata`, {
1061
- version: _constants.ATLASPACK_VERSION,
1062
- entries: this.options.entries,
1063
- mode: this.options.mode,
1064
- shouldBuildLazily: this.options.shouldBuildLazily,
1065
- watchBackend: this.options.watchBackend
1066
- }), () => Promise.resolve());
1067
1077
  let opts = getWatcherOptions(this.options);
1068
1078
  let snapshotPath = _path2().default.join(this.options.cacheDir, snapshotKey + '.txt');
1069
1079
  await this.options.outputFS.writeSnapshot(this.options.watchDir, snapshotPath, opts);
1070
1080
  } catch (err) {
1071
1081
  // If we have aborted, ignore the error and continue
1072
1082
  if (!(signal !== null && signal !== void 0 && signal.aborted)) throw err;
1073
- } finally {
1074
- await runCacheImprovements(async cache => {
1075
- await cache.getNativeRef().commitWriteTransaction();
1076
- }, () => Promise.resolve());
1077
1083
  }
1078
1084
  (0, _ReporterRunner.report)({
1079
1085
  type: 'cache',
@@ -1103,7 +1109,8 @@ function getWatcherOptions({
1103
1109
  watchDir,
1104
1110
  watchBackend
1105
1111
  }) {
1106
- const uniqueDirs = [...new Set([...watchIgnore, ...['.git', '.hg'], cacheDir])];
1112
+ const vcsDirs = ['.git', '.hg'];
1113
+ const uniqueDirs = [...new Set([...watchIgnore, ...vcsDirs, cacheDir])];
1107
1114
  const ignore = uniqueDirs.map(dir => _path2().default.resolve(watchDir, dir));
1108
1115
  return {
1109
1116
  ignore,
@@ -1111,33 +1118,22 @@ function getWatcherOptions({
1111
1118
  };
1112
1119
  }
1113
1120
  function getCacheKey(options) {
1114
- if ((0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements')) {
1115
- const hash = (0, _rust().hashString)(`${_constants.ATLASPACK_VERSION}:${JSON.stringify(options.entries)}:${options.mode}:${options.shouldBuildLazily ? 'lazy' : 'eager'}:${options.watchBackend ?? ''}`);
1116
- return `RequestTracker/${_constants.ATLASPACK_VERSION}/${hash}`;
1117
- }
1118
1121
  return (0, _rust().hashString)(`${_constants.ATLASPACK_VERSION}:${JSON.stringify(options.entries)}:${options.mode}:${options.shouldBuildLazily ? 'lazy' : 'eager'}:${options.watchBackend ?? ''}`);
1119
1122
  }
1120
1123
  function getRequestGraphNodeKey(index, cacheKey) {
1121
- if ((0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements')) {
1122
- return `${cacheKey}/RequestGraph/nodes/${index}`;
1123
- }
1124
1124
  return `requestGraph-nodes-${index}-${cacheKey}`;
1125
1125
  }
1126
1126
  async function readAndDeserializeRequestGraph(cache, requestGraphKey, cacheKey) {
1127
1127
  let bufferLength = 0;
1128
1128
  const getAndDeserialize = async key => {
1129
- if ((0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements')) {
1130
- const buffer = await cache.getBlob(key);
1131
- bufferLength += Buffer.byteLength(buffer);
1132
- return (0, _buildCache().deserialize)(buffer);
1133
- } else {
1134
- const buffer = await cache.getLargeBlob(key);
1135
- bufferLength += Buffer.byteLength(buffer);
1136
- return (0, _buildCache().deserialize)(buffer);
1137
- }
1129
+ const buffer = await cache.getLargeBlob(key);
1130
+ bufferLength += Buffer.byteLength(buffer);
1131
+ return (0, _buildCache().deserialize)(buffer);
1138
1132
  };
1139
1133
  let serializedRequestGraph = await getAndDeserialize(requestGraphKey);
1140
- let nodePromises = serializedRequestGraph.nodeCountsPerBlob.map(async (nodesCount, i) => {
1134
+ let nodePromises = serializedRequestGraph.nodeCountsPerBlob.map(
1135
+ // @ts-expect-error TS7006
1136
+ async (nodesCount, i) => {
1141
1137
  let nodes = await getAndDeserialize(getRequestGraphNodeKey(i, cacheKey));
1142
1138
  _assert().default.equal(nodes.length, nodesCount, 'RequestTracker node chunk: invalid node count');
1143
1139
  return nodes;
@@ -1156,9 +1152,9 @@ async function loadRequestGraph(options) {
1156
1152
  return new RequestGraph();
1157
1153
  }
1158
1154
  let cacheKey = getCacheKey(options);
1159
- let requestGraphKey = (0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements') ? `${cacheKey}/RequestGraph` : `requestGraph-${cacheKey}`;
1155
+ let requestGraphKey = `requestGraph-${cacheKey}`;
1160
1156
  let timeout;
1161
- const snapshotKey = (0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements') ? `${cacheKey}/snapshot` : `snapshot-${cacheKey}`;
1157
+ const snapshotKey = `snapshot-${cacheKey}`;
1162
1158
  const snapshotPath = _path2().default.join(options.cacheDir, snapshotKey + '.txt');
1163
1159
  const commonMeta = {
1164
1160
  cacheKey,
@@ -1178,7 +1174,10 @@ async function loadRequestGraph(options) {
1178
1174
  ...commonMeta
1179
1175
  }
1180
1176
  });
1181
- const hasRequestGraphInCache = (0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements') ? await options.cache.has(requestGraphKey) : await options.cache.hasLargeBlob(requestGraphKey);
1177
+ if ((0, _featureFlags().getFeatureFlag)('environmentDeduplication')) {
1178
+ await (0, _EnvironmentManager.loadEnvironmentsFromCache)(options.cache);
1179
+ }
1180
+ const hasRequestGraphInCache = await options.cache.hasLargeBlob(requestGraphKey);
1182
1181
  if (hasRequestGraphInCache) {
1183
1182
  try {
1184
1183
  let {
@@ -1204,23 +1203,16 @@ async function loadRequestGraph(options) {
1204
1203
  duration: Date.now() - startTime
1205
1204
  }
1206
1205
  });
1207
- if ((0, _featureFlags().getFeatureFlag)('verboseRequestInvalidationStats')) {
1208
- const invalidationStats = await invalidateRequestGraph(requestGraph, options, events);
1209
- _logger().default.verbose({
1210
- origin: '@atlaspack/core',
1211
- message: 'Request track loaded from cache',
1212
- meta: {
1213
- ...commonMeta,
1214
- trackableEvent: 'request_tracker_cache_key_hit',
1215
- invalidationStats
1216
- }
1217
- });
1218
- } else {
1219
- requestGraph.invalidateUnpredictableNodes();
1220
- requestGraph.invalidateOnBuildNodes();
1221
- requestGraph.invalidateEnvNodes(options.env);
1222
- requestGraph.invalidateOptionNodes(options);
1223
- }
1206
+ const invalidationStats = await invalidateRequestGraph(requestGraph, options, events);
1207
+ _logger().default.verbose({
1208
+ origin: '@atlaspack/core',
1209
+ message: 'Request track loaded from cache',
1210
+ meta: {
1211
+ ...commonMeta,
1212
+ trackableEvent: 'request_tracker_cache_key_hit',
1213
+ invalidationStats
1214
+ }
1215
+ });
1224
1216
  return requestGraph;
1225
1217
  } catch (e) {
1226
1218
  // Prevent logging fs events took too long warning
@@ -1246,6 +1238,20 @@ async function loadRequestGraph(options) {
1246
1238
  * A wrapper around an invalidation type / method
1247
1239
  */
1248
1240
 
1241
+ /**
1242
+ * Details about an invalidation.
1243
+ *
1244
+ * If this is a fs events invalidation, this key will contain statistics about invalidations
1245
+ * by path.
1246
+ *
1247
+ * If this is a env or option invalidation, this key will contain the list of changed environment
1248
+ * variables or options.
1249
+ */
1250
+
1251
+ /**
1252
+ * Number of invalidations for a given file-system event.
1253
+ */
1254
+
1249
1255
  /**
1250
1256
  * Information about a certain cache invalidation type.
1251
1257
  */
@@ -1259,9 +1265,11 @@ async function loadRequestGraph(options) {
1259
1265
  async function invalidateRequestGraph(requestGraph, options, events) {
1260
1266
  const invalidationFns = [{
1261
1267
  key: 'unpredictable',
1268
+ // @ts-expect-error TS2322
1262
1269
  fn: () => requestGraph.invalidateUnpredictableNodes()
1263
1270
  }, {
1264
1271
  key: 'onBuild',
1272
+ // @ts-expect-error TS2322
1265
1273
  fn: () => requestGraph.invalidateOnBuildNodes()
1266
1274
  }, {
1267
1275
  key: 'env',
@@ -1271,9 +1279,7 @@ async function invalidateRequestGraph(requestGraph, options, events) {
1271
1279
  fn: () => requestGraph.invalidateOptionNodes(options)
1272
1280
  }, {
1273
1281
  key: 'fsEvents',
1274
- fn: async () => {
1275
- await requestGraph.respondToFSEvents(options.unstableFileInvalidations || events, options, 10000, true);
1276
- }
1282
+ fn: () => invalidateRequestGraphFSEvents(requestGraph, options, events)
1277
1283
  }];
1278
1284
  const invalidations = [];
1279
1285
  for (const invalidation of invalidationFns) {
@@ -1282,27 +1288,45 @@ async function invalidateRequestGraph(requestGraph, options, events) {
1282
1288
  const invalidatedCount = invalidations.reduce((acc, invalidation) => acc + invalidation.count, 0);
1283
1289
  const requestCount = requestGraph.nodes.reduce((acc, node) => acc + ((node === null || node === void 0 ? void 0 : node.type) === REQUEST ? 1 : 0), 0);
1284
1290
  const nodeCount = requestGraph.nodes.length;
1291
+ const nodeInvalidationRatio = invalidatedCount / nodeCount;
1292
+ const requestInvalidationRatio = invalidatedCount / requestCount;
1285
1293
  return {
1286
1294
  invalidations,
1287
1295
  nodeCount,
1288
1296
  requestCount,
1289
1297
  invalidatedCount,
1290
- nodeInvalidationRatio: invalidatedCount / nodeCount,
1291
- requestInvalidationRatio: invalidatedCount / requestCount
1298
+ nodeInvalidationRatio,
1299
+ requestInvalidationRatio
1300
+ };
1301
+ }
1302
+ /**
1303
+ * Invalidate the request graph based on file-system events.
1304
+ *
1305
+ * Returns statistics about the invalidations.
1306
+ */
1307
+ async function invalidateRequestGraphFSEvents(requestGraph, options, events) {
1308
+ const {
1309
+ invalidationsByPath
1310
+ } = await requestGraph.respondToFSEvents(options.unstableFileInvalidations || events, options, 10000, true);
1311
+ const biggestInvalidations = getBiggestFSEventsInvalidations(invalidationsByPath);
1312
+ return {
1313
+ biggestInvalidations
1292
1314
  };
1293
1315
  }
1294
-
1295
1316
  /**
1296
1317
  * Runs an invalidation function and reports metrics.
1297
1318
  */
1298
1319
  async function runInvalidation(requestGraph, invalidationFn) {
1299
- const startInvalidationCount = requestGraph.invalidNodeIds.size;
1320
+ const start = _perf_hooks().performance.now();
1321
+ const startInvalidationCount = requestGraph.getInvalidNodeCount();
1300
1322
  const result = await invalidationFn.fn();
1301
- const count = requestGraph.invalidNodeIds.size - startInvalidationCount;
1323
+ const count = requestGraph.getInvalidNodeCount() - startInvalidationCount;
1324
+ const duration = _perf_hooks().performance.now() - start;
1302
1325
  return {
1303
1326
  key: invalidationFn.key,
1304
1327
  count,
1305
- changes: typeof result === 'object' && Array.isArray(result) ? result : null
1328
+ detail: result ?? null,
1329
+ duration
1306
1330
  };
1307
1331
  }
1308
1332
  function logErrorOnBailout(options, snapshotPath, e) {
@@ -1344,4 +1368,19 @@ function cleanUpOrphans(graph) {
1344
1368
  }
1345
1369
  });
1346
1370
  return removedNodeIds;
1371
+ }
1372
+
1373
+ /**
1374
+ * Returns paths that invalidated the most nodes
1375
+ */
1376
+ function getBiggestFSEventsInvalidations(invalidationsByPath, limit = 10) {
1377
+ const invalidations = [];
1378
+ for (const [path, count] of invalidationsByPath) {
1379
+ invalidations.push({
1380
+ path,
1381
+ count
1382
+ });
1383
+ }
1384
+ invalidations.sort((a, b) => b.count - a.count);
1385
+ return invalidations.slice(0, limit);
1347
1386
  }