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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (380) hide show
  1. package/CHANGELOG.md +1324 -0
  2. package/dist/AssetGraph.js +523 -0
  3. package/dist/Atlaspack.js +701 -0
  4. package/dist/AtlaspackConfig.js +324 -0
  5. package/dist/AtlaspackConfig.schema.js +117 -0
  6. package/dist/BundleGraph.js +1906 -0
  7. package/dist/CommittedAsset.js +142 -0
  8. package/dist/Dependency.js +125 -0
  9. package/dist/Environment.js +132 -0
  10. package/dist/EnvironmentManager.js +108 -0
  11. package/dist/IdentifierRegistry.js +38 -0
  12. package/dist/InternalConfig.js +37 -0
  13. package/dist/PackagerRunner.js +470 -0
  14. package/dist/ReporterRunner.js +151 -0
  15. package/dist/RequestTracker.js +1297 -0
  16. package/dist/SymbolPropagation.js +624 -0
  17. package/dist/TargetDescriptor.schema.js +146 -0
  18. package/dist/Transformation.js +514 -0
  19. package/dist/UncommittedAsset.js +310 -0
  20. package/dist/Validation.js +196 -0
  21. package/dist/applyRuntimes.js +384 -0
  22. package/dist/assetUtils.js +169 -0
  23. package/dist/atlaspack-v3/AtlaspackV3.js +83 -0
  24. package/dist/atlaspack-v3/NapiWorkerPool.js +114 -0
  25. package/dist/atlaspack-v3/fs.js +53 -0
  26. package/dist/atlaspack-v3/index.js +25 -0
  27. package/dist/atlaspack-v3/jsCallable.js +16 -0
  28. package/dist/atlaspack-v3/worker/compat/asset-symbols.js +190 -0
  29. package/dist/atlaspack-v3/worker/compat/bitflags.js +98 -0
  30. package/dist/atlaspack-v3/worker/compat/dependency.js +43 -0
  31. package/dist/atlaspack-v3/worker/compat/environment.js +57 -0
  32. package/dist/atlaspack-v3/worker/compat/index.js +24 -0
  33. package/dist/atlaspack-v3/worker/compat/mutable-asset.js +152 -0
  34. package/dist/atlaspack-v3/worker/compat/plugin-config.js +64 -0
  35. package/dist/atlaspack-v3/worker/compat/plugin-options.js +137 -0
  36. package/dist/atlaspack-v3/worker/compat/plugin-tracer.js +10 -0
  37. package/dist/atlaspack-v3/worker/compat/target.js +14 -0
  38. package/dist/atlaspack-v3/worker/side-effect-detector.js +243 -0
  39. package/dist/atlaspack-v3/worker/worker.js +398 -0
  40. package/dist/constants.js +17 -0
  41. package/dist/dumpGraphToGraphViz.js +281 -0
  42. package/dist/index.js +62 -0
  43. package/dist/loadAtlaspackPlugin.js +128 -0
  44. package/dist/loadDotEnv.js +41 -0
  45. package/dist/projectPath.js +83 -0
  46. package/dist/public/Asset.js +279 -0
  47. package/dist/public/Bundle.js +224 -0
  48. package/dist/public/BundleGraph.js +371 -0
  49. package/dist/public/BundleGroup.js +53 -0
  50. package/dist/public/Config.js +286 -0
  51. package/dist/public/Dependency.js +138 -0
  52. package/dist/public/Environment.js +278 -0
  53. package/dist/public/MutableBundleGraph.js +277 -0
  54. package/dist/public/PluginOptions.js +80 -0
  55. package/dist/public/Symbols.js +248 -0
  56. package/dist/public/Target.js +69 -0
  57. package/dist/registerCoreWithSerializer.js +38 -0
  58. package/dist/requests/AssetGraphRequest.js +430 -0
  59. package/dist/requests/AssetGraphRequestRust.js +471 -0
  60. package/dist/requests/AssetRequest.js +130 -0
  61. package/dist/requests/AtlaspackBuildRequest.js +98 -0
  62. package/dist/requests/AtlaspackConfigRequest.js +493 -0
  63. package/dist/requests/BundleGraphRequest.js +381 -0
  64. package/dist/requests/BundleGraphRequestRust.js +324 -0
  65. package/dist/requests/BundleGraphRequestUtils.js +262 -0
  66. package/dist/requests/ConfigRequest.js +246 -0
  67. package/dist/requests/DevDepRequest.js +204 -0
  68. package/dist/requests/EntryRequest.js +314 -0
  69. package/dist/requests/PackageRequest.js +89 -0
  70. package/dist/requests/PathRequest.js +349 -0
  71. package/dist/requests/TargetRequest.js +1316 -0
  72. package/dist/requests/ValidationRequest.js +49 -0
  73. package/dist/requests/WriteBundleRequest.js +522 -0
  74. package/dist/requests/WriteBundlesRequest.js +190 -0
  75. package/dist/requests/asset-graph-diff.js +128 -0
  76. package/dist/requests/asset-graph-dot.js +131 -0
  77. package/dist/resolveOptions.js +267 -0
  78. package/dist/rustWorkerThreadDylibHack.js +19 -0
  79. package/dist/serializerCore.browser.js +43 -0
  80. package/dist/summarizeRequest.js +39 -0
  81. package/dist/types.js +31 -0
  82. package/dist/utils.js +172 -0
  83. package/dist/worker.js +123 -0
  84. package/lib/AssetGraph.js +53 -15
  85. package/lib/Atlaspack.js +140 -56
  86. package/lib/AtlaspackConfig.js +17 -6
  87. package/lib/AtlaspackConfig.schema.js +16 -5
  88. package/lib/BundleGraph.js +390 -43
  89. package/lib/CommittedAsset.js +8 -2
  90. package/lib/Dependency.js +9 -3
  91. package/lib/Environment.js +16 -10
  92. package/lib/EnvironmentManager.js +143 -0
  93. package/lib/IdentifierRegistry.js +2 -4
  94. package/lib/InternalConfig.js +3 -2
  95. package/lib/PackagerRunner.js +46 -82
  96. package/lib/ReporterRunner.js +8 -12
  97. package/lib/RequestTracker.js +191 -152
  98. package/lib/SymbolPropagation.js +52 -29
  99. package/lib/TargetDescriptor.schema.js +10 -1
  100. package/lib/Transformation.js +68 -19
  101. package/lib/UncommittedAsset.js +17 -24
  102. package/lib/Validation.js +20 -5
  103. package/lib/applyRuntimes.js +98 -7
  104. package/lib/assetUtils.js +16 -6
  105. package/lib/atlaspack-v3/AtlaspackV3.js +58 -15
  106. package/lib/atlaspack-v3/NapiWorkerPool.js +63 -2
  107. package/lib/atlaspack-v3/fs.js +4 -1
  108. package/lib/atlaspack-v3/index.js +28 -1
  109. package/lib/atlaspack-v3/jsCallable.js +0 -2
  110. package/lib/atlaspack-v3/worker/compat/asset-symbols.js +7 -4
  111. package/lib/atlaspack-v3/worker/compat/bitflags.js +31 -25
  112. package/lib/atlaspack-v3/worker/compat/dependency.js +4 -1
  113. package/lib/atlaspack-v3/worker/compat/environment.js +10 -7
  114. package/lib/atlaspack-v3/worker/compat/index.js +0 -11
  115. package/lib/atlaspack-v3/worker/compat/mutable-asset.js +16 -11
  116. package/lib/atlaspack-v3/worker/compat/plugin-config.js +14 -35
  117. package/lib/atlaspack-v3/worker/compat/plugin-options.js +16 -2
  118. package/lib/atlaspack-v3/worker/compat/plugin-tracer.js +3 -0
  119. package/lib/atlaspack-v3/worker/compat/target.js +2 -0
  120. package/lib/atlaspack-v3/worker/index.js +3 -0
  121. package/lib/atlaspack-v3/worker/side-effect-detector.js +214 -0
  122. package/lib/atlaspack-v3/worker/worker.js +231 -79
  123. package/lib/constants.js +0 -1
  124. package/lib/dumpGraphToGraphViz.js +72 -17
  125. package/lib/index.js +46 -3
  126. package/lib/loadAtlaspackPlugin.js +2 -3
  127. package/lib/loadDotEnv.js +5 -2
  128. package/lib/projectPath.js +6 -1
  129. package/lib/public/Asset.js +22 -12
  130. package/lib/public/Bundle.js +16 -18
  131. package/lib/public/BundleGraph.js +27 -25
  132. package/lib/public/BundleGroup.js +5 -6
  133. package/lib/public/Config.js +118 -18
  134. package/lib/public/Dependency.js +9 -7
  135. package/lib/public/Environment.js +13 -8
  136. package/lib/public/MutableBundleGraph.js +56 -15
  137. package/lib/public/PluginOptions.js +2 -2
  138. package/lib/public/Symbols.js +12 -12
  139. package/lib/public/Target.js +8 -7
  140. package/lib/registerCoreWithSerializer.js +7 -4
  141. package/lib/requests/AssetGraphRequest.js +61 -40
  142. package/lib/requests/AssetGraphRequestRust.js +314 -82
  143. package/lib/requests/AssetRequest.js +24 -7
  144. package/lib/requests/AtlaspackBuildRequest.js +53 -7
  145. package/lib/requests/AtlaspackConfigRequest.js +29 -19
  146. package/lib/requests/BundleGraphRequest.js +61 -130
  147. package/lib/requests/BundleGraphRequestRust.js +381 -0
  148. package/lib/requests/BundleGraphRequestUtils.js +280 -0
  149. package/lib/requests/ConfigRequest.js +55 -7
  150. package/lib/requests/DevDepRequest.js +32 -6
  151. package/lib/requests/EntryRequest.js +4 -3
  152. package/lib/requests/PackageRequest.js +56 -12
  153. package/lib/requests/PathRequest.js +26 -6
  154. package/lib/requests/TargetRequest.js +129 -60
  155. package/lib/requests/ValidationRequest.js +6 -2
  156. package/lib/requests/WriteBundleRequest.js +329 -20
  157. package/lib/requests/WriteBundlesRequest.js +64 -10
  158. package/lib/requests/asset-graph-diff.js +13 -8
  159. package/lib/requests/asset-graph-dot.js +2 -8
  160. package/lib/resolveOptions.js +37 -14
  161. package/lib/rustWorkerThreadDylibHack.js +0 -1
  162. package/lib/serializerCore.browser.js +1 -2
  163. package/lib/summarizeRequest.js +1 -1
  164. package/lib/types/AssetGraph.d.ts +55 -0
  165. package/lib/types/Atlaspack.d.ts +52 -0
  166. package/lib/types/AtlaspackConfig.d.ts +65 -0
  167. package/lib/types/AtlaspackConfig.schema.d.ts +53 -0
  168. package/lib/types/BundleGraph.d.ts +232 -0
  169. package/lib/types/CommittedAsset.d.ts +23 -0
  170. package/lib/types/Dependency.d.ts +44 -0
  171. package/lib/types/Environment.d.ts +11 -0
  172. package/lib/types/EnvironmentManager.d.ts +37 -0
  173. package/lib/types/IdentifierRegistry.d.ts +6 -0
  174. package/lib/types/InternalConfig.d.ts +23 -0
  175. package/lib/types/PackagerRunner.d.ts +85 -0
  176. package/lib/types/ReporterRunner.d.ts +25 -0
  177. package/lib/types/RequestTracker.d.ts +385 -0
  178. package/lib/types/SymbolPropagation.d.ts +11 -0
  179. package/lib/types/TargetDescriptor.schema.d.ts +5 -0
  180. package/lib/types/Transformation.d.ts +72 -0
  181. package/lib/types/UncommittedAsset.d.ts +61 -0
  182. package/lib/types/Validation.d.ts +37 -0
  183. package/lib/types/applyRuntimes.d.ts +25 -0
  184. package/lib/types/assetUtils.d.ts +42 -0
  185. package/lib/types/atlaspack-v3/AtlaspackV3.d.ts +35 -0
  186. package/lib/types/atlaspack-v3/NapiWorkerPool.d.ts +13 -0
  187. package/lib/types/atlaspack-v3/fs.d.ts +13 -0
  188. package/lib/types/atlaspack-v3/index.d.ts +6 -0
  189. package/lib/types/atlaspack-v3/jsCallable.d.ts +1 -0
  190. package/lib/types/atlaspack-v3/worker/compat/asset-symbols.d.ts +51 -0
  191. package/lib/types/atlaspack-v3/worker/compat/bitflags.d.ts +14 -0
  192. package/lib/types/atlaspack-v3/worker/compat/dependency.d.ts +25 -0
  193. package/lib/types/atlaspack-v3/worker/compat/environment.d.ts +27 -0
  194. package/{src/atlaspack-v3/worker/compat/index.js → lib/types/atlaspack-v3/worker/compat/index.d.ts} +0 -2
  195. package/lib/types/atlaspack-v3/worker/compat/mutable-asset.d.ts +49 -0
  196. package/lib/types/atlaspack-v3/worker/compat/plugin-config.d.ts +29 -0
  197. package/lib/types/atlaspack-v3/worker/compat/plugin-options.d.ts +23 -0
  198. package/lib/types/atlaspack-v3/worker/compat/plugin-tracer.d.ts +5 -0
  199. package/lib/types/atlaspack-v3/worker/compat/target.d.ts +11 -0
  200. package/lib/types/atlaspack-v3/worker/side-effect-detector.d.ts +76 -0
  201. package/lib/types/atlaspack-v3/worker/worker.d.ts +81 -0
  202. package/lib/types/constants.d.ts +13 -0
  203. package/lib/types/dumpGraphToGraphViz.d.ts +10 -0
  204. package/lib/types/index.d.ts +8 -0
  205. package/lib/types/loadAtlaspackPlugin.d.ts +8 -0
  206. package/lib/types/loadDotEnv.d.ts +3 -0
  207. package/lib/types/projectPath.d.ts +19 -0
  208. package/lib/types/public/Asset.d.ts +74 -0
  209. package/lib/types/public/Bundle.d.ts +45 -0
  210. package/lib/types/public/BundleGraph.d.ts +72 -0
  211. package/lib/types/public/BundleGroup.d.ts +12 -0
  212. package/lib/types/public/Config.d.ts +75 -0
  213. package/lib/types/public/Dependency.d.ts +32 -0
  214. package/lib/types/public/Environment.d.ts +34 -0
  215. package/lib/types/public/MutableBundleGraph.d.ts +26 -0
  216. package/lib/types/public/PluginOptions.d.ts +25 -0
  217. package/lib/types/public/Symbols.d.ts +81 -0
  218. package/lib/types/public/Target.d.ts +16 -0
  219. package/lib/types/registerCoreWithSerializer.d.ts +2 -0
  220. package/lib/types/requests/AssetGraphRequest.d.ts +76 -0
  221. package/lib/types/requests/AssetGraphRequestRust.d.ts +21 -0
  222. package/lib/types/requests/AssetRequest.d.ts +16 -0
  223. package/lib/types/requests/AtlaspackBuildRequest.d.ts +33 -0
  224. package/lib/types/requests/AtlaspackConfigRequest.d.ts +45 -0
  225. package/lib/types/requests/BundleGraphRequest.d.ts +28 -0
  226. package/lib/types/requests/BundleGraphRequestRust.d.ts +34 -0
  227. package/lib/types/requests/BundleGraphRequestUtils.d.ts +38 -0
  228. package/lib/types/requests/ConfigRequest.d.ts +67 -0
  229. package/lib/types/requests/DevDepRequest.d.ts +30 -0
  230. package/lib/types/requests/EntryRequest.d.ts +36 -0
  231. package/lib/types/requests/PackageRequest.d.ts +27 -0
  232. package/lib/types/requests/PathRequest.d.ts +48 -0
  233. package/lib/types/requests/TargetRequest.d.ts +48 -0
  234. package/lib/types/requests/ValidationRequest.d.ts +20 -0
  235. package/lib/types/requests/WriteBundleRequest.d.ts +80 -0
  236. package/lib/types/requests/WriteBundlesRequest.d.ts +32 -0
  237. package/lib/types/requests/asset-graph-diff.d.ts +1 -0
  238. package/lib/types/requests/asset-graph-dot.d.ts +9 -0
  239. package/lib/types/resolveOptions.d.ts +3 -0
  240. package/lib/types/rustWorkerThreadDylibHack.d.ts +9 -0
  241. package/lib/types/serializerCore.browser.d.ts +3 -0
  242. package/lib/types/summarizeRequest.d.ts +10 -0
  243. package/lib/types/types.d.ts +496 -0
  244. package/lib/types/utils.d.ts +23 -0
  245. package/lib/types/worker.d.ts +44 -0
  246. package/lib/types.js +8 -1
  247. package/lib/utils.js +18 -3
  248. package/lib/worker.js +32 -15
  249. package/package.json +26 -36
  250. package/src/{AssetGraph.js → AssetGraph.ts} +87 -51
  251. package/src/{Atlaspack.js → Atlaspack.ts} +181 -72
  252. package/src/{AtlaspackConfig.schema.js → AtlaspackConfig.schema.ts} +25 -19
  253. package/src/{AtlaspackConfig.js → AtlaspackConfig.ts} +78 -54
  254. package/src/{BundleGraph.js → BundleGraph.ts} +575 -145
  255. package/src/{CommittedAsset.js → CommittedAsset.ts} +15 -13
  256. package/src/{Dependency.js → Dependency.ts} +59 -42
  257. package/src/{Environment.js → Environment.ts} +24 -15
  258. package/src/EnvironmentManager.ts +154 -0
  259. package/src/{IdentifierRegistry.js → IdentifierRegistry.ts} +1 -4
  260. package/src/{InternalConfig.js → InternalConfig.ts} +22 -23
  261. package/src/{PackagerRunner.js → PackagerRunner.ts} +114 -159
  262. package/src/{ReporterRunner.js → ReporterRunner.ts} +13 -18
  263. package/src/{RequestTracker.js → RequestTracker.ts} +444 -355
  264. package/src/{SymbolPropagation.js → SymbolPropagation.ts} +178 -61
  265. package/src/{TargetDescriptor.schema.js → TargetDescriptor.schema.ts} +10 -1
  266. package/src/{Transformation.js → Transformation.ts} +110 -65
  267. package/src/{UncommittedAsset.js → UncommittedAsset.ts} +45 -49
  268. package/src/{Validation.js → Validation.ts} +32 -17
  269. package/src/{applyRuntimes.js → applyRuntimes.ts} +135 -26
  270. package/src/{assetUtils.js → assetUtils.ts} +49 -36
  271. package/src/atlaspack-v3/AtlaspackV3.ts +183 -0
  272. package/src/atlaspack-v3/NapiWorkerPool.ts +129 -0
  273. package/src/atlaspack-v3/{fs.js → fs.ts} +8 -4
  274. package/src/atlaspack-v3/{index.js → index.ts} +3 -4
  275. package/src/atlaspack-v3/jsCallable.ts +14 -0
  276. package/src/atlaspack-v3/worker/compat/{asset-symbols.js → asset-symbols.ts} +40 -30
  277. package/src/atlaspack-v3/worker/compat/bitflags.ts +102 -0
  278. package/src/atlaspack-v3/worker/compat/{dependency.js → dependency.ts} +13 -13
  279. package/src/atlaspack-v3/worker/compat/{environment.js → environment.ts} +13 -9
  280. package/src/atlaspack-v3/worker/compat/index.ts +8 -0
  281. package/src/atlaspack-v3/worker/compat/{mutable-asset.js → mutable-asset.ts} +21 -20
  282. package/src/atlaspack-v3/worker/compat/{plugin-config.js → plugin-config.ts} +25 -56
  283. package/src/atlaspack-v3/worker/compat/{plugin-options.js → plugin-options.ts} +19 -5
  284. package/src/atlaspack-v3/worker/compat/{plugin-tracer.js → plugin-tracer.ts} +2 -2
  285. package/src/atlaspack-v3/worker/compat/{target.js → target.ts} +3 -4
  286. package/src/atlaspack-v3/worker/index.js +2 -1
  287. package/src/atlaspack-v3/worker/side-effect-detector.ts +298 -0
  288. package/src/atlaspack-v3/worker/worker.ts +548 -0
  289. package/src/{constants.js → constants.ts} +0 -3
  290. package/src/{dumpGraphToGraphViz.js → dumpGraphToGraphViz.ts} +73 -28
  291. package/src/index.ts +18 -0
  292. package/src/{loadAtlaspackPlugin.js → loadAtlaspackPlugin.ts} +8 -9
  293. package/src/{loadDotEnv.js → loadDotEnv.ts} +2 -2
  294. package/src/{projectPath.js → projectPath.ts} +20 -9
  295. package/src/public/{Asset.js → Asset.ts} +41 -28
  296. package/src/public/{Bundle.js → Bundle.ts} +28 -29
  297. package/src/public/{BundleGraph.js → BundleGraph.ts} +103 -68
  298. package/src/public/{BundleGroup.js → BundleGroup.ts} +7 -10
  299. package/src/public/{Config.js → Config.ts} +171 -33
  300. package/src/public/{Dependency.js → Dependency.ts} +20 -17
  301. package/src/public/{Environment.js → Environment.ts} +28 -17
  302. package/src/public/{MutableBundleGraph.js → MutableBundleGraph.ts} +55 -24
  303. package/src/public/{PluginOptions.js → PluginOptions.ts} +6 -6
  304. package/src/public/{Symbols.js → Symbols.ts} +75 -36
  305. package/src/public/{Target.js → Target.ts} +10 -8
  306. package/src/{registerCoreWithSerializer.js → registerCoreWithSerializer.ts} +9 -7
  307. package/src/requests/{AssetGraphRequest.js → AssetGraphRequest.ts} +117 -90
  308. package/src/requests/AssetGraphRequestRust.ts +557 -0
  309. package/src/requests/{AssetRequest.js → AssetRequest.ts} +24 -18
  310. package/src/requests/AtlaspackBuildRequest.ts +168 -0
  311. package/src/requests/{AtlaspackConfigRequest.js → AtlaspackConfigRequest.ts} +72 -58
  312. package/src/requests/{BundleGraphRequest.js → BundleGraphRequest.ts} +119 -199
  313. package/src/requests/BundleGraphRequestRust.ts +470 -0
  314. package/src/requests/BundleGraphRequestUtils.ts +323 -0
  315. package/src/requests/{ConfigRequest.js → ConfigRequest.ts} +110 -50
  316. package/src/requests/{DevDepRequest.js → DevDepRequest.ts} +60 -35
  317. package/src/requests/{EntryRequest.js → EntryRequest.ts} +36 -31
  318. package/src/requests/{PackageRequest.js → PackageRequest.ts} +52 -25
  319. package/src/requests/{PathRequest.js → PathRequest.ts} +47 -37
  320. package/src/requests/{TargetRequest.js → TargetRequest.ts} +265 -179
  321. package/src/requests/{ValidationRequest.js → ValidationRequest.ts} +18 -17
  322. package/src/requests/WriteBundleRequest.ts +734 -0
  323. package/src/requests/{WriteBundlesRequest.js → WriteBundlesRequest.ts} +134 -50
  324. package/src/requests/{asset-graph-diff.js → asset-graph-diff.ts} +25 -21
  325. package/src/requests/{asset-graph-dot.js → asset-graph-dot.ts} +8 -12
  326. package/src/{resolveOptions.js → resolveOptions.ts} +57 -27
  327. package/src/{rustWorkerThreadDylibHack.js → rustWorkerThreadDylibHack.ts} +1 -4
  328. package/src/{serializerCore.browser.js → serializerCore.browser.ts} +2 -3
  329. package/src/{summarizeRequest.js → summarizeRequest.ts} +17 -5
  330. package/src/types.ts +651 -0
  331. package/src/{utils.js → utils.ts} +52 -21
  332. package/src/{worker.js → worker.ts} +50 -42
  333. package/test/{AssetGraph.test.js → AssetGraph.test.ts} +5 -8
  334. package/test/{Atlaspack.test.js → Atlaspack.test.ts} +5 -10
  335. package/test/{AtlaspackConfig.test.js → AtlaspackConfig.test.ts} +0 -5
  336. package/test/{AtlaspackConfigRequest.test.js → AtlaspackConfigRequest.test.ts} +76 -16
  337. package/test/{BundleGraph.test.js → BundleGraph.test.ts} +8 -13
  338. package/test/{Dependency.test.js → Dependency.test.ts} +2 -3
  339. package/test/{EntryRequest.test.js → EntryRequest.test.ts} +1 -6
  340. package/test/Environment.test.ts +153 -0
  341. package/test/EnvironmentManager.test.ts +188 -0
  342. package/test/{IdentifierRegistry.test.js → IdentifierRegistry.test.ts} +2 -4
  343. package/test/{InternalAsset.test.js → InternalAsset.test.ts} +2 -7
  344. package/test/PackagerRunner.test.ts +0 -0
  345. package/test/{PublicAsset.test.js → PublicAsset.test.ts} +2 -7
  346. package/test/{PublicBundle.test.js → PublicBundle.test.ts} +1 -2
  347. package/test/{PublicDependency.test.js → PublicDependency.test.ts} +0 -2
  348. package/test/PublicEnvironment.test.ts +49 -0
  349. package/test/{PublicMutableBundleGraph.test.js → PublicMutableBundleGraph.test.ts} +6 -11
  350. package/test/{RequestTracker.test.js → RequestTracker.test.ts} +136 -58
  351. package/test/{SymbolPropagation.test.js → SymbolPropagation.test.ts} +124 -74
  352. package/test/{TargetRequest.test.js → TargetRequest.test.ts} +91 -92
  353. package/test/fixtures/config-with-reporters/.parcelrc +7 -0
  354. package/test/fixtures/custom-targets/package.json +6 -0
  355. package/test/public/Config.test.ts +104 -0
  356. package/test/requests/AssetGraphRequestRust.test.ts +443 -0
  357. package/test/requests/{ConfigRequest.test.js → ConfigRequest.test.ts} +202 -13
  358. package/test/requests/{DevDepRequest.test.js → DevDepRequest.test.ts} +0 -2
  359. package/test/requests/WriteBundleRequest.test.ts +602 -0
  360. package/test/{test-utils.js → test-utils.ts} +3 -4
  361. package/test/{utils.test.js → utils.test.ts} +1 -3
  362. package/tsconfig.json +60 -0
  363. package/tsconfig.tsbuildinfo +1 -0
  364. package/index.d.ts +0 -30
  365. package/lib/atlaspack-v3/worker/compat/plugin-logger.js +0 -29
  366. package/src/atlaspack-v3/AtlaspackV3.js +0 -87
  367. package/src/atlaspack-v3/NapiWorkerPool.js +0 -53
  368. package/src/atlaspack-v3/jsCallable.js +0 -18
  369. package/src/atlaspack-v3/worker/compat/bitflags.js +0 -100
  370. package/src/atlaspack-v3/worker/compat/plugin-logger.js +0 -47
  371. package/src/atlaspack-v3/worker/worker.js +0 -369
  372. package/src/index.js +0 -13
  373. package/src/requests/AssetGraphRequestRust.js +0 -263
  374. package/src/requests/AtlaspackBuildRequest.js +0 -111
  375. package/src/requests/WriteBundleRequest.js +0 -369
  376. package/src/types.js +0 -600
  377. package/test/Environment.test.js +0 -119
  378. package/test/PackagerRunner.test.js +0 -27
  379. package/test/PublicEnvironment.test.js +0 -27
  380. package/test/requests/AssetGraphRequestRust.test.js +0 -411
