powerlines 0.23.3 → 0.23.5

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 (290) hide show
  1. package/dist/api--9pVSIbm.d.cts +168 -0
  2. package/dist/api-DxPACGY4.d.ts +168 -0
  3. package/dist/api.cjs +3 -3
  4. package/dist/api.d.cts +16 -7
  5. package/dist/api.d.ts +16 -7
  6. package/dist/api.js +2 -2
  7. package/dist/astro.cjs +8 -8
  8. package/dist/astro.d.cts +3 -5
  9. package/dist/astro.d.ts +3 -5
  10. package/dist/astro.js +5 -5
  11. package/dist/babel-types.d.ts +292 -0
  12. package/dist/{chunk-CPRXGMH2.js → chunk-33BDG6M5.js} +1 -1
  13. package/dist/{chunk-KFRKOIP3.js → chunk-3HOOIAF4.js} +1 -1
  14. package/dist/{chunk-JZAQW55G.cjs → chunk-4OAW547A.cjs} +2 -2
  15. package/dist/{chunk-Q7HBETZW.js → chunk-5CCEQUAZ.js} +1 -1
  16. package/dist/{chunk-DWV5QAGZ.cjs → chunk-62BQYRPM.cjs} +2999 -2712
  17. package/dist/{chunk-F6BDL4HD.js → chunk-AK5B45AH.js} +1 -1
  18. package/dist/{chunk-3WDMXRK6.cjs → chunk-AYKZK666.cjs} +1 -1
  19. package/dist/{chunk-TNYZH6EG.js → chunk-E4M4KEL3.js} +2983 -2701
  20. package/dist/{chunk-WSLPUUGZ.js → chunk-GHHMURR4.js} +1 -1
  21. package/dist/{chunk-5A7FM72H.cjs → chunk-GXJ5L37C.cjs} +2 -2
  22. package/dist/{chunk-IGWSCIES.js → chunk-GZNJUK7U.js} +3 -2
  23. package/dist/{chunk-J7MZRPLN.cjs → chunk-I3EUY74Q.cjs} +5 -4
  24. package/dist/chunk-IVABRCNA.js +29 -0
  25. package/dist/{chunk-M4QJ2474.cjs → chunk-JJXDDTSL.cjs} +4 -4
  26. package/dist/{chunk-WDBPA4RQ.cjs → chunk-K5TOHSUD.cjs} +2 -2
  27. package/dist/{chunk-4ODWTALP.js → chunk-M7N6RX2H.js} +2 -2
  28. package/dist/{chunk-J3LN5HOC.cjs → chunk-MAOXZVDE.cjs} +2 -2
  29. package/dist/{chunk-YQ76DZYD.cjs → chunk-NWZXH2HK.cjs} +2 -2
  30. package/dist/{chunk-ZFO3FUM4.cjs → chunk-PFECSHR6.cjs} +2 -2
  31. package/dist/{chunk-JAJ4CI2F.cjs → chunk-Q3ZFML4W.cjs} +2 -2
  32. package/dist/chunk-RM37JA3L.cjs +32 -0
  33. package/dist/{chunk-GNNF5SG6.cjs → chunk-RVO5GC2H.cjs} +2 -2
  34. package/dist/{chunk-J5LKLH5Z.js → chunk-TSKJTJ2P.js} +1 -1
  35. package/dist/{chunk-WG55ZHJL.cjs → chunk-VRFJDHDN.cjs} +2 -2
  36. package/dist/{chunk-FM4ABZQ2.js → chunk-VT7NVLLU.js} +1 -1
  37. package/dist/{chunk-LKN52AAX.js → chunk-W36NC3B7.js} +1 -1
  38. package/dist/{chunk-RWVNX2CP.js → chunk-XDNNFAQR.js} +1 -1
  39. package/dist/{chunk-DUYZ3TCT.js → chunk-XWBVMNBI.js} +1 -1
  40. package/dist/{chunk-WXU3KLBP.cjs → chunk-YBOJFFO2.cjs} +2 -2
  41. package/dist/{chunk-NH7U3PTV.js → chunk-ZOMJH52N.js} +1 -1
  42. package/dist/config.d.cts +3 -5
  43. package/dist/config.d.ts +3 -5
  44. package/dist/esbuild.cjs +7 -7
  45. package/dist/esbuild.d.cts +3 -5
  46. package/dist/esbuild.d.ts +3 -5
  47. package/dist/esbuild.js +4 -4
  48. package/dist/farm.cjs +4 -4
  49. package/dist/farm.d.cts +3 -5
  50. package/dist/farm.d.ts +3 -5
  51. package/dist/farm.js +3 -3
  52. package/dist/index.cjs +54 -33
  53. package/dist/index.d.cts +188 -36
  54. package/dist/index.d.ts +188 -36
  55. package/dist/index.js +18 -17
  56. package/dist/lib/api-B6hfFxVS.d.ts +167 -0
  57. package/dist/lib/api-CD2QlMig.d.cts +167 -0
  58. package/dist/lib/build/esbuild.d.cts +2 -4
  59. package/dist/lib/build/esbuild.d.ts +2 -4
  60. package/dist/lib/build/index.d.cts +4 -5
  61. package/dist/lib/build/index.d.ts +4 -5
  62. package/dist/lib/build/rolldown.d.cts +2 -4
  63. package/dist/lib/build/rolldown.d.ts +2 -4
  64. package/dist/lib/build/rollup.d.cts +2 -4
  65. package/dist/lib/build/rollup.d.ts +2 -4
  66. package/dist/lib/build/rspack.d.cts +2 -4
  67. package/dist/lib/build/rspack.d.ts +2 -4
  68. package/dist/lib/build/tsup.d.cts +2 -4
  69. package/dist/lib/build/tsup.d.ts +2 -4
  70. package/dist/lib/build/unbuild.d.cts +4 -23
  71. package/dist/lib/build/unbuild.d.ts +4 -23
  72. package/dist/lib/build/vite.d.cts +2 -4
  73. package/dist/lib/build/vite.d.ts +2 -4
  74. package/dist/lib/build/webpack.d.cts +2 -4
  75. package/dist/lib/build/webpack.d.ts +2 -4
  76. package/dist/lib/chunk-27RAXIPT.cjs +175 -0
  77. package/dist/lib/chunk-32Q2PG5D.js +9 -0
  78. package/dist/lib/chunk-35FGUJFD.cjs +2 -0
  79. package/dist/lib/{chunk-LIN4KAV3.js → chunk-52VDUP5J.js} +5 -7
  80. package/dist/lib/{chunk-UWHGJ4JS.js → chunk-764HUXP3.js} +484 -1777
  81. package/dist/lib/chunk-B3EE3VHZ.cjs +127 -0
  82. package/dist/lib/chunk-CCGA6ZHZ.cjs +1218 -0
  83. package/dist/lib/chunk-DX2VAXZB.cjs +11 -0
  84. package/dist/lib/{chunk-VGSV2BEL.cjs → chunk-EFYMNU53.cjs} +6 -12
  85. package/dist/lib/chunk-EJTGOYSI.cjs +146 -0
  86. package/dist/lib/chunk-EN4XP4D5.js +144 -0
  87. package/dist/lib/chunk-FFT4PWRM.js +1 -0
  88. package/dist/lib/{chunk-L4NEN725.js → chunk-G7S5PIAC.js} +1 -1
  89. package/dist/lib/chunk-KFJCWNVG.js +120 -0
  90. package/dist/lib/chunk-MVIKYHBX.cjs +2 -0
  91. package/dist/lib/chunk-NDKPSA3I.js +1190 -0
  92. package/dist/lib/{chunk-A5SB72VO.cjs → chunk-NVUXGMU5.cjs} +495 -1781
  93. package/dist/lib/chunk-NYNHNTHT.js +1 -0
  94. package/dist/lib/chunk-SZH2DJOG.js +168 -0
  95. package/dist/lib/{chunk-ULJVBW4L.cjs → chunk-ZBDVQVUK.cjs} +1 -1
  96. package/dist/lib/{config-BoGlIhnH.d.cts → config-DTSdCZsw.d.cts} +650 -633
  97. package/dist/lib/{config-CTej7RMP.d.ts → config-DeUaQYc_.d.ts} +650 -633
  98. package/dist/lib/config-file.d.cts +2 -4
  99. package/dist/lib/config-file.d.ts +2 -4
  100. package/dist/lib/contexts/api-context.cjs +18 -0
  101. package/dist/lib/contexts/api-context.d.cts +69 -0
  102. package/dist/lib/contexts/api-context.d.ts +69 -0
  103. package/dist/lib/contexts/api-context.js +9 -0
  104. package/dist/lib/contexts/context.cjs +15 -0
  105. package/dist/lib/contexts/context.d.cts +255 -0
  106. package/dist/lib/contexts/context.d.ts +255 -0
  107. package/dist/lib/contexts/context.js +6 -0
  108. package/dist/lib/contexts/environment-context.cjs +17 -0
  109. package/dist/lib/contexts/environment-context.d.cts +65 -0
  110. package/dist/lib/contexts/environment-context.d.ts +65 -0
  111. package/dist/lib/contexts/environment-context.js +8 -0
  112. package/dist/lib/contexts/index.cjs +31 -0
  113. package/dist/lib/contexts/index.d.cts +35 -0
  114. package/dist/lib/contexts/index.d.ts +35 -0
  115. package/dist/lib/contexts/index.js +10 -0
  116. package/dist/lib/contexts/plugin-context.cjs +11 -0
  117. package/dist/lib/contexts/plugin-context.d.cts +42 -0
  118. package/dist/lib/contexts/plugin-context.d.ts +42 -0
  119. package/dist/lib/contexts/plugin-context.js +2 -0
  120. package/dist/lib/entry.d.cts +2 -4
  121. package/dist/lib/entry.d.ts +2 -4
  122. package/dist/lib/index.cjs +96 -74
  123. package/dist/lib/index.d.cts +17 -14
  124. package/dist/lib/index.d.ts +17 -14
  125. package/dist/lib/index.js +18 -12
  126. package/dist/lib/internal-CpVMJCaU.d.ts +39 -0
  127. package/dist/lib/internal-ypnrUNZy.d.cts +39 -0
  128. package/dist/lib/logger.d.cts +2 -4
  129. package/dist/lib/logger.d.ts +2 -4
  130. package/dist/lib/typescript/compiler-host.cjs +1 -1
  131. package/dist/lib/typescript/compiler-host.d.cts +2 -4
  132. package/dist/lib/typescript/compiler-host.d.ts +2 -4
  133. package/dist/lib/typescript/compiler-host.js +1 -1
  134. package/dist/lib/typescript/import-transformer.d.cts +2 -4
  135. package/dist/lib/typescript/import-transformer.d.ts +2 -4
  136. package/dist/lib/typescript/index.cjs +29 -24
  137. package/dist/lib/typescript/index.d.cts +4 -4
  138. package/dist/lib/typescript/index.d.ts +4 -4
  139. package/dist/lib/typescript/index.js +3 -2
  140. package/dist/lib/typescript/program.d.cts +2 -4
  141. package/dist/lib/typescript/program.d.ts +2 -4
  142. package/dist/lib/typescript/ts-morph.cjs +11 -0
  143. package/dist/lib/{create-program.d.ts → typescript/ts-morph.d.cts} +3 -5
  144. package/dist/lib/{create-program.d.cts → typescript/ts-morph.d.ts} +3 -5
  145. package/dist/lib/typescript/ts-morph.js +2 -0
  146. package/dist/lib/unplugin/factory.cjs +8 -4
  147. package/dist/lib/unplugin/factory.d.cts +27 -10
  148. package/dist/lib/unplugin/factory.d.ts +27 -10
  149. package/dist/lib/unplugin/factory.js +7 -3
  150. package/dist/lib/unplugin/helpers.cjs +11 -0
  151. package/dist/lib/unplugin/helpers.d.cts +128 -0
  152. package/dist/lib/unplugin/helpers.d.ts +128 -0
  153. package/dist/lib/unplugin/helpers.js +2 -0
  154. package/dist/lib/unplugin/index.cjs +12 -7
  155. package/dist/lib/unplugin/index.d.cts +4 -6
  156. package/dist/lib/unplugin/index.d.ts +4 -6
  157. package/dist/lib/unplugin/index.js +9 -4
  158. package/dist/lib/unplugin/plugin.cjs +4 -3
  159. package/dist/lib/unplugin/plugin.d.cts +2 -4
  160. package/dist/lib/unplugin/plugin.d.ts +2 -4
  161. package/dist/lib/unplugin/plugin.js +3 -2
  162. package/dist/lib/unplugin/resolve-id.cjs +2 -2
  163. package/dist/lib/unplugin/resolve-id.d.cts +2 -4
  164. package/dist/lib/unplugin/resolve-id.d.ts +2 -4
  165. package/dist/lib/unplugin/resolve-id.js +1 -1
  166. package/dist/lib/utilities/bundle.d.cts +2 -4
  167. package/dist/lib/utilities/bundle.d.ts +2 -4
  168. package/dist/lib/utilities/cache.d.cts +2 -4
  169. package/dist/lib/utilities/cache.d.ts +2 -4
  170. package/dist/lib/utilities/file-header.d.cts +2 -4
  171. package/dist/lib/utilities/file-header.d.ts +2 -4
  172. package/dist/lib/utilities/index.cjs +18 -18
  173. package/dist/lib/utilities/index.d.cts +2 -4
  174. package/dist/lib/utilities/index.d.ts +2 -4
  175. package/dist/lib/utilities/index.js +4 -4
  176. package/dist/lib/utilities/meta.d.cts +2 -4
  177. package/dist/lib/utilities/meta.d.ts +2 -4
  178. package/dist/lib/utilities/resolve-path.d.cts +2 -4
  179. package/dist/lib/utilities/resolve-path.d.ts +2 -4
  180. package/dist/lib/utilities/resolve.d.cts +2 -4
  181. package/dist/lib/utilities/resolve.d.ts +2 -4
  182. package/dist/lib/utilities/source-file.d.cts +2 -4
  183. package/dist/lib/utilities/source-file.d.ts +2 -4
  184. package/dist/lib/utilities/source-map.d.cts +2 -4
  185. package/dist/lib/utilities/source-map.d.ts +2 -4
  186. package/dist/lib/utilities/worker.d.cts +2 -4
  187. package/dist/lib/utilities/worker.d.ts +2 -4
  188. package/dist/lib/utilities/write-file.d.cts +2 -4
  189. package/dist/lib/utilities/write-file.d.ts +2 -4
  190. package/dist/next.cjs +8 -8
  191. package/dist/next.js +5 -5
  192. package/dist/nuxt.cjs +9 -9
  193. package/dist/nuxt.js +6 -6
  194. package/dist/plugin-utils/{context-D1I2JQgs.d.cts → context-DRFZE3XI.d.cts} +535 -518
  195. package/dist/plugin-utils/{context-D1I2JQgs.d.ts → context-DRFZE3XI.d.ts} +535 -518
  196. package/dist/plugin-utils/context-helpers.d.cts +2 -4
  197. package/dist/plugin-utils/context-helpers.d.ts +2 -4
  198. package/dist/plugin-utils/enforce.d.cts +2 -4
  199. package/dist/plugin-utils/enforce.d.ts +2 -4
  200. package/dist/plugin-utils/extend.d.cts +2 -4
  201. package/dist/plugin-utils/extend.d.ts +2 -4
  202. package/dist/plugin-utils/get-config-path.d.cts +2 -4
  203. package/dist/plugin-utils/get-config-path.d.ts +2 -4
  204. package/dist/plugin-utils/helpers.d.cts +2 -4
  205. package/dist/plugin-utils/helpers.d.ts +2 -4
  206. package/dist/plugin-utils/index.d.cts +2 -4
  207. package/dist/plugin-utils/index.d.ts +2 -4
  208. package/dist/plugin-utils/merge.d.cts +2 -4
  209. package/dist/plugin-utils/merge.d.ts +2 -4
  210. package/dist/plugin-utils/paths.d.cts +2 -4
  211. package/dist/plugin-utils/paths.d.ts +2 -4
  212. package/dist/{resolved-Dem-rX6I.d.cts → resolved-C00CJgsk.d.cts} +9 -8
  213. package/dist/{resolved-BVakEeek.d.ts → resolved-DKFZ11S7.d.ts} +9 -8
  214. package/dist/rolldown.cjs +7 -7
  215. package/dist/rolldown.d.cts +3 -5
  216. package/dist/rolldown.d.ts +3 -5
  217. package/dist/rolldown.js +4 -4
  218. package/dist/rollup.cjs +7 -7
  219. package/dist/rollup.d.cts +3 -5
  220. package/dist/rollup.d.ts +3 -5
  221. package/dist/rollup.js +4 -4
  222. package/dist/rspack.cjs +7 -7
  223. package/dist/rspack.d.cts +3 -5
  224. package/dist/rspack.d.ts +3 -5
  225. package/dist/rspack.js +4 -4
  226. package/dist/tsup.cjs +8 -8
  227. package/dist/tsup.js +5 -5
  228. package/dist/types/api.cjs +4 -0
  229. package/dist/types/api.d.cts +36 -0
  230. package/dist/types/api.d.ts +36 -0
  231. package/dist/types/api.js +1 -0
  232. package/dist/types/babel.d.cts +3 -5
  233. package/dist/types/babel.d.ts +3 -5
  234. package/dist/types/commands.d.cts +3 -5
  235. package/dist/types/commands.d.ts +3 -5
  236. package/dist/types/config.d.cts +3 -5
  237. package/dist/types/config.d.ts +3 -5
  238. package/dist/types/context.d.cts +3 -5
  239. package/dist/types/context.d.ts +3 -5
  240. package/dist/types/{vfs.cjs → fs.cjs} +3 -3
  241. package/dist/types/{vfs.d.cts → fs.d.cts} +43 -38
  242. package/dist/types/{vfs.d.ts → fs.d.ts} +43 -38
  243. package/dist/types/fs.js +2 -0
  244. package/dist/types/hooks.d.cts +3 -5
  245. package/dist/types/hooks.d.ts +3 -5
  246. package/dist/types/index.cjs +9 -8
  247. package/dist/types/index.d.cts +5 -6
  248. package/dist/types/index.d.ts +5 -6
  249. package/dist/types/index.js +3 -2
  250. package/dist/types/internal.d.cts +44 -9
  251. package/dist/types/internal.d.ts +44 -9
  252. package/dist/types/plugin.d.cts +3 -5
  253. package/dist/types/plugin.d.ts +3 -5
  254. package/dist/types/resolved.d.cts +3 -5
  255. package/dist/types/resolved.d.ts +3 -5
  256. package/dist/types/unplugin.d.cts +20 -12
  257. package/dist/types/unplugin.d.ts +20 -12
  258. package/dist/unloader.cjs +7 -7
  259. package/dist/unloader.d.cts +12 -14
  260. package/dist/unloader.d.ts +12 -14
  261. package/dist/unloader.js +4 -4
  262. package/dist/unplugin.cjs +18 -18
  263. package/dist/unplugin.d.cts +6 -9
  264. package/dist/unplugin.d.ts +6 -9
  265. package/dist/unplugin.js +15 -15
  266. package/dist/vite.cjs +7 -7
  267. package/dist/vite.d.cts +3 -5
  268. package/dist/vite.d.ts +3 -5
  269. package/dist/vite.js +4 -4
  270. package/dist/webpack.cjs +7 -7
  271. package/dist/webpack.d.cts +3 -5
  272. package/dist/webpack.d.ts +3 -5
  273. package/dist/webpack.js +4 -4
  274. package/package.json +38 -10
  275. package/schemas/fs.capnp +73 -15
  276. package/dist/chunk-RODEAGIJ.cjs +0 -32
  277. package/dist/chunk-SKLSRHBU.js +0 -29
  278. package/dist/hooks-B3vzw6La.d.ts +0 -28
  279. package/dist/hooks-YACA4jMY.d.cts +0 -28
  280. package/dist/lib/create-program.cjs +0 -11
  281. package/dist/lib/create-program.js +0 -2
  282. package/dist/lib/hooks-CDLPWf7j.d.cts +0 -28
  283. package/dist/lib/hooks-Cn-IqwYp.d.ts +0 -28
  284. package/dist/types/vfs.js +0 -2
  285. /package/dist/{chunk-KIKTWMI3.cjs → chunk-2NCILNCH.cjs} +0 -0
  286. /package/dist/{chunk-XVLT2RQ2.js → chunk-BLNT5INX.js} +0 -0
  287. /package/dist/{lib/chunk-RJ4277VZ.cjs → chunk-GRU7B3QM.cjs} +0 -0
  288. /package/dist/{lib/chunk-ZBLDAREE.js → chunk-T2P533I5.js} +0 -0
  289. /package/dist/lib/{chunk-CGYAL3S2.cjs → chunk-4EIXDLFP.cjs} +0 -0
  290. /package/dist/lib/{chunk-CXRSMYEX.js → chunk-RD5AUWXN.js} +0 -0
