@hyperfrontend/project-scope 0.2.1 → 0.2.2

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 (439) hide show
  1. package/CHANGELOG.md +7 -1
  2. package/README.md +3 -4
  3. package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/array/index.cjs.js +7 -0
  4. package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/array/index.esm.js +5 -0
  5. package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/console/index.cjs.js +13 -0
  6. package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/console/index.esm.js +8 -0
  7. package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/date/index.cjs.js +10 -0
  8. package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/date/index.esm.js +8 -0
  9. package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/error/index.cjs.js +6 -0
  10. package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/error/index.esm.js +5 -0
  11. package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/json/index.cjs.js +7 -0
  12. package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/json/index.esm.js +5 -0
  13. package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/map/index.cjs.js +6 -0
  14. package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/map/index.esm.js +5 -0
  15. package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/math/index.cjs.js +9 -0
  16. package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/math/index.esm.js +6 -0
  17. package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/number/index.cjs.js +7 -0
  18. package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/number/index.esm.js +7 -0
  19. package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/object/index.cjs.js +15 -0
  20. package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/object/index.esm.js +9 -0
  21. package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/set/index.cjs.js +6 -0
  22. package/_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/set/index.esm.js +5 -0
  23. package/_dependencies/@hyperfrontend/logging/index.cjs.js +191 -0
  24. package/_dependencies/@hyperfrontend/logging/index.d.ts +151 -0
  25. package/_dependencies/@hyperfrontend/logging/index.esm.js +186 -0
  26. package/_shared/core/cache/index.cjs.js +135 -0
  27. package/_shared/core/cache/index.esm.js +128 -0
  28. package/_shared/core/errors/structured-errors/index.cjs.js +28 -0
  29. package/_shared/core/errors/structured-errors/index.esm.js +23 -0
  30. package/_shared/core/fs/stat/index.cjs.js +46 -0
  31. package/_shared/core/fs/stat/index.esm.js +40 -0
  32. package/_shared/core/path/join/index.cjs.js +13 -0
  33. package/_shared/core/path/join/index.esm.js +10 -0
  34. package/_shared/core/path/normalize/index.cjs.js +37 -0
  35. package/_shared/core/path/normalize/index.esm.js +31 -0
  36. package/_shared/core/path/resolve/index.cjs.js +47 -0
  37. package/_shared/core/path/resolve/index.esm.js +41 -0
  38. package/_shared/core/path/segments/index.cjs.js +38 -0
  39. package/_shared/core/path/segments/index.esm.js +31 -0
  40. package/_shared/core/patterns/glob/index.cjs.js +145 -0
  41. package/_shared/core/patterns/glob/index.esm.js +136 -0
  42. package/_shared/core/platform/detect/index.cjs.js +103 -0
  43. package/_shared/core/platform/detect/index.esm.js +95 -0
  44. package/_shared/core/platform/line-endings/index.cjs.js +52 -0
  45. package/_shared/core/platform/line-endings/index.esm.js +44 -0
  46. package/_shared/project/config/patterns/index.cjs.js +172 -0
  47. package/_shared/project/config/patterns/index.esm.js +169 -0
  48. package/_shared/tech/monorepo/pnpm-workspaces/index.cjs.js +33 -0
  49. package/_shared/tech/monorepo/pnpm-workspaces/index.esm.js +31 -0
  50. package/_shared/tech/shared-utils/detector-helpers/index.cjs.js +48 -0
  51. package/_shared/tech/shared-utils/detector-helpers/index.esm.js +43 -0
  52. package/_shared/vfs/types/index.cjs.js +14 -0
  53. package/_shared/vfs/types/index.esm.js +12 -0
  54. package/cli/index.cjs.js +1702 -1910
  55. package/cli/index.d.ts +273 -7
  56. package/cli/index.d.ts.map +1 -1
  57. package/cli/index.esm.js +1586 -1794
  58. package/core/encoding/index.cjs.js +86 -401
  59. package/core/encoding/index.d.ts +186 -3
  60. package/core/encoding/index.d.ts.map +1 -1
  61. package/core/encoding/index.esm.js +78 -392
  62. package/core/fs/index.cjs.js +231 -581
  63. package/core/fs/index.d.ts +479 -6
  64. package/core/fs/index.d.ts.map +1 -1
  65. package/core/fs/index.esm.js +221 -571
  66. package/core/index.cjs.js +518 -1748
  67. package/core/index.d.ts +486 -9
  68. package/core/index.d.ts.map +1 -1
  69. package/core/index.esm.js +501 -1728
  70. package/core/path/index.cjs.js +6 -234
  71. package/core/path/index.d.ts +306 -5
  72. package/core/path/index.d.ts.map +1 -1
  73. package/core/path/index.esm.js +4 -232
  74. package/core/platform/index.cjs.js +5 -216
  75. package/core/platform/index.d.ts +185 -3
  76. package/core/platform/index.d.ts.map +1 -1
  77. package/core/platform/index.esm.js +3 -212
  78. package/heuristics/dependencies/index.cjs.js +95 -492
  79. package/heuristics/dependencies/index.d.ts +99 -2
  80. package/heuristics/dependencies/index.d.ts.map +1 -1
  81. package/heuristics/dependencies/index.esm.js +69 -466
  82. package/heuristics/entry-points/index.cjs.js +91 -795
  83. package/heuristics/entry-points/index.d.ts +123 -2
  84. package/heuristics/entry-points/index.d.ts.map +1 -1
  85. package/heuristics/entry-points/index.esm.js +72 -776
  86. package/heuristics/framework/index.cjs.js +1481 -1410
  87. package/heuristics/framework/index.d.ts +104 -2
  88. package/heuristics/framework/index.d.ts.map +1 -1
  89. package/heuristics/framework/index.esm.js +1417 -1346
  90. package/heuristics/index.cjs.js +3206 -3301
  91. package/heuristics/index.d.ts +4 -5
  92. package/heuristics/index.d.ts.map +1 -1
  93. package/heuristics/index.esm.js +3231 -3326
  94. package/heuristics/project-type/index.cjs.js +1487 -1437
  95. package/heuristics/project-type/index.d.ts +64 -2
  96. package/heuristics/project-type/index.d.ts.map +1 -1
  97. package/heuristics/project-type/index.esm.js +1416 -1366
  98. package/index.cjs.js +3044 -3533
  99. package/index.d.ts +44 -10
  100. package/index.d.ts.map +1 -1
  101. package/index.esm.js +2900 -3377
  102. package/models/index.cjs.js +0 -1
  103. package/models/index.d.ts +20 -14
  104. package/models/index.d.ts.map +1 -1
  105. package/models/index.esm.js +0 -1
  106. package/nx/index.cjs.js +163 -577
  107. package/nx/index.d.ts +279 -4
  108. package/nx/index.d.ts.map +1 -1
  109. package/nx/index.esm.js +145 -554
  110. package/package.json +13 -12
  111. package/project/config/index.cjs.js +122 -1062
  112. package/project/config/index.d.ts +202 -4
  113. package/project/config/index.d.ts.map +1 -1
  114. package/project/config/index.esm.js +105 -1043
  115. package/project/index.cjs.js +323 -1100
  116. package/project/index.d.ts +4 -5
  117. package/project/index.d.ts.map +1 -1
  118. package/project/index.esm.js +302 -1076
  119. package/project/package/index.cjs.js +191 -472
  120. package/project/package/index.d.ts +280 -3
  121. package/project/package/index.d.ts.map +1 -1
  122. package/project/package/index.esm.js +178 -458
  123. package/project/root/index.cjs.js +107 -416
  124. package/project/root/index.d.ts +83 -2
  125. package/project/root/index.d.ts.map +1 -1
  126. package/project/root/index.esm.js +96 -405
  127. package/project/traversal/index.cjs.js +94 -621
  128. package/project/traversal/index.d.ts +165 -3
  129. package/project/traversal/index.d.ts.map +1 -1
  130. package/project/traversal/index.esm.js +80 -607
  131. package/tech/backend/index.cjs.js +221 -507
  132. package/tech/backend/index.d.ts +205 -8
  133. package/tech/backend/index.d.ts.map +1 -1
  134. package/tech/backend/index.esm.js +200 -486
  135. package/tech/build/index.cjs.js +348 -635
  136. package/tech/build/index.d.ts +276 -10
  137. package/tech/build/index.d.ts.map +1 -1
  138. package/tech/build/index.esm.js +326 -613
  139. package/tech/frontend/index.cjs.js +505 -684
  140. package/tech/frontend/index.d.ts +379 -15
  141. package/tech/frontend/index.d.ts.map +1 -1
  142. package/tech/frontend/index.esm.js +481 -660
  143. package/tech/index.cjs.js +1580 -1420
  144. package/tech/index.d.ts +55 -32
  145. package/tech/index.d.ts.map +1 -1
  146. package/tech/index.esm.js +1513 -1353
  147. package/tech/legacy/index.cjs.js +97 -448
  148. package/tech/legacy/index.d.ts +125 -7
  149. package/tech/legacy/index.d.ts.map +1 -1
  150. package/tech/legacy/index.esm.js +79 -430
  151. package/tech/linting/index.cjs.js +136 -522
  152. package/tech/linting/index.d.ts +129 -7
  153. package/tech/linting/index.d.ts.map +1 -1
  154. package/tech/linting/index.esm.js +116 -502
  155. package/tech/monorepo/index.cjs.js +244 -572
  156. package/tech/monorepo/index.d.ts +241 -10
  157. package/tech/monorepo/index.d.ts.map +1 -1
  158. package/tech/monorepo/index.esm.js +224 -552
  159. package/tech/testing/index.cjs.js +214 -570
  160. package/tech/testing/index.d.ts +176 -8
  161. package/tech/testing/index.d.ts.map +1 -1
  162. package/tech/testing/index.esm.js +196 -552
  163. package/tech/types/index.cjs.js +121 -505
  164. package/tech/types/index.d.ts +120 -2
  165. package/tech/types/index.d.ts.map +1 -1
  166. package/tech/types/index.esm.js +99 -483
  167. package/vfs/index.cjs.js +647 -1142
  168. package/vfs/index.d.ts +360 -6
  169. package/vfs/index.d.ts.map +1 -1
  170. package/vfs/index.esm.js +672 -1167
  171. package/ARCHITECTURE.md +0 -370
  172. package/analyze.d.ts +0 -33
  173. package/analyze.d.ts.map +0 -1
  174. package/cli/commands/analyze.d.ts +0 -28
  175. package/cli/commands/analyze.d.ts.map +0 -1
  176. package/cli/commands/config.d.ts +0 -27
  177. package/cli/commands/config.d.ts.map +0 -1
  178. package/cli/commands/deps.d.ts +0 -24
  179. package/cli/commands/deps.d.ts.map +0 -1
  180. package/cli/commands/tree.d.ts +0 -36
  181. package/cli/commands/tree.d.ts.map +0 -1
  182. package/cli/index.cjs.js.map +0 -1
  183. package/cli/index.esm.js.map +0 -1
  184. package/cli/run.d.ts +0 -25
  185. package/cli/run.d.ts.map +0 -1
  186. package/cli/types.d.ts +0 -55
  187. package/cli/types.d.ts.map +0 -1
  188. package/core/cache.d.ts +0 -158
  189. package/core/cache.d.ts.map +0 -1
  190. package/core/encoding/convert.d.ts +0 -32
  191. package/core/encoding/convert.d.ts.map +0 -1
  192. package/core/encoding/detect.d.ts +0 -91
  193. package/core/encoding/detect.d.ts.map +0 -1
  194. package/core/encoding/index.cjs.js.map +0 -1
  195. package/core/encoding/index.esm.js.map +0 -1
  196. package/core/errors/structured-errors.d.ts +0 -66
  197. package/core/errors/structured-errors.d.ts.map +0 -1
  198. package/core/fs/directory.d.ts +0 -91
  199. package/core/fs/directory.d.ts.map +0 -1
  200. package/core/fs/index.cjs.js.map +0 -1
  201. package/core/fs/index.esm.js.map +0 -1
  202. package/core/fs/read.d.ts +0 -94
  203. package/core/fs/read.d.ts.map +0 -1
  204. package/core/fs/stat.d.ts +0 -58
  205. package/core/fs/stat.d.ts.map +0 -1
  206. package/core/fs/traversal.d.ts +0 -26
  207. package/core/fs/traversal.d.ts.map +0 -1
  208. package/core/fs/write.d.ts +0 -75
  209. package/core/fs/write.d.ts.map +0 -1
  210. package/core/index.cjs.js.map +0 -1
  211. package/core/index.esm.js.map +0 -1
  212. package/core/logger.d.ts +0 -111
  213. package/core/logger.d.ts.map +0 -1
  214. package/core/path/index.cjs.js.map +0 -1
  215. package/core/path/index.esm.js.map +0 -1
  216. package/core/path/join.d.ts +0 -17
  217. package/core/path/join.d.ts.map +0 -1
  218. package/core/path/normalize.d.ts +0 -37
  219. package/core/path/normalize.d.ts.map +0 -1
  220. package/core/path/resolve.d.ts +0 -52
  221. package/core/path/resolve.d.ts.map +0 -1
  222. package/core/path/segments.d.ts +0 -59
  223. package/core/path/segments.d.ts.map +0 -1
  224. package/core/patterns/glob.d.ts +0 -42
  225. package/core/patterns/glob.d.ts.map +0 -1
  226. package/core/platform/detect.d.ts +0 -66
  227. package/core/platform/detect.d.ts.map +0 -1
  228. package/core/platform/index.cjs.js.map +0 -1
  229. package/core/platform/index.esm.js.map +0 -1
  230. package/core/platform/line-endings.d.ts +0 -48
  231. package/core/platform/line-endings.d.ts.map +0 -1
  232. package/heuristics/dependencies/analyze.d.ts +0 -77
  233. package/heuristics/dependencies/analyze.d.ts.map +0 -1
  234. package/heuristics/dependencies/index.cjs.js.map +0 -1
  235. package/heuristics/dependencies/index.esm.js.map +0 -1
  236. package/heuristics/entry-points/discover.d.ts +0 -113
  237. package/heuristics/entry-points/discover.d.ts.map +0 -1
  238. package/heuristics/entry-points/index.cjs.js.map +0 -1
  239. package/heuristics/entry-points/index.esm.js.map +0 -1
  240. package/heuristics/framework/identify.d.ts +0 -84
  241. package/heuristics/framework/identify.d.ts.map +0 -1
  242. package/heuristics/framework/index.cjs.js.map +0 -1
  243. package/heuristics/framework/index.esm.js.map +0 -1
  244. package/heuristics/index.cjs.js.map +0 -1
  245. package/heuristics/index.esm.js.map +0 -1
  246. package/heuristics/project-type/detect.d.ts +0 -61
  247. package/heuristics/project-type/detect.d.ts.map +0 -1
  248. package/heuristics/project-type/index.cjs.js.map +0 -1
  249. package/heuristics/project-type/index.esm.js.map +0 -1
  250. package/index.cjs.js.map +0 -1
  251. package/index.esm.js.map +0 -1
  252. package/models/index.cjs.js.map +0 -1
  253. package/models/index.esm.js.map +0 -1
  254. package/nx/detect.d.ts +0 -105
  255. package/nx/detect.d.ts.map +0 -1
  256. package/nx/devkit-loader.d.ts +0 -62
  257. package/nx/devkit-loader.d.ts.map +0 -1
  258. package/nx/index.cjs.js.map +0 -1
  259. package/nx/index.esm.js.map +0 -1
  260. package/nx/project-config.d.ts +0 -111
  261. package/nx/project-config.d.ts.map +0 -1
  262. package/project/config/detect.d.ts +0 -77
  263. package/project/config/detect.d.ts.map +0 -1
  264. package/project/config/index.cjs.js.map +0 -1
  265. package/project/config/index.esm.js.map +0 -1
  266. package/project/config/parse.d.ts +0 -53
  267. package/project/config/parse.d.ts.map +0 -1
  268. package/project/config/patterns.d.ts +0 -31
  269. package/project/config/patterns.d.ts.map +0 -1
  270. package/project/index.cjs.js.map +0 -1
  271. package/project/index.esm.js.map +0 -1
  272. package/project/package/dependencies.d.ts +0 -101
  273. package/project/package/dependencies.d.ts.map +0 -1
  274. package/project/package/index.cjs.js.map +0 -1
  275. package/project/package/index.esm.js.map +0 -1
  276. package/project/package/read.d.ts +0 -67
  277. package/project/package/read.d.ts.map +0 -1
  278. package/project/root/detect.d.ts +0 -65
  279. package/project/root/detect.d.ts.map +0 -1
  280. package/project/root/index.cjs.js.map +0 -1
  281. package/project/root/index.esm.js.map +0 -1
  282. package/project/traversal/index.cjs.js.map +0 -1
  283. package/project/traversal/index.esm.js.map +0 -1
  284. package/project/traversal/search.d.ts +0 -59
  285. package/project/traversal/search.d.ts.map +0 -1
  286. package/project/traversal/walk.d.ts +0 -63
  287. package/project/traversal/walk.d.ts.map +0 -1
  288. package/tech/backend/detect-all.d.ts +0 -13
  289. package/tech/backend/detect-all.d.ts.map +0 -1
  290. package/tech/backend/express.d.ts +0 -11
  291. package/tech/backend/express.d.ts.map +0 -1
  292. package/tech/backend/fastify.d.ts +0 -11
  293. package/tech/backend/fastify.d.ts.map +0 -1
  294. package/tech/backend/hono.d.ts +0 -11
  295. package/tech/backend/hono.d.ts.map +0 -1
  296. package/tech/backend/index.cjs.js.map +0 -1
  297. package/tech/backend/index.esm.js.map +0 -1
  298. package/tech/backend/koa.d.ts +0 -11
  299. package/tech/backend/koa.d.ts.map +0 -1
  300. package/tech/backend/nestjs.d.ts +0 -11
  301. package/tech/backend/nestjs.d.ts.map +0 -1
  302. package/tech/backend/types.d.ts +0 -31
  303. package/tech/backend/types.d.ts.map +0 -1
  304. package/tech/build/babel.d.ts +0 -13
  305. package/tech/build/babel.d.ts.map +0 -1
  306. package/tech/build/detect-all.d.ts +0 -13
  307. package/tech/build/detect-all.d.ts.map +0 -1
  308. package/tech/build/esbuild.d.ts +0 -11
  309. package/tech/build/esbuild.d.ts.map +0 -1
  310. package/tech/build/index.cjs.js.map +0 -1
  311. package/tech/build/index.esm.js.map +0 -1
  312. package/tech/build/parcel.d.ts +0 -13
  313. package/tech/build/parcel.d.ts.map +0 -1
  314. package/tech/build/rollup.d.ts +0 -13
  315. package/tech/build/rollup.d.ts.map +0 -1
  316. package/tech/build/swc.d.ts +0 -13
  317. package/tech/build/swc.d.ts.map +0 -1
  318. package/tech/build/types.d.ts +0 -31
  319. package/tech/build/types.d.ts.map +0 -1
  320. package/tech/build/vite.d.ts +0 -13
  321. package/tech/build/vite.d.ts.map +0 -1
  322. package/tech/build/webpack.d.ts +0 -13
  323. package/tech/build/webpack.d.ts.map +0 -1
  324. package/tech/frontend/angular.d.ts +0 -11
  325. package/tech/frontend/angular.d.ts.map +0 -1
  326. package/tech/frontend/astro.d.ts +0 -11
  327. package/tech/frontend/astro.d.ts.map +0 -1
  328. package/tech/frontend/detect-all.d.ts +0 -13
  329. package/tech/frontend/detect-all.d.ts.map +0 -1
  330. package/tech/frontend/gatsby.d.ts +0 -11
  331. package/tech/frontend/gatsby.d.ts.map +0 -1
  332. package/tech/frontend/index.cjs.js.map +0 -1
  333. package/tech/frontend/index.esm.js.map +0 -1
  334. package/tech/frontend/nextjs.d.ts +0 -11
  335. package/tech/frontend/nextjs.d.ts.map +0 -1
  336. package/tech/frontend/nuxt.d.ts +0 -11
  337. package/tech/frontend/nuxt.d.ts.map +0 -1
  338. package/tech/frontend/qwik.d.ts +0 -11
  339. package/tech/frontend/qwik.d.ts.map +0 -1
  340. package/tech/frontend/react.d.ts +0 -11
  341. package/tech/frontend/react.d.ts.map +0 -1
  342. package/tech/frontend/remix.d.ts +0 -11
  343. package/tech/frontend/remix.d.ts.map +0 -1
  344. package/tech/frontend/solid.d.ts +0 -11
  345. package/tech/frontend/solid.d.ts.map +0 -1
  346. package/tech/frontend/svelte.d.ts +0 -11
  347. package/tech/frontend/svelte.d.ts.map +0 -1
  348. package/tech/frontend/sveltekit.d.ts +0 -11
  349. package/tech/frontend/sveltekit.d.ts.map +0 -1
  350. package/tech/frontend/types.d.ts +0 -35
  351. package/tech/frontend/types.d.ts.map +0 -1
  352. package/tech/frontend/vue.d.ts +0 -11
  353. package/tech/frontend/vue.d.ts.map +0 -1
  354. package/tech/index.cjs.js.map +0 -1
  355. package/tech/index.esm.js.map +0 -1
  356. package/tech/legacy/angularjs.d.ts +0 -12
  357. package/tech/legacy/angularjs.d.ts.map +0 -1
  358. package/tech/legacy/backbone.d.ts +0 -11
  359. package/tech/legacy/backbone.d.ts.map +0 -1
  360. package/tech/legacy/detect-all.d.ts +0 -13
  361. package/tech/legacy/detect-all.d.ts.map +0 -1
  362. package/tech/legacy/ember.d.ts +0 -11
  363. package/tech/legacy/ember.d.ts.map +0 -1
  364. package/tech/legacy/index.cjs.js.map +0 -1
  365. package/tech/legacy/index.esm.js.map +0 -1
  366. package/tech/legacy/jquery.d.ts +0 -11
  367. package/tech/legacy/jquery.d.ts.map +0 -1
  368. package/tech/legacy/types.d.ts +0 -33
  369. package/tech/legacy/types.d.ts.map +0 -1
  370. package/tech/linting/biome.d.ts +0 -11
  371. package/tech/linting/biome.d.ts.map +0 -1
  372. package/tech/linting/detect-all.d.ts +0 -13
  373. package/tech/linting/detect-all.d.ts.map +0 -1
  374. package/tech/linting/eslint.d.ts +0 -13
  375. package/tech/linting/eslint.d.ts.map +0 -1
  376. package/tech/linting/index.cjs.js.map +0 -1
  377. package/tech/linting/index.esm.js.map +0 -1
  378. package/tech/linting/prettier.d.ts +0 -13
  379. package/tech/linting/prettier.d.ts.map +0 -1
  380. package/tech/linting/stylelint.d.ts +0 -13
  381. package/tech/linting/stylelint.d.ts.map +0 -1
  382. package/tech/linting/types.d.ts +0 -31
  383. package/tech/linting/types.d.ts.map +0 -1
  384. package/tech/monorepo/detect-all.d.ts +0 -13
  385. package/tech/monorepo/detect-all.d.ts.map +0 -1
  386. package/tech/monorepo/index.cjs.js.map +0 -1
  387. package/tech/monorepo/index.esm.js.map +0 -1
  388. package/tech/monorepo/lerna.d.ts +0 -11
  389. package/tech/monorepo/lerna.d.ts.map +0 -1
  390. package/tech/monorepo/npm-workspaces.d.ts +0 -11
  391. package/tech/monorepo/npm-workspaces.d.ts.map +0 -1
  392. package/tech/monorepo/nx.d.ts +0 -11
  393. package/tech/monorepo/nx.d.ts.map +0 -1
  394. package/tech/monorepo/pnpm-workspaces.d.ts +0 -9
  395. package/tech/monorepo/pnpm-workspaces.d.ts.map +0 -1
  396. package/tech/monorepo/rush.d.ts +0 -11
  397. package/tech/monorepo/rush.d.ts.map +0 -1
  398. package/tech/monorepo/turborepo.d.ts +0 -11
  399. package/tech/monorepo/turborepo.d.ts.map +0 -1
  400. package/tech/monorepo/types.d.ts +0 -39
  401. package/tech/monorepo/types.d.ts.map +0 -1
  402. package/tech/monorepo/yarn-workspaces.d.ts +0 -11
  403. package/tech/monorepo/yarn-workspaces.d.ts.map +0 -1
  404. package/tech/shared-utils/detector-helpers.d.ts +0 -52
  405. package/tech/shared-utils/detector-helpers.d.ts.map +0 -1
  406. package/tech/shared-utils/types.d.ts +0 -41
  407. package/tech/shared-utils/types.d.ts.map +0 -1
  408. package/tech/testing/cypress.d.ts +0 -13
  409. package/tech/testing/cypress.d.ts.map +0 -1
  410. package/tech/testing/detect-all.d.ts +0 -13
  411. package/tech/testing/detect-all.d.ts.map +0 -1
  412. package/tech/testing/index.cjs.js.map +0 -1
  413. package/tech/testing/index.esm.js.map +0 -1
  414. package/tech/testing/jest.d.ts +0 -13
  415. package/tech/testing/jest.d.ts.map +0 -1
  416. package/tech/testing/mocha.d.ts +0 -13
  417. package/tech/testing/mocha.d.ts.map +0 -1
  418. package/tech/testing/playwright.d.ts +0 -13
  419. package/tech/testing/playwright.d.ts.map +0 -1
  420. package/tech/testing/types.d.ts +0 -35
  421. package/tech/testing/types.d.ts.map +0 -1
  422. package/tech/testing/vitest.d.ts +0 -13
  423. package/tech/testing/vitest.d.ts.map +0 -1
  424. package/tech/types/detectors.d.ts +0 -67
  425. package/tech/types/detectors.d.ts.map +0 -1
  426. package/tech/types/index.cjs.js.map +0 -1
  427. package/tech/types/index.esm.js.map +0 -1
  428. package/vfs/commit.d.ts +0 -32
  429. package/vfs/commit.d.ts.map +0 -1
  430. package/vfs/diff.d.ts +0 -73
  431. package/vfs/diff.d.ts.map +0 -1
  432. package/vfs/factory.d.ts +0 -37
  433. package/vfs/factory.d.ts.map +0 -1
  434. package/vfs/fs-tree.d.ts +0 -13
  435. package/vfs/fs-tree.d.ts.map +0 -1
  436. package/vfs/index.cjs.js.map +0 -1
  437. package/vfs/index.esm.js.map +0 -1
  438. package/vfs/types.d.ts +0 -179
  439. package/vfs/types.d.ts.map +0 -1
