@hyperfrontend/project-scope 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (391) hide show
  1. package/ARCHITECTURE.md +370 -0
  2. package/CHANGELOG.md +10 -0
  3. package/FUNDING.md +141 -0
  4. package/LICENSE.md +21 -0
  5. package/README.md +242 -0
  6. package/SECURITY.md +82 -0
  7. package/analyze.d.ts +33 -0
  8. package/analyze.d.ts.map +1 -0
  9. package/cli/commands/analyze.d.ts +20 -0
  10. package/cli/commands/analyze.d.ts.map +1 -0
  11. package/cli/commands/config.d.ts +20 -0
  12. package/cli/commands/config.d.ts.map +1 -0
  13. package/cli/commands/deps.d.ts +18 -0
  14. package/cli/commands/deps.d.ts.map +1 -0
  15. package/cli/commands/tree.d.ts +24 -0
  16. package/cli/commands/tree.d.ts.map +1 -0
  17. package/cli/index.cjs.js +6639 -0
  18. package/cli/index.cjs.js.map +1 -0
  19. package/cli/index.d.ts +7 -0
  20. package/cli/index.d.ts.map +1 -0
  21. package/cli/index.esm.js +6629 -0
  22. package/cli/index.esm.js.map +1 -0
  23. package/cli/run.d.ts +25 -0
  24. package/cli/run.d.ts.map +1 -0
  25. package/cli/types.d.ts +55 -0
  26. package/cli/types.d.ts.map +1 -0
  27. package/core/cache.d.ts +157 -0
  28. package/core/cache.d.ts.map +1 -0
  29. package/core/encoding/convert.d.ts +32 -0
  30. package/core/encoding/convert.d.ts.map +1 -0
  31. package/core/encoding/detect.d.ts +86 -0
  32. package/core/encoding/detect.d.ts.map +1 -0
  33. package/core/encoding/index.cjs.js +751 -0
  34. package/core/encoding/index.cjs.js.map +1 -0
  35. package/core/encoding/index.d.ts +3 -0
  36. package/core/encoding/index.d.ts.map +1 -0
  37. package/core/encoding/index.esm.js +736 -0
  38. package/core/encoding/index.esm.js.map +1 -0
  39. package/core/errors/structured-errors.d.ts +64 -0
  40. package/core/errors/structured-errors.d.ts.map +1 -0
  41. package/core/fs/directory.d.ts +88 -0
  42. package/core/fs/directory.d.ts.map +1 -0
  43. package/core/fs/index.cjs.js +1079 -0
  44. package/core/fs/index.cjs.js.map +1 -0
  45. package/core/fs/index.d.ts +6 -0
  46. package/core/fs/index.d.ts.map +1 -0
  47. package/core/fs/index.esm.js +1056 -0
  48. package/core/fs/index.esm.js.map +1 -0
  49. package/core/fs/read.d.ts +86 -0
  50. package/core/fs/read.d.ts.map +1 -0
  51. package/core/fs/stat.d.ts +58 -0
  52. package/core/fs/stat.d.ts.map +1 -0
  53. package/core/fs/traversal.d.ts +26 -0
  54. package/core/fs/traversal.d.ts.map +1 -0
  55. package/core/fs/write.d.ts +75 -0
  56. package/core/fs/write.d.ts.map +1 -0
  57. package/core/index.cjs.js +2376 -0
  58. package/core/index.cjs.js.map +1 -0
  59. package/core/index.d.ts +9 -0
  60. package/core/index.d.ts.map +1 -0
  61. package/core/index.esm.js +2286 -0
  62. package/core/index.esm.js.map +1 -0
  63. package/core/logger.d.ts +111 -0
  64. package/core/logger.d.ts.map +1 -0
  65. package/core/path/index.cjs.js +254 -0
  66. package/core/path/index.cjs.js.map +1 -0
  67. package/core/path/index.d.ts +5 -0
  68. package/core/path/index.d.ts.map +1 -0
  69. package/core/path/index.esm.js +233 -0
  70. package/core/path/index.esm.js.map +1 -0
  71. package/core/path/join.d.ts +17 -0
  72. package/core/path/join.d.ts.map +1 -0
  73. package/core/path/normalize.d.ts +37 -0
  74. package/core/path/normalize.d.ts.map +1 -0
  75. package/core/path/resolve.d.ts +52 -0
  76. package/core/path/resolve.d.ts.map +1 -0
  77. package/core/path/segments.d.ts +59 -0
  78. package/core/path/segments.d.ts.map +1 -0
  79. package/core/patterns/glob.d.ts +46 -0
  80. package/core/patterns/glob.d.ts.map +1 -0
  81. package/core/platform/detect.d.ts +66 -0
  82. package/core/platform/detect.d.ts.map +1 -0
  83. package/core/platform/index.cjs.js +241 -0
  84. package/core/platform/index.cjs.js.map +1 -0
  85. package/core/platform/index.d.ts +3 -0
  86. package/core/platform/index.d.ts.map +1 -0
  87. package/core/platform/index.esm.js +226 -0
  88. package/core/platform/index.esm.js.map +1 -0
  89. package/core/platform/line-endings.d.ts +48 -0
  90. package/core/platform/line-endings.d.ts.map +1 -0
  91. package/heuristics/dependencies/analyze.d.ts +77 -0
  92. package/heuristics/dependencies/analyze.d.ts.map +1 -0
  93. package/heuristics/dependencies/index.cjs.js +1126 -0
  94. package/heuristics/dependencies/index.cjs.js.map +1 -0
  95. package/heuristics/dependencies/index.d.ts +2 -0
  96. package/heuristics/dependencies/index.d.ts.map +1 -0
  97. package/heuristics/dependencies/index.esm.js +1122 -0
  98. package/heuristics/dependencies/index.esm.js.map +1 -0
  99. package/heuristics/entry-points/discover.d.ts +86 -0
  100. package/heuristics/entry-points/discover.d.ts.map +1 -0
  101. package/heuristics/entry-points/index.cjs.js +1581 -0
  102. package/heuristics/entry-points/index.cjs.js.map +1 -0
  103. package/heuristics/entry-points/index.d.ts +2 -0
  104. package/heuristics/entry-points/index.d.ts.map +1 -0
  105. package/heuristics/entry-points/index.esm.js +1577 -0
  106. package/heuristics/entry-points/index.esm.js.map +1 -0
  107. package/heuristics/framework/identify.d.ts +84 -0
  108. package/heuristics/framework/identify.d.ts.map +1 -0
  109. package/heuristics/framework/index.cjs.js +3618 -0
  110. package/heuristics/framework/index.cjs.js.map +1 -0
  111. package/heuristics/framework/index.d.ts +2 -0
  112. package/heuristics/framework/index.d.ts.map +1 -0
  113. package/heuristics/framework/index.esm.js +3614 -0
  114. package/heuristics/framework/index.esm.js.map +1 -0
  115. package/heuristics/index.cjs.js +4833 -0
  116. package/heuristics/index.cjs.js.map +1 -0
  117. package/heuristics/index.d.ts +5 -0
  118. package/heuristics/index.d.ts.map +1 -0
  119. package/heuristics/index.esm.js +4822 -0
  120. package/heuristics/index.esm.js.map +1 -0
  121. package/heuristics/project-type/detect.d.ts +61 -0
  122. package/heuristics/project-type/detect.d.ts.map +1 -0
  123. package/heuristics/project-type/index.cjs.js +3633 -0
  124. package/heuristics/project-type/index.cjs.js.map +1 -0
  125. package/heuristics/project-type/index.d.ts +2 -0
  126. package/heuristics/project-type/index.d.ts.map +1 -0
  127. package/heuristics/project-type/index.esm.js +3631 -0
  128. package/heuristics/project-type/index.esm.js.map +1 -0
  129. package/index.cjs.js +10255 -0
  130. package/index.cjs.js.map +1 -0
  131. package/index.d.ts +10 -0
  132. package/index.d.ts.map +1 -0
  133. package/index.esm.js +10006 -0
  134. package/index.esm.js.map +1 -0
  135. package/models/index.cjs.js +3 -0
  136. package/models/index.cjs.js.map +1 -0
  137. package/models/index.d.ts +176 -0
  138. package/models/index.d.ts.map +1 -0
  139. package/models/index.esm.js +2 -0
  140. package/models/index.esm.js.map +1 -0
  141. package/nx/detect.d.ts +105 -0
  142. package/nx/detect.d.ts.map +1 -0
  143. package/nx/devkit-loader.d.ts +62 -0
  144. package/nx/devkit-loader.d.ts.map +1 -0
  145. package/nx/index.cjs.js +1302 -0
  146. package/nx/index.cjs.js.map +1 -0
  147. package/nx/index.d.ts +4 -0
  148. package/nx/index.d.ts.map +1 -0
  149. package/nx/index.esm.js +1286 -0
  150. package/nx/index.esm.js.map +1 -0
  151. package/nx/project-config.d.ts +109 -0
  152. package/nx/project-config.d.ts.map +1 -0
  153. package/package.json +218 -0
  154. package/project/config/detect.d.ts +77 -0
  155. package/project/config/detect.d.ts.map +1 -0
  156. package/project/config/index.cjs.js +1982 -0
  157. package/project/config/index.cjs.js.map +1 -0
  158. package/project/config/index.d.ts +4 -0
  159. package/project/config/index.d.ts.map +1 -0
  160. package/project/config/index.esm.js +1971 -0
  161. package/project/config/index.esm.js.map +1 -0
  162. package/project/config/parse.d.ts +53 -0
  163. package/project/config/parse.d.ts.map +1 -0
  164. package/project/config/patterns.d.ts +31 -0
  165. package/project/config/patterns.d.ts.map +1 -0
  166. package/project/index.cjs.js +2585 -0
  167. package/project/index.cjs.js.map +1 -0
  168. package/project/index.d.ts +5 -0
  169. package/project/index.d.ts.map +1 -0
  170. package/project/index.esm.js +2549 -0
  171. package/project/index.esm.js.map +1 -0
  172. package/project/package/dependencies.d.ts +101 -0
  173. package/project/package/dependencies.d.ts.map +1 -0
  174. package/project/package/index.cjs.js +972 -0
  175. package/project/package/index.cjs.js.map +1 -0
  176. package/project/package/index.d.ts +3 -0
  177. package/project/package/index.d.ts.map +1 -0
  178. package/project/package/index.esm.js +957 -0
  179. package/project/package/index.esm.js.map +1 -0
  180. package/project/package/read.d.ts +66 -0
  181. package/project/package/read.d.ts.map +1 -0
  182. package/project/root/detect.d.ts +65 -0
  183. package/project/root/detect.d.ts.map +1 -0
  184. package/project/root/index.cjs.js +860 -0
  185. package/project/root/index.cjs.js.map +1 -0
  186. package/project/root/index.d.ts +2 -0
  187. package/project/root/index.d.ts.map +1 -0
  188. package/project/root/index.esm.js +853 -0
  189. package/project/root/index.esm.js.map +1 -0
  190. package/project/traversal/index.cjs.js +1179 -0
  191. package/project/traversal/index.cjs.js.map +1 -0
  192. package/project/traversal/index.d.ts +3 -0
  193. package/project/traversal/index.d.ts.map +1 -0
  194. package/project/traversal/index.esm.js +1173 -0
  195. package/project/traversal/index.esm.js.map +1 -0
  196. package/project/traversal/search.d.ts +59 -0
  197. package/project/traversal/search.d.ts.map +1 -0
  198. package/project/traversal/walk.d.ts +63 -0
  199. package/project/traversal/walk.d.ts.map +1 -0
  200. package/tech/backend/detect-all.d.ts +13 -0
  201. package/tech/backend/detect-all.d.ts.map +1 -0
  202. package/tech/backend/express.d.ts +11 -0
  203. package/tech/backend/express.d.ts.map +1 -0
  204. package/tech/backend/fastify.d.ts +11 -0
  205. package/tech/backend/fastify.d.ts.map +1 -0
  206. package/tech/backend/hono.d.ts +11 -0
  207. package/tech/backend/hono.d.ts.map +1 -0
  208. package/tech/backend/index.cjs.js +939 -0
  209. package/tech/backend/index.cjs.js.map +1 -0
  210. package/tech/backend/index.d.ts +8 -0
  211. package/tech/backend/index.d.ts.map +1 -0
  212. package/tech/backend/index.esm.js +931 -0
  213. package/tech/backend/index.esm.js.map +1 -0
  214. package/tech/backend/koa.d.ts +11 -0
  215. package/tech/backend/koa.d.ts.map +1 -0
  216. package/tech/backend/nestjs.d.ts +11 -0
  217. package/tech/backend/nestjs.d.ts.map +1 -0
  218. package/tech/backend/types.d.ts +31 -0
  219. package/tech/backend/types.d.ts.map +1 -0
  220. package/tech/build/babel.d.ts +13 -0
  221. package/tech/build/babel.d.ts.map +1 -0
  222. package/tech/build/detect-all.d.ts +13 -0
  223. package/tech/build/detect-all.d.ts.map +1 -0
  224. package/tech/build/esbuild.d.ts +11 -0
  225. package/tech/build/esbuild.d.ts.map +1 -0
  226. package/tech/build/index.cjs.js +1118 -0
  227. package/tech/build/index.cjs.js.map +1 -0
  228. package/tech/build/index.d.ts +10 -0
  229. package/tech/build/index.d.ts.map +1 -0
  230. package/tech/build/index.esm.js +1102 -0
  231. package/tech/build/index.esm.js.map +1 -0
  232. package/tech/build/parcel.d.ts +13 -0
  233. package/tech/build/parcel.d.ts.map +1 -0
  234. package/tech/build/rollup.d.ts +13 -0
  235. package/tech/build/rollup.d.ts.map +1 -0
  236. package/tech/build/swc.d.ts +13 -0
  237. package/tech/build/swc.d.ts.map +1 -0
  238. package/tech/build/types.d.ts +31 -0
  239. package/tech/build/types.d.ts.map +1 -0
  240. package/tech/build/vite.d.ts +13 -0
  241. package/tech/build/vite.d.ts.map +1 -0
  242. package/tech/build/webpack.d.ts +13 -0
  243. package/tech/build/webpack.d.ts.map +1 -0
  244. package/tech/frontend/angular.d.ts +11 -0
  245. package/tech/frontend/angular.d.ts.map +1 -0
  246. package/tech/frontend/astro.d.ts +11 -0
  247. package/tech/frontend/astro.d.ts.map +1 -0
  248. package/tech/frontend/detect-all.d.ts +13 -0
  249. package/tech/frontend/detect-all.d.ts.map +1 -0
  250. package/tech/frontend/gatsby.d.ts +11 -0
  251. package/tech/frontend/gatsby.d.ts.map +1 -0
  252. package/tech/frontend/index.cjs.js +1310 -0
  253. package/tech/frontend/index.cjs.js.map +1 -0
  254. package/tech/frontend/index.d.ts +15 -0
  255. package/tech/frontend/index.d.ts.map +1 -0
  256. package/tech/frontend/index.esm.js +1295 -0
  257. package/tech/frontend/index.esm.js.map +1 -0
  258. package/tech/frontend/nextjs.d.ts +11 -0
  259. package/tech/frontend/nextjs.d.ts.map +1 -0
  260. package/tech/frontend/nuxt.d.ts +11 -0
  261. package/tech/frontend/nuxt.d.ts.map +1 -0
  262. package/tech/frontend/qwik.d.ts +11 -0
  263. package/tech/frontend/qwik.d.ts.map +1 -0
  264. package/tech/frontend/react.d.ts +11 -0
  265. package/tech/frontend/react.d.ts.map +1 -0
  266. package/tech/frontend/remix.d.ts +11 -0
  267. package/tech/frontend/remix.d.ts.map +1 -0
  268. package/tech/frontend/solid.d.ts +11 -0
  269. package/tech/frontend/solid.d.ts.map +1 -0
  270. package/tech/frontend/svelte.d.ts +11 -0
  271. package/tech/frontend/svelte.d.ts.map +1 -0
  272. package/tech/frontend/sveltekit.d.ts +11 -0
  273. package/tech/frontend/sveltekit.d.ts.map +1 -0
  274. package/tech/frontend/types.d.ts +35 -0
  275. package/tech/frontend/types.d.ts.map +1 -0
  276. package/tech/frontend/vue.d.ts +11 -0
  277. package/tech/frontend/vue.d.ts.map +1 -0
  278. package/tech/index.cjs.js +3684 -0
  279. package/tech/index.cjs.js.map +1 -0
  280. package/tech/index.d.ts +96 -0
  281. package/tech/index.d.ts.map +1 -0
  282. package/tech/index.esm.js +3603 -0
  283. package/tech/index.esm.js.map +1 -0
  284. package/tech/legacy/angularjs.d.ts +12 -0
  285. package/tech/legacy/angularjs.d.ts.map +1 -0
  286. package/tech/legacy/backbone.d.ts +11 -0
  287. package/tech/legacy/backbone.d.ts.map +1 -0
  288. package/tech/legacy/detect-all.d.ts +13 -0
  289. package/tech/legacy/detect-all.d.ts.map +1 -0
  290. package/tech/legacy/ember.d.ts +11 -0
  291. package/tech/legacy/ember.d.ts.map +1 -0
  292. package/tech/legacy/index.cjs.js +903 -0
  293. package/tech/legacy/index.cjs.js.map +1 -0
  294. package/tech/legacy/index.d.ts +7 -0
  295. package/tech/legacy/index.d.ts.map +1 -0
  296. package/tech/legacy/index.esm.js +896 -0
  297. package/tech/legacy/index.esm.js.map +1 -0
  298. package/tech/legacy/jquery.d.ts +11 -0
  299. package/tech/legacy/jquery.d.ts.map +1 -0
  300. package/tech/legacy/types.d.ts +33 -0
  301. package/tech/legacy/types.d.ts.map +1 -0
  302. package/tech/linting/biome.d.ts +11 -0
  303. package/tech/linting/biome.d.ts.map +1 -0
  304. package/tech/linting/detect-all.d.ts +13 -0
  305. package/tech/linting/detect-all.d.ts.map +1 -0
  306. package/tech/linting/eslint.d.ts +13 -0
  307. package/tech/linting/eslint.d.ts.map +1 -0
  308. package/tech/linting/index.cjs.js +992 -0
  309. package/tech/linting/index.cjs.js.map +1 -0
  310. package/tech/linting/index.d.ts +7 -0
  311. package/tech/linting/index.d.ts.map +1 -0
  312. package/tech/linting/index.esm.js +982 -0
  313. package/tech/linting/index.esm.js.map +1 -0
  314. package/tech/linting/prettier.d.ts +13 -0
  315. package/tech/linting/prettier.d.ts.map +1 -0
  316. package/tech/linting/stylelint.d.ts +13 -0
  317. package/tech/linting/stylelint.d.ts.map +1 -0
  318. package/tech/linting/types.d.ts +31 -0
  319. package/tech/linting/types.d.ts.map +1 -0
  320. package/tech/monorepo/detect-all.d.ts +13 -0
  321. package/tech/monorepo/detect-all.d.ts.map +1 -0
  322. package/tech/monorepo/index.cjs.js +1021 -0
  323. package/tech/monorepo/index.cjs.js.map +1 -0
  324. package/tech/monorepo/index.d.ts +10 -0
  325. package/tech/monorepo/index.d.ts.map +1 -0
  326. package/tech/monorepo/index.esm.js +1011 -0
  327. package/tech/monorepo/index.esm.js.map +1 -0
  328. package/tech/monorepo/lerna.d.ts +11 -0
  329. package/tech/monorepo/lerna.d.ts.map +1 -0
  330. package/tech/monorepo/npm-workspaces.d.ts +11 -0
  331. package/tech/monorepo/npm-workspaces.d.ts.map +1 -0
  332. package/tech/monorepo/nx.d.ts +11 -0
  333. package/tech/monorepo/nx.d.ts.map +1 -0
  334. package/tech/monorepo/pnpm-workspaces.d.ts +9 -0
  335. package/tech/monorepo/pnpm-workspaces.d.ts.map +1 -0
  336. package/tech/monorepo/rush.d.ts +11 -0
  337. package/tech/monorepo/rush.d.ts.map +1 -0
  338. package/tech/monorepo/turborepo.d.ts +11 -0
  339. package/tech/monorepo/turborepo.d.ts.map +1 -0
  340. package/tech/monorepo/types.d.ts +39 -0
  341. package/tech/monorepo/types.d.ts.map +1 -0
  342. package/tech/monorepo/yarn-workspaces.d.ts +11 -0
  343. package/tech/monorepo/yarn-workspaces.d.ts.map +1 -0
  344. package/tech/shared-utils/detector-helpers.d.ts +52 -0
  345. package/tech/shared-utils/detector-helpers.d.ts.map +1 -0
  346. package/tech/shared-utils/types.d.ts +41 -0
  347. package/tech/shared-utils/types.d.ts.map +1 -0
  348. package/tech/testing/cypress.d.ts +13 -0
  349. package/tech/testing/cypress.d.ts.map +1 -0
  350. package/tech/testing/detect-all.d.ts +13 -0
  351. package/tech/testing/detect-all.d.ts.map +1 -0
  352. package/tech/testing/index.cjs.js +1031 -0
  353. package/tech/testing/index.cjs.js.map +1 -0
  354. package/tech/testing/index.d.ts +8 -0
  355. package/tech/testing/index.d.ts.map +1 -0
  356. package/tech/testing/index.esm.js +1018 -0
  357. package/tech/testing/index.esm.js.map +1 -0
  358. package/tech/testing/jest.d.ts +13 -0
  359. package/tech/testing/jest.d.ts.map +1 -0
  360. package/tech/testing/mocha.d.ts +13 -0
  361. package/tech/testing/mocha.d.ts.map +1 -0
  362. package/tech/testing/playwright.d.ts +13 -0
  363. package/tech/testing/playwright.d.ts.map +1 -0
  364. package/tech/testing/types.d.ts +35 -0
  365. package/tech/testing/types.d.ts.map +1 -0
  366. package/tech/testing/vitest.d.ts +13 -0
  367. package/tech/testing/vitest.d.ts.map +1 -0
  368. package/tech/types/detectors.d.ts +67 -0
  369. package/tech/types/detectors.d.ts.map +1 -0
  370. package/tech/types/index.cjs.js +1045 -0
  371. package/tech/types/index.cjs.js.map +1 -0
  372. package/tech/types/index.d.ts +2 -0
  373. package/tech/types/index.d.ts.map +1 -0
  374. package/tech/types/index.esm.js +1039 -0
  375. package/tech/types/index.esm.js.map +1 -0
  376. package/vfs/commit.d.ts +32 -0
  377. package/vfs/commit.d.ts.map +1 -0
  378. package/vfs/diff.d.ts +73 -0
  379. package/vfs/diff.d.ts.map +1 -0
  380. package/vfs/factory.d.ts +37 -0
  381. package/vfs/factory.d.ts.map +1 -0
  382. package/vfs/fs-tree.d.ts +13 -0
  383. package/vfs/fs-tree.d.ts.map +1 -0
  384. package/vfs/index.cjs.js +1600 -0
  385. package/vfs/index.cjs.js.map +1 -0
  386. package/vfs/index.d.ts +6 -0
  387. package/vfs/index.d.ts.map +1 -0
  388. package/vfs/index.esm.js +1590 -0
  389. package/vfs/index.esm.js.map +1 -0
  390. package/vfs/types.d.ts +178 -0
  391. package/vfs/types.d.ts.map +1 -0