@@ -0,0 +1,1190 @@
1
+ import { writeFile } from './chunk-TANQDHYY.js';
2
+ import { getFileHeader } from './chunk-GANVMM73.js';
3
+ import { handleResolveId } from './chunk-G7S5PIAC.js';
4
+ import { getParsedTypeScriptConfig, getTsconfigFilePath, isIncludeMatchFound } from './chunk-YOENMDZY.js';
5
+ import { PowerlinesAPIContext } from './chunk-SZH2DJOG.js';
6
+ import { callHook } from './chunk-KFJCWNVG.js';
7
+ import { __VFS_PATCH__, __VFS_REVERT__, isPluginConfig, isPlugin, isPluginConfigTuple, isPluginConfigObject, checkDedupe } from './chunk-764HUXP3.js';
8
+ import { writeMetaFile } from './chunk-YH5GOJS3.js';
9
+ import { createLog } from './chunk-ENRLU4UR.js';
10
+ import { getString } from './chunk-M263EZ4F.js';
11
+ import { replacePathTokens } from './chunk-XZFEHPYE.js';
12
+ import { __name } from './chunk-SHUYVCID.js';
13
+ import { LogLevelLabel } from '@storm-software/config-tools/types';
14
+ import { getWorkspaceRoot } from '@stryke/fs/get-workspace-root';
15
+ import { tsconfigPathsToRegExp } from 'bundle-require';
16
+ import { transformAsync } from '@babel/core';
17
+ import { formatLogMessage } from '@storm-software/config-tools/logger/console';
18
+ import { toArray } from '@stryke/convert/to-array';
19
+ import { copyFiles } from '@stryke/fs/copy-file';
20
+ import { existsSync } from '@stryke/fs/exists';
21
+ import { createDirectory } from '@stryke/fs/helpers';
22
+ import { install } from '@stryke/fs/install';
23
+ import { listFiles } from '@stryke/fs/list-files';
24
+ import { isPackageExists, isPackageListed, doesPackageMatch, getPackageListing } from '@stryke/fs/package-fns';
25
+ import { resolvePackage } from '@stryke/fs/resolve';
26
+ import { appendPath } from '@stryke/path/append';
27
+ import { joinPaths } from '@stryke/path/join-paths';
28
+ import { replacePath } from '@stryke/path/replace';
29
+ import { isError } from '@stryke/type-checks/is-error';
30
+ import { isFunction } from '@stryke/type-checks/is-function';
31
+ import { isNumber } from '@stryke/type-checks/is-number';
32
+ import { isPromiseLike } from '@stryke/type-checks/is-promise';
33
+ import { isSet } from '@stryke/type-checks/is-set';
34
+ import { isSetObject } from '@stryke/type-checks/is-set-object';
35
+ import { isSetString } from '@stryke/type-checks/is-set-string';
36
+ import chalk2 from 'chalk';
37
+ import defu from 'defu';
38
+ import Handlebars from 'handlebars';
39
+ import { declare } from '@babel/helper-plugin-utils';
40
+ import * as t from '@babel/types';
41
+ import ts, { createProgram, createCompilerHost, getPreEmitDiagnostics, getLineAndCharacterOfPosition, flattenDiagnosticMessageText } from 'typescript';
42
+ import { getPackageName, hasPackageVersion, getPackageVersion } from '@stryke/string-format/package';
43
+ import { getObjectDiff } from '@donedeal0/superdiff';
44
+ import { readJsonFile } from '@stryke/fs/json';
45
+ import { loadTsConfig } from '@stryke/fs/tsconfig';
46
+ import { StormJSON } from '@stryke/json/storm-json';
47
+ import { relativePath, findFilePath, findFileName } from '@stryke/path/file-path-fns';
48
+ import { titleCase } from '@stryke/string-format/title-case';
49
+
50
+ function resolveModulePath(nodePath, state) {
51
+ if (!t.isStringLiteral(nodePath.node)) {
52
+ return;
53
+ }
54
+ const sourcePath = nodePath.node.value;
55
+ const resolvedPath = state.context?.fs.resolve(sourcePath);
56
+ if (resolvedPath) {
57
+ nodePath.replaceWith(t.stringLiteral(
58
+ // Remove the file extension if it exists
59
+ resolvedPath.replace(/\.(?:ts|mts|cts)x?$/, "")
60
+ ));
61
+ }
62
+ }
63
+ __name(resolveModulePath, "resolveModulePath");
64
+ var TRANSFORM_FUNCTIONS = [
65
+ "require",
66
+ "require.resolve",
67
+ "System.import",
68
+ // Jest methods
69
+ "jest.genMockFromModule",
70
+ "jest.mock",
71
+ "jest.unmock",
72
+ "jest.doMock",
73
+ // eslint-disable-next-line @cspell/spellchecker
74
+ "jest.dontMock",
75
+ "jest.setMock",
76
+ "jest.requireActual",
77
+ "jest.requireMock",
78
+ // Older Jest methods
79
+ "require.requireActual",
80
+ "require.requireMock"
81
+ ];
82
+ function matchesPattern(state, calleePath, pattern) {
83
+ const { node } = calleePath;
84
+ if (t.isMemberExpression(node)) {
85
+ return calleePath.matchesPattern(pattern);
86
+ }
87
+ if (!t.isIdentifier(node) || pattern.includes(".")) {
88
+ return false;
89
+ }
90
+ const name = pattern.split(".")[0];
91
+ return node.name === name;
92
+ }
93
+ __name(matchesPattern, "matchesPattern");
94
+ var importVisitors = {
95
+ CallExpression: /* @__PURE__ */ __name((nodePath, state) => {
96
+ if (state.moduleResolverVisited.has(nodePath)) {
97
+ return;
98
+ }
99
+ const calleePath = nodePath.get("callee");
100
+ if (calleePath && TRANSFORM_FUNCTIONS.some((pattern) => matchesPattern(state, calleePath, pattern)) || t.isImport(nodePath.node.callee)) {
101
+ state.moduleResolverVisited.add(nodePath);
102
+ resolveModulePath(nodePath.get("arguments.0"), state);
103
+ }
104
+ }, "CallExpression"),
105
+ // eslint-disable-next-line ts/naming-convention
106
+ "ImportDeclaration|ExportDeclaration|ExportAllDeclaration": /* @__PURE__ */ __name((nodePath, state) => {
107
+ if (!nodePath || !nodePath.get("source") || state.moduleResolverVisited.has(nodePath)) {
108
+ return;
109
+ }
110
+ state.moduleResolverVisited.add(nodePath);
111
+ resolveModulePath(nodePath.get("source"), state);
112
+ }, "ImportDeclaration|ExportDeclaration|ExportAllDeclaration")
113
+ };
114
+ var moduleResolverBabelPlugin = /* @__PURE__ */ __name((context) => {
115
+ return declare(/* @__PURE__ */ __name(function builder(api) {
116
+ let moduleResolverVisited = /* @__PURE__ */ new Set();
117
+ return {
118
+ name: "powerlines:module-resolver",
119
+ manipulateOptions(opts) {
120
+ opts.filename ??= "unknown";
121
+ },
122
+ pre() {
123
+ moduleResolverVisited = /* @__PURE__ */ new Set();
124
+ },
125
+ visitor: {
126
+ Program: {
127
+ enter(programPath, state) {
128
+ programPath.traverse(importVisitors, {
129
+ ...state,
130
+ context,
131
+ moduleResolverVisited,
132
+ api
133
+ });
134
+ },
135
+ exit(programPath, state) {
136
+ programPath.traverse(importVisitors, {
137
+ ...state,
138
+ context,
139
+ moduleResolverVisited,
140
+ api
141
+ });
142
+ }
143
+ }
144
+ },
145
+ post() {
146
+ moduleResolverVisited.clear();
147
+ }
148
+ };
149
+ }, "builder"));
150
+ }, "moduleResolverBabelPlugin");
151
+ function formatTypes(code) {
152
+ return code.replace(
153
+ // eslint-disable-next-line regexp/no-super-linear-backtracking
154
+ /import\s*(?:type\s*)?\{?[\w,\s]*(?:\}\s*)?from\s*(?:'|")@?[a-zA-Z0-9-\\/.]*(?:'|");?/g,
155
+ ""
156
+ ).replaceAll("#private;", "").replace(/__Ω/g, "");
157
+ }
158
+ __name(formatTypes, "formatTypes");
159
+ async function emitTypes(context, tsconfig, files) {
160
+ context.log(LogLevelLabel.TRACE, "Creating the TypeScript compiler host");
161
+ const program = createProgram(files, tsconfig.options, createCompilerHost(tsconfig.options));
162
+ context.log(LogLevelLabel.TRACE, `Running the TypeScript compiler for ${context.builtins.length} built-in runtime files.`);
163
+ let builtinModules = "";
164
+ const emitResult = program.emit(void 0, (fileName, text, _, __, sourceFiles, _data) => {
165
+ const sourceFile = sourceFiles?.[0];
166
+ if (sourceFile?.fileName && !fileName.endsWith(".map")) {
167
+ if (context.builtins.some((file) => file === sourceFile.fileName || context.fs.metadata[file]?.id && context.fs.metadata[file]?.id === sourceFile.fileName)) {
168
+ builtinModules += `
169
+ declare module "${context.fs.resolve(sourceFile.fileName)}" {
170
+ ${text.trim().replace(/^\s*export\s*declare\s*/gm, "export ").replace(/^\s*declare\s*/gm, "")}
171
+ }
172
+ `;
173
+ }
174
+ }
175
+ }, void 0, true);
176
+ const diagnostics = getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
177
+ const diagnosticMessages = [];
178
+ diagnostics.forEach((diagnostic) => {
179
+ if (diagnostic.file) {
180
+ const { line, character } = getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start);
181
+ const message = flattenDiagnosticMessageText(diagnostic.messageText, "\n");
182
+ diagnosticMessages.push(`${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`);
183
+ } else {
184
+ const message = flattenDiagnosticMessageText(diagnostic.messageText, "\n");
185
+ diagnosticMessages.push(message);
186
+ }
187
+ });
188
+ const diagnosticMessage = diagnosticMessages.join("\n");
189
+ if (diagnosticMessage) {
190
+ throw new Error(`TypeScript compilation failed:
191
+
192
+ ${diagnosticMessage.length > 5e3 ? `${diagnosticMessage.slice(0, 5e3)}...` : diagnosticMessage}`);
193
+ }
194
+ return formatTypes(builtinModules);
195
+ }
196
+ __name(emitTypes, "emitTypes");
197
+ async function installPackage(context, packageName, dev = false) {
198
+ if (!await isPackageListed(getPackageName(packageName), {
199
+ cwd: context.config.projectRoot
200
+ })) {
201
+ if (context.config.skipInstalls !== true && !process.env.POWERLINES_LOCAL) {
202
+ context.log(LogLevelLabel.WARN, `The package "${packageName}" is not installed. It will be installed automatically.`);
203
+ const result = await install(packageName, {
204
+ cwd: context.config.projectRoot,
205
+ dev
206
+ });
207
+ if (isNumber(result.exitCode) && result.exitCode > 0) {
208
+ context.log(LogLevelLabel.ERROR, result.stderr);
209
+ throw new Error(`An error occurred while installing the package "${packageName}"`);
210
+ }
211
+ } else {
212
+ context.log(LogLevelLabel.WARN, `The package "${packageName}" is not installed. Since the "skipInstalls" option is set to true, it will not be installed automatically.`);
213
+ }
214
+ } else if (hasPackageVersion(packageName) && !process.env.POWERLINES_SKIP_VERSION_CHECK) {
215
+ const isMatching = await doesPackageMatch(getPackageName(packageName), getPackageVersion(packageName), context.config.projectRoot);
216
+ if (!isMatching) {
217
+ const packageListing = await getPackageListing(getPackageName(packageName), {
218
+ cwd: context.config.projectRoot
219
+ });
220
+ if (!packageListing?.version.startsWith("catalog:") && !packageListing?.version.startsWith("workspace:")) {
221
+ 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.`);
222
+ }
223
+ }
224
+ }
225
+ }
226
+ __name(installPackage, "installPackage");
227
+
228
+ // src/internal/helpers/install-dependencies.ts
229
+ async function installDependencies(context) {
230
+ context.log(LogLevelLabel.TRACE, `Checking and installing missing project dependencies.`);
231
+ context.dependencies ??= {};
232
+ context.devDependencies ??= {};
233
+ if (Object.keys(context.dependencies).length === 0 && Object.keys(context.devDependencies).length === 0) {
234
+ context.log(LogLevelLabel.TRACE, `No dependencies or devDependencies to install. Skipping installation step.`);
235
+ return;
236
+ }
237
+ context.log(LogLevelLabel.DEBUG, `The following packages are required:
238
+ Dependencies:
239
+ ${Object.entries(context.dependencies).map(([name, version]) => `- ${name}@${String(version)}`).join(" \n")}
240
+
241
+ DevDependencies:
242
+ ${Object.entries(context.devDependencies).map(([name, version]) => `- ${name}@${String(version)}`).join(" \n")}`);
243
+ await Promise.all([
244
+ Promise.all(Object.entries(context.dependencies).map(async ([name, version]) => installPackage(context, `${getPackageName(name)}@${String(version)}`, false))),
245
+ Promise.all(Object.entries(context.devDependencies).map(async ([name, version]) => installPackage(context, `${getPackageName(name)}@${String(version)}`, true)))
246
+ ]);
247
+ }
248
+ __name(installDependencies, "installDependencies");
249
+ async function resolveTsconfigChanges(context) {
250
+ const tsconfig = getParsedTypeScriptConfig(context.workspaceConfig.workspaceRoot, context.config.projectRoot, context.config.tsconfig, context.config.tsconfigRaw);
251
+ const tsconfigFilePath = getTsconfigFilePath(context.workspaceConfig.workspaceRoot, context.config.projectRoot, context.config.tsconfig);
252
+ const tsconfigJson = await readJsonFile(tsconfigFilePath);
253
+ tsconfigJson.compilerOptions ??= {};
254
+ const extendedTsconfig = await loadTsConfig(tsconfigFilePath);
255
+ extendedTsconfig.compilerOptions ??= {};
256
+ if (tsconfigJson.reflection !== true) {
257
+ tsconfigJson.reflection = true;
258
+ }
259
+ if (tsconfig.options.experimentalDecorators !== true) {
260
+ tsconfigJson.compilerOptions.experimentalDecorators = true;
261
+ }
262
+ if (tsconfig.options.emitDecoratorMetadata !== true) {
263
+ tsconfigJson.compilerOptions.emitDecoratorMetadata = true;
264
+ }
265
+ if (context.config.output.dts) {
266
+ 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");
267
+ const dtsRelativePath = joinPaths(relativePath(joinPaths(context.workspaceConfig.workspaceRoot, context.config.projectRoot), findFilePath(dtsFilePath)), findFileName(dtsFilePath));
268
+ if (!tsconfigJson.include?.some((filePattern) => isIncludeMatchFound(filePattern, [
269
+ dtsFilePath,
270
+ dtsRelativePath,
271
+ "storm.d.ts"
272
+ ]))) {
273
+ tsconfigJson.include ??= [];
274
+ tsconfigJson.include.push(dtsRelativePath.startsWith("./") ? dtsRelativePath.slice(2) : dtsRelativePath);
275
+ }
276
+ }
277
+ if (!tsconfig.options.lib?.some((lib) => [
278
+ "lib.esnext.d.ts",
279
+ "lib.es2021.d.ts",
280
+ "lib.es2022.d.ts",
281
+ "lib.es2023.d.ts"
282
+ ].includes(lib.toLowerCase()))) {
283
+ tsconfigJson.compilerOptions.lib ??= [];
284
+ tsconfigJson.compilerOptions.lib.push("esnext");
285
+ }
286
+ if (tsconfig.options.module !== ts.ModuleKind.ESNext) {
287
+ tsconfigJson.compilerOptions.module = "ESNext";
288
+ }
289
+ if (!tsconfig.options.target || ![
290
+ ts.ScriptTarget.ESNext,
291
+ ts.ScriptTarget.ES2024,
292
+ ts.ScriptTarget.ES2023,
293
+ ts.ScriptTarget.ES2022,
294
+ ts.ScriptTarget.ES2021
295
+ ].includes(tsconfig.options.target)) {
296
+ tsconfigJson.compilerOptions.target = "ESNext";
297
+ }
298
+ if (tsconfig.options.moduleResolution !== ts.ModuleResolutionKind.Bundler) {
299
+ tsconfigJson.compilerOptions.moduleResolution = "Bundler";
300
+ }
301
+ if (tsconfig.options.moduleDetection !== ts.ModuleDetectionKind.Force) {
302
+ tsconfigJson.compilerOptions.moduleDetection = "force";
303
+ }
304
+ if (tsconfig.options.allowSyntheticDefaultImports !== true) {
305
+ tsconfigJson.compilerOptions.allowSyntheticDefaultImports = true;
306
+ }
307
+ if (tsconfig.options.noImplicitOverride !== true) {
308
+ tsconfigJson.compilerOptions.noImplicitOverride = true;
309
+ }
310
+ if (tsconfig.options.noUncheckedIndexedAccess !== true) {
311
+ tsconfigJson.compilerOptions.noUncheckedIndexedAccess = true;
312
+ }
313
+ if (tsconfig.options.skipLibCheck !== true) {
314
+ tsconfigJson.compilerOptions.skipLibCheck = true;
315
+ }
316
+ if (tsconfig.options.resolveJsonModule !== true) {
317
+ tsconfigJson.compilerOptions.resolveJsonModule = true;
318
+ }
319
+ if (tsconfig.options.isolatedModules !== true) {
320
+ tsconfigJson.compilerOptions.isolatedModules = true;
321
+ }
322
+ if (tsconfig.options.verbatimModuleSyntax !== false) {
323
+ tsconfigJson.compilerOptions.verbatimModuleSyntax = false;
324
+ }
325
+ if (tsconfig.options.allowJs !== true) {
326
+ tsconfigJson.compilerOptions.allowJs = true;
327
+ }
328
+ if (tsconfig.options.esModuleInterop !== true) {
329
+ tsconfigJson.compilerOptions.esModuleInterop = true;
330
+ }
331
+ if (tsconfig.options.declaration !== true) {
332
+ tsconfigJson.compilerOptions.declaration = true;
333
+ }
334
+ if (context.environment.consumer === "client") {
335
+ if (tsconfig.options.jsx !== ts.JsxEmit.ReactJSX) {
336
+ tsconfigJson.compilerOptions.jsx = "react-jsx";
337
+ }
338
+ if (!tsconfig.options.lib?.some((lib) => lib.toLowerCase() !== "dom")) {
339
+ tsconfigJson.compilerOptions.lib ??= [];
340
+ tsconfigJson.compilerOptions.lib.push("dom");
341
+ }
342
+ if (!tsconfig.options.lib?.some((lib) => lib.toLowerCase() !== "dom.iterable")) {
343
+ tsconfigJson.compilerOptions.lib ??= [];
344
+ tsconfigJson.compilerOptions.lib.push("dom.iterable");
345
+ }
346
+ } else if (context.config.build.platform === "node") {
347
+ if (!tsconfig.options.types?.some((type) => type.toLowerCase() === "node" || type.toLowerCase() === "@types/node")) {
348
+ tsconfigJson.compilerOptions.types ??= [];
349
+ tsconfigJson.compilerOptions.types.push("node");
350
+ }
351
+ }
352
+ return tsconfigJson;
353
+ }
354
+ __name(resolveTsconfigChanges, "resolveTsconfigChanges");
355
+ async function initializeTsconfig(context) {
356
+ context.log(LogLevelLabel.TRACE, "Initializing TypeScript configuration (tsconfig.json) for the Powerlines project.");
357
+ if (!isPackageExists("typescript")) {
358
+ throw new Error('The TypeScript package is not installed. Please install the package using the command: "npm install typescript --save-dev"');
359
+ }
360
+ const tsconfigFilePath = getTsconfigFilePath(context.workspaceConfig.workspaceRoot, context.config.projectRoot, context.config.tsconfig);
361
+ context.tsconfig.originalTsconfigJson = await readJsonFile(tsconfigFilePath);
362
+ context.tsconfig.tsconfigJson = await resolveTsconfigChanges(context);
363
+ await context.fs.writeFile(tsconfigFilePath, StormJSON.stringify(context.tsconfig.tsconfigJson), {
364
+ mode: "fs"
365
+ });
366
+ context.tsconfig = getParsedTypeScriptConfig(context.workspaceConfig.workspaceRoot, context.config.projectRoot, context.config.tsconfig, context.config.tsconfigRaw, context.tsconfig.originalTsconfigJson);
367
+ }
368
+ __name(initializeTsconfig, "initializeTsconfig");
369
+ async function resolveTsconfig(context) {
370
+ const updateTsconfigJson = await readJsonFile(context.tsconfig.tsconfigFilePath);
371
+ if (updateTsconfigJson?.compilerOptions?.types && Array.isArray(updateTsconfigJson.compilerOptions.types) && !updateTsconfigJson.compilerOptions.types.length) {
372
+ delete updateTsconfigJson.compilerOptions.types;
373
+ }
374
+ const result = getObjectDiff(context.tsconfig.originalTsconfigJson, updateTsconfigJson, {
375
+ ignoreArrayOrder: true,
376
+ showOnly: {
377
+ statuses: [
378
+ "added",
379
+ "deleted",
380
+ "updated"
381
+ ],
382
+ granularity: "deep"
383
+ }
384
+ });
385
+ const changes = [];
386
+ const getChanges = /* @__PURE__ */ __name((difference, property) => {
387
+ if (difference.status === "added" || difference.status === "deleted" || difference.status === "updated") {
388
+ if (difference.diff) {
389
+ for (const diff of difference.diff) {
390
+ getChanges(diff, property ? `${property}.${difference.property}` : difference.property);
391
+ }
392
+ } else {
393
+ changes.push({
394
+ field: property ? `${property}.${difference.property}` : difference.property,
395
+ status: difference.status,
396
+ previous: difference.status === "added" ? "---" : StormJSON.stringify(difference.previousValue),
397
+ current: difference.status === "deleted" ? "---" : StormJSON.stringify(difference.currentValue)
398
+ });
399
+ }
400
+ }
401
+ }, "getChanges");
402
+ for (const diff of result.diff) {
403
+ getChanges(diff);
404
+ }
405
+ if (changes.length > 0) {
406
+ context.log(LogLevelLabel.WARN, `Updating the following configuration values in "${context.tsconfig.tsconfigFilePath}" file:
407
+
408
+ ${changes.map((change, i) => `${chalk2.bold.whiteBright(`${i + 1}. ${titleCase(change.status)} the ${change.field} field: `)}
409
+ ${chalk2.red(` - Previous: ${change.previous} `)}
410
+ ${chalk2.green(` - Updated: ${change.current} `)}
411
+ `).join("\n")}
412
+ `);
413
+ }
414
+ await writeFile(context.log, context.tsconfig.tsconfigFilePath, StormJSON.stringify(updateTsconfigJson));
415
+ context.tsconfig = getParsedTypeScriptConfig(context.workspaceConfig.workspaceRoot, context.config.projectRoot, context.config.tsconfig);
416
+ if (!context.tsconfig) {
417
+ throw new Error("Failed to parse the TypeScript configuration file.");
418
+ }
419
+ context.tsconfig.tsconfigJson.compilerOptions ??= {};
420
+ context.tsconfig.tsconfigJson.compilerOptions.strict = false;
421
+ }
422
+ __name(resolveTsconfig, "resolveTsconfig");
423
+
424
+ // src/api.ts
425
+ var PowerlinesAPI = class _PowerlinesAPI {
426
+ static {
427
+ __name(this, "PowerlinesAPI");
428
+ }
429
+ /**
430
+ * The Powerlines context
431
+ */
432
+ #context;
433
+ /**
434
+ * The Powerlines context
435
+ */
436
+ get context() {
437
+ return this.#context;
438
+ }
439
+ /**
440
+ * Create a new Powerlines API instance
441
+ *
442
+ * @param context - The Powerlines context
443
+ */
444
+ constructor(context) {
445
+ this.#context = context;
446
+ }
447
+ /**
448
+ * Initialize the Powerlines API
449
+ */
450
+ static async from(workspaceRoot, config) {
451
+ const api = new _PowerlinesAPI(await PowerlinesAPIContext.from(workspaceRoot, config));
452
+ api.#context.$$internal.api = api;
453
+ for (const plugin of api.context.config.plugins ?? []) {
454
+ await api.#addPlugin(plugin);
455
+ }
456
+ if (api.context.plugins.length === 0) {
457
+ api.context.log(LogLevelLabel.WARN, "No Powerlines plugins were specified in the options. Please ensure this is correct, as it is generally not recommended.");
458
+ }
459
+ const pluginConfig = await callHook(await api.context.getEnvironment(), "config", {
460
+ sequential: true,
461
+ result: "merge"
462
+ });
463
+ await api.context.withUserConfig(pluginConfig, {
464
+ isHighPriority: false
465
+ });
466
+ return api;
467
+ }
468
+ /**
469
+ * Prepare the Powerlines API
470
+ *
471
+ * @remarks
472
+ * This method will prepare the Powerlines API for use, initializing any necessary resources.
473
+ *
474
+ * @param inlineConfig - The inline configuration for the prepare command
475
+ */
476
+ async prepare(inlineConfig = {
477
+ command: "prepare"
478
+ }) {
479
+ this.context.log(LogLevelLabel.TRACE, " \u{1F3D7}\uFE0F Preparing the Powerlines project");
480
+ this.context.log(LogLevelLabel.TRACE, " \u2699\uFE0F Aggregating configuration options for the Powerlines project");
481
+ await this.context.withInlineConfig(inlineConfig);
482
+ await this.#executeEnvironments(async (context) => {
483
+ context.log(LogLevelLabel.TRACE, `Initializing the processing options for the Powerlines project.`);
484
+ await this.callPreHook(context, "configResolved");
485
+ await initializeTsconfig(context);
486
+ await this.callNormalHook(context, "configResolved");
487
+ 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 ? `:
488
+ ${context.entry.map((entry) => `- ${entry.input.file || entry.file}${entry.output ? ` -> ${entry.output}` : ""}`).join(" \n")}` : ""}.`);
489
+ await resolveTsconfig(context);
490
+ await installDependencies(context);
491
+ await this.callPostHook(context, "configResolved");
492
+ if (context.config.build.polyfill) {
493
+ context.config.build.polyfill = context.config.build.polyfill.map((polyfill) => replacePathTokens(context, polyfill));
494
+ }
495
+ context.log(LogLevelLabel.TRACE, `Powerlines configuration has been resolved:
496
+
497
+ ${formatLogMessage(context.config)}`);
498
+ context.fs[__VFS_PATCH__]();
499
+ await writeMetaFile(context);
500
+ context.persistedMeta = context.meta;
501
+ if (!existsSync(context.cachePath)) {
502
+ await createDirectory(context.cachePath);
503
+ }
504
+ if (!existsSync(context.dataPath)) {
505
+ await createDirectory(context.dataPath);
506
+ }
507
+ await this.callPreHook(context, "prepare");
508
+ await this.callNormalHook(context, "prepare");
509
+ if (context.config.output.dts !== false) {
510
+ context.log(LogLevelLabel.TRACE, `Preparing the TypeScript definitions for the Powerlines project.`);
511
+ context.log(LogLevelLabel.TRACE, "Transforming built-ins runtime modules files.");
512
+ const builtinFilePaths = await Promise.all((await context.getBuiltins()).map(async (file) => {
513
+ const result2 = await transformAsync(file.code.toString(), {
514
+ highlightCode: true,
515
+ code: true,
516
+ ast: false,
517
+ cloneInputAst: false,
518
+ comments: true,
519
+ sourceType: "module",
520
+ configFile: false,
521
+ babelrc: false,
522
+ envName: context.config.mode,
523
+ caller: {
524
+ name: "powerlines"
525
+ },
526
+ ...context.config.transform.babel,
527
+ filename: file.path,
528
+ plugins: [
529
+ [
530
+ "@babel/plugin-syntax-typescript"
531
+ ],
532
+ [
533
+ moduleResolverBabelPlugin(context)
534
+ ]
535
+ ]
536
+ });
537
+ if (!result2?.code) {
538
+ throw new Error(`Powerlines - Generate Types failed to compile ${file.id}`);
539
+ }
540
+ context.log(LogLevelLabel.TRACE, `Writing transformed built-in runtime file ${file.id}.`);
541
+ await context.emitBuiltin(result2.code, file.id, file.path);
542
+ return file.path;
543
+ }));
544
+ const typescriptPath = await resolvePackage("typescript");
545
+ if (!typescriptPath) {
546
+ throw new Error("Could not resolve TypeScript package location. Please ensure TypeScript is installed.");
547
+ }
548
+ const files = builtinFilePaths.reduce((ret, fileName) => {
549
+ const formatted = replacePath(fileName, context.workspaceConfig.workspaceRoot);
550
+ if (!ret.includes(formatted)) {
551
+ ret.push(formatted);
552
+ }
553
+ return ret;
554
+ }, [
555
+ joinPaths(typescriptPath, "lib", "lib.esnext.full.d.ts")
556
+ ]);
557
+ context.log(LogLevelLabel.TRACE, "Parsing TypeScript configuration for the Powerlines project.");
558
+ const resolvedTsconfig = getParsedTypeScriptConfig(context.workspaceConfig.workspaceRoot, context.config.projectRoot, context.tsconfig.tsconfigFilePath, defu({
559
+ compilerOptions: {
560
+ strict: false,
561
+ noEmit: false,
562
+ declaration: true,
563
+ declarationMap: false,
564
+ emitDeclarationOnly: true,
565
+ skipLibCheck: true
566
+ },
567
+ exclude: [
568
+ "node_modules",
569
+ "dist"
570
+ ],
571
+ include: files
572
+ }, context.config.tsconfigRaw ?? {}));
573
+ resolvedTsconfig.options.configFilePath = joinPaths(context.workspaceConfig.workspaceRoot, context.tsconfig.tsconfigFilePath);
574
+ resolvedTsconfig.options.pathsBasePath = context.workspaceConfig.workspaceRoot;
575
+ resolvedTsconfig.options.suppressOutputPathCheck = true;
576
+ let generatedTypes = await emitTypes(context, resolvedTsconfig, files);
577
+ context.log(LogLevelLabel.TRACE, `Generating TypeScript declaration file in ${context.config.output.dts}.`);
578
+ const directives = [];
579
+ let result = await this.callPreHook(context, "generateTypes", generatedTypes);
580
+ if (result) {
581
+ if (isSetObject(result)) {
582
+ generatedTypes = result.code;
583
+ if (Array.isArray(result.directives) && result.directives.length > 0) {
584
+ directives.push(...result.directives);
585
+ }
586
+ } else if (isSetString(result)) {
587
+ generatedTypes = result;
588
+ }
589
+ }
590
+ result = await this.callNormalHook(context, "generateTypes", generatedTypes);
591
+ if (result) {
592
+ if (isSetObject(result)) {
593
+ generatedTypes = result.code;
594
+ if (Array.isArray(result.directives) && result.directives.length > 0) {
595
+ directives.push(...result.directives);
596
+ }
597
+ } else if (isSetString(result)) {
598
+ generatedTypes = result;
599
+ }
600
+ }
601
+ result = await this.callPostHook(context, "generateTypes", generatedTypes);
602
+ if (result) {
603
+ if (isSetObject(result)) {
604
+ generatedTypes = result.code;
605
+ if (Array.isArray(result.directives) && result.directives.length > 0) {
606
+ directives.push(...result.directives);
607
+ }
608
+ } else if (isSetString(result)) {
609
+ generatedTypes = result;
610
+ }
611
+ }
612
+ await context.fs.writeFile(context.config.output.dts, `${directives ? `${directives.map((directive) => `/// <reference types="${directive}" />`).join("\n")}
613
+
614
+ ` : ""}${getFileHeader(context, {
615
+ directive: null,
616
+ prettierIgnore: false
617
+ })}
618
+
619
+ ${formatTypes(generatedTypes)}
620
+ `, {
621
+ mode: "fs"
622
+ });
623
+ }
624
+ context.tsconfig = getParsedTypeScriptConfig(context.workspaceConfig.workspaceRoot, context.config.projectRoot, context.config.tsconfig);
625
+ if (!context.tsconfig) {
626
+ throw new Error("Failed to parse the TypeScript configuration file.");
627
+ }
628
+ await this.callPostHook(context, "prepare");
629
+ await writeMetaFile(context);
630
+ context.fs[__VFS_REVERT__]();
631
+ });
632
+ this.context.log(LogLevelLabel.INFO, "Powerlines API has been prepared successfully");
633
+ }
634
+ /**
635
+ * Create a new Powerlines project
636
+ *
637
+ * @remarks
638
+ * This method will create a new Powerlines project in the current directory.
639
+ *
640
+ * @param inlineConfig - The inline configuration for the new command
641
+ * @returns A promise that resolves when the project has been created
642
+ */
643
+ async new(inlineConfig) {
644
+ this.context.log(LogLevelLabel.INFO, "\u{1F195} Creating a new Powerlines project");
645
+ await this.prepare(inlineConfig);
646
+ await this.#executeEnvironments(async (context) => {
647
+ context.log(LogLevelLabel.TRACE, `Initializing the processing options for the Powerlines project.`);
648
+ await this.callPreHook(context, "new");
649
+ const files = await listFiles(joinPaths(context.powerlinesPath, "files/common/**/*.hbs"));
650
+ for (const file of files) {
651
+ context.log(LogLevelLabel.TRACE, `Adding template file: ${file}`);
652
+ const template = Handlebars.compile(file);
653
+ await writeFile(context.log, joinPaths(context.config.projectRoot, file.replace(".hbs", "")), template(context));
654
+ }
655
+ await this.callNormalHook(context, "new");
656
+ if (context.config.projectType === "application") {
657
+ const files2 = await listFiles(joinPaths(context.powerlinesPath, "files/application/**/*.hbs"));
658
+ for (const file of files2) {
659
+ context.log(LogLevelLabel.TRACE, `Adding application template file: ${file}`);
660
+ const template = Handlebars.compile(file);
661
+ await writeFile(context.log, joinPaths(context.config.projectRoot, file.replace(".hbs", "")), template(context));
662
+ }
663
+ } else {
664
+ const files2 = await listFiles(joinPaths(context.powerlinesPath, "files/library/**/*.hbs"));
665
+ for (const file of files2) {
666
+ context.log(LogLevelLabel.TRACE, `Adding library template file: ${file}`);
667
+ const template = Handlebars.compile(file);
668
+ await writeFile(context.log, joinPaths(context.config.projectRoot, file.replace(".hbs", "")), template(context));
669
+ }
670
+ }
671
+ await this.callPostHook(context, "new");
672
+ });
673
+ this.context.log(LogLevelLabel.TRACE, "Powerlines - New command completed");
674
+ }
675
+ /**
676
+ * Clean any previously prepared artifacts
677
+ *
678
+ * @remarks
679
+ * This method will remove the previous Powerlines artifacts from the project.
680
+ *
681
+ * @param inlineConfig - The inline configuration for the clean command
682
+ * @returns A promise that resolves when the clean command has completed
683
+ */
684
+ async clean(inlineConfig = {
685
+ command: "clean"
686
+ }) {
687
+ this.context.log(LogLevelLabel.INFO, "\u{1F9F9} Cleaning the previous Powerlines artifacts");
688
+ await this.prepare(inlineConfig);
689
+ await this.#executeEnvironments(async (context) => {
690
+ this.context.log(LogLevelLabel.TRACE, "Cleaning the project's dist and artifacts directories.");
691
+ await context.fs.rmdir(joinPaths(context.workspaceConfig.workspaceRoot, context.config.output.distPath));
692
+ await context.fs.rmdir(joinPaths(context.workspaceConfig.workspaceRoot, context.config.output.artifactsFolder));
693
+ await callHook(context, "clean", {
694
+ sequential: true
695
+ });
696
+ });
697
+ this.context.log(LogLevelLabel.TRACE, "Powerlines - Clean command completed");
698
+ }
699
+ /**
700
+ * Lint the project
701
+ *
702
+ * @param inlineConfig - The inline configuration for the lint command
703
+ * @returns A promise that resolves when the lint command has completed
704
+ */
705
+ async lint(inlineConfig = {
706
+ command: "lint"
707
+ }) {
708
+ this.context.log(LogLevelLabel.INFO, "\u{1F4CB} Linting the Powerlines project");
709
+ await this.prepare(inlineConfig);
710
+ await this.#executeEnvironments(async (context) => {
711
+ if (context.config.lint !== false) {
712
+ await this.callHook(context, "lint");
713
+ }
714
+ });
715
+ this.context.log(LogLevelLabel.TRACE, "Powerlines linting completed");
716
+ }
717
+ /**
718
+ * Build the project
719
+ *
720
+ * @remarks
721
+ * This method will build the Powerlines project, generating the necessary artifacts.
722
+ *
723
+ * @param inlineConfig - The inline configuration for the build command
724
+ * @returns A promise that resolves when the build command has completed
725
+ */
726
+ async build(inlineConfig = {
727
+ command: "build"
728
+ }) {
729
+ this.context.log(LogLevelLabel.INFO, "\u{1F4E6} Building the Powerlines project");
730
+ await this.prepare(inlineConfig);
731
+ await this.#executeEnvironments(async (context) => {
732
+ await this.callPreHook(context, "build");
733
+ await this.callNormalHook(context, "build");
734
+ if (context.config.output.distPath !== context.config.output.outputPath) {
735
+ const sourcePath = appendPath(context.config.output.distPath, context.workspaceConfig.workspaceRoot);
736
+ const destinationPath = joinPaths(appendPath(context.config.output.outputPath, context.workspaceConfig.workspaceRoot), "dist");
737
+ if (sourcePath !== destinationPath) {
738
+ context.log(LogLevelLabel.INFO, `Copying build output files from project's build directory (${context.config.output.distPath}) to the workspace's output directory (${context.config.output.outputPath}).`);
739
+ await copyFiles({
740
+ input: sourcePath,
741
+ glob: "**/*"
742
+ }, destinationPath);
743
+ }
744
+ }
745
+ await Promise.all(context.config.output.assets.map(async (asset) => {
746
+ context.log(LogLevelLabel.DEBUG, `Copying asset(s): ${chalk2.redBright(context.workspaceConfig.workspaceRoot === asset.input ? asset.glob : joinPaths(replacePath(asset.input, context.workspaceConfig.workspaceRoot), asset.glob))} -> ${chalk2.greenBright(joinPaths(replacePath(asset.output, context.workspaceConfig.workspaceRoot), asset.glob))} ${Array.isArray(asset.ignore) && asset.ignore.length > 0 ? ` (ignoring: ${asset.ignore.map((i) => chalk2.yellowBright(i)).join(", ")})` : ""}`);
747
+ await copyFiles(asset, asset.output);
748
+ }));
749
+ await this.callPostHook(context, "build");
750
+ });
751
+ this.context.log(LogLevelLabel.TRACE, "Powerlines build completed");
752
+ }
753
+ /**
754
+ * Prepare the documentation for the project
755
+ *
756
+ * @param inlineConfig - The inline configuration for the docs command
757
+ * @returns A promise that resolves when the documentation generation has completed
758
+ */
759
+ async docs(inlineConfig = {
760
+ command: "docs"
761
+ }) {
762
+ this.context.log(LogLevelLabel.INFO, "\u{1F4D3} Generating documentation for the Powerlines project");
763
+ await this.prepare(inlineConfig);
764
+ await this.#executeEnvironments(async (context) => {
765
+ context.log(LogLevelLabel.TRACE, "Writing documentation for the Powerlines project artifacts.");
766
+ await this.prepare(inlineConfig);
767
+ await this.#executeEnvironments(async (context2) => {
768
+ await this.callHook(context2, "docs");
769
+ });
770
+ });
771
+ this.#context.log(LogLevelLabel.TRACE, "Powerlines documentation generation completed");
772
+ }
773
+ /**
774
+ * Deploy the project source code
775
+ *
776
+ * @remarks
777
+ * This method will prepare and build the Powerlines project, generating the necessary artifacts for the deployment.
778
+ *
779
+ * @param inlineConfig - The inline configuration for the deploy command
780
+ */
781
+ async deploy(inlineConfig = {
782
+ command: "deploy"
783
+ }) {
784
+ this.context.log(LogLevelLabel.INFO, "\u{1F4E6} Deploying the Powerlines project");
785
+ await this.prepare(inlineConfig);
786
+ await this.#executeEnvironments(async (context) => {
787
+ await this.callHook(context, "deploy");
788
+ });
789
+ this.context.log(LogLevelLabel.TRACE, "Powerlines deploy completed");
790
+ }
791
+ /**
792
+ * Finalization process
793
+ *
794
+ * @remarks
795
+ * This step includes any final processes or clean up required by Powerlines. It will be run after each Powerlines command.
796
+ *
797
+ * @returns A promise that resolves when the finalization process has completed
798
+ */
799
+ async finalize() {
800
+ this.context.log(LogLevelLabel.TRACE, "Powerlines finalize execution started");
801
+ await this.#executeEnvironments(async (context) => {
802
+ await this.callHook(context, "finalize");
803
+ context.fs[__VFS_REVERT__]();
804
+ await context.fs.dispose();
805
+ });
806
+ this.context.log(LogLevelLabel.TRACE, "Powerlines finalize execution completed");
807
+ }
808
+ /**
809
+ * Calls a hook in parallel
810
+ *
811
+ * @param hook - The hook to call
812
+ * @param options - Options for calling the hook
813
+ * @param args - The arguments to pass to the hook
814
+ * @returns The result of the hook call
815
+ */
816
+ async callHookParallel(hook, options, ...args) {
817
+ return callHook(isSetObject(options?.environment) ? options.environment : await this.#context.getEnvironment(options?.environment), hook, {
818
+ ...options,
819
+ sequential: false
820
+ }, ...args);
821
+ }
822
+ /**
823
+ * Calls a hook in sequence
824
+ *
825
+ * @param hook - The hook to call
826
+ * @param options - Options for calling the hook
827
+ * @param args - The arguments to pass to the hook
828
+ * @returns The result of the hook call
829
+ */
830
+ async callHookSequential(hook, options, ...args) {
831
+ return callHook(isSetObject(options?.environment) ? options.environment : await this.#context.getEnvironment(options?.environment), hook, {
832
+ ...options,
833
+ sequential: true
834
+ }, ...args);
835
+ }
836
+ /**
837
+ * Calls the `"pre"` ordered hooks in sequence
838
+ *
839
+ * @param environment - The environment to use for the hook call
840
+ * @param hook - The hook to call
841
+ * @param args - The arguments to pass to the hook
842
+ * @returns The result of the hook call
843
+ */
844
+ async callPreHook(environment, hook, ...args) {
845
+ return this.callHookSequential(hook, {
846
+ order: "pre",
847
+ environment
848
+ }, ...args);
849
+ }
850
+ /**
851
+ * Calls the `"post"` ordered hooks in sequence
852
+ *
853
+ * @param environment - The environment to use for the hook call
854
+ * @param hook - The hook to call
855
+ * @param args - The arguments to pass to the hook
856
+ * @returns The result of the hook call
857
+ */
858
+ async callPostHook(environment, hook, ...args) {
859
+ return this.callHookSequential(hook, {
860
+ order: "post",
861
+ environment
862
+ }, ...args);
863
+ }
864
+ /**
865
+ * Calls a hook in sequence
866
+ *
867
+ * @param environment - The environment to use for the hook call
868
+ * @param hook - The hook to call
869
+ * @param args - The arguments to pass to the hook
870
+ * @returns The result of the hook call
871
+ */
872
+ async callNormalHook(environment, hook, ...args) {
873
+ return this.callHookSequential(hook, {
874
+ order: "normal",
875
+ environment
876
+ }, ...args);
877
+ }
878
+ /**
879
+ * Calls the `"pre"` and `"post"` ordered hooks, as well as the normal hooks in sequence
880
+ *
881
+ * @param environment - The environment to use for the hook call
882
+ * @param hook - The hook to call
883
+ * @param args - The arguments to pass to the hook
884
+ * @returns The result of the hook call
885
+ */
886
+ async callHook(environment, hook, ...args) {
887
+ return this.callHookSequential(hook, {
888
+ environment
889
+ }, ...args);
890
+ }
891
+ /**
892
+ * Dispose of the Powerlines API instance
893
+ *
894
+ * @remarks
895
+ * This method will finalize the Powerlines API instance, cleaning up any resources used.
896
+ */
897
+ async [Symbol.asyncDispose]() {
898
+ await this.finalize();
899
+ }
900
+ /**
901
+ * Get the configured environments
902
+ *
903
+ * @returns The configured environments
904
+ */
905
+ async #getEnvironments() {
906
+ if (!this.context.config.environments || Object.keys(this.context.config.environments).length <= 1) {
907
+ this.context.log(LogLevelLabel.DEBUG, "No environments are configured for this Powerlines project. Using the default environment.");
908
+ return [
909
+ await this.context.getEnvironment()
910
+ ];
911
+ }
912
+ this.context.log(LogLevelLabel.DEBUG, `Found ${Object.keys(this.context.config.environments).length} configured environment(s) for this Powerlines project.`);
913
+ return (await Promise.all(Object.entries(this.context.config.environments).map(async ([name, config]) => {
914
+ const environment = await this.context.getEnvironmentSafe(name);
915
+ if (!environment) {
916
+ const resolvedEnvironment = await this.callHookParallel("configEnvironment", {
917
+ environment: name
918
+ }, name, config);
919
+ if (resolvedEnvironment) {
920
+ this.context.environments[name] = await this.context.in(resolvedEnvironment);
921
+ }
922
+ }
923
+ return this.context.environments[name];
924
+ }))).filter((context) => isSet(context));
925
+ }
926
+ /**
927
+ * Execute a handler function for each environment
928
+ *
929
+ * @param handle - The handler function to execute for each environment
930
+ */
931
+ async #executeEnvironments(handle) {
932
+ await Promise.all((await this.#getEnvironments()).map(async (context) => {
933
+ return Promise.resolve(handle(context));
934
+ }));
935
+ }
936
+ /**
937
+ * Add a Powerlines plugin used in the build process
938
+ *
939
+ * @param config - The import path of the plugin to add
940
+ */
941
+ async #addPlugin(config) {
942
+ if (config) {
943
+ const plugin = await this.#initPlugin(config);
944
+ if (!plugin) {
945
+ return;
946
+ }
947
+ if (plugin.dependsOn) {
948
+ for (const required of plugin.dependsOn) {
949
+ await this.#addPlugin(required);
950
+ }
951
+ }
952
+ this.context.log(LogLevelLabel.DEBUG, `Successfully initialized the ${chalk2.bold.cyanBright(plugin.name)} plugin`);
953
+ await this.context.addPlugin(plugin);
954
+ }
955
+ }
956
+ /**
957
+ * Initialize a Powerlines plugin
958
+ *
959
+ * @param config - The configuration for the plugin
960
+ * @returns The initialized plugin instance, or null if the plugin was a duplicate
961
+ * @throws Will throw an error if the plugin cannot be found or is invalid
962
+ */
963
+ async #initPlugin(config) {
964
+ let awaited = config;
965
+ if (isPromiseLike(config)) {
966
+ awaited = await Promise.resolve(config);
967
+ }
968
+ if (!isPluginConfig(awaited)) {
969
+ 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\`.`);
970
+ }
971
+ let plugin;
972
+ if (isPlugin(awaited)) {
973
+ plugin = awaited;
974
+ } else if (isFunction(awaited)) {
975
+ plugin = await Promise.resolve(awaited());
976
+ } else if (isSetString(awaited)) {
977
+ const resolved = await this.#resolvePlugin(awaited);
978
+ if (isFunction(resolved)) {
979
+ plugin = await Promise.resolve(resolved());
980
+ } else {
981
+ plugin = resolved;
982
+ }
983
+ } else if (isPluginConfigTuple(awaited) || isPluginConfigObject(awaited)) {
984
+ let pluginConfig;
985
+ let pluginOptions;
986
+ if (isPluginConfigTuple(awaited)) {
987
+ pluginConfig = awaited[0];
988
+ pluginOptions = awaited?.length === 2 ? awaited[1] : void 0;
989
+ } else {
990
+ pluginConfig = awaited.plugin;
991
+ pluginOptions = awaited.options;
992
+ }
993
+ if (isSetString(pluginConfig)) {
994
+ const resolved = await this.#resolvePlugin(pluginConfig);
995
+ if (isFunction(resolved)) {
996
+ plugin = await Promise.resolve(pluginOptions ? resolved(pluginOptions) : resolved());
997
+ } else {
998
+ plugin = resolved;
999
+ }
1000
+ } else if (isFunction(pluginConfig)) {
1001
+ plugin = await Promise.resolve(pluginConfig(pluginOptions));
1002
+ } else if (isPlugin(pluginConfig)) {
1003
+ plugin = pluginConfig;
1004
+ }
1005
+ }
1006
+ if (!plugin) {
1007
+ throw new Error(`The plugin configuration ${JSON.stringify(awaited)} is invalid. This configuration must point to a valid Powerlines plugin module.`);
1008
+ }
1009
+ if (!isPlugin(plugin)) {
1010
+ 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.`);
1011
+ }
1012
+ if (checkDedupe(plugin, this.context.plugins)) {
1013
+ this.context.log(LogLevelLabel.TRACE, `Duplicate ${chalk2.bold.cyanBright(plugin.name)} plugin dependency detected - Skipping initialization.`);
1014
+ return null;
1015
+ }
1016
+ this.context.log(LogLevelLabel.TRACE, `Initializing the ${chalk2.bold.cyanBright(plugin.name)} plugin...`);
1017
+ return plugin;
1018
+ }
1019
+ async #resolvePlugin(pluginPath) {
1020
+ if (pluginPath.startsWith("@") && pluginPath.split("/").filter(Boolean).length > 2) {
1021
+ const splits = pluginPath.split("/").filter(Boolean);
1022
+ pluginPath = `${splits[0]}/${splits[1]}`;
1023
+ }
1024
+ const isInstalled = isPackageExists(pluginPath, {
1025
+ paths: [
1026
+ this.context.workspaceConfig.workspaceRoot,
1027
+ this.context.config.projectRoot
1028
+ ]
1029
+ });
1030
+ if (!isInstalled && this.context.config.skipInstalls !== true) {
1031
+ this.#context.log(LogLevelLabel.WARN, `The plugin package "${pluginPath}" is not installed. It will be installed automatically.`);
1032
+ const result = await install(pluginPath, {
1033
+ cwd: this.context.config.projectRoot
1034
+ });
1035
+ if (isNumber(result.exitCode) && result.exitCode > 0) {
1036
+ this.#context.log(LogLevelLabel.ERROR, result.stderr);
1037
+ throw new Error(`An error occurred while installing the build plugin package "${pluginPath}" `);
1038
+ }
1039
+ }
1040
+ try {
1041
+ const module = await this.context.resolver.plugin.import(this.context.resolver.plugin.esmResolve(joinPaths(pluginPath, "plugin")));
1042
+ const result = module.plugin ?? module.default;
1043
+ if (!result) {
1044
+ throw new Error(`The plugin package "${pluginPath}" does not export a valid module.`);
1045
+ }
1046
+ return result;
1047
+ } catch (error) {
1048
+ try {
1049
+ const module = await this.context.resolver.plugin.import(this.context.resolver.plugin.esmResolve(pluginPath));
1050
+ const result = module.plugin ?? module.default;
1051
+ if (!result) {
1052
+ throw new Error(`The plugin package "${pluginPath}" does not export a valid module.`);
1053
+ }
1054
+ return result;
1055
+ } catch {
1056
+ if (!isInstalled) {
1057
+ throw new Error(`The plugin package "${pluginPath}" is not installed. Please install the package using the command: "npm install ${pluginPath} --save-dev"`);
1058
+ } else {
1059
+ throw new Error(`An error occurred while importing the build plugin package "${pluginPath}":
1060
+ ${isError(error) ? error.message : String(error)}
1061
+
1062
+ 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\`.`);
1063
+ }
1064
+ }
1065
+ }
1066
+ }
1067
+ };
1068
+
1069
+ // src/lib/unplugin/factory.ts
1070
+ function createUnpluginFactory(variant, decorate) {
1071
+ return (config, meta) => {
1072
+ const log = createLog("unplugin", config);
1073
+ log(LogLevelLabel.DEBUG, "Initializing Unplugin");
1074
+ try {
1075
+ const userConfig = {
1076
+ ...config,
1077
+ variant,
1078
+ unplugin: meta
1079
+ };
1080
+ let api;
1081
+ let resolvePatterns = [];
1082
+ async function buildStart() {
1083
+ log(LogLevelLabel.DEBUG, "Powerlines build plugin starting...");
1084
+ const workspaceRoot = getWorkspaceRoot(process.cwd());
1085
+ api = await PowerlinesAPI.from(workspaceRoot, userConfig);
1086
+ if (api.context.config.build.skipNodeModulesBundle) {
1087
+ resolvePatterns = tsconfigPathsToRegExp(api.context.tsconfig.options.paths ?? []);
1088
+ }
1089
+ log(LogLevelLabel.DEBUG, "Preparing build artifacts for the Powerlines project...");
1090
+ await api.prepare({
1091
+ command: "build"
1092
+ });
1093
+ }
1094
+ __name(buildStart, "buildStart");
1095
+ async function resolveId(id, importer, options = {
1096
+ isEntry: false
1097
+ }) {
1098
+ return handleResolveId(api.context, {
1099
+ id,
1100
+ importer,
1101
+ options
1102
+ }, {
1103
+ skipNodeModulesBundle: api.context.config.build.skipNodeModulesBundle,
1104
+ external: api.context.config.build.external,
1105
+ noExternal: api.context.config.build.noExternal,
1106
+ resolvePatterns
1107
+ });
1108
+ }
1109
+ __name(resolveId, "resolveId");
1110
+ async function load(id) {
1111
+ const environment = await api.context.getEnvironment();
1112
+ if (id) {
1113
+ const resolvedPath = environment.fs.resolve(id);
1114
+ if (resolvedPath) {
1115
+ return environment.fs.readFile(resolvedPath);
1116
+ }
1117
+ }
1118
+ let result2 = await api.callPreHook(environment, "load", id);
1119
+ if (result2) {
1120
+ return result2;
1121
+ }
1122
+ result2 = await api.callNormalHook(environment, "load", id);
1123
+ if (result2) {
1124
+ return result2;
1125
+ }
1126
+ return api.callPostHook(environment, "load", id);
1127
+ }
1128
+ __name(load, "load");
1129
+ async function transform(code, id) {
1130
+ const environment = await api.context.getEnvironment();
1131
+ let transformed = code;
1132
+ let result2 = await api.callPreHook(environment, "transform", getString(transformed), id);
1133
+ if (result2) {
1134
+ transformed = result2;
1135
+ }
1136
+ result2 = await api.callNormalHook(environment, "transform", getString(transformed), id);
1137
+ if (result2) {
1138
+ transformed = result2;
1139
+ }
1140
+ result2 = await api.callPostHook(environment, "transform", getString(transformed), id);
1141
+ if (result2) {
1142
+ transformed = result2;
1143
+ }
1144
+ return transformed;
1145
+ }
1146
+ __name(transform, "transform");
1147
+ async function writeBundle() {
1148
+ log(LogLevelLabel.DEBUG, "Finalizing Powerlines project output...");
1149
+ const environment = await api.context.getEnvironment();
1150
+ await api.callHook(environment, "writeBundle");
1151
+ }
1152
+ __name(writeBundle, "writeBundle");
1153
+ const result = {
1154
+ name: "powerlines",
1155
+ api,
1156
+ resolveId: {
1157
+ filter: {
1158
+ id: {
1159
+ include: [
1160
+ /.*/
1161
+ ]
1162
+ }
1163
+ },
1164
+ handler: resolveId
1165
+ },
1166
+ load: {
1167
+ filter: {
1168
+ id: {
1169
+ include: [
1170
+ /.*/,
1171
+ /^storm:/
1172
+ ]
1173
+ }
1174
+ },
1175
+ handler: load
1176
+ },
1177
+ transform,
1178
+ buildStart,
1179
+ writeBundle
1180
+ };
1181
+ return decorate ? decorate(api, result) : result;
1182
+ } catch (error) {
1183
+ log(LogLevelLabel.FATAL, error?.message);
1184
+ throw error;
1185
+ }
1186
+ };
1187
+ }
1188
+ __name(createUnpluginFactory, "createUnpluginFactory");
1189
+
1190
+ export { createUnpluginFactory };