cindel 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,185 @@
1
+ /**
2
+ * HMR client with baked-in file loading, override detection, and cold file handling.
3
+ *
4
+ * @example
5
+ * // Simple setup
6
+ * const client = new HMRClient({
7
+ * port: 1338,
8
+ * skip: ['_*\/**'],
9
+ * cold: ['**\/*.cold.js'],
10
+ * onFileLoaded: (file) => swapPrototype(file)
11
+ * });
12
+ *
13
+ * @example
14
+ * // With override detection
15
+ * const client = new HMRClient({
16
+ * port: 1338,
17
+ * getOverrideTarget: (file, allFiles) => {
18
+ * const m = file.match(/^x_[^/]+\/overrides\/(.+)$/);
19
+ * if (!m) return null;
20
+ * const core = `core/${m[1]}`;
21
+ * return allFiles?.includes(core) ? core : null;
22
+ * }
23
+ * });
24
+ */
25
+ export class HMRClient {
26
+ /**
27
+ * `options` can be a shorthand or a full config object:
28
+ * - **number** treated as `{ port: n }`, connects to `ws://localhost:<n>`
29
+ * - **string** treated as a full WebSocket URL
30
+ * - **object** full config, see below
31
+ *
32
+ * @param {Object} options - setting options jsdoc to `Object` only for the sake of auto complete.
33
+ * @param {string} [options.wsUrl] - Explicit WebSocket URL. Takes priority over host/port.
34
+ * @param {string} [options.httpUrl] - Explicit HTTP base URL for fetching files. Derived from `wsUrl` if omitted.
35
+ * @param {boolean} [options.watchFiles=true] Server side file watching is enabled by default.
36
+ * @param {string} [options.host='localhost'] - Hostname (used when building from `port`)
37
+ * @param {number} [options.port] - Port number
38
+ * @param {boolean} [options.secure=false] - Use `wss://` and `https://`
39
+ * @param {boolean} [options.autoReconnect=true] - Reconnect on disconnect with exponential backoff.
40
+ * @param {number} [options.reconnectDelay=2000] - Base reconnect delay in ms
41
+ * @param {number} [options.maxReconnectDelay=30000] - Maximum reconnect delay cap in ms
42
+ * @param {string[]} [options.skip] - Glob patterns for files that should never be loaded (e.g. `['_*\/**']`)
43
+ * @param {function(string, string[]): boolean} [options.filterSkip] - Custom skip logic. Receives `(filePath, allFiles)`. Combined with `skip` via OR.
44
+ * @param {string[]} [options.cold] - Glob patterns for files that require a full page reload. Merged with the server's `cold` config on connect. A `cold` event is emitted instead of hot reloading.
45
+ * @param {function(string): boolean} [options.filterCold] - Custom cold file logic. Receives `(filePath)`. Combined with `cold` via OR.
46
+ * @param {function(string, string[]): string|null} [options.getOverrideTarget] - Given a changed file, return the path of the original it replaces, or `null`. Receives `(filePath, allFiles)`. When matched, the original is unloaded before the override loads.
47
+ * @param {function(string): void} [options.onFileLoaded] - Called after each file loads or reloads. Receives `(filePath)`.
48
+ * @param {function(string[]): string[]} [options.sortFiles] - Custom sort for the initial file load order. Default sorts CSS before JS, cold files first.
49
+ */
50
+ constructor(options: {
51
+ wsUrl?: string;
52
+ httpUrl?: string;
53
+ watchFiles?: boolean;
54
+ host?: string;
55
+ port?: number;
56
+ secure?: boolean;
57
+ autoReconnect?: boolean;
58
+ reconnectDelay?: number;
59
+ maxReconnectDelay?: number;
60
+ skip?: string[];
61
+ filterSkip?: (arg0: string, arg1: string[]) => boolean;
62
+ cold?: string[];
63
+ filterCold?: (arg0: string) => boolean;
64
+ getOverrideTarget?: (arg0: string, arg1: string[]) => string | null;
65
+ onFileLoaded?: (arg0: string) => void;
66
+ sortFiles?: (arg0: string[]) => string[];
67
+ });
68
+ wsUrl: any;
69
+ httpUrl: any;
70
+ watchFiles: boolean;
71
+ _autoReconnectDefault: boolean;
72
+ autoReconnect: boolean;
73
+ reconnectDelay: number;
74
+ maxReconnectDelay: number;
75
+ _coldPatterns: string[];
76
+ _filterCold: (arg0: string) => boolean;
77
+ shouldSkipFile: any;
78
+ isColdFile: any;
79
+ allFiles: any[];
80
+ getOverrideTarget: (arg0: string, arg1: string[]) => string | null;
81
+ onFileLoaded: (arg0: string) => void;
82
+ sortFiles: any;
83
+ socket: WebSocket;
84
+ reconnectAttempts: number;
85
+ isConnected: boolean;
86
+ eventHandlers: Map<any, any>;
87
+ _reconnectTimer: NodeJS.Timeout;
88
+ _messageQueue: any[];
89
+ _processingMessages: boolean;
90
+ fileLoader: FileLoader;
91
+ /** @type {Map<string, string>} - Maps override file -> original file */
92
+ overrideMap: Map<string, string>;
93
+ /** @type {Map<string, Set<string>>} - Maps original file -> set of active overrides */
94
+ _reverseOverrideMap: Map<string, Set<string>>;
95
+ logStyles: {
96
+ info: {
97
+ symbol: string;
98
+ color: string;
99
+ };
100
+ success: {
101
+ symbol: string;
102
+ color: string;
103
+ };
104
+ warning: {
105
+ symbol: string;
106
+ color: string;
107
+ };
108
+ error: {
109
+ symbol: string;
110
+ color: string;
111
+ };
112
+ add: {
113
+ symbol: string;
114
+ color: string;
115
+ };
116
+ remove: {
117
+ symbol: string;
118
+ color: string;
119
+ };
120
+ inject: {
121
+ symbol: string;
122
+ color: string;
123
+ };
124
+ disconnect: {
125
+ symbol: string;
126
+ color: string;
127
+ };
128
+ override: {
129
+ symbol: string;
130
+ color: string;
131
+ };
132
+ skip: {
133
+ symbol: string;
134
+ color: string;
135
+ };
136
+ cold: {
137
+ symbol: string;
138
+ color: string;
139
+ };
140
+ };
141
+ defaultSortFiles(files: any): any[];
142
+ makeFilter(patterns: any, callback: any): any;
143
+ log(type: any, message: any): void;
144
+ logInitFileGroup(files: any, overrideMap: any, isColdFile: any): void;
145
+ buildOverrideMap(files: any): any;
146
+ processInitFiles(files: any): Promise<void>;
147
+ handleFileChange(file: any, action: any, serverCold?: boolean): Promise<void>;
148
+ handleFileRemove(file: any): Promise<void>;
149
+ handleMessage(data: any): Promise<void>;
150
+ /**
151
+ * Register an event handler
152
+ * @param {'init'|'reload'|'add'|'remove'|'cold'|'connect'|'disconnect'|'error'} event - Event name
153
+ * @param {Function} handler - Event handler function
154
+ * @returns {HMRClient} This client for chaining
155
+ */
156
+ on(event: "init" | "reload" | "add" | "remove" | "cold" | "connect" | "disconnect" | "error", handler: Function): HMRClient;
157
+ /**
158
+ * Register a one-time event handler that auto-removes itself after the first call
159
+ * @param {'init'|'reload'|'add'|'remove'|'cold'|'connect'|'disconnect'|'error'} event - Event name
160
+ * @param {Function} handler - Event handler function
161
+ * @returns {HMRClient} This client for chaining
162
+ */
163
+ once(event: "init" | "reload" | "add" | "remove" | "cold" | "connect" | "disconnect" | "error", handler: Function): HMRClient;
164
+ /**
165
+ * Remove a previously registered event handler
166
+ * @param {'init'|'reload'|'add'|'remove'|'cold'|'connect'|'disconnect'|'error'} event - Event name
167
+ * @param {Function} handler - The exact handler reference passed to `on()`
168
+ * @returns {HMRClient} This client for chaining
169
+ */
170
+ off(event: "init" | "reload" | "add" | "remove" | "cold" | "connect" | "disconnect" | "error", handler: Function): HMRClient;
171
+ emit(event: any, ...args: any[]): void;
172
+ _enqueueMessage(data: any): void;
173
+ _drainMessageQueue(): Promise<void>;
174
+ /**
175
+ * Connect to the HMR server
176
+ * @returns {Promise<void>}
177
+ */
178
+ connect(): Promise<void>;
179
+ /**
180
+ * Disconnect from the HMR server and clean up
181
+ */
182
+ disconnect(): void;
183
+ }
184
+ import { FileLoader } from './file-loader.js';
185
+ //# sourceMappingURL=hmr-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hmr-client.d.ts","sourceRoot":"","sources":["../../src/client/hmr-client.js"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH;IACE;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,qBAjBG;QAAyB,KAAK,GAAtB,MAAM;QACW,OAAO,GAAxB,MAAM;QACY,UAAU,GAA5B,OAAO;QACU,IAAI,GAArB,MAAM;QACW,IAAI,GAArB,MAAM;QACY,MAAM,GAAxB,OAAO;QACW,aAAa,GAA/B,OAAO;QACU,cAAc,GAA/B,MAAM;QACW,iBAAiB,GAAlC,MAAM;QACa,IAAI,GAAvB,MAAM,EAAE;QACsC,UAAU,GAAxD,CAAS,IAAM,EAAN,MAAM,EAAE,IAAQ,EAAR,MAAM,EAAE,KAAG,OAAO;QAChB,IAAI,GA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AS,CAQrB;IAED;;;;;OAKG;IACH,YAJW,MAAM,GAAC,QAAQ,GAAC,KAAK,GAAC,QAAQ,GAAC,MAAM,GAAC,SAAS,GAAC,YAAY,GAAC,OAAO,sBAElE,SAAS,CASrB;IAED;;;;;OAKG;IACH,WAJW,MAAM,GAAC,QAAQ,GAAC,KAAK,GAAC,QAAQ,GAAC,MAAM,GAAC,SAAS,GAAC,YAAY,GAAC,OAAO,sBAElE,SAAS,CAoBrB;IAED,uCAQC;IAMD,iCAGC;IAED,oCAWC;IAED;;;OAGG;IACH,WAFa,OAAO,CAAC,IAAI,CAAC,CAuFzB;IAED;;OAEG;IACH,mBAUC;CACF;2BApnB0B,kBAAkB"}
@@ -0,0 +1,3 @@
1
+ export { FileLoader } from "./client/file-loader.js";
2
+ export { HMRClient as default, HMRClient } from "./client/hmr-client.js";
3
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.js"],"names":[],"mappings":""}