vibecodingmachine-core 2026.2.26-1739 → 2026.3.9-850
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/package.json +1 -1
- package/src/agents/AgentCheckDiscoveryService.js +180 -0
- package/src/agents/AgentCheckService.js +18 -261
- package/src/agents/AgentCheckStatisticsService.js +195 -0
- package/src/agents/EnvironmentConfigurationManager.js +31 -380
- package/src/agents/InstallationType.js +19 -6
- package/src/agents/SimpleAgentCheckService.js +472 -0
- package/src/agents/config-managers/ConfigUtils.js +72 -0
- package/src/agents/config-managers/DefaultConfig.js +58 -0
- package/src/agents/config-managers/EnvVarLoader.js +66 -0
- package/src/agents/config-managers/FileConfigLoader.js +124 -0
- package/src/agents/config-managers/TypeConverters.js +61 -0
- package/src/agents/config-managers/VariableMappings.js +92 -0
- package/src/agents/discovery/AgentDiscoveryService-refactored.js +272 -0
- package/src/agents/discovery/AgentDiscoveryService.js +29 -403
- package/src/agents/discovery/agent-validator.js +262 -0
- package/src/agents/discovery/discovery-results.js +176 -0
- package/src/agents/discovery/discovery-scanner.js +268 -0
- package/src/agents/discovery/discovery-utils.js +161 -0
- package/src/agents/discovery/executable-analyzer.js +290 -0
- package/src/agents/discovery/history-manager.js +310 -0
- package/src/agents/verification/ResultAnalyzer-refactored.js +341 -0
- package/src/agents/verification/ResultAnalyzer.js +30 -431
- package/src/agents/verification/analysis-utils.js +310 -0
- package/src/agents/verification/batch-analyzer.js +440 -0
- package/src/agents/verification/pattern-recognizer.js +369 -0
- package/src/agents/verification/report-generator.js +320 -0
- package/src/agents/verification/test-analyzer.js +290 -0
- package/src/agents/windows/InstallerFactory.js +4 -0
- package/src/agents/windows/VSCodeExtensionInstaller.js +404 -0
- package/src/analysis/analysis-engine.js +314 -0
- package/src/analysis/ast-analyzer.js +342 -0
- package/src/analysis/boundary-detector-refactored.js +378 -0
- package/src/analysis/boundary-detector.js +200 -603
- package/src/analysis/boundary-scanner.js +609 -0
- package/src/analysis/boundary-types.js +118 -0
- package/src/analysis/boundary-utils.js +293 -0
- package/src/analysis/deadline-priority-calculator.js +18 -0
- package/src/analysis/detection-methods.js +347 -0
- package/src/analysis/importance-priority-calculator.js +18 -0
- package/src/analysis/priority/factor-calculators.js +204 -0
- package/src/analysis/priority/factor-helpers.js +71 -0
- package/src/analysis/priority/priority-constants.js +73 -0
- package/src/analysis/priority/priority-factor-calculators.js +301 -0
- package/src/analysis/priority/reasons-generator.js +44 -0
- package/src/analysis/priority-calculator.js +15 -580
- package/src/analysis/strategy-generator.js +16 -66
- package/src/analysis/type-priority-calculator.js +18 -0
- package/src/analysis/urgency-priority-calculator.js +18 -0
- package/src/auto-mode/AutoModeBusinessLogic.js +2 -40
- package/src/commands/disable-requirement.js +60 -0
- package/src/commands/disable-spec.js +60 -0
- package/src/commands/enable-requirement.js +60 -0
- package/src/commands/enable-spec.js +60 -0
- package/src/commands/registry.js +1 -6
- package/src/commands/requirements.js +8 -2
- package/src/ide-integration/applescript-manager.cjs +9 -24
- package/src/ide-integration/cdp-handlers/chat-reader.js +44 -0
- package/src/ide-integration/cdp-handlers/connection-handler.js +88 -0
- package/src/ide-integration/cdp-handlers/continuation-handler.js +314 -0
- package/src/ide-integration/cdp-handlers/message-submitter.js +75 -0
- package/src/ide-integration/cdp-handlers/text-sender.js +138 -0
- package/src/ide-integration/cdp-manager.js +28 -573
- package/src/ide-integration/claude-code-cli-manager.cjs +48 -12
- package/src/ide-integration/ide-openers/claude-opener.js +171 -0
- package/src/ide-integration/ide-openers/cursor-opener.js +53 -0
- package/src/ide-integration/ide-openers/other-ides-opener.js +230 -0
- package/src/ide-integration/ide-openers/vscode-opener.js +147 -0
- package/src/ide-integration/macos-ide-manager.js +20 -582
- package/src/ide-integration/macos-quota-checker.js +164 -0
- package/src/ide-integration/macos-text-sender.js +19 -38
- package/src/ide-integration/provider-manager.cjs +52 -7
- package/src/index.cjs +6 -0
- package/src/index.js +10 -0
- package/src/llm/direct-llm-manager.cjs +501 -0
- package/src/localization/translations/en-part1.js +363 -0
- package/src/localization/translations/en-part2.js +320 -0
- package/src/localization/translations/en.js +4 -687
- package/src/localization/translations/es-part1.js +363 -0
- package/src/localization/translations/es-part2.js +320 -0
- package/src/localization/translations/es.js +4 -688
- package/src/models/file-analysis-collection.js +139 -0
- package/src/models/file-analysis-metrics.js +50 -0
- package/src/models/file-analysis.js +15 -262
- package/src/models/plan-manager.js +410 -0
- package/src/models/refactoring-models.js +380 -0
- package/src/models/refactoring-plan-refactored.js +81 -0
- package/src/models/refactoring-plan.js +2 -663
- package/src/monitoring/alert-system.js +4 -45
- package/src/monitoring/continuous-scan-notifications.js +37 -191
- package/src/monitoring/notification-handlers/base-handler.js +58 -0
- package/src/monitoring/notification-handlers/error-handler.js +36 -0
- package/src/monitoring/notification-handlers/index.js +21 -0
- package/src/monitoring/notification-handlers/new-violation-handler.js +91 -0
- package/src/monitoring/notification-handlers/progress-handler.js +48 -0
- package/src/monitoring/notification-handlers/resolved-violation-handler.js +54 -0
- package/src/monitoring/notification-handlers/threshold-handler.js +36 -0
- package/src/provider-registry.js +8 -0
- package/src/refactoring/boundary/boundary-detector-refactored.js +58 -0
- package/src/refactoring/boundary/boundary-detector.js +26 -596
- package/src/refactoring/boundary/detectors/boundary-analyzers.js +281 -0
- package/src/refactoring/boundary/detectors/boundary-core.js +167 -0
- package/src/refactoring/boundary/detectors/class-detector.js +247 -0
- package/src/refactoring/boundary/detectors/config-detector.js +270 -0
- package/src/refactoring/boundary/detectors/constant-detector.js +269 -0
- package/src/refactoring/boundary/detectors/function-detector.js +248 -0
- package/src/refactoring/boundary/detectors/module-detector.js +249 -0
- package/src/refactoring/boundary/detectors/object-detector.js +247 -0
- package/src/refactoring/boundary/detectors/type-detectors.js +338 -0
- package/src/refactoring/boundary/detectors/utility-detector.js +270 -0
- package/src/refactoring/circular-dependency-resolver-original.js +16 -76
- package/src/refactoring/code-mover-refactored.js +309 -0
- package/src/refactoring/code-mover.js +48 -355
- package/src/refactoring/execution-status.js +18 -0
- package/src/refactoring/execution-strategies.js +172 -0
- package/src/refactoring/file-splitter-core.js +568 -0
- package/src/refactoring/file-splitter-types.js +136 -0
- package/src/refactoring/file-splitter.js +2 -682
- package/src/refactoring/functionality-validator.js +11 -51
- package/src/refactoring/import-manager-refactored.js +385 -0
- package/src/refactoring/import-manager.js +112 -487
- package/src/refactoring/import-models.js +189 -0
- package/src/refactoring/import-parser.js +306 -0
- package/src/refactoring/move-executor.js +431 -0
- package/src/refactoring/move-utils.js +368 -0
- package/src/refactoring/operation-executor.js +76 -0
- package/src/refactoring/plan-creator.js +36 -0
- package/src/refactoring/plan-executor.js +143 -0
- package/src/refactoring/plan-validator.js +68 -0
- package/src/refactoring/refactoring-executor-result.js +70 -0
- package/src/refactoring/refactoring-executor.js +34 -569
- package/src/refactoring/refactoring-operation.js +94 -0
- package/src/refactoring/refactoring-plan.js +69 -0
- package/src/refactoring/refactoring-rollback.js +22 -527
- package/src/refactoring/rollback-handlers/RollbackExecutor.js +107 -0
- package/src/refactoring/rollback-handlers/RollbackManager.js +265 -0
- package/src/refactoring/rollback-handlers/RollbackOperation.js +105 -0
- package/src/refactoring/rollback-handlers/RollbackResult.js +109 -0
- package/src/refactoring/rollback-handlers/RollbackStatistics.js +77 -0
- package/src/refactoring/test-validator.js +32 -448
- package/src/refactoring/validation/baseline-runner.js +71 -0
- package/src/refactoring/validation/report-generator.js +136 -0
- package/src/refactoring/validation/result-comparator.js +92 -0
- package/src/refactoring/validation/test-suite.js +59 -0
- package/src/refactoring/validation/test-validation-result.js +83 -0
- package/src/refactoring/validation/validation-runner.js +95 -0
- package/src/refactoring/validation/validation-status.js +18 -0
- package/src/rui/commands/AgentCommandParser.js +60 -369
- package/src/rui/commands/AgentResponseFormatter.js +7 -47
- package/src/rui/commands/parsers/CommandMapper.js +148 -0
- package/src/rui/commands/parsers/CommandValidator.js +228 -0
- package/src/rui/commands/parsers/ComponentExtractor.js +100 -0
- package/src/rui/commands/parsers/TokenParser.js +69 -0
- package/src/rui/commands/parsers/tokenizer.js +153 -0
- package/src/utils/current-requirement-operations.js +50 -1
- package/src/utils/report-generator.js +18 -514
- package/src/utils/report-generators/analysis-generator.js +115 -0
- package/src/utils/report-generators/base-generator.js +141 -0
- package/src/utils/report-generators/compliance-generator.js +41 -0
- package/src/utils/report-generators/format-handlers.js +185 -0
- package/src/utils/report-generators/refactoring-generator.js +46 -0
- package/src/utils/report-generators/validation-generator.js +63 -0
- package/src/utils/requirement-enable-disable.js +265 -0
- package/src/utils/requirement-helpers/requirement-file-ops.js +69 -1
- package/src/utils/requirement-helpers/requirement-mover.js +88 -1
- package/src/utils/requirement-helpers.js +5 -2
- package/src/utils/smoke-test-cli.js +45 -8
- package/src/utils/specification-enable-disable.js +122 -0
- package/src/utils/specification-helpers.js +30 -4
- package/src/utils/specification-migration.js +5 -5
- package/src/utils/test-comparator.js +118 -0
- package/src/utils/test-config.js +54 -0
- package/src/utils/test-executor.js +133 -0
- package/src/utils/test-parser.js +215 -0
- package/src/utils/test-runner-baseline.js +63 -0
- package/src/utils/test-runner-core.js +98 -0
- package/src/utils/test-runner-report.js +39 -0
- package/src/utils/test-runner-validation.js +71 -0
- package/src/utils/test-runner.js +11 -535
- package/src/validation/comparison-analyzer.js +333 -0
- package/src/validation/compliance-reporter-new.js +282 -0
- package/src/validation/compliance-reporter-refactored.js +344 -0
- package/src/validation/compliance-reporter.js +278 -591
- package/src/validation/compliance-utils.js +278 -0
- package/src/validation/html-generator.js +446 -0
- package/src/validation/metrics/category-calculator.js +137 -0
- package/src/validation/metrics/metrics-helpers.js +155 -0
- package/src/validation/metrics/overview-calculator.js +85 -0
- package/src/validation/metrics/overview-metrics.js +41 -0
- package/src/validation/metrics/quality-calculator.js +166 -0
- package/src/validation/metrics/size-calculator.js +69 -0
- package/src/validation/metrics-calculator.js +27 -551
|
@@ -9,26 +9,12 @@ const fs = require('fs');
|
|
|
9
9
|
const path = require('path');
|
|
10
10
|
const { execSync } = require('child_process');
|
|
11
11
|
|
|
12
|
-
/**
|
|
13
|
-
* Validation techniques
|
|
14
|
-
*/
|
|
15
12
|
const VALIDATION_TECHNIQUES = {
|
|
16
|
-
STATIC_ANALYSIS: 'static_analysis',
|
|
17
|
-
|
|
18
|
-
API_COMPATIBILITY: 'api_compatibility',
|
|
19
|
-
TYPE_CHECKING: 'type_checking',
|
|
20
|
-
RUNTIME_VALIDATION: 'runtime_validation'
|
|
13
|
+
STATIC_ANALYSIS: 'static_analysis', BEHAVIORAL_COMPARISON: 'behavioral_comparison', API_COMPATIBILITY: 'api_compatibility',
|
|
14
|
+
TYPE_CHECKING: 'type_checking', RUNTIME_VALIDATION: 'runtime_validation'
|
|
21
15
|
};
|
|
22
16
|
|
|
23
|
-
|
|
24
|
-
* Validation severity levels
|
|
25
|
-
*/
|
|
26
|
-
const VALIDATION_SEVERITY = {
|
|
27
|
-
INFO: 'info',
|
|
28
|
-
WARNING: 'warning',
|
|
29
|
-
ERROR: 'error',
|
|
30
|
-
CRITICAL: 'critical'
|
|
31
|
-
};
|
|
17
|
+
const VALIDATION_SEVERITY = { INFO: 'info', WARNING: 'warning', ERROR: 'error', CRITICAL: 'critical' };
|
|
32
18
|
|
|
33
19
|
/**
|
|
34
20
|
* Functionality validation result class
|
|
@@ -47,38 +33,24 @@ class FunctionalityValidationResult {
|
|
|
47
33
|
};
|
|
48
34
|
}
|
|
49
35
|
|
|
50
|
-
addTechniqueResult(technique, result) {
|
|
51
|
-
this.techniques.set(technique, result);
|
|
52
|
-
}
|
|
36
|
+
addTechniqueResult(technique, result) { this.techniques.set(technique, result); }
|
|
53
37
|
|
|
54
38
|
addIssue(severity, message, details = null) {
|
|
55
|
-
this.issues.push({
|
|
56
|
-
severity,
|
|
57
|
-
message,
|
|
58
|
-
details,
|
|
59
|
-
timestamp: new Date().toISOString()
|
|
60
|
-
});
|
|
39
|
+
this.issues.push({ severity, message, details, timestamp: new Date().toISOString() });
|
|
61
40
|
}
|
|
62
41
|
|
|
63
|
-
setSuccess(success) {
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
setConfidence(confidence) {
|
|
68
|
-
this.confidence = Math.max(0, Math.min(1, confidence));
|
|
69
|
-
}
|
|
42
|
+
setSuccess(success) { this.success = success; }
|
|
43
|
+
setConfidence(confidence) { this.confidence = Math.max(0, Math.min(1, confidence)); }
|
|
70
44
|
|
|
71
45
|
calculateOverallSuccess() {
|
|
72
46
|
const techniqueResults = Array.from(this.techniques.values());
|
|
73
47
|
const passedTechniques = techniqueResults.filter(r => r.success).length;
|
|
74
48
|
const totalTechniques = techniqueResults.length;
|
|
75
|
-
|
|
76
49
|
if (totalTechniques === 0) {
|
|
77
50
|
this.setSuccess(false);
|
|
78
51
|
this.setConfidence(0);
|
|
79
52
|
return;
|
|
80
53
|
}
|
|
81
|
-
|
|
82
54
|
const successRate = passedTechniques / totalTechniques;
|
|
83
55
|
this.setSuccess(successRate >= 0.8 && this.issues.filter(i => i.severity === VALIDATION_SEVERITY.ERROR || i.severity === VALIDATION_SEVERITY.CRITICAL).length === 0);
|
|
84
56
|
this.setConfidence(successRate);
|
|
@@ -120,26 +92,14 @@ class TechniqueResult {
|
|
|
120
92
|
};
|
|
121
93
|
}
|
|
122
94
|
|
|
123
|
-
setSuccess(success) {
|
|
124
|
-
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
setDuration(duration) {
|
|
128
|
-
this.duration = duration;
|
|
129
|
-
}
|
|
95
|
+
setSuccess(success) { this.success = success; }
|
|
96
|
+
setDuration(duration) { this.duration = duration; }
|
|
130
97
|
|
|
131
98
|
addIssue(severity, message, details = null) {
|
|
132
|
-
this.issues.push({
|
|
133
|
-
severity,
|
|
134
|
-
message,
|
|
135
|
-
details,
|
|
136
|
-
timestamp: new Date().toISOString()
|
|
137
|
-
});
|
|
99
|
+
this.issues.push({ severity, message, details, timestamp: new Date().toISOString() });
|
|
138
100
|
}
|
|
139
101
|
|
|
140
|
-
setDetails(details) {
|
|
141
|
-
this.metadata.details = details;
|
|
142
|
-
}
|
|
102
|
+
setDetails(details) { this.metadata.details = details; }
|
|
143
103
|
}
|
|
144
104
|
|
|
145
105
|
/**
|
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Import Manager
|
|
3
|
+
*
|
|
4
|
+
* Manages import statement updates during refactoring operations.
|
|
5
|
+
* Handles import resolution, organization, and dependency tracking.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const ImportParser = require('./import-parser');
|
|
9
|
+
const { ImportStatement, ImportGroup, ImportDependency } = require('./import-models');
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Import Manager class
|
|
13
|
+
*/
|
|
14
|
+
class ImportManager {
|
|
15
|
+
constructor(options = {}) {
|
|
16
|
+
this.options = {
|
|
17
|
+
autoOrganize: options.autoOrganize !== false,
|
|
18
|
+
removeUnused: options.removeUnused !== false,
|
|
19
|
+
resolveRelative: options.resolveRelative !== false,
|
|
20
|
+
preserveOrder: options.preserveOrder || false,
|
|
21
|
+
...options
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
this.parser = new ImportParser(this.options);
|
|
25
|
+
this.dependencies = new Map();
|
|
26
|
+
this.history = [];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
analyzeFile(filePath) {
|
|
30
|
+
const parseResult = this.parser.parseFile(filePath);
|
|
31
|
+
|
|
32
|
+
// Analyze dependencies
|
|
33
|
+
const dependencies = this.analyzeDependencies(parseResult.imports, filePath);
|
|
34
|
+
|
|
35
|
+
// Detect unused imports
|
|
36
|
+
const unusedImports = this.parser.detectUnusedImports(
|
|
37
|
+
parseResult.imports,
|
|
38
|
+
require('fs').readFileSync(filePath, 'utf8')
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
...parseResult,
|
|
43
|
+
dependencies,
|
|
44
|
+
unusedImports,
|
|
45
|
+
summary: {
|
|
46
|
+
totalImports: parseResult.imports.length,
|
|
47
|
+
unusedCount: unusedImports.length,
|
|
48
|
+
dependencyCount: dependencies.length
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
analyzeFiles(filePaths) {
|
|
54
|
+
const results = [];
|
|
55
|
+
|
|
56
|
+
filePaths.forEach(filePath => {
|
|
57
|
+
const analysis = this.analyzeFile(filePath);
|
|
58
|
+
results.push(analysis);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
// Build dependency graph
|
|
62
|
+
this.buildDependencyGraph(results);
|
|
63
|
+
|
|
64
|
+
return {
|
|
65
|
+
results,
|
|
66
|
+
summary: {
|
|
67
|
+
totalFiles: filePaths.length,
|
|
68
|
+
totalImports: results.reduce((sum, r) => sum + r.totalImports, 0),
|
|
69
|
+
totalUnused: results.reduce((sum, r) => sum + r.unusedImports.length, 0),
|
|
70
|
+
totalDependencies: results.reduce((sum, r) => sum + r.dependencyCount, 0)
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
analyzeDependencies(imports, filePath) {
|
|
76
|
+
const dependencies = [];
|
|
77
|
+
const path = require('path');
|
|
78
|
+
|
|
79
|
+
imports.forEach(importStatement => {
|
|
80
|
+
if (importStatement.isRelative) {
|
|
81
|
+
const resolvedPath = path.resolve(path.dirname(filePath), importStatement.module);
|
|
82
|
+
const dependency = new ImportDependency(
|
|
83
|
+
importStatement.module,
|
|
84
|
+
filePath,
|
|
85
|
+
resolvedPath
|
|
86
|
+
);
|
|
87
|
+
dependencies.push(dependency);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
return dependencies;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
buildDependencyGraph(analysisResults) {
|
|
95
|
+
this.dependencies.clear();
|
|
96
|
+
|
|
97
|
+
analysisResults.forEach(result => {
|
|
98
|
+
result.dependencies.forEach(dep => {
|
|
99
|
+
this.dependencies.set(dep.module, dep);
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
// Detect circular dependencies
|
|
104
|
+
this.detectCircularDependencies();
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
detectCircularDependencies() {
|
|
108
|
+
const visited = new Set();
|
|
109
|
+
const recursionStack = new Set();
|
|
110
|
+
|
|
111
|
+
for (const [module, dependency] of this.dependencies) {
|
|
112
|
+
if (this.hasCircularDependency(module, visited, recursionStack)) {
|
|
113
|
+
dependency.markCircular();
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
hasCircularDependency(module, visited, recursionStack) {
|
|
119
|
+
if (recursionStack.has(module)) {
|
|
120
|
+
return true; // Circular dependency detected
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (visited.has(module)) {
|
|
124
|
+
return false; // Already processed
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
visited.add(module);
|
|
128
|
+
recursionStack.add(module);
|
|
129
|
+
|
|
130
|
+
const dependency = this.dependencies.get(module);
|
|
131
|
+
if (dependency) {
|
|
132
|
+
for (const dep of dependency.dependencies) {
|
|
133
|
+
if (this.hasCircularDependency(dep.module, visited, recursionStack)) {
|
|
134
|
+
return true;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
recursionStack.delete(module);
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
organizeImports(imports, options = {}) {
|
|
144
|
+
const organizeOptions = {
|
|
145
|
+
groupByType: options.groupByType !== false,
|
|
146
|
+
sortAlphabetically: options.sortAlphabetically !== false,
|
|
147
|
+
preserveOrder: options.preserveOrder || this.options.preserveOrder,
|
|
148
|
+
...options
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
let organizedImports = [...imports];
|
|
152
|
+
|
|
153
|
+
if (organizeOptions.groupByType) {
|
|
154
|
+
const groups = this.parser.groupImportsByType(imports);
|
|
155
|
+
organizedImports = this.flattenGroups(groups, organizeOptions.sortAlphabetically);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (organizeOptions.sortAlphabetically && !organizeOptions.groupByType) {
|
|
159
|
+
organizedImports.sort((a, b) => a.module.localeCompare(b.module));
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return organizedImports;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
flattenGroups(groups, sortAlphabetically) {
|
|
166
|
+
const flattened = [];
|
|
167
|
+
|
|
168
|
+
// Define group order
|
|
169
|
+
const groupOrder = ['external', 'scoped', 'node', 'relative'];
|
|
170
|
+
|
|
171
|
+
// Sort groups by defined order
|
|
172
|
+
groups.sort((a, b) => {
|
|
173
|
+
const aIndex = groupOrder.indexOf(a.type);
|
|
174
|
+
const bIndex = groupOrder.indexOf(b.type);
|
|
175
|
+
return aIndex - bIndex;
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
groups.forEach(group => {
|
|
179
|
+
if (sortAlphabetically) {
|
|
180
|
+
group.sortImports();
|
|
181
|
+
}
|
|
182
|
+
flattened.push(...group.imports);
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
return flattened;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
updateImportPaths(imports, pathMappings) {
|
|
189
|
+
return imports.map(importStatement => {
|
|
190
|
+
const updatedImport = { ...importStatement };
|
|
191
|
+
|
|
192
|
+
// Check if this import needs updating
|
|
193
|
+
const mapping = pathMappings.find(mapping =>
|
|
194
|
+
mapping.oldPath === importStatement.module
|
|
195
|
+
);
|
|
196
|
+
|
|
197
|
+
if (mapping) {
|
|
198
|
+
updatedImport.module = mapping.newPath;
|
|
199
|
+
updatedImport.isRelative = this.isRelativeModule(mapping.newPath);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
return updatedImport;
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
isRelativeModule(module) {
|
|
207
|
+
return module.startsWith('./') || module.startsWith('../');
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
removeUnusedImports(imports, codeContent) {
|
|
211
|
+
const unusedImports = this.parser.detectUnusedImports(imports, codeContent);
|
|
212
|
+
|
|
213
|
+
return imports.filter(importStatement =>
|
|
214
|
+
!unusedImports.includes(importStatement)
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
generateImportStatements(imports) {
|
|
219
|
+
return imports.map(importStatement => {
|
|
220
|
+
switch (importStatement.type) {
|
|
221
|
+
case 'es6_import':
|
|
222
|
+
return this.generateES6Import(importStatement);
|
|
223
|
+
case 'commonjs_require':
|
|
224
|
+
return this.generateCommonJSRequire(importStatement);
|
|
225
|
+
default:
|
|
226
|
+
return importStatement.originalStatement;
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
generateES6Import(importStatement) {
|
|
232
|
+
if (importStatement.isDefault) {
|
|
233
|
+
return `import ${importStatement.specifier || 'default'} from '${importStatement.module}';`;
|
|
234
|
+
} else if (importStatement.specifier === '*') {
|
|
235
|
+
return `import * as ${importStatement.specifier} from '${importStatement.module}';`;
|
|
236
|
+
} else {
|
|
237
|
+
return `import { ${importStatement.specifier} } from '${importStatement.module}';`;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
generateCommonJSRequire(importStatement) {
|
|
242
|
+
if (importStatement.isDefault) {
|
|
243
|
+
return `const ${importStatement.specifier} = require('${importStatement.module}');`;
|
|
244
|
+
} else {
|
|
245
|
+
return `const { ${importStatement.specifier} } = require('${importStatement.module}');`;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
updateFileImports(filePath, updates) {
|
|
250
|
+
const fs = require('fs');
|
|
251
|
+
const content = fs.readFileSync(filePath, 'utf8');
|
|
252
|
+
const analysis = this.analyzeFile(filePath);
|
|
253
|
+
|
|
254
|
+
let updatedContent = content;
|
|
255
|
+
|
|
256
|
+
// Apply updates
|
|
257
|
+
updates.forEach(update => {
|
|
258
|
+
switch (update.type) {
|
|
259
|
+
case 'organize':
|
|
260
|
+
if (this.options.autoOrganize) {
|
|
261
|
+
const organizedImports = this.organizeImports(analysis.imports, update.options);
|
|
262
|
+
updatedContent = this.replaceImportsInContent(
|
|
263
|
+
updatedContent,
|
|
264
|
+
analysis.imports,
|
|
265
|
+
organizedImports
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
break;
|
|
269
|
+
|
|
270
|
+
case 'remove_unused':
|
|
271
|
+
if (this.options.removeUnused) {
|
|
272
|
+
const filteredImports = this.removeUnusedImports(analysis.imports, content);
|
|
273
|
+
updatedContent = this.replaceImportsInContent(
|
|
274
|
+
updatedContent,
|
|
275
|
+
analysis.imports,
|
|
276
|
+
filteredImports
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
break;
|
|
280
|
+
|
|
281
|
+
case 'update_paths':
|
|
282
|
+
const updatedImports = this.updateImportPaths(analysis.imports, update.pathMappings);
|
|
283
|
+
updatedContent = this.replaceImportsInContent(
|
|
284
|
+
updatedContent,
|
|
285
|
+
analysis.imports,
|
|
286
|
+
updatedImports
|
|
287
|
+
);
|
|
288
|
+
break;
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
// Write updated content
|
|
293
|
+
fs.writeFileSync(filePath, updatedContent, 'utf8');
|
|
294
|
+
|
|
295
|
+
// Record in history
|
|
296
|
+
this.history.push({
|
|
297
|
+
filePath,
|
|
298
|
+
updates,
|
|
299
|
+
timestamp: new Date().toISOString(),
|
|
300
|
+
previousAnalysis: analysis
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
return {
|
|
304
|
+
success: true,
|
|
305
|
+
filePath,
|
|
306
|
+
updatesApplied: updates.length,
|
|
307
|
+
newAnalysis: this.analyzeFile(filePath)
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
replaceImportsInContent(content, oldImports, newImports) {
|
|
312
|
+
let updatedContent = content;
|
|
313
|
+
|
|
314
|
+
oldImports.forEach((oldImport, index) => {
|
|
315
|
+
const newImport = newImports[index];
|
|
316
|
+
if (newImport && newImport.originalStatement !== oldImport.originalStatement) {
|
|
317
|
+
const newStatement = this.generateImportStatements([newImport])[0];
|
|
318
|
+
updatedContent = updatedContent.replace(
|
|
319
|
+
oldImport.originalStatement,
|
|
320
|
+
newStatement
|
|
321
|
+
);
|
|
322
|
+
}
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
return updatedContent;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
getDependencyGraph() {
|
|
329
|
+
const graph = {};
|
|
330
|
+
|
|
331
|
+
this.dependencies.forEach((dependency, module) => {
|
|
332
|
+
graph[module] = {
|
|
333
|
+
sourceFile: dependency.sourceFile,
|
|
334
|
+
targetFile: dependency.targetFile,
|
|
335
|
+
dependencies: dependency.dependencies.map(dep => dep.module),
|
|
336
|
+
isCircular: dependency.isCircular
|
|
337
|
+
};
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
return graph;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
getImportHistory() {
|
|
344
|
+
return this.history;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
getManagerInfo() {
|
|
348
|
+
return {
|
|
349
|
+
supportedImportTypes: ['es6_import', 'commonjs_require', 'dynamic_import'],
|
|
350
|
+
defaultOptions: this.options,
|
|
351
|
+
features: [
|
|
352
|
+
'import parsing',
|
|
353
|
+
'dependency analysis',
|
|
354
|
+
'import organization',
|
|
355
|
+
'unused import detection',
|
|
356
|
+
'path updates',
|
|
357
|
+
'circular dependency detection',
|
|
358
|
+
'batch processing'
|
|
359
|
+
],
|
|
360
|
+
version: '1.0.0'
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
static createDefault(config = {}) {
|
|
365
|
+
return new ImportManager({
|
|
366
|
+
autoOrganize: true,
|
|
367
|
+
removeUnused: true,
|
|
368
|
+
resolveRelative: false,
|
|
369
|
+
preserveOrder: false,
|
|
370
|
+
...config
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
static createForRefactoring(config = {}) {
|
|
375
|
+
return new ImportManager({
|
|
376
|
+
autoOrganize: true,
|
|
377
|
+
removeUnused: true,
|
|
378
|
+
resolveRelative: true,
|
|
379
|
+
preserveOrder: false,
|
|
380
|
+
...config
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
module.exports = ImportManager;
|