@@ -0,0 +1,183 @@
1
+ import {
2
+ atlaspackNapiCreate,
3
+ atlaspackNapiBuild,
4
+ atlaspackNapiBuildAssetGraph,
5
+ atlaspackNapiBuildBundleGraph,
6
+ atlaspackNapiRespondToFsEvents,
7
+ atlaspackNapiCompleteSession,
8
+ atlaspackNapiLoadBundleGraph,
9
+ atlaspackNapiPackage,
10
+ atlaspackNapiUpdateBundleGraph,
11
+ AtlaspackNapi,
12
+ Lmdb,
13
+ AtlaspackNapiOptions,
14
+ CacheStats,
15
+ PackageOptions,
16
+ } from '@atlaspack/rust';
17
+ import {NapiWorkerPool} from './NapiWorkerPool';
18
+ import ThrowableDiagnostic, {Diagnostic} from '@atlaspack/diagnostic';
19
+ import type {Event} from '@parcel/watcher';
20
+ import type {NapiWorkerPool as INapiWorkerPool} from '@atlaspack/types';
21
+ import type BundleGraph from '../BundleGraph';
22
+ import {RunPackagerRunnerResult} from '../PackagerRunner';
23
+
24
+ export type AtlaspackV3Options = {
25
+ fs?: AtlaspackNapiOptions['fs'];
26
+ packageManager?: AtlaspackNapiOptions['packageManager'];
27
+ threads?: number;
28
+ /**
29
+ * A reference to LMDB lite's rust object
30
+ */
31
+ lmdb: Lmdb;
32
+ featureFlags?: {
33
+ [key: string]: string | boolean;
34
+ };
35
+ napiWorkerPool?: INapiWorkerPool;
36
+ } & AtlaspackNapiOptions['options'];
37
+
38
+ export class AtlaspackV3 {
39
+ _atlaspack_napi: AtlaspackNapi;
40
+ _napiWorkerPool: INapiWorkerPool;
41
+ _isDefaultNapiWorkerPool: boolean;
42
+
43
+ constructor(
44
+ atlaspack_napi: AtlaspackNapi,
45
+ napiWorkerPool: INapiWorkerPool,
46
+ isDefaultNapiWorkerPool: boolean,
47
+ ) {
48
+ this._atlaspack_napi = atlaspack_napi;
49
+ this._napiWorkerPool = napiWorkerPool;
50
+ this._isDefaultNapiWorkerPool = isDefaultNapiWorkerPool;
51
+ }
52
+
53
+ static async create({
54
+ fs,
55
+ packageManager,
56
+ threads,
57
+ lmdb,
58
+ napiWorkerPool,
59
+ ...options
60
+ }: AtlaspackV3Options): Promise<AtlaspackV3> {
61
+ // @ts-expect-error TS2339
62
+ options.logLevel = options.logLevel || 'error';
63
+ // @ts-expect-error TS2339
64
+ options.defaultTargetOptions = options.defaultTargetOptions || {};
65
+ // @ts-expect-error TS2339
66
+ options.defaultTargetOptions.engines =
67
+ // @ts-expect-error TS2339
68
+ options.defaultTargetOptions.engines || {};
69
+
70
+ let isDefaultNapiWorkerPool = false;
71
+ if (!napiWorkerPool) {
72
+ napiWorkerPool = new NapiWorkerPool();
73
+ isDefaultNapiWorkerPool = true;
74
+ }
75
+
76
+ // @ts-expect-error TS2488
77
+ const [internal, error] = await atlaspackNapiCreate(
78
+ {
79
+ fs,
80
+ packageManager,
81
+ threads,
82
+ options,
83
+ napiWorkerPool,
84
+ },
85
+ lmdb,
86
+ );
87
+
88
+ if (error !== null) {
89
+ throw new ThrowableDiagnostic({
90
+ diagnostic: error,
91
+ });
92
+ }
93
+
94
+ return new AtlaspackV3(internal, napiWorkerPool, isDefaultNapiWorkerPool);
95
+ }
96
+
97
+ end(): void {
98
+ // If the worker pool was provided to us, don't shut it down, it's up to the provider.
99
+ if (this._isDefaultNapiWorkerPool) {
100
+ this._napiWorkerPool.shutdown();
101
+ }
102
+ }
103
+
104
+ buildAssetGraph(
105
+ progressCallback?: (eventJson: string) => void,
106
+ ): Promise<any> {
107
+ return atlaspackNapiBuildAssetGraph(
108
+ this._atlaspack_napi,
109
+ progressCallback,
110
+ ) as Promise<any>;
111
+ }
112
+
113
+ buildBundleGraph(
114
+ progressCallback?: (eventJson: string) => void,
115
+ ): Promise<any> {
116
+ return atlaspackNapiBuildBundleGraph(
117
+ this._atlaspack_napi,
118
+ progressCallback,
119
+ ) as Promise<any>;
120
+ }
121
+
122
+ build(progressCallback: (eventJson: string) => void): Promise<any> {
123
+ return atlaspackNapiBuild(
124
+ this._atlaspack_napi,
125
+ progressCallback,
126
+ ) as Promise<any>;
127
+ }
128
+
129
+ loadBundleGraph(bundleGraph: BundleGraph): Promise<void> {
130
+ const {nodesJson, edges, publicIdByAssetId, environmentsJson} =
131
+ bundleGraph.serializeForNative();
132
+
133
+ return atlaspackNapiLoadBundleGraph(
134
+ this._atlaspack_napi,
135
+ nodesJson,
136
+ edges,
137
+ publicIdByAssetId,
138
+ environmentsJson,
139
+ ) as Promise<void>;
140
+ }
141
+
142
+ updateBundleGraph(
143
+ bundleGraph: BundleGraph,
144
+ changedAssetIds: string[],
145
+ ): Promise<void> {
146
+ const nodesJson = bundleGraph.serializeAssetNodesForNative(changedAssetIds);
147
+ return atlaspackNapiUpdateBundleGraph(
148
+ this._atlaspack_napi,
149
+ nodesJson,
150
+ ) as Promise<void>;
151
+ }
152
+
153
+ package(
154
+ bundleId: string,
155
+ options?: PackageOptions,
156
+ ): Promise<[RunPackagerRunnerResult, Diagnostic | null]> {
157
+ return atlaspackNapiPackage(
158
+ this._atlaspack_napi,
159
+ bundleId,
160
+ options,
161
+ ) as Promise<[RunPackagerRunnerResult, Diagnostic | null]>;
162
+ }
163
+
164
+ async respondToFsEvents(events: Array<Event>): Promise<boolean> {
165
+ // @ts-expect-error TS2488
166
+ let [needsRebuild, error] = await atlaspackNapiRespondToFsEvents(
167
+ this._atlaspack_napi,
168
+ events,
169
+ );
170
+
171
+ if (error) {
172
+ throw new Error(error);
173
+ }
174
+
175
+ return needsRebuild;
176
+ }
177
+
178
+ async completeCacheSession(): Promise<CacheStats> {
179
+ return (await atlaspackNapiCompleteSession(
180
+ this._atlaspack_napi,
181
+ )) as CacheStats;
182
+ }
183
+ }
@@ -0,0 +1,129 @@
1
+ import type {NapiWorkerPool as INapiWorkerPool} from '@atlaspack/types';
2
+ import {Worker} from 'worker_threads';
3
+ import path from 'path';
4
+ import process from 'process';
5
+ // @ts-expect-error TS2724
6
+ import type {Transferable} from '@atlaspack/rust';
7
+ import {getAvailableThreads} from '@atlaspack/rust';
8
+ import logger from '@atlaspack/logger';
9
+ import type {LogEvent} from '@atlaspack/types-internal';
10
+
11
+ const WORKER_PATH = path.join(__dirname, 'worker', 'index.js');
12
+ const ATLASPACK_NAPI_WORKERS =
13
+ process.env.ATLASPACK_NAPI_WORKERS &&
14
+ parseInt(process.env.ATLASPACK_NAPI_WORKERS, 10);
15
+
16
+ export type NapiWorkerPoolOptions = {
17
+ workerCount?: number;
18
+ };
19
+
20
+ export class NapiWorkerPool implements INapiWorkerPool {
21
+ #workers: Worker[];
22
+ #napiWorkers: Array<Promise<Transferable>>;
23
+ #workerCount: number;
24
+
25
+ constructor({workerCount}: NapiWorkerPoolOptions = {workerCount: undefined}) {
26
+ // @ts-expect-error TS2322
27
+ this.#workerCount =
28
+ workerCount ??
29
+ ATLASPACK_NAPI_WORKERS ??
30
+ // Default to a maximum of 4 workers as performance worsens beyond that
31
+ // point in most cases
32
+ Math.min(getAvailableThreads(), 4);
33
+ if (!this.#workerCount) {
34
+ // TODO use main thread if workerCount is 0
35
+ }
36
+
37
+ this.#workers = [];
38
+ this.#napiWorkers = [];
39
+
40
+ for (let i = 0; i < this.#workerCount; i++) {
41
+ let worker = new Worker(WORKER_PATH);
42
+ this.#workers.push(worker);
43
+ this.#napiWorkers.push(
44
+ new Promise((res: (result: Promise<never>) => void) =>
45
+ worker.once('message', res),
46
+ ),
47
+ );
48
+
49
+ // Re-emit log events from the worker thread into the main-thread logger
50
+ // so they reach reporters and are subject to log-level filtering.
51
+ worker.on('message', (message: unknown) => {
52
+ if (
53
+ message != null &&
54
+ typeof message === 'object' &&
55
+ (message as {type?: unknown}).type === 'logEvent'
56
+ ) {
57
+ const event = (message as {type: string; event: LogEvent}).event;
58
+ switch (event.level) {
59
+ case 'verbose':
60
+ logger.verbose(event.diagnostics);
61
+ break;
62
+ case 'info':
63
+ logger.info(event.diagnostics);
64
+ break;
65
+ case 'warn':
66
+ logger.warn(event.diagnostics);
67
+ break;
68
+ case 'error':
69
+ logger.error(event.diagnostics);
70
+ break;
71
+ case 'progress':
72
+ logger.progress(event.message);
73
+ break;
74
+ }
75
+ }
76
+ });
77
+ }
78
+ }
79
+
80
+ clearAllWorkerState(): Promise<void[]> {
81
+ return Promise.all(
82
+ this.#workers.map(
83
+ (worker) =>
84
+ new Promise<void>((res) => {
85
+ worker.postMessage('clearState');
86
+
87
+ // Set up a message handler that only resolves on 'stateCleared'
88
+ // and ignores all other messages (like the initial napiWorker Transferable)
89
+ const messageHandler = (message: unknown) => {
90
+ if (message === 'stateCleared') {
91
+ worker.removeListener('message', messageHandler);
92
+ res();
93
+ } else if (
94
+ message != null &&
95
+ typeof message === 'object' &&
96
+ (message as {type?: unknown}).type === 'logEvent'
97
+ ) {
98
+ // logEvent messages are forwarded asynchronously from the worker
99
+ // logger bridge and are expected at any time; ignore them here.
100
+ } else {
101
+ // Log unexpected messages for debugging
102
+ // eslint-disable-next-line no-console
103
+ console.warn(
104
+ `[NapiWorkerPool] Received unexpected message during clearAllWorkerState: ${JSON.stringify(message)} (type: ${typeof message})`,
105
+ );
106
+ // Keep listening for 'stateCleared' - don't remove the listener
107
+ }
108
+ };
109
+
110
+ worker.on('message', messageHandler);
111
+ }),
112
+ ),
113
+ );
114
+ }
115
+
116
+ workerCount(): number {
117
+ return this.#workerCount;
118
+ }
119
+
120
+ getWorkers(): Promise<Array<Transferable>> {
121
+ return Promise.all(this.#napiWorkers);
122
+ }
123
+
124
+ shutdown(): void {
125
+ for (const worker of this.#workers) {
126
+ worker.terminate();
127
+ }
128
+ }
129
+ }
@@ -1,5 +1,4 @@
1
- // @flow strict-local
2
-
1
+ // @ts-expect-error TS2305
3
2
  import type {FileSystem, JsCallable} from '@atlaspack/rust';
4
3
  import type {
5
4
  Encoding,
@@ -9,6 +8,7 @@ import type {
9
8
 
10
9
  import {jsCallable} from './jsCallable';
11
10
 
11
+ // @ts-expect-error TS2420
12
12
  export class FileSystemV3 implements FileSystem {
13
13
  #fs: IFileSystem;
14
14
 
@@ -20,7 +20,7 @@ export class FileSystemV3 implements FileSystem {
20
20
  (path: FilePath) => this.#fs.realpathSync(path),
21
21
  );
22
22
 
23
- createDirectory: JsCallable<[FilePath], Promise<void>> = jsCallable(
23
+ createDirectory: JsCallable<[FilePath], Promise<undefined>> = jsCallable(
24
24
  (path: FilePath) => this.#fs.mkdirp(path),
25
25
  );
26
26
 
@@ -45,11 +45,15 @@ export class FileSystemV3 implements FileSystem {
45
45
  readFile: JsCallable<[FilePath, Encoding], string> = jsCallable(
46
46
  (path: string, encoding?: Encoding) => {
47
47
  if (!encoding) {
48
- // $FlowFixMe
49
48
  return [...this.#fs.readFileSync(path)];
50
49
  } else {
51
50
  return this.#fs.readFileSync(path, encoding);
52
51
  }
53
52
  },
54
53
  );
54
+
55
+ writeFile: JsCallable<[FilePath, number[]], Promise<void>> = jsCallable(
56
+ (path: FilePath, contents: number[]) =>
57
+ this.#fs.writeFile(path, Buffer.from(contents)),
58
+ );
55
59
  }
@@ -1,7 +1,6 @@
1
- // @flow
2
-
3
1
  export {FileSystemV3} from './fs';
4
2
  export {AtlaspackV3} from './AtlaspackV3';
5
3
  export {NapiWorkerPool} from './NapiWorkerPool';
6
- export type * from './AtlaspackV3';
7
- export type * from './NapiWorkerPool';
4
+ export * from './AtlaspackV3';
5
+ export * from './NapiWorkerPool';
6
+ export type {CacheStats} from '@atlaspack/rust';
@@ -0,0 +1,14 @@
1
+ export function jsCallable<Args extends ReadonlyArray<unknown>, Return>(
2
+ fn: (...rest: Args) => Return | Promise<Return>,
3
+ ): (...rest: Args) => Promise<Return> {
4
+ return async (...args: Args): Promise<Return> => {
5
+ try {
6
+ // Promises and is safe to use on non-promises
7
+ return await fn(...args);
8
+ } catch (error: any) {
9
+ // eslint-disable-next-line no-console
10
+ console.error(error);
11
+ throw error;
12
+ }
13
+ };
14
+ }
@@ -1,5 +1,3 @@
1
- // @flow
2
-
3
1
  import type {Symbol as NapiSymbol} from '@atlaspack/rust';
4
2
  import type {
5
3
  AssetSymbols as IAssetSymbols,
@@ -18,7 +16,7 @@ export class MutableDependencySymbols implements IMutableDependencySymbols {
18
16
  return this.#symbols.size === 0;
19
17
  }
20
18
 
21
- constructor(inner: ?(NapiSymbol[]) | null) {
19
+ constructor(inner: NapiSymbol[] | null | undefined | null) {
22
20
  this.#symbols = new Map();
23
21
  this.#locals = new Set();
24
22
  for (const {exported, local, loc, isWeak} of inner || []) {
@@ -30,7 +28,7 @@ export class MutableDependencySymbols implements IMutableDependencySymbols {
30
28
  throw new Error('MutableDependencySymbols.ensure()');
31
29
  }
32
30
 
33
- get(exportSymbol: Symbol): ?DependencyAssetSymbol {
31
+ get(exportSymbol: Symbol): DependencyAssetSymbol | null | undefined {
34
32
  return this.#symbols.get(exportSymbol);
35
33
  }
36
34
 
@@ -49,8 +47,8 @@ export class MutableDependencySymbols implements IMutableDependencySymbols {
49
47
  set(
50
48
  exportSymbol: Symbol,
51
49
  local: Symbol,
52
- loc: ?SourceLocation,
53
- isWeak: ?boolean,
50
+ loc?: SourceLocation | null,
51
+ isWeak?: boolean | null,
54
52
  ): void {
55
53
  this.#locals.add(local);
56
54
  this.#symbols.set(exportSymbol, {
@@ -69,7 +67,7 @@ export class MutableDependencySymbols implements IMutableDependencySymbols {
69
67
  }
70
68
 
71
69
  /*:: @@iterator(): Iterator<[Symbol, DependencyAssetSymbol]> { return ({}: any); } */
72
- // $FlowFixMe Flow can't do computed properties
70
+ // @ts-expect-error TS2416
73
71
  [Symbol.iterator]() {
74
72
  return this.#symbols.values();
75
73
  }
@@ -83,7 +81,7 @@ export class AssetSymbols implements IAssetSymbols {
83
81
  return this.#symbols.size === 0;
84
82
  }
85
83
 
86
- constructor(inner: ?(NapiSymbol[]) | null) {
84
+ constructor(inner: NapiSymbol[] | null | undefined | null) {
87
85
  this.#symbols = new Map();
88
86
  this.#locals = new Set();
89
87
  for (const {exported, local, loc} of inner || []) {
@@ -91,7 +89,11 @@ export class AssetSymbols implements IAssetSymbols {
91
89
  }
92
90
  }
93
91
 
94
- #set(exportSymbol: Symbol, local: Symbol, loc: ?SourceLocation): void {
92
+ #set(
93
+ exportSymbol: Symbol,
94
+ local: Symbol,
95
+ loc?: SourceLocation | null,
96
+ ): undefined {
95
97
  this.#locals.add(local);
96
98
  this.#symbols.set(exportSymbol, {
97
99
  local,
@@ -100,7 +102,7 @@ export class AssetSymbols implements IAssetSymbols {
100
102
  });
101
103
  }
102
104
 
103
- get(exportSymbol: Symbol): ?AssetSymbol {
105
+ get(exportSymbol: Symbol): AssetSymbol | null | undefined {
104
106
  return this.#symbols.get(exportSymbol);
105
107
  }
106
108
 
@@ -121,7 +123,7 @@ export class AssetSymbols implements IAssetSymbols {
121
123
  }
122
124
 
123
125
  /*:: @@iterator(): Iterator<[Symbol, AssetSymbol]> { return ({}: any); } */
124
- // $FlowFixMe Flow can't do computed properties
126
+ // @ts-expect-error TS2416
125
127
  [Symbol.iterator]() {
126
128
  return this.#symbols.values();
127
129
  }
@@ -135,13 +137,20 @@ export class MutableAssetSymbols implements IMutableAssetSymbols {
135
137
  return this.#symbols.size === 0;
136
138
  }
137
139
 
138
- constructor(inner: ?(NapiSymbol[]) | null) {
140
+ constructor(inner: NapiSymbol[] | null | undefined | null) {
139
141
  this.#symbols = new Map();
140
142
  this.#locals = new Set();
141
- for (const {exported, loc, local, isEsmExport, selfReferenced} of inner ||
142
- []) {
143
+ for (const {
144
+ exported,
145
+ loc,
146
+ local,
147
+ isEsmExport,
148
+ selfReferenced,
149
+ isStaticBindingSafe,
150
+ } of inner || []) {
143
151
  this.set(exported, local, loc, {
144
152
  isEsm: isEsmExport,
153
+ isStaticBindingSafe,
145
154
  selfReferenced,
146
155
  });
147
156
  }
@@ -167,6 +176,7 @@ export class MutableAssetSymbols implements IMutableAssetSymbols {
167
176
  }
168
177
  : undefined,
169
178
  isEsmExport: Boolean(meta?.isEsm),
179
+ isStaticBindingSafe: Boolean(meta?.isStaticBindingSafe),
170
180
  isWeak: false,
171
181
  selfReferenced: Boolean(meta?.selfReferenced),
172
182
  });
@@ -181,8 +191,8 @@ export class MutableAssetSymbols implements IMutableAssetSymbols {
181
191
  set(
182
192
  exportSymbol: Symbol,
183
193
  local: Symbol,
184
- loc: ?SourceLocation,
185
- meta: ?Meta,
194
+ loc?: SourceLocation | null,
195
+ meta?: Meta | null,
186
196
  ): void {
187
197
  this.#locals.add(local);
188
198
  this.#symbols.set(exportSymbol, {
@@ -192,7 +202,7 @@ export class MutableAssetSymbols implements IMutableAssetSymbols {
192
202
  });
193
203
  }
194
204
 
195
- get(exportSymbol: Symbol): ?AssetSymbol {
205
+ get(exportSymbol: Symbol): AssetSymbol | null | undefined {
196
206
  return this.#symbols.get(exportSymbol);
197
207
  }
198
208
 
@@ -216,21 +226,21 @@ export class MutableAssetSymbols implements IMutableAssetSymbols {
216
226
  }
217
227
 
218
228
  /*:: @@iterator(): Iterator<[Symbol, AssetSymbol]> { return ({}: any); } */
219
- // $FlowFixMe Flow can't do computed properties
229
+ // @ts-expect-error TS2416
220
230
  [Symbol.iterator]() {
221
231
  return this.#symbols.values();
222
232
  }
223
233
  }
224
234
 
225
- export type AssetSymbol = {|
226
- local: Symbol,
227
- loc: ?SourceLocation,
228
- meta?: ?Meta,
229
- |};
230
-
231
- export type DependencyAssetSymbol = {|
232
- local: Symbol,
233
- loc: ?SourceLocation,
234
- meta?: ?Meta,
235
- isWeak: boolean,
236
- |};
235
+ export type AssetSymbol = {
236
+ local: Symbol;
237
+ loc: SourceLocation | null | undefined;
238
+ meta?: Meta | null | undefined;
239
+ };
240
+
241
+ export type DependencyAssetSymbol = {
242
+ local: Symbol;
243
+ loc: SourceLocation | null | undefined;
244
+ meta?: Meta | null | undefined;
245
+ isWeak: boolean;
246
+ };
@@ -0,0 +1,102 @@
1
+ import type {
2
+ BundleBehavior,
3
+ DependencyPriority,
4
+ SpecifierType,
5
+ } from '@atlaspack/types';
6
+
7
+ /// BitFlags is used to map number/string types from napi types
8
+ export class BitFlags<K> {
9
+ // @ts-expect-error TS2344
10
+ #kv: Partial<Record<K, number>>;
11
+ #vk: Partial<Record<number, K>>;
12
+
13
+ // @ts-expect-error TS2344
14
+ constructor(source: Partial<Record<K, number>>) {
15
+ this.#kv = source;
16
+ this.#vk = Object.fromEntries(
17
+ Object.entries(source).map((a) => a.reverse()),
18
+ );
19
+ }
20
+
21
+ into(key: K): number {
22
+ const found = this.#kv[key];
23
+ if (found === undefined) {
24
+ throw new Error(`Invalid BundleBehavior(${key})`);
25
+ }
26
+ return found;
27
+ }
28
+
29
+ intoNullable(key?: K | null): number | null | undefined {
30
+ if (key === undefined || key === null) {
31
+ return undefined;
32
+ }
33
+ return this.into(key);
34
+ }
35
+
36
+ from(key: number): K {
37
+ const found = this.#vk[key];
38
+ if (found === undefined) {
39
+ throw new Error(`Invalid BundleBehavior(${key})`);
40
+ }
41
+ return found;
42
+ }
43
+
44
+ fromNullable(key?: number | null): K | null | undefined {
45
+ if (key === undefined || key === null) {
46
+ return undefined;
47
+ }
48
+ return this.from(key);
49
+ }
50
+
51
+ toArray(keys: number): K[] {
52
+ let values = [];
53
+ for (let [key, value] of Object.entries(this.#kv) as [K, number][]) {
54
+ if ((keys & value) !== 0) {
55
+ values.push(key);
56
+ }
57
+ }
58
+
59
+ return values;
60
+ }
61
+ }
62
+
63
+ export const bundleBehaviorMap: BitFlags<BundleBehavior> = new BitFlags({
64
+ inline: 0,
65
+ isolated: 1,
66
+ inlineIsolated: 2,
67
+ });
68
+
69
+ export const dependencyPriorityMap: BitFlags<DependencyPriority> = new BitFlags(
70
+ {
71
+ sync: 0,
72
+ parallel: 1,
73
+ lazy: 2,
74
+ conditional: 3,
75
+ },
76
+ );
77
+
78
+ // Note: The bitflags must match the bitflags in the Rust code.
79
+ // crates/atlaspack_core/src/types/package_json.rs
80
+ export const packageConditionsMap: BitFlags<string> = new BitFlags({
81
+ import: 1 << 0,
82
+ require: 1 << 1,
83
+ module: 1 << 2,
84
+ node: 1 << 3,
85
+ browser: 1 << 4,
86
+ worker: 1 << 5,
87
+ worklet: 1 << 6,
88
+ electron: 1 << 7,
89
+ development: 1 << 8,
90
+ production: 1 << 9,
91
+ types: 1 << 10,
92
+ default: 1 << 11,
93
+ style: 1 << 12,
94
+ sass: 1 << 13,
95
+ });
96
+
97
+ export const specifierTypeMap: BitFlags<SpecifierType> = new BitFlags({
98
+ esm: 0,
99
+ commonjs: 1,
100
+ url: 2,
101
+ custom: 3,
102
+ });