@mui/internal-docs-infra
Version:
MUI Infra - internal documentation creation tools.
84 lines • 3.14 kB
text/typescript
/**
* Socket client for communicating with the TypeScript language service worker
*
* When a worker starts, it checks if another worker is already running via a socket.
* If so, it forwards requests to that worker instead of processing them locally.
*
* On Unix systems, this uses Unix domain sockets.
* On Windows, this uses named pipes (which Node.js net module supports transparently).
*/
import type { WorkerRequest, WorkerResponse } from "./worker.mjs";
/**
* Get the path to the IPC endpoint (Unix socket or Windows named pipe)
* @param socketDir - Optional custom directory for socket files (Unix only)
*/
export declare function getSocketPath(socketDir?: string): string;
/**
* Get the path to the lock file used for server election
* @param socketDir - Optional custom directory for socket files
*/
export declare function getLockPath(socketDir?: string): string;
/**
* Ensure the socket directory exists
* @param socketDir - Optional custom directory for socket files
*/
export declare function ensureSocketDir(socketDir?: string): Promise<void>;
/**
* Wait for the IPC endpoint to become available.
* On Unix: Polls the filesystem for the socket file to appear. We avoid
* `fs.watch` here because on macOS it does not reliably fire events when a
* unix domain socket file is created.
* On Windows: Polls by attempting to connect to the named pipe.
* @param socketDir - Optional custom directory for socket files (Unix only)
* @param timeoutMs - Timeout in milliseconds (default: 5000)
*/
export declare function waitForSocketFile(socketDir?: string, timeoutMs?: number): Promise<void>;
/**
* Try to acquire the server lock using proper-lockfile
* Returns true if successfully acquired (this worker should be server)
* @param socketDir - Optional custom directory for socket files
*/
export declare function tryAcquireServerLock(socketDir?: string): Promise<boolean>;
/**
* Release the server lock
*/
export declare function releaseServerLock(): Promise<void>;
/**
* Check if there's an existing worker socket file
* Note: The socket server will clean up stale sockets on startup
* @param socketDir - Optional custom directory for socket files
*/
export declare function hasExistingWorker(socketDir?: string): Promise<boolean>;
/**
* Client for communicating with an existing worker via socket
*/
export declare class SocketClient {
private socket;
private messageId;
private socketDir;
private pendingRequests;
private buffer;
constructor(socketDir?: string);
/**
* Connect to the worker socket with retry logic
*/
connect(retryCount?: number, maxRetries?: number, retryDelay?: number): Promise<void>;
/**
* Attempt to connect to the socket
*/
private attemptConnect;
/**
* Handle incoming data from socket.
* Optimized to avoid O(n²) behavior on large messages: only split the buffer
* when the incoming chunk actually contains a newline delimiter.
*/
private handleData;
/**
* Send a request to the worker
*/
sendRequest(request: WorkerRequest): Promise<WorkerResponse>;
/**
* Close the connection
*/
close(): void;
}