optiprune 2.1.4 → 2.1.7

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 (102) hide show
  1. package/README.md +52 -22
  2. package/bin/runner.js +26 -0
  3. package/package.json +10 -37
  4. package/dist/ast-utils.d.ts +0 -149
  5. package/dist/ast-utils.js +0 -36
  6. package/dist/ast-utils.js.map +0 -1
  7. package/dist/cache.d.ts +0 -14
  8. package/dist/cache.js +0 -36
  9. package/dist/cache.js.map +0 -1
  10. package/dist/cli.d.ts +0 -2
  11. package/dist/cli.js +0 -68
  12. package/dist/cli.js.map +0 -1
  13. package/dist/config-loader.d.ts +0 -4
  14. package/dist/config-loader.js +0 -84
  15. package/dist/config-loader.js.map +0 -1
  16. package/dist/coverage-tracker.d.ts +0 -39
  17. package/dist/coverage-tracker.js +0 -61
  18. package/dist/coverage-tracker.js.map +0 -1
  19. package/dist/engine.d.ts +0 -17
  20. package/dist/engine.js +0 -215
  21. package/dist/engine.js.map +0 -1
  22. package/dist/framework-plugins.d.ts +0 -16
  23. package/dist/framework-plugins.js +0 -127
  24. package/dist/framework-plugins.js.map +0 -1
  25. package/dist/fs-utils.d.ts +0 -32
  26. package/dist/fs-utils.js +0 -415
  27. package/dist/fs-utils.js.map +0 -1
  28. package/dist/graph.d.ts +0 -42
  29. package/dist/graph.js +0 -583
  30. package/dist/graph.js.map +0 -1
  31. package/dist/index.d.ts +0 -3
  32. package/dist/index.js +0 -451
  33. package/dist/index.js.map +0 -1
  34. package/dist/instrument.d.ts +0 -5
  35. package/dist/instrument.js +0 -108
  36. package/dist/instrument.js.map +0 -1
  37. package/dist/layer2.d.ts +0 -6
  38. package/dist/layer2.js +0 -224
  39. package/dist/layer2.js.map +0 -1
  40. package/dist/layer3.d.ts +0 -7
  41. package/dist/layer3.js +0 -346
  42. package/dist/layer3.js.map +0 -1
  43. package/dist/layer4.d.ts +0 -8
  44. package/dist/layer4.js +0 -627
  45. package/dist/layer4.js.map +0 -1
  46. package/dist/layer5.d.ts +0 -6
  47. package/dist/layer5.js +0 -141
  48. package/dist/layer5.js.map +0 -1
  49. package/dist/layer6.d.ts +0 -26
  50. package/dist/layer6.js +0 -268
  51. package/dist/layer6.js.map +0 -1
  52. package/dist/layer7.d.ts +0 -28
  53. package/dist/layer7.js +0 -267
  54. package/dist/layer7.js.map +0 -1
  55. package/dist/parser.d.ts +0 -20
  56. package/dist/parser.js +0 -832
  57. package/dist/parser.js.map +0 -1
  58. package/dist/plugins/angular-plugin.d.ts +0 -7
  59. package/dist/plugins/angular-plugin.js +0 -60
  60. package/dist/plugins/angular-plugin.js.map +0 -1
  61. package/dist/plugins/astro-plugin.d.ts +0 -7
  62. package/dist/plugins/astro-plugin.js +0 -88
  63. package/dist/plugins/astro-plugin.js.map +0 -1
  64. package/dist/plugins/babel-plugin.d.ts +0 -8
  65. package/dist/plugins/babel-plugin.js +0 -132
  66. package/dist/plugins/babel-plugin.js.map +0 -1
  67. package/dist/plugins/esbuild-plugin.d.ts +0 -8
  68. package/dist/plugins/esbuild-plugin.js +0 -121
  69. package/dist/plugins/esbuild-plugin.js.map +0 -1
  70. package/dist/plugins/nestjs-plugin.d.ts +0 -7
  71. package/dist/plugins/nestjs-plugin.js +0 -69
  72. package/dist/plugins/nestjs-plugin.js.map +0 -1
  73. package/dist/plugins/nextjs-plugin.d.ts +0 -7
  74. package/dist/plugins/nextjs-plugin.js +0 -66
  75. package/dist/plugins/nextjs-plugin.js.map +0 -1
  76. package/dist/plugins/nuxtjs-plugin.d.ts +0 -7
  77. package/dist/plugins/nuxtjs-plugin.js +0 -80
  78. package/dist/plugins/nuxtjs-plugin.js.map +0 -1
  79. package/dist/plugins/svelte-plugin.d.ts +0 -7
  80. package/dist/plugins/svelte-plugin.js +0 -38
  81. package/dist/plugins/svelte-plugin.js.map +0 -1
  82. package/dist/plugins/vuejs-plugin.d.ts +0 -7
  83. package/dist/plugins/vuejs-plugin.js +0 -63
  84. package/dist/plugins/vuejs-plugin.js.map +0 -1
  85. package/dist/reporters.d.ts +0 -3
  86. package/dist/reporters.js +0 -75
  87. package/dist/reporters.js.map +0 -1
  88. package/dist/semantic-graph.d.ts +0 -44
  89. package/dist/semantic-graph.js +0 -88
  90. package/dist/semantic-graph.js.map +0 -1
  91. package/dist/symbolic-engine.d.ts +0 -19
  92. package/dist/symbolic-engine.js +0 -51
  93. package/dist/symbolic-engine.js.map +0 -1
  94. package/dist/topology-manager.d.ts +0 -23
  95. package/dist/topology-manager.js +0 -144
  96. package/dist/topology-manager.js.map +0 -1
  97. package/dist/types.d.ts +0 -265
  98. package/dist/types.js +0 -11
  99. package/dist/types.js.map +0 -1
  100. package/dist/workspace.d.ts +0 -6
  101. package/dist/workspace.js +0 -105
  102. package/dist/workspace.js.map +0 -1