@@ -0,0 +1,1173 @@
1
+ import { join } from 'node:path';
2
+ import { existsSync, readFileSync, statSync, lstatSync, readdirSync } from 'node:fs';
3
+
4
+ /**
5
+ * Safe copies of Error built-ins via factory functions.
6
+ *
7
+ * Since constructors cannot be safely captured via Object.assign, this module
8
+ * provides factory functions that use Reflect.construct internally.
9
+ *
10
+ * These references are captured at module initialization time to protect against
11
+ * prototype pollution attacks. Import only what you need for tree-shaking.
12
+ *
13
+ * @module @hyperfrontend/immutable-api-utils/built-in-copy/error
14
+ */
15
+ // Capture references at module initialization time
16
+ const _Error = globalThis.Error;
17
+ const _Reflect$1 = globalThis.Reflect;
18
+ /**
19
+ * (Safe copy) Creates a new Error using the captured Error constructor.
20
+ * Use this instead of `new Error()`.
21
+ *
22
+ * @param message - Optional error message.
23
+ * @param options - Optional error options.
24
+ * @returns A new Error instance.
25
+ */
26
+ const createError = (message, options) => _Reflect$1.construct(_Error, [message, options]);
27
+
28
+ /**
29
+ * Safe copies of JSON built-in methods.
30
+ *
31
+ * These references are captured at module initialization time to protect against
32
+ * prototype pollution attacks. Import only what you need for tree-shaking.
33
+ *
34
+ * @module @hyperfrontend/immutable-api-utils/built-in-copy/json
35
+ */
36
+ // Capture references at module initialization time
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
+ // Capture references at module initialization time
52
+ const _Object = globalThis.Object;
53
+ /**
54
+ * (Safe copy) Prevents modification of existing property attributes and values,
55
+ * and prevents the addition of new properties.
56
+ */
57
+ const freeze = _Object.freeze;
58
+ /**
59
+ * (Safe copy) Returns the names of the enumerable string properties and methods of an object.
60
+ */
61
+ const keys = _Object.keys;
62
+ /**
63
+ * (Safe copy) Returns an array of key/values of the enumerable own properties of an object.
64
+ */
65
+ const entries = _Object.entries;
66
+ /**
67
+ * (Safe copy) Adds one or more properties to an object, and/or modifies attributes of existing properties.
68
+ */
69
+ const defineProperties = _Object.defineProperties;
70
+
71
+ /**
72
+ * Safe copies of Array built-in static methods.
73
+ *
74
+ * These references are captured at module initialization time to protect against
75
+ * prototype pollution attacks. Import only what you need for tree-shaking.
76
+ *
77
+ * @module @hyperfrontend/immutable-api-utils/built-in-copy/array
78
+ */
79
+ // Capture references at module initialization time
80
+ const _Array = globalThis.Array;
81
+ /**
82
+ * (Safe copy) Determines whether the passed value is an Array.
83
+ */
84
+ const isArray = _Array.isArray;
85
+
86
+ /**
87
+ * Safe copies of Console built-in methods.
88
+ *
89
+ * These references are captured at module initialization time to protect against
90
+ * prototype pollution attacks. Import only what you need for tree-shaking.
91
+ *
92
+ * @module @hyperfrontend/immutable-api-utils/built-in-copy/console
93
+ */
94
+ // Capture references at module initialization time
95
+ const _console = globalThis.console;
96
+ /**
97
+ * (Safe copy) Outputs a message to the console.
98
+ */
99
+ const log = _console.log.bind(_console);
100
+ /**
101
+ * (Safe copy) Outputs a warning message to the console.
102
+ */
103
+ const warn = _console.warn.bind(_console);
104
+ /**
105
+ * (Safe copy) Outputs an error message to the console.
106
+ */
107
+ const error = _console.error.bind(_console);
108
+ /**
109
+ * (Safe copy) Outputs an informational message to the console.
110
+ */
111
+ const info = _console.info.bind(_console);
112
+ /**
113
+ * (Safe copy) Outputs a debug message to the console.
114
+ */
115
+ const debug = _console.debug.bind(_console);
116
+ /**
117
+ * (Safe copy) Outputs a stack trace to the console.
118
+ */
119
+ _console.trace.bind(_console);
120
+ /**
121
+ * (Safe copy) Displays an interactive listing of the properties of a specified object.
122
+ */
123
+ _console.dir.bind(_console);
124
+ /**
125
+ * (Safe copy) Displays tabular data as a table.
126
+ */
127
+ _console.table.bind(_console);
128
+ /**
129
+ * (Safe copy) Writes an error message to the console if the assertion is false.
130
+ */
131
+ _console.assert.bind(_console);
132
+ /**
133
+ * (Safe copy) Clears the console.
134
+ */
135
+ _console.clear.bind(_console);
136
+ /**
137
+ * (Safe copy) Logs the number of times that this particular call to count() has been called.
138
+ */
139
+ _console.count.bind(_console);
140
+ /**
141
+ * (Safe copy) Resets the counter used with console.count().
142
+ */
143
+ _console.countReset.bind(_console);
144
+ /**
145
+ * (Safe copy) Creates a new inline group in the console.
146
+ */
147
+ _console.group.bind(_console);
148
+ /**
149
+ * (Safe copy) Creates a new inline group in the console that is initially collapsed.
150
+ */
151
+ _console.groupCollapsed.bind(_console);
152
+ /**
153
+ * (Safe copy) Exits the current inline group.
154
+ */
155
+ _console.groupEnd.bind(_console);
156
+ /**
157
+ * (Safe copy) Starts a timer with a name specified as an input parameter.
158
+ */
159
+ _console.time.bind(_console);
160
+ /**
161
+ * (Safe copy) Stops a timer that was previously started.
162
+ */
163
+ _console.timeEnd.bind(_console);
164
+ /**
165
+ * (Safe copy) Logs the current value of a timer that was previously started.
166
+ */
167
+ _console.timeLog.bind(_console);
168
+
169
+ /**
170
+ * Safe copies of Set built-in via factory function.
171
+ *
172
+ * Since constructors cannot be safely captured via Object.assign, this module
173
+ * provides a factory function that uses Reflect.construct internally.
174
+ *
175
+ * These references are captured at module initialization time to protect against
176
+ * prototype pollution attacks. Import only what you need for tree-shaking.
177
+ *
178
+ * @module @hyperfrontend/immutable-api-utils/built-in-copy/set
179
+ */
180
+ // Capture references at module initialization time
181
+ const _Set = globalThis.Set;
182
+ const _Reflect = 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.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
+ /* eslint-disable @typescript-eslint/no-explicit-any */
218
+ /**
219
+ * Creates a wrapper function that only executes the wrapped function if the condition function returns true.
220
+ *
221
+ * @param func - The function to be conditionally executed.
222
+ * @param conditionFunc - A function that returns a boolean, determining if `func` should be executed.
223
+ * @returns A wrapped version of `func` that executes conditionally.
224
+ */
225
+ function createConditionalExecutionFunction(func, conditionFunc) {
226
+ return function (...args) {
227
+ if (conditionFunc()) {
228
+ return func(...args);
229
+ }
230
+ };
231
+ }
232
+
233
+ /* eslint-disable @typescript-eslint/no-explicit-any */
234
+ /**
235
+ * Creates a wrapper function that silently ignores any errors thrown by the wrapped void function.
236
+ * This function is specifically for wrapping functions that do not return a value (void functions).
237
+ * Exceptions are swallowed without any logging or handling.
238
+ *
239
+ * @param func - The void function to be wrapped.
240
+ * @returns A wrapped version of the input function that ignores errors.
241
+ */
242
+ function createErrorIgnoringFunction(func) {
243
+ return function (...args) {
244
+ try {
245
+ func(...args);
246
+ }
247
+ catch {
248
+ // Deliberately swallowing/ignoring the exception
249
+ }
250
+ };
251
+ }
252
+
253
+ /* eslint-disable @typescript-eslint/no-unused-vars */
254
+ /**
255
+ * A no-operation function (noop) that does nothing regardless of the arguments passed.
256
+ * It is designed to be as permissive as possible in its typing without using the `Function` keyword.
257
+ *
258
+ * @param args - Any arguments passed to the function (ignored)
259
+ */
260
+ const noop = (...args) => {
261
+ // Intentionally does nothing
262
+ };
263
+
264
+ const logLevels = ['none', 'error', 'warn', 'log', 'info', 'debug'];
265
+ const priority = {
266
+ error: 4,
267
+ warn: 3,
268
+ log: 2,
269
+ info: 1,
270
+ debug: 0,
271
+ };
272
+ /**
273
+ * Validates whether a given string is a valid log level.
274
+ *
275
+ * @param level - The log level to validate
276
+ * @returns True if the level is valid, false otherwise
277
+ */
278
+ function isValidLogLevel(level) {
279
+ return logLevels.includes(level);
280
+ }
281
+ /**
282
+ * Creates a log level configuration manager for controlling logging behavior.
283
+ * Provides methods to get, set, and evaluate log levels based on priority.
284
+ *
285
+ * @param level - The initial log level (defaults to 'error')
286
+ * @returns A configuration object with log level management methods
287
+ * @throws {Error} When the provided level is not a valid log level
288
+ */
289
+ function createLogLevelConfig(level = 'error') {
290
+ if (!isValidLogLevel(level)) {
291
+ throw createError('Cannot create log level configuration with a valid default log level');
292
+ }
293
+ const state = { level };
294
+ const getLogLevel = () => state.level;
295
+ const setLogLevel = (level) => {
296
+ if (!isValidLogLevel(level)) {
297
+ throw createError(`Cannot set value '${level}' level. Expected levels are ${logLevels}.`);
298
+ }
299
+ state.level = level;
300
+ };
301
+ const shouldLog = (level) => {
302
+ if (state.level === 'none' || level === 'none' || !isValidLogLevel(level)) {
303
+ return false;
304
+ }
305
+ return priority[level] >= priority[state.level];
306
+ };
307
+ return freeze({
308
+ getLogLevel,
309
+ setLogLevel,
310
+ shouldLog,
311
+ });
312
+ }
313
+
314
+ /**
315
+ * Creates a logger instance with configurable log level filtering.
316
+ * Each log function is wrapped to respect the current log level setting.
317
+ *
318
+ * @param error - Function to handle error-level logs (required)
319
+ * @param warn - Function to handle warning-level logs (optional, defaults to noop)
320
+ * @param log - Function to handle standard logs (optional, defaults to noop)
321
+ * @param info - Function to handle info-level logs (optional, defaults to noop)
322
+ * @param debug - Function to handle debug-level logs (optional, defaults to noop)
323
+ * @returns A frozen logger object with log methods and level control
324
+ * @throws {ErrorLevelFn} When any provided log function is invalid
325
+ */
326
+ function createLogger(error, warn = noop, log = noop, info = noop, debug = noop) {
327
+ if (notValidLogFn(error)) {
328
+ throw createError(notFnMsg('error'));
329
+ }
330
+ if (notValidLogFn(warn)) {
331
+ throw createError(notFnMsg('warn'));
332
+ }
333
+ if (notValidLogFn(log)) {
334
+ throw createError(notFnMsg('log'));
335
+ }
336
+ if (notValidLogFn(info)) {
337
+ throw createError(notFnMsg('info'));
338
+ }
339
+ if (notValidLogFn(debug)) {
340
+ throw createError(notFnMsg('debug'));
341
+ }
342
+ const { setLogLevel, getLogLevel, shouldLog } = createLogLevelConfig();
343
+ const wrapLogFn = (fn, level) => {
344
+ if (fn === noop)
345
+ return fn;
346
+ const condition = () => shouldLog(level);
347
+ return createConditionalExecutionFunction(createErrorIgnoringFunction(fn), condition);
348
+ };
349
+ return freeze({
350
+ error: wrapLogFn(error, 'error'),
351
+ warn: wrapLogFn(warn, 'warn'),
352
+ log: wrapLogFn(log, 'log'),
353
+ info: wrapLogFn(info, 'info'),
354
+ debug: wrapLogFn(debug, 'debug'),
355
+ setLogLevel,
356
+ getLogLevel,
357
+ });
358
+ }
359
+ /**
360
+ * Validates whether a given value is a valid log function.
361
+ *
362
+ * @param fn - The value to validate
363
+ * @returns True if the value is not a function (invalid), false if it is valid
364
+ */
365
+ function notValidLogFn(fn) {
366
+ return getType(fn) !== 'function' && fn !== noop;
367
+ }
368
+ /**
369
+ * Generates an error message for invalid log function parameters.
370
+ *
371
+ * @param label - The name of the log function that failed validation
372
+ * @returns A formatted error message string
373
+ */
374
+ function notFnMsg(label) {
375
+ return `Cannot create a logger when ${label} is not a function`;
376
+ }
377
+
378
+ createLogger(error, warn, log, info, debug);
379
+
380
+ /**
381
+ * Global log level registry.
382
+ * Tracks all created scoped loggers to allow global log level changes.
383
+ */
384
+ const loggerRegistry = createSet();
385
+ /** Redacted placeholder for sensitive values */
386
+ const REDACTED = '[REDACTED]';
387
+ /**
388
+ * Patterns that indicate a sensitive key name.
389
+ * Keys containing these patterns will have their values sanitized.
390
+ */
391
+ const SENSITIVE_KEY_PATTERNS = [
392
+ /token/i,
393
+ /key/i,
394
+ /password/i,
395
+ /secret/i,
396
+ /credential/i,
397
+ /auth/i,
398
+ /bearer/i,
399
+ /api[_-]?key/i,
400
+ /private/i,
401
+ /passphrase/i,
402
+ ];
403
+ /**
404
+ * Checks if a key name indicates sensitive data.
405
+ *
406
+ * @param key - Key name to check
407
+ * @returns True if the key indicates sensitive data
408
+ */
409
+ function isSensitiveKey(key) {
410
+ return SENSITIVE_KEY_PATTERNS.some((pattern) => pattern.test(key));
411
+ }
412
+ /**
413
+ * Sanitizes an object by replacing sensitive values with REDACTED.
414
+ * This function recursively processes nested objects and arrays.
415
+ *
416
+ * @param obj - Object to sanitize
417
+ * @returns New object with sensitive values redacted
418
+ */
419
+ function sanitize(obj) {
420
+ if (obj === null || obj === undefined) {
421
+ return obj;
422
+ }
423
+ if (isArray(obj)) {
424
+ return obj.map((item) => sanitize(item));
425
+ }
426
+ if (typeof obj === 'object') {
427
+ const result = {};
428
+ for (const [key, value] of entries(obj)) {
429
+ if (isSensitiveKey(key)) {
430
+ result[key] = REDACTED;
431
+ }
432
+ else if (typeof value === 'object' && value !== null) {
433
+ result[key] = sanitize(value);
434
+ }
435
+ else {
436
+ result[key] = value;
437
+ }
438
+ }
439
+ return result;
440
+ }
441
+ return obj;
442
+ }
443
+ /**
444
+ * Formats a log message with optional metadata.
445
+ *
446
+ * @param namespace - Logger namespace prefix
447
+ * @param message - Log message
448
+ * @param meta - Optional metadata object
449
+ * @returns Formatted log string
450
+ */
451
+ function formatMessage(namespace, message, meta) {
452
+ const prefix = `[${namespace}]`;
453
+ if (meta && keys(meta).length > 0) {
454
+ const sanitizedMeta = sanitize(meta);
455
+ return `${prefix} ${message} ${stringify(sanitizedMeta)}`;
456
+ }
457
+ return `${prefix} ${message}`;
458
+ }
459
+ /**
460
+ * Creates a scoped logger with namespace prefix and optional secret sanitization.
461
+ * All log messages will be prefixed with [namespace] and sensitive metadata
462
+ * values will be automatically redacted.
463
+ *
464
+ * @param namespace - Logger namespace (e.g., 'project-scope', 'analyze')
465
+ * @param options - Logger configuration options
466
+ * @returns A configured scoped logger instance
467
+ *
468
+ * @example
469
+ * ```typescript
470
+ * const logger = createScopedLogger('project-scope')
471
+ * logger.setLogLevel('debug')
472
+ *
473
+ * // Basic logging
474
+ * logger.info('Starting analysis', { path: './project' })
475
+ *
476
+ * // Sensitive data is automatically redacted
477
+ * logger.debug('Config loaded', { apiKey: 'secret123' })
478
+ * // Output: [project-scope] Config loaded {"apiKey":"[REDACTED]"}
479
+ * ```
480
+ */
481
+ function createScopedLogger(namespace, options = {}) {
482
+ const { level = 'error', sanitizeSecrets = true } = options;
483
+ // Create wrapper functions that add namespace prefix and sanitization
484
+ const createLogFn = (baseFn) => (message, meta) => {
485
+ const processedMeta = sanitizeSecrets && meta ? sanitize(meta) : meta;
486
+ baseFn(formatMessage(namespace, message, processedMeta));
487
+ };
488
+ // Create base logger with wrapped functions
489
+ const baseLogger = createLogger(createLogFn(error), createLogFn(warn), createLogFn(log), createLogFn(info), createLogFn(debug));
490
+ // Set initial log level (use global override if set)
491
+ baseLogger.setLogLevel(level);
492
+ const scopedLogger = freeze({
493
+ error: (message, meta) => baseLogger.error(message, meta),
494
+ warn: (message, meta) => baseLogger.warn(message, meta),
495
+ log: (message, meta) => baseLogger.log(message, meta),
496
+ info: (message, meta) => baseLogger.info(message, meta),
497
+ debug: (message, meta) => baseLogger.debug(message, meta),
498
+ setLogLevel: baseLogger.setLogLevel,
499
+ getLogLevel: baseLogger.getLogLevel,
500
+ });
501
+ // Register logger for global level management
502
+ loggerRegistry.add(scopedLogger);
503
+ return scopedLogger;
504
+ }
505
+ /**
506
+ * Default logger instance for the project-scope library.
507
+ * Use this for general logging within the library.
508
+ *
509
+ * @example
510
+ * ```typescript
511
+ * import { logger } from '@hyperfrontend/project-scope/core'
512
+ *
513
+ * logger.setLogLevel('debug')
514
+ * logger.debug('Analyzing project', { path: './src' })
515
+ * ```
516
+ */
517
+ createScopedLogger('project-scope');
518
+
519
+ createScopedLogger('project-scope:fs');
520
+ /**
521
+ * Create a file system error with code and context.
522
+ *
523
+ * @param message - The error message describing what went wrong
524
+ * @param code - The category code for this type of filesystem failure
525
+ * @param context - Additional context including path, operation, and cause
526
+ * @returns A configured Error object with code and context properties
527
+ */
528
+ function createFileSystemError(message, code, context) {
529
+ const error = createError(message);
530
+ defineProperties(error, {
531
+ code: { value: code, enumerable: true },
532
+ context: { value: context, enumerable: true },
533
+ });
534
+ return error;
535
+ }
536
+ /**
537
+ * Read file if exists, return null otherwise.
538
+ *
539
+ * @param filePath - Path to file
540
+ * @param encoding - File encoding (default: utf-8)
541
+ * @returns File contents or null if file doesn't exist
542
+ */
543
+ function readFileIfExists(filePath, encoding = 'utf-8') {
544
+ if (!existsSync(filePath)) {
545
+ return null;
546
+ }
547
+ try {
548
+ return readFileSync(filePath, { encoding });
549
+ }
550
+ catch {
551
+ return null;
552
+ }
553
+ }
554
+
555
+ createScopedLogger('project-scope:fs:write');
556
+
557
+ /**
558
+ * Get file stats with error handling.
559
+ *
560
+ * @param filePath - Path to file
561
+ * @param followSymlinks - Whether to follow symlinks (default: true)
562
+ * @returns File stats or null if path doesn't exist
563
+ */
564
+ function getFileStat(filePath, followSymlinks = true) {
565
+ if (!existsSync(filePath)) {
566
+ return null;
567
+ }
568
+ try {
569
+ const stat = followSymlinks ? statSync(filePath) : lstatSync(filePath);
570
+ return {
571
+ isFile: stat.isFile(),
572
+ isDirectory: stat.isDirectory(),
573
+ isSymlink: stat.isSymbolicLink(),
574
+ size: stat.size,
575
+ created: stat.birthtime,
576
+ modified: stat.mtime,
577
+ accessed: stat.atime,
578
+ mode: stat.mode,
579
+ };
580
+ }
581
+ catch {
582
+ return null;
583
+ }
584
+ }
585
+ /**
586
+ * Check if path is a directory.
587
+ *
588
+ * @param dirPath - Path to check
589
+ * @returns True if path is a directory
590
+ */
591
+ function isDirectory(dirPath) {
592
+ const stats = getFileStat(dirPath);
593
+ return stats?.isDirectory ?? false;
594
+ }
595
+
596
+ const fsDirLogger = createScopedLogger('project-scope:fs:dir');
597
+ /**
598
+ * List immediate contents of a directory.
599
+ *
600
+ * @param dirPath - Absolute or relative path to the directory
601
+ * @returns Array of entries with metadata for each file/directory
602
+ * @throws {Error} If directory doesn't exist or isn't a directory
603
+ *
604
+ * @example
605
+ * ```typescript
606
+ * import { readDirectory } from '@hyperfrontend/project-scope'
607
+ *
608
+ * const entries = readDirectory('./src')
609
+ * for (const entry of entries) {
610
+ * console.log(entry.name, entry.isFile ? 'file' : 'directory')
611
+ * }
612
+ * ```
613
+ */
614
+ function readDirectory(dirPath) {
615
+ fsDirLogger.debug('Reading directory', { path: dirPath });
616
+ if (!existsSync(dirPath)) {
617
+ fsDirLogger.debug('Directory not found', { path: dirPath });
618
+ throw createFileSystemError(`Directory not found: ${dirPath}`, 'FS_NOT_FOUND', { path: dirPath, operation: 'readdir' });
619
+ }
620
+ if (!isDirectory(dirPath)) {
621
+ fsDirLogger.debug('Path is not a directory', { path: dirPath });
622
+ throw createFileSystemError(`Not a directory: ${dirPath}`, 'FS_NOT_A_DIRECTORY', { path: dirPath, operation: 'readdir' });
623
+ }
624
+ try {
625
+ const entries = readdirSync(dirPath, { withFileTypes: true });
626
+ fsDirLogger.debug('Directory read complete', { path: dirPath, entryCount: entries.length });
627
+ return entries.map((entry) => ({
628
+ name: entry.name,
629
+ path: join(dirPath, entry.name),
630
+ isFile: entry.isFile(),
631
+ isDirectory: entry.isDirectory(),
632
+ isSymlink: entry.isSymbolicLink(),
633
+ }));
634
+ }
635
+ catch (error) {
636
+ fsDirLogger.warn('Failed to read directory', { path: dirPath, error: error instanceof Error ? error.message : String(error) });
637
+ throw createFileSystemError(`Failed to read directory: ${dirPath}`, 'FS_READ_ERROR', {
638
+ path: dirPath,
639
+ operation: 'readdir',
640
+ cause: error,
641
+ });
642
+ }
643
+ }
644
+
645
+ createScopedLogger('project-scope:fs:traversal');
646
+
647
+ /**
648
+ * Pattern matching utilities with ReDoS protection.
649
+ * Uses character-by-character matching instead of regex where possible.
650
+ */
651
+ /**
652
+ * Match path against glob pattern using safe character iteration.
653
+ * Avoids regex to prevent ReDoS attacks.
654
+ *
655
+ * Supported patterns:
656
+ * - * matches any characters except /
657
+ * - ** matches any characters including /
658
+ * - ? matches exactly one character except /
659
+ * - {a,b,c} matches any of the alternatives
660
+ *
661
+ * @param path - The filesystem path to test against the pattern
662
+ * @param pattern - The glob pattern to match against
663
+ * @returns True if path matches pattern
664
+ *
665
+ * @example
666
+ * ```typescript
667
+ * import { matchGlobPattern } from '@hyperfrontend/project-scope'
668
+ *
669
+ * matchGlobPattern('src/utils/helper.ts', '\*\*\/*.ts') // true
670
+ * matchGlobPattern('test.spec.ts', '\*.spec.ts') // true
671
+ * matchGlobPattern('config.json', '\*.{json,yaml}') // true
672
+ * matchGlobPattern('src/index.ts', 'src/\*.ts') // true
673
+ * ```
674
+ */
675
+ function matchGlobPattern(path, pattern) {
676
+ return matchSegments(path.split('/'), pattern.split('/'), 0, 0);
677
+ }
678
+ /**
679
+ * Internal recursive function to match path segments against pattern segments.
680
+ *
681
+ * @param pathParts - Array of path segments split by '/'
682
+ * @param patternParts - Array of pattern segments split by '/'
683
+ * @param pathIdx - Current index in pathParts being examined
684
+ * @param patternIdx - Current index in patternParts being examined
685
+ * @returns True if remaining segments match
686
+ */
687
+ function matchSegments(pathParts, patternParts, pathIdx, patternIdx) {
688
+ // Base cases
689
+ if (pathIdx === pathParts.length && patternIdx === patternParts.length) {
690
+ return true; // Both exhausted = match
691
+ }
692
+ if (patternIdx >= patternParts.length) {
693
+ return false; // Pattern exhausted but path remains
694
+ }
695
+ const patternPart = patternParts[patternIdx];
696
+ // Handle ** (globstar) - matches zero or more directories
697
+ if (patternPart === '**') {
698
+ // Try matching rest of pattern against current position and all future positions
699
+ for (let i = pathIdx; i <= pathParts.length; i++) {
700
+ if (matchSegments(pathParts, patternParts, i, patternIdx + 1)) {
701
+ return true;
702
+ }
703
+ }
704
+ return false;
705
+ }
706
+ if (pathIdx >= pathParts.length) {
707
+ return false; // Path exhausted but pattern remains (and it's not **)
708
+ }
709
+ const pathPart = pathParts[pathIdx];
710
+ // Match current segment
711
+ if (matchSegment(pathPart, patternPart)) {
712
+ return matchSegments(pathParts, patternParts, pathIdx + 1, patternIdx + 1);
713
+ }
714
+ return false;
715
+ }
716
+ /**
717
+ * Match a single path segment against a pattern segment.
718
+ * Handles *, ?, and {a,b,c} patterns.
719
+ *
720
+ * @param text - The path segment text to match
721
+ * @param pattern - The pattern segment to match against
722
+ * @returns True if the text matches the pattern
723
+ */
724
+ function matchSegment(text, pattern) {
725
+ let textIdx = 0;
726
+ let patternIdx = 0;
727
+ while (patternIdx < pattern.length) {
728
+ const char = pattern[patternIdx];
729
+ if (char === '*') {
730
+ // * matches zero or more characters
731
+ patternIdx++;
732
+ if (patternIdx === pattern.length) {
733
+ return true; // * at end matches rest of string
734
+ }
735
+ // Try matching rest of pattern at each position in text
736
+ for (let i = textIdx; i <= text.length; i++) {
737
+ if (matchSegmentFrom(text, i, pattern, patternIdx)) {
738
+ return true;
739
+ }
740
+ }
741
+ return false;
742
+ }
743
+ else if (char === '?') {
744
+ // ? matches exactly one character
745
+ if (textIdx >= text.length) {
746
+ return false;
747
+ }
748
+ textIdx++;
749
+ patternIdx++;
750
+ }
751
+ else if (char === '{') {
752
+ // {a,b,c} matches any alternative
753
+ const closeIdx = findClosingBrace(pattern, patternIdx);
754
+ if (closeIdx === -1) {
755
+ // Unmatched brace, treat as literal
756
+ if (textIdx >= text.length || text[textIdx] !== char) {
757
+ return false;
758
+ }
759
+ textIdx++;
760
+ patternIdx++;
761
+ }
762
+ else {
763
+ const alternatives = extractAlternatives(pattern.slice(patternIdx + 1, closeIdx));
764
+ for (const alt of alternatives) {
765
+ if (matchSegmentFrom(text, textIdx, text.slice(0, textIdx) + alt + pattern.slice(closeIdx + 1), textIdx)) {
766
+ return true;
767
+ }
768
+ }
769
+ return false;
770
+ }
771
+ }
772
+ else {
773
+ // Literal character
774
+ if (textIdx >= text.length || text[textIdx] !== char) {
775
+ return false;
776
+ }
777
+ textIdx++;
778
+ patternIdx++;
779
+ }
780
+ }
781
+ return textIdx === text.length;
782
+ }
783
+ /**
784
+ * Helper to match from a specific position.
785
+ *
786
+ * @param text - The full text being matched
787
+ * @param textIdx - The starting index in text to match from
788
+ * @param pattern - The full pattern being matched
789
+ * @param patternIdx - The starting index in pattern to match from
790
+ * @returns True if the text matches the pattern from the given positions
791
+ */
792
+ function matchSegmentFrom(text, textIdx, pattern, patternIdx) {
793
+ const remainingText = text.slice(textIdx);
794
+ const remainingPattern = pattern.slice(patternIdx);
795
+ return matchSegment(remainingText, remainingPattern);
796
+ }
797
+ /**
798
+ * Find closing brace for {a,b,c} pattern.
799
+ *
800
+ * @param pattern - The pattern string to search within
801
+ * @param startIdx - The index of the opening brace
802
+ * @returns The index of the matching closing brace, or -1 if not found
803
+ */
804
+ function findClosingBrace(pattern, startIdx) {
805
+ let depth = 0;
806
+ for (let i = startIdx; i < pattern.length; i++) {
807
+ if (pattern[i] === '{') {
808
+ depth++;
809
+ }
810
+ else if (pattern[i] === '}') {
811
+ depth--;
812
+ if (depth === 0) {
813
+ return i;
814
+ }
815
+ }
816
+ }
817
+ return -1;
818
+ }
819
+ /**
820
+ * Extract alternatives from {a,b,c} pattern content.
821
+ *
822
+ * @param content - The content between braces (without the braces themselves)
823
+ * @returns Array of alternative strings split by commas at depth 0
824
+ */
825
+ function extractAlternatives(content) {
826
+ const alternatives = [];
827
+ let current = '';
828
+ let depth = 0;
829
+ for (let i = 0; i < content.length; i++) {
830
+ const char = content[i];
831
+ if (char === '{') {
832
+ depth++;
833
+ current += char;
834
+ }
835
+ else if (char === '}') {
836
+ depth--;
837
+ current += char;
838
+ }
839
+ else if (char === ',' && depth === 0) {
840
+ alternatives.push(current);
841
+ current = '';
842
+ }
843
+ else {
844
+ current += char;
845
+ }
846
+ }
847
+ if (current) {
848
+ alternatives.push(current);
849
+ }
850
+ return alternatives;
851
+ }
852
+
853
+ const walkLogger = createScopedLogger('project-scope:project:walk');
854
+ /**
855
+ * Reads .gitignore file from the given directory and extracts
856
+ * non-comment patterns for use in file traversal filtering.
857
+ *
858
+ * @param startPath - Directory containing the .gitignore file
859
+ * @returns Array of gitignore patterns
860
+ */
861
+ function loadGitignorePatterns(startPath) {
862
+ const patterns = [];
863
+ const gitignorePath = join(startPath, '.gitignore');
864
+ const content = readFileIfExists(gitignorePath);
865
+ if (content) {
866
+ const lines = content.split('\n');
867
+ for (const line of lines) {
868
+ const trimmed = line.trim();
869
+ if (trimmed && !trimmed.startsWith('#')) {
870
+ patterns.push(trimmed);
871
+ }
872
+ }
873
+ }
874
+ return patterns;
875
+ }
876
+ /**
877
+ * Evaluates whether a relative path should be ignored based on
878
+ * a list of gitignore-style patterns.
879
+ *
880
+ * @param relativePath - Path relative to the root directory
881
+ * @param patterns - Array of gitignore-style patterns to test
882
+ * @returns True if the path matches any ignore pattern
883
+ */
884
+ function matchesIgnorePattern(relativePath, patterns) {
885
+ for (const pattern of patterns) {
886
+ if (matchPattern(relativePath, pattern)) {
887
+ return true;
888
+ }
889
+ }
890
+ return false;
891
+ }
892
+ /**
893
+ * Tests if the given path matches a gitignore-style pattern,
894
+ * supporting negation patterns with '!' prefix.
895
+ * Uses safe character-by-character matching to prevent ReDoS attacks.
896
+ *
897
+ * @param path - File or directory path to test
898
+ * @param pattern - Gitignore-style pattern (may include wildcards)
899
+ * @returns True if the path matches the pattern (or doesn't match if negated)
900
+ */
901
+ function matchPattern(path, pattern) {
902
+ const normalizedPattern = pattern.startsWith('/') ? pattern.slice(1) : pattern;
903
+ const isNegation = normalizedPattern.startsWith('!');
904
+ const actualPattern = isNegation ? normalizedPattern.slice(1) : normalizedPattern;
905
+ const matchesFullPath = matchGlobPattern(path, actualPattern) || matchGlobPattern(path, `**/${actualPattern}`);
906
+ const matchesSegment = path.split('/').some((segment) => matchGlobPattern(segment, actualPattern));
907
+ const matches = matchesFullPath || matchesSegment;
908
+ return isNegation ? !matches : matches;
909
+ }
910
+ /**
911
+ * Traverses a directory tree synchronously, calling a visitor function
912
+ * for each file and directory encountered. Supports depth limiting,
913
+ * hidden file filtering, and gitignore pattern matching.
914
+ *
915
+ * @param startPath - Root directory to begin traversal
916
+ * @param visitor - Callback function invoked for each file system entry
917
+ * @param options - Configuration for traversal behavior
918
+ */
919
+ function walkDirectory(startPath, visitor, options) {
920
+ walkLogger.debug('Starting directory walk', {
921
+ startPath,
922
+ maxDepth: options?.maxDepth ?? -1,
923
+ includeHidden: options?.includeHidden ?? false,
924
+ respectGitignore: options?.respectGitignore ?? true,
925
+ ignorePatterns: options?.ignorePatterns?.length ?? 0,
926
+ });
927
+ const maxDepth = options?.maxDepth ?? -1;
928
+ const includeHidden = options?.includeHidden ?? false;
929
+ const ignorePatterns = options?.ignorePatterns ?? [];
930
+ const respectGitignore = options?.respectGitignore ?? true;
931
+ const gitignorePatterns = respectGitignore ? loadGitignorePatterns(startPath) : [];
932
+ const allIgnorePatterns = [...ignorePatterns, ...gitignorePatterns];
933
+ if (gitignorePatterns.length > 0) {
934
+ walkLogger.debug('Loaded gitignore patterns', { count: gitignorePatterns.length });
935
+ }
936
+ /**
937
+ * Recursively walks directory entries, applying visitor to each.
938
+ *
939
+ * @param currentPath - Absolute path to current directory
940
+ * @param relativePath - Path relative to the starting directory
941
+ * @param depth - Current recursion depth
942
+ * @returns False to stop walking, true to continue
943
+ */
944
+ function walk(currentPath, relativePath, depth) {
945
+ if (maxDepth !== -1 && depth > maxDepth) {
946
+ return true;
947
+ }
948
+ let entries;
949
+ try {
950
+ entries = readDirectory(currentPath);
951
+ }
952
+ catch {
953
+ return true;
954
+ }
955
+ for (const entry of entries) {
956
+ if (!includeHidden && entry.name.startsWith('.')) {
957
+ continue;
958
+ }
959
+ const entryRelativePath = relativePath ? `${relativePath}/${entry.name}` : entry.name;
960
+ if (matchesIgnorePattern(entryRelativePath, allIgnorePatterns)) {
961
+ continue;
962
+ }
963
+ const walkEntry = {
964
+ name: entry.name,
965
+ path: entry.path,
966
+ relativePath: entryRelativePath,
967
+ isFile: entry.isFile,
968
+ isDirectory: entry.isDirectory,
969
+ isSymlink: entry.isSymlink,
970
+ depth,
971
+ };
972
+ const result = visitor(walkEntry);
973
+ if (result === 'stop') {
974
+ return false;
975
+ }
976
+ if (result === 'skip') {
977
+ continue;
978
+ }
979
+ if (entry.isDirectory) {
980
+ const shouldContinue = walk(entry.path, entryRelativePath, depth + 1);
981
+ if (!shouldContinue) {
982
+ return false;
983
+ }
984
+ }
985
+ }
986
+ return true;
987
+ }
988
+ walk(startPath, '', 0);
989
+ walkLogger.debug('Directory walk complete', { startPath });
990
+ }
991
+ /**
992
+ * Traverses a virtual file system tree, calling a visitor function
993
+ * for each file and directory. Operates on in-memory tree structure
994
+ * without disk I/O.
995
+ *
996
+ * @param tree - In-memory virtual file system representation
997
+ * @param startPath - Root path within the tree to begin traversal
998
+ * @param visitor - Callback function invoked for each tree entry
999
+ * @param options - Configuration for traversal behavior
1000
+ */
1001
+ function walkTree(tree, startPath, visitor, options) {
1002
+ const maxDepth = options?.maxDepth ?? -1;
1003
+ const includeHidden = options?.includeHidden ?? false;
1004
+ /**
1005
+ * Recursively walks tree entries, applying visitor to each.
1006
+ *
1007
+ * @param currentPath - Current path within the tree
1008
+ * @param relativePath - Path relative to the starting path
1009
+ * @param depth - Current recursion depth
1010
+ * @returns False to stop walking, true to continue
1011
+ */
1012
+ function walk(currentPath, relativePath, depth) {
1013
+ if (maxDepth !== -1 && depth > maxDepth) {
1014
+ return true;
1015
+ }
1016
+ let children;
1017
+ try {
1018
+ children = tree.children(currentPath);
1019
+ }
1020
+ catch {
1021
+ return true;
1022
+ }
1023
+ for (const name of children) {
1024
+ if (!includeHidden && name.startsWith('.')) {
1025
+ continue;
1026
+ }
1027
+ const childPath = currentPath ? `${currentPath}/${name}` : name;
1028
+ const entryRelativePath = relativePath ? `${relativePath}/${name}` : name;
1029
+ const isFileEntry = tree.isFile(childPath);
1030
+ const walkEntry = {
1031
+ name,
1032
+ path: childPath,
1033
+ relativePath: entryRelativePath,
1034
+ isFile: isFileEntry,
1035
+ isDirectory: !isFileEntry,
1036
+ isSymlink: false,
1037
+ depth,
1038
+ };
1039
+ const result = visitor(walkEntry);
1040
+ if (result === 'stop') {
1041
+ return false;
1042
+ }
1043
+ if (result === 'skip') {
1044
+ continue;
1045
+ }
1046
+ if (!isFileEntry) {
1047
+ const shouldContinue = walk(childPath, entryRelativePath, depth + 1);
1048
+ if (!shouldContinue) {
1049
+ return false;
1050
+ }
1051
+ }
1052
+ }
1053
+ return true;
1054
+ }
1055
+ walk(startPath, '', 0);
1056
+ }
1057
+
1058
+ const searchLogger = createScopedLogger('project-scope:project:search');
1059
+ /**
1060
+ * Tests if a path matches at least one pattern from an array of globs,
1061
+ * enabling flexible multi-pattern file filtering.
1062
+ * Uses safe character-by-character matching to prevent ReDoS attacks.
1063
+ *
1064
+ * @param path - File path to test
1065
+ * @param patterns - Array of glob patterns
1066
+ * @returns True if path matches any pattern
1067
+ */
1068
+ function matchesPatterns(path, patterns) {
1069
+ return patterns.some((pattern) => matchGlobPattern(path, pattern));
1070
+ }
1071
+ /**
1072
+ * Searches a directory tree for files matching one or more glob patterns,
1073
+ * returning relative or absolute paths based on options.
1074
+ *
1075
+ * @param startPath - Root directory to begin the search
1076
+ * @param patterns - Glob patterns (e.g., '*.ts', '**\/*.json') to filter files
1077
+ * @param options - Configuration for search behavior
1078
+ * @returns List of relative file paths that match the patterns
1079
+ *
1080
+ * @example
1081
+ * ```typescript
1082
+ * import { findFiles } from '@hyperfrontend/project-scope'
1083
+ *
1084
+ * // Find all TypeScript files
1085
+ * const tsFiles = findFiles('./src', '\*\*\/*.ts')
1086
+ *
1087
+ * // Find multiple file types
1088
+ * const configFiles = findFiles('./', ['\*.json', '\*.yaml', '\*.yml'])
1089
+ *
1090
+ * // Limit results and get absolute paths
1091
+ * const first10 = findFiles('./src', '\*\*\/*.ts', {
1092
+ * maxResults: 10,
1093
+ * absolutePaths: true
1094
+ * })
1095
+ * ```
1096
+ */
1097
+ function findFiles(startPath, patterns, options) {
1098
+ const normalizedPatterns = isArray(patterns) ? patterns : [patterns];
1099
+ searchLogger.debug('Finding files', { startPath, patterns: normalizedPatterns, maxResults: options?.maxResults });
1100
+ const results = [];
1101
+ const maxResults = options?.maxResults ?? Infinity;
1102
+ walkDirectory(startPath, (entry) => {
1103
+ if (results.length >= maxResults) {
1104
+ return 'stop';
1105
+ }
1106
+ if (!entry.isFile) {
1107
+ return undefined;
1108
+ }
1109
+ if (matchesPatterns(entry.relativePath, normalizedPatterns)) {
1110
+ results.push(options?.absolutePaths ? entry.path : entry.relativePath);
1111
+ }
1112
+ return undefined;
1113
+ }, options);
1114
+ searchLogger.debug('File search complete', { startPath, matchCount: results.length });
1115
+ return results;
1116
+ }
1117
+ /**
1118
+ * Searches a virtual file system tree for files matching glob patterns,
1119
+ * useful for analyzing project structure without disk I/O.
1120
+ *
1121
+ * @param tree - In-memory virtual file system representation
1122
+ * @param patterns - Glob patterns (e.g., '*.ts', '**\/*.json') to filter files
1123
+ * @param options - Configuration for search behavior
1124
+ * @returns List of virtual file paths that match the patterns
1125
+ */
1126
+ function findFilesInTree(tree, patterns, options) {
1127
+ const normalizedPatterns = isArray(patterns) ? patterns : [patterns];
1128
+ const results = [];
1129
+ const maxResults = options?.maxResults ?? Infinity;
1130
+ walkTree(tree, tree.root || '', (entry) => {
1131
+ if (results.length >= maxResults) {
1132
+ return 'stop';
1133
+ }
1134
+ if (!entry.isFile) {
1135
+ return undefined;
1136
+ }
1137
+ if (matchesPatterns(entry.relativePath, normalizedPatterns)) {
1138
+ results.push(entry.relativePath);
1139
+ }
1140
+ return undefined;
1141
+ }, options);
1142
+ return results;
1143
+ }
1144
+ /**
1145
+ * Searches a directory tree for directories matching one or more glob patterns,
1146
+ * returning relative or absolute paths based on options.
1147
+ *
1148
+ * @param startPath - Root directory to begin the search
1149
+ * @param patterns - Glob patterns to filter directories (supports wildcards)
1150
+ * @param options - Configuration for search behavior
1151
+ * @returns List of relative directory paths that match the patterns
1152
+ */
1153
+ function findDirectories(startPath, patterns, options) {
1154
+ const normalizedPatterns = isArray(patterns) ? patterns : [patterns];
1155
+ const results = [];
1156
+ const maxResults = options?.maxResults ?? Infinity;
1157
+ walkDirectory(startPath, (entry) => {
1158
+ if (results.length >= maxResults) {
1159
+ return 'stop';
1160
+ }
1161
+ if (!entry.isDirectory) {
1162
+ return undefined;
1163
+ }
1164
+ if (matchesPatterns(entry.relativePath, normalizedPatterns)) {
1165
+ results.push(options?.absolutePaths ? entry.path : entry.relativePath);
1166
+ }
1167
+ return undefined;
1168
+ }, options);
1169
+ return results;
1170
+ }
1171
+
1172
+ export { findDirectories, findFiles, findFilesInTree, walkDirectory, walkTree };
1173
+ //# sourceMappingURL=index.esm.js.map