entkapp 5.4.0 β†’ 5.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/README.md +7 -1
  2. package/bin/cli.js +117 -58
  3. package/bin/cli.mjs +175 -0
  4. package/index.cjs +18 -0
  5. package/index.mjs +51 -0
  6. package/package.json +7 -6
  7. package/src/EngineContext.js +0 -6
  8. package/src/EngineContext.mjs +428 -0
  9. package/src/Initializer.mjs +82 -0
  10. package/src/analyzers/CodeSmellAnalyzer.mjs +106 -0
  11. package/src/analyzers/OxcAnalyzer.mjs +11 -0
  12. package/src/api/HeadlessAPI.js +31 -16
  13. package/src/api/HeadlessAPI.mjs +369 -0
  14. package/src/api/PluginSDK.mjs +135 -0
  15. package/src/ast/ASTAnalyzer.js +23 -97
  16. package/src/ast/ASTAnalyzer.mjs +742 -0
  17. package/src/ast/AdvancedAnalysis.mjs +586 -0
  18. package/src/ast/BarrelParser.mjs +230 -0
  19. package/src/ast/DeadCodeDetector.js +7 -5
  20. package/src/ast/DeadCodeDetector.mjs +92 -0
  21. package/src/ast/MagicDetector.js +43 -23
  22. package/src/ast/MagicDetector.mjs +203 -0
  23. package/src/ast/OxcAnalyzer.js +27 -190
  24. package/src/ast/OxcAnalyzer.mjs +188 -0
  25. package/src/ast/SecretScanner.mjs +374 -0
  26. package/src/healing/GitSandbox.mjs +82 -0
  27. package/src/healing/SelfHealer.mjs +48 -0
  28. package/src/index.js +41 -88
  29. package/src/index.mjs +1176 -0
  30. package/src/performance/GraphCache.js +0 -27
  31. package/src/performance/GraphCache.mjs +108 -0
  32. package/src/performance/SupplyChainGuard.mjs +92 -0
  33. package/src/performance/WorkerPool.js +4 -22
  34. package/src/performance/WorkerPool.mjs +132 -0
  35. package/src/performance/WorkerTaskRunner.js +0 -26
  36. package/src/performance/WorkerTaskRunner.mjs +144 -0
  37. package/src/plugins/BasePlugin.js +27 -16
  38. package/src/plugins/BasePlugin.mjs +240 -0
  39. package/src/plugins/PluginRegistry.js +0 -44
  40. package/src/plugins/PluginRegistry.mjs +203 -0
  41. package/src/plugins/ecosystems/BackendServices.mjs +197 -0
  42. package/src/plugins/ecosystems/GenericPlugins.mjs +142 -0
  43. package/src/plugins/ecosystems/ModernFrameworks.mjs +162 -0
  44. package/src/plugins/ecosystems/MorePlugins.mjs +562 -0
  45. package/src/plugins/ecosystems/NewPlugins.mjs +526 -0
  46. package/src/plugins/ecosystems/NextJsPlugin.mjs +45 -0
  47. package/src/plugins/ecosystems/PluginLoader.mjs +193 -0
  48. package/src/plugins/ecosystems/TypeScriptPlugin.mjs +56 -0
  49. package/src/plugins/ecosystems/UltimateBundle.js +0 -259
  50. package/src/plugins/ecosystems/UltimateBundle.mjs +1182 -0
  51. package/src/refractor/ImpactAnalyzer.mjs +92 -0
  52. package/src/refractor/SourceRewriter.mjs +86 -0
  53. package/src/refractor/TransactionManager.mjs +5 -0
  54. package/src/refractor/TypeIntegrity.mjs +4 -0
  55. package/src/resolution/BuildOrchestrator.mjs +46 -0
  56. package/src/resolution/CircularDetector.mjs +91 -0
  57. package/src/resolution/ConfigGenerator.mjs +83 -0
  58. package/src/resolution/ConfigLoader.js +26 -190
  59. package/src/resolution/ConfigLoader.mjs +94 -0
  60. package/src/resolution/DepencyResolver.mjs +66 -0
  61. package/src/resolution/DependencyFixer.mjs +88 -0
  62. package/src/resolution/DependencyProfiler.mjs +286 -0
  63. package/src/resolution/EntryPointDetector.mjs +134 -0
  64. package/src/resolution/FrameworkConfigParser.mjs +119 -0
  65. package/src/resolution/GraphAnalyzer.js +1 -65
  66. package/src/resolution/GraphAnalyzer.mjs +80 -0
  67. package/src/resolution/MigrationAnalyzer.mjs +60 -0
  68. package/src/resolution/PathMapper.js +0 -81
  69. package/src/resolution/PathMapper.mjs +82 -0
  70. package/src/resolution/TSConfigLoader.js +1 -3
  71. package/src/resolution/TSConfigLoader.mjs +162 -0
  72. package/src/resolution/WorkSpaceGraph.js +89 -260
  73. package/src/resolution/WorkSpaceGraph.mjs +183 -0
  74. package/src/resolution/WorkspaceDiagnostic.mjs +139 -0
  75. package/test.js +76 -0
  76. package/wrangler.toml +6 -0
