@powerlines/core 0.14.5 → 0.15.1

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 (391) hide show
  1. package/dist/constants/api.cjs +6 -5
  2. package/dist/constants/api.d.cts +3 -3
  3. package/dist/constants/api.d.cts.map +1 -1
  4. package/dist/constants/api.d.mts +3 -3
  5. package/dist/constants/api.d.mts.map +1 -1
  6. package/dist/constants/api.mjs +4 -4
  7. package/dist/constants/api.mjs.map +1 -1
  8. package/dist/constants/commands.cjs +3 -2
  9. package/dist/constants/commands.d.cts +1 -1
  10. package/dist/constants/commands.d.mts +1 -1
  11. package/dist/constants/commands.mjs +2 -2
  12. package/dist/constants/commands.mjs.map +1 -1
  13. package/dist/constants/devtools.cjs +23 -0
  14. package/dist/constants/devtools.d.cts +13 -0
  15. package/dist/constants/devtools.d.cts.map +1 -0
  16. package/dist/constants/devtools.d.mts +13 -0
  17. package/dist/constants/devtools.d.mts.map +1 -0
  18. package/dist/constants/devtools.mjs +14 -0
  19. package/dist/constants/devtools.mjs.map +1 -0
  20. package/dist/constants/environments.cjs +1 -0
  21. package/dist/constants/extensions.cjs +21 -0
  22. package/dist/constants/extensions.d.cts +5 -0
  23. package/dist/constants/extensions.d.cts.map +1 -0
  24. package/dist/constants/extensions.d.mts +5 -0
  25. package/dist/constants/extensions.d.mts.map +1 -0
  26. package/dist/constants/extensions.mjs +20 -0
  27. package/dist/constants/extensions.mjs.map +1 -0
  28. package/dist/constants/fs.cjs +1 -0
  29. package/dist/constants/hooks.cjs +1 -0
  30. package/dist/constants/index.cjs +48 -30
  31. package/dist/constants/index.d.cts +5 -3
  32. package/dist/constants/index.d.mts +5 -3
  33. package/dist/constants/index.mjs +5 -3
  34. package/dist/constants/log-level.cjs +90 -0
  35. package/dist/constants/log-level.d.cts +63 -0
  36. package/dist/constants/log-level.d.cts.map +1 -0
  37. package/dist/constants/log-level.d.mts +63 -0
  38. package/dist/constants/log-level.d.mts.map +1 -0
  39. package/dist/constants/log-level.mjs +82 -0
  40. package/dist/constants/log-level.mjs.map +1 -0
  41. package/dist/constants/meta.cjs +1 -0
  42. package/dist/constants/plugin.cjs +3 -2
  43. package/dist/constants/plugin.d.cts +2 -2
  44. package/dist/constants/plugin.d.mts +2 -2
  45. package/dist/context/base-context.cjs +127 -0
  46. package/dist/context/base-context.d.cts +81 -0
  47. package/dist/context/base-context.d.cts.map +1 -0
  48. package/dist/context/base-context.d.mts +81 -0
  49. package/dist/context/base-context.d.mts.map +1 -0
  50. package/dist/context/base-context.mjs +125 -0
  51. package/dist/context/base-context.mjs.map +1 -0
  52. package/dist/context/context.cjs +934 -0
  53. package/dist/context/context.d.cts +369 -0
  54. package/dist/context/context.d.cts.map +1 -0
  55. package/dist/context/context.d.mts +369 -0
  56. package/dist/context/context.d.mts.map +1 -0
  57. package/dist/context/context.mjs +932 -0
  58. package/dist/context/context.mjs.map +1 -0
  59. package/dist/context/environment-context.cjs +219 -0
  60. package/dist/context/environment-context.d.cts +100 -0
  61. package/dist/context/environment-context.d.cts.map +1 -0
  62. package/dist/context/environment-context.d.mts +100 -0
  63. package/dist/context/environment-context.d.mts.map +1 -0
  64. package/dist/context/environment-context.mjs +218 -0
  65. package/dist/context/environment-context.mjs.map +1 -0
  66. package/dist/context/execution-context.cjs +230 -0
  67. package/dist/context/execution-context.d.cts +101 -0
  68. package/dist/context/execution-context.d.cts.map +1 -0
  69. package/dist/context/execution-context.d.mts +101 -0
  70. package/dist/context/execution-context.d.mts.map +1 -0
  71. package/dist/context/execution-context.mjs +228 -0
  72. package/dist/context/execution-context.mjs.map +1 -0
  73. package/dist/context/index.cjs +12 -0
  74. package/dist/context/index.d.cts +6 -0
  75. package/dist/context/index.d.mts +6 -0
  76. package/dist/context/index.mjs +7 -0
  77. package/dist/context/plugin-context.cjs +83 -0
  78. package/dist/context/plugin-context.d.cts +18 -0
  79. package/dist/context/plugin-context.d.cts.map +1 -0
  80. package/dist/context/plugin-context.d.mts +18 -0
  81. package/dist/context/plugin-context.d.mts.map +1 -0
  82. package/dist/context/plugin-context.mjs +82 -0
  83. package/dist/context/plugin-context.mjs.map +1 -0
  84. package/dist/index.cjs +62 -9
  85. package/dist/index.d.cts +20 -9
  86. package/dist/index.d.mts +20 -9
  87. package/dist/index.mjs +17 -5
  88. package/dist/lib/config.cjs +160 -15
  89. package/dist/lib/config.d.cts +92 -6
  90. package/dist/lib/config.d.cts.map +1 -1
  91. package/dist/lib/config.d.mts +92 -6
  92. package/dist/lib/config.d.mts.map +1 -1
  93. package/dist/lib/config.mjs +154 -16
  94. package/dist/lib/config.mjs.map +1 -1
  95. package/dist/lib/context-helpers.cjs +43 -0
  96. package/dist/lib/context-helpers.d.cts +19 -0
  97. package/dist/lib/context-helpers.d.cts.map +1 -0
  98. package/dist/lib/context-helpers.d.mts +19 -0
  99. package/dist/lib/context-helpers.d.mts.map +1 -0
  100. package/dist/lib/context-helpers.mjs +41 -0
  101. package/dist/lib/context-helpers.mjs.map +1 -0
  102. package/dist/lib/entry.cjs +5 -5
  103. package/dist/lib/entry.d.cts.map +1 -1
  104. package/dist/lib/entry.d.mts.map +1 -1
  105. package/dist/lib/entry.mjs +5 -5
  106. package/dist/lib/entry.mjs.map +1 -1
  107. package/dist/lib/environment.cjs +72 -0
  108. package/dist/lib/environment.d.cts +12 -0
  109. package/dist/lib/environment.d.cts.map +1 -0
  110. package/dist/lib/environment.d.mts +12 -0
  111. package/dist/lib/environment.d.mts.map +1 -0
  112. package/dist/lib/environment.mjs +67 -0
  113. package/dist/lib/environment.mjs.map +1 -0
  114. package/dist/lib/events.cjs +43 -0
  115. package/dist/lib/events.d.cts +10 -0
  116. package/dist/lib/events.d.cts.map +1 -0
  117. package/dist/lib/events.d.mts +10 -0
  118. package/dist/lib/events.d.mts.map +1 -0
  119. package/dist/lib/events.mjs +42 -0
  120. package/dist/lib/events.mjs.map +1 -0
  121. package/dist/lib/generate-types.cjs +371 -0
  122. package/dist/lib/generate-types.d.cts +67 -0
  123. package/dist/lib/generate-types.d.cts.map +1 -0
  124. package/dist/lib/generate-types.d.mts +67 -0
  125. package/dist/lib/generate-types.d.mts.map +1 -0
  126. package/dist/lib/generate-types.mjs +368 -0
  127. package/dist/lib/generate-types.mjs.map +1 -0
  128. package/dist/lib/hooks.cjs +152 -0
  129. package/dist/lib/hooks.d.cts +28 -0
  130. package/dist/lib/hooks.d.cts.map +1 -0
  131. package/dist/lib/hooks.d.mts +28 -0
  132. package/dist/lib/hooks.d.mts.map +1 -0
  133. package/dist/lib/hooks.mjs +147 -0
  134. package/dist/lib/hooks.mjs.map +1 -0
  135. package/dist/lib/index.cjs +64 -9
  136. package/dist/lib/index.d.cts +15 -3
  137. package/dist/lib/index.d.mts +15 -3
  138. package/dist/lib/index.mjs +19 -5
  139. package/dist/lib/install-dependencies.cjs +25 -0
  140. package/dist/lib/install-dependencies.d.cts +12 -0
  141. package/dist/lib/install-dependencies.d.cts.map +1 -0
  142. package/dist/lib/install-dependencies.d.mts +12 -0
  143. package/dist/lib/install-dependencies.d.mts.map +1 -0
  144. package/dist/lib/install-dependencies.mjs +24 -0
  145. package/dist/lib/install-dependencies.mjs.map +1 -0
  146. package/dist/lib/meta.cjs +57 -0
  147. package/dist/lib/meta.d.cts +34 -0
  148. package/dist/lib/meta.d.cts.map +1 -0
  149. package/dist/lib/meta.d.mts +34 -0
  150. package/dist/lib/meta.d.mts.map +1 -0
  151. package/dist/lib/meta.mjs +54 -0
  152. package/dist/lib/meta.mjs.map +1 -0
  153. package/dist/lib/plugins.cjs +150 -0
  154. package/dist/lib/plugins.d.cts +40 -0
  155. package/dist/lib/plugins.d.cts.map +1 -0
  156. package/dist/lib/plugins.d.mts +40 -0
  157. package/dist/lib/plugins.d.mts.map +1 -0
  158. package/dist/lib/plugins.mjs +146 -0
  159. package/dist/lib/plugins.mjs.map +1 -0
  160. package/dist/lib/resolver.cjs +35 -0
  161. package/dist/lib/resolver.d.cts +21 -0
  162. package/dist/lib/resolver.d.cts.map +1 -0
  163. package/dist/lib/resolver.d.mts +21 -0
  164. package/dist/lib/resolver.d.mts.map +1 -0
  165. package/dist/lib/resolver.mjs +33 -0
  166. package/dist/lib/resolver.mjs.map +1 -0
  167. package/dist/lib/schemas.cjs +9 -0
  168. package/dist/lib/schemas.d.cts +2 -0
  169. package/dist/lib/schemas.d.mts +2 -0
  170. package/dist/lib/schemas.mjs +3 -0
  171. package/dist/lib/streaming-channel.cjs +260 -0
  172. package/dist/lib/streaming-channel.d.cts +133 -0
  173. package/dist/lib/streaming-channel.d.cts.map +1 -0
  174. package/dist/lib/streaming-channel.d.mts +133 -0
  175. package/dist/lib/streaming-channel.d.mts.map +1 -0
  176. package/dist/lib/streaming-channel.mjs +258 -0
  177. package/dist/lib/streaming-channel.mjs.map +1 -0
  178. package/dist/lib/typescript/index.cjs +16 -0
  179. package/dist/lib/typescript/index.d.cts +3 -0
  180. package/dist/lib/typescript/index.d.mts +3 -0
  181. package/dist/lib/typescript/index.mjs +4 -0
  182. package/dist/lib/typescript/ts-morph.cjs +105 -0
  183. package/dist/lib/typescript/ts-morph.d.cts +38 -0
  184. package/dist/lib/typescript/ts-morph.d.cts.map +1 -0
  185. package/dist/lib/typescript/ts-morph.d.mts +38 -0
  186. package/dist/lib/typescript/ts-morph.d.mts.map +1 -0
  187. package/dist/lib/typescript/ts-morph.mjs +102 -0
  188. package/dist/lib/typescript/ts-morph.mjs.map +1 -0
  189. package/dist/lib/typescript/tsconfig.cjs +253 -0
  190. package/dist/lib/typescript/tsconfig.d.cts +77 -0
  191. package/dist/lib/typescript/tsconfig.d.cts.map +1 -0
  192. package/dist/lib/typescript/tsconfig.d.mts +77 -0
  193. package/dist/lib/typescript/tsconfig.d.mts.map +1 -0
  194. package/dist/lib/typescript/tsconfig.mjs +240 -0
  195. package/dist/lib/typescript/tsconfig.mjs.map +1 -0
  196. package/dist/lib/unplugin/helpers.cjs +2 -2
  197. package/dist/lib/unplugin/module-resolution.cjs +18 -18
  198. package/dist/lib/unplugin/module-resolution.mjs +18 -18
  199. package/dist/lib/unplugin/module-resolution.mjs.map +1 -1
  200. package/dist/lib/unplugin/plugin.cjs +55 -62
  201. package/dist/lib/unplugin/plugin.d.cts +10 -11
  202. package/dist/lib/unplugin/plugin.d.cts.map +1 -1
  203. package/dist/lib/unplugin/plugin.d.mts +10 -11
  204. package/dist/lib/unplugin/plugin.d.mts.map +1 -1
  205. package/dist/lib/unplugin/plugin.mjs +55 -62
  206. package/dist/lib/unplugin/plugin.mjs.map +1 -1
  207. package/dist/lib/utilities/file-header.cjs +2 -2
  208. package/dist/lib/utilities/file-header.mjs +2 -2
  209. package/dist/lib/utilities/file-header.mjs.map +1 -1
  210. package/dist/lib/utilities/format.cjs +1 -1
  211. package/dist/lib/utilities/format.mjs +1 -1
  212. package/dist/lib/utilities/index.cjs +2 -2
  213. package/dist/lib/utilities/index.mjs +2 -2
  214. package/dist/lib/utilities/write-file.cjs +1 -2
  215. package/dist/lib/utilities/write-file.d.cts +1 -1
  216. package/dist/lib/utilities/write-file.d.cts.map +1 -1
  217. package/dist/lib/utilities/write-file.d.mts +1 -1
  218. package/dist/lib/utilities/write-file.d.mts.map +1 -1
  219. package/dist/lib/utilities/write-file.mjs +1 -2
  220. package/dist/lib/utilities/write-file.mjs.map +1 -1
  221. package/dist/lib/vfs.cjs +1104 -0
  222. package/dist/lib/vfs.d.cts +321 -0
  223. package/dist/lib/vfs.d.cts.map +1 -0
  224. package/dist/lib/vfs.d.mts +321 -0
  225. package/dist/lib/vfs.d.mts.map +1 -0
  226. package/dist/lib/vfs.mjs +1102 -0
  227. package/dist/lib/vfs.mjs.map +1 -0
  228. package/dist/plugin-base.cjs +1 -1
  229. package/dist/plugin-base.mjs +1 -1
  230. package/dist/plugin-base.mjs.map +1 -1
  231. package/dist/plugin-utils/build-helpers.cjs +2 -2
  232. package/dist/plugin-utils/build-helpers.mjs +2 -2
  233. package/dist/plugin-utils/build-helpers.mjs.map +1 -1
  234. package/dist/plugin-utils/context-helpers.cjs +22 -12
  235. package/dist/plugin-utils/context-helpers.d.cts +9 -1
  236. package/dist/plugin-utils/context-helpers.d.cts.map +1 -1
  237. package/dist/plugin-utils/context-helpers.d.mts +9 -1
  238. package/dist/plugin-utils/context-helpers.d.mts.map +1 -1
  239. package/dist/plugin-utils/context-helpers.mjs +22 -13
  240. package/dist/plugin-utils/context-helpers.mjs.map +1 -1
  241. package/dist/plugin-utils/filter.cjs +13 -5
  242. package/dist/plugin-utils/filter.d.cts +2 -1
  243. package/dist/plugin-utils/filter.d.cts.map +1 -1
  244. package/dist/plugin-utils/filter.d.mts +2 -1
  245. package/dist/plugin-utils/filter.d.mts.map +1 -1
  246. package/dist/plugin-utils/filter.mjs +13 -6
  247. package/dist/plugin-utils/filter.mjs.map +1 -1
  248. package/dist/plugin-utils/format.cjs +44 -0
  249. package/dist/plugin-utils/format.d.cts +11 -0
  250. package/dist/plugin-utils/format.d.cts.map +1 -0
  251. package/dist/plugin-utils/format.d.mts +11 -0
  252. package/dist/plugin-utils/format.d.mts.map +1 -0
  253. package/dist/plugin-utils/format.mjs +43 -0
  254. package/dist/plugin-utils/format.mjs.map +1 -0
  255. package/dist/plugin-utils/helpers.cjs +6 -6
  256. package/dist/plugin-utils/helpers.d.cts +15 -15
  257. package/dist/plugin-utils/helpers.d.cts.map +1 -1
  258. package/dist/plugin-utils/helpers.d.mts +15 -15
  259. package/dist/plugin-utils/helpers.d.mts.map +1 -1
  260. package/dist/plugin-utils/helpers.mjs +1 -1
  261. package/dist/plugin-utils/helpers.mjs.map +1 -1
  262. package/dist/plugin-utils/index.cjs +34 -4
  263. package/dist/plugin-utils/index.d.cts +7 -4
  264. package/dist/plugin-utils/index.d.mts +7 -4
  265. package/dist/plugin-utils/index.mjs +9 -6
  266. package/dist/plugin-utils/install.cjs +47 -0
  267. package/dist/plugin-utils/install.d.cts +23 -0
  268. package/dist/plugin-utils/install.d.cts.map +1 -0
  269. package/dist/plugin-utils/install.d.mts +23 -0
  270. package/dist/plugin-utils/install.d.mts.map +1 -0
  271. package/dist/plugin-utils/install.mjs +45 -0
  272. package/dist/plugin-utils/install.mjs.map +1 -0
  273. package/dist/plugin-utils/logging.cjs +588 -1
  274. package/dist/plugin-utils/logging.d.cts +93 -1
  275. package/dist/plugin-utils/logging.d.cts.map +1 -1
  276. package/dist/plugin-utils/logging.d.mts +93 -1
  277. package/dist/plugin-utils/logging.d.mts.map +1 -1
  278. package/dist/plugin-utils/logging.mjs +572 -1
  279. package/dist/plugin-utils/logging.mjs.map +1 -1
  280. package/dist/plugin-utils/merge.cjs +1 -1
  281. package/dist/plugin-utils/merge.mjs +1 -1
  282. package/dist/plugin-utils/modules.cjs +1 -1
  283. package/dist/plugin-utils/modules.mjs +1 -1
  284. package/dist/plugin-utils/modules.mjs.map +1 -1
  285. package/dist/plugin-utils/paths.cjs +6 -2
  286. package/dist/plugin-utils/paths.mjs +6 -2
  287. package/dist/plugin-utils/paths.mjs.map +1 -1
  288. package/dist/plugin-utils/virtual.cjs +80 -0
  289. package/dist/plugin-utils/virtual.d.cts +69 -0
  290. package/dist/plugin-utils/virtual.d.cts.map +1 -0
  291. package/dist/plugin-utils/virtual.d.mts +69 -0
  292. package/dist/plugin-utils/virtual.d.mts.map +1 -0
  293. package/dist/plugin-utils/virtual.mjs +73 -0
  294. package/dist/plugin-utils/virtual.mjs.map +1 -0
  295. package/dist/schemas/fs.cjs +232 -0
  296. package/dist/schemas/fs.d.cts +127 -0
  297. package/dist/schemas/fs.d.cts.map +1 -0
  298. package/dist/schemas/fs.d.mts +127 -0
  299. package/dist/schemas/fs.d.mts.map +1 -0
  300. package/dist/schemas/fs.mjs +226 -0
  301. package/dist/schemas/fs.mjs.map +1 -0
  302. package/dist/storage/base.cjs +216 -0
  303. package/dist/storage/base.d.cts +201 -0
  304. package/dist/storage/base.d.cts.map +1 -0
  305. package/dist/storage/base.d.mts +201 -0
  306. package/dist/storage/base.d.mts.map +1 -0
  307. package/dist/storage/base.mjs +215 -0
  308. package/dist/storage/base.mjs.map +1 -0
  309. package/dist/storage/file-system.cjs +180 -0
  310. package/dist/storage/file-system.d.cts +129 -0
  311. package/dist/storage/file-system.d.cts.map +1 -0
  312. package/dist/storage/file-system.d.mts +129 -0
  313. package/dist/storage/file-system.d.mts.map +1 -0
  314. package/dist/storage/file-system.mjs +179 -0
  315. package/dist/storage/file-system.mjs.map +1 -0
  316. package/dist/storage/helpers.cjs +37 -0
  317. package/dist/storage/helpers.d.cts +25 -0
  318. package/dist/storage/helpers.d.cts.map +1 -0
  319. package/dist/storage/helpers.d.mts +25 -0
  320. package/dist/storage/helpers.d.mts.map +1 -0
  321. package/dist/storage/helpers.mjs +34 -0
  322. package/dist/storage/helpers.mjs.map +1 -0
  323. package/dist/storage/index.cjs +12 -0
  324. package/dist/storage/index.d.cts +5 -0
  325. package/dist/storage/index.d.mts +5 -0
  326. package/dist/storage/index.mjs +6 -0
  327. package/dist/storage/virtual.cjs +98 -0
  328. package/dist/storage/virtual.d.cts +80 -0
  329. package/dist/storage/virtual.d.cts.map +1 -0
  330. package/dist/storage/virtual.d.mts +80 -0
  331. package/dist/storage/virtual.d.mts.map +1 -0
  332. package/dist/storage/virtual.mjs +97 -0
  333. package/dist/storage/virtual.mjs.map +1 -0
  334. package/dist/types/api.d.cts +18 -152
  335. package/dist/types/api.d.cts.map +1 -1
  336. package/dist/types/api.d.mts +18 -152
  337. package/dist/types/api.d.mts.map +1 -1
  338. package/dist/types/config.d.cts +194 -135
  339. package/dist/types/config.d.cts.map +1 -1
  340. package/dist/types/config.d.mts +195 -136
  341. package/dist/types/config.d.mts.map +1 -1
  342. package/dist/types/context.d.cts +152 -128
  343. package/dist/types/context.d.cts.map +1 -1
  344. package/dist/types/context.d.mts +155 -131
  345. package/dist/types/context.d.mts.map +1 -1
  346. package/dist/types/fs.d.mts +1 -1
  347. package/dist/types/index.d.cts +5 -6
  348. package/dist/types/index.d.mts +5 -6
  349. package/dist/types/logging.d.cts +161 -0
  350. package/dist/types/logging.d.cts.map +1 -0
  351. package/dist/types/logging.d.mts +161 -0
  352. package/dist/types/logging.d.mts.map +1 -0
  353. package/dist/types/plugin.d.cts +6 -9
  354. package/dist/types/plugin.d.cts.map +1 -1
  355. package/dist/types/plugin.d.mts +6 -9
  356. package/dist/types/plugin.d.mts.map +1 -1
  357. package/dist/types/tsconfig.d.mts +1 -1
  358. package/dist/types/unplugin.d.cts +5 -26
  359. package/dist/types/unplugin.d.cts.map +1 -1
  360. package/dist/types/unplugin.d.mts +5 -26
  361. package/dist/types/unplugin.d.mts.map +1 -1
  362. package/package.json +259 -457
  363. package/schemas/fs.capnp +42 -0
  364. package/dist/constants/virtual-modules.cjs +0 -8
  365. package/dist/constants/virtual-modules.d.cts +0 -6
  366. package/dist/constants/virtual-modules.d.cts.map +0 -1
  367. package/dist/constants/virtual-modules.d.mts +0 -6
  368. package/dist/constants/virtual-modules.d.mts.map +0 -1
  369. package/dist/constants/virtual-modules.mjs +0 -7
  370. package/dist/constants/virtual-modules.mjs.map +0 -1
  371. package/dist/lib/logger.cjs +0 -99
  372. package/dist/lib/logger.d.cts +0 -53
  373. package/dist/lib/logger.d.cts.map +0 -1
  374. package/dist/lib/logger.d.mts +0 -53
  375. package/dist/lib/logger.d.mts.map +0 -1
  376. package/dist/lib/logger.mjs +0 -93
  377. package/dist/lib/logger.mjs.map +0 -1
  378. package/dist/types/_internal.cjs +0 -0
  379. package/dist/types/_internal.d.cts +0 -106
  380. package/dist/types/_internal.d.cts.map +0 -1
  381. package/dist/types/_internal.d.mts +0 -106
  382. package/dist/types/_internal.d.mts.map +0 -1
  383. package/dist/types/_internal.mjs +0 -1
  384. package/dist/types/commands.d.cts +0 -16
  385. package/dist/types/commands.d.cts.map +0 -1
  386. package/dist/types/commands.d.mts +0 -16
  387. package/dist/types/commands.d.mts.map +0 -1
  388. package/dist/types/utils.d.cts +0 -9
  389. package/dist/types/utils.d.cts.map +0 -1
  390. package/dist/types/utils.d.mts +0 -9
  391. package/dist/types/utils.d.mts.map +0 -1
