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