agent-ide 0.8.1 → 0.9.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 (418) hide show
  1. package/dist/application/index.d.ts +1 -12
  2. package/dist/application/index.d.ts.map +1 -1
  3. package/dist/application/index.js +0 -16
  4. package/dist/application/index.js.map +1 -1
  5. package/dist/application/services/cache-coordinator.service.d.ts.map +1 -1
  6. package/dist/application/services/cache-coordinator.service.js.map +1 -1
  7. package/dist/application/services/module-coordinator.service.d.ts +3 -8
  8. package/dist/application/services/module-coordinator.service.d.ts.map +1 -1
  9. package/dist/application/services/module-coordinator.service.js +5 -139
  10. package/dist/application/services/module-coordinator.service.js.map +1 -1
  11. package/dist/application/types.d.ts +0 -63
  12. package/dist/application/types.d.ts.map +1 -1
  13. package/dist/application/types.js +1 -9
  14. package/dist/application/types.js.map +1 -1
  15. package/dist/core/call-hierarchy/call-hierarchy-analyzer.d.ts.map +1 -1
  16. package/dist/core/call-hierarchy/call-hierarchy-analyzer.js +3 -5
  17. package/dist/core/call-hierarchy/call-hierarchy-analyzer.js.map +1 -1
  18. package/dist/core/change-signature/call-site-updater.d.ts +108 -0
  19. package/dist/core/change-signature/call-site-updater.d.ts.map +1 -0
  20. package/dist/core/change-signature/call-site-updater.js +347 -0
  21. package/dist/core/change-signature/call-site-updater.js.map +1 -0
  22. package/dist/core/change-signature/change-signature-service.d.ts +11 -53
  23. package/dist/core/change-signature/change-signature-service.d.ts.map +1 -1
  24. package/dist/core/change-signature/change-signature-service.js +91 -475
  25. package/dist/core/change-signature/change-signature-service.js.map +1 -1
  26. package/dist/core/change-signature/index.d.ts +4 -0
  27. package/dist/core/change-signature/index.d.ts.map +1 -1
  28. package/dist/core/change-signature/index.js +5 -0
  29. package/dist/core/change-signature/index.js.map +1 -1
  30. package/dist/core/change-signature/signature-parser.d.ts +46 -4
  31. package/dist/core/change-signature/signature-parser.d.ts.map +1 -1
  32. package/dist/core/change-signature/signature-parser.js +180 -9
  33. package/dist/core/change-signature/signature-parser.js.map +1 -1
  34. package/dist/core/change-signature/signature-transformer.d.ts +20 -0
  35. package/dist/core/change-signature/signature-transformer.d.ts.map +1 -0
  36. package/dist/core/change-signature/signature-transformer.js +91 -0
  37. package/dist/core/change-signature/signature-transformer.js.map +1 -0
  38. package/dist/core/change-signature/signature-validator.d.ts +30 -0
  39. package/dist/core/change-signature/signature-validator.d.ts.map +1 -0
  40. package/dist/core/change-signature/signature-validator.js +152 -0
  41. package/dist/core/change-signature/signature-validator.js.map +1 -0
  42. package/dist/core/change-signature/utils.d.ts +19 -0
  43. package/dist/core/change-signature/utils.d.ts.map +1 -0
  44. package/dist/core/change-signature/utils.js +23 -0
  45. package/dist/core/change-signature/utils.js.map +1 -0
  46. package/dist/core/cycles/cycle-detector.d.ts.map +1 -1
  47. package/dist/core/cycles/cycle-detector.js +16 -8
  48. package/dist/core/cycles/cycle-detector.js.map +1 -1
  49. package/dist/core/cycles/index.d.ts +1 -1
  50. package/dist/core/cycles/index.d.ts.map +1 -1
  51. package/dist/core/cycles/index.js +1 -1
  52. package/dist/core/cycles/index.js.map +1 -1
  53. package/dist/core/cycles/types.d.ts +20 -4
  54. package/dist/core/cycles/types.d.ts.map +1 -1
  55. package/dist/core/cycles/types.js +22 -4
  56. package/dist/core/cycles/types.js.map +1 -1
  57. package/dist/core/deadcode/dead-code-detector.d.ts +22 -1
  58. package/dist/core/deadcode/dead-code-detector.d.ts.map +1 -1
  59. package/dist/core/deadcode/dead-code-detector.js +134 -61
  60. package/dist/core/deadcode/dead-code-detector.js.map +1 -1
  61. package/dist/core/deadcode/dead-code-remover.d.ts +11 -93
  62. package/dist/core/deadcode/dead-code-remover.d.ts.map +1 -1
  63. package/dist/core/deadcode/dead-code-remover.js +71 -690
  64. package/dist/core/deadcode/dead-code-remover.js.map +1 -1
  65. package/dist/core/deadcode/file-operations.d.ts +85 -0
  66. package/dist/core/deadcode/file-operations.d.ts.map +1 -0
  67. package/dist/core/deadcode/file-operations.js +263 -0
  68. package/dist/core/deadcode/file-operations.js.map +1 -0
  69. package/dist/core/deadcode/import-cleaner.d.ts +63 -0
  70. package/dist/core/deadcode/import-cleaner.d.ts.map +1 -0
  71. package/dist/core/deadcode/import-cleaner.js +229 -0
  72. package/dist/core/deadcode/import-cleaner.js.map +1 -0
  73. package/dist/core/deadcode/import-parser.d.ts +79 -0
  74. package/dist/core/deadcode/import-parser.d.ts.map +1 -0
  75. package/dist/core/deadcode/import-parser.js +229 -0
  76. package/dist/core/deadcode/import-parser.js.map +1 -0
  77. package/dist/core/deadcode/range-expander.d.ts +38 -0
  78. package/dist/core/deadcode/range-expander.d.ts.map +1 -0
  79. package/dist/core/deadcode/range-expander.js +175 -0
  80. package/dist/core/deadcode/range-expander.js.map +1 -0
  81. package/dist/core/deadcode/types.d.ts +2 -0
  82. package/dist/core/deadcode/types.d.ts.map +1 -1
  83. package/dist/core/deadcode/types.js.map +1 -1
  84. package/dist/core/find-references/index.d.ts +2 -2
  85. package/dist/core/find-references/index.d.ts.map +1 -1
  86. package/dist/core/find-references/index.js +1 -1
  87. package/dist/core/find-references/index.js.map +1 -1
  88. package/dist/core/impact/dependency-extractor.d.ts +25 -0
  89. package/dist/core/impact/dependency-extractor.d.ts.map +1 -0
  90. package/dist/core/impact/dependency-extractor.js +65 -0
  91. package/dist/core/impact/dependency-extractor.js.map +1 -0
  92. package/dist/core/impact/file-scanner.d.ts +52 -0
  93. package/dist/core/impact/file-scanner.d.ts.map +1 -0
  94. package/dist/core/impact/file-scanner.js +131 -0
  95. package/dist/core/impact/file-scanner.js.map +1 -0
  96. package/dist/core/impact/impact-analyzer.d.ts +3 -64
  97. package/dist/core/impact/impact-analyzer.d.ts.map +1 -1
  98. package/dist/core/impact/impact-analyzer.js +13 -312
  99. package/dist/core/impact/impact-analyzer.js.map +1 -1
  100. package/dist/core/impact/index.d.ts +3 -0
  101. package/dist/core/impact/index.d.ts.map +1 -1
  102. package/dist/core/impact/index.js +3 -0
  103. package/dist/core/impact/index.js.map +1 -1
  104. package/dist/core/impact/path-resolver.d.ts +35 -0
  105. package/dist/core/impact/path-resolver.d.ts.map +1 -0
  106. package/dist/core/impact/path-resolver.js +166 -0
  107. package/dist/core/impact/path-resolver.js.map +1 -0
  108. package/dist/core/move/file-scanner.d.ts +48 -0
  109. package/dist/core/move/file-scanner.d.ts.map +1 -0
  110. package/dist/core/move/file-scanner.js +137 -0
  111. package/dist/core/move/file-scanner.js.map +1 -0
  112. package/dist/core/move/import-resolver.d.ts +10 -0
  113. package/dist/core/move/import-resolver.d.ts.map +1 -1
  114. package/dist/core/move/import-resolver.js +31 -6
  115. package/dist/core/move/import-resolver.js.map +1 -1
  116. package/dist/core/move/index.d.ts +7 -3
  117. package/dist/core/move/index.d.ts.map +1 -1
  118. package/dist/core/move/index.js +7 -2
  119. package/dist/core/move/index.js.map +1 -1
  120. package/dist/core/move/move-service.d.ts +41 -52
  121. package/dist/core/move/move-service.d.ts.map +1 -1
  122. package/dist/core/move/move-service.js +189 -358
  123. package/dist/core/move/move-service.js.map +1 -1
  124. package/dist/core/move/path-calculator.d.ts +49 -0
  125. package/dist/core/move/path-calculator.d.ts.map +1 -0
  126. package/dist/core/move/path-calculator.js +158 -0
  127. package/dist/core/move/path-calculator.js.map +1 -0
  128. package/dist/core/move/path-parser.d.ts +33 -0
  129. package/dist/core/move/path-parser.d.ts.map +1 -0
  130. package/dist/core/move/path-parser.js +53 -0
  131. package/dist/core/move/path-parser.js.map +1 -0
  132. package/dist/core/move/path-utils.d.ts +70 -0
  133. package/dist/core/move/path-utils.d.ts.map +1 -0
  134. package/dist/core/move/path-utils.js +201 -0
  135. package/dist/core/move/path-utils.js.map +1 -0
  136. package/dist/core/move/types.d.ts +81 -18
  137. package/dist/core/move/types.d.ts.map +1 -1
  138. package/dist/core/move/types.js +73 -5
  139. package/dist/core/move/types.js.map +1 -1
  140. package/dist/core/move-member/change-applier.d.ts +23 -0
  141. package/dist/core/move-member/change-applier.d.ts.map +1 -0
  142. package/dist/core/move-member/change-applier.js +51 -0
  143. package/dist/core/move-member/change-applier.js.map +1 -0
  144. package/dist/core/move-member/file-change-preparer.d.ts +49 -0
  145. package/dist/core/move-member/file-change-preparer.d.ts.map +1 -0
  146. package/dist/core/move-member/file-change-preparer.js +340 -0
  147. package/dist/core/move-member/file-change-preparer.js.map +1 -0
  148. package/dist/core/move-member/index.d.ts +4 -1
  149. package/dist/core/move-member/index.d.ts.map +1 -1
  150. package/dist/core/move-member/index.js +3 -0
  151. package/dist/core/move-member/index.js.map +1 -1
  152. package/dist/core/move-member/member-extractor.d.ts +11 -0
  153. package/dist/core/move-member/member-extractor.d.ts.map +1 -1
  154. package/dist/core/move-member/member-extractor.js +116 -24
  155. package/dist/core/move-member/member-extractor.js.map +1 -1
  156. package/dist/core/move-member/move-member-service.d.ts +9 -78
  157. package/dist/core/move-member/move-member-service.d.ts.map +1 -1
  158. package/dist/core/move-member/move-member-service.js +86 -413
  159. package/dist/core/move-member/move-member-service.js.map +1 -1
  160. package/dist/core/move-member/reference-updater.d.ts +73 -0
  161. package/dist/core/move-member/reference-updater.d.ts.map +1 -0
  162. package/dist/core/move-member/reference-updater.js +286 -0
  163. package/dist/core/move-member/reference-updater.js.map +1 -0
  164. package/dist/core/move-member/types.d.ts +17 -2
  165. package/dist/core/move-member/types.d.ts.map +1 -1
  166. package/dist/core/move-member/types.js.map +1 -1
  167. package/dist/core/rename/reference-updater.d.ts +1 -35
  168. package/dist/core/rename/reference-updater.d.ts.map +1 -1
  169. package/dist/core/rename/reference-updater.js +8 -251
  170. package/dist/core/rename/reference-updater.js.map +1 -1
  171. package/dist/core/rename/rename-engine.d.ts +16 -22
  172. package/dist/core/rename/rename-engine.d.ts.map +1 -1
  173. package/dist/core/rename/rename-engine.js +59 -208
  174. package/dist/core/rename/rename-engine.js.map +1 -1
  175. package/dist/core/rename/scope-analyzer.d.ts.map +1 -1
  176. package/dist/core/shared/index.d.ts +1 -1
  177. package/dist/core/shared/index.d.ts.map +1 -1
  178. package/dist/core/shared/index.js +1 -1
  179. package/dist/core/shared/index.js.map +1 -1
  180. package/dist/core/shared/indexing/index-engine.d.ts +1 -1
  181. package/dist/core/shared/indexing/index-engine.d.ts.map +1 -1
  182. package/dist/core/shared/indexing/index-engine.js +1 -1
  183. package/dist/core/shared/indexing/index-engine.js.map +1 -1
  184. package/dist/core/shared/symbol-finder/call-site-parser.d.ts +71 -0
  185. package/dist/core/shared/symbol-finder/call-site-parser.d.ts.map +1 -0
  186. package/dist/core/shared/symbol-finder/call-site-parser.js +369 -0
  187. package/dist/core/shared/symbol-finder/call-site-parser.js.map +1 -0
  188. package/dist/core/shared/symbol-finder/index.d.ts +9 -0
  189. package/dist/core/shared/symbol-finder/index.d.ts.map +1 -0
  190. package/dist/core/shared/symbol-finder/index.js +12 -0
  191. package/dist/core/shared/symbol-finder/index.js.map +1 -0
  192. package/dist/core/shared/{symbol-finder.d.ts → symbol-finder/symbol-finder.d.ts} +27 -133
  193. package/dist/core/shared/symbol-finder/symbol-finder.d.ts.map +1 -0
  194. package/dist/core/shared/symbol-finder/symbol-finder.js +552 -0
  195. package/dist/core/shared/symbol-finder/symbol-finder.js.map +1 -0
  196. package/dist/core/shared/symbol-finder/text-matcher.d.ts +45 -0
  197. package/dist/core/shared/symbol-finder/text-matcher.d.ts.map +1 -0
  198. package/dist/core/shared/symbol-finder/text-matcher.js +195 -0
  199. package/dist/core/shared/symbol-finder/text-matcher.js.map +1 -0
  200. package/dist/core/shared/symbol-finder/types.d.ts +108 -0
  201. package/dist/core/shared/symbol-finder/types.d.ts.map +1 -0
  202. package/dist/core/shared/symbol-finder/types.js +71 -0
  203. package/dist/core/shared/symbol-finder/types.js.map +1 -0
  204. package/dist/core/snapshot/snapshot-generator.d.ts +16 -4
  205. package/dist/core/snapshot/snapshot-generator.d.ts.map +1 -1
  206. package/dist/core/snapshot/snapshot-generator.js +91 -18
  207. package/dist/core/snapshot/snapshot-generator.js.map +1 -1
  208. package/dist/infrastructure/cache/cache-manager.d.ts.map +1 -1
  209. package/dist/infrastructure/cache/cache-manager.js +4 -0
  210. package/dist/infrastructure/cache/cache-manager.js.map +1 -1
  211. package/dist/infrastructure/cache/index.d.ts +15 -9
  212. package/dist/infrastructure/cache/index.d.ts.map +1 -1
  213. package/dist/infrastructure/cache/index.js +5 -5
  214. package/dist/infrastructure/cache/index.js.map +1 -1
  215. package/dist/infrastructure/cache/memory-cache.d.ts.map +1 -1
  216. package/dist/infrastructure/cache/memory-cache.js.map +1 -1
  217. package/dist/infrastructure/cache/strategies.d.ts.map +1 -1
  218. package/dist/infrastructure/cache/strategies.js +2 -1
  219. package/dist/infrastructure/cache/strategies.js.map +1 -1
  220. package/dist/infrastructure/cache/types.d.ts +4 -4
  221. package/dist/infrastructure/cache/types.d.ts.map +1 -1
  222. package/dist/infrastructure/changeset/change-applicator.d.ts +95 -0
  223. package/dist/infrastructure/changeset/change-applicator.d.ts.map +1 -0
  224. package/dist/infrastructure/changeset/change-applicator.js +467 -0
  225. package/dist/infrastructure/changeset/change-applicator.js.map +1 -0
  226. package/dist/infrastructure/changeset/changeset-builder.d.ts +107 -0
  227. package/dist/infrastructure/changeset/changeset-builder.d.ts.map +1 -0
  228. package/dist/infrastructure/changeset/changeset-builder.js +188 -0
  229. package/dist/infrastructure/changeset/changeset-builder.js.map +1 -0
  230. package/dist/infrastructure/changeset/changeset-converter.d.ts +15 -0
  231. package/dist/infrastructure/changeset/changeset-converter.d.ts.map +1 -0
  232. package/dist/infrastructure/changeset/changeset-converter.js +370 -0
  233. package/dist/infrastructure/changeset/changeset-converter.js.map +1 -0
  234. package/dist/infrastructure/changeset/index.d.ts +10 -0
  235. package/dist/infrastructure/changeset/index.d.ts.map +1 -0
  236. package/dist/infrastructure/changeset/index.js +13 -0
  237. package/dist/infrastructure/changeset/index.js.map +1 -0
  238. package/dist/infrastructure/changeset/types.d.ts +147 -0
  239. package/dist/infrastructure/changeset/types.d.ts.map +1 -0
  240. package/dist/infrastructure/changeset/types.js +46 -0
  241. package/dist/infrastructure/changeset/types.js.map +1 -0
  242. package/dist/infrastructure/parser/base.d.ts.map +1 -1
  243. package/dist/infrastructure/parser/base.js +4 -3
  244. package/dist/infrastructure/parser/base.js.map +1 -1
  245. package/dist/infrastructure/parser/interface.d.ts +4 -2
  246. package/dist/infrastructure/parser/interface.d.ts.map +1 -1
  247. package/dist/infrastructure/parser/interface.js.map +1 -1
  248. package/dist/infrastructure/storage/file-system.d.ts.map +1 -1
  249. package/dist/infrastructure/storage/file-system.js +61 -54
  250. package/dist/infrastructure/storage/file-system.js.map +1 -1
  251. package/dist/interfaces/cli/cli.d.ts.map +1 -1
  252. package/dist/interfaces/cli/cli.js +1 -2
  253. package/dist/interfaces/cli/cli.js.map +1 -1
  254. package/dist/interfaces/cli/commands/change-signature.command.d.ts.map +1 -1
  255. package/dist/interfaces/cli/commands/change-signature.command.js +31 -107
  256. package/dist/interfaces/cli/commands/change-signature.command.js.map +1 -1
  257. package/dist/interfaces/cli/commands/deadcode.command.js +51 -46
  258. package/dist/interfaces/cli/commands/deadcode.command.js.map +1 -1
  259. package/dist/interfaces/cli/commands/find-references.command.d.ts.map +1 -1
  260. package/dist/interfaces/cli/commands/find-references.command.js +18 -3
  261. package/dist/interfaces/cli/commands/find-references.command.js.map +1 -1
  262. package/dist/interfaces/cli/commands/index.d.ts +0 -1
  263. package/dist/interfaces/cli/commands/index.d.ts.map +1 -1
  264. package/dist/interfaces/cli/commands/index.js +0 -1
  265. package/dist/interfaces/cli/commands/index.js.map +1 -1
  266. package/dist/interfaces/cli/commands/move.command.d.ts +1 -0
  267. package/dist/interfaces/cli/commands/move.command.d.ts.map +1 -1
  268. package/dist/interfaces/cli/commands/move.command.js +170 -65
  269. package/dist/interfaces/cli/commands/move.command.js.map +1 -1
  270. package/dist/interfaces/cli/commands/rename.command.d.ts.map +1 -1
  271. package/dist/interfaces/cli/commands/rename.command.js +133 -59
  272. package/dist/interfaces/cli/commands/rename.command.js.map +1 -1
  273. package/dist/interfaces/cli/output-formatter.d.ts +2 -2
  274. package/dist/interfaces/cli/output-formatter.d.ts.map +1 -1
  275. package/dist/interfaces/cli/output-formatter.js.map +1 -1
  276. package/dist/plugins/javascript/declaration-analyzer.d.ts.map +1 -1
  277. package/dist/plugins/javascript/declaration-analyzer.js +9 -0
  278. package/dist/plugins/javascript/declaration-analyzer.js.map +1 -1
  279. package/dist/plugins/javascript/parser.d.ts +11 -10
  280. package/dist/plugins/javascript/parser.d.ts.map +1 -1
  281. package/dist/plugins/javascript/parser.js +57 -53
  282. package/dist/plugins/javascript/parser.js.map +1 -1
  283. package/dist/plugins/javascript/pattern-analyzer.d.ts.map +1 -1
  284. package/dist/plugins/javascript/pattern-analyzer.js +4 -3
  285. package/dist/plugins/javascript/pattern-analyzer.js.map +1 -1
  286. package/dist/plugins/javascript/reference-finder.d.ts +21 -0
  287. package/dist/plugins/javascript/reference-finder.d.ts.map +1 -1
  288. package/dist/plugins/javascript/reference-finder.js +119 -76
  289. package/dist/plugins/javascript/reference-finder.js.map +1 -1
  290. package/dist/plugins/javascript/types.d.ts +4 -7
  291. package/dist/plugins/javascript/types.d.ts.map +1 -1
  292. package/dist/plugins/javascript/types.js +9 -9
  293. package/dist/plugins/javascript/types.js.map +1 -1
  294. package/dist/plugins/shared/parser-helpers.js.map +1 -1
  295. package/dist/{shared → plugins/shared}/utils/array.d.ts +6 -1
  296. package/dist/plugins/shared/utils/array.d.ts.map +1 -0
  297. package/dist/plugins/shared/utils/array.js.map +1 -0
  298. package/dist/{shared → plugins/shared}/utils/async.d.ts +1 -1
  299. package/dist/plugins/shared/utils/async.d.ts.map +1 -0
  300. package/dist/{shared → plugins/shared}/utils/async.js +2 -0
  301. package/dist/plugins/shared/utils/async.js.map +1 -0
  302. package/dist/{shared → plugins/shared}/utils/index.d.ts +0 -20
  303. package/dist/plugins/shared/utils/index.d.ts.map +1 -0
  304. package/dist/{shared → plugins/shared}/utils/index.js +0 -20
  305. package/dist/plugins/shared/utils/index.js.map +1 -0
  306. package/dist/plugins/shared/utils/memory-monitor.d.ts.map +1 -0
  307. package/dist/plugins/shared/utils/memory-monitor.js.map +1 -0
  308. package/dist/{shared → plugins/shared}/utils/object.d.ts +6 -6
  309. package/dist/plugins/shared/utils/object.d.ts.map +1 -0
  310. package/dist/{shared → plugins/shared}/utils/object.js +21 -3
  311. package/dist/plugins/shared/utils/object.js.map +1 -0
  312. package/dist/plugins/shared/utils/path.d.ts.map +1 -0
  313. package/dist/plugins/shared/utils/path.js.map +1 -0
  314. package/dist/{shared → plugins/shared}/utils/string.d.ts +1 -1
  315. package/dist/plugins/shared/utils/string.d.ts.map +1 -0
  316. package/dist/{shared → plugins/shared}/utils/string.js +7 -4
  317. package/dist/plugins/shared/utils/string.js.map +1 -0
  318. package/dist/plugins/typescript/declaration-analyzer.d.ts +4 -4
  319. package/dist/plugins/typescript/declaration-analyzer.d.ts.map +1 -1
  320. package/dist/plugins/typescript/declaration-analyzer.js +13 -6
  321. package/dist/plugins/typescript/declaration-analyzer.js.map +1 -1
  322. package/dist/plugins/typescript/language-service.d.ts +1 -1
  323. package/dist/plugins/typescript/language-service.d.ts.map +1 -1
  324. package/dist/plugins/typescript/parser.d.ts +3 -2
  325. package/dist/plugins/typescript/parser.d.ts.map +1 -1
  326. package/dist/plugins/typescript/parser.js +18 -13
  327. package/dist/plugins/typescript/parser.js.map +1 -1
  328. package/dist/plugins/typescript/reference-finder.d.ts +3 -0
  329. package/dist/plugins/typescript/reference-finder.d.ts.map +1 -1
  330. package/dist/plugins/typescript/reference-finder.js +16 -4
  331. package/dist/plugins/typescript/reference-finder.js.map +1 -1
  332. package/dist/plugins/typescript/symbol-extractor.d.ts +4 -0
  333. package/dist/plugins/typescript/symbol-extractor.d.ts.map +1 -1
  334. package/dist/plugins/typescript/symbol-extractor.js +24 -6
  335. package/dist/plugins/typescript/symbol-extractor.js.map +1 -1
  336. package/dist/plugins/typescript/types.d.ts +0 -3
  337. package/dist/plugins/typescript/types.d.ts.map +1 -1
  338. package/dist/plugins/typescript/types.js +6 -9
  339. package/dist/plugins/typescript/types.js.map +1 -1
  340. package/dist/shared/errors/index.d.ts +1 -1
  341. package/dist/shared/errors/index.d.ts.map +1 -1
  342. package/dist/shared/errors/parser-error.js +5 -5
  343. package/dist/shared/errors/parser-error.js.map +1 -1
  344. package/dist/shared/errors/validation-error.d.ts +2 -2
  345. package/dist/shared/errors/validation-error.d.ts.map +1 -1
  346. package/dist/shared/errors/validation-error.js.map +1 -1
  347. package/dist/shared/types/ast.d.ts +4 -4
  348. package/dist/shared/types/ast.d.ts.map +1 -1
  349. package/dist/shared/types/ast.js.map +1 -1
  350. package/dist/shared/types/core.d.ts +1 -1
  351. package/dist/shared/types/core.d.ts.map +1 -1
  352. package/dist/shared/types/index.d.ts +1 -0
  353. package/dist/shared/types/index.d.ts.map +1 -1
  354. package/dist/shared/types/index.js +2 -0
  355. package/dist/shared/types/index.js.map +1 -1
  356. package/dist/shared/types/line-number.d.ts +22 -0
  357. package/dist/shared/types/line-number.d.ts.map +1 -0
  358. package/dist/shared/types/line-number.js +28 -0
  359. package/dist/shared/types/line-number.js.map +1 -0
  360. package/package.json +2 -2
  361. package/dist/application/services/workflow-engine.service.d.ts +0 -76
  362. package/dist/application/services/workflow-engine.service.d.ts.map +0 -1
  363. package/dist/application/services/workflow-engine.service.js +0 -405
  364. package/dist/application/services/workflow-engine.service.js.map +0 -1
  365. package/dist/application/workflows/analysis-workflow.d.ts +0 -239
  366. package/dist/application/workflows/analysis-workflow.d.ts.map +0 -1
  367. package/dist/application/workflows/analysis-workflow.js +0 -395
  368. package/dist/application/workflows/analysis-workflow.js.map +0 -1
  369. package/dist/application/workflows/base-workflow.d.ts +0 -108
  370. package/dist/application/workflows/base-workflow.d.ts.map +0 -1
  371. package/dist/application/workflows/base-workflow.js +0 -236
  372. package/dist/application/workflows/base-workflow.js.map +0 -1
  373. package/dist/application/workflows/index.d.ts +0 -115
  374. package/dist/application/workflows/index.d.ts.map +0 -1
  375. package/dist/application/workflows/index.js +0 -218
  376. package/dist/application/workflows/index.js.map +0 -1
  377. package/dist/application/workflows/refactor-workflow.d.ts +0 -107
  378. package/dist/application/workflows/refactor-workflow.d.ts.map +0 -1
  379. package/dist/application/workflows/refactor-workflow.js +0 -310
  380. package/dist/application/workflows/refactor-workflow.js.map +0 -1
  381. package/dist/core/shared/symbol-finder.d.ts.map +0 -1
  382. package/dist/core/shared/symbol-finder.js +0 -882
  383. package/dist/core/shared/symbol-finder.js.map +0 -1
  384. package/dist/interfaces/cli/commands/move-member.command.d.ts +0 -11
  385. package/dist/interfaces/cli/commands/move-member.command.d.ts.map +0 -1
  386. package/dist/interfaces/cli/commands/move-member.command.js +0 -211
  387. package/dist/interfaces/cli/commands/move-member.command.js.map +0 -1
  388. package/dist/plugins/javascript/code-analyzer.d.ts +0 -68
  389. package/dist/plugins/javascript/code-analyzer.d.ts.map +0 -1
  390. package/dist/plugins/javascript/code-analyzer.js +0 -302
  391. package/dist/plugins/javascript/code-analyzer.js.map +0 -1
  392. package/dist/plugins/javascript/index.d.ts +0 -12
  393. package/dist/plugins/javascript/index.d.ts.map +0 -1
  394. package/dist/plugins/javascript/index.js +0 -16
  395. package/dist/plugins/javascript/index.js.map +0 -1
  396. package/dist/plugins/typescript/index.d.ts +0 -14
  397. package/dist/plugins/typescript/index.d.ts.map +0 -1
  398. package/dist/plugins/typescript/index.js +0 -13
  399. package/dist/plugins/typescript/index.js.map +0 -1
  400. package/dist/shared/utils/array.d.ts.map +0 -1
  401. package/dist/shared/utils/array.js.map +0 -1
  402. package/dist/shared/utils/async.d.ts.map +0 -1
  403. package/dist/shared/utils/async.js.map +0 -1
  404. package/dist/shared/utils/index.d.ts.map +0 -1
  405. package/dist/shared/utils/index.js.map +0 -1
  406. package/dist/shared/utils/memory-monitor.d.ts.map +0 -1
  407. package/dist/shared/utils/memory-monitor.js.map +0 -1
  408. package/dist/shared/utils/object.d.ts.map +0 -1
  409. package/dist/shared/utils/object.js.map +0 -1
  410. package/dist/shared/utils/path.d.ts.map +0 -1
  411. package/dist/shared/utils/path.js.map +0 -1
  412. package/dist/shared/utils/string.d.ts.map +0 -1
  413. package/dist/shared/utils/string.js.map +0 -1
  414. /package/dist/{shared → plugins/shared}/utils/array.js +0 -0
  415. /package/dist/{shared → plugins/shared}/utils/memory-monitor.d.ts +0 -0
  416. /package/dist/{shared → plugins/shared}/utils/memory-monitor.js +0 -0
  417. /package/dist/{shared → plugins/shared}/utils/path.d.ts +0 -0
  418. /package/dist/{shared → plugins/shared}/utils/path.js +0 -0
