@atlaspack/core 2.16.2-canary.27 → 2.16.2-canary.270

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 (358) hide show
  1. package/CHANGELOG.md +665 -0
  2. package/dist/AssetGraph.js +591 -0
  3. package/dist/Atlaspack.js +658 -0
  4. package/dist/AtlaspackConfig.js +324 -0
  5. package/dist/AtlaspackConfig.schema.js +108 -0
  6. package/dist/BundleGraph.js +1635 -0
  7. package/dist/CommittedAsset.js +142 -0
  8. package/dist/Dependency.js +125 -0
  9. package/dist/Environment.js +132 -0
  10. package/dist/EnvironmentManager.js +108 -0
  11. package/dist/IdentifierRegistry.js +38 -0
  12. package/dist/InternalConfig.js +37 -0
  13. package/dist/PackagerRunner.js +545 -0
  14. package/dist/ReporterRunner.js +151 -0
  15. package/dist/RequestTracker.js +1360 -0
  16. package/dist/SymbolPropagation.js +620 -0
  17. package/dist/TargetDescriptor.schema.js +143 -0
  18. package/dist/Transformation.js +490 -0
  19. package/dist/UncommittedAsset.js +315 -0
  20. package/dist/Validation.js +196 -0
  21. package/dist/applyRuntimes.js +305 -0
  22. package/dist/assetUtils.js +168 -0
  23. package/dist/atlaspack-v3/AtlaspackV3.js +70 -0
  24. package/dist/atlaspack-v3/NapiWorkerPool.js +57 -0
  25. package/dist/atlaspack-v3/fs.js +52 -0
  26. package/dist/atlaspack-v3/index.js +25 -0
  27. package/dist/atlaspack-v3/jsCallable.js +16 -0
  28. package/dist/atlaspack-v3/worker/compat/asset-symbols.js +190 -0
  29. package/dist/atlaspack-v3/worker/compat/bitflags.js +94 -0
  30. package/dist/atlaspack-v3/worker/compat/dependency.js +43 -0
  31. package/dist/atlaspack-v3/worker/compat/environment.js +57 -0
  32. package/dist/atlaspack-v3/worker/compat/index.js +25 -0
  33. package/dist/atlaspack-v3/worker/compat/mutable-asset.js +152 -0
  34. package/dist/atlaspack-v3/worker/compat/plugin-config.js +76 -0
  35. package/dist/atlaspack-v3/worker/compat/plugin-logger.js +26 -0
  36. package/dist/atlaspack-v3/worker/compat/plugin-options.js +122 -0
  37. package/dist/atlaspack-v3/worker/compat/plugin-tracer.js +10 -0
  38. package/dist/atlaspack-v3/worker/compat/target.js +14 -0
  39. package/dist/atlaspack-v3/worker/worker.js +297 -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 +359 -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 +429 -0
  59. package/dist/requests/AssetGraphRequestRust.js +262 -0
  60. package/dist/requests/AssetRequest.js +130 -0
  61. package/dist/requests/AtlaspackBuildRequest.js +65 -0
  62. package/dist/requests/AtlaspackConfigRequest.js +493 -0
  63. package/dist/requests/BundleGraphRequest.js +445 -0
  64. package/dist/requests/ConfigRequest.js +222 -0
  65. package/dist/requests/DevDepRequest.js +204 -0
  66. package/dist/requests/EntryRequest.js +314 -0
  67. package/dist/requests/PackageRequest.js +62 -0
  68. package/dist/requests/PathRequest.js +349 -0
  69. package/dist/requests/TargetRequest.js +1311 -0
  70. package/dist/requests/ValidationRequest.js +49 -0
  71. package/dist/requests/WriteBundleRequest.js +254 -0
  72. package/dist/requests/WriteBundlesRequest.js +184 -0
  73. package/dist/requests/asset-graph-diff.js +128 -0
  74. package/dist/requests/asset-graph-dot.js +131 -0
  75. package/dist/resolveOptions.js +268 -0
  76. package/dist/rustWorkerThreadDylibHack.js +19 -0
  77. package/dist/serializerCore.browser.js +43 -0
  78. package/dist/summarizeRequest.js +39 -0
  79. package/dist/types.js +31 -0
  80. package/dist/utils.js +172 -0
  81. package/dist/worker.js +123 -0
  82. package/lib/AssetGraph.js +111 -14
  83. package/lib/Atlaspack.js +81 -37
  84. package/lib/AtlaspackConfig.js +15 -3
  85. package/lib/AtlaspackConfig.schema.js +7 -5
  86. package/lib/BundleGraph.js +90 -32
  87. package/lib/CommittedAsset.js +6 -0
  88. package/lib/Dependency.js +8 -2
  89. package/lib/Environment.js +15 -8
  90. package/lib/EnvironmentManager.js +143 -0
  91. package/lib/IdentifierRegistry.js +1 -3
  92. package/lib/InternalConfig.js +3 -2
  93. package/lib/PackagerRunner.js +90 -27
  94. package/lib/ReporterRunner.js +6 -9
  95. package/lib/RequestTracker.js +266 -156
  96. package/lib/SymbolPropagation.js +42 -18
  97. package/lib/TargetDescriptor.schema.js +7 -1
  98. package/lib/Transformation.js +26 -10
  99. package/lib/UncommittedAsset.js +30 -9
  100. package/lib/Validation.js +18 -2
  101. package/lib/applyRuntimes.js +9 -1
  102. package/lib/assetUtils.js +7 -4
  103. package/lib/atlaspack-v3/AtlaspackV3.js +32 -7
  104. package/lib/atlaspack-v3/NapiWorkerPool.js +3 -0
  105. package/lib/atlaspack-v3/fs.js +3 -1
  106. package/lib/atlaspack-v3/index.js +28 -1
  107. package/lib/atlaspack-v3/jsCallable.js +0 -2
  108. package/lib/atlaspack-v3/worker/compat/asset-symbols.js +7 -4
  109. package/lib/atlaspack-v3/worker/compat/bitflags.js +7 -6
  110. package/lib/atlaspack-v3/worker/compat/dependency.js +3 -0
  111. package/lib/atlaspack-v3/worker/compat/environment.js +10 -7
  112. package/lib/atlaspack-v3/worker/compat/mutable-asset.js +14 -9
  113. package/lib/atlaspack-v3/worker/compat/plugin-config.js +8 -10
  114. package/lib/atlaspack-v3/worker/compat/plugin-options.js +1 -0
  115. package/lib/atlaspack-v3/worker/compat/plugin-tracer.js +3 -0
  116. package/lib/atlaspack-v3/worker/compat/target.js +2 -0
  117. package/lib/atlaspack-v3/worker/index.js +3 -0
  118. package/lib/atlaspack-v3/worker/worker.js +43 -7
  119. package/lib/constants.js +0 -1
  120. package/lib/dumpGraphToGraphViz.js +71 -16
  121. package/lib/index.js +45 -1
  122. package/lib/loadDotEnv.js +4 -1
  123. package/lib/projectPath.js +5 -0
  124. package/lib/public/Asset.js +21 -11
  125. package/lib/public/Bundle.js +15 -16
  126. package/lib/public/BundleGraph.js +10 -4
  127. package/lib/public/BundleGroup.js +4 -5
  128. package/lib/public/Config.js +118 -17
  129. package/lib/public/Dependency.js +8 -6
  130. package/lib/public/Environment.js +12 -7
  131. package/lib/public/MutableBundleGraph.js +54 -12
  132. package/lib/public/PluginOptions.js +2 -2
  133. package/lib/public/Symbols.js +11 -11
  134. package/lib/public/Target.js +7 -6
  135. package/lib/registerCoreWithSerializer.js +5 -3
  136. package/lib/requests/AssetGraphRequest.js +42 -5
  137. package/lib/requests/AssetGraphRequestRust.js +126 -62
  138. package/lib/requests/AssetRequest.js +23 -6
  139. package/lib/requests/AtlaspackBuildRequest.js +10 -4
  140. package/lib/requests/AtlaspackConfigRequest.js +27 -16
  141. package/lib/requests/BundleGraphRequest.js +34 -19
  142. package/lib/requests/ConfigRequest.js +28 -4
  143. package/lib/requests/DevDepRequest.js +31 -5
  144. package/lib/requests/EntryRequest.js +2 -0
  145. package/lib/requests/PackageRequest.js +2 -1
  146. package/lib/requests/PathRequest.js +24 -3
  147. package/lib/requests/TargetRequest.js +122 -57
  148. package/lib/requests/ValidationRequest.js +5 -1
  149. package/lib/requests/WriteBundleRequest.js +39 -11
  150. package/lib/requests/WriteBundlesRequest.js +51 -4
  151. package/lib/requests/asset-graph-diff.js +12 -7
  152. package/lib/requests/asset-graph-dot.js +1 -7
  153. package/lib/resolveOptions.js +36 -10
  154. package/lib/rustWorkerThreadDylibHack.js +0 -1
  155. package/lib/types/AssetGraph.d.ts +80 -0
  156. package/lib/types/Atlaspack.d.ts +52 -0
  157. package/lib/types/AtlaspackConfig.d.ts +65 -0
  158. package/lib/types/AtlaspackConfig.schema.d.ts +46 -0
  159. package/lib/types/BundleGraph.d.ts +182 -0
  160. package/lib/types/CommittedAsset.d.ts +23 -0
  161. package/lib/types/Dependency.d.ts +44 -0
  162. package/lib/types/Environment.d.ts +11 -0
  163. package/lib/types/EnvironmentManager.d.ts +37 -0
  164. package/lib/types/IdentifierRegistry.d.ts +6 -0
  165. package/lib/types/InternalConfig.d.ts +24 -0
  166. package/lib/types/PackagerRunner.d.ts +85 -0
  167. package/lib/types/ReporterRunner.d.ts +25 -0
  168. package/lib/types/RequestTracker.d.ts +385 -0
  169. package/lib/types/SymbolPropagation.d.ts +11 -0
  170. package/lib/types/TargetDescriptor.schema.d.ts +5 -0
  171. package/lib/types/Transformation.d.ts +72 -0
  172. package/lib/types/UncommittedAsset.d.ts +61 -0
  173. package/lib/types/Validation.d.ts +37 -0
  174. package/lib/types/applyRuntimes.d.ts +25 -0
  175. package/lib/types/assetUtils.d.ts +42 -0
  176. package/lib/types/atlaspack-v3/AtlaspackV3.d.ts +26 -0
  177. package/lib/types/atlaspack-v3/NapiWorkerPool.d.ts +12 -0
  178. package/lib/types/atlaspack-v3/fs.d.ts +12 -0
  179. package/lib/types/atlaspack-v3/index.d.ts +5 -0
  180. package/lib/types/atlaspack-v3/jsCallable.d.ts +1 -0
  181. package/lib/types/atlaspack-v3/worker/compat/asset-symbols.d.ts +51 -0
  182. package/lib/types/atlaspack-v3/worker/compat/bitflags.d.ts +15 -0
  183. package/lib/types/atlaspack-v3/worker/compat/dependency.d.ts +25 -0
  184. package/lib/types/atlaspack-v3/worker/compat/environment.d.ts +27 -0
  185. package/{src/atlaspack-v3/worker/compat/index.js → lib/types/atlaspack-v3/worker/compat/index.d.ts} +0 -1
  186. package/lib/types/atlaspack-v3/worker/compat/mutable-asset.d.ts +49 -0
  187. package/lib/types/atlaspack-v3/worker/compat/plugin-config.d.ts +37 -0
  188. package/lib/types/atlaspack-v3/worker/compat/plugin-logger.d.ts +9 -0
  189. package/lib/types/atlaspack-v3/worker/compat/plugin-options.d.ts +22 -0
  190. package/lib/types/atlaspack-v3/worker/compat/plugin-tracer.d.ts +5 -0
  191. package/lib/types/atlaspack-v3/worker/compat/target.d.ts +11 -0
  192. package/lib/types/atlaspack-v3/worker/worker.d.ts +60 -0
  193. package/lib/types/constants.d.ts +13 -0
  194. package/lib/types/dumpGraphToGraphViz.d.ts +10 -0
  195. package/lib/types/index.d.ts +8 -0
  196. package/lib/types/loadAtlaspackPlugin.d.ts +8 -0
  197. package/lib/types/loadDotEnv.d.ts +3 -0
  198. package/lib/types/projectPath.d.ts +19 -0
  199. package/lib/types/public/Asset.d.ts +74 -0
  200. package/lib/types/public/Bundle.d.ts +45 -0
  201. package/lib/types/public/BundleGraph.d.ts +70 -0
  202. package/lib/types/public/BundleGroup.d.ts +12 -0
  203. package/lib/types/public/Config.d.ts +75 -0
  204. package/lib/types/public/Dependency.d.ts +32 -0
  205. package/lib/types/public/Environment.d.ts +34 -0
  206. package/lib/types/public/MutableBundleGraph.d.ts +26 -0
  207. package/lib/types/public/PluginOptions.d.ts +25 -0
  208. package/lib/types/public/Symbols.d.ts +81 -0
  209. package/lib/types/public/Target.d.ts +16 -0
  210. package/lib/types/registerCoreWithSerializer.d.ts +2 -0
  211. package/lib/types/requests/AssetGraphRequest.d.ts +74 -0
  212. package/lib/types/requests/AssetGraphRequestRust.d.ts +21 -0
  213. package/lib/types/requests/AssetRequest.d.ts +16 -0
  214. package/lib/types/requests/AtlaspackBuildRequest.d.ts +33 -0
  215. package/lib/types/requests/AtlaspackConfigRequest.d.ts +45 -0
  216. package/lib/types/requests/BundleGraphRequest.d.ts +28 -0
  217. package/lib/types/requests/ConfigRequest.d.ts +59 -0
  218. package/lib/types/requests/DevDepRequest.d.ts +30 -0
  219. package/lib/types/requests/EntryRequest.d.ts +36 -0
  220. package/lib/types/requests/PackageRequest.d.ts +27 -0
  221. package/lib/types/requests/PathRequest.d.ts +48 -0
  222. package/lib/types/requests/TargetRequest.d.ts +48 -0
  223. package/lib/types/requests/ValidationRequest.d.ts +20 -0
  224. package/lib/types/requests/WriteBundleRequest.d.ts +28 -0
  225. package/lib/types/requests/WriteBundlesRequest.d.ts +32 -0
  226. package/lib/types/requests/asset-graph-diff.d.ts +1 -0
  227. package/lib/types/requests/asset-graph-dot.d.ts +9 -0
  228. package/lib/types/resolveOptions.d.ts +3 -0
  229. package/lib/types/rustWorkerThreadDylibHack.d.ts +9 -0
  230. package/lib/types/serializerCore.browser.d.ts +3 -0
  231. package/lib/types/summarizeRequest.d.ts +10 -0
  232. package/lib/types/types.d.ts +493 -0
  233. package/lib/types/utils.d.ts +23 -0
  234. package/lib/types/worker.d.ts +44 -0
  235. package/lib/types.js +8 -1
  236. package/lib/utils.js +17 -2
  237. package/lib/worker.js +29 -13
  238. package/package.json +24 -34
  239. package/src/{AssetGraph.js → AssetGraph.ts} +156 -52
  240. package/src/{Atlaspack.js → Atlaspack.ts} +114 -61
  241. package/src/{AtlaspackConfig.schema.js → AtlaspackConfig.schema.ts} +16 -19
  242. package/src/{AtlaspackConfig.js → AtlaspackConfig.ts} +78 -54
  243. package/src/{BundleGraph.js → BundleGraph.ts} +231 -140
  244. package/src/{CommittedAsset.js → CommittedAsset.ts} +14 -12
  245. package/src/{Dependency.js → Dependency.ts} +59 -42
  246. package/src/{Environment.js → Environment.ts} +24 -15
  247. package/src/EnvironmentManager.ts +154 -0
  248. package/src/{IdentifierRegistry.js → IdentifierRegistry.ts} +1 -4
  249. package/src/{InternalConfig.js → InternalConfig.ts} +22 -23
  250. package/src/{PackagerRunner.js → PackagerRunner.ts} +178 -86
  251. package/src/{ReporterRunner.js → ReporterRunner.ts} +13 -18
  252. package/src/{RequestTracker.js → RequestTracker.ts} +572 -357
  253. package/src/{SymbolPropagation.js → SymbolPropagation.ts} +165 -57
  254. package/src/{TargetDescriptor.schema.js → TargetDescriptor.schema.ts} +7 -1
  255. package/src/{Transformation.js → Transformation.ts} +71 -62
  256. package/src/{UncommittedAsset.js → UncommittedAsset.ts} +57 -36
  257. package/src/{Validation.js → Validation.ts} +32 -17
  258. package/src/{applyRuntimes.js → applyRuntimes.ts} +35 -26
  259. package/src/{assetUtils.js → assetUtils.ts} +47 -35
  260. package/src/atlaspack-v3/AtlaspackV3.ts +122 -0
  261. package/src/atlaspack-v3/{NapiWorkerPool.js → NapiWorkerPool.ts} +10 -5
  262. package/src/atlaspack-v3/{fs.js → fs.ts} +3 -4
  263. package/src/atlaspack-v3/{index.js → index.ts} +2 -4
  264. package/src/atlaspack-v3/jsCallable.ts +14 -0
  265. package/src/atlaspack-v3/worker/compat/{asset-symbols.js → asset-symbols.ts} +40 -30
  266. package/src/atlaspack-v3/worker/compat/{bitflags.js → bitflags.ts} +9 -10
  267. package/src/atlaspack-v3/worker/compat/{dependency.js → dependency.ts} +12 -12
  268. package/src/atlaspack-v3/worker/compat/{environment.js → environment.ts} +13 -9
  269. package/src/atlaspack-v3/worker/compat/index.ts +9 -0
  270. package/src/atlaspack-v3/worker/compat/{mutable-asset.js → mutable-asset.ts} +20 -19
  271. package/src/atlaspack-v3/worker/compat/{plugin-config.js → plugin-config.ts} +27 -26
  272. package/src/atlaspack-v3/worker/compat/{plugin-logger.js → plugin-logger.ts} +0 -2
  273. package/src/atlaspack-v3/worker/compat/{plugin-options.js → plugin-options.ts} +4 -5
  274. package/src/atlaspack-v3/worker/compat/{plugin-tracer.js → plugin-tracer.ts} +2 -2
  275. package/src/atlaspack-v3/worker/compat/{target.js → target.ts} +3 -4
  276. package/src/atlaspack-v3/worker/index.js +2 -1
  277. package/src/atlaspack-v3/worker/{worker.js → worker.ts} +102 -66
  278. package/src/{constants.js → constants.ts} +0 -3
  279. package/src/{dumpGraphToGraphViz.js → dumpGraphToGraphViz.ts} +73 -28
  280. package/src/index.ts +18 -0
  281. package/src/{loadAtlaspackPlugin.js → loadAtlaspackPlugin.ts} +8 -9
  282. package/src/{loadDotEnv.js → loadDotEnv.ts} +2 -2
  283. package/src/{projectPath.js → projectPath.ts} +20 -9
  284. package/src/public/{Asset.js → Asset.ts} +40 -27
  285. package/src/public/{Bundle.js → Bundle.ts} +28 -29
  286. package/src/public/{BundleGraph.js → BundleGraph.ts} +81 -50
  287. package/src/public/{BundleGroup.js → BundleGroup.ts} +7 -10
  288. package/src/public/{Config.js → Config.ts} +171 -33
  289. package/src/public/{Dependency.js → Dependency.ts} +20 -17
  290. package/src/public/{Environment.js → Environment.ts} +28 -17
  291. package/src/public/{MutableBundleGraph.js → MutableBundleGraph.ts} +55 -24
  292. package/src/public/{PluginOptions.js → PluginOptions.ts} +6 -6
  293. package/src/public/{Symbols.js → Symbols.ts} +75 -36
  294. package/src/public/{Target.js → Target.ts} +10 -8
  295. package/src/{registerCoreWithSerializer.js → registerCoreWithSerializer.ts} +9 -7
  296. package/src/requests/{AssetGraphRequest.js → AssetGraphRequest.ts} +84 -49
  297. package/src/requests/AssetGraphRequestRust.ts +352 -0
  298. package/src/requests/{AssetRequest.js → AssetRequest.ts} +24 -18
  299. package/src/requests/{AtlaspackBuildRequest.js → AtlaspackBuildRequest.ts} +46 -32
  300. package/src/requests/{AtlaspackConfigRequest.js → AtlaspackConfigRequest.ts} +72 -58
  301. package/src/requests/{BundleGraphRequest.js → BundleGraphRequest.ts} +71 -58
  302. package/src/requests/{ConfigRequest.js → ConfigRequest.ts} +71 -50
  303. package/src/requests/{DevDepRequest.js → DevDepRequest.ts} +60 -35
  304. package/src/requests/{EntryRequest.js → EntryRequest.ts} +36 -31
  305. package/src/requests/{PackageRequest.js → PackageRequest.ts} +20 -22
  306. package/src/requests/{PathRequest.js → PathRequest.ts} +47 -37
  307. package/src/requests/{TargetRequest.js → TargetRequest.ts} +260 -179
  308. package/src/requests/{ValidationRequest.js → ValidationRequest.ts} +18 -17
  309. package/src/requests/{WriteBundleRequest.js → WriteBundleRequest.ts} +77 -49
  310. package/src/requests/{WriteBundlesRequest.js → WriteBundlesRequest.ts} +109 -37
  311. package/src/requests/{asset-graph-diff.js → asset-graph-diff.ts} +25 -21
  312. package/src/requests/{asset-graph-dot.js → asset-graph-dot.ts} +8 -12
  313. package/src/{resolveOptions.js → resolveOptions.ts} +56 -24
  314. package/src/{rustWorkerThreadDylibHack.js → rustWorkerThreadDylibHack.ts} +1 -4
  315. package/src/{serializerCore.browser.js → serializerCore.browser.ts} +2 -3
  316. package/src/{summarizeRequest.js → summarizeRequest.ts} +17 -5
  317. package/src/types.ts +647 -0
  318. package/src/{utils.js → utils.ts} +52 -21
  319. package/src/{worker.js → worker.ts} +49 -41
  320. package/test/{AssetGraph.test.js → AssetGraph.test.ts} +37 -8
  321. package/test/{Atlaspack.test.js → Atlaspack.test.ts} +5 -10
  322. package/test/{AtlaspackConfig.test.js → AtlaspackConfig.test.ts} +0 -5
  323. package/test/{AtlaspackConfigRequest.test.js → AtlaspackConfigRequest.test.ts} +75 -15
  324. package/test/{BundleGraph.test.js → BundleGraph.test.ts} +8 -13
  325. package/test/{Dependency.test.js → Dependency.test.ts} +2 -3
  326. package/test/{EntryRequest.test.js → EntryRequest.test.ts} +1 -6
  327. package/test/Environment.test.ts +153 -0
  328. package/test/EnvironmentManager.test.ts +188 -0
  329. package/test/{IdentifierRegistry.test.js → IdentifierRegistry.test.ts} +2 -4
  330. package/test/{InternalAsset.test.js → InternalAsset.test.ts} +2 -7
  331. package/test/PackagerRunner.test.ts +0 -0
  332. package/test/{PublicAsset.test.js → PublicAsset.test.ts} +2 -7
  333. package/test/{PublicBundle.test.js → PublicBundle.test.ts} +1 -2
  334. package/test/{PublicDependency.test.js → PublicDependency.test.ts} +0 -2
  335. package/test/PublicEnvironment.test.ts +49 -0
  336. package/test/{PublicMutableBundleGraph.test.js → PublicMutableBundleGraph.test.ts} +6 -11
  337. package/test/{RequestTracker.test.js → RequestTracker.test.ts} +314 -59
  338. package/test/{SymbolPropagation.test.js → SymbolPropagation.test.ts} +124 -74
  339. package/test/{TargetRequest.test.js → TargetRequest.test.ts} +66 -92
  340. package/test/fixtures/config-with-reporters/.parcelrc +7 -0
  341. package/test/fixtures/custom-targets/package.json +6 -0
  342. package/test/public/Config.test.ts +104 -0
  343. package/test/requests/{AssetGraphRequestRust.test.js → AssetGraphRequestRust.test.ts} +164 -134
  344. package/test/requests/{ConfigRequest.test.js → ConfigRequest.test.ts} +202 -13
  345. package/test/requests/{DevDepRequest.test.js → DevDepRequest.test.ts} +0 -2
  346. package/test/{test-utils.js → test-utils.ts} +4 -11
  347. package/test/{utils.test.js → utils.test.ts} +1 -3
  348. package/tsconfig.json +57 -0
  349. package/tsconfig.tsbuildinfo +1 -0
  350. package/index.d.ts +0 -30
  351. package/src/atlaspack-v3/AtlaspackV3.js +0 -87
  352. package/src/atlaspack-v3/jsCallable.js +0 -18
  353. package/src/index.js +0 -13
  354. package/src/requests/AssetGraphRequestRust.js +0 -263
  355. package/src/types.js +0 -600
  356. package/test/Environment.test.js +0 -119
  357. package/test/PackagerRunner.test.js +0 -27
  358. package/test/PublicEnvironment.test.js +0 -27
