@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,3618 @@
1
+ 'use strict';
2
+
3
+ var node_path = require('node:path');
4
+ var node_fs = require('node:fs');
5
+
6
+ /**
7
+ * Safe copies of Map built-in via factory function.
8
+ *
9
+ * Since constructors cannot be safely captured via Object.assign, this module
10
+ * provides a factory function that uses Reflect.construct internally.
11
+ *
12
+ * These references are captured at module initialization time to protect against
13
+ * prototype pollution attacks. Import only what you need for tree-shaking.
14
+ *
15
+ * @module @hyperfrontend/immutable-api-utils/built-in-copy/map
16
+ */
17
+ // Capture references at module initialization time
18
+ const _Map = globalThis.Map;
19
+ const _Reflect$2 = globalThis.Reflect;
20
+ /**
21
+ * (Safe copy) Creates a new Map using the captured Map constructor.
22
+ * Use this instead of `new Map()`.
23
+ *
24
+ * @param iterable - Optional iterable of key-value pairs.
25
+ * @returns A new Map instance.
26
+ */
27
+ const createMap = (iterable) => _Reflect$2.construct(_Map, iterable ? [iterable] : []);
28
+
29
+ /**
30
+ * Safe copies of Object built-in methods.
31
+ *
32
+ * These references are captured at module initialization time to protect against
33
+ * prototype pollution attacks. Import only what you need for tree-shaking.
34
+ *
35
+ * @module @hyperfrontend/immutable-api-utils/built-in-copy/object
36
+ */
37
+ // Capture references at module initialization time
38
+ const _Object = globalThis.Object;
39
+ /**
40
+ * (Safe copy) Prevents modification of existing property attributes and values,
41
+ * and prevents the addition of new properties.
42
+ */
43
+ const freeze = _Object.freeze;
44
+ /**
45
+ * (Safe copy) Returns the names of the enumerable string properties and methods of an object.
46
+ */
47
+ const keys = _Object.keys;
48
+ /**
49
+ * (Safe copy) Returns an array of key/values of the enumerable own properties of an object.
50
+ */
51
+ const entries = _Object.entries;
52
+ /**
53
+ * (Safe copy) Returns an array of values of the enumerable own properties of an object.
54
+ */
55
+ const values = _Object.values;
56
+ /**
57
+ * (Safe copy) Adds one or more properties to an object, and/or modifies attributes of existing properties.
58
+ */
59
+ const defineProperties = _Object.defineProperties;
60
+
61
+ /**
62
+ * Safe copies of Set built-in via factory function.
63
+ *
64
+ * Since constructors cannot be safely captured via Object.assign, this module
65
+ * provides a factory function that uses Reflect.construct internally.
66
+ *
67
+ * These references are captured at module initialization time to protect against
68
+ * prototype pollution attacks. Import only what you need for tree-shaking.
69
+ *
70
+ * @module @hyperfrontend/immutable-api-utils/built-in-copy/set
71
+ */
72
+ // Capture references at module initialization time
73
+ const _Set = globalThis.Set;
74
+ const _Reflect$1 = globalThis.Reflect;
75
+ /**
76
+ * (Safe copy) Creates a new Set using the captured Set constructor.
77
+ * Use this instead of `new Set()`.
78
+ *
79
+ * @param iterable - Optional iterable of values.
80
+ * @returns A new Set instance.
81
+ */
82
+ const createSet = (iterable) => _Reflect$1.construct(_Set, iterable ? [iterable] : []);
83
+
84
+ /**
85
+ * Global registry of all caches for bulk operations.
86
+ */
87
+ const cacheRegistry = createSet();
88
+ /**
89
+ * Create a cache with optional TTL and size limits.
90
+ *
91
+ * The cache provides a simple key-value store with:
92
+ * - Optional TTL (time-to-live) for automatic expiration
93
+ * - Optional maxSize for limiting cache size with FIFO eviction
94
+ * - Lazy expiration (entries are checked on access)
95
+ *
96
+ * @param options - Cache configuration options
97
+ * @returns Cache instance
98
+ *
99
+ * @example
100
+ * ```typescript
101
+ * // Basic cache
102
+ * const cache = createCache<string, number>()
103
+ * cache.set('answer', 42)
104
+ * cache.get('answer') // 42
105
+ *
106
+ * // Cache with TTL (expires after 60 seconds)
107
+ * const ttlCache = createCache<string, object>({ ttl: 60000 })
108
+ *
109
+ * // Cache with max size (evicts oldest when full)
110
+ * const lruCache = createCache<string, object>({ maxSize: 100 })
111
+ *
112
+ * // Combined options
113
+ * const configCache = createCache<string, object>({
114
+ * ttl: 30000,
115
+ * maxSize: 50
116
+ * })
117
+ * ```
118
+ */
119
+ function createCache(options) {
120
+ const { ttl, maxSize } = options ?? {};
121
+ const store = createMap();
122
+ // Track insertion order for FIFO eviction
123
+ const insertionOrder = [];
124
+ /**
125
+ * Check if an entry is expired.
126
+ *
127
+ * @param entry - Cache entry to check
128
+ * @returns True if entry is expired
129
+ */
130
+ function isExpired(entry) {
131
+ if (ttl === undefined)
132
+ return false;
133
+ // eslint-disable-next-line workspace/no-unsafe-builtin-methods -- Date.now() is needed for Jest fake timers compatibility
134
+ return Date.now() - entry.timestamp > ttl;
135
+ }
136
+ /**
137
+ * Evict oldest entries to make room for new ones.
138
+ */
139
+ function evictIfNeeded() {
140
+ if (maxSize === undefined)
141
+ return;
142
+ while (store.size >= maxSize && insertionOrder.length > 0) {
143
+ const oldestKey = insertionOrder.shift();
144
+ if (oldestKey !== undefined) {
145
+ store.delete(oldestKey);
146
+ }
147
+ }
148
+ }
149
+ /**
150
+ * Remove key from insertion order tracking.
151
+ *
152
+ * @param key - Key to remove from order tracking
153
+ */
154
+ function removeFromOrder(key) {
155
+ const index = insertionOrder.indexOf(key);
156
+ if (index !== -1) {
157
+ insertionOrder.splice(index, 1);
158
+ }
159
+ }
160
+ const cache = {
161
+ get(key) {
162
+ const entry = store.get(key);
163
+ if (!entry)
164
+ return undefined;
165
+ if (isExpired(entry)) {
166
+ store.delete(key);
167
+ removeFromOrder(key);
168
+ return undefined;
169
+ }
170
+ return entry.value;
171
+ },
172
+ set(key, value) {
173
+ // If key exists, remove from order first
174
+ if (store.has(key)) {
175
+ removeFromOrder(key);
176
+ }
177
+ else {
178
+ // Evict if needed before adding new entry
179
+ evictIfNeeded();
180
+ }
181
+ // eslint-disable-next-line workspace/no-unsafe-builtin-methods -- Date.now() is needed for Jest fake timers compatibility
182
+ store.set(key, { value, timestamp: Date.now() });
183
+ insertionOrder.push(key);
184
+ },
185
+ has(key) {
186
+ const entry = store.get(key);
187
+ if (!entry)
188
+ return false;
189
+ if (isExpired(entry)) {
190
+ store.delete(key);
191
+ removeFromOrder(key);
192
+ return false;
193
+ }
194
+ return true;
195
+ },
196
+ delete(key) {
197
+ removeFromOrder(key);
198
+ return store.delete(key);
199
+ },
200
+ clear() {
201
+ store.clear();
202
+ insertionOrder.length = 0;
203
+ },
204
+ size() {
205
+ return store.size;
206
+ },
207
+ keys() {
208
+ return [...insertionOrder];
209
+ },
210
+ };
211
+ // Register cache for global operations
212
+ cacheRegistry.add(cache);
213
+ return freeze(cache);
214
+ }
215
+
216
+ /**
217
+ * Safe copies of Array built-in static methods.
218
+ *
219
+ * These references are captured at module initialization time to protect against
220
+ * prototype pollution attacks. Import only what you need for tree-shaking.
221
+ *
222
+ * @module @hyperfrontend/immutable-api-utils/built-in-copy/array
223
+ */
224
+ // Capture references at module initialization time
225
+ const _Array = globalThis.Array;
226
+ /**
227
+ * (Safe copy) Determines whether the passed value is an Array.
228
+ */
229
+ const isArray = _Array.isArray;
230
+
231
+ /**
232
+ * Safe copies of Console built-in methods.
233
+ *
234
+ * These references are captured at module initialization time to protect against
235
+ * prototype pollution attacks. Import only what you need for tree-shaking.
236
+ *
237
+ * @module @hyperfrontend/immutable-api-utils/built-in-copy/console
238
+ */
239
+ // Capture references at module initialization time
240
+ const _console = globalThis.console;
241
+ /**
242
+ * (Safe copy) Outputs a message to the console.
243
+ */
244
+ const log = _console.log.bind(_console);
245
+ /**
246
+ * (Safe copy) Outputs a warning message to the console.
247
+ */
248
+ const warn = _console.warn.bind(_console);
249
+ /**
250
+ * (Safe copy) Outputs an error message to the console.
251
+ */
252
+ const error = _console.error.bind(_console);
253
+ /**
254
+ * (Safe copy) Outputs an informational message to the console.
255
+ */
256
+ const info = _console.info.bind(_console);
257
+ /**
258
+ * (Safe copy) Outputs a debug message to the console.
259
+ */
260
+ const debug = _console.debug.bind(_console);
261
+ /**
262
+ * (Safe copy) Outputs a stack trace to the console.
263
+ */
264
+ _console.trace.bind(_console);
265
+ /**
266
+ * (Safe copy) Displays an interactive listing of the properties of a specified object.
267
+ */
268
+ _console.dir.bind(_console);
269
+ /**
270
+ * (Safe copy) Displays tabular data as a table.
271
+ */
272
+ _console.table.bind(_console);
273
+ /**
274
+ * (Safe copy) Writes an error message to the console if the assertion is false.
275
+ */
276
+ _console.assert.bind(_console);
277
+ /**
278
+ * (Safe copy) Clears the console.
279
+ */
280
+ _console.clear.bind(_console);
281
+ /**
282
+ * (Safe copy) Logs the number of times that this particular call to count() has been called.
283
+ */
284
+ _console.count.bind(_console);
285
+ /**
286
+ * (Safe copy) Resets the counter used with console.count().
287
+ */
288
+ _console.countReset.bind(_console);
289
+ /**
290
+ * (Safe copy) Creates a new inline group in the console.
291
+ */
292
+ _console.group.bind(_console);
293
+ /**
294
+ * (Safe copy) Creates a new inline group in the console that is initially collapsed.
295
+ */
296
+ _console.groupCollapsed.bind(_console);
297
+ /**
298
+ * (Safe copy) Exits the current inline group.
299
+ */
300
+ _console.groupEnd.bind(_console);
301
+ /**
302
+ * (Safe copy) Starts a timer with a name specified as an input parameter.
303
+ */
304
+ _console.time.bind(_console);
305
+ /**
306
+ * (Safe copy) Stops a timer that was previously started.
307
+ */
308
+ _console.timeEnd.bind(_console);
309
+ /**
310
+ * (Safe copy) Logs the current value of a timer that was previously started.
311
+ */
312
+ _console.timeLog.bind(_console);
313
+
314
+ /**
315
+ * Safe copies of JSON built-in methods.
316
+ *
317
+ * These references are captured at module initialization time to protect against
318
+ * prototype pollution attacks. Import only what you need for tree-shaking.
319
+ *
320
+ * @module @hyperfrontend/immutable-api-utils/built-in-copy/json
321
+ */
322
+ // Capture references at module initialization time
323
+ const _JSON = globalThis.JSON;
324
+ /**
325
+ * (Safe copy) Converts a JavaScript Object Notation (JSON) string into an object.
326
+ */
327
+ const parse = _JSON.parse;
328
+ /**
329
+ * (Safe copy) Converts a JavaScript value to a JavaScript Object Notation (JSON) string.
330
+ */
331
+ const stringify = _JSON.stringify;
332
+
333
+ const registeredClasses = [];
334
+
335
+ /**
336
+ * Returns the data type of the target.
337
+ * Uses native `typeof` operator, however, makes distinction between `null`, `array`, and `object`.
338
+ * Also, when classes are registered via `registerClass`, it checks if objects are instance of any known registered class.
339
+ *
340
+ * @param target - The target to get the data type of.
341
+ * @returns The data type of the target.
342
+ */
343
+ const getType = (target) => {
344
+ if (target === null)
345
+ return 'null';
346
+ const nativeDataType = typeof target;
347
+ if (nativeDataType === 'object') {
348
+ if (isArray(target))
349
+ return 'array';
350
+ for (const registeredClass of registeredClasses) {
351
+ if (target instanceof registeredClass)
352
+ return registeredClass.name;
353
+ }
354
+ }
355
+ return nativeDataType;
356
+ };
357
+
358
+ /**
359
+ * Safe copies of Error built-ins via factory functions.
360
+ *
361
+ * Since constructors cannot be safely captured via Object.assign, this module
362
+ * provides factory functions that use Reflect.construct internally.
363
+ *
364
+ * These references are captured at module initialization time to protect against
365
+ * prototype pollution attacks. Import only what you need for tree-shaking.
366
+ *
367
+ * @module @hyperfrontend/immutable-api-utils/built-in-copy/error
368
+ */
369
+ // Capture references at module initialization time
370
+ const _Error = globalThis.Error;
371
+ const _Reflect = globalThis.Reflect;
372
+ /**
373
+ * (Safe copy) Creates a new Error using the captured Error constructor.
374
+ * Use this instead of `new Error()`.
375
+ *
376
+ * @param message - Optional error message.
377
+ * @param options - Optional error options.
378
+ * @returns A new Error instance.
379
+ */
380
+ const createError = (message, options) => _Reflect.construct(_Error, [message, options]);
381
+
382
+ /**
383
+ * Safe copies of Math built-in methods.
384
+ *
385
+ * These references are captured at module initialization time to protect against
386
+ * prototype pollution attacks. Import only what you need for tree-shaking.
387
+ *
388
+ * @module @hyperfrontend/immutable-api-utils/built-in-copy/math
389
+ */
390
+ // Capture references at module initialization time
391
+ const _Math = globalThis.Math;
392
+ /**
393
+ * (Safe copy) Returns the smaller of zero or more numbers.
394
+ */
395
+ const min = _Math.min;
396
+
397
+ /* eslint-disable @typescript-eslint/no-explicit-any */
398
+ /**
399
+ * Creates a wrapper function that only executes the wrapped function if the condition function returns true.
400
+ *
401
+ * @param func - The function to be conditionally executed.
402
+ * @param conditionFunc - A function that returns a boolean, determining if `func` should be executed.
403
+ * @returns A wrapped version of `func` that executes conditionally.
404
+ */
405
+ function createConditionalExecutionFunction(func, conditionFunc) {
406
+ return function (...args) {
407
+ if (conditionFunc()) {
408
+ return func(...args);
409
+ }
410
+ };
411
+ }
412
+
413
+ /* eslint-disable @typescript-eslint/no-explicit-any */
414
+ /**
415
+ * Creates a wrapper function that silently ignores any errors thrown by the wrapped void function.
416
+ * This function is specifically for wrapping functions that do not return a value (void functions).
417
+ * Exceptions are swallowed without any logging or handling.
418
+ *
419
+ * @param func - The void function to be wrapped.
420
+ * @returns A wrapped version of the input function that ignores errors.
421
+ */
422
+ function createErrorIgnoringFunction(func) {
423
+ return function (...args) {
424
+ try {
425
+ func(...args);
426
+ }
427
+ catch {
428
+ // Deliberately swallowing/ignoring the exception
429
+ }
430
+ };
431
+ }
432
+
433
+ /* eslint-disable @typescript-eslint/no-unused-vars */
434
+ /**
435
+ * A no-operation function (noop) that does nothing regardless of the arguments passed.
436
+ * It is designed to be as permissive as possible in its typing without using the `Function` keyword.
437
+ *
438
+ * @param args - Any arguments passed to the function (ignored)
439
+ */
440
+ const noop = (...args) => {
441
+ // Intentionally does nothing
442
+ };
443
+
444
+ const logLevels = ['none', 'error', 'warn', 'log', 'info', 'debug'];
445
+ const priority = {
446
+ error: 4,
447
+ warn: 3,
448
+ log: 2,
449
+ info: 1,
450
+ debug: 0,
451
+ };
452
+ /**
453
+ * Validates whether a given string is a valid log level.
454
+ *
455
+ * @param level - The log level to validate
456
+ * @returns True if the level is valid, false otherwise
457
+ */
458
+ function isValidLogLevel(level) {
459
+ return logLevels.includes(level);
460
+ }
461
+ /**
462
+ * Creates a log level configuration manager for controlling logging behavior.
463
+ * Provides methods to get, set, and evaluate log levels based on priority.
464
+ *
465
+ * @param level - The initial log level (defaults to 'error')
466
+ * @returns A configuration object with log level management methods
467
+ * @throws {Error} When the provided level is not a valid log level
468
+ */
469
+ function createLogLevelConfig(level = 'error') {
470
+ if (!isValidLogLevel(level)) {
471
+ throw createError('Cannot create log level configuration with a valid default log level');
472
+ }
473
+ const state = { level };
474
+ const getLogLevel = () => state.level;
475
+ const setLogLevel = (level) => {
476
+ if (!isValidLogLevel(level)) {
477
+ throw createError(`Cannot set value '${level}' level. Expected levels are ${logLevels}.`);
478
+ }
479
+ state.level = level;
480
+ };
481
+ const shouldLog = (level) => {
482
+ if (state.level === 'none' || level === 'none' || !isValidLogLevel(level)) {
483
+ return false;
484
+ }
485
+ return priority[level] >= priority[state.level];
486
+ };
487
+ return freeze({
488
+ getLogLevel,
489
+ setLogLevel,
490
+ shouldLog,
491
+ });
492
+ }
493
+
494
+ /**
495
+ * Creates a logger instance with configurable log level filtering.
496
+ * Each log function is wrapped to respect the current log level setting.
497
+ *
498
+ * @param error - Function to handle error-level logs (required)
499
+ * @param warn - Function to handle warning-level logs (optional, defaults to noop)
500
+ * @param log - Function to handle standard logs (optional, defaults to noop)
501
+ * @param info - Function to handle info-level logs (optional, defaults to noop)
502
+ * @param debug - Function to handle debug-level logs (optional, defaults to noop)
503
+ * @returns A frozen logger object with log methods and level control
504
+ * @throws {ErrorLevelFn} When any provided log function is invalid
505
+ */
506
+ function createLogger(error, warn = noop, log = noop, info = noop, debug = noop) {
507
+ if (notValidLogFn(error)) {
508
+ throw createError(notFnMsg('error'));
509
+ }
510
+ if (notValidLogFn(warn)) {
511
+ throw createError(notFnMsg('warn'));
512
+ }
513
+ if (notValidLogFn(log)) {
514
+ throw createError(notFnMsg('log'));
515
+ }
516
+ if (notValidLogFn(info)) {
517
+ throw createError(notFnMsg('info'));
518
+ }
519
+ if (notValidLogFn(debug)) {
520
+ throw createError(notFnMsg('debug'));
521
+ }
522
+ const { setLogLevel, getLogLevel, shouldLog } = createLogLevelConfig();
523
+ const wrapLogFn = (fn, level) => {
524
+ if (fn === noop)
525
+ return fn;
526
+ const condition = () => shouldLog(level);
527
+ return createConditionalExecutionFunction(createErrorIgnoringFunction(fn), condition);
528
+ };
529
+ return freeze({
530
+ error: wrapLogFn(error, 'error'),
531
+ warn: wrapLogFn(warn, 'warn'),
532
+ log: wrapLogFn(log, 'log'),
533
+ info: wrapLogFn(info, 'info'),
534
+ debug: wrapLogFn(debug, 'debug'),
535
+ setLogLevel,
536
+ getLogLevel,
537
+ });
538
+ }
539
+ /**
540
+ * Validates whether a given value is a valid log function.
541
+ *
542
+ * @param fn - The value to validate
543
+ * @returns True if the value is not a function (invalid), false if it is valid
544
+ */
545
+ function notValidLogFn(fn) {
546
+ return getType(fn) !== 'function' && fn !== noop;
547
+ }
548
+ /**
549
+ * Generates an error message for invalid log function parameters.
550
+ *
551
+ * @param label - The name of the log function that failed validation
552
+ * @returns A formatted error message string
553
+ */
554
+ function notFnMsg(label) {
555
+ return `Cannot create a logger when ${label} is not a function`;
556
+ }
557
+
558
+ createLogger(error, warn, log, info, debug);
559
+
560
+ /**
561
+ * Global log level registry.
562
+ * Tracks all created scoped loggers to allow global log level changes.
563
+ */
564
+ const loggerRegistry = createSet();
565
+ /** Redacted placeholder for sensitive values */
566
+ const REDACTED = '[REDACTED]';
567
+ /**
568
+ * Patterns that indicate a sensitive key name.
569
+ * Keys containing these patterns will have their values sanitized.
570
+ */
571
+ const SENSITIVE_KEY_PATTERNS = [
572
+ /token/i,
573
+ /key/i,
574
+ /password/i,
575
+ /secret/i,
576
+ /credential/i,
577
+ /auth/i,
578
+ /bearer/i,
579
+ /api[_-]?key/i,
580
+ /private/i,
581
+ /passphrase/i,
582
+ ];
583
+ /**
584
+ * Checks if a key name indicates sensitive data.
585
+ *
586
+ * @param key - Key name to check
587
+ * @returns True if the key indicates sensitive data
588
+ */
589
+ function isSensitiveKey(key) {
590
+ return SENSITIVE_KEY_PATTERNS.some((pattern) => pattern.test(key));
591
+ }
592
+ /**
593
+ * Sanitizes an object by replacing sensitive values with REDACTED.
594
+ * This function recursively processes nested objects and arrays.
595
+ *
596
+ * @param obj - Object to sanitize
597
+ * @returns New object with sensitive values redacted
598
+ */
599
+ function sanitize(obj) {
600
+ if (obj === null || obj === undefined) {
601
+ return obj;
602
+ }
603
+ if (isArray(obj)) {
604
+ return obj.map((item) => sanitize(item));
605
+ }
606
+ if (typeof obj === 'object') {
607
+ const result = {};
608
+ for (const [key, value] of entries(obj)) {
609
+ if (isSensitiveKey(key)) {
610
+ result[key] = REDACTED;
611
+ }
612
+ else if (typeof value === 'object' && value !== null) {
613
+ result[key] = sanitize(value);
614
+ }
615
+ else {
616
+ result[key] = value;
617
+ }
618
+ }
619
+ return result;
620
+ }
621
+ return obj;
622
+ }
623
+ /**
624
+ * Formats a log message with optional metadata.
625
+ *
626
+ * @param namespace - Logger namespace prefix
627
+ * @param message - Log message
628
+ * @param meta - Optional metadata object
629
+ * @returns Formatted log string
630
+ */
631
+ function formatMessage(namespace, message, meta) {
632
+ const prefix = `[${namespace}]`;
633
+ if (meta && keys(meta).length > 0) {
634
+ const sanitizedMeta = sanitize(meta);
635
+ return `${prefix} ${message} ${stringify(sanitizedMeta)}`;
636
+ }
637
+ return `${prefix} ${message}`;
638
+ }
639
+ /**
640
+ * Creates a scoped logger with namespace prefix and optional secret sanitization.
641
+ * All log messages will be prefixed with [namespace] and sensitive metadata
642
+ * values will be automatically redacted.
643
+ *
644
+ * @param namespace - Logger namespace (e.g., 'project-scope', 'analyze')
645
+ * @param options - Logger configuration options
646
+ * @returns A configured scoped logger instance
647
+ *
648
+ * @example
649
+ * ```typescript
650
+ * const logger = createScopedLogger('project-scope')
651
+ * logger.setLogLevel('debug')
652
+ *
653
+ * // Basic logging
654
+ * logger.info('Starting analysis', { path: './project' })
655
+ *
656
+ * // Sensitive data is automatically redacted
657
+ * logger.debug('Config loaded', { apiKey: 'secret123' })
658
+ * // Output: [project-scope] Config loaded {"apiKey":"[REDACTED]"}
659
+ * ```
660
+ */
661
+ function createScopedLogger(namespace, options = {}) {
662
+ const { level = 'error', sanitizeSecrets = true } = options;
663
+ // Create wrapper functions that add namespace prefix and sanitization
664
+ const createLogFn = (baseFn) => (message, meta) => {
665
+ const processedMeta = sanitizeSecrets && meta ? sanitize(meta) : meta;
666
+ baseFn(formatMessage(namespace, message, processedMeta));
667
+ };
668
+ // Create base logger with wrapped functions
669
+ const baseLogger = createLogger(createLogFn(error), createLogFn(warn), createLogFn(log), createLogFn(info), createLogFn(debug));
670
+ // Set initial log level (use global override if set)
671
+ baseLogger.setLogLevel(level);
672
+ const scopedLogger = freeze({
673
+ error: (message, meta) => baseLogger.error(message, meta),
674
+ warn: (message, meta) => baseLogger.warn(message, meta),
675
+ log: (message, meta) => baseLogger.log(message, meta),
676
+ info: (message, meta) => baseLogger.info(message, meta),
677
+ debug: (message, meta) => baseLogger.debug(message, meta),
678
+ setLogLevel: baseLogger.setLogLevel,
679
+ getLogLevel: baseLogger.getLogLevel,
680
+ });
681
+ // Register logger for global level management
682
+ loggerRegistry.add(scopedLogger);
683
+ return scopedLogger;
684
+ }
685
+ /**
686
+ * Default logger instance for the project-scope library.
687
+ * Use this for general logging within the library.
688
+ *
689
+ * @example
690
+ * ```typescript
691
+ * import { logger } from '@hyperfrontend/project-scope/core'
692
+ *
693
+ * logger.setLogLevel('debug')
694
+ * logger.debug('Analyzing project', { path: './src' })
695
+ * ```
696
+ */
697
+ createScopedLogger('project-scope');
698
+
699
+ createScopedLogger('project-scope:fs');
700
+ /**
701
+ * Create a file system error with code and context.
702
+ *
703
+ * @param message - The error message describing what went wrong
704
+ * @param code - The category code for this type of filesystem failure
705
+ * @param context - Additional context including path, operation, and cause
706
+ * @returns A configured Error object with code and context properties
707
+ */
708
+ function createFileSystemError(message, code, context) {
709
+ const error = createError(message);
710
+ defineProperties(error, {
711
+ code: { value: code, enumerable: true },
712
+ context: { value: context, enumerable: true },
713
+ });
714
+ return error;
715
+ }
716
+ /**
717
+ * Read file if exists, return null otherwise.
718
+ *
719
+ * @param filePath - Path to file
720
+ * @param encoding - File encoding (default: utf-8)
721
+ * @returns File contents or null if file doesn't exist
722
+ */
723
+ function readFileIfExists(filePath, encoding = 'utf-8') {
724
+ if (!node_fs.existsSync(filePath)) {
725
+ return null;
726
+ }
727
+ try {
728
+ return node_fs.readFileSync(filePath, { encoding });
729
+ }
730
+ catch {
731
+ return null;
732
+ }
733
+ }
734
+
735
+ createScopedLogger('project-scope:fs:write');
736
+
737
+ /**
738
+ * Get file stats with error handling.
739
+ *
740
+ * @param filePath - Path to file
741
+ * @param followSymlinks - Whether to follow symlinks (default: true)
742
+ * @returns File stats or null if path doesn't exist
743
+ */
744
+ function getFileStat(filePath, followSymlinks = true) {
745
+ if (!node_fs.existsSync(filePath)) {
746
+ return null;
747
+ }
748
+ try {
749
+ const stat = followSymlinks ? node_fs.statSync(filePath) : node_fs.lstatSync(filePath);
750
+ return {
751
+ isFile: stat.isFile(),
752
+ isDirectory: stat.isDirectory(),
753
+ isSymlink: stat.isSymbolicLink(),
754
+ size: stat.size,
755
+ created: stat.birthtime,
756
+ modified: stat.mtime,
757
+ accessed: stat.atime,
758
+ mode: stat.mode,
759
+ };
760
+ }
761
+ catch {
762
+ return null;
763
+ }
764
+ }
765
+ /**
766
+ * Check if path is a directory.
767
+ *
768
+ * @param dirPath - Path to check
769
+ * @returns True if path is a directory
770
+ */
771
+ function isDirectory(dirPath) {
772
+ const stats = getFileStat(dirPath);
773
+ return stats?.isDirectory ?? false;
774
+ }
775
+ /**
776
+ * Check if path exists.
777
+ *
778
+ * @param filePath - Path to check
779
+ * @returns True if path exists
780
+ */
781
+ function exists(filePath) {
782
+ return node_fs.existsSync(filePath);
783
+ }
784
+
785
+ const fsDirLogger = createScopedLogger('project-scope:fs:dir');
786
+ /**
787
+ * List immediate contents of a directory.
788
+ *
789
+ * @param dirPath - Absolute or relative path to the directory
790
+ * @returns Array of entries with metadata for each file/directory
791
+ * @throws {Error} If directory doesn't exist or isn't a directory
792
+ *
793
+ * @example
794
+ * ```typescript
795
+ * import { readDirectory } from '@hyperfrontend/project-scope'
796
+ *
797
+ * const entries = readDirectory('./src')
798
+ * for (const entry of entries) {
799
+ * console.log(entry.name, entry.isFile ? 'file' : 'directory')
800
+ * }
801
+ * ```
802
+ */
803
+ function readDirectory(dirPath) {
804
+ fsDirLogger.debug('Reading directory', { path: dirPath });
805
+ if (!node_fs.existsSync(dirPath)) {
806
+ fsDirLogger.debug('Directory not found', { path: dirPath });
807
+ throw createFileSystemError(`Directory not found: ${dirPath}`, 'FS_NOT_FOUND', { path: dirPath, operation: 'readdir' });
808
+ }
809
+ if (!isDirectory(dirPath)) {
810
+ fsDirLogger.debug('Path is not a directory', { path: dirPath });
811
+ throw createFileSystemError(`Not a directory: ${dirPath}`, 'FS_NOT_A_DIRECTORY', { path: dirPath, operation: 'readdir' });
812
+ }
813
+ try {
814
+ const entries = node_fs.readdirSync(dirPath, { withFileTypes: true });
815
+ fsDirLogger.debug('Directory read complete', { path: dirPath, entryCount: entries.length });
816
+ return entries.map((entry) => ({
817
+ name: entry.name,
818
+ path: node_path.join(dirPath, entry.name),
819
+ isFile: entry.isFile(),
820
+ isDirectory: entry.isDirectory(),
821
+ isSymlink: entry.isSymbolicLink(),
822
+ }));
823
+ }
824
+ catch (error) {
825
+ fsDirLogger.warn('Failed to read directory', { path: dirPath, error: error instanceof Error ? error.message : String(error) });
826
+ throw createFileSystemError(`Failed to read directory: ${dirPath}`, 'FS_READ_ERROR', {
827
+ path: dirPath,
828
+ operation: 'readdir',
829
+ cause: error,
830
+ });
831
+ }
832
+ }
833
+
834
+ /**
835
+ * Join path segments.
836
+ * Uses platform-specific separators (e.g., / or \).
837
+ *
838
+ * @param paths - Path segments to join
839
+ * @returns Joined path
840
+ */
841
+ function join(...paths) {
842
+ return node_path.join(...paths);
843
+ }
844
+
845
+ createScopedLogger('project-scope:fs:traversal');
846
+
847
+ const packageLogger = createScopedLogger('project-scope:project:package');
848
+ /**
849
+ * Verifies that a value is an object with only string values,
850
+ * used for validating dependency maps and script definitions.
851
+ *
852
+ * @param value - Value to check
853
+ * @returns True if value is a record of strings
854
+ */
855
+ function isStringRecord(value) {
856
+ if (typeof value !== 'object' || value === null)
857
+ return false;
858
+ return values(value).every((v) => typeof v === 'string');
859
+ }
860
+ /**
861
+ * Extracts and normalizes the workspaces field from package.json,
862
+ * supporting both array format and object with packages array.
863
+ *
864
+ * @param value - Raw workspaces value from package.json
865
+ * @returns Normalized workspace patterns or undefined if invalid
866
+ */
867
+ function parseWorkspaces(value) {
868
+ if (isArray(value) && value.every((v) => typeof v === 'string')) {
869
+ return value;
870
+ }
871
+ if (typeof value === 'object' && value !== null) {
872
+ const obj = value;
873
+ if (isArray(obj['packages'])) {
874
+ return { packages: obj['packages'] };
875
+ }
876
+ }
877
+ return undefined;
878
+ }
879
+ /**
880
+ * Validate and normalize package.json data.
881
+ *
882
+ * @param data - Raw parsed data
883
+ * @returns Validated package.json
884
+ */
885
+ function validatePackageJson(data) {
886
+ if (typeof data !== 'object' || data === null) {
887
+ throw createError('package.json must be an object');
888
+ }
889
+ const pkg = data;
890
+ return {
891
+ name: typeof pkg['name'] === 'string' ? pkg['name'] : undefined,
892
+ version: typeof pkg['version'] === 'string' ? pkg['version'] : undefined,
893
+ description: typeof pkg['description'] === 'string' ? pkg['description'] : undefined,
894
+ main: typeof pkg['main'] === 'string' ? pkg['main'] : undefined,
895
+ module: typeof pkg['module'] === 'string' ? pkg['module'] : undefined,
896
+ browser: typeof pkg['browser'] === 'string' ? pkg['browser'] : undefined,
897
+ types: typeof pkg['types'] === 'string' ? pkg['types'] : undefined,
898
+ bin: typeof pkg['bin'] === 'string' || isStringRecord(pkg['bin']) ? pkg['bin'] : undefined,
899
+ scripts: isStringRecord(pkg['scripts']) ? pkg['scripts'] : undefined,
900
+ dependencies: isStringRecord(pkg['dependencies']) ? pkg['dependencies'] : undefined,
901
+ devDependencies: isStringRecord(pkg['devDependencies']) ? pkg['devDependencies'] : undefined,
902
+ peerDependencies: isStringRecord(pkg['peerDependencies']) ? pkg['peerDependencies'] : undefined,
903
+ optionalDependencies: isStringRecord(pkg['optionalDependencies']) ? pkg['optionalDependencies'] : undefined,
904
+ workspaces: parseWorkspaces(pkg['workspaces']),
905
+ exports: typeof pkg['exports'] === 'object' ? pkg['exports'] : undefined,
906
+ engines: isStringRecord(pkg['engines']) ? pkg['engines'] : undefined,
907
+ ...pkg,
908
+ };
909
+ }
910
+ /**
911
+ * Attempts to read and parse package.json if it exists,
912
+ * returning null on missing file or parse failure.
913
+ *
914
+ * @param projectPath - Project directory path or path to package.json
915
+ * @returns Parsed package.json or null if not found
916
+ */
917
+ function readPackageJsonIfExists(projectPath) {
918
+ const packageJsonPath = projectPath.endsWith('package.json') ? projectPath : node_path.join(projectPath, 'package.json');
919
+ const content = readFileIfExists(packageJsonPath);
920
+ if (!content) {
921
+ packageLogger.debug('Package.json not found', { path: packageJsonPath });
922
+ return null;
923
+ }
924
+ try {
925
+ const validated = validatePackageJson(parse(content));
926
+ packageLogger.debug('Package.json loaded', { path: packageJsonPath, name: validated.name });
927
+ return validated;
928
+ }
929
+ catch {
930
+ packageLogger.debug('Failed to parse package.json, returning null', { path: packageJsonPath });
931
+ return null;
932
+ }
933
+ }
934
+
935
+ /**
936
+ * Get combined dependencies from package.json.
937
+ * Merges dependencies, devDependencies, peerDependencies, and optionalDependencies.
938
+ *
939
+ * @param packageJson - The package.json object to extract dependencies from
940
+ * @returns Combined dependencies as a single record
941
+ */
942
+ function collectAllDependencies(packageJson) {
943
+ return {
944
+ ...packageJson?.dependencies,
945
+ ...packageJson?.devDependencies,
946
+ ...packageJson?.peerDependencies,
947
+ ...packageJson?.optionalDependencies,
948
+ };
949
+ }
950
+ /**
951
+ * Extract clean version from dependency version string.
952
+ * Removes semver prefixes like ^, ~, >=, etc.
953
+ * Uses character-by-character parsing to avoid ReDoS vulnerabilities.
954
+ *
955
+ * @param versionString - The version string with optional prefix characters
956
+ * @returns The cleaned version string without prefix characters
957
+ */
958
+ function parseVersionString(versionString) {
959
+ if (versionString === undefined || versionString === null)
960
+ return undefined;
961
+ // Manual parsing instead of regex to avoid ReDoS
962
+ let start = 0;
963
+ while (start < versionString.length) {
964
+ const char = versionString[start];
965
+ if (char !== '^' && char !== '~' && char !== '>' && char !== '=' && char !== '<') {
966
+ break;
967
+ }
968
+ start++;
969
+ }
970
+ return versionString.slice(start);
971
+ }
972
+ /**
973
+ * Find first matching config file in project.
974
+ * Note: Name avoids similarity to fs.readFile/fs.readFileSync.
975
+ *
976
+ * @param projectPath - The project directory path
977
+ * @param patterns - Array of config file patterns to search for
978
+ * @returns The first matching config file path or undefined
979
+ */
980
+ function locateConfigFile(projectPath, patterns) {
981
+ for (const pattern of patterns) {
982
+ const fullPath = join(projectPath, pattern);
983
+ if (exists(fullPath)) {
984
+ return pattern;
985
+ }
986
+ }
987
+ return undefined;
988
+ }
989
+ /**
990
+ * Find scripts containing a specific command.
991
+ *
992
+ * @param scripts - The scripts object from package.json
993
+ * @param command - The command string to search for
994
+ * @returns Array of script names that contain the command
995
+ */
996
+ function filterScriptsByCommand(scripts, command) {
997
+ if (!scripts)
998
+ return [];
999
+ return entries(scripts)
1000
+ .filter(([, script]) => script.includes(command))
1001
+ .map(([name]) => name);
1002
+ }
1003
+
1004
+ /**
1005
+ * Detect Express in project.
1006
+ *
1007
+ * @param projectPath - Project directory path
1008
+ * @param packageJson - Optional pre-loaded package.json
1009
+ * @returns Detection result or null if not detected
1010
+ */
1011
+ function expressDetector(projectPath, packageJson) {
1012
+ const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
1013
+ const sources = [];
1014
+ let confidence = 0;
1015
+ let version;
1016
+ const deps = collectAllDependencies(pkg);
1017
+ if (deps['express']) {
1018
+ confidence += 80;
1019
+ version = parseVersionString(deps['express']);
1020
+ sources.push({ type: 'package.json', field: 'dependencies.express' });
1021
+ }
1022
+ // @types/express (indicates usage)
1023
+ if (deps['@types/express']) {
1024
+ confidence += 10;
1025
+ sources.push({ type: 'package.json', field: 'dependencies.@types/express' });
1026
+ }
1027
+ const expressMiddleware = keys(deps).filter((d) => d.includes('express-') || d === 'body-parser' || d === 'cors' || d === 'helmet' || d === 'morgan');
1028
+ if (expressMiddleware.length > 0) {
1029
+ confidence += 10;
1030
+ sources.push({ type: 'package.json', field: 'dependencies (express middleware)' });
1031
+ }
1032
+ if (confidence === 0) {
1033
+ return null;
1034
+ }
1035
+ return {
1036
+ id: 'express',
1037
+ name: 'Express',
1038
+ version,
1039
+ confidence: min(confidence, 100),
1040
+ detectedFrom: sources,
1041
+ };
1042
+ }
1043
+
1044
+ /**
1045
+ * Detect NestJS in project.
1046
+ *
1047
+ * @param projectPath - Project directory path
1048
+ * @param packageJson - Optional pre-loaded package.json
1049
+ * @returns Detection result or null if not detected
1050
+ */
1051
+ function nestDetector(projectPath, packageJson) {
1052
+ const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
1053
+ const sources = [];
1054
+ let confidence = 0;
1055
+ let version;
1056
+ let configPath;
1057
+ const deps = collectAllDependencies(pkg);
1058
+ // @nestjs/core package
1059
+ if (deps['@nestjs/core']) {
1060
+ confidence += 70;
1061
+ version = parseVersionString(deps['@nestjs/core']);
1062
+ sources.push({ type: 'package.json', field: 'dependencies.@nestjs/core' });
1063
+ }
1064
+ // @nestjs/common
1065
+ if (deps['@nestjs/common']) {
1066
+ confidence += 15;
1067
+ sources.push({ type: 'package.json', field: 'dependencies.@nestjs/common' });
1068
+ }
1069
+ if (exists(node_path.join(projectPath, 'nest-cli.json'))) {
1070
+ confidence += 15;
1071
+ configPath = 'nest-cli.json';
1072
+ sources.push({ type: 'config-file', path: 'nest-cli.json' });
1073
+ }
1074
+ const nestPackages = keys(deps).filter((d) => d.startsWith('@nestjs/'));
1075
+ if (nestPackages.length > 2) {
1076
+ confidence += 5;
1077
+ sources.push({ type: 'package.json', field: 'dependencies (@nestjs packages)' });
1078
+ }
1079
+ if (confidence === 0) {
1080
+ return null;
1081
+ }
1082
+ return {
1083
+ id: 'nestjs',
1084
+ name: 'NestJS',
1085
+ version,
1086
+ configPath,
1087
+ confidence: min(confidence, 100),
1088
+ detectedFrom: sources,
1089
+ };
1090
+ }
1091
+
1092
+ /**
1093
+ * Detect Fastify in project.
1094
+ *
1095
+ * @param projectPath - Project directory path
1096
+ * @param packageJson - Optional pre-loaded package.json
1097
+ * @returns Detection result or null if not detected
1098
+ */
1099
+ function fastifyDetector(projectPath, packageJson) {
1100
+ const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
1101
+ const sources = [];
1102
+ let confidence = 0;
1103
+ let version;
1104
+ const deps = collectAllDependencies(pkg);
1105
+ if (deps['fastify']) {
1106
+ confidence += 80;
1107
+ version = parseVersionString(deps['fastify']);
1108
+ sources.push({ type: 'package.json', field: 'dependencies.fastify' });
1109
+ }
1110
+ const fastifyPlugins = keys(deps).filter((d) => d.startsWith('@fastify/') || d.startsWith('fastify-'));
1111
+ if (fastifyPlugins.length > 0) {
1112
+ confidence += 15;
1113
+ sources.push({ type: 'package.json', field: 'dependencies (fastify plugins)' });
1114
+ }
1115
+ // @types/fastify (older versions)
1116
+ if (deps['@types/fastify']) {
1117
+ confidence += 5;
1118
+ sources.push({ type: 'package.json', field: 'dependencies.@types/fastify' });
1119
+ }
1120
+ if (confidence === 0) {
1121
+ return null;
1122
+ }
1123
+ return {
1124
+ id: 'fastify',
1125
+ name: 'Fastify',
1126
+ version,
1127
+ confidence: min(confidence, 100),
1128
+ detectedFrom: sources,
1129
+ };
1130
+ }
1131
+
1132
+ /**
1133
+ * Detect Koa in project.
1134
+ *
1135
+ * @param projectPath - Project directory path
1136
+ * @param packageJson - Optional pre-loaded package.json
1137
+ * @returns Detection result or null if not detected
1138
+ */
1139
+ function koaDetector(projectPath, packageJson) {
1140
+ const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
1141
+ const sources = [];
1142
+ let confidence = 0;
1143
+ let version;
1144
+ const deps = collectAllDependencies(pkg);
1145
+ if (deps['koa']) {
1146
+ confidence += 80;
1147
+ version = parseVersionString(deps['koa']);
1148
+ sources.push({ type: 'package.json', field: 'dependencies.koa' });
1149
+ }
1150
+ // @types/koa
1151
+ if (deps['@types/koa']) {
1152
+ confidence += 10;
1153
+ sources.push({ type: 'package.json', field: 'dependencies.@types/koa' });
1154
+ }
1155
+ const koaMiddleware = keys(deps).filter((d) => d.startsWith('koa-') || d.startsWith('@koa/'));
1156
+ if (koaMiddleware.length > 0) {
1157
+ confidence += 10;
1158
+ sources.push({ type: 'package.json', field: 'dependencies (koa middleware)' });
1159
+ }
1160
+ if (confidence === 0) {
1161
+ return null;
1162
+ }
1163
+ return {
1164
+ id: 'koa',
1165
+ name: 'Koa',
1166
+ version,
1167
+ confidence: min(confidence, 100),
1168
+ detectedFrom: sources,
1169
+ };
1170
+ }
1171
+
1172
+ /**
1173
+ * Detect Hono in project.
1174
+ *
1175
+ * @param projectPath - Project directory path
1176
+ * @param packageJson - Optional pre-loaded package.json
1177
+ * @returns Detection result or null if not detected
1178
+ */
1179
+ function honoDetector(projectPath, packageJson) {
1180
+ const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
1181
+ const sources = [];
1182
+ let confidence = 0;
1183
+ let version;
1184
+ const deps = collectAllDependencies(pkg);
1185
+ if (deps['hono']) {
1186
+ confidence += 85;
1187
+ version = parseVersionString(deps['hono']);
1188
+ sources.push({ type: 'package.json', field: 'dependencies.hono' });
1189
+ }
1190
+ const honoAdapters = keys(deps).filter((d) => d.startsWith('@hono/'));
1191
+ if (honoAdapters.length > 0) {
1192
+ confidence += 15;
1193
+ sources.push({ type: 'package.json', field: 'dependencies (@hono adapters)' });
1194
+ }
1195
+ if (confidence === 0) {
1196
+ return null;
1197
+ }
1198
+ return {
1199
+ id: 'hono',
1200
+ name: 'Hono',
1201
+ version,
1202
+ confidence: min(confidence, 100),
1203
+ detectedFrom: sources,
1204
+ };
1205
+ }
1206
+
1207
+ /** All backend framework detectors */
1208
+ const backendDetectors = [
1209
+ { id: 'express', name: 'Express', detect: expressDetector },
1210
+ { id: 'nestjs', name: 'NestJS', detect: nestDetector },
1211
+ { id: 'fastify', name: 'Fastify', detect: fastifyDetector },
1212
+ { id: 'koa', name: 'Koa', detect: koaDetector },
1213
+ { id: 'hono', name: 'Hono', detect: honoDetector },
1214
+ ];
1215
+
1216
+ /** Config patterns for Webpack */
1217
+ const WEBPACK_CONFIG_PATTERNS = [
1218
+ 'webpack.config.js',
1219
+ 'webpack.config.ts',
1220
+ 'webpack.config.cjs',
1221
+ 'webpack.config.mjs',
1222
+ 'webpack.config.babel.js',
1223
+ ];
1224
+ /**
1225
+ * Detect Webpack in project.
1226
+ *
1227
+ * @param projectPath - Project directory path
1228
+ * @param packageJson - Optional pre-loaded package.json
1229
+ * @returns Detection result or null if not detected
1230
+ */
1231
+ function webpackDetector(projectPath, packageJson) {
1232
+ const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
1233
+ const sources = [];
1234
+ let confidence = 0;
1235
+ let version;
1236
+ const deps = collectAllDependencies(pkg);
1237
+ if (deps['webpack']) {
1238
+ confidence += 50;
1239
+ version = parseVersionString(deps['webpack']);
1240
+ sources.push({ type: 'package.json', field: 'dependencies.webpack' });
1241
+ }
1242
+ const configPath = locateConfigFile(projectPath, WEBPACK_CONFIG_PATTERNS);
1243
+ if (configPath) {
1244
+ confidence += 40;
1245
+ sources.push({ type: 'config-file', path: configPath });
1246
+ }
1247
+ if (deps['webpack-cli']) {
1248
+ confidence += 10;
1249
+ sources.push({ type: 'package.json', field: 'dependencies.webpack-cli' });
1250
+ }
1251
+ const scriptMatches = filterScriptsByCommand(pkg?.scripts, 'webpack');
1252
+ for (const name of scriptMatches) {
1253
+ confidence = min(confidence + 5, 100);
1254
+ sources.push({ type: 'package.json', field: `scripts.${name}` });
1255
+ }
1256
+ if (confidence === 0) {
1257
+ return null;
1258
+ }
1259
+ return {
1260
+ id: 'webpack',
1261
+ name: 'Webpack',
1262
+ version,
1263
+ configPath,
1264
+ confidence: min(confidence, 100),
1265
+ detectedFrom: sources,
1266
+ };
1267
+ }
1268
+
1269
+ /** Config patterns for Vite */
1270
+ const VITE_CONFIG_PATTERNS = ['vite.config.js', 'vite.config.ts', 'vite.config.mjs', 'vite.config.cjs'];
1271
+ /**
1272
+ * Detect Vite in project.
1273
+ *
1274
+ * @param projectPath - Project directory path
1275
+ * @param packageJson - Optional pre-loaded package.json
1276
+ * @returns Detection result or null if not detected
1277
+ */
1278
+ function viteDetector(projectPath, packageJson) {
1279
+ const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
1280
+ const sources = [];
1281
+ let confidence = 0;
1282
+ let version;
1283
+ const deps = collectAllDependencies(pkg);
1284
+ if (deps['vite']) {
1285
+ confidence += 60;
1286
+ version = parseVersionString(deps['vite']);
1287
+ sources.push({ type: 'package.json', field: 'dependencies.vite' });
1288
+ }
1289
+ const configPath = locateConfigFile(projectPath, VITE_CONFIG_PATTERNS);
1290
+ if (configPath) {
1291
+ confidence += 35;
1292
+ sources.push({ type: 'config-file', path: configPath });
1293
+ }
1294
+ if (deps['vitest']) {
1295
+ confidence += 10;
1296
+ sources.push({ type: 'package.json', field: 'dependencies.vitest' });
1297
+ }
1298
+ const vitePlugins = keys(deps).filter((d) => d.startsWith('vite-plugin-') || d.startsWith('@vitejs/'));
1299
+ if (vitePlugins.length > 0) {
1300
+ confidence += 10;
1301
+ sources.push({ type: 'package.json', field: 'dependencies (vite plugins)' });
1302
+ }
1303
+ if (confidence === 0) {
1304
+ return null;
1305
+ }
1306
+ return {
1307
+ id: 'vite',
1308
+ name: 'Vite',
1309
+ version,
1310
+ configPath,
1311
+ confidence: min(confidence, 100),
1312
+ detectedFrom: sources,
1313
+ };
1314
+ }
1315
+
1316
+ /** Config patterns for Rollup */
1317
+ const ROLLUP_CONFIG_PATTERNS = ['rollup.config.js', 'rollup.config.ts', 'rollup.config.mjs', 'rollup.config.cjs'];
1318
+ /**
1319
+ * Detect Rollup in project.
1320
+ *
1321
+ * @param projectPath - Project directory path
1322
+ * @param packageJson - Optional pre-loaded package.json
1323
+ * @returns Detection result or null if not detected
1324
+ */
1325
+ function rollupDetector(projectPath, packageJson) {
1326
+ const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
1327
+ const sources = [];
1328
+ let confidence = 0;
1329
+ let version;
1330
+ const deps = collectAllDependencies(pkg);
1331
+ if (deps['rollup']) {
1332
+ confidence += 55;
1333
+ version = parseVersionString(deps['rollup']);
1334
+ sources.push({ type: 'package.json', field: 'dependencies.rollup' });
1335
+ }
1336
+ const configPath = locateConfigFile(projectPath, ROLLUP_CONFIG_PATTERNS);
1337
+ if (configPath) {
1338
+ confidence += 40;
1339
+ sources.push({ type: 'config-file', path: configPath });
1340
+ }
1341
+ const rollupPlugins = keys(deps).filter((d) => d.startsWith('@rollup/') || d.startsWith('rollup-plugin-'));
1342
+ if (rollupPlugins.length > 0) {
1343
+ confidence += 10;
1344
+ sources.push({ type: 'package.json', field: 'dependencies (rollup plugins)' });
1345
+ }
1346
+ const scriptMatches = filterScriptsByCommand(pkg?.scripts, 'rollup');
1347
+ for (const name of scriptMatches) {
1348
+ confidence = min(confidence + 5, 100);
1349
+ sources.push({ type: 'package.json', field: `scripts.${name}` });
1350
+ }
1351
+ if (confidence === 0) {
1352
+ return null;
1353
+ }
1354
+ return {
1355
+ id: 'rollup',
1356
+ name: 'Rollup',
1357
+ version,
1358
+ configPath,
1359
+ confidence: min(confidence, 100),
1360
+ detectedFrom: sources,
1361
+ };
1362
+ }
1363
+
1364
+ /**
1365
+ * Detect esbuild in project.
1366
+ *
1367
+ * @param projectPath - Project directory path
1368
+ * @param packageJson - Optional pre-loaded package.json
1369
+ * @returns Detection result or null if not detected
1370
+ */
1371
+ function esbuildDetector(projectPath, packageJson) {
1372
+ const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
1373
+ const sources = [];
1374
+ let confidence = 0;
1375
+ let version;
1376
+ const deps = collectAllDependencies(pkg);
1377
+ if (deps['esbuild']) {
1378
+ confidence += 70;
1379
+ version = parseVersionString(deps['esbuild']);
1380
+ sources.push({ type: 'package.json', field: 'dependencies.esbuild' });
1381
+ }
1382
+ const esbuildPlugins = keys(deps).filter((d) => d.includes('esbuild-plugin') || d.includes('esbuild-'));
1383
+ if (esbuildPlugins.length > 0) {
1384
+ confidence += 15;
1385
+ sources.push({ type: 'package.json', field: 'dependencies (esbuild plugins)' });
1386
+ }
1387
+ const scriptMatches = filterScriptsByCommand(pkg?.scripts, 'esbuild');
1388
+ for (const name of scriptMatches) {
1389
+ confidence = min(confidence + 10, 100);
1390
+ sources.push({ type: 'package.json', field: `scripts.${name}` });
1391
+ }
1392
+ if (confidence === 0) {
1393
+ return null;
1394
+ }
1395
+ return {
1396
+ id: 'esbuild',
1397
+ name: 'esbuild',
1398
+ version,
1399
+ confidence: min(confidence, 100),
1400
+ detectedFrom: sources,
1401
+ };
1402
+ }
1403
+
1404
+ /** Config patterns for Babel */
1405
+ const BABEL_CONFIG_PATTERNS = ['babel.config.js', 'babel.config.cjs', 'babel.config.mjs', 'babel.config.json', '.babelrc', '.babelrc.json', '.babelrc.js'];
1406
+ /**
1407
+ * Detect Babel in project.
1408
+ *
1409
+ * @param projectPath - Project directory path
1410
+ * @param packageJson - Optional pre-loaded package.json
1411
+ * @returns Detection result or null if not detected
1412
+ */
1413
+ function babelDetector(projectPath, packageJson) {
1414
+ const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
1415
+ const sources = [];
1416
+ let confidence = 0;
1417
+ let version;
1418
+ const deps = collectAllDependencies(pkg);
1419
+ if (deps['@babel/core']) {
1420
+ confidence += 50;
1421
+ version = parseVersionString(deps['@babel/core']);
1422
+ sources.push({ type: 'package.json', field: 'dependencies.@babel/core' });
1423
+ }
1424
+ const configPath = locateConfigFile(projectPath, BABEL_CONFIG_PATTERNS);
1425
+ if (configPath) {
1426
+ confidence += 40;
1427
+ sources.push({ type: 'config-file', path: configPath });
1428
+ }
1429
+ if (pkg && 'babel' in pkg) {
1430
+ confidence += 30;
1431
+ sources.push({ type: 'package.json', field: 'babel' });
1432
+ }
1433
+ const babelPackages = keys(deps).filter((d) => d.startsWith('@babel/'));
1434
+ if (babelPackages.length > 1) {
1435
+ confidence += 10;
1436
+ sources.push({ type: 'package.json', field: 'dependencies (@babel packages)' });
1437
+ }
1438
+ if (confidence === 0) {
1439
+ return null;
1440
+ }
1441
+ return {
1442
+ id: 'babel',
1443
+ name: 'Babel',
1444
+ version,
1445
+ configPath,
1446
+ confidence: min(confidence, 100),
1447
+ detectedFrom: sources,
1448
+ };
1449
+ }
1450
+
1451
+ /** Config patterns for SWC */
1452
+ const SWC_CONFIG_PATTERNS = ['.swcrc', 'swc.config.js'];
1453
+ /**
1454
+ * Detect SWC in project.
1455
+ *
1456
+ * @param projectPath - Project directory path
1457
+ * @param packageJson - Optional pre-loaded package.json
1458
+ * @returns Detection result or null if not detected
1459
+ */
1460
+ function swcDetector(projectPath, packageJson) {
1461
+ const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
1462
+ const sources = [];
1463
+ let confidence = 0;
1464
+ let version;
1465
+ const deps = collectAllDependencies(pkg);
1466
+ if (deps['@swc/core']) {
1467
+ confidence += 60;
1468
+ version = parseVersionString(deps['@swc/core']);
1469
+ sources.push({ type: 'package.json', field: 'dependencies.@swc/core' });
1470
+ }
1471
+ const configPath = locateConfigFile(projectPath, SWC_CONFIG_PATTERNS);
1472
+ if (configPath) {
1473
+ confidence += 35;
1474
+ sources.push({ type: 'config-file', path: configPath });
1475
+ }
1476
+ if (deps['@swc/cli']) {
1477
+ confidence += 10;
1478
+ sources.push({ type: 'package.json', field: 'dependencies.@swc/cli' });
1479
+ }
1480
+ const swcPlugins = keys(deps).filter((d) => d.startsWith('@swc/') || d.includes('swc-plugin'));
1481
+ if (swcPlugins.length > 1) {
1482
+ confidence += 5;
1483
+ sources.push({ type: 'package.json', field: 'dependencies (@swc packages)' });
1484
+ }
1485
+ if (confidence === 0) {
1486
+ return null;
1487
+ }
1488
+ return {
1489
+ id: 'swc',
1490
+ name: 'SWC',
1491
+ version,
1492
+ configPath,
1493
+ confidence: min(confidence, 100),
1494
+ detectedFrom: sources,
1495
+ };
1496
+ }
1497
+
1498
+ /** Config patterns for Parcel */
1499
+ const PARCEL_CONFIG_PATTERNS = ['.parcelrc'];
1500
+ /**
1501
+ * Detect Parcel in project.
1502
+ *
1503
+ * @param projectPath - Project directory path
1504
+ * @param packageJson - Optional pre-loaded package.json
1505
+ * @returns Detection result or null if not detected
1506
+ */
1507
+ function parcelDetector(projectPath, packageJson) {
1508
+ const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
1509
+ const sources = [];
1510
+ let confidence = 0;
1511
+ let version;
1512
+ const deps = collectAllDependencies(pkg);
1513
+ if (deps['parcel']) {
1514
+ confidence += 60;
1515
+ version = parseVersionString(deps['parcel']);
1516
+ sources.push({ type: 'package.json', field: 'dependencies.parcel' });
1517
+ }
1518
+ if (deps['parcel-bundler']) {
1519
+ confidence += 60;
1520
+ version = parseVersionString(deps['parcel-bundler']);
1521
+ sources.push({ type: 'package.json', field: 'dependencies.parcel-bundler' });
1522
+ }
1523
+ const configPath = locateConfigFile(projectPath, PARCEL_CONFIG_PATTERNS);
1524
+ if (configPath) {
1525
+ confidence += 30;
1526
+ sources.push({ type: 'config-file', path: configPath });
1527
+ }
1528
+ const scriptMatches = filterScriptsByCommand(pkg?.scripts, 'parcel');
1529
+ for (const name of scriptMatches) {
1530
+ confidence = min(confidence + 10, 100);
1531
+ sources.push({ type: 'package.json', field: `scripts.${name}` });
1532
+ }
1533
+ if (confidence === 0) {
1534
+ return null;
1535
+ }
1536
+ return {
1537
+ id: 'parcel',
1538
+ name: 'Parcel',
1539
+ version,
1540
+ configPath,
1541
+ confidence: min(confidence, 100),
1542
+ detectedFrom: sources,
1543
+ };
1544
+ }
1545
+
1546
+ /** All build tool detectors */
1547
+ const buildToolDetectors = [
1548
+ { id: 'webpack', name: 'Webpack', detect: webpackDetector },
1549
+ { id: 'vite', name: 'Vite', detect: viteDetector },
1550
+ { id: 'rollup', name: 'Rollup', detect: rollupDetector },
1551
+ { id: 'esbuild', name: 'esbuild', detect: esbuildDetector },
1552
+ { id: 'babel', name: 'Babel', detect: babelDetector },
1553
+ { id: 'swc', name: 'SWC', detect: swcDetector },
1554
+ { id: 'parcel', name: 'Parcel', detect: parcelDetector },
1555
+ ];
1556
+
1557
+ /**
1558
+ * Detect React in project.
1559
+ *
1560
+ * @param projectPath - Project directory path
1561
+ * @param packageJson - Optional pre-loaded package.json
1562
+ * @returns Detection result or null if not detected
1563
+ */
1564
+ function reactDetector(projectPath, packageJson) {
1565
+ const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
1566
+ const sources = [];
1567
+ let confidence = 0;
1568
+ let version;
1569
+ const metaFrameworks = [];
1570
+ const deps = collectAllDependencies(pkg);
1571
+ if (deps['react']) {
1572
+ confidence += 60;
1573
+ version = parseVersionString(deps['react']);
1574
+ sources.push({ type: 'package.json', field: 'dependencies.react' });
1575
+ }
1576
+ if (deps['react-dom']) {
1577
+ confidence += 20;
1578
+ sources.push({ type: 'package.json', field: 'dependencies.react-dom' });
1579
+ }
1580
+ if (deps['react-native']) {
1581
+ confidence += 20;
1582
+ sources.push({ type: 'package.json', field: 'dependencies.react-native' });
1583
+ }
1584
+ const hasJsxFiles = exists(node_path.join(projectPath, 'src', 'App.tsx')) ||
1585
+ exists(node_path.join(projectPath, 'src', 'App.jsx')) ||
1586
+ exists(node_path.join(projectPath, 'src', 'index.tsx')) ||
1587
+ exists(node_path.join(projectPath, 'src', 'index.jsx'));
1588
+ if (hasJsxFiles) {
1589
+ confidence += 10;
1590
+ sources.push({ type: 'directory', path: 'src/*.tsx or src/*.jsx' });
1591
+ }
1592
+ if (deps['next']) {
1593
+ metaFrameworks.push({
1594
+ id: 'nextjs',
1595
+ name: 'Next.js',
1596
+ category: 'meta-framework',
1597
+ version: parseVersionString(deps['next']),
1598
+ confidence: 90,
1599
+ detectedFrom: [{ type: 'package.json', field: 'dependencies.next' }],
1600
+ });
1601
+ }
1602
+ if (deps['gatsby']) {
1603
+ metaFrameworks.push({
1604
+ id: 'gatsby',
1605
+ name: 'Gatsby',
1606
+ category: 'meta-framework',
1607
+ version: parseVersionString(deps['gatsby']),
1608
+ confidence: 90,
1609
+ detectedFrom: [{ type: 'package.json', field: 'dependencies.gatsby' }],
1610
+ });
1611
+ }
1612
+ if (deps['@remix-run/react'] || deps['remix']) {
1613
+ metaFrameworks.push({
1614
+ id: 'remix',
1615
+ name: 'Remix',
1616
+ category: 'meta-framework',
1617
+ version: parseVersionString(deps['@remix-run/react'] ?? deps['remix']),
1618
+ confidence: 90,
1619
+ detectedFrom: [{ type: 'package.json', field: 'dependencies.@remix-run/react' }],
1620
+ });
1621
+ }
1622
+ if (confidence === 0) {
1623
+ return null;
1624
+ }
1625
+ return {
1626
+ id: 'react',
1627
+ name: 'React',
1628
+ category: 'frontend',
1629
+ version,
1630
+ confidence: min(confidence, 100),
1631
+ detectedFrom: sources,
1632
+ metaFrameworks: metaFrameworks.length > 0 ? metaFrameworks : undefined,
1633
+ };
1634
+ }
1635
+
1636
+ /**
1637
+ * Detect Next.js in project.
1638
+ *
1639
+ * @param projectPath - Project directory path
1640
+ * @param packageJson - Optional pre-loaded package.json
1641
+ * @returns Detection result or null if not detected
1642
+ */
1643
+ function nextjsDetector(projectPath, packageJson) {
1644
+ const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
1645
+ const sources = [];
1646
+ let confidence = 0;
1647
+ let version;
1648
+ const deps = collectAllDependencies(pkg);
1649
+ if (deps['next']) {
1650
+ confidence += 70;
1651
+ version = parseVersionString(deps['next']);
1652
+ sources.push({ type: 'package.json', field: 'dependencies.next' });
1653
+ }
1654
+ if (exists(node_path.join(projectPath, 'next.config.js')) ||
1655
+ exists(node_path.join(projectPath, 'next.config.mjs')) ||
1656
+ exists(node_path.join(projectPath, 'next.config.ts'))) {
1657
+ confidence += 25;
1658
+ sources.push({ type: 'config-file', path: 'next.config.*' });
1659
+ }
1660
+ if (exists(node_path.join(projectPath, 'pages')) ||
1661
+ exists(node_path.join(projectPath, 'app')) ||
1662
+ exists(node_path.join(projectPath, 'src', 'pages')) ||
1663
+ exists(node_path.join(projectPath, 'src', 'app'))) {
1664
+ confidence += 5;
1665
+ sources.push({ type: 'directory', path: 'pages/ or app/' });
1666
+ }
1667
+ if (confidence === 0) {
1668
+ return null;
1669
+ }
1670
+ return {
1671
+ id: 'nextjs',
1672
+ name: 'Next.js',
1673
+ category: 'meta-framework',
1674
+ version,
1675
+ confidence: min(confidence, 100),
1676
+ detectedFrom: sources,
1677
+ };
1678
+ }
1679
+
1680
+ /**
1681
+ * Detect Remix in project.
1682
+ *
1683
+ * @param projectPath - Project directory path
1684
+ * @param packageJson - Optional pre-loaded package.json
1685
+ * @returns Detection result or null if not detected
1686
+ */
1687
+ function remixDetector(projectPath, packageJson) {
1688
+ const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
1689
+ const sources = [];
1690
+ let confidence = 0;
1691
+ let version;
1692
+ const deps = collectAllDependencies(pkg);
1693
+ // @remix-run packages
1694
+ if (deps['@remix-run/react']) {
1695
+ confidence += 70;
1696
+ version = parseVersionString(deps['@remix-run/react']);
1697
+ sources.push({ type: 'package.json', field: 'dependencies.@remix-run/react' });
1698
+ }
1699
+ if (deps['@remix-run/node'] || deps['@remix-run/cloudflare'] || deps['@remix-run/deno']) {
1700
+ confidence += 20;
1701
+ sources.push({ type: 'package.json', field: 'dependencies.@remix-run/*' });
1702
+ }
1703
+ if (exists(node_path.join(projectPath, 'remix.config.js')) || exists(node_path.join(projectPath, 'remix.config.ts'))) {
1704
+ confidence += 10;
1705
+ sources.push({ type: 'config-file', path: 'remix.config.*' });
1706
+ }
1707
+ if (confidence === 0) {
1708
+ return null;
1709
+ }
1710
+ return {
1711
+ id: 'remix',
1712
+ name: 'Remix',
1713
+ category: 'meta-framework',
1714
+ version,
1715
+ confidence: min(confidence, 100),
1716
+ detectedFrom: sources,
1717
+ };
1718
+ }
1719
+
1720
+ /**
1721
+ * Detect Gatsby in project.
1722
+ *
1723
+ * @param projectPath - Project directory path
1724
+ * @param packageJson - Optional pre-loaded package.json
1725
+ * @returns Detection result or null if not detected
1726
+ */
1727
+ function gatsbyDetector(projectPath, packageJson) {
1728
+ const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
1729
+ const sources = [];
1730
+ let confidence = 0;
1731
+ let version;
1732
+ const deps = collectAllDependencies(pkg);
1733
+ if (deps['gatsby']) {
1734
+ confidence += 70;
1735
+ version = parseVersionString(deps['gatsby']);
1736
+ sources.push({ type: 'package.json', field: 'dependencies.gatsby' });
1737
+ }
1738
+ if (exists(node_path.join(projectPath, 'gatsby-config.js')) || exists(node_path.join(projectPath, 'gatsby-config.ts'))) {
1739
+ confidence += 25;
1740
+ sources.push({ type: 'config-file', path: 'gatsby-config.*' });
1741
+ }
1742
+ const gatsbyPlugins = keys(deps).filter((d) => d.startsWith('gatsby-plugin-') || d.startsWith('gatsby-source-'));
1743
+ if (gatsbyPlugins.length > 0) {
1744
+ confidence += 5;
1745
+ sources.push({ type: 'package.json', field: 'dependencies (gatsby plugins)' });
1746
+ }
1747
+ if (confidence === 0) {
1748
+ return null;
1749
+ }
1750
+ return {
1751
+ id: 'gatsby',
1752
+ name: 'Gatsby',
1753
+ category: 'meta-framework',
1754
+ version,
1755
+ confidence: min(confidence, 100),
1756
+ detectedFrom: sources,
1757
+ };
1758
+ }
1759
+
1760
+ /**
1761
+ * Detect Vue in project.
1762
+ *
1763
+ * @param projectPath - Project directory path
1764
+ * @param packageJson - Optional pre-loaded package.json
1765
+ * @returns Detection result or null if not detected
1766
+ */
1767
+ function vueDetector(projectPath, packageJson) {
1768
+ const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
1769
+ const sources = [];
1770
+ let confidence = 0;
1771
+ let version;
1772
+ const metaFrameworks = [];
1773
+ const deps = collectAllDependencies(pkg);
1774
+ if (deps['vue']) {
1775
+ confidence += 70;
1776
+ version = parseVersionString(deps['vue']);
1777
+ sources.push({ type: 'package.json', field: 'dependencies.vue' });
1778
+ }
1779
+ if (deps['@vue/cli-service']) {
1780
+ confidence += 15;
1781
+ sources.push({ type: 'package.json', field: 'dependencies.@vue/cli-service' });
1782
+ }
1783
+ const hasVueFiles = exists(node_path.join(projectPath, 'src', 'App.vue')) || exists(node_path.join(projectPath, 'src', 'main.vue'));
1784
+ if (hasVueFiles) {
1785
+ confidence += 10;
1786
+ sources.push({ type: 'directory', path: 'src/*.vue' });
1787
+ }
1788
+ if (exists(node_path.join(projectPath, 'vue.config.js'))) {
1789
+ confidence += 5;
1790
+ sources.push({ type: 'config-file', path: 'vue.config.js' });
1791
+ }
1792
+ if (deps['nuxt'] || deps['nuxt3']) {
1793
+ metaFrameworks.push({
1794
+ id: 'nuxt',
1795
+ name: 'Nuxt',
1796
+ category: 'meta-framework',
1797
+ version: parseVersionString(deps['nuxt'] ?? deps['nuxt3']),
1798
+ confidence: 90,
1799
+ detectedFrom: [{ type: 'package.json', field: 'dependencies.nuxt' }],
1800
+ });
1801
+ }
1802
+ if (confidence === 0) {
1803
+ return null;
1804
+ }
1805
+ return {
1806
+ id: 'vue',
1807
+ name: 'Vue',
1808
+ category: 'frontend',
1809
+ version,
1810
+ confidence: min(confidence, 100),
1811
+ detectedFrom: sources,
1812
+ metaFrameworks: metaFrameworks.length > 0 ? metaFrameworks : undefined,
1813
+ };
1814
+ }
1815
+
1816
+ /**
1817
+ * Detect Nuxt in project.
1818
+ *
1819
+ * @param projectPath - Project directory path
1820
+ * @param packageJson - Optional pre-loaded package.json
1821
+ * @returns Detection result or null if not detected
1822
+ */
1823
+ function nuxtDetector(projectPath, packageJson) {
1824
+ const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
1825
+ const sources = [];
1826
+ let confidence = 0;
1827
+ let version;
1828
+ const deps = collectAllDependencies(pkg);
1829
+ if (deps['nuxt'] || deps['nuxt3']) {
1830
+ confidence += 70;
1831
+ version = parseVersionString(deps['nuxt'] ?? deps['nuxt3']);
1832
+ sources.push({ type: 'package.json', field: 'dependencies.nuxt' });
1833
+ }
1834
+ if (exists(node_path.join(projectPath, 'nuxt.config.js')) || exists(node_path.join(projectPath, 'nuxt.config.ts'))) {
1835
+ confidence += 25;
1836
+ sources.push({ type: 'config-file', path: 'nuxt.config.*' });
1837
+ }
1838
+ if (exists(node_path.join(projectPath, 'pages'))) {
1839
+ confidence += 5;
1840
+ sources.push({ type: 'directory', path: 'pages/' });
1841
+ }
1842
+ if (confidence === 0) {
1843
+ return null;
1844
+ }
1845
+ return {
1846
+ id: 'nuxt',
1847
+ name: 'Nuxt',
1848
+ category: 'meta-framework',
1849
+ version,
1850
+ confidence: min(confidence, 100),
1851
+ detectedFrom: sources,
1852
+ };
1853
+ }
1854
+
1855
+ /**
1856
+ * Detect Angular in project.
1857
+ *
1858
+ * @param projectPath - Project directory path
1859
+ * @param packageJson - Optional pre-loaded package.json
1860
+ * @returns Detection result or null if not detected
1861
+ */
1862
+ function angularDetector(projectPath, packageJson) {
1863
+ const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
1864
+ const sources = [];
1865
+ let confidence = 0;
1866
+ let version;
1867
+ const deps = collectAllDependencies(pkg);
1868
+ if (deps['@angular/core']) {
1869
+ confidence += 70;
1870
+ version = parseVersionString(deps['@angular/core']);
1871
+ sources.push({ type: 'package.json', field: 'dependencies.@angular/core' });
1872
+ }
1873
+ if (deps['@angular/cli']) {
1874
+ confidence += 15;
1875
+ sources.push({ type: 'package.json', field: 'dependencies.@angular/cli' });
1876
+ }
1877
+ if (exists(node_path.join(projectPath, 'angular.json'))) {
1878
+ confidence += 15;
1879
+ sources.push({ type: 'config-file', path: 'angular.json' });
1880
+ }
1881
+ if (deps['angular'] && !deps['@angular/core']) {
1882
+ return {
1883
+ id: 'angularjs',
1884
+ name: 'AngularJS (Legacy)',
1885
+ category: 'frontend',
1886
+ version: parseVersionString(deps['angular']),
1887
+ confidence: 80,
1888
+ detectedFrom: [{ type: 'package.json', field: 'dependencies.angular' }],
1889
+ };
1890
+ }
1891
+ if (confidence === 0) {
1892
+ return null;
1893
+ }
1894
+ return {
1895
+ id: 'angular',
1896
+ name: 'Angular',
1897
+ category: 'frontend',
1898
+ version,
1899
+ confidence: min(confidence, 100),
1900
+ detectedFrom: sources,
1901
+ };
1902
+ }
1903
+
1904
+ /**
1905
+ * Detect Svelte in project.
1906
+ *
1907
+ * @param projectPath - Project directory path
1908
+ * @param packageJson - Optional pre-loaded package.json
1909
+ * @returns Detection result or null if not detected
1910
+ */
1911
+ function svelteDetector(projectPath, packageJson) {
1912
+ const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
1913
+ const sources = [];
1914
+ let confidence = 0;
1915
+ let version;
1916
+ const metaFrameworks = [];
1917
+ const deps = collectAllDependencies(pkg);
1918
+ if (deps['svelte']) {
1919
+ confidence += 70;
1920
+ version = parseVersionString(deps['svelte']);
1921
+ sources.push({ type: 'package.json', field: 'dependencies.svelte' });
1922
+ }
1923
+ if (exists(node_path.join(projectPath, 'svelte.config.js'))) {
1924
+ confidence += 20;
1925
+ sources.push({ type: 'config-file', path: 'svelte.config.js' });
1926
+ }
1927
+ const hasSvelteFiles = exists(node_path.join(projectPath, 'src', 'App.svelte')) || exists(node_path.join(projectPath, 'src', 'routes'));
1928
+ if (hasSvelteFiles) {
1929
+ confidence += 10;
1930
+ sources.push({ type: 'directory', path: 'src/*.svelte or src/routes/' });
1931
+ }
1932
+ if (deps['@sveltejs/kit']) {
1933
+ metaFrameworks.push({
1934
+ id: 'sveltekit',
1935
+ name: 'SvelteKit',
1936
+ category: 'meta-framework',
1937
+ version: parseVersionString(deps['@sveltejs/kit']),
1938
+ confidence: 90,
1939
+ detectedFrom: [{ type: 'package.json', field: 'dependencies.@sveltejs/kit' }],
1940
+ });
1941
+ }
1942
+ if (confidence === 0) {
1943
+ return null;
1944
+ }
1945
+ return {
1946
+ id: 'svelte',
1947
+ name: 'Svelte',
1948
+ category: 'frontend',
1949
+ version,
1950
+ confidence: min(confidence, 100),
1951
+ detectedFrom: sources,
1952
+ metaFrameworks: metaFrameworks.length > 0 ? metaFrameworks : undefined,
1953
+ };
1954
+ }
1955
+
1956
+ /**
1957
+ * Detect SvelteKit in project.
1958
+ *
1959
+ * @param projectPath - Project directory path
1960
+ * @param packageJson - Optional pre-loaded package.json
1961
+ * @returns Detection result or null if not detected
1962
+ */
1963
+ function sveltekitDetector(projectPath, packageJson) {
1964
+ const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
1965
+ const sources = [];
1966
+ let confidence = 0;
1967
+ let version;
1968
+ const deps = collectAllDependencies(pkg);
1969
+ // @sveltejs/kit package
1970
+ if (deps['@sveltejs/kit']) {
1971
+ confidence += 70;
1972
+ version = parseVersionString(deps['@sveltejs/kit']);
1973
+ sources.push({ type: 'package.json', field: 'dependencies.@sveltejs/kit' });
1974
+ }
1975
+ if (exists(node_path.join(projectPath, 'svelte.config.js'))) {
1976
+ confidence += 20;
1977
+ sources.push({ type: 'config-file', path: 'svelte.config.js' });
1978
+ }
1979
+ if (exists(node_path.join(projectPath, 'src', 'routes'))) {
1980
+ confidence += 10;
1981
+ sources.push({ type: 'directory', path: 'src/routes/' });
1982
+ }
1983
+ if (confidence === 0) {
1984
+ return null;
1985
+ }
1986
+ return {
1987
+ id: 'sveltekit',
1988
+ name: 'SvelteKit',
1989
+ category: 'meta-framework',
1990
+ version,
1991
+ confidence: min(confidence, 100),
1992
+ detectedFrom: sources,
1993
+ };
1994
+ }
1995
+
1996
+ /**
1997
+ * Detect Solid in project.
1998
+ *
1999
+ * @param projectPath - Project directory path
2000
+ * @param packageJson - Optional pre-loaded package.json
2001
+ * @returns Detection result or null if not detected
2002
+ */
2003
+ function solidDetector(projectPath, packageJson) {
2004
+ const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
2005
+ const sources = [];
2006
+ let confidence = 0;
2007
+ let version;
2008
+ const deps = collectAllDependencies(pkg);
2009
+ if (deps['solid-js']) {
2010
+ confidence += 70;
2011
+ version = parseVersionString(deps['solid-js']);
2012
+ sources.push({ type: 'package.json', field: 'dependencies.solid-js' });
2013
+ }
2014
+ if (deps['vite-plugin-solid']) {
2015
+ confidence += 20;
2016
+ sources.push({ type: 'package.json', field: 'dependencies.vite-plugin-solid' });
2017
+ }
2018
+ if (deps['solid-start'] || deps['@solidjs/start']) {
2019
+ confidence += 10;
2020
+ sources.push({ type: 'package.json', field: 'dependencies.solid-start' });
2021
+ }
2022
+ if (confidence === 0) {
2023
+ return null;
2024
+ }
2025
+ return {
2026
+ id: 'solid',
2027
+ name: 'Solid',
2028
+ category: 'frontend',
2029
+ version,
2030
+ confidence: min(confidence, 100),
2031
+ detectedFrom: sources,
2032
+ };
2033
+ }
2034
+
2035
+ /**
2036
+ * Detect Qwik in project.
2037
+ *
2038
+ * @param projectPath - Project directory path
2039
+ * @param packageJson - Optional pre-loaded package.json
2040
+ * @returns Detection result or null if not detected
2041
+ */
2042
+ function qwikDetector(projectPath, packageJson) {
2043
+ const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
2044
+ const sources = [];
2045
+ let confidence = 0;
2046
+ let version;
2047
+ const deps = collectAllDependencies(pkg);
2048
+ // @builder.io/qwik package
2049
+ if (deps['@builder.io/qwik']) {
2050
+ confidence += 70;
2051
+ version = parseVersionString(deps['@builder.io/qwik']);
2052
+ sources.push({ type: 'package.json', field: 'dependencies.@builder.io/qwik' });
2053
+ }
2054
+ // @builder.io/qwik-city
2055
+ if (deps['@builder.io/qwik-city']) {
2056
+ confidence += 20;
2057
+ sources.push({ type: 'package.json', field: 'dependencies.@builder.io/qwik-city' });
2058
+ }
2059
+ if (exists(node_path.join(projectPath, 'qwik.config.ts')) || exists(node_path.join(projectPath, 'qwik.config.js'))) {
2060
+ confidence += 10;
2061
+ sources.push({ type: 'config-file', path: 'qwik.config.*' });
2062
+ }
2063
+ if (confidence === 0) {
2064
+ return null;
2065
+ }
2066
+ return {
2067
+ id: 'qwik',
2068
+ name: 'Qwik',
2069
+ category: 'frontend',
2070
+ version,
2071
+ confidence: min(confidence, 100),
2072
+ detectedFrom: sources,
2073
+ };
2074
+ }
2075
+
2076
+ /**
2077
+ * Detect Astro in project.
2078
+ *
2079
+ * @param projectPath - Project directory path
2080
+ * @param packageJson - Optional pre-loaded package.json
2081
+ * @returns Detection result or null if not detected
2082
+ */
2083
+ function astroDetector(projectPath, packageJson) {
2084
+ const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
2085
+ const sources = [];
2086
+ let confidence = 0;
2087
+ let version;
2088
+ const deps = collectAllDependencies(pkg);
2089
+ if (deps['astro']) {
2090
+ confidence += 70;
2091
+ version = parseVersionString(deps['astro']);
2092
+ sources.push({ type: 'package.json', field: 'dependencies.astro' });
2093
+ }
2094
+ if (exists(node_path.join(projectPath, 'astro.config.mjs')) ||
2095
+ exists(node_path.join(projectPath, 'astro.config.ts')) ||
2096
+ exists(node_path.join(projectPath, 'astro.config.js'))) {
2097
+ confidence += 25;
2098
+ sources.push({ type: 'config-file', path: 'astro.config.*' });
2099
+ }
2100
+ if (exists(node_path.join(projectPath, 'src', 'pages'))) {
2101
+ confidence += 5;
2102
+ sources.push({ type: 'directory', path: 'src/pages/' });
2103
+ }
2104
+ if (confidence === 0) {
2105
+ return null;
2106
+ }
2107
+ return {
2108
+ id: 'astro',
2109
+ name: 'Astro',
2110
+ category: 'meta-framework',
2111
+ version,
2112
+ confidence: min(confidence, 100),
2113
+ detectedFrom: sources,
2114
+ };
2115
+ }
2116
+
2117
+ /** All frontend framework detectors */
2118
+ const frameworkDetectors = [
2119
+ { id: 'react', name: 'React', category: 'frontend', detect: reactDetector },
2120
+ { id: 'nextjs', name: 'Next.js', category: 'meta-framework', detect: nextjsDetector },
2121
+ { id: 'remix', name: 'Remix', category: 'meta-framework', detect: remixDetector },
2122
+ { id: 'gatsby', name: 'Gatsby', category: 'meta-framework', detect: gatsbyDetector },
2123
+ { id: 'vue', name: 'Vue', category: 'frontend', detect: vueDetector },
2124
+ { id: 'nuxt', name: 'Nuxt', category: 'meta-framework', detect: nuxtDetector },
2125
+ { id: 'angular', name: 'Angular', category: 'frontend', detect: angularDetector },
2126
+ { id: 'svelte', name: 'Svelte', category: 'frontend', detect: svelteDetector },
2127
+ { id: 'sveltekit', name: 'SvelteKit', category: 'meta-framework', detect: sveltekitDetector },
2128
+ { id: 'solid', name: 'Solid', category: 'frontend', detect: solidDetector },
2129
+ { id: 'qwik', name: 'Qwik', category: 'frontend', detect: qwikDetector },
2130
+ { id: 'astro', name: 'Astro', category: 'meta-framework', detect: astroDetector },
2131
+ ];
2132
+
2133
+ /**
2134
+ * Detect AngularJS (1.x) in project.
2135
+ * AngularJS is the original Angular framework, distinct from Angular 2+.
2136
+ *
2137
+ * @param projectPath - Project directory path
2138
+ * @param packageJson - Optional pre-loaded package.json
2139
+ * @returns Detection result or null if not detected
2140
+ */
2141
+ function angularJSDetector(projectPath, packageJson) {
2142
+ const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
2143
+ const sources = [];
2144
+ let confidence = 0;
2145
+ let version;
2146
+ const deps = collectAllDependencies(pkg);
2147
+ // AngularJS package (angular, not @angular/core)
2148
+ if (deps['angular']) {
2149
+ confidence += 70;
2150
+ version = parseVersionString(deps['angular']);
2151
+ sources.push({ type: 'package.json', field: 'dependencies.angular' });
2152
+ }
2153
+ // AngularJS router
2154
+ if (deps['angular-route']) {
2155
+ confidence += 15;
2156
+ sources.push({ type: 'package.json', field: 'dependencies.angular-route' });
2157
+ }
2158
+ // AngularJS resource
2159
+ if (deps['angular-resource']) {
2160
+ confidence += 10;
2161
+ sources.push({ type: 'package.json', field: 'dependencies.angular-resource' });
2162
+ }
2163
+ // AngularJS animate
2164
+ if (deps['angular-animate']) {
2165
+ confidence += 5;
2166
+ sources.push({ type: 'package.json', field: 'dependencies.angular-animate' });
2167
+ }
2168
+ if (confidence === 0) {
2169
+ return null;
2170
+ }
2171
+ return {
2172
+ id: 'angularjs',
2173
+ name: 'AngularJS',
2174
+ category: 'legacy-frontend',
2175
+ version,
2176
+ confidence: min(confidence, 100),
2177
+ detectedFrom: sources,
2178
+ };
2179
+ }
2180
+
2181
+ /**
2182
+ * Detect Backbone.js in project.
2183
+ *
2184
+ * @param projectPath - Project directory path
2185
+ * @param packageJson - Optional pre-loaded package.json
2186
+ * @returns Detection result or null if not detected
2187
+ */
2188
+ function backboneDetector(projectPath, packageJson) {
2189
+ const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
2190
+ const sources = [];
2191
+ let confidence = 0;
2192
+ let version;
2193
+ const deps = collectAllDependencies(pkg);
2194
+ // Backbone package
2195
+ if (deps['backbone']) {
2196
+ confidence += 70;
2197
+ version = parseVersionString(deps['backbone']);
2198
+ sources.push({ type: 'package.json', field: 'dependencies.backbone' });
2199
+ // Underscore (commonly used with Backbone)
2200
+ if (deps['underscore']) {
2201
+ confidence += 15;
2202
+ sources.push({ type: 'package.json', field: 'dependencies.underscore' });
2203
+ }
2204
+ // Lodash can be used as underscore replacement
2205
+ if (deps['lodash']) {
2206
+ confidence += 5;
2207
+ sources.push({ type: 'package.json', field: 'dependencies.lodash' });
2208
+ }
2209
+ }
2210
+ // Marionette (Backbone framework)
2211
+ if (deps['backbone.marionette'] || deps['marionette']) {
2212
+ confidence += 10;
2213
+ sources.push({ type: 'package.json', field: 'dependencies.backbone.marionette' });
2214
+ }
2215
+ if (confidence === 0) {
2216
+ return null;
2217
+ }
2218
+ return {
2219
+ id: 'backbone',
2220
+ name: 'Backbone.js',
2221
+ category: 'legacy-frontend',
2222
+ version,
2223
+ confidence: min(confidence, 100),
2224
+ detectedFrom: sources,
2225
+ };
2226
+ }
2227
+
2228
+ /**
2229
+ * Detect Ember.js in project.
2230
+ *
2231
+ * @param projectPath - Project directory path
2232
+ * @param packageJson - Optional pre-loaded package.json
2233
+ * @returns Detection result or null if not detected
2234
+ */
2235
+ function emberDetector(projectPath, packageJson) {
2236
+ const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
2237
+ const sources = [];
2238
+ let confidence = 0;
2239
+ let version;
2240
+ const deps = collectAllDependencies(pkg);
2241
+ // Ember source package
2242
+ if (deps['ember-source']) {
2243
+ confidence += 70;
2244
+ version = parseVersionString(deps['ember-source']);
2245
+ sources.push({ type: 'package.json', field: 'dependencies.ember-source' });
2246
+ }
2247
+ // Ember CLI
2248
+ if (deps['ember-cli']) {
2249
+ confidence += 20;
2250
+ sources.push({ type: 'package.json', field: 'devDependencies.ember-cli' });
2251
+ }
2252
+ // Ember Data
2253
+ if (deps['ember-data']) {
2254
+ confidence += 10;
2255
+ sources.push({ type: 'package.json', field: 'dependencies.ember-data' });
2256
+ }
2257
+ if (confidence === 0) {
2258
+ return null;
2259
+ }
2260
+ return {
2261
+ id: 'ember',
2262
+ name: 'Ember.js',
2263
+ category: 'legacy-frontend',
2264
+ version,
2265
+ confidence: min(confidence, 100),
2266
+ detectedFrom: sources,
2267
+ };
2268
+ }
2269
+
2270
+ /**
2271
+ * Detect jQuery in project.
2272
+ *
2273
+ * @param projectPath - Project directory path
2274
+ * @param packageJson - Optional pre-loaded package.json
2275
+ * @returns Detection result or null if not detected
2276
+ */
2277
+ function jqueryDetector(projectPath, packageJson) {
2278
+ const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
2279
+ const sources = [];
2280
+ let confidence = 0;
2281
+ let version;
2282
+ const deps = collectAllDependencies(pkg);
2283
+ // jQuery package
2284
+ if (deps['jquery']) {
2285
+ confidence += 80;
2286
+ version = parseVersionString(deps['jquery']);
2287
+ sources.push({ type: 'package.json', field: 'dependencies.jquery' });
2288
+ }
2289
+ // jQuery UI
2290
+ if (deps['jquery-ui']) {
2291
+ confidence += 10;
2292
+ sources.push({ type: 'package.json', field: 'dependencies.jquery-ui' });
2293
+ }
2294
+ // jQuery plugins
2295
+ if (deps['jquery-validation']) {
2296
+ confidence += 5;
2297
+ sources.push({ type: 'package.json', field: 'dependencies.jquery-validation' });
2298
+ }
2299
+ if (confidence === 0) {
2300
+ return null;
2301
+ }
2302
+ return {
2303
+ id: 'jquery',
2304
+ name: 'jQuery',
2305
+ category: 'legacy-frontend',
2306
+ version,
2307
+ confidence: min(confidence, 100),
2308
+ detectedFrom: sources,
2309
+ };
2310
+ }
2311
+
2312
+ /** All legacy framework detectors */
2313
+ const legacyDetectors = [
2314
+ { id: 'angularjs', name: 'AngularJS', category: 'legacy-frontend', detect: angularJSDetector },
2315
+ { id: 'backbone', name: 'Backbone.js', category: 'legacy-frontend', detect: backboneDetector },
2316
+ { id: 'ember', name: 'Ember.js', category: 'legacy-frontend', detect: emberDetector },
2317
+ { id: 'jquery', name: 'jQuery', category: 'legacy-frontend', detect: jqueryDetector },
2318
+ ];
2319
+
2320
+ /** Config patterns for ESLint */
2321
+ const ESLINT_CONFIG_PATTERNS = [
2322
+ 'eslint.config.js',
2323
+ 'eslint.config.mjs',
2324
+ 'eslint.config.cjs',
2325
+ 'eslint.config.ts',
2326
+ '.eslintrc.js',
2327
+ '.eslintrc.cjs',
2328
+ '.eslintrc.json',
2329
+ '.eslintrc.yaml',
2330
+ '.eslintrc.yml',
2331
+ '.eslintrc',
2332
+ ];
2333
+ /**
2334
+ * Detect ESLint in project.
2335
+ *
2336
+ * @param projectPath - Project directory path
2337
+ * @param packageJson - Optional pre-loaded package.json
2338
+ * @returns Detection result or null if not detected
2339
+ */
2340
+ function eslintDetector(projectPath, packageJson) {
2341
+ const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
2342
+ const sources = [];
2343
+ let confidence = 0;
2344
+ let version;
2345
+ const deps = collectAllDependencies(pkg);
2346
+ if (deps['eslint']) {
2347
+ confidence += 50;
2348
+ version = parseVersionString(deps['eslint']);
2349
+ sources.push({ type: 'package.json', field: 'dependencies.eslint' });
2350
+ }
2351
+ const configPath = locateConfigFile(projectPath, ESLINT_CONFIG_PATTERNS);
2352
+ if (configPath) {
2353
+ confidence += 40;
2354
+ sources.push({ type: 'config-file', path: configPath });
2355
+ }
2356
+ if (pkg && 'eslintConfig' in pkg) {
2357
+ confidence += 30;
2358
+ sources.push({ type: 'package.json', field: 'eslintConfig' });
2359
+ }
2360
+ const eslintPlugins = keys(deps).filter((d) => d.startsWith('eslint-plugin-') || d.startsWith('@typescript-eslint/') || d.startsWith('eslint-config-'));
2361
+ if (eslintPlugins.length > 0) {
2362
+ confidence += 10;
2363
+ sources.push({ type: 'package.json', field: 'dependencies (eslint plugins)' });
2364
+ }
2365
+ const lintScript = pkg?.scripts?.['lint'] ?? '';
2366
+ if (lintScript.includes('eslint')) {
2367
+ confidence += 5;
2368
+ sources.push({ type: 'package.json', field: 'scripts.lint' });
2369
+ }
2370
+ if (confidence === 0) {
2371
+ return null;
2372
+ }
2373
+ return {
2374
+ id: 'eslint',
2375
+ name: 'ESLint',
2376
+ version,
2377
+ configPath,
2378
+ confidence: min(confidence, 100),
2379
+ detectedFrom: sources,
2380
+ };
2381
+ }
2382
+
2383
+ /** Config patterns for Prettier */
2384
+ const PRETTIER_CONFIG_PATTERNS = [
2385
+ 'prettier.config.js',
2386
+ 'prettier.config.mjs',
2387
+ 'prettier.config.cjs',
2388
+ '.prettierrc',
2389
+ '.prettierrc.json',
2390
+ '.prettierrc.yaml',
2391
+ '.prettierrc.yml',
2392
+ '.prettierrc.js',
2393
+ '.prettierrc.cjs',
2394
+ '.prettierrc.toml',
2395
+ ];
2396
+ /**
2397
+ * Detect Prettier in project.
2398
+ *
2399
+ * @param projectPath - Project directory path
2400
+ * @param packageJson - Optional pre-loaded package.json
2401
+ * @returns Detection result or null if not detected
2402
+ */
2403
+ function prettierDetector(projectPath, packageJson) {
2404
+ const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
2405
+ const sources = [];
2406
+ let confidence = 0;
2407
+ let version;
2408
+ const deps = collectAllDependencies(pkg);
2409
+ if (deps['prettier']) {
2410
+ confidence += 50;
2411
+ version = parseVersionString(deps['prettier']);
2412
+ sources.push({ type: 'package.json', field: 'dependencies.prettier' });
2413
+ }
2414
+ const configPath = locateConfigFile(projectPath, PRETTIER_CONFIG_PATTERNS);
2415
+ if (configPath) {
2416
+ confidence += 40;
2417
+ sources.push({ type: 'config-file', path: configPath });
2418
+ }
2419
+ if (pkg && 'prettier' in pkg) {
2420
+ confidence += 30;
2421
+ sources.push({ type: 'package.json', field: 'prettier' });
2422
+ }
2423
+ // .prettierignore file
2424
+ if (exists(node_path.join(projectPath, '.prettierignore'))) {
2425
+ confidence += 10;
2426
+ sources.push({ type: 'config-file', path: '.prettierignore' });
2427
+ }
2428
+ const prettierPlugins = keys(deps).filter((d) => d.startsWith('prettier-plugin-'));
2429
+ if (prettierPlugins.length > 0) {
2430
+ confidence += 5;
2431
+ sources.push({ type: 'package.json', field: 'dependencies (prettier plugins)' });
2432
+ }
2433
+ const formatScript = pkg?.scripts?.['format'] ?? pkg?.scripts?.['prettier'] ?? '';
2434
+ if (formatScript.includes('prettier')) {
2435
+ confidence += 5;
2436
+ sources.push({ type: 'package.json', field: 'scripts.format' });
2437
+ }
2438
+ if (confidence === 0) {
2439
+ return null;
2440
+ }
2441
+ return {
2442
+ id: 'prettier',
2443
+ name: 'Prettier',
2444
+ version,
2445
+ configPath,
2446
+ confidence: min(confidence, 100),
2447
+ detectedFrom: sources,
2448
+ };
2449
+ }
2450
+
2451
+ /** Config patterns for Stylelint */
2452
+ const STYLELINT_CONFIG_PATTERNS = [
2453
+ '.stylelintrc',
2454
+ '.stylelintrc.json',
2455
+ '.stylelintrc.js',
2456
+ 'stylelint.config.js',
2457
+ 'stylelint.config.cjs',
2458
+ ];
2459
+ /**
2460
+ * Detect Stylelint in project.
2461
+ *
2462
+ * @param projectPath - Project directory path
2463
+ * @param packageJson - Optional pre-loaded package.json
2464
+ * @returns Detection result or null if not detected
2465
+ */
2466
+ function stylelintDetector(projectPath, packageJson) {
2467
+ const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
2468
+ const sources = [];
2469
+ let confidence = 0;
2470
+ let configPath;
2471
+ let version;
2472
+ const deps = collectAllDependencies(pkg);
2473
+ if (deps['stylelint']) {
2474
+ confidence += 60;
2475
+ version = parseVersionString(deps['stylelint']);
2476
+ sources.push({ type: 'package.json', field: 'dependencies.stylelint' });
2477
+ }
2478
+ for (const config of STYLELINT_CONFIG_PATTERNS) {
2479
+ if (exists(node_path.join(projectPath, config))) {
2480
+ confidence += 35;
2481
+ configPath = config;
2482
+ sources.push({ type: 'config-file', path: config });
2483
+ break;
2484
+ }
2485
+ }
2486
+ const stylelintPlugins = keys(deps).filter((d) => d.startsWith('stylelint-'));
2487
+ if (stylelintPlugins.length > 0) {
2488
+ confidence += 5;
2489
+ sources.push({ type: 'package.json', field: 'dependencies (stylelint plugins)' });
2490
+ }
2491
+ if (confidence === 0) {
2492
+ return null;
2493
+ }
2494
+ return {
2495
+ id: 'stylelint',
2496
+ name: 'Stylelint',
2497
+ version,
2498
+ configPath,
2499
+ confidence: min(confidence, 100),
2500
+ detectedFrom: sources,
2501
+ };
2502
+ }
2503
+
2504
+ /**
2505
+ * Detect Biome in project.
2506
+ *
2507
+ * @param projectPath - Project directory path
2508
+ * @param packageJson - Optional pre-loaded package.json
2509
+ * @returns Detection result or null if not detected
2510
+ */
2511
+ function biomeDetector(projectPath, packageJson) {
2512
+ const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
2513
+ const sources = [];
2514
+ let confidence = 0;
2515
+ let configPath;
2516
+ let version;
2517
+ const deps = collectAllDependencies(pkg);
2518
+ // @biomejs/biome package
2519
+ if (deps['@biomejs/biome']) {
2520
+ confidence += 70;
2521
+ version = parseVersionString(deps['@biomejs/biome']);
2522
+ sources.push({ type: 'package.json', field: 'dependencies.@biomejs/biome' });
2523
+ }
2524
+ if (exists(node_path.join(projectPath, 'biome.json'))) {
2525
+ confidence += 30;
2526
+ configPath = 'biome.json';
2527
+ sources.push({ type: 'config-file', path: 'biome.json' });
2528
+ }
2529
+ if (!configPath && exists(node_path.join(projectPath, 'biome.jsonc'))) {
2530
+ confidence += 30;
2531
+ configPath = 'biome.jsonc';
2532
+ sources.push({ type: 'config-file', path: 'biome.jsonc' });
2533
+ }
2534
+ if (confidence === 0) {
2535
+ return null;
2536
+ }
2537
+ return {
2538
+ id: 'biome',
2539
+ name: 'Biome',
2540
+ version,
2541
+ configPath,
2542
+ confidence: min(confidence, 100),
2543
+ detectedFrom: sources,
2544
+ };
2545
+ }
2546
+
2547
+ /** All linting tool detectors */
2548
+ const lintingDetectors = [
2549
+ { id: 'eslint', name: 'ESLint', detect: eslintDetector },
2550
+ { id: 'prettier', name: 'Prettier', detect: prettierDetector },
2551
+ { id: 'stylelint', name: 'Stylelint', detect: stylelintDetector },
2552
+ { id: 'biome', name: 'Biome', detect: biomeDetector },
2553
+ ];
2554
+
2555
+ /**
2556
+ * Detect NX in project.
2557
+ *
2558
+ * @param workspacePath - Workspace directory path
2559
+ * @param packageJson - Optional pre-loaded package.json
2560
+ * @returns Detection result or null if not detected
2561
+ */
2562
+ function nxDetector(workspacePath, packageJson) {
2563
+ const pkg = packageJson ?? readPackageJsonIfExists(workspacePath);
2564
+ const sources = [];
2565
+ let confidence = 0;
2566
+ let version;
2567
+ let workspaceLayout;
2568
+ const nxJsonPath = node_path.join(workspacePath, 'nx.json');
2569
+ if (exists(nxJsonPath)) {
2570
+ confidence += 70;
2571
+ sources.push({ type: 'config-file', path: 'nx.json' });
2572
+ }
2573
+ const deps = collectAllDependencies(pkg);
2574
+ if (deps['nx']) {
2575
+ confidence += 20;
2576
+ version = parseVersionString(deps['nx']);
2577
+ sources.push({ type: 'package.json', field: 'dependencies.nx' });
2578
+ }
2579
+ const hasApps = exists(node_path.join(workspacePath, 'apps'));
2580
+ const hasLibs = exists(node_path.join(workspacePath, 'libs'));
2581
+ if (hasApps || hasLibs) {
2582
+ confidence += 10;
2583
+ sources.push({ type: 'directory', path: 'apps/ or libs/' });
2584
+ workspaceLayout = {
2585
+ appsDir: hasApps ? 'apps' : '',
2586
+ libsDir: hasLibs ? 'libs' : '',
2587
+ };
2588
+ }
2589
+ const nxPackages = keys(deps).filter((d) => d.startsWith('@nx/') || d.startsWith('@nrwl/'));
2590
+ if (nxPackages.length > 0) {
2591
+ confidence += 10;
2592
+ sources.push({ type: 'package.json', field: '@nx/* packages' });
2593
+ }
2594
+ if (confidence === 0) {
2595
+ return null;
2596
+ }
2597
+ return {
2598
+ id: 'nx',
2599
+ name: 'NX',
2600
+ version,
2601
+ configPath: exists(nxJsonPath) ? 'nx.json' : undefined,
2602
+ confidence: min(confidence, 100),
2603
+ detectedFrom: sources,
2604
+ workspaceLayout,
2605
+ };
2606
+ }
2607
+
2608
+ /**
2609
+ * Detect Turborepo in project.
2610
+ *
2611
+ * @param workspacePath - Workspace directory path
2612
+ * @param packageJson - Optional pre-loaded package.json
2613
+ * @returns Detection result or null if not detected
2614
+ */
2615
+ function turborepoDetector(workspacePath, packageJson) {
2616
+ const pkg = packageJson ?? readPackageJsonIfExists(workspacePath);
2617
+ const sources = [];
2618
+ let confidence = 0;
2619
+ let version;
2620
+ let configPath;
2621
+ const turboJsonPath = node_path.join(workspacePath, 'turbo.json');
2622
+ if (exists(turboJsonPath)) {
2623
+ confidence += 80;
2624
+ configPath = 'turbo.json';
2625
+ sources.push({ type: 'config-file', path: 'turbo.json' });
2626
+ }
2627
+ const deps = collectAllDependencies(pkg);
2628
+ if (deps['turbo']) {
2629
+ confidence += 15;
2630
+ version = parseVersionString(deps['turbo']);
2631
+ sources.push({ type: 'package.json', field: 'dependencies.turbo' });
2632
+ }
2633
+ const scripts = pkg?.scripts ?? {};
2634
+ if (values(scripts).some((s) => s?.includes('turbo'))) {
2635
+ confidence += 5;
2636
+ sources.push({ type: 'package.json', field: 'scripts (turbo commands)' });
2637
+ }
2638
+ if (confidence === 0) {
2639
+ return null;
2640
+ }
2641
+ return {
2642
+ id: 'turborepo',
2643
+ name: 'Turborepo',
2644
+ version,
2645
+ configPath,
2646
+ confidence: min(confidence, 100),
2647
+ detectedFrom: sources,
2648
+ };
2649
+ }
2650
+
2651
+ /**
2652
+ * Detect Lerna in project.
2653
+ *
2654
+ * @param workspacePath - Workspace directory path
2655
+ * @param packageJson - Optional pre-loaded package.json
2656
+ * @returns Detection result or null if not detected
2657
+ */
2658
+ function lernaDetector(workspacePath, packageJson) {
2659
+ const pkg = packageJson ?? readPackageJsonIfExists(workspacePath);
2660
+ const sources = [];
2661
+ let confidence = 0;
2662
+ let version;
2663
+ let configPath;
2664
+ const lernaJsonPath = node_path.join(workspacePath, 'lerna.json');
2665
+ if (exists(lernaJsonPath)) {
2666
+ confidence += 80;
2667
+ configPath = 'lerna.json';
2668
+ sources.push({ type: 'config-file', path: 'lerna.json' });
2669
+ }
2670
+ const deps = collectAllDependencies(pkg);
2671
+ if (deps['lerna']) {
2672
+ confidence += 15;
2673
+ version = parseVersionString(deps['lerna']);
2674
+ sources.push({ type: 'package.json', field: 'dependencies.lerna' });
2675
+ }
2676
+ if (exists(node_path.join(workspacePath, 'packages'))) {
2677
+ confidence += 5;
2678
+ sources.push({ type: 'directory', path: 'packages/' });
2679
+ }
2680
+ if (confidence === 0) {
2681
+ return null;
2682
+ }
2683
+ return {
2684
+ id: 'lerna',
2685
+ name: 'Lerna',
2686
+ version,
2687
+ configPath,
2688
+ confidence: min(confidence, 100),
2689
+ detectedFrom: sources,
2690
+ };
2691
+ }
2692
+
2693
+ /**
2694
+ * Detect Rush in project.
2695
+ *
2696
+ * @param workspacePath - Workspace directory path
2697
+ * @param packageJson - Optional pre-loaded package.json
2698
+ * @returns Detection result or null if not detected
2699
+ */
2700
+ function rushDetector(workspacePath, packageJson) {
2701
+ const pkg = packageJson ?? readPackageJsonIfExists(workspacePath);
2702
+ const sources = [];
2703
+ let confidence = 0;
2704
+ let version;
2705
+ let configPath;
2706
+ const rushJsonPath = node_path.join(workspacePath, 'rush.json');
2707
+ if (exists(rushJsonPath)) {
2708
+ confidence += 90;
2709
+ configPath = 'rush.json';
2710
+ sources.push({ type: 'config-file', path: 'rush.json' });
2711
+ }
2712
+ const deps = collectAllDependencies(pkg);
2713
+ if (deps['@microsoft/rush']) {
2714
+ confidence += 10;
2715
+ version = parseVersionString(deps['@microsoft/rush']);
2716
+ sources.push({ type: 'package.json', field: 'dependencies.@microsoft/rush' });
2717
+ }
2718
+ if (exists(node_path.join(workspacePath, 'common', 'config', 'rush'))) {
2719
+ confidence += 5;
2720
+ sources.push({ type: 'directory', path: 'common/config/rush/' });
2721
+ }
2722
+ if (confidence === 0) {
2723
+ return null;
2724
+ }
2725
+ return {
2726
+ id: 'rush',
2727
+ name: 'Rush',
2728
+ version,
2729
+ configPath,
2730
+ confidence: min(confidence, 100),
2731
+ detectedFrom: sources,
2732
+ };
2733
+ }
2734
+
2735
+ /**
2736
+ * Detect pnpm workspaces in project.
2737
+ *
2738
+ * @param workspacePath - Workspace directory path
2739
+ * @returns Detection result or null if not detected
2740
+ */
2741
+ function pnpmWorkspacesDetector(workspacePath) {
2742
+ const sources = [];
2743
+ let confidence = 0;
2744
+ let configPath;
2745
+ const pnpmWorkspacePath = node_path.join(workspacePath, 'pnpm-workspace.yaml');
2746
+ if (exists(pnpmWorkspacePath)) {
2747
+ confidence += 90;
2748
+ configPath = 'pnpm-workspace.yaml';
2749
+ sources.push({ type: 'config-file', path: 'pnpm-workspace.yaml' });
2750
+ }
2751
+ if (exists(node_path.join(workspacePath, 'pnpm-lock.yaml'))) {
2752
+ confidence += 10;
2753
+ sources.push({ type: 'lockfile', path: 'pnpm-lock.yaml' });
2754
+ }
2755
+ if (confidence === 0) {
2756
+ return null;
2757
+ }
2758
+ return {
2759
+ id: 'pnpm-workspaces',
2760
+ name: 'pnpm Workspaces',
2761
+ configPath,
2762
+ confidence: min(confidence, 100),
2763
+ detectedFrom: sources,
2764
+ };
2765
+ }
2766
+
2767
+ /**
2768
+ * Detect npm workspaces in project.
2769
+ *
2770
+ * @param workspacePath - Workspace directory path
2771
+ * @param packageJson - Optional pre-loaded package.json
2772
+ * @returns Detection result or null if not detected
2773
+ */
2774
+ function npmWorkspacesDetector(workspacePath, packageJson) {
2775
+ const pkg = packageJson ?? readPackageJsonIfExists(workspacePath);
2776
+ const sources = [];
2777
+ let confidence = 0;
2778
+ if (pkg?.workspaces) {
2779
+ confidence += 80;
2780
+ sources.push({ type: 'package.json', field: 'workspaces' });
2781
+ }
2782
+ if (exists(node_path.join(workspacePath, 'package-lock.json'))) {
2783
+ confidence += 10;
2784
+ sources.push({ type: 'lockfile', path: 'package-lock.json' });
2785
+ }
2786
+ if (exists(node_path.join(workspacePath, 'yarn.lock'))) {
2787
+ return null; // Let yarn workspace detector handle this
2788
+ }
2789
+ if (confidence === 0) {
2790
+ return null;
2791
+ }
2792
+ return {
2793
+ id: 'npm-workspaces',
2794
+ name: 'npm Workspaces',
2795
+ configPath: 'package.json',
2796
+ confidence: min(confidence, 100),
2797
+ detectedFrom: sources,
2798
+ };
2799
+ }
2800
+
2801
+ /**
2802
+ * Detect yarn workspaces in project.
2803
+ *
2804
+ * @param workspacePath - Workspace directory path
2805
+ * @param packageJson - Optional pre-loaded package.json
2806
+ * @returns Detection result or null if not detected
2807
+ */
2808
+ function yarnWorkspacesDetector(workspacePath, packageJson) {
2809
+ const pkg = packageJson ?? readPackageJsonIfExists(workspacePath);
2810
+ const sources = [];
2811
+ let confidence = 0;
2812
+ if (pkg?.workspaces) {
2813
+ confidence += 70;
2814
+ sources.push({ type: 'package.json', field: 'workspaces' });
2815
+ }
2816
+ if (exists(node_path.join(workspacePath, 'yarn.lock'))) {
2817
+ confidence += 20;
2818
+ sources.push({ type: 'lockfile', path: 'yarn.lock' });
2819
+ }
2820
+ if (exists(node_path.join(workspacePath, '.yarnrc.yml'))) {
2821
+ confidence += 10;
2822
+ sources.push({ type: 'config-file', path: '.yarnrc.yml' });
2823
+ }
2824
+ if (confidence === 0 || !pkg?.workspaces) {
2825
+ return null;
2826
+ }
2827
+ return {
2828
+ id: 'yarn-workspaces',
2829
+ name: 'Yarn Workspaces',
2830
+ configPath: 'package.json',
2831
+ confidence: min(confidence, 100),
2832
+ detectedFrom: sources,
2833
+ };
2834
+ }
2835
+
2836
+ /** All monorepo detectors */
2837
+ const monorepoDetectors = [
2838
+ { id: 'nx', name: 'NX', detect: nxDetector },
2839
+ { id: 'turborepo', name: 'Turborepo', detect: turborepoDetector },
2840
+ { id: 'lerna', name: 'Lerna', detect: lernaDetector },
2841
+ { id: 'rush', name: 'Rush', detect: rushDetector },
2842
+ { id: 'pnpm-workspaces', name: 'pnpm Workspaces', detect: pnpmWorkspacesDetector },
2843
+ { id: 'npm-workspaces', name: 'npm Workspaces', detect: npmWorkspacesDetector },
2844
+ { id: 'yarn-workspaces', name: 'Yarn Workspaces', detect: yarnWorkspacesDetector },
2845
+ ];
2846
+
2847
+ /** Config patterns for Jest */
2848
+ const JEST_CONFIG_PATTERNS = ['jest.config.js', 'jest.config.ts', 'jest.config.mjs', 'jest.config.cjs', 'jest.config.json'];
2849
+ /**
2850
+ * Detect Jest in project.
2851
+ *
2852
+ * @param projectPath - Project directory path
2853
+ * @param packageJson - Optional pre-loaded package.json
2854
+ * @returns Detection result or null if not detected
2855
+ */
2856
+ function jestDetector(projectPath, packageJson) {
2857
+ const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
2858
+ const sources = [];
2859
+ let confidence = 0;
2860
+ let version;
2861
+ const deps = collectAllDependencies(pkg);
2862
+ if (deps['jest']) {
2863
+ confidence += 60;
2864
+ version = parseVersionString(deps['jest']);
2865
+ sources.push({ type: 'package.json', field: 'dependencies.jest' });
2866
+ }
2867
+ const configPath = locateConfigFile(projectPath, JEST_CONFIG_PATTERNS);
2868
+ if (configPath) {
2869
+ confidence += 30;
2870
+ sources.push({ type: 'config-file', path: configPath });
2871
+ }
2872
+ if (pkg && 'jest' in pkg) {
2873
+ confidence += 20;
2874
+ sources.push({ type: 'package.json', field: 'jest' });
2875
+ }
2876
+ const testScript = pkg?.scripts?.['test'] ?? '';
2877
+ if (testScript.includes('jest')) {
2878
+ confidence += 10;
2879
+ sources.push({ type: 'package.json', field: 'scripts.test' });
2880
+ }
2881
+ if (deps['@types/jest']) {
2882
+ confidence += 5;
2883
+ sources.push({ type: 'package.json', field: 'dependencies.@types/jest' });
2884
+ }
2885
+ if (deps['ts-jest']) {
2886
+ confidence += 5;
2887
+ sources.push({ type: 'package.json', field: 'dependencies.ts-jest' });
2888
+ }
2889
+ if (confidence === 0) {
2890
+ return null;
2891
+ }
2892
+ return {
2893
+ id: 'jest',
2894
+ name: 'Jest',
2895
+ type: 'unit',
2896
+ version,
2897
+ configPath,
2898
+ confidence: min(confidence, 100),
2899
+ detectedFrom: sources,
2900
+ };
2901
+ }
2902
+
2903
+ /** Config patterns for Vitest */
2904
+ const VITEST_CONFIG_PATTERNS = ['vitest.config.js', 'vitest.config.ts', 'vitest.config.mjs'];
2905
+ /**
2906
+ * Detect Vitest in project.
2907
+ *
2908
+ * @param projectPath - Project directory path
2909
+ * @param packageJson - Optional pre-loaded package.json
2910
+ * @returns Detection result or null if not detected
2911
+ */
2912
+ function vitestDetector(projectPath, packageJson) {
2913
+ const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
2914
+ const sources = [];
2915
+ let confidence = 0;
2916
+ let version;
2917
+ const deps = collectAllDependencies(pkg);
2918
+ if (deps['vitest']) {
2919
+ confidence += 70;
2920
+ version = parseVersionString(deps['vitest']);
2921
+ sources.push({ type: 'package.json', field: 'dependencies.vitest' });
2922
+ }
2923
+ const configPath = locateConfigFile(projectPath, VITEST_CONFIG_PATTERNS);
2924
+ if (configPath) {
2925
+ confidence += 25;
2926
+ sources.push({ type: 'config-file', path: configPath });
2927
+ }
2928
+ if (!configPath) {
2929
+ const viteConfig = exists(node_path.join(projectPath, 'vite.config.ts')) ||
2930
+ exists(node_path.join(projectPath, 'vite.config.js')) ||
2931
+ exists(node_path.join(projectPath, 'vite.config.mjs'));
2932
+ if (viteConfig && deps['vitest']) {
2933
+ confidence += 5;
2934
+ sources.push({ type: 'config-file', path: 'vite.config.*' });
2935
+ }
2936
+ }
2937
+ const testScript = pkg?.scripts?.['test'] ?? '';
2938
+ if (testScript.includes('vitest')) {
2939
+ confidence += 10;
2940
+ sources.push({ type: 'package.json', field: 'scripts.test' });
2941
+ }
2942
+ if (confidence === 0) {
2943
+ return null;
2944
+ }
2945
+ return {
2946
+ id: 'vitest',
2947
+ name: 'Vitest',
2948
+ type: 'unit',
2949
+ version,
2950
+ configPath,
2951
+ confidence: min(confidence, 100),
2952
+ detectedFrom: sources,
2953
+ };
2954
+ }
2955
+
2956
+ /** Config patterns for Mocha */
2957
+ const MOCHA_CONFIG_PATTERNS = ['.mocharc.js', '.mocharc.json', '.mocharc.yaml', '.mocharc.yml', 'mocha.opts'];
2958
+ /**
2959
+ * Detect Mocha in project.
2960
+ *
2961
+ * @param projectPath - Project directory path
2962
+ * @param packageJson - Optional pre-loaded package.json
2963
+ * @returns Detection result or null if not detected
2964
+ */
2965
+ function mochaDetector(projectPath, packageJson) {
2966
+ const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
2967
+ const sources = [];
2968
+ let confidence = 0;
2969
+ let version;
2970
+ const deps = collectAllDependencies(pkg);
2971
+ if (deps['mocha']) {
2972
+ confidence += 65;
2973
+ version = parseVersionString(deps['mocha']);
2974
+ sources.push({ type: 'package.json', field: 'dependencies.mocha' });
2975
+ }
2976
+ const configPath = locateConfigFile(projectPath, MOCHA_CONFIG_PATTERNS);
2977
+ if (configPath) {
2978
+ confidence += 30;
2979
+ sources.push({ type: 'config-file', path: configPath });
2980
+ }
2981
+ if (deps['@types/mocha']) {
2982
+ confidence += 5;
2983
+ sources.push({ type: 'package.json', field: 'dependencies.@types/mocha' });
2984
+ }
2985
+ if (deps['chai']) {
2986
+ confidence += 5;
2987
+ sources.push({ type: 'package.json', field: 'dependencies.chai' });
2988
+ }
2989
+ const testScript = pkg?.scripts?.['test'] ?? '';
2990
+ if (testScript.includes('mocha')) {
2991
+ confidence += 10;
2992
+ sources.push({ type: 'package.json', field: 'scripts.test' });
2993
+ }
2994
+ if (confidence === 0) {
2995
+ return null;
2996
+ }
2997
+ return {
2998
+ id: 'mocha',
2999
+ name: 'Mocha',
3000
+ type: 'unit',
3001
+ version,
3002
+ configPath,
3003
+ confidence: min(confidence, 100),
3004
+ detectedFrom: sources,
3005
+ };
3006
+ }
3007
+
3008
+ /** Config patterns for Cypress */
3009
+ const CYPRESS_CONFIG_PATTERNS = ['cypress.config.js', 'cypress.config.ts', 'cypress.config.mjs', 'cypress.json'];
3010
+ /**
3011
+ * Detect Cypress in project.
3012
+ *
3013
+ * @param projectPath - Project directory path
3014
+ * @param packageJson - Optional pre-loaded package.json
3015
+ * @returns Detection result or null if not detected
3016
+ */
3017
+ function cypressDetector(projectPath, packageJson) {
3018
+ const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
3019
+ const sources = [];
3020
+ let confidence = 0;
3021
+ let version;
3022
+ const deps = collectAllDependencies(pkg);
3023
+ if (deps['cypress']) {
3024
+ confidence += 60;
3025
+ version = parseVersionString(deps['cypress']);
3026
+ sources.push({ type: 'package.json', field: 'dependencies.cypress' });
3027
+ }
3028
+ const configPath = locateConfigFile(projectPath, CYPRESS_CONFIG_PATTERNS);
3029
+ if (configPath) {
3030
+ confidence += 30;
3031
+ sources.push({ type: 'config-file', path: configPath });
3032
+ }
3033
+ if (exists(node_path.join(projectPath, 'cypress'))) {
3034
+ confidence += 10;
3035
+ sources.push({ type: 'directory', path: 'cypress/' });
3036
+ }
3037
+ const e2eScript = pkg?.scripts?.['e2e'] ?? pkg?.scripts?.['test:e2e'] ?? '';
3038
+ if (e2eScript.includes('cypress')) {
3039
+ confidence += 5;
3040
+ sources.push({ type: 'package.json', field: 'scripts.e2e or scripts.test:e2e' });
3041
+ }
3042
+ if (confidence === 0) {
3043
+ return null;
3044
+ }
3045
+ return {
3046
+ id: 'cypress',
3047
+ name: 'Cypress',
3048
+ type: 'e2e',
3049
+ version,
3050
+ configPath,
3051
+ confidence: min(confidence, 100),
3052
+ detectedFrom: sources,
3053
+ };
3054
+ }
3055
+
3056
+ /** Config patterns for Playwright */
3057
+ const PLAYWRIGHT_CONFIG_PATTERNS = ['playwright.config.js', 'playwright.config.ts', 'playwright.config.mjs'];
3058
+ /**
3059
+ * Detect Playwright in project.
3060
+ *
3061
+ * @param projectPath - Project directory path
3062
+ * @param packageJson - Optional pre-loaded package.json
3063
+ * @returns Detection result or null if not detected
3064
+ */
3065
+ function playwrightDetector(projectPath, packageJson) {
3066
+ const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
3067
+ const sources = [];
3068
+ let confidence = 0;
3069
+ let version;
3070
+ const deps = collectAllDependencies(pkg);
3071
+ if (deps['@playwright/test']) {
3072
+ confidence += 70;
3073
+ version = parseVersionString(deps['@playwright/test']);
3074
+ sources.push({ type: 'package.json', field: 'dependencies.@playwright/test' });
3075
+ }
3076
+ if (deps['playwright']) {
3077
+ confidence += 50;
3078
+ version = version ?? parseVersionString(deps['playwright']);
3079
+ sources.push({ type: 'package.json', field: 'dependencies.playwright' });
3080
+ }
3081
+ const configPath = locateConfigFile(projectPath, PLAYWRIGHT_CONFIG_PATTERNS);
3082
+ if (configPath) {
3083
+ confidence += 25;
3084
+ sources.push({ type: 'config-file', path: configPath });
3085
+ }
3086
+ if (exists(node_path.join(projectPath, 'e2e')) || exists(node_path.join(projectPath, 'tests'))) {
3087
+ confidence += 5;
3088
+ sources.push({ type: 'directory', path: 'e2e/ or tests/' });
3089
+ }
3090
+ const e2eScript = pkg?.scripts?.['e2e'] ?? pkg?.scripts?.['test:e2e'] ?? '';
3091
+ if (e2eScript.includes('playwright')) {
3092
+ confidence += 5;
3093
+ sources.push({ type: 'package.json', field: 'scripts.e2e or scripts.test:e2e' });
3094
+ }
3095
+ if (confidence === 0) {
3096
+ return null;
3097
+ }
3098
+ return {
3099
+ id: 'playwright',
3100
+ name: 'Playwright',
3101
+ type: 'e2e',
3102
+ version,
3103
+ configPath,
3104
+ confidence: min(confidence, 100),
3105
+ detectedFrom: sources,
3106
+ };
3107
+ }
3108
+
3109
+ /** All testing framework detectors */
3110
+ const testingDetectors = [
3111
+ { id: 'jest', name: 'Jest', testType: 'unit', detect: jestDetector },
3112
+ { id: 'vitest', name: 'Vitest', testType: 'unit', detect: vitestDetector },
3113
+ { id: 'mocha', name: 'Mocha', testType: 'unit', detect: mochaDetector },
3114
+ { id: 'cypress', name: 'Cypress', testType: 'e2e', detect: cypressDetector },
3115
+ { id: 'playwright', name: 'Playwright', testType: 'e2e', detect: playwrightDetector },
3116
+ ];
3117
+
3118
+ /**
3119
+ * Check if tsconfig has strict mode enabled.
3120
+ *
3121
+ * @param projectPath - The project directory path
3122
+ * @returns True if strict mode is enabled, undefined if unable to determine
3123
+ */
3124
+ function checkTsConfigStrict(projectPath) {
3125
+ const tsconfigPath = node_path.join(projectPath, 'tsconfig.json');
3126
+ const content = readFileIfExists(tsconfigPath);
3127
+ if (!content)
3128
+ return undefined;
3129
+ try {
3130
+ // Simple JSON parsing - doesn't handle comments but good enough for strict check
3131
+ const cleanContent = content.replace(/\/\*[\s\S]*?\*\/|\/\/.*/g, '');
3132
+ const parsed = parse(cleanContent);
3133
+ return parsed?.compilerOptions?.strict === true;
3134
+ }
3135
+ catch {
3136
+ return undefined;
3137
+ }
3138
+ }
3139
+ /**
3140
+ * Detect TypeScript in project.
3141
+ *
3142
+ * @param projectPath - Project directory path
3143
+ * @param packageJson - Optional pre-loaded package.json
3144
+ * @returns Detection result or null if not detected
3145
+ */
3146
+ function typescriptDetector(projectPath, packageJson) {
3147
+ const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
3148
+ const sources = [];
3149
+ let confidence = 0;
3150
+ let configPath;
3151
+ let version;
3152
+ const deps = collectAllDependencies(pkg);
3153
+ // TypeScript package
3154
+ if (deps['typescript']) {
3155
+ confidence += 50;
3156
+ version = parseVersionString(deps['typescript']);
3157
+ sources.push({ type: 'package.json', field: 'dependencies.typescript' });
3158
+ }
3159
+ // tsconfig.json
3160
+ if (exists(node_path.join(projectPath, 'tsconfig.json'))) {
3161
+ confidence += 40;
3162
+ configPath = 'tsconfig.json';
3163
+ sources.push({ type: 'config-file', path: 'tsconfig.json' });
3164
+ }
3165
+ // tsconfig.*.json variants
3166
+ const tsconfigVariants = ['tsconfig.build.json', 'tsconfig.lib.json', 'tsconfig.spec.json', 'tsconfig.app.json'];
3167
+ for (const variant of tsconfigVariants) {
3168
+ if (exists(node_path.join(projectPath, variant))) {
3169
+ confidence += 5;
3170
+ sources.push({ type: 'config-file', path: variant });
3171
+ break;
3172
+ }
3173
+ }
3174
+ // @types packages
3175
+ const typePackages = keys(deps).filter((d) => d.startsWith('@types/'));
3176
+ if (typePackages.length > 0) {
3177
+ confidence += 10;
3178
+ sources.push({ type: 'package.json', field: '@types/* packages' });
3179
+ }
3180
+ if (confidence === 0) {
3181
+ return null;
3182
+ }
3183
+ const strictMode = checkTsConfigStrict(projectPath);
3184
+ return {
3185
+ id: 'typescript',
3186
+ name: 'TypeScript',
3187
+ version,
3188
+ configPath,
3189
+ strictMode,
3190
+ confidence: min(confidence, 100),
3191
+ detectedFrom: sources,
3192
+ };
3193
+ }
3194
+ /**
3195
+ * Detect Flow in project.
3196
+ *
3197
+ * @param projectPath - Project directory path
3198
+ * @param packageJson - Optional pre-loaded package.json
3199
+ * @returns Detection result or null if not detected
3200
+ */
3201
+ function flowDetector(projectPath, packageJson) {
3202
+ const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
3203
+ const sources = [];
3204
+ let confidence = 0;
3205
+ let configPath;
3206
+ let version;
3207
+ const deps = collectAllDependencies(pkg);
3208
+ // flow-bin package
3209
+ if (deps['flow-bin']) {
3210
+ confidence += 60;
3211
+ version = parseVersionString(deps['flow-bin']);
3212
+ sources.push({ type: 'package.json', field: 'dependencies.flow-bin' });
3213
+ }
3214
+ // .flowconfig
3215
+ if (exists(node_path.join(projectPath, '.flowconfig'))) {
3216
+ confidence += 40;
3217
+ configPath = '.flowconfig';
3218
+ sources.push({ type: 'config-file', path: '.flowconfig' });
3219
+ }
3220
+ // flow-typed directory
3221
+ if (exists(node_path.join(projectPath, 'flow-typed'))) {
3222
+ confidence += 10;
3223
+ sources.push({ type: 'directory', path: 'flow-typed/' });
3224
+ }
3225
+ // @babel/preset-flow
3226
+ if (deps['@babel/preset-flow']) {
3227
+ confidence += 10;
3228
+ sources.push({ type: 'package.json', field: 'dependencies.@babel/preset-flow' });
3229
+ }
3230
+ if (confidence === 0) {
3231
+ return null;
3232
+ }
3233
+ return {
3234
+ id: 'flow',
3235
+ name: 'Flow',
3236
+ version,
3237
+ configPath,
3238
+ confidence: min(confidence, 100),
3239
+ detectedFrom: sources,
3240
+ };
3241
+ }
3242
+ /**
3243
+ * Check if a file contains JSDoc type annotations.
3244
+ *
3245
+ * @param content - The file content to check.
3246
+ * @returns `true` if the content contains JSDoc type annotations.
3247
+ */
3248
+ function hasJsDocTypes(content) {
3249
+ // Check for JSDoc type annotations
3250
+ return (content.includes('@type {') ||
3251
+ content.includes('@param {') ||
3252
+ content.includes('@returns {') ||
3253
+ content.includes('@typedef') ||
3254
+ content.includes('@template'));
3255
+ }
3256
+ /**
3257
+ * Detect JSDoc type annotations in project.
3258
+ *
3259
+ * @param projectPath - Project directory path
3260
+ * @param packageJson - Optional pre-loaded package.json
3261
+ * @returns Detection result or null if not detected
3262
+ */
3263
+ function jsdocDetector(projectPath, packageJson) {
3264
+ const pkg = packageJson ?? readPackageJsonIfExists(projectPath);
3265
+ const sources = [];
3266
+ let confidence = 0;
3267
+ const deps = collectAllDependencies(pkg);
3268
+ // jsdoc package
3269
+ if (deps['jsdoc']) {
3270
+ confidence += 30;
3271
+ sources.push({ type: 'package.json', field: 'dependencies.jsdoc' });
3272
+ }
3273
+ // typescript with checkJs (JSDoc type checking)
3274
+ if (deps['typescript']) {
3275
+ // Check if checkJs is enabled in tsconfig
3276
+ const tsconfigPath = node_path.join(projectPath, 'tsconfig.json');
3277
+ const content = readFileIfExists(tsconfigPath);
3278
+ if (content) {
3279
+ try {
3280
+ const cleanContent = content.replace(/\/\*[\s\S]*?\*\/|\/\/.*/g, '');
3281
+ const parsed = parse(cleanContent);
3282
+ if (parsed?.compilerOptions?.checkJs === true || parsed?.compilerOptions?.allowJs === true) {
3283
+ confidence += 30;
3284
+ sources.push({ type: 'config-file', path: 'tsconfig.json (checkJs/allowJs)' });
3285
+ }
3286
+ }
3287
+ catch {
3288
+ // Ignore parsing errors
3289
+ }
3290
+ }
3291
+ }
3292
+ // Check for jsconfig.json (VS Code JS type checking)
3293
+ if (exists(node_path.join(projectPath, 'jsconfig.json'))) {
3294
+ confidence += 40;
3295
+ sources.push({ type: 'config-file', path: 'jsconfig.json' });
3296
+ }
3297
+ // Sample check for JSDoc annotations in source files
3298
+ const srcDir = node_path.join(projectPath, 'src');
3299
+ if (exists(srcDir)) {
3300
+ try {
3301
+ const entries = readDirectory(srcDir);
3302
+ const files = entries.filter((e) => e.isFile && (e.name.endsWith('.js') || e.name.endsWith('.mjs'))).map((e) => e.name);
3303
+ for (const file of files.slice(0, 3)) {
3304
+ const content = readFileIfExists(node_path.join(srcDir, file));
3305
+ if (content && hasJsDocTypes(content)) {
3306
+ confidence += 20;
3307
+ sources.push({ type: 'directory', path: `src/${file} (JSDoc annotations)` });
3308
+ break;
3309
+ }
3310
+ }
3311
+ }
3312
+ catch {
3313
+ // Ignore directory read errors
3314
+ }
3315
+ }
3316
+ if (confidence === 0) {
3317
+ return null;
3318
+ }
3319
+ return {
3320
+ id: 'jsdoc',
3321
+ name: 'JSDoc',
3322
+ confidence: min(confidence, 100),
3323
+ detectedFrom: sources,
3324
+ };
3325
+ }
3326
+ /** All type system detectors */
3327
+ const typeSystemDetectors = [
3328
+ { id: 'typescript', name: 'TypeScript', detect: typescriptDetector },
3329
+ { id: 'flow', name: 'Flow', detect: flowDetector },
3330
+ { id: 'jsdoc', name: 'JSDoc', detect: jsdocDetector },
3331
+ ];
3332
+
3333
+ const techLogger = createScopedLogger('project-scope:tech');
3334
+ /**
3335
+ * Cache for tech detection results.
3336
+ * TTL: 60 seconds (tech stack can change during active development)
3337
+ */
3338
+ const detectAllCache = createCache({ ttl: 60000, maxSize: 50 });
3339
+ /**
3340
+ * Check if the value is a DetectAllOptions object.
3341
+ *
3342
+ * @param value - Value to check
3343
+ * @returns True if value is DetectAllOptions
3344
+ */
3345
+ function isDetectAllOptions(value) {
3346
+ if (typeof value !== 'object' || value === null)
3347
+ return false;
3348
+ // DetectAllOptions has skipCache or packageJson fields specifically
3349
+ // PackageJson never has skipCache field
3350
+ return 'skipCache' in value || 'packageJson' in value;
3351
+ }
3352
+ /**
3353
+ * Run all technology detectors on a project.
3354
+ *
3355
+ * Results are cached for 60 seconds per project path to avoid
3356
+ * redundant file system operations on repeated calls.
3357
+ *
3358
+ * @param projectPath - Path to project directory
3359
+ * @param packageJsonOrOptions - Optional pre-loaded package.json or options object
3360
+ * @returns All detection results organized by category
3361
+ *
3362
+ * @example
3363
+ * ```typescript
3364
+ * import { detectAll } from '@hyperfrontend/project-scope'
3365
+ *
3366
+ * const detections = detectAll('./my-project')
3367
+ *
3368
+ * // Check frontend frameworks
3369
+ * for (const fw of detections.frontendFrameworks) {
3370
+ * console.log(`${fw.name} v${fw.version} (${fw.confidence}% confidence)`)
3371
+ * }
3372
+ *
3373
+ * // Check build tools
3374
+ * console.log('Build tools:', detections.buildTools.map(t => t.name))
3375
+ *
3376
+ * // Check testing frameworks
3377
+ * console.log('Testing:', detections.testingFrameworks.map(t => t.name))
3378
+ * ```
3379
+ */
3380
+ function detectAll(projectPath, packageJsonOrOptions) {
3381
+ // Handle backward-compatible arguments
3382
+ const options = isDetectAllOptions(packageJsonOrOptions) ? packageJsonOrOptions : { packageJson: packageJsonOrOptions };
3383
+ // Check cache first (unless skipCache is true)
3384
+ if (!options.skipCache) {
3385
+ const cached = detectAllCache.get(projectPath);
3386
+ if (cached) {
3387
+ techLogger.debug('Returning cached tech detection results', { projectPath });
3388
+ return cached;
3389
+ }
3390
+ }
3391
+ const pkg = options.packageJson ?? readPackageJsonIfExists(projectPath);
3392
+ techLogger.debug('Running all tech detectors', { projectPath });
3393
+ const result = {
3394
+ buildTools: buildToolDetectors
3395
+ .map((d) => d.detect(projectPath, pkg ?? undefined))
3396
+ .filter((r) => r !== null)
3397
+ .sort((a, b) => b.confidence - a.confidence),
3398
+ monorepo: monorepoDetectors
3399
+ .map((d) => d.detect(projectPath, pkg ?? undefined))
3400
+ .filter((r) => r !== null)
3401
+ .sort((a, b) => b.confidence - a.confidence),
3402
+ frontendFrameworks: frameworkDetectors
3403
+ .map((d) => d.detect(projectPath, pkg ?? undefined))
3404
+ .filter((r) => r !== null)
3405
+ .sort((a, b) => b.confidence - a.confidence),
3406
+ backendFrameworks: backendDetectors
3407
+ .map((d) => d.detect(projectPath, pkg ?? undefined))
3408
+ .filter((r) => r !== null)
3409
+ .sort((a, b) => b.confidence - a.confidence),
3410
+ legacyFrameworks: legacyDetectors
3411
+ .map((d) => d.detect(projectPath, pkg ?? undefined))
3412
+ .filter((r) => r !== null)
3413
+ .sort((a, b) => b.confidence - a.confidence),
3414
+ testingFrameworks: testingDetectors
3415
+ .map((d) => d.detect(projectPath, pkg ?? undefined))
3416
+ .filter((r) => r !== null)
3417
+ .sort((a, b) => b.confidence - a.confidence),
3418
+ typeSystem: typeSystemDetectors
3419
+ .map((d) => d.detect(projectPath, pkg ?? undefined))
3420
+ .filter((r) => r !== null)
3421
+ .sort((a, b) => b.confidence - a.confidence),
3422
+ linting: lintingDetectors
3423
+ .map((d) => d.detect(projectPath, pkg ?? undefined))
3424
+ .filter((r) => r !== null)
3425
+ .sort((a, b) => b.confidence - a.confidence),
3426
+ };
3427
+ techLogger.debug('Tech detection complete', {
3428
+ buildTools: result.buildTools.map((t) => t.id),
3429
+ frontendFrameworks: result.frontendFrameworks.map((f) => f.id),
3430
+ backendFrameworks: result.backendFrameworks.map((f) => f.id),
3431
+ legacyFrameworks: result.legacyFrameworks.map((f) => f.id),
3432
+ testingFrameworks: result.testingFrameworks.map((f) => f.id),
3433
+ });
3434
+ // Cache the result
3435
+ detectAllCache.set(projectPath, result);
3436
+ return result;
3437
+ }
3438
+
3439
+ const frameworkLogger = createScopedLogger('project-scope:heuristics:framework');
3440
+ /**
3441
+ * Cache for framework identification results.
3442
+ * TTL: 60 seconds (frameworks are stable but can change during development)
3443
+ */
3444
+ const frameworkIdCache = createCache({ ttl: 60000, maxSize: 50 });
3445
+ /**
3446
+ * Build a human-readable summary string from detected frameworks.
3447
+ *
3448
+ * @param frontend - Frontend framework names
3449
+ * @param backend - Backend framework names
3450
+ * @param testing - Testing framework names
3451
+ * @returns Human-readable summary
3452
+ */
3453
+ function buildSummary(frontend, backend, testing) {
3454
+ const parts = [];
3455
+ if (frontend.length > 0) {
3456
+ parts.push(frontend.join(' + '));
3457
+ }
3458
+ if (backend.length > 0) {
3459
+ if (parts.length > 0) {
3460
+ parts.push('with');
3461
+ }
3462
+ parts.push(backend.join(' + '));
3463
+ }
3464
+ if (testing.length > 0) {
3465
+ if (parts.length > 0) {
3466
+ parts.push('and');
3467
+ }
3468
+ parts.push(testing.join('/'));
3469
+ }
3470
+ return parts.length > 0 ? parts.join(' ') : 'No frameworks detected';
3471
+ }
3472
+ /**
3473
+ * Identify all frameworks in project.
3474
+ *
3475
+ * Runs all technology detectors and aggregates results into a comprehensive
3476
+ * framework identification with confidence scoring.
3477
+ *
3478
+ * @param projectPath - Project directory path
3479
+ * @param options - Identification options
3480
+ * @returns Framework identification result
3481
+ *
3482
+ * @example
3483
+ * ```typescript
3484
+ * import { identifyFrameworks } from '@hyperfrontend/project-scope'
3485
+ *
3486
+ * const result = identifyFrameworks('./my-react-app')
3487
+ * console.log(result.summary) // 'React + Next.js with Jest'
3488
+ * console.log(result.primary?.name) // 'React'
3489
+ * console.log(result.stack.frontend) // ['react', 'nextjs']
3490
+ * console.log(result.stack.testing) // ['jest']
3491
+ * ```
3492
+ */
3493
+ function identifyFrameworks(projectPath, options) {
3494
+ frameworkLogger.debug('Identifying frameworks', { projectPath, minConfidence: options?.minConfidence ?? 10 });
3495
+ const minConfidence = options?.minConfidence ?? 10;
3496
+ const cacheKey = `${projectPath}:${minConfidence}`;
3497
+ if (!options?.skipCache) {
3498
+ const cached = frameworkIdCache.get(cacheKey);
3499
+ if (cached) {
3500
+ frameworkLogger.debug('Returning cached framework identification', { projectPath });
3501
+ return cached;
3502
+ }
3503
+ }
3504
+ const packageJson = readPackageJsonIfExists(projectPath);
3505
+ const detections = detectAll(projectPath, packageJson ?? undefined);
3506
+ const frontendFrameworks = detections.frontendFrameworks
3507
+ .filter((d) => d.confidence >= minConfidence)
3508
+ .map((d) => ({
3509
+ id: d.id,
3510
+ name: d.name,
3511
+ version: d.version,
3512
+ confidence: d.confidence,
3513
+ category: d.category === 'meta-framework' ? 'frontend' : 'frontend',
3514
+ metaFrameworks: d.metaFrameworks?.map((m) => m.id),
3515
+ }));
3516
+ const metaFrameworks = [];
3517
+ for (const detection of detections.frontendFrameworks) {
3518
+ if (detection.category === 'meta-framework' && detection.confidence >= minConfidence) {
3519
+ metaFrameworks.push({
3520
+ id: detection.id,
3521
+ name: detection.name,
3522
+ version: detection.version,
3523
+ confidence: detection.confidence,
3524
+ category: 'frontend',
3525
+ });
3526
+ }
3527
+ if (detection.metaFrameworks) {
3528
+ for (const meta of detection.metaFrameworks) {
3529
+ if (meta.confidence >= minConfidence && !metaFrameworks.some((m) => m.id === meta.id)) {
3530
+ metaFrameworks.push({
3531
+ id: meta.id,
3532
+ name: meta.name,
3533
+ version: meta.version,
3534
+ confidence: meta.confidence,
3535
+ category: 'frontend',
3536
+ });
3537
+ }
3538
+ }
3539
+ }
3540
+ }
3541
+ const backendFrameworks = detections.backendFrameworks
3542
+ .filter((d) => d.confidence >= minConfidence)
3543
+ .map((d) => ({
3544
+ id: d.id,
3545
+ name: d.name,
3546
+ version: d.version,
3547
+ confidence: d.confidence,
3548
+ category: 'backend',
3549
+ }));
3550
+ const testingFrameworks = detections.testingFrameworks
3551
+ .filter((d) => d.confidence >= minConfidence)
3552
+ .map((d) => ({
3553
+ id: d.id,
3554
+ name: d.name,
3555
+ version: d.version,
3556
+ configPath: d.configPath,
3557
+ type: d.type,
3558
+ confidence: d.confidence,
3559
+ }));
3560
+ const stack = {
3561
+ frontend: detections.frontendFrameworks.filter((d) => d.confidence >= minConfidence).map((d) => d.id),
3562
+ backend: detections.backendFrameworks.filter((d) => d.confidence >= minConfidence).map((d) => d.id),
3563
+ testing: detections.testingFrameworks.filter((d) => d.confidence >= minConfidence).map((d) => d.id),
3564
+ build: detections.buildTools.filter((d) => d.confidence >= minConfidence).map((d) => d.id),
3565
+ typeSystem: detections.typeSystem.filter((d) => d.confidence >= minConfidence).map((d) => d.id),
3566
+ linting: detections.linting.filter((d) => d.confidence >= minConfidence).map((d) => d.id),
3567
+ };
3568
+ const allFrameworks = [...frontendFrameworks, ...backendFrameworks];
3569
+ allFrameworks.sort((a, b) => b.confidence - a.confidence);
3570
+ const primary = allFrameworks[0];
3571
+ const summary = buildSummary(frontendFrameworks.map((f) => f.name), backendFrameworks.map((f) => f.name), testingFrameworks.map((f) => f.name));
3572
+ frameworkLogger.debug('Framework identification complete', {
3573
+ projectPath,
3574
+ primaryFramework: primary?.name ?? 'none',
3575
+ frontendCount: frontendFrameworks.length,
3576
+ backendCount: backendFrameworks.length,
3577
+ testingCount: testingFrameworks.length,
3578
+ metaFrameworkCount: metaFrameworks.length,
3579
+ summary,
3580
+ });
3581
+ const result = {
3582
+ primary,
3583
+ frontend: frontendFrameworks,
3584
+ backend: backendFrameworks,
3585
+ testing: testingFrameworks,
3586
+ metaFrameworks,
3587
+ summary,
3588
+ stack,
3589
+ };
3590
+ frameworkIdCache.set(cacheKey, result);
3591
+ return result;
3592
+ }
3593
+ /**
3594
+ * Clear the framework identification cache.
3595
+ *
3596
+ * Useful for testing or when the project files have changed.
3597
+ */
3598
+ function clearFrameworkIdentificationCache() {
3599
+ frameworkIdCache.clear();
3600
+ }
3601
+ /**
3602
+ * Check if a project uses a specific framework.
3603
+ *
3604
+ * @param projectPath - Project directory path
3605
+ * @param frameworkId - Framework identifier to check
3606
+ * @param minConfidence - Minimum confidence threshold (default: 50)
3607
+ * @returns True if the framework is detected with sufficient confidence
3608
+ */
3609
+ function usesFramework(projectPath, frameworkId, minConfidence = 50) {
3610
+ const identification = identifyFrameworks(projectPath, { minConfidence });
3611
+ const allFrameworks = [...identification.frontend, ...identification.backend, ...identification.metaFrameworks];
3612
+ return allFrameworks.some((f) => f.id === frameworkId && f.confidence >= minConfidence);
3613
+ }
3614
+
3615
+ exports.clearFrameworkIdentificationCache = clearFrameworkIdentificationCache;
3616
+ exports.identifyFrameworks = identifyFrameworks;
3617
+ exports.usesFramework = usesFramework;
3618
+ //# sourceMappingURL=index.cjs.js.map