package/src/index.js CHANGED
@@ -113,81 +113,22 @@ export class RefactoringEngine {
113
113
 
114
114
  // Pass 1: Boot environment contexts and load alias configuration maps
115
115
  await this.oxcAnalyzer.init();
116
- // UPGRADE: Wire pathMapper onto context so ASTAnalyzer alias-filtering works in all code paths
117
- this.context.pathMapper = this.pathMapper;
118
116
  await this.pathMapper.loadMappings(this.context.tsconfigFilename);
119
117
 
120
118
  // Always attempt workspace mesh initialization
121
119
  console.log(ansis.dim('🌐 Probing for monorepo workspace configuration...'));
122
120
  await this.workspaceGraph.initializeWorkspaceMesh();
123
- // UPGRADE: Always expose workspaceGraph on context (not only when workspace is enabled)
124
- this.context.workspaceGraph = this.workspaceGraph;
125
-
126
- // UPGRADE: Scan all discovered framework configs across the workspace EARLY
127
- const discoveredConfigs = await this.workspaceGraph.findFrameworkConfigs();
128
- if (discoveredConfigs.length > 0) {
129
- console.log(ansis.dim(`βš™οΈ Detected ${discoveredConfigs.length} framework configurations...`));
130
- const { FrameworkConfigParser } = await import('./resolution/FrameworkConfigParser.js');
131
- const parser = new FrameworkConfigParser(this.context);
132
-
133
- for (const configPath of discoveredConfigs) {
134
- try {
135
- const content = await fs.readFile(configPath, 'utf8');
136
-
137
- // 1. Core Parsing (Aliases)
138
- const { aliases } = parser.parse(content, configPath);
139
- for (const [key, target] of aliases.entries()) {
140
- this.pathMapper.addAlias(key, target);
141
- }
142
-
143
- // 2. Plugin-based Entry Detection
144
- const detectedEntries = await this.magicDetector.detectEntryPointsFromPlugins(content, configPath);
145
- for (const entry of detectedEntries) {
146
- const absEntry = path.resolve(path.dirname(configPath), entry).replace(/\\/g, '/');
147
- if (!this.context.entryPoints.includes(absEntry)) {
148
- this.context.entryPoints.push(absEntry);
149
- }
150
- }
151
-
152
- // 3. Register config file itself as entry
153
- if (!this.context.entryPoints.includes(configPath)) {
154
- this.context.entryPoints.push(configPath);
155
- }
156
- } catch (e) {}
157
- }
158
- }
159
-
160
121
  if (this.context.isWorkspaceEnabled) {
161
122
  console.log(ansis.dim('🌐 Monorepo workspace detected – mapping package mesh layers...'));
162
-
163
- // NEW: Register all workspace package entry points
164
- for (const [dir, manifest] of this.workspaceGraph.packageManifests.entries()) {
165
- if (manifest.entryPoints && manifest.entryPoints.length > 0) {
166
- for (const ep of manifest.entryPoints) {
167
- if (!this.context.entryPoints.includes(ep)) {
168
- this.context.entryPoints.push(ep);
169
- }
170
- }
171
- }
172
- }
173
-
123
+ // Expose workspaceGraph on context for WorkspaceDiagnostic and other components
124
+ this.context.workspaceGraph = this.workspaceGraph;
174
125
  // Reload PathMapper aliases now that workspace roots are known
175
126
  await this.pathMapper.loadMappings(this.context.tsconfigFilename);
176
127
  if (this.context.verbose) {
177
- const wsSummary = this.workspaceGraph.getSummary();
178
- console.log(`[Workspace] Found ${wsSummary.packages} workspace packages:`);
128
+ console.log(`[Workspace] Found ${this.workspaceGraph.packageManifests.size} workspace packages:`);
179
129
  for (const [dir, manifest] of this.workspaceGraph.packageManifests.entries()) {
180
130
  console.log(ansis.dim(` β€’ ${manifest.name || dir}`));
181
131
  }
182
- if (wsSummary.tsconfigsLoaded > 0) {
183
- console.log(ansis.dim(`[Workspace] Loaded ${wsSummary.tsconfigsLoaded} tsconfig.json file(s) from workspace packages`));
184
- }
185
- if (wsSummary.configFilesLoaded > 0) {
186
- console.log(ansis.dim(`[Workspace] Loaded ${wsSummary.configFilesLoaded} *.config.ts/js file(s) from workspace packages`));
187
- }
188
- if (wsSummary.monorepoConfigs && wsSummary.monorepoConfigs.length > 0) {
189
- console.log(ansis.dim(`[Workspace] Detected global configs: ${wsSummary.monorepoConfigs.join(', ')}`));
190
- }
191
132
  }
192
133
  }
193
134
 
@@ -259,14 +200,6 @@ export class RefactoringEngine {
259
200
  for (const filePath of sourceCodeFilesList) {
260
201
  const absFilePath = slashifyInternal(filePath);
261
202
  const node = this.context.getOrCreateNode(absFilePath);
262
-
263
- // Config data is now handled early in the workspace mesh initialization phase.
264
- // We still mark the rawCode for plugin analysis.
265
- if (absFilePath.includes('.config.')) {
266
- try {
267
- node.rawCode = await fs.readFile(absFilePath, 'utf8');
268
- } catch (e) {}
269
- }
270
203
  const currentHash = await this.cacheManager.computeHash(absFilePath);
271
204
  node.contentHash = currentHash;
272
205
 
@@ -294,7 +227,6 @@ export class RefactoringEngine {
294
227
  } else if (!parallelParseCompleted) {
295
228
  this.context.metrics.cacheMisses++;
296
229
  const fileContent = await fs.readFile(filePath, 'utf8');
297
- node.rawCode = fileContent; // UPGRADE: Store raw code for plugin analysis
298
230
 
299
231
  let success = false;
300
232
  if (this.oxcAnalyzer.isAvailable) {
@@ -316,10 +248,6 @@ export class RefactoringEngine {
316
248
  if (!success || (oxcFailedToFindDependencies && (hasImportExportKeywords || hasCommonJSKeywords))) {
317
249
  await this.analyzer.parseFile(filePath, fileContent, node);
318
250
  }
319
-
320
- // UPGRADE 5.3.0: Run plugin-specific content analysis
321
- await this.magicDetector.runPluginContentAnalysis(node, absFilePath);
322
-
323
251
  // Secret scan on freshly parsed content
324
252
  const secretFindings = this.secretScanner.scanFileContent(filePath, fileContent);
325
253
  if (secretFindings.length > 0) {
@@ -419,7 +347,18 @@ export class RefactoringEngine {
419
347
  }
420
348
  }
421
349
  if (entryCount === 0) {
422
- console.log(ansis.bold.red(' 🚨 ALARM: Keine einzige Datei wurde als Entry Point markiert!'));
350
+ console.log(ansis.bold.yellow(' 🚨 ALARM: Keine einzige Datei wurde als Entry Point markiert! Greife auf Fallbacks zurück...'));
351
+ const fallbackFiles = ['index.js', 'index.mjs', 'src/index.js', 'src/index.mjs', 'main.js', 'src/main.js'];
352
+ for (const fallback of fallbackFiles) {
353
+ const absFallback = path.resolve(this.context.cwd, fallback).replace(/\\/g, '/');
354
+ if (this.context.projectGraph.has(absFallback)) {
355
+ const node = this.context.projectGraph.get(absFallback);
356
+ node.isEntry = true;
357
+ console.log(ansis.green(` β€’ πŸ’Ž FALLBACK ENTRY: ${fallback}`));
358
+ entryCount++;
359
+ break;
360
+ }
361
+ }
423
362
  }
424
363
 
425
364
  // Mark workspace packages as used to block false alarms in the manifest auditor
@@ -634,17 +573,6 @@ export class RefactoringEngine {
634
573
  const nodeBuiltins = ['assert', 'async_hooks', 'buffer', 'child_process', 'cluster', 'console', 'constants', 'crypto', 'dgram', 'dns', 'domain', 'events', 'fs', 'http', 'http2', 'https', 'inspector', 'module', 'net', 'os', 'path', 'perf_hooks', 'process', 'punycode', 'querystring', 'readline', 'repl', 'stream', 'string_decoder', 'timers', 'tls', 'trace_events', 'tty', 'url', 'util', 'v8', 'vm', 'worker_threads', 'zlib'];
635
574
  if (nodeBuiltins.includes(basePkg) || nodeBuiltins.includes(basePkg.replace('node:', ''))) return;
636
575
 
637
- // UPGRADE: Skip tsconfig path aliases (e.g. @shared/*, @idk/*, ~/*)
638
- // Check full specifier AND basePkg against alias patterns
639
- if (this.pathMapper && typeof this.pathMapper.isTsconfigAlias === 'function') {
640
- if (this.pathMapper.isTsconfigAlias(specifier) || this.pathMapper.isTsconfigAlias(basePkg)) return;
641
- }
642
-
643
- // UPGRADE: Skip workspace packages detected via pnpm-workspace.yaml / package.json workspaces
644
- if (this.workspaceGraph && typeof this.workspaceGraph.isLocalWorkspaceSpecifier === 'function') {
645
- if (this.workspaceGraph.isLocalWorkspaceSpecifier(specifier) || this.workspaceGraph.isLocalWorkspaceSpecifier(basePkg)) return;
646
- }
647
-
648
576
  if (!localDeps.has(basePkg)) {
649
577
  const alreadyFlagged = this.context.unlistedDependencies.some(u => u.package === basePkg && u.file === filePath);
650
578
  if (!alreadyFlagged) {
@@ -657,7 +585,7 @@ export class RefactoringEngine {
657
585
  }
658
586
  });
659
587
  } catch (error) {
660
- if (this.context.options.verbose && error.code !== 'ENOENT') {
588
+ if (this.context.options.verbose) {
661
589
  console.error(ansis.red(` ❌ Manifest Parsing Exception: ${error.message}`));
662
590
  }
663
591
  }
@@ -826,6 +754,31 @@ export class RefactoringEngine {
826
754
  await this.typeIntegrity.synchronizeDeclarationFile(absPath, unusedExport.symbol);
827
755
  }
828
756
  }
757
+
758
+ // --- FIXED: Added dependency removal logic ---
759
+ for (const dep of (analysisSummary.unusedDependencies || [])) {
760
+ try {
761
+ const absPath = path.resolve(this.context.cwd, dep.manifest);
762
+ const pkgContent = await fs.readFile(absPath, 'utf8');
763
+ const pkg = JSON.parse(pkgContent);
764
+
765
+ let removed = false;
766
+ if (pkg.dependencies && pkg.dependencies[dep.package]) {
767
+ delete pkg.dependencies[dep.package];
768
+ removed = true;
769
+ } else if (pkg.devDependencies && pkg.devDependencies[dep.package]) {
770
+ delete pkg.devDependencies[dep.package];
771
+ removed = true;
772
+ }
773
+
774
+ if (removed) {
775
+ console.log(ansis.red(`πŸ“¦ Removing unused dependency [${dep.package}] from ${dep.manifest}`));
776
+ await this.txManager.stageWrite(absPath, JSON.stringify(pkg, null, 2) + '\n');
777
+ }
778
+ } catch (e) {
779
+ console.error(ansis.red(`❌ Failed to remove dependency ${dep.package}: ${e.message}`));
780
+ }
781
+ }
829
782
  });
830
783
  } else {
831
784
  console.log(ansis.bold.yellow('\n⚠️ Optimization plan aborted by user. No changes applied.'));