[Feature] Refactor large source files exceeding 500 lines for better maintainability
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 35/100
- Loại issue
- Tái cấu trúc
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- typescript
- Lĩnh vực
- developer-experience, tooling
Hướng nghiên cứu
Bắt đầu bằng cách đọc src/common/packager.ts và kiểm tra các API công khai, các dependency cũng như ranh giới trách nhiệm tự nhiên của nó; sử dụng lệnh find/wc được liệt kê để xác nhận kích thước hiện tại của các tệp. Một lần refactor thành công sẽ xử lý các tệp theo từng bước, giữ nguyên các export công khai và hành vi, giữ các tệp được tách ra dưới 300 dòng, đồng thời duy trì hoặc cải thiện độ bao phủ kiểm thử mà không gây ra breaking changes.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Summary
Several source files in the project exceed 500-700 lines, making them difficult to maintain, test, and understand. These files could benefit from refactoring into smaller, more focused modules.
Files Over 500 Lines
705 lines: src/common/packager.ts
665 lines: src/extension/networkInspector/certificateProvider.ts
659 lines: src/extension/appLauncher.ts
553 lines: src/extension/exponent/exponentHelper.ts
505 lines: src/extension/rn-extension.ts
Problems with Large Files
- Cognitive load: Hard to understand full scope of responsibilities
- Testing complexity: Large files are harder to unit test comprehensively
- Merge conflicts: More likely when multiple contributors work on same file
- Single Responsibility Principle: Large files often have multiple concerns
- Navigation: Difficult to find specific functionality
- Refactoring risk: Changes have wider blast radius
Proposed Refactoring Strategy
Priority 1: packager.ts (705 lines)
Current responsibilities (likely):
- Packager lifecycle management
- Port management
- Status monitoring
- Output handling
- Configuration
Suggested split:
packager/PackagerManager.ts- Core packager lifecyclepackager/PackagerStatusMonitor.ts- Status checkingpackager/PackagerOutputHandler.ts- Output parsingpackager/PackagerConfiguration.ts- Config managementpackager/PackagerPortManager.ts- Port allocation/detection
Priority 2: certificateProvider.ts (665 lines)
Suggested split:
certificates/CertificateGenerator.ts- OpenSSL certificate generationcertificates/CertificateInstaller.ts- Device installation logiccertificates/CertificateStore.ts- Certificate storage/retrievalcertificates/PlatformCertificateHandler.ts- Platform-specific logic
Priority 3: appLauncher.ts (659 lines)
Suggested split:
launcher/AppLaunchCoordinator.ts- High-level orchestrationlauncher/PlatformLauncher.ts- Platform-specific launch logiclauncher/LaunchConfiguration.ts- Configuration handlinglauncher/LaunchValidator.ts- Pre-launch validation
Priority 4: exponentHelper.ts (553 lines)
Suggested split:
expo/ExpoProjectDetector.ts- Project type detectionexpo/ExpoConfigHandler.ts- app.json/eas.json handlingexpo/ExpoCommandRunner.ts- Expo CLI command executionexpo/ExpoVersionManager.ts- Expo SDK version management
Priority 5: rn-extension.ts (505 lines)
Suggested split:
extension/ExtensionActivator.ts- Activation logicextension/CommandRegistry.ts- Command registrationextension/ExtensionLifecycle.ts- Lifecycle managementextension/WorkspaceManager.ts- Workspace handling
Refactoring Principles
- Extract Classes: One class per file when possible
- Cohesive Responsibilities: Each file should have a single, clear purpose
- Preserve Interfaces: Maintain public APIs to avoid breaking changes
- Incremental Changes: Refactor one file at a time
- Test Coverage: Add/update tests for extracted modules
- Maintain Backwards Compatibility: Use facade pattern if needed
Benefits
- Improved testability: Smaller units are easier to test
- Better code organization: Clear separation of concerns
- Reduced complexity: Each file has narrower scope
- Easier maintenance: Smaller files are easier to understand
- Reduced merge conflicts: Changes touch fewer lines
- Improved reusability: Extracted modules can be reused
Implementation Approach
Phase 1: Analysis (Do not implement yet)
- Read and understand current file structure
- Identify natural boundaries and responsibilities
- Document public APIs and dependencies
- Plan extraction strategy
Phase 2: Extract Helpers
- Move static utility functions to separate files
- Extract constants and type definitions
- Create shared interfaces
Phase 3: Extract Classes
- One class per file
- Maintain original public API through index file
- Update imports
Phase 4: Reorganize
- Group related files into subdirectories
- Update import paths
- Add index files for clean imports
Example: Refactoring packager.ts
Before:
src/common/packager.ts (705 lines)
- class Packager
- class PackagerStatusIndicator
- port management functions
- output parsing utilities
After:
src/common/packager/
- index.ts (exports public API)
- PackagerManager.ts (core logic)
- PackagerStatusMonitor.ts
- PortManager.ts
- OutputHandler.ts
- types.ts (shared types)
- constants.ts
Risks and Mitigation
Risk: Breaking existing code
Mitigation: Use index.ts to maintain original export structure
Risk: Incomplete refactoring
Mitigation: One file at a time, fully tested before moving to next
Risk: Over-engineering
Mitigation: Extract only when clear responsibility boundaries exist
Success Criteria
- All extracted files are under 300 lines
- Test coverage maintained or improved
- No breaking changes to public APIs
- Clear documentation of module responsibilities
- Improved code metrics (cyclomatic complexity, etc.)
References
- Largest files: Found via
find src -name "*.ts" -exec wc -l {} \; | sort -rn - Related: Single Responsibility Principle
- Similar refactoring: Network inspector manager (already well-structured)
- Ngôn ngữ chính
- TypeScript
- Star
- 2.7k
- Fork
- 298
- Merge trung bình
- 15 giờ 2 phút
- Pull request đã merge (30 ngày)
- 28
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của microsoft/vscode-react-native
-
[Feature] Avoid duplicate error notificationsCó thể đã có người làm @erenbati đã nhận 3 ngày trước. Đang mởenhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
microsoft/vscode-react-native#2963 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Feature] Stop Expo Go installation when Quick Pick is canceledCó thể đã có người làm @erenbati đã nhận 18 ngày trước. Đang mởenhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
microsoft/vscode-react-native#2959 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement follow-up
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
microsoft/vscode-react-native#2951 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Feature] Expo Doctor output is lost when diagnostics failCó thể đã có người làm @erenbati đã nhận 18 ngày trước. Đang mởenhancement
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 72/100
microsoft/vscode-react-native#2957 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Feature] Incorrect log message when Metro process termination failsCó thể đã có người làm @erenbati đã nhận 3 ngày trước. Đang mởenhancement follow-up
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 68/100
microsoft/vscode-react-native#2952 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của microsoft/vscode-react-native
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
one-zero-eight/apply-bot#39 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
bigbluebutton/bbb-ui-components-react#108 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
Maintainer thường phản hồi trong vòng 1 ngày
-
high priority
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
CI-CMG/deep-sea-corals-exb#84 · 1 bình luận ·