Refactor watcher and server with improved error handling#20
Merged
Conversation
- builder.js: parallelize buildFiles with Promise.all instead of serial await - watcher.js: extract shared debounce() and afterRebuild() helpers, removing three near-duplicate debounced rebuild blocks - server.js: actually handle EADDRINUSE by listening for the server 'error' event (previous catch was dead code since listen() emits via event, not throw); also fix ReferenceError in 404 path where `url` was out of scope - commands/dev.js: drop the broken duplicate EADDRINUSE fallback and the redundant second buildFile call for single-file mode; reuse the initial build result for indexFile - constants.js: add ERROR_CODES for EADDRINUSE/ENOENT - renderer.js: drop what-style comments and inline small helpers -122 lines, same test pass count (131 pass, 2 pre-existing unrelated failures).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR refactors the file watcher and development server code to improve maintainability, reduce duplication, and enhance error handling through better abstraction and constant management.
Key Changes
Watcher Module (
watcher.js)debounceutility function to centralize debouncing logic used across multiple watchers, eliminating code duplicationafterRebuildhelper function to consolidate post-rebuild operations (onRebuild callback + WebSocket broadcast)createWebSocketServerby removing intermediate variables and consolidating error handling withERROR_CODES.PORT_IN_USEconstantwatchFilesto use the new debounce and afterRebuild utilities, creating separaterebuildPage,rebuildAll, andregenerateBarrelhandlerswatchFileto use the new debounce and afterRebuild utilitiesDev Command (
dev.js)createDevServer)watchOptsobjectServer Module (
server.js)createDevServerfor better separation of concernsEADDRINUSEerror occursERROR_CODESconstant for error code comparisonsConstants Module (
constants.js)ERROR_CODESobject to centralize Node.js error code constants (EADDRINUSE,ENOENT)Renderer Module (
renderer.js)renderChildrenhelper function to reduce duplication?.) and early returnsBuilder Module (
builder.js)buildFilesto usePromise.allfor parallel file building instead of sequential processingNotable Implementation Details
buildFilesnow happens in parallel for better performancehttps://claude.ai/code/session_01CYi7ea5Fdbr3EkhhowSfdG