@@ -3,10 +3,41 @@
3
3
  * 提供安全的檔案移動功能,自動更新所有相關的 import 路徑
4
4
  */
5
5
  import * as path from 'path';
6
+ import { ChangesetCommand, TextEditOperationType, createChangesetBuilder } from '../../infrastructure/changeset/index.js';
6
7
  import { ImportResolver } from './import-resolver.js';
8
+ import { PathCalculator } from './path-calculator.js';
9
+ import { PathUtils } from './path-utils.js';
10
+ import { createMoveError } from './types.js';
11
+ /**
12
+ * 移動操作錯誤類別
13
+ * 用於事務中明確識別錯誤類型
14
+ */
15
+ export class MoveOperationError extends Error {
16
+ errorType;
17
+ filePath;
18
+ cause;
19
+ constructor(message, errorType, filePath, cause) {
20
+ super(message);
21
+ this.errorType = errorType;
22
+ this.filePath = filePath;
23
+ this.cause = cause;
24
+ this.name = 'MoveOperationError';
25
+ }
26
+ /**
27
+ * 轉換為 MoveError 介面
28
+ */
29
+ toMoveError() {
30
+ return createMoveError(this.errorType, this.message, this.filePath, this.cause);
31
+ }
32
+ }
33
+ /**
34
+ * 檔案移動服務類別
35
+ */
7
36
  export class MoveService {
8
37
  fileSystem;
9
38
  importResolver;
39
+ pathCalculator;
40
+ pathUtils;
10
41
  constructor(fileSystem, config, importResolver) {
11
42
  this.fileSystem = fileSystem;
12
43
  if (importResolver) {
@@ -20,6 +51,8 @@ export class MoveService {
20
51
  };
21
52
  this.importResolver = new ImportResolver(defaultConfig);
22
53
  }
54
+ this.pathCalculator = new PathCalculator(this.fileSystem, this.importResolver);
55
+ this.pathUtils = new PathUtils(this.importResolver);
23
56
  }
24
57
  /**
25
58
  * 移動檔案或目錄
@@ -28,45 +61,16 @@ export class MoveService {
28
61
  const { source, target, updateImports = true } = operation;
29
62
  const { preview = false, projectRoot = process.cwd() } = options;
30
63
  let fileMoved = false;
64
+ const transactionLog = [];
31
65
  try {
32
66
  // 1. 驗證路徑
33
67
  await this.validatePaths(source, target);
34
68
  // 檢查是否為目錄
35
69
  const isDirectory = await this.fileSystem.isDirectory(source);
36
70
  // 2. 收集需要更新的檔案
37
- const pathUpdates = [];
38
- if (updateImports) {
39
- if (isDirectory) {
40
- // 目錄移動:處理目錄內所有檔案
41
- const filesInDir = await this.getFilesInDirectory(source);
42
- for (const filePath of filesInDir) {
43
- // 計算檔案在目錄內的相對路徑
44
- const relativePath = path.relative(source, filePath);
45
- const newFilePath = path.join(target, relativePath);
46
- // 2.1 更新其他檔案對目錄內檔案的引用
47
- const affectedFiles = await this.findAffectedFiles(filePath, projectRoot);
48
- for (const affectedFile of affectedFiles) {
49
- const updates = await this.calculatePathUpdates(affectedFile, filePath, newFilePath);
50
- pathUpdates.push(...updates);
51
- }
52
- // 2.2 更新目錄內檔案的內部 import
53
- const internalUpdates = await this.calculateMovedFileInternalUpdates(filePath, newFilePath);
54
- pathUpdates.push(...internalUpdates);
55
- }
56
- }
57
- else {
58
- // 單一檔案移動
59
- // 2.1 更新其他檔案對被移動檔案的引用
60
- const affectedFiles = await this.findAffectedFiles(source, projectRoot);
61
- for (const filePath of affectedFiles) {
62
- const updates = await this.calculatePathUpdates(filePath, source, target);
63
- pathUpdates.push(...updates);
64
- }
65
- // 2.2 更新被移動檔案內部的 import(在移動前處理)
66
- const movedFileInternalUpdates = await this.calculateMovedFileInternalUpdates(source, target);
67
- pathUpdates.push(...movedFileInternalUpdates);
68
- }
69
- }
71
+ const pathUpdates = updateImports
72
+ ? await this.pathCalculator.calculatePathUpdatesInternal(source, target, isDirectory, projectRoot)
73
+ : [];
70
74
  // 3. 預覽模式
71
75
  if (preview) {
72
76
  return {
@@ -79,41 +83,60 @@ export class MoveService {
79
83
  };
80
84
  }
81
85
  // 4. 執行移動
86
+ transactionLog.push(`MOVE: ${source} → ${target}`);
82
87
  await this.performMove(source, target);
83
88
  fileMoved = true;
84
89
  // 5. 更新 import 路徑
85
90
  if (updateImports && pathUpdates.length > 0) {
86
91
  try {
87
92
  await this.applyPathUpdates(pathUpdates);
93
+ transactionLog.push(`IMPORT_UPDATES: ${JSON.stringify(pathUpdates.map(u => ({
94
+ file: u.filePath,
95
+ line: u.line,
96
+ from: u.oldImport,
97
+ to: u.newImport
98
+ })))}`);
88
99
  }
89
100
  catch (updateError) {
90
- // 如果更新 import 失敗,記錄錯誤但仍然回傳 success
91
- // 因為檔案已經移動成功
92
- // 測試環境中靜默處理
93
- if (process.env.NODE_ENV !== 'test') {
94
- console.error('更新 import 路徑失敗:', updateError);
95
- }
101
+ // 所有 import 更新錯誤都應該觸發回滾
96
102
  const errorMessage = updateError instanceof Error ? updateError.message : 'Unknown error';
97
- // 如果錯誤訊息包含 "更新檔案" 或其他寫入相關錯誤,表示更新失敗
98
- if (errorMessage.includes('更新檔案') || errorMessage.includes('Write permission') || errorMessage.includes('permission denied')) {
99
- // 回滾檔案移動(如果可能)
100
- try {
101
- await this.fileSystem.moveFile(target, source);
102
- fileMoved = false;
103
- }
104
- catch {
105
- // 無法回滾,但仍然要回傳失敗
106
- }
103
+ // 記錄錯誤到事務日誌
104
+ transactionLog.push(`IMPORT_UPDATE_FAILED: ${errorMessage}`);
105
+ // 嘗試回滾檔案移動
106
+ try {
107
+ transactionLog.push(`ROLLBACK_ATTEMPT: ${target} → ${source}`);
108
+ await this.performRollback(target, source, isDirectory);
109
+ fileMoved = false;
110
+ transactionLog.push('ROLLBACK_SUCCESS');
111
+ }
112
+ catch (rollbackError) {
113
+ // 回滾失敗,記錄完整事務日誌供手動恢復
114
+ const rollbackErrorMsg = rollbackError instanceof Error ? rollbackError.message : 'Unknown error';
115
+ transactionLog.push(`ROLLBACK_FAILED: ${rollbackErrorMsg}`);
116
+ // 建構詳細的手動恢復指引
117
+ const manualRecoverySteps = [
118
+ `將 ${target} 移動回 ${source}`,
119
+ `檢查並還原以下檔案的 import 變更: ${pathUpdates.map(u => u.filePath).join(', ')}`
120
+ ];
107
121
  return {
108
122
  success: false,
109
123
  source,
110
124
  target,
111
- moved: fileMoved,
112
- pathUpdates: [],
113
- error: errorMessage,
114
- message: `移動失敗: ${errorMessage}`
125
+ moved: true, // 檔案仍在 target 位置
126
+ pathUpdates,
127
+ error: `Import 更新失敗且無法回滾: ${errorMessage}。回滾錯誤: ${rollbackErrorMsg}。手動恢復步驟: ${manualRecoverySteps.join('; ')}`,
128
+ message: `移動失敗且回滾失敗,需要手動恢復。事務日誌: ${transactionLog.join('; ')}`
115
129
  };
116
130
  }
131
+ return {
132
+ success: false,
133
+ source,
134
+ target,
135
+ moved: fileMoved,
136
+ pathUpdates,
137
+ error: errorMessage,
138
+ message: `移動失敗: ${errorMessage}`
139
+ };
117
140
  }
118
141
  }
119
142
  return {
@@ -126,17 +149,124 @@ export class MoveService {
126
149
  };
127
150
  }
128
151
  catch (error) {
152
+ // 最外層的 try-catch:在計算 pathUpdates 之前發生的錯誤,pathUpdates 可能尚未初始化
153
+ const pathUpdates = [];
129
154
  return {
130
155
  success: false,
131
156
  source,
132
157
  target,
133
158
  moved: fileMoved,
134
- pathUpdates: [],
159
+ pathUpdates,
135
160
  error: error instanceof Error ? error.message : 'Unknown error',
136
161
  message: `移動失敗: ${error instanceof Error ? error.message : 'Unknown error'}`
137
162
  };
138
163
  }
139
164
  }
165
+ /**
166
+ * 執行回滾操作
167
+ */
168
+ async performRollback(currentPath, originalPath, isDirectory) {
169
+ if (isDirectory) {
170
+ await this.moveDirectory(currentPath, originalPath);
171
+ }
172
+ else {
173
+ await this.fileSystem.moveFile(currentPath, originalPath);
174
+ }
175
+ }
176
+ /**
177
+ * 生成移動的 Changeset
178
+ * 不執行實際移動,只計算變更
179
+ *
180
+ * @param operation - 移動操作輸入
181
+ * @param options - 移動選項
182
+ * @returns Changeset 物件
183
+ */
184
+ async generateChangeset(operation, options = {}) {
185
+ const { source, target, updateImports = true } = operation;
186
+ const { projectRoot = process.cwd() } = options;
187
+ const builder = createChangesetBuilder()
188
+ .forCommand(ChangesetCommand.Move)
189
+ .withDescription(`Moved '${path.basename(source)}' to '${path.basename(target)}'`);
190
+ try {
191
+ // 驗證路徑(只讀驗證,不建立目錄)
192
+ await this.validatePathsForChangeset(source, target);
193
+ // 檢查是否為目錄
194
+ const isDirectory = await this.fileSystem.isDirectory(source);
195
+ // 收集 import 更新
196
+ const pathUpdates = updateImports
197
+ ? await this.pathCalculator.calculatePathUpdatesInternal(source, target, isDirectory, projectRoot)
198
+ : [];
199
+ // 轉換 pathUpdates 為 TextEdit,按檔案分組
200
+ // 注意:對於被移動檔案的內部更新,filePath 是 target,但需要從 source 讀取內容
201
+ const grouped = new Map();
202
+ for (const update of pathUpdates) {
203
+ const list = grouped.get(update.filePath) ?? [];
204
+ list.push(update);
205
+ grouped.set(update.filePath, list);
206
+ }
207
+ for (const [filePath, updates] of grouped) {
208
+ // 判斷是否為被移動檔案的內部更新
209
+ // 可能是單檔移動(filePath === target)或目錄移動(filePath 以 target 開頭)
210
+ const isMovedFile = filePath === target || filePath.startsWith(target + path.sep);
211
+ // 計算原始檔案路徑
212
+ let readPath = filePath;
213
+ if (isMovedFile) {
214
+ if (filePath === target) {
215
+ // 單檔移動
216
+ readPath = source;
217
+ }
218
+ else {
219
+ // 目錄移動:將 target 前綴替換為 source
220
+ const relativePath = filePath.slice(target.length);
221
+ readPath = source + relativePath;
222
+ }
223
+ }
224
+ const content = await this.fileSystem.readFile(readPath, 'utf-8');
225
+ const lines = content.split('\n');
226
+ const edits = updates.map(update => {
227
+ const lineIndex = update.line - 1;
228
+ const lineContent = lines[lineIndex] ?? '';
229
+ const startCol = lineContent.indexOf(update.oldImport) + 1;
230
+ const endCol = startCol + update.oldImport.length;
231
+ return {
232
+ range: {
233
+ start: { line: update.line, column: startCol },
234
+ end: { line: update.line, column: endCol }
235
+ },
236
+ newText: update.newImport,
237
+ description: `Update import: ${update.oldImport} → ${update.newImport}`
238
+ };
239
+ });
240
+ // 對於被移動檔案,使用原始路徑來建立 TextChange(轉換器會從該路徑讀取)
241
+ // 實際的檔案移動由 fileOperations 處理
242
+ builder.addTextChange(readPath, edits, TextEditOperationType.Modify);
243
+ }
244
+ // 新增檔案移動操作
245
+ builder.addFileMove(source, target);
246
+ return builder.build();
247
+ }
248
+ catch (error) {
249
+ return builder
250
+ .addError(error instanceof Error ? error.message : String(error))
251
+ .build();
252
+ }
253
+ }
254
+ /**
255
+ * 驗證路徑(只讀版本,用於 generateChangeset)
256
+ * 不建立任何目錄,只做驗證
257
+ */
258
+ async validatePathsForChangeset(source, target) {
259
+ // 檢查來源是否存在
260
+ const sourceExists = await this.fileSystem.exists(source);
261
+ if (!sourceExists) {
262
+ throw new Error(`來源路徑不存在: ${source}`);
263
+ }
264
+ // 檢查目標是否已存在
265
+ const targetExists = await this.fileSystem.exists(target);
266
+ if (targetExists) {
267
+ throw new Error(`目標路徑已存在: ${target}`);
268
+ }
269
+ }
140
270
  /**
141
271
  * 驗證路徑
142
272
  */
@@ -201,302 +331,6 @@ export class MoveService {
201
331
  // 刪除原目錄
202
332
  await this.fileSystem.deleteDirectory(source);
203
333
  }
204
- /**
205
- * 找出受影響的檔案
206
- */
207
- async findAffectedFiles(movedPath, projectRoot) {
208
- const affectedFiles = [];
209
- const files = await this.getAllProjectFiles(projectRoot);
210
- for (const file of files) {
211
- // 跳過被移動的檔案本身(處理不同的路徑格式)
212
- const normalizedFile = path.normalize(file);
213
- const normalizedMovedPath = path.normalize(movedPath);
214
- if (normalizedFile === normalizedMovedPath) {
215
- continue;
216
- }
217
- const hasReference = await this.fileReferencesPath(file, movedPath);
218
- if (hasReference) {
219
- affectedFiles.push(file);
220
- }
221
- }
222
- return affectedFiles;
223
- }
224
- /**
225
- * 獲取專案中的所有檔案
226
- */
227
- async getAllProjectFiles(projectRoot) {
228
- const files = [];
229
- const allowedExtensions = ['.ts', '.tsx', '.js', '.jsx', '.vue'];
230
- const excludePatterns = ['node_modules', 'dist', '.git', 'coverage', '.build'];
231
- const walkDir = async (dir) => {
232
- try {
233
- const entries = await this.fileSystem.readDirectory(dir);
234
- for (const entry of entries) {
235
- if (entry.isDirectory) {
236
- // 跳過排除的目錄
237
- if (excludePatterns.some(pattern => entry.name.includes(pattern))) {
238
- continue;
239
- }
240
- await walkDir(entry.path);
241
- }
242
- else if (entry.isFile) {
243
- // 只包含支援的副檔名
244
- if (allowedExtensions.some(ext => entry.name.endsWith(ext))) {
245
- files.push(entry.path);
246
- }
247
- }
248
- }
249
- }
250
- catch {
251
- // 忽略無法存取的目錄
252
- }
253
- };
254
- await walkDir(projectRoot);
255
- return files;
256
- }
257
- /**
258
- * 獲取目錄內的所有檔案(遞迴)
259
- */
260
- async getFilesInDirectory(dirPath) {
261
- const files = [];
262
- const allowedExtensions = ['.ts', '.tsx', '.js', '.jsx', '.vue'];
263
- const walkDir = async (dir) => {
264
- try {
265
- const entries = await this.fileSystem.readDirectory(dir);
266
- for (const entry of entries) {
267
- if (entry.isDirectory) {
268
- await walkDir(entry.path);
269
- }
270
- else if (entry.isFile) {
271
- if (allowedExtensions.some(ext => entry.name.endsWith(ext))) {
272
- files.push(entry.path);
273
- }
274
- }
275
- }
276
- }
277
- catch {
278
- // 忽略無法存取的目錄
279
- }
280
- };
281
- await walkDir(dirPath);
282
- return files;
283
- }
284
- /**
285
- * 檢查檔案是否引用了指定路徑
286
- */
287
- async fileReferencesPath(filePath, targetPath) {
288
- try {
289
- const content = await this.fileSystem.readFile(filePath, 'utf-8');
290
- const imports = this.importResolver.parseImportStatements(content, filePath);
291
- for (const importStatement of imports) {
292
- // 跳過 node_modules
293
- if (this.importResolver.isNodeModuleImport(importStatement.path)) {
294
- continue;
295
- }
296
- // 解析 import 路徑並檢查是否指向目標檔案
297
- const resolvedPath = this.resolveImportPath(importStatement.path, filePath);
298
- if (this.pathsMatch(resolvedPath, targetPath)) {
299
- return true;
300
- }
301
- }
302
- return false;
303
- }
304
- catch {
305
- return false;
306
- }
307
- }
308
- /**
309
- * 解析 import 路徑為絕對路徑
310
- */
311
- resolveImportPath(importPath, fromFile) {
312
- if (this.importResolver.isNodeModuleImport(importPath)) {
313
- return importPath; // Node 模組不處理
314
- }
315
- if (importPath.startsWith('.')) {
316
- // 相對路徑 - 轉換為絕對路徑
317
- const fromDir = path.dirname(path.isAbsolute(fromFile) ? fromFile : path.resolve(fromFile));
318
- const resolved = path.resolve(fromDir, importPath);
319
- // 正規化路徑
320
- return path.normalize(resolved);
321
- }
322
- // 嘗試解析別名(如 @/ 開頭的路徑映射)
323
- const resolved = this.importResolver.resolvePathAlias(importPath);
324
- if (resolved !== importPath) {
325
- // 如果解析成功(與原始路徑不同)
326
- if (path.isAbsolute(resolved)) {
327
- // 絕對路徑直接返回
328
- return path.normalize(resolved);
329
- }
330
- // 非絕對路徑:相對於專案根目錄或 baseUrl
331
- // 由於 pathAliases 已經在 move.command.ts 中轉為絕對路徑,這裡應該是絕對路徑
332
- // 若仍為相對路徑,則視為相對於當前檔案
333
- const fromDir = path.dirname(path.isAbsolute(fromFile) ? fromFile : path.resolve(fromFile));
334
- const absoluteResolved = path.resolve(fromDir, resolved);
335
- return path.normalize(absoluteResolved);
336
- }
337
- return importPath;
338
- }
339
- /**
340
- * 檢查兩個路徑是否指向同一個檔案
341
- */
342
- pathsMatch(path1, path2) {
343
- try {
344
- // 確保兩個路徑都是絕對路徑並正規化
345
- const abs1 = path.isAbsolute(path1)
346
- ? path.normalize(path1)
347
- : path.normalize(path.resolve(path1));
348
- const abs2 = path.isAbsolute(path2)
349
- ? path.normalize(path2)
350
- : path.normalize(path.resolve(path2));
351
- // 檢查完全匹配
352
- if (abs1 === abs2) {
353
- return true;
354
- }
355
- // 檢查去除副檔名後是否匹配(TypeScript/JavaScript 可以省略副檔名)
356
- const withoutExt1 = this.removeExtension(abs1);
357
- const withoutExt2 = this.removeExtension(abs2);
358
- return withoutExt1 === withoutExt2;
359
- }
360
- catch {
361
- return false;
362
- }
363
- }
364
- /**
365
- * 移除檔案副檔名
366
- */
367
- removeExtension(filePath) {
368
- const ext = path.extname(filePath);
369
- if (['.js', '.ts', '.jsx', '.tsx'].includes(ext)) {
370
- return filePath.slice(0, -ext.length);
371
- }
372
- return filePath;
373
- }
374
- /**
375
- * 計算路徑更新
376
- */
377
- async calculatePathUpdates(filePath, oldPath, newPath) {
378
- const updates = [];
379
- try {
380
- const content = await this.fileSystem.readFile(filePath, 'utf-8');
381
- const imports = this.importResolver.parseImportStatements(content, filePath);
382
- for (const importStatement of imports) {
383
- // 跳過 node_modules
384
- if (this.importResolver.isNodeModuleImport(importStatement.path)) {
385
- continue;
386
- }
387
- // 將 oldPath 規範化為絕對路徑以便比較
388
- const normalizedOldPath = path.isAbsolute(oldPath)
389
- ? path.normalize(oldPath)
390
- : path.normalize(path.resolve(oldPath));
391
- // 計算 import 指向的絕對路徑
392
- const resolvedPath = this.resolveImportPath(importStatement.path, filePath);
393
- // 使用 pathsMatch 檢查是否指向被移動的檔案
394
- if (this.pathsMatch(resolvedPath, normalizedOldPath)) {
395
- // 計算新的 import 路徑,保留原始路徑類型(別名或相對路徑)
396
- const newImportPath = this.calculateNewImportPathPreservingStyle(importStatement.path, filePath, normalizedOldPath, newPath);
397
- const newImport = importStatement.rawStatement.replace(new RegExp(`(['"\`])${this.escapeRegex(importStatement.path)}\\1`), `$1${newImportPath}$1`);
398
- updates.push({
399
- filePath,
400
- line: importStatement.position.line,
401
- oldImport: importStatement.rawStatement,
402
- newImport
403
- });
404
- }
405
- }
406
- }
407
- catch (error) {
408
- console.warn(`無法處理檔案 ${filePath}:`, error);
409
- }
410
- return updates;
411
- }
412
- /**
413
- * 計算被移動檔案內部的 import 更新
414
- * 這些更新會在檔案移動後套用
415
- */
416
- async calculateMovedFileInternalUpdates(source, target) {
417
- const updates = [];
418
- try {
419
- const content = await this.fileSystem.readFile(source, 'utf-8');
420
- const imports = this.importResolver.parseImportStatements(content, source);
421
- // 防禦性檢查:確保 imports 是陣列
422
- if (!imports || !Array.isArray(imports)) {
423
- return updates;
424
- }
425
- for (const importStatement of imports) {
426
- // 跳過 node_modules
427
- if (this.importResolver.isNodeModuleImport(importStatement.path)) {
428
- continue;
429
- }
430
- // 只處理相對路徑的 import
431
- if (importStatement.path.startsWith('.')) {
432
- // 計算這個 import 當前指向的檔案
433
- const sourceDir = path.dirname(source);
434
- const currentResolved = path.resolve(sourceDir, importStatement.path);
435
- // 計算從新位置應該如何 import 這個檔案
436
- const newImportPath = this.calculateNewImportPath(target, currentResolved);
437
- // 如果路徑改變了,加入更新列表
438
- if (newImportPath !== importStatement.path) {
439
- updates.push({
440
- filePath: target, // 注意:這裡是 target,因為更新會在檔案移動後套用
441
- line: importStatement.position.line,
442
- oldImport: importStatement.rawStatement,
443
- newImport: importStatement.rawStatement.replace(new RegExp(`(['"\`])${this.escapeRegex(importStatement.path)}\\1`), `$1${newImportPath}$1`)
444
- });
445
- }
446
- }
447
- }
448
- }
449
- catch (error) {
450
- console.warn(`無法處理被移動檔案的內部 import ${source}:`, error);
451
- }
452
- return updates;
453
- }
454
- /**
455
- * 計算新的 import 路徑,保留原始路徑樣式(別名或相對路徑)
456
- */
457
- calculateNewImportPathPreservingStyle(originalImportPath, fromFile, oldFilePath, newFilePath) {
458
- // 如果原本是路徑別名,保留別名並更新路徑
459
- if (!originalImportPath.startsWith('.') && !originalImportPath.startsWith('/')) {
460
- // 檢查是否為路徑別名(精確匹配:alias 本身或 alias/ 開頭)
461
- for (const [alias, aliasPath] of Object.entries(this.importResolver['config'].pathAliases)) {
462
- if (originalImportPath === alias || originalImportPath.startsWith(alias + '/')) {
463
- const resolvedAliasPath = path.normalize(aliasPath);
464
- // 計算新檔案相對於別名基礎路徑的相對路徑
465
- let newRelativeToAlias = path.relative(resolvedAliasPath, path.normalize(newFilePath));
466
- newRelativeToAlias = newRelativeToAlias.replace(/\\/g, '/');
467
- // 移除副檔名
468
- const newExt = path.extname(newRelativeToAlias);
469
- if (['.js', '.ts', '.jsx', '.tsx'].includes(newExt)) {
470
- newRelativeToAlias = newRelativeToAlias.slice(0, -newExt.length);
471
- }
472
- // 組合新的別名路徑:alias + / + newRelativeToAlias
473
- // 如果 alias 本身不以 / 結尾,需要加上
474
- const separator = alias.endsWith('/') ? '' : '/';
475
- return alias + separator + newRelativeToAlias;
476
- }
477
- }
478
- }
479
- // 否則使用相對路徑
480
- return this.calculateNewImportPath(fromFile, newFilePath);
481
- }
482
- /**
483
- * 計算新的 import 路徑
484
- */
485
- calculateNewImportPath(fromFile, toFile) {
486
- const fromDir = path.dirname(fromFile);
487
- let relativePath = path.relative(fromDir, toFile);
488
- // 移除副檔名(如果目標是支援的檔案類型)
489
- const ext = path.extname(relativePath);
490
- if (['.js', '.ts', '.jsx', '.tsx'].includes(ext)) {
491
- relativePath = relativePath.slice(0, -ext.length);
492
- }
493
- // 確保相對路徑以 ./ 或 ../ 開始
494
- if (!relativePath.startsWith('.')) {
495
- relativePath = './' + relativePath;
496
- }
497
- // 統一使用正斜線
498
- return relativePath.replace(/\\/g, '/');
499
- }
500
334
  /**
501
335
  * 應用路徑更新
502
336
  */
@@ -507,7 +341,10 @@ export class MoveService {
507
341
  if (!fileUpdates.has(update.filePath)) {
508
342
  fileUpdates.set(update.filePath, []);
509
343
  }
510
- fileUpdates.get(update.filePath).push(update);
344
+ const list = fileUpdates.get(update.filePath);
345
+ if (list) {
346
+ list.push(update);
347
+ }
511
348
  }
512
349
  // 逐檔案應用更新
513
350
  for (const [filePath, fileUpdateList] of fileUpdates) {
@@ -532,7 +369,7 @@ export class MoveService {
532
369
  const contentNormalized = newContent.replace(/\s+/g, ' ');
533
370
  if (contentNormalized.indexOf(normalizedOldImport) !== -1) {
534
371
  newContent = content; // 重置
535
- newContent = newContent.replace(new RegExp(this.escapeRegex(normalizedOldImport).replace(/\s+/g, '\\s+'), 'g'), update.newImport.replace(/\s+/g, ' ').trim());
372
+ newContent = newContent.replace(new RegExp(this.pathUtils.escapeRegex(normalizedOldImport).replace(/\s+/g, '\\s+'), 'g'), update.newImport.replace(/\s+/g, ' ').trim());
536
373
  }
537
374
  }
538
375
  }
@@ -542,11 +379,5 @@ export class MoveService {
542
379
  throw new Error(`更新檔案 ${filePath} 失敗: ${error instanceof Error ? error.message : 'Unknown error'}`);
543
380
  }
544
381
  }
545
- /**
546
- * 跳脫正則表達式特殊字元
547
- */
548
- escapeRegex(str) {
549
- return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
550
- }
551
382
  }
552
383
  //# sourceMappingURL=move-service.js.map