powerlines 0.14.0 → 0.14.4

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 (728) hide show
  1. package/README.md +30 -21
  2. package/dist/_virtual/_rolldown/runtime.cjs +29 -0
  3. package/dist/_virtual/_rolldown/runtime.mjs +36 -0
  4. package/dist/api.cjs +10 -0
  5. package/dist/api.d.cts +2 -0
  6. package/dist/api.d.mts +2 -0
  7. package/dist/api.mjs +3 -0
  8. package/dist/astro.cjs +24 -28
  9. package/dist/astro.d.cts +14 -47
  10. package/dist/astro.d.cts.map +1 -0
  11. package/dist/astro.d.mts +25 -0
  12. package/dist/astro.d.mts.map +1 -0
  13. package/dist/astro.mjs +25 -0
  14. package/dist/astro.mjs.map +1 -0
  15. package/dist/config.cjs +9 -0
  16. package/dist/config.d.cts +1 -0
  17. package/dist/config.d.mts +1 -0
  18. package/dist/config.mjs +3 -0
  19. package/dist/constants.cjs +9 -0
  20. package/dist/constants.d.cts +1 -0
  21. package/dist/constants.d.mts +1 -0
  22. package/dist/constants.mjs +3 -0
  23. package/dist/context.cjs +9 -0
  24. package/dist/context.d.cts +1 -0
  25. package/dist/context.d.mts +1 -0
  26. package/dist/context.mjs +3 -0
  27. package/dist/engine.cjs +30 -0
  28. package/dist/engine.d.cts +24 -0
  29. package/dist/engine.d.cts.map +1 -0
  30. package/dist/engine.d.mts +24 -0
  31. package/dist/engine.d.mts.map +1 -0
  32. package/dist/engine.mjs +29 -0
  33. package/dist/engine.mjs.map +1 -0
  34. package/dist/esbuild.cjs +51 -23
  35. package/dist/esbuild.d.cts +13 -45
  36. package/dist/esbuild.d.cts.map +1 -0
  37. package/dist/esbuild.d.mts +25 -0
  38. package/dist/esbuild.d.mts.map +1 -0
  39. package/dist/esbuild.mjs +43 -0
  40. package/dist/esbuild.mjs.map +1 -0
  41. package/dist/farm.cjs +26 -18
  42. package/dist/farm.d.cts +15 -47
  43. package/dist/farm.d.cts.map +1 -0
  44. package/dist/farm.d.mts +25 -0
  45. package/dist/farm.d.mts.map +1 -0
  46. package/dist/farm.mjs +26 -0
  47. package/dist/farm.mjs.map +1 -0
  48. package/dist/index.cjs +40 -91
  49. package/dist/index.d.cts +21 -60
  50. package/dist/index.d.cts.map +1 -0
  51. package/dist/index.d.mts +26 -0
  52. package/dist/index.d.mts.map +1 -0
  53. package/dist/index.mjs +34 -0
  54. package/dist/index.mjs.map +1 -0
  55. package/dist/next.cjs +35 -27
  56. package/dist/next.d.cts +6 -4
  57. package/dist/next.d.cts.map +1 -0
  58. package/dist/{next.d.ts → next.d.mts} +6 -4
  59. package/dist/next.d.mts.map +1 -0
  60. package/dist/next.mjs +36 -0
  61. package/dist/next.mjs.map +1 -0
  62. package/dist/nuxt.cjs +44 -29
  63. package/dist/nuxt.d.cts +19 -10
  64. package/dist/nuxt.d.cts.map +1 -0
  65. package/dist/nuxt.d.mts +29 -0
  66. package/dist/nuxt.d.mts.map +1 -0
  67. package/dist/nuxt.mjs +44 -0
  68. package/dist/nuxt.mjs.map +1 -0
  69. package/dist/package.cjs +18 -0
  70. package/dist/package.mjs +7 -0
  71. package/dist/package.mjs.map +1 -0
  72. package/dist/plugin-utils.cjs +9 -0
  73. package/dist/plugin-utils.d.cts +1 -0
  74. package/dist/plugin-utils.d.mts +1 -0
  75. package/dist/plugin-utils.mjs +3 -0
  76. package/dist/rolldown.cjs +43 -22
  77. package/dist/rolldown.d.cts +10 -43
  78. package/dist/rolldown.d.cts.map +1 -0
  79. package/dist/rolldown.d.mts +24 -0
  80. package/dist/rolldown.d.mts.map +1 -0
  81. package/dist/rolldown.mjs +35 -0
  82. package/dist/rolldown.mjs.map +1 -0
  83. package/dist/rollup.cjs +34 -22
  84. package/dist/rollup.d.cts +11 -43
  85. package/dist/rollup.d.cts.map +1 -0
  86. package/dist/rollup.d.mts +25 -0
  87. package/dist/rollup.d.mts.map +1 -0
  88. package/dist/rollup.mjs +26 -0
  89. package/dist/rollup.mjs.map +1 -0
  90. package/dist/rspack.cjs +34 -22
  91. package/dist/rspack.d.cts +14 -46
  92. package/dist/rspack.d.cts.map +1 -0
  93. package/dist/rspack.d.mts +25 -0
  94. package/dist/rspack.d.mts.map +1 -0
  95. package/dist/rspack.mjs +26 -0
  96. package/dist/rspack.mjs.map +1 -0
  97. package/dist/schemas.cjs +9 -0
  98. package/dist/schemas.d.cts +1 -0
  99. package/dist/schemas.d.mts +1 -0
  100. package/dist/schemas.mjs +3 -0
  101. package/dist/storage.cjs +9 -0
  102. package/dist/storage.d.cts +1 -0
  103. package/dist/storage.d.mts +1 -0
  104. package/dist/storage.mjs +3 -0
  105. package/dist/tsdown.cjs +96 -0
  106. package/dist/tsdown.d.cts +31 -0
  107. package/dist/tsdown.d.cts.map +1 -0
  108. package/dist/tsdown.d.mts +31 -0
  109. package/dist/tsdown.d.mts.map +1 -0
  110. package/dist/tsdown.mjs +82 -0
  111. package/dist/tsdown.mjs.map +1 -0
  112. package/dist/tsup.cjs +67 -24
  113. package/dist/tsup.d.cts +12 -8
  114. package/dist/tsup.d.cts.map +1 -0
  115. package/dist/{tsup.d.ts → tsup.d.mts} +12 -8
  116. package/dist/tsup.d.mts.map +1 -0
  117. package/dist/tsup.mjs +59 -0
  118. package/dist/tsup.mjs.map +1 -0
  119. package/dist/types.cjs +0 -0
  120. package/dist/types.d.cts +8 -0
  121. package/dist/types.d.cts.map +1 -0
  122. package/dist/types.d.mts +8 -0
  123. package/dist/types.d.mts.map +1 -0
  124. package/dist/types.mjs +1 -0
  125. package/dist/typescript.cjs +9 -0
  126. package/dist/typescript.d.cts +1 -0
  127. package/dist/typescript.d.mts +1 -0
  128. package/dist/typescript.mjs +3 -0
  129. package/dist/unbuild.cjs +17 -0
  130. package/dist/unbuild.d.cts +2 -0
  131. package/dist/unbuild.d.mts +2 -0
  132. package/dist/unbuild.mjs +3 -0
  133. package/dist/unloader.cjs +23 -26
  134. package/dist/unloader.d.cts +11 -45
  135. package/dist/unloader.d.cts.map +1 -0
  136. package/dist/unloader.d.mts +22 -0
  137. package/dist/unloader.d.mts.map +1 -0
  138. package/dist/unloader.mjs +23 -0
  139. package/dist/unloader.mjs.map +1 -0
  140. package/dist/unplugin.cjs +105 -37
  141. package/dist/unplugin.d.cts +9 -69
  142. package/dist/unplugin.d.cts.map +1 -0
  143. package/dist/unplugin.d.mts +17 -0
  144. package/dist/unplugin.d.mts.map +1 -0
  145. package/dist/unplugin.mjs +101 -0
  146. package/dist/unplugin.mjs.map +1 -0
  147. package/dist/utils.cjs +25 -0
  148. package/dist/utils.d.cts +3 -0
  149. package/dist/utils.d.mts +3 -0
  150. package/dist/utils.mjs +7 -0
  151. package/dist/vite.cjs +76 -24
  152. package/dist/vite.d.cts +12 -44
  153. package/dist/vite.d.cts.map +1 -0
  154. package/dist/vite.d.mts +25 -0
  155. package/dist/vite.d.mts.map +1 -0
  156. package/dist/vite.mjs +66 -0
  157. package/dist/vite.mjs.map +1 -0
  158. package/dist/webpack.cjs +34 -23
  159. package/dist/webpack.d.cts +10 -43
  160. package/dist/webpack.d.cts.map +1 -0
  161. package/dist/webpack.d.mts +24 -0
  162. package/dist/webpack.d.mts.map +1 -0
  163. package/dist/webpack.mjs +25 -0
  164. package/dist/webpack.mjs.map +1 -0
  165. package/files/application/README.md.hbs +16 -42
  166. package/files/application/package.json.hbs +7 -28
  167. package/files/common/jest.config.ts.hbs +2 -3
  168. package/files/common/tsconfig.json.hbs +5 -10
  169. package/files/common/tsconfig.spec.json.hbs +3 -13
  170. package/files/library/README.md.hbs +11 -34
  171. package/files/library/package.json.hbs +9 -32
  172. package/package.json +253 -342
  173. package/schemas/fs.capnp +42 -0
  174. package/dist/astro.d.ts +0 -58
  175. package/dist/astro.js +0 -11
  176. package/dist/babel-types.d.ts +0 -292
  177. package/dist/chunk-22K72CJ5.cjs +0 -18
  178. package/dist/chunk-2VIXD2XB.js +0 -3
  179. package/dist/chunk-4AKYOJXA.cjs +0 -20
  180. package/dist/chunk-4HGQJ4KR.js +0 -11
  181. package/dist/chunk-4JCNAKOE.cjs +0 -4
  182. package/dist/chunk-5VPVJHJO.cjs +0 -18
  183. package/dist/chunk-6TJGZR5X.js +0 -46
  184. package/dist/chunk-6ZGIV2SU.cjs +0 -4
  185. package/dist/chunk-7BZQBW77.cjs +0 -4
  186. package/dist/chunk-7MTW3KR2.cjs +0 -12
  187. package/dist/chunk-7QVYU63E.js +0 -6
  188. package/dist/chunk-7UIYU6SC.js +0 -39
  189. package/dist/chunk-7WMWRX2S.cjs +0 -12
  190. package/dist/chunk-A3BBPLTY.js +0 -9
  191. package/dist/chunk-AFJCY3R6.js +0 -3
  192. package/dist/chunk-APVMN2H7.cjs +0 -14
  193. package/dist/chunk-AXIRZAL7.js +0 -3
  194. package/dist/chunk-BHP6KBGK.js +0 -16
  195. package/dist/chunk-BOIEJ5I6.js +0 -109
  196. package/dist/chunk-DELRP3WY.js +0 -31
  197. package/dist/chunk-DFLNRC3B.cjs +0 -4
  198. package/dist/chunk-DS7OM4NX.cjs +0 -4
  199. package/dist/chunk-DURCSSLV.js +0 -3
  200. package/dist/chunk-EBMELFCF.js +0 -12
  201. package/dist/chunk-ELHJY5WG.cjs +0 -34
  202. package/dist/chunk-FANQC345.cjs +0 -116
  203. package/dist/chunk-GC3BRYAK.cjs +0 -13
  204. package/dist/chunk-GIE6OE3X.js +0 -3
  205. package/dist/chunk-GV3S7ZR3.cjs +0 -34
  206. package/dist/chunk-HJW7OH6E.js +0 -3
  207. package/dist/chunk-IHUNA3MO.cjs +0 -4
  208. package/dist/chunk-KMLFL4CW.js +0 -14
  209. package/dist/chunk-L3DAMAEC.js +0 -21
  210. package/dist/chunk-LC6FLEJS.cjs +0 -12
  211. package/dist/chunk-LO77RPRV.js +0 -16
  212. package/dist/chunk-MAEKW52U.js +0 -31
  213. package/dist/chunk-MXJWCZDP.cjs +0 -12
  214. package/dist/chunk-NGKWITCO.js +0 -9
  215. package/dist/chunk-OC7CCD5M.cjs +0 -19
  216. package/dist/chunk-OYASPHNL.js +0 -3
  217. package/dist/chunk-P4BOYWXT.js +0 -3570
  218. package/dist/chunk-PJRHRDLS.cjs +0 -3602
  219. package/dist/chunk-PK6SKIKE.cjs +0 -8
  220. package/dist/chunk-Q7EJVZVI.cjs +0 -4
  221. package/dist/chunk-RBRFT2R6.js +0 -9
  222. package/dist/chunk-RU6BHTIP.cjs +0 -24
  223. package/dist/chunk-SIZKRND7.js +0 -12
  224. package/dist/chunk-SNARILEC.cjs +0 -24
  225. package/dist/chunk-SY7N6FC3.js +0 -9
  226. package/dist/chunk-TLHFXGYV.js +0 -3
  227. package/dist/chunk-UZQYBO6Z.cjs +0 -52
  228. package/dist/chunk-V5D5NVV7.cjs +0 -42
  229. package/dist/chunk-V7LXFIGK.js +0 -199
  230. package/dist/chunk-VNRXLY2T.js +0 -3
  231. package/dist/chunk-VQCQRLGM.cjs +0 -4
  232. package/dist/chunk-WCTOTE3T.cjs +0 -201
  233. package/dist/chunk-WD4363UW.cjs +0 -12
  234. package/dist/chunk-XBF43VLE.cjs +0 -4
  235. package/dist/chunk-XZO6ZJQP.cjs +0 -4
  236. package/dist/chunk-YIWHO6SW.cjs +0 -14
  237. package/dist/chunk-YZCTXGFH.js +0 -11
  238. package/dist/chunk-Z5H7LD6W.js +0 -3
  239. package/dist/chunk-ZP5QLZQ2.js +0 -21
  240. package/dist/chunk-ZQ7U35QZ.js +0 -9
  241. package/dist/define-config.cjs +0 -13
  242. package/dist/define-config.d.cts +0 -50
  243. package/dist/define-config.d.ts +0 -50
  244. package/dist/define-config.js +0 -4
  245. package/dist/esbuild.d.ts +0 -57
  246. package/dist/esbuild.js +0 -10
  247. package/dist/extend-plugin.cjs +0 -13
  248. package/dist/extend-plugin.d.cts +0 -48
  249. package/dist/extend-plugin.d.ts +0 -48
  250. package/dist/extend-plugin.js +0 -4
  251. package/dist/farm.d.ts +0 -57
  252. package/dist/farm.js +0 -14
  253. package/dist/hooks-Wrj1dKJ9.d.cts +0 -28
  254. package/dist/hooks-q1Az_C64.d.ts +0 -28
  255. package/dist/index.d.ts +0 -65
  256. package/dist/index.js +0 -40
  257. package/dist/internal/api.cjs +0 -16
  258. package/dist/internal/api.cjs.map +0 -1
  259. package/dist/internal/api.d.cts +0 -192
  260. package/dist/internal/api.d.ts +0 -192
  261. package/dist/internal/api.js +0 -7
  262. package/dist/internal/api.js.map +0 -1
  263. package/dist/lib/build/esbuild.cjs +0 -22
  264. package/dist/lib/build/esbuild.cjs.map +0 -1
  265. package/dist/lib/build/esbuild.d.cts +0 -51
  266. package/dist/lib/build/esbuild.d.ts +0 -51
  267. package/dist/lib/build/esbuild.js +0 -5
  268. package/dist/lib/build/esbuild.js.map +0 -1
  269. package/dist/lib/build/index.cjs +0 -82
  270. package/dist/lib/build/index.cjs.map +0 -1
  271. package/dist/lib/build/index.d.cts +0 -41
  272. package/dist/lib/build/index.d.ts +0 -41
  273. package/dist/lib/build/index.js +0 -13
  274. package/dist/lib/build/index.js.map +0 -1
  275. package/dist/lib/build/rolldown.cjs +0 -14
  276. package/dist/lib/build/rolldown.cjs.map +0 -1
  277. package/dist/lib/build/rolldown.d.cts +0 -42
  278. package/dist/lib/build/rolldown.d.ts +0 -42
  279. package/dist/lib/build/rolldown.js +0 -5
  280. package/dist/lib/build/rolldown.js.map +0 -1
  281. package/dist/lib/build/rollup.cjs +0 -17
  282. package/dist/lib/build/rollup.cjs.map +0 -1
  283. package/dist/lib/build/rollup.d.cts +0 -49
  284. package/dist/lib/build/rollup.d.ts +0 -49
  285. package/dist/lib/build/rollup.js +0 -4
  286. package/dist/lib/build/rollup.js.map +0 -1
  287. package/dist/lib/build/rspack.cjs +0 -13
  288. package/dist/lib/build/rspack.cjs.map +0 -1
  289. package/dist/lib/build/rspack.d.cts +0 -42
  290. package/dist/lib/build/rspack.d.ts +0 -42
  291. package/dist/lib/build/rspack.js +0 -4
  292. package/dist/lib/build/rspack.js.map +0 -1
  293. package/dist/lib/build/tsup.cjs +0 -23
  294. package/dist/lib/build/tsup.cjs.map +0 -1
  295. package/dist/lib/build/tsup.d.cts +0 -51
  296. package/dist/lib/build/tsup.d.ts +0 -51
  297. package/dist/lib/build/tsup.js +0 -6
  298. package/dist/lib/build/tsup.js.map +0 -1
  299. package/dist/lib/build/unbuild.cjs +0 -23
  300. package/dist/lib/build/unbuild.cjs.map +0 -1
  301. package/dist/lib/build/unbuild.d.cts +0 -63
  302. package/dist/lib/build/unbuild.d.ts +0 -63
  303. package/dist/lib/build/unbuild.js +0 -6
  304. package/dist/lib/build/unbuild.js.map +0 -1
  305. package/dist/lib/build/vite.cjs +0 -19
  306. package/dist/lib/build/vite.cjs.map +0 -1
  307. package/dist/lib/build/vite.d.cts +0 -43
  308. package/dist/lib/build/vite.d.ts +0 -43
  309. package/dist/lib/build/vite.js +0 -6
  310. package/dist/lib/build/vite.js.map +0 -1
  311. package/dist/lib/build/webpack.cjs +0 -13
  312. package/dist/lib/build/webpack.cjs.map +0 -1
  313. package/dist/lib/build/webpack.d.cts +0 -42
  314. package/dist/lib/build/webpack.d.ts +0 -42
  315. package/dist/lib/build/webpack.js +0 -4
  316. package/dist/lib/build/webpack.js.map +0 -1
  317. package/dist/lib/chunk-35EO5Y7R.js +0 -50
  318. package/dist/lib/chunk-35EO5Y7R.js.map +0 -1
  319. package/dist/lib/chunk-367E23MI.js +0 -48
  320. package/dist/lib/chunk-367E23MI.js.map +0 -1
  321. package/dist/lib/chunk-3GMJQ5G3.cjs +0 -4
  322. package/dist/lib/chunk-3GMJQ5G3.cjs.map +0 -1
  323. package/dist/lib/chunk-3I2YOM2E.js +0 -58
  324. package/dist/lib/chunk-3I2YOM2E.js.map +0 -1
  325. package/dist/lib/chunk-4BPHC6QQ.js +0 -3
  326. package/dist/lib/chunk-4BPHC6QQ.js.map +0 -1
  327. package/dist/lib/chunk-4XUVP2LL.cjs +0 -39
  328. package/dist/lib/chunk-4XUVP2LL.cjs.map +0 -1
  329. package/dist/lib/chunk-56LQSSQ3.js +0 -62
  330. package/dist/lib/chunk-56LQSSQ3.js.map +0 -1
  331. package/dist/lib/chunk-5PNLONNN.cjs +0 -30
  332. package/dist/lib/chunk-5PNLONNN.cjs.map +0 -1
  333. package/dist/lib/chunk-62ZJYXT3.cjs +0 -54
  334. package/dist/lib/chunk-62ZJYXT3.cjs.map +0 -1
  335. package/dist/lib/chunk-632PWWU7.cjs +0 -57
  336. package/dist/lib/chunk-632PWWU7.cjs.map +0 -1
  337. package/dist/lib/chunk-6BRTJXZ2.js +0 -3333
  338. package/dist/lib/chunk-6BRTJXZ2.js.map +0 -1
  339. package/dist/lib/chunk-6IJTWIVJ.cjs +0 -107
  340. package/dist/lib/chunk-6IJTWIVJ.cjs.map +0 -1
  341. package/dist/lib/chunk-7EAV6Q7B.cjs +0 -78
  342. package/dist/lib/chunk-7EAV6Q7B.cjs.map +0 -1
  343. package/dist/lib/chunk-7LLECRBP.cjs +0 -41
  344. package/dist/lib/chunk-7LLECRBP.cjs.map +0 -1
  345. package/dist/lib/chunk-7QVYU63E.js +0 -6
  346. package/dist/lib/chunk-7QVYU63E.js.map +0 -1
  347. package/dist/lib/chunk-7R23HVGQ.js +0 -27
  348. package/dist/lib/chunk-7R23HVGQ.js.map +0 -1
  349. package/dist/lib/chunk-BEKLDCTV.cjs +0 -95
  350. package/dist/lib/chunk-BEKLDCTV.cjs.map +0 -1
  351. package/dist/lib/chunk-BW3VFCTS.cjs +0 -110
  352. package/dist/lib/chunk-BW3VFCTS.cjs.map +0 -1
  353. package/dist/lib/chunk-CAPN4FSS.js +0 -152
  354. package/dist/lib/chunk-CAPN4FSS.js.map +0 -1
  355. package/dist/lib/chunk-ESYYL5UH.js +0 -105
  356. package/dist/lib/chunk-ESYYL5UH.js.map +0 -1
  357. package/dist/lib/chunk-GJNFAFKR.cjs +0 -66
  358. package/dist/lib/chunk-GJNFAFKR.cjs.map +0 -1
  359. package/dist/lib/chunk-GWYTWFZE.cjs +0 -72
  360. package/dist/lib/chunk-GWYTWFZE.cjs.map +0 -1
  361. package/dist/lib/chunk-HJWJNSSZ.js +0 -3
  362. package/dist/lib/chunk-HJWJNSSZ.js.map +0 -1
  363. package/dist/lib/chunk-HQ6TGY34.js +0 -27
  364. package/dist/lib/chunk-HQ6TGY34.js.map +0 -1
  365. package/dist/lib/chunk-IK3ABDPP.cjs +0 -64
  366. package/dist/lib/chunk-IK3ABDPP.cjs.map +0 -1
  367. package/dist/lib/chunk-JTUL3477.cjs +0 -137
  368. package/dist/lib/chunk-JTUL3477.cjs.map +0 -1
  369. package/dist/lib/chunk-KOCDKJDJ.js +0 -96
  370. package/dist/lib/chunk-KOCDKJDJ.js.map +0 -1
  371. package/dist/lib/chunk-KSBESEOF.js +0 -169
  372. package/dist/lib/chunk-KSBESEOF.js.map +0 -1
  373. package/dist/lib/chunk-LBMMBFQE.js +0 -65
  374. package/dist/lib/chunk-LBMMBFQE.js.map +0 -1
  375. package/dist/lib/chunk-LEIOWD2W.js +0 -28
  376. package/dist/lib/chunk-LEIOWD2W.js.map +0 -1
  377. package/dist/lib/chunk-LJZEN4HP.cjs +0 -110
  378. package/dist/lib/chunk-LJZEN4HP.cjs.map +0 -1
  379. package/dist/lib/chunk-LTVWU4J2.js +0 -47
  380. package/dist/lib/chunk-LTVWU4J2.js.map +0 -1
  381. package/dist/lib/chunk-LYD5OTBI.cjs +0 -3362
  382. package/dist/lib/chunk-LYD5OTBI.cjs.map +0 -1
  383. package/dist/lib/chunk-MAHHHINV.js +0 -67
  384. package/dist/lib/chunk-MAHHHINV.js.map +0 -1
  385. package/dist/lib/chunk-MFC7UJHT.cjs +0 -30
  386. package/dist/lib/chunk-MFC7UJHT.cjs.map +0 -1
  387. package/dist/lib/chunk-MGEZC2RV.cjs +0 -69
  388. package/dist/lib/chunk-MGEZC2RV.cjs.map +0 -1
  389. package/dist/lib/chunk-MVQSM5WM.cjs +0 -73
  390. package/dist/lib/chunk-MVQSM5WM.cjs.map +0 -1
  391. package/dist/lib/chunk-NANLYIUO.cjs +0 -70
  392. package/dist/lib/chunk-NANLYIUO.cjs.map +0 -1
  393. package/dist/lib/chunk-NE46WXNJ.js +0 -58
  394. package/dist/lib/chunk-NE46WXNJ.js.map +0 -1
  395. package/dist/lib/chunk-ODJBZ6PS.js +0 -39
  396. package/dist/lib/chunk-ODJBZ6PS.js.map +0 -1
  397. package/dist/lib/chunk-OF5IJ4WG.js +0 -65
  398. package/dist/lib/chunk-OF5IJ4WG.js.map +0 -1
  399. package/dist/lib/chunk-OO4BIM7N.js +0 -98
  400. package/dist/lib/chunk-OO4BIM7N.js.map +0 -1
  401. package/dist/lib/chunk-PEZXLKQD.cjs +0 -4
  402. package/dist/lib/chunk-PEZXLKQD.cjs.map +0 -1
  403. package/dist/lib/chunk-PK6SKIKE.cjs +0 -8
  404. package/dist/lib/chunk-PK6SKIKE.cjs.map +0 -1
  405. package/dist/lib/chunk-PXSRMP4E.js +0 -39
  406. package/dist/lib/chunk-PXSRMP4E.js.map +0 -1
  407. package/dist/lib/chunk-Q2L3FNJO.js +0 -120
  408. package/dist/lib/chunk-Q2L3FNJO.js.map +0 -1
  409. package/dist/lib/chunk-Q3KJZ3B5.js +0 -161
  410. package/dist/lib/chunk-Q3KJZ3B5.js.map +0 -1
  411. package/dist/lib/chunk-RK2VVGL6.cjs +0 -107
  412. package/dist/lib/chunk-RK2VVGL6.cjs.map +0 -1
  413. package/dist/lib/chunk-RLMEYZ5I.cjs +0 -167
  414. package/dist/lib/chunk-RLMEYZ5I.cjs.map +0 -1
  415. package/dist/lib/chunk-RQICHHZM.cjs +0 -29
  416. package/dist/lib/chunk-RQICHHZM.cjs.map +0 -1
  417. package/dist/lib/chunk-RXQWNSZX.js +0 -37
  418. package/dist/lib/chunk-RXQWNSZX.js.map +0 -1
  419. package/dist/lib/chunk-STAKGAWR.js +0 -86
  420. package/dist/lib/chunk-STAKGAWR.js.map +0 -1
  421. package/dist/lib/chunk-U36VZLW6.cjs +0 -172
  422. package/dist/lib/chunk-U36VZLW6.cjs.map +0 -1
  423. package/dist/lib/chunk-UGRFAVAJ.js +0 -93
  424. package/dist/lib/chunk-UGRFAVAJ.js.map +0 -1
  425. package/dist/lib/chunk-UQJWVRRE.cjs +0 -47
  426. package/dist/lib/chunk-UQJWVRRE.cjs.map +0 -1
  427. package/dist/lib/chunk-V2T4H24I.js +0 -156
  428. package/dist/lib/chunk-V2T4H24I.js.map +0 -1
  429. package/dist/lib/chunk-V5OY4ALI.cjs +0 -56
  430. package/dist/lib/chunk-V5OY4ALI.cjs.map +0 -1
  431. package/dist/lib/chunk-VJN72T2O.js +0 -50
  432. package/dist/lib/chunk-VJN72T2O.js.map +0 -1
  433. package/dist/lib/chunk-W4OMKQ7W.cjs +0 -128
  434. package/dist/lib/chunk-W4OMKQ7W.cjs.map +0 -1
  435. package/dist/lib/chunk-XGH6JWRO.js +0 -3
  436. package/dist/lib/chunk-XGH6JWRO.js.map +0 -1
  437. package/dist/lib/chunk-XQMVE2NH.cjs +0 -4
  438. package/dist/lib/chunk-XQMVE2NH.cjs.map +0 -1
  439. package/dist/lib/chunk-XZD7S5TU.cjs +0 -53
  440. package/dist/lib/chunk-XZD7S5TU.cjs.map +0 -1
  441. package/dist/lib/chunk-YBIWVB66.js +0 -76
  442. package/dist/lib/chunk-YBIWVB66.js.map +0 -1
  443. package/dist/lib/chunk-YF3YHK4X.js +0 -127
  444. package/dist/lib/chunk-YF3YHK4X.js.map +0 -1
  445. package/dist/lib/chunk-YVDJCVE5.cjs +0 -160
  446. package/dist/lib/chunk-YVDJCVE5.cjs.map +0 -1
  447. package/dist/lib/chunk-ZP7PDTVE.cjs +0 -167
  448. package/dist/lib/chunk-ZP7PDTVE.cjs.map +0 -1
  449. package/dist/lib/compiler-CuQLTmTB.d.cts +0 -32
  450. package/dist/lib/compiler-CuQLTmTB.d.ts +0 -32
  451. package/dist/lib/config-DnifzkPt.d.ts +0 -1474
  452. package/dist/lib/config-Ro14HmyO.d.cts +0 -1474
  453. package/dist/lib/config-file.cjs +0 -17
  454. package/dist/lib/config-file.cjs.map +0 -1
  455. package/dist/lib/config-file.d.cts +0 -57
  456. package/dist/lib/config-file.d.ts +0 -57
  457. package/dist/lib/config-file.js +0 -4
  458. package/dist/lib/config-file.js.map +0 -1
  459. package/dist/lib/create-program.cjs +0 -13
  460. package/dist/lib/create-program.cjs.map +0 -1
  461. package/dist/lib/create-program.d.cts +0 -42
  462. package/dist/lib/create-program.d.ts +0 -42
  463. package/dist/lib/create-program.js +0 -4
  464. package/dist/lib/create-program.js.map +0 -1
  465. package/dist/lib/entry.cjs +0 -41
  466. package/dist/lib/entry.cjs.map +0 -1
  467. package/dist/lib/entry.d.cts +0 -69
  468. package/dist/lib/entry.d.ts +0 -69
  469. package/dist/lib/entry.js +0 -4
  470. package/dist/lib/entry.js.map +0 -1
  471. package/dist/lib/hooks-B6Ow5MtE.d.ts +0 -28
  472. package/dist/lib/hooks-CM-BbMzz.d.cts +0 -28
  473. package/dist/lib/index.cjs +0 -281
  474. package/dist/lib/index.cjs.map +0 -1
  475. package/dist/lib/index.d.cts +0 -57
  476. package/dist/lib/index.d.ts +0 -57
  477. package/dist/lib/index.js +0 -28
  478. package/dist/lib/index.js.map +0 -1
  479. package/dist/lib/logger.cjs +0 -17
  480. package/dist/lib/logger.cjs.map +0 -1
  481. package/dist/lib/logger.d.cts +0 -51
  482. package/dist/lib/logger.d.ts +0 -51
  483. package/dist/lib/logger.js +0 -4
  484. package/dist/lib/logger.js.map +0 -1
  485. package/dist/lib/tsconfig-Bz-CiFqD.d.cts +0 -68
  486. package/dist/lib/tsconfig-Bz-CiFqD.d.ts +0 -68
  487. package/dist/lib/typescript/compiler-host.cjs +0 -166
  488. package/dist/lib/typescript/compiler-host.cjs.map +0 -1
  489. package/dist/lib/typescript/compiler-host.d.cts +0 -64
  490. package/dist/lib/typescript/compiler-host.d.ts +0 -64
  491. package/dist/lib/typescript/compiler-host.js +0 -158
  492. package/dist/lib/typescript/compiler-host.js.map +0 -1
  493. package/dist/lib/typescript/import-transformer.cjs +0 -51
  494. package/dist/lib/typescript/import-transformer.cjs.map +0 -1
  495. package/dist/lib/typescript/import-transformer.d.cts +0 -36
  496. package/dist/lib/typescript/import-transformer.d.ts +0 -36
  497. package/dist/lib/typescript/import-transformer.js +0 -49
  498. package/dist/lib/typescript/import-transformer.js.map +0 -1
  499. package/dist/lib/typescript/index.cjs +0 -60
  500. package/dist/lib/typescript/index.cjs.map +0 -1
  501. package/dist/lib/typescript/index.d.cts +0 -35
  502. package/dist/lib/typescript/index.d.ts +0 -35
  503. package/dist/lib/typescript/index.js +0 -7
  504. package/dist/lib/typescript/index.js.map +0 -1
  505. package/dist/lib/typescript/isolated-decl.cjs +0 -13
  506. package/dist/lib/typescript/isolated-decl.cjs.map +0 -1
  507. package/dist/lib/typescript/isolated-decl.d.cts +0 -11
  508. package/dist/lib/typescript/isolated-decl.d.ts +0 -11
  509. package/dist/lib/typescript/isolated-decl.js +0 -4
  510. package/dist/lib/typescript/isolated-decl.js.map +0 -1
  511. package/dist/lib/typescript/program.cjs +0 -29
  512. package/dist/lib/typescript/program.cjs.map +0 -1
  513. package/dist/lib/typescript/program.d.cts +0 -69
  514. package/dist/lib/typescript/program.d.ts +0 -69
  515. package/dist/lib/typescript/program.js +0 -4
  516. package/dist/lib/typescript/program.js.map +0 -1
  517. package/dist/lib/typescript/tsconfig.cjs +0 -33
  518. package/dist/lib/typescript/tsconfig.cjs.map +0 -1
  519. package/dist/lib/typescript/tsconfig.d.cts +0 -61
  520. package/dist/lib/typescript/tsconfig.d.ts +0 -61
  521. package/dist/lib/typescript/tsconfig.js +0 -4
  522. package/dist/lib/typescript/tsconfig.js.map +0 -1
  523. package/dist/lib/unplugin/factory.cjs +0 -23
  524. package/dist/lib/unplugin/factory.cjs.map +0 -1
  525. package/dist/lib/unplugin/factory.d.cts +0 -200
  526. package/dist/lib/unplugin/factory.d.ts +0 -200
  527. package/dist/lib/unplugin/factory.js +0 -14
  528. package/dist/lib/unplugin/factory.js.map +0 -1
  529. package/dist/lib/unplugin/index.cjs +0 -33
  530. package/dist/lib/unplugin/index.cjs.map +0 -1
  531. package/dist/lib/unplugin/index.d.cts +0 -36
  532. package/dist/lib/unplugin/index.d.ts +0 -36
  533. package/dist/lib/unplugin/index.js +0 -16
  534. package/dist/lib/unplugin/index.js.map +0 -1
  535. package/dist/lib/unplugin/plugin.cjs +0 -16
  536. package/dist/lib/unplugin/plugin.cjs.map +0 -1
  537. package/dist/lib/unplugin/plugin.d.cts +0 -55
  538. package/dist/lib/unplugin/plugin.d.ts +0 -55
  539. package/dist/lib/unplugin/plugin.js +0 -7
  540. package/dist/lib/unplugin/plugin.js.map +0 -1
  541. package/dist/lib/unplugin/resolve-id.cjs +0 -13
  542. package/dist/lib/unplugin/resolve-id.cjs.map +0 -1
  543. package/dist/lib/unplugin/resolve-id.d.cts +0 -60
  544. package/dist/lib/unplugin/resolve-id.d.ts +0 -60
  545. package/dist/lib/unplugin/resolve-id.js +0 -4
  546. package/dist/lib/unplugin/resolve-id.js.map +0 -1
  547. package/dist/lib/utilities/bundle.cjs +0 -16
  548. package/dist/lib/utilities/bundle.cjs.map +0 -1
  549. package/dist/lib/utilities/bundle.d.cts +0 -44
  550. package/dist/lib/utilities/bundle.d.ts +0 -44
  551. package/dist/lib/utilities/bundle.js +0 -7
  552. package/dist/lib/utilities/bundle.js.map +0 -1
  553. package/dist/lib/utilities/cache.cjs +0 -18
  554. package/dist/lib/utilities/cache.cjs.map +0 -1
  555. package/dist/lib/utilities/cache.d.cts +0 -7
  556. package/dist/lib/utilities/cache.d.ts +0 -7
  557. package/dist/lib/utilities/cache.js +0 -5
  558. package/dist/lib/utilities/cache.js.map +0 -1
  559. package/dist/lib/utilities/file-header.cjs +0 -17
  560. package/dist/lib/utilities/file-header.cjs.map +0 -1
  561. package/dist/lib/utilities/file-header.d.cts +0 -42
  562. package/dist/lib/utilities/file-header.d.ts +0 -42
  563. package/dist/lib/utilities/file-header.js +0 -4
  564. package/dist/lib/utilities/file-header.js.map +0 -1
  565. package/dist/lib/utilities/index.cjs +0 -159
  566. package/dist/lib/utilities/index.cjs.map +0 -1
  567. package/dist/lib/utilities/index.d.cts +0 -45
  568. package/dist/lib/utilities/index.d.ts +0 -45
  569. package/dist/lib/utilities/index.js +0 -18
  570. package/dist/lib/utilities/index.js.map +0 -1
  571. package/dist/lib/utilities/meta.cjs +0 -37
  572. package/dist/lib/utilities/meta.cjs.map +0 -1
  573. package/dist/lib/utilities/meta.d.cts +0 -68
  574. package/dist/lib/utilities/meta.d.ts +0 -68
  575. package/dist/lib/utilities/meta.js +0 -4
  576. package/dist/lib/utilities/meta.js.map +0 -1
  577. package/dist/lib/utilities/plugin-helpers.cjs +0 -61
  578. package/dist/lib/utilities/plugin-helpers.cjs.map +0 -1
  579. package/dist/lib/utilities/plugin-helpers.d.cts +0 -153
  580. package/dist/lib/utilities/plugin-helpers.d.ts +0 -153
  581. package/dist/lib/utilities/plugin-helpers.js +0 -4
  582. package/dist/lib/utilities/plugin-helpers.js.map +0 -1
  583. package/dist/lib/utilities/resolve-path.cjs +0 -13
  584. package/dist/lib/utilities/resolve-path.cjs.map +0 -1
  585. package/dist/lib/utilities/resolve-path.d.cts +0 -43
  586. package/dist/lib/utilities/resolve-path.d.ts +0 -43
  587. package/dist/lib/utilities/resolve-path.js +0 -4
  588. package/dist/lib/utilities/resolve-path.js.map +0 -1
  589. package/dist/lib/utilities/resolve.cjs +0 -17
  590. package/dist/lib/utilities/resolve.cjs.map +0 -1
  591. package/dist/lib/utilities/resolve.d.cts +0 -44
  592. package/dist/lib/utilities/resolve.d.ts +0 -44
  593. package/dist/lib/utilities/resolve.js +0 -8
  594. package/dist/lib/utilities/resolve.js.map +0 -1
  595. package/dist/lib/utilities/source-file.cjs +0 -21
  596. package/dist/lib/utilities/source-file.cjs.map +0 -1
  597. package/dist/lib/utilities/source-file.d.cts +0 -28
  598. package/dist/lib/utilities/source-file.d.ts +0 -28
  599. package/dist/lib/utilities/source-file.js +0 -4
  600. package/dist/lib/utilities/source-file.js.map +0 -1
  601. package/dist/lib/utilities/source-map.cjs +0 -13
  602. package/dist/lib/utilities/source-map.cjs.map +0 -1
  603. package/dist/lib/utilities/source-map.d.cts +0 -14
  604. package/dist/lib/utilities/source-map.d.ts +0 -14
  605. package/dist/lib/utilities/source-map.js +0 -4
  606. package/dist/lib/utilities/source-map.js.map +0 -1
  607. package/dist/lib/utilities/worker.cjs +0 -18
  608. package/dist/lib/utilities/worker.cjs.map +0 -1
  609. package/dist/lib/utilities/worker.d.cts +0 -58
  610. package/dist/lib/utilities/worker.d.ts +0 -58
  611. package/dist/lib/utilities/worker.js +0 -5
  612. package/dist/lib/utilities/worker.js.map +0 -1
  613. package/dist/lib/utilities/write-file.cjs +0 -13
  614. package/dist/lib/utilities/write-file.cjs.map +0 -1
  615. package/dist/lib/utilities/write-file.d.cts +0 -44
  616. package/dist/lib/utilities/write-file.d.ts +0 -44
  617. package/dist/lib/utilities/write-file.js +0 -4
  618. package/dist/lib/utilities/write-file.js.map +0 -1
  619. package/dist/next.js +0 -10
  620. package/dist/nuxt.d.ts +0 -20
  621. package/dist/nuxt.js +0 -12
  622. package/dist/resolved-DtY60yLh.d.cts +0 -1351
  623. package/dist/resolved-wPXZS7aW.d.ts +0 -1351
  624. package/dist/rolldown.d.ts +0 -57
  625. package/dist/rolldown.js +0 -9
  626. package/dist/rollup.d.ts +0 -57
  627. package/dist/rollup.js +0 -9
  628. package/dist/rspack.d.ts +0 -57
  629. package/dist/rspack.js +0 -9
  630. package/dist/tsup.js +0 -11
  631. package/dist/types/babel.cjs +0 -6
  632. package/dist/types/babel.cjs.map +0 -1
  633. package/dist/types/babel.d.cts +0 -38
  634. package/dist/types/babel.d.ts +0 -38
  635. package/dist/types/babel.js +0 -3
  636. package/dist/types/babel.js.map +0 -1
  637. package/dist/types/build.cjs +0 -6
  638. package/dist/types/build.cjs.map +0 -1
  639. package/dist/types/build.d.cts +0 -111
  640. package/dist/types/build.d.ts +0 -111
  641. package/dist/types/build.js +0 -3
  642. package/dist/types/build.js.map +0 -1
  643. package/dist/types/commands.cjs +0 -13
  644. package/dist/types/commands.cjs.map +0 -1
  645. package/dist/types/commands.d.cts +0 -38
  646. package/dist/types/commands.d.ts +0 -38
  647. package/dist/types/commands.js +0 -4
  648. package/dist/types/commands.js.map +0 -1
  649. package/dist/types/compiler.cjs +0 -6
  650. package/dist/types/compiler.cjs.map +0 -1
  651. package/dist/types/compiler.d.cts +0 -38
  652. package/dist/types/compiler.d.ts +0 -38
  653. package/dist/types/compiler.js +0 -3
  654. package/dist/types/compiler.js.map +0 -1
  655. package/dist/types/config.cjs +0 -6
  656. package/dist/types/config.cjs.map +0 -1
  657. package/dist/types/config.d.cts +0 -38
  658. package/dist/types/config.d.ts +0 -38
  659. package/dist/types/config.js +0 -3
  660. package/dist/types/config.js.map +0 -1
  661. package/dist/types/context.cjs +0 -13
  662. package/dist/types/context.cjs.map +0 -1
  663. package/dist/types/context.d.cts +0 -38
  664. package/dist/types/context.d.ts +0 -38
  665. package/dist/types/context.js +0 -4
  666. package/dist/types/context.js.map +0 -1
  667. package/dist/types/hooks.cjs +0 -6
  668. package/dist/types/hooks.cjs.map +0 -1
  669. package/dist/types/hooks.d.cts +0 -38
  670. package/dist/types/hooks.d.ts +0 -38
  671. package/dist/types/hooks.js +0 -3
  672. package/dist/types/hooks.js.map +0 -1
  673. package/dist/types/index.cjs +0 -58
  674. package/dist/types/index.cjs.map +0 -1
  675. package/dist/types/index.d.cts +0 -42
  676. package/dist/types/index.d.ts +0 -42
  677. package/dist/types/index.js +0 -17
  678. package/dist/types/index.js.map +0 -1
  679. package/dist/types/internal.cjs +0 -4
  680. package/dist/types/internal.cjs.map +0 -1
  681. package/dist/types/internal.d.cts +0 -61
  682. package/dist/types/internal.d.ts +0 -61
  683. package/dist/types/internal.js +0 -3
  684. package/dist/types/internal.js.map +0 -1
  685. package/dist/types/plugin.cjs +0 -13
  686. package/dist/types/plugin.cjs.map +0 -1
  687. package/dist/types/plugin.d.cts +0 -38
  688. package/dist/types/plugin.d.ts +0 -38
  689. package/dist/types/plugin.js +0 -4
  690. package/dist/types/plugin.js.map +0 -1
  691. package/dist/types/resolved.cjs +0 -6
  692. package/dist/types/resolved.cjs.map +0 -1
  693. package/dist/types/resolved.d.cts +0 -38
  694. package/dist/types/resolved.d.ts +0 -38
  695. package/dist/types/resolved.js +0 -3
  696. package/dist/types/resolved.js.map +0 -1
  697. package/dist/types/tsconfig.cjs +0 -6
  698. package/dist/types/tsconfig.cjs.map +0 -1
  699. package/dist/types/tsconfig.d.cts +0 -75
  700. package/dist/types/tsconfig.d.ts +0 -75
  701. package/dist/types/tsconfig.js +0 -3
  702. package/dist/types/tsconfig.js.map +0 -1
  703. package/dist/types/typedoc.cjs +0 -6
  704. package/dist/types/typedoc.cjs.map +0 -1
  705. package/dist/types/typedoc.d.cts +0 -25
  706. package/dist/types/typedoc.d.ts +0 -25
  707. package/dist/types/typedoc.js +0 -3
  708. package/dist/types/typedoc.js.map +0 -1
  709. package/dist/types/unplugin.cjs +0 -6
  710. package/dist/types/unplugin.cjs.map +0 -1
  711. package/dist/types/unplugin.d.cts +0 -54
  712. package/dist/types/unplugin.d.ts +0 -54
  713. package/dist/types/unplugin.js +0 -3
  714. package/dist/types/unplugin.js.map +0 -1
  715. package/dist/types/vfs.cjs +0 -33
  716. package/dist/types/vfs.cjs.map +0 -1
  717. package/dist/types/vfs.d.cts +0 -408
  718. package/dist/types/vfs.d.ts +0 -408
  719. package/dist/types/vfs.js +0 -4
  720. package/dist/types/vfs.js.map +0 -1
  721. package/dist/unloader.d.ts +0 -56
  722. package/dist/unloader.js +0 -9
  723. package/dist/unplugin.d.ts +0 -77
  724. package/dist/unplugin.js +0 -21
  725. package/dist/vite.d.ts +0 -57
  726. package/dist/vite.js +0 -10
  727. package/dist/webpack.d.ts +0 -57
  728. package/dist/webpack.js +0 -9
