Improve Jqhtml_Integration.js documentation with hydration system explanation Add jqhtml-laravel integration packages for traditional Laravel projects 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
5.0 KiB
Executable File
Code Quality Support Classes
FileSanitizer - RPC Server Architecture
Overview
JavaScript sanitization uses long-running Node.js RPC server via Unix socket to avoid spawning 1000+ Node processes during manifest build.
Components
FileSanitizer.php- PHP client, manages server lifecyclejs-sanitizer-server.js- Node.js RPC server, processes batch sanitization requestsjs-sanitizer.js- Legacy single-file sanitizer (kept in/bin/for compatibility)
Server Lifecycle
- Lazy start: Server spawns on first JS file sanitization during code quality checks
- Startup: Checks for stale socket, force-kills if found, starts fresh server
- Wait: Polls socket with ping (50ms intervals, 10s max), fatal error if timeout
- Usage: All JS sanitization during checks goes through RPC
- Shutdown: Graceful shutdown when code quality checks complete (registered shutdown handler)
Socket
- Path:
storage/rsx-tmp/js-sanitizer-server.sock - Protocol: Line-delimited JSON over Unix domain socket
RPC Methods
ping→"pong"- Health checksanitize→{file: {status, sanitized, original_lines}, ...}- Batch sanitize multiple filesshutdown→ Graceful server termination
PHP API
FileSanitizer::sanitize_javascript($file_path); // Auto-starts RPC server, uses cache
FileSanitizer::start_rpc_server(); // Lazy init, auto-called
FileSanitizer::stop_rpc_server($force); // Clean shutdown
Force Parameter
stop_rpc_server($force = false):
false(default): Send shutdown command, return immediatelytrue: Send shutdown + wait + SIGTERM if needed (used for stale server cleanup)
Cache Integration
Cache checked before RPC call - only files with stale cache sent to server for sanitization. Cache directory: storage/rsx-tmp/cache/js-sanitized/
Error Handling
Server failure → fatal error (no fallback). Server must start or code quality check fails.
Sanitization Process
- Remove comments: Uses
decommentnpm package to strip comments while preserving line numbers - Replace string contents: Parses with Acorn AST parser, replaces string literal contents with spaces
- Preserve structure: Maintains line/column positions for accurate violation reporting
Performance Impact
Before RPC: 900+ Node.js process spawns during manifest build (~30-60s overhead) After RPC: Single Node.js process, reused across all sanitizations (~1-2s startup overhead)
Parallel to JS Parser
This architecture mirrors the JS parser RPC server pattern. See /app/RSpade/Core/JsParsers/CLAUDE.md for detailed RPC pattern documentation.
Js_CodeQuality_Rpc - RPC Server Architecture
Overview
JavaScript linting and this-usage analysis use a long-running Node.js RPC server via Unix socket to avoid spawning thousands of Node processes during code quality checks.
Components
Js_CodeQuality_Rpc.php- PHP client, manages server lifecyclejs-code-quality-server.js- Node.js RPC server, processes lint and this-usage analysis requests
Server Lifecycle
- Lazy start: Server spawns on first lint or analyze_this call during code quality checks
- Startup: Checks for stale socket, force-kills if found, starts fresh server
- Wait: Polls socket with ping (50ms intervals, 10s max), fatal error if timeout
- Usage: All JS linting and this-usage analysis goes through RPC
- Shutdown: Graceful shutdown when code quality checks complete (registered shutdown handler)
Socket
- Path:
storage/rsx-tmp/js-code-quality-server.sock - Protocol: Line-delimited JSON over Unix domain socket
RPC Methods
ping→"pong"- Health checklint→{file: {status, error}, ...}- Check JavaScript syntax using Babel parseranalyze_this→{file: {status, violations}, ...}- Analyze 'this' usage patterns using Acornshutdown→ Graceful server termination
PHP API
Js_CodeQuality_Rpc::lint($file_path); // Returns error array or null
Js_CodeQuality_Rpc::analyze_this($file_path); // Returns violations array
Js_CodeQuality_Rpc::start_rpc_server(); // Lazy init, auto-called
Js_CodeQuality_Rpc::stop_rpc_server($force); // Clean shutdown
Force Parameter
stop_rpc_server($force = false):
false(default): Send shutdown command, return immediatelytrue: Send shutdown + wait + SIGTERM if needed (used for stale server cleanup)
Cache Integration
Both lint and analyze_this have their own caching layers:
- Lint cache: Flag files in
storage/rsx-tmp/cache/js-lint-passed/(mtime-based) - This-usage cache: JSON files in
storage/rsx-tmp/cache/code-quality/js-this/(mtime-based)
Cache is checked before RPC call - only files with stale cache are sent to the server.
Error Handling
Server failure → fatal error for lint, silent failure for analyze_this.
Performance Impact
Before RPC: Thousands of Node.js process spawns during rsx:check (~20+ seconds on first run) After RPC: Single Node.js process, reused across all operations (~1-2s startup overhead)