|
1 | 1 | # Lambda Doctor — Implementation Guide |
2 | 2 |
|
3 | | -Bu projenin scaffold'u hazır. Aşağıdaki sırayla implement et. |
| 3 | +Project scaffold is ready. Implement in the following order. |
4 | 4 |
|
5 | 5 | ## Implementation Order |
6 | 6 |
|
7 | 7 | ### 1. `src/analyzers/bundle-size.ts` |
8 | | -- `fast-glob` ile `node_modules/` altındaki tüm dosyaları tara |
9 | | -- @scoped paketleri doğru grupla (`@aws-sdk/client-dynamodb` → `@aws-sdk/client-dynamodb`) |
10 | | -- `fs.stat` ile dosya boyutlarını topla |
11 | | -- Top 10 en büyük dependency'yi raporla |
| 8 | +- Scan all files under `node_modules/` using `fast-glob` |
| 9 | +- Group scoped packages correctly (`@aws-sdk/client-dynamodb` → `@aws-sdk/client-dynamodb`) |
| 10 | +- Collect file sizes via `fs.stat` |
| 11 | +- Report top 10 largest dependencies |
12 | 12 | - Thresholds: >50MB critical, >10MB warning, single dep >5MB critical, >1MB warning |
13 | 13 |
|
14 | 14 | ### 2. `src/analyzers/heavy-dependencies.ts` |
15 | | -- `package.json` oku, `dependencies` ve `devDependencies` ayrıştır |
16 | | -- Her dependency'yi `known-heavy-packages.ts` ile karşılaştır |
17 | | -- typescript, ts-node gibi dev tool'ların `dependencies`'de olmasını critical olarak flag'le |
18 | | -- Match olan her paket için alternative ve estimatedSavingsMs değerlerini diagnostic'e ekle |
| 15 | +- Read `package.json`, split `dependencies` and `devDependencies` |
| 16 | +- Check each dependency against `known-heavy-packages.ts` |
| 17 | +- Flag dev tools (typescript, ts-node) in `dependencies` as critical |
| 18 | +- Add alternative and estimatedSavingsMs to each diagnostic |
19 | 19 |
|
20 | 20 | ### 3. `src/analyzers/import-analysis.ts` |
21 | | -- `fast-glob` ile `.ts`, `.js`, `.mjs` dosyalarını bul (node_modules hariç) |
22 | | -- Regex ile import/require pattern'lerini çıkar: |
| 21 | +- Find `.ts`, `.js`, `.mjs` files using `fast-glob` (excluding node_modules) |
| 22 | +- Extract import/require patterns with regex: |
23 | 23 | - ESM: `/^import\s+.*\s+from\s+['"](.+)['"]/gm` |
24 | 24 | - CJS: `/^(?:const|let|var)\s+.*=\s*require\(['"](.+)['"]\)/gm` |
25 | | -- Top-level vs function-body tespiti: satır indentation'ı 0-1 ise top-level |
26 | | -- Heavy paket top-level import'ını flag'le |
27 | | -- `import * as` pattern'ini flag'le (tree-shaking engelliyor) |
| 25 | +- Top-level vs function-body detection: line indentation 0-1 = top-level |
| 26 | +- Flag top-level imports of heavy packages |
| 27 | +- Flag `import * as` patterns (blocks tree-shaking) |
28 | 28 |
|
29 | 29 | ### 4. `src/analyzers/aws-sdk.ts` |
30 | | -- package.json'da `aws-sdk` (v2) varsa → critical |
31 | | -- `@aws-sdk/client-*` varsa → good, count et |
32 | | -- İkisi birden varsa → warning (incomplete migration) |
33 | | -- 5'ten fazla @aws-sdk client → info (çok fazla client) |
34 | | -- Source'da `@aws-sdk/client-sso` import'u → warning (Lambda'da gereksiz) |
| 30 | +- `aws-sdk` (v2) in package.json → critical |
| 31 | +- `@aws-sdk/client-*` present → good, count them |
| 32 | +- Both v2 and v3 → warning (incomplete migration) |
| 33 | +- More than 5 @aws-sdk clients → info (too many clients) |
| 34 | +- `@aws-sdk/client-sso` import in source → warning (unnecessary in Lambda) |
35 | 35 |
|
36 | 36 | ### 5. `src/analyzers/bundler-detection.ts` |
37 | | -- package.json devDependencies'de bundler var mı: esbuild, webpack, rollup, tsup, parcel |
38 | | -- Config dosyaları var mı: webpack.config.*, rollup.config.*, tsup.config.*, esbuild.config.* |
39 | | -- package.json scripts'te bundler keyword'leri var mı |
40 | | -- serverless.yml'de serverless-esbuild veya serverless-webpack var mı |
41 | | -- `"type": "module"` set mi (ESM check) |
42 | | -- Hiç bundler yoksa → critical (en büyük iyileştirme fırsatı) |
| 37 | +- Check devDependencies for bundlers: esbuild, webpack, rollup, tsup, parcel |
| 38 | +- Check for config files: webpack.config.*, rollup.config.*, tsup.config.*, esbuild.config.* |
| 39 | +- Check package.json scripts for bundler keywords |
| 40 | +- Check serverless.yml for serverless-esbuild or serverless-webpack |
| 41 | +- Check for `"type": "module"` (ESM) |
| 42 | +- No bundler found → critical (biggest optimization opportunity) |
43 | 43 |
|
44 | 44 | ### 6. `src/reporters/console.ts` |
45 | | -- chalk ile renkli output |
| 45 | +- Colored output with chalk |
46 | 46 | - Severity icon mapping: critical=🔴, warning=⚠️, info=💡 |
47 | | -- Bundle size breakdown (top dependencies tablosu) |
48 | | -- Diagnostics severity'ye göre sıralı |
49 | | -- Footer'da toplam estimated improvement |
| 47 | +- Bundle size breakdown (top dependencies table) |
| 48 | +- Diagnostics sorted by severity |
| 49 | +- Footer with total estimated improvement |
50 | 50 |
|
51 | 51 | ### 7. `src/bin/cli.ts` |
52 | | -- ora spinner göster analiz sırasında |
53 | | -- Error handling: path yoksa, package.json yoksa anlamlı hata mesajı |
54 | | -- JSON output formatı desteği |
55 | | -- Critical issue varsa exit code 1 |
| 52 | +- Show ora spinner during analysis |
| 53 | +- Error handling: meaningful messages for missing path or package.json |
| 54 | +- JSON output format support |
| 55 | +- Exit code 1 if critical issues found |
56 | 56 |
|
57 | 57 | ## Quality Standards |
58 | 58 |
|
59 | | -- Her analyzer kendi AnalyzerResult'unu döner |
60 | | -- Tüm file I/O async olmalı (fs/promises) |
61 | | -- Her diagnostic'te mutlaka: title, description, recommendation, estimatedImpactMs |
62 | | -- Hiçbir analyzer crash etmemeli — hata durumunda boş result dön, console'a warning bas |
63 | | -- Test fixtures'daki unhealthy-lambda'da en az 8 issue bulunmalı |
64 | | -- Test fixtures'daki healthy-lambda'da 0 critical issue bulunmalı |
| 59 | +- Each analyzer returns its own AnalyzerResult |
| 60 | +- All file I/O must be async (fs/promises) |
| 61 | +- Every diagnostic must have: title, description, recommendation, estimatedImpactMs |
| 62 | +- No analyzer should crash — return empty result on error, log warning to console |
| 63 | +- Test fixtures: unhealthy-lambda must have at least 8 issues |
| 64 | +- Test fixtures: healthy-lambda must have 0 critical issues |
65 | 65 |
|
66 | 66 | ## Run & Verify |
67 | 67 |
|
|
0 commit comments