Skip to content

Commit 3ec77e3

Browse files
authored
Add rake shakapacker:doctor command for configuration checks (#609)
This PR introduces a comprehensive diagnostic tool for Shakapacker configurations, addressing the increased complexity after removing peer dependencies in v9.0.0. Key Features: - Validates JavaScript transpiler dependencies (Babel, SWC, esbuild) - Checks package manager availability and lock file consistency - Verifies Node.js version compatibility (>=18.0.0) - Detects missing entry points and validates manifest.json - Checks asset compilation freshness - Validates shakapacker.yml configuration - Detects version mismatches between gem and npm package - Provides migration guidance from deprecated options - Platform-specific issue detection (Windows, CI environments) Implementation Details: - Created Shakapacker::Doctor class with modular check methods - Added nested Reporter class for formatted output - Implemented secure command execution using Open3 - Added performance optimizations with early exits and caching - Comprehensive test suite with 66 test cases - Support for all package managers (npm, yarn, pnpm, bun) Security Improvements: - Replaced backticks with Open3.capture3 for command execution - Added proper error handling for all external commands - Validated file paths before operations Impact on Users: - New installations: Helps verify correct setup after v9 migration - Existing installations: Assists in troubleshooting configuration issues - Migration from v8: Provides specific guidance on dependency changes - All users: Proactive detection of common configuration problems The doctor command is especially valuable for v9 users adapting to the new peer dependency model and SWC as the default JavaScript transpiler.
1 parent 405c2bf commit 3ec77e3

6 files changed

Lines changed: 1761 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ Changes since the last non-beta release.
5050
- Configure `private_output_path` for private server bundles
5151
- **Enhanced TypeScript definitions** ([PR 602](https://github.com/shakacode/shakapacker/pull/602) by [justin808](https://github.com/justin808))
5252
- Better IDE support and type safety
53+
- **`rake shakapacker:doctor` diagnostic command** ([PR 609](https://github.com/shakacode/shakapacker/pull/609) by [justin808](https://github.com/justin808))
54+
- Check for configuration issues and missing dependencies
55+
- Identify missing loaders that cause build errors
56+
- Particularly useful when migrating to v9 where peer dependencies are removed
57+
- Detects transpiler-specific issues based on v9 changes
5358

5459
### Changed
5560
- Configuration option renamed from `bundler` to `assets_bundler` (deprecated but supported)

lib/shakapacker.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ def ensure_log_goes_to_stdout
4444
require_relative "shakapacker/compiler"
4545
require_relative "shakapacker/commands"
4646
require_relative "shakapacker/dev_server"
47+
require_relative "shakapacker/doctor"
4748
require_relative "shakapacker/deprecation_helper"
4849

4950
require_relative "shakapacker/railtie" if defined?(Rails)

0 commit comments

Comments
 (0)