@@ -0,0 +1,1104 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
3
+ const require_lib_utilities_format = require('./utilities/format.cjs');
4
+ const require_plugin_utils_paths = require('../plugin-utils/paths.cjs');
5
+ require('../plugin-utils/index.cjs');
6
+ const require_constants_extensions = require('../constants/extensions.cjs');
7
+ const require_fs = require('../schemas/fs.cjs');
8
+ const require_storage_file_system = require('../storage/file-system.cjs');
9
+ const require_storage_virtual = require('../storage/virtual.cjs');
10
+ let _stryke_fs_exists = require("@stryke/fs/exists");
11
+ let _stryke_path_append = require("@stryke/path/append");
12
+ let _stryke_path_file_path_fns = require("@stryke/path/file-path-fns");
13
+ let _stryke_path_replace = require("@stryke/path/replace");
14
+ let _stryke_type_checks_is_set_object = require("@stryke/type-checks/is-set-object");
15
+ let _stryke_type_checks_is_set_string = require("@stryke/type-checks/is-set-string");
16
+ let _stryke_type_checks_is_string = require("@stryke/type-checks/is-string");
17
+ let _stryke_convert_to_array = require("@stryke/convert/to-array");
18
+ let _stryke_type_checks_is_set = require("@stryke/type-checks/is-set");
19
+ let _stryke_helpers_get_unique = require("@stryke/helpers/get-unique");
20
+ let _stryke_type_checks_is_regexp = require("@stryke/type-checks/is-regexp");
21
+ let _stryke_path_join = require("@stryke/path/join");
22
+ let _stryke_path_is_type = require("@stryke/path/is-type");
23
+ let _stryke_path_is_parent_path = require("@stryke/path/is-parent-path");
24
+ let _stryke_hash = require("@stryke/hash");
25
+ let _stryke_fs_resolve = require("@stryke/fs/resolve");
26
+ let _stryke_string_format_pretty_bytes = require("@stryke/string-format/pretty-bytes");
27
+ let _stryke_capnp = require("@stryke/capnp");
28
+ _stryke_capnp = require_runtime.__toESM(_stryke_capnp, 1);
29
+ let _stryke_fs_buffer = require("@stryke/fs/buffer");
30
+ let _stryke_path_correct_path = require("@stryke/path/correct-path");
31
+ let _stryke_path_glob_to_regex = require("@stryke/path/glob-to-regex");
32
+ let _stryke_path_slash = require("@stryke/path/slash");
33
+ let bundle_require = require("bundle-require");
34
+ let flat_cache = require("flat-cache");
35
+ let node_buffer = require("node:buffer");
36
+ let node_url = require("node:url");
37
+
38
+ //#region src/lib/vfs.ts
39
+ function toFilePath(path) {
40
+ return (0, _stryke_path_correct_path.correctPath)((0, _stryke_path_slash.slash)(path?.toString() || ".").replace(/^file:\/\//, ""));
41
+ }
42
+ /**
43
+ * Checks if a given file id is valid based on the specified prefix.
44
+ *
45
+ * @param id - The file ID to check.
46
+ * @param prefix - The prefix to use for built-in files. Default is "powerlines".
47
+ * @returns `true` if the file ID is valid, otherwise `false`.
48
+ */
49
+ function isValidId(id, prefix = "powerlines") {
50
+ return id.replace(/^\\0/, "").startsWith(`${prefix.replace(/:$/, "")}`);
51
+ }
52
+ /**
53
+ * Formats a file id by removing the file extension and prepended runtime prefix.
54
+ *
55
+ * @param id - The file ID to format.
56
+ * @param prefix - The prefix to use for built-in files. Default is "powerlines".
57
+ * @returns The formatted file ID.
58
+ */
59
+ function normalizeId(id, prefix = "powerlines") {
60
+ return (0, _stryke_path_replace.replaceExtension)(toFilePath(id)).replace(/^\\0/, "").replace(/^powerlines:/, "").replace(new RegExp(`^${prefix.replace(/:$/, "")}:`), "");
61
+ }
62
+ /**
63
+ * Normalizes a given path by resolving it against the project root, workspace root, and built-ins path.
64
+ *
65
+ * @param path - The path to normalize.
66
+ * @param builtinsPath - The path to built-in files.
67
+ * @param prefix - The prefix to use for built-in files. Default is "powerlines".
68
+ * @returns The normalized path.
69
+ */
70
+ function normalizePath(path, builtinsPath, prefix = "powerlines") {
71
+ if (!(0, _stryke_type_checks_is_set_string.isSetString)(path)) {
72
+ if (!(0, _stryke_type_checks_is_string.isString)(path)) throw new Error("Path type must be a string or a file descriptor");
73
+ throw new Error("Path cannot be empty");
74
+ }
75
+ return (0, _stryke_path_is_type.isAbsolutePath)(path) ? path : isValidId(toFilePath(path), prefix) ? normalizeId(toFilePath(path), prefix).replace(new RegExp(`^${prefix.replace(/:$/, "")}:`), builtinsPath) : toFilePath(path);
76
+ }
77
+ /**
78
+ * Normalizes glob patterns by resolving them against the workspace root.
79
+ *
80
+ * @param workspaceRoot - The root directory of the workspace.
81
+ * @param patterns - The glob patterns to normalize.
82
+ * @returns An array of normalized glob patterns.
83
+ */
84
+ function normalizeGlobPatterns(workspaceRoot, patterns) {
85
+ return (0, _stryke_helpers_get_unique.getUnique)((0, _stryke_convert_to_array.toArray)(patterns).map((pattern) => {
86
+ if ((0, _stryke_type_checks_is_set_object.isSetObject)(pattern) && ((0, _stryke_type_checks_is_set_string.isSetString)(pattern.input) || (0, _stryke_type_checks_is_set_string.isSetString)(pattern.glob))) return (0, _stryke_path_join.joinPaths)(pattern.input || workspaceRoot, pattern.glob || "**/*");
87
+ else if (!(0, _stryke_type_checks_is_set_string.isSetString)(pattern)) return;
88
+ return pattern;
89
+ }).filter(_stryke_type_checks_is_set_string.isSetString));
90
+ }
91
+ /**
92
+ * Represents a virtual file system (VFS) that stores files and their associated metadata in virtual memory.
93
+ *
94
+ * @remarks
95
+ * This class provides methods to manage virtual files, check their existence, retrieve their content, and manipulate the virtual file system. It allows for efficient file management and retrieval without relying on the actual file system.
96
+ */
97
+ var VirtualFileSystem = class VirtualFileSystem {
98
+ /**
99
+ * A map of virtual file IDs to their associated metadata.
100
+ */
101
+ #metadata;
102
+ /**
103
+ * A map of underlying file paths to their virtual file IDs.
104
+ */
105
+ #ids;
106
+ /**
107
+ * A map of virtual file IDs to their underlying file paths.
108
+ */
109
+ #paths;
110
+ /**
111
+ * The unified volume that combines the virtual file system with the real file system.
112
+ *
113
+ * @remarks
114
+ * This volume allows for seamless access to both virtual and real files.
115
+ */
116
+ #storage;
117
+ /**
118
+ * A cache for module resolution results.
119
+ */
120
+ #resolverCache;
121
+ /**
122
+ * Indicator specifying if the virtual file system (VFS) is disposed
123
+ */
124
+ #isDisposed = false;
125
+ /**
126
+ * The context of the virtual file system.
127
+ */
128
+ #context;
129
+ /**
130
+ * The file system's logger client utility.
131
+ */
132
+ #logger;
133
+ /**
134
+ * Normalizes a given module id by resolving it against the built-ins path.
135
+ *
136
+ * @param id - The module id to normalize.
137
+ * @returns The normalized module id.
138
+ */
139
+ #normalizeId(id) {
140
+ let normalized = id;
141
+ if ((0, _stryke_path_is_parent_path.isParentPath)(normalized, this.#context.builtinsPath)) normalized = (0, _stryke_path_replace.replacePath)(normalized, this.#context.builtinsPath);
142
+ return normalizeId(normalized, this.#context.config.framework?.name ?? "powerlines");
143
+ }
144
+ /**
145
+ * Normalizes a given path by resolving it against the project root, workspace root, and built-ins path.
146
+ *
147
+ * @param path - The path to normalize.
148
+ * @returns The normalized path.
149
+ */
150
+ #normalizePath(path) {
151
+ if (!(0, _stryke_type_checks_is_set_string.isSetString)(path)) {
152
+ if (!(0, _stryke_type_checks_is_string.isString)(path)) throw new Error("Path type must be a string or a file descriptor");
153
+ throw new Error("Path cannot be empty");
154
+ }
155
+ return normalizePath(path.includes("{") || path.includes("}") ? require_plugin_utils_paths.replacePathTokens(this.#context, path) : path, this.#context.builtinsPath, this.#context.config.framework?.name ?? "powerlines");
156
+ }
157
+ /**
158
+ * Gets the storage adapter and relative key for a given key.
159
+ *
160
+ * @remarks
161
+ * The `key` can be either a path or a storage adapter name.
162
+ *
163
+ * @param key - The key to get the storage adapter for.
164
+ * @returns The storage adapter and relative key for the given key.
165
+ */
166
+ #getStorage(key, preset) {
167
+ const path = this.resolveSync(this.#normalizePath(key)) || key;
168
+ for (const base of Object.keys(this.#storage).filter(Boolean).sort().reverse()) if ((path === base || (0, _stryke_path_is_parent_path.isParentPath)(path, base)) && (!preset || this.#storage[base]?.preset?.toLowerCase() === preset.toLowerCase())) return {
169
+ base,
170
+ relativeKey: (0, _stryke_path_replace.replacePath)(path, base),
171
+ adapter: this.#storage[base]
172
+ };
173
+ if (!preset || this.#storage[""]?.preset?.toLowerCase() === preset.toLowerCase()) return {
174
+ base: "",
175
+ relativeKey: path,
176
+ adapter: this.#storage[""]
177
+ };
178
+ this.#storage[path] = preset === "virtual" ? new require_storage_virtual.VirtualStorageAdapter(this.#context, { base: path }) : new require_storage_file_system.FileSystemStorageAdapter(this.#context, { base: path });
179
+ return {
180
+ base: path,
181
+ relativeKey: "",
182
+ adapter: this.#storage[path]
183
+ };
184
+ }
185
+ /**
186
+ * Gets all storage adapters that match a given base key.
187
+ *
188
+ * @param base - The base key to match storage adapters against.
189
+ * @param includeParent - Whether to include parent storage adapters.
190
+ * @returns An array of storage adapters that match the given base key.
191
+ */
192
+ #getStorages(base = "", includeParent = false) {
193
+ const baseKey = this.resolveSync(base) || base;
194
+ return Object.keys(this.#storage).sort().reverse().filter((key) => (0, _stryke_path_is_parent_path.isParentPath)(key, baseKey) || includeParent && (0, _stryke_path_is_parent_path.isParentPath)(baseKey, key) || baseKey.includes("*") && ((0, _stryke_path_is_parent_path.isParentPath)((0, _stryke_path_correct_path.stripStars)(baseKey), key) || (0, _stryke_path_glob_to_regex.globToRegex)((0, _stryke_path_replace.replaceExtension)(baseKey)).test(key))).map((key) => ({
195
+ relativeBase: baseKey.length > key.length ? baseKey.slice(key.length) : void 0,
196
+ base: key,
197
+ adapter: this.#storage[key]
198
+ }));
199
+ }
200
+ /**
201
+ * A helper function to resolve modules in the virtual file system (VFS).
202
+ *
203
+ * @remarks
204
+ * This function can be used to resolve modules relative to the project root directory.
205
+ *
206
+ * @example
207
+ * ```ts
208
+ * const resolved = await context.resolvePath("some-module", "/path/to/importer");
209
+ * ```
210
+ *
211
+ * @param id - The module to resolve.
212
+ * @param importer - An optional path to the importer module.
213
+ * @param options - Additional resolution options.
214
+ * @returns A promise that resolves to the resolved module path.
215
+ */
216
+ #innerResolve = async (id, importer, options = {}) => {
217
+ let path = id;
218
+ if (path.includes("{") || path.includes("}")) path = require_plugin_utils_paths.replacePathTokens(this.#context, path);
219
+ if (options.skipAlias !== true) path = this.resolveAlias(path);
220
+ if ((0, _stryke_path_is_type.isAbsolutePath)(path) && (!options.isFile || !await this.isDirectory(path))) return path;
221
+ const resolverCacheKey = (0, _stryke_hash.murmurhash)({
222
+ path: this.#normalizeId(path),
223
+ importer,
224
+ options
225
+ });
226
+ let result;
227
+ if (!this.#context.config.skipCache) {
228
+ result = this.resolverCache.get(resolverCacheKey);
229
+ if (result) return result;
230
+ }
231
+ result = this.paths[this.#normalizeId(path)];
232
+ if (!(0, _stryke_type_checks_is_set_string.isSetString)(result)) {
233
+ const paths = options.paths ?? [];
234
+ if (importer && !paths.includes(importer)) paths.push(importer);
235
+ if (!importer) {
236
+ paths.push(this.#context.config.cwd);
237
+ paths.push((0, _stryke_path_append.appendPath)(this.#context.config.root, this.#context.config.cwd));
238
+ paths.push((0, _stryke_path_append.appendPath)((0, _stryke_path_join.joinPaths)(this.#context.config.root, "src"), this.#context.config.cwd));
239
+ }
240
+ paths.push(...Object.keys(this.#context.tsconfig?.options?.paths ?? {}).filter((tsconfigPath) => path.startsWith(tsconfigPath.replace(/\*$/, ""))).map((tsconfigPath) => this.#context.tsconfig?.options?.paths?.[tsconfigPath]).flat().filter(Boolean).map((tsconfigPath) => (0, _stryke_path_append.appendPath)(tsconfigPath, this.#context.config.cwd)));
241
+ for (const combination of (0, _stryke_fs_resolve.getResolutionCombinations)(path, { paths: (0, _stryke_helpers_get_unique.getUnique)(paths) })) {
242
+ const { relativeKey, adapter } = this.#getStorage(combination);
243
+ if (await adapter.exists(relativeKey)) {
244
+ result = combination;
245
+ break;
246
+ }
247
+ }
248
+ if (!(0, _stryke_type_checks_is_set_string.isSetString)(result)) try {
249
+ result = await (0, _stryke_fs_resolve.resolve)(path, {
250
+ ...options,
251
+ paths
252
+ });
253
+ } catch {}
254
+ }
255
+ if ((0, _stryke_type_checks_is_set_string.isSetString)(result)) {
256
+ if (!this.#context.config.skipCache) this.resolverCache.set(this.#normalizeId(path), result);
257
+ return result;
258
+ }
259
+ };
260
+ /**
261
+ * A synchronous helper function to resolve modules using the Jiti resolver
262
+ *
263
+ * @remarks
264
+ * This function can be used to resolve modules relative to the project root directory.
265
+ *
266
+ * @example
267
+ * ```ts
268
+ * const resolvedPath = context.resolveSync("some-module", "/path/to/importer");
269
+ * ```
270
+ *
271
+ * @param id - The module to resolve.
272
+ * @param importer - An optional path to the importer module.
273
+ * @param options - Additional resolution options.
274
+ * @returns The resolved module path.
275
+ */
276
+ #innerResolveSync = (id, importer, options = {}) => {
277
+ let path = id;
278
+ if (path.includes("{") || path.includes("}")) path = require_plugin_utils_paths.replacePathTokens(this.#context, path);
279
+ if (options.skipAlias !== true) path = this.resolveAlias(path);
280
+ if ((0, _stryke_path_is_type.isAbsolutePath)(path) && (!options.isFile || !this.isDirectorySync(path))) return path;
281
+ let result;
282
+ if (!this.#context.config.skipCache) {
283
+ result = this.resolverCache.get(this.#normalizeId(path));
284
+ if ((0, _stryke_type_checks_is_set_string.isSetString)(result)) return result;
285
+ }
286
+ result = this.paths[this.#normalizeId(path)];
287
+ if (!(0, _stryke_type_checks_is_set_string.isSetString)(result)) {
288
+ const paths = options.paths ?? [];
289
+ if (importer && !paths.includes(importer)) paths.push(importer);
290
+ if (!importer) {
291
+ paths.push(this.#context.config.cwd);
292
+ paths.push((0, _stryke_path_append.appendPath)(this.#context.config.root, this.#context.config.cwd));
293
+ paths.push((0, _stryke_path_append.appendPath)((0, _stryke_path_join.joinPaths)(this.#context.config.root, "src"), this.#context.config.cwd));
294
+ }
295
+ paths.push(...Object.keys(this.#context.tsconfig?.options?.paths ?? {}).filter((tsconfigPath) => path.startsWith(tsconfigPath.replace(/\*$/, ""))).map((tsconfigPath) => this.#context.tsconfig?.options?.paths?.[tsconfigPath]).flat().filter(Boolean).map((tsconfigPath) => (0, _stryke_path_append.appendPath)(tsconfigPath, this.#context.config.cwd)));
296
+ for (const combination of (0, _stryke_fs_resolve.getResolutionCombinations)(path, { paths })) {
297
+ const { relativeKey, adapter } = this.#getStorage(combination);
298
+ if (adapter.existsSync(relativeKey)) {
299
+ result = combination;
300
+ break;
301
+ }
302
+ }
303
+ if (!(0, _stryke_type_checks_is_set_string.isSetString)(result)) try {
304
+ result = (0, _stryke_fs_resolve.resolveSync)(path, {
305
+ ...options,
306
+ paths
307
+ });
308
+ } catch {}
309
+ }
310
+ if ((0, _stryke_type_checks_is_set_string.isSetString)(result)) {
311
+ if (!this.#context.config.skipCache) this.resolverCache.set(this.#normalizeId(path), result);
312
+ return result;
313
+ }
314
+ };
315
+ /**
316
+ * Creates a virtual file system (VFS) that is backed up to a Cap'n Proto message buffer.
317
+ *
318
+ * @param context - The context of the virtual file system, typically containing options and logging functions.
319
+ * @returns A promise that resolves to a new virtual file system instance.
320
+ */
321
+ static async create(context) {
322
+ context.debug("Starting virtual file system (VFS) initialization processes...");
323
+ let result;
324
+ if (!context.config.skipCache && (0, _stryke_fs_exists.existsSync)((0, _stryke_path_join.joinPaths)(context.dataPath, "fs.bin"))) {
325
+ const buffer = await (0, _stryke_fs_buffer.readFileBuffer)((0, _stryke_path_join.joinPaths)(context.dataPath, "fs.bin"));
326
+ const fs = new _stryke_capnp.Message(buffer, false).getRoot(require_fs.FileSystem);
327
+ result = new VirtualFileSystem(context, fs);
328
+ if (fs._hasStorage() && fs.storage.length > 0) await Promise.all(fs.storage.values().map(async (file) => {
329
+ if (file.path && file.code) {
330
+ let id;
331
+ if (fs._hasIds()) id = fs.ids.find((fileId) => fileId.path === file.path);
332
+ let metadata;
333
+ if (fs._hasMetadata()) metadata = fs.metadata.find((meta) => meta.id === result.#normalizeId(id?.id ?? file.path));
334
+ await result.write(file.path, file.code, { meta: {
335
+ id: result.#normalizeId(id?.id ?? metadata?.id ?? file.path),
336
+ type: metadata?.type || "normal",
337
+ properties: metadata?._hasProperties() ? metadata?.properties.values().reduce((ret, kvp) => {
338
+ ret[kvp.key] = kvp.value;
339
+ return ret;
340
+ }, {}) : void 0,
341
+ timestamp: metadata?.timestamp
342
+ } });
343
+ }
344
+ }));
345
+ } else result = new VirtualFileSystem(context, new _stryke_capnp.Message().initRoot(require_fs.FileSystem));
346
+ result.#logger.debug("Successfully completed virtual file system (VFS) initialization.");
347
+ return result;
348
+ }
349
+ /**
350
+ * Synchronously creates a virtual file system (VFS) that is backed up to a Cap'n Proto message buffer.
351
+ *
352
+ * @param context - The context of the virtual file system, typically containing options and logging functions.
353
+ * @returns A new virtual file system instance.
354
+ */
355
+ static createSync(context) {
356
+ context.debug("Starting virtual file system (VFS) initialization processes...");
357
+ let result;
358
+ if (!context.config.skipCache && (0, _stryke_fs_exists.existsSync)((0, _stryke_path_join.joinPaths)(context.dataPath, "fs.bin"))) {
359
+ const buffer = (0, _stryke_fs_buffer.readFileBufferSync)((0, _stryke_path_join.joinPaths)(context.dataPath, "fs.bin"));
360
+ const fs = new _stryke_capnp.Message(buffer, false).getRoot(require_fs.FileSystem);
361
+ result = new VirtualFileSystem(context, fs);
362
+ if (fs._hasStorage() && fs.storage.length > 0) fs.storage.values().forEach((file) => {
363
+ if (file.path && file.code) {
364
+ let id;
365
+ if (fs._hasIds()) id = fs.ids.find((fileId) => fileId.path === file.path);
366
+ let metadata;
367
+ if (fs._hasMetadata()) metadata = fs.metadata.find((meta) => meta.id === result.#normalizeId(id?.id ?? file.path));
368
+ result.writeSync(file.path, file.code, { meta: {
369
+ id: result.#normalizeId(id?.id ?? metadata?.id ?? file.path),
370
+ type: metadata?.type,
371
+ properties: metadata?._hasProperties() ? metadata?.properties.values().reduce((ret, kvp) => {
372
+ ret[kvp.key] = kvp.value;
373
+ return ret;
374
+ }, {}) : void 0,
375
+ timestamp: metadata?.timestamp
376
+ } });
377
+ }
378
+ });
379
+ } else result = new VirtualFileSystem(context, new _stryke_capnp.Message().initRoot(require_fs.FileSystem));
380
+ result.#logger.debug("Successfully completed virtual file system (VFS) initialization.");
381
+ return result;
382
+ }
383
+ /**
384
+ * A map of file ids to their metadata.
385
+ */
386
+ get metadata() {
387
+ return new Proxy(this.#metadata, {
388
+ get: (target, prop) => {
389
+ return target[this.#normalizeId(prop)];
390
+ },
391
+ set: (target, prop, value) => {
392
+ target[this.#normalizeId(prop)] = value;
393
+ return true;
394
+ },
395
+ deleteProperty: (target, prop) => {
396
+ delete target[this.#normalizeId(prop)];
397
+ return true;
398
+ },
399
+ has: (target, prop) => {
400
+ return this.#normalizeId(prop) in target;
401
+ },
402
+ ownKeys: (target) => {
403
+ return (0, _stryke_helpers_get_unique.getUnique)(Reflect.ownKeys(target).map((key) => this.#normalizeId(key)));
404
+ }
405
+ });
406
+ }
407
+ /**
408
+ * A map of file paths to their module ids.
409
+ */
410
+ get ids() {
411
+ return new Proxy(this.#ids, {
412
+ get: (target, prop) => {
413
+ return target[this.#normalizePath(prop)];
414
+ },
415
+ set: (target, prop, value) => {
416
+ target[this.#normalizePath(prop)] = value;
417
+ return true;
418
+ },
419
+ deleteProperty: (target, prop) => {
420
+ delete target[this.#normalizePath(prop)];
421
+ return true;
422
+ },
423
+ has: (target, prop) => {
424
+ return this.#normalizePath(prop) in target;
425
+ },
426
+ ownKeys: (target) => {
427
+ return (0, _stryke_helpers_get_unique.getUnique)(Reflect.ownKeys(target).map((key) => this.#normalizePath(key)));
428
+ }
429
+ });
430
+ }
431
+ /**
432
+ * A map of module ids to their file paths.
433
+ */
434
+ get paths() {
435
+ return new Proxy(this.#paths, {
436
+ get: (target, prop) => {
437
+ return this.#normalizeId(prop) in target ? target[this.#normalizeId(prop)] : void 0;
438
+ },
439
+ set: (target, prop, value) => {
440
+ target[this.#normalizeId(prop)] = value;
441
+ return true;
442
+ },
443
+ deleteProperty: (target, prop) => {
444
+ delete target[this.#normalizeId(prop)];
445
+ return true;
446
+ },
447
+ has: (target, prop) => {
448
+ return this.#normalizeId(prop) in target;
449
+ },
450
+ ownKeys: (target) => {
451
+ return (0, _stryke_helpers_get_unique.getUnique)(Reflect.ownKeys(target).map((key) => this.#normalizeId(key)));
452
+ }
453
+ });
454
+ }
455
+ /**
456
+ * Gets the resolver cache.
457
+ */
458
+ get resolverCache() {
459
+ if (!this.#resolverCache) this.#resolverCache = (0, flat_cache.create)({
460
+ cacheId: "module-resolution",
461
+ cacheDir: this.#context.cachePath,
462
+ ttl: 2.5 * 60 * 1e3,
463
+ lruSize: 8e3,
464
+ persistInterval: 100
465
+ });
466
+ return this.#resolverCache;
467
+ }
468
+ /**
469
+ * Creates a new instance of the {@link VirtualFileSystem}.
470
+ *
471
+ * @param context - The context of the virtual file system, typically containing options and logging functions.
472
+ * @param fs - A buffer containing the serialized virtual file system data.
473
+ */
474
+ constructor(context, fs) {
475
+ this.#context = context;
476
+ this.#storage = { "": new require_storage_file_system.FileSystemStorageAdapter(context) };
477
+ if ((0, _stryke_type_checks_is_set_object.isSetObject)(this.#context.config.output.storage)) this.#storage = {
478
+ ...this.#storage,
479
+ ...this.#context.config.output.storage
480
+ };
481
+ this.#storage.virtual ??= new require_storage_virtual.VirtualStorageAdapter(context, { base: "/_virtual" });
482
+ this.#storage[this.#context.config.output.path] ??= new require_storage_file_system.FileSystemStorageAdapter(context, { base: this.#context.config.output.path });
483
+ if (this.#context.config.output.copy && this.#context.config.output.copy.path) this.#storage[this.#context.config.output.copy.path] ??= new require_storage_file_system.FileSystemStorageAdapter(context, { base: this.#context.config.output.copy.path });
484
+ if (this.#context.config.output.storage !== "fs") {
485
+ this.#storage[this.#context.artifactsPath] ??= new require_storage_virtual.VirtualStorageAdapter(context, { base: this.#context.artifactsPath });
486
+ this.#storage[this.#context.builtinsPath] ??= new require_storage_virtual.VirtualStorageAdapter(context, { base: this.#context.builtinsPath });
487
+ this.#storage[this.#context.entryPath] ??= new require_storage_virtual.VirtualStorageAdapter(context, { base: this.#context.entryPath });
488
+ }
489
+ this.#metadata = {};
490
+ if (fs._hasMetadata()) this.#metadata = fs.metadata.values().reduce((ret, metadata) => {
491
+ ret[metadata.id] = {
492
+ id: metadata.id,
493
+ type: metadata.type,
494
+ timestamp: metadata.timestamp ?? Date.now(),
495
+ properties: metadata._hasProperties() ? metadata.properties.values().reduce((ret, item) => {
496
+ ret[item.key] = item.value;
497
+ return ret;
498
+ }, {}) : {}
499
+ };
500
+ return ret;
501
+ }, {});
502
+ this.#ids = {};
503
+ this.#paths = {};
504
+ if (fs._hasIds()) {
505
+ this.#ids = fs.ids.values().reduce((ret, identifier) => {
506
+ ret[identifier.path] ??= identifier.id;
507
+ return ret;
508
+ }, {});
509
+ this.#paths = fs.ids.values().reduce((ret, identifier) => {
510
+ ret[identifier.id] ??= identifier.path;
511
+ return ret;
512
+ }, {});
513
+ }
514
+ this.#logger = context.extendLogger({ category: "fs" });
515
+ }
516
+ /**
517
+ * Asynchronously checks if a file exists in the virtual file system (VFS).
518
+ *
519
+ * @param path - The path to the file.
520
+ * @returns A promise that resolves to `true` if the file exists, otherwise `false`.
521
+ */
522
+ async exists(path) {
523
+ const { relativeKey, adapter } = this.#getStorage(path);
524
+ return adapter.exists(relativeKey);
525
+ }
526
+ /**
527
+ * Synchronously checks if a file exists in the virtual file system (VFS).
528
+ *
529
+ * @param path - The path to the file.
530
+ * @returns `true` if the file exists, otherwise `false`.
531
+ */
532
+ existsSync(path) {
533
+ const { relativeKey, adapter } = this.#getStorage(path);
534
+ return adapter.existsSync(relativeKey);
535
+ }
536
+ /**
537
+ * Checks if a file is virtual in the virtual file system (VFS).
538
+ *
539
+ * @param path - The path to the file.
540
+ * @param importer - An optional path to the importer module.
541
+ * @param options - Additional resolution options.
542
+ * @returns `true` if the file is virtual, otherwise `false`.
543
+ */
544
+ isVirtual(path, importer, options) {
545
+ const resolved = this.resolveSync(path, importer, options);
546
+ if (!(0, _stryke_type_checks_is_set_string.isSetString)(resolved)) {
547
+ if ((0, _stryke_type_checks_is_set.isSet)(resolved)) throw new Error(`Resolved path is not a string: ${String(resolved)}`);
548
+ return false;
549
+ }
550
+ return this.#getStorage(resolved)?.adapter?.preset === "virtual" || resolved.startsWith(`${this.#context.config.framework?.name ?? "powerlines"}:`) || path.startsWith(`${this.#context.config.framework?.name ?? "powerlines"}:`);
551
+ }
552
+ /**
553
+ * Checks if a path is a directory in the virtual file system (VFS).
554
+ *
555
+ * @param path - The path to check.
556
+ * @param importer - An optional path to the importer module.
557
+ * @param options - Additional resolution options.
558
+ * @returns `true` if the path is a directory, otherwise `false`.
559
+ */
560
+ isDirectorySync(path, importer, options) {
561
+ const resolved = this.resolveSync(path, importer, options);
562
+ if (!(0, _stryke_type_checks_is_set_string.isSetString)(resolved)) {
563
+ if ((0, _stryke_type_checks_is_set.isSet)(resolved)) throw new Error(`Resolved path is not a string: ${String(resolved)}`);
564
+ return false;
565
+ }
566
+ return !!(this.existsSync(resolved) && this.#getStorage(resolved)?.adapter?.isDirectorySync(resolved));
567
+ }
568
+ /**
569
+ * Checks if a path is a directory in the virtual file system (VFS).
570
+ *
571
+ * @param path - The path to check.
572
+ * @param importer - An optional path to the importer module.
573
+ * @param options - Additional resolution options.
574
+ * @returns `true` if the path is a directory, otherwise `false`.
575
+ */
576
+ async isDirectory(path, importer, options) {
577
+ const resolved = await this.resolve(path, importer, options);
578
+ if (!(0, _stryke_type_checks_is_set_string.isSetString)(resolved)) {
579
+ if ((0, _stryke_type_checks_is_set.isSet)(resolved)) throw new Error(`Resolved path is not a string: ${String(resolved)}`);
580
+ return false;
581
+ }
582
+ return !!(await this.exists(resolved) && await this.#getStorage(resolved)?.adapter?.isDirectory(resolved));
583
+ }
584
+ /**
585
+ * Checks if a path is a file in the virtual file system (VFS).
586
+ *
587
+ * @param path - The path to check.
588
+ * @param importer - An optional path to the importer module.
589
+ * @param options - Additional resolution options.
590
+ * @returns `true` if the path is a file, otherwise `false`.
591
+ */
592
+ isFileSync(path, importer, options) {
593
+ const resolved = this.resolveSync(path, importer, options);
594
+ if (!(0, _stryke_type_checks_is_set_string.isSetString)(resolved)) {
595
+ if ((0, _stryke_type_checks_is_set.isSet)(resolved)) throw new Error(`Resolved path is not a string: ${String(resolved)}`);
596
+ return false;
597
+ }
598
+ return this.#getStorage(resolved)?.adapter?.isFileSync(resolved) ?? false;
599
+ }
600
+ /**
601
+ * Checks if a path is a file in the virtual file system (VFS).
602
+ *
603
+ * @param path - The path to check.
604
+ * @param importer - An optional path to the importer module.
605
+ * @param options - Additional resolution options.
606
+ * @returns `true` if the path is a file, otherwise `false`.
607
+ */
608
+ async isFile(path, importer, options) {
609
+ const resolved = await this.resolve(path, importer, options);
610
+ if (!(0, _stryke_type_checks_is_set_string.isSetString)(resolved)) {
611
+ if ((0, _stryke_type_checks_is_set.isSet)(resolved)) throw new Error(`Resolved path is not a string: ${String(resolved)}`);
612
+ return false;
613
+ }
614
+ return await this.#getStorage(resolved)?.adapter?.isFile(resolved) ?? false;
615
+ }
616
+ /**
617
+ * Checks if a file Id must be resolved by the virtual file system (VFS).
618
+ *
619
+ * @remarks
620
+ * Examples of file Ids that would be considered virtual include:
621
+ * - Ids that start with the framework specific prefix (e.g. `powerlines:`)
622
+ * - Ids that match a configured alias for virtual modules (returned true from {@link VirtualFileSystemInterface.isVirtual})
623
+ *
624
+ * @param path - The path or id of the file.
625
+ * @param importer - An optional path to the importer module, used for resolving the file path.
626
+ * @param options - Additional options for resolving the file path.
627
+ * @returns `true` if the file is virtual, otherwise `false`.
628
+ */
629
+ isResolvableId(path, importer, options) {
630
+ return path.startsWith(`${this.#context.config.framework?.name ?? "powerlines"}:`) || this.isVirtual(path, importer, options) || this.isAlias(path) || this.isTsconfigPath(path);
631
+ }
632
+ /**
633
+ * Lists files in a given path.
634
+ *
635
+ * @param path - The path to list files from.
636
+ * @returns An array of file names in the specified path.
637
+ */
638
+ listSync(path) {
639
+ let resolvedPath = path;
640
+ if (resolvedPath.includes("*")) {
641
+ this.#logger.warn(`Invoking "listSync" with a glob pattern is not supported. It is likely you meant to use "globSync". Path: ${path}`);
642
+ resolvedPath = (0, _stryke_path_correct_path.stripStars)(resolvedPath);
643
+ }
644
+ return (0, _stryke_helpers_get_unique.getUnique)(this.#getStorages(resolvedPath, true).map((storage) => storage.adapter.listSync(storage.relativeBase ? storage.base ? (0, _stryke_path_append.appendPath)(storage.relativeBase, storage.base) : storage.relativeBase : storage.base)).flat().filter(Boolean));
645
+ }
646
+ /**
647
+ * Lists files in a given path.
648
+ *
649
+ * @param path - The path to list files from.
650
+ * @returns An array of file names in the specified path.
651
+ */
652
+ async list(path) {
653
+ let resolvedPath = path;
654
+ if (resolvedPath.includes("*")) {
655
+ this.#logger.warn(`Invoking "list" with a glob pattern is not supported. It is likely you meant to use "glob". Path: ${path}`);
656
+ resolvedPath = (0, _stryke_path_correct_path.stripStars)(resolvedPath);
657
+ }
658
+ return (0, _stryke_helpers_get_unique.getUnique)((await Promise.all(this.#getStorages(resolvedPath, true).map(async (storage) => storage.adapter.list(storage.relativeBase ? storage.base ? (0, _stryke_path_append.appendPath)(storage.relativeBase, storage.base) : storage.relativeBase : storage.base)))).flat().filter(Boolean));
659
+ }
660
+ /**
661
+ * Removes a file in the virtual file system (VFS).
662
+ *
663
+ * @param path - The path to create the directory at.
664
+ */
665
+ async remove(path) {
666
+ const normalizedPath = this.#normalizePath(path);
667
+ this.#logger.trace(`Removing file: ${normalizedPath}`);
668
+ const { relativeKey, adapter } = this.#getStorage(normalizedPath);
669
+ if ((0, _stryke_path_file_path_fns.hasFileExtension)(normalizedPath)) await adapter.remove(relativeKey);
670
+ else await adapter.clear(relativeKey);
671
+ const id = this.#ids[normalizedPath];
672
+ if (id && this.#metadata[id]) {
673
+ delete this.#metadata[id];
674
+ delete this.#ids[normalizedPath];
675
+ delete this.#paths[id];
676
+ }
677
+ }
678
+ /**
679
+ * Removes a file in the virtual file system (VFS).
680
+ *
681
+ * @param path - The path to create the directory at.
682
+ */
683
+ removeSync(path) {
684
+ const normalizedPath = this.#normalizePath(path);
685
+ this.#logger.trace(`Removing file: ${normalizedPath}`);
686
+ const { relativeKey, adapter } = this.#getStorage(normalizedPath);
687
+ if ((0, _stryke_path_file_path_fns.hasFileExtension)(normalizedPath)) adapter.removeSync(relativeKey);
688
+ else adapter.clearSync(relativeKey);
689
+ const id = this.#ids[normalizedPath];
690
+ if (id && this.#metadata[id]) {
691
+ delete this.#metadata[id];
692
+ delete this.#ids[normalizedPath];
693
+ delete this.#paths[id];
694
+ }
695
+ }
696
+ /**
697
+ * Glob files in the virtual file system (VFS) based on the provided pattern(s).
698
+ *
699
+ * @param patterns - A pattern (or multiple patterns) to use to determine the file paths to return
700
+ * @returns An array of file paths matching the provided pattern(s)
701
+ */
702
+ async glob(patterns) {
703
+ const results = [];
704
+ for (const pattern of normalizeGlobPatterns(this.#context.config.cwd, patterns)) {
705
+ const normalized = this.#normalizePath(pattern);
706
+ if (!/[*?[\]{}]/.test(normalized) && !normalized.includes("*")) if (this.isDirectorySync(normalized)) results.push(...await this.list(normalized));
707
+ else {
708
+ const resolved = await this.resolve(normalized);
709
+ if (resolved && !results.includes(resolved)) results.push(resolved);
710
+ }
711
+ else {
712
+ const absPattern = (0, _stryke_path_is_type.isAbsolutePath)(normalized) ? normalized : this.#normalizePath((0, _stryke_path_append.appendPath)(normalized, this.#context.config.cwd));
713
+ await Promise.all((await this.list((0, _stryke_path_correct_path.stripStars)(absPattern))).map(async (file) => {
714
+ if ((0, _stryke_path_glob_to_regex.globToRegex)(absPattern).test(file)) {
715
+ const resolved = await this.resolve(file);
716
+ if (resolved && !results.includes(resolved)) results.push(resolved);
717
+ }
718
+ }));
719
+ }
720
+ }
721
+ return results;
722
+ }
723
+ /**
724
+ * Synchronously glob files in the virtual file system (VFS) based on the provided pattern(s).
725
+ *
726
+ * @param patterns - A pattern (or multiple patterns) to use to determine the file paths to return
727
+ * @returns An array of file paths matching the provided pattern(s)
728
+ */
729
+ globSync(patterns) {
730
+ const results = [];
731
+ for (const pattern of normalizeGlobPatterns(this.#context.config.cwd, patterns)) {
732
+ const normalized = this.#normalizePath(pattern);
733
+ if (!/[*?[\]{}]/.test(normalized) && !normalized.includes("*")) if (this.isDirectorySync(normalized)) results.push(...this.listSync(normalized));
734
+ else {
735
+ const resolved = this.resolveSync(normalized);
736
+ if (resolved && !results.includes(resolved)) results.push(resolved);
737
+ }
738
+ else {
739
+ const absPattern = (0, _stryke_path_is_type.isAbsolutePath)(normalized) ? normalized : this.#normalizePath((0, _stryke_path_append.appendPath)(normalized, this.#context.config.cwd));
740
+ const files = this.listSync((0, _stryke_path_correct_path.stripStars)(absPattern));
741
+ for (const file of files) if ((0, _stryke_path_glob_to_regex.globToRegex)(absPattern).test(file)) {
742
+ const resolved = this.resolveSync(file);
743
+ if (resolved && !results.includes(resolved)) results.push(resolved);
744
+ }
745
+ }
746
+ }
747
+ return results;
748
+ }
749
+ /**
750
+ * Copies a file from one path to another in the virtual file system (VFS).
751
+ *
752
+ * @param srcPath - The source path to copy
753
+ * @param destPath - The destination path to copy to
754
+ */
755
+ async copy(srcPath, destPath) {
756
+ const src = srcPath instanceof URL ? (0, node_url.fileURLToPath)(srcPath) : srcPath;
757
+ const dest = destPath instanceof URL ? (0, node_url.fileURLToPath)(destPath) : destPath;
758
+ if (!(0, _stryke_type_checks_is_set_string.isSetString)(src) && (!(0, _stryke_type_checks_is_set_object.isSetObject)(src) || !(0, _stryke_type_checks_is_set_string.isSetString)(src.input)) || !(0, _stryke_type_checks_is_set_string.isSetString)(dest)) return;
759
+ const sourceStr = (0, _stryke_type_checks_is_string.isString)(src) ? src : src.input ? src.input : this.#context.config.cwd;
760
+ const source = await this.resolve(sourceStr);
761
+ if (!source) return;
762
+ if (this.isDirectorySync(source) || (0, _stryke_type_checks_is_set_string.isSetString)(src) && src.includes("*") || (0, _stryke_type_checks_is_set_object.isSetObject)(src) && (0, _stryke_type_checks_is_set_string.isSetString)(src.glob)) await Promise.all((await this.glob(src)).map(async (file) => {
763
+ return this.copy(file, (0, _stryke_path_append.appendPath)((0, _stryke_path_replace.replacePath)(file, sourceStr), dest));
764
+ }));
765
+ else {
766
+ const content = await this.read(source);
767
+ if (content !== void 0) await this.write(this.#normalizePath(dest), content, { skipFormat: true });
768
+ }
769
+ }
770
+ /**
771
+ * Synchronously copies a file from one path to another in the virtual file system (VFS).
772
+ *
773
+ * @param srcPath - The source path to copy
774
+ * @param destPath - The destination path to copy to
775
+ */
776
+ copySync(srcPath, destPath) {
777
+ const src = srcPath instanceof URL ? (0, node_url.fileURLToPath)(srcPath) : srcPath;
778
+ const dest = destPath instanceof URL ? (0, node_url.fileURLToPath)(destPath) : destPath;
779
+ if (!(0, _stryke_type_checks_is_set_string.isSetString)(src) && (!(0, _stryke_type_checks_is_set_object.isSetObject)(src) || !(0, _stryke_type_checks_is_set_string.isSetString)(src.input)) || !(0, _stryke_type_checks_is_set_string.isSetString)(dest)) return;
780
+ const sourceStr = (0, _stryke_type_checks_is_string.isString)(src) ? src : src.input ? src.input : this.#context.config.cwd;
781
+ const source = this.resolveSync(sourceStr);
782
+ if (!source) return;
783
+ if (this.isDirectorySync(source) || (0, _stryke_type_checks_is_set_string.isSetString)(src) && src.includes("*") || (0, _stryke_type_checks_is_set_object.isSetObject)(src) && (0, _stryke_type_checks_is_set_string.isSetString)(src.glob)) this.globSync(src).map((file) => {
784
+ return this.copySync(file, (0, _stryke_path_append.appendPath)((0, _stryke_path_file_path_fns.findFilePath)((0, _stryke_path_replace.replacePath)(file, sourceStr)), dest));
785
+ });
786
+ else {
787
+ const content = this.readSync(source);
788
+ if (content !== void 0) this.writeSync(this.#normalizePath((0, _stryke_path_file_path_fns.hasFileExtension)(dest) ? dest : (0, _stryke_path_append.appendPath)((0, _stryke_path_file_path_fns.findFileName)(source), dest)), content, { skipFormat: true });
789
+ }
790
+ }
791
+ /**
792
+ * Moves a file (or files) from one path to another in the virtual file system (VFS).
793
+ *
794
+ * @param srcPath - The source path to move
795
+ * @param destPath - The destination path to move to
796
+ */
797
+ async move(srcPath, destPath) {
798
+ if ((0, _stryke_path_file_path_fns.hasFileExtension)(srcPath)) {
799
+ await this.copy(srcPath, destPath);
800
+ await this.remove(srcPath);
801
+ } else await Promise.all((await this.list(srcPath)).map(async (file) => {
802
+ await this.copy(file, destPath);
803
+ await this.remove(file);
804
+ }));
805
+ }
806
+ /**
807
+ * Synchronously moves a file (or files) from one path to another in the virtual file system (VFS).
808
+ *
809
+ * @param srcPath - The source path to move
810
+ * @param destPath - The destination path to move to
811
+ */
812
+ moveSync(srcPath, destPath) {
813
+ if ((0, _stryke_path_file_path_fns.hasFileExtension)(srcPath)) {
814
+ this.copySync(srcPath, destPath);
815
+ this.removeSync(srcPath);
816
+ } else this.listSync(srcPath).forEach((file) => {
817
+ this.copySync(file, destPath);
818
+ this.removeSync(file);
819
+ });
820
+ }
821
+ /**
822
+ * Asynchronously reads a file from the virtual file system (VFS).
823
+ *
824
+ * @param path - The path or ID of the file to read.
825
+ * @returns A promise that resolves to the contents of the file as a string, or undefined if the file does not exist.
826
+ */
827
+ async read(path) {
828
+ const filePath = await this.resolve(path, void 0, { isFile: true });
829
+ if (!filePath || !this.existsSync(filePath)) return;
830
+ const { adapter } = this.#getStorage(filePath);
831
+ this.#logger.trace(`Reading ${adapter.name} file: ${filePath}`);
832
+ return await adapter.get(filePath) ?? void 0;
833
+ }
834
+ /**
835
+ * Synchronously reads a file from the virtual file system (VFS).
836
+ *
837
+ * @param path - The path or ID of the file to read.
838
+ * @returns The contents of the file as a string, or undefined if the file does not exist.
839
+ */
840
+ readSync(path) {
841
+ const filePath = this.resolveSync(path, void 0, { isFile: true });
842
+ if (!filePath || !this.existsSync(filePath)) return;
843
+ const { adapter } = this.#getStorage(filePath);
844
+ this.#logger.trace(`Reading ${adapter.name} file: ${filePath}`);
845
+ return adapter.getSync(filePath) ?? void 0;
846
+ }
847
+ /**
848
+ * Writes a file to the virtual file system (VFS).
849
+ *
850
+ * @param path - The path to the file.
851
+ * @param data - The contents of the file.
852
+ * @param options - Optional parameters for writing the file.
853
+ * @returns A promise that resolves when the file is written.
854
+ */
855
+ async write(path, data = "", options = {}) {
856
+ const meta = options.meta ?? {};
857
+ const resolvedPath = await this.resolve(this.#normalizePath(path)) || path;
858
+ const { relativeKey, adapter } = this.#getStorage(resolvedPath, options.storage);
859
+ this.#logger.trace(`Writing ${resolvedPath} to ${adapter.name === "virtual" ? "the virtual file system" : adapter.name === "file-system" ? "the local file system" : adapter.name} (size: ${(0, _stryke_string_format_pretty_bytes.prettyBytes)(new node_buffer.Blob((0, _stryke_convert_to_array.toArray)(data)).size)})`);
860
+ let code = data;
861
+ try {
862
+ if (!options.skipFormat) code = await require_lib_utilities_format.format(this.#context, resolvedPath, data);
863
+ } catch (err) {
864
+ if (require_constants_extensions.DEFAULT_EXTENSIONS.includes((0, _stryke_path_file_path_fns.findFileExtensionSafe)(resolvedPath, { fullExtension: true }))) this.#logger.warn(`Failed to format file ${resolvedPath} before writing: ${err.message}`);
865
+ code = data;
866
+ }
867
+ this.#logger.trace(`Writing ${resolvedPath} to ${adapter.name === "virtual" ? "the virtual file system" : adapter.name === "file-system" ? "the local file system" : adapter.name} (size: ${(0, _stryke_string_format_pretty_bytes.prettyBytes)(new node_buffer.Blob((0, _stryke_convert_to_array.toArray)(code)).size)})`);
868
+ const id = this.#normalizeId(meta.id || resolvedPath);
869
+ this.metadata[id] = {
870
+ type: "normal",
871
+ timestamp: Date.now(),
872
+ ...this.metadata[id] ?? {},
873
+ ...meta
874
+ };
875
+ this.paths[id] = resolvedPath;
876
+ this.ids[resolvedPath] = id;
877
+ return adapter.set(relativeKey, code);
878
+ }
879
+ /**
880
+ * Synchronously writes a file to the virtual file system (VFS).
881
+ *
882
+ * @param path - The file to write.
883
+ * @param data - The contents of the file.
884
+ * @param options - Optional parameters for writing the file.
885
+ */
886
+ writeSync(path, data = "", options = {}) {
887
+ const meta = options.meta ?? {};
888
+ const resolvedPath = this.resolveSync(this.#normalizePath(path)) || path;
889
+ const { relativeKey, adapter } = this.#getStorage(resolvedPath, options.storage);
890
+ this.#logger.trace(`Writing ${resolvedPath} file to ${adapter.name === "virtual" ? "the virtual file system" : adapter.name === "file-system" ? "the local file system" : adapter.name} (size: ${(0, _stryke_string_format_pretty_bytes.prettyBytes)(new node_buffer.Blob((0, _stryke_convert_to_array.toArray)(data)).size)})`);
891
+ const id = this.#normalizeId(meta.id || resolvedPath);
892
+ this.metadata[id] = {
893
+ type: "normal",
894
+ timestamp: Date.now(),
895
+ ...this.metadata[id] ?? {},
896
+ ...meta
897
+ };
898
+ this.paths[id] = resolvedPath;
899
+ this.ids[resolvedPath] = id;
900
+ return adapter.setSync(relativeKey, data);
901
+ }
902
+ /**
903
+ * Synchronously creates a directory at the specified path.
904
+ *
905
+ * @param dirPath - The path of the directory to create.
906
+ */
907
+ mkdirSync(dirPath) {
908
+ return this.#getStorage(dirPath)?.adapter?.mkdirSync(dirPath);
909
+ }
910
+ /**
911
+ * Creates a directory at the specified path.
912
+ *
913
+ * @param path - The path of the directory to create.
914
+ */
915
+ async mkdir(path) {
916
+ return this.#getStorage(path)?.adapter?.mkdir(path);
917
+ }
918
+ /**
919
+ * Retrieves the metadata of a file in the virtual file system (VFS).
920
+ *
921
+ * @param pathOrId - The path or ID of the file to retrieve metadata for.
922
+ * @returns The metadata of the file, or undefined if the file does not exist.
923
+ */
924
+ getMetadata(pathOrId) {
925
+ const resolved = this.resolveSync(pathOrId);
926
+ if (resolved && this.metadata[resolved]) return this.metadata[resolved];
927
+ }
928
+ /**
929
+ * Resolves a given module ID using the configured aliases.
930
+ *
931
+ * @remarks
932
+ * This function can be used to map module IDs to different paths based on the alias configuration.
933
+ *
934
+ * @param id - The module ID to resolve.
935
+ * @returns The resolved module ID - after applying any configured aliases (this will be the same as the input ID if no aliases match).
936
+ */
937
+ resolveAlias(id) {
938
+ let path = id;
939
+ if (this.#context.config.resolve.alias) {
940
+ if (Array.isArray(this.#context.config.resolve.alias) && this.#context.config.resolve.alias.length > 0) {
941
+ const found = this.#context.config.resolve.alias.filter((alias) => (0, _stryke_type_checks_is_set_string.isSetString)(alias.find) && (alias.find === path || path.startsWith(`${alias.find}/`)) || (0, _stryke_type_checks_is_regexp.isRegExp)(alias.find) && alias.find.test(path));
942
+ if (found.length > 0) {
943
+ const alias = found.reduce((ret, current) => {
944
+ return ((0, _stryke_type_checks_is_set_string.isSetString)(ret.find) ? ret.find.length : (0, _stryke_type_checks_is_regexp.isRegExp)(ret.find) ? ret.find.source.length : 0) > ((0, _stryke_type_checks_is_set_string.isSetString)(current.find) ? current.find.length : (0, _stryke_type_checks_is_regexp.isRegExp)(current.find) ? current.find.source.length : 0) ? ret : current;
945
+ });
946
+ if ((0, _stryke_type_checks_is_set_string.isSetString)(alias.find)) path = path.replace(new RegExp(`^${alias.find}`), alias.replacement);
947
+ else if ((0, _stryke_type_checks_is_regexp.isRegExp)(alias.find)) path = path.replace(alias.find, alias.replacement);
948
+ }
949
+ } else if ((0, _stryke_type_checks_is_set_object.isSetObject)(this.#context.config.resolve.alias)) {
950
+ const found = Object.keys(this.#context.config.resolve.alias).filter((key) => key === path || path.startsWith(`${key}/`));
951
+ if (found.length > 0) {
952
+ const alias = found.reduce((ret, current) => {
953
+ return ret.length > current.length ? ret : current;
954
+ });
955
+ path = path.replace(new RegExp(`^${alias}`), this.#context.config.resolve.alias[alias]);
956
+ }
957
+ }
958
+ }
959
+ return path;
960
+ }
961
+ /**
962
+ * Checks if a given module ID is an alias.
963
+ *
964
+ * @remarks
965
+ * This function can be used to determine if a module ID matches any configured aliases.
966
+ *
967
+ * @param id - The module ID to check.
968
+ * @returns A boolean indicating whether the module ID is an alias.
969
+ */
970
+ isAlias(id) {
971
+ const path = id;
972
+ if (this.#context.config.resolve.alias) {
973
+ if (Array.isArray(this.#context.config.resolve.alias) && this.#context.config.resolve.alias.length > 0) return this.#context.config.resolve.alias.filter((alias) => (0, _stryke_type_checks_is_set_string.isSetString)(alias.find) && (alias.find === path || path.startsWith(`${alias.find}/`)) || (0, _stryke_type_checks_is_regexp.isRegExp)(alias.find) && alias.find.test(path)).length > 0;
974
+ else if ((0, _stryke_type_checks_is_set_object.isSetObject)(this.#context.config.resolve.alias)) return Object.keys(this.#context.config.resolve.alias).filter((key) => key === path || path.startsWith(`${key}/`)).length > 0;
975
+ }
976
+ return false;
977
+ }
978
+ /**
979
+ * Checks if a given module ID is a tsconfig path.
980
+ *
981
+ * @remarks
982
+ * This function can be used to determine if a module ID matches any configured tsconfig paths.
983
+ *
984
+ * @param id - The module ID to check.
985
+ * @returns A boolean indicating whether the module ID is a tsconfig path.
986
+ */
987
+ isTsconfigPath(id) {
988
+ return !!(this.#context.tsconfig.options.paths && Object.keys(this.#context.tsconfig.options.paths).length > 0 && (0, bundle_require.match)(id, this.#context.resolvePatterns));
989
+ }
990
+ /**
991
+ * A helper function to resolve modules in the virtual file system (VFS).
992
+ *
993
+ * @remarks
994
+ * This function can be used to resolve modules relative to the project root directory.
995
+ *
996
+ * @example
997
+ * ```ts
998
+ * const resolved = await context.resolvePath("some-module", "/path/to/importer");
999
+ * ```
1000
+ *
1001
+ * @param id - The module to resolve.
1002
+ * @param importer - An optional path to the importer module.
1003
+ * @param options - Additional resolution options.
1004
+ * @returns A promise that resolves to the resolved module path.
1005
+ */
1006
+ async resolve(id, importer, options = {}) {
1007
+ const origResult = await this.#innerResolve(id, importer, options);
1008
+ if (origResult && options.isFile && await this.isDirectory(origResult)) {
1009
+ const indexResult = await this.resolve((0, _stryke_path_join.joinPaths)(origResult, "index"), importer, options);
1010
+ if (indexResult) return indexResult;
1011
+ if (!(0, _stryke_path_file_path_fns.hasFileExtension)(origResult)) for (const ext of require_constants_extensions.DEFAULT_EXTENSIONS) {
1012
+ const extResult = await this.resolve(`${origResult}.${ext}`, importer, options);
1013
+ if (extResult) return extResult;
1014
+ }
1015
+ return;
1016
+ }
1017
+ return origResult;
1018
+ }
1019
+ /**
1020
+ * A synchronous helper function to resolve modules using the Jiti resolver
1021
+ *
1022
+ * @remarks
1023
+ * This function can be used to resolve modules relative to the project root directory.
1024
+ *
1025
+ * @example
1026
+ * ```ts
1027
+ * const resolvedPath = context.resolveSync("some-module", "/path/to/importer");
1028
+ * ```
1029
+ *
1030
+ * @param id - The module to resolve.
1031
+ * @param importer - An optional path to the importer module.
1032
+ * @param options - Additional resolution options.
1033
+ * @returns The resolved module path.
1034
+ */
1035
+ resolveSync(id, importer, options = {}) {
1036
+ const origResult = this.#innerResolveSync(id, importer, options);
1037
+ if (origResult && options.isFile && this.isDirectorySync(origResult)) {
1038
+ const indexResult = this.resolveSync((0, _stryke_path_join.joinPaths)(origResult, "index"), importer, options);
1039
+ if (indexResult) return indexResult;
1040
+ if (!(0, _stryke_path_file_path_fns.hasFileExtension)(origResult)) for (const ext of require_constants_extensions.DEFAULT_EXTENSIONS) {
1041
+ const extResult = this.resolveSync(`${origResult}.${ext}`, importer, options);
1042
+ if (extResult) return extResult;
1043
+ }
1044
+ return;
1045
+ }
1046
+ return origResult;
1047
+ }
1048
+ /**
1049
+ * Disposes of the virtual file system (VFS) by saving its state to disk.
1050
+ */
1051
+ async dispose() {
1052
+ if (!this.#isDisposed) {
1053
+ this.#isDisposed = true;
1054
+ this.#logger.debug("Disposing virtual file system...");
1055
+ await this.remove((0, _stryke_path_join.joinPaths)(this.#context.dataPath, "fs.bin"));
1056
+ const message = new _stryke_capnp.Message();
1057
+ const fs = message.initRoot(require_fs.FileSystem);
1058
+ const storage = fs._initStorage(Object.keys(this.#paths).length);
1059
+ await Promise.all(Object.values(this.#paths).map(async (path, index) => {
1060
+ const code = await this.read(path);
1061
+ const fd = storage.get(index);
1062
+ fd.path = path;
1063
+ fd.code = code || "";
1064
+ }));
1065
+ const ids = fs._initIds(Object.keys(this.#ids).length);
1066
+ Object.entries(this.#ids).filter(([, id]) => id).forEach(([path, id], index) => {
1067
+ const fileId = ids.get(index);
1068
+ fileId.id = id;
1069
+ fileId.path = path;
1070
+ });
1071
+ const metadata = fs._initMetadata(Object.keys(this.#metadata).length);
1072
+ Object.entries(this.#metadata).filter(([, value]) => value).forEach(([id, value], index) => {
1073
+ const fileMetadata = metadata.get(index);
1074
+ fileMetadata.id = id;
1075
+ fileMetadata.type = value.type;
1076
+ fileMetadata.timestamp = value.timestamp ?? Date.now();
1077
+ if (value.properties) {
1078
+ const props = fileMetadata._initProperties(Object.keys(value.properties).length);
1079
+ Object.entries(value.properties).filter(([, val]) => (0, _stryke_type_checks_is_set_string.isSetString)(val)).forEach(([key, val], index) => {
1080
+ const prop = props.get(index);
1081
+ prop.key = key;
1082
+ prop.value = val;
1083
+ });
1084
+ }
1085
+ });
1086
+ await (0, _stryke_fs_buffer.writeFileBuffer)((0, _stryke_path_join.joinPaths)(this.#context.dataPath, "fs.bin"), message.toArrayBuffer());
1087
+ if (!this.#context.config.skipCache) this.resolverCache.save(true);
1088
+ await Promise.all(this.#getStorages().map(async (storage) => storage.adapter.dispose()));
1089
+ this.#logger.trace("Virtual file system has been disposed.");
1090
+ }
1091
+ }
1092
+ /**
1093
+ * Asynchronously disposes of the virtual file system (VFS) by saving its state to disk.
1094
+ *
1095
+ * @remarks
1096
+ * This method is automatically called when the VFS instance is used within a `using` block, or can be manually invoked to ensure that the VFS state is saved and resources are cleaned up properly.
1097
+ */
1098
+ async [Symbol.asyncDispose]() {
1099
+ return this.dispose();
1100
+ }
1101
+ };
1102
+
1103
+ //#endregion
1104
+ exports.VirtualFileSystem = VirtualFileSystem;