package/vfs/index.cjs.js CHANGED
@@ -1,427 +1,27 @@
1
1
  'use strict';
2
2
 
3
- var node_fs = require('node:fs');
4
- var node_path = require('node:path');
5
-
6
- /**
7
- * Safe copies of Error built-ins via factory functions.
8
- *
9
- * Since constructors cannot be safely captured via Object.assign, this module
10
- * provides factory functions that use Reflect.construct internally.
11
- *
12
- * These references are captured at module initialization time to protect against
13
- * prototype pollution attacks. Import only what you need for tree-shaking.
14
- *
15
- * @module @hyperfrontend/immutable-api-utils/built-in-copy/error
16
- */
17
- const _Error = globalThis.Error;
18
- const _Reflect$2 = globalThis.Reflect;
19
- /**
20
- * (Safe copy) Creates a new Error using the captured Error constructor.
21
- * Use this instead of `new Error()`.
22
- *
23
- * @param message - Optional error message.
24
- * @param options - Optional error options.
25
- * @returns A new Error instance.
26
- */
27
- const createError = (message, options) => _Reflect$2.construct(_Error, [message, options]);
28
-
29
- /**
30
- * Safe copies of JSON built-in methods.
31
- *
32
- * These references are captured at module initialization time to protect against
33
- * prototype pollution attacks. Import only what you need for tree-shaking.
34
- *
35
- * @module @hyperfrontend/immutable-api-utils/built-in-copy/json
36
- */
37
- const _JSON = globalThis.JSON;
38
- /**
39
- * (Safe copy) Converts a JavaScript value to a JavaScript Object Notation (JSON) string.
40
- */
41
- const stringify = _JSON.stringify;
42
-
43
- /**
44
- * Safe copies of Object built-in methods.
45
- *
46
- * These references are captured at module initialization time to protect against
47
- * prototype pollution attacks. Import only what you need for tree-shaking.
48
- *
49
- * @module @hyperfrontend/immutable-api-utils/built-in-copy/object
50
- */
51
- const _Object = globalThis.Object;
52
- /**
53
- * (Safe copy) Prevents modification of existing property attributes and values,
54
- * and prevents the addition of new properties.
55
- */
56
- const freeze = _Object.freeze;
57
- /**
58
- * (Safe copy) Returns the names of the enumerable string properties and methods of an object.
59
- */
60
- const keys = _Object.keys;
61
- /**
62
- * (Safe copy) Returns an array of key/values of the enumerable own properties of an object.
63
- */
64
- const entries = _Object.entries;
65
- /**
66
- * (Safe copy) Adds one or more properties to an object, and/or modifies attributes of existing properties.
67
- */
68
- const defineProperties = _Object.defineProperties;
69
-
70
- /**
71
- * Safe copies of Array built-in static methods.
72
- *
73
- * These references are captured at module initialization time to protect against
74
- * prototype pollution attacks. Import only what you need for tree-shaking.
75
- *
76
- * @module @hyperfrontend/immutable-api-utils/built-in-copy/array
77
- */
78
- const _Array = globalThis.Array;
79
- /**
80
- * (Safe copy) Determines whether the passed value is an Array.
81
- */
82
- const isArray = _Array.isArray;
83
- /**
84
- * (Safe copy) Creates an array from an array-like or iterable object.
85
- */
86
- const from = _Array.from;
87
-
88
- /**
89
- * Safe copies of Console built-in methods.
90
- *
91
- * These references are captured at module initialization time to protect against
92
- * prototype pollution attacks. Import only what you need for tree-shaking.
93
- *
94
- * @module @hyperfrontend/immutable-api-utils/built-in-copy/console
95
- */
96
- const _console = globalThis.console;
97
- /**
98
- * (Safe copy) Outputs a message to the console.
99
- */
100
- const log = _console.log.bind(_console);
101
- /**
102
- * (Safe copy) Outputs a warning message to the console.
103
- */
104
- const warn = _console.warn.bind(_console);
105
- /**
106
- * (Safe copy) Outputs an error message to the console.
107
- */
108
- const error = _console.error.bind(_console);
109
- /**
110
- * (Safe copy) Outputs an informational message to the console.
111
- */
112
- const info = _console.info.bind(_console);
113
- /**
114
- * (Safe copy) Outputs a debug message to the console.
115
- */
116
- const debug = _console.debug.bind(_console);
117
- /**
118
- * (Safe copy) Outputs a stack trace to the console.
119
- */
120
- _console.trace.bind(_console);
121
- /**
122
- * (Safe copy) Displays an interactive listing of the properties of a specified object.
123
- */
124
- _console.dir.bind(_console);
125
- /**
126
- * (Safe copy) Displays tabular data as a table.
127
- */
128
- _console.table.bind(_console);
129
- /**
130
- * (Safe copy) Writes an error message to the console if the assertion is false.
131
- */
132
- _console.assert.bind(_console);
133
- /**
134
- * (Safe copy) Clears the console.
135
- */
136
- _console.clear.bind(_console);
137
- /**
138
- * (Safe copy) Logs the number of times that this particular call to count() has been called.
139
- */
140
- _console.count.bind(_console);
141
- /**
142
- * (Safe copy) Resets the counter used with console.count().
143
- */
144
- _console.countReset.bind(_console);
145
- /**
146
- * (Safe copy) Creates a new inline group in the console.
147
- */
148
- _console.group.bind(_console);
149
- /**
150
- * (Safe copy) Creates a new inline group in the console that is initially collapsed.
151
- */
152
- _console.groupCollapsed.bind(_console);
153
- /**
154
- * (Safe copy) Exits the current inline group.
155
- */
156
- _console.groupEnd.bind(_console);
157
- /**
158
- * (Safe copy) Starts a timer with a name specified as an input parameter.
159
- */
160
- _console.time.bind(_console);
161
- /**
162
- * (Safe copy) Stops a timer that was previously started.
163
- */
164
- _console.timeEnd.bind(_console);
165
- /**
166
- * (Safe copy) Logs the current value of a timer that was previously started.
167
- */
168
- _console.timeLog.bind(_console);
169
-
170
- /**
171
- * Safe copies of Set built-in via factory function.
172
- *
173
- * Since constructors cannot be safely captured via Object.assign, this module
174
- * provides a factory function that uses Reflect.construct internally.
175
- *
176
- * These references are captured at module initialization time to protect against
177
- * prototype pollution attacks. Import only what you need for tree-shaking.
178
- *
179
- * @module @hyperfrontend/immutable-api-utils/built-in-copy/set
180
- */
181
- const _Set = globalThis.Set;
182
- const _Reflect$1 = globalThis.Reflect;
183
- /**
184
- * (Safe copy) Creates a new Set using the captured Set constructor.
185
- * Use this instead of `new Set()`.
186
- *
187
- * @param iterable - Optional iterable of values.
188
- * @returns A new Set instance.
189
- */
190
- const createSet = (iterable) => _Reflect$1.construct(_Set, iterable ? [iterable] : []);
191
-
192
- const registeredClasses = [];
193
-
194
- /**
195
- * Returns the data type of the target.
196
- * Uses native `typeof` operator, however, makes distinction between `null`, `array`, and `object`.
197
- * Also, when classes are registered via `registerClass`, it checks if objects are instance of any known registered class.
198
- *
199
- * @param target - The target to get the data type of.
200
- * @returns The data type of the target.
201
- */
202
- const getType = (target) => {
203
- if (target === null)
204
- return 'null';
205
- const nativeDataType = typeof target;
206
- if (nativeDataType === 'object') {
207
- if (isArray(target))
208
- return 'array';
209
- for (const registeredClass of registeredClasses) {
210
- if (target instanceof registeredClass)
211
- return registeredClass.name;
212
- }
213
- }
214
- return nativeDataType;
215
- };
216
-
217
- /**
218
- * Safe copies of Map built-in via factory function.
219
- *
220
- * Since constructors cannot be safely captured via Object.assign, this module
221
- * provides a factory function that uses Reflect.construct internally.
222
- *
223
- * These references are captured at module initialization time to protect against
224
- * prototype pollution attacks. Import only what you need for tree-shaking.
225
- *
226
- * @module @hyperfrontend/immutable-api-utils/built-in-copy/map
227
- */
228
- const _Map = globalThis.Map;
229
- const _Reflect = globalThis.Reflect;
230
- /**
231
- * (Safe copy) Creates a new Map using the captured Map constructor.
232
- * Use this instead of `new Map()`.
233
- *
234
- * @param iterable - Optional iterable of key-value pairs.
235
- * @returns A new Map instance.
236
- */
237
- const createMap = (iterable) => _Reflect.construct(_Map, iterable ? [iterable] : []);
238
-
239
- /**
240
- * Safe copies of Math built-in methods.
241
- *
242
- * These references are captured at module initialization time to protect against
243
- * prototype pollution attacks. Import only what you need for tree-shaking.
244
- *
245
- * @module @hyperfrontend/immutable-api-utils/built-in-copy/math
246
- */
247
- const _Math = globalThis.Math;
248
- /**
249
- * (Safe copy) Returns the larger of zero or more numbers.
250
- */
251
- const max = _Math.max;
252
- /**
253
- * (Safe copy) Returns the smaller of zero or more numbers.
254
- */
255
- const min = _Math.min;
256
-
257
- /* eslint-disable @typescript-eslint/no-explicit-any */
258
- /**
259
- * Creates a wrapper function that only executes the wrapped function if the condition function returns true.
260
- *
261
- * @param func - The function to be conditionally executed.
262
- * @param conditionFunc - A function that returns a boolean, determining if `func` should be executed.
263
- * @returns A wrapped version of `func` that executes conditionally.
264
- */
265
- function createConditionalExecutionFunction(func, conditionFunc) {
266
- return function (...args) {
267
- if (conditionFunc()) {
268
- return func(...args);
269
- }
270
- };
271
- }
272
-
273
- /* eslint-disable @typescript-eslint/no-explicit-any */
274
- /**
275
- * Creates a wrapper function that silently ignores any errors thrown by the wrapped void function.
276
- * This function is specifically for wrapping functions that do not return a value (void functions).
277
- * Exceptions are swallowed without any logging or handling.
278
- *
279
- * @param func - The void function to be wrapped.
280
- * @returns A wrapped version of the input function that ignores errors.
281
- */
282
- function createErrorIgnoringFunction(func) {
283
- return function (...args) {
284
- try {
285
- func(...args);
286
- }
287
- catch {
288
- // Deliberately swallowing/ignoring the exception
289
- }
290
- };
291
- }
292
-
293
- /* eslint-disable @typescript-eslint/no-unused-vars */
294
- /**
295
- * A no-operation function (noop) that does nothing regardless of the arguments passed.
296
- * It is designed to be as permissive as possible in its typing without using the `Function` keyword.
297
- *
298
- * @param args - Any arguments passed to the function (ignored)
299
- */
300
- const noop = (...args) => {
301
- // Intentionally does nothing
302
- };
303
-
304
- const logLevels = ['none', 'error', 'warn', 'log', 'info', 'debug'];
305
- const priority = {
306
- error: 4,
307
- warn: 3,
308
- log: 2,
309
- info: 1,
310
- debug: 0,
311
- };
312
- /**
313
- * Validates whether a given string is a valid log level.
314
- *
315
- * @param level - The log level to validate
316
- * @returns True if the level is valid, false otherwise
317
- */
318
- function isValidLogLevel(level) {
319
- return logLevels.includes(level);
320
- }
321
- /**
322
- * Creates a log level configuration manager for controlling logging behavior.
323
- * Provides methods to get, set, and evaluate log levels based on priority.
324
- *
325
- * @param level - The initial log level (defaults to 'error')
326
- * @returns A configuration object with log level management methods
327
- * @throws {Error} When the provided level is not a valid log level
328
- */
329
- function createLogLevelConfig(level = 'error') {
330
- if (!isValidLogLevel(level)) {
331
- throw createError('Cannot create log level configuration with a valid default log level');
332
- }
333
- const state = { level };
334
- const getLogLevel = () => state.level;
335
- const setLogLevel = (level) => {
336
- if (!isValidLogLevel(level)) {
337
- throw createError(`Cannot set value '${level}' level. Expected levels are ${logLevels}.`);
338
- }
339
- state.level = level;
340
- };
341
- const shouldLog = (level) => {
342
- if (state.level === 'none' || level === 'none' || !isValidLogLevel(level)) {
343
- return false;
344
- }
345
- return priority[level] >= priority[state.level];
346
- };
347
- return freeze({
348
- getLogLevel,
349
- setLogLevel,
350
- shouldLog,
351
- });
352
- }
353
-
354
- /**
355
- * Creates a logger instance with configurable log level filtering.
356
- * Each log function is wrapped to respect the current log level setting.
357
- *
358
- * @param error - Function to handle error-level logs (required)
359
- * @param warn - Function to handle warning-level logs (optional, defaults to noop)
360
- * @param log - Function to handle standard logs (optional, defaults to noop)
361
- * @param info - Function to handle info-level logs (optional, defaults to noop)
362
- * @param debug - Function to handle debug-level logs (optional, defaults to noop)
363
- * @returns A frozen logger object with log methods and level control
364
- * @throws {ErrorLevelFn} When any provided log function is invalid
365
- */
366
- function createLogger(error, warn = noop, log = noop, info = noop, debug = noop) {
367
- if (notValidLogFn(error)) {
368
- throw createError(notFnMsg('error'));
369
- }
370
- if (notValidLogFn(warn)) {
371
- throw createError(notFnMsg('warn'));
372
- }
373
- if (notValidLogFn(log)) {
374
- throw createError(notFnMsg('log'));
375
- }
376
- if (notValidLogFn(info)) {
377
- throw createError(notFnMsg('info'));
378
- }
379
- if (notValidLogFn(debug)) {
380
- throw createError(notFnMsg('debug'));
381
- }
382
- const { setLogLevel, getLogLevel, shouldLog } = createLogLevelConfig();
383
- const wrapLogFn = (fn, level) => {
384
- if (fn === noop)
385
- return fn;
386
- const condition = () => shouldLog(level);
387
- return createConditionalExecutionFunction(createErrorIgnoringFunction(fn), condition);
388
- };
389
- return freeze({
390
- error: wrapLogFn(error, 'error'),
391
- warn: wrapLogFn(warn, 'warn'),
392
- log: wrapLogFn(log, 'log'),
393
- info: wrapLogFn(info, 'info'),
394
- debug: wrapLogFn(debug, 'debug'),
395
- setLogLevel,
396
- getLogLevel,
397
- });
398
- }
399
- /**
400
- * Validates whether a given value is a valid log function.
401
- *
402
- * @param fn - The value to validate
403
- * @returns True if the value is not a function (invalid), false if it is valid
404
- */
405
- function notValidLogFn(fn) {
406
- return getType(fn) !== 'function' && fn !== noop;
407
- }
408
- /**
409
- * Generates an error message for invalid log function parameters.
410
- *
411
- * @param label - The name of the log function that failed validation
412
- * @returns A formatted error message string
413
- */
414
- function notFnMsg(label) {
415
- return `Cannot create a logger when ${label} is not a function`;
416
- }
417
-
418
- createLogger(error, warn, log, info, debug);
3
+ const node_fs = require('node:fs');
4
+ const node_path = require('node:path');
5
+ const index_cjs_js$6 = require('../_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/error/index.cjs.js');
6
+ const index_cjs_js$4 = require('../_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/array/index.cjs.js');
7
+ const index_cjs_js$3 = require('../_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/console/index.cjs.js');
8
+ const index_cjs_js$5 = require('../_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/json/index.cjs.js');
9
+ const index_cjs_js$2 = require('../_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/object/index.cjs.js');
10
+ const index_cjs_js = require('../_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/set/index.cjs.js');
11
+ const index_cjs_js$1 = require('../_dependencies/@hyperfrontend/logging/index.cjs.js');
12
+ const index_cjs_js$7 = require('../_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/math/index.cjs.js');
13
+ const index_cjs_js$8 = require('../_dependencies/@hyperfrontend/immutable-api-utils/built-in-copy/map/index.cjs.js');
14
+ const { isFile, isDirectory, exists } = require('../_shared/core/fs/stat/index.cjs.js');
15
+ const { normalizePath, removeTrailingSlash } = require('../_shared/core/path/normalize/index.cjs.js');
16
+ const { resolvePath, relativePath, joinPath, isAbsolute } = require('../_shared/core/path/resolve/index.cjs.js');
17
+ const { getDirname } = require('../_shared/core/path/segments/index.cjs.js');
18
+ const { Mode } = require('../_shared/vfs/types/index.cjs.js');
419
19
 
