agent-ide 0.10.2 → 0.10.3
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.
- package/README.md +36 -26
- package/dist/core/deadcode/dead-code-detector.d.ts.map +1 -1
- package/dist/core/deadcode/dead-code-detector.js +3 -2
- package/dist/core/deadcode/dead-code-detector.js.map +1 -1
- package/dist/core/deadcode/dead-code-remover.d.ts.map +1 -1
- package/dist/core/deadcode/dead-code-remover.js +3 -2
- package/dist/core/deadcode/dead-code-remover.js.map +1 -1
- package/dist/core/foundations/dependency-graph/dependency-graph.d.ts +27 -3
- package/dist/core/foundations/dependency-graph/dependency-graph.d.ts.map +1 -1
- package/dist/core/foundations/dependency-graph/dependency-graph.js +92 -5
- package/dist/core/foundations/dependency-graph/dependency-graph.js.map +1 -1
- package/dist/core/foundations/symbol-finder/symbol-finder.d.ts.map +1 -1
- package/dist/core/foundations/symbol-finder/symbol-finder.js +95 -74
- package/dist/core/foundations/symbol-finder/symbol-finder.js.map +1 -1
- package/dist/core/move/file-scanner.d.ts.map +1 -1
- package/dist/core/move/file-scanner.js +17 -9
- package/dist/core/move/file-scanner.js.map +1 -1
- package/dist/core/move/index.d.ts +0 -1
- package/dist/core/move/index.d.ts.map +1 -1
- package/dist/core/move/index.js +0 -1
- package/dist/core/move/index.js.map +1 -1
- package/dist/core/move/move-service.d.ts.map +1 -1
- package/dist/core/move/move-service.js +3 -2
- package/dist/core/move/move-service.js.map +1 -1
- package/dist/core/move/path-calculator.d.ts +5 -3
- package/dist/core/move/path-calculator.d.ts.map +1 -1
- package/dist/core/move/path-calculator.js +42 -4
- package/dist/core/move/path-calculator.js.map +1 -1
- package/dist/core/move/types.d.ts +10 -0
- package/dist/core/move/types.d.ts.map +1 -1
- package/dist/core/move/types.js.map +1 -1
- package/dist/core/rename/reference-updater.d.ts +2 -1
- package/dist/core/rename/reference-updater.d.ts.map +1 -1
- package/dist/core/rename/reference-updater.js +23 -5
- package/dist/core/rename/reference-updater.js.map +1 -1
- package/dist/infrastructure/changeset/change-applicator.d.ts.map +1 -1
- package/dist/infrastructure/changeset/change-applicator.js +5 -4
- package/dist/infrastructure/changeset/change-applicator.js.map +1 -1
- package/dist/infrastructure/formatters/strategies/analyze-formatter.d.ts.map +1 -1
- package/dist/infrastructure/formatters/strategies/analyze-formatter.js +10 -15
- package/dist/infrastructure/formatters/strategies/analyze-formatter.js.map +1 -1
- package/dist/infrastructure/formatters/strategies/call-hierarchy-formatter.d.ts +0 -4
- package/dist/infrastructure/formatters/strategies/call-hierarchy-formatter.d.ts.map +1 -1
- package/dist/infrastructure/formatters/strategies/call-hierarchy-formatter.js +13 -26
- package/dist/infrastructure/formatters/strategies/call-hierarchy-formatter.js.map +1 -1
- package/dist/infrastructure/formatters/strategies/find-references-formatter.d.ts +0 -4
- package/dist/infrastructure/formatters/strategies/find-references-formatter.d.ts.map +1 -1
- package/dist/infrastructure/formatters/strategies/find-references-formatter.js +10 -20
- package/dist/infrastructure/formatters/strategies/find-references-formatter.js.map +1 -1
- package/dist/infrastructure/formatters/utils/grouping.d.ts +32 -0
- package/dist/infrastructure/formatters/utils/grouping.d.ts.map +1 -0
- package/dist/infrastructure/formatters/utils/grouping.js +33 -0
- package/dist/infrastructure/formatters/utils/grouping.js.map +1 -0
- package/dist/infrastructure/formatters/utils/index.d.ts +5 -0
- package/dist/infrastructure/formatters/utils/index.d.ts.map +1 -0
- package/dist/infrastructure/formatters/utils/index.js +5 -0
- package/dist/infrastructure/formatters/utils/index.js.map +1 -0
- package/dist/infrastructure/parser/registry.d.ts.map +1 -1
- package/dist/infrastructure/parser/registry.js +2 -2
- package/dist/infrastructure/parser/registry.js.map +1 -1
- package/dist/infrastructure/worker-pool/workers/parse-worker.d.ts.map +1 -1
- package/dist/infrastructure/worker-pool/workers/parse-worker.js +2 -1
- package/dist/infrastructure/worker-pool/workers/parse-worker.js.map +1 -1
- package/dist/interfaces/cli/command-utils.d.ts +82 -0
- package/dist/interfaces/cli/command-utils.d.ts.map +1 -0
- package/dist/interfaces/cli/command-utils.js +95 -0
- package/dist/interfaces/cli/command-utils.js.map +1 -0
- package/dist/interfaces/cli/commands/call-hierarchy.command.d.ts.map +1 -1
- package/dist/interfaces/cli/commands/call-hierarchy.command.js +8 -9
- package/dist/interfaces/cli/commands/call-hierarchy.command.js.map +1 -1
- package/dist/interfaces/cli/commands/change-signature.command.d.ts.map +1 -1
- package/dist/interfaces/cli/commands/change-signature.command.js +16 -36
- package/dist/interfaces/cli/commands/change-signature.command.js.map +1 -1
- package/dist/interfaces/cli/commands/cycles.command.d.ts.map +1 -1
- package/dist/interfaces/cli/commands/cycles.command.js +8 -9
- package/dist/interfaces/cli/commands/cycles.command.js.map +1 -1
- package/dist/interfaces/cli/commands/deadcode.command.d.ts.map +1 -1
- package/dist/interfaces/cli/commands/deadcode.command.js +37 -55
- package/dist/interfaces/cli/commands/deadcode.command.js.map +1 -1
- package/dist/interfaces/cli/commands/find-references.command.d.ts.map +1 -1
- package/dist/interfaces/cli/commands/find-references.command.js +8 -9
- package/dist/interfaces/cli/commands/find-references.command.js.map +1 -1
- package/dist/interfaces/cli/commands/impact.command.d.ts.map +1 -1
- package/dist/interfaces/cli/commands/impact.command.js +8 -9
- package/dist/interfaces/cli/commands/impact.command.js.map +1 -1
- package/dist/interfaces/cli/commands/move.command.d.ts.map +1 -1
- package/dist/interfaces/cli/commands/move.command.js +44 -55
- package/dist/interfaces/cli/commands/move.command.js.map +1 -1
- package/dist/interfaces/cli/commands/rename.command.d.ts.map +1 -1
- package/dist/interfaces/cli/commands/rename.command.js +18 -92
- package/dist/interfaces/cli/commands/rename.command.js.map +1 -1
- package/dist/interfaces/cli/commands/snapshot.command.d.ts.map +1 -1
- package/dist/interfaces/cli/commands/snapshot.command.js +6 -8
- package/dist/interfaces/cli/commands/snapshot.command.js.map +1 -1
- package/dist/interfaces/cli/path-location-parser.d.ts +49 -0
- package/dist/interfaces/cli/path-location-parser.d.ts.map +1 -0
- package/dist/interfaces/cli/path-location-parser.js +77 -0
- package/dist/interfaces/cli/path-location-parser.js.map +1 -0
- package/dist/plugins/javascript/parser.d.ts +2 -0
- package/dist/plugins/javascript/parser.d.ts.map +1 -1
- package/dist/plugins/javascript/parser.js +16 -3
- package/dist/plugins/javascript/parser.js.map +1 -1
- package/dist/plugins/javascript/pattern-analyzer.d.ts.map +1 -1
- package/dist/plugins/javascript/pattern-analyzer.js +2 -1
- package/dist/plugins/javascript/pattern-analyzer.js.map +1 -1
- package/dist/plugins/typescript/parser.d.ts +7 -0
- package/dist/plugins/typescript/parser.d.ts.map +1 -1
- package/dist/plugins/typescript/parser.js +24 -2
- package/dist/plugins/typescript/parser.js.map +1 -1
- package/dist/shared/errors/error-utils.d.ts +11 -0
- package/dist/shared/errors/error-utils.d.ts.map +1 -0
- package/dist/shared/errors/error-utils.js +13 -0
- package/dist/shared/errors/error-utils.js.map +1 -0
- package/dist/shared/errors/index.d.ts +1 -0
- package/dist/shared/errors/index.d.ts.map +1 -1
- package/dist/shared/errors/index.js +2 -0
- package/dist/shared/errors/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/core/move/path-parser.d.ts +0 -33
- package/dist/core/move/path-parser.d.ts.map +0 -1
- package/dist/core/move/path-parser.js +0 -53
- package/dist/core/move/path-parser.js.map +0 -1
|
@@ -6,7 +6,9 @@ import * as path from 'path';
|
|
|
6
6
|
import { ImpactAnalyzer } from '../../../core/impact/index.js';
|
|
7
7
|
import { CycleDetector } from '../../../core/cycles/index.js';
|
|
8
8
|
import { QueryCommand } from '../../../infrastructure/formatters/index.js';
|
|
9
|
-
import { createUnifiedOutputHandler,
|
|
9
|
+
import { createUnifiedOutputHandler, OutputFormat } from '../../cli/unified-output-handler.js';
|
|
10
|
+
import { tryParseOutputFormat } from '../../cli/command-utils.js';
|
|
11
|
+
import { getErrorMessage } from '../../../shared/errors/index.js';
|
|
10
12
|
/**
|
|
11
13
|
* 設定 cycles 命令
|
|
12
14
|
*/
|
|
@@ -25,15 +27,12 @@ export function setupCyclesCommand(program, context) {
|
|
|
25
27
|
*/
|
|
26
28
|
async function handleCyclesCommand(options, context) {
|
|
27
29
|
const outputHandler = createUnifiedOutputHandler();
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
catch {
|
|
33
|
-
outputHandler.outputError('不支援的輸出格式。可用格式: json, summary', OutputFormat.Summary);
|
|
34
|
-
process.exitCode = 1;
|
|
30
|
+
// 解析輸出格式
|
|
31
|
+
const formatResult = tryParseOutputFormat(options.format, false, outputHandler);
|
|
32
|
+
if (!formatResult.success) {
|
|
35
33
|
return;
|
|
36
34
|
}
|
|
35
|
+
const format = formatResult.format;
|
|
37
36
|
const analyzePath = path.resolve(options.path || process.cwd());
|
|
38
37
|
// 檢查路徑是否存在(在進度訊息前檢查)
|
|
39
38
|
const pathExists = await context.fileSystem.exists(analyzePath);
|
|
@@ -78,7 +77,7 @@ async function handleCyclesCommand(options, context) {
|
|
|
78
77
|
outputHandler.outputQuery(result, format);
|
|
79
78
|
}
|
|
80
79
|
catch (error) {
|
|
81
|
-
const errorMessage =
|
|
80
|
+
const errorMessage = getErrorMessage(error);
|
|
82
81
|
outputHandler.outputError(`依賴分析失敗: ${errorMessage}`, format);
|
|
83
82
|
process.exitCode = 1;
|
|
84
83
|
if (process.env.NODE_ENV !== 'test') {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cycles.command.js","sourceRoot":"","sources":["../../../../src/interfaces/cli/commands/cycles.command.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAmC,MAAM,qCAAqC,CAAC;AACpG,OAAO,EAAE,0BAA0B,EAAE,
|
|
1
|
+
{"version":3,"file":"cycles.command.js","sour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K,CAAC,UAAU;gBAC9B,WAAW,EAAE,MAAM,CAAC,MAAM;gBAC1B,UAAU,EAAE,KAAK,CAAC,UAAU;gBAC5B,iBAAiB,EAAE,KAAK,CAAC,iBAAiB;gBAC1C,WAAW,EAAE,MAAM,CAAC,MAAM;aAC3B;YACD,QAAQ,EAAE,WAAW;SACtB,CAAC;QAEF,aAAa,CAAC,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,YAAY,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC;QAC5C,aAAa,CAAC,WAAW,CAAC,WAAW,YAAY,EAAE,EAAE,MAAM,CAAC,CAAC;QAC7D,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;QACrB,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,MAAM,EAAE,CAAC;YAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAAC,CAAC;IAC3D,CAAC;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deadcode.command.d.ts","sourceRoot":"","sources":["../../../../src/interfaces/cli/commands/deadcode.command.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"deadcode.command.d.ts","sourceRoot":"","sources":["../../../../src/interfaces/cli/commands/deadcode.command.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAazC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AAaxE;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,cAAc,GAAG,IAAI,CAapF"}
|
|
@@ -5,8 +5,9 @@
|
|
|
5
5
|
import { IndexEngine, createIndexConfig, CLI_INDEX_DEFAULTS } from '../../../core/foundations/indexing/index.js';
|
|
6
6
|
import { createDeadCodeDetector, createDeadCodeRemover } from '../../../core/deadcode/index.js';
|
|
7
7
|
import { ParserRegistry } from '../../../infrastructure/parser/registry.js';
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
8
|
+
import { createUnifiedOutputHandler, OutputFormat } from '../../cli/unified-output-handler.js';
|
|
9
|
+
import { tryParseOutputFormat, executeMutationCommand } from '../../cli/command-utils.js';
|
|
10
|
+
import { getErrorMessage } from '../../../shared/errors/index.js';
|
|
10
11
|
/**
|
|
11
12
|
* 設定 deadcode 命令
|
|
12
13
|
*/
|
|
@@ -39,17 +40,12 @@ async function runDeadCodeDetection(options, context, indexEngine, parserRegistr
|
|
|
39
40
|
*/
|
|
40
41
|
async function handleDeadCodeCommand(options, context) {
|
|
41
42
|
const outputHandler = createUnifiedOutputHandler();
|
|
42
|
-
//
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
format = parseOutputFormat(formatStr, true); // 允許 diff
|
|
47
|
-
}
|
|
48
|
-
catch {
|
|
49
|
-
outputHandler.outputError('不支援的輸出格式。可用格式: json, summary, diff', OutputFormat.Summary);
|
|
50
|
-
process.exitCode = 1;
|
|
51
|
-
throw new Error('不支援的輸出格式');
|
|
43
|
+
// 解析輸出格式
|
|
44
|
+
const formatResult = tryParseOutputFormat(options.format, true, outputHandler);
|
|
45
|
+
if (!formatResult.success) {
|
|
46
|
+
return;
|
|
52
47
|
}
|
|
48
|
+
const format = formatResult.format;
|
|
53
49
|
const isJsonFormat = format === OutputFormat.Json;
|
|
54
50
|
if (!isJsonFormat) {
|
|
55
51
|
console.log(' 檢測並準備刪除 Dead Code...');
|
|
@@ -60,7 +56,7 @@ async function handleDeadCodeCommand(options, context) {
|
|
|
60
56
|
if (!exists) {
|
|
61
57
|
outputHandler.outputError(`路徑不存在: ${projectPath}`, format);
|
|
62
58
|
process.exitCode = 1;
|
|
63
|
-
|
|
59
|
+
return;
|
|
64
60
|
}
|
|
65
61
|
// 建立索引引擎
|
|
66
62
|
const indexConfig = createIndexConfig(projectPath, CLI_INDEX_DEFAULTS);
|
|
@@ -95,15 +91,10 @@ async function handleDeadCodeCommand(options, context) {
|
|
|
95
91
|
excludeSymbols,
|
|
96
92
|
cleanupImports: true
|
|
97
93
|
});
|
|
98
|
-
// 3.
|
|
94
|
+
// 3. 生成 Changeset
|
|
99
95
|
const changeset = await remover.generateChangeset(detectionResult.items);
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
process.exitCode = 1;
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
// 無變更時的處理
|
|
106
|
-
if (changeset.textChanges.length === 0) {
|
|
96
|
+
// 無變更時的處理(changeset.success 但無 textChanges)
|
|
97
|
+
if (changeset.success && changeset.textChanges.length === 0) {
|
|
107
98
|
if (!isJsonFormat) {
|
|
108
99
|
console.log(' 符合條件的 dead code 已被過濾(排除規則)');
|
|
109
100
|
if (changeset.warnings && changeset.warnings.length > 0) {
|
|
@@ -123,47 +114,38 @@ async function handleDeadCodeCommand(options, context) {
|
|
|
123
114
|
}
|
|
124
115
|
return;
|
|
125
116
|
}
|
|
126
|
-
// 4.
|
|
127
|
-
|
|
128
|
-
// 5. Dry-run 模式只輸出預覽
|
|
129
|
-
if (options.dryRun) {
|
|
130
|
-
outputHandler.outputMutation(previewInput, format);
|
|
131
|
-
if (!isJsonFormat) {
|
|
132
|
-
console.log('\n 移除 --dry-run 實際執行刪除');
|
|
133
|
-
}
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
// 6. 應用變更(帶回滾)
|
|
137
|
-
if (!isJsonFormat) {
|
|
117
|
+
// 4. 執行變更類命令統一流程
|
|
118
|
+
if (!isJsonFormat && !options.dryRun) {
|
|
138
119
|
console.log(' 執行刪除...');
|
|
139
120
|
}
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
121
|
+
const result = await executeMutationCommand(changeset, {
|
|
122
|
+
fileSystem: context.fileSystem,
|
|
123
|
+
format,
|
|
124
|
+
dryRun: options.dryRun,
|
|
125
|
+
outputHandler,
|
|
126
|
+
commandName: 'deadcode',
|
|
127
|
+
onSuccess: () => {
|
|
128
|
+
if (!isJsonFormat) {
|
|
129
|
+
const totalRemovals = changeset.textChanges
|
|
130
|
+
.flatMap(tc => tc.edits)
|
|
131
|
+
.filter(e => e.description?.startsWith('Remove ')).length;
|
|
132
|
+
const importsCleanedUp = changeset.textChanges
|
|
133
|
+
.flatMap(tc => tc.edits)
|
|
134
|
+
.filter(e => e.description?.includes('import')).length;
|
|
135
|
+
console.log(`\n 已刪除 ${totalRemovals} 個 dead code`);
|
|
136
|
+
if (importsCleanedUp > 0) {
|
|
137
|
+
console.log(` 並清理 ${importsCleanedUp} 個未使用的 import`);
|
|
138
|
+
}
|
|
157
139
|
}
|
|
158
140
|
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
141
|
+
});
|
|
142
|
+
// dry-run 提示
|
|
143
|
+
if (options.dryRun && result.success && !isJsonFormat) {
|
|
144
|
+
console.log('\n 移除 --dry-run 實際執行刪除');
|
|
163
145
|
}
|
|
164
146
|
}
|
|
165
147
|
catch (error) {
|
|
166
|
-
const errorMessage =
|
|
148
|
+
const errorMessage = getErrorMessage(error);
|
|
167
149
|
outputHandler.outputError(`Dead code 刪除失敗: ${errorMessage}`, format);
|
|
168
150
|
process.exitCode = 1;
|
|
169
151
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deadcode.command.js","sourceRoot":"","sources":["../../../../src/interfaces/cli/commands/deadcode.command.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AACzG,OAAO,EACL,sBAAsB,EACtB,qBAAqB,EAEtB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,
|
|
1
|
+
{"version":3,"file":"deadcode.command.js","sourceRoot":"","sources":["../../../../src/interfaces/cli/commands/deadcode.command.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AACzG,OAAO,EACL,sBAAsB,EACtB,qBAAqB,EAEtB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,EACL,0BAA0B,EAC1B,YAAY,EACb,MAAM,2CAA2C,CAAC;AACnD,OAAO,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,MAAM,kCAAkC,CAAC;AAEhG,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAY1D;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAAC,OAAgB,EAAE,OAAuB;IAC5E,OAAO;SACJ,OAAO,CAAC,UAAU,CAAC;SACnB,WAAW,CAAC,yBAAyB,CAAC;SACtC,MAAM,CAAC,mBAAmB,EAAE,MAAM,EAAE,GAAG,CAAC;SACxC,MAAM,CAAC,mBAAmB,EAAE,0BAA0B,EAAE,SAAS,CAAC;SAClE,MAAM,CAAC,mBAAmB,EAAE,qBAAqB,EAAE,KAAK,CAAC;SACzD,MAAM,CAAC,0BAA0B,EAAE,+BAA+B,EAAE,KAAK,CAAC;SAC1E,MAAM,CAAC,WAAW,EAAE,UAAU,CAAC;SAC/B,MAAM,CAAC,yBAAyB,EAAE,YAAY,CAAC;SAC/C,MAAM,CAAC,KAAK,EAAE,OAAwB,EAAE,EAAE;QACzC,MAAM,qBAAqB,CAAC,OAAO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MAAM,CAAC,OAAO,IAAI,CAAC,YAAY,EAAE,CAAC;YACtD,OAAO,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAC;QAC1C,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,YAAY,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC;QAC5C,aAAa,CAAC,WAAW,CAAC,mBAAmB,YAAY,EAAE,EAAE,MAAM,CAAC,CAAC;QACrE,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;IACvB,CAAC;YAAS,CAAC;QACT,WAAW,CAAC,OAAO,EAAE,CAAC;IACxB,CAAC;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"find-references.command.d.ts","sourceRoot":"","sources":["../../../../src/interfaces/cli/commands/find-references.command.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAsBzC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;
|
|
1
|
+
{"version":3,"file":"find-references.command.d.ts","sourceRoot":"","sources":["../../../../src/interfaces/cli/commands/find-references.command.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAsBzC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AASxE;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,cAAc,GAAG,IAAI,CAS1F"}
|
|
@@ -6,7 +6,9 @@ import { IndexEngine, createIndexConfig, CLI_INDEX_DEFAULTS } from '../../../cor
|
|
|
6
6
|
import { createSymbolFinder, SymbolReferenceType, symbolToKey, serializeSymbolKey } from '../../../core/foundations/symbol-finder/index.js';
|
|
7
7
|
import { ParserRegistry } from '../../../infrastructure/parser/registry.js';
|
|
8
8
|
import { QueryCommand } from '../../../infrastructure/formatters/index.js';
|
|
9
|
-
import { createUnifiedOutputHandler,
|
|
9
|
+
import { createUnifiedOutputHandler, OutputFormat } from '../../cli/unified-output-handler.js';
|
|
10
|
+
import { tryParseOutputFormat } from '../../cli/command-utils.js';
|
|
11
|
+
import { getErrorMessage } from '../../../shared/errors/index.js';
|
|
10
12
|
/**
|
|
11
13
|
* 設定 find-references 命令
|
|
12
14
|
*/
|
|
@@ -25,15 +27,12 @@ export function setupFindReferencesCommand(program, context) {
|
|
|
25
27
|
*/
|
|
26
28
|
async function handleFindReferencesCommand(symbolName, options, context) {
|
|
27
29
|
const outputHandler = createUnifiedOutputHandler();
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
catch {
|
|
33
|
-
outputHandler.outputError('不支援的輸出格式。可用格式: json, summary', OutputFormat.Summary);
|
|
34
|
-
process.exitCode = 1;
|
|
30
|
+
// 解析輸出格式
|
|
31
|
+
const formatResult = tryParseOutputFormat(options.format, false, outputHandler);
|
|
32
|
+
if (!formatResult.success) {
|
|
35
33
|
return;
|
|
36
34
|
}
|
|
35
|
+
const format = formatResult.format;
|
|
37
36
|
if (format !== OutputFormat.Json) {
|
|
38
37
|
console.log(`🔍 查找符號引用: ${symbolName}...`);
|
|
39
38
|
}
|
|
@@ -111,7 +110,7 @@ async function handleFindReferencesCommand(symbolName, options, context) {
|
|
|
111
110
|
outputHandler.outputQuery(result, format);
|
|
112
111
|
}
|
|
113
112
|
catch (error) {
|
|
114
|
-
const errorMessage =
|
|
113
|
+
const errorMessage = getErrorMessage(error);
|
|
115
114
|
// 區分索引錯誤和查找錯誤
|
|
116
115
|
const isIndexError = errorMessage.includes('索引')
|
|
117
116
|
|| errorMessage.includes('index')
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"find-references.command.js","sourceRoot":"","sources":["../../../../src/interfaces/cli/commands/find-references.command.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AACzG,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,WAAW,EACX,kBAAkB,EAEnB,MAAM,0CAA0C,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,EACL,YAAY,EAKb,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EACL,0BAA0B,EAC1B,
|
|
1
|
+
{"version":3,"file":"find-references.command.js","sourceRoot":"","sources":["../../../../src/interfaces/cli/commands/find-references.command.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AACzG,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,WAAW,EACX,kBAAkB,EAEnB,MAAM,0CAA0C,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,EACL,YAAY,EAKb,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EACL,0BAA0B,EAC1B,YAAY,EACb,MAAM,2CAA2C,CAAC;AACnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AAExE,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAQ1D;;GAEG;AACH,MAAM,UAAU,0BAA0B,CAAC,OAAgB,EAAE,OAAuB;IAClF,OAAO;SACJ,OAAO,CAAC,0BAA0B,CAAC;SACnC,WAAW,CAAC,cAAc,CAAC;SAC3B,MAAM,CAAC,mBAAmB,EAAE,MAAM,EAAE,GAAG,CAAC;SACxC,MAAM,CAAC,mBAAmB,EAAE,qBAAqB,EAAE,SAAS,CAAC;SAC7D,MAAM,CAAC,KAAK,EAAE,MAAc,EAAE,OAA8B,EAAE,EAAE;QAC/D,MAAM,2BAA2B,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IAC9D,C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AY,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC;QAE5C,cAAc;QACd,MAAM,YAAY,GAAG,YAAY,CAAC,QAAQ,CAAC,IAAI,CAAC;eAC3C,YAAY,CAAC,QAAQ,CAAC,OAAO,CAAC;eAC9B,YAAY,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QACrC,MAAM,WAAW,GAAG,YAAY,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC;QAEvD,aAAa,CAAC,WAAW,CAAC,GAAG,WAAW,KAAK,YAAY,EAAE,EAAE,MAAM,CAAC,CAAC;QACrE,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;IACvB,CAAC;YAAS,CAAC;QACT,WAAW,CAAC,OAAO,EAAE,CAAC;IACxB,CAAC;AACH,CAAC;AAED;;GAEG;AACH,SAAS,gBAAgB,CAAC,IAAyB;IACjD,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,mBAAmB,CAAC,UAAU;YACjC,OAAO,YAAY,CAAC;QACtB,KAAK,mBAAmB,CAAC,MAAM;YAC7B,OAAO,QAAQ,CAAC;QAClB,KAAK,mBAAmB,CAAC,MAAM;YAC7B,OAAO,QAAQ,CAAC;QAClB,KAAK,mBAAmB,CAAC,KAAK,CAAC;QAC/B;YACE,OAAO,OAAO,CAAC;IACnB,CAAC;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"impact.command.d.ts","sourceRoot":"","sources":["../../../../src/interfaces/cli/commands/impact.command.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"impact.command.d.ts","sourceRoot":"","sources":["../../../../src/interfaces/cli/commands/impact.command.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAKzC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AAWxE;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,cAAc,GAAG,IAAI,CAUlF"}
|
|
@@ -5,8 +5,10 @@
|
|
|
5
5
|
import * as path from 'path';
|
|
6
6
|
import { ImpactAnalyzer } from '../../../core/impact/index.js';
|
|
7
7
|
import { QueryCommand } from '../../../infrastructure/formatters/index.js';
|
|
8
|
-
import { createUnifiedOutputHandler,
|
|
8
|
+
import { createUnifiedOutputHandler, OutputFormat } from '../../cli/unified-output-handler.js';
|
|
9
|
+
import { tryParseOutputFormat } from '../../cli/command-utils.js';
|
|
9
10
|
import { loadPathAliases } from '../../../plugins/typescript/tsconfig-loader.js';
|
|
11
|
+
import { getErrorMessage } from '../../../shared/errors/index.js';
|
|
10
12
|
/**
|
|
11
13
|
* 設定 impact 命令
|
|
12
14
|
*/
|
|
@@ -26,15 +28,12 @@ export function setupImpactCommand(program, context) {
|
|
|
26
28
|
*/
|
|
27
29
|
async function handleImpactCommand(options, context) {
|
|
28
30
|
const outputHandler = createUnifiedOutputHandler();
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
catch {
|
|
34
|
-
outputHandler.outputError('不支援的輸出格式。可用格式: json, summary', OutputFormat.Summary);
|
|
35
|
-
process.exitCode = 1;
|
|
31
|
+
// 解析輸出格式
|
|
32
|
+
const formatResult = tryParseOutputFormat(options.format, false, outputHandler);
|
|
33
|
+
if (!formatResult.success) {
|
|
36
34
|
return;
|
|
37
35
|
}
|
|
36
|
+
const format = formatResult.format;
|
|
38
37
|
const analyzePath = path.resolve(options.path || process.cwd());
|
|
39
38
|
// 檢查專案路徑是否存在(在進度訊息前檢查)
|
|
40
39
|
const pathExists = await context.fileSystem.exists(analyzePath);
|
|
@@ -92,7 +91,7 @@ async function handleImpactCommand(options, context) {
|
|
|
92
91
|
outputHandler.outputQuery(result, format);
|
|
93
92
|
}
|
|
94
93
|
catch (error) {
|
|
95
|
-
const errorMessage =
|
|
94
|
+
const errorMessage = getErrorMessage(error);
|
|
96
95
|
outputHandler.outputError(`依賴分析失敗: ${errorMessage}`, format);
|
|
97
96
|
process.exitCode = 1;
|
|
98
97
|
if (process.env.NODE_ENV !== 'test') {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"impact.command.js","sourceRoot":"","sources":["../../../../src/interfaces/cli/commands/impact.command.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAmB,MAAM,qCAAqC,CAAC;AACpF,OAAO,EAAE,0BAA0B,EAAE,
|
|
1
|
+
{"version":3,"file":"impact.command.js","sourceRoot":"","sources":["../../../../src/interfaces/cli/commands/impact.command.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAmB,MAAM,qCAAqC,CAAC;AACpF,OAAO,EAAE,0BAA0B,EAAE,YAAY,EAAE,MAAM,2CAA2C,CAAC;AACrG,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AAExE,OAAO,EAAE,eAAe,EAAE,MAAM,wCAAwC,CAAC;AACzE,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAS1D;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,OAAgB,EAAE,OAAuB;IAC1E,OAAO;SACJ,OAAO,CAAC,QAAQ,CAAC;SACjB,WAAW,CAAC,UAAU,CAAC;SACvB,cAAc,CAAC,mBAAmB,EAAE,QAAQ,CAAC;SAC7C,MAAM,CAAC,mBAAmB,EAAE,MAAM,EAAE,GAAG,CAAC;SACxC,MAAM,CAAC,m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,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,YAAY,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC;QAC5C,aAAa,CAAC,WAAW,CAAC,WAAW,YAAY,EAAE,EAAE,MAAM,CAAC,CAAC;QAC7D,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;QACrB,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,MAAM,EAAE,CAAC;YAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAAC,CAAC;IAC3D,CAAC;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"move.command.d.ts","sourceRoot":"","sources":["../../../../src/interfaces/cli/commands/move.command.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"move.command.d.ts","sourceRoot":"","sources":["../../../../src/interfaces/cli/commands/move.command.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAUzC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AA0CxE;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,cAAc,GAAG,IAAI,CA+ChF"}
|
|
@@ -6,13 +6,15 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import * as path from 'path';
|
|
8
8
|
import { MoveService } from '../../../core/move/move-service.js';
|
|
9
|
-
import { parseMoveTarget, hasPositionInfo } from '../../../core/move/path-parser.js';
|
|
10
9
|
import { MoveMemberService, MoveTargetType } from '../../../core/move-member/index.js';
|
|
10
|
+
import { parsePathLocation, hasPositionInfo } from '../../cli/path-location-parser.js';
|
|
11
11
|
import { ParserRegistry } from '../../../infrastructure/parser/registry.js';
|
|
12
12
|
import { ChangeApplicator, convertChangesetToPreviewInput, ChangesetBuilder } from '../../../infrastructure/changeset/index.js';
|
|
13
13
|
import { FileOperationType } from '../../../infrastructure/changeset/index.js';
|
|
14
|
-
import { createUnifiedOutputHandler,
|
|
14
|
+
import { createUnifiedOutputHandler, OutputFormat } from '../../cli/unified-output-handler.js';
|
|
15
|
+
import { tryParseOutputFormat, executeMutationCommand } from '../../cli/command-utils.js';
|
|
15
16
|
import { loadTsconfigPathConfig } from '../../../plugins/typescript/tsconfig-loader.js';
|
|
17
|
+
import { getErrorMessage } from '../../../shared/errors/index.js';
|
|
16
18
|
/** 檢查路徑是否包含 glob pattern */
|
|
17
19
|
function isGlobPattern(pattern) {
|
|
18
20
|
return /[*?[\]{}]/.test(pattern);
|
|
@@ -73,7 +75,7 @@ export function setupMoveCommand(program, context) {
|
|
|
73
75
|
}
|
|
74
76
|
else {
|
|
75
77
|
// 解析路徑格式,判斷是檔案移動還是成員移動
|
|
76
|
-
const parsedSource =
|
|
78
|
+
const parsedSource = parsePathLocation(source);
|
|
77
79
|
if (hasPositionInfo(parsedSource)) {
|
|
78
80
|
// 成員移動模式
|
|
79
81
|
await handleMoveMemberCommand(source, target, options, context);
|
|
@@ -90,15 +92,12 @@ export function setupMoveCommand(program, context) {
|
|
|
90
92
|
*/
|
|
91
93
|
async function handleMoveCommand(source, target, options, context) {
|
|
92
94
|
const outputHandler = createUnifiedOutputHandler();
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}
|
|
97
|
-
catch {
|
|
98
|
-
outputHandler.outputError('不支援的輸出格式。可用格式: json, summary, diff', OutputFormat.Summary);
|
|
99
|
-
process.exitCode = 1;
|
|
95
|
+
// 解析輸出格式
|
|
96
|
+
const formatResult = tryParseOutputFormat(options.format, true, outputHandler);
|
|
97
|
+
if (!formatResult.success) {
|
|
100
98
|
return;
|
|
101
99
|
}
|
|
100
|
+
const format = formatResult.format;
|
|
102
101
|
const isJsonFormat = format === OutputFormat.Json;
|
|
103
102
|
const projectRoot = options.path || process.cwd();
|
|
104
103
|
// Bug 1 修復:解析相對路徑為絕對路徑(相對於 --path)
|
|
@@ -211,7 +210,7 @@ async function handleMoveCommand(source, target, options, context) {
|
|
|
211
210
|
}
|
|
212
211
|
}
|
|
213
212
|
catch (error) {
|
|
214
|
-
const errorMsg =
|
|
213
|
+
const errorMsg = getErrorMessage(error);
|
|
215
214
|
outputHandler.outputError(errorMsg, format);
|
|
216
215
|
process.exitCode = 1;
|
|
217
216
|
if (process.env.NODE_ENV !== 'test') {
|
|
@@ -225,15 +224,12 @@ async function handleMoveCommand(source, target, options, context) {
|
|
|
225
224
|
*/
|
|
226
225
|
async function handleGlobMoveCommand(source, target, options, context) {
|
|
227
226
|
const outputHandler = createUnifiedOutputHandler();
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
}
|
|
232
|
-
catch {
|
|
233
|
-
outputHandler.outputError('不支援的輸出格式。可用格式: json, summary, diff', OutputFormat.Summary);
|
|
234
|
-
process.exitCode = 1;
|
|
227
|
+
// 解析輸出格式
|
|
228
|
+
const formatResult = tryParseOutputFormat(options.format, true, outputHandler);
|
|
229
|
+
if (!formatResult.success) {
|
|
235
230
|
return;
|
|
236
231
|
}
|
|
232
|
+
const format = formatResult.format;
|
|
237
233
|
const isJsonFormat = format === OutputFormat.Json;
|
|
238
234
|
const projectRoot = options.path || process.cwd();
|
|
239
235
|
try {
|
|
@@ -293,6 +289,15 @@ async function handleGlobMoveCommand(source, target, options, context) {
|
|
|
293
289
|
// 計算 glob 的基礎目錄(用於保留目錄結構)
|
|
294
290
|
const globBaseDir = getGlobBaseDir(globPattern);
|
|
295
291
|
const absoluteGlobBaseDir = path.resolve(projectRoot, globBaseDir);
|
|
292
|
+
// 建立所有被移動檔案的 source → target 映射(用於識別內部引用)
|
|
293
|
+
const allMovedFilesMap = new Map();
|
|
294
|
+
for (const sourceFile of matchedFiles) {
|
|
295
|
+
const relativePath = path.relative(absoluteGlobBaseDir, sourceFile);
|
|
296
|
+
const targetFile = targetIsDirectory
|
|
297
|
+
? path.join(resolvedTarget, relativePath)
|
|
298
|
+
: resolvedTarget;
|
|
299
|
+
allMovedFilesMap.set(sourceFile, targetFile);
|
|
300
|
+
}
|
|
296
301
|
// 為每個檔案生成 changeset 並合併
|
|
297
302
|
const builder = new ChangesetBuilder();
|
|
298
303
|
const allMovedFiles = [];
|
|
@@ -307,7 +312,11 @@ async function handleGlobMoveCommand(source, target, options, context) {
|
|
|
307
312
|
target: targetFile,
|
|
308
313
|
updateImports: options.updateImports
|
|
309
314
|
};
|
|
310
|
-
|
|
315
|
+
// 傳入 batchMoveInfo 讓服務知道哪些檔案是一起被移動的
|
|
316
|
+
const changeset = await moveService.generateChangeset(moveOperation, {
|
|
317
|
+
projectRoot,
|
|
318
|
+
batchMoveInfo: { allMovedFiles: allMovedFilesMap }
|
|
319
|
+
});
|
|
311
320
|
if (!changeset.success) {
|
|
312
321
|
outputHandler.outputError(changeset.errors?.join(', ') ?? `移動失敗: ${sourceFile}`, format);
|
|
313
322
|
process.exitCode = 1;
|
|
@@ -363,7 +372,7 @@ async function handleGlobMoveCommand(source, target, options, context) {
|
|
|
363
372
|
}
|
|
364
373
|
}
|
|
365
374
|
catch (error) {
|
|
366
|
-
const errorMsg =
|
|
375
|
+
const errorMsg = getErrorMessage(error);
|
|
367
376
|
outputHandler.outputError(errorMsg, format);
|
|
368
377
|
process.exitCode = 1;
|
|
369
378
|
if (process.env.NODE_ENV !== 'test') {
|
|
@@ -429,21 +438,18 @@ function printSuccess(source, target, totalUpdates, movedFiles, isJsonFormat) {
|
|
|
429
438
|
*/
|
|
430
439
|
async function handleMoveMemberCommand(source, target, options, context) {
|
|
431
440
|
const outputHandler = createUnifiedOutputHandler();
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
}
|
|
436
|
-
catch {
|
|
437
|
-
outputHandler.outputError('不支援的輸出格式。可用格式: json, summary, diff', OutputFormat.Summary);
|
|
438
|
-
process.exitCode = 1;
|
|
441
|
+
// 解析輸出格式
|
|
442
|
+
const formatResult = tryParseOutputFormat(options.format, true, outputHandler);
|
|
443
|
+
if (!formatResult.success) {
|
|
439
444
|
return;
|
|
440
445
|
}
|
|
446
|
+
const format = formatResult.format;
|
|
441
447
|
const isJsonFormat = format === OutputFormat.Json;
|
|
442
448
|
const projectRoot = options.path || process.cwd();
|
|
443
449
|
try {
|
|
444
450
|
// 解析 source 和 target 路徑
|
|
445
|
-
const parsedSource =
|
|
446
|
-
const parsedTarget =
|
|
451
|
+
const parsedSource = parsePathLocation(source);
|
|
452
|
+
const parsedTarget = parsePathLocation(target);
|
|
447
453
|
// 解析為絕對路徑
|
|
448
454
|
const sourceFilePath = path.isAbsolute(parsedSource.filePath)
|
|
449
455
|
? parsedSource.filePath
|
|
@@ -482,37 +488,20 @@ async function handleMoveMemberCommand(source, target, options, context) {
|
|
|
482
488
|
};
|
|
483
489
|
// 生成 Changeset
|
|
484
490
|
const changeset = await moveMemberService.generateChangeset(moveMemberOptions);
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
process.exitCode = 1;
|
|
488
|
-
return;
|
|
489
|
-
}
|
|
490
|
-
// 轉換為 PreviewInput
|
|
491
|
-
const previewInput = await convertChangesetToPreviewInput(changeset, context.fileSystem);
|
|
492
|
-
// Dry-run 模式只輸出預覽
|
|
493
|
-
if (options.dryRun) {
|
|
494
|
-
outputHandler.outputMutation(previewInput, format);
|
|
495
|
-
return;
|
|
496
|
-
}
|
|
497
|
-
// 執行變更
|
|
498
|
-
if (!isJsonFormat) {
|
|
491
|
+
// 執行變更類命令統一流程
|
|
492
|
+
if (!isJsonFormat && !options.dryRun) {
|
|
499
493
|
console.log(' 執行移動...');
|
|
500
494
|
}
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
495
|
+
await executeMutationCommand(changeset, {
|
|
496
|
+
fileSystem: context.fileSystem,
|
|
497
|
+
format,
|
|
498
|
+
dryRun: options.dryRun ?? false,
|
|
499
|
+
outputHandler,
|
|
500
|
+
commandName: 'move'
|
|
505
501
|
});
|
|
506
|
-
if (result.success) {
|
|
507
|
-
outputHandler.outputMutation(previewInput, format);
|
|
508
|
-
}
|
|
509
|
-
else {
|
|
510
|
-
outputHandler.outputError(result.errors?.join(', ') ?? '執行失敗', format, 'move');
|
|
511
|
-
process.exitCode = 1;
|
|
512
|
-
}
|
|
513
502
|
}
|
|
514
503
|
catch (error) {
|
|
515
|
-
const errorMsg =
|
|
504
|
+
const errorMsg = getErrorMessage(error);
|
|
516
505
|
outputHandler.outputError(errorMsg, format, 'move');
|
|
517
506
|
process.exitCode = 1;
|
|
518
507
|
}
|