siko 0.3.1 → 0.4.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.
- package/CHANGELOG.md +29 -1
- package/README.md +94 -48
- package/dist/cli/index.js +37 -28
- package/dist/cli/runner.js +16 -5
- package/dist/config/loader.js +6 -13
- package/dist/config/types.d.ts +9 -0
- package/dist/config/types.js +8 -5
- package/dist/instrumentation/babel-plugin.js +12 -17
- package/dist/instrumentation/instrumenter.d.ts +10 -0
- package/dist/instrumentation/instrumenter.js +27 -2
- package/dist/reporter/json-reporter.d.ts +17 -16
- package/dist/reporter/json-reporter.js +61 -12
- package/dist/reporter/terminal-reporter.d.ts +3 -2
- package/dist/reporter/terminal-reporter.js +30 -6
- package/dist/reporter/threshold-checker.js +2 -2
- package/dist/runtime/tracker.js +1 -1
- package/dist/utils/file-discovery.js +3 -3
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +5 -1
- package/dist/utils/source-map.d.ts +25 -0
- package/dist/utils/source-map.js +117 -0
- package/package.json +8 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,16 +1,39 @@
|
|
|
1
|
+
## [0.4.0] - 2026-02-08
|
|
2
|
+
|
|
3
|
+
### Added
|
|
4
|
+
- **Source map support** - Reports now show original TypeScript line numbers
|
|
5
|
+
- **Glob pattern exclusions** - Use `**/*.test.ts`, `*.tsx`, `src/jsx/**` patterns
|
|
6
|
+
- Prettier code formatting with CI enforcement
|
|
7
|
+
- `--no-source-maps` flag to disable source map resolution
|
|
8
|
+
|
|
9
|
+
### Fixed
|
|
10
|
+
- JSX/TSX file exclusion now works correctly with glob patterns
|
|
11
|
+
- Line number accuracy in TypeScript projects
|
|
12
|
+
- Exclude patterns like `*.test.js` now properly recognized
|
|
13
|
+
|
|
14
|
+
### Improved
|
|
15
|
+
- CI optimized - runs only on PRs, 2x faster
|
|
16
|
+
- File discovery with robust glob pattern matching
|
|
17
|
+
- Developer experience for TypeScript users
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
1
21
|
## [0.3.1] - 2026-02-07
|
|
2
22
|
|
|
3
23
|
### Fixed
|
|
24
|
+
|
|
4
25
|
- Glob pattern support for exclude patterns (e.g., `**/*.test.ts`, `*.tsx`)
|
|
5
26
|
- File exclusion now properly handles wildcard patterns
|
|
6
27
|
- JSX/TSX files can now be excluded using glob patterns
|
|
7
28
|
|
|
8
29
|
### Added
|
|
30
|
+
|
|
9
31
|
- minimatch library for robust glob pattern matching
|
|
10
32
|
- Comprehensive file discovery tests (12 new tests)
|
|
11
33
|
- Support for nested directory exclusions (e.g., `src/jsx/**`)
|
|
12
34
|
|
|
13
35
|
### Improved
|
|
36
|
+
|
|
14
37
|
- File discovery logic with proper glob matching
|
|
15
38
|
- Documentation for exclude pattern usage
|
|
16
39
|
- React/JSX project compatibility via proper exclusions
|
|
@@ -20,6 +43,7 @@
|
|
|
20
43
|
## [0.3.0] - 2026-02-07
|
|
21
44
|
|
|
22
45
|
### Added
|
|
46
|
+
|
|
23
47
|
- Comprehensive test suite with Jest (28 tests, all passing)
|
|
24
48
|
- ESLint configuration with TypeScript support
|
|
25
49
|
- GitHub Actions CI/CD workflows
|
|
@@ -32,18 +56,21 @@
|
|
|
32
56
|
- API.md for detailed API documentation
|
|
33
57
|
|
|
34
58
|
### Improved
|
|
59
|
+
|
|
35
60
|
- Build process with proper TypeScript compilation
|
|
36
61
|
- Error handling with type narrowing
|
|
37
62
|
- Code quality with linting rules
|
|
38
63
|
- Documentation structure
|
|
39
64
|
|
|
40
65
|
### CI/CD
|
|
66
|
+
|
|
41
67
|
- Automated tests on every push and PR
|
|
42
68
|
- ESLint checks in CI
|
|
43
69
|
- Multi-version Node.js testing (18.x, 20.x)
|
|
44
70
|
- Build verification checks
|
|
45
71
|
|
|
46
72
|
### Testing
|
|
73
|
+
|
|
47
74
|
- Runtime tracker tests
|
|
48
75
|
- Babel instrumentation tests
|
|
49
76
|
- Configuration loader tests
|
|
@@ -56,6 +83,7 @@
|
|
|
56
83
|
## [0.1.0] - 2026-02-05
|
|
57
84
|
|
|
58
85
|
### Added
|
|
86
|
+
|
|
59
87
|
- Initial package setup
|
|
60
88
|
- Basic placeholder CLI
|
|
61
89
|
|
|
@@ -64,7 +92,7 @@
|
|
|
64
92
|
## Upcoming Features
|
|
65
93
|
|
|
66
94
|
### Planned
|
|
67
|
-
|
|
95
|
+
|
|
68
96
|
- HTML report generation
|
|
69
97
|
- Watch mode
|
|
70
98
|
- Historical trend analysis
|
package/README.md
CHANGED
|
@@ -6,12 +6,12 @@
|
|
|
6
6
|
[](https://www.npmjs.com/package/siko)
|
|
7
7
|
[](https://opensource.org/licenses/MIT)
|
|
8
8
|
|
|
9
|
-
Unlike static analysis tools that
|
|
9
|
+
Unlike static analysis tools that _guess_ which code is unused, **siko actually runs your code** and tells you what never executed.
|
|
10
10
|
|
|
11
11
|
✅ **Zero false positives** - Based on real execution data
|
|
12
12
|
✅ **Finds runtime-only dead code** - Not just unused exports
|
|
13
13
|
✅ **Works with any test framework** - Jest, Mocha, Vitest, etc.
|
|
14
|
-
✅ **CI/CD ready** - Enforce coverage thresholds in your pipeline
|
|
14
|
+
✅ **CI/CD ready** - Enforce coverage thresholds in your pipeline
|
|
15
15
|
|
|
16
16
|
---
|
|
17
17
|
|
|
@@ -19,31 +19,34 @@ Unlike static analysis tools that *guess* which code is unused, **siko actually
|
|
|
19
19
|
|
|
20
20
|
### The Problem with Static Analysis
|
|
21
21
|
|
|
22
|
-
Popular tools like **Knip**, **ts-prune**, and **ESLint** use static analysis - they analyze your code
|
|
22
|
+
Popular tools like **Knip**, **ts-prune**, and **ESLint** use static analysis - they analyze your code _without running it_. This leads to:
|
|
23
23
|
|
|
24
24
|
❌ **False positives** - Code flagged as unused but actually runs conditionally
|
|
25
25
|
❌ **Missed dead code** - Private functions that are never called
|
|
26
|
-
❌ **Can't handle dynamic code** - Feature flags, conditional logic, runtime imports
|
|
26
|
+
❌ **Can't handle dynamic code** - Feature flags, conditional logic, runtime imports
|
|
27
27
|
|
|
28
28
|
### siko's Runtime Approach
|
|
29
29
|
|
|
30
30
|
**siko instruments your code and tracks what actually executes during your tests.**
|
|
31
|
+
|
|
31
32
|
```javascript
|
|
32
33
|
// example.js
|
|
33
|
-
export function apiCall() {
|
|
34
|
-
function validateInput() {
|
|
35
|
-
function legacyHelper() {
|
|
34
|
+
export function apiCall() {} // Used in prod only
|
|
35
|
+
function validateInput() {} // Used everywhere
|
|
36
|
+
function legacyHelper() {} // NEVER called!
|
|
36
37
|
|
|
37
38
|
// Your test
|
|
38
|
-
test(
|
|
39
|
+
test("api", () => {
|
|
39
40
|
apiCall(); // siko tracks this execution
|
|
40
41
|
});
|
|
41
42
|
```
|
|
42
43
|
|
|
43
44
|
**Static tools report:**
|
|
45
|
+
|
|
44
46
|
- ❌ All three functions look "used" (or flag `apiCall` incorrectly)
|
|
45
47
|
|
|
46
48
|
**siko reports:**
|
|
49
|
+
|
|
47
50
|
- ✅ `legacyHelper()` never executed - **true dead code!**
|
|
48
51
|
- ⚠️ `apiCall()` called 1x during tests
|
|
49
52
|
- ✅ `validateInput()` called 5x during tests
|
|
@@ -52,18 +55,19 @@ test('api', () => {
|
|
|
52
55
|
|
|
53
56
|
## 🔍 Comparison Matrix
|
|
54
57
|
|
|
55
|
-
| Feature
|
|
56
|
-
|
|
57
|
-
| **Analysis Type**
|
|
58
|
-
| **Runs Your Code**
|
|
59
|
-
| **Finds Unused Exports**
|
|
60
|
-
| **Finds Never-Executed Functions** | ❌
|
|
61
|
-
| **False Positives**
|
|
62
|
-
| **Works on Private Functions**
|
|
63
|
-
| **Detects Feature-Flagged Code**
|
|
64
|
-
| **Execution Count**
|
|
58
|
+
| Feature | Knip/ts-prune | ESLint | **siko** |
|
|
59
|
+
| ---------------------------------- | ------------- | ------- | -------------- |
|
|
60
|
+
| **Analysis Type** | Static | Static | **Runtime** ✨ |
|
|
61
|
+
| **Runs Your Code** | No | No | **Yes** |
|
|
62
|
+
| **Finds Unused Exports** | ✅ | ✅ | ❌ |
|
|
63
|
+
| **Finds Never-Executed Functions** | ❌ | ❌ | **✅** |
|
|
64
|
+
| **False Positives** | Common | Common | **Rare** |
|
|
65
|
+
| **Works on Private Functions** | Limited | Limited | **✅** |
|
|
66
|
+
| **Detects Feature-Flagged Code** | ❌ | ❌ | **✅** |
|
|
67
|
+
| **Execution Count** | ❌ | ❌ | **✅** |
|
|
65
68
|
|
|
66
69
|
**💡 Pro Tip**: Use **both approaches** together!
|
|
70
|
+
|
|
67
71
|
- **Knip** for structural cleanup (unused files, dependencies, exports)
|
|
68
72
|
- **siko** for runtime cleanup (never-executed functions)
|
|
69
73
|
|
|
@@ -72,6 +76,7 @@ test('api', () => {
|
|
|
72
76
|
### Static Analysis (No Execution Required)
|
|
73
77
|
|
|
74
78
|
**Knip, ts-prune, ESLint**
|
|
79
|
+
|
|
75
80
|
- ✅ Fast - no execution needed
|
|
76
81
|
- ✅ Finds structural issues (unused exports, files)
|
|
77
82
|
- ❌ Can't see runtime behavior
|
|
@@ -82,6 +87,7 @@ test('api', () => {
|
|
|
82
87
|
### Runtime Analysis (Execution Required)
|
|
83
88
|
|
|
84
89
|
**siko**
|
|
90
|
+
|
|
85
91
|
- ✅ High accuracy - based on real execution
|
|
86
92
|
- ✅ Finds never-executed functions
|
|
87
93
|
- ✅ No false positives
|
|
@@ -92,6 +98,7 @@ test('api', () => {
|
|
|
92
98
|
### Traditional Coverage Tools
|
|
93
99
|
|
|
94
100
|
**Istanbul, nyc, c8**
|
|
101
|
+
|
|
95
102
|
- ✅ Line/branch/statement coverage
|
|
96
103
|
- ✅ Standard industry metrics
|
|
97
104
|
- ❌ Focus on "% covered", not "what's unused"
|
|
@@ -101,11 +108,12 @@ test('api', () => {
|
|
|
101
108
|
---
|
|
102
109
|
|
|
103
110
|
**The Complete Toolkit:**
|
|
111
|
+
|
|
104
112
|
```bash
|
|
105
113
|
# 1. Structural cleanup
|
|
106
114
|
npx knip
|
|
107
115
|
|
|
108
|
-
# 2. Runtime analysis
|
|
116
|
+
# 2. Runtime analysis
|
|
109
117
|
npx siko run npm test
|
|
110
118
|
|
|
111
119
|
# 3. Coverage metrics
|
|
@@ -130,11 +138,13 @@ npx nyc npm test
|
|
|
130
138
|
## 🚀 Quick Start
|
|
131
139
|
|
|
132
140
|
### Installation
|
|
141
|
+
|
|
133
142
|
```bash
|
|
134
143
|
npm install --save-dev siko
|
|
135
144
|
```
|
|
136
145
|
|
|
137
146
|
### Basic Usage
|
|
147
|
+
|
|
138
148
|
```bash
|
|
139
149
|
# Run your tests with instrumentation
|
|
140
150
|
npx siko run npm test
|
|
@@ -144,6 +154,7 @@ npx siko report
|
|
|
144
154
|
```
|
|
145
155
|
|
|
146
156
|
**Example Output:**
|
|
157
|
+
|
|
147
158
|
```
|
|
148
159
|
📊 siko Signal Analysis Report
|
|
149
160
|
────────────────────────────────────────────────────────────
|
|
@@ -172,9 +183,10 @@ Now you can **confidently delete** those 3 functions - they never executed durin
|
|
|
172
183
|
## 📖 How It Works
|
|
173
184
|
|
|
174
185
|
siko uses a unique **runtime instrumentation approach**:
|
|
186
|
+
|
|
175
187
|
```
|
|
176
188
|
1. Instrument → Babel plugin injects tracking calls
|
|
177
|
-
2. Execute → Run your tests/app normally
|
|
189
|
+
2. Execute → Run your tests/app normally
|
|
178
190
|
3. Track → Record which functions actually run
|
|
179
191
|
4. Analyze → Compare inventory vs execution
|
|
180
192
|
5. Report → Show never-executed functions
|
|
@@ -185,6 +197,7 @@ siko uses a unique **runtime instrumentation approach**:
|
|
|
185
197
|
siko performs **runtime analysis** - it needs to execute your code to track what runs.
|
|
186
198
|
|
|
187
199
|
### You Can Run:
|
|
200
|
+
|
|
188
201
|
```bash
|
|
189
202
|
# ✅ Tests (recommended - most comprehensive)
|
|
190
203
|
siko run npm test
|
|
@@ -205,13 +218,15 @@ siko run ts-node src/index.ts
|
|
|
205
218
|
### Best Results: Comprehensive Test Suites
|
|
206
219
|
|
|
207
220
|
**With good test coverage:**
|
|
221
|
+
|
|
208
222
|
```bash
|
|
209
223
|
siko run npm test
|
|
210
|
-
# Result: High confidence - if tests are thorough,
|
|
224
|
+
# Result: High confidence - if tests are thorough,
|
|
211
225
|
# unused functions are likely dead code
|
|
212
226
|
```
|
|
213
227
|
|
|
214
228
|
**Without tests (manual app run):**
|
|
229
|
+
|
|
215
230
|
```bash
|
|
216
231
|
siko run node app.js
|
|
217
232
|
# Use app for 5 minutes, then stop
|
|
@@ -220,6 +235,7 @@ siko run node app.js
|
|
|
220
235
|
```
|
|
221
236
|
|
|
222
237
|
### 💡 Pro Tip: Run Multiple Times
|
|
238
|
+
|
|
223
239
|
```bash
|
|
224
240
|
# Run tests first
|
|
225
241
|
siko run npm test
|
|
@@ -234,6 +250,7 @@ siko report
|
|
|
234
250
|
This gives you the most comprehensive view of your codebase!
|
|
235
251
|
|
|
236
252
|
### Architecture
|
|
253
|
+
|
|
237
254
|
```
|
|
238
255
|
Source Code → Babel Instrumentation → Runtime Tracking → Signal Report
|
|
239
256
|
```
|
|
@@ -250,21 +267,23 @@ Unlike static analysis, siko gives you **certainty** - if a function didn't run
|
|
|
250
267
|
✅ **Refactoring with confidence** - Know exactly what's safe to delete
|
|
251
268
|
✅ **Test coverage insights** - Which code paths are never tested
|
|
252
269
|
✅ **Legacy code cleanup** - Find ancient functions that never run
|
|
253
|
-
✅ **CI/CD quality gates** - Enforce execution coverage standards
|
|
270
|
+
✅ **CI/CD quality gates** - Enforce execution coverage standards
|
|
254
271
|
|
|
255
272
|
### When to Use Static Tools Instead:
|
|
256
273
|
|
|
257
274
|
Use **Knip** or **ts-prune** when you want to:
|
|
275
|
+
|
|
258
276
|
- Find unused files and dependencies
|
|
259
277
|
- Detect unused exports across modules
|
|
260
278
|
- Quick analysis without running code
|
|
261
279
|
|
|
262
280
|
### Best Practice: Use Both! 🎯
|
|
281
|
+
|
|
263
282
|
```bash
|
|
264
283
|
# 1. Static analysis - structural cleanup
|
|
265
284
|
npx knip
|
|
266
285
|
|
|
267
|
-
# 2. Runtime analysis - execution cleanup
|
|
286
|
+
# 2. Runtime analysis - execution cleanup
|
|
268
287
|
npx siko run npm test
|
|
269
288
|
npx siko report
|
|
270
289
|
```
|
|
@@ -278,6 +297,7 @@ npx siko report
|
|
|
278
297
|
#### `siko run <command>`
|
|
279
298
|
|
|
280
299
|
Instruments your code and runs a command:
|
|
300
|
+
|
|
281
301
|
```bash
|
|
282
302
|
# Run tests
|
|
283
303
|
npx siko run npm test
|
|
@@ -290,6 +310,7 @@ npx siko run jest --coverage
|
|
|
290
310
|
```
|
|
291
311
|
|
|
292
312
|
**Options:**
|
|
313
|
+
|
|
293
314
|
- `-v, --verbose` - Show detailed instrumentation info
|
|
294
315
|
- `--no-clean` - Don't clean previous execution data
|
|
295
316
|
- `-c, --config <path>` - Path to config file
|
|
@@ -297,6 +318,7 @@ npx siko run jest --coverage
|
|
|
297
318
|
#### `siko report`
|
|
298
319
|
|
|
299
320
|
Generate analysis report:
|
|
321
|
+
|
|
300
322
|
```bash
|
|
301
323
|
# Terminal report (default)
|
|
302
324
|
npx siko report
|
|
@@ -318,6 +340,7 @@ npx siko report --fail-on-threshold
|
|
|
318
340
|
```
|
|
319
341
|
|
|
320
342
|
**Options:**
|
|
343
|
+
|
|
321
344
|
- `-v, --verbose` - Show executed functions with call counts
|
|
322
345
|
- `-a, --all` - Show all statistics
|
|
323
346
|
- `-f, --format <format>` - Output format: `terminal`, `json`, or `both`
|
|
@@ -327,6 +350,7 @@ npx siko report --fail-on-threshold
|
|
|
327
350
|
#### `siko init`
|
|
328
351
|
|
|
329
352
|
Create a configuration file:
|
|
353
|
+
|
|
330
354
|
```bash
|
|
331
355
|
# Create JSON config (default)
|
|
332
356
|
npx siko init
|
|
@@ -338,6 +362,7 @@ npx siko init --format js
|
|
|
338
362
|
#### `siko clean`
|
|
339
363
|
|
|
340
364
|
Remove execution data files:
|
|
365
|
+
|
|
341
366
|
```bash
|
|
342
367
|
npx siko clean
|
|
343
368
|
```
|
|
@@ -347,6 +372,7 @@ npx siko clean
|
|
|
347
372
|
## ⚙️ Configuration
|
|
348
373
|
|
|
349
374
|
Create a `siko.config.json` or `siko.config.js` file:
|
|
375
|
+
|
|
350
376
|
```json
|
|
351
377
|
{
|
|
352
378
|
"include": ["src", "lib"],
|
|
@@ -370,18 +396,18 @@ Create a `siko.config.json` or `siko.config.js` file:
|
|
|
370
396
|
|
|
371
397
|
### Configuration Options
|
|
372
398
|
|
|
373
|
-
| Option
|
|
374
|
-
|
|
375
|
-
| `include`
|
|
376
|
-
| `exclude`
|
|
377
|
-
| `extensions`
|
|
378
|
-
| `output.inventory`
|
|
379
|
-
| `output.execution`
|
|
380
|
-
| `thresholds.coverage`
|
|
381
|
-
| `thresholds.maxUnused` | `number`
|
|
382
|
-
| `report.format`
|
|
383
|
-
| `report.verbose`
|
|
384
|
-
| `report.showAll`
|
|
399
|
+
| Option | Type | Default | Description |
|
|
400
|
+
| ---------------------- | ---------- | -------------------------------- | -------------------------------- |
|
|
401
|
+
| `include` | `string[]` | `["src", "lib", "app"]` | Directories to instrument |
|
|
402
|
+
| `exclude` | `string[]` | `["node_modules", "dist", ...]` | Patterns to exclude |
|
|
403
|
+
| `extensions` | `string[]` | `[".js", ".jsx", ".ts", ".tsx"]` | File extensions to instrument |
|
|
404
|
+
| `output.inventory` | `string` | `.siko-signal.inventory.json` | Static inventory output path |
|
|
405
|
+
| `output.execution` | `string` | `.siko-signal.exec.json` | Execution data output path |
|
|
406
|
+
| `thresholds.coverage` | `number` | `undefined` | Minimum coverage % (0-100) |
|
|
407
|
+
| `thresholds.maxUnused` | `number` | `undefined` | Maximum unused functions allowed |
|
|
408
|
+
| `report.format` | `string` | `"terminal"` | Default report format |
|
|
409
|
+
| `report.verbose` | `boolean` | `false` | Show verbose output by default |
|
|
410
|
+
| `report.showAll` | `boolean` | `false` | Show all statistics by default |
|
|
385
411
|
|
|
386
412
|
---
|
|
387
413
|
|
|
@@ -390,6 +416,7 @@ Create a `siko.config.json` or `siko.config.js` file:
|
|
|
390
416
|
Use thresholds to enforce code quality standards:
|
|
391
417
|
|
|
392
418
|
**GitHub Actions Example:**
|
|
419
|
+
|
|
393
420
|
```yaml
|
|
394
421
|
name: Dead Code Check
|
|
395
422
|
|
|
@@ -402,20 +429,20 @@ jobs:
|
|
|
402
429
|
- uses: actions/checkout@v3
|
|
403
430
|
- uses: actions/setup-node@v3
|
|
404
431
|
with:
|
|
405
|
-
node-version:
|
|
406
|
-
|
|
432
|
+
node-version: "20"
|
|
433
|
+
|
|
407
434
|
- name: Install dependencies
|
|
408
435
|
run: npm ci
|
|
409
|
-
|
|
436
|
+
|
|
410
437
|
- name: Install siko
|
|
411
438
|
run: npm install -g siko
|
|
412
|
-
|
|
439
|
+
|
|
413
440
|
- name: Run tests with tracking
|
|
414
441
|
run: siko run npm test
|
|
415
|
-
|
|
442
|
+
|
|
416
443
|
- name: Check execution coverage
|
|
417
444
|
run: siko report --fail-on-threshold
|
|
418
|
-
|
|
445
|
+
|
|
419
446
|
- name: Upload runtime report
|
|
420
447
|
if: always()
|
|
421
448
|
uses: actions/upload-artifact@v3
|
|
@@ -425,6 +452,7 @@ jobs:
|
|
|
425
452
|
```
|
|
426
453
|
|
|
427
454
|
**siko.config.json:**
|
|
455
|
+
|
|
428
456
|
```json
|
|
429
457
|
{
|
|
430
458
|
"thresholds": {
|
|
@@ -441,6 +469,7 @@ If thresholds are not met, the build will fail with exit code 1.
|
|
|
441
469
|
## 📊 Example Report
|
|
442
470
|
|
|
443
471
|
### Terminal Report
|
|
472
|
+
|
|
444
473
|
```
|
|
445
474
|
📊 siko Signal Analysis Report
|
|
446
475
|
────────────────────────────────────────────────────────────
|
|
@@ -464,6 +493,7 @@ Generated by siko - Runtime Signal Analyzer
|
|
|
464
493
|
```
|
|
465
494
|
|
|
466
495
|
### JSON Report
|
|
496
|
+
|
|
467
497
|
```json
|
|
468
498
|
{
|
|
469
499
|
"summary": {
|
|
@@ -500,6 +530,7 @@ Generated by siko - Runtime Signal Analyzer
|
|
|
500
530
|
## 🔧 Real-World Examples
|
|
501
531
|
|
|
502
532
|
### Example 1: Feature Flag Detection
|
|
533
|
+
|
|
503
534
|
```javascript
|
|
504
535
|
// src/features.js
|
|
505
536
|
function newCheckout() {
|
|
@@ -511,18 +542,20 @@ function oldCheckout() {
|
|
|
511
542
|
}
|
|
512
543
|
|
|
513
544
|
// Tests only run with new feature flag
|
|
514
|
-
test(
|
|
545
|
+
test("checkout", () => {
|
|
515
546
|
newCheckout(); // Executed ✅
|
|
516
547
|
// oldCheckout never called
|
|
517
548
|
});
|
|
518
549
|
```
|
|
519
550
|
|
|
520
551
|
**siko report shows:**
|
|
552
|
+
|
|
521
553
|
```
|
|
522
554
|
❌ Unused: oldCheckout() - Safe to delete!
|
|
523
555
|
```
|
|
524
556
|
|
|
525
557
|
### Example 2: Error Path Coverage
|
|
558
|
+
|
|
526
559
|
```javascript
|
|
527
560
|
// src/api.js
|
|
528
561
|
function handleSuccess(data) {
|
|
@@ -537,18 +570,20 @@ function handleError(error) {
|
|
|
537
570
|
```
|
|
538
571
|
|
|
539
572
|
**siko report shows:**
|
|
573
|
+
|
|
540
574
|
```
|
|
541
575
|
⚠️ handleError() never executed
|
|
542
576
|
💡 Add tests for error scenarios!
|
|
543
577
|
```
|
|
544
578
|
|
|
545
579
|
### Example 3: Refactoring Confidence
|
|
580
|
+
|
|
546
581
|
```javascript
|
|
547
582
|
// After a big refactor, which old helpers are still needed?
|
|
548
|
-
function newImplementation() {
|
|
549
|
-
function oldHelper1() {
|
|
550
|
-
function oldHelper2() {
|
|
551
|
-
function stillNeeded() {
|
|
583
|
+
function newImplementation() {} // ✅ Called 50x
|
|
584
|
+
function oldHelper1() {} // ❌ Never called
|
|
585
|
+
function oldHelper2() {} // ❌ Never called
|
|
586
|
+
function stillNeeded() {} // ✅ Called 3x
|
|
552
587
|
```
|
|
553
588
|
|
|
554
589
|
**siko gives you confidence to delete `oldHelper1` and `oldHelper2`!**
|
|
@@ -558,6 +593,7 @@ function stillNeeded() { } // ✅ Called 3x
|
|
|
558
593
|
## 🆚 When to Use siko vs Static Tools
|
|
559
594
|
|
|
560
595
|
### Use **siko** when you want to:
|
|
596
|
+
|
|
561
597
|
- ✅ Find functions that **never execute** during tests
|
|
562
598
|
- ✅ Get **high-confidence** dead code detection (zero false positives)
|
|
563
599
|
- ✅ Discover **untested code paths** (error handlers, edge cases)
|
|
@@ -565,12 +601,14 @@ function stillNeeded() { } // ✅ Called 3x
|
|
|
565
601
|
- ✅ Clean up after **refactoring** (what old code is still needed?)
|
|
566
602
|
|
|
567
603
|
### Use **Knip/ts-prune** when you want to:
|
|
604
|
+
|
|
568
605
|
- ✅ Find unused **files** and **dependencies**
|
|
569
606
|
- ✅ Detect unused **exports** across modules
|
|
570
607
|
- ✅ Quick analysis **without running** code
|
|
571
608
|
- ✅ Static analysis for **build-time** optimization
|
|
572
609
|
|
|
573
610
|
### 🏆 Best Practice: Use Both!
|
|
611
|
+
|
|
574
612
|
```bash
|
|
575
613
|
# 1. Structural cleanup (static)
|
|
576
614
|
npx knip
|
|
@@ -581,6 +619,7 @@ npx siko report
|
|
|
581
619
|
```
|
|
582
620
|
|
|
583
621
|
This combination gives you **complete dead code coverage**:
|
|
622
|
+
|
|
584
623
|
- Knip removes structural waste
|
|
585
624
|
- siko removes runtime waste
|
|
586
625
|
|
|
@@ -589,11 +628,13 @@ This combination gives you **complete dead code coverage**:
|
|
|
589
628
|
## 🚀 Quick Start
|
|
590
629
|
|
|
591
630
|
### Installation
|
|
631
|
+
|
|
592
632
|
```bash
|
|
593
633
|
npm install --save-dev siko
|
|
594
634
|
```
|
|
595
635
|
|
|
596
636
|
### Basic Usage
|
|
637
|
+
|
|
597
638
|
```bash
|
|
598
639
|
# Run your tests with instrumentation
|
|
599
640
|
npx siko run npm test
|
|
@@ -618,7 +659,7 @@ A: Yes! Full support for both JavaScript and TypeScript.
|
|
|
618
659
|
A: siko is designed for development/test environments, not production monitoring.
|
|
619
660
|
|
|
620
661
|
**Q: How is this different from code coverage tools?**
|
|
621
|
-
A: Code coverage shows which
|
|
662
|
+
A: Code coverage shows which _lines_ ran. siko shows which _functions_ never ran - perfect for finding entire unused functions.
|
|
622
663
|
|
|
623
664
|
**Q: Do I need to change my code?**
|
|
624
665
|
A: No! siko instruments your code automatically - no changes needed.
|
|
@@ -637,6 +678,7 @@ A: No! siko instruments your code automatically - no changes needed.
|
|
|
637
678
|
6. **Reporting**: Shows functions that never ran
|
|
638
679
|
|
|
639
680
|
### Architecture
|
|
681
|
+
|
|
640
682
|
```
|
|
641
683
|
Source Code → Babel Instrumentation → Runtime Tracking → Signal Report
|
|
642
684
|
↓
|
|
@@ -674,6 +716,7 @@ Source Code → Babel Instrumentation → Runtime Tracking → Signal Report
|
|
|
674
716
|
We welcome contributions! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for details.
|
|
675
717
|
|
|
676
718
|
### Development
|
|
719
|
+
|
|
677
720
|
```bash
|
|
678
721
|
# Clone repository
|
|
679
722
|
git clone https://github.com/sikojs/signal.git
|
|
@@ -727,6 +770,7 @@ Currently, siko has **limited support for JSX/TSX files** due to Babel transform
|
|
|
727
770
|
**Issue**: Instrumentation can break JSX syntax in some cases, causing TypeScript compilation errors.
|
|
728
771
|
|
|
729
772
|
**Workaround for React/Next.js/JSX projects:**
|
|
773
|
+
|
|
730
774
|
```json
|
|
731
775
|
{
|
|
732
776
|
"extensions": [".js", ".ts"],
|
|
@@ -735,6 +779,7 @@ Currently, siko has **limited support for JSX/TSX files** due to Babel transform
|
|
|
735
779
|
```
|
|
736
780
|
|
|
737
781
|
Or exclude specific JSX directories:
|
|
782
|
+
|
|
738
783
|
```json
|
|
739
784
|
{
|
|
740
785
|
"exclude": ["src/components", "src/jsx"]
|
|
@@ -744,6 +789,7 @@ Or exclude specific JSX directories:
|
|
|
744
789
|
**Status**: Full JSX/TSX support is in active development for **v0.4.0**
|
|
745
790
|
|
|
746
791
|
**Current Best Use Cases** (v0.3.0):
|
|
792
|
+
|
|
747
793
|
- ✅ Node.js backends and APIs
|
|
748
794
|
- ✅ TypeScript libraries and packages
|
|
749
795
|
- ✅ JavaScript utilities and tools
|
|
@@ -758,4 +804,4 @@ Glob patterns in `exclude` (like `*.test.js`) may require full paths. Use `exten
|
|
|
758
804
|
|
|
759
805
|
**Made with ❤️ by [Mayukh Sinha](https://github.com/neu-msinha)**
|
|
760
806
|
|
|
761
|
-
|
|
807
|
+
_Runtime analysis for a cleaner codebase._
|