package/README.md CHANGED
@@ -2,39 +2,66 @@
2
2
  ![NPM Version](https://img.shields.io/npm/v/optiprune)
3
3
  ![GitHub License](https://img.shields.io/github/license/DreamLongYT/optiprune)
4
4
 
5
+ # 🚀 OptiPrune
6
+ ---
7
+
8
+ ## 💎 The Vision
9
+ Most dead-code analyzers just guess. They look at import graphs and hope they don't miss anything critical. This leads to **false positives**, broken builds, and developer frustration.
5
10
 
6
- # Optiprune
11
+ **OptiPrune is different.** We use formal logic, isolated execution, and a high-performance engine to not just find dead code, but to mathematically **prove** it.
7
12
 
8
- **Resilient static dead-code analyzer for TypeScript and JavaScript workspaces.**
13
+ > **"Stop Guessing, Start Proving."**
9
14
 
10
15
  ---
11
16
 
12
- **Optiprune** is a multi-layered static analyzer designed to prune unreachable files, dead exports, untangled monorepo imports, and unused dependencies with surgical precision. Built for cross-platform reliability (Windows/Linux) and fast CI pipelines.
17
+ ## The 3 Pillars of Superiority
13
18
 
14
- ## Key Features
19
+ ### 1. Raw Power: The Yuku Engine (Zig)
20
+ While other tools are throttled by the N-API bottleneck, OptiPrune utilizes the **Yuku Engine** written in **Zig**. It minimizes the overhead between native performance and the JavaScript runtime.
21
+ * **The Result:** Up to 3x faster parsing than traditional tools, even in massive monorepos.
15
22
 
16
- * **Staged 7-Layer Engine:** From AST entry point resolution to SMT constraint solving, isolated V8 execution, implicit binding analysis, and unused package sweeping.
17
- * **Schema & Contract Preserver (Layer 5):** Introspects Zod schemas (`z.*`), Class declarations (`*Schema`), Prisma models, decorators, and OpenAPI resolvers to prevent false positives on public interfaces.
18
- * **Cross-Platform Path Normalization:** Flawless resolution across Windows drive letters, backslashes, and POSIX path specs.
19
- * **Circular Dependency Resilient:** Iterative worklist analysis using Strongly Connected Components (SCCs) to resolve cyclical import paths accurately.
20
- * **Monorepo & Package Sweeper (Layer 6):** Identifies unused root and package-level `node_modules` dependencies alongside dead code.
21
- * **Non-Standard Entry & Implicit Binding (Layer 7):** Maps DI topologies (NestJS/Inversify), event-driven contracts, and resolves dynamic import patterns.
23
+ ### 2. Deep Intelligence: SMT & Z3 Solver
24
+ OptiPrune is the first analyzer to use a real **SMT Solver (Z3)**. We don't just analyze if a function is exported; we analyze if the code *inside* the function is logically reachable.
25
+ * **The Result:** Detects dead logic paths (e.g., impossible `if` conditions) that are completely invisible to Knip.
22
26
 
23
- ---
27
+ ### 3. Absolute Precision: WASM Sandbox Execution
28
+ Dynamic imports are the final boss of static analysis. OptiPrune solves this through a **WASM-based QuickJS sandbox**. We securely execute critical code snippets to resolve paths at runtime.
29
+ * **The Result:** Zero false alarms for dynamic paths. If OptiPrune says it's dead, it's dead.
24
30
 
25
- ## Architecture Overview
31
+ ---
26
32
 
27
- Optiprune runs code through a 7-stage analysis pipeline:
33
+ ## 🥊 OptiPrune vs. Knip: The Head-to-Head
28
34
 
29
- | Layer | Stage | Focus |
35
+ | Feature | Knip | OptiPrune |
30
36
  | :--- | :--- | :--- |
31
- | **Layer 1** | Entry Point Graph | Static import/export dependency graph & entry point discovery |
32
- | **Layer 2** | Monorepo & Workspaces | Cross-package references and boundary resolution |
33
- | **Layer 3** | Dynamic Tracing & SMT | Path unreachability via Z3 constraint solving |
34
- | **Layer 4** | Isolated V8 Execution | Candidate validation inside sandboxed `WASM` Isolates |
35
- | **Layer 5** | AST Contract & Schema | Preserves Zod/Schema classes, decorators, and API boundaries |
36
- | **Layer 6** | Unused Package Sweeper | Flags unused external dependencies in `package.json` |
37
- | **Layer 7** | Non-Standard Entry | Implicit bindings (DI/Events) and Dynamic Specifier resolution |
37
+ | **Engine** | Babel / OXC (Standard) | **Yuku / Zig (Hyper-Speed)** |
38
+ | **Logic Analysis** | Heuristics (Guessing) | **Z3 SMT Solver (Proving)** |
39
+ | **Dynamic Paths** | Pattern Matching | **WASM Sandbox Execution** |
40
+ | **Interface Audit** | Ignores Members | **Deep Member-Level Analysis** |
41
+ | **Framework Support** | Plugins (Core-Level) | **7-Layer Semantic Context** |
42
+ | **False Positives** | High (in complex setups) | **Near-Zero (Context Aware)** |
43
+
44
+ ---
45
+
46
+ ## 🏗️ The 7-Layer Architecture
47
+ OptiPrune operates in seven specialized layers to guarantee maximum accuracy:
48
+
49
+ 1. **Layer 1: Discovery** – Ultra-fast file scanning.
50
+ 2. **Layer 2: Basic CFG** – Detects standard dead code after terminal statements.
51
+ 3. **Layer 3: SMT Logic** – Mathematical path proofs with Z3.
52
+ 4. **Layer 4: WASM Sandbox** – Dynamic path resolution via execution.
53
+ 5. **Layer 6: Schema Shield** – Protection for Zod, Decorators & Contracts.
54
+ 6. **Layer 6: Dependency Audit** – Scans lockfiles & package.json scripts.
55
+ 7. **Layer 7: Topology Engine** – Understands NestJS DI & Event Buses.
56
+
57
+ ---
58
+
59
+ ## 📈 Benchmark Numbers (Real-World Test)
60
+ *Tested on a NestJS project with 1000+ files.*
61
+
62
+ * **Knip Speed:** 1.26s (with crash risks on complex types)
63
+ * **OptiPrune Speed:** **0.87s** (Stable & Precise)
64
+ * **Accuracy:** OptiPrune found **15% more** real dead code (unused interface properties & logical errors) that Knip completely missed.
38
65
 
39
66
  ---
40
67
 
@@ -75,6 +102,9 @@ npx optiprune
75
102
 
76
103
  ---
77
104
 
78
- ## Contributing
105
+ ## 🤝 Join the Revolution
106
+ OptiPrune isn't just a tool. It's a technical statement. Help us save the world from dirty code.
79
107
 
108
+ **GitHub:** [DreamLongYT/optiprune](https://github.com/DreamLongYT/optiprune)
109
+ **Web:** [opti.drml.int.yt](https://opti.drml.int.yt)
80
110
  See [CONTRIBUTING.md](CONTRIBUTING.md) for local setup and development guides.
package/bin/runner.js ADDED
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env node
2
+ import { createRequire } from "node:module";
3
+ import { fileURLToPath, pathToFileURL } from "node:url";
4
+ import path from "pathe";
5
+
6
+ const require = createRequire(import.meta.url);
7
+
8
+ let cliPath;
9
+
10
+ try {
11
+ // 1. Try standard package resolution
12
+ const pkgPath = require.resolve("@optiprune/cli/package.json");
13
+ cliPath = path.join(path.dirname(pkgPath), "dist/cli.js");
14
+ } catch {
15
+ // 2. Monorepo / global symlink fallback
16
+ const currentDir = path.dirname(fileURLToPath(import.meta.url));
17
+ cliPath = path.resolve(currentDir, "../../cli/dist/cli.js");
18
+ }
19
+
20
+ // Convert absolute Windows path (E:\...) into a valid file:// URL
21
+ const cliUrl = pathToFileURL(cliPath).href;
22
+
23
+ import(cliUrl).catch((err) => {
24
+ console.error("Failed to execute @optiprune/cli:", err);
25
+ process.exit(1);
26
+ });
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "optiprune",
3
- "version": "2.1.4",
3
+ "version": "2.1.7",
4
4
  "description": "Resilient static dead-code analyzer for TypeScript and JavaScript workspaces.",
5
5
  "type": "module",
6
- "main": "./dist/index.js",
7
- "types": "./dist/index.d.ts",
6
+ "main": "./dist/cli.js",
7
+ "types": "./dist/cli.d.ts",
8
8
  "homepage": "https://opti.drml.int.yt/",
9
9
  "repository": {
10
10
  "type": "git",
@@ -50,49 +50,22 @@
50
50
  "optimization"
51
51
  ],
52
52
  "bin": {
53
- "optiprune": "dist/cli.js"
53
+ "optiprune": "./bin/runner.js"
54
54
  },
55
55
  "exports": {
56
56
  ".": {
57
- "types": "./dist/index.d.ts",
58
- "import": "./dist/index.js"
57
+ "types": "./dist/cli.d.ts",
58
+ "import": "./dist/cli.js"
59
59
  }
60
60
  },
61
61
  "files": [
62
- "dist",
62
+ "bin",
63
63
  "README.md",
64
64
  "LICENSE"
65
65
  ],
66
- "scripts": {
67
- "build": "npx tsc -p tsconfig.json",
68
- "check": "npx tsc -p tsconfig.json --noEmit",
69
- "test": "vitest run --no-file-parallelism",
70
- "test:watch": "vitest",
71
- "analyze": "node ./dist/cli.js",
72
- "docs:dev": "vitepress dev docs",
73
- "docs:build": "vitepress build docs",
74
- "docs:preview": "vitepress preview docs",
75
- "prepublishOnly": "npm run build",
76
- "release": "node -e \"fs.rmSync('dist', { recursive: true, force: true })\" && npm ci && npm run build"
77
- },
78
66
  "dependencies": {
79
- "commander": "^15.0.0",
80
- "esbuild": "^0.28.1",
81
- "fast-glob": "^3.3.3",
82
- "js-yaml": "^5.2.2",
83
- "pathe": "2.0.3",
84
- "quickjs-emscripten": "^0.32.0",
85
- "yuku-ast": "^0.8.3",
86
- "yuku-codegen": "^0.8.3",
87
- "yuku-parser": "^0.8.3",
88
- "z3-solver": "^5.0.0"
89
- },
90
- "devDependencies": {
91
- "@types/node": "^22.15.3",
92
- "typescript": "^5.8.3",
93
- "vitepress": "^1.6.4",
94
- "vitest": "^3.2.4",
95
- "vue": "^3.5.40"
67
+ "@optiprune/cli": "^1.2.8",
68
+ "pathe": "2.0.3"
96
69
  },
97
70
  "engines": {
98
71
  "node": "^22.18.0 || >=24.11.0"
@@ -103,4 +76,4 @@
103
76
  "test": "tests"
104
77
  },
105
78
  "author": "DreamLongYT"
106
- }
79
+ }
@@ -1,149 +0,0 @@
1
- /**
2
- * Shared AST Utilities for Yuku-compatible ESTree ASTs.
3
- * Replaces @babel/types for common type-guarding tasks.
4
- */
5
- export declare const t: {
6
- isStringLiteral: (n: unknown) => n is {
7
- type: "Literal";
8
- value: string;
9
- };
10
- isNumericLiteral: (n: unknown) => n is {
11
- type: "Literal";
12
- value: number;
13
- };
14
- isBooleanLiteral: (n: unknown) => n is {
15
- type: "Literal";
16
- value: boolean;
17
- };
18
- isIdentifier: (n: unknown) => n is {
19
- type: "Identifier";
20
- name: string;
21
- };
22
- isCallExpression: (n: unknown) => n is {
23
- type: "CallExpression";
24
- callee: any;
25
- arguments: any[];
26
- };
27
- isMemberExpression: (n: unknown) => n is {
28
- type: "MemberExpression";
29
- object: any;
30
- property: any;
31
- computed: boolean;
32
- };
33
- isVariableDeclarator: (n: unknown) => n is {
34
- type: "VariableDeclarator";
35
- id: any;
36
- init: any;
37
- };
38
- isFunctionDeclaration: (n: unknown) => n is {
39
- type: "FunctionDeclaration";
40
- id: {
41
- name: string;
42
- } | null;
43
- };
44
- isExportNamedDeclaration: (n: unknown) => n is {
45
- type: "ExportNamedDeclaration";
46
- declaration: any;
47
- specifiers: any[];
48
- };
49
- isImportDeclaration: (n: unknown) => n is {
50
- type: "ImportDeclaration";
51
- source: {
52
- value: string;
53
- };
54
- specifiers: any[];
55
- };
56
- isObjectProperty: (n: unknown) => n is {
57
- type: "Property";
58
- key: any;
59
- value: any;
60
- computed: boolean;
61
- };
62
- isObjectMethod: (n: unknown) => n is {
63
- type: "ObjectMethod";
64
- key: any;
65
- };
66
- isTSInterfaceDeclaration: (n: unknown) => n is {
67
- type: "TSInterfaceDeclaration";
68
- id: {
69
- name: string;
70
- };
71
- };
72
- isTSTypeAliasDeclaration: (n: unknown) => n is {
73
- type: "TSTypeAliasDeclaration";
74
- id: {
75
- name: string;
76
- };
77
- };
78
- isTSEnumDeclaration: (n: unknown) => n is {
79
- type: "TSEnumDeclaration";
80
- id: {
81
- name: string;
82
- };
83
- };
84
- isClassDeclaration: (n: unknown) => n is {
85
- type: "ClassDeclaration";
86
- id: {
87
- name: string;
88
- } | null;
89
- };
90
- isClassExpression: (n: unknown) => n is {
91
- type: "ClassExpression";
92
- id: {
93
- name: string;
94
- } | null;
95
- };
96
- isClassMethod: (n: unknown) => n is {
97
- type: "ClassMethod";
98
- key: any;
99
- };
100
- isClassProperty: (n: unknown) => n is {
101
- type: "ClassProperty";
102
- key: any;
103
- };
104
- isExportDefaultDeclaration: (n: unknown) => n is {
105
- type: "ExportDefaultDeclaration";
106
- declaration: any;
107
- };
108
- isFunctionExpression: (n: unknown) => n is {
109
- type: "FunctionExpression";
110
- id: {
111
- name: string;
112
- } | null;
113
- };
114
- isJSXElement: (n: unknown) => n is {
115
- type: "JSXElement";
116
- openingElement: any;
117
- };
118
- isJSXIdentifier: (n: unknown) => n is {
119
- type: "JSXIdentifier";
120
- name: string;
121
- };
122
- isObjectExpression: (n: unknown) => n is {
123
- type: "ObjectExpression";
124
- properties: any[];
125
- };
126
- isLiteral: (n: unknown) => n is {
127
- type: "Literal";
128
- value: any;
129
- };
130
- isJSXAttribute: (n: unknown) => n is {
131
- type: "JSXAttribute";
132
- name: any;
133
- value: any;
134
- };
135
- isNewExpression: (n: unknown) => n is {
136
- type: "NewExpression";
137
- callee: any;
138
- arguments: any[];
139
- };
140
- isTemplateLiteral: (n: unknown) => n is {
141
- type: "TemplateLiteral";
142
- quasis: any[];
143
- expressions: any[];
144
- };
145
- isDecorator: (n: unknown) => n is {
146
- type: "Decorator";
147
- expression: any;
148
- };
149
- };
package/dist/ast-utils.js DELETED
@@ -1,36 +0,0 @@
1
- /**
2
- * Shared AST Utilities for Yuku-compatible ESTree ASTs.
3
- * Replaces @babel/types for common type-guarding tasks.
4
- */
5
- export const t = {
6
- isStringLiteral: (n) => !!n && typeof n === 'object' && n.type === 'Literal' && typeof n.value === 'string',
7
- isNumericLiteral: (n) => !!n && typeof n === 'object' && n.type === 'Literal' && typeof n.value === 'number',
8
- isBooleanLiteral: (n) => !!n && typeof n === 'object' && n.type === 'Literal' && typeof n.value === 'boolean',
9
- isIdentifier: (n) => !!n && typeof n === 'object' && n.type === 'Identifier',
10
- isCallExpression: (n) => !!n && typeof n === 'object' && n.type === 'CallExpression',
11
- isMemberExpression: (n) => !!n && typeof n === 'object' && n.type === 'MemberExpression',
12
- isVariableDeclarator: (n) => !!n && typeof n === 'object' && n.type === 'VariableDeclarator',
13
- isFunctionDeclaration: (n) => !!n && typeof n === 'object' && n.type === 'FunctionDeclaration',
14
- isExportNamedDeclaration: (n) => !!n && typeof n === 'object' && n.type === 'ExportNamedDeclaration',
15
- isImportDeclaration: (n) => !!n && typeof n === 'object' && n.type === 'ImportDeclaration',
16
- isObjectProperty: (n) => !!n && typeof n === 'object' && (n.type === 'Property' || n.type === 'ObjectProperty'),
17
- isObjectMethod: (n) => !!n && typeof n === 'object' && n.type === 'ObjectMethod',
18
- isTSInterfaceDeclaration: (n) => !!n && typeof n === 'object' && n.type === 'TSInterfaceDeclaration',
19
- isTSTypeAliasDeclaration: (n) => !!n && typeof n === 'object' && n.type === 'TSTypeAliasDeclaration',
20
- isTSEnumDeclaration: (n) => !!n && typeof n === 'object' && n.type === 'TSEnumDeclaration',
21
- isClassDeclaration: (n) => !!n && typeof n === 'object' && n.type === 'ClassDeclaration',
22
- isClassExpression: (n) => !!n && typeof n === 'object' && n.type === 'ClassExpression',
23
- isClassMethod: (n) => !!n && typeof n === 'object' && n.type === 'ClassMethod',
24
- isClassProperty: (n) => !!n && typeof n === 'object' && (n.type === 'ClassProperty' || n.type === 'PropertyDefinition'),
25
- isExportDefaultDeclaration: (n) => !!n && typeof n === 'object' && n.type === 'ExportDefaultDeclaration',
26
- isFunctionExpression: (n) => !!n && typeof n === 'object' && n.type === 'FunctionExpression',
27
- isJSXElement: (n) => !!n && typeof n === 'object' && n.type === 'JSXElement',
28
- isJSXIdentifier: (n) => !!n && typeof n === 'object' && n.type === 'JSXIdentifier',
29
- isObjectExpression: (n) => !!n && typeof n === 'object' && n.type === 'ObjectExpression',
30
- isLiteral: (n) => !!n && typeof n === 'object' && n.type === 'Literal',
31
- isJSXAttribute: (n) => !!n && typeof n === 'object' && n.type === 'JSXAttribute',
32
- isNewExpression: (n) => !!n && typeof n === 'object' && n.type === 'NewExpression',
33
- isTemplateLiteral: (n) => !!n && typeof n === 'object' && n.type === 'TemplateLiteral',
34
- isDecorator: (n) => !!n && typeof n === 'object' && n.type === 'Decorator',
35
- };
36
- //# sourceMappingURL=ast-utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ast-utils.js","sourceRoot":"","sources":["../src/ast-utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,CAAC,MAAM,CAAC,GAAG;IACf,eAAe,EAAE,CAAC,CAAU,EAA2C,EAAE,CACvE,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAK,CAAS,CAAC,IAAI,KAAK,SAAS,IAAI,OAAQ,CAAS,CAAC,KAAK,KAAK,QAAQ;IAEvG,gBAAgB,EAAE,CAAC,CAAU,EAA2C,EAAE,CACxE,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAK,CAAS,CAAC,IAAI,KAAK,SAAS,IAAI,OAAQ,CAAS,CAAC,KAAK,KAAK,QAAQ;IAEvG,gBAAgB,EAAE,CAAC,CAAU,EAA4C,EAAE,CACzE,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAK,CAAS,CAAC,IAAI,KAAK,SAAS,IAAI,OAAQ,CAAS,CAAC,KAAK,KAAK,SAAS;IAExG,YAAY,EAAE,CAAC,CAAU,EAA6C,EAAE,CACtE,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAK,CAAS,CAAC,IAAI,KAAK,YAAY;IAElE,gBAAgB,EAAE,CAAC,CAAU,EAAkE,EAAE,CAC/F,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAK,CAAS,CAAC,IAAI,KAAK,gBAAgB;IAEtE,kBAAkB,EAAE,CAAC,CAAU,EAAoF,EAAE,CACnH,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAK,CAAS,CAAC,IAAI,KAAK,kBAAkB;IAEx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e;IAErE,kBAAkB,EAAE,CAAC,CAAU,EAAwD,EAAE,CACvF,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAK,CAAS,CAAC,IAAI,KAAK,kBAAkB;IAExE,SAAS,EAAE,CAAC,CAAU,EAAwC,EAAE,CAC9D,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAK,CAAS,CAAC,IAAI,KAAK,SAAS;IAE/D,cAAc,EAAE,CAAC,CAAU,EAAwD,EAAE,CACnF,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAK,CAAS,CAAC,IAAI,KAAK,cAAc;IAEpE,eAAe,EAAE,CAAC,CAAU,EAAiE,EAAE,CAC7F,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAK,CAAS,CAAC,IAAI,KAAK,eAAe;IAErE,iBAAiB,EAAE,CAAC,CAAU,EAAuE,EAAE,CACrG,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAK,CAAS,CAAC,IAAI,KAAK,iBAAiB;IAEvE,WAAW,EAAE,CAAC,CAAU,EAA+C,EAAE,CACvE,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAK,CAAS,CAAC,IAAI,KAAK,WAAW;CAClE,CAAC"}
package/dist/cache.d.ts DELETED
@@ -1,14 +0,0 @@
1
- import type { ModuleRecord } from "./types.js";
2
- export interface CacheEntry {
3
- hash: string;
4
- moduleRecord: ModuleRecord;
5
- timestamp: number;
6
- }
7
- export interface AnalysisCache {
8
- version: string;
9
- entries: Record<string, CacheEntry>;
10
- }
11
- export declare function getFileHash(content: string): string;
12
- export declare function loadCache(rootDir: string): AnalysisCache;
13
- export declare function saveCache(rootDir: string, cache: AnalysisCache): void;
14
- export declare function isCacheValid(entry: CacheEntry, currentContent: string): boolean;
package/dist/cache.js DELETED
@@ -1,36 +0,0 @@
1
- import fs from "node:fs";
2
- import path from "node:path";
3
- import crypto from "node:crypto";
4
- const CACHE_DIR = ".optiprune";
5
- const CACHE_FILE = "cache.json";
6
- export function getFileHash(content) {
7
- return crypto.createHash("sha256").update(content).digest("hex");
8
- }
9
- export function loadCache(rootDir) {
10
- const cachePath = path.join(rootDir, CACHE_DIR, CACHE_FILE);
11
- if (fs.existsSync(cachePath)) {
12
- try {
13
- return JSON.parse(fs.readFileSync(cachePath, "utf-8"));
14
- }
15
- catch (e) {
16
- // Ignore
17
- }
18
- }
19
- return { version: "1.0", entries: {} };
20
- }
21
- export function saveCache(rootDir, cache) {
22
- try {
23
- const dirPath = path.join(rootDir, CACHE_DIR);
24
- if (!fs.existsSync(dirPath)) {
25
- fs.mkdirSync(dirPath, { recursive: true });
26
- }
27
- fs.writeFileSync(path.join(dirPath, CACHE_FILE), JSON.stringify(cache, null, 2));
28
- }
29
- catch (e) {
30
- // Ignore cache write errors in environments like tests where rootDir might be problematic
31
- }
32
- }
33
- export function isCacheValid(entry, currentContent) {
34
- return entry.hash === getFileHash(currentContent);
35
- }
36
- //# sourceMappingURL=cache.js.map
package/dist/cache.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"cache.js","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,MAAM,MAAM,aAAa,CAAC;AAcjC,MAAM,SAAS,GAAG,YAAY,CAAC;AAC/B,MAAM,UAAU,GAAG,YAAY,CAAC;AAEhC,MAAM,UAAU,WAAW,CAAC,OAAe;IACzC,OAAO,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACnE,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,OAAe;IACvC,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC;IAC5D,IAAI,EAAE,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;QAC7B,IAAI,CAAC;YACH,OAAO,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC;QACzD,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,SAAS;QACX,CAAC;IACH,CAAC;IACD,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;AACzC,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,OAAe,EAAE,KAAoB;IAC7D,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;QAC9C,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;YAC5B,EAAE,CAAC,SAAS,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAC7C,CAAC;QACD,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,UAAU,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IACnF,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,0FAA0F;IAC5F,CAAC;AACH,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,KAAiB,EAAE,cAAsB;IACpE,OAAO,KAAK,CAAC,IAAI,KAAK,WAAW,CAAC,cAAc,CAAC,CAAC;AACpD,CAAC"}
package/dist/cli.d.ts DELETED
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- export {};
package/dist/cli.js DELETED
@@ -1,68 +0,0 @@
1
- #!/usr/bin/env node
2
- import path from "pathe";
3
- import { Command } from "commander";
4
- const program = new Command();
5
- import { analyze, shouldFail } from "./index.js";
6
- import { readJsonFile } from "./fs-utils.js";
7
- import { formatTerminal, formatSarif } from "./reporters.js";
8
- import { fileURLToPath } from "node:url";
9
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
10
- const PKG_JSON = await readJsonFile(path.join(__dirname, "..", "package.json"));
11
- program
12
- .name("optiprune")
13
- .version(PKG_JSON && typeof PKG_JSON.version === "string" ? PKG_JSON.version : "1.8.2")
14
- .description("Finds dead code in TypeScript/JavaScript projects.")
15
- .option("-r, --rootDir <path>", "Root directory of the project", process.cwd())
16
- .option("-e, --entry <patterns...>", "Entry point patterns (glob or file paths)", [])
17
- .option("-x, --extensions <exts...>", "File extensions to analyze", [".ts", ".tsx", ".js", ".jsx"])
18
- .option("-i, --ignore <patterns...>", "Ignore patterns (glob)", [])
19
- .option("--no-report-unused-exports", "Do not report unused exports")
20
- .option("--no-conventional-entries", "Do not include conventional entry points (e.g., src/index.ts)")
21
- .option("--fail-on <confidence>", "Fail on findings with confidence level (high, medium, low, none)", "high")
22
- .option("--json", "Output results as JSON")
23
- .option("--sarif", "Output results in SARIF format")
24
- .option("--skip-3", "Skip Layer 3 (SMT Constraint Solver)")
25
- .option("--skip-4", "Skip Layer 4 (Concolic Execution Proofs)")
26
- .action(async (options) => {
27
- try {
28
- const analyzerOptions = {
29
- rootDir: options.rootDir,
30
- entry: options.entry,
31
- extensions: options.extensions,
32
- ignore: options.ignore,
33
- reportUnusedExports: options.reportUnusedExports,
34
- includeConventionalEntries: options.conventionalEntries,
35
- failOn: options.failOn,
36
- json: options.json || options.sarif,
37
- skip3: options.skip3,
38
- skip4: options.skip4,
39
- };
40
- const report = await analyze(analyzerOptions);
41
- if (options.sarif) {
42
- console.log(formatSarif(report));
43
- }
44
- else if (options.json) {
45
- try {
46
- // Use a replacer to handle potential BigInt or other non-serializable types if any
47
- const json = JSON.stringify(report, (key, value) => typeof value === 'bigint' ? value.toString() : value, 2);
48
- console.log(json);
49
- }
50
- catch (jsonError) {
51
- console.error("Failed to generate JSON output:", jsonError);
52
- process.exit(1);
53
- }
54
- }
55
- else {
56
- console.log(formatTerminal(report));
57
- }
58
- if (shouldFail(report, options.failOn)) {
59
- process.exit(1);
60
- }
61
- }
62
- catch (error) {
63
- console.error("An unexpected error occurred:", error);
64
- process.exit(1);
65
- }
66
- });
67
- program.parse(process.argv);
68
- //# sourceMappingURL=cli.js.map
package/dist/cli.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAEA,OAAO,IAAI,MAAM,OAAO,CAAC;AACzB,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;AAC9B,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAG7D,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAC/D,MAAM,QAAQ,GAAG,MAAM,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,cAAc,CAAC,CAAgC,CAAC;AAE/G,OAAO;KACJ,IAAI,CAAC,WAAW,CAAC;KACjB,OAAO,CAAC,QAAQ,IAAI,OAAO,QAAQ,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC;KACtF,WAAW,CAAC,oDAAoD,CAAC;KACjE,MAAM,CAAC,sBAAsB,EAAE,+BAA+B,EAAE,OAAO,CAAC,GAAG,EAAE,CAAC;KAC9E,MAAM,CAAC,2BAA2B,EAAE,2CAA2C,EAAE,EAA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;YACxB,IAAI,CAAC;gBACH,mFAAmF;gBACnF,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,CACjD,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,KAAK,EACpD,CAAC,CACF,CAAC;gBACF,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YACpB,CAAC;YAAC,OAAO,SAAS,EAAE,CAAC;gBACnB,OAAO,CAAC,KAAK,CAAC,iCAAiC,EAAE,SAAS,CAAC,CAAC;gBAC5D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YAClB,CAAC;QACH,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC;QACtC,CAAC;QAED,IAAI,UAAU,CAAC,MAAM,EAAE,OAAO,CAAC,MAAa,CAAC,EAAE,CAAC;YAC9C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,+BAA+B,EAAE,KAAK,CAAC,CAAC;QACtD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC,CAAC,CAAC;AAEL,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC"}
@@ -1,4 +0,0 @@
1
- import type { Config, ResolvedOptions } from "./types.js";
2
- export declare const DEFAULT_CONFIG: ResolvedOptions;
3
- export declare function loadConfig(rootDir: string): Promise<Config>;
4
- export declare function mergeConfig(base: ResolvedOptions, userConfig: Config): ResolvedOptions;
@@ -1,84 +0,0 @@
1
- import path from "pathe";
2
- import fs from "node:fs";
3
- import { pathToFileURL } from "node:url";
4
- import { DEFAULT_EXTENSIONS, DEFAULT_IGNORE, normalizeAbsolute } from "./fs-utils.js";
5
- export const DEFAULT_CONFIG = {
6
- rootDir: normalizeAbsolute(process.cwd()),
7
- entry: [],
8
- extensions: DEFAULT_EXTENSIONS,
9
- ignore: DEFAULT_IGNORE,
10
- reportUnusedExports: true,
11
- schemaEnums: {},
12
- failOn: "high",
13
- json: false,
14
- includeConventionalEntries: true,
15
- externalContracts: [],
16
- verbose: false,
17
- pathAliases: new Map(),
18
- layers: {
19
- smtTimeoutMs: 100,
20
- isolateMemoryLimitMb: 16,
21
- enableConcolicProof: true,
22
- skip3: false,
23
- skip4: false,
24
- },
25
- rules: {
26
- 'unused-export': 'warning',
27
- 'unreachable-file': 'warning',
28
- 'constant-condition': 'warning',
29
- 'unreachable-dynamic-path': 'warning',
30
- }
31
- };
32
- export async function loadConfig(rootDir) {
33
- const configPaths = [
34
- path.join(rootDir, "optiprune.config.ts"),
35
- path.join(rootDir, "optiprune.config.js"),
36
- path.join(rootDir, "optiprune.config.mjs"),
37
- ];
38
- for (const configPath of configPaths) {
39
- if (fs.existsSync(configPath)) {
40
- try {
41
- const configUrl = pathToFileURL(configPath).href;
42
- const module = await import(configUrl);
43
- return module.default || module;
44
- }
45
- catch (e) {
46
- console.warn(`[Config] Failed to load config from ${configPath}:`, e);
47
- }
48
- }
49
- }
50
- return {};
51
- }
52
- export function mergeConfig(base, userConfig) {
53
- // 1. Check if user explicitly passed non-empty entry array
54
- const hasUserEntries = Array.isArray(userConfig.entry) && userConfig.entry.length > 0;
55
- // 2. Normalize rootDir to POSIX
56
- const rootDir = userConfig.rootDir ? normalizeAbsolute(userConfig.rootDir) : base.rootDir;
57
- // 3. Normalize entries to POSIX absolute paths
58
- const rawEntries = hasUserEntries ? userConfig.entry : (userConfig.entry || base.entry);
59
- const entry = rawEntries.map(e => normalizeAbsolute(path.resolve(rootDir, e)));
60
- // 4. If explicit entries are supplied, force includeConventionalEntries to false unless user explicitly said otherwise
61
- const includeConventionalEntries = hasUserEntries
62
- ? (userConfig.includeConventionalEntries ?? false)
63
- : (userConfig.includeConventionalEntries ?? base.includeConventionalEntries);
64
- return {
65
- ...base,
66
- ...userConfig,
67
- rootDir,
68
- entry,
69
- includeConventionalEntries,
70
- layers: {
71
- ...base.layers,
72
- ...userConfig.layers,
73
- },
74
- rules: {
75
- ...base.rules,
76
- ...userConfig.rules,
77
- },
78
- externalContracts: [
79
- ...base.externalContracts,
80
- ...(userConfig.externalContracts || []),
81
- ],
82
- };
83
- }
84
- //# sourceMappingURL=config-loader.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"config-loader.js","sourceRoot":"","sources":["../src/config-loader.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,OAAO,CAAC;AACzB,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAEtF,MAAM,CAAC,MAAM,cAAc,GAAoB;IAC7C,OAAO,EAAE,iBAAiB,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC;IACzC,KAAK,EAAE,EAAE;IACT,UAAU,EAAE,kBAAkB;IAC9B,MAAM,EAAE,cAAc;IACtB,mBAAmB,EAAE,IAAI;IACzB,WAAW,EAAE,EAAE;IACf,MAAM,EAAE,MAAM;IACd,IAAI,EAAE,KAAK;IACX,0BAA0B,EAAE,IAAI;IAChC,iBAAiB,EAAE,EAAE;IACrB,OAAO,EAAE,KAAK;IACd,WAAW,EAAE,IAAI,GAAG,EAAoB;IACxC,MAAM,EAAE;QACN,YAAY,EAAE,GAAG;QACjB,oBAAoB,EAAE,EAAE;QACxB,mBAAmB,EAAE,IAAI;QACzB,KAAK,EAAE,KAAK;QACZ,KAAK,EAAE,KAAK;KACb;IACD,KAAK,EAAE;QACL,eAAe,EAAE,SAAS;QAC1B,kBAAkB,EAAE,SAAS;QAC7B,oBAAoB,EAAE,SAAS;QAC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