@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,1971 @@
1
+ import { join, basename } from 'node:path';
2
+ import { existsSync, readFileSync, statSync, lstatSync, readdirSync } from 'node:fs';
3
+
4
+ /**
5
+ * Known configuration file patterns organized by type.
6
+ */
7
+ const CONFIG_PATTERNS = {
8
+ // Package Management
9
+ 'package.json': {
10
+ patterns: ['package.json'],
11
+ format: 'json',
12
+ description: 'NPM package manifest',
13
+ },
14
+ 'package-lock.json': {
15
+ patterns: ['package-lock.json'],
16
+ format: 'json',
17
+ description: 'NPM lockfile',
18
+ },
19
+ 'pnpm-lock.yaml': {
20
+ patterns: ['pnpm-lock.yaml'],
21
+ format: 'yaml',
22
+ description: 'PNPM lockfile',
23
+ },
24
+ 'yarn.lock': {
25
+ patterns: ['yarn.lock'],
26
+ format: 'text',
27
+ description: 'Yarn lockfile',
28
+ },
29
+ '.npmrc': {
30
+ patterns: ['.npmrc'],
31
+ format: 'ini',
32
+ description: 'NPM configuration',
33
+ sensitive: true,
34
+ },
35
+ // TypeScript
36
+ tsconfig: {
37
+ patterns: ['tsconfig.json', 'tsconfig.*.json'],
38
+ format: 'jsonc',
39
+ description: 'TypeScript configuration',
40
+ canExtend: true,
41
+ },
42
+ // Monorepo
43
+ nx: {
44
+ patterns: ['nx.json'],
45
+ format: 'json',
46
+ description: 'NX workspace configuration',
47
+ },
48
+ 'project.json': {
49
+ patterns: ['project.json', '**/project.json'],
50
+ format: 'json',
51
+ description: 'NX project configuration',
52
+ },
53
+ 'workspace.json': {
54
+ patterns: ['workspace.json'],
55
+ format: 'json',
56
+ description: 'NX workspace projects (deprecated)',
57
+ },
58
+ turbo: {
59
+ patterns: ['turbo.json'],
60
+ format: 'jsonc',
61
+ description: 'TurboRepo configuration',
62
+ },
63
+ lerna: {
64
+ patterns: ['lerna.json'],
65
+ format: 'json',
66
+ description: 'Lerna configuration',
67
+ },
68
+ // Build Tools
69
+ webpack: {
70
+ patterns: ['webpack.config.js', 'webpack.config.ts', 'webpack.config.cjs', 'webpack.config.mjs'],
71
+ format: 'js',
72
+ description: 'Webpack configuration',
73
+ },
74
+ rollup: {
75
+ patterns: ['rollup.config.js', 'rollup.config.ts', 'rollup.config.mjs'],
76
+ format: 'js',
77
+ description: 'Rollup configuration',
78
+ },
79
+ vite: {
80
+ patterns: ['vite.config.js', 'vite.config.ts', 'vite.config.mjs'],
81
+ format: 'js',
82
+ description: 'Vite configuration',
83
+ },
84
+ esbuild: {
85
+ patterns: ['esbuild.config.js', 'esbuild.config.ts', 'esbuild.config.mjs'],
86
+ format: 'js',
87
+ description: 'esbuild configuration',
88
+ },
89
+ babel: {
90
+ patterns: ['babel.config.js', 'babel.config.json', '.babelrc', '.babelrc.js', '.babelrc.json'],
91
+ format: 'json',
92
+ description: 'Babel configuration',
93
+ },
94
+ swc: {
95
+ patterns: ['.swcrc'],
96
+ format: 'json',
97
+ description: 'SWC configuration',
98
+ },
99
+ // Testing
100
+ jest: {
101
+ patterns: ['jest.config.js', 'jest.config.ts', 'jest.config.mjs'],
102
+ description: 'Jest configuration',
103
+ },
104
+ vitest: {
105
+ patterns: ['vitest.config.js', 'vitest.config.ts'],
106
+ description: 'Vitest configuration',
107
+ },
108
+ cypress: {
109
+ patterns: ['cypress.config.js', 'cypress.config.ts'],
110
+ description: 'Cypress configuration',
111
+ },
112
+ playwright: {
113
+ patterns: ['playwright.config.js', 'playwright.config.ts'],
114
+ description: 'Playwright configuration',
115
+ },
116
+ // Framework configs
117
+ next: {
118
+ patterns: ['next.config.js', 'next.config.mjs', 'next.config.ts'],
119
+ format: 'js',
120
+ description: 'Next.js configuration',
121
+ },
122
+ angular: {
123
+ patterns: ['angular.json'],
124
+ format: 'json',
125
+ description: 'Angular CLI configuration',
126
+ },
127
+ nuxt: {
128
+ patterns: ['nuxt.config.js', 'nuxt.config.ts'],
129
+ format: 'js',
130
+ description: 'Nuxt.js configuration',
131
+ },
132
+ svelte: {
133
+ patterns: ['svelte.config.js', 'svelte.config.ts'],
134
+ format: 'js',
135
+ description: 'SvelteKit configuration',
136
+ },
137
+ astro: {
138
+ patterns: ['astro.config.js', 'astro.config.ts', 'astro.config.mjs'],
139
+ format: 'js',
140
+ description: 'Astro configuration',
141
+ },
142
+ // Linting & Formatting
143
+ eslint: {
144
+ patterns: [
145
+ 'eslint.config.js',
146
+ 'eslint.config.cjs',
147
+ 'eslint.config.mjs',
148
+ '.eslintrc',
149
+ '.eslintrc.js',
150
+ '.eslintrc.json',
151
+ '.eslintrc.yml',
152
+ ],
153
+ format: 'js',
154
+ description: 'ESLint configuration',
155
+ },
156
+ prettier: {
157
+ patterns: ['prettier.config.js', 'prettier.config.cjs', '.prettierrc', '.prettierrc.js', '.prettierrc.json', '.prettierrc.yml'],
158
+ format: 'json',
159
+ description: 'Prettier configuration',
160
+ },
161
+ // Environment (sensitive)
162
+ env: {
163
+ patterns: ['.env', '.env.*', '*.env'],
164
+ format: 'dotenv',
165
+ description: 'Environment variables',
166
+ sensitive: true,
167
+ },
168
+ // Git
169
+ '.gitignore': {
170
+ patterns: ['.gitignore'],
171
+ format: 'text',
172
+ description: 'Git ignore patterns',
173
+ },
174
+ '.gitattributes': {
175
+ patterns: ['.gitattributes'],
176
+ format: 'text',
177
+ description: 'Git attributes',
178
+ },
179
+ };
180
+ /**
181
+ * Get patterns for specific config types.
182
+ *
183
+ * @param types - Array of config types to get patterns for
184
+ * @returns Array of file patterns
185
+ */
186
+ function getConfigPatternsByType(types) {
187
+ return types.flatMap((type) => CONFIG_PATTERNS[type]?.patterns ?? []);
188
+ }
189
+
190
+ /**
191
+ * Safe copies of Object built-in methods.
192
+ *
193
+ * These references are captured at module initialization time to protect against
194
+ * prototype pollution attacks. Import only what you need for tree-shaking.
195
+ *
196
+ * @module @hyperfrontend/immutable-api-utils/built-in-copy/object
197
+ */
198
+ // Capture references at module initialization time
199
+ const _Object = globalThis.Object;
200
+ /**
201
+ * (Safe copy) Prevents modification of existing property attributes and values,
202
+ * and prevents the addition of new properties.
203
+ */
204
+ const freeze = _Object.freeze;
205
+ /**
206
+ * (Safe copy) Returns the names of the enumerable string properties and methods of an object.
207
+ */
208
+ const keys = _Object.keys;
209
+ /**
210
+ * (Safe copy) Returns an array of key/values of the enumerable own properties of an object.
211
+ */
212
+ const entries = _Object.entries;
213
+ /**
214
+ * (Safe copy) Adds one or more properties to an object, and/or modifies attributes of existing properties.
215
+ */
216
+ const defineProperties = _Object.defineProperties;
217
+
218
+ /**
219
+ * Safe copies of Map built-in via factory function.
220
+ *
221
+ * Since constructors cannot be safely captured via Object.assign, this module
222
+ * provides a factory function that uses Reflect.construct internally.
223
+ *
224
+ * These references are captured at module initialization time to protect against
225
+ * prototype pollution attacks. Import only what you need for tree-shaking.
226
+ *
227
+ * @module @hyperfrontend/immutable-api-utils/built-in-copy/map
228
+ */
229
+ // Capture references at module initialization time
230
+ const _Map = globalThis.Map;
231
+ const _Reflect$2 = globalThis.Reflect;
232
+ /**
233
+ * (Safe copy) Creates a new Map using the captured Map constructor.
234
+ * Use this instead of `new Map()`.
235
+ *
236
+ * @param iterable - Optional iterable of key-value pairs.
237
+ * @returns A new Map instance.
238
+ */
239
+ const createMap = (iterable) => _Reflect$2.construct(_Map, iterable ? [iterable] : []);
240
+
241
+ /**
242
+ * Safe copies of Set built-in via factory function.
243
+ *
244
+ * Since constructors cannot be safely captured via Object.assign, this module
245
+ * provides a factory function that uses Reflect.construct internally.
246
+ *
247
+ * These references are captured at module initialization time to protect against
248
+ * prototype pollution attacks. Import only what you need for tree-shaking.
249
+ *
250
+ * @module @hyperfrontend/immutable-api-utils/built-in-copy/set
251
+ */
252
+ // Capture references at module initialization time
253
+ const _Set = globalThis.Set;
254
+ const _Reflect$1 = globalThis.Reflect;
255
+ /**
256
+ * (Safe copy) Creates a new Set using the captured Set constructor.
257
+ * Use this instead of `new Set()`.
258
+ *
259
+ * @param iterable - Optional iterable of values.
260
+ * @returns A new Set instance.
261
+ */
262
+ const createSet = (iterable) => _Reflect$1.construct(_Set, iterable ? [iterable] : []);
263
+
264
+ /**
265
+ * Global registry of all caches for bulk operations.
266
+ */
267
+ const cacheRegistry = createSet();
268
+ /**
269
+ * Create a cache with optional TTL and size limits.
270
+ *
271
+ * The cache provides a simple key-value store with:
272
+ * - Optional TTL (time-to-live) for automatic expiration
273
+ * - Optional maxSize for limiting cache size with FIFO eviction
274
+ * - Lazy expiration (entries are checked on access)
275
+ *
276
+ * @param options - Cache configuration options
277
+ * @returns Cache instance
278
+ *
279
+ * @example
280
+ * ```typescript
281
+ * // Basic cache
282
+ * const cache = createCache<string, number>()
283
+ * cache.set('answer', 42)
284
+ * cache.get('answer') // 42
285
+ *
286
+ * // Cache with TTL (expires after 60 seconds)
287
+ * const ttlCache = createCache<string, object>({ ttl: 60000 })
288
+ *
289
+ * // Cache with max size (evicts oldest when full)
290
+ * const lruCache = createCache<string, object>({ maxSize: 100 })
291
+ *
292
+ * // Combined options
293
+ * const configCache = createCache<string, object>({
294
+ * ttl: 30000,
295
+ * maxSize: 50
296
+ * })
297
+ * ```
298
+ */
299
+ function createCache(options) {
300
+ const { ttl, maxSize } = options ?? {};
301
+ const store = createMap();
302
+ // Track insertion order for FIFO eviction
303
+ const insertionOrder = [];
304
+ /**
305
+ * Check if an entry is expired.
306
+ *
307
+ * @param entry - Cache entry to check
308
+ * @returns True if entry is expired
309
+ */
310
+ function isExpired(entry) {
311
+ if (ttl === undefined)
312
+ return false;
313
+ // eslint-disable-next-line workspace/no-unsafe-builtin-methods -- Date.now() is needed for Jest fake timers compatibility
314
+ return Date.now() - entry.timestamp > ttl;
315
+ }
316
+ /**
317
+ * Evict oldest entries to make room for new ones.
318
+ */
319
+ function evictIfNeeded() {
320
+ if (maxSize === undefined)
321
+ return;
322
+ while (store.size >= maxSize && insertionOrder.length > 0) {
323
+ const oldestKey = insertionOrder.shift();
324
+ if (oldestKey !== undefined) {
325
+ store.delete(oldestKey);
326
+ }
327
+ }
328
+ }
329
+ /**
330
+ * Remove key from insertion order tracking.
331
+ *
332
+ * @param key - Key to remove from order tracking
333
+ */
334
+ function removeFromOrder(key) {
335
+ const index = insertionOrder.indexOf(key);
336
+ if (index !== -1) {
337
+ insertionOrder.splice(index, 1);
338
+ }
339
+ }
340
+ const cache = {
341
+ get(key) {
342
+ const entry = store.get(key);
343
+ if (!entry)
344
+ return undefined;
345
+ if (isExpired(entry)) {
346
+ store.delete(key);
347
+ removeFromOrder(key);
348
+ return undefined;
349
+ }
350
+ return entry.value;
351
+ },
352
+ set(key, value) {
353
+ // If key exists, remove from order first
354
+ if (store.has(key)) {
355
+ removeFromOrder(key);
356
+ }
357
+ else {
358
+ // Evict if needed before adding new entry
359
+ evictIfNeeded();
360
+ }
361
+ // eslint-disable-next-line workspace/no-unsafe-builtin-methods -- Date.now() is needed for Jest fake timers compatibility
362
+ store.set(key, { value, timestamp: Date.now() });
363
+ insertionOrder.push(key);
364
+ },
365
+ has(key) {
366
+ const entry = store.get(key);
367
+ if (!entry)
368
+ return false;
369
+ if (isExpired(entry)) {
370
+ store.delete(key);
371
+ removeFromOrder(key);
372
+ return false;
373
+ }
374
+ return true;
375
+ },
376
+ delete(key) {
377
+ removeFromOrder(key);
378
+ return store.delete(key);
379
+ },
380
+ clear() {
381
+ store.clear();
382
+ insertionOrder.length = 0;
383
+ },
384
+ size() {
385
+ return store.size;
386
+ },
387
+ keys() {
388
+ return [...insertionOrder];
389
+ },
390
+ };
391
+ // Register cache for global operations
392
+ cacheRegistry.add(cache);
393
+ return freeze(cache);
394
+ }
395
+
396
+ /**
397
+ * Safe copies of Error built-ins via factory functions.
398
+ *
399
+ * Since constructors cannot be safely captured via Object.assign, this module
400
+ * provides factory functions that use Reflect.construct internally.
401
+ *
402
+ * These references are captured at module initialization time to protect against
403
+ * prototype pollution attacks. Import only what you need for tree-shaking.
404
+ *
405
+ * @module @hyperfrontend/immutable-api-utils/built-in-copy/error
406
+ */
407
+ // Capture references at module initialization time
408
+ const _Error = globalThis.Error;
409
+ const _Reflect = globalThis.Reflect;
410
+ /**
411
+ * (Safe copy) Creates a new Error using the captured Error constructor.
412
+ * Use this instead of `new Error()`.
413
+ *
414
+ * @param message - Optional error message.
415
+ * @param options - Optional error options.
416
+ * @returns A new Error instance.
417
+ */
418
+ const createError = (message, options) => _Reflect.construct(_Error, [message, options]);
419
+
420
+ /**
421
+ * Safe copies of JSON built-in methods.
422
+ *
423
+ * These references are captured at module initialization time to protect against
424
+ * prototype pollution attacks. Import only what you need for tree-shaking.
425
+ *
426
+ * @module @hyperfrontend/immutable-api-utils/built-in-copy/json
427
+ */
428
+ // Capture references at module initialization time
429
+ const _JSON = globalThis.JSON;
430
+ /**
431
+ * (Safe copy) Converts a JavaScript Object Notation (JSON) string into an object.
432
+ */
433
+ const parse = _JSON.parse;
434
+ /**
435
+ * (Safe copy) Converts a JavaScript value to a JavaScript Object Notation (JSON) string.
436
+ */
437
+ const stringify = _JSON.stringify;
438
+
439
+ /**
440
+ * Safe copies of Array built-in static methods.
441
+ *
442
+ * These references are captured at module initialization time to protect against
443
+ * prototype pollution attacks. Import only what you need for tree-shaking.
444
+ *
445
+ * @module @hyperfrontend/immutable-api-utils/built-in-copy/array
446
+ */
447
+ // Capture references at module initialization time
448
+ const _Array = globalThis.Array;
449
+ /**
450
+ * (Safe copy) Determines whether the passed value is an Array.
451
+ */
452
+ const isArray = _Array.isArray;
453
+
454
+ /**
455
+ * Safe copies of Console built-in methods.
456
+ *
457
+ * These references are captured at module initialization time to protect against
458
+ * prototype pollution attacks. Import only what you need for tree-shaking.
459
+ *
460
+ * @module @hyperfrontend/immutable-api-utils/built-in-copy/console
461
+ */
462
+ // Capture references at module initialization time
463
+ const _console = globalThis.console;
464
+ /**
465
+ * (Safe copy) Outputs a message to the console.
466
+ */
467
+ const log = _console.log.bind(_console);
468
+ /**
469
+ * (Safe copy) Outputs a warning message to the console.
470
+ */
471
+ const warn = _console.warn.bind(_console);
472
+ /**
473
+ * (Safe copy) Outputs an error message to the console.
474
+ */
475
+ const error = _console.error.bind(_console);
476
+ /**
477
+ * (Safe copy) Outputs an informational message to the console.
478
+ */
479
+ const info = _console.info.bind(_console);
480
+ /**
481
+ * (Safe copy) Outputs a debug message to the console.
482
+ */
483
+ const debug = _console.debug.bind(_console);
484
+ /**
485
+ * (Safe copy) Outputs a stack trace to the console.
486
+ */
487
+ _console.trace.bind(_console);
488
+ /**
489
+ * (Safe copy) Displays an interactive listing of the properties of a specified object.
490
+ */
491
+ _console.dir.bind(_console);
492
+ /**
493
+ * (Safe copy) Displays tabular data as a table.
494
+ */
495
+ _console.table.bind(_console);
496
+ /**
497
+ * (Safe copy) Writes an error message to the console if the assertion is false.
498
+ */
499
+ _console.assert.bind(_console);
500
+ /**
501
+ * (Safe copy) Clears the console.
502
+ */
503
+ _console.clear.bind(_console);
504
+ /**
505
+ * (Safe copy) Logs the number of times that this particular call to count() has been called.
506
+ */
507
+ _console.count.bind(_console);
508
+ /**
509
+ * (Safe copy) Resets the counter used with console.count().
510
+ */
511
+ _console.countReset.bind(_console);
512
+ /**
513
+ * (Safe copy) Creates a new inline group in the console.
514
+ */
515
+ _console.group.bind(_console);
516
+ /**
517
+ * (Safe copy) Creates a new inline group in the console that is initially collapsed.
518
+ */
519
+ _console.groupCollapsed.bind(_console);
520
+ /**
521
+ * (Safe copy) Exits the current inline group.
522
+ */
523
+ _console.groupEnd.bind(_console);
524
+ /**
525
+ * (Safe copy) Starts a timer with a name specified as an input parameter.
526
+ */
527
+ _console.time.bind(_console);
528
+ /**
529
+ * (Safe copy) Stops a timer that was previously started.
530
+ */
531
+ _console.timeEnd.bind(_console);
532
+ /**
533
+ * (Safe copy) Logs the current value of a timer that was previously started.
534
+ */
535
+ _console.timeLog.bind(_console);
536
+
537
+ const registeredClasses = [];
538
+
539
+ /**
540
+ * Returns the data type of the target.
541
+ * Uses native `typeof` operator, however, makes distinction between `null`, `array`, and `object`.
542
+ * Also, when classes are registered via `registerClass`, it checks if objects are instance of any known registered class.
543
+ *
544
+ * @param target - The target to get the data type of.
545
+ * @returns The data type of the target.
546
+ */
547
+ const getType = (target) => {
548
+ if (target === null)
549
+ return 'null';
550
+ const nativeDataType = typeof target;
551
+ if (nativeDataType === 'object') {
552
+ if (isArray(target))
553
+ return 'array';
554
+ for (const registeredClass of registeredClasses) {
555
+ if (target instanceof registeredClass)
556
+ return registeredClass.name;
557
+ }
558
+ }
559
+ return nativeDataType;
560
+ };
561
+
562
+ /* eslint-disable @typescript-eslint/no-explicit-any */
563
+ /**
564
+ * Creates a wrapper function that only executes the wrapped function if the condition function returns true.
565
+ *
566
+ * @param func - The function to be conditionally executed.
567
+ * @param conditionFunc - A function that returns a boolean, determining if `func` should be executed.
568
+ * @returns A wrapped version of `func` that executes conditionally.
569
+ */
570
+ function createConditionalExecutionFunction(func, conditionFunc) {
571
+ return function (...args) {
572
+ if (conditionFunc()) {
573
+ return func(...args);
574
+ }
575
+ };
576
+ }
577
+
578
+ /* eslint-disable @typescript-eslint/no-explicit-any */
579
+ /**
580
+ * Creates a wrapper function that silently ignores any errors thrown by the wrapped void function.
581
+ * This function is specifically for wrapping functions that do not return a value (void functions).
582
+ * Exceptions are swallowed without any logging or handling.
583
+ *
584
+ * @param func - The void function to be wrapped.
585
+ * @returns A wrapped version of the input function that ignores errors.
586
+ */
587
+ function createErrorIgnoringFunction(func) {
588
+ return function (...args) {
589
+ try {
590
+ func(...args);
591
+ }
592
+ catch {
593
+ // Deliberately swallowing/ignoring the exception
594
+ }
595
+ };
596
+ }
597
+
598
+ /* eslint-disable @typescript-eslint/no-unused-vars */
599
+ /**
600
+ * A no-operation function (noop) that does nothing regardless of the arguments passed.
601
+ * It is designed to be as permissive as possible in its typing without using the `Function` keyword.
602
+ *
603
+ * @param args - Any arguments passed to the function (ignored)
604
+ */
605
+ const noop = (...args) => {
606
+ // Intentionally does nothing
607
+ };
608
+
609
+ const logLevels = ['none', 'error', 'warn', 'log', 'info', 'debug'];
610
+ const priority = {
611
+ error: 4,
612
+ warn: 3,
613
+ log: 2,
614
+ info: 1,
615
+ debug: 0,
616
+ };
617
+ /**
618
+ * Validates whether a given string is a valid log level.
619
+ *
620
+ * @param level - The log level to validate
621
+ * @returns True if the level is valid, false otherwise
622
+ */
623
+ function isValidLogLevel(level) {
624
+ return logLevels.includes(level);
625
+ }
626
+ /**
627
+ * Creates a log level configuration manager for controlling logging behavior.
628
+ * Provides methods to get, set, and evaluate log levels based on priority.
629
+ *
630
+ * @param level - The initial log level (defaults to 'error')
631
+ * @returns A configuration object with log level management methods
632
+ * @throws {Error} When the provided level is not a valid log level
633
+ */
634
+ function createLogLevelConfig(level = 'error') {
635
+ if (!isValidLogLevel(level)) {
636
+ throw createError('Cannot create log level configuration with a valid default log level');
637
+ }
638
+ const state = { level };
639
+ const getLogLevel = () => state.level;
640
+ const setLogLevel = (level) => {
641
+ if (!isValidLogLevel(level)) {
642
+ throw createError(`Cannot set value '${level}' level. Expected levels are ${logLevels}.`);
643
+ }
644
+ state.level = level;
645
+ };
646
+ const shouldLog = (level) => {
647
+ if (state.level === 'none' || level === 'none' || !isValidLogLevel(level)) {
648
+ return false;
649
+ }
650
+ return priority[level] >= priority[state.level];
651
+ };
652
+ return freeze({
653
+ getLogLevel,
654
+ setLogLevel,
655
+ shouldLog,
656
+ });
657
+ }
658
+
659
+ /**
660
+ * Creates a logger instance with configurable log level filtering.
661
+ * Each log function is wrapped to respect the current log level setting.
662
+ *
663
+ * @param error - Function to handle error-level logs (required)
664
+ * @param warn - Function to handle warning-level logs (optional, defaults to noop)
665
+ * @param log - Function to handle standard logs (optional, defaults to noop)
666
+ * @param info - Function to handle info-level logs (optional, defaults to noop)
667
+ * @param debug - Function to handle debug-level logs (optional, defaults to noop)
668
+ * @returns A frozen logger object with log methods and level control
669
+ * @throws {ErrorLevelFn} When any provided log function is invalid
670
+ */
671
+ function createLogger(error, warn = noop, log = noop, info = noop, debug = noop) {
672
+ if (notValidLogFn(error)) {
673
+ throw createError(notFnMsg('error'));
674
+ }
675
+ if (notValidLogFn(warn)) {
676
+ throw createError(notFnMsg('warn'));
677
+ }
678
+ if (notValidLogFn(log)) {
679
+ throw createError(notFnMsg('log'));
680
+ }
681
+ if (notValidLogFn(info)) {
682
+ throw createError(notFnMsg('info'));
683
+ }
684
+ if (notValidLogFn(debug)) {
685
+ throw createError(notFnMsg('debug'));
686
+ }
687
+ const { setLogLevel, getLogLevel, shouldLog } = createLogLevelConfig();
688
+ const wrapLogFn = (fn, level) => {
689
+ if (fn === noop)
690
+ return fn;
691
+ const condition = () => shouldLog(level);
692
+ return createConditionalExecutionFunction(createErrorIgnoringFunction(fn), condition);
693
+ };
694
+ return freeze({
695
+ error: wrapLogFn(error, 'error'),
696
+ warn: wrapLogFn(warn, 'warn'),
697
+ log: wrapLogFn(log, 'log'),
698
+ info: wrapLogFn(info, 'info'),
699
+ debug: wrapLogFn(debug, 'debug'),
700
+ setLogLevel,
701
+ getLogLevel,
702
+ });
703
+ }
704
+ /**
705
+ * Validates whether a given value is a valid log function.
706
+ *
707
+ * @param fn - The value to validate
708
+ * @returns True if the value is not a function (invalid), false if it is valid
709
+ */
710
+ function notValidLogFn(fn) {
711
+ return getType(fn) !== 'function' && fn !== noop;
712
+ }
713
+ /**
714
+ * Generates an error message for invalid log function parameters.
715
+ *
716
+ * @param label - The name of the log function that failed validation
717
+ * @returns A formatted error message string
718
+ */
719
+ function notFnMsg(label) {
720
+ return `Cannot create a logger when ${label} is not a function`;
721
+ }
722
+
723
+ createLogger(error, warn, log, info, debug);
724
+
725
+ /**
726
+ * Global log level registry.
727
+ * Tracks all created scoped loggers to allow global log level changes.
728
+ */
729
+ const loggerRegistry = createSet();
730
+ /** Redacted placeholder for sensitive values */
731
+ const REDACTED = '[REDACTED]';
732
+ /**
733
+ * Patterns that indicate a sensitive key name.
734
+ * Keys containing these patterns will have their values sanitized.
735
+ */
736
+ const SENSITIVE_KEY_PATTERNS = [
737
+ /token/i,
738
+ /key/i,
739
+ /password/i,
740
+ /secret/i,
741
+ /credential/i,
742
+ /auth/i,
743
+ /bearer/i,
744
+ /api[_-]?key/i,
745
+ /private/i,
746
+ /passphrase/i,
747
+ ];
748
+ /**
749
+ * Checks if a key name indicates sensitive data.
750
+ *
751
+ * @param key - Key name to check
752
+ * @returns True if the key indicates sensitive data
753
+ */
754
+ function isSensitiveKey(key) {
755
+ return SENSITIVE_KEY_PATTERNS.some((pattern) => pattern.test(key));
756
+ }
757
+ /**
758
+ * Sanitizes an object by replacing sensitive values with REDACTED.
759
+ * This function recursively processes nested objects and arrays.
760
+ *
761
+ * @param obj - Object to sanitize
762
+ * @returns New object with sensitive values redacted
763
+ */
764
+ function sanitize(obj) {
765
+ if (obj === null || obj === undefined) {
766
+ return obj;
767
+ }
768
+ if (isArray(obj)) {
769
+ return obj.map((item) => sanitize(item));
770
+ }
771
+ if (typeof obj === 'object') {
772
+ const result = {};
773
+ for (const [key, value] of entries(obj)) {
774
+ if (isSensitiveKey(key)) {
775
+ result[key] = REDACTED;
776
+ }
777
+ else if (typeof value === 'object' && value !== null) {
778
+ result[key] = sanitize(value);
779
+ }
780
+ else {
781
+ result[key] = value;
782
+ }
783
+ }
784
+ return result;
785
+ }
786
+ return obj;
787
+ }
788
+ /**
789
+ * Formats a log message with optional metadata.
790
+ *
791
+ * @param namespace - Logger namespace prefix
792
+ * @param message - Log message
793
+ * @param meta - Optional metadata object
794
+ * @returns Formatted log string
795
+ */
796
+ function formatMessage(namespace, message, meta) {
797
+ const prefix = `[${namespace}]`;
798
+ if (meta && keys(meta).length > 0) {
799
+ const sanitizedMeta = sanitize(meta);
800
+ return `${prefix} ${message} ${stringify(sanitizedMeta)}`;
801
+ }
802
+ return `${prefix} ${message}`;
803
+ }
804
+ /**
805
+ * Creates a scoped logger with namespace prefix and optional secret sanitization.
806
+ * All log messages will be prefixed with [namespace] and sensitive metadata
807
+ * values will be automatically redacted.
808
+ *
809
+ * @param namespace - Logger namespace (e.g., 'project-scope', 'analyze')
810
+ * @param options - Logger configuration options
811
+ * @returns A configured scoped logger instance
812
+ *
813
+ * @example
814
+ * ```typescript
815
+ * const logger = createScopedLogger('project-scope')
816
+ * logger.setLogLevel('debug')
817
+ *
818
+ * // Basic logging
819
+ * logger.info('Starting analysis', { path: './project' })
820
+ *
821
+ * // Sensitive data is automatically redacted
822
+ * logger.debug('Config loaded', { apiKey: 'secret123' })
823
+ * // Output: [project-scope] Config loaded {"apiKey":"[REDACTED]"}
824
+ * ```
825
+ */
826
+ function createScopedLogger(namespace, options = {}) {
827
+ const { level = 'error', sanitizeSecrets = true } = options;
828
+ // Create wrapper functions that add namespace prefix and sanitization
829
+ const createLogFn = (baseFn) => (message, meta) => {
830
+ const processedMeta = sanitizeSecrets && meta ? sanitize(meta) : meta;
831
+ baseFn(formatMessage(namespace, message, processedMeta));
832
+ };
833
+ // Create base logger with wrapped functions
834
+ const baseLogger = createLogger(createLogFn(error), createLogFn(warn), createLogFn(log), createLogFn(info), createLogFn(debug));
835
+ // Set initial log level (use global override if set)
836
+ baseLogger.setLogLevel(level);
837
+ const scopedLogger = freeze({
838
+ error: (message, meta) => baseLogger.error(message, meta),
839
+ warn: (message, meta) => baseLogger.warn(message, meta),
840
+ log: (message, meta) => baseLogger.log(message, meta),
841
+ info: (message, meta) => baseLogger.info(message, meta),
842
+ debug: (message, meta) => baseLogger.debug(message, meta),
843
+ setLogLevel: baseLogger.setLogLevel,
844
+ getLogLevel: baseLogger.getLogLevel,
845
+ });
846
+ // Register logger for global level management
847
+ loggerRegistry.add(scopedLogger);
848
+ return scopedLogger;
849
+ }
850
+ /**
851
+ * Default logger instance for the project-scope library.
852
+ * Use this for general logging within the library.
853
+ *
854
+ * @example
855
+ * ```typescript
856
+ * import { logger } from '@hyperfrontend/project-scope/core'
857
+ *
858
+ * logger.setLogLevel('debug')
859
+ * logger.debug('Analyzing project', { path: './src' })
860
+ * ```
861
+ */
862
+ createScopedLogger('project-scope');
863
+
864
+ const fsLogger = createScopedLogger('project-scope:fs');
865
+ /**
866
+ * Create a file system error with code and context.
867
+ *
868
+ * @param message - The error message describing what went wrong
869
+ * @param code - The category code for this type of filesystem failure
870
+ * @param context - Additional context including path, operation, and cause
871
+ * @returns A configured Error object with code and context properties
872
+ */
873
+ function createFileSystemError(message, code, context) {
874
+ const error = createError(message);
875
+ defineProperties(error, {
876
+ code: { value: code, enumerable: true },
877
+ context: { value: context, enumerable: true },
878
+ });
879
+ return error;
880
+ }
881
+ /**
882
+ * Read file contents as string.
883
+ *
884
+ * @param filePath - Path to file
885
+ * @param encoding - File encoding (default: utf-8)
886
+ * @returns File contents as string
887
+ * @throws {Error} If file doesn't exist or can't be read
888
+ *
889
+ * @example
890
+ * ```typescript
891
+ * import { readFileContent } from '@hyperfrontend/project-scope'
892
+ *
893
+ * const content = readFileContent('./package.json')
894
+ * console.log(content) // JSON string
895
+ * ```
896
+ */
897
+ function readFileContent(filePath, encoding = 'utf-8') {
898
+ if (!existsSync(filePath)) {
899
+ fsLogger.debug('File not found', { path: filePath });
900
+ throw createFileSystemError(`File not found: ${filePath}`, 'FS_NOT_FOUND', { path: filePath, operation: 'read' });
901
+ }
902
+ try {
903
+ return readFileSync(filePath, { encoding });
904
+ }
905
+ catch (error) {
906
+ fsLogger.warn('Failed to read file', { path: filePath });
907
+ throw createFileSystemError(`Failed to read file: ${filePath}`, 'FS_READ_ERROR', { path: filePath, operation: 'read', cause: error });
908
+ }
909
+ }
910
+ /**
911
+ * Read file if exists, return null otherwise.
912
+ *
913
+ * @param filePath - Path to file
914
+ * @param encoding - File encoding (default: utf-8)
915
+ * @returns File contents or null if file doesn't exist
916
+ */
917
+ function readFileIfExists(filePath, encoding = 'utf-8') {
918
+ if (!existsSync(filePath)) {
919
+ return null;
920
+ }
921
+ try {
922
+ return readFileSync(filePath, { encoding });
923
+ }
924
+ catch {
925
+ return null;
926
+ }
927
+ }
928
+
929
+ createScopedLogger('project-scope:fs:write');
930
+
931
+ /**
932
+ * Get file stats with error handling.
933
+ *
934
+ * @param filePath - Path to file
935
+ * @param followSymlinks - Whether to follow symlinks (default: true)
936
+ * @returns File stats or null if path doesn't exist
937
+ */
938
+ function getFileStat(filePath, followSymlinks = true) {
939
+ if (!existsSync(filePath)) {
940
+ return null;
941
+ }
942
+ try {
943
+ const stat = followSymlinks ? statSync(filePath) : lstatSync(filePath);
944
+ return {
945
+ isFile: stat.isFile(),
946
+ isDirectory: stat.isDirectory(),
947
+ isSymlink: stat.isSymbolicLink(),
948
+ size: stat.size,
949
+ created: stat.birthtime,
950
+ modified: stat.mtime,
951
+ accessed: stat.atime,
952
+ mode: stat.mode,
953
+ };
954
+ }
955
+ catch {
956
+ return null;
957
+ }
958
+ }
959
+ /**
960
+ * Check if path is a directory.
961
+ *
962
+ * @param dirPath - Path to check
963
+ * @returns True if path is a directory
964
+ */
965
+ function isDirectory(dirPath) {
966
+ const stats = getFileStat(dirPath);
967
+ return stats?.isDirectory ?? false;
968
+ }
969
+ /**
970
+ * Check if path exists.
971
+ *
972
+ * @param filePath - Path to check
973
+ * @returns True if path exists
974
+ */
975
+ function exists(filePath) {
976
+ return existsSync(filePath);
977
+ }
978
+
979
+ const fsDirLogger = createScopedLogger('project-scope:fs:dir');
980
+ /**
981
+ * List immediate contents of a directory.
982
+ *
983
+ * @param dirPath - Absolute or relative path to the directory
984
+ * @returns Array of entries with metadata for each file/directory
985
+ * @throws {Error} If directory doesn't exist or isn't a directory
986
+ *
987
+ * @example
988
+ * ```typescript
989
+ * import { readDirectory } from '@hyperfrontend/project-scope'
990
+ *
991
+ * const entries = readDirectory('./src')
992
+ * for (const entry of entries) {
993
+ * console.log(entry.name, entry.isFile ? 'file' : 'directory')
994
+ * }
995
+ * ```
996
+ */
997
+ function readDirectory(dirPath) {
998
+ fsDirLogger.debug('Reading directory', { path: dirPath });
999
+ if (!existsSync(dirPath)) {
1000
+ fsDirLogger.debug('Directory not found', { path: dirPath });
1001
+ throw createFileSystemError(`Directory not found: ${dirPath}`, 'FS_NOT_FOUND', { path: dirPath, operation: 'readdir' });
1002
+ }
1003
+ if (!isDirectory(dirPath)) {
1004
+ fsDirLogger.debug('Path is not a directory', { path: dirPath });
1005
+ throw createFileSystemError(`Not a directory: ${dirPath}`, 'FS_NOT_A_DIRECTORY', { path: dirPath, operation: 'readdir' });
1006
+ }
1007
+ try {
1008
+ const entries = readdirSync(dirPath, { withFileTypes: true });
1009
+ fsDirLogger.debug('Directory read complete', { path: dirPath, entryCount: entries.length });
1010
+ return entries.map((entry) => ({
1011
+ name: entry.name,
1012
+ path: join(dirPath, entry.name),
1013
+ isFile: entry.isFile(),
1014
+ isDirectory: entry.isDirectory(),
1015
+ isSymlink: entry.isSymbolicLink(),
1016
+ }));
1017
+ }
1018
+ catch (error) {
1019
+ fsDirLogger.warn('Failed to read directory', { path: dirPath, error: error instanceof Error ? error.message : String(error) });
1020
+ throw createFileSystemError(`Failed to read directory: ${dirPath}`, 'FS_READ_ERROR', {
1021
+ path: dirPath,
1022
+ operation: 'readdir',
1023
+ cause: error,
1024
+ });
1025
+ }
1026
+ }
1027
+
1028
+ createScopedLogger('project-scope:fs:traversal');
1029
+
1030
+ /**
1031
+ * Pattern matching utilities with ReDoS protection.
1032
+ * Uses character-by-character matching instead of regex where possible.
1033
+ */
1034
+ /**
1035
+ * Match path against glob pattern using safe character iteration.
1036
+ * Avoids regex to prevent ReDoS attacks.
1037
+ *
1038
+ * Supported patterns:
1039
+ * - * matches any characters except /
1040
+ * - ** matches any characters including /
1041
+ * - ? matches exactly one character except /
1042
+ * - {a,b,c} matches any of the alternatives
1043
+ *
1044
+ * @param path - The filesystem path to test against the pattern
1045
+ * @param pattern - The glob pattern to match against
1046
+ * @returns True if path matches pattern
1047
+ *
1048
+ * @example
1049
+ * ```typescript
1050
+ * import { matchGlobPattern } from '@hyperfrontend/project-scope'
1051
+ *
1052
+ * matchGlobPattern('src/utils/helper.ts', '\*\*\/*.ts') // true
1053
+ * matchGlobPattern('test.spec.ts', '\*.spec.ts') // true
1054
+ * matchGlobPattern('config.json', '\*.{json,yaml}') // true
1055
+ * matchGlobPattern('src/index.ts', 'src/\*.ts') // true
1056
+ * ```
1057
+ */
1058
+ function matchGlobPattern(path, pattern) {
1059
+ return matchSegments(path.split('/'), pattern.split('/'), 0, 0);
1060
+ }
1061
+ /**
1062
+ * Internal recursive function to match path segments against pattern segments.
1063
+ *
1064
+ * @param pathParts - Array of path segments split by '/'
1065
+ * @param patternParts - Array of pattern segments split by '/'
1066
+ * @param pathIdx - Current index in pathParts being examined
1067
+ * @param patternIdx - Current index in patternParts being examined
1068
+ * @returns True if remaining segments match
1069
+ */
1070
+ function matchSegments(pathParts, patternParts, pathIdx, patternIdx) {
1071
+ // Base cases
1072
+ if (pathIdx === pathParts.length && patternIdx === patternParts.length) {
1073
+ return true; // Both exhausted = match
1074
+ }
1075
+ if (patternIdx >= patternParts.length) {
1076
+ return false; // Pattern exhausted but path remains
1077
+ }
1078
+ const patternPart = patternParts[patternIdx];
1079
+ // Handle ** (globstar) - matches zero or more directories
1080
+ if (patternPart === '**') {
1081
+ // Try matching rest of pattern against current position and all future positions
1082
+ for (let i = pathIdx; i <= pathParts.length; i++) {
1083
+ if (matchSegments(pathParts, patternParts, i, patternIdx + 1)) {
1084
+ return true;
1085
+ }
1086
+ }
1087
+ return false;
1088
+ }
1089
+ if (pathIdx >= pathParts.length) {
1090
+ return false; // Path exhausted but pattern remains (and it's not **)
1091
+ }
1092
+ const pathPart = pathParts[pathIdx];
1093
+ // Match current segment
1094
+ if (matchSegment(pathPart, patternPart)) {
1095
+ return matchSegments(pathParts, patternParts, pathIdx + 1, patternIdx + 1);
1096
+ }
1097
+ return false;
1098
+ }
1099
+ /**
1100
+ * Match a single path segment against a pattern segment.
1101
+ * Handles *, ?, and {a,b,c} patterns.
1102
+ *
1103
+ * @param text - The path segment text to match
1104
+ * @param pattern - The pattern segment to match against
1105
+ * @returns True if the text matches the pattern
1106
+ */
1107
+ function matchSegment(text, pattern) {
1108
+ let textIdx = 0;
1109
+ let patternIdx = 0;
1110
+ while (patternIdx < pattern.length) {
1111
+ const char = pattern[patternIdx];
1112
+ if (char === '*') {
1113
+ // * matches zero or more characters
1114
+ patternIdx++;
1115
+ if (patternIdx === pattern.length) {
1116
+ return true; // * at end matches rest of string
1117
+ }
1118
+ // Try matching rest of pattern at each position in text
1119
+ for (let i = textIdx; i <= text.length; i++) {
1120
+ if (matchSegmentFrom(text, i, pattern, patternIdx)) {
1121
+ return true;
1122
+ }
1123
+ }
1124
+ return false;
1125
+ }
1126
+ else if (char === '?') {
1127
+ // ? matches exactly one character
1128
+ if (textIdx >= text.length) {
1129
+ return false;
1130
+ }
1131
+ textIdx++;
1132
+ patternIdx++;
1133
+ }
1134
+ else if (char === '{') {
1135
+ // {a,b,c} matches any alternative
1136
+ const closeIdx = findClosingBrace(pattern, patternIdx);
1137
+ if (closeIdx === -1) {
1138
+ // Unmatched brace, treat as literal
1139
+ if (textIdx >= text.length || text[textIdx] !== char) {
1140
+ return false;
1141
+ }
1142
+ textIdx++;
1143
+ patternIdx++;
1144
+ }
1145
+ else {
1146
+ const alternatives = extractAlternatives(pattern.slice(patternIdx + 1, closeIdx));
1147
+ for (const alt of alternatives) {
1148
+ if (matchSegmentFrom(text, textIdx, text.slice(0, textIdx) + alt + pattern.slice(closeIdx + 1), textIdx)) {
1149
+ return true;
1150
+ }
1151
+ }
1152
+ return false;
1153
+ }
1154
+ }
1155
+ else {
1156
+ // Literal character
1157
+ if (textIdx >= text.length || text[textIdx] !== char) {
1158
+ return false;
1159
+ }
1160
+ textIdx++;
1161
+ patternIdx++;
1162
+ }
1163
+ }
1164
+ return textIdx === text.length;
1165
+ }
1166
+ /**
1167
+ * Helper to match from a specific position.
1168
+ *
1169
+ * @param text - The full text being matched
1170
+ * @param textIdx - The starting index in text to match from
1171
+ * @param pattern - The full pattern being matched
1172
+ * @param patternIdx - The starting index in pattern to match from
1173
+ * @returns True if the text matches the pattern from the given positions
1174
+ */
1175
+ function matchSegmentFrom(text, textIdx, pattern, patternIdx) {
1176
+ const remainingText = text.slice(textIdx);
1177
+ const remainingPattern = pattern.slice(patternIdx);
1178
+ return matchSegment(remainingText, remainingPattern);
1179
+ }
1180
+ /**
1181
+ * Find closing brace for {a,b,c} pattern.
1182
+ *
1183
+ * @param pattern - The pattern string to search within
1184
+ * @param startIdx - The index of the opening brace
1185
+ * @returns The index of the matching closing brace, or -1 if not found
1186
+ */
1187
+ function findClosingBrace(pattern, startIdx) {
1188
+ let depth = 0;
1189
+ for (let i = startIdx; i < pattern.length; i++) {
1190
+ if (pattern[i] === '{') {
1191
+ depth++;
1192
+ }
1193
+ else if (pattern[i] === '}') {
1194
+ depth--;
1195
+ if (depth === 0) {
1196
+ return i;
1197
+ }
1198
+ }
1199
+ }
1200
+ return -1;
1201
+ }
1202
+ /**
1203
+ * Extract alternatives from {a,b,c} pattern content.
1204
+ *
1205
+ * @param content - The content between braces (without the braces themselves)
1206
+ * @returns Array of alternative strings split by commas at depth 0
1207
+ */
1208
+ function extractAlternatives(content) {
1209
+ const alternatives = [];
1210
+ let current = '';
1211
+ let depth = 0;
1212
+ for (let i = 0; i < content.length; i++) {
1213
+ const char = content[i];
1214
+ if (char === '{') {
1215
+ depth++;
1216
+ current += char;
1217
+ }
1218
+ else if (char === '}') {
1219
+ depth--;
1220
+ current += char;
1221
+ }
1222
+ else if (char === ',' && depth === 0) {
1223
+ alternatives.push(current);
1224
+ current = '';
1225
+ }
1226
+ else {
1227
+ current += char;
1228
+ }
1229
+ }
1230
+ if (current) {
1231
+ alternatives.push(current);
1232
+ }
1233
+ return alternatives;
1234
+ }
1235
+
1236
+ const walkLogger = createScopedLogger('project-scope:project:walk');
1237
+ /**
1238
+ * Reads .gitignore file from the given directory and extracts
1239
+ * non-comment patterns for use in file traversal filtering.
1240
+ *
1241
+ * @param startPath - Directory containing the .gitignore file
1242
+ * @returns Array of gitignore patterns
1243
+ */
1244
+ function loadGitignorePatterns(startPath) {
1245
+ const patterns = [];
1246
+ const gitignorePath = join(startPath, '.gitignore');
1247
+ const content = readFileIfExists(gitignorePath);
1248
+ if (content) {
1249
+ const lines = content.split('\n');
1250
+ for (const line of lines) {
1251
+ const trimmed = line.trim();
1252
+ if (trimmed && !trimmed.startsWith('#')) {
1253
+ patterns.push(trimmed);
1254
+ }
1255
+ }
1256
+ }
1257
+ return patterns;
1258
+ }
1259
+ /**
1260
+ * Evaluates whether a relative path should be ignored based on
1261
+ * a list of gitignore-style patterns.
1262
+ *
1263
+ * @param relativePath - Path relative to the root directory
1264
+ * @param patterns - Array of gitignore-style patterns to test
1265
+ * @returns True if the path matches any ignore pattern
1266
+ */
1267
+ function matchesIgnorePattern(relativePath, patterns) {
1268
+ for (const pattern of patterns) {
1269
+ if (matchPattern(relativePath, pattern)) {
1270
+ return true;
1271
+ }
1272
+ }
1273
+ return false;
1274
+ }
1275
+ /**
1276
+ * Tests if the given path matches a gitignore-style pattern,
1277
+ * supporting negation patterns with '!' prefix.
1278
+ * Uses safe character-by-character matching to prevent ReDoS attacks.
1279
+ *
1280
+ * @param path - File or directory path to test
1281
+ * @param pattern - Gitignore-style pattern (may include wildcards)
1282
+ * @returns True if the path matches the pattern (or doesn't match if negated)
1283
+ */
1284
+ function matchPattern(path, pattern) {
1285
+ const normalizedPattern = pattern.startsWith('/') ? pattern.slice(1) : pattern;
1286
+ const isNegation = normalizedPattern.startsWith('!');
1287
+ const actualPattern = isNegation ? normalizedPattern.slice(1) : normalizedPattern;
1288
+ const matchesFullPath = matchGlobPattern(path, actualPattern) || matchGlobPattern(path, `**/${actualPattern}`);
1289
+ const matchesSegment = path.split('/').some((segment) => matchGlobPattern(segment, actualPattern));
1290
+ const matches = matchesFullPath || matchesSegment;
1291
+ return isNegation ? !matches : matches;
1292
+ }
1293
+ /**
1294
+ * Traverses a directory tree synchronously, calling a visitor function
1295
+ * for each file and directory encountered. Supports depth limiting,
1296
+ * hidden file filtering, and gitignore pattern matching.
1297
+ *
1298
+ * @param startPath - Root directory to begin traversal
1299
+ * @param visitor - Callback function invoked for each file system entry
1300
+ * @param options - Configuration for traversal behavior
1301
+ */
1302
+ function walkDirectory(startPath, visitor, options) {
1303
+ walkLogger.debug('Starting directory walk', {
1304
+ startPath,
1305
+ maxDepth: options?.maxDepth ?? -1,
1306
+ includeHidden: options?.includeHidden ?? false,
1307
+ respectGitignore: options?.respectGitignore ?? true,
1308
+ ignorePatterns: options?.ignorePatterns?.length ?? 0,
1309
+ });
1310
+ const maxDepth = options?.maxDepth ?? -1;
1311
+ const includeHidden = options?.includeHidden ?? false;
1312
+ const ignorePatterns = options?.ignorePatterns ?? [];
1313
+ const respectGitignore = options?.respectGitignore ?? true;
1314
+ const gitignorePatterns = respectGitignore ? loadGitignorePatterns(startPath) : [];
1315
+ const allIgnorePatterns = [...ignorePatterns, ...gitignorePatterns];
1316
+ if (gitignorePatterns.length > 0) {
1317
+ walkLogger.debug('Loaded gitignore patterns', { count: gitignorePatterns.length });
1318
+ }
1319
+ /**
1320
+ * Recursively walks directory entries, applying visitor to each.
1321
+ *
1322
+ * @param currentPath - Absolute path to current directory
1323
+ * @param relativePath - Path relative to the starting directory
1324
+ * @param depth - Current recursion depth
1325
+ * @returns False to stop walking, true to continue
1326
+ */
1327
+ function walk(currentPath, relativePath, depth) {
1328
+ if (maxDepth !== -1 && depth > maxDepth) {
1329
+ return true;
1330
+ }
1331
+ let entries;
1332
+ try {
1333
+ entries = readDirectory(currentPath);
1334
+ }
1335
+ catch {
1336
+ return true;
1337
+ }
1338
+ for (const entry of entries) {
1339
+ if (!includeHidden && entry.name.startsWith('.')) {
1340
+ continue;
1341
+ }
1342
+ const entryRelativePath = relativePath ? `${relativePath}/${entry.name}` : entry.name;
1343
+ if (matchesIgnorePattern(entryRelativePath, allIgnorePatterns)) {
1344
+ continue;
1345
+ }
1346
+ const walkEntry = {
1347
+ name: entry.name,
1348
+ path: entry.path,
1349
+ relativePath: entryRelativePath,
1350
+ isFile: entry.isFile,
1351
+ isDirectory: entry.isDirectory,
1352
+ isSymlink: entry.isSymlink,
1353
+ depth,
1354
+ };
1355
+ const result = visitor(walkEntry);
1356
+ if (result === 'stop') {
1357
+ return false;
1358
+ }
1359
+ if (result === 'skip') {
1360
+ continue;
1361
+ }
1362
+ if (entry.isDirectory) {
1363
+ const shouldContinue = walk(entry.path, entryRelativePath, depth + 1);
1364
+ if (!shouldContinue) {
1365
+ return false;
1366
+ }
1367
+ }
1368
+ }
1369
+ return true;
1370
+ }
1371
+ walk(startPath, '', 0);
1372
+ walkLogger.debug('Directory walk complete', { startPath });
1373
+ }
1374
+
1375
+ const searchLogger = createScopedLogger('project-scope:project:search');
1376
+ /**
1377
+ * Tests if a path matches at least one pattern from an array of globs,
1378
+ * enabling flexible multi-pattern file filtering.
1379
+ * Uses safe character-by-character matching to prevent ReDoS attacks.
1380
+ *
1381
+ * @param path - File path to test
1382
+ * @param patterns - Array of glob patterns
1383
+ * @returns True if path matches any pattern
1384
+ */
1385
+ function matchesPatterns(path, patterns) {
1386
+ return patterns.some((pattern) => matchGlobPattern(path, pattern));
1387
+ }
1388
+ /**
1389
+ * Searches a directory tree for files matching one or more glob patterns,
1390
+ * returning relative or absolute paths based on options.
1391
+ *
1392
+ * @param startPath - Root directory to begin the search
1393
+ * @param patterns - Glob patterns (e.g., '*.ts', '**\/*.json') to filter files
1394
+ * @param options - Configuration for search behavior
1395
+ * @returns List of relative file paths that match the patterns
1396
+ *
1397
+ * @example
1398
+ * ```typescript
1399
+ * import { findFiles } from '@hyperfrontend/project-scope'
1400
+ *
1401
+ * // Find all TypeScript files
1402
+ * const tsFiles = findFiles('./src', '\*\*\/*.ts')
1403
+ *
1404
+ * // Find multiple file types
1405
+ * const configFiles = findFiles('./', ['\*.json', '\*.yaml', '\*.yml'])
1406
+ *
1407
+ * // Limit results and get absolute paths
1408
+ * const first10 = findFiles('./src', '\*\*\/*.ts', {
1409
+ * maxResults: 10,
1410
+ * absolutePaths: true
1411
+ * })
1412
+ * ```
1413
+ */
1414
+ function findFiles(startPath, patterns, options) {
1415
+ const normalizedPatterns = isArray(patterns) ? patterns : [patterns];
1416
+ searchLogger.debug('Finding files', { startPath, patterns: normalizedPatterns, maxResults: options?.maxResults });
1417
+ const results = [];
1418
+ const maxResults = options?.maxResults ?? Infinity;
1419
+ walkDirectory(startPath, (entry) => {
1420
+ if (results.length >= maxResults) {
1421
+ return 'stop';
1422
+ }
1423
+ if (!entry.isFile) {
1424
+ return undefined;
1425
+ }
1426
+ if (matchesPatterns(entry.relativePath, normalizedPatterns)) {
1427
+ results.push(options?.absolutePaths ? entry.path : entry.relativePath);
1428
+ }
1429
+ return undefined;
1430
+ }, options);
1431
+ searchLogger.debug('File search complete', { startPath, matchCount: results.length });
1432
+ return results;
1433
+ }
1434
+
1435
+ const configLogger = createScopedLogger('project-scope:config');
1436
+ /**
1437
+ * Cache for config detection results.
1438
+ * TTL: 30 seconds (configs can change frequently during setup)
1439
+ */
1440
+ const configDetectionCache = createCache({ ttl: 30000, maxSize: 50 });
1441
+ /**
1442
+ * Detect all configuration files in a directory.
1443
+ *
1444
+ * Results are cached for 30 seconds per project path and options
1445
+ * to avoid redundant file system operations on repeated calls.
1446
+ *
1447
+ * @param rootPath - Project root directory
1448
+ * @param types - Optional array of config types to check (defaults to all)
1449
+ * @param options - Detection options
1450
+ * @returns Array of detected configuration files
1451
+ *
1452
+ * @example
1453
+ * ```typescript
1454
+ * import { detectConfigs } from '@hyperfrontend/project-scope'
1455
+ *
1456
+ * // Detect all config files
1457
+ * const configs = detectConfigs('./my-project')
1458
+ * for (const config of configs) {
1459
+ * console.log(`${config.type}: ${config.path}`)
1460
+ * }
1461
+ * // Output:
1462
+ * // typescript: tsconfig.json
1463
+ * // eslint: eslint.config.js
1464
+ * // jest: jest.config.ts
1465
+ *
1466
+ * // Detect specific config types only
1467
+ * const tsConfigs = detectConfigs('./my-project', ['typescript', 'eslint'])
1468
+ * ```
1469
+ */
1470
+ function detectConfigs(rootPath, types, options) {
1471
+ const typesToCheck = types ?? keys(CONFIG_PATTERNS);
1472
+ const results = [];
1473
+ const maxDepth = options?.maxDepth ?? 10;
1474
+ const includeHidden = options?.includeHidden ?? true;
1475
+ const typeKey = types ? types.sort().join(',') : 'all';
1476
+ const cacheKey = `${rootPath}:${typeKey}:${maxDepth}:${includeHidden}`;
1477
+ if (!options?.skipCache) {
1478
+ const cached = configDetectionCache.get(cacheKey);
1479
+ if (cached) {
1480
+ configLogger.debug('Returning cached config detection results', { rootPath });
1481
+ return cached;
1482
+ }
1483
+ }
1484
+ configLogger.debug('Detecting config files', { rootPath, types: typesToCheck.length });
1485
+ for (const type of typesToCheck) {
1486
+ const info = CONFIG_PATTERNS[type];
1487
+ if (!info)
1488
+ continue;
1489
+ for (const pattern of info.patterns) {
1490
+ const isRecursive = pattern.includes('**');
1491
+ if (isRecursive) {
1492
+ const files = findFiles(rootPath, pattern, {
1493
+ maxDepth,
1494
+ includeHidden: options?.includeHidden ?? true,
1495
+ });
1496
+ for (const file of files) {
1497
+ if (!results.some((r) => r.path === file && r.type === type)) {
1498
+ configLogger.debug('Found config file', { type, path: file });
1499
+ results.push({
1500
+ type,
1501
+ path: file,
1502
+ matchedPattern: pattern,
1503
+ info,
1504
+ });
1505
+ }
1506
+ }
1507
+ }
1508
+ else {
1509
+ const fullPath = join(rootPath, pattern);
1510
+ if (exists(fullPath)) {
1511
+ if (!results.some((r) => r.path === pattern && r.type === type)) {
1512
+ configLogger.debug('Found config file', { type, path: pattern });
1513
+ results.push({
1514
+ type,
1515
+ path: pattern,
1516
+ matchedPattern: pattern,
1517
+ info,
1518
+ });
1519
+ }
1520
+ }
1521
+ }
1522
+ }
1523
+ }
1524
+ configLogger.debug('Config detection complete', { found: results.length });
1525
+ configDetectionCache.set(cacheKey, results);
1526
+ return results;
1527
+ }
1528
+ /**
1529
+ * Clear the config detection cache.
1530
+ *
1531
+ * Useful for testing or when the project files have changed.
1532
+ */
1533
+ function clearConfigDetectionCache() {
1534
+ configDetectionCache.clear();
1535
+ }
1536
+ /**
1537
+ * Find a specific configuration file.
1538
+ *
1539
+ * @param rootPath - Project root directory
1540
+ * @param type - Config type to find
1541
+ * @returns Full path to config file or null if not found
1542
+ */
1543
+ function findConfigFile(rootPath, type) {
1544
+ const info = CONFIG_PATTERNS[type];
1545
+ if (!info)
1546
+ return null;
1547
+ for (const pattern of info.patterns) {
1548
+ if (!pattern.includes('*')) {
1549
+ const fullPath = join(rootPath, pattern);
1550
+ if (exists(fullPath)) {
1551
+ return fullPath;
1552
+ }
1553
+ }
1554
+ }
1555
+ for (const pattern of info.patterns) {
1556
+ if (pattern.includes('*') && !pattern.includes('**')) {
1557
+ const files = findFiles(rootPath, pattern, { maxDepth: 0 });
1558
+ if (files.length > 0) {
1559
+ return join(rootPath, files[0]);
1560
+ }
1561
+ }
1562
+ }
1563
+ return null;
1564
+ }
1565
+ /**
1566
+ * Get all known config file patterns for a given configuration type.
1567
+ *
1568
+ * @param type - Configuration type identifier
1569
+ * @returns Array of glob patterns for matching config files
1570
+ */
1571
+ function getConfigPaths(type) {
1572
+ const info = CONFIG_PATTERNS[type];
1573
+ return info?.patterns ?? [];
1574
+ }
1575
+
1576
+ /**
1577
+ * Safe copies of Number built-in methods and constants.
1578
+ *
1579
+ * These references are captured at module initialization time to protect against
1580
+ * prototype pollution attacks. Import only what you need for tree-shaking.
1581
+ *
1582
+ * @module @hyperfrontend/immutable-api-utils/built-in-copy/number
1583
+ */
1584
+ // Capture references at module initialization time
1585
+ const _parseInt = globalThis.parseInt;
1586
+ const _parseFloat = globalThis.parseFloat;
1587
+ // ============================================================================
1588
+ // Parsing
1589
+ // ============================================================================
1590
+ /**
1591
+ * (Safe copy) Parses a string and returns an integer.
1592
+ */
1593
+ const parseInt = _parseInt;
1594
+ /**
1595
+ * (Safe copy) Parses a string and returns a floating point number.
1596
+ */
1597
+ const parseFloat = _parseFloat;
1598
+
1599
+ /**
1600
+ * Create a structured error with code and optional context.
1601
+ *
1602
+ * @param message - The human-readable error message
1603
+ * @param code - The machine-readable error code for programmatic handling
1604
+ * @param context - Additional contextual information about the error
1605
+ * @returns Structured error instance with code and context properties
1606
+ *
1607
+ * @example
1608
+ * ```typescript
1609
+ * import { createStructuredError } from '@hyperfrontend/project-scope'
1610
+ *
1611
+ * throw createStructuredError(
1612
+ * 'Configuration file not found',
1613
+ * 'CONFIG_NOT_FOUND',
1614
+ * { path: './config.json', searched: ['./config.json', './settings.json'] }
1615
+ * )
1616
+ * ```
1617
+ */
1618
+ function createStructuredError(message, code, context) {
1619
+ const error = createError(message);
1620
+ error.code = code;
1621
+ error.context = context ?? {};
1622
+ return error;
1623
+ }
1624
+ /**
1625
+ * Create a configuration-related error.
1626
+ *
1627
+ * @param message - The human-readable error message
1628
+ * @param code - The machine-readable error code for programmatic handling
1629
+ * @param context - Additional contextual information (e.g., file path, config key)
1630
+ * @returns Structured error instance tagged with type 'config'
1631
+ */
1632
+ function createConfigError(message, code, context) {
1633
+ return createStructuredError(message, code, { ...context, type: 'config' });
1634
+ }
1635
+
1636
+ /**
1637
+ * Detect config type from file name.
1638
+ * Uses safe character-by-character matching to prevent ReDoS attacks.
1639
+ *
1640
+ * @param filePath - Path to config file
1641
+ * @returns Detected config type or undefined
1642
+ */
1643
+ function detectConfigType(filePath) {
1644
+ const fileName = basename(filePath);
1645
+ for (const [type, info] of entries(CONFIG_PATTERNS)) {
1646
+ for (const pattern of info.patterns) {
1647
+ if (matchGlobPattern(fileName, pattern)) {
1648
+ return type;
1649
+ }
1650
+ }
1651
+ }
1652
+ return undefined;
1653
+ }
1654
+ /**
1655
+ * Detect format from file path.
1656
+ *
1657
+ * @param filePath - Path to config file
1658
+ * @returns Detected format
1659
+ */
1660
+ function detectFormat(filePath) {
1661
+ const ext = filePath.split('.').pop()?.toLowerCase();
1662
+ switch (ext) {
1663
+ case 'json':
1664
+ return 'json';
1665
+ case 'yaml':
1666
+ case 'yml':
1667
+ return 'yaml';
1668
+ case 'js':
1669
+ case 'cjs':
1670
+ case 'mjs':
1671
+ return 'js';
1672
+ case 'ts':
1673
+ return 'ts';
1674
+ case 'toml':
1675
+ return 'toml';
1676
+ case 'ini':
1677
+ return 'ini';
1678
+ default:
1679
+ return 'text';
1680
+ }
1681
+ }
1682
+ /**
1683
+ * Strip JSON comments (// and /* *\/).
1684
+ *
1685
+ * @param content - JSONC content
1686
+ * @returns JSON content without comments
1687
+ */
1688
+ function stripJsonComments(content) {
1689
+ let result = '';
1690
+ let inString = false;
1691
+ let inLineComment = false;
1692
+ let inBlockComment = false;
1693
+ let stringChar = '';
1694
+ for (let i = 0; i < content.length; i++) {
1695
+ const char = content[i];
1696
+ const nextChar = content[i + 1];
1697
+ if (inLineComment) {
1698
+ if (char === '\n') {
1699
+ inLineComment = false;
1700
+ result += char;
1701
+ }
1702
+ continue;
1703
+ }
1704
+ if (inBlockComment) {
1705
+ if (char === '*' && nextChar === '/') {
1706
+ inBlockComment = false;
1707
+ i++;
1708
+ }
1709
+ continue;
1710
+ }
1711
+ if (inString) {
1712
+ result += char;
1713
+ if (char === stringChar && content[i - 1] !== '\\') {
1714
+ inString = false;
1715
+ }
1716
+ continue;
1717
+ }
1718
+ if (char === '"' || char === "'") {
1719
+ inString = true;
1720
+ stringChar = char;
1721
+ result += char;
1722
+ continue;
1723
+ }
1724
+ if (char === '/' && nextChar === '/') {
1725
+ inLineComment = true;
1726
+ i++;
1727
+ continue;
1728
+ }
1729
+ if (char === '/' && nextChar === '*') {
1730
+ inBlockComment = true;
1731
+ i++;
1732
+ continue;
1733
+ }
1734
+ result += char;
1735
+ }
1736
+ return result;
1737
+ }
1738
+ /**
1739
+ * Parse simple YAML key-value pairs into an object.
1740
+ * Note: This is a simplified parser for basic config structures.
1741
+ *
1742
+ * @param content - Raw YAML file content to parse
1743
+ * @returns Object representation of the YAML key-value pairs
1744
+ */
1745
+ function parseSimpleYaml(content) {
1746
+ const lines = content.split('\n');
1747
+ const result = {};
1748
+ for (const line of lines) {
1749
+ if (line.trim().startsWith('#') || !line.includes(':')) {
1750
+ continue;
1751
+ }
1752
+ const colonIndex = line.indexOf(':');
1753
+ const key = line.substring(0, colonIndex).trim();
1754
+ const value = line.substring(colonIndex + 1).trim();
1755
+ if (key && value) {
1756
+ if (value === 'true') {
1757
+ result[key] = true;
1758
+ }
1759
+ else if (value === 'false') {
1760
+ result[key] = false;
1761
+ }
1762
+ else if (value === 'null') {
1763
+ result[key] = null;
1764
+ }
1765
+ else if (/^-?\d+$/.test(value)) {
1766
+ result[key] = parseInt(value, 10);
1767
+ }
1768
+ else if (/^-?\d+\.\d+$/.test(value)) {
1769
+ result[key] = parseFloat(value);
1770
+ }
1771
+ else {
1772
+ result[key] = value.replace(/^["']|["']$/g, '');
1773
+ }
1774
+ }
1775
+ }
1776
+ return result;
1777
+ }
1778
+ /**
1779
+ * Parse INI-style configuration format into an object.
1780
+ * Supports sections and key-value pairs.
1781
+ *
1782
+ * @param content - Raw INI file content to parse
1783
+ * @returns Object with sections as keys and their key-value pairs
1784
+ */
1785
+ function parseIniConfig(content) {
1786
+ const result = {};
1787
+ let currentSection = '';
1788
+ for (const line of content.split('\n')) {
1789
+ const trimmed = line.trim();
1790
+ if (!trimmed || trimmed.startsWith('#') || trimmed.startsWith(';')) {
1791
+ continue;
1792
+ }
1793
+ const sectionMatch = trimmed.match(/^\[([^\]]+)\]$/);
1794
+ if (sectionMatch) {
1795
+ currentSection = sectionMatch[1];
1796
+ result[currentSection] = {};
1797
+ continue;
1798
+ }
1799
+ const keyValueMatch = trimmed.match(/^([^=]+)=(.*)$/);
1800
+ if (keyValueMatch) {
1801
+ const key = keyValueMatch[1].trim();
1802
+ const value = keyValueMatch[2].trim();
1803
+ if (currentSection) {
1804
+ result[currentSection][key] = value;
1805
+ }
1806
+ else {
1807
+ result[key] = value;
1808
+ }
1809
+ }
1810
+ }
1811
+ return result;
1812
+ }
1813
+ /**
1814
+ * Parse dotenv-style environment variable format.
1815
+ * Handles quoted values and comments.
1816
+ *
1817
+ * @param content - Raw dotenv file content to parse
1818
+ * @returns Object mapping variable names to their values
1819
+ */
1820
+ function parseDotenv(content) {
1821
+ const result = {};
1822
+ for (const line of content.split('\n')) {
1823
+ const trimmed = line.trim();
1824
+ if (!trimmed || trimmed.startsWith('#')) {
1825
+ continue;
1826
+ }
1827
+ const match = trimmed.match(/^([^=]+)=(.*)$/);
1828
+ if (match) {
1829
+ const key = match[1].trim();
1830
+ let value = match[2].trim();
1831
+ if ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'"))) {
1832
+ value = value.slice(1, -1);
1833
+ }
1834
+ result[key] = value;
1835
+ }
1836
+ }
1837
+ return result;
1838
+ }
1839
+ /**
1840
+ * Parse JSON configuration file.
1841
+ *
1842
+ * @param filePath - Path to the JSON configuration file
1843
+ * @param content - Raw file content to parse
1844
+ * @param type - Category of configuration (e.g., typescript, eslint)
1845
+ * @param format - Whether to strip comments (jsonc) or parse strictly (json)
1846
+ * @returns Configuration object with parsed data and extends references
1847
+ */
1848
+ function parseJsonConfig(filePath, content, type, format = 'json') {
1849
+ const cleanContent = format === 'jsonc' ? stripJsonComments(content) : content;
1850
+ try {
1851
+ const data = parse(cleanContent);
1852
+ let extendsPath;
1853
+ if (typeof data['extends'] === 'string') {
1854
+ extendsPath = [data['extends']];
1855
+ }
1856
+ else if (isArray(data['extends'])) {
1857
+ extendsPath = data['extends'];
1858
+ }
1859
+ return {
1860
+ type: type ?? 'unknown',
1861
+ path: filePath,
1862
+ format,
1863
+ data,
1864
+ extends: extendsPath,
1865
+ };
1866
+ }
1867
+ catch (error) {
1868
+ throw createConfigError(`Failed to parse JSON config: ${filePath}`, 'CONFIG_PARSE_ERROR', {
1869
+ filePath,
1870
+ format,
1871
+ cause: error,
1872
+ });
1873
+ }
1874
+ }
1875
+ /**
1876
+ * Parse YAML configuration file.
1877
+ *
1878
+ * @param filePath - Path to the YAML configuration file
1879
+ * @param content - Raw file content to parse
1880
+ * @param type - Category of configuration (e.g., github-actions, docker-compose)
1881
+ * @returns Configuration object with parsed YAML data
1882
+ */
1883
+ function parseYamlConfig(filePath, content, type) {
1884
+ const data = parseSimpleYaml(content);
1885
+ return {
1886
+ type: type ?? 'unknown',
1887
+ path: filePath,
1888
+ format: 'yaml',
1889
+ data,
1890
+ };
1891
+ }
1892
+ /**
1893
+ * Parse configuration file.
1894
+ *
1895
+ * @param filePath - Path to config file
1896
+ * @param type - Optional config type (auto-detected if not provided)
1897
+ * @returns Parsed configuration
1898
+ */
1899
+ function parseConfig(filePath, type) {
1900
+ const content = readFileContent(filePath);
1901
+ const detectedType = type ?? detectConfigType(filePath);
1902
+ const info = detectedType ? CONFIG_PATTERNS[detectedType] : null;
1903
+ const format = info?.format ?? detectFormat(filePath);
1904
+ switch (format) {
1905
+ case 'json':
1906
+ return parseJsonConfig(filePath, content, detectedType, 'json');
1907
+ case 'jsonc':
1908
+ return parseJsonConfig(filePath, content, detectedType, 'jsonc');
1909
+ case 'yaml':
1910
+ return parseYamlConfig(filePath, content, detectedType);
1911
+ case 'ini':
1912
+ return {
1913
+ type: detectedType ?? 'unknown',
1914
+ path: filePath,
1915
+ format: 'ini',
1916
+ data: parseIniConfig(content),
1917
+ };
1918
+ case 'dotenv':
1919
+ return {
1920
+ type: detectedType ?? 'unknown',
1921
+ path: filePath,
1922
+ format: 'dotenv',
1923
+ data: parseDotenv(content),
1924
+ };
1925
+ case 'js':
1926
+ case 'ts':
1927
+ return {
1928
+ type: detectedType ?? 'unknown',
1929
+ path: filePath,
1930
+ format,
1931
+ raw: content,
1932
+ };
1933
+ default:
1934
+ return {
1935
+ type: detectedType ?? 'unknown',
1936
+ path: filePath,
1937
+ format: 'text',
1938
+ raw: content,
1939
+ };
1940
+ }
1941
+ }
1942
+ /**
1943
+ * Read and parse config file if it exists.
1944
+ *
1945
+ * @param configPath - Path to config file
1946
+ * @returns Parsed config or null if file doesn't exist
1947
+ */
1948
+ function readConfigIfExists(configPath) {
1949
+ const content = readFileIfExists(configPath);
1950
+ if (!content)
1951
+ return null;
1952
+ try {
1953
+ const format = detectFormat(configPath);
1954
+ switch (format) {
1955
+ case 'json':
1956
+ return parse(content);
1957
+ case 'jsonc':
1958
+ return parse(stripJsonComments(content));
1959
+ case 'yaml':
1960
+ return parseSimpleYaml(content);
1961
+ default:
1962
+ return null;
1963
+ }
1964
+ }
1965
+ catch {
1966
+ return null;
1967
+ }
1968
+ }
1969
+
1970
+ export { CONFIG_PATTERNS, clearConfigDetectionCache, detectConfigs, findConfigFile, getConfigPaths, getConfigPatternsByType, parseConfig, parseJsonConfig, parseYamlConfig, readConfigIfExists };
1971
+ //# sourceMappingURL=index.esm.js.map