@ai-dev-tools/test-copilot-core 1.0.19

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 (328) hide show
  1. package/README.md +6 -0
  2. package/azure-pipelines.yml +51 -0
  3. package/out/cli/commands/appInsightTelemetry.d.ts +7 -0
  4. package/out/cli/commands/appInsightTelemetry.d.ts.map +1 -0
  5. package/out/cli/commands/appInsightTelemetry.js +76 -0
  6. package/out/cli/commands/appInsightTelemetry.js.map +1 -0
  7. package/out/cli/commands/cliConfig.d.ts +4 -0
  8. package/out/cli/commands/cliConfig.d.ts.map +1 -0
  9. package/out/cli/commands/cliConfig.js +68 -0
  10. package/out/cli/commands/cliConfig.js.map +1 -0
  11. package/out/cli/commands/prompt.d.ts +6 -0
  12. package/out/cli/commands/prompt.d.ts.map +1 -0
  13. package/out/cli/commands/prompt.js +29 -0
  14. package/out/cli/commands/prompt.js.map +1 -0
  15. package/out/cli/commands/ut.d.ts +14 -0
  16. package/out/cli/commands/ut.d.ts.map +1 -0
  17. package/out/cli/commands/ut.js +72 -0
  18. package/out/cli/commands/ut.js.map +1 -0
  19. package/out/cli/commands/utPipeCmdWrapper.d.ts +18 -0
  20. package/out/cli/commands/utPipeCmdWrapper.d.ts.map +1 -0
  21. package/out/cli/commands/utPipeCmdWrapper.js +37 -0
  22. package/out/cli/commands/utPipeCmdWrapper.js.map +1 -0
  23. package/out/cli/config/index.d.ts +15 -0
  24. package/out/cli/config/index.d.ts.map +1 -0
  25. package/out/cli/config/index.js +10 -0
  26. package/out/cli/config/index.js.map +1 -0
  27. package/out/cli/index.d.ts +3 -0
  28. package/out/cli/index.d.ts.map +1 -0
  29. package/out/cli/index.js +169 -0
  30. package/out/cli/index.js.map +1 -0
  31. package/out/cli/type.d.ts +11 -0
  32. package/out/cli/type.d.ts.map +1 -0
  33. package/out/cli/type.js +3 -0
  34. package/out/cli/type.js.map +1 -0
  35. package/out/cli/utils/ds.d.ts +3 -0
  36. package/out/cli/utils/ds.d.ts.map +1 -0
  37. package/out/cli/utils/ds.js +50 -0
  38. package/out/cli/utils/ds.js.map +1 -0
  39. package/out/cli/utils/gpt.d.ts +3 -0
  40. package/out/cli/utils/gpt.d.ts.map +1 -0
  41. package/out/cli/utils/gpt.js +63 -0
  42. package/out/cli/utils/gpt.js.map +1 -0
  43. package/out/core/analyze/cjs.d.ts +61 -0
  44. package/out/core/analyze/cjs.d.ts.map +1 -0
  45. package/out/core/analyze/cjs.js +358 -0
  46. package/out/core/analyze/cjs.js.map +1 -0
  47. package/out/core/analyze/class.d.ts +4 -0
  48. package/out/core/analyze/class.d.ts.map +1 -0
  49. package/out/core/analyze/class.js +32 -0
  50. package/out/core/analyze/class.js.map +1 -0
  51. package/out/core/analyze/declares.d.ts +7 -0
  52. package/out/core/analyze/declares.d.ts.map +1 -0
  53. package/out/core/analyze/declares.js +316 -0
  54. package/out/core/analyze/declares.js.map +1 -0
  55. package/out/core/analyze/deps.d.ts +8 -0
  56. package/out/core/analyze/deps.d.ts.map +1 -0
  57. package/out/core/analyze/deps.js +210 -0
  58. package/out/core/analyze/deps.js.map +1 -0
  59. package/out/core/analyze/functionComponent.d.ts +4 -0
  60. package/out/core/analyze/functionComponent.d.ts.map +1 -0
  61. package/out/core/analyze/functionComponent.js +77 -0
  62. package/out/core/analyze/functionComponent.js.map +1 -0
  63. package/out/core/analyze/functions.d.ts +4 -0
  64. package/out/core/analyze/functions.d.ts.map +1 -0
  65. package/out/core/analyze/functions.js +46 -0
  66. package/out/core/analyze/functions.js.map +1 -0
  67. package/out/core/analyze/index.d.ts +16 -0
  68. package/out/core/analyze/index.d.ts.map +1 -0
  69. package/out/core/analyze/index.js +149 -0
  70. package/out/core/analyze/index.js.map +1 -0
  71. package/out/core/analyze/index.type.d.ts +69 -0
  72. package/out/core/analyze/index.type.d.ts.map +1 -0
  73. package/out/core/analyze/index.type.js +14 -0
  74. package/out/core/analyze/index.type.js.map +1 -0
  75. package/out/core/analyze/utils/global.d.ts +2 -0
  76. package/out/core/analyze/utils/global.d.ts.map +1 -0
  77. package/out/core/analyze/utils/global.js +84 -0
  78. package/out/core/analyze/utils/global.js.map +1 -0
  79. package/out/core/analyzev2/declare/class.d.ts +4 -0
  80. package/out/core/analyzev2/declare/class.d.ts.map +1 -0
  81. package/out/core/analyzev2/declare/class.js +24 -0
  82. package/out/core/analyzev2/declare/class.js.map +1 -0
  83. package/out/core/analyzev2/declare/funcLike.d.ts +8 -0
  84. package/out/core/analyzev2/declare/funcLike.d.ts.map +1 -0
  85. package/out/core/analyzev2/declare/funcLike.js +71 -0
  86. package/out/core/analyzev2/declare/funcLike.js.map +1 -0
  87. package/out/core/analyzev2/declare/variable.d.ts +3 -0
  88. package/out/core/analyzev2/declare/variable.d.ts.map +1 -0
  89. package/out/core/analyzev2/declare/variable.js +15 -0
  90. package/out/core/analyzev2/declare/variable.js.map +1 -0
  91. package/out/core/analyzev2/file.d.ts +19 -0
  92. package/out/core/analyzev2/file.d.ts.map +1 -0
  93. package/out/core/analyzev2/file.js +449 -0
  94. package/out/core/analyzev2/file.js.map +1 -0
  95. package/out/core/analyzev2/index.d.ts +5 -0
  96. package/out/core/analyzev2/index.d.ts.map +1 -0
  97. package/out/core/analyzev2/index.js +30 -0
  98. package/out/core/analyzev2/index.js.map +1 -0
  99. package/out/core/analyzev2/type.d.ts +35 -0
  100. package/out/core/analyzev2/type.d.ts.map +1 -0
  101. package/out/core/analyzev2/type.js +3 -0
  102. package/out/core/analyzev2/type.js.map +1 -0
  103. package/out/core/config/index.d.ts +25 -0
  104. package/out/core/config/index.d.ts.map +1 -0
  105. package/out/core/config/index.js +14 -0
  106. package/out/core/config/index.js.map +1 -0
  107. package/out/core/constants.d.ts +9 -0
  108. package/out/core/constants.d.ts.map +1 -0
  109. package/out/core/constants.js +12 -0
  110. package/out/core/constants.js.map +1 -0
  111. package/out/core/features/common/base.d.ts +20 -0
  112. package/out/core/features/common/base.d.ts.map +1 -0
  113. package/out/core/features/common/base.js +77 -0
  114. package/out/core/features/common/base.js.map +1 -0
  115. package/out/core/features/common/types.d.ts +16 -0
  116. package/out/core/features/common/types.d.ts.map +1 -0
  117. package/out/core/features/common/types.js +12 -0
  118. package/out/core/features/common/types.js.map +1 -0
  119. package/out/core/features/generateFile.d.ts +31 -0
  120. package/out/core/features/generateFile.d.ts.map +1 -0
  121. package/out/core/features/generateFile.js +148 -0
  122. package/out/core/features/generateFile.js.map +1 -0
  123. package/out/core/features/generateSingle.d.ts +28 -0
  124. package/out/core/features/generateSingle.d.ts.map +1 -0
  125. package/out/core/features/generateSingle.js +149 -0
  126. package/out/core/features/generateSingle.js.map +1 -0
  127. package/out/core/features/index.d.ts +9 -0
  128. package/out/core/features/index.d.ts.map +1 -0
  129. package/out/core/features/index.js +16 -0
  130. package/out/core/features/index.js.map +1 -0
  131. package/out/core/features/lintFix.d.ts +2 -0
  132. package/out/core/features/lintFix.d.ts.map +1 -0
  133. package/out/core/features/lintFix.js +33 -0
  134. package/out/core/features/lintFix.js.map +1 -0
  135. package/out/core/features/mergeUTFile.d.ts +19 -0
  136. package/out/core/features/mergeUTFile.d.ts.map +1 -0
  137. package/out/core/features/mergeUTFile.js +63 -0
  138. package/out/core/features/mergeUTFile.js.map +1 -0
  139. package/out/core/features/removeFailedCases.d.ts +23 -0
  140. package/out/core/features/removeFailedCases.d.ts.map +1 -0
  141. package/out/core/features/removeFailedCases.js +81 -0
  142. package/out/core/features/removeFailedCases.js.map +1 -0
  143. package/out/core/features/updateSpec.d.ts +20 -0
  144. package/out/core/features/updateSpec.d.ts.map +1 -0
  145. package/out/core/features/updateSpec.js +98 -0
  146. package/out/core/features/updateSpec.js.map +1 -0
  147. package/out/core/features/validFix.d.ts +29 -0
  148. package/out/core/features/validFix.d.ts.map +1 -0
  149. package/out/core/features/validFix.js +219 -0
  150. package/out/core/features/validFix.js.map +1 -0
  151. package/out/core/generate/UTGen.d.ts +79 -0
  152. package/out/core/generate/UTGen.d.ts.map +1 -0
  153. package/out/core/generate/UTGen.js +795 -0
  154. package/out/core/generate/UTGen.js.map +1 -0
  155. package/out/core/llm/index.d.ts +9 -0
  156. package/out/core/llm/index.d.ts.map +1 -0
  157. package/out/core/llm/index.js +39 -0
  158. package/out/core/llm/index.js.map +1 -0
  159. package/out/core/llm/prompts/config.d.ts +6 -0
  160. package/out/core/llm/prompts/config.d.ts.map +1 -0
  161. package/out/core/llm/prompts/config.js +239 -0
  162. package/out/core/llm/prompts/config.js.map +1 -0
  163. package/out/core/llm/prompts/templates/common.d.ts +3 -0
  164. package/out/core/llm/prompts/templates/common.d.ts.map +1 -0
  165. package/out/core/llm/prompts/templates/common.js +27 -0
  166. package/out/core/llm/prompts/templates/common.js.map +1 -0
  167. package/out/core/llm/prompts/templates/fixCase.d.ts +4 -0
  168. package/out/core/llm/prompts/templates/fixCase.d.ts.map +1 -0
  169. package/out/core/llm/prompts/templates/fixCase.js +46 -0
  170. package/out/core/llm/prompts/templates/fixCase.js.map +1 -0
  171. package/out/core/llm/prompts/templates/fixLint.d.ts +3 -0
  172. package/out/core/llm/prompts/templates/fixLint.d.ts.map +1 -0
  173. package/out/core/llm/prompts/templates/fixLint.js +22 -0
  174. package/out/core/llm/prompts/templates/fixLint.js.map +1 -0
  175. package/out/core/llm/prompts/templates/genClassMemberUT.d.ts +5 -0
  176. package/out/core/llm/prompts/templates/genClassMemberUT.d.ts.map +1 -0
  177. package/out/core/llm/prompts/templates/genClassMemberUT.js +115 -0
  178. package/out/core/llm/prompts/templates/genClassMemberUT.js.map +1 -0
  179. package/out/core/llm/prompts/templates/genFuncUT.d.ts +4 -0
  180. package/out/core/llm/prompts/templates/genFuncUT.d.ts.map +1 -0
  181. package/out/core/llm/prompts/templates/genFuncUT.js +64 -0
  182. package/out/core/llm/prompts/templates/genFuncUT.js.map +1 -0
  183. package/out/core/llm/prompts/templates/mergeUT.d.ts +4 -0
  184. package/out/core/llm/prompts/templates/mergeUT.d.ts.map +1 -0
  185. package/out/core/llm/prompts/templates/mergeUT.js +106 -0
  186. package/out/core/llm/prompts/templates/mergeUT.js.map +1 -0
  187. package/out/core/llm/prompts/templates/msnStudio.d.ts +3 -0
  188. package/out/core/llm/prompts/templates/msnStudio.d.ts.map +1 -0
  189. package/out/core/llm/prompts/templates/msnStudio.js +36 -0
  190. package/out/core/llm/prompts/templates/msnStudio.js.map +1 -0
  191. package/out/core/llm/prompts/templates/snapshotUT.d.ts +4 -0
  192. package/out/core/llm/prompts/templates/snapshotUT.d.ts.map +1 -0
  193. package/out/core/llm/prompts/templates/snapshotUT.js +68 -0
  194. package/out/core/llm/prompts/templates/snapshotUT.js.map +1 -0
  195. package/out/core/llm/prompts/templates/updateSpecBlock.d.ts +3 -0
  196. package/out/core/llm/prompts/templates/updateSpecBlock.d.ts.map +1 -0
  197. package/out/core/llm/prompts/templates/updateSpecBlock.js +38 -0
  198. package/out/core/llm/prompts/templates/updateSpecBlock.js.map +1 -0
  199. package/out/core/llm/prompts/templates/updateSpecFile.d.ts +3 -0
  200. package/out/core/llm/prompts/templates/updateSpecFile.d.ts.map +1 -0
  201. package/out/core/llm/prompts/templates/updateSpecFile.js +30 -0
  202. package/out/core/llm/prompts/templates/updateSpecFile.js.map +1 -0
  203. package/out/core/llm/types.d.ts +80 -0
  204. package/out/core/llm/types.d.ts.map +1 -0
  205. package/out/core/llm/types.js +5 -0
  206. package/out/core/llm/types.js.map +1 -0
  207. package/out/core/quality/validateMockedTest.d.ts +3 -0
  208. package/out/core/quality/validateMockedTest.d.ts.map +1 -0
  209. package/out/core/quality/validateMockedTest.js +211 -0
  210. package/out/core/quality/validateMockedTest.js.map +1 -0
  211. package/out/core/utils/checkTestIgnore.d.ts +4 -0
  212. package/out/core/utils/checkTestIgnore.d.ts.map +1 -0
  213. package/out/core/utils/checkTestIgnore.js +52 -0
  214. package/out/core/utils/checkTestIgnore.js.map +1 -0
  215. package/out/core/utils/common.d.ts +4 -0
  216. package/out/core/utils/common.d.ts.map +1 -0
  217. package/out/core/utils/common.js +34 -0
  218. package/out/core/utils/common.js.map +1 -0
  219. package/out/core/utils/console.d.ts +8 -0
  220. package/out/core/utils/console.d.ts.map +1 -0
  221. package/out/core/utils/console.js +24 -0
  222. package/out/core/utils/console.js.map +1 -0
  223. package/out/core/utils/deps.d.ts +3 -0
  224. package/out/core/utils/deps.d.ts.map +1 -0
  225. package/out/core/utils/deps.js +58 -0
  226. package/out/core/utils/deps.js.map +1 -0
  227. package/out/core/utils/eslintRuleHandler.d.ts +3 -0
  228. package/out/core/utils/eslintRuleHandler.d.ts.map +1 -0
  229. package/out/core/utils/eslintRuleHandler.js +98 -0
  230. package/out/core/utils/eslintRuleHandler.js.map +1 -0
  231. package/out/core/utils/file.d.ts +18 -0
  232. package/out/core/utils/file.d.ts.map +1 -0
  233. package/out/core/utils/file.js +142 -0
  234. package/out/core/utils/file.js.map +1 -0
  235. package/out/core/utils/lint.d.ts +9 -0
  236. package/out/core/utils/lint.d.ts.map +1 -0
  237. package/out/core/utils/lint.js +95 -0
  238. package/out/core/utils/lint.js.map +1 -0
  239. package/out/core/utils/lru.d.ts +12 -0
  240. package/out/core/utils/lru.d.ts.map +1 -0
  241. package/out/core/utils/lru.js +47 -0
  242. package/out/core/utils/lru.js.map +1 -0
  243. package/out/core/utils/move.d.ts +12 -0
  244. package/out/core/utils/move.d.ts.map +1 -0
  245. package/out/core/utils/move.js +93 -0
  246. package/out/core/utils/move.js.map +1 -0
  247. package/out/core/utils/msnStudio.d.ts +13 -0
  248. package/out/core/utils/msnStudio.d.ts.map +1 -0
  249. package/out/core/utils/msnStudio.js +150 -0
  250. package/out/core/utils/msnStudio.js.map +1 -0
  251. package/out/core/utils/parseCustomizedCmd.d.ts +2 -0
  252. package/out/core/utils/parseCustomizedCmd.d.ts.map +1 -0
  253. package/out/core/utils/parseCustomizedCmd.js +32 -0
  254. package/out/core/utils/parseCustomizedCmd.js.map +1 -0
  255. package/out/core/utils/specBlock.d.ts +20 -0
  256. package/out/core/utils/specBlock.d.ts.map +1 -0
  257. package/out/core/utils/specBlock.js +231 -0
  258. package/out/core/utils/specBlock.js.map +1 -0
  259. package/out/core/utils/system.d.ts +13 -0
  260. package/out/core/utils/system.d.ts.map +1 -0
  261. package/out/core/utils/system.js +86 -0
  262. package/out/core/utils/system.js.map +1 -0
  263. package/out/core/utils/telemetry.d.ts +9 -0
  264. package/out/core/utils/telemetry.d.ts.map +1 -0
  265. package/out/core/utils/telemetry.js +32 -0
  266. package/out/core/utils/telemetry.js.map +1 -0
  267. package/out/core/utils/tsMorph.d.ts +13 -0
  268. package/out/core/utils/tsMorph.d.ts.map +1 -0
  269. package/out/core/utils/tsMorph.js +76 -0
  270. package/out/core/utils/tsMorph.js.map +1 -0
  271. package/out/core/valid/customizedLint.d.ts +2 -0
  272. package/out/core/valid/customizedLint.d.ts.map +1 -0
  273. package/out/core/valid/customizedLint.js +64 -0
  274. package/out/core/valid/customizedLint.js.map +1 -0
  275. package/out/core/valid/customizedTest.d.ts +3 -0
  276. package/out/core/valid/customizedTest.d.ts.map +1 -0
  277. package/out/core/valid/customizedTest.js +58 -0
  278. package/out/core/valid/customizedTest.js.map +1 -0
  279. package/out/core/valid/extractVitestConfig.d.ts +5 -0
  280. package/out/core/valid/extractVitestConfig.d.ts.map +1 -0
  281. package/out/core/valid/extractVitestConfig.js +97 -0
  282. package/out/core/valid/extractVitestConfig.js.map +1 -0
  283. package/out/core/valid/getViteConfig.d.ts +2 -0
  284. package/out/core/valid/getViteConfig.d.ts.map +1 -0
  285. package/out/core/valid/getViteConfig.js +65 -0
  286. package/out/core/valid/getViteConfig.js.map +1 -0
  287. package/out/core/valid/index.d.ts +15 -0
  288. package/out/core/valid/index.d.ts.map +1 -0
  289. package/out/core/valid/index.js +99 -0
  290. package/out/core/valid/index.js.map +1 -0
  291. package/out/core/valid/jest.d.ts +4 -0
  292. package/out/core/valid/jest.d.ts.map +1 -0
  293. package/out/core/valid/jest.js +121 -0
  294. package/out/core/valid/jest.js.map +1 -0
  295. package/out/core/valid/mock.d.ts +2 -0
  296. package/out/core/valid/mock.d.ts.map +1 -0
  297. package/out/core/valid/mock.js +149 -0
  298. package/out/core/valid/mock.js.map +1 -0
  299. package/out/core/valid/remove.d.ts +5 -0
  300. package/out/core/valid/remove.d.ts.map +1 -0
  301. package/out/core/valid/remove.js +109 -0
  302. package/out/core/valid/remove.js.map +1 -0
  303. package/out/core/valid/tag.d.ts +3 -0
  304. package/out/core/valid/tag.d.ts.map +1 -0
  305. package/out/core/valid/tag.js +91 -0
  306. package/out/core/valid/tag.js.map +1 -0
  307. package/out/core/valid/type.d.ts +83 -0
  308. package/out/core/valid/type.d.ts.map +1 -0
  309. package/out/core/valid/type.js +3 -0
  310. package/out/core/valid/type.js.map +1 -0
  311. package/out/core/valid/vitest.d.ts +3 -0
  312. package/out/core/valid/vitest.d.ts.map +1 -0
  313. package/out/core/valid/vitest.js +82 -0
  314. package/out/core/valid/vitest.js.map +1 -0
  315. package/out/index.d.ts +20 -0
  316. package/out/index.d.ts.map +1 -0
  317. package/out/index.js +60 -0
  318. package/out/index.js.map +1 -0
  319. package/out/setup.d.ts +11 -0
  320. package/out/setup.d.ts.map +1 -0
  321. package/out/setup.js +14 -0
  322. package/out/setup.js.map +1 -0
  323. package/out/types.d.ts +23 -0
  324. package/out/types.d.ts.map +1 -0
  325. package/out/types.js +3 -0
  326. package/out/types.js.map +1 -0
  327. package/package.json +39 -0
  328. package/package_devops.json +42 -0
