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 +1 -1
- package/src/EngineContext.js +19 -5
- package/src/ast/ASTAnalyzer.js +8 -2
- package/src/index.js +56 -31
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.
|
|
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",
|
package/src/EngineContext.js
CHANGED
|
@@ -86,10 +86,16 @@ export class GraphNode {
|
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
// Fuzzy / Dynamic usage (Identifiers, Strings, JSX, Decorators)
|
|
89
|
-
if
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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
|
-
|
|
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',
|
package/src/ast/ASTAnalyzer.js
CHANGED
|
@@ -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
|
-
|
|
608
|
-
|
|
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
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
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
|
-
|
|
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;
|