420
20
  /**
421
21
  * Global log level registry.
422
22
  * Tracks all created scoped loggers to allow global log level changes.
423
23
  */
424
- const loggerRegistry = createSet();
24
+ const loggerRegistry = index_cjs_js.createSet();
425
25
  /** Redacted placeholder for sensitive values */
426
26
  const REDACTED = '[REDACTED]';
427
27
  /**
@@ -455,17 +55,24 @@ function isSensitiveKey(key) {
455
55
  *
456
56
  * @param obj - Object to sanitize
457
57
  * @returns New object with sensitive values redacted
58
+ *
59
+ * @example Sanitizing sensitive data
60
+ * ```typescript
61
+ * const config = { apiKey: 'secret123', endpoint: 'https://api.example.com' }
62
+ * const safe = sanitize(config)
63
+ * // => { apiKey: '[REDACTED]', endpoint: 'https://api.example.com' }
64
+ * ```
458
65
  */
459
66
  function sanitize(obj) {
460
67
  if (obj === null || obj === undefined) {
461
68
  return obj;
462
69
  }
463
- if (isArray(obj)) {
70
+ if (index_cjs_js$4.isArray(obj)) {
464
71
  return obj.map((item) => sanitize(item));
465
72
  }
466
73
  if (typeof obj === 'object') {
467
74
  const result = {};
468
- for (const [key, value] of entries(obj)) {
75
+ for (const [key, value] of index_cjs_js$2.entries(obj)) {
469
76
  if (isSensitiveKey(key)) {
470
77
  result[key] = REDACTED;
471
78
  }
@@ -490,9 +97,9 @@ function sanitize(obj) {
490
97
  */
491
98
  function formatMessage(namespace, message, meta) {
492
99
  const prefix = `[${namespace}]`;
493
- if (meta && keys(meta).length > 0) {
100
+ if (meta && index_cjs_js$2.keys(meta).length > 0) {
494
101
  const sanitizedMeta = sanitize(meta);
495
- return `${prefix} ${message} ${stringify(sanitizedMeta)}`;
102
+ return `${prefix} ${message} ${index_cjs_js$5.stringify(sanitizedMeta)}`;
496
103
  }
497
104
  return `${prefix} ${message}`;
498
105
  }
@@ -505,7 +112,7 @@ function formatMessage(namespace, message, meta) {
505
112
  * @param options - Logger configuration options
506
113
  * @returns A configured scoped logger instance
507
114
  *
508
- * @example
115
+ * @example Creating a scoped logger
509
116
  * ```typescript
510
117
  * const logger = createScopedLogger('project-scope')
511
118
  * logger.setLogLevel('debug')
@@ -524,9 +131,9 @@ function createScopedLogger(namespace, options = {}) {
524
131
  const processedMeta = sanitizeSecrets && meta ? sanitize(meta) : meta;
525
132
  baseFn(formatMessage(namespace, message, processedMeta));
526
133
  };
527
- const baseLogger = createLogger(createLogFn(error), createLogFn(warn), createLogFn(log), createLogFn(info), createLogFn(debug));
134
+ const baseLogger = index_cjs_js$1.createLogger(createLogFn(index_cjs_js$3.error), createLogFn(index_cjs_js$3.warn), createLogFn(index_cjs_js$3.log), createLogFn(index_cjs_js$3.info), createLogFn(index_cjs_js$3.debug));
528
135
  baseLogger.setLogLevel(level);
529
- const scopedLogger = freeze({
136
+ const scopedLogger = index_cjs_js$2.freeze({
530
137
  error: (message, meta) => baseLogger.error(message, meta),
531
138
  warn: (message, meta) => baseLogger.warn(message, meta),
532
139
  log: (message, meta) => baseLogger.log(message, meta),
@@ -542,7 +149,7 @@ function createScopedLogger(namespace, options = {}) {
542
149
  * Default logger instance for the project-scope library.
543
150
  * Use this for general logging within the library.
544
151
  *
545
- * @example
152
+ * @example Using the default logger
546
153
  * ```typescript
547
154
  * import { logger } from '@hyperfrontend/project-scope/core'
548
155
  *
@@ -560,87 +167,25 @@ createScopedLogger('project-scope:fs');
560
167
  * @param code - The category code for this type of filesystem failure
561
168
  * @param context - Additional context including path, operation, and cause
562
169
  * @returns A configured Error object with code and context properties
170
+ *
171
+ * @example Creating a file system error
172
+ * ```typescript
173
+ * throw createFileSystemError(
174
+ * 'Cannot read file',
175
+ * 'FS_READ_ERROR',
176
+ * { path: './missing.txt', operation: 'read' }
177
+ * )
178
+ * ```
563
179
  */
564
180
  function createFileSystemError(message, code, context) {
565
- const error = createError(message);
566
- defineProperties(error, {
181
+ const error = index_cjs_js$6.createError(message);
182
+ index_cjs_js$2.defineProperties(error, {
567
183
  code: { value: code, enumerable: true },
568
184
  context: { value: context, enumerable: true },
569
185
  });
570
186
  return error;
571
187
  }
572
188
 
573
- const fsWriteLogger = createScopedLogger('project-scope:fs:write');
574
- /**
575
- * Ensure directory exists, create recursively if not.
576
- *
577
- * @param dirPath - Directory path to ensure exists
578
- */
579
- function ensureDir(dirPath) {
580
- if (!node_fs.existsSync(dirPath)) {
581
- fsWriteLogger.debug('Creating directory recursively', { path: dirPath });
582
- node_fs.mkdirSync(dirPath, { recursive: true });
583
- }
584
- }
585
-
586
- /**
587
- * Get file stats with error handling.
588
- *
589
- * @param filePath - Path to file
590
- * @param followSymlinks - Whether to follow symlinks (default: true)
591
- * @returns File stats or null if path doesn't exist
592
- */
593
- function getFileStat(filePath, followSymlinks = true) {
594
- if (!node_fs.existsSync(filePath)) {
595
- return null;
596
- }
597
- try {
598
- const stat = followSymlinks ? node_fs.statSync(filePath) : node_fs.lstatSync(filePath);
599
- return {
600
- isFile: stat.isFile(),
601
- isDirectory: stat.isDirectory(),
602
- isSymlink: stat.isSymbolicLink(),
603
- size: stat.size,
604
- created: stat.birthtime,
605
- modified: stat.mtime,
606
- accessed: stat.atime,
607
- mode: stat.mode,
608
- };
609
- }
610
- catch {
611
- return null;
612
- }
613
- }
614
- /**
615
- * Check if path is a file.
616
- *
617
- * @param filePath - Path to check
618
- * @returns True if path is a file
619
- */
620
- function isFile(filePath) {
621
- const stats = getFileStat(filePath);
622
- return stats?.isFile ?? false;
623
- }
624
- /**
625
- * Check if path is a directory.
626
- *
627
- * @param dirPath - Path to check
628
- * @returns True if path is a directory
629
- */
630
- function isDirectory(dirPath) {
631
- const stats = getFileStat(dirPath);
632
- return stats?.isDirectory ?? false;
633
- }
634
- /**
635
- * Check if path exists.
636
- *
637
- * @param filePath - Path to check
638
- * @returns True if path exists
639
- */
640
- function exists(filePath) {
641
- return node_fs.existsSync(filePath);
642
- }
643
-
644
189
  const fsDirLogger = createScopedLogger('project-scope:fs:dir');
645
190
  /**
646
191
  * List immediate contents of a directory.
@@ -649,7 +194,7 @@ const fsDirLogger = createScopedLogger('project-scope:fs:dir');
649
194
  * @returns Array of entries with metadata for each file/directory
650
195
  * @throws {Error} If directory doesn't exist or isn't a directory
651
196
  *
652
- * @example
197
+ * @example Listing directory contents
653
198
  * ```typescript
654
199
  * import { readDirectory } from '@hyperfrontend/project-scope'
655
200
  *
@@ -690,189 +235,522 @@ function readDirectory(dirPath) {
690
235
  }
691
236
  }
692
237
 
238
+ createScopedLogger('project-scope:fs:traversal');
239
+
240
+ const fsWriteLogger = createScopedLogger('project-scope:fs:write');
693
241
  /**
694
- * Normalize path separators to forward slashes.
242
+ * Ensure directory exists, create recursively if not.
695
243
  *
696
- * @param filePath - Path to normalize
697
- * @returns Normalized path with forward slashes
698
- */
699
- function normalizePath(filePath) {
700
- if (!filePath)
701
- return '';
702
- const normalized = node_path.normalize(filePath);
703
- return node_path.sep === '\\' ? normalized.replace(/\\/g, '/') : normalized;
704
- }
705
- /**
706
- * Strip any trailing forward or back slashes from a path.
244
+ * @param dirPath - Directory path to ensure exists
707
245
  *
708
- * @param filePath - Path that may have trailing slashes
709
- * @returns Path with trailing slashes removed
246
+ * @example Ensuring directory exists
247
+ * ```typescript
248
+ * ensureDir('./output/reports')
249
+ * // Directory now exists (created if missing)
250
+ * ```
710
251
  */
711
- function removeTrailingSlash(filePath) {
712
- let i = filePath.length;
713
- while (i > 0 && (filePath[i - 1] === '/' || filePath[i - 1] === '\\')) {
714
- i--;
252
+ function ensureDir(dirPath) {
253
+ if (!node_fs.existsSync(dirPath)) {
254
+ fsWriteLogger.debug('Creating directory recursively', { path: dirPath });
255
+ node_fs.mkdirSync(dirPath, { recursive: true });
715
256
  }
716
- return filePath.slice(0, i);
717
257
  }
718
258
 
259
+ const vfsLogger = createScopedLogger('project-scope:vfs');
719
260
  /**
720
- * Resolve path segments to an absolute path.
261
+ * Commit buffered changes to disk.
721
262
  *
722
- * @param segments - Path segments to resolve
723
- * @returns Resolved absolute path with normalized separators
724
- */
725
- function resolvePath(...segments) {
726
- return normalizePath(node_path.resolve(...segments));
727
- }
728
- /**
729
- * Compute the normalized path from source directory to target.
263
+ * @param tree - Virtual file system tree with pending modifications
264
+ * @param options - Configuration for dry-run and verbosity
265
+ * @returns Result of the commit operation
730
266
  *
731
- * @param from - Source path (base directory)
732
- * @param to - Target path to reach
733
- * @returns Relative path from source to target with forward slashes
734
- */
735
- function relativePath(from, to) {
736
- return normalizePath(node_path.relative(from, to));
737
- }
738
- /**
739
- * Join path segments.
267
+ * @example Committing changes to disk
268
+ * ```typescript
269
+ * import { createTree, commitChanges } from '@hyperfrontend/project-scope'
740
270
  *
741
- * @param segments - Path segments to join
742
- * @returns Joined path with normalized separators
743
- */
744
- function joinPath(...segments) {
745
- return normalizePath(node_path.join(...segments));
746
- }
747
- /**
748
- * Check if path is absolute.
271
+ * const tree = createTree('./my-project')
272
+ * tree.write('src/new-file.ts', 'export const hello = "world"')
749
273
  *
750
- * @param filePath - Path to check
751
- * @returns True if path is absolute
752
- */
753
- function isAbsolute(filePath) {
754
- return node_path.isAbsolute(filePath);
755
- }
756
-
757
- /**
758
- * Get directory name of path.
274
+ * // Preview changes without writing
275
+ * const preview = commitChanges(tree, { dryRun: true })
276
+ * console.log('Would create:', preview.created, 'files')
759
277
  *
760
- * @param filePath - Path to extract directory from
761
- * @returns Directory name
278
+ * // Actually commit changes
279
+ * const result = commitChanges(tree)
280
+ * console.log('Created:', result.created, 'Updated:', result.updated)
281
+ * ```
762
282
  */
763
- function getDirname(filePath) {
764
- return normalizePath(node_path.dirname(filePath));
283
+ function commitChanges(tree, options) {
284
+ const changes = tree.listChanges();
285
+ const appliedChanges = [];
286
+ if (options?.verbose) {
287
+ vfsLogger.setLogLevel('debug');
288
+ }
289
+ vfsLogger.debug('Committing changes', { changeCount: changes.length, dryRun: options?.dryRun });
290
+ const result = {
291
+ created: 0,
292
+ updated: 0,
293
+ deleted: 0,
294
+ changes: [],
295
+ dryRun: options?.dryRun ?? false,
296
+ };
297
+ if (options?.dryRun) {
298
+ for (const change of changes) {
299
+ switch (change.type) {
300
+ case 'CREATE':
301
+ result.created++;
302
+ break;
303
+ case 'UPDATE':
304
+ result.updated++;
305
+ break;
306
+ case 'DELETE':
307
+ result.deleted++;
308
+ break;
309
+ }
310
+ }
311
+ result.changes = changes;
312
+ return result;
313
+ }
314
+ const sortedChanges = [...changes].sort((a, b) => {
315
+ const order = { DELETE: 0, CREATE: 1, UPDATE: 2 };
316
+ return order[a.type] - order[b.type];
317
+ });
318
+ for (const change of sortedChanges) {
319
+ const absPath = node_path.join(tree.root, change.path);
320
+ try {
321
+ switch (change.type) {
322
+ case 'CREATE':
323
+ case 'UPDATE':
324
+ /* istanbul ignore if -- content is always defined for CREATE/UPDATE from tree.write() */
325
+ if (change.content !== undefined) {
326
+ const dir = node_path.dirname(absPath);
327
+ ensureDir(dir);
328
+ node_fs.writeFileSync(absPath, change.content);
329
+ if (change.mode !== undefined) {
330
+ node_fs.chmodSync(absPath, change.mode);
331
+ }
332
+ if (change.type === 'CREATE') {
333
+ result.created++;
334
+ }
335
+ else {
336
+ result.updated++;
337
+ }
338
+ }
339
+ break;
340
+ case 'DELETE':
341
+ if (exists(absPath)) {
342
+ try {
343
+ node_fs.unlinkSync(absPath);
344
+ }
345
+ catch {
346
+ node_fs.rmSync(absPath, { recursive: true });
347
+ }
348
+ }
349
+ result.deleted++;
350
+ break;
351
+ }
352
+ appliedChanges.push(change);
353
+ if (options?.verbose) {
354
+ const prefix = change.type === 'CREATE' ? '+' : change.type === 'DELETE' ? '-' : '~';
355
+ vfsLogger.info(`${prefix} ${change.path}`);
356
+ }
357
+ }
358
+ catch (error) {
359
+ vfsLogger.error('Commit failed', { path: change.path, type: change.type });
360
+ const message = error instanceof Error
361
+ ? `Failed to ${change.type.toLowerCase()} ${change.path}: ${error.message}`
362
+ : `Failed to ${change.type.toLowerCase()} ${change.path}`;
363
+ throw index_cjs_js$6.createError(message);
364
+ }
365
+ }
366
+ result.changes = appliedChanges;
367
+ tree.clearChanges();
368
+ return result;
765
369
  }
766
-
767
- createScopedLogger('project-scope:fs:traversal');
768
-
769
370
  /**
770
- * Write mode for file operations.
371
+ * Discard all pending changes.
372
+ *
373
+ * @param tree - Virtual file system tree
374
+ *
375
+ * @example Rolling back pending changes
376
+ * ```typescript
377
+ * import { createTree, rollbackChanges } from '@hyperfrontend/project-scope'
378
+ *
379
+ * const tree = createTree('/workspace')
380
+ * tree.write('new-file.ts', 'content')
381
+ * // Decide to abort - discard all pending changes
382
+ * rollbackChanges(tree)
383
+ * ```
771
384
  */
772
- const Mode = freeze({
773
- /** Overwrite existing files */
774
- Overwrite: 'overwrite',
775
- /** Fail if file exists */
776
- ExclusiveCreate: 'exclusive',
777
- /** Skip if file exists */
778
- SkipIfExists: 'skip',
779
- });
385
+ function rollbackChanges(tree) {
386
+ tree.clearChanges();
387
+ }
780
388
 
781
- const fsTreeLogger = createScopedLogger('project-scope:vfs:tree');
389
+ const diffLogger = createScopedLogger('project-scope:vfs:diff');
390
+ const DEFAULT_CONTEXT_LINES = 3;
782
391
  /**
783
- * Create a file system-backed tree implementation.
784
- *
785
- * Supports transactional modifications - all changes are buffered
786
- * in memory and can be committed atomically or rolled back.
392
+ * Compute the Longest Common Subsequence (LCS) table for two arrays of lines.
393
+ * Uses dynamic programming for O(n*m) time complexity.
787
394
  *
788
- * @param root - Absolute path to the workspace root directory
789
- * @param options - Configuration for verbose logging
790
- * @returns A Tree instance
395
+ * @param oldLines - Lines from the original file version
396
+ * @param newLines - Lines from the new file version
397
+ * @returns Two-dimensional LCS table for backtracking
791
398
  */
792
- function createFsTree(root, options) {
793
- const _root = removeTrailingSlash(normalizePath(root));
794
- const _changes = createMap();
795
- const _isVerbose = options?.verbose ?? false;
796
- const _followSymlinks = options?.followSymlinks ?? true;
797
- fsTreeLogger.debug('Creating VFS tree', { root: _root, verbose: _isVerbose, followSymlinks: _followSymlinks });
798
- /**
799
- * Normalize path to be relative from root.
800
- *
801
- * @param filePath - Path to normalize
802
- * @returns Normalized relative path
803
- * @throws {Error} if path traverses outside the tree root
804
- */
805
- function normalizeFilePath(filePath) {
806
- const normalized = isAbsolute(filePath) ? relativePath(_root, filePath) : normalizePath(filePath);
807
- const absoluteResolved = resolvePath(_root, normalized);
808
- if (!absoluteResolved.startsWith(_root + '/') && absoluteResolved !== _root) {
809
- throw createError(`Path escapes tree root: ${filePath}`);
399
+ function computeLcsTable(oldLines, newLines) {
400
+ const m = oldLines.length;
401
+ const n = newLines.length;
402
+ const table = index_cjs_js$4.from({ length: m + 1 }, () => Array(n + 1).fill(0));
403
+ for (let i = 1; i <= m; i++) {
404
+ for (let j = 1; j <= n; j++) {
405
+ if (oldLines[i - 1] === newLines[j - 1]) {
406
+ table[i][j] = table[i - 1][j - 1] + 1;
407
+ }
408
+ else {
409
+ table[i][j] = index_cjs_js$7.max(table[i - 1][j], table[i][j - 1]);
410
+ }
810
411
  }
811
- return normalized;
812
- }
813
- /**
814
- * Get absolute path on disk.
815
- *
816
- * @param filePath - Relative path from root
817
- * @returns Absolute path on disk
818
- */
819
- function absolutePath(filePath) {
820
- return joinPath(_root, normalizeFilePath(filePath));
821
412
  }
822
- /**
823
- * Check if a normalized path is a symbolic link.
824
- *
825
- * @param normalPath - Already normalized path
826
- * @returns True if path is a symlink
827
- */
828
- function isSymlinkNormalizedPath(normalPath) {
829
- const absPath = absolutePath(normalPath);
830
- try {
831
- const stats = node_fs.lstatSync(absPath);
832
- return stats.isSymbolicLink();
413
+ return table;
414
+ }
415
+ /**
416
+ * Backtrack through LCS table to produce diff operations.
417
+ *
418
+ * @param table - Two-dimensional LCS table from computeLcsTable
419
+ * @param oldLines - Lines from the original file version
420
+ * @param newLines - Lines from the new file version
421
+ * @returns Array of diff operations (unfiltered, includes all lines)
422
+ */
423
+ function backtrackLcs(table, oldLines, newLines) {
424
+ const result = [];
425
+ let i = oldLines.length;
426
+ let j = newLines.length;
427
+ while (i > 0 || j > 0) {
428
+ if (i > 0 && j > 0 && oldLines[i - 1] === newLines[j - 1]) {
429
+ result.unshift({ type: 'same', oldIdx: i - 1, newIdx: j - 1, content: oldLines[i - 1] });
430
+ i--;
431
+ j--;
833
432
  }
834
- catch {
835
- return false;
433
+ else if (j > 0 && (i === 0 || table[i][j - 1] >= table[i - 1][j])) {
434
+ result.unshift({ type: 'add', oldIdx: i - 1, newIdx: j - 1, content: newLines[j - 1] });
435
+ j--;
836
436
  }
837
- }
838
- /**
839
- * Validate that a symlink target stays within tree bounds.
840
- *
841
- * @param normalPath - Already normalized path to symlink
842
- * @throws {Error} If symlink target escapes tree root or followSymlinks is disabled
843
- */
844
- function validateSymlink(normalPath) {
845
- const absPath = absolutePath(normalPath);
846
- if (!isSymlinkNormalizedPath(normalPath)) {
847
- return;
437
+ else {
438
+ result.unshift({ type: 'remove', oldIdx: i - 1, newIdx: -1, content: oldLines[i - 1] });
439
+ i--;
848
440
  }
849
- if (!_followSymlinks) {
850
- throw createError(`Cannot access symlink when followSymlinks is disabled: ${normalPath}`);
441
+ }
442
+ return result;
443
+ }
444
+ /**
445
+ * Convert raw diff operations to DiffLine array with context filtering.
446
+ *
447
+ * @param operations - Raw diff operations
448
+ * @param contextLines - Number of context lines to include
449
+ * @returns Filtered DiffLine array
450
+ */
451
+ function operationsToDiffLines(operations, contextLines) {
452
+ const include = new Array(operations.length).fill(false);
453
+ for (let i = 0; i < operations.length; i++) {
454
+ if (operations[i].type !== 'same') {
455
+ for (let j = index_cjs_js$7.max(0, i - contextLines); j <= index_cjs_js$7.min(operations.length - 1, i + contextLines); j++) {
456
+ include[j] = true;
457
+ }
851
458
  }
852
- try {
853
- const target = node_fs.readlinkSync(absPath);
854
- let targetAbsolute;
855
- if (isAbsolute(target)) {
856
- targetAbsolute = target;
459
+ }
460
+ const lines = [];
461
+ let oldLineNum = 1;
462
+ let newLineNum = 1;
463
+ for (let i = 0; i < operations.length; i++) {
464
+ const op = operations[i];
465
+ if (include[i]) {
466
+ if (op.type === 'same') {
467
+ lines.push({ type: 'context', line: oldLineNum, content: op.content });
468
+ oldLineNum++;
469
+ newLineNum++;
857
470
  }
858
- else {
859
- const symlinkDir = getDirname(absPath);
860
- targetAbsolute = resolvePath(symlinkDir, target);
471
+ else if (op.type === 'remove') {
472
+ lines.push({ type: 'remove', line: oldLineNum, content: op.content });
473
+ oldLineNum++;
861
474
  }
862
- const normalizedTarget = normalizePath(targetAbsolute);
863
- if (!normalizedTarget.startsWith(_root + '/') && normalizedTarget !== _root) {
864
- throw createError(`Symlink target escapes tree root: ${normalPath} -> ${target}`);
475
+ else {
476
+ lines.push({ type: 'add', line: newLineNum, content: op.content });
477
+ newLineNum++;
865
478
  }
866
479
  }
867
- catch (error) {
868
- /* istanbul ignore else -- other errors are rare edge cases (e.g., permission denied) */
869
- if (error instanceof Error && error.message.includes('Symlink target escapes')) {
870
- throw error;
480
+ else {
481
+ if (op.type === 'same') {
482
+ oldLineNum++;
483
+ newLineNum++;
871
484
  }
872
- if (error instanceof Error && error.message.includes('followSymlinks is disabled')) {
873
- throw error;
485
+ else if (op.type === 'remove') {
486
+ /* istanbul ignore next -- unreachable: remove operations always have include=true */
487
+ oldLineNum++;
874
488
  }
875
- throw createError(`Failed to validate symlink: ${normalPath}`);
489
+ else {
490
+ /* istanbul ignore next -- unreachable: add operations always have include=true */
491
+ newLineNum++;
492
+ }
493
+ }
494
+ }
495
+ return lines;
496
+ }
497
+ /**
498
+ * Split buffer content into lines.
499
+ *
500
+ * @param content - File content as Buffer, or undefined for empty
501
+ * @returns Array of string lines from the buffer
502
+ */
503
+ function bufferToLines(content) {
504
+ if (!content)
505
+ return [];
506
+ const text = content.toString('utf-8');
507
+ return text.split('\n');
508
+ }
509
+ /**
510
+ * Generate a diff for a single file change.
511
+ *
512
+ * @example Generating a diff for a file change
513
+ * ```typescript
514
+ * const change: FileChange = {
515
+ * path: 'src/app.ts',
516
+ * type: 'UPDATE',
517
+ * originalContent: Buffer.from('const x = 1;\n'),
518
+ * content: Buffer.from('const x = 2;\n'),
519
+ * }
520
+ * const diff = generateDiff(change)
521
+ * // { path: 'src/app.ts', additions: 1, deletions: 1, lines: [...] }
522
+ * ```
523
+ *
524
+ * @param change - File change to diff
525
+ * @param options - Configuration for diff generation including context lines
526
+ * @returns FileDiff object
527
+ */
528
+ function generateDiff(change, options = {}) {
529
+ const contextLines = options.contextLines ?? DEFAULT_CONTEXT_LINES;
530
+ diffLogger.debug('generateDiff', { path: change.path, type: change.type, contextLines });
531
+ const oldLines = bufferToLines(change.originalContent);
532
+ const newLines = bufferToLines(change.content);
533
+ if (change.type === 'CREATE') {
534
+ const lines = newLines
535
+ .filter((line) => line !== '' || newLines.indexOf(line) !== newLines.length - 1 || newLines.length === 1)
536
+ .map((content, idx) => ({
537
+ type: 'add',
538
+ line: idx + 1,
539
+ content,
540
+ }));
541
+ const filteredLines = lines.filter((l, i) => !(i === lines.length - 1 && l.content === '' && lines.length > 1));
542
+ return {
543
+ path: change.path,
544
+ lines: filteredLines,
545
+ additions: filteredLines.length,
546
+ deletions: 0,
547
+ };
548
+ }
549
+ if (change.type === 'DELETE') {
550
+ const lines = oldLines.map((content, idx) => ({
551
+ type: 'remove',
552
+ line: idx + 1,
553
+ content,
554
+ }));
555
+ const filteredLines = lines.filter((l, i) => !(i === lines.length - 1 && l.content === '' && lines.length > 1));
556
+ return {
557
+ path: change.path,
558
+ lines: filteredLines,
559
+ additions: 0,
560
+ deletions: filteredLines.length,
561
+ };
562
+ }
563
+ const table = computeLcsTable(oldLines, newLines);
564
+ const operations = backtrackLcs(table, oldLines, newLines);
565
+ const lines = operationsToDiffLines(operations, contextLines);
566
+ const additions = lines.filter((l) => l.type === 'add').length;
567
+ const deletions = lines.filter((l) => l.type === 'remove').length;
568
+ return {
569
+ path: change.path,
570
+ lines,
571
+ additions,
572
+ deletions,
573
+ };
574
+ }
575
+ /**
576
+ * Format a FileDiff as a unified diff string.
577
+ *
578
+ * @example Formatting a unified diff
579
+ * ```typescript
580
+ * const formatted = formatUnifiedDiff(diff)
581
+ * console.log(formatted)
582
+ * // --- a/src/app.ts
583
+ * // +++ b/src/app.ts
584
+ * // @@ -1,3 +1,3 @@
585
+ * // const x = 1;
586
+ * // -const y = 2;
587
+ * // +const y = 3;
588
+ * // const z = 4;
589
+ * ```
590
+ *
591
+ * @param diff - FileDiff to format
592
+ * @returns Unified diff string
593
+ */
594
+ function formatUnifiedDiff(diff) {
595
+ const lines = [];
596
+ lines.push(`--- a/${diff.path}`);
597
+ lines.push(`+++ b/${diff.path}`);
598
+ if (diff.lines.length === 0) {
599
+ return lines.join('\n');
600
+ }
601
+ const hunks = [];
602
+ const currentHunk = [];
603
+ for (const line of diff.lines) {
604
+ currentHunk.push(line);
605
+ }
606
+ if (currentHunk.length > 0) {
607
+ hunks.push(currentHunk);
608
+ }
609
+ for (const hunk of hunks) {
610
+ const contextAndRemove = hunk.filter((l) => l.type === 'context' || l.type === 'remove');
611
+ const contextAndAdd = hunk.filter((l) => l.type === 'context' || l.type === 'add');
612
+ const oldStart = hunk.find((l) => l.type === 'context' || l.type === 'remove')?.line ?? 1;
613
+ const newStart = hunk.find((l) => l.type === 'context' || l.type === 'add')?.line ?? 1;
614
+ const oldCount = contextAndRemove.length;
615
+ const newCount = contextAndAdd.length;
616
+ lines.push(`@@ -${oldStart},${oldCount} +${newStart},${newCount} @@`);
617
+ for (const line of hunk) {
618
+ const prefix = line.type === 'add' ? '+' : line.type === 'remove' ? '-' : ' ';
619
+ lines.push(`${prefix}${line.content}`);
620
+ }
621
+ }
622
+ return lines.join('\n');
623
+ }
624
+ /**
625
+ * Generate diffs for all changes in a tree.
626
+ *
627
+ * @example Generating diffs for all changes
628
+ * ```typescript
629
+ * const tree = createTree('/workspace')
630
+ * tree.write('new.txt', 'hello')
631
+ * tree.delete('old.txt')
632
+ *
633
+ * const diffs = generateAllDiffs(tree)
634
+ * for (const diff of diffs) {
635
+ * console.log(formatUnifiedDiff(diff))
636
+ * }
637
+ * ```
638
+ *
639
+ * @param tree - Tree to generate diffs for
640
+ * @param options - Diff options
641
+ * @returns Array of FileDiff objects
642
+ */
643
+ function generateAllDiffs(tree, options = {}) {
644
+ const changes = tree.listChanges();
645
+ diffLogger.debug('generateAllDiffs', { changeCount: changes.length });
646
+ return changes.map((change) => generateDiff(change, options));
647
+ }
648
+
649
+ const fsTreeLogger = createScopedLogger('project-scope:vfs:tree');
650
+ /**
651
+ * Create a file system-backed tree implementation.
652
+ *
653
+ * Supports transactional modifications - all changes are buffered
654
+ * in memory and can be committed atomically or rolled back.
655
+ *
656
+ * @param root - Absolute path to the workspace root directory
657
+ * @param options - Configuration for verbose logging
658
+ * @returns A Tree instance
659
+ *
660
+ * @example Creating and using a file system tree
661
+ * ```typescript
662
+ * import { createFsTree, commitChanges } from '@hyperfrontend/project-scope'
663
+ *
664
+ * const tree = createFsTree('/workspace')
665
+ * tree.write('src/new-file.ts', 'export const value = 42')
666
+ * tree.delete('old-file.ts')
667
+ * commitChanges(tree) // Atomically apply all changes to disk
668
+ * ```
669
+ */
670
+ function createFsTree(root, options) {
671
+ const _root = removeTrailingSlash(normalizePath(root));
672
+ const _changes = index_cjs_js$8.createMap();
673
+ const _isVerbose = options?.verbose ?? false;
674
+ const _followSymlinks = options?.followSymlinks ?? true;
675
+ fsTreeLogger.debug('Creating VFS tree', { root: _root, verbose: _isVerbose, followSymlinks: _followSymlinks });
676
+ /**
677
+ * Normalize path to be relative from root.
678
+ *
679
+ * @param filePath - Path to normalize
680
+ * @returns Normalized relative path
681
+ * @throws {Error} if path traverses outside the tree root
682
+ */
683
+ function normalizeFilePath(filePath) {
684
+ const normalized = isAbsolute(filePath) ? relativePath(_root, filePath) : normalizePath(filePath);
685
+ const absoluteResolved = resolvePath(_root, normalized);
686
+ if (!absoluteResolved.startsWith(_root + '/') && absoluteResolved !== _root) {
687
+ throw index_cjs_js$6.createError(`Path escapes tree root: ${filePath}`);
688
+ }
689
+ return normalized;
690
+ }
691
+ /**
692
+ * Get absolute path on disk.
693
+ *
694
+ * @param filePath - Relative path from root
695
+ * @returns Absolute path on disk
696
+ */
697
+ function absolutePath(filePath) {
698
+ return joinPath(_root, normalizeFilePath(filePath));
699
+ }
700
+ /**
701
+ * Check if a normalized path is a symbolic link.
702
+ *
703
+ * @param normalPath - Already normalized path
704
+ * @returns True if path is a symlink
705
+ */
706
+ function isSymlinkNormalizedPath(normalPath) {
707
+ const absPath = absolutePath(normalPath);
708
+ try {
709
+ const stats = node_fs.lstatSync(absPath);
710
+ return stats.isSymbolicLink();
711
+ }
712
+ catch {
713
+ return false;
714
+ }
715
+ }
716
+ /**
717
+ * Validate that a symlink target stays within tree bounds.
718
+ *
719
+ * @param normalPath - Already normalized path to symlink
720
+ * @throws {Error} If symlink target escapes tree root or followSymlinks is disabled
721
+ */
722
+ function validateSymlink(normalPath) {
723
+ const absPath = absolutePath(normalPath);
724
+ if (!isSymlinkNormalizedPath(normalPath)) {
725
+ return;
726
+ }
727
+ if (!_followSymlinks) {
728
+ throw index_cjs_js$6.createError(`Cannot access symlink when followSymlinks is disabled: ${normalPath}`);
729
+ }
730
+ try {
731
+ const target = node_fs.readlinkSync(absPath);
732
+ let targetAbsolute;
733
+ if (isAbsolute(target)) {
734
+ targetAbsolute = target;
735
+ }
736
+ else {
737
+ const symlinkDir = getDirname(absPath);
738
+ targetAbsolute = resolvePath(symlinkDir, target);
739
+ }
740
+ const normalizedTarget = normalizePath(targetAbsolute);
741
+ if (!normalizedTarget.startsWith(_root + '/') && normalizedTarget !== _root) {
742
+ throw index_cjs_js$6.createError(`Symlink target escapes tree root: ${normalPath} -> ${target}`);
743
+ }
744
+ }
745
+ catch (error) {
746
+ /* istanbul ignore else -- other errors are rare edge cases (e.g., permission denied) */
747
+ if (error instanceof Error && error.message.includes('Symlink target escapes')) {
748
+ throw error;
749
+ }
750
+ if (error instanceof Error && error.message.includes('followSymlinks is disabled')) {
751
+ throw error;
752
+ }
753
+ throw index_cjs_js$6.createError(`Failed to validate symlink: ${normalPath}`);
876
754
  }
877
755
  }
878
756
  /**
@@ -942,7 +820,7 @@ function createFsTree(root, options) {
942
820
  fsTreeLogger.debug('write', { path: normalPath, size: buffer.length, mode: options?.mode ?? 'Overwrite' });
943
821
  const mode = options?.mode ?? Mode.Overwrite;
944
822
  if (mode === Mode.ExclusiveCreate && this.exists(normalPath)) {
945
- throw createError(`File already exists: ${normalPath}`);
823
+ throw index_cjs_js$6.createError(`File already exists: ${normalPath}`);
946
824
  }
947
825
  if (mode === Mode.SkipIfExists && this.exists(normalPath)) {
948
826
  return;
@@ -998,7 +876,7 @@ function createFsTree(root, options) {
998
876
  rename(from, to) {
999
877
  const content = this.read(from);
1000
878
  if (content === null) {
1001
- throw createError(`Source file not found: ${from}`);
879
+ throw index_cjs_js$6.createError(`Source file not found: ${from}`);
1002
880
  }
1003
881
  this.write(to, content);
1004
882
  this.delete(from);
@@ -1028,523 +906,151 @@ function createFsTree(root, options) {
1028
906
  },
1029
907
  children(dirPath) {
1030
908
  const normalPath = normalizeFilePath(dirPath);
1031
- const childSet = createSet();
909
+ const childSet = index_cjs_js.createSet();
1032
910
  const absPath = absolutePath(normalPath);
1033
911
  try {
1034
- if (exists(absPath) && isDirectory(absPath)) {
1035
- const entries = readDirectory(absPath);
1036
- for (const entry of entries) {
1037
- childSet.add(entry.name);
1038
- }
1039
- }
1040
- }
1041
- catch {
1042
- // Directory doesn't exist on disk
1043
- }
1044
- const prefix = normalPath === '.' || normalPath === '' ? '' : normalPath + '/';
1045
- for (const [changedPath, change] of _changes) {
1046
- if (prefix === '') {
1047
- const childName = changedPath.split('/')[0];
1048
- if (change.type === 'DELETE' && !changedPath.includes('/')) {
1049
- childSet.delete(childName);
1050
- }
1051
- else if (change.type !== 'DELETE') {
1052
- childSet.add(childName);
1053
- }
1054
- continue;
1055
- }
1056
- if (!changedPath.startsWith(prefix)) {
1057
- continue;
1058
- }
1059
- const relativePath = changedPath.slice(prefix.length);
1060
- const childName = relativePath.split('/')[0];
1061
- if (change.type === 'DELETE') {
1062
- if (!relativePath.includes('/')) {
1063
- childSet.delete(childName);
1064
- }
1065
- }
1066
- else {
1067
- childSet.add(childName);
1068
- }
1069
- }
1070
- return from(childSet).sort();
1071
- },
1072
- listChanges() {
1073
- const changes = [];
1074
- for (const [path, record] of _changes) {
1075
- changes.push({
1076
- path,
1077
- type: record.type,
1078
- content: record.content ?? undefined,
1079
- originalContent: record.originalContent ?? undefined,
1080
- mode: record.permissions,
1081
- });
1082
- }
1083
- return changes.sort((a, b) => a.path.localeCompare(b.path));
1084
- },
1085
- changePermissions(filePath, mode) {
1086
- const normalPath = normalizeFilePath(filePath);
1087
- if (!this.exists(normalPath)) {
1088
- throw createError(`File not found: ${normalPath}`);
1089
- }
1090
- const existingChange = _changes.get(normalPath);
1091
- if (existingChange) {
1092
- existingChange.permissions = mode;
1093
- }
1094
- else {
1095
- const content = readFromDisk(normalPath);
1096
- _changes.set(normalPath, {
1097
- type: 'UPDATE',
1098
- content,
1099
- originalContent: content,
1100
- permissions: mode,
1101
- });
1102
- }
1103
- },
1104
- changeFile(filePath, transform) {
1105
- const content = this.read(filePath);
1106
- if (content === null) {
1107
- throw createError(`File not found: ${filePath}`);
1108
- }
1109
- const newContent = transform(content);
1110
- this.write(filePath, newContent);
1111
- },
1112
- clearChanges() {
1113
- _changes.clear();
1114
- },
1115
- };
1116
- return tree;
1117
- }
1118
-
1119
- const factoryLogger = createScopedLogger('project-scope:vfs:factory');
1120
- /**
1121
- * Create a virtual file system tree.
1122
- *
1123
- * @param root - Root directory path
1124
- * @param options - Tree creation options
1125
- * @returns A new Tree instance
1126
- * @throws {Error} If root doesn't exist or isn't a directory
1127
- *
1128
- * @example
1129
- * ```typescript
1130
- * import { createTree } from '@hyperfrontend/project-scope'
1131
- *
1132
- * const tree = createTree('./my-project')
1133
- *
1134
- * // Read files from tree
1135
- * const content = tree.read('src/index.ts', 'utf-8')
1136
- *
1137
- * // Make changes (buffered in memory)
1138
- * tree.write('src/new-file.ts', 'export const x = 1')
1139
- *
1140
- * // List pending changes
1141
- * console.log(tree.listChanges())
1142
- * ```
1143
- */
1144
- function createTree(root, options) {
1145
- const normalizedRoot = normalizePath(root);
1146
- factoryLogger.debug('createTree', { root: normalizedRoot });
1147
- if (!exists(normalizedRoot)) {
1148
- factoryLogger.warn('createTree failed: root does not exist', { root: normalizedRoot });
1149
- throw createError(`Root directory does not exist: ${normalizedRoot}`);
1150
- }
1151
- if (!isDirectory(normalizedRoot)) {
1152
- factoryLogger.warn('createTree failed: root is not a directory', { root: normalizedRoot });
1153
- throw createError(`Root path is not a directory: ${normalizedRoot}`);
1154
- }
1155
- return createFsTree(normalizedRoot, options);
1156
- }
1157
- /**
1158
- * Create a tree from disk.
1159
- *
1160
- * Convenience alias for createTree.
1161
- *
1162
- * @param root - Root directory path
1163
- * @param options - Tree creation options
1164
- * @returns A new Tree instance backed by disk
1165
- */
1166
- function createTreeFromDisk(root, options) {
1167
- return createTree(root, options);
1168
- }
1169
-
1170
- const vfsLogger = createScopedLogger('project-scope:vfs');
1171
- /**
1172
- * Commit buffered changes to disk.
1173
- *
1174
- * @param tree - Virtual file system tree with pending modifications
1175
- * @param options - Configuration for dry-run and verbosity
1176
- * @returns Result of the commit operation
1177
- *
1178
- * @example
1179
- * ```typescript
1180
- * import { createTree, commitChanges } from '@hyperfrontend/project-scope'
1181
- *
1182
- * const tree = createTree('./my-project')
1183
- * tree.write('src/new-file.ts', 'export const hello = "world"')
1184
- *
1185
- * // Preview changes without writing
1186
- * const preview = commitChanges(tree, { dryRun: true })
1187
- * console.log('Would create:', preview.created, 'files')
1188
- *
1189
- * // Actually commit changes
1190
- * const result = commitChanges(tree)
1191
- * console.log('Created:', result.created, 'Updated:', result.updated)
1192
- * ```
1193
- */
1194
- function commitChanges(tree, options) {
1195
- const changes = tree.listChanges();
1196
- const appliedChanges = [];
1197
- if (options?.verbose) {
1198
- vfsLogger.setLogLevel('debug');
1199
- }
1200
- vfsLogger.debug('Committing changes', { changeCount: changes.length, dryRun: options?.dryRun });
1201
- const result = {
1202
- created: 0,
1203
- updated: 0,
1204
- deleted: 0,
1205
- changes: [],
1206
- dryRun: options?.dryRun ?? false,
1207
- };
1208
- if (options?.dryRun) {
1209
- for (const change of changes) {
1210
- switch (change.type) {
1211
- case 'CREATE':
1212
- result.created++;
1213
- break;
1214
- case 'UPDATE':
1215
- result.updated++;
1216
- break;
1217
- case 'DELETE':
1218
- result.deleted++;
1219
- break;
1220
- }
1221
- }
1222
- result.changes = changes;
1223
- return result;
1224
- }
1225
- const sortedChanges = [...changes].sort((a, b) => {
1226
- const order = { DELETE: 0, CREATE: 1, UPDATE: 2 };
1227
- return order[a.type] - order[b.type];
1228
- });
1229
- for (const change of sortedChanges) {
1230
- const absPath = node_path.join(tree.root, change.path);
1231
- try {
1232
- switch (change.type) {
1233
- case 'CREATE':
1234
- case 'UPDATE':
1235
- /* istanbul ignore if -- content is always defined for CREATE/UPDATE from tree.write() */
1236
- if (change.content !== undefined) {
1237
- const dir = node_path.dirname(absPath);
1238
- ensureDir(dir);
1239
- node_fs.writeFileSync(absPath, change.content);
1240
- if (change.mode !== undefined) {
1241
- node_fs.chmodSync(absPath, change.mode);
1242
- }
1243
- if (change.type === 'CREATE') {
1244
- result.created++;
1245
- }
1246
- else {
1247
- result.updated++;
1248
- }
1249
- }
1250
- break;
1251
- case 'DELETE':
1252
- if (exists(absPath)) {
1253
- try {
1254
- node_fs.unlinkSync(absPath);
1255
- }
1256
- catch {
1257
- node_fs.rmSync(absPath, { recursive: true });
1258
- }
1259
- }
1260
- result.deleted++;
1261
- break;
1262
- }
1263
- appliedChanges.push(change);
1264
- if (options?.verbose) {
1265
- const prefix = change.type === 'CREATE' ? '+' : change.type === 'DELETE' ? '-' : '~';
1266
- vfsLogger.info(`${prefix} ${change.path}`);
1267
- }
1268
- }
1269
- catch (error) {
1270
- vfsLogger.error('Commit failed', { path: change.path, type: change.type });
1271
- const message = error instanceof Error
1272
- ? `Failed to ${change.type.toLowerCase()} ${change.path}: ${error.message}`
1273
- : `Failed to ${change.type.toLowerCase()} ${change.path}`;
1274
- throw createError(message);
1275
- }
1276
- }
1277
- result.changes = appliedChanges;
1278
- tree.clearChanges();
1279
- return result;
1280
- }
1281
- /**
1282
- * Discard all pending changes.
1283
- *
1284
- * @param tree - Virtual file system tree
1285
- */
1286
- function rollbackChanges(tree) {
1287
- tree.clearChanges();
1288
- }
1289
-
1290
- const diffLogger = createScopedLogger('project-scope:vfs:diff');
1291
- const DEFAULT_CONTEXT_LINES = 3;
1292
- /**
1293
- * Compute the Longest Common Subsequence (LCS) table for two arrays of lines.
1294
- * Uses dynamic programming for O(n*m) time complexity.
1295
- *
1296
- * @param oldLines - Lines from the original file version
1297
- * @param newLines - Lines from the new file version
1298
- * @returns Two-dimensional LCS table for backtracking
1299
- */
1300
- function computeLcsTable(oldLines, newLines) {
1301
- const m = oldLines.length;
1302
- const n = newLines.length;
1303
- const table = from({ length: m + 1 }, () => Array(n + 1).fill(0));
1304
- for (let i = 1; i <= m; i++) {
1305
- for (let j = 1; j <= n; j++) {
1306
- if (oldLines[i - 1] === newLines[j - 1]) {
1307
- table[i][j] = table[i - 1][j - 1] + 1;
1308
- }
1309
- else {
1310
- table[i][j] = max(table[i - 1][j], table[i][j - 1]);
1311
- }
1312
- }
1313
- }
1314
- return table;
1315
- }
1316
- /**
1317
- * Backtrack through LCS table to produce diff operations.
1318
- *
1319
- * @param table - Two-dimensional LCS table from computeLcsTable
1320
- * @param oldLines - Lines from the original file version
1321
- * @param newLines - Lines from the new file version
1322
- * @returns Array of diff operations (unfiltered, includes all lines)
1323
- */
1324
- function backtrackLcs(table, oldLines, newLines) {
1325
- const result = [];
1326
- let i = oldLines.length;
1327
- let j = newLines.length;
1328
- while (i > 0 || j > 0) {
1329
- if (i > 0 && j > 0 && oldLines[i - 1] === newLines[j - 1]) {
1330
- result.unshift({ type: 'same', oldIdx: i - 1, newIdx: j - 1, content: oldLines[i - 1] });
1331
- i--;
1332
- j--;
1333
- }
1334
- else if (j > 0 && (i === 0 || table[i][j - 1] >= table[i - 1][j])) {
1335
- result.unshift({ type: 'add', oldIdx: i - 1, newIdx: j - 1, content: newLines[j - 1] });
1336
- j--;
1337
- }
1338
- else {
1339
- result.unshift({ type: 'remove', oldIdx: i - 1, newIdx: -1, content: oldLines[i - 1] });
1340
- i--;
1341
- }
1342
- }
1343
- return result;
1344
- }
1345
- /**
1346
- * Convert raw diff operations to DiffLine array with context filtering.
1347
- *
1348
- * @param operations - Raw diff operations
1349
- * @param contextLines - Number of context lines to include
1350
- * @returns Filtered DiffLine array
1351
- */
1352
- function operationsToDiffLines(operations, contextLines) {
1353
- const include = new Array(operations.length).fill(false);
1354
- for (let i = 0; i < operations.length; i++) {
1355
- if (operations[i].type !== 'same') {
1356
- for (let j = max(0, i - contextLines); j <= min(operations.length - 1, i + contextLines); j++) {
1357
- include[j] = true;
1358
- }
1359
- }
1360
- }
1361
- const lines = [];
1362
- let oldLineNum = 1;
1363
- let newLineNum = 1;
1364
- for (let i = 0; i < operations.length; i++) {
1365
- const op = operations[i];
1366
- if (include[i]) {
1367
- if (op.type === 'same') {
1368
- lines.push({ type: 'context', line: oldLineNum, content: op.content });
1369
- oldLineNum++;
1370
- newLineNum++;
912
+ if (exists(absPath) && isDirectory(absPath)) {
913
+ const entries = readDirectory(absPath);
914
+ for (const entry of entries) {
915
+ childSet.add(entry.name);
916
+ }
917
+ }
1371
918
  }
1372
- else if (op.type === 'remove') {
1373
- lines.push({ type: 'remove', line: oldLineNum, content: op.content });
1374
- oldLineNum++;
919
+ catch {
920
+ // Directory doesn't exist on disk
1375
921
  }
1376
- else {
1377
- lines.push({ type: 'add', line: newLineNum, content: op.content });
1378
- newLineNum++;
922
+ const prefix = normalPath === '.' || normalPath === '' ? '' : normalPath + '/';
923
+ for (const [changedPath, change] of _changes) {
924
+ if (prefix === '') {
925
+ const childName = changedPath.split('/')[0];
926
+ if (change.type === 'DELETE' && !changedPath.includes('/')) {
927
+ childSet.delete(childName);
928
+ }
929
+ else if (change.type !== 'DELETE') {
930
+ childSet.add(childName);
931
+ }
932
+ continue;
933
+ }
934
+ if (!changedPath.startsWith(prefix)) {
935
+ continue;
936
+ }
937
+ const relativePath = changedPath.slice(prefix.length);
938
+ const childName = relativePath.split('/')[0];
939
+ if (change.type === 'DELETE') {
940
+ if (!relativePath.includes('/')) {
941
+ childSet.delete(childName);
942
+ }
943
+ }
944
+ else {
945
+ childSet.add(childName);
946
+ }
1379
947
  }
1380
- }
1381
- else {
1382
- if (op.type === 'same') {
1383
- oldLineNum++;
1384
- newLineNum++;
948
+ return index_cjs_js$4.from(childSet).sort();
949
+ },
950
+ listChanges() {
951
+ const changes = [];
952
+ for (const [path, record] of _changes) {
953
+ changes.push({
954
+ path,
955
+ type: record.type,
956
+ content: record.content ?? undefined,
957
+ originalContent: record.originalContent ?? undefined,
958
+ mode: record.permissions,
959
+ });
1385
960
  }
1386
- else if (op.type === 'remove') {
1387
- /* istanbul ignore next -- unreachable: remove operations always have include=true */
1388
- oldLineNum++;
961
+ return changes.sort((a, b) => a.path.localeCompare(b.path));
962
+ },
963
+ changePermissions(filePath, mode) {
964
+ const normalPath = normalizeFilePath(filePath);
965
+ if (!this.exists(normalPath)) {
966
+ throw index_cjs_js$6.createError(`File not found: ${normalPath}`);
967
+ }
968
+ const existingChange = _changes.get(normalPath);
969
+ if (existingChange) {
970
+ existingChange.permissions = mode;
1389
971
  }
1390
972
  else {
1391
- /* istanbul ignore next -- unreachable: add operations always have include=true */
1392
- newLineNum++;
973
+ const content = readFromDisk(normalPath);
974
+ _changes.set(normalPath, {
975
+ type: 'UPDATE',
976
+ content,
977
+ originalContent: content,
978
+ permissions: mode,
979
+ });
1393
980
  }
1394
- }
1395
- }
1396
- return lines;
981
+ },
982
+ changeFile(filePath, transform) {
983
+ const content = this.read(filePath);
984
+ if (content === null) {
985
+ throw index_cjs_js$6.createError(`File not found: ${filePath}`);
986
+ }
987
+ const newContent = transform(content);
988
+ this.write(filePath, newContent);
989
+ },
990
+ clearChanges() {
991
+ _changes.clear();
992
+ },
993
+ };
994
+ return tree;
1397
995
  }
996
+
997
+ const factoryLogger = createScopedLogger('project-scope:vfs:factory');
1398
998
  /**
1399
- * Split buffer content into lines.
999
+ * Create a virtual file system tree.
1400
1000
  *
1401
- * @param content - File content as Buffer, or undefined for empty
1402
- * @returns Array of string lines from the buffer
1403
- */
1404
- function bufferToLines(content) {
1405
- if (!content)
1406
- return [];
1407
- const text = content.toString('utf-8');
1408
- return text.split('\n');
1409
- }
1410
- /**
1411
- * Generate a diff for a single file change.
1001
+ * @param root - Root directory path
1002
+ * @param options - Tree creation options
1003
+ * @returns A new Tree instance
1004
+ * @throws {Error} If root doesn't exist or isn't a directory
1412
1005
  *
1413
- * @example
1006
+ * @example Creating a virtual tree
1414
1007
  * ```typescript
1415
- * const change: FileChange = {
1416
- * path: 'src/app.ts',
1417
- * type: 'UPDATE',
1418
- * originalContent: Buffer.from('const x = 1;\n'),
1419
- * content: Buffer.from('const x = 2;\n'),
1420
- * }
1421
- * const diff = generateDiff(change)
1422
- * // { path: 'src/app.ts', additions: 1, deletions: 1, lines: [...] }
1423
- * ```
1008
+ * import { createTree } from '@hyperfrontend/project-scope'
1424
1009
  *
1425
- * @param change - File change to diff
1426
- * @param options - Configuration for diff generation including context lines
1427
- * @returns FileDiff object
1428
- */
1429
- function generateDiff(change, options = {}) {
1430
- const contextLines = options.contextLines ?? DEFAULT_CONTEXT_LINES;
1431
- diffLogger.debug('generateDiff', { path: change.path, type: change.type, contextLines });
1432
- const oldLines = bufferToLines(change.originalContent);
1433
- const newLines = bufferToLines(change.content);
1434
- if (change.type === 'CREATE') {
1435
- const lines = newLines
1436
- .filter((line) => line !== '' || newLines.indexOf(line) !== newLines.length - 1 || newLines.length === 1)
1437
- .map((content, idx) => ({
1438
- type: 'add',
1439
- line: idx + 1,
1440
- content,
1441
- }));
1442
- const filteredLines = lines.filter((l, i) => !(i === lines.length - 1 && l.content === '' && lines.length > 1));
1443
- return {
1444
- path: change.path,
1445
- lines: filteredLines,
1446
- additions: filteredLines.length,
1447
- deletions: 0,
1448
- };
1449
- }
1450
- if (change.type === 'DELETE') {
1451
- const lines = oldLines.map((content, idx) => ({
1452
- type: 'remove',
1453
- line: idx + 1,
1454
- content,
1455
- }));
1456
- const filteredLines = lines.filter((l, i) => !(i === lines.length - 1 && l.content === '' && lines.length > 1));
1457
- return {
1458
- path: change.path,
1459
- lines: filteredLines,
1460
- additions: 0,
1461
- deletions: filteredLines.length,
1462
- };
1463
- }
1464
- const table = computeLcsTable(oldLines, newLines);
1465
- const operations = backtrackLcs(table, oldLines, newLines);
1466
- const lines = operationsToDiffLines(operations, contextLines);
1467
- const additions = lines.filter((l) => l.type === 'add').length;
1468
- const deletions = lines.filter((l) => l.type === 'remove').length;
1469
- return {
1470
- path: change.path,
1471
- lines,
1472
- additions,
1473
- deletions,
1474
- };
1475
- }
1476
- /**
1477
- * Format a FileDiff as a unified diff string.
1010
+ * const tree = createTree('./my-project')
1478
1011
  *
1479
- * @example
1480
- * ```typescript
1481
- * const formatted = formatUnifiedDiff(diff)
1482
- * console.log(formatted)
1483
- * // --- a/src/app.ts
1484
- * // +++ b/src/app.ts
1485
- * // @@ -1,3 +1,3 @@
1486
- * // const x = 1;
1487
- * // -const y = 2;
1488
- * // +const y = 3;
1489
- * // const z = 4;
1490
- * ```
1012
+ * // Read files from tree
1013
+ * const content = tree.read('src/index.ts', 'utf-8')
1491
1014
  *
1492
- * @param diff - FileDiff to format
1493
- * @returns Unified diff string
1015
+ * // Make changes (buffered in memory)
1016
+ * tree.write('src/new-file.ts', 'export const x = 1')
1017
+ *
1018
+ * // List pending changes
1019
+ * console.log(tree.listChanges())
1020
+ * ```
1494
1021
  */
1495
- function formatUnifiedDiff(diff) {
1496
- const lines = [];
1497
- lines.push(`--- a/${diff.path}`);
1498
- lines.push(`+++ b/${diff.path}`);
1499
- if (diff.lines.length === 0) {
1500
- return lines.join('\n');
1501
- }
1502
- const hunks = [];
1503
- const currentHunk = [];
1504
- for (const line of diff.lines) {
1505
- currentHunk.push(line);
1506
- }
1507
- if (currentHunk.length > 0) {
1508
- hunks.push(currentHunk);
1022
+ function createTree(root, options) {
1023
+ const normalizedRoot = normalizePath(root);
1024
+ factoryLogger.debug('createTree', { root: normalizedRoot });
1025
+ if (!exists(normalizedRoot)) {
1026
+ factoryLogger.warn('createTree failed: root does not exist', { root: normalizedRoot });
1027
+ throw index_cjs_js$6.createError(`Root directory does not exist: ${normalizedRoot}`);
1509
1028
  }
1510
- for (const hunk of hunks) {
1511
- const contextAndRemove = hunk.filter((l) => l.type === 'context' || l.type === 'remove');
1512
- const contextAndAdd = hunk.filter((l) => l.type === 'context' || l.type === 'add');
1513
- const oldStart = hunk.find((l) => l.type === 'context' || l.type === 'remove')?.line ?? 1;
1514
- const newStart = hunk.find((l) => l.type === 'context' || l.type === 'add')?.line ?? 1;
1515
- const oldCount = contextAndRemove.length;
1516
- const newCount = contextAndAdd.length;
1517
- lines.push(`@@ -${oldStart},${oldCount} +${newStart},${newCount} @@`);
1518
- for (const line of hunk) {
1519
- const prefix = line.type === 'add' ? '+' : line.type === 'remove' ? '-' : ' ';
1520
- lines.push(`${prefix}${line.content}`);
1521
- }
1029
+ if (!isDirectory(normalizedRoot)) {
1030
+ factoryLogger.warn('createTree failed: root is not a directory', { root: normalizedRoot });
1031
+ throw index_cjs_js$6.createError(`Root path is not a directory: ${normalizedRoot}`);
1522
1032
  }
1523
- return lines.join('\n');
1033
+ return createFsTree(normalizedRoot, options);
1524
1034
  }
1525
1035
  /**
1526
- * Generate diffs for all changes in a tree.
1036
+ * Create a tree from disk.
1037
+ *
1038
+ * Convenience alias for createTree.
1039
+ *
1040
+ * @param root - Root directory path
1041
+ * @param options - Tree creation options
1042
+ * @returns A new Tree instance backed by disk
1527
1043
  *
1528
- * @example
1044
+ * @example Creating a tree from disk
1529
1045
  * ```typescript
1530
- * const tree = createTree('/workspace')
1531
- * tree.write('new.txt', 'hello')
1532
- * tree.delete('old.txt')
1046
+ * import { createTreeFromDisk } from '@hyperfrontend/project-scope'
1533
1047
  *
1534
- * const diffs = generateAllDiffs(tree)
1535
- * for (const diff of diffs) {
1536
- * console.log(formatUnifiedDiff(diff))
1537
- * }
1048
+ * const tree = createTreeFromDisk('/path/to/project', { verbose: true })
1049
+ * const files = tree.children('/src')
1538
1050
  * ```
1539
- *
1540
- * @param tree - Tree to generate diffs for
1541
- * @param options - Diff options
1542
- * @returns Array of FileDiff objects
1543
1051
  */
1544
- function generateAllDiffs(tree, options = {}) {
1545
- const changes = tree.listChanges();
1546
- diffLogger.debug('generateAllDiffs', { changeCount: changes.length });
1547
- return changes.map((change) => generateDiff(change, options));
1052
+ function createTreeFromDisk(root, options) {
1053
+ return createTree(root, options);
1548
1054
  }
1549
1055
 
1550
1056
  exports.Mode = Mode;
@@ -1556,4 +1062,3 @@ exports.formatUnifiedDiff = formatUnifiedDiff;
1556
1062
  exports.generateAllDiffs = generateAllDiffs;
1557
1063
  exports.generateDiff = generateDiff;
1558
1064
  exports.rollbackChanges = rollbackChanges;
1559
- //# sourceMappingURL=index.cjs.js.map