entkapp 5.2.0 → 5.2.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "http://json-schema.org/draft-07/schema#",
3
3
  "name": "entkapp",
4
- "version": "5.2.0",
4
+ "version": "5.2.2",
5
5
  "description": "The Ultimate Enterprise Codebase Janitor. Faster than Knip with OXC integration, type-aware analysis, and automated structural healing. Fully standalone - solving what Knip cannot.",
6
6
  "type": "module",
7
7
  "main": "index.js",
@@ -86,10 +86,16 @@ export class GraphNode {
86
86
  }
87
87
 
88
88
  // Fuzzy / Dynamic usage (Identifiers, Strings, JSX, Decorators)
89
- if (parentNode.instantiatedIdentifiers.has(symbolName)) return true;
90
- if (parentNode.rawStringReferences.has(symbolName)) return true;
91
- if (parentNode.jsxComponents.has(symbolName)) return true;
92
- if (parentNode.decorators.has(symbolName)) return true;
89
+ // UPGRADE: Only check for fuzzy matches if we have a reason to believe it might be used.
90
+ // We skip global names like 'toLowerCase' unless they are explicitly imported.
91
+ const isGlobalName = ['toLowerCase', 'toUpperCase', 'toString', 'valueOf', 'hasOwnProperty', 'constructor'].includes(symbolName);
92
+
93
+ if (!isGlobalName) {
94
+ if (parentNode.instantiatedIdentifiers.has(symbolName)) return true;
95
+ if (parentNode.rawStringReferences.has(symbolName)) return true;
96
+ if (parentNode.jsxComponents.has(symbolName)) return true;
97
+ if (parentNode.decorators.has(symbolName)) return true;
98
+ }
93
99
 
