Skip to content

refactor: optimize dependency tree and remove unused packages (#175)#206

Merged
kitelev merged 1 commit intomainfrom
refactor/deps-optimization
Oct 29, 2025
Merged

refactor: optimize dependency tree and remove unused packages (#175)#206
kitelev merged 1 commit intomainfrom
refactor/deps-optimization

Conversation

@kitelev
Copy link
Owner

@kitelev kitelev commented Oct 29, 2025

Summary

Completed comprehensive dependency audit and optimization to address Issue #175 (Reduce node_modules size).

Changes

Optimizations Applied

  1. Deduplication (npm dedupe)

    • Removed 3 duplicate packages
    • Added 2 packages for optimization
    • Net result: -1 package
  2. Unused Package Removal

    • ❌ Removed eslint-plugin-import (not used in eslint.config.mjs)
    • ❌ Removed eslint-plugin-prettier (not used in eslint.config.mjs)
    • Net result: -3 packages

Results

Metric Before After Change
Total size 264 MB 263 MB -1 MB (-0.4%)
Package count 904 900 -4 packages
Dependency health Multiple duplicates Clean tree ✅ Improved

Analysis Performed

  1. Size Analysis: Identified largest dependencies (eslint-plugin-obsidianmd: 34 MB, typescript: 23 MB)
  2. Depcheck: Verified truly unused dependencies (filtered false positives)
  3. Code Verification: Searched codebase to confirm actual usage patterns
  4. Transitive Dependencies: Analyzed indirect dependencies (moment via obsidian)

False Positives (Verified as REQUIRED)

Depcheck incorrectly flagged these as unused:

  • builtin-modules - used in esbuild.config.mjs:3,138
  • preact/@preact/compat - used in esbuild.config.mjs:147-149 (React alias)
  • ts-jest - used in jest.ui.config.js:15
  • jest-environment-obsidian - used in jest.ui.config.js:9,12
  • jest-environment-jsdom - used in jest.config.js:3
  • @typescript-eslint/* - used in eslint.config.mjs

Constraints Preventing Further Reduction

  1. Large Required Dependencies:

    • eslint-plugin-obsidianmd (34 MB) - Obsidian-specific linting
    • typescript (23 MB) - build toolchain
    • @babel (14 MB) - Jest ES module transformation
    • playwright-core (8.5 MB) - E2E testing
  2. Transitive Dependencies:

    • moment (5.1 MB) - required by Obsidian package (cannot remove)
  3. Essential Tooling:

    • Cannot remove testing infrastructure
    • Cannot remove build tools
    • Cannot remove linting/formatting

Documentation

Created comprehensive DEPENDENCY_OPTIMIZATION_REPORT.md with:

  • Detailed analysis methodology
  • Findings and rationale for each decision
  • Recommendations for future optimizations
  • pnpm migration evaluation (40-50% estimated savings)

Testing

All quality gates passed:

✅ Unit tests (803 tests) - PASSED
✅ UI tests - PASSED  
✅ Component tests (218 tests) - PASSED
✅ E2E tests (Docker) - PASSED
✅ Build successful - bundle: 118.6kb
✅ TypeScript compilation - PASSED
✅ Zero vulnerabilities (npm audit)

Why Target (<200 MB) Not Achieved

Initial issue estimated 367 MB, but actual size was already 264 MB (optimized by previous work).

The 1 MB savings represents maximum optimization within current npm + toolchain constraints.

To reach <200 MB would require:

  • pnpm migration (40-50% savings) - separate initiative recommended
  • or fundamental tooling changes (remove Babel, switch test frameworks)
  • or removal of Obsidian plugin dev workflow (not feasible)

Recommendations

Short Term

  • ✅ Monitor bundle size trends (already tracked in build-meta.json)
  • ✅ Audit transitive dependencies quarterly

Medium Term

  • 📋 Evaluate pnpm migration (Issue TBD - separate PR)
  • 📋 Investigate Docker layer caching for CI speedup

Long Term

  • 📋 Monitor Obsidian API updates (may reduce moment dependency)
  • 📋 Track TypeScript/ESLint/Jest major version updates

Value Delivered

While the 1 MB savings is modest, the primary value is:

  1. ✅ Improved dependency hygiene - removed unused packages
  2. ✅ Cleaner dependency tree - deduplicated packages
  3. ✅ Documented dependency rationale - clear understanding of requirements
  4. ✅ Baseline established - future optimizations measurable against this

Closes

Breaking Changes

None

Additional Notes

This PR represents pragmatic optimization within current constraints. Further size reduction requires infrastructure changes (pnpm migration) warranting separate evaluation.

Completed comprehensive dependency audit and optimization for Issue #175.

Changes:
- Deduplicated dependencies with npm dedupe (removed 3 duplicates)
- Removed unused ESLint plugins (eslint-plugin-import, eslint-plugin-prettier)
- Analyzed all dependencies with depcheck and code verification
- Documented optimization rationale and findings

Results:
- Total size: 264 MB → 263 MB (-1 MB, -0.4%)
- Package count: 904 → 900 (-4 packages)
- Dependency tree health improved
- All tests passing (100%)
- Build successful (bundle: 118.6kb)

Analysis:
- Verified all remaining dependencies as required
- Documented false positives from depcheck
- Identified constraints preventing further reduction (large required tooling)
- Created comprehensive optimization report

See DEPENDENCY_OPTIMIZATION_REPORT.md for full analysis.

Closes #175
@kitelev kitelev merged commit f7d5b5f into main Oct 29, 2025
9 checks passed
@kitelev kitelev deleted the refactor/deps-optimization branch October 29, 2025 14:40
kitelev added a commit that referenced this pull request Dec 21, 2025
Closes #1096

Add js/unused-local-variable to CodeQL SARIF filtering for main.js to
handle unused variables from bundled third-party code:
- reflect-metadata polyfills (import_reflect_metadata)
- RDF type constants (XSD_STRING3, XSD_INTEGER, XSD_DECIMAL)
- Bundler artifacts (errorInfo, depEndTime, resultFpsPercentage, pad)

These are valid bundler artifacts where not all exports from libraries
are used, but esbuild includes them for module resolution compatibility.

Also documents the filter in codeql-config.yml query-filters for
consistency with other bundled code filters.

Note: Test file alerts (#186, #206, #207) are stale - they reference
code that was already fixed in PR #924 or are intentional side-effect
imports. These will auto-dismiss on next CodeQL scan.
kitelev added a commit that referenced this pull request Dec 21, 2025
Closes #1096

Add js/unused-local-variable to CodeQL SARIF filtering for main.js to
handle unused variables from bundled third-party code:
- reflect-metadata polyfills (import_reflect_metadata)
- RDF type constants (XSD_STRING3, XSD_INTEGER, XSD_DECIMAL)
- Bundler artifacts (errorInfo, depEndTime, resultFpsPercentage, pad)

These are valid bundler artifacts where not all exports from libraries
are used, but esbuild includes them for module resolution compatibility.

Also documents the filter in codeql-config.yml query-filters for
consistency with other bundled code filters.

Note: Test file alerts (#186, #206, #207) are stale - they reference
code that was already fixed in PR #924 or are intentional side-effect
imports. These will auto-dismiss on next CodeQL scan.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

chore: Reduce node_modules size and optimize dependency tree

1 participant