elit 2.0.1 → 3.0.1
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/README.md +275 -128
- package/dist/build.d.mts +10 -1
- package/dist/build.d.ts +10 -1
- package/dist/build.js +670 -1
- package/dist/build.mjs +641 -1
- package/dist/chokidar.d.mts +134 -0
- package/dist/chokidar.d.ts +134 -0
- package/dist/chokidar.js +240 -0
- package/dist/chokidar.mjs +221 -0
- package/dist/cli.js +2792 -495
- package/dist/dom.d.mts +10 -3
- package/dist/dom.d.ts +10 -3
- package/dist/dom.js +676 -1
- package/dist/dom.mjs +647 -1
- package/dist/el.d.mts +16 -36
- package/dist/el.d.ts +16 -36
- package/dist/el.js +789 -1
- package/dist/el.mjs +583 -1
- package/dist/fs.d.mts +255 -0
- package/dist/fs.d.ts +255 -0
- package/dist/fs.js +513 -0
- package/dist/fs.mjs +469 -0
- package/dist/hmr.js +112 -1
- package/dist/hmr.mjs +91 -1
- package/dist/http.d.mts +163 -0
- package/dist/http.d.ts +163 -0
- package/dist/http.js +632 -0
- package/dist/http.mjs +605 -0
- package/dist/https.d.mts +108 -0
- package/dist/https.d.ts +108 -0
- package/dist/https.js +907 -0
- package/dist/https.mjs +901 -0
- package/dist/index.d.mts +613 -33
- package/dist/index.d.ts +613 -33
- package/dist/index.js +2589 -1
- package/dist/index.mjs +2312 -1
- package/dist/mime-types.d.mts +48 -0
- package/dist/mime-types.d.ts +48 -0
- package/dist/mime-types.js +197 -0
- package/dist/mime-types.mjs +166 -0
- package/dist/path.d.mts +163 -0
- package/dist/path.d.ts +163 -0
- package/dist/path.js +350 -0
- package/dist/path.mjs +310 -0
- package/dist/router.d.mts +3 -1
- package/dist/router.d.ts +3 -1
- package/dist/router.js +830 -1
- package/dist/router.mjs +801 -1
- package/dist/runtime.d.mts +97 -0
- package/dist/runtime.d.ts +97 -0
- package/dist/runtime.js +43 -0
- package/dist/runtime.mjs +15 -0
- package/dist/server.d.mts +5 -1
- package/dist/server.d.ts +5 -1
- package/dist/server.js +3267 -1
- package/dist/server.mjs +3241 -1
- package/dist/state.d.mts +3 -1
- package/dist/state.d.ts +3 -1
- package/dist/state.js +1036 -1
- package/dist/state.mjs +992 -1
- package/dist/style.d.mts +47 -1
- package/dist/style.d.ts +47 -1
- package/dist/style.js +551 -1
- package/dist/style.mjs +483 -1
- package/dist/{types-DOAdFFJB.d.ts → types-C0nGi6MX.d.mts} +29 -13
- package/dist/{types-DOAdFFJB.d.mts → types-Du6kfwTm.d.ts} +29 -13
- package/dist/types.d.mts +452 -3
- package/dist/types.d.ts +452 -3
- package/dist/types.js +18 -1
- package/dist/ws.d.mts +195 -0
- package/dist/ws.d.ts +195 -0
- package/dist/ws.js +380 -0
- package/dist/ws.mjs +358 -0
- package/dist/wss.d.mts +108 -0
- package/dist/wss.d.ts +108 -0
- package/dist/wss.js +1306 -0
- package/dist/wss.mjs +1300 -0
- package/package.json +53 -6
- package/dist/client.d.mts +0 -9
- package/dist/client.d.ts +0 -9
- package/dist/client.js +0 -1
- package/dist/client.mjs +0 -1
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* File watcher module with unified API across runtimes
|
|
5
|
+
* Pure implementation without external dependencies
|
|
6
|
+
* Compatible with 'chokidar' package API
|
|
7
|
+
* - Node.js: uses native fs.watch
|
|
8
|
+
* - Bun: uses native fs.watch with enhancements
|
|
9
|
+
* - Deno: uses Deno.watchFs
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Watch options
|
|
14
|
+
*/
|
|
15
|
+
interface WatchOptions {
|
|
16
|
+
/**
|
|
17
|
+
* Indicates whether the process should continue to run as long as files are being watched.
|
|
18
|
+
* If set to false, the process will continue running even if the watcher is closed.
|
|
19
|
+
*/
|
|
20
|
+
persistent?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Indicates whether to watch files that don't have read permissions.
|
|
23
|
+
*/
|
|
24
|
+
ignorePermissionErrors?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* A function that takes one parameter (the path of the file/directory)
|
|
27
|
+
* and returns true to ignore or false to watch.
|
|
28
|
+
*/
|
|
29
|
+
ignored?: string | RegExp | ((path: string) => boolean);
|
|
30
|
+
/**
|
|
31
|
+
* If set to false, only the parent directory will be watched for new files.
|
|
32
|
+
*/
|
|
33
|
+
ignoreInitial?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* If set to true, symlinks will be followed.
|
|
36
|
+
*/
|
|
37
|
+
followSymlinks?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Interval of file system polling (in milliseconds).
|
|
40
|
+
*/
|
|
41
|
+
interval?: number;
|
|
42
|
+
/**
|
|
43
|
+
* Interval of file system polling for binary files (in milliseconds).
|
|
44
|
+
*/
|
|
45
|
+
binaryInterval?: number;
|
|
46
|
+
/**
|
|
47
|
+
* If set to true, will provide fs.Stats object as second argument
|
|
48
|
+
* in add, addDir, and change events.
|
|
49
|
+
*/
|
|
50
|
+
alwaysStat?: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* If set, limits how many levels of subdirectories will be traversed.
|
|
53
|
+
*/
|
|
54
|
+
depth?: number;
|
|
55
|
+
/**
|
|
56
|
+
* By default, add event fires when a file first appears on disk.
|
|
57
|
+
* Setting this will wait for the write to finish before firing.
|
|
58
|
+
*/
|
|
59
|
+
awaitWriteFinish?: boolean | {
|
|
60
|
+
stabilityThreshold?: number;
|
|
61
|
+
pollInterval?: number;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* If set to true, will use fs.watchFile() (polling) instead of fs.watch().
|
|
65
|
+
*/
|
|
66
|
+
usePolling?: boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Whether to use fsevents watching on macOS (if available).
|
|
69
|
+
*/
|
|
70
|
+
useFsEvents?: boolean;
|
|
71
|
+
/**
|
|
72
|
+
* The base path to watch.
|
|
73
|
+
*/
|
|
74
|
+
cwd?: string;
|
|
75
|
+
/**
|
|
76
|
+
* Whether to disable globbing.
|
|
77
|
+
*/
|
|
78
|
+
disableGlobbing?: boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Automatically filter out artifacts that occur when using editors.
|
|
81
|
+
*/
|
|
82
|
+
atomic?: boolean | number;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* FSWatcher class - Compatible with chokidar
|
|
86
|
+
*/
|
|
87
|
+
declare class FSWatcher extends EventEmitter {
|
|
88
|
+
private _watcher;
|
|
89
|
+
private _closed;
|
|
90
|
+
private _watched;
|
|
91
|
+
constructor(options?: WatchOptions);
|
|
92
|
+
options: WatchOptions;
|
|
93
|
+
/**
|
|
94
|
+
* Add paths to be watched
|
|
95
|
+
*/
|
|
96
|
+
add(paths: string | string[]): FSWatcher;
|
|
97
|
+
/**
|
|
98
|
+
* Stop watching paths
|
|
99
|
+
*/
|
|
100
|
+
unwatch(paths: string | string[]): FSWatcher;
|
|
101
|
+
/**
|
|
102
|
+
* Close the watcher
|
|
103
|
+
*/
|
|
104
|
+
close(): Promise<void>;
|
|
105
|
+
/**
|
|
106
|
+
* Get watched paths
|
|
107
|
+
*/
|
|
108
|
+
getWatched(): {
|
|
109
|
+
[directory: string]: string[];
|
|
110
|
+
};
|
|
111
|
+
/**
|
|
112
|
+
* Internal method to set native watcher
|
|
113
|
+
* @internal
|
|
114
|
+
*/
|
|
115
|
+
_setWatcher(watcher: any): void;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Watch files and directories
|
|
119
|
+
*/
|
|
120
|
+
declare function watch(paths: string | string[], options?: WatchOptions): FSWatcher;
|
|
121
|
+
/**
|
|
122
|
+
* Get current runtime
|
|
123
|
+
*/
|
|
124
|
+
declare function getRuntime(): 'node' | 'bun' | 'deno';
|
|
125
|
+
/**
|
|
126
|
+
* Default export
|
|
127
|
+
*/
|
|
128
|
+
declare const _default: {
|
|
129
|
+
watch: typeof watch;
|
|
130
|
+
FSWatcher: typeof FSWatcher;
|
|
131
|
+
getRuntime: typeof getRuntime;
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
export { FSWatcher, type WatchOptions, _default as default, getRuntime, watch };
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* File watcher module with unified API across runtimes
|
|
5
|
+
* Pure implementation without external dependencies
|
|
6
|
+
* Compatible with 'chokidar' package API
|
|
7
|
+
* - Node.js: uses native fs.watch
|
|
8
|
+
* - Bun: uses native fs.watch with enhancements
|
|
9
|
+
* - Deno: uses Deno.watchFs
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Watch options
|
|
14
|
+
*/
|
|
15
|
+
interface WatchOptions {
|
|
16
|
+
/**
|
|
17
|
+
* Indicates whether the process should continue to run as long as files are being watched.
|
|
18
|
+
* If set to false, the process will continue running even if the watcher is closed.
|
|
19
|
+
*/
|
|
20
|
+
persistent?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Indicates whether to watch files that don't have read permissions.
|
|
23
|
+
*/
|
|
24
|
+
ignorePermissionErrors?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* A function that takes one parameter (the path of the file/directory)
|
|
27
|
+
* and returns true to ignore or false to watch.
|
|
28
|
+
*/
|
|
29
|
+
ignored?: string | RegExp | ((path: string) => boolean);
|
|
30
|
+
/**
|
|
31
|
+
* If set to false, only the parent directory will be watched for new files.
|
|
32
|
+
*/
|
|
33
|
+
ignoreInitial?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* If set to true, symlinks will be followed.
|
|
36
|
+
*/
|
|
37
|
+
followSymlinks?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Interval of file system polling (in milliseconds).
|
|
40
|
+
*/
|
|
41
|
+
interval?: number;
|
|
42
|
+
/**
|
|
43
|
+
* Interval of file system polling for binary files (in milliseconds).
|
|
44
|
+
*/
|
|
45
|
+
binaryInterval?: number;
|
|
46
|
+
/**
|
|
47
|
+
* If set to true, will provide fs.Stats object as second argument
|
|
48
|
+
* in add, addDir, and change events.
|
|
49
|
+
*/
|
|
50
|
+
alwaysStat?: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* If set, limits how many levels of subdirectories will be traversed.
|
|
53
|
+
*/
|
|
54
|
+
depth?: number;
|
|
55
|
+
/**
|
|
56
|
+
* By default, add event fires when a file first appears on disk.
|
|
57
|
+
* Setting this will wait for the write to finish before firing.
|
|
58
|
+
*/
|
|
59
|
+
awaitWriteFinish?: boolean | {
|
|
60
|
+
stabilityThreshold?: number;
|
|
61
|
+
pollInterval?: number;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* If set to true, will use fs.watchFile() (polling) instead of fs.watch().
|
|
65
|
+
*/
|
|
66
|
+
usePolling?: boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Whether to use fsevents watching on macOS (if available).
|
|
69
|
+
*/
|
|
70
|
+
useFsEvents?: boolean;
|
|
71
|
+
/**
|
|
72
|
+
* The base path to watch.
|
|
73
|
+
*/
|
|
74
|
+
cwd?: string;
|
|
75
|
+
/**
|
|
76
|
+
* Whether to disable globbing.
|
|
77
|
+
*/
|
|
78
|
+
disableGlobbing?: boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Automatically filter out artifacts that occur when using editors.
|
|
81
|
+
*/
|
|
82
|
+
atomic?: boolean | number;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* FSWatcher class - Compatible with chokidar
|
|
86
|
+
*/
|
|
87
|
+
declare class FSWatcher extends EventEmitter {
|
|
88
|
+
private _watcher;
|
|
89
|
+
private _closed;
|
|
90
|
+
private _watched;
|
|
91
|
+
constructor(options?: WatchOptions);
|
|
92
|
+
options: WatchOptions;
|
|
93
|
+
/**
|
|
94
|
+
* Add paths to be watched
|
|
95
|
+
*/
|
|
96
|
+
add(paths: string | string[]): FSWatcher;
|
|
97
|
+
/**
|
|
98
|
+
* Stop watching paths
|
|
99
|
+
*/
|
|
100
|
+
unwatch(paths: string | string[]): FSWatcher;
|
|
101
|
+
/**
|
|
102
|
+
* Close the watcher
|
|
103
|
+
*/
|
|
104
|
+
close(): Promise<void>;
|
|
105
|
+
/**
|
|
106
|
+
* Get watched paths
|
|
107
|
+
*/
|
|
108
|
+
getWatched(): {
|
|
109
|
+
[directory: string]: string[];
|
|
110
|
+
};
|
|
111
|
+
/**
|
|
112
|
+
* Internal method to set native watcher
|
|
113
|
+
* @internal
|
|
114
|
+
*/
|
|
115
|
+
_setWatcher(watcher: any): void;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Watch files and directories
|
|
119
|
+
*/
|
|
120
|
+
declare function watch(paths: string | string[], options?: WatchOptions): FSWatcher;
|
|
121
|
+
/**
|
|
122
|
+
* Get current runtime
|
|
123
|
+
*/
|
|
124
|
+
declare function getRuntime(): 'node' | 'bun' | 'deno';
|
|
125
|
+
/**
|
|
126
|
+
* Default export
|
|
127
|
+
*/
|
|
128
|
+
declare const _default: {
|
|
129
|
+
watch: typeof watch;
|
|
130
|
+
FSWatcher: typeof FSWatcher;
|
|
131
|
+
getRuntime: typeof getRuntime;
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
export { FSWatcher, type WatchOptions, _default as default, getRuntime, watch };
|
package/dist/chokidar.js
ADDED
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/chokidar.ts
|
|
21
|
+
var chokidar_exports = {};
|
|
22
|
+
__export(chokidar_exports, {
|
|
23
|
+
FSWatcher: () => FSWatcher,
|
|
24
|
+
default: () => chokidar_default,
|
|
25
|
+
getRuntime: () => getRuntime,
|
|
26
|
+
watch: () => watch
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(chokidar_exports);
|
|
29
|
+
var import_events = require("events");
|
|
30
|
+
|
|
31
|
+
// src/runtime.ts
|
|
32
|
+
var runtime = (() => {
|
|
33
|
+
if (typeof Deno !== "undefined") return "deno";
|
|
34
|
+
if (typeof Bun !== "undefined") return "bun";
|
|
35
|
+
return "node";
|
|
36
|
+
})();
|
|
37
|
+
|
|
38
|
+
// src/chokidar.ts
|
|
39
|
+
function normalizePath(path) {
|
|
40
|
+
return path.replace(/\\/g, "/");
|
|
41
|
+
}
|
|
42
|
+
function emitEvent(watcher, eventType, path) {
|
|
43
|
+
watcher.emit(eventType, path);
|
|
44
|
+
watcher.emit("all", eventType, path);
|
|
45
|
+
}
|
|
46
|
+
function matchesAnyPattern(path, patterns) {
|
|
47
|
+
return patterns.some((pattern) => matchesPattern(path, pattern));
|
|
48
|
+
}
|
|
49
|
+
function handleRenameEvent(watcher, fullPath, fs) {
|
|
50
|
+
try {
|
|
51
|
+
fs.statSync(fullPath);
|
|
52
|
+
emitEvent(watcher, "add", fullPath);
|
|
53
|
+
} catch {
|
|
54
|
+
emitEvent(watcher, "unlink", fullPath);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function setupFsWatch(watcher, baseDir, patterns, fs) {
|
|
58
|
+
try {
|
|
59
|
+
const nativeWatcher = fs.watch(baseDir, { recursive: true }, (eventType, filename) => {
|
|
60
|
+
if (!filename) return;
|
|
61
|
+
const fullPath = normalizePath(`${baseDir}/${filename}`);
|
|
62
|
+
if (!matchesAnyPattern(fullPath, patterns)) return;
|
|
63
|
+
if (eventType === "rename") {
|
|
64
|
+
handleRenameEvent(watcher, fullPath, fs);
|
|
65
|
+
} else if (eventType === "change") {
|
|
66
|
+
emitEvent(watcher, "change", fullPath);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
watcher._setWatcher(nativeWatcher);
|
|
70
|
+
watcher["_watched"].add(baseDir);
|
|
71
|
+
queueMicrotask(() => watcher.emit("ready"));
|
|
72
|
+
} catch (error) {
|
|
73
|
+
watcher.emit("error", error);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
var FSWatcher = class extends import_events.EventEmitter {
|
|
77
|
+
constructor(options) {
|
|
78
|
+
super();
|
|
79
|
+
this._closed = false;
|
|
80
|
+
this._watched = /* @__PURE__ */ new Set();
|
|
81
|
+
this.options = options || {};
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Add paths to be watched
|
|
85
|
+
*/
|
|
86
|
+
add(paths) {
|
|
87
|
+
if (this._closed) {
|
|
88
|
+
throw new Error("Watcher has been closed");
|
|
89
|
+
}
|
|
90
|
+
const pathArray = Array.isArray(paths) ? paths : [paths];
|
|
91
|
+
if (runtime === "node") {
|
|
92
|
+
if (this._watcher) {
|
|
93
|
+
this._watcher.add(pathArray);
|
|
94
|
+
}
|
|
95
|
+
} else {
|
|
96
|
+
pathArray.forEach((path) => this._watched.add(path));
|
|
97
|
+
}
|
|
98
|
+
return this;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Stop watching paths
|
|
102
|
+
*/
|
|
103
|
+
unwatch(paths) {
|
|
104
|
+
if (this._closed) {
|
|
105
|
+
return this;
|
|
106
|
+
}
|
|
107
|
+
const pathArray = Array.isArray(paths) ? paths : [paths];
|
|
108
|
+
if (runtime === "node") {
|
|
109
|
+
if (this._watcher) {
|
|
110
|
+
this._watcher.unwatch(pathArray);
|
|
111
|
+
}
|
|
112
|
+
} else {
|
|
113
|
+
pathArray.forEach((path) => this._watched.delete(path));
|
|
114
|
+
}
|
|
115
|
+
return this;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Close the watcher
|
|
119
|
+
*/
|
|
120
|
+
async close() {
|
|
121
|
+
if (this._closed) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
this._closed = true;
|
|
125
|
+
if (runtime === "node") {
|
|
126
|
+
if (this._watcher) {
|
|
127
|
+
await this._watcher.close();
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
this.removeAllListeners();
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Get watched paths
|
|
134
|
+
*/
|
|
135
|
+
getWatched() {
|
|
136
|
+
if (runtime === "node" && this._watcher) {
|
|
137
|
+
return this._watcher.getWatched();
|
|
138
|
+
}
|
|
139
|
+
const result = {};
|
|
140
|
+
this._watched.forEach((path) => {
|
|
141
|
+
const dir = path.substring(0, path.lastIndexOf("/")) || ".";
|
|
142
|
+
const file = path.substring(path.lastIndexOf("/") + 1);
|
|
143
|
+
if (!result[dir]) {
|
|
144
|
+
result[dir] = [];
|
|
145
|
+
}
|
|
146
|
+
result[dir].push(file);
|
|
147
|
+
});
|
|
148
|
+
return result;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Internal method to set native watcher
|
|
152
|
+
* @internal
|
|
153
|
+
*/
|
|
154
|
+
_setWatcher(watcher) {
|
|
155
|
+
this._watcher = watcher;
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
function getBaseDirectory(pattern) {
|
|
159
|
+
const parts = pattern.split(/[\\\/]/);
|
|
160
|
+
let baseDir = "";
|
|
161
|
+
for (const part of parts) {
|
|
162
|
+
if (part.includes("*") || part.includes("?")) {
|
|
163
|
+
break;
|
|
164
|
+
}
|
|
165
|
+
baseDir = baseDir ? `${baseDir}/${part}` : part;
|
|
166
|
+
}
|
|
167
|
+
return baseDir || ".";
|
|
168
|
+
}
|
|
169
|
+
function matchesPattern(filePath, pattern) {
|
|
170
|
+
const regexPattern = normalizePath(pattern).replace(/\*\*/g, ".*").replace(/\*/g, "[^/]*").replace(/\?/g, ".");
|
|
171
|
+
const regex = new RegExp(`^${regexPattern}$`);
|
|
172
|
+
const normalizedPath = normalizePath(filePath);
|
|
173
|
+
return regex.test(normalizedPath);
|
|
174
|
+
}
|
|
175
|
+
function watch(paths, options) {
|
|
176
|
+
const watcher = new FSWatcher(options);
|
|
177
|
+
const pathArray = Array.isArray(paths) ? paths : [paths];
|
|
178
|
+
const watchMap = /* @__PURE__ */ new Map();
|
|
179
|
+
pathArray.forEach((path) => {
|
|
180
|
+
const baseDir = getBaseDirectory(path);
|
|
181
|
+
if (!watchMap.has(baseDir)) {
|
|
182
|
+
watchMap.set(baseDir, []);
|
|
183
|
+
}
|
|
184
|
+
watchMap.get(baseDir).push(path);
|
|
185
|
+
});
|
|
186
|
+
if (runtime === "node") {
|
|
187
|
+
const fs = require("fs");
|
|
188
|
+
watchMap.forEach((patterns, baseDir) => setupFsWatch(watcher, baseDir, patterns, fs));
|
|
189
|
+
} else if (runtime === "bun") {
|
|
190
|
+
const fs = require("fs");
|
|
191
|
+
watchMap.forEach((patterns, baseDir) => setupFsWatch(watcher, baseDir, patterns, fs));
|
|
192
|
+
} else if (runtime === "deno") {
|
|
193
|
+
const baseDirs = Array.from(watchMap.keys());
|
|
194
|
+
const allPatterns = Array.from(watchMap.values()).flat();
|
|
195
|
+
(async () => {
|
|
196
|
+
try {
|
|
197
|
+
const denoWatcher = Deno.watchFs(baseDirs);
|
|
198
|
+
for await (const event of denoWatcher) {
|
|
199
|
+
if (watcher["_closed"]) break;
|
|
200
|
+
for (const path of event.paths) {
|
|
201
|
+
const normalizedPath = normalizePath(path);
|
|
202
|
+
if (!matchesAnyPattern(normalizedPath, allPatterns)) continue;
|
|
203
|
+
switch (event.kind) {
|
|
204
|
+
case "create":
|
|
205
|
+
emitEvent(watcher, "add", path);
|
|
206
|
+
break;
|
|
207
|
+
case "modify":
|
|
208
|
+
emitEvent(watcher, "change", path);
|
|
209
|
+
break;
|
|
210
|
+
case "remove":
|
|
211
|
+
emitEvent(watcher, "unlink", path);
|
|
212
|
+
break;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
} catch (error) {
|
|
217
|
+
if (!watcher["_closed"]) {
|
|
218
|
+
watcher.emit("error", error);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
})();
|
|
222
|
+
pathArray.forEach((path) => watcher.add(path));
|
|
223
|
+
queueMicrotask(() => watcher.emit("ready"));
|
|
224
|
+
}
|
|
225
|
+
return watcher;
|
|
226
|
+
}
|
|
227
|
+
function getRuntime() {
|
|
228
|
+
return runtime;
|
|
229
|
+
}
|
|
230
|
+
var chokidar_default = {
|
|
231
|
+
watch,
|
|
232
|
+
FSWatcher,
|
|
233
|
+
getRuntime
|
|
234
|
+
};
|
|
235
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
236
|
+
0 && (module.exports = {
|
|
237
|
+
FSWatcher,
|
|
238
|
+
getRuntime,
|
|
239
|
+
watch
|
|
240
|
+
});
|