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
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Import Statement Models
|
|
3
|
+
*
|
|
4
|
+
* Data models for import statements and management.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Import types
|
|
9
|
+
*/
|
|
10
|
+
const IMPORT_TYPES = {
|
|
11
|
+
ES6_IMPORT: 'es6_import',
|
|
12
|
+
COMMONJS_REQUIRE: 'commonjs_require',
|
|
13
|
+
DYNAMIC_IMPORT: 'dynamic_import',
|
|
14
|
+
TYPESCRIPT_IMPORT: 'typescript_import'
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Import statement class
|
|
19
|
+
*/
|
|
20
|
+
class ImportStatement {
|
|
21
|
+
constructor(type, module, specifier = null, isDefault = false) {
|
|
22
|
+
this.type = type;
|
|
23
|
+
this.module = module;
|
|
24
|
+
this.specifier = specifier;
|
|
25
|
+
this.isDefault = isDefault;
|
|
26
|
+
this.isTypeOnly = false;
|
|
27
|
+
this.isRelative = this.isRelativeModule(module);
|
|
28
|
+
this.originalStatement = '';
|
|
29
|
+
this.lineNumber = 0;
|
|
30
|
+
this.metadata = {
|
|
31
|
+
createdAt: new Date().toISOString(),
|
|
32
|
+
used: false,
|
|
33
|
+
unused: false
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
isRelativeModule(module) {
|
|
38
|
+
return module.startsWith('./') || module.startsWith('../');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
setOriginalStatement(statement) {
|
|
42
|
+
this.originalStatement = statement;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
setLineNumber(lineNumber) {
|
|
46
|
+
this.lineNumber = lineNumber;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
markUsed() {
|
|
50
|
+
this.metadata.used = true;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
markUnused() {
|
|
54
|
+
this.metadata.unused = true;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
getSummary() {
|
|
58
|
+
return {
|
|
59
|
+
type: this.type,
|
|
60
|
+
module: this.module,
|
|
61
|
+
specifier: this.specifier,
|
|
62
|
+
isDefault: this.isDefault,
|
|
63
|
+
isRelative: this.isRelative,
|
|
64
|
+
lineNumber: this.lineNumber
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
toJSON() {
|
|
69
|
+
return {
|
|
70
|
+
type: this.type,
|
|
71
|
+
module: this.module,
|
|
72
|
+
specifier: this.specifier,
|
|
73
|
+
isDefault: this.isDefault,
|
|
74
|
+
isTypeOnly: this.isTypeOnly,
|
|
75
|
+
isRelative: this.isRelative,
|
|
76
|
+
originalStatement: this.originalStatement,
|
|
77
|
+
lineNumber: this.lineNumber,
|
|
78
|
+
metadata: this.metadata
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Import dependency class
|
|
85
|
+
*/
|
|
86
|
+
class ImportDependency {
|
|
87
|
+
constructor(module, sourceFile, targetFile) {
|
|
88
|
+
this.module = module;
|
|
89
|
+
this.sourceFile = sourceFile;
|
|
90
|
+
this.targetFile = targetFile;
|
|
91
|
+
this.dependencies = [];
|
|
92
|
+
this.dependents = [];
|
|
93
|
+
this.isCircular = false;
|
|
94
|
+
this.metadata = {
|
|
95
|
+
createdAt: new Date().toISOString(),
|
|
96
|
+
resolved: false,
|
|
97
|
+
error: null
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
addDependency(dependency) {
|
|
102
|
+
if (!this.dependencies.find(dep => dep.module === dependency.module)) {
|
|
103
|
+
this.dependencies.push(dependency);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
addDependent(dependent) {
|
|
108
|
+
if (!this.dependents.find(dep => dep.module === dependent.module)) {
|
|
109
|
+
this.dependents.push(dependent);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
markCircular() {
|
|
114
|
+
this.isCircular = true;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
markResolved() {
|
|
118
|
+
this.metadata.resolved = true;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
setError(error) {
|
|
122
|
+
this.metadata.error = error;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
getSummary() {
|
|
126
|
+
return {
|
|
127
|
+
module: this.module,
|
|
128
|
+
sourceFile: this.sourceFile,
|
|
129
|
+
targetFile: this.targetFile,
|
|
130
|
+
dependenciesCount: this.dependencies.length,
|
|
131
|
+
dependentsCount: this.dependents.length,
|
|
132
|
+
isCircular: this.isCircular,
|
|
133
|
+
isResolved: this.metadata.resolved
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Import group class
|
|
140
|
+
*/
|
|
141
|
+
class ImportGroup {
|
|
142
|
+
constructor(type) {
|
|
143
|
+
this.type = type;
|
|
144
|
+
this.imports = [];
|
|
145
|
+
this.order = 0;
|
|
146
|
+
this.metadata = {
|
|
147
|
+
createdAt: new Date().toISOString(),
|
|
148
|
+
sorted: false
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
addImport(importStatement) {
|
|
153
|
+
this.imports.push(importStatement);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
removeImport(importStatement) {
|
|
157
|
+
this.imports = this.imports.filter(imp => imp !== importStatement);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
sortImports() {
|
|
161
|
+
this.imports.sort((a, b) => {
|
|
162
|
+
// Sort by module name, then by specifier
|
|
163
|
+
if (a.module !== b.module) {
|
|
164
|
+
return a.module.localeCompare(b.module);
|
|
165
|
+
}
|
|
166
|
+
return (a.specifier || '').localeCompare(b.specifier || '');
|
|
167
|
+
});
|
|
168
|
+
this.metadata.sorted = true;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
getImportCount() {
|
|
172
|
+
return this.imports.length;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
getSummary() {
|
|
176
|
+
return {
|
|
177
|
+
type: this.type,
|
|
178
|
+
importCount: this.imports.length,
|
|
179
|
+
isSorted: this.metadata.sorted
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
module.exports = {
|
|
185
|
+
IMPORT_TYPES,
|
|
186
|
+
ImportStatement,
|
|
187
|
+
ImportDependency,
|
|
188
|
+
ImportGroup
|
|
189
|
+
};
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Import Parser
|
|
3
|
+
*
|
|
4
|
+
* Parses and analyzes import statements in code files.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const { IMPORT_TYPES, ImportStatement, ImportGroup } = require('./import-models');
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Import Parser class
|
|
11
|
+
*/
|
|
12
|
+
class ImportParser {
|
|
13
|
+
constructor(options = {}) {
|
|
14
|
+
this.options = {
|
|
15
|
+
includeComments: options.includeComments !== false,
|
|
16
|
+
trackUnused: options.trackUnused !== false,
|
|
17
|
+
resolveRelative: options.resolveRelative !== false,
|
|
18
|
+
...options
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
parseFile(filePath) {
|
|
23
|
+
const content = require('fs').readFileSync(filePath, 'utf8');
|
|
24
|
+
return this.parseContent(content, filePath);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
parseContent(content, filePath = null) {
|
|
28
|
+
const lines = content.split('\n');
|
|
29
|
+
const imports = [];
|
|
30
|
+
|
|
31
|
+
lines.forEach((line, index) => {
|
|
32
|
+
const importStatements = this.parseLine(line, index + 1);
|
|
33
|
+
imports.push(...importStatements);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
imports,
|
|
38
|
+
filePath,
|
|
39
|
+
totalImports: imports.length,
|
|
40
|
+
metadata: {
|
|
41
|
+
parsedAt: new Date().toISOString(),
|
|
42
|
+
options: this.options
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
parseLine(line, lineNumber) {
|
|
48
|
+
const imports = [];
|
|
49
|
+
const trimmedLine = line.trim();
|
|
50
|
+
|
|
51
|
+
// Skip empty lines and comments
|
|
52
|
+
if (!trimmedLine || this.isCommentLine(trimmedLine)) {
|
|
53
|
+
return imports;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Parse different import types
|
|
57
|
+
if (trimmedLine.startsWith('import ')) {
|
|
58
|
+
const es6Import = this.parseES6Import(trimmedLine, lineNumber);
|
|
59
|
+
if (es6Import) imports.push(es6Import);
|
|
60
|
+
} else if (trimmedLine.includes('require(')) {
|
|
61
|
+
const commonJSImport = this.parseCommonJSImport(trimmedLine, lineNumber);
|
|
62
|
+
if (commonJSImport) imports.push(commonJSImport);
|
|
63
|
+
} else if (trimmedLine.includes('import(')) {
|
|
64
|
+
const dynamicImport = this.parseDynamicImport(trimmedLine, lineNumber);
|
|
65
|
+
if (dynamicImport) imports.push(dynamicImport);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return imports;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
parseES6Import(line, lineNumber) {
|
|
72
|
+
// Match: import ... from 'module'
|
|
73
|
+
const importRegex = /^import\s+(.+?)\s+from\s+['"]([^'"]+)['"]\s*;?$/;
|
|
74
|
+
const match = line.match(importRegex);
|
|
75
|
+
|
|
76
|
+
if (!match) return null;
|
|
77
|
+
|
|
78
|
+
const importPart = match[1].trim();
|
|
79
|
+
const module = match[2];
|
|
80
|
+
|
|
81
|
+
// Parse import specifiers
|
|
82
|
+
const { specifier, isDefault, isTypeOnly } = this.parseImportSpecifiers(importPart);
|
|
83
|
+
|
|
84
|
+
const importStatement = new ImportStatement(
|
|
85
|
+
IMPORT_TYPES.ES6_IMPORT,
|
|
86
|
+
module,
|
|
87
|
+
specifier,
|
|
88
|
+
isDefault
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
importStatement.setOriginalStatement(line);
|
|
92
|
+
importStatement.setLineNumber(lineNumber);
|
|
93
|
+
importStatement.isTypeOnly = isTypeOnly;
|
|
94
|
+
|
|
95
|
+
return importStatement;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
parseCommonJSImport(line, lineNumber) {
|
|
99
|
+
// Match: const ... = require('module')
|
|
100
|
+
const requireRegex = /(?:const|let|var)\s+(.+?)\s*=\s*require\(['"]([^'"]+)['"]\)\s*;?$/;
|
|
101
|
+
const match = line.match(requireRegex);
|
|
102
|
+
|
|
103
|
+
if (!match) return null;
|
|
104
|
+
|
|
105
|
+
const variableName = match[1].trim();
|
|
106
|
+
const module = match[2];
|
|
107
|
+
|
|
108
|
+
// Check if it's a default import
|
|
109
|
+
const isDefault = !variableName.includes('{') && !variableName.includes('[');
|
|
110
|
+
|
|
111
|
+
const importStatement = new ImportStatement(
|
|
112
|
+
IMPORT_TYPES.COMMONJS_REQUIRE,
|
|
113
|
+
module,
|
|
114
|
+
isDefault ? 'default' : variableName,
|
|
115
|
+
isDefault
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
importStatement.setOriginalStatement(line);
|
|
119
|
+
importStatement.setLineNumber(lineNumber);
|
|
120
|
+
|
|
121
|
+
return importStatement;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
parseDynamicImport(line, lineNumber) {
|
|
125
|
+
// Match: import('module')
|
|
126
|
+
const dynamicRegex = /import\(['"]([^'"]+)['"]\)/;
|
|
127
|
+
const match = line.match(dynamicRegex);
|
|
128
|
+
|
|
129
|
+
if (!match) return null;
|
|
130
|
+
|
|
131
|
+
const module = match[1];
|
|
132
|
+
|
|
133
|
+
const importStatement = new ImportStatement(
|
|
134
|
+
IMPORT_TYPES.DYNAMIC_IMPORT,
|
|
135
|
+
module,
|
|
136
|
+
null,
|
|
137
|
+
false
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
importStatement.setOriginalStatement(line);
|
|
141
|
+
importStatement.setLineNumber(lineNumber);
|
|
142
|
+
|
|
143
|
+
return importStatement;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
parseImportSpecifiers(importPart) {
|
|
147
|
+
// Default import: import name from 'module'
|
|
148
|
+
if (!importPart.includes('{') && !importPart.includes('*')) {
|
|
149
|
+
return {
|
|
150
|
+
specifier: 'default',
|
|
151
|
+
isDefault: true,
|
|
152
|
+
isTypeOnly: false
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// Namespace import: import * as name from 'module'
|
|
157
|
+
if (importPart.includes('*')) {
|
|
158
|
+
const namespaceRegex = /\*\s+as\s+(\w+)/;
|
|
159
|
+
const match = importPart.match(namespaceRegex);
|
|
160
|
+
return {
|
|
161
|
+
specifier: match ? match[1] : '*',
|
|
162
|
+
isDefault: false,
|
|
163
|
+
isTypeOnly: false
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// Named imports: import { a, b, c } from 'module'
|
|
168
|
+
if (importPart.includes('{')) {
|
|
169
|
+
const namedRegex = /{([^}]+)}/;
|
|
170
|
+
const match = importPart.match(namedRegex);
|
|
171
|
+
const specifier = match ? match[1].trim() : '';
|
|
172
|
+
|
|
173
|
+
return {
|
|
174
|
+
specifier,
|
|
175
|
+
isDefault: false,
|
|
176
|
+
isTypeOnly: importPart.includes('type')
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return {
|
|
181
|
+
specifier: importPart,
|
|
182
|
+
isDefault: false,
|
|
183
|
+
isTypeOnly: false
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
isCommentLine(line) {
|
|
188
|
+
return line.startsWith('//') || line.startsWith('/*') || line.startsWith('*');
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
groupImportsByType(imports) {
|
|
192
|
+
const groups = new Map();
|
|
193
|
+
|
|
194
|
+
imports.forEach(importStatement => {
|
|
195
|
+
const type = this.getImportGroupType(importStatement);
|
|
196
|
+
|
|
197
|
+
if (!groups.has(type)) {
|
|
198
|
+
groups.set(type, new ImportGroup(type));
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
groups.get(type).addImport(importStatement);
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
// Sort each group
|
|
205
|
+
groups.forEach(group => group.sortImports());
|
|
206
|
+
|
|
207
|
+
return Array.from(groups.values());
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
getImportGroupType(importStatement) {
|
|
211
|
+
if (importStatement.isRelative) {
|
|
212
|
+
return 'relative';
|
|
213
|
+
} else if (importStatement.module.startsWith('node:')) {
|
|
214
|
+
return 'node';
|
|
215
|
+
} else if (importStatement.module.startsWith('@')) {
|
|
216
|
+
return 'scoped';
|
|
217
|
+
} else {
|
|
218
|
+
return 'external';
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
detectUnusedImports(imports, codeContent) {
|
|
223
|
+
if (!this.options.trackUnused) {
|
|
224
|
+
return [];
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
const unusedImports = [];
|
|
228
|
+
|
|
229
|
+
imports.forEach(importStatement => {
|
|
230
|
+
if (!this.isImportUsed(importStatement, codeContent)) {
|
|
231
|
+
importStatement.markUnused();
|
|
232
|
+
unusedImports.push(importStatement);
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
return unusedImports;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
isImportUsed(importStatement, codeContent) {
|
|
240
|
+
const name = importStatement.specifier || importStatement.module;
|
|
241
|
+
|
|
242
|
+
// Simple usage detection (in real scenario, use AST parsing)
|
|
243
|
+
const usageRegex = new RegExp(`\\b${name}\\b`, 'g');
|
|
244
|
+
const matches = codeContent.match(usageRegex);
|
|
245
|
+
|
|
246
|
+
// Count matches excluding the import statement itself
|
|
247
|
+
const nonImportMatches = matches ? matches.filter(match =>
|
|
248
|
+
!match.includes('import') && !match.includes('require')
|
|
249
|
+
) : [];
|
|
250
|
+
|
|
251
|
+
return nonImportMatches.length > 0;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
resolveRelativeImports(imports, filePath) {
|
|
255
|
+
if (!this.options.resolveRelative) {
|
|
256
|
+
return imports;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
const path = require('path');
|
|
260
|
+
const fileDir = path.dirname(filePath);
|
|
261
|
+
|
|
262
|
+
return imports.map(importStatement => {
|
|
263
|
+
if (importStatement.isRelative) {
|
|
264
|
+
const resolvedPath = path.resolve(fileDir, importStatement.module);
|
|
265
|
+
importStatement.module = resolvedPath;
|
|
266
|
+
}
|
|
267
|
+
return importStatement;
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
getParserInfo() {
|
|
272
|
+
return {
|
|
273
|
+
supportedTypes: Object.values(IMPORT_TYPES),
|
|
274
|
+
defaultOptions: this.options,
|
|
275
|
+
features: [
|
|
276
|
+
'ES6 import parsing',
|
|
277
|
+
'CommonJS require parsing',
|
|
278
|
+
'dynamic import parsing',
|
|
279
|
+
'import grouping',
|
|
280
|
+
'unused import detection',
|
|
281
|
+
'relative path resolution'
|
|
282
|
+
],
|
|
283
|
+
version: '1.0.0'
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
static createDefault(config = {}) {
|
|
288
|
+
return new ImportParser({
|
|
289
|
+
includeComments: true,
|
|
290
|
+
trackUnused: true,
|
|
291
|
+
resolveRelative: false,
|
|
292
|
+
...config
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
static createForRefactoring(config = {}) {
|
|
297
|
+
return new ImportParser({
|
|
298
|
+
includeComments: false,
|
|
299
|
+
trackUnused: true,
|
|
300
|
+
resolveRelative: true,
|
|
301
|
+
...config
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
module.exports = ImportParser;
|