@@ -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 () {
@@ -84,6 +88,14 @@ var _projectPath = require("./projectPath");
84
88
  var _ReporterRunner = require("./ReporterRunner");
85
89
  var _ConfigRequest = require("./requests/ConfigRequest");
86
90
  var _utils2 = require("./utils");
91
+ function _perf_hooks() {
92
+ const data = require("perf_hooks");
93
+ _perf_hooks = function () {
94
+ return data;
95
+ };
96
+ return data;
97
+ }
98
+ var _EnvironmentManager = require("./EnvironmentManager");
87
99
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
88
100
  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
101
  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; }
@@ -151,7 +163,7 @@ const nodeFromOption = (option, value) => ({
151
163
  hash: (0, _utils2.hashFromOption)(value)
152
164
  });
153
165
  const nodeFromConfigKey = (fileName, configKey, contentHash) => ({
154
- id: `config_key:${(0, _projectPath.fromProjectPathRelative)(fileName)}:${configKey}`,
166
+ id: `config_key:${(0, _projectPath.fromProjectPathRelative)(fileName)}:${JSON.stringify(configKey)}`,
155
167
  type: CONFIG_KEY,
156
168
  configKey,
157
169
  contentHash
@@ -162,6 +174,8 @@ const keyFromOptionContentKey = contentKey => contentKey.slice('option:'.length)
162
174
  // 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
175
  // The goal is to free up the event loop periodically to allow interruption by the user.
164
176
  const NODES_PER_BLOB = 2 ** 14;
177
+
178
+ // @ts-expect-error TS2417
165
179
  class RequestGraph extends _graph().ContentGraph {
166
180
  invalidNodeIds = new Set();
167
181
  incompleteNodeIds = new Set();
@@ -176,10 +190,7 @@ class RequestGraph extends _graph().ContentGraph {
176
190
  cachedRequestChunks = new Set();
177
191
  configKeyNodes = new Map();
178
192
  nodesPerBlob = NODES_PER_BLOB;
179
-
180
- // $FlowFixMe[prop-missing]
181
193
  static deserialize(opts) {
182
- // $FlowFixMe[prop-missing]
183
194
  let deserialized = new RequestGraph(opts);
184
195
  deserialized.invalidNodeIds = opts.invalidNodeIds;
185
196
  deserialized.incompleteNodeIds = opts.incompleteNodeIds;
@@ -192,8 +203,6 @@ class RequestGraph extends _graph().ContentGraph {
192
203
  deserialized.configKeyNodes = opts.configKeyNodes;
193
204
  return deserialized;
194
205
  }
195
-
196
- // $FlowFixMe[prop-missing]
197
206
  serialize() {
198
207
  return {
199
208
  ...super.serialize(),
@@ -333,6 +342,8 @@ class RequestGraph extends _graph().ContentGraph {
333
342
  let node = (0, _nullthrows().default)(this.getNode(nodeId));
334
343
  (0, _assert().default)(node.type === OPTION);
335
344
  const key = keyFromOptionContentKey(node.id);
345
+
346
+ // @ts-expect-error TS7053
336
347
  if ((0, _utils2.hashFromOption)(options[key]) !== node.hash) {
337
348
  invalidatedKeys.push(key);
338
349
  let parentNodes = this.getNodeIdsConnectedTo(nodeId, requestGraphEdgeTypes.invalidated_by_update);
@@ -371,9 +382,13 @@ class RequestGraph extends _graph().ContentGraph {
371
382
  }
372
383
  invalidateOnFileCreate(requestNodeId, input) {
373
384
  let node;
385
+ // @ts-expect-error TS2339
374
386
  if (input.glob != null) {
387
+ // @ts-expect-error TS2339
375
388
  node = nodeFromGlob(input.glob);
389
+ // @ts-expect-error TS2339
376
390
  } else if (input.fileName != null && input.aboveFilePath != null) {
391
+ // @ts-expect-error TS2339
377
392
  let aboveFilePath = input.aboveFilePath;
378
393
 
379
394
  // Create nodes and edges for each part of the filename pattern.
@@ -381,6 +396,7 @@ class RequestGraph extends _graph().ContentGraph {
381
396
  // This creates a sort of trie structure within the graph that can be
382
397
  // quickly matched by following the edges. This is also memory efficient
383
398
  // since common sub-paths (e.g. 'node_modules') are deduplicated.
399
+ // @ts-expect-error TS2339
384
400
  let parts = input.fileName.split('/').reverse();
385
401
  let lastNodeId;
386
402
  for (let part of parts) {
@@ -415,7 +431,9 @@ class RequestGraph extends _graph().ContentGraph {
415
431
  if (!this.hasEdge(lastNodeId, nodeId, requestGraphEdgeTypes.invalidated_by_create_above)) {
416
432
  this.addEdge(lastNodeId, nodeId, requestGraphEdgeTypes.invalidated_by_create_above);
417
433
  }
434
+ // @ts-expect-error TS2339
418
435
  } else if (input.filePath != null) {
436
+ // @ts-expect-error TS2339
419
437
  node = nodeFromFilePath(input.filePath);
420
438
  } else {
421
439
  throw new Error('Invalid invalidation');
@@ -434,8 +452,8 @@ class RequestGraph extends _graph().ContentGraph {
434
452
  this.invalidateOnBuildNodeIds.add(requestNodeId);
435
453
  }
436
454
  invalidateOnEnvChange(requestNodeId, env, value) {
437
- let envNode = nodeFromEnv(env, value);
438
- let envNodeId = this.addNode(envNode);
455
+ const envNode = nodeFromEnv(env, value);
456
+ const envNodeId = this.addNode(envNode);
439
457
  if (!this.hasEdge(requestNodeId, envNodeId, requestGraphEdgeTypes.invalidated_by_update)) {
440
458
  this.addEdge(requestNodeId, envNodeId, requestGraphEdgeTypes.invalidated_by_update);
441
459
  }
@@ -461,6 +479,7 @@ class RequestGraph extends _graph().ContentGraph {
461
479
 
462
480
  // For now just handling updates. Could add creates/deletes later if needed.
463
481
  let invalidations = this.getNodeIdsConnectedFrom(requestNodeId, requestGraphEdgeTypes.invalidated_by_update);
482
+ // @ts-expect-error TS2322
464
483
  return invalidations.map(nodeId => {
465
484
  let node = (0, _nullthrows().default)(this.getNode(nodeId));
466
485
  switch (node.type) {
@@ -582,10 +601,12 @@ class RequestGraph extends _graph().ContentGraph {
582
601
  aboveCache.set(fileNameNodeId, above);
583
602
  return above;
584
603
  };
604
+ const invalidationsByPath = new Map();
585
605
  for (let {
586
606
  path: _path,
587
607
  type
588
608
  } of events) {
609
+ const invalidationsBefore = this.getInvalidNodeCount();
589
610
  if (!enableOptimization && process.env.ATLASPACK_DISABLE_CACHE_TIMEOUT !== 'true' && ++count === 256) {
590
611
  let duration = Date.now() - startTime;
591
612
  predictedTime = duration * (events.length >> 8);
@@ -622,7 +643,10 @@ class RequestGraph extends _graph().ContentGraph {
622
643
  this.invalidNodeIds.add(id);
623
644
  }
624
645
  }
625
- return true;
646
+ return {
647
+ didInvalidate: true,
648
+ invalidationsByPath: new Map()
649
+ };
626
650
  }
627
651
 
628
652
  // sometimes mac os reports update events as create events.
@@ -679,10 +703,17 @@ class RequestGraph extends _graph().ContentGraph {
679
703
  this.removeNode(nodeId, removeOrphans);
680
704
  }
681
705
  let configKeyNodes = this.configKeyNodes.get(_filePath);
682
- if (configKeyNodes && (type === 'delete' || type === 'update')) {
706
+
707
+ // With granular invalidations we will always run this block,
708
+ // so even if we get a create event (for whatever reason), we will still
709
+ // try to limit invalidations from config key changes through hashing.
710
+ //
711
+ // Currently create events can invalidate a large number of nodes due to
712
+ // "create above" invalidations.
713
+ if (configKeyNodes) {
683
714
  for (let nodeId of configKeyNodes) {
684
715
  let isInvalid = type === 'delete';
685
- if (type === 'update') {
716
+ if (type !== 'delete') {
686
717
  let node = this.getNode(nodeId);
687
718
  (0, _assert().default)(node && node.type === CONFIG_KEY);
688
719
  let contentHash = await (0, _ConfigRequest.getConfigKeyContentHash)(_filePath, node.configKey, options);
@@ -697,6 +728,9 @@ class RequestGraph extends _graph().ContentGraph {
697
728
  }
698
729
  }
699
730
  }
731
+ const invalidationsAfter = this.getInvalidNodeCount();
732
+ const invalidationsForEvent = invalidationsAfter - invalidationsBefore;
733
+ invalidationsByPath.set(_path, (invalidationsByPath.get(_path) ?? 0) + invalidationsForEvent);
700
734
  }
701
735
  if ((0, _featureFlags().getFeatureFlag)('fixQuadraticCacheInvalidation')) {
702
736
  cleanUpOrphans(this);
@@ -714,7 +748,10 @@ class RequestGraph extends _graph().ContentGraph {
714
748
  numberOfInvalidatedNodes: invalidatedNodes.size
715
749
  }
716
750
  });
717
- return didInvalidate && this.invalidNodeIds.size > 0;
751
+ return {
752
+ didInvalidate,
753
+ invalidationsByPath
754
+ };
718
755
  }
719
756
  hasCachedRequestChunk(index) {
720
757
  return this.cachedRequestChunks.has(index);
@@ -725,6 +762,13 @@ class RequestGraph extends _graph().ContentGraph {
725
762
  removeCachedRequestChunkForNode(nodeId) {
726
763
  this.cachedRequestChunks.delete(Math.floor(nodeId / this.nodesPerBlob));
727
764
  }
765
+
766
+ /**
767
+ * Returns the number of invalidated nodes in the graph.
768
+ */
769
+ getInvalidNodeCount() {
770
+ return this.invalidNodeIds.size;
771
+ }
728
772
  }
729
773
  exports.RequestGraph = RequestGraph;
730
774
  class RequestTracker {
@@ -740,11 +784,6 @@ class RequestTracker {
740
784
  this.options = options;
741
785
  this.rustAtlaspack = rustAtlaspack;
742
786
  }
743
-
744
- // TODO: refactor (abortcontroller should be created by RequestTracker)
745
- setSignal(signal) {
746
- this.signal = signal;
747
- }
748
787
  startRequest(request) {
749
788
  let didPreviouslyExist = this.graph.hasContentKey(request.id);
750
789
  let requestNodeId;
@@ -762,6 +801,7 @@ class RequestTracker {
762
801
  promise,
763
802
  deferred
764
803
  } = (0, _utils().makeDeferredWithPromise)();
804
+ // @ts-expect-error TS2345
765
805
  this.graph.incompleteNodePromises.set(requestNodeId, promise);
766
806
  return {
767
807
  requestNodeId,
@@ -787,7 +827,6 @@ class RequestTracker {
787
827
  return null;
788
828
  }
789
829
  if (node.result != undefined) {
790
- // $FlowFixMe
791
830
  let result = node.result;
792
831
  return result;
793
832
  } else if (node.resultCacheKey != null && ifMatch == null) {
@@ -841,7 +880,7 @@ class RequestTracker {
841
880
  let requestId = hasKey ? this.graph.getNodeIdByContentKey(request.id) : undefined;
842
881
  let hasValidResult = requestId != null && this.hasValidResult(requestId);
843
882
  if (!(opts !== null && opts !== void 0 && opts.force) && hasValidResult) {
844
- // $FlowFixMe[incompatible-type]
883
+ // @ts-expect-error TS2322
845
884
  return this.getRequestResult(request.id);
846
885
  }
847
886
  if (requestId != null) {
@@ -850,7 +889,7 @@ class RequestTracker {
850
889
  // There is a another instance of this request already running, wait for its completion and reuse its result
851
890
  try {
852
891
  if (await incompletePromise) {
853
- // $FlowFixMe[incompatible-type]
892
+ // @ts-expect-error TS2322
854
893
  return this.getRequestResult(request.id);
855
894
  }
856
895
  } catch (e) {
@@ -883,7 +922,6 @@ class RequestTracker {
883
922
  options: this.options,
884
923
  rustAtlaspack: this.rustAtlaspack
885
924
  });
886
- (0, _utils2.assertSignalNotAborted)(this.signal);
887
925
  this.completeRequest(requestNodeId);
888
926
  deferred.resolve(true);
889
927
  return result;
@@ -921,40 +959,45 @@ class RequestTracker {
921
959
  }
922
960
  createAPI(requestId, previousInvalidations) {
923
961
  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);
962
+ let api = {
963
+ invalidateOnFileCreate: input => this.graph.invalidateOnFileCreate(requestId, input),
964
+ invalidateOnConfigKeyChange: (filePath, configKey, contentHash) => this.graph.invalidateOnConfigKeyChange(requestId, filePath, configKey, contentHash),
965
+ invalidateOnFileDelete: filePath => this.graph.invalidateOnFileDelete(requestId, filePath),
966
+ invalidateOnFileUpdate: filePath => this.graph.invalidateOnFileUpdate(requestId, filePath),
967
+ invalidateOnStartup: () => this.graph.invalidateOnStartup(requestId),
968
+ invalidateOnBuild: () => this.graph.invalidateOnBuild(requestId),
969
+ invalidateOnEnvChange: env => this.graph.invalidateOnEnvChange(requestId, env, this.options.env[env]),
970
+ invalidateOnOptionChange: option => this.graph.invalidateOnOptionChange(requestId, option,
971
+ // @ts-expect-error TS7053
972
+ this.options[option]),
973
+ getInvalidations: () => previousInvalidations,
974
+ storeResult: (result, cacheKey) => {
975
+ this.storeResult(requestId, result, cacheKey);
976
+ },
977
+ getSubRequests: () => this.graph.getSubRequests(requestId),
978
+ getInvalidSubRequests: () => this.graph.getInvalidSubRequests(requestId),
979
+ getPreviousResult: ifMatch => {
980
+ var _this$graph$getNode;
981
+ let contentKey = (0, _nullthrows().default)((_this$graph$getNode = this.graph.getNode(requestId)) === null || _this$graph$getNode === void 0 ? void 0 : _this$graph$getNode.id);
982
+ return this.getRequestResult(contentKey, ifMatch);
983
+ },
984
+ getRequestResult: (
985
+ // @ts-expect-error TS7006
986
+ id) => this.getRequestResult(id),
987
+ canSkipSubrequest: contentKey => {
988
+ if (this.graph.hasContentKey(contentKey) && this.hasValidResult(this.graph.getNodeIdByContentKey(contentKey))) {
989
+ subRequestContentKeys.add(contentKey);
990
+ return true;
956
991
  }
992
+ return false;
957
993
  },
994
+ runRequest: (subRequest, opts) => {
995
+ subRequestContentKeys.add(subRequest.id);
996
+ return this.runRequest(subRequest, opts);
997
+ }
998
+ };
999
+ return {
1000
+ api,
958
1001
  subRequestContentKeys
959
1002
  };
960
1003
  }
@@ -970,84 +1013,90 @@ class RequestTracker {
970
1013
  return result;
971
1014
  }
972
1015
  }
973
- await runCacheImprovements(async cache => {
974
- await cache.getNativeRef().startWriteTransaction();
975
- }, () => Promise.resolve());
976
1016
  let cacheKey = getCacheKey(this.options);
977
- let requestGraphKey = `requestGraph-${cacheKey}`;
1017
+ let requestGraphKey = (0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements') ? `${cacheKey}/RequestGraph` : `requestGraph-${cacheKey}`;
1018
+ let snapshotKey = (0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements') ? `${cacheKey}/snapshot` : `snapshot-${cacheKey}`;
978
1019
  if (this.options.shouldDisableCache) {
979
1020
  return;
980
1021
  }
981
1022
  let total = 0;
982
- (0, _ReporterRunner.report)({
983
- type: 'cache',
984
- phase: 'start',
985
- total,
986
- size: this.graph.nodes.length
987
- });
988
- let serialisedGraph = this.graph.serialize();
989
-
990
- // Delete an existing request graph cache, to prevent invalid states
991
- await this.options.cache.deleteLargeBlob(requestGraphKey);
992
- const serialiseAndSet = async (key, contents) => {
993
- if (signal !== null && signal !== void 0 && signal.aborted) {
994
- throw new Error('Serialization was aborted');
995
- }
996
- await runCacheImprovements(cache => {
997
- (0, _logger().instrument)(`cache.put(${key})`, () => {
998
- cache.getNativeRef().putNoConfirm(key, (0, _buildCache().serialize)(contents));
999
- });
1000
- return Promise.resolve();
1001
- }, async () => {
1002
- await this.options.cache.setLargeBlob(key, (0, _buildCache().serialize)(contents), signal ? {
1003
- signal: signal
1004
- } : undefined);
1005
- });
1006
- total += 1;
1023
+ await runCacheImprovements(async cache => {
1024
+ await cache.getNativeRef().startWriteTransaction();
1025
+ }, () => Promise.resolve());
1026
+ try {
1007
1027
  (0, _ReporterRunner.report)({
1008
1028
  type: 'cache',
1009
- phase: 'write',
1029
+ phase: 'start',
1010
1030
  total,
1011
1031
  size: this.graph.nodes.length
1012
1032
  });
1013
- };
1014
- let queue = new (_utils().PromiseQueue)({
1015
- maxConcurrent: 32
1016
- });
1033
+ if ((0, _featureFlags().getFeatureFlag)('environmentDeduplication')) {
1034
+ await (0, _EnvironmentManager.writeEnvironmentsToCache)(options.cache);
1035
+ }
1036
+ let serialisedGraph = this.graph.serialize();
1037
+
1038
+ // Delete an existing request graph cache, to prevent invalid states
1039
+ await this.options.cache.deleteLargeBlob(requestGraphKey);
1040
+ const serialiseAndSet = async (key, contents) => {
1041
+ if (signal !== null && signal !== void 0 && signal.aborted) {
1042
+ throw new Error('Serialization was aborted');
1043
+ }
1044
+ await runCacheImprovements(cache => {
1045
+ (0, _logger().instrument)(`RequestTracker::writeToCache::cache.put(${key})`, () => {
1046
+ cache.getNativeRef().putNoConfirm(key, (0, _buildCache().serialize)(contents));
1047
+ });
1048
+ return Promise.resolve();
1049
+ }, async () => {
1050
+ await this.options.cache.setLargeBlob(key, (0, _buildCache().serialize)(contents), signal ? {
1051
+ signal: signal
1052
+ } : undefined);
1053
+ });
1054
+ total += 1;
1055
+ (0, _ReporterRunner.report)({
1056
+ type: 'cache',
1057
+ phase: 'write',
1058
+ total,
1059
+ size: this.graph.nodes.length
1060
+ });
1061
+ };
1062
+ let queue = new (_utils().PromiseQueue)({
1063
+ maxConcurrent: 32
1064
+ });
1017
1065
 
1018
- // Preallocating a sparse array is faster than pushing when N is high enough
1019
- let cacheableNodes = new Array(serialisedGraph.nodes.length);
1020
- for (let i = 0; i < serialisedGraph.nodes.length; i += 1) {
1021
- let node = serialisedGraph.nodes[i];
1022
- let resultCacheKey = node === null || node === void 0 ? void 0 : node.resultCacheKey;
1023
- if ((node === null || node === void 0 ? void 0 : node.type) === REQUEST && resultCacheKey != null && (node === null || node === void 0 ? void 0 : node.result) != null) {
1024
- queue.add(() => serialiseAndSet(resultCacheKey, node.result));
1066
+ // Preallocating a sparse array is faster than pushing when N is high enough
1067
+ let cacheableNodes = new Array(serialisedGraph.nodes.length);
1068
+ for (let i = 0; i < serialisedGraph.nodes.length; i += 1) {
1069
+ let node = serialisedGraph.nodes[i];
1025
1070
 
1026
- // eslint-disable-next-line no-unused-vars
1027
- let {
1028
- result: _,
1029
- ...newNode
1030
- } = node;
1031
- cacheableNodes[i] = newNode;
1032
- } else {
1033
- cacheableNodes[i] = node;
1071
+ // @ts-expect-error TS2339
1072
+ let resultCacheKey = node === null || node === void 0 ? void 0 : node.resultCacheKey;
1073
+ if ((node === null || node === void 0 ? void 0 : node.type) === REQUEST && resultCacheKey != null && (node === null || node === void 0 ? void 0 : node.result) != null) {
1074
+ queue.add(() => serialiseAndSet(resultCacheKey, node.result));
1075
+
1076
+ // eslint-disable-next-line no-unused-vars
1077
+ let {
1078
+ result: _,
1079
+ ...newNode
1080
+ } = node;
1081
+ cacheableNodes[i] = newNode;
1082
+ } else {
1083
+ cacheableNodes[i] = node;
1084
+ }
1034
1085
  }
1035
- }
1036
- let nodeCountsPerBlob = [];
1037
- for (let i = 0; i * this.graph.nodesPerBlob < cacheableNodes.length; i += 1) {
1038
- let nodesStartIndex = i * this.graph.nodesPerBlob;
1039
- let nodesEndIndex = Math.min((i + 1) * this.graph.nodesPerBlob, cacheableNodes.length);
1040
- nodeCountsPerBlob.push(nodesEndIndex - nodesStartIndex);
1041
- if (!this.graph.hasCachedRequestChunk(i)) {
1042
- // We assume the request graph nodes are immutable and won't change
1043
- let nodesToCache = cacheableNodes.slice(nodesStartIndex, nodesEndIndex);
1044
- queue.add(() => serialiseAndSet(getRequestGraphNodeKey(i, cacheKey), nodesToCache).then(() => {
1045
- // Succeeded in writing to disk, save that we have completed this chunk
1046
- this.graph.setCachedRequestChunk(i);
1047
- }));
1086
+ let nodeCountsPerBlob = [];
1087
+ for (let i = 0; i * this.graph.nodesPerBlob < cacheableNodes.length; i += 1) {
1088
+ let nodesStartIndex = i * this.graph.nodesPerBlob;
1089
+ let nodesEndIndex = Math.min((i + 1) * this.graph.nodesPerBlob, cacheableNodes.length);
1090
+ nodeCountsPerBlob.push(nodesEndIndex - nodesStartIndex);
1091
+ if (!this.graph.hasCachedRequestChunk(i)) {
1092
+ // We assume the request graph nodes are immutable and won't change
1093
+ let nodesToCache = cacheableNodes.slice(nodesStartIndex, nodesEndIndex);
1094
+ queue.add(() => serialiseAndSet(getRequestGraphNodeKey(i, cacheKey), nodesToCache).then(() => {
1095
+ // Succeeded in writing to disk, save that we have completed this chunk
1096
+ this.graph.setCachedRequestChunk(i);
1097
+ }));
1098
+ }
1048
1099
  }
1049
- }
1050
- try {
1051
1100
  await queue.run();
1052
1101
 
1053
1102
  // Set the request graph after the queue is flushed to avoid writing an invalid state
@@ -1056,7 +1105,7 @@ class RequestTracker {
1056
1105
  nodeCountsPerBlob,
1057
1106
  nodes: undefined
1058
1107
  });
1059
- await runCacheImprovements(() => serialiseAndSet(`request_tracker:cache_metadata:${cacheKey}`, {
1108
+ await runCacheImprovements(() => serialiseAndSet(`${cacheKey}/cache_metadata`, {
1060
1109
  version: _constants.ATLASPACK_VERSION,
1061
1110
  entries: this.options.entries,
1062
1111
  mode: this.options.mode,
@@ -1064,15 +1113,16 @@ class RequestTracker {
1064
1113
  watchBackend: this.options.watchBackend
1065
1114
  }), () => Promise.resolve());
1066
1115
  let opts = getWatcherOptions(this.options);
1067
- let snapshotPath = _path2().default.join(this.options.cacheDir, `snapshot-${cacheKey}` + '.txt');
1116
+ let snapshotPath = _path2().default.join(this.options.cacheDir, snapshotKey + '.txt');
1068
1117
  await this.options.outputFS.writeSnapshot(this.options.watchDir, snapshotPath, opts);
1069
1118
  } catch (err) {
1070
1119
  // If we have aborted, ignore the error and continue
1071
1120
  if (!(signal !== null && signal !== void 0 && signal.aborted)) throw err;
1121
+ } finally {
1122
+ await runCacheImprovements(async cache => {
1123
+ await cache.getNativeRef().commitWriteTransaction();
1124
+ }, () => Promise.resolve());
1072
1125
  }
1073
- await runCacheImprovements(async cache => {
1074
- await cache.getNativeRef().commitWriteTransaction();
1075
- }, () => Promise.resolve());
1076
1126
  (0, _ReporterRunner.report)({
1077
1127
  type: 'cache',
1078
1128
  phase: 'end',
@@ -1101,7 +1151,8 @@ function getWatcherOptions({
1101
1151
  watchDir,
1102
1152
  watchBackend
1103
1153
  }) {
1104
- const uniqueDirs = [...new Set([...watchIgnore, ...['.git', '.hg'], cacheDir])];
1154
+ const vcsDirs = ['.git', '.hg'];
1155
+ const uniqueDirs = [...new Set([...watchIgnore, ...vcsDirs, cacheDir])];
1105
1156
  const ignore = uniqueDirs.map(dir => _path2().default.resolve(watchDir, dir));
1106
1157
  return {
1107
1158
  ignore,
@@ -1109,20 +1160,35 @@ function getWatcherOptions({
1109
1160
  };
1110
1161
  }
1111
1162
  function getCacheKey(options) {
1163
+ if ((0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements')) {
1164
+ const hash = (0, _rust().hashString)(`${_constants.ATLASPACK_VERSION}:${JSON.stringify(options.entries)}:${options.mode}:${options.shouldBuildLazily ? 'lazy' : 'eager'}:${options.watchBackend ?? ''}`);
1165
+ return `RequestTracker/${_constants.ATLASPACK_VERSION}/${hash}`;
1166
+ }
1112
1167
  return (0, _rust().hashString)(`${_constants.ATLASPACK_VERSION}:${JSON.stringify(options.entries)}:${options.mode}:${options.shouldBuildLazily ? 'lazy' : 'eager'}:${options.watchBackend ?? ''}`);
1113
1168
  }
1114
1169
  function getRequestGraphNodeKey(index, cacheKey) {
1170
+ if ((0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements')) {
1171
+ return `${cacheKey}/RequestGraph/nodes/${index}`;
1172
+ }
1115
1173
  return `requestGraph-nodes-${index}-${cacheKey}`;
1116
1174
  }
1117
1175
  async function readAndDeserializeRequestGraph(cache, requestGraphKey, cacheKey) {
1118
1176
  let bufferLength = 0;
1119
1177
  const getAndDeserialize = async key => {
1120
- let buffer = await cache.getLargeBlob(key);
1121
- bufferLength += Buffer.byteLength(buffer);
1122
- return (0, _buildCache().deserialize)(buffer);
1178
+ if ((0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements')) {
1179
+ const buffer = await cache.getBlob(key);
1180
+ bufferLength += Buffer.byteLength(buffer);
1181
+ return (0, _buildCache().deserialize)(buffer);
1182
+ } else {
1183
+ const buffer = await cache.getLargeBlob(key);
1184
+ bufferLength += Buffer.byteLength(buffer);
1185
+ return (0, _buildCache().deserialize)(buffer);
1186
+ }
1123
1187
  };
1124
1188
  let serializedRequestGraph = await getAndDeserialize(requestGraphKey);
1125
- let nodePromises = serializedRequestGraph.nodeCountsPerBlob.map(async (nodesCount, i) => {
1189
+ let nodePromises = serializedRequestGraph.nodeCountsPerBlob.map(
1190
+ // @ts-expect-error TS7006
1191
+ async (nodesCount, i) => {
1126
1192
  let nodes = await getAndDeserialize(getRequestGraphNodeKey(i, cacheKey));
1127
1193
  _assert().default.equal(nodes.length, nodesCount, 'RequestTracker node chunk: invalid node count');
1128
1194
  return nodes;
@@ -1141,9 +1207,9 @@ async function loadRequestGraph(options) {
1141
1207
  return new RequestGraph();
1142
1208
  }
1143
1209
  let cacheKey = getCacheKey(options);
1144
- let requestGraphKey = `requestGraph-${cacheKey}`;
1210
+ let requestGraphKey = (0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements') ? `${cacheKey}/RequestGraph` : `requestGraph-${cacheKey}`;
1145
1211
  let timeout;
1146
- const snapshotKey = `snapshot-${cacheKey}`;
1212
+ const snapshotKey = (0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements') ? `${cacheKey}/snapshot` : `snapshot-${cacheKey}`;
1147
1213
  const snapshotPath = _path2().default.join(options.cacheDir, snapshotKey + '.txt');
1148
1214
  const commonMeta = {
1149
1215
  cacheKey,
@@ -1163,7 +1229,11 @@ async function loadRequestGraph(options) {
1163
1229
  ...commonMeta
1164
1230
  }
1165
1231
  });
1166
- if (await options.cache.hasLargeBlob(requestGraphKey)) {
1232
+ if ((0, _featureFlags().getFeatureFlag)('environmentDeduplication')) {
1233
+ await (0, _EnvironmentManager.loadEnvironmentsFromCache)(options.cache);
1234
+ }
1235
+ const hasRequestGraphInCache = (0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements') ? await options.cache.has(requestGraphKey) : await options.cache.hasLargeBlob(requestGraphKey);
1236
+ if (hasRequestGraphInCache) {
1167
1237
  try {
1168
1238
  let {
1169
1239
  requestGraph
@@ -1188,23 +1258,16 @@ async function loadRequestGraph(options) {
1188
1258
  duration: Date.now() - startTime
1189
1259
  }
1190
1260
  });
1191
- if ((0, _featureFlags().getFeatureFlag)('verboseRequestInvalidationStats')) {
1192
- const invalidationStats = await invalidateRequestGraph(requestGraph, options, events);
1193
- _logger().default.verbose({
1194
- origin: '@atlaspack/core',
1195
- message: 'Request track loaded from cache',
1196
- meta: {
1197
- ...commonMeta,
1198
- trackableEvent: 'request_tracker_cache_key_hit',
1199
- invalidationStats
1200
- }
1201
- });
1202
- } else {
1203
- requestGraph.invalidateUnpredictableNodes();
1204
- requestGraph.invalidateOnBuildNodes();
1205
- requestGraph.invalidateEnvNodes(options.env);
1206
- requestGraph.invalidateOptionNodes(options);
1207
- }
1261
+ const invalidationStats = await invalidateRequestGraph(requestGraph, options, events);
1262
+ _logger().default.verbose({
1263
+ origin: '@atlaspack/core',
1264
+ message: 'Request track loaded from cache',
1265
+ meta: {
1266
+ ...commonMeta,
1267
+ trackableEvent: 'request_tracker_cache_key_hit',
1268
+ invalidationStats
1269
+ }
1270
+ });
1208
1271
  return requestGraph;
1209
1272
  } catch (e) {
1210
1273
  // Prevent logging fs events took too long warning
@@ -1230,6 +1293,20 @@ async function loadRequestGraph(options) {
1230
1293
  * A wrapper around an invalidation type / method
1231
1294
  */
1232
1295
 
1296
+ /**
1297
+ * Details about an invalidation.
1298
+ *
1299
+ * If this is a fs events invalidation, this key will contain statistics about invalidations
1300
+ * by path.
1301
+ *
1302
+ * If this is a env or option invalidation, this key will contain the list of changed environment
1303
+ * variables or options.
1304
+ */
1305
+
1306
+ /**
1307
+ * Number of invalidations for a given file-system event.
1308
+ */
1309
+
1233
1310
  /**
1234
1311
  * Information about a certain cache invalidation type.
1235
1312
  */
@@ -1243,9 +1320,11 @@ async function loadRequestGraph(options) {
1243
1320
  async function invalidateRequestGraph(requestGraph, options, events) {
1244
1321
  const invalidationFns = [{
1245
1322
  key: 'unpredictable',
1323
+ // @ts-expect-error TS2322
1246
1324
  fn: () => requestGraph.invalidateUnpredictableNodes()
1247
1325
  }, {
1248
1326
  key: 'onBuild',
1327
+ // @ts-expect-error TS2322
1249
1328
  fn: () => requestGraph.invalidateOnBuildNodes()
1250
1329
  }, {
1251
1330
  key: 'env',
@@ -1255,9 +1334,7 @@ async function invalidateRequestGraph(requestGraph, options, events) {
1255
1334
  fn: () => requestGraph.invalidateOptionNodes(options)
1256
1335
  }, {
1257
1336
  key: 'fsEvents',
1258
- fn: async () => {
1259
- await requestGraph.respondToFSEvents(options.unstableFileInvalidations || events, options, 10000, true);
1260
- }
1337
+ fn: () => invalidateRequestGraphFSEvents(requestGraph, options, events)
1261
1338
  }];
1262
1339
  const invalidations = [];
1263
1340
  for (const invalidation of invalidationFns) {
@@ -1266,27 +1343,45 @@ async function invalidateRequestGraph(requestGraph, options, events) {
1266
1343
  const invalidatedCount = invalidations.reduce((acc, invalidation) => acc + invalidation.count, 0);
1267
1344
  const requestCount = requestGraph.nodes.reduce((acc, node) => acc + ((node === null || node === void 0 ? void 0 : node.type) === REQUEST ? 1 : 0), 0);
1268
1345
  const nodeCount = requestGraph.nodes.length;
1346
+ const nodeInvalidationRatio = invalidatedCount / nodeCount;
1347
+ const requestInvalidationRatio = invalidatedCount / requestCount;
1269
1348
  return {
1270
1349
  invalidations,
1271
1350
  nodeCount,
1272
1351
  requestCount,
1273
1352
  invalidatedCount,
1274
- nodeInvalidationRatio: invalidatedCount / nodeCount,
1275
- requestInvalidationRatio: invalidatedCount / requestCount
1353
+ nodeInvalidationRatio,
1354
+ requestInvalidationRatio
1355
+ };
1356
+ }
1357
+ /**
1358
+ * Invalidate the request graph based on file-system events.
1359
+ *
1360
+ * Returns statistics about the invalidations.
1361
+ */
1362
+ async function invalidateRequestGraphFSEvents(requestGraph, options, events) {
1363
+ const {
1364
+ invalidationsByPath
1365
+ } = await requestGraph.respondToFSEvents(options.unstableFileInvalidations || events, options, 10000, true);
1366
+ const biggestInvalidations = getBiggestFSEventsInvalidations(invalidationsByPath);
1367
+ return {
1368
+ biggestInvalidations
1276
1369
  };
1277
1370
  }
1278
-
1279
1371
  /**
1280
1372
  * Runs an invalidation function and reports metrics.
1281
1373
  */
1282
1374
  async function runInvalidation(requestGraph, invalidationFn) {
1283
- const startInvalidationCount = requestGraph.invalidNodeIds.size;
1375
+ const start = _perf_hooks().performance.now();
1376
+ const startInvalidationCount = requestGraph.getInvalidNodeCount();
1284
1377
  const result = await invalidationFn.fn();
1285
- const count = requestGraph.invalidNodeIds.size - startInvalidationCount;
1378
+ const count = requestGraph.getInvalidNodeCount() - startInvalidationCount;
1379
+ const duration = _perf_hooks().performance.now() - start;
1286
1380
  return {
1287
1381
  key: invalidationFn.key,
1288
1382
  count,
1289
- changes: typeof result === 'object' && Array.isArray(result) ? result : null
1383
+ detail: result ?? null,
1384
+ duration
1290
1385
  };
1291
1386
  }
1292
1387
  function logErrorOnBailout(options, snapshotPath, e) {
@@ -1328,4 +1423,19 @@ function cleanUpOrphans(graph) {
1328
1423
  }
1329
1424
  });
1330
1425
  return removedNodeIds;
1426
+ }
1427
+
1428
+ /**
1429
+ * Returns paths that invalidated the most nodes
1430
+ */
1431
+ function getBiggestFSEventsInvalidations(invalidationsByPath, limit = 10) {
1432
+ const invalidations = [];
1433
+ for (const [path, count] of invalidationsByPath) {
1434
+ invalidations.push({
1435
+ path,
1436
+ count
1437
+ });
1438
+ }
1439
+ invalidations.sort((a, b) => b.count - a.count);
1440
+ return invalidations.slice(0, limit);
1331
1441
  }