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