94
100
  for (const accessChain of parentNode.propertyAccessChains) {
95
101
  if (accessChain.endsWith(`.${symbolName}`) || accessChain.includes(`.${symbolName}.`)) return true;
@@ -390,7 +396,15 @@ export class EngineContext {
390
396
  continue;
391
397
  }
392
398
 
393
- if (!usedByReachableFiles.has(dep)) {
399
+ // UPGRADE: Be more aggressive in detecting unused dependencies.
400
+ // Check both externalPackageUsage and rawStringReferences.
401
+ const isUsed = usedByReachableFiles.has(dep) ||
402
+ Array.from(reachableFiles).some(f => {
403
+ const node = this.projectGraph.get(f);
404
+ return node && (node.externalPackageUsage.has(dep) || node.rawStringReferences.has(dep));
405
+ });
406
+
407
+ if (!isUsed) {
394
408
  report.unusedDependencies.push({
395
409
  package: dep,
396
410
  type: deps.dependencies.includes(dep) ? 'dependency' : 'devDependency',
@@ -604,8 +604,14 @@ export class ASTAnalyzer {
604
604
  if (this.context.verbose) console.log(`[AST-DEBUG] Found require() call in ${fileNode.filePath}`);
605
605
  const arg = node.arguments[0];
606
606
  if (arg && ts.isStringLiteral(arg)) {
607
- if (this.context.verbose) console.log(`[AST-DEBUG] Added import: ${arg.text}`);
608
- fileNode.explicitImports.add(arg.text);
607
+ const specifier = arg.text;
608
+ if (this.context.verbose) console.log(`[AST-DEBUG] Added import: ${specifier}`);
609
+ fileNode.explicitImports.add(specifier);
610
+
611
+ // UPGRADE: Also track package usage for unlisted dependency detection
612
+ if (!specifier.startsWith('.') && !specifier.startsWith('/')) {
613
+ fileNode.externalPackageUsage.add(this._extractPackageName(specifier));
614
+ }
609
615
  }
610
616
  }
611
617
  }
package/src/index.js CHANGED
@@ -498,40 +498,63 @@ export class RefactoringEngine {
498
498
  }
499
499
  }
500
500
 
501
+ // UPGRADE: Unlisted Dependency Audit (Unified Root & Workspace)
502
+ const auditManifests = [];
503
+ // 1. Collect Root Manifest
504
+ const rootPkgPath = path.join(this.context.cwd, 'package.json');
505
+ if (existsSync(rootPkgPath)) {
506
+ auditManifests.push({
507
+ rootDirectory: this.context.cwd,
508
+ manifestPath: rootPkgPath
509
+ });
510
+ }
511
+ // 2. Collect Workspace Manifests
501
512
  if (this.workspaceGraph && this.workspaceGraph.packageManifests) {
502
513
  for (const [_, metadata] of this.workspaceGraph.packageManifests.entries()) {
503
- if (this.context.projectGraph) {
504
- for (const [filePath, fileNode] of this.context.projectGraph.entries()) {
505
- const cleanRelative = path.relative(metadata.rootDirectory, filePath).replace(/\\/g, '/');
506
-
507
- if (!cleanRelative.startsWith('..') && !cleanRelative.startsWith('/') && fileNode.explicitImports) {
508
- try {
509
- const localManifest = JSON.parse(readFileSync(metadata.manifestPath, 'utf8'));
510
- const localDeps = new Set([
511
- ...Object.keys(localManifest.dependencies || {}),
512
- ...Object.keys(localManifest.devDependencies || {}),
513
- ...Object.keys(localManifest.peerDependencies || {})
514
- ]);
515
-
516
- fileNode.explicitImports.forEach(specifier => {
517
- if (specifier.startsWith('.') || specifier.startsWith('/')) return;
518
- const basePkg = specifier.startsWith('@') ? specifier.split('/').slice(0, 2).join('/') : specifier.split('/')[0];
519
-
520
- if (!localDeps.has(basePkg)) {
521
- const alreadyFlagged = this.context.unlistedDependencies.some(u => u.package === basePkg && u.file === filePath);
522
- if (!alreadyFlagged) {
523
- this.context.unlistedDependencies.push({
524
- package: basePkg,
525
- file: path.relative(this.context.cwd, filePath),
526
- manifest: path.relative(this.context.cwd, metadata.manifestPath)
527
- });
528
- }
514
+ auditManifests.push(metadata);
515
+ }
516
+ }
517
+
518
+ for (const metadata of auditManifests) {
519
+ if (this.context.projectGraph) {
520
+ for (const [filePath, fileNode] of this.context.projectGraph.entries()) {
521
+ const cleanRelative = path.relative(metadata.rootDirectory, filePath).replace(/\\/g, '/');
522
+
523
+ // Check if file belongs to this manifest's directory scope
524
+ if (!cleanRelative.startsWith('..') && !cleanRelative.startsWith('/') && fileNode.explicitImports) {
525
+ try {
526
+ const localManifest = JSON.parse(readFileSync(metadata.manifestPath, 'utf8'));
527
+ const localDeps = new Set([
528
+ ...Object.keys(localManifest.dependencies || {}),
529
+ ...Object.keys(localManifest.devDependencies || {}),
530
+ ...Object.keys(localManifest.peerDependencies || {}),
531
+ ...Object.keys(localManifest.optionalDependencies || {})
532
+ ]);
533
+
534
+ fileNode.explicitImports.forEach(specifier => {
535
+ if (specifier.startsWith('.') || specifier.startsWith('/')) return;
536
+
537
+ // Extract base package name (handle scoped packages)
538
+ const basePkg = specifier.startsWith('@') ? specifier.split('/').slice(0, 2).join('/') : specifier.split('/')[0];
539
+
540
+ // Ignore Node.js built-ins
541
+ 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'];
542
+ if (nodeBuiltins.includes(basePkg) || nodeBuiltins.includes(basePkg.replace('node:', ''))) return;
543
+
544
+ if (!localDeps.has(basePkg)) {
545
+ const alreadyFlagged = this.context.unlistedDependencies.some(u => u.package === basePkg && u.file === filePath);
546
+ if (!alreadyFlagged) {
547
+ this.context.unlistedDependencies.push({
548
+ package: basePkg,
549
+ file: path.relative(this.context.cwd, filePath),
550
+ manifest: path.relative(this.context.cwd, metadata.manifestPath)
551
+ });
529
552
  }
530
- });
531
- } catch (error) {
532
- if (this.context.options.verbose) {
533
- console.error(ansis.red(` ❌ Manifest Parsing Exception: ${error.message}`));
534
553
  }
554
+ });
555
+ } catch (error) {
556
+ if (this.context.options.verbose) {
557
+ console.error(ansis.red(` ❌ Manifest Parsing Exception: ${error.message}`));
535
558
  }
536
559
  }
537
560
  }
@@ -940,7 +963,9 @@ export class RefactoringEngine {
940
963
  if (isProtected || isExplicitlyDeclared) {
941
964
  finalIsEntry = true;
942
965
  } else if (!hasManifestEntries && hasNoIncoming && hasOutgoing && !isLikelyBarrel) {
943
- finalIsEntry = true;
966
+ // UPGRADE: Orphan files with imports are NOT entry points by default.
967
+ // They must have side effects (detected in AST pass) to be entries.
968
+ finalIsEntry = node.isEntry;
944
969
  }
945
970
 
946
971
  node.isEntry = finalIsEntry;