@@ -0,0 +1,142 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.findProjectRoot = findProjectRoot;
7
+ exports.toUnixStyle = toUnixStyle;
8
+ exports.getFilesInDir = getFilesInDir;
9
+ exports.getPackagesFrom = getPackagesFrom;
10
+ exports.getNormalizedRelativePath = getNormalizedRelativePath;
11
+ const fs_1 = __importDefault(require("fs"));
12
+ const path_1 = __importDefault(require("path"));
13
+ function findProjectRoot(p, findTop = false, fileKey = 'package.json') {
14
+ if (!p || !path_1.default.isAbsolute(p)) {
15
+ return '';
16
+ }
17
+ let currentPath = p;
18
+ let last = '';
19
+ let res = '';
20
+ while (currentPath && last !== currentPath) {
21
+ if (fs_1.default.existsSync(path_1.default.join(currentPath, fileKey))) {
22
+ res = toUnixStyle(currentPath);
23
+ if (!findTop) {
24
+ return res;
25
+ }
26
+ }
27
+ last = currentPath;
28
+ currentPath = path_1.default.resolve(currentPath, '..');
29
+ }
30
+ return res;
31
+ }
32
+ function toUnixStyle(filePath) {
33
+ return filePath.replace(/\\/g, "/");
34
+ }
35
+ function isTsFile(filePath) {
36
+ const isCode = filePath.endsWith('.ts')
37
+ || filePath.endsWith('.tsx')
38
+ || filePath.endsWith('.js')
39
+ || filePath.endsWith('.jsx');
40
+ const isTest = filePath.includes('.spec.')
41
+ || filePath.includes('.test.');
42
+ return isCode && !isTest;
43
+ }
44
+ function getFilesInDir(dirPath, options) {
45
+ const files = [];
46
+ if (!fs_1.default.existsSync(dirPath)) {
47
+ return files;
48
+ }
49
+ const fileFilter = options?.filter || isTsFile;
50
+ if (!fs_1.default.statSync(dirPath).isDirectory()) {
51
+ return fileFilter(dirPath) ? [dirPath] : [];
52
+ }
53
+ const ignoreDir = options?.ignoreDir || new Set(['node_modules', 'dist', 'out']);
54
+ function readDirRecursively(currentPath) {
55
+ if (!fs_1.default.existsSync(currentPath)) {
56
+ return;
57
+ }
58
+ const src = path_1.default.join(currentPath, options?.skipFolderName || 'src');
59
+ if (fs_1.default.existsSync(src)) {
60
+ return readDirRecursively(src);
61
+ }
62
+ const items = fs_1.default.readdirSync(currentPath);
63
+ for (const item of items) {
64
+ const itemPath = path_1.default.join(currentPath, item);
65
+ if (fs_1.default.statSync(itemPath).isDirectory()) {
66
+ if (ignoreDir.has(item)) {
67
+ continue;
68
+ }
69
+ readDirRecursively(itemPath);
70
+ }
71
+ else {
72
+ fileFilter(itemPath) && files.push(toUnixStyle(itemPath));
73
+ }
74
+ }
75
+ }
76
+ readDirRecursively(dirPath);
77
+ return files;
78
+ }
79
+ function findLeafPackages(dirPath, options) {
80
+ if (!fs_1.default.existsSync(dirPath)) {
81
+ return [];
82
+ }
83
+ const ignoreDir = options?.ignoreDir || new Set(['node_modules', 'dist', 'out']);
84
+ function dfs(dir) {
85
+ // have src should be a single package
86
+ if (fs_1.default.existsSync(path_1.default.resolve(dir, options?.skipFolderName || 'src'))) {
87
+ return [toUnixStyle(dir)];
88
+ }
89
+ const files = fs_1.default.readdirSync(dir);
90
+ let res = [];
91
+ for (const file of files) {
92
+ if (!fs_1.default.lstatSync(path_1.default.resolve(dir, file)).isDirectory() || ignoreDir.has(file) || file.startsWith('.')) {
93
+ continue;
94
+ }
95
+ res = res.concat(dfs(path_1.default.resolve(dir, file)));
96
+ }
97
+ if (res.length) {
98
+ return res;
99
+ }
100
+ const hasPackageJson = fs_1.default.existsSync(path_1.default.resolve(dir, 'package.json'));
101
+ if (hasPackageJson) {
102
+ return [toUnixStyle(dir)];
103
+ }
104
+ return [];
105
+ }
106
+ return dfs(dirPath);
107
+ }
108
+ function getPackagesFrom(inputPath, options) {
109
+ if (!fs_1.default.existsSync(inputPath)) {
110
+ return [];
111
+ }
112
+ if (fs_1.default.statSync(inputPath).isFile()) {
113
+ const packageRoot = findProjectRoot(inputPath);
114
+ return [{
115
+ packagePath: packageRoot || toUnixStyle(path_1.default.dirname(inputPath)),
116
+ targetFiles: isTsFile(inputPath) ? [toUnixStyle(inputPath)] : []
117
+ }];
118
+ }
119
+ const packages = findLeafPackages(inputPath, options);
120
+ if (packages.length) {
121
+ return packages.map(p => ({
122
+ packagePath: p,
123
+ targetFiles: getFilesInDir(p, options)
124
+ }));
125
+ }
126
+ const packageRoot = findProjectRoot(inputPath);
127
+ return [{
128
+ packagePath: packageRoot || toUnixStyle(path_1.default.dirname(inputPath)),
129
+ targetFiles: getFilesInDir(inputPath, options)
130
+ }];
131
+ }
132
+ function getNormalizedRelativePath(from, to) {
133
+ let relativePath = path_1.default.relative(from, to);
134
+ if (!relativePath) {
135
+ return './';
136
+ }
137
+ if (!/^\.\.?[\\/]/.test(relativePath)) {
138
+ relativePath = './' + relativePath;
139
+ }
140
+ return toUnixStyle(relativePath);
141
+ }
142
+ //# sourceMappingURL=file.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file.js","sourceRoot":"","sources":["../../../src/core/utils/file.ts"],"names":[],"mappings":";;;;;AAIA,0CAkBC;AAED,kCAEC;AAaD,sCA0CC;AA2CD,0CA6BC;AAED,8DAYC;AAvKD,4CAAoB;AACpB,gDAAwB;AAGxB,SAAgB,eAAe,CAAC,CAAS,EAAE,OAAO,GAAG,KAAK,EAAE,OAAO,GAAG,cAAc;IAChF,IAAI,CAAC,CAAC,IAAI,CAAC,cAAI,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC;QAC5B,OAAO,EAAE,CAAC;IACd,CAAC;IACD,IAAI,WAAW,GAAG,CAAC,CAAC;IACpB,IAAI,IAAI,GAAG,EAAE,CAAC;IACd,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,OAAO,WAAW,IAAI,IAAI,KAAK,WAAW,EAAE,CAAC;QACzC,IAAI,YAAE,CAAC,UAAU,CAAC,cAAI,CAAC,IAAI,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC,EAAE,CAAC;YACjD,GAAG,GAAG,WAAW,CAAC,WAAW,CAAC,CAAC;YAC/B,IAAI,CAAC,OAAO,EAAE,CAAC;gBACX,OAAO,GAAG,CAAC;YACf,CAAC;QACL,CAAC;QACD,IAAI,GAAG,WAAW,CAAC;QACnB,WAAW,GAAG,cAAI,CAAC,OAAO,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;IAClD,CAAC;IACD,OAAO,GAAG,CAAC;AACf,CAAC;AAED,SAAgB,WAAW,CAAC,QAAgB;IACxC,OAAO,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;AACxC,CAAC;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AC,SAAS,CAAC,CAAC;gBAChE,WAAW,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE;aACnE,CAAC,CAAC;IACP,CAAC;IAED,MAAM,QAAQ,GAAG,gBAAgB,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;IACtD,IAAI,QAAQ,CAAC,MAAM,EAAE,CAAC;QAClB,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;YACtB,WAAW,EAAE,CAAC;YACd,WAAW,EAAE,aAAa,CAAC,CAAC,EAAE,OAAO,CAAC;SACzC,CAAC,CAAC,CAAC;IACR,CAAC;IAED,MAAM,WAAW,GAAG,eAAe,CAAC,SAAS,CAAC,CAAC;IAC/C,OAAO,CAAC;YACJ,WAAW,EAAE,WAAW,IAAI,WAAW,CAAC,cAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;YAChE,WAAW,EAAE,aAAa,CAAC,SAAS,EAAE,OAAO,CAAC;SACjD,CAAC,CAAC;AACP,CAAC;AAED,SAAgB,yBAAyB,CAAC,IAAI,EAAE,EAAE;IAC9C,IAAI,YAAY,GAAG,cAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IAE3C,IAAI,CAAC,YAAY,EAAE,CAAC;QAChB,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,YAAY,CAAC,EAAE,CAAC;QACpC,YAAY,GAAG,IAAI,GAAG,YAAY,CAAC;IACvC,CAAC;IAED,OAAO,WAAW,CAAC,YAAY,CAAC,CAAC;AACrC,CAAC"}
@@ -0,0 +1,9 @@
1
+ export declare function runLint(filePath: string, rootDir?: string): Promise<void>;
2
+ export declare function runLintWithAutofix(filePath: string, testFramework: string, abortSignal: AbortSignal, rootDir?: string): Promise<{
3
+ success: boolean;
4
+ errors?: undefined;
5
+ } | {
6
+ success: boolean;
7
+ errors: any;
8
+ }>;
9
+ //# sourceMappingURL=lint.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lint.d.ts","sourceRoot":"","sources":["../../../src/core/utils/lint.ts"],"names":[],"mappings":"AAYA,wBAAsB,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,iBAM/D;AAED,wBAAsB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,MAAM;;;;;;GAwE3H"}
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.runLint = runLint;
7
+ exports.runLintWithAutofix = runLintWithAutofix;
8
+ const eslintRuleHandler_1 = require("./eslintRuleHandler");
9
+ const constants_1 = require("../constants");
10
+ const eslint_1 = require("../valid/eslint");
11
+ const lintFix_1 = require("../features/lintFix");
12
+ const fs_1 = __importDefault(require("fs"));
13
+ const config_1 = require("../config");
14
+ const console_1 = require("./console");
15
+ const path_1 = __importDefault(require("path"));
16
+ const customizedLint_1 = require("../valid/customizedLint");
17
+ const valid_1 = require("../valid");
18
+ async function runLint(filePath, rootDir) {
19
+ const cwd = rootDir ?? path_1.default.dirname(filePath);
20
+ (0, console_1.getConsole)().log(`Running lint for ${filePath}`);
21
+ // run twice to make sure the lint is correct
22
+ await (0, eslint_1.ensureExecLint)(filePath, cwd);
23
+ (0, console_1.getConsole)().log(`Lint done for ${filePath}`);
24
+ }
25
+ async function runLintWithAutofix(filePath, testFramework, abortSignal, rootDir) {
26
+ const cwd = rootDir ?? path_1.default.dirname(filePath);
27
+ (0, console_1.getConsole)().log(`Running lint for ${filePath}`);
28
+ let originalTestCode = fs_1.default.readFileSync(filePath, 'utf-8');
29
+ let originalLintErrors;
30
+ const isCustomizedLint = !!(0, config_1.getConfig)().common.customizedLintCmd;
31
+ let lastestLintErrors;
32
+ for (let i = 0; i <= constants_1.DEFAULT_RETRY_TIMES; i++) {
33
+ lastestLintErrors = isCustomizedLint ? await (0, customizedLint_1.runCustomizedLint)(filePath, abortSignal) : await (0, eslint_1.ensureExecLint)(filePath, cwd);
34
+ if (!lastestLintErrors || lastestLintErrors.length === 0) {
35
+ (0, console_1.getConsole)().log(`Lint Fix done for ${filePath}`);
36
+ return { success: true };
37
+ }
38
+ if (!originalLintErrors) {
39
+ originalLintErrors = lastestLintErrors;
40
+ }
41
+ // if last iteration, break
42
+ if (i === constants_1.DEFAULT_RETRY_TIMES) {
43
+ break;
44
+ }
45
+ (0, console_1.getConsole)().error(`Lint error found for ${filePath}, lint error count: ${lastestLintErrors?.length}`);
46
+ const formattedLintErrorsStr = lastestLintErrors.join('\n');
47
+ const fixedTestCode = await (0, lintFix_1.fixLintErrors)(filePath, formattedLintErrorsStr, testFramework);
48
+ if (!fixedTestCode) {
49
+ (0, console_1.getConsole)().error(`Failed to generate test code to fix lint issues for ${filePath}`);
50
+ continue;
51
+ }
52
+ (0, console_1.getConsole)().log(`Generate fixed test code for lint issues successfully for ${filePath}`);
53
+ // run test to verify the fix
54
+ fs_1.default.writeFileSync(filePath, fixedTestCode, 'utf-8');
55
+ }
56
+ const testResult = await (0, valid_1.runTest)(testFramework, filePath, {
57
+ projectFolder: rootDir,
58
+ abortSignal
59
+ });
60
+ if (testResult?.success) {
61
+ // use the fixed code for next iteration
62
+ (0, console_1.getConsole)().log(`Test passed for lint fixed code`);
63
+ }
64
+ else {
65
+ fs_1.default.writeFileSync(filePath, originalTestCode, 'utf-8');
66
+ (0, console_1.getConsole)().log(`Test is not passed for lint fixed code, write back original code`);
67
+ }
68
+ (0, console_1.getConsole)().error(`Failed to fix lint errors by LLM for ${filePath}`);
69
+ const ruleErrors = (0, eslintRuleHandler_1.getRuleErrors)(lastestLintErrors);
70
+ if (ruleErrors.length === lastestLintErrors.length) {
71
+ (0, console_1.getConsole)().log(`Start to disable eslint rules: ${filePath}`);
72
+ const ruleKeys = Array.from(new Set(ruleErrors.map(e => e.rule)));
73
+ // if LLM can't resolve the lint errors, disable the lint rules
74
+ const disabledLintRulesCode = (0, eslintRuleHandler_1.disableLintRules)(originalTestCode, ruleKeys);
75
+ fs_1.default.writeFileSync(filePath, disabledLintRulesCode, 'utf-8');
76
+ (0, console_1.getConsole)().log(`Fix lint errors by disabling eslint rules`);
77
+ return { success: true, errors: lastestLintErrors };
78
+ }
79
+ else {
80
+ const lineErrorsStr = lastestLintErrors.join('\n');
81
+ (0, console_1.getConsole)().error(`Disable eslint rules can't fix lint errors: ${filePath}\n${lineErrorsStr}`);
82
+ }
83
+ return { success: false, errors: lastestLintErrors };
84
+ }
85
+ // runLint("D:\\code\\studio\\test\\unit\\components\\answer-cards\\shopping-card\\shopping-curated-card\\shopping-curated-card.spec\\shopping-curated-card.test.tsx", "D:\\code\\studio");
86
+ // runLintWithAutofix("D:\\code\\AdsAppsCampaignUI\\private\\ads-copilot\\packages\\copilot-layout-provider\\formal-jest-overwrite\\index.spec\\CopilotLayoutProvider.web.spec.tsx", "jest", new AbortController().signal);
87
+ // runLintWithAutofix("D:\\code\\studio\\test\\unit\\components\\answer-cards\\shopping-card\\shopping-curated-card\\shopping-curated-fashion-card.spec\\shopping-curated-fashion-card.test.tsx", "vitest", new AbortController().signal, "D:\\code\\studio");
88
+ // runLint("D:\\code\\msnews-experiences\\experiences\\weather-home-page\\src\\entry\\WeatherHomePage.spec\\WeatherHomePage.cleanup.web.spec.tsx", "D:\\code\\msnews-experiences");
89
+ // ensureExecLint("D:\\code\\studio\\test\\unit\\components\\answer-cards\\shopping-card\\shopping-curated-card\\shopping-curated-card.spec\\shopping-curated-card.test.tsx", "D:\\code\\studio").then((lintErrors) => {
90
+ // const normalizedLintErrors = normalizeLintErrors(lintErrors);
91
+ // const testCode = fs.readFileSync("D:\\code\\studio\\test\\unit\\components\\answer-cards\\shopping-card\\shopping-curated-card\\shopping-curated-card.spec\\shopping-curated-card.test.tsx", 'utf-8');
92
+ // const disabledLintRulesCode = disableLintRules(testCode, normalizedLintErrors);
93
+ // fs.writeFileSync("D:\\code\\studio\\test\\unit\\components\\answer-cards\\shopping-card\\shopping-curated-card\\shopping-curated-card.spec\\shopping-curated-card.test.tsx", disabledLintRulesCode, 'utf-8');
94
+ // });
95
+ //# sourceMappingURL=lint.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lint.js","sourceRoot":"","sources":["../../../src/core/utils/lint.ts"],"names":[],"mappings":";;;;;AAYA,0BAMC;AAED,gDAwEC;AA5FD,2DAAsE;AAEtE,4CAAmD;AACnD,4CAAiD;AACjD,iDAAoD;AACpD,4CAAoB;AACpB,sCAAsC;AACtC,uCAAuC;AACvC,gDAAwB;AACxB,4DAA4D;AAC5D,oCAAmC;AAE5B,KAAK,UAAU,OAAO,CAAC,QAAgB,EAAE,OAAgB;IAC5D,MAAM,GAAG,GAAG,OAAO,IAAI,cAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC9C,IAAA,oBAAU,GAAE,CAAC,GAAG,CAAC,oBAAoB,QAAQ,EAAE,CAAC,CAAC;IACjD,6CAA6C;IAC7C,MAAM,IAAA,uBAAc,EAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;IACpC,IAAA,oBAAU,GAAE,CAAC,GAAG,CAAC,iBAAiB,QAAQ,EAAE,CAAC,CAAC;AAClD,CAAC;AAEM,KAAK,UAAU,kBAAkB,CAAC,QAAgB,EAAE,aAAqB,EAAE,WAAwB,EAAE,OAAgB;IACxH,MAAM,GAAG,GAAG,OAAO,IAAI,cAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC9C,IAAA,oBAAU,GAAE,CAAC,GAAG,CAAC,oBAAoB,QAAQ,EAAE,CAAC,CAAC;IAEjD,IAAI,gBAAgB,GAAG,YAAE,CAAC,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;QAC3D,IAAA,oBAAU,GAAE,CAAC,GAAG,CAAC,2CAA2C,CAAC,CAAC;QAC9D,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,iBAAiB,EAAE,CAAC;IACxD,CAAC;SAAM,CAAC;QACJ,MAAM,aAAa,GAAG,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACnD,IAAA,oBAAU,GAAE,CAAC,KAAK,CAAC,+CAA+C,QAAQ,KAAK,aAAa,EAAE,CAAC,CAAC;IACpG,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,iBAAiB,EAAE,CAAC;AACzD,CAAC;AAGD,2LAA2L;AAC3L,2NAA2N;AAC3N,8PAA8P;AAC9P,mLAAmL;AACnL,wNAAwN;AACxN,oEAAoE;AACpE,6MAA6M;AAC7M,sFAAsF;AACtF,oNAAoN;AACpN,MAAM"}
@@ -0,0 +1,12 @@
1
+ export declare class LRU<TKey, TValue> {
2
+ #private;
3
+ constructor(capacity: number);
4
+ get(key: TKey): TValue | null;
5
+ set(key: TKey, value: TValue): void;
6
+ has(key: TKey): boolean;
7
+ values(): TValue[];
8
+ clear(): void;
9
+ get size(): number;
10
+ get capacity(): number;
11
+ }
12
+ //# sourceMappingURL=lru.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lru.d.ts","sourceRoot":"","sources":["../../../src/core/utils/lru.ts"],"names":[],"mappings":"AAAA,qBAAa,GAAG,CAAC,IAAI,EAAE,MAAM;;gBAIb,QAAQ,EAAE,MAAM;IAK5B,GAAG,CAAC,GAAG,EAAE,IAAI,GAAG,MAAM,GAAG,IAAI;IAU7B,GAAG,CAAC,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAUnC,GAAG,CAAC,GAAG,EAAE,IAAI,GAAG,OAAO;IAIvB,MAAM,IAAI,MAAM,EAAE;IAIlB,KAAK,IAAI,IAAI;IAIb,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,IAAI,QAAQ,IAAI,MAAM,CAErB;CACJ"}
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LRU = void 0;
4
+ class LRU {
5
+ #capacity;
6
+ #cache;
7
+ constructor(capacity) {
8
+ this.#capacity = capacity;
9
+ this.#cache = new Map();
10
+ }
11
+ get(key) {
12
+ if (!this.#cache.has(key)) {
13
+ return null;
14
+ }
15
+ const value = this.#cache.get(key);
16
+ this.#cache.delete(key);
17
+ this.#cache.set(key, value);
18
+ return value;
19
+ }
20
+ set(key, value) {
21
+ if (this.#cache.has(key)) {
22
+ this.#cache.delete(key);
23
+ }
24
+ else if (this.#cache.size >= this.#capacity) {
25
+ const firstKey = this.#cache.keys().next().value;
26
+ this.#cache.delete(firstKey);
27
+ }
28
+ this.#cache.set(key, value);
29
+ }
30
+ has(key) {
31
+ return this.#cache.has(key);
32
+ }
33
+ values() {
34
+ return Array.from(this.#cache.values());
35
+ }
36
+ clear() {
37
+ this.#cache.clear();
38
+ }
39
+ get size() {
40
+ return this.#cache.size;
41
+ }
42
+ get capacity() {
43
+ return this.#capacity;
44
+ }
45
+ }
46
+ exports.LRU = LRU;
47
+ //# sourceMappingURL=lru.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lru.js","sourceRoot":"","sources":["../../../src/core/utils/lru.ts"],"names":[],"mappings":";;;AAAA,MAAa,GAAG;IACZ,SAAS,CAAS;IAClB,MAAM,CAAoB;IAE1B,YAAY,QAAgB;QACxB,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;QAC1B,IAAI,CAAC,MAAM,GAAG,IAAI,GAAG,EAAE,CAAC;IAC5B,CAAC;IAED,GAAG,CAAC,GAAS;QACT,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YACxB,OAAO,IAAI,CAAC;QAChB,CAAC;QACD,MAAM,KAAK,GAAG,IAA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* @param srcDir source directory where the file is located
4
+ * @param destDir destination directory where the file will be moved
5
+ * @param filename name of the file to update
6
+ * @param content content of the file to update
7
+ * @returns updated content of the file with references to the source directory updated to the destination directory.
8
+ * If the source and destination directories are the same, returns null.
9
+ */
10
+ export declare function updateCodeReferences(srcDir: string, destDir: string, filename: string, content: string): Promise<string>;
11
+ export declare function moveFile(srcDir: string, destDir: string, filename: string): Promise<string>;
12
+ //# sourceMappingURL=move.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"move.d.ts","sourceRoot":"","sources":["../../../src/core/utils/move.ts"],"names":[],"mappings":"AAcA;;;;;;;;GAQG;AACH,wBAAsB,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAuD9H;AAED,wBAAsB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAmBjG"}
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.updateCodeReferences = updateCodeReferences;
7
+ exports.moveFile = moveFile;
8
+ const ts_morph_1 = require("ts-morph");
9
+ const fs_extra_1 = __importDefault(require("fs-extra"));
10
+ const path_1 = __importDefault(require("path"));
11
+ const file_1 = require("./file");
12
+ const importFuncs = new Set([
13
+ 'require',
14
+ 'jest.mock',
15
+ 'jest.requireActual',
16
+ 'vi.mock',
17
+ 'vi.importActual',
18
+ 'import'
19
+ ]);
20
+ /**
21
+ * In memory update of code references in a file.
22
+ * @param srcDir source directory where the file is located
23
+ * @param destDir destination directory where the file will be moved
24
+ * @param filename name of the file to update
25
+ * @param content content of the file to update
26
+ * @returns updated content of the file with references to the source directory updated to the destination directory.
27
+ * If the source and destination directories are the same, returns null.
28
+ */
29
+ async function updateCodeReferences(srcDir, destDir, filename, content) {
30
+ if ((0, file_1.toUnixStyle)(srcDir) === (0, file_1.toUnixStyle)(destDir)) {
31
+ return content;
32
+ }
33
+ const oldPath = path_1.default.join(srcDir, filename);
34
+ const project = new ts_morph_1.Project({
35
+ useInMemoryFileSystem: true,
36
+ skipAddingFilesFromTsConfig: true,
37
+ skipFileDependencyResolution: true,
38
+ skipLoadingLibFiles: true,
39
+ compilerOptions: {
40
+ allowJs: true,
41
+ checkJs: false
42
+ },
43
+ });
44
+ const sourceFile = project.createSourceFile(oldPath, content, { overwrite: true });
45
+ const updatePath = (oldImportPath) => {
46
+ const absoluteOldImportPath = path_1.default.resolve(srcDir, oldImportPath);
47
+ let relativePath = (0, file_1.toUnixStyle)(path_1.default.relative(destDir, absoluteOldImportPath));
48
+ if (!relativePath.startsWith('.')) {
49
+ relativePath = './' + relativePath;
50
+ }
51
+ return relativePath;
52
+ };
53
+ // import statements
54
+ sourceFile.getImportDeclarations().forEach(importDecl => {
55
+ const oldImport = importDecl.getModuleSpecifierValue();
56
+ if (oldImport.startsWith('.')) {
57
+ importDecl.setModuleSpecifier(updatePath(oldImport));
58
+ }
59
+ });
60
+ // export statements & test framework functions
61
+ sourceFile.getDescendantsOfKind(ts_morph_1.ts.SyntaxKind.CallExpression).forEach(callExpr => {
62
+ const expression = callExpr.getExpression();
63
+ if (!importFuncs.has(expression.getText())) {
64
+ return;
65
+ }
66
+ const args = callExpr.getArguments();
67
+ if (!ts_morph_1.ts.isStringLiteral(args[0].compilerNode)) {
68
+ return;
69
+ }
70
+ const argValue = args[0].getText().slice(1, -1);
71
+ if (argValue.startsWith('.')) {
72
+ args[0].replaceWithText(`'${updatePath(argValue)}'`);
73
+ }
74
+ });
75
+ return sourceFile.getFullText();
76
+ }
77
+ async function moveFile(srcDir, destDir, filename) {
78
+ const oldPath = path_1.default.join(srcDir, filename);
79
+ const newPath = path_1.default.join(destDir, filename);
80
+ if (!await fs_extra_1.default.pathExists(oldPath)) {
81
+ throw new Error(`Source file does not exist: ${oldPath}`);
82
+ }
83
+ const content = await fs_extra_1.default.readFile(oldPath, 'utf8');
84
+ const updatedContent = await updateCodeReferences(srcDir, destDir, filename, content);
85
+ if (updatedContent === content) {
86
+ return newPath;
87
+ }
88
+ await fs_extra_1.default.ensureDir(destDir);
89
+ await fs_extra_1.default.writeFile(newPath, updatedContent, 'utf8');
90
+ await fs_extra_1.default.remove(oldPath);
91
+ return newPath;
92
+ }
93
+ //# sourceMappingURL=move.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"move.js","sourceRoot":"","sources":["../../../src/core/utils/move.ts"],"names":[],"mappings":";;;;;AAuBA,oDAuDC;AAED,4BAmBC;AAnGD,uCAAuC;AACvC,wDAA0B;AAC1B,gDAAwB;AACxB,iCAAqC;AAErC,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC;IACxB,SAAS;IACT,WAAW;IACX,oBAAoB;IACpB,SAAS;IACT,iBAAiB;IACjB,QAAQ;CACX,CAAC,CAAC;AAEH;;;;;;;;GAQG;AACI,KAAK,UAAU,oBAAoB,CAAC,MAAc,EAAE,OAAe,EAAE,QAAgB,EAAE,OAAe;IACzG,IAAI,IAAA,kBAAW,EAAC,MAAM,CAAC,KAAK,IAAA,kBAAW,EAAC,OAAO,CAAC,EAAE,CAAC;QAC/C,OAAO,OAAO,CAAC;IACnB,CAAC;IAED,MAAM,OAAO,GAAG,cAAI,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IAE5C,MAAM,OAAO,GAAG,IAAI,kBAAO,CAAC;QACxB,qBAAqB,EAAE,IAAI;QAC3B,2BAA2B,EAAE,IAAI;QACjC,4BAA4B,EAAE,IAAI;QAClC,mBAAmB,EAAE,IAAI;QACzB,eAAe,EAAE;YACb,OAAO,EAAE,IAAI;YACb,OAAO,EAAE,KAAK;SACjB;KACJ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,MAAM,CAAC,OAAO,CAAC,CAAC;IACzB,OAAO,OAAO,CAAC;AACnB,CAAC"}
@@ -0,0 +1,13 @@
1
+ export declare function initializeDoc(workspacePath: string, category: string, component: string, folderPath: string, ownership: string): Promise<string>;
2
+ export declare function getPackageDocInitParams(filePath: string, options?: {
3
+ componentName?: string;
4
+ category?: string;
5
+ ownership?: string;
6
+ }): Promise<{
7
+ packagePath: string;
8
+ packageName: any;
9
+ docPath: string;
10
+ depDocs: string[];
11
+ packageIndexPath: string;
12
+ }>;
13
+ //# sourceMappingURL=msnStudio.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"msnStudio.d.ts","sourceRoot":"","sources":["../../../src/core/utils/msnStudio.ts"],"names":[],"mappings":"AAMA,wBAAgB,aAAa,CACzB,aAAa,EAAE,MAAM,EACrB,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,GAClB,OAAO,CAAC,MAAM,CAAC,CAiCjB;AAED,wBAAsB,uBAAuB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;IACtE,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAA;CACrB;;;;;;GAgDA"}
@@ -0,0 +1,150 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.initializeDoc = initializeDoc;
7
+ exports.getPackageDocInitParams = getPackageDocInitParams;
8
+ const child_process_1 = require("child_process");
9
+ const path_1 = __importDefault(require("path"));
10
+ const fs_1 = __importDefault(require("fs"));
11
+ const fast_glob_1 = require("fast-glob");
12
+ const file_1 = require("./file");
13
+ function initializeDoc(workspacePath, category, component, folderPath, ownership) {
14
+ return new Promise((resolve, reject) => {
15
+ const dashedCategory = category.trim().replace(/\s+/g, "-").toLowerCase();
16
+ const dashedComponent = component.trim().replace(/\s+/g, "-").toLowerCase();
17
+ const upperCaseCategory = category.trim().replace(/\b\w/g, c => c.toUpperCase());
18
+ (0, child_process_1.execFile)("node", [
19
+ "./build/scripts/msnStudio/onboardNewComponent.js",
20
+ `--category="${upperCaseCategory}"`,
21
+ `--component="${component.trim()}"`,
22
+ `--folderPath="${folderPath.trim()}"`,
23
+ `--ownership="${ownership.trim()}"`
24
+ ], { cwd: workspacePath, shell: true }, (error, stdout, stderr) => {
25
+ if (error) {
26
+ reject(`Error initializing doc: ${error.message}`);
27
+ return;
28
+ }
29
+ const docName = path_1.default.resolve(workspacePath, `./experiences/msn-studio/src/components/${dashedCategory}/${dashedComponent}`);
30
+ const suffixes = ['.doc.ts', '.doc.tsx'];
31
+ for (const suffix of suffixes) {
32
+ const docFile = docName + suffix;
33
+ if (fs_1.default.existsSync(docFile)) {
34
+ return resolve(docFile);
35
+ }
36
+ }
37
+ resolve('');
38
+ });
39
+ });
40
+ }
41
+ async function getPackageDocInitParams(filePath, options) {
42
+ const workspacePath = (0, file_1.findProjectRoot)(filePath, true);
43
+ if (!workspacePath) {
44
+ throw new Error(`Cannot find workspace root for the path: ${filePath}. Please provide a valid package path.`);
45
+ }
46
+ const packageRoot = (0, file_1.findProjectRoot)(filePath);
47
+ let docName = options?.componentName || '';
48
+ const packageJsonPath = path_1.default.join(packageRoot, "package.json");
49
+ const packageJson = JSON.parse(fs_1.default.readFileSync(packageJsonPath, "utf-8"));
50
+ if (!docName) {
51
+ if (packageJson.name) {
52
+ docName = packageJson.name?.replace('@msnews/', '').split('-').map(el => el.charAt(0).toUpperCase() + el.slice(1)).join(' ');
53
+ }
54
+ else {
55
+ // just in case
56
+ docName = path_1.default.basename(packageRoot);
57
+ }
58
+ }
59
+ const docPath = await initializeDoc(workspacePath, options?.category || 'Common', docName, path_1.default.join(packageRoot, 'src'), options?.ownership || '');
60
+ if (!docPath) {
61
+ throw new Error(`Failed to create documentation for the component: ${docName}. Please check the provided paths and try again.`);
62
+ }
63
+ const depDocs = findDependentDocs(packageRoot, workspacePath).filter(doc => doc !== docPath);
64
+ const indexTs = path_1.default.join(packageRoot, 'src', 'index.ts');
65
+ const indexTsx = path_1.default.join(packageRoot, 'src', 'index.tsx');
66
+ let packageIndexPath = packageJsonPath;
67
+ if (fs_1.default.existsSync(indexTs)) {
68
+ packageIndexPath = indexTs;
69
+ }
70
+ else if (fs_1.default.existsSync(indexTsx)) {
71
+ packageIndexPath = indexTsx;
72
+ }
73
+ return {
74
+ packagePath: `./${(0, file_1.toUnixStyle)(path_1.default.relative(workspacePath, filePath))}`,
75
+ packageName: packageJson.name || docName,
76
+ docPath: `./${(0, file_1.toUnixStyle)(path_1.default.relative(workspacePath, docPath))}`,
77
+ depDocs: depDocs,
78
+ packageIndexPath: `./${(0, file_1.toUnixStyle)(path_1.default.relative(workspacePath, packageIndexPath))}`
79
+ };
80
+ }
81
+ function findDependentDocs(pkgPath, workspacePath) {
82
+ const deps = getDependentUXPackages(pkgPath);
83
+ let docs = [];
84
+ for (const dep of deps) {
85
+ const docFiles = getPackageDocFiles(dep);
86
+ if (docFiles.length > 0) {
87
+ docs = docs.concat(docFiles.map(file => path_1.default.relative(workspacePath, file)));
88
+ }
89
+ }
90
+ return docs;
91
+ }
92
+ const UXPackageReg = /\/(components|experiences|web-components|cs-core-desktop|cs-core-mobile)\//;
93
+ /**
94
+ * Finds all dependent UX packages for a given package path.
95
+ * @param packagePath The absolute path to the package to find dependent UX packages.
96
+ * @returns
97
+ */
98
+ function getDependentUXPackages(packagePath) {
99
+ const packageRoot = (0, file_1.findProjectRoot)(packagePath);
100
+ if (!packagePath) {
101
+ return [];
102
+ }
103
+ const packageJsonPath = path_1.default.join(packageRoot, "package.json");
104
+ const packageJson = JSON.parse(fs_1.default.readFileSync(packageJsonPath, "utf-8"));
105
+ const dependencies = {
106
+ ...packageJson.dependencies,
107
+ ...packageJson.devDependencies,
108
+ };
109
+ return Array.from(Object.keys(dependencies)).reduce((res, depKey) => {
110
+ if (!depKey.startsWith('@msnews/')) {
111
+ return res;
112
+ }
113
+ let depPath = dependencies[depKey];
114
+ if (!depPath?.startsWith('file:') || !UXPackageReg.test(depPath)) {
115
+ return res;
116
+ }
117
+ const depPackagePath = path_1.default.join(packageRoot, depPath.replace('file:', '').trim());
118
+ res.push({
119
+ name: depKey,
120
+ path: depPackagePath
121
+ });
122
+ return res;
123
+ }, []);
124
+ }
125
+ /**
126
+ * Finds the MSN Studio documentation file for a given package.
127
+ * @param pkg package to find the documentation file for.
128
+ * @param projectRoot optional project root path, if not provided, will find the project root from the package path.
129
+ * @returns An array of documentation file paths that match the package name.
130
+ */
131
+ function getPackageDocFiles(pkg, projectRoot) {
132
+ const peregrineRoot = projectRoot || (0, file_1.findProjectRoot)(pkg.path, true);
133
+ if (!peregrineRoot) {
134
+ return [];
135
+ }
136
+ const docsFolder = path_1.default.join(peregrineRoot, 'experiences/msn-studio/src/components');
137
+ const docFiles = (0, fast_glob_1.sync)([
138
+ '**/*.doc.ts',
139
+ '**/*.doc.tsx',
140
+ ], {
141
+ cwd: docsFolder,
142
+ onlyFiles: true,
143
+ absolute: true,
144
+ });
145
+ return docFiles.filter(file => {
146
+ const content = fs_1.default.readFileSync(file, 'utf-8');
147
+ return content.includes(pkg.name);
148
+ });
149
+ }
150
+ //# sourceMappingURL=msnStudio.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"msnStudio.js","sourceRoot":"","sources":["../../../src/core/utils/msnStudio.ts"],"names":[],"mappings":";;;;;AAMA,sCAuCC;AAED,0DAoDC;AAnGD,iDAAyC;AACzC,gDAAwB;AACxB,4CAAoB;AACpB,yCAAiC;AACjC,iCAAsD;AAEtD,SAAgB,aAAa,CACzB,aAAqB,EACrB,QAAgB,EAChB,SAAiB,EACjB,UAAkB,EAClB,SAAiB;IAEjB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,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0 +1,2 @@
1
+ export declare function parseCustomizedCmd(customizedCmds: string, testFilePath: string): any[];
2
+ //# sourceMappingURL=parseCustomizedCmd.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parseCustomizedCmd.d.ts","sourceRoot":"","sources":["../../../src/core/utils/parseCustomizedCmd.ts"],"names":[],"mappings":"AAKA,wBAAgB,kBAAkB,CAAC,cAAc,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,SA4B9E"}