elit 3.0.0 → 3.0.2
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.
- package/dist/build.d.ts +4 -12
- package/dist/build.d.ts.map +1 -0
- package/dist/chokidar.d.ts +7 -9
- package/dist/chokidar.d.ts.map +1 -0
- package/dist/cli.d.ts +6 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +17 -4
- package/dist/config.d.ts +29 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/dom.d.ts +7 -14
- package/dist/dom.d.ts.map +1 -0
- package/dist/el.d.ts +19 -191
- package/dist/el.d.ts.map +1 -0
- package/dist/fs.d.ts +35 -35
- package/dist/fs.d.ts.map +1 -0
- package/dist/hmr.d.ts +3 -3
- package/dist/hmr.d.ts.map +1 -0
- package/dist/http.d.ts +20 -22
- package/dist/http.d.ts.map +1 -0
- package/dist/https.d.ts +12 -15
- package/dist/https.d.ts.map +1 -0
- package/dist/index.d.ts +10 -629
- package/dist/index.d.ts.map +1 -0
- package/dist/mime-types.d.ts +9 -9
- package/dist/mime-types.d.ts.map +1 -0
- package/dist/path.d.ts +22 -19
- package/dist/path.d.ts.map +1 -0
- package/dist/router.d.ts +10 -17
- package/dist/router.d.ts.map +1 -0
- package/dist/runtime.d.ts +5 -6
- package/dist/runtime.d.ts.map +1 -0
- package/dist/server.d.ts +105 -7
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +14 -2
- package/dist/server.mjs +14 -2
- package/dist/state.d.ts +21 -27
- package/dist/state.d.ts.map +1 -0
- package/dist/style.d.ts +14 -55
- package/dist/style.d.ts.map +1 -0
- package/dist/types.d.ts +26 -240
- package/dist/types.d.ts.map +1 -0
- package/dist/ws.d.ts +14 -17
- package/dist/ws.d.ts.map +1 -0
- package/dist/wss.d.ts +16 -16
- package/dist/wss.d.ts.map +1 -0
- package/package.json +3 -2
- package/src/build.ts +337 -0
- package/src/chokidar.ts +401 -0
- package/src/cli.ts +638 -0
- package/src/config.ts +205 -0
- package/src/dom.ts +817 -0
- package/src/el.ts +164 -0
- package/src/fs.ts +727 -0
- package/src/hmr.ts +137 -0
- package/src/http.ts +775 -0
- package/src/https.ts +411 -0
- package/src/index.ts +14 -0
- package/src/mime-types.ts +222 -0
- package/src/path.ts +493 -0
- package/src/router.ts +237 -0
- package/src/runtime.ts +97 -0
- package/src/server.ts +1290 -0
- package/src/state.ts +468 -0
- package/src/style.ts +524 -0
- package/{dist/types-Du6kfwTm.d.ts → src/types.ts} +58 -141
- package/src/ws.ts +506 -0
- package/src/wss.ts +241 -0
- package/dist/build.d.mts +0 -20
- package/dist/chokidar.d.mts +0 -134
- package/dist/dom.d.mts +0 -87
- package/dist/el.d.mts +0 -207
- package/dist/fs.d.mts +0 -255
- package/dist/hmr.d.mts +0 -38
- package/dist/http.d.mts +0 -163
- package/dist/https.d.mts +0 -108
- package/dist/index.d.mts +0 -629
- package/dist/mime-types.d.mts +0 -48
- package/dist/path.d.mts +0 -163
- package/dist/router.d.mts +0 -47
- package/dist/runtime.d.mts +0 -97
- package/dist/server.d.mts +0 -7
- package/dist/state.d.mts +0 -111
- package/dist/style.d.mts +0 -159
- package/dist/types-C0nGi6MX.d.mts +0 -346
- package/dist/types.d.mts +0 -452
- package/dist/ws.d.mts +0 -195
- package/dist/wss.d.mts +0 -108
package/src/chokidar.ts
ADDED
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File watcher module with unified API across runtimes
|
|
3
|
+
* Pure implementation without external dependencies
|
|
4
|
+
* Compatible with 'chokidar' package API
|
|
5
|
+
* - Node.js: uses native fs.watch
|
|
6
|
+
* - Bun: uses native fs.watch with enhancements
|
|
7
|
+
* - Deno: uses Deno.watchFs
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { EventEmitter } from 'events';
|
|
11
|
+
import { runtime } from './runtime';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Helper: Normalize path separators (eliminates duplication in path handling)
|
|
15
|
+
*/
|
|
16
|
+
function normalizePath(path: string): string {
|
|
17
|
+
return path.replace(/\\/g, '/');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Helper: Emit event and all event (eliminates duplication in event emitting)
|
|
22
|
+
*/
|
|
23
|
+
function emitEvent(watcher: FSWatcher, eventType: string, path: string): void {
|
|
24
|
+
watcher.emit(eventType, path);
|
|
25
|
+
watcher.emit('all', eventType, path);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Helper: Check if path matches any pattern (eliminates duplication in pattern matching)
|
|
30
|
+
*/
|
|
31
|
+
function matchesAnyPattern(path: string, patterns: string[]): boolean {
|
|
32
|
+
return patterns.some(pattern => matchesPattern(path, pattern));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Helper: Handle rename event (eliminates duplication in rename handling)
|
|
37
|
+
*/
|
|
38
|
+
function handleRenameEvent(watcher: FSWatcher, fullPath: string, fs: any): void {
|
|
39
|
+
try {
|
|
40
|
+
fs.statSync(fullPath);
|
|
41
|
+
emitEvent(watcher, 'add', fullPath);
|
|
42
|
+
} catch {
|
|
43
|
+
emitEvent(watcher, 'unlink', fullPath);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Helper: Setup fs.watch for Node.js/Bun (eliminates duplication in watcher setup)
|
|
49
|
+
*/
|
|
50
|
+
function setupFsWatch(
|
|
51
|
+
watcher: FSWatcher,
|
|
52
|
+
baseDir: string,
|
|
53
|
+
patterns: string[],
|
|
54
|
+
fs: any
|
|
55
|
+
): void {
|
|
56
|
+
try {
|
|
57
|
+
const nativeWatcher = fs.watch(baseDir, { recursive: true }, (eventType: string, filename: string) => {
|
|
58
|
+
if (!filename) return;
|
|
59
|
+
|
|
60
|
+
const fullPath = normalizePath(`${baseDir}/${filename}`);
|
|
61
|
+
|
|
62
|
+
// Check if the file matches any of the patterns
|
|
63
|
+
if (!matchesAnyPattern(fullPath, patterns)) return;
|
|
64
|
+
|
|
65
|
+
if (eventType === 'rename') {
|
|
66
|
+
handleRenameEvent(watcher, fullPath, fs);
|
|
67
|
+
} else if (eventType === 'change') {
|
|
68
|
+
emitEvent(watcher, 'change', fullPath);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
watcher._setWatcher(nativeWatcher);
|
|
73
|
+
// Track watched paths directly
|
|
74
|
+
watcher['_watched'].add(baseDir);
|
|
75
|
+
|
|
76
|
+
// Emit ready after a short delay
|
|
77
|
+
queueMicrotask(() => watcher.emit('ready'));
|
|
78
|
+
} catch (error) {
|
|
79
|
+
watcher.emit('error', error as Error);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Watch options
|
|
85
|
+
*/
|
|
86
|
+
export interface WatchOptions {
|
|
87
|
+
/**
|
|
88
|
+
* Indicates whether the process should continue to run as long as files are being watched.
|
|
89
|
+
* If set to false, the process will continue running even if the watcher is closed.
|
|
90
|
+
*/
|
|
91
|
+
persistent?: boolean;
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Indicates whether to watch files that don't have read permissions.
|
|
95
|
+
*/
|
|
96
|
+
ignorePermissionErrors?: boolean;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* A function that takes one parameter (the path of the file/directory)
|
|
100
|
+
* and returns true to ignore or false to watch.
|
|
101
|
+
*/
|
|
102
|
+
ignored?: string | RegExp | ((path: string) => boolean);
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* If set to false, only the parent directory will be watched for new files.
|
|
106
|
+
*/
|
|
107
|
+
ignoreInitial?: boolean;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* If set to true, symlinks will be followed.
|
|
111
|
+
*/
|
|
112
|
+
followSymlinks?: boolean;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Interval of file system polling (in milliseconds).
|
|
116
|
+
*/
|
|
117
|
+
interval?: number;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Interval of file system polling for binary files (in milliseconds).
|
|
121
|
+
*/
|
|
122
|
+
binaryInterval?: number;
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* If set to true, will provide fs.Stats object as second argument
|
|
126
|
+
* in add, addDir, and change events.
|
|
127
|
+
*/
|
|
128
|
+
alwaysStat?: boolean;
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* If set, limits how many levels of subdirectories will be traversed.
|
|
132
|
+
*/
|
|
133
|
+
depth?: number;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* By default, add event fires when a file first appears on disk.
|
|
137
|
+
* Setting this will wait for the write to finish before firing.
|
|
138
|
+
*/
|
|
139
|
+
awaitWriteFinish?: boolean | {
|
|
140
|
+
stabilityThreshold?: number;
|
|
141
|
+
pollInterval?: number;
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* If set to true, will use fs.watchFile() (polling) instead of fs.watch().
|
|
146
|
+
*/
|
|
147
|
+
usePolling?: boolean;
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Whether to use fsevents watching on macOS (if available).
|
|
151
|
+
*/
|
|
152
|
+
useFsEvents?: boolean;
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* The base path to watch.
|
|
156
|
+
*/
|
|
157
|
+
cwd?: string;
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Whether to disable globbing.
|
|
161
|
+
*/
|
|
162
|
+
disableGlobbing?: boolean;
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Automatically filter out artifacts that occur when using editors.
|
|
166
|
+
*/
|
|
167
|
+
atomic?: boolean | number;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* FSWatcher class - Compatible with chokidar
|
|
172
|
+
*/
|
|
173
|
+
export class FSWatcher extends EventEmitter {
|
|
174
|
+
private _watcher: any;
|
|
175
|
+
private _closed: boolean = false;
|
|
176
|
+
private _watched: Set<string> = new Set();
|
|
177
|
+
|
|
178
|
+
constructor(options?: WatchOptions) {
|
|
179
|
+
super();
|
|
180
|
+
this.options = options || {};
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
public options: WatchOptions;
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Add paths to be watched
|
|
187
|
+
*/
|
|
188
|
+
add(paths: string | string[]): FSWatcher {
|
|
189
|
+
if (this._closed) {
|
|
190
|
+
throw new Error('Watcher has been closed');
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const pathArray = Array.isArray(paths) ? paths : [paths];
|
|
194
|
+
|
|
195
|
+
if (runtime === 'node') {
|
|
196
|
+
if (this._watcher) {
|
|
197
|
+
this._watcher.add(pathArray);
|
|
198
|
+
}
|
|
199
|
+
} else {
|
|
200
|
+
pathArray.forEach(path => this._watched.add(path));
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return this;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Stop watching paths
|
|
208
|
+
*/
|
|
209
|
+
unwatch(paths: string | string[]): FSWatcher {
|
|
210
|
+
if (this._closed) {
|
|
211
|
+
return this;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
const pathArray = Array.isArray(paths) ? paths : [paths];
|
|
215
|
+
|
|
216
|
+
if (runtime === 'node') {
|
|
217
|
+
if (this._watcher) {
|
|
218
|
+
this._watcher.unwatch(pathArray);
|
|
219
|
+
}
|
|
220
|
+
} else {
|
|
221
|
+
pathArray.forEach(path => this._watched.delete(path));
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
return this;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Close the watcher
|
|
229
|
+
*/
|
|
230
|
+
async close(): Promise<void> {
|
|
231
|
+
if (this._closed) {
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
this._closed = true;
|
|
236
|
+
|
|
237
|
+
if (runtime === 'node') {
|
|
238
|
+
if (this._watcher) {
|
|
239
|
+
await this._watcher.close();
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
this.removeAllListeners();
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Get watched paths
|
|
248
|
+
*/
|
|
249
|
+
getWatched(): { [directory: string]: string[] } {
|
|
250
|
+
if (runtime === 'node' && this._watcher) {
|
|
251
|
+
return this._watcher.getWatched();
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
const result: { [directory: string]: string[] } = {};
|
|
255
|
+
this._watched.forEach(path => {
|
|
256
|
+
const dir = path.substring(0, path.lastIndexOf('/')) || '.';
|
|
257
|
+
const file = path.substring(path.lastIndexOf('/') + 1);
|
|
258
|
+
if (!result[dir]) {
|
|
259
|
+
result[dir] = [];
|
|
260
|
+
}
|
|
261
|
+
result[dir].push(file);
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
return result;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Internal method to set native watcher
|
|
269
|
+
* @internal
|
|
270
|
+
*/
|
|
271
|
+
_setWatcher(watcher: any): void {
|
|
272
|
+
this._watcher = watcher;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Extract base directory from glob pattern
|
|
278
|
+
* e.g., 'src/**\/*.ts' -> 'src', '**\/*.ts' -> '.'
|
|
279
|
+
*/
|
|
280
|
+
function getBaseDirectory(pattern: string): string {
|
|
281
|
+
// Remove glob patterns to get the base directory
|
|
282
|
+
const parts = pattern.split(/[\\\/]/);
|
|
283
|
+
let baseDir = '';
|
|
284
|
+
|
|
285
|
+
for (const part of parts) {
|
|
286
|
+
if (part.includes('*') || part.includes('?')) {
|
|
287
|
+
break;
|
|
288
|
+
}
|
|
289
|
+
baseDir = baseDir ? `${baseDir}/${part}` : part;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
return baseDir || '.';
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Check if a path matches a glob pattern
|
|
297
|
+
*/
|
|
298
|
+
function matchesPattern(filePath: string, pattern: string): boolean {
|
|
299
|
+
// Simple glob matching - convert pattern to regex
|
|
300
|
+
const regexPattern = normalizePath(pattern)
|
|
301
|
+
.replace(/\*\*/g, '.*')
|
|
302
|
+
.replace(/\*/g, '[^/]*')
|
|
303
|
+
.replace(/\?/g, '.');
|
|
304
|
+
|
|
305
|
+
const regex = new RegExp(`^${regexPattern}$`);
|
|
306
|
+
const normalizedPath = normalizePath(filePath);
|
|
307
|
+
|
|
308
|
+
return regex.test(normalizedPath);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* Watch files and directories
|
|
313
|
+
*/
|
|
314
|
+
export function watch(
|
|
315
|
+
paths: string | string[],
|
|
316
|
+
options?: WatchOptions
|
|
317
|
+
): FSWatcher {
|
|
318
|
+
const watcher = new FSWatcher(options);
|
|
319
|
+
const pathArray = Array.isArray(paths) ? paths : [paths];
|
|
320
|
+
|
|
321
|
+
// Extract patterns and their base directories
|
|
322
|
+
const watchMap = new Map<string, string[]>();
|
|
323
|
+
|
|
324
|
+
pathArray.forEach(path => {
|
|
325
|
+
const baseDir = getBaseDirectory(path);
|
|
326
|
+
if (!watchMap.has(baseDir)) {
|
|
327
|
+
watchMap.set(baseDir, []);
|
|
328
|
+
}
|
|
329
|
+
watchMap.get(baseDir)!.push(path);
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
if (runtime === 'node') {
|
|
333
|
+
// Node.js - use native fs.watch
|
|
334
|
+
const fs = require('fs');
|
|
335
|
+
watchMap.forEach((patterns, baseDir) => setupFsWatch(watcher, baseDir, patterns, fs));
|
|
336
|
+
} else if (runtime === 'bun') {
|
|
337
|
+
// Bun - use native fs.watch
|
|
338
|
+
const fs = require('fs');
|
|
339
|
+
watchMap.forEach((patterns, baseDir) => setupFsWatch(watcher, baseDir, patterns, fs));
|
|
340
|
+
} else if (runtime === 'deno') {
|
|
341
|
+
// Deno - use Deno.watchFs
|
|
342
|
+
// Extract just the base directories for Deno
|
|
343
|
+
const baseDirs = Array.from(watchMap.keys());
|
|
344
|
+
const allPatterns = Array.from(watchMap.values()).flat();
|
|
345
|
+
|
|
346
|
+
(async () => {
|
|
347
|
+
try {
|
|
348
|
+
// @ts-ignore
|
|
349
|
+
const denoWatcher = Deno.watchFs(baseDirs);
|
|
350
|
+
|
|
351
|
+
for await (const event of denoWatcher) {
|
|
352
|
+
if (watcher['_closed']) break;
|
|
353
|
+
|
|
354
|
+
for (const path of event.paths) {
|
|
355
|
+
const normalizedPath = normalizePath(path);
|
|
356
|
+
|
|
357
|
+
// Check if the file matches any of the patterns
|
|
358
|
+
if (!matchesAnyPattern(normalizedPath, allPatterns)) continue;
|
|
359
|
+
|
|
360
|
+
switch (event.kind) {
|
|
361
|
+
case 'create':
|
|
362
|
+
emitEvent(watcher, 'add', path);
|
|
363
|
+
break;
|
|
364
|
+
case 'modify':
|
|
365
|
+
emitEvent(watcher, 'change', path);
|
|
366
|
+
break;
|
|
367
|
+
case 'remove':
|
|
368
|
+
emitEvent(watcher, 'unlink', path);
|
|
369
|
+
break;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
} catch (error) {
|
|
374
|
+
if (!watcher['_closed']) {
|
|
375
|
+
watcher.emit('error', error as Error);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
})();
|
|
379
|
+
|
|
380
|
+
pathArray.forEach(path => watcher.add(path));
|
|
381
|
+
queueMicrotask(() => watcher.emit('ready'));
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
return watcher;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* Get current runtime
|
|
389
|
+
*/
|
|
390
|
+
export function getRuntime(): 'node' | 'bun' | 'deno' {
|
|
391
|
+
return runtime;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* Default export
|
|
396
|
+
*/
|
|
397
|
+
export default {
|
|
398
|
+
watch,
|
|
399
|
+
FSWatcher,
|
|
400
|
+
getRuntime,
|
|
401
|
+
};
|