@@ -1,3333 +0,0 @@
1
- import { writeFile } from './chunk-HQ6TGY34.js';
2
- import { getFileHeader } from './chunk-7R23HVGQ.js';
3
- import { __VFS_CACHE__, __VFS_RESOLVER__, __VFS_VIRTUAL__, __VFS_UNIFIED__, __VFS_INIT__, __VFS_REVERT__, CACHE_HASH_LENGTH, PROJECT_ROOT_HASH_LENGTH, getPrefixedProjectRootHash, getChecksum, writeMetaFile } from './chunk-KOCDKJDJ.js';
4
- import { isPlugin, checkDedupe, isPluginHook, isHookExternal, addPluginHook, getHookHandler, isPluginConfig, isPluginConfigTuple, isPluginConfigObject } from './chunk-UGRFAVAJ.js';
5
- import { handleResolveId } from './chunk-YBIWVB66.js';
6
- import { getParsedTypeScriptConfig, getTsconfigFilePath, isIncludeMatchFound } from './chunk-OO4BIM7N.js';
7
- import { loadWorkspaceConfig, loadUserConfigFile } from './chunk-56LQSSQ3.js';
8
- import { extendLog, createLog } from './chunk-35EO5Y7R.js';
9
- import { getSourceFile, getString } from './chunk-PXSRMP4E.js';
10
- import { resolveEntriesSync, getUniqueEntries } from './chunk-STAKGAWR.js';
11
- import { __name } from './chunk-7QVYU63E.js';
12
- import { LogLevelLabel } from '@storm-software/config-tools/types';
13
- import { relativeToWorkspaceRoot, getWorkspaceRoot } from '@stryke/fs/get-workspace-root';
14
- import { tsconfigPathsToRegExp } from 'bundle-require';
15
- import { formatLogMessage } from '@storm-software/config-tools/logger/console';
16
- import { toArray } from '@stryke/convert/to-array';
17
- import { copyFiles } from '@stryke/fs/copy-file';
18
- import { existsSync } from '@stryke/fs/exists';
19
- import { createDirectory } from '@stryke/fs/helpers';
20
- import { install } from '@stryke/fs/install';
21
- import { listFiles } from '@stryke/fs/list-files';
22
- import { isPackageExists, isPackageListed, doesPackageMatch, getPackageListing } from '@stryke/fs/package-fns';
23
- import { joinPaths } from '@stryke/path/join-paths';
24
- import { replacePath } from '@stryke/path/replace';
25
- import { isError } from '@stryke/type-checks/is-error';
26
- import { isFunction } from '@stryke/type-checks/is-function';
27
- import { isNumber } from '@stryke/type-checks/is-number';
28
- import { isPromiseLike } from '@stryke/type-checks/is-promise';
29
- import { isSet } from '@stryke/type-checks/is-set';
30
- import { isSetObject } from '@stryke/type-checks/is-set-object';
31
- import { isSetString } from '@stryke/type-checks/is-set-string';
32
- import chalk4 from 'chalk';
33
- import Handlebars from 'handlebars';
34
- import { resolvePackage } from '@stryke/fs/resolve';
35
- import { titleCase } from '@stryke/string-format/title-case';
36
- import defu3, { defu } from 'defu';
37
- import { getEnvPaths } from '@stryke/env/get-env-paths';
38
- import { readJsonFile } from '@stryke/fs/json';
39
- import { murmurhash } from '@stryke/hash/murmurhash';
40
- import { getUnique } from '@stryke/helpers/get-unique';
41
- import { omit } from '@stryke/helpers/omit';
42
- import { appendPath } from '@stryke/path/append';
43
- import { findFilePath, findFileDotExtensionSafe, hasFileExtension, relativePath, findFileName } from '@stryke/path/file-path-fns';
44
- import { isAbsolutePath, isAbsolute } from '@stryke/path/is-type';
45
- import { joinPaths as joinPaths$1 } from '@stryke/path/join';
46
- import { isNull } from '@stryke/type-checks/is-null';
47
- import { isString } from '@stryke/type-checks/is-string';
48
- import { uuid } from '@stryke/unique-id/uuid';
49
- import { parseAsync } from 'oxc-parser';
50
- import { createJiti } from 'jiti';
51
- import { bufferToString } from '@stryke/convert/buffer-to-string';
52
- import { isParentPath } from '@stryke/path/is-parent-path';
53
- import { prettyBytes } from '@stryke/string-format/pretty-bytes';
54
- import { isBuffer } from '@stryke/type-checks/is-buffer';
55
- import { isUndefined } from '@stryke/type-checks/is-undefined';
56
- import { Volume } from 'memfs';
57
- import { Blob } from 'node:buffer';
58
- import fs from 'node:fs';
59
- import { resolveConfig, format } from 'prettier';
60
- import { Union } from 'unionfs';
61
- import { isObject } from '@stryke/type-checks/is-object';
62
- import { transformAsync } from '@babel/core';
63
- import ts, { createProgram, createCompilerHost, getPreEmitDiagnostics, getLineAndCharacterOfPosition, flattenDiagnosticMessageText } from 'typescript';
64
- import { declare } from '@babel/helper-plugin-utils';
65
- import * as t from '@babel/types';
66
- import { getPackageName, hasPackageVersion, getPackageVersion } from '@stryke/string-format/package';
67
- import { getObjectDiff } from '@donedeal0/superdiff';
68
- import { loadTsConfig } from '@stryke/fs/tsconfig';
69
- import { StormJSON } from '@stryke/json/storm-json';
70
-
71
- var DEFAULT_ENVIRONMENT = "default";
72
- function createEnvironment(name, userConfig) {
73
- return defu3(userConfig.environments?.[name] ?? {}, {
74
- name,
75
- title: userConfig.title || titleCase(userConfig.name),
76
- ssr: false,
77
- mainFields: userConfig.build?.platform === "browser" ? [
78
- "browser",
79
- "module",
80
- "jsnext:main",
81
- "jsnext"
82
- ] : [
83
- "module",
84
- "jsnext:main",
85
- "jsnext"
86
- ],
87
- extensions: [
88
- ".mjs",
89
- ".js",
90
- ".mts",
91
- ".ts",
92
- ".jsx",
93
- ".tsx",
94
- ".json"
95
- ],
96
- consumer: userConfig.build?.platform === "browser" ? "client" : "server",
97
- preview: userConfig.build?.platform === "browser" ? {
98
- port: 5173,
99
- open: true,
100
- strictPort: false,
101
- // https: false,
102
- host: "localhost",
103
- allowedHosts: [
104
- "."
105
- ],
106
- cors: true,
107
- headers: {}
108
- } : void 0
109
- }, userConfig);
110
- }
111
- __name(createEnvironment, "createEnvironment");
112
- function createDefaultEnvironment(userConfig) {
113
- return createEnvironment(DEFAULT_ENVIRONMENT, userConfig);
114
- }
115
- __name(createDefaultEnvironment, "createDefaultEnvironment");
116
- function resolveOptions(options) {
117
- return defu3(options, {
118
- interopDefault: true,
119
- fsCache: options.mode !== "development" ? joinPaths(options.cacheDir, "jiti") : false,
120
- moduleCache: options.mode !== "development"
121
- });
122
- }
123
- __name(resolveOptions, "resolveOptions");
124
- function createPluginResolver(options) {
125
- return createJiti(joinPaths(options.workspaceRoot, options.projectRoot), resolveOptions({
126
- ...options
127
- }));
128
- }
129
- __name(createPluginResolver, "createPluginResolver");
130
- function createResolver(options) {
131
- const baseResolver = createJiti(joinPaths(options.workspaceRoot, options.projectRoot), resolveOptions(options));
132
- baseResolver.plugin = createPluginResolver(options);
133
- return baseResolver;
134
- }
135
- __name(createResolver, "createResolver");
136
- function isBufferEncoding(options) {
137
- return isSetString(options) || options === null;
138
- }
139
- __name(isBufferEncoding, "isBufferEncoding");
140
- function isPowerlinesWriteFileOptions(options) {
141
- return !isBufferEncoding(options) && isSetObject(options) && ("skipFormat" in options || "mode" in options && (options.mode === "fs" || options.mode === "virtual"));
142
- }
143
- __name(isPowerlinesWriteFileOptions, "isPowerlinesWriteFileOptions");
144
- function isNodeWriteFileOptions(options) {
145
- return !isUndefined(options) && (isBufferEncoding(options) || !isPowerlinesWriteFileOptions(options));
146
- }
147
- __name(isNodeWriteFileOptions, "isNodeWriteFileOptions");
148
- function isPowerLinesWriteFileData(data) {
149
- return !!(isSetObject(data) && "code" in data && data.code);
150
- }
151
- __name(isPowerLinesWriteFileData, "isPowerLinesWriteFileData");
152
- var FILE_PREFIX = "file://";
153
- function toFilePath(pathOrUrl) {
154
- if (!pathOrUrl) {
155
- throw new Error("No Path or URL provided to Virtual File System");
156
- }
157
- let result = pathOrUrl.toString();
158
- if (result.startsWith(FILE_PREFIX)) {
159
- result = result.slice(FILE_PREFIX.length);
160
- }
161
- return result;
162
- }
163
- __name(toFilePath, "toFilePath");
164
- var FS_METHODS = [
165
- "mkdir",
166
- "mkdirSync",
167
- "rmdir",
168
- "rmdirSync",
169
- "unlink",
170
- "unlinkSync",
171
- "existsSync",
172
- "realpathSync",
173
- "writeFileSync",
174
- "readFileSync",
175
- "readdirSync",
176
- "createWriteStream",
177
- "WriteStream",
178
- "createReadStream",
179
- "ReadStream"
180
- ];
181
- var FS_PROMISE_METHODS = [
182
- "mkdir",
183
- "rm",
184
- "rmdir",
185
- "unlink",
186
- "writeFile",
187
- "readFile",
188
- "readdir",
189
- "stat",
190
- "lstat"
191
- ];
192
- function cloneFS(originalFS) {
193
- const clonedFS = {
194
- ...originalFS,
195
- promises: {
196
- ...originalFS.promises ?? {}
197
- }
198
- };
199
- for (const method of FS_METHODS) {
200
- if (originalFS[method]) {
201
- clonedFS[method] = originalFS[method];
202
- }
203
- }
204
- originalFS.promises ??= {};
205
- for (const method of FS_PROMISE_METHODS) {
206
- if (originalFS.promises[method]) {
207
- clonedFS.promises ??= {};
208
- clonedFS.promises[method] = originalFS.promises[method];
209
- clonedFS[method] = originalFS.promises[method];
210
- }
211
- }
212
- for (const prop in clonedFS) {
213
- if (isFunction(clonedFS[prop])) {
214
- clonedFS[prop] = clonedFS[prop].bind(originalFS);
215
- if (isFunction(clonedFS.promises[prop])) {
216
- clonedFS.promises[prop] = clonedFS.promises[prop].bind(originalFS);
217
- }
218
- }
219
- }
220
- for (const prop in clonedFS.promises) {
221
- if (isFunction(clonedFS.promises[prop])) {
222
- clonedFS.promises[prop] = clonedFS.promises[prop].bind(originalFS);
223
- }
224
- }
225
- return clonedFS;
226
- }
227
- __name(cloneFS, "cloneFS");
228
- function patchFS(originalFS, vfs) {
229
- const clonedFS = cloneFS(originalFS);
230
- originalFS.mkdirSync = (file, options) => vfs.mkdirSync(toFilePath(file), options);
231
- originalFS.mkdir = (file, options, callback) => vfs.mkdir(toFilePath(file), options, callback);
232
- originalFS.promises.mkdir = async (file, options) => vfs.mkdir(toFilePath(file), options);
233
- originalFS.unlinkSync = (file) => vfs.unlinkSync(toFilePath(file));
234
- originalFS.promises.rm = async (file, options) => vfs.rm(toFilePath(file), options);
235
- originalFS.promises.unlink = async (file) => vfs.unlink(toFilePath(file));
236
- originalFS.existsSync = (file) => vfs.existsSync(toFilePath(file));
237
- Object.defineProperty(originalFS, "realpathSync", {
238
- value: /* @__PURE__ */ __name((file, options) => vfs.realpathSync(toFilePath(file), options), "value")
239
- });
240
- originalFS.writeFileSync = (file, data, options) => vfs.writeFileSync(toFilePath(file), data, options);
241
- originalFS.promises.writeFile = async (file, data, options) => vfs.writeFile(toFilePath(file), data, options);
242
- originalFS.readFileSync = (file, options) => vfs.readFileSync(toFilePath(file), options);
243
- originalFS.promises.readFile = (file, options) => vfs.readFile(toFilePath(file), options);
244
- originalFS.readdirSync = (file, options) => vfs.readdirSync(toFilePath(file), options);
245
- originalFS.promises.readdir = (file, options) => vfs.readdir(toFilePath(file), options);
246
- Object.defineProperty(originalFS, "statSync", {
247
- value: /* @__PURE__ */ __name((file, options) => vfs.statSync(toFilePath(file), options), "value")
248
- });
249
- originalFS.stat = (file, options) => vfs.statSync(toFilePath(file), options);
250
- originalFS.promises.stat = (file, options) => vfs.stat(toFilePath(file), options);
251
- Object.defineProperty(originalFS, "lstatSync", {
252
- value: /* @__PURE__ */ __name((file, options) => vfs.lstatSync(toFilePath(file), options), "value")
253
- });
254
- originalFS.lstat = (file, options) => vfs.lstatSync(toFilePath(file), options);
255
- originalFS.promises.lstat = (file, options) => vfs.lstat(toFilePath(file), options);
256
- return () => {
257
- originalFS.mkdirSync = clonedFS.mkdirSync;
258
- originalFS.mkdir = clonedFS.mkdir;
259
- originalFS.promises.mkdir = clonedFS.promises.mkdir;
260
- originalFS.unlinkSync = clonedFS.unlinkSync;
261
- originalFS.promises.rm = clonedFS.promises.rm;
262
- originalFS.promises.unlink = clonedFS.promises.unlink;
263
- originalFS.existsSync = clonedFS.existsSync;
264
- originalFS.realpathSync = clonedFS.realpathSync;
265
- originalFS.writeFileSync = clonedFS.writeFileSync;
266
- originalFS.promises.writeFile = clonedFS.promises.writeFile;
267
- originalFS.readFileSync = clonedFS.readFileSync;
268
- originalFS.promises.readFile = clonedFS.promises.readFile;
269
- originalFS.readdirSync = clonedFS.readdirSync;
270
- originalFS.promises.readdir = clonedFS.promises.readdir;
271
- Object.defineProperty(originalFS, "statSync", {
272
- value: clonedFS.statSync
273
- });
274
- originalFS.stat = clonedFS.stat;
275
- originalFS.promises.stat = clonedFS.promises.stat;
276
- Object.defineProperty(originalFS, "lstatSync", {
277
- value: clonedFS.lstatSync
278
- });
279
- originalFS.lstat = clonedFS.lstat;
280
- originalFS.promises.lstat = clonedFS.promises.lstat;
281
- };
282
- }
283
- __name(patchFS, "patchFS");
284
- var VirtualFileSystem = class {
285
- static {
286
- __name(this, "VirtualFileSystem");
287
- }
288
- /**
289
- * The internal map of virtual files.
290
- */
291
- #meta = {};
292
- /**
293
- * A map of unique identifiers to their virtual file paths.
294
- */
295
- #ids = {};
296
- /**
297
- * A map of virtual file paths to their underlying file content.
298
- */
299
- #cachedFS = /* @__PURE__ */ new Map();
300
- /**
301
- * A map of virtual file paths to their underlying file content.
302
- */
303
- #cachedResolver = /* @__PURE__ */ new Map();
304
- /**
305
- * The internal map of virtual files.
306
- */
307
- #virtualFS = new Volume();
308
- /**
309
- * The physical file system.
310
- */
311
- #fs = cloneFS(fs);
312
- /**
313
- * The unified volume that combines the virtual file system with the real file system.
314
- *
315
- * @remarks
316
- * This volume allows for seamless access to both virtual and real files.
317
- */
318
- #unifiedFS = new Union();
319
- /**
320
- * Indicator specifying if the file system module is patched
321
- */
322
- #isPatched = false;
323
- /**
324
- * Function to revert require patch
325
- */
326
- #revert;
327
- /**
328
- * The context of the virtual file system.
329
- */
330
- #context;
331
- /**
332
- * The file system's logging function.
333
- */
334
- #log;
335
- /**
336
- * Checks if a path exists in the virtual file system (VFS).
337
- *
338
- * @param path - The path to check.
339
- * @returns `true` if the path exists, otherwise `false`.
340
- */
341
- #existsSync(path) {
342
- const formattedPath = this.formatPath(path);
343
- return this.#virtualFS.existsSync(formattedPath) || this.#fs.existsSync(formattedPath) || this.resolveFS(path).existsSync(formattedPath);
344
- }
345
- /**
346
- * Exposes the internal VFS map for advanced usage.
347
- */
348
- get [__VFS_CACHE__]() {
349
- return this.#cachedFS;
350
- }
351
- /**
352
- * Exposes the internal VFS resolver cache for advanced usage.
353
- */
354
- get [__VFS_RESOLVER__]() {
355
- return this.#cachedResolver;
356
- }
357
- /**
358
- * Exposes the internal VFS map for advanced usage.
359
- */
360
- get [__VFS_VIRTUAL__]() {
361
- return this.#virtualFS;
362
- }
363
- /**
364
- * Exposes the internal UFS map for advanced usage.
365
- */
366
- get [__VFS_UNIFIED__]() {
367
- return this.#unifiedFS;
368
- }
369
- /**
370
- * A proxy to access the underlying file metadata.
371
- */
372
- get meta() {
373
- return new Proxy(this.#meta, {
374
- get: /* @__PURE__ */ __name((target, prop) => {
375
- if (target[prop]) {
376
- return {
377
- id: prop,
378
- mode: this.#virtualFS.existsSync(prop) ? "virtual" : this.#fs.existsSync(prop) ? "fs" : this.#context.config.output.mode,
379
- details: {},
380
- variant: "normal",
381
- ...target[prop]
382
- };
383
- }
384
- return void 0;
385
- }, "get"),
386
- set: /* @__PURE__ */ __name((target, prop, value) => {
387
- target[prop] = value;
388
- this.#ids[value.id || prop] = prop;
389
- return true;
390
- }, "set"),
391
- deleteProperty: /* @__PURE__ */ __name((target, prop) => {
392
- delete this.#ids[target[prop]?.id || prop];
393
- delete target[prop];
394
- return true;
395
- }, "deleteProperty")
396
- });
397
- }
398
- /**
399
- * A map of module ids to their file paths.
400
- */
401
- get ids() {
402
- return this.#ids;
403
- }
404
- /**
405
- * Creates a new instance of the VirtualFileSystem.
406
- *
407
- * @param context - The context of the virtual file system, typically containing options and logging functions.
408
- * @param serialized - A map of files/file contents to populate in cache
409
- */
410
- constructor(context, serialized = {}) {
411
- this.#context = context;
412
- this.#cachedFS = /* @__PURE__ */ new Map();
413
- this.#meta = Object.fromEntries(Object.entries(serialized.virtualFilesMeta ?? {}));
414
- this.#ids = Object.fromEntries(Object.entries(this.#meta).map(([path, data]) => [
415
- data.id || path,
416
- path
417
- ]));
418
- if (!this.#fs.existsSync(this.#context.dataPath)) {
419
- this.#fs.mkdirSync(this.#context.dataPath, {
420
- recursive: true
421
- });
422
- }
423
- if (!this.#fs.existsSync(this.#context.cachePath)) {
424
- this.#fs.mkdirSync(this.#context.cachePath, {
425
- recursive: true
426
- });
427
- }
428
- if (!this.#fs.existsSync(joinPaths(this.#context.workspaceConfig.workspaceRoot, this.#context.config.output.outputPath))) {
429
- this.#fs.mkdirSync(joinPaths(this.#context.workspaceConfig.workspaceRoot, this.#context.config.output.outputPath), {
430
- recursive: true
431
- });
432
- }
433
- this.#unifiedFS = this.#unifiedFS.use(this.#fs);
434
- if (this.#context.config.output.mode !== "fs") {
435
- if (serialized?.virtualFiles && Object.keys(serialized.virtualFiles).length > 0) {
436
- this.#virtualFS = Volume.fromJSON(serialized.virtualFiles);
437
- }
438
- if (!this.#virtualFS.existsSync(this.#context.artifactsPath)) {
439
- this.#virtualFS.mkdirSync(this.#context.artifactsPath, {
440
- recursive: true
441
- });
442
- }
443
- if (!this.#virtualFS.existsSync(this.#context.builtinsPath)) {
444
- this.#virtualFS.mkdirSync(this.#context.builtinsPath, {
445
- recursive: true
446
- });
447
- }
448
- if (!this.#virtualFS.existsSync(this.#context.entryPath)) {
449
- this.#virtualFS.mkdirSync(this.#context.entryPath, {
450
- recursive: true
451
- });
452
- }
453
- if (!this.#virtualFS.existsSync(this.#context.dtsPath)) {
454
- this.#virtualFS.mkdirSync(this.#context.dtsPath, {
455
- recursive: true
456
- });
457
- }
458
- this.#unifiedFS = this.#unifiedFS.use(this.#virtualFS);
459
- } else if (this.#context.config.projectType === "application") {
460
- if (!this.#fs.existsSync(this.#context.artifactsPath)) {
461
- this.#fs.mkdirSync(this.#context.artifactsPath, {
462
- recursive: true
463
- });
464
- }
465
- if (!this.#fs.existsSync(this.#context.builtinsPath)) {
466
- this.#fs.mkdirSync(this.#context.builtinsPath, {
467
- recursive: true
468
- });
469
- }
470
- if (!this.#fs.existsSync(this.#context.entryPath)) {
471
- this.#fs.mkdirSync(this.#context.entryPath, {
472
- recursive: true
473
- });
474
- }
475
- if (!this.#fs.existsSync(this.#context.dtsPath)) {
476
- this.#fs.mkdirSync(this.#context.dtsPath, {
477
- recursive: true
478
- });
479
- }
480
- }
481
- this.#log = extendLog(this.#context.log, "virtual-file-system");
482
- }
483
- [__VFS_INIT__]() {
484
- if (!this.#isPatched && this.#context.config.output.mode !== "fs") {
485
- this.#revert = patchFS(fs, this);
486
- this.#isPatched = true;
487
- }
488
- }
489
- [__VFS_REVERT__]() {
490
- if (this.#isPatched && this.#context.config.output.mode !== "fs") {
491
- if (!this.#revert) {
492
- throw new Error("Attempting to revert File System patch prior to calling `__init__` function");
493
- }
494
- this.#revert?.();
495
- this.#isPatched = false;
496
- }
497
- }
498
- /**
499
- * Check if a path or id corresponds to a virtual file **(does not actually exists on disk)**.
500
- *
501
- * @param pathOrId - The path or id to check.
502
- * @param options - Optional parameters for resolving the path.
503
- * @returns Whether the path or id corresponds to a virtual file **(does not actually exists on disk)**.
504
- */
505
- isVirtual(pathOrId, options = {}) {
506
- if (!pathOrId) {
507
- return false;
508
- }
509
- const resolvedPath = this.resolve(pathOrId, {
510
- ...options,
511
- type: "file"
512
- });
513
- if (!resolvedPath) {
514
- return false;
515
- }
516
- return this.meta[resolvedPath]?.mode === "virtual";
517
- }
518
- /**
519
- * Check if a path or id corresponds to a file written to the file system **(actually exists on disk)**.
520
- *
521
- * @param pathOrId - The path or id to check.
522
- * @param options - Optional parameters for resolving the path.
523
- * @returns Whether the path or id corresponds to a file written to the file system **(actually exists on disk)**.
524
- */
525
- isFs(pathOrId, options = {}) {
526
- if (!pathOrId) {
527
- return false;
528
- }
529
- const resolvedPath = this.resolve(pathOrId, {
530
- ...options,
531
- type: "file"
532
- });
533
- if (!resolvedPath) {
534
- return false;
535
- }
536
- return this.meta[resolvedPath]?.mode === "fs";
537
- }
538
- /**
539
- * Check if a path exists within one of the directories specified in the tsconfig.json's `path` field.
540
- *
541
- * @see https://www.typescriptlang.org/tsconfig#paths
542
- *
543
- * @param pathOrId - The path or ID to check.
544
- * @returns Whether the path or ID corresponds to a virtual file.
545
- */
546
- isTsconfigPath(pathOrId) {
547
- return !!this.#context.tsconfig.options.paths && Object.keys(this.#context.tsconfig.options.paths).some((path) => pathOrId.startsWith(path.replaceAll("*", "")));
548
- }
549
- /**
550
- * Lists files in a given path.
551
- *
552
- * @param path - The path to list files from.
553
- * @param options - Options for listing files, such as encoding and recursion.
554
- * @returns An array of file names in the specified path.
555
- */
556
- readdirSync(path, options = "utf8") {
557
- return this.resolveFS(path).readdirSync(toFilePath(path), options);
558
- }
559
- /**
560
- * Removes a file in the virtual file system (VFS).
561
- *
562
- * @param path - The path to create the directory at.
563
- */
564
- unlinkSync(path, options) {
565
- const formattedPath = toFilePath(path);
566
- if (!this.isFile(formattedPath)) {
567
- return;
568
- }
569
- this.#log(LogLevelLabel.TRACE, `Synchronously removing file: ${formattedPath}`);
570
- this.resolveFS(path, options).unlinkSync(formattedPath);
571
- this.#cachedFS.delete(formattedPath);
572
- this.clearResolverCache(formattedPath);
573
- }
574
- /**
575
- * Removes a file in the virtual file system (VFS).
576
- *
577
- * @param path - The path to create the directory at.
578
- */
579
- async unlink(path, options) {
580
- const formattedPath = toFilePath(path);
581
- if (!this.isFile(formattedPath)) {
582
- return;
583
- }
584
- this.#log(LogLevelLabel.TRACE, `Removing file: ${formattedPath}`);
585
- if (isFunction(this.resolveFS(path, options).promises.unlink)) {
586
- await this.resolveFS(path, options).promises.unlink(formattedPath);
587
- this.#cachedFS.delete(formattedPath);
588
- this.clearResolverCache(formattedPath);
589
- } else {
590
- this.unlinkSync(formattedPath, options);
591
- }
592
- }
593
- /**
594
- * Removes a directory in the virtual file system (VFS).
595
- *
596
- * @param path - The path to create the directory at.
597
- * @param options - Options for creating the directory.
598
- */
599
- rmdirSync(path, options = {}) {
600
- const formattedPath = toFilePath(path);
601
- if (!this.isDirectory(formattedPath)) {
602
- return;
603
- }
604
- this.#log(LogLevelLabel.TRACE, `Synchronously removing directory: ${formattedPath}`);
605
- this.resolveFS(path, options).rmdirSync(formattedPath, defu3(options, {
606
- recursive: true
607
- }));
608
- this.#cachedFS.delete(formattedPath);
609
- this.clearResolverCache(formattedPath);
610
- }
611
- /**
612
- * Removes a directory in the virtual file system (VFS).
613
- *
614
- * @param path - The path to create the directory at.
615
- * @param options - Options for creating the directory.
616
- * @returns A promise that resolves to the path of the created directory, or undefined if the directory could not be created.
617
- */
618
- async rmdir(path, options = {}) {
619
- const formattedPath = toFilePath(path);
620
- if (!this.isDirectory(formattedPath)) {
621
- return;
622
- }
623
- this.#log(LogLevelLabel.TRACE, `Removing directory: ${formattedPath}`);
624
- if (isFunction(this.resolveFS(path, options).promises.rm)) {
625
- await this.resolveFS(path, options).promises.rm(formattedPath, defu3(options, {
626
- force: true,
627
- recursive: true
628
- }));
629
- this.#cachedFS.delete(formattedPath);
630
- this.clearResolverCache(formattedPath);
631
- } else {
632
- this.rmdirSync(formattedPath, defu3(options ?? {}, {
633
- force: true,
634
- recursive: true
635
- }));
636
- }
637
- }
638
- /**
639
- * Removes a file in the virtual file system (VFS).
640
- *
641
- * @param path - The path to the file to remove.
642
- * @param options - Options for removing the file.
643
- * @returns A promise that resolves when the file is removed.
644
- */
645
- async rm(path, options = {}) {
646
- this.#log(LogLevelLabel.TRACE, `Removing: ${toFilePath(path)}`);
647
- if (this.isDirectory(path)) {
648
- return this.rmdir(path, options);
649
- }
650
- return this.unlink(path, options);
651
- }
652
- /**
653
- * Synchronously removes a file or directory in the virtual file system (VFS).
654
- *
655
- * @param path - The path to the file or directory to remove.
656
- * @param options - Options for removing the file or directory.
657
- */
658
- rmSync(path, options = {}) {
659
- this.#log(LogLevelLabel.TRACE, `Removing: ${toFilePath(path)}`);
660
- if (this.isDirectory(path)) {
661
- return this.rmdirSync(path, options);
662
- }
663
- return this.unlinkSync(path, options);
664
- }
665
- /**
666
- * Creates a directory in the virtual file system (VFS).
667
- *
668
- * @param path - The path to create the directory at.
669
- * @param options - Options for creating the directory.
670
- * @returns A promise that resolves to the path of the created directory, or undefined if the directory could not be created.
671
- */
672
- mkdirSync(path, options = {}) {
673
- const filePath = toFilePath(path);
674
- this.clearResolverCache(filePath);
675
- return this.resolveFS(filePath, options).mkdirSync(filePath, defu3(options ?? {}, {
676
- recursive: true
677
- }));
678
- }
679
- /**
680
- * Creates a directory in the virtual file system (VFS).
681
- *
682
- * @param path - The path to create the directory at.
683
- * @param options - Options for creating the directory.
684
- * @returns A promise that resolves to the path of the created directory, or undefined if the directory could not be created.
685
- */
686
- async mkdir(path, options = {}) {
687
- let result;
688
- const filePath = toFilePath(path);
689
- if (isFunction(this.resolveFS(filePath, options).promises.mkdir)) {
690
- result = await this.resolveFS(filePath, options).promises.mkdir(filePath, defu3(options ?? {}, {
691
- recursive: true
692
- }));
693
- } else {
694
- result = this.resolveFS(filePath, options).mkdirSync(filePath, defu3(options ?? {}, {
695
- recursive: true
696
- }));
697
- }
698
- this.clearResolverCache(filePath);
699
- return result;
700
- }
701
- /**
702
- * Glob files in the virtual file system (VFS) based on the provided pattern(s).
703
- *
704
- * @param patterns - A pattern (or multiple patterns) to use to determine the file paths to return
705
- * @returns An array of file paths matching the provided pattern(s)
706
- */
707
- async glob(patterns) {
708
- const results = [];
709
- for (const pattern of toArray(patterns)) {
710
- const normalized = this.formatPath(pattern);
711
- if (!/[*?[\]{}]/.test(normalized) && !normalized.includes("**")) {
712
- const resolved = this.resolve(normalized, {
713
- type: "file"
714
- });
715
- if (resolved && !results.includes(resolved)) {
716
- results.push(resolved);
717
- }
718
- continue;
719
- }
720
- const absPattern = isAbsolutePath(normalized) ? normalized : this.formatPath(joinPaths(this.#context.workspaceConfig.workspaceRoot, normalized));
721
- const firstGlobIdx = absPattern.search(/[*?[\]{}]/);
722
- const baseDir = firstGlobIdx === -1 ? findFilePath(absPattern) : absPattern.slice(0, Math.max(0, absPattern.lastIndexOf("/", firstGlobIdx)));
723
- const stack = [
724
- baseDir && isAbsolutePath(baseDir) ? baseDir : this.#context.workspaceConfig.workspaceRoot
725
- ];
726
- while (stack.length) {
727
- const dir = stack.pop();
728
- let entries = [];
729
- try {
730
- entries = await this.readdir(dir);
731
- } catch {
732
- continue;
733
- }
734
- for (const entry of entries) {
735
- const full = this.formatPath(joinPaths(dir, entry));
736
- let stats;
737
- try {
738
- stats = this.#unifiedFS.lstatSync(full);
739
- } catch {
740
- stats = void 0;
741
- }
742
- if (!stats) continue;
743
- if (stats.isDirectory()) {
744
- stack.push(full);
745
- } else if (stats.isFile()) {
746
- if (this.buildRegex(absPattern).test(full)) {
747
- const resolved = this.resolve(full, {
748
- type: "file"
749
- });
750
- if (resolved && !results.includes(resolved)) {
751
- results.push(resolved);
752
- }
753
- }
754
- }
755
- }
756
- }
757
- }
758
- return results;
759
- }
760
- /**
761
- * Synchronously glob files in the virtual file system (VFS) based on the provided pattern(s).
762
- *
763
- * @param patterns - A pattern (or multiple patterns) to use to determine the file paths to return
764
- * @returns An array of file paths matching the provided pattern(s)
765
- */
766
- globSync(patterns) {
767
- const results = [];
768
- for (const pattern of toArray(patterns)) {
769
- const normalized = this.formatPath(pattern);
770
- if (!/[*?[\]{}]/.test(normalized) && !normalized.includes("**")) {
771
- const resolved = this.resolve(normalized, {
772
- type: "file"
773
- });
774
- if (resolved && !results.includes(resolved)) {
775
- results.push(resolved);
776
- }
777
- continue;
778
- }
779
- const absPattern = isAbsolutePath(normalized) ? normalized : this.formatPath(joinPaths(this.#context.workspaceConfig.workspaceRoot, normalized));
780
- const firstGlobIdx = absPattern.search(/[*?[\]{}]/);
781
- const baseDir = firstGlobIdx === -1 ? findFilePath(absPattern) : absPattern.slice(0, Math.max(0, absPattern.lastIndexOf("/", firstGlobIdx)));
782
- const stack = [
783
- baseDir && isAbsolutePath(baseDir) ? baseDir : this.#context.workspaceConfig.workspaceRoot
784
- ];
785
- while (stack.length) {
786
- const dir = stack.pop();
787
- let entries = [];
788
- try {
789
- entries = this.readdirSync(dir);
790
- } catch {
791
- continue;
792
- }
793
- for (const entry of entries) {
794
- const full = this.formatPath(joinPaths(dir, entry));
795
- let stats;
796
- try {
797
- stats = this.#unifiedFS.lstatSync(full);
798
- } catch {
799
- stats = void 0;
800
- }
801
- if (!stats) continue;
802
- if (stats.isDirectory()) {
803
- stack.push(full);
804
- } else if (stats.isFile()) {
805
- if (this.buildRegex(absPattern).test(full)) {
806
- const resolved = this.resolve(full, {
807
- type: "file"
808
- });
809
- if (resolved && !results.includes(resolved)) {
810
- results.push(resolved);
811
- }
812
- }
813
- }
814
- }
815
- }
816
- }
817
- return results;
818
- }
819
- /**
820
- * Moves a file from one path to another in the virtual file system (VFS).
821
- *
822
- * @param srcPath - The source path to move
823
- * @param destPath - The destination path to move to
824
- */
825
- async move(srcPath, destPath) {
826
- const content = await this.readFile(srcPath);
827
- await this.writeFile(destPath, content);
828
- await this.rm(srcPath);
829
- }
830
- /**
831
- * Synchronously moves a file from one path to another in the virtual file system (VFS).
832
- *
833
- * @param srcPath - The source path to move
834
- * @param destPath - The destination path to move to
835
- */
836
- moveSync(srcPath, destPath) {
837
- const content = this.readFileSync(srcPath);
838
- this.writeFileSync(destPath, content);
839
- this.rmSync(srcPath);
840
- }
841
- /**
842
- * Copies a file from one path to another in the virtual file system (VFS).
843
- *
844
- * @param srcPath - The source path to copy
845
- * @param destPath - The destination path to copy to
846
- */
847
- async copy(srcPath, destPath) {
848
- const content = await this.readFile(srcPath);
849
- await this.writeFile(destPath, content);
850
- }
851
- /**
852
- * Synchronously copies a file from one path to another in the virtual file system (VFS).
853
- *
854
- * @param srcPath - The source path to copy
855
- * @param destPath - The destination path to copy to
856
- */
857
- copySync(srcPath, destPath) {
858
- const content = this.readFileSync(srcPath);
859
- this.writeFileSync(destPath, content);
860
- }
861
- /**
862
- * Lists files in a given path.
863
- *
864
- * @param pathOrId - The path to list files from.
865
- * @param options - Options for listing files, such as encoding and recursion.
866
- * @returns An array of file names in the specified path.
867
- */
868
- async readdir(pathOrId, options = "utf8") {
869
- return this.resolveFS(pathOrId).promises.readdir(toFilePath(pathOrId), options);
870
- }
871
- /**
872
- * Asynchronously reads a file from the virtual file system (VFS).
873
- *
874
- * @param pathOrId - The path or ID of the file to read.
875
- * @returns A promise that resolves to the contents of the file as a string, or undefined if the file does not exist.
876
- */
877
- async readFile(pathOrId, options = "utf8") {
878
- if (!pathOrId) {
879
- return void 0;
880
- }
881
- const filePath = this.resolve(toFilePath(pathOrId), {
882
- type: "file"
883
- });
884
- if (filePath) {
885
- if (this.#cachedFS.has(filePath)) {
886
- return this.#cachedFS.get(filePath);
887
- }
888
- let result;
889
- if (isFunction(this.resolveFS(filePath).promises.readFile)) {
890
- result = (await this.resolveFS(filePath).promises.readFile(filePath, options))?.toString("utf8");
891
- } else {
892
- result = this.resolveFS(filePath).readFileSync(filePath, options);
893
- }
894
- const content = isBuffer(result) ? bufferToString(result) : result;
895
- this.#cachedFS.set(filePath, content);
896
- return content;
897
- }
898
- return void 0;
899
- }
900
- /**
901
- * Synchronously reads a file from the virtual file system (VFS).
902
- *
903
- * @param pathOrId - The path or ID of the file to read.
904
- * @returns The contents of the file as a string, or undefined if the file does not exist.
905
- */
906
- readFileSync(pathOrId, options = "utf8") {
907
- if (!pathOrId) {
908
- return void 0;
909
- }
910
- const filePath = this.resolve(toFilePath(pathOrId), {
911
- type: "file"
912
- });
913
- if (filePath) {
914
- if (this.#cachedFS.has(filePath)) {
915
- return this.#cachedFS.get(filePath);
916
- }
917
- const result = this.resolveFS(filePath).readFileSync(filePath, options);
918
- const content = isBuffer(result) ? bufferToString(result) : result;
919
- this.#cachedFS.set(filePath, content);
920
- return content;
921
- }
922
- return void 0;
923
- }
924
- /**
925
- * Writes a file to the virtual file system (VFS).
926
- *
927
- * @param path - The path to the file.
928
- * @param data - The contents of the file.
929
- * @param options - Optional parameters for writing the file.
930
- * @returns A promise that resolves when the file is written.
931
- */
932
- async writeFile(path, data = "", options = "utf8") {
933
- const formattedPath = this.formatPath(path);
934
- if (!this.isDirectory(findFilePath(formattedPath))) {
935
- await this.mkdir(findFilePath(formattedPath), isPowerlinesWriteFileOptions(options) ? options : void 0);
936
- }
937
- let code = isPowerLinesWriteFileData(data) ? data.code : data;
938
- if ((!isPowerlinesWriteFileOptions(options) || !options.skipFormat) && isSetString(code)) {
939
- const resolvedConfig = await resolveConfig(formattedPath);
940
- if (resolvedConfig) {
941
- code = await format(code, {
942
- absolutePath: formattedPath,
943
- ...resolvedConfig
944
- });
945
- }
946
- }
947
- const outputMode = this.resolveOutputMode(formattedPath, isPowerlinesWriteFileOptions(options) ? options : void 0);
948
- this.#log(LogLevelLabel.TRACE, `Writing ${formattedPath} file to the ${outputMode === "fs" ? "" : "virtual "}file system (size: ${prettyBytes(new Blob(toArray(code)).size)})`);
949
- this.meta[formattedPath] = {
950
- path: formattedPath,
951
- code,
952
- mode: outputMode,
953
- variant: "normal",
954
- ...isPowerLinesWriteFileData(data) ? data : {}
955
- };
956
- this.clearResolverCache(formattedPath);
957
- const ifs = this.resolveFS(formattedPath, isPowerlinesWriteFileOptions(options) ? options : void 0);
958
- if (isFunction(ifs.promises.writeFile)) {
959
- return ifs.promises.writeFile(formattedPath, code, isNodeWriteFileOptions(options) ? options : "utf8");
960
- }
961
- return ifs.writeFileSync(formattedPath, code, isNodeWriteFileOptions(options) ? options : "utf8");
962
- }
963
- /**
964
- * Synchronously writes a file to the virtual file system (VFS).
965
- *
966
- * @param path - The file to write.
967
- * @param data - The contents of the file.
968
- * @param options - Optional parameters for writing the file.
969
- */
970
- writeFileSync(path, data = "", options = "utf8") {
971
- const formattedPath = this.formatPath(path);
972
- if (!this.isDirectory(findFilePath(formattedPath))) {
973
- this.mkdirSync(findFilePath(formattedPath), isPowerlinesWriteFileOptions(options) ? options : void 0);
974
- }
975
- const code = isPowerLinesWriteFileData(data) ? data.code : data;
976
- const outputMode = this.resolveOutputMode(formattedPath, isPowerlinesWriteFileOptions(options) ? options : void 0);
977
- this.#log(LogLevelLabel.TRACE, `Writing ${formattedPath} file to the ${outputMode === "fs" ? "" : "virtual "}file system (size: ${prettyBytes(new Blob(toArray(code)).size)})`);
978
- this.meta[formattedPath] = {
979
- path: formattedPath,
980
- code,
981
- mode: outputMode,
982
- variant: "normal",
983
- ...isPowerLinesWriteFileData(data) ? data : {}
984
- };
985
- this.clearResolverCache(formattedPath);
986
- const writeStream = this.resolveFS(formattedPath, isPowerlinesWriteFileOptions(options) ? options : void 0).createWriteStream(formattedPath);
987
- try {
988
- writeStream.write(code);
989
- } finally {
990
- writeStream.close();
991
- }
992
- }
993
- /**
994
- * Synchronously checks if a file exists in the virtual file system (VFS).
995
- *
996
- * @param pathOrId - The path or ID of the file to check.
997
- * @returns `true` if the file exists, otherwise `false`.
998
- */
999
- existsSync(pathOrId) {
1000
- return this.resolve(pathOrId) !== false;
1001
- }
1002
- /**
1003
- * Retrieves the metadata of a file in the virtual file system (VFS).
1004
- *
1005
- * @param pathOrId - The path or ID of the file to retrieve metadata for.
1006
- * @returns The metadata of the file, or undefined if the file does not exist.
1007
- */
1008
- getMetadata(pathOrId) {
1009
- const resolved = this.resolve(pathOrId);
1010
- if (resolved && this.meta[resolved]) {
1011
- return this.meta[resolved];
1012
- }
1013
- return void 0;
1014
- }
1015
- /**
1016
- * Checks if a file exists in the virtual file system (VFS).
1017
- *
1018
- * @remarks
1019
- * This is a base method used by {@link existsSync} - it does not try to resolve the path prior to checking if it exists or not.
1020
- *
1021
- * @param pathOrId - The path of the file to check.
1022
- * @returns `true` if the file exists, otherwise `false`.
1023
- */
1024
- isFile(pathOrId) {
1025
- const resolved = this.resolve(pathOrId);
1026
- return !!(resolved && (this.#virtualFS.existsSync(resolved) && this.#virtualFS.lstatSync(resolved).isFile() || this.#fs.existsSync(resolved) && this.#fs.lstatSync(resolved).isFile() || this.resolveFS(resolved).existsSync(resolved) && this.resolveFS(resolved).lstatSync(resolved).isFile()));
1027
- }
1028
- /**
1029
- * Checks if a directory exists in the virtual file system (VFS).
1030
- *
1031
- * @param pathOrId - The path of the directory to check.
1032
- * @returns `true` if the directory exists, otherwise `false`.
1033
- */
1034
- isDirectory(pathOrId) {
1035
- const resolved = this.resolve(pathOrId);
1036
- return !!(resolved && (this.#virtualFS.existsSync(resolved) && this.#virtualFS.lstatSync(resolved).isDirectory() || this.#fs.existsSync(resolved) && this.#fs.lstatSync(resolved).isDirectory() || this.resolveFS(resolved).existsSync(resolved) && this.resolveFS(resolved).lstatSync(resolved).isDirectory()));
1037
- }
1038
- /**
1039
- * Retrieves the status of a file in the virtual file system (VFS).
1040
- *
1041
- * @param pathOrId - The path or ID of the file to retrieve status for.
1042
- * @returns A promise that resolves to the file's status information, or false if the file does not exist.
1043
- */
1044
- async stat(pathOrId, options) {
1045
- return this.resolveFS(pathOrId).promises.stat(this.resolve(toFilePath(pathOrId)) || toFilePath(pathOrId), options);
1046
- }
1047
- /**
1048
- * Synchronously retrieves the status of a file in the virtual file system (VFS).
1049
- *
1050
- * @param pathOrId - The path or ID of the file to retrieve status for.
1051
- * @returns The file's status information, or false if the file does not exist.
1052
- */
1053
- statSync(pathOrId) {
1054
- return this.resolveFS(pathOrId).statSync(this.resolve(toFilePath(pathOrId)) || toFilePath(pathOrId));
1055
- }
1056
- /**
1057
- * Retrieves the status of a symbolic link in the virtual file system (VFS).
1058
- *
1059
- * @param pathOrId - The path or ID of the symbolic link to retrieve status for.
1060
- * @returns A promise that resolves to the symbolic link's status information, or false if the link does not exist.
1061
- */
1062
- async lstat(pathOrId, options) {
1063
- return this.resolveFS(pathOrId).promises.lstat(this.resolve(toFilePath(pathOrId)) || toFilePath(pathOrId), options);
1064
- }
1065
- /**
1066
- * Synchronously retrieves the status of a symbolic link in the virtual file system (VFS).
1067
- *
1068
- * @param pathOrId - The path or ID of the symbolic link to retrieve status for.
1069
- * @returns The symbolic link's status information, or false if the link does not exist.
1070
- */
1071
- lstatSync(pathOrId, options) {
1072
- return this.resolveFS(pathOrId).lstatSync(this.resolve(toFilePath(pathOrId)) || toFilePath(pathOrId), options);
1073
- }
1074
- /**
1075
- * Resolves a path based on TypeScript's `tsconfig.json` paths.
1076
- *
1077
- * @see https://www.typescriptlang.org/tsconfig#paths
1078
- *
1079
- * @param path - The path to check.
1080
- * @returns The resolved file path if it exists, otherwise undefined.
1081
- */
1082
- resolveTsconfigPath(path) {
1083
- if (this.#context.tsconfig.options.paths) {
1084
- for (const tsconfigPathKey of Object.keys(this.#context.tsconfig.options.paths).filter((tsconfigPath) => path.startsWith(tsconfigPath.replaceAll("*", "")))) {
1085
- const resolvedPath = this.#context.tsconfig.options.paths[tsconfigPathKey]?.find((tsconfigPath) => this.resolvePath(joinPaths(this.#context.workspaceConfig.workspaceRoot, tsconfigPath.replaceAll("*", ""), path.replace(tsconfigPathKey.replaceAll("*", ""), ""))) || this.formatPath(tsconfigPath) === this.formatPath(path));
1086
- if (resolvedPath) {
1087
- return this.formatPath(resolvedPath) === this.formatPath(path) ? this.formatPath(resolvedPath) : this.resolvePath(joinPaths(this.#context.workspaceConfig.workspaceRoot, resolvedPath.replaceAll("*", ""), path.replace(tsconfigPathKey.replaceAll("*", ""), "")));
1088
- }
1089
- }
1090
- }
1091
- return false;
1092
- }
1093
- /**
1094
- * Resolves a path based on TypeScript's `tsconfig.json` paths.
1095
- *
1096
- * @see https://www.typescriptlang.org/tsconfig#paths
1097
- *
1098
- * @param path - The path to check.
1099
- * @returns The resolved file path if it exists, otherwise undefined.
1100
- */
1101
- resolveTsconfigPathPackage(path) {
1102
- if (this.#context.tsconfig.options.paths) {
1103
- const tsconfigPathKeys = Object.keys(this.#context.tsconfig.options.paths).filter((tsconfigPath) => path.startsWith(tsconfigPath.replaceAll("*", "")));
1104
- if (tsconfigPathKeys.length > 0 && tsconfigPathKeys[0]) {
1105
- return tsconfigPathKeys[0].replace(/\/\*$/, "");
1106
- }
1107
- }
1108
- return false;
1109
- }
1110
- /**
1111
- * Resolves a path or ID to its real path in the virtual file system (VFS).
1112
- *
1113
- * @param pathOrId - The path or ID to resolve.
1114
- * @returns The resolved real path if it exists, otherwise undefined.
1115
- */
1116
- realpathSync(pathOrId) {
1117
- const filePath = this.resolve(toFilePath(pathOrId));
1118
- if (!filePath) {
1119
- throw new Error(`File not found: ${toFilePath(pathOrId)}`);
1120
- }
1121
- return filePath;
1122
- }
1123
- /**
1124
- * Resolves a path or ID parameter to a corresponding virtual file path in the virtual file system (VFS).
1125
- *
1126
- * @param pathOrId - The path or ID to resolve.
1127
- * @param options - Optional parameters for resolving the path, such as whether to include the file extension.
1128
- * @returns The resolved file path if it exists, otherwise undefined.
1129
- */
1130
- resolve(pathOrId, options = {}) {
1131
- const formattedPathOrId = toFilePath(pathOrId);
1132
- const resolverKey = `${formattedPathOrId}${options.withExtension ? "-ext" : ""}${options.paths ? `-${murmurhash(options.paths)}` : ""}${options.type ? `-${options.type}` : ""}`;
1133
- if (this.#cachedResolver.has(resolverKey)) {
1134
- return this.#cachedResolver.get(resolverKey);
1135
- }
1136
- let result = this.resolveId(formattedPathOrId);
1137
- if (!result) {
1138
- result = this.resolvePath(formattedPathOrId, options);
1139
- }
1140
- if (!result) {
1141
- result = false;
1142
- }
1143
- if (result && options.withExtension === false) {
1144
- return result.replace(/\.[m|c]?[t|j]sx?$/, "");
1145
- }
1146
- this.#cachedResolver.set(resolverKey, result);
1147
- return result;
1148
- }
1149
- /**
1150
- * Retrieves the partial metadata for all files in the virtual file system (VFS).
1151
- *
1152
- * @returns A record containing the partial metadata for all files.
1153
- */
1154
- getPartialMeta() {
1155
- return Object.fromEntries(Object.entries(this.#meta).filter(([_, data]) => isSetObject(data)));
1156
- }
1157
- buildRegex(strPattern) {
1158
- const token = "::GLOBSTAR::";
1159
- return new RegExp(`^${this.formatPath(strPattern).replace(/\*\*/g, token).replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, "[^/]*").replace(/\?/g, "[^/]").replace(new RegExp(token, "g"), ".*")}$`);
1160
- }
1161
- /**
1162
- * Converts a relative path to an absolute path based on the workspace and project root.
1163
- *
1164
- * @param path - The relative path to convert.
1165
- * @returns The absolute path.
1166
- */
1167
- formatPath(path) {
1168
- const formattedPath = toFilePath(path);
1169
- if (isAbsolutePath(formattedPath) || formattedPath.startsWith(this.#context.workspaceConfig.workspaceRoot)) {
1170
- return formattedPath;
1171
- } else if (formattedPath.startsWith(this.#context.config.projectRoot)) {
1172
- return joinPaths(this.#context.workspaceConfig.workspaceRoot, formattedPath);
1173
- }
1174
- return formattedPath;
1175
- }
1176
- /**
1177
- * Formats a file id by removing the file extension and prepending the runtime prefix.
1178
- *
1179
- * @param id - The file ID to format.
1180
- * @returns The formatted file ID.
1181
- */
1182
- formatId(id) {
1183
- const formattedId = toFilePath(id);
1184
- return `${this.#context.config.output.builtinPrefix}:${formattedId.replace(new RegExp(`^${this.#context.config.output.builtinPrefix}:`), "").replace(/^\\0/, "").replace(findFileDotExtensionSafe(formattedId), "")}`;
1185
- }
1186
- /**
1187
- * Resolves an id parameter to a corresponding virtual file path in the virtual file system (VFS).
1188
- *
1189
- * @param id - The id to resolve.
1190
- * @returns The resolved file id if it exists, otherwise undefined.
1191
- */
1192
- resolveId(id) {
1193
- if (this.#ids[this.formatId(id)]) {
1194
- return this.#ids[this.formatId(id)] || false;
1195
- }
1196
- return false;
1197
- }
1198
- /**
1199
- * Resolves a path parameter to a corresponding virtual file path in the virtual file system (VFS).
1200
- *
1201
- * @param path - The path to resolve.
1202
- * @param options - Optional parameters for resolving the path.
1203
- * @returns The resolved file path if it exists, otherwise undefined.
1204
- */
1205
- resolvePath(path, options = {}) {
1206
- if (isAbsolutePath(path)) {
1207
- if (this.#existsSync(path)) {
1208
- return path;
1209
- }
1210
- const result = this.checkVariants(path);
1211
- if (result) {
1212
- return result;
1213
- }
1214
- }
1215
- for (const parentPath of this.resolveParentPaths(path, options.paths)) {
1216
- const request = joinPaths(parentPath, path);
1217
- if (this.#existsSync(request)) {
1218
- return request;
1219
- }
1220
- const result = this.checkVariants(request);
1221
- if (result) {
1222
- return result;
1223
- }
1224
- }
1225
- return false;
1226
- }
1227
- resolveParentPaths(request, parents = []) {
1228
- let paths = [
1229
- this.#context.workspaceConfig.workspaceRoot,
1230
- joinPaths(this.#context.workspaceConfig.workspaceRoot, this.#context.config.projectRoot)
1231
- ];
1232
- if (this.#context.tsconfig.options.paths) {
1233
- paths = this.#context.tsconfig.options.paths ? Object.keys(this.#context.tsconfig.options.paths).filter((tsconfigPath) => request.startsWith(tsconfigPath.replaceAll("*", ""))).map((tsconfigPath) => this.#context.tsconfig.options.paths?.[tsconfigPath]).flat().reduce((ret, path) => {
1234
- if (path && !ret.includes(joinPaths(this.#context.workspaceConfig.workspaceRoot, path))) {
1235
- ret.push(joinPaths(this.#context.workspaceConfig.workspaceRoot, path));
1236
- }
1237
- return ret;
1238
- }, paths) : paths;
1239
- }
1240
- return paths.reduce((ret, path) => {
1241
- if (!ret.includes(path)) {
1242
- ret.push(path);
1243
- }
1244
- return ret;
1245
- }, parents.filter(Boolean).map((p) => this.formatPath(p)));
1246
- }
1247
- /**
1248
- * Select the file system module to use for the operation based on the path or URL.
1249
- *
1250
- * @param pathOrUrl - The path to perform the file system operation on.
1251
- * @param options - Options for the operation, such as output mode.
1252
- * @returns The file system module used for the operation.
1253
- */
1254
- resolveFS(pathOrUrl, options = {}) {
1255
- const mode = this.resolveOutputMode(pathOrUrl, options);
1256
- if (mode === "virtual") {
1257
- return this.#virtualFS;
1258
- } else if (mode === "fs") {
1259
- return this.#fs;
1260
- }
1261
- return this.#unifiedFS;
1262
- }
1263
- /**
1264
- * Select the file system module to use for the operation based on the path or URL.
1265
- *
1266
- * @param pathOrUrl - The path to perform the file system operation on.
1267
- * @param options - Options for the operation, such as output mode.
1268
- * @returns The file system module used for the operation.
1269
- */
1270
- resolveOutputMode(pathOrUrl, options = {}) {
1271
- if (options.mode === "virtual" && this.#context.config.output.mode !== "fs" && isParentPath(toFilePath(pathOrUrl), this.#context.artifactsPath)) {
1272
- return "virtual";
1273
- } else if (options.mode === "fs" || this.#context.config.output.mode === "fs" || isParentPath(toFilePath(pathOrUrl), this.#context.dataPath) || isParentPath(toFilePath(pathOrUrl), this.#context.cachePath) || isParentPath(toFilePath(pathOrUrl), joinPaths(this.#context.workspaceConfig.workspaceRoot, this.#context.config.output.outputPath))) {
1274
- return "fs";
1275
- }
1276
- return void 0;
1277
- }
1278
- /**
1279
- * Clears the resolver cache for a given path.
1280
- *
1281
- * @param path - The path to clear the resolver cache for.
1282
- */
1283
- clearResolverCache(path) {
1284
- this.#cachedResolver.keys().filter((key) => key.startsWith(toFilePath(path))).forEach((key) => this.#cachedResolver.delete(key));
1285
- }
1286
- /**
1287
- * Check if the file exists with different variants (index, extensions).
1288
- *
1289
- * @param request - The request path to check.
1290
- * @param parentPath - An optional parent path to prepend to the request.
1291
- * @returns The file path if it exists, otherwise false.
1292
- */
1293
- checkVariants(request, parentPath) {
1294
- const path = parentPath ? joinPaths(parentPath, request) : request;
1295
- let file = this.checkExtensions(path);
1296
- if (file) {
1297
- return file;
1298
- }
1299
- file = this.checkIndex(path);
1300
- if (file) {
1301
- return file;
1302
- }
1303
- return false;
1304
- }
1305
- /**
1306
- * Check if the index file exists in the given request path.
1307
- *
1308
- * @param request - The request path to check.
1309
- * @returns The index file path if it exists, otherwise false.
1310
- */
1311
- checkIndex(request) {
1312
- let file = joinPaths(request, "index");
1313
- if (this.#existsSync(file)) {
1314
- return file;
1315
- }
1316
- file = this.checkExtensions(file);
1317
- if (file) {
1318
- return file;
1319
- }
1320
- return false;
1321
- }
1322
- /**
1323
- * Check if the file exists with different extensions.
1324
- *
1325
- * @param request - The request path to check.
1326
- * @param vfs - The file system module to use for checking file existence.
1327
- * @returns The file path if it exists with any of the checked extensions, otherwise false.
1328
- */
1329
- checkExtensions(request) {
1330
- let file = `${request}.ts`;
1331
- if (this.#existsSync(file)) {
1332
- return file;
1333
- }
1334
- file = `${request}.mts`;
1335
- if (this.#existsSync(file)) {
1336
- return file;
1337
- }
1338
- file = `${request}.cts`;
1339
- if (this.#existsSync(file)) {
1340
- return file;
1341
- }
1342
- file = `${request}.tsx`;
1343
- if (this.#existsSync(file)) {
1344
- return file;
1345
- }
1346
- file = `${request}.js`;
1347
- if (this.#existsSync(file)) {
1348
- return file;
1349
- }
1350
- file = `${request}.mjs`;
1351
- if (this.#existsSync(file)) {
1352
- return file;
1353
- }
1354
- file = `${request}.cjs`;
1355
- if (this.#existsSync(file)) {
1356
- return file;
1357
- }
1358
- file = `${request}.jsx`;
1359
- if (this.#existsSync(file)) {
1360
- return file;
1361
- }
1362
- file = `${request}.json`;
1363
- if (this.#existsSync(file)) {
1364
- return file;
1365
- }
1366
- file = `${request}.d.ts`;
1367
- if (this.#existsSync(file)) {
1368
- return file;
1369
- }
1370
- return false;
1371
- }
1372
- };
1373
- function createVfs(context) {
1374
- const vfs = new VirtualFileSystem(context);
1375
- return vfs;
1376
- }
1377
- __name(createVfs, "createVfs");
1378
-
1379
- // src/internal/contexts/context.ts
1380
- var configCache = /* @__PURE__ */ new WeakMap();
1381
- var parseCache = /* @__PURE__ */ new WeakMap();
1382
- var PowerlinesContext = class _PowerlinesContext {
1383
- static {
1384
- __name(this, "PowerlinesContext");
1385
- }
1386
- #workspaceConfig;
1387
- #checksum = null;
1388
- #buildId = uuid();
1389
- #releaseId = uuid();
1390
- #timestamp = Date.now();
1391
- #envPaths;
1392
- #fs;
1393
- #tsconfig;
1394
- #getConfigProps(config = {}) {
1395
- return {
1396
- variant: config.build?.variant,
1397
- projectType: config.type,
1398
- projectRoot: config.root,
1399
- name: config.name,
1400
- title: config.title,
1401
- description: config.description,
1402
- sourceRoot: config.sourceRoot,
1403
- configFile: config.configFile,
1404
- customLogger: config.customLogger,
1405
- logLevel: config.logLevel,
1406
- tsconfig: config.tsconfig,
1407
- tsconfigRaw: config.tsconfigRaw,
1408
- skipCache: config.skipCache,
1409
- skipInstalls: config.skipInstalls,
1410
- entry: config.entry,
1411
- output: config.output,
1412
- plugins: config.plugins,
1413
- mode: config.mode,
1414
- lint: config.lint,
1415
- transform: config.transform,
1416
- build: config.build,
1417
- override: config.override,
1418
- framework: config.framework
1419
- };
1420
- }
1421
- /**
1422
- * Create a new Storm context from the workspace root and user config.
1423
- *
1424
- * @param workspaceRoot - The root directory of the workspace.
1425
- * @param config - The user configuration options.
1426
- * @returns A promise that resolves to the new context.
1427
- */
1428
- static async from(workspaceRoot, config) {
1429
- const context = new _PowerlinesContext(await loadWorkspaceConfig(workspaceRoot, config.root));
1430
- await context.withUserConfig(config);
1431
- context.powerlinesPath = await resolvePackage("powerlines");
1432
- if (!context.powerlinesPath) {
1433
- throw new Error("Could not resolve `powerlines` package location.");
1434
- }
1435
- return context;
1436
- }
1437
- /**
1438
- * An object containing the dependencies that should be installed for the project
1439
- */
1440
- dependencies = {};
1441
- /**
1442
- * An object containing the development dependencies that should be installed for the project
1443
- */
1444
- devDependencies = {};
1445
- /**
1446
- * The persisted meta information about the current build
1447
- */
1448
- persistedMeta = void 0;
1449
- /**
1450
- * The path to the Powerlines package
1451
- */
1452
- powerlinesPath;
1453
- /**
1454
- * The parsed `package.json` file for the project
1455
- */
1456
- packageJson;
1457
- /**
1458
- * The parsed `project.json` file for the project
1459
- */
1460
- projectJson = void 0;
1461
- /**
1462
- * The module resolver for the project
1463
- */
1464
- resolver;
1465
- /**
1466
- * The resolved entry type definitions for the project
1467
- */
1468
- get entry() {
1469
- return resolveEntriesSync(this, toArray(this.config.entry));
1470
- }
1471
- /**
1472
- * The TypeScript configuration parsed from the tsconfig file
1473
- */
1474
- get tsconfig() {
1475
- if (!this.#tsconfig) {
1476
- this.#tsconfig = {
1477
- tsconfigFilePath: this.config.tsconfig
1478
- };
1479
- }
1480
- return this.#tsconfig;
1481
- }
1482
- /**
1483
- * Sets the TypeScript configuration parsed from the tsconfig file
1484
- */
1485
- set tsconfig(value) {
1486
- this.#tsconfig = value;
1487
- }
1488
- /**
1489
- * The virtual file system interface for the project
1490
- */
1491
- get fs() {
1492
- if (!this.#fs) {
1493
- this.#fs = createVfs(this);
1494
- }
1495
- return this.#fs;
1496
- }
1497
- /**
1498
- * Get the checksum of the project's current state
1499
- */
1500
- get checksum() {
1501
- return this.#checksum;
1502
- }
1503
- /**
1504
- * The meta information about the current build
1505
- */
1506
- get meta() {
1507
- return {
1508
- buildId: this.#buildId,
1509
- releaseId: this.#releaseId,
1510
- checksum: this.#checksum,
1511
- timestamp: this.#timestamp,
1512
- projectRootHash: murmurhash({
1513
- workspaceRoot: this.workspaceConfig?.workspaceRoot,
1514
- projectRoot: this.config?.projectRoot
1515
- }, {
1516
- maxLength: PROJECT_ROOT_HASH_LENGTH
1517
- }),
1518
- configHash: murmurhash(this.config, {
1519
- maxLength: CACHE_HASH_LENGTH
1520
- }),
1521
- builtinIdMap: {},
1522
- virtualFiles: {}
1523
- };
1524
- }
1525
- /**
1526
- * The resolved configuration options
1527
- */
1528
- get config() {
1529
- return this.resolvedConfig ?? {};
1530
- }
1531
- /**
1532
- * The logger function
1533
- */
1534
- get log() {
1535
- if (!this.logFn) {
1536
- this.logFn = this.createLog();
1537
- }
1538
- return this.logFn;
1539
- }
1540
- /**
1541
- * The workspace configuration
1542
- */
1543
- get workspaceConfig() {
1544
- return this.#workspaceConfig;
1545
- }
1546
- /**
1547
- * The environment paths for the project
1548
- */
1549
- get envPaths() {
1550
- if (!this.#envPaths) {
1551
- this.#envPaths = getEnvPaths({
1552
- orgId: "storm-software",
1553
- appId: "powerlines",
1554
- workspaceRoot: this.workspaceConfig.workspaceRoot
1555
- });
1556
- }
1557
- return this.#envPaths;
1558
- }
1559
- /**
1560
- * Get the path to the artifacts directory for the project
1561
- */
1562
- get artifactsPath() {
1563
- return joinPaths$1(this.workspaceConfig.workspaceRoot, this.config.projectRoot, this.config.output.artifactsFolder);
1564
- }
1565
- /**
1566
- * Get the path to the builtin modules used by the project
1567
- */
1568
- get builtinsPath() {
1569
- return joinPaths$1(this.artifactsPath, "builtins");
1570
- }
1571
- /**
1572
- * Get the path to the entry directory for the project
1573
- */
1574
- get entryPath() {
1575
- return joinPaths$1(this.artifactsPath, "entry");
1576
- }
1577
- /**
1578
- * Get the path to the data directory for the project
1579
- */
1580
- get dataPath() {
1581
- return joinPaths$1(this.envPaths.data, "projects", getPrefixedProjectRootHash(this.config.name, this.meta.projectRootHash));
1582
- }
1583
- /**
1584
- * Get the path to the cache directory for the project
1585
- */
1586
- get cachePath() {
1587
- return joinPaths$1(this.envPaths.cache, "projects", murmurhash({
1588
- checksum: this.#checksum,
1589
- config: this.meta.configHash
1590
- }, {
1591
- maxLength: CACHE_HASH_LENGTH
1592
- }));
1593
- }
1594
- /**
1595
- * Get the path to the generated declaration file for the project
1596
- */
1597
- get dtsPath() {
1598
- return this.config.output.dts ? appendPath(this.config.output.dts, this.workspaceConfig.workspaceRoot) : joinPaths$1(this.workspaceConfig.workspaceRoot, this.config.projectRoot, "storm.d.ts");
1599
- }
1600
- /**
1601
- * Get the project root relative to the workspace root
1602
- */
1603
- get relativeToWorkspaceRoot() {
1604
- return relativeToWorkspaceRoot(this.config.projectRoot);
1605
- }
1606
- /**
1607
- * The builtin module id that exist in the Powerlines virtual file system
1608
- */
1609
- get builtins() {
1610
- return Object.values(this.fs.meta).filter((meta) => meta && meta.variant === "builtin").map((meta) => meta?.id).filter(Boolean);
1611
- }
1612
- /**
1613
- * Get the project root relative to the workspace root
1614
- */
1615
- async getBuiltins() {
1616
- return Promise.all(Object.entries(this.fs.meta).filter(([, meta]) => meta && meta.variant === "builtin").map(async ([path, meta]) => {
1617
- const code = await this.fs.readFile(path);
1618
- return {
1619
- ...meta,
1620
- path,
1621
- code
1622
- };
1623
- }));
1624
- }
1625
- /**
1626
- * Resolves a entry virtual file and writes it to the VFS if it does not already exist
1627
- *
1628
- * @param code - The source code of the entry file
1629
- * @param path - A path to write the entry file to
1630
- * @param options - Optional write file options
1631
- */
1632
- async writeEntry(code, path, options = {}) {
1633
- return this.fs.writeFile(isAbsolute(path) ? path : appendPath(path, this.entryPath), {
1634
- code,
1635
- variant: "entry"
1636
- }, defu3(options, {
1637
- mode: this.config.output.mode
1638
- }));
1639
- }
1640
- /**
1641
- * Resolves a builtin virtual file and writes it to the VFS if it does not already exist
1642
- *
1643
- * @param code - The source code of the builtin file
1644
- * @param id - The unique identifier of the builtin file
1645
- * @param path - An optional path to write the builtin file to
1646
- * @param options - Optional write file options
1647
- */
1648
- async writeBuiltin(code, id, path, options = {}) {
1649
- return this.fs.writeFile(path ? isAbsolute(path) ? path : joinPaths$1(this.builtinsPath, path) : appendPath(id, this.builtinsPath), {
1650
- id,
1651
- code,
1652
- variant: "builtin"
1653
- }, defu3(options, {
1654
- mode: this.config.output.mode
1655
- }));
1656
- }
1657
- /**
1658
- * Parses the source code and returns a {@link ParseResult} object.
1659
- *
1660
- * @param code - The source code to parse.
1661
- * @param id - The unique identifier for the source file.
1662
- * @param options - Optional parser options.
1663
- * @returns The parsed {@link ParseResult} object.
1664
- */
1665
- async parse(code, id, options = {}) {
1666
- if (parseCache.has({
1667
- code,
1668
- options
1669
- })) {
1670
- return parseCache.get({
1671
- code,
1672
- options
1673
- });
1674
- }
1675
- const result = await parseAsync(id, code, defu3(options ?? {}, {
1676
- lang: hasFileExtension(id) ? void 0 : "ts",
1677
- astType: hasFileExtension(id) ? void 0 : "ts",
1678
- sourceType: "module",
1679
- showSemanticErrors: false
1680
- }));
1681
- if (result.errors && result.errors.length > 0) {
1682
- throw new Error(`Powerlines parsing errors in file: ${id}
1683
- ${result.errors.map((error) => ` [${error.severity}] ${error.message}${error.codeframe ? ` (${error.codeframe})` : ""}${error.helpMessage ? `
1684
- Help: ${error.helpMessage}` : ""}`).join("\n")}`);
1685
- }
1686
- parseCache.set({
1687
- code,
1688
- options
1689
- }, result);
1690
- return result;
1691
- }
1692
- /**
1693
- * Update the context using a new user configuration options
1694
- *
1695
- * @param userConfig - The new user configuration options.
1696
- */
1697
- async withUserConfig(userConfig, options = {
1698
- isHighPriority: true
1699
- }) {
1700
- this.mergeUserConfig(userConfig);
1701
- await this.init(this.config.userConfig, options);
1702
- }
1703
- /**
1704
- * Update the context using a new inline configuration options
1705
- *
1706
- * @param inlineConfig - The new inline configuration options.
1707
- */
1708
- async withInlineConfig(inlineConfig, options = {
1709
- isHighPriority: true
1710
- }) {
1711
- this.config.inlineConfig = inlineConfig;
1712
- if (inlineConfig.command === "new") {
1713
- const workspacePackageJsonPath = joinPaths$1(this.workspaceConfig.workspaceRoot, "package.json");
1714
- if (!existsSync(workspacePackageJsonPath)) {
1715
- throw new Error(`The workspace package.json file could not be found at ${workspacePackageJsonPath}`);
1716
- }
1717
- this.packageJson = await readJsonFile(workspacePackageJsonPath);
1718
- this.workspaceConfig.repository ??= isSetString(this.packageJson?.repository) ? this.packageJson.repository : this.packageJson?.repository?.url;
1719
- }
1720
- await this.init(this.config.inlineConfig, options);
1721
- }
1722
- /**
1723
- * Create a new logger instance
1724
- *
1725
- * @param name - The name to use for the logger instance
1726
- * @returns A logger function
1727
- */
1728
- createLog(name = null) {
1729
- return createLog(name, {
1730
- ...this.config,
1731
- logLevel: isNull(this.config.logLevel) ? "silent" : this.config.logLevel
1732
- });
1733
- }
1734
- /**
1735
- * Extend the current logger instance with a new name
1736
- *
1737
- * @param name - The name to use for the extended logger instance
1738
- * @returns A logger function
1739
- */
1740
- extendLog(name) {
1741
- return extendLog(this.log, name);
1742
- }
1743
- /**
1744
- * Creates a new StormContext instance.
1745
- *
1746
- * @param workspaceConfig - The workspace configuration.
1747
- */
1748
- constructor(workspaceConfig) {
1749
- this.#workspaceConfig = workspaceConfig;
1750
- this.#envPaths = getEnvPaths({
1751
- orgId: "storm-software",
1752
- appId: "powerlines",
1753
- workspaceRoot: workspaceConfig.workspaceRoot
1754
- });
1755
- }
1756
- /**
1757
- * The resolved configuration for this context
1758
- */
1759
- resolvedConfig = {};
1760
- /**
1761
- * A logger function specific to this context
1762
- */
1763
- logFn;
1764
- /**
1765
- * Initialize the context with the provided configuration options
1766
- *
1767
- * @param config - The partial user configuration to use for initialization.
1768
- */
1769
- async init(config = {}, options = {
1770
- isHighPriority: true
1771
- }) {
1772
- const cacheKey = {
1773
- projectRoot: config.root ?? this.config.projectRoot ?? this.config.userConfig?.root ?? this.config.inlineConfig?.root,
1774
- mode: (config.mode ?? this.config.mode) || this.workspaceConfig.mode,
1775
- skipCache: config.skipCache ?? this.config.skipCache ?? false,
1776
- configFile: config.configFile ?? this.config.configFile,
1777
- command: this.config.inlineConfig?.command
1778
- };
1779
- if (configCache.has(cacheKey)) {
1780
- const result = configCache.get(cacheKey);
1781
- this.projectJson = result.projectJson;
1782
- this.packageJson = result.packageJson;
1783
- this.#checksum = result.checksum;
1784
- this.resolver = result.resolver;
1785
- this.mergeUserConfig(result.userConfig.config, this.config.userConfig);
1786
- } else {
1787
- const projectJsonPath = joinPaths$1(cacheKey.projectRoot, "project.json");
1788
- if (existsSync(projectJsonPath)) {
1789
- this.projectJson = await readJsonFile(projectJsonPath);
1790
- }
1791
- const packageJsonPath = joinPaths$1(cacheKey.projectRoot, "package.json");
1792
- if (existsSync(packageJsonPath)) {
1793
- this.packageJson = await readJsonFile(packageJsonPath);
1794
- }
1795
- this.#checksum = await getChecksum(cacheKey.projectRoot);
1796
- this.resolver = createResolver({
1797
- workspaceRoot: this.workspaceConfig.workspaceRoot,
1798
- projectRoot: cacheKey.projectRoot,
1799
- cacheDir: this.cachePath,
1800
- mode: cacheKey.mode,
1801
- skipCache: cacheKey.skipCache
1802
- });
1803
- const userConfig = await loadUserConfigFile(cacheKey.projectRoot, this.resolver, cacheKey.command, cacheKey.mode, cacheKey.configFile);
1804
- this.mergeUserConfig(userConfig.config);
1805
- configCache.set(cacheKey, {
1806
- projectJson: this.projectJson,
1807
- packageJson: this.packageJson,
1808
- checksum: this.#checksum,
1809
- resolver: this.resolver,
1810
- userConfig
1811
- });
1812
- }
1813
- if (isSetObject(config)) {
1814
- this.resolvedConfig = defu3({
1815
- inlineConfig: this.config.inlineConfig,
1816
- userConfig: this.config.userConfig
1817
- }, options.isHighPriority ? this.#getConfigProps(config) : {}, {
1818
- command: this.config.inlineConfig?.command,
1819
- ...this.#getConfigProps(this.config.inlineConfig)
1820
- }, this.#getConfigProps(this.config.userConfig), {
1821
- mode: this.workspaceConfig?.mode,
1822
- logLevel: this.workspaceConfig?.logLevel,
1823
- skipCache: this.workspaceConfig?.skipCache
1824
- }, {
1825
- name: this.projectJson?.name || this.packageJson?.name,
1826
- version: this.packageJson?.version,
1827
- description: this.packageJson?.description,
1828
- tsconfig: appendPath("tsconfig.json", cacheKey.projectRoot),
1829
- sourceRoot: this.projectJson?.sourceRoot || appendPath("src", cacheKey.projectRoot),
1830
- output: {
1831
- outputPath: joinPaths$1("dist", cacheKey.projectRoot),
1832
- mode: "virtual",
1833
- dts: joinPaths$1(cacheKey.projectRoot, `${config.framework ?? "powerlines"}.d.ts`),
1834
- builtinPrefix: config.framework ?? "powerlines",
1835
- artifactsFolder: joinPaths$1(cacheKey.projectRoot, `.${config.framework ?? "powerlines"}`),
1836
- assets: [
1837
- {
1838
- glob: "LICENSE"
1839
- },
1840
- {
1841
- input: cacheKey.projectRoot,
1842
- glob: "*.md"
1843
- },
1844
- {
1845
- input: cacheKey.projectRoot,
1846
- glob: "package.json"
1847
- }
1848
- ]
1849
- }
1850
- }, options.isHighPriority ? {} : this.#getConfigProps(config), {
1851
- inlineConfig: {},
1852
- userConfig: {},
1853
- framework: "powerlines",
1854
- platform: "neutral",
1855
- mode: "production",
1856
- projectType: "application",
1857
- logLevel: "info",
1858
- preview: false,
1859
- environments: {},
1860
- transform: {
1861
- babel: {
1862
- plugins: [],
1863
- presets: []
1864
- }
1865
- },
1866
- lint: {
1867
- eslint: {}
1868
- },
1869
- build: {
1870
- target: "esnext"
1871
- },
1872
- override: {}
1873
- });
1874
- }
1875
- this.config.entry = getUniqueEntries(this.config.entry);
1876
- if (this.config.name?.startsWith("@") && this.config.name.split("/").filter(Boolean).length > 1) {
1877
- this.config.name = this.config.name.split("/").filter(Boolean)[1];
1878
- }
1879
- this.config.title ??= titleCase(this.config.name);
1880
- if (this.config.build.external) {
1881
- this.config.build.external = getUnique(this.config.build.external);
1882
- }
1883
- if (this.config.build.noExternal) {
1884
- this.config.build.noExternal = getUnique(this.config.build.noExternal);
1885
- }
1886
- this.config.output.format = getUnique(toArray(this.config.output?.format ?? (this.config.projectType === "library" ? [
1887
- "cjs",
1888
- "esm"
1889
- ] : [
1890
- "esm"
1891
- ])));
1892
- this.config.output.outputPath ??= joinPaths$1("dist", this.config.projectRoot || ".");
1893
- this.config.output.assets = getUnique(this.config.output.assets.map((asset) => {
1894
- return {
1895
- glob: isSetObject(asset) ? asset.glob : asset,
1896
- input: isString(asset) || !asset.input || asset.input === "." || asset.input === "/" || asset.input === "./" ? this.workspaceConfig.workspaceRoot : appendPath(asset.input, this.workspaceConfig.workspaceRoot),
1897
- output: appendPath(isSetObject(asset) && asset.output ? joinPaths$1(this.config.output.outputPath, replacePath(asset.output, this.config.output.outputPath)) : this.config.output.outputPath, this.workspaceConfig.workspaceRoot),
1898
- ignore: isSetObject(asset) && asset.ignore ? toArray(asset.ignore) : void 0
1899
- };
1900
- }));
1901
- this.config.plugins = (this.config.plugins ?? []).filter(Boolean).reduce((ret, plugin) => {
1902
- if (isPlugin(plugin) && checkDedupe(plugin, ret.filter((p) => isPlugin(p)))) {
1903
- return ret;
1904
- }
1905
- ret.push(plugin);
1906
- return ret;
1907
- }, []);
1908
- }
1909
- mergeUserConfig(from = {}, into = this.config.userConfig ?? {}) {
1910
- this.config.userConfig = defu3({
1911
- entry: Array.isArray(from.entry) && from.entry.length > 0 ? from.entry : Array.isArray(into?.entry) && into.entry.length > 0 ? into.entry : []
1912
- }, omit(from ?? {}, [
1913
- "entry"
1914
- ]), omit(into ?? {}, [
1915
- "entry"
1916
- ]));
1917
- if (this.config.userConfig.output?.format) {
1918
- this.config.userConfig.output.format = getUnique(toArray(this.config.userConfig.output?.format));
1919
- }
1920
- this.config.userConfig.plugins = (this.config.userConfig.plugins ?? []).filter(Boolean).reduce((ret, plugin) => {
1921
- if (isPlugin(plugin) && checkDedupe(plugin, ret.filter((p) => isPlugin(p)))) {
1922
- return ret;
1923
- }
1924
- ret.push(plugin);
1925
- return ret;
1926
- }, []);
1927
- }
1928
- };
1929
-
1930
- // src/types/plugin.ts
1931
- var PLUGIN_NON_HOOK_FIELDS = [
1932
- "name",
1933
- "enforce",
1934
- "dedupe",
1935
- "dependsOn",
1936
- "applyToEnvironment"
1937
- ];
1938
- async function callHook(context, hook, options, ...args) {
1939
- const handlers = context.selectHooks(hook, options);
1940
- if (handlers.length > 0) {
1941
- context.log(LogLevelLabel.DEBUG, ` \u{1F9E9} Calling plugin hook: ${chalk4.bold.cyanBright(`${hook}${options?.order ? ` (${options.order})` : ""}`)}`);
1942
- let results = [];
1943
- if (options?.sequential === false) {
1944
- results = await Promise.all(handlers.map(async (handler) => {
1945
- if (!isFunction(handler)) {
1946
- throw new Error(`Plugin hook handler for hook "${hook}" is not a function.`);
1947
- }
1948
- return Promise.resolve(handler.apply(null, ...args));
1949
- }));
1950
- } else {
1951
- for (const handler of handlers) {
1952
- if (!isFunction(handler)) {
1953
- throw new Error(`Plugin hook handler for hook "${hook}" is not a function.`);
1954
- }
1955
- results.push(await Promise.resolve(handler.apply(null, ...args)));
1956
- if (options?.result === "first" && isSet(results[results.length - 1])) {
1957
- break;
1958
- }
1959
- }
1960
- }
1961
- const definedResults = results.filter((result) => isSet(result));
1962
- if (definedResults.length > 0) {
1963
- let mergedResult = void 0;
1964
- for (const result of definedResults) {
1965
- mergedResult = defu(result, mergedResult ?? {});
1966
- }
1967
- return mergedResult;
1968
- }
1969
- }
1970
- return void 0;
1971
- }
1972
- __name(callHook, "callHook");
1973
-
1974
- // src/internal/contexts/plugin-context.ts
1975
- function createPluginContext(plugin, environment) {
1976
- const normalizeMessage = /* @__PURE__ */ __name((message) => {
1977
- return isString(message) ? message : message.message;
1978
- }, "normalizeMessage");
1979
- const log = environment.extendLog(plugin.name);
1980
- const callHookFn = /* @__PURE__ */ __name(async (hook, options, ...args) => {
1981
- return callHook(environment, hook, {
1982
- sequential: true,
1983
- ...options
1984
- }, ...args);
1985
- }, "callHookFn");
1986
- return new Proxy({}, {
1987
- get(_, prop) {
1988
- if (prop === "$$internal") {
1989
- return {
1990
- environment,
1991
- callHook: callHookFn
1992
- };
1993
- }
1994
- if (prop === "log" || prop === "logger") {
1995
- return log;
1996
- }
1997
- if (prop === "error") {
1998
- return (message) => {
1999
- log(LogLevelLabel.ERROR, normalizeMessage(message));
2000
- };
2001
- }
2002
- if (prop === "warn") {
2003
- return (message) => {
2004
- log(LogLevelLabel.WARN, normalizeMessage(message));
2005
- };
2006
- }
2007
- return environment[prop];
2008
- },
2009
- set(_, prop, value) {
2010
- if ([
2011
- "$$internal",
2012
- "environment",
2013
- "config",
2014
- "log",
2015
- "logger",
2016
- "error",
2017
- "warn",
2018
- "plugins",
2019
- "hooks",
2020
- "addPlugin",
2021
- "selectHooks"
2022
- ].includes(prop)) {
2023
- log(LogLevelLabel.WARN, `Cannot set read-only property "${String(prop)}"`);
2024
- return false;
2025
- }
2026
- environment[prop] = value;
2027
- return true;
2028
- }
2029
- });
2030
- }
2031
- __name(createPluginContext, "createPluginContext");
2032
-
2033
- // src/internal/contexts/environment-context.ts
2034
- var PowerlinesEnvironmentContext = class _PowerlinesEnvironmentContext extends PowerlinesContext {
2035
- static {
2036
- __name(this, "PowerlinesEnvironmentContext");
2037
- }
2038
- #hooks = {};
2039
- /**
2040
- * Create a new Storm context from the workspace root and user config.
2041
- *
2042
- * @param workspaceConfig - The root directory of the workspace.
2043
- * @param config - The user configuration options.
2044
- * @returns A promise that resolves to the new context.
2045
- */
2046
- static async fromConfig(workspaceConfig, config) {
2047
- const context = new _PowerlinesEnvironmentContext(config, workspaceConfig);
2048
- await context.init();
2049
- context.powerlinesPath = await resolvePackage("powerlines");
2050
- if (!context.powerlinesPath) {
2051
- throw new Error("Could not resolve `powerlines` package location.");
2052
- }
2053
- return context;
2054
- }
2055
- environment;
2056
- plugins = [];
2057
- /**
2058
- * The resolved configuration options
2059
- */
2060
- get config() {
2061
- return super.config;
2062
- }
2063
- get hooks() {
2064
- return this.#hooks;
2065
- }
2066
- async addPlugin(plugin) {
2067
- let resolvedPlugin = plugin;
2068
- if (plugin.applyToEnvironment) {
2069
- const result = await Promise.resolve(plugin.applyToEnvironment(this.environment));
2070
- if (!result || isObject(result) && Object.keys(result).length === 0) {
2071
- return;
2072
- }
2073
- resolvedPlugin = isPlugin(result) ? result : plugin;
2074
- }
2075
- const context = createPluginContext(resolvedPlugin, this);
2076
- this.plugins.push({
2077
- plugin: resolvedPlugin,
2078
- context
2079
- });
2080
- this.#hooks = Object.keys(resolvedPlugin).filter((key) => !PLUGIN_NON_HOOK_FIELDS.includes(key)).reduce((ret, key) => {
2081
- const hook = key;
2082
- const pluginHook = resolvedPlugin[hook];
2083
- if (!isPluginHook(pluginHook)) {
2084
- return ret;
2085
- }
2086
- if (!isHookExternal(hook)) {
2087
- ret[hook] ??= {};
2088
- if (resolvedPlugin.enforce) {
2089
- ret[hook][`${resolvedPlugin.enforce}Enforced`] ??= [];
2090
- addPluginHook(context, resolvedPlugin, pluginHook, ret[hook][`${resolvedPlugin.enforce}Enforced`]);
2091
- return ret;
2092
- }
2093
- if (isFunction(pluginHook) || !pluginHook.order) {
2094
- ret[hook].normal ??= [];
2095
- addPluginHook(context, resolvedPlugin, pluginHook, ret[hook].normal);
2096
- return ret;
2097
- }
2098
- ret[hook][`${pluginHook.order}Ordered`] ??= [];
2099
- addPluginHook(context, resolvedPlugin, pluginHook, ret[hook][`${pluginHook.order}Ordered`]);
2100
- } else {
2101
- ret[hook] ??= [];
2102
- ret[hook].push({
2103
- plugin: resolvedPlugin,
2104
- hook: getHookHandler(pluginHook).bind(context)
2105
- });
2106
- }
2107
- return ret;
2108
- }, this.hooks);
2109
- }
2110
- /**
2111
- * Retrieves the hook handlers for a specific hook name
2112
- */
2113
- selectHooks(hook, options) {
2114
- const handlers = [];
2115
- if (this.hooks[hook]) {
2116
- if (!isHookExternal(hook)) {
2117
- const hooks = this.hooks[hook];
2118
- if (options?.order) {
2119
- if (options?.order === "pre") {
2120
- handlers.push(...(hooks.preOrdered ?? []).map((h) => h.handler));
2121
- handlers.push(...(hooks.preEnforced ?? []).map((h) => h.handler));
2122
- } else if (options?.order === "post") {
2123
- handlers.push(...(hooks.postOrdered ?? []).map((h) => h.handler));
2124
- handlers.push(...(hooks.postEnforced ?? []).map((h) => h.handler));
2125
- } else {
2126
- handlers.push(...(hooks.normal ?? []).map((h) => h.handler));
2127
- }
2128
- } else {
2129
- handlers.push(...this.selectHooks(hook, {
2130
- order: "pre"
2131
- }));
2132
- handlers.push(...this.selectHooks(hook, {
2133
- order: "normal"
2134
- }));
2135
- handlers.push(...this.selectHooks(hook, {
2136
- order: "post"
2137
- }));
2138
- }
2139
- } else {
2140
- handlers.push(...this.hooks[hook].map((h) => h.handler));
2141
- }
2142
- }
2143
- return handlers;
2144
- }
2145
- constructor(config, workspaceConfig) {
2146
- super(workspaceConfig);
2147
- this.resolvedConfig = config;
2148
- }
2149
- };
2150
-
2151
- // src/internal/contexts/api-context.ts
2152
- var PowerlinesAPIContext = class _PowerlinesAPIContext extends PowerlinesContext {
2153
- static {
2154
- __name(this, "PowerlinesAPIContext");
2155
- }
2156
- #environments = {};
2157
- #plugins = [];
2158
- #log;
2159
- /**
2160
- * Create a new Storm context from the workspace root and user config.
2161
- *
2162
- * @param workspaceRoot - The root directory of the workspace.
2163
- * @param config - The user configuration options.
2164
- * @returns A promise that resolves to the new context.
2165
- */
2166
- static async from(workspaceRoot, config) {
2167
- const context = new _PowerlinesAPIContext(await loadWorkspaceConfig(workspaceRoot, config.root));
2168
- await context.withUserConfig(config);
2169
- context.powerlinesPath = await resolvePackage("powerlines");
2170
- if (!context.powerlinesPath) {
2171
- throw new Error("Could not resolve `powerlines` package location.");
2172
- }
2173
- return context;
2174
- }
2175
- /**
2176
- * A record of all environments by name
2177
- */
2178
- get environments() {
2179
- return this.#environments;
2180
- }
2181
- get log() {
2182
- if (!this.#log) {
2183
- this.#log = this.createLog("engine");
2184
- }
2185
- return this.#log;
2186
- }
2187
- get plugins() {
2188
- return this.#plugins;
2189
- }
2190
- constructor(workspaceConfig) {
2191
- super(workspaceConfig);
2192
- }
2193
- /**
2194
- * Initialize the context with the provided configuration options
2195
- *
2196
- * @param config - The partial user configuration to use for initialization.
2197
- */
2198
- async init(config = {}) {
2199
- await super.init(config);
2200
- await Promise.all(toArray(this.config.userConfig.environments && Object.keys(this.config.userConfig.environments).length > 0 ? Object.keys(this.config.userConfig.environments).map((name) => createEnvironment(name, this.config.userConfig)) : createDefaultEnvironment(this.config.userConfig)).map(async (env) => {
2201
- this.#environments[env.name] = await this.in(env);
2202
- }));
2203
- }
2204
- /**
2205
- * A function to copy the context and update the fields for a specific environment
2206
- *
2207
- * @param environment - The environment configuration to use.
2208
- * @returns A new context instance with the updated environment.
2209
- */
2210
- async in(environment) {
2211
- let context;
2212
- if (this.environments[environment.name]) {
2213
- context = this.environments[environment.name];
2214
- } else {
2215
- context = await PowerlinesEnvironmentContext.fromConfig(this.workspaceConfig, this.config);
2216
- }
2217
- if (isSetObject(this.config.inlineConfig)) {
2218
- await context.withInlineConfig(this.config.inlineConfig);
2219
- }
2220
- context.environment = environment;
2221
- context.plugins = [];
2222
- for (const plugin of this.plugins) {
2223
- await context.addPlugin(plugin);
2224
- }
2225
- return context;
2226
- }
2227
- async addPlugin(plugin) {
2228
- this.plugins.push(plugin);
2229
- await Promise.all(Object.keys(this.environments).map(async (name) => {
2230
- await this.environments[name].addPlugin(plugin);
2231
- }));
2232
- }
2233
- async getEnvironment(name) {
2234
- let environment;
2235
- if (name) {
2236
- environment = this.environments[name];
2237
- }
2238
- if (Object.keys(this.environments).length === 1) {
2239
- environment = this.environments[Object.keys(this.environments)[0]];
2240
- this.log(LogLevelLabel.DEBUG, `Applying the only configured environment: ${chalk4.bold.cyanBright(environment?.environment.name)}`);
2241
- }
2242
- if (!environment) {
2243
- if (name) {
2244
- throw new Error(`Environment "${name}" not found.`);
2245
- }
2246
- environment = await this.in(createDefaultEnvironment(this.config.userConfig));
2247
- this.log(LogLevelLabel.WARN, `No environment specified, and no default environment found. Using a temporary default environment: ${chalk4.bold.cyanBright(environment?.environment.name)}`);
2248
- }
2249
- return environment;
2250
- }
2251
- async getEnvironmentSafe(name) {
2252
- try {
2253
- return await this.getEnvironment(name);
2254
- } catch {
2255
- return void 0;
2256
- }
2257
- }
2258
- };
2259
- function resolveModulePath(nodePath, state) {
2260
- if (!t.isStringLiteral(nodePath.node)) {
2261
- return;
2262
- }
2263
- const sourcePath = nodePath.node.value;
2264
- const resolvedPath = state.context?.fs.resolve(sourcePath);
2265
- if (resolvedPath) {
2266
- nodePath.replaceWith(t.stringLiteral(
2267
- // Remove the file extension if it exists
2268
- resolvedPath.replace(/\.(?:ts|mts|cts)x?$/, "")
2269
- ));
2270
- }
2271
- }
2272
- __name(resolveModulePath, "resolveModulePath");
2273
- var TRANSFORM_FUNCTIONS = [
2274
- "require",
2275
- "require.resolve",
2276
- "System.import",
2277
- // Jest methods
2278
- "jest.genMockFromModule",
2279
- "jest.mock",
2280
- "jest.unmock",
2281
- "jest.doMock",
2282
- // eslint-disable-next-line @cspell/spellchecker
2283
- "jest.dontMock",
2284
- "jest.setMock",
2285
- "jest.requireActual",
2286
- "jest.requireMock",
2287
- // Older Jest methods
2288
- "require.requireActual",
2289
- "require.requireMock"
2290
- ];
2291
- function matchesPattern(state, calleePath, pattern) {
2292
- const { node } = calleePath;
2293
- if (t.isMemberExpression(node)) {
2294
- return calleePath.matchesPattern(pattern);
2295
- }
2296
- if (!t.isIdentifier(node) || pattern.includes(".")) {
2297
- return false;
2298
- }
2299
- const name = pattern.split(".")[0];
2300
- return node.name === name;
2301
- }
2302
- __name(matchesPattern, "matchesPattern");
2303
- var importVisitors = {
2304
- CallExpression: /* @__PURE__ */ __name((nodePath, state) => {
2305
- if (state.moduleResolverVisited.has(nodePath)) {
2306
- return;
2307
- }
2308
- const calleePath = nodePath.get("callee");
2309
- if (calleePath && TRANSFORM_FUNCTIONS.some((pattern) => matchesPattern(state, calleePath, pattern)) || t.isImport(nodePath.node.callee)) {
2310
- state.moduleResolverVisited.add(nodePath);
2311
- resolveModulePath(nodePath.get("arguments.0"), state);
2312
- }
2313
- }, "CallExpression"),
2314
- // eslint-disable-next-line ts/naming-convention
2315
- "ImportDeclaration|ExportDeclaration|ExportAllDeclaration": /* @__PURE__ */ __name((nodePath, state) => {
2316
- if (!nodePath || !nodePath.get("source") || state.moduleResolverVisited.has(nodePath)) {
2317
- return;
2318
- }
2319
- state.moduleResolverVisited.add(nodePath);
2320
- resolveModulePath(nodePath.get("source"), state);
2321
- }, "ImportDeclaration|ExportDeclaration|ExportAllDeclaration")
2322
- };
2323
- var moduleResolverBabelPlugin = /* @__PURE__ */ __name((context) => {
2324
- return declare(/* @__PURE__ */ __name(function builder(api) {
2325
- let moduleResolverVisited = /* @__PURE__ */ new Set();
2326
- return {
2327
- name: "powerlines:module-resolver",
2328
- manipulateOptions(opts) {
2329
- opts.filename ??= "unknown";
2330
- },
2331
- pre() {
2332
- moduleResolverVisited = /* @__PURE__ */ new Set();
2333
- },
2334
- visitor: {
2335
- Program: {
2336
- enter(programPath, state) {
2337
- programPath.traverse(importVisitors, {
2338
- ...state,
2339
- context,
2340
- moduleResolverVisited,
2341
- api
2342
- });
2343
- },
2344
- exit(programPath, state) {
2345
- programPath.traverse(importVisitors, {
2346
- ...state,
2347
- context,
2348
- moduleResolverVisited,
2349
- api
2350
- });
2351
- }
2352
- }
2353
- },
2354
- post() {
2355
- moduleResolverVisited.clear();
2356
- }
2357
- };
2358
- }, "builder"));
2359
- }, "moduleResolverBabelPlugin");
2360
-
2361
- // src/internal/helpers/generate-types.ts
2362
- async function generateTypes(context) {
2363
- context.log(LogLevelLabel.TRACE, `Preparing the TypeScript definitions for the Powerlines project.`);
2364
- context.log(LogLevelLabel.TRACE, "Transforming built-ins runtime modules files.");
2365
- const builtinFiles = await context.getBuiltins();
2366
- const builtinFilePaths = await Promise.all(builtinFiles.map(async (file) => {
2367
- const result = await transformAsync(file.code.toString(), {
2368
- highlightCode: true,
2369
- code: true,
2370
- ast: false,
2371
- cloneInputAst: false,
2372
- comments: true,
2373
- sourceType: "module",
2374
- configFile: false,
2375
- babelrc: false,
2376
- envName: context.config.mode,
2377
- caller: {
2378
- name: "powerlines"
2379
- },
2380
- ...context.config.transform.babel,
2381
- filename: file.path,
2382
- plugins: [
2383
- [
2384
- "@babel/plugin-syntax-typescript"
2385
- ],
2386
- [
2387
- moduleResolverBabelPlugin(context)
2388
- ]
2389
- ]
2390
- });
2391
- if (!result?.code) {
2392
- throw new Error(`Powerlines - Generate Types failed to compile ${file.id}`);
2393
- }
2394
- context.log(LogLevelLabel.TRACE, `Writing transformed built-in runtime file ${file.id}.`);
2395
- await context.writeBuiltin(result.code, file.id, file.path);
2396
- return file.path;
2397
- }));
2398
- const typescriptPath = await resolvePackage("typescript");
2399
- if (!typescriptPath) {
2400
- throw new Error("Could not resolve TypeScript package location. Please ensure TypeScript is installed.");
2401
- }
2402
- const files = builtinFilePaths.reduce((ret, fileName) => {
2403
- const formatted = replacePath(fileName, context.workspaceConfig.workspaceRoot);
2404
- if (!ret.includes(formatted)) {
2405
- ret.push(formatted);
2406
- }
2407
- return ret;
2408
- }, [
2409
- joinPaths(typescriptPath, "lib", "lib.esnext.full.d.ts")
2410
- ]);
2411
- context.log(LogLevelLabel.TRACE, "Parsing TypeScript configuration for the Powerlines project.");
2412
- const resolvedTsconfig = getParsedTypeScriptConfig(context.workspaceConfig.workspaceRoot, context.config.projectRoot, context.tsconfig.tsconfigFilePath, defu3({
2413
- compilerOptions: {
2414
- strict: false,
2415
- noEmit: false,
2416
- declaration: true,
2417
- declarationMap: false,
2418
- emitDeclarationOnly: true,
2419
- skipLibCheck: true
2420
- },
2421
- exclude: [
2422
- "node_modules",
2423
- "dist"
2424
- ],
2425
- include: files
2426
- }, context.config.tsconfigRaw ?? {}));
2427
- resolvedTsconfig.options.configFilePath = joinPaths(context.workspaceConfig.workspaceRoot, context.tsconfig.tsconfigFilePath);
2428
- resolvedTsconfig.options.pathsBasePath = context.workspaceConfig.workspaceRoot;
2429
- resolvedTsconfig.options.suppressOutputPathCheck = true;
2430
- context.log(LogLevelLabel.TRACE, "Creating the TypeScript compiler host");
2431
- const program = createProgram(files, resolvedTsconfig.options, createCompilerHost(resolvedTsconfig.options));
2432
- context.log(LogLevelLabel.TRACE, `Running TypeScript compiler on ${builtinFiles.length} built-in runtime files.`);
2433
- let builtinModules = "";
2434
- const emitResult = program.emit(void 0, (fileName, text, _, __, sourceFiles, _data) => {
2435
- const sourceFile2 = sourceFiles?.[0];
2436
- if (sourceFile2?.fileName && !fileName.endsWith(".map")) {
2437
- if (builtinFiles.some((file) => file.id === sourceFile2.fileName || file.path === sourceFile2.fileName)) {
2438
- builtinModules += `
2439
- declare module "${context.fs.resolve(sourceFile2.fileName)}" {
2440
- ${text.trim().replace(/^\s*export\s*declare\s*/gm, "export ").replace(/^\s*declare\s*/gm, "")}
2441
- }
2442
- `;
2443
- }
2444
- }
2445
- }, void 0, true);
2446
- const diagnostics = getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
2447
- const diagnosticMessages = [];
2448
- diagnostics.forEach((diagnostic) => {
2449
- if (diagnostic.file) {
2450
- const { line, character } = getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start);
2451
- const message = flattenDiagnosticMessageText(diagnostic.messageText, "\n");
2452
- diagnosticMessages.push(`${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`);
2453
- } else {
2454
- const message = flattenDiagnosticMessageText(diagnostic.messageText, "\n");
2455
- diagnosticMessages.push(message);
2456
- }
2457
- });
2458
- const diagnosticMessage = diagnosticMessages.join("\n");
2459
- if (diagnosticMessage) {
2460
- throw new Error(`TypeScript compilation failed:
2461
-
2462
- ${diagnosticMessage.length > 5e3 ? `${diagnosticMessage.slice(0, 5e3)}...` : diagnosticMessage}`);
2463
- }
2464
- context.log(LogLevelLabel.TRACE, `Generating TypeScript declaration file in ${context.config.output.dts}.`);
2465
- const sourceFile = getSourceFile(String(context.config.output.dts), `/// <reference types="powerlines/shared" />${context.config.build.platform !== "neutral" ? `
2466
- /// <reference types="powerlines/${context.config.build.platform}" />` : ""}
2467
-
2468
- ${getFileHeader(context, {
2469
- directive: null,
2470
- prettierIgnore: false
2471
- })}
2472
-
2473
- ${builtinModules}`.replace(
2474
- // eslint-disable-next-line regexp/no-super-linear-backtracking
2475
- /import\s*(?:type\s*)?\{?[\w,\s]*(?:\}\s*)?from\s*(?:'|")@?[a-zA-Z0-9-\\/.]*(?:'|");?/g,
2476
- ""
2477
- ).replaceAll("#private;", "").replace(/__Ω/g, ""));
2478
- await context.fs.writeFile(sourceFile.id, getString(sourceFile.code), {
2479
- mode: "fs"
2480
- });
2481
- }
2482
- __name(generateTypes, "generateTypes");
2483
- async function installPackage(context, packageName, dev = false) {
2484
- if (!await isPackageListed(getPackageName(packageName), {
2485
- cwd: context.config.projectRoot
2486
- })) {
2487
- if (context.config.skipInstalls !== true && !process.env.POWERLINES_LOCAL) {
2488
- context.log(LogLevelLabel.WARN, `The package "${packageName}" is not installed. It will be installed automatically.`);
2489
- const result = await install(packageName, {
2490
- cwd: context.config.projectRoot,
2491
- dev
2492
- });
2493
- if (isNumber(result.exitCode) && result.exitCode > 0) {
2494
- context.log(LogLevelLabel.ERROR, result.stderr);
2495
- throw new Error(`An error occurred while installing the package "${packageName}"`);
2496
- }
2497
- } else {
2498
- context.log(LogLevelLabel.WARN, `The package "${packageName}" is not installed. Since the "skipInstalls" option is set to true, it will not be installed automatically.`);
2499
- }
2500
- } else if (hasPackageVersion(packageName) && !process.env.POWERLINES_SKIP_VERSION_CHECK) {
2501
- const isMatching = await doesPackageMatch(getPackageName(packageName), getPackageVersion(packageName), context.config.projectRoot);
2502
- if (!isMatching) {
2503
- const packageListing = await getPackageListing(getPackageName(packageName), {
2504
- cwd: context.config.projectRoot
2505
- });
2506
- if (!packageListing?.version.startsWith("catalog:") && !packageListing?.version.startsWith("workspace:")) {
2507
- context.log(LogLevelLabel.WARN, `The package "${getPackageName(packageName)}" is installed but does not match the expected version ${getPackageVersion(packageName)} (installed version: ${packageListing?.version || "<Unknown>"}). Please ensure this is intentional before proceeding. Note: You can skip this validation with the "STORM_STACK_SKIP_VERSION_CHECK" environment variable.`);
2508
- }
2509
- }
2510
- }
2511
- }
2512
- __name(installPackage, "installPackage");
2513
-
2514
- // src/internal/helpers/install-dependencies.ts
2515
- async function installDependencies(context) {
2516
- context.log(LogLevelLabel.TRACE, `Checking and installing missing project dependencies.`);
2517
- context.dependencies ??= {};
2518
- context.log(LogLevelLabel.TRACE, `The following packages are required:
2519
- Dependencies:
2520
- ${Object.entries(context.dependencies).map(([name, version]) => `- ${name}@${String(version)}`).join(" \n")}
2521
-
2522
- DevDependencies:
2523
- ${Object.entries(context.devDependencies).map(([name, version]) => `- ${name}@${String(version)}`).join(" \n")}`);
2524
- await Promise.all([
2525
- Promise.all(Object.entries(context.dependencies).map(async ([name, version]) => installPackage(context, `${getPackageName(name)}@${String(version)}`, false))),
2526
- Promise.all(Object.entries(context.devDependencies).map(async ([name, version]) => installPackage(context, `${getPackageName(name)}@${String(version)}`, true)))
2527
- ]);
2528
- }
2529
- __name(installDependencies, "installDependencies");
2530
- async function resolveTsconfigChanges(context) {
2531
- const tsconfig = getParsedTypeScriptConfig(context.workspaceConfig.workspaceRoot, context.config.projectRoot, context.config.tsconfig, context.config.tsconfigRaw);
2532
- const tsconfigFilePath = getTsconfigFilePath(context.workspaceConfig.workspaceRoot, context.config.projectRoot, context.config.tsconfig);
2533
- const tsconfigJson = await readJsonFile(tsconfigFilePath);
2534
- tsconfigJson.compilerOptions ??= {};
2535
- const extendedTsconfig = await loadTsConfig(tsconfigFilePath);
2536
- extendedTsconfig.compilerOptions ??= {};
2537
- if (tsconfigJson.reflection !== true) {
2538
- tsconfigJson.reflection = true;
2539
- }
2540
- if (tsconfig.options.experimentalDecorators !== true) {
2541
- tsconfigJson.compilerOptions.experimentalDecorators = true;
2542
- }
2543
- if (tsconfig.options.emitDecoratorMetadata !== true) {
2544
- tsconfigJson.compilerOptions.emitDecoratorMetadata = true;
2545
- }
2546
- if (context.config.output.dts) {
2547
- const dtsFilePath = context.config.output.dts ? context.config.output.dts.startsWith(context.workspaceConfig.workspaceRoot) ? context.config.output.dts : joinPaths(context.workspaceConfig.workspaceRoot, context.config.output.dts) : joinPaths(context.workspaceConfig.workspaceRoot, context.config.projectRoot, "storm.d.ts");
2548
- const dtsRelativePath = joinPaths(relativePath(joinPaths(context.workspaceConfig.workspaceRoot, context.config.projectRoot), findFilePath(dtsFilePath)), findFileName(dtsFilePath));
2549
- if (!tsconfigJson.include?.some((filePattern) => isIncludeMatchFound(filePattern, [
2550
- dtsFilePath,
2551
- dtsRelativePath,
2552
- "storm.d.ts"
2553
- ]))) {
2554
- tsconfigJson.include ??= [];
2555
- tsconfigJson.include.push(dtsRelativePath.startsWith("./") ? dtsRelativePath.slice(2) : dtsRelativePath);
2556
- }
2557
- }
2558
- if (!tsconfig.options.lib?.some((lib) => [
2559
- "lib.esnext.d.ts",
2560
- "lib.es2021.d.ts",
2561
- "lib.es2022.d.ts",
2562
- "lib.es2023.d.ts"
2563
- ].includes(lib.toLowerCase()))) {
2564
- tsconfigJson.compilerOptions.lib ??= [];
2565
- tsconfigJson.compilerOptions.lib.push("esnext");
2566
- }
2567
- if (tsconfig.options.module !== ts.ModuleKind.ESNext) {
2568
- tsconfigJson.compilerOptions.module = "ESNext";
2569
- }
2570
- if (!tsconfig.options.target || ![
2571
- ts.ScriptTarget.ESNext,
2572
- ts.ScriptTarget.ES2024,
2573
- ts.ScriptTarget.ES2023,
2574
- ts.ScriptTarget.ES2022,
2575
- ts.ScriptTarget.ES2021
2576
- ].includes(tsconfig.options.target)) {
2577
- tsconfigJson.compilerOptions.target = "ESNext";
2578
- }
2579
- if (tsconfig.options.moduleResolution !== ts.ModuleResolutionKind.Bundler) {
2580
- tsconfigJson.compilerOptions.moduleResolution = "Bundler";
2581
- }
2582
- if (tsconfig.options.moduleDetection !== ts.ModuleDetectionKind.Force) {
2583
- tsconfigJson.compilerOptions.moduleDetection = "force";
2584
- }
2585
- if (tsconfig.options.allowSyntheticDefaultImports !== true) {
2586
- tsconfigJson.compilerOptions.allowSyntheticDefaultImports = true;
2587
- }
2588
- if (tsconfig.options.noImplicitOverride !== true) {
2589
- tsconfigJson.compilerOptions.noImplicitOverride = true;
2590
- }
2591
- if (tsconfig.options.noUncheckedIndexedAccess !== true) {
2592
- tsconfigJson.compilerOptions.noUncheckedIndexedAccess = true;
2593
- }
2594
- if (tsconfig.options.skipLibCheck !== true) {
2595
- tsconfigJson.compilerOptions.skipLibCheck = true;
2596
- }
2597
- if (tsconfig.options.resolveJsonModule !== true) {
2598
- tsconfigJson.compilerOptions.resolveJsonModule = true;
2599
- }
2600
- if (tsconfig.options.isolatedModules !== true) {
2601
- tsconfigJson.compilerOptions.isolatedModules = true;
2602
- }
2603
- if (tsconfig.options.verbatimModuleSyntax !== false) {
2604
- tsconfigJson.compilerOptions.verbatimModuleSyntax = false;
2605
- }
2606
- if (tsconfig.options.allowJs !== true) {
2607
- tsconfigJson.compilerOptions.allowJs = true;
2608
- }
2609
- if (tsconfig.options.esModuleInterop !== true) {
2610
- tsconfigJson.compilerOptions.esModuleInterop = true;
2611
- }
2612
- if (tsconfig.options.declaration !== true) {
2613
- tsconfigJson.compilerOptions.declaration = true;
2614
- }
2615
- if (context.environment.consumer === "client") {
2616
- if (tsconfig.options.jsx !== ts.JsxEmit.ReactJSX) {
2617
- tsconfigJson.compilerOptions.jsx = "react-jsx";
2618
- }
2619
- if (!tsconfig.options.lib?.some((lib) => lib.toLowerCase() !== "dom")) {
2620
- tsconfigJson.compilerOptions.lib ??= [];
2621
- tsconfigJson.compilerOptions.lib.push("dom");
2622
- }
2623
- if (!tsconfig.options.lib?.some((lib) => lib.toLowerCase() !== "dom.iterable")) {
2624
- tsconfigJson.compilerOptions.lib ??= [];
2625
- tsconfigJson.compilerOptions.lib.push("dom.iterable");
2626
- }
2627
- } else if (context.config.build.platform === "node") {
2628
- if (!tsconfig.options.types?.some((type) => type.toLowerCase() === "node" || type.toLowerCase() === "@types/node")) {
2629
- tsconfigJson.compilerOptions.types ??= [];
2630
- tsconfigJson.compilerOptions.types.push("node");
2631
- }
2632
- }
2633
- return tsconfigJson;
2634
- }
2635
- __name(resolveTsconfigChanges, "resolveTsconfigChanges");
2636
- async function initializeTsconfig(context) {
2637
- context.log(LogLevelLabel.TRACE, "Initializing TypeScript configuration (tsconfig.json) for the Powerlines project.");
2638
- if (!isPackageExists("typescript")) {
2639
- throw new Error('The TypeScript package is not installed. Please install the package using the command: "npm install typescript --save-dev"');
2640
- }
2641
- const tsconfigFilePath = getTsconfigFilePath(context.workspaceConfig.workspaceRoot, context.config.projectRoot, context.config.tsconfig);
2642
- context.tsconfig.originalTsconfigJson = await readJsonFile(tsconfigFilePath);
2643
- context.tsconfig.tsconfigJson = await resolveTsconfigChanges(context);
2644
- await context.fs.writeFile(tsconfigFilePath, StormJSON.stringify(context.tsconfig.tsconfigJson), {
2645
- mode: "fs"
2646
- });
2647
- context.tsconfig = getParsedTypeScriptConfig(context.workspaceConfig.workspaceRoot, context.config.projectRoot, context.config.tsconfig, context.config.tsconfigRaw, context.tsconfig.originalTsconfigJson);
2648
- }
2649
- __name(initializeTsconfig, "initializeTsconfig");
2650
- async function resolveTsconfig(context) {
2651
- const updateTsconfigJson = await readJsonFile(context.tsconfig.tsconfigFilePath);
2652
- if (updateTsconfigJson?.compilerOptions?.types && Array.isArray(updateTsconfigJson.compilerOptions.types) && !updateTsconfigJson.compilerOptions.types.length) {
2653
- delete updateTsconfigJson.compilerOptions.types;
2654
- }
2655
- const result = getObjectDiff(context.tsconfig.originalTsconfigJson, updateTsconfigJson, {
2656
- ignoreArrayOrder: true,
2657
- showOnly: {
2658
- statuses: [
2659
- "added",
2660
- "deleted",
2661
- "updated"
2662
- ],
2663
- granularity: "deep"
2664
- }
2665
- });
2666
- const changes = [];
2667
- const getChanges = /* @__PURE__ */ __name((difference, property) => {
2668
- if (difference.status === "added" || difference.status === "deleted" || difference.status === "updated") {
2669
- if (difference.diff) {
2670
- for (const diff of difference.diff) {
2671
- getChanges(diff, property ? `${property}.${difference.property}` : difference.property);
2672
- }
2673
- } else {
2674
- changes.push({
2675
- field: property ? `${property}.${difference.property}` : difference.property,
2676
- status: difference.status,
2677
- previous: difference.status === "added" ? "---" : StormJSON.stringify(difference.previousValue),
2678
- current: difference.status === "deleted" ? "---" : StormJSON.stringify(difference.currentValue)
2679
- });
2680
- }
2681
- }
2682
- }, "getChanges");
2683
- for (const diff of result.diff) {
2684
- getChanges(diff);
2685
- }
2686
- if (changes.length > 0) {
2687
- context.log(LogLevelLabel.WARN, `Updating the following configuration values in "${context.tsconfig.tsconfigFilePath}" file:
2688
-
2689
- ${changes.map((change, i) => `${chalk4.bold.whiteBright(`${i + 1}. ${titleCase(change.status)} the ${change.field} field: `)}
2690
- ${chalk4.red(` - Previous: ${change.previous} `)}
2691
- ${chalk4.green(` - Updated: ${change.current} `)}
2692
- `).join("\n")}
2693
- `);
2694
- }
2695
- await writeFile(context.log, context.tsconfig.tsconfigFilePath, StormJSON.stringify(updateTsconfigJson));
2696
- context.tsconfig = getParsedTypeScriptConfig(context.workspaceConfig.workspaceRoot, context.config.projectRoot, context.config.tsconfig);
2697
- if (!context.tsconfig) {
2698
- throw new Error("Failed to parse the TypeScript configuration file.");
2699
- }
2700
- context.tsconfig.tsconfigJson.compilerOptions ??= {};
2701
- context.tsconfig.tsconfigJson.compilerOptions.strict = false;
2702
- }
2703
- __name(resolveTsconfig, "resolveTsconfig");
2704
-
2705
- // src/internal/api.ts
2706
- var PowerlinesAPI = class _PowerlinesAPI {
2707
- static {
2708
- __name(this, "PowerlinesAPI");
2709
- }
2710
- /**
2711
- * The Powerlines context
2712
- */
2713
- #context;
2714
- /**
2715
- * The Powerlines context
2716
- */
2717
- get context() {
2718
- return this.#context;
2719
- }
2720
- /**
2721
- * Create a new Powerlines API instance
2722
- *
2723
- * @param context - The Powerlines context
2724
- */
2725
- constructor(context) {
2726
- this.#context = context;
2727
- }
2728
- /**
2729
- * Initialize the Powerlines API
2730
- */
2731
- static async from(workspaceRoot, config) {
2732
- const api = new _PowerlinesAPI(await PowerlinesAPIContext.from(workspaceRoot, config));
2733
- for (const plugin of api.context.config.plugins ?? []) {
2734
- await api.#addPlugin(plugin);
2735
- }
2736
- if (api.context.plugins.length === 0) {
2737
- api.context.log(LogLevelLabel.WARN, "No Powerlines plugins were specified in the options. Please ensure this is correct, as it is generally not recommended.");
2738
- }
2739
- const pluginConfig = await callHook(await api.context.getEnvironment(), "config", {
2740
- sequential: true,
2741
- result: "merge"
2742
- });
2743
- await api.context.withUserConfig(pluginConfig, {
2744
- isHighPriority: false
2745
- });
2746
- return api;
2747
- }
2748
- /**
2749
- * Prepare the Powerlines API
2750
- */
2751
- async prepare(inlineConfig = {
2752
- command: "prepare"
2753
- }) {
2754
- this.context.log(LogLevelLabel.TRACE, " \u{1F3D7}\uFE0F Preparing the Powerlines project");
2755
- this.context.log(LogLevelLabel.TRACE, " \u2699\uFE0F Aggregating configuration options for the Powerlines project");
2756
- await this.context.withInlineConfig(inlineConfig);
2757
- await this.#executeEnvironments(async (context) => {
2758
- context.log(LogLevelLabel.TRACE, `Initializing the processing options for the Powerlines project.`);
2759
- await this.callPreHook(context, "configResolved");
2760
- await initializeTsconfig(context);
2761
- await this.callNormalHook(context, "configResolved");
2762
- context.log(LogLevelLabel.DEBUG, `The configuration provided ${toArray(context.config.entry).length} entry point(s), Powerlines has found ${context.entry.length} entry files(s) for the ${context.config.title} project${context.entry.length > 0 && context.entry.length < 10 ? `:
2763
- ${context.entry.map((entry) => `- ${entry.input.file || entry.file}${entry.output ? ` -> ${entry.output}` : ""}`).join(" \n")}` : ""}.`);
2764
- await resolveTsconfig(context);
2765
- await installDependencies(context);
2766
- await this.callPostHook(context, "configResolved");
2767
- context.log(LogLevelLabel.TRACE, `Powerlines configuration has been resolved:
2768
-
2769
- ${formatLogMessage(context.config)}`);
2770
- context.fs[__VFS_INIT__]();
2771
- await writeMetaFile(context);
2772
- context.persistedMeta = context.meta;
2773
- if (!existsSync(context.cachePath)) {
2774
- await createDirectory(context.cachePath);
2775
- }
2776
- if (!existsSync(context.dataPath)) {
2777
- await createDirectory(context.dataPath);
2778
- }
2779
- await this.callPreHook(context, "prepare");
2780
- if (context.config.projectType === "application") {
2781
- context.log(LogLevelLabel.TRACE, "Generating built-in barrel file");
2782
- }
2783
- if (context.config.output.dts !== false) {
2784
- await generateTypes(context);
2785
- }
2786
- await this.callNormalHook(context, "prepare");
2787
- context.tsconfig = getParsedTypeScriptConfig(context.workspaceConfig.workspaceRoot, context.config.projectRoot, context.config.tsconfig);
2788
- if (!context.tsconfig) {
2789
- throw new Error("Failed to parse the TypeScript configuration file.");
2790
- }
2791
- await this.callPostHook(context, "prepare");
2792
- await writeMetaFile(context);
2793
- context.fs[__VFS_REVERT__]();
2794
- });
2795
- this.context.log(LogLevelLabel.INFO, "Powerlines API has been prepared successfully");
2796
- }
2797
- /**
2798
- * Create a new Powerlines project
2799
- *
2800
- * @remarks
2801
- * This method will create a new Powerlines project in the current directory.
2802
- *
2803
- * @param inlineConfig - The inline configuration for the new command
2804
- * @returns A promise that resolves when the project has been created
2805
- */
2806
- async new(inlineConfig) {
2807
- this.context.log(LogLevelLabel.INFO, "\u{1F195} Creating a new Powerlines project");
2808
- await this.prepare(inlineConfig);
2809
- await this.#executeEnvironments(async (context) => {
2810
- context.log(LogLevelLabel.TRACE, `Initializing the processing options for the Powerlines project.`);
2811
- await this.callPreHook(context, "new");
2812
- const files = await listFiles(joinPaths(context.powerlinesPath, "files/common/**/*.hbs"));
2813
- for (const file of files) {
2814
- context.log(LogLevelLabel.TRACE, `Adding template file: ${file}`);
2815
- const template = Handlebars.compile(file);
2816
- await writeFile(context.log, joinPaths(context.config.projectRoot, file.replace(".hbs", "")), template(context));
2817
- }
2818
- await this.callNormalHook(context, "new");
2819
- if (context.config.projectType === "application") {
2820
- const files2 = await listFiles(joinPaths(context.powerlinesPath, "files/application/**/*.hbs"));
2821
- for (const file of files2) {
2822
- context.log(LogLevelLabel.TRACE, `Adding application template file: ${file}`);
2823
- const template = Handlebars.compile(file);
2824
- await writeFile(context.log, joinPaths(context.config.projectRoot, file.replace(".hbs", "")), template(context));
2825
- }
2826
- } else {
2827
- const files2 = await listFiles(joinPaths(context.powerlinesPath, "files/library/**/*.hbs"));
2828
- for (const file of files2) {
2829
- context.log(LogLevelLabel.TRACE, `Adding library template file: ${file}`);
2830
- const template = Handlebars.compile(file);
2831
- await writeFile(context.log, joinPaths(context.config.projectRoot, file.replace(".hbs", "")), template(context));
2832
- }
2833
- }
2834
- await this.callPostHook(context, "new");
2835
- });
2836
- this.context.log(LogLevelLabel.TRACE, "Powerlines - New command completed");
2837
- }
2838
- /**
2839
- * Clean any previously prepared artifacts
2840
- *
2841
- * @remarks
2842
- * This method will remove the previous Powerlines artifacts from the project.
2843
- *
2844
- * @param inlineConfig - The inline configuration for the clean command
2845
- * @returns A promise that resolves when the clean command has completed
2846
- */
2847
- async clean(inlineConfig = {
2848
- command: "clean"
2849
- }) {
2850
- this.context.log(LogLevelLabel.INFO, "\u{1F9F9} Cleaning the previous Powerlines artifacts");
2851
- await this.prepare(inlineConfig);
2852
- await this.#executeEnvironments(async (context) => {
2853
- await callHook(context, "clean", {
2854
- sequential: true
2855
- });
2856
- });
2857
- this.context.log(LogLevelLabel.TRACE, "Powerlines - Clean command completed");
2858
- }
2859
- /**
2860
- * Lint the project
2861
- *
2862
- * @param inlineConfig - The inline configuration for the lint command
2863
- * @returns A promise that resolves when the lint command has completed
2864
- */
2865
- async lint(inlineConfig = {
2866
- command: "lint"
2867
- }) {
2868
- this.context.log(LogLevelLabel.INFO, "\u{1F4CB} Linting the Powerlines project");
2869
- await this.prepare(inlineConfig);
2870
- await this.#executeEnvironments(async (context) => {
2871
- if (context.config.lint !== false) {
2872
- await this.callHook(context, "lint");
2873
- }
2874
- });
2875
- this.context.log(LogLevelLabel.TRACE, "Powerlines linting completed");
2876
- }
2877
- /**
2878
- * Build the project
2879
- *
2880
- * @remarks
2881
- * This method will build the Powerlines project, generating the necessary artifacts.
2882
- *
2883
- * @param inlineConfig - The inline configuration for the build command
2884
- * @returns A promise that resolves when the build command has completed
2885
- */
2886
- async build(inlineConfig = {
2887
- command: "build"
2888
- }) {
2889
- this.context.log(LogLevelLabel.INFO, "\u{1F4E6} Building the Powerlines project");
2890
- await this.prepare(inlineConfig);
2891
- await this.#executeEnvironments(async (context) => {
2892
- await this.callPreHook(context, "build");
2893
- await this.callNormalHook(context, "build");
2894
- await Promise.all(context.config.output.assets.map(async (asset) => {
2895
- context.log(LogLevelLabel.DEBUG, `Copying asset(s): ${chalk4.redBright(context.workspaceConfig.workspaceRoot === asset.input ? asset.glob : joinPaths(replacePath(asset.input, context.workspaceConfig.workspaceRoot), asset.glob))} -> ${chalk4.greenBright(joinPaths(replacePath(asset.output, context.workspaceConfig.workspaceRoot), asset.glob))} ${Array.isArray(asset.ignore) && asset.ignore.length > 0 ? ` (ignoring: ${asset.ignore.map((i) => chalk4.yellowBright(i)).join(", ")})` : ""}`);
2896
- await copyFiles(asset, asset.output);
2897
- }));
2898
- await this.callPostHook(context, "build");
2899
- });
2900
- this.context.log(LogLevelLabel.TRACE, "Powerlines build completed");
2901
- }
2902
- /**
2903
- * Prepare the documentation for the project
2904
- *
2905
- * @param inlineConfig - The inline configuration for the docs command
2906
- * @returns A promise that resolves when the documentation generation has completed
2907
- */
2908
- async docs(inlineConfig = {
2909
- command: "docs"
2910
- }) {
2911
- this.context.log(LogLevelLabel.INFO, "\u{1F4D3} Generating documentation for the Powerlines project");
2912
- await this.prepare(inlineConfig);
2913
- await this.#executeEnvironments(async (context) => {
2914
- context.log(LogLevelLabel.TRACE, "Writing documentation for the Powerlines project artifacts.");
2915
- await this.prepare(inlineConfig);
2916
- await this.#executeEnvironments(async (context2) => {
2917
- await this.callHook(context2, "docs");
2918
- });
2919
- });
2920
- this.#context.log(LogLevelLabel.TRACE, "Powerlines documentation generation completed");
2921
- }
2922
- /**
2923
- * Release the project
2924
- *
2925
- * @remarks
2926
- * This method will prepare and build the Powerlines project, generating the necessary artifacts for release.
2927
- *
2928
- * @param inlineConfig - The inline configuration for the release command
2929
- */
2930
- async release(inlineConfig = {
2931
- command: "release"
2932
- }) {
2933
- this.context.log(LogLevelLabel.INFO, "\u{1F4E6} Releasing the Powerlines project");
2934
- await this.prepare(inlineConfig);
2935
- await this.#executeEnvironments(async (context) => {
2936
- await this.callHook(context, "release");
2937
- });
2938
- this.context.log(LogLevelLabel.TRACE, "Powerlines release completed");
2939
- }
2940
- /**
2941
- * Finalization process
2942
- *
2943
- * @remarks
2944
- * This step includes any final processes or clean up required by Powerlines. It will be run after each Powerlines command.
2945
- *
2946
- * @returns A promise that resolves when the finalization process has completed
2947
- */
2948
- async finalize() {
2949
- this.context.log(LogLevelLabel.TRACE, "Powerlines finalize execution started");
2950
- await this.#executeEnvironments(async (context) => {
2951
- await this.callHook(context, "finalize");
2952
- context.fs[__VFS_REVERT__]();
2953
- });
2954
- this.context.log(LogLevelLabel.TRACE, "Powerlines finalize execution completed");
2955
- }
2956
- /**
2957
- * Calls a hook in parallel
2958
- *
2959
- * @param hook - The hook to call
2960
- * @param options - Options for calling the hook
2961
- * @param args - The arguments to pass to the hook
2962
- * @returns The result of the hook call
2963
- */
2964
- async callHookParallel(hook, options, ...args) {
2965
- return callHook(isSetObject(options?.environment) ? options.environment : await this.#context.getEnvironment(options?.environment), hook, {
2966
- ...options,
2967
- sequential: false
2968
- }, ...args);
2969
- }
2970
- /**
2971
- * Calls a hook in sequence
2972
- *
2973
- * @param hook - The hook to call
2974
- * @param options - Options for calling the hook
2975
- * @param args - The arguments to pass to the hook
2976
- * @returns The result of the hook call
2977
- */
2978
- async callHookSequential(hook, options, ...args) {
2979
- return callHook(isSetObject(options?.environment) ? options.environment : await this.#context.getEnvironment(options?.environment), hook, {
2980
- ...options,
2981
- sequential: true
2982
- }, ...args);
2983
- }
2984
- /**
2985
- * Calls the `"pre"` ordered hooks in sequence
2986
- *
2987
- * @param environment - The environment to use for the hook call
2988
- * @param hook - The hook to call
2989
- * @param args - The arguments to pass to the hook
2990
- * @returns The result of the hook call
2991
- */
2992
- async callPreHook(environment, hook, ...args) {
2993
- return this.callHookSequential(hook, {
2994
- order: "pre",
2995
- environment
2996
- }, ...args);
2997
- }
2998
- /**
2999
- * Calls the `"post"` ordered hooks in sequence
3000
- *
3001
- * @param environment - The environment to use for the hook call
3002
- * @param hook - The hook to call
3003
- * @param args - The arguments to pass to the hook
3004
- * @returns The result of the hook call
3005
- */
3006
- async callPostHook(environment, hook, ...args) {
3007
- return this.callHookSequential(hook, {
3008
- order: "post",
3009
- environment
3010
- }, ...args);
3011
- }
3012
- /**
3013
- * Calls a hook in sequence
3014
- *
3015
- * @param environment - The environment to use for the hook call
3016
- * @param hook - The hook to call
3017
- * @param args - The arguments to pass to the hook
3018
- * @returns The result of the hook call
3019
- */
3020
- async callNormalHook(environment, hook, ...args) {
3021
- return this.callHookSequential(hook, {
3022
- order: "normal",
3023
- environment
3024
- }, ...args);
3025
- }
3026
- /**
3027
- * Calls the `"pre"` and `"post"` ordered hooks, as well as the normal hooks in sequence
3028
- *
3029
- * @param environment - The environment to use for the hook call
3030
- * @param hook - The hook to call
3031
- * @param args - The arguments to pass to the hook
3032
- * @returns The result of the hook call
3033
- */
3034
- async callHook(environment, hook, ...args) {
3035
- return this.callHookSequential(hook, {
3036
- environment
3037
- }, ...args);
3038
- }
3039
- async [Symbol.asyncDispose]() {
3040
- await this.finalize();
3041
- }
3042
- /**
3043
- * Get the configured environments
3044
- *
3045
- * @returns The configured environments
3046
- */
3047
- async #getEnvironments() {
3048
- if (!this.context.config.environments || Object.keys(this.context.config.environments).length <= 1) {
3049
- this.context.log(LogLevelLabel.DEBUG, "No environments are configured for this Powerlines project. Using the default environment.");
3050
- return [
3051
- await this.context.getEnvironment()
3052
- ];
3053
- }
3054
- this.context.log(LogLevelLabel.DEBUG, `Found ${Object.keys(this.context.config.environments).length} configured environment(s) for this Powerlines project.`);
3055
- return (await Promise.all(Object.entries(this.context.config.environments).map(async ([name, config]) => {
3056
- const environment = await this.context.getEnvironmentSafe(name);
3057
- if (!environment) {
3058
- const resolvedEnvironment = await this.callHookParallel("configEnvironment", {
3059
- environment: name
3060
- }, name, config);
3061
- if (resolvedEnvironment) {
3062
- this.context.environments[name] = await this.context.in(resolvedEnvironment);
3063
- }
3064
- }
3065
- return this.context.environments[name];
3066
- }))).filter((context) => isSet(context));
3067
- }
3068
- /**
3069
- * Execute a handler function for each environment
3070
- *
3071
- * @param handle - The handler function to execute for each environment
3072
- */
3073
- async #executeEnvironments(handle) {
3074
- await Promise.all((await this.#getEnvironments()).map(async (context) => {
3075
- return Promise.resolve(handle(context));
3076
- }));
3077
- }
3078
- /**
3079
- * Add a Powerlines plugin used in the build process
3080
- *
3081
- * @param config - The import path of the plugin to add
3082
- */
3083
- async #addPlugin(config) {
3084
- if (config) {
3085
- const plugin = await this.#initPlugin(config);
3086
- if (!plugin) {
3087
- return;
3088
- }
3089
- if (plugin.dependsOn) {
3090
- for (const required of plugin.dependsOn) {
3091
- await this.#addPlugin(required);
3092
- }
3093
- }
3094
- this.context.log(LogLevelLabel.DEBUG, `Successfully initialized the ${chalk4.bold.cyanBright(plugin.name)} plugin`);
3095
- await this.context.addPlugin(plugin);
3096
- }
3097
- }
3098
- /**
3099
- * Initialize a Powerlines plugin
3100
- *
3101
- * @param config - The configuration for the plugin
3102
- * @returns The initialized plugin instance, or null if the plugin was a duplicate
3103
- * @throws Will throw an error if the plugin cannot be found or is invalid
3104
- */
3105
- async #initPlugin(config) {
3106
- let awaited = config;
3107
- if (isPromiseLike(config)) {
3108
- awaited = await Promise.resolve(config);
3109
- }
3110
- if (!isPluginConfig(awaited)) {
3111
- throw new Error(`Invalid plugin specified in the configuration - ${JSON.stringify(awaited)}. Please ensure the value is a plugin name, an object with the \`plugin\` and \`props\` properties, or an instance of \`Plugin\`.`);
3112
- }
3113
- let plugin;
3114
- if (isPlugin(awaited)) {
3115
- plugin = awaited;
3116
- } else if (isFunction(awaited)) {
3117
- plugin = await Promise.resolve(awaited());
3118
- } else if (isSetString(awaited)) {
3119
- const resolved = await this.#resolvePlugin(awaited);
3120
- if (isFunction(resolved)) {
3121
- plugin = await Promise.resolve(resolved());
3122
- } else {
3123
- plugin = resolved;
3124
- }
3125
- } else if (isPluginConfigTuple(awaited) || isPluginConfigObject(awaited)) {
3126
- let pluginConfig;
3127
- let pluginOptions;
3128
- if (isPluginConfigTuple(awaited)) {
3129
- pluginConfig = awaited[0];
3130
- pluginOptions = awaited?.length === 2 ? awaited[1] : void 0;
3131
- } else {
3132
- pluginConfig = awaited.plugin;
3133
- pluginOptions = awaited.options;
3134
- }
3135
- if (isSetString(pluginConfig)) {
3136
- const resolved = await this.#resolvePlugin(pluginConfig);
3137
- if (isFunction(resolved)) {
3138
- plugin = await Promise.resolve(pluginOptions ? resolved(pluginOptions) : resolved());
3139
- } else {
3140
- plugin = resolved;
3141
- }
3142
- } else if (isFunction(pluginConfig)) {
3143
- plugin = await Promise.resolve(pluginConfig(pluginOptions));
3144
- } else if (isPlugin(pluginConfig)) {
3145
- plugin = pluginConfig;
3146
- }
3147
- }
3148
- if (!plugin) {
3149
- throw new Error(`The plugin configuration ${JSON.stringify(awaited)} is invalid. This configuration must point to a valid Powerlines plugin module.`);
3150
- }
3151
- if (!isPlugin(plugin)) {
3152
- throw new Error(`The plugin option ${JSON.stringify(plugin)} does not export a valid module. This configuration must point to a valid Powerlines plugin module.`);
3153
- }
3154
- if (checkDedupe(plugin, this.context.plugins)) {
3155
- this.context.log(LogLevelLabel.TRACE, `Duplicate ${chalk4.bold.cyanBright(plugin.name)} plugin dependency detected - Skipping initialization.`);
3156
- return null;
3157
- }
3158
- this.context.log(LogLevelLabel.TRACE, `Initializing the ${chalk4.bold.cyanBright(plugin.name)} plugin...`);
3159
- return plugin;
3160
- }
3161
- async #resolvePlugin(pluginPath) {
3162
- if (pluginPath.startsWith("@") && pluginPath.split("/").filter(Boolean).length > 2) {
3163
- const splits = pluginPath.split("/").filter(Boolean);
3164
- pluginPath = `${splits[0]}/${splits[1]}`;
3165
- }
3166
- const isInstalled = isPackageExists(pluginPath, {
3167
- paths: [
3168
- this.context.workspaceConfig.workspaceRoot,
3169
- this.context.config.projectRoot
3170
- ]
3171
- });
3172
- if (!isInstalled && this.context.config.skipInstalls !== true) {
3173
- this.#context.log(LogLevelLabel.WARN, `The plugin package "${pluginPath}" is not installed. It will be installed automatically.`);
3174
- const result = await install(pluginPath, {
3175
- cwd: this.context.config.projectRoot
3176
- });
3177
- if (isNumber(result.exitCode) && result.exitCode > 0) {
3178
- this.#context.log(LogLevelLabel.ERROR, result.stderr);
3179
- throw new Error(`An error occurred while installing the build plugin package "${pluginPath}" `);
3180
- }
3181
- }
3182
- try {
3183
- const module = await this.context.resolver.plugin.import(this.context.resolver.plugin.esmResolve(joinPaths(pluginPath, "plugin")));
3184
- const result = module.plugin ?? module.default;
3185
- if (!result) {
3186
- throw new Error(`The plugin package "${pluginPath}" does not export a valid module.`);
3187
- }
3188
- return result;
3189
- } catch (error) {
3190
- try {
3191
- const module = await this.context.resolver.plugin.import(this.context.resolver.plugin.esmResolve(pluginPath));
3192
- const result = module.plugin ?? module.default;
3193
- if (!result) {
3194
- throw new Error(`The plugin package "${pluginPath}" does not export a valid module.`);
3195
- }
3196
- return result;
3197
- } catch {
3198
- if (!isInstalled) {
3199
- throw new Error(`The plugin package "${pluginPath}" is not installed. Please install the package using the command: "npm install ${pluginPath} --save-dev"`);
3200
- } else {
3201
- throw new Error(`An error occurred while importing the build plugin package "${pluginPath}":
3202
- ${isError(error) ? error.message : String(error)}
3203
-
3204
- Note: Please ensure the plugin package's default export is a class that extends \`Plugin\` with a constructor that excepts a single arguments of type \`PluginOptions\`.`);
3205
- }
3206
- }
3207
- }
3208
- }
3209
- };
3210
-
3211
- // src/lib/unplugin/factory.ts
3212
- function createUnpluginFactory(variant, decorate) {
3213
- return (config, meta) => {
3214
- const log = createLog("unplugin", config);
3215
- log(LogLevelLabel.DEBUG, "Initializing Unplugin");
3216
- try {
3217
- const userConfig = {
3218
- ...config,
3219
- variant,
3220
- unplugin: meta
3221
- };
3222
- let api;
3223
- let resolvePatterns = [];
3224
- async function buildStart() {
3225
- log(LogLevelLabel.DEBUG, "Powerlines build plugin starting...");
3226
- const workspaceRoot = getWorkspaceRoot(process.cwd());
3227
- api = await PowerlinesAPI.from(workspaceRoot, userConfig);
3228
- if (api.context.config.build.skipNodeModulesBundle) {
3229
- resolvePatterns = tsconfigPathsToRegExp(api.context.tsconfig.options.paths ?? []);
3230
- }
3231
- log(LogLevelLabel.DEBUG, "Preparing build artifacts for the Powerlines project...");
3232
- await api.prepare({
3233
- command: "build"
3234
- });
3235
- }
3236
- __name(buildStart, "buildStart");
3237
- async function resolveId(id, importer, options = {
3238
- isEntry: false
3239
- }) {
3240
- return handleResolveId(api.context, {
3241
- id,
3242
- importer,
3243
- options
3244
- }, {
3245
- skipNodeModulesBundle: api.context.config.build.skipNodeModulesBundle,
3246
- external: api.context.config.build.external,
3247
- noExternal: api.context.config.build.noExternal,
3248
- resolvePatterns
3249
- });
3250
- }
3251
- __name(resolveId, "resolveId");
3252
- async function load(id) {
3253
- const environment = await api.context.getEnvironment();
3254
- if (id) {
3255
- const resolvedPath = environment.fs.resolve(id);
3256
- if (resolvedPath) {
3257
- return environment.fs.readFile(resolvedPath);
3258
- }
3259
- }
3260
- let result2 = await api.callPreHook(environment, "load", id);
3261
- if (result2) {
3262
- return result2;
3263
- }
3264
- result2 = await api.callNormalHook(environment, "load", id);
3265
- if (result2) {
3266
- return result2;
3267
- }
3268
- return api.callPostHook(environment, "load", id);
3269
- }
3270
- __name(load, "load");
3271
- async function transform(code, id) {
3272
- const environment = await api.context.getEnvironment();
3273
- let transformed = code;
3274
- let result2 = await api.callPreHook(environment, "transform", getString(transformed), id);
3275
- if (result2) {
3276
- transformed = result2;
3277
- }
3278
- result2 = await api.callNormalHook(environment, "transform", getString(transformed), id);
3279
- if (result2) {
3280
- transformed = result2;
3281
- }
3282
- result2 = await api.callPostHook(environment, "transform", getString(transformed), id);
3283
- if (result2) {
3284
- transformed = result2;
3285
- }
3286
- return transformed;
3287
- }
3288
- __name(transform, "transform");
3289
- async function writeBundle() {
3290
- log(LogLevelLabel.DEBUG, "Finalizing Powerlines project output...");
3291
- const environment = await api.context.getEnvironment();
3292
- await api.callHook(environment, "writeBundle");
3293
- }
3294
- __name(writeBundle, "writeBundle");
3295
- const result = {
3296
- name: "powerlines",
3297
- resolveId: {
3298
- filter: {
3299
- id: {
3300
- include: [
3301
- /.*/
3302
- ]
3303
- }
3304
- },
3305
- handler: resolveId
3306
- },
3307
- load: {
3308
- filter: {
3309
- id: {
3310
- include: [
3311
- /.*/,
3312
- /^storm:/
3313
- ]
3314
- }
3315
- },
3316
- handler: load
3317
- },
3318
- transform,
3319
- buildStart,
3320
- writeBundle
3321
- };
3322
- return decorate ? decorate(api, result) : result;
3323
- } catch (error) {
3324
- log(LogLevelLabel.FATAL, error?.message);
3325
- throw error;
3326
- }
3327
- };
3328
- }
3329
- __name(createUnpluginFactory, "createUnpluginFactory");
3330
-
3331
- export { createUnpluginFactory };
3332
- //# sourceMappingURL=chunk-6BRTJXZ2.js.map
3333
- //# sourceMappingURL=chunk-6BRTJXZ2.js.map