@rsbuild/core 2.2.8 → 2.2.9
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/compiled/css-loader/index.js +2 -2
- package/compiled/html-rspack-plugin/htmlLoader.js +8 -17
- package/compiled/html-rspack-plugin/index.d.ts +8 -4
- package/compiled/html-rspack-plugin/index.js +61 -69
- package/compiled/html-rspack-plugin/package.json +1 -1
- package/compiled/postcss-loader/index.js +6 -6
- package/compiled/ws/index.d.ts +445 -0
- package/compiled/ws/license +21 -0
- package/compiled/ws/package.json +1 -0
- package/dist/chokidar.js +1 -1
- package/dist/client/hmr.js +1 -1
- package/dist/client/overlay.js +1 -1
- package/dist/cssUrlLoader.mjs +1 -1
- package/dist/helpers/cachedImport.d.ts +2 -0
- package/dist/http-proxy-middleware.js +4 -4
- package/dist/ignoreCssLoader.mjs +1 -1
- package/dist/index.js +1 -1
- package/dist/launch-editor-middleware.js +1 -1
- package/dist/{626.js → m.js} +76 -143
- package/dist/manifest-plugin.js +1 -1
- package/dist/memfs.js +1 -1
- package/dist/open.js +2 -2
- package/dist/r.js +7 -0
- package/dist/remapping.js +8 -3
- package/dist/rslib-runtime.js +1 -1
- package/dist/server/runner/asModule.d.ts +1 -1
- package/dist/server/runner/basic.d.ts +5 -4
- package/dist/server/runner/type.d.ts +1 -1
- package/dist/server/socketServer.d.ts +1 -1
- package/dist/sirv.js +1 -1
- package/dist/tinyglobby.js +1 -1
- package/dist/trace-mapping.js +220 -8
- package/dist/transformLoader.mjs +3 -2
- package/dist/ws.js +2 -2
- package/package.json +7 -7
- /package/dist/{252.js → c.js} +0 -0
- /package/dist/client/{307~0.js → f~0.js} +0 -0
- /package/dist/{626.js.LICENSE.txt → m.js.LICENSE.txt} +0 -0
|
@@ -0,0 +1,445 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
|
|
3
|
+
import { EventEmitter } from "events";
|
|
4
|
+
import {
|
|
5
|
+
Agent,
|
|
6
|
+
ClientRequest,
|
|
7
|
+
ClientRequestArgs,
|
|
8
|
+
IncomingMessage,
|
|
9
|
+
OutgoingHttpHeaders,
|
|
10
|
+
Server as HTTPServer,
|
|
11
|
+
} from "http";
|
|
12
|
+
import { Server as HTTPSServer } from "https";
|
|
13
|
+
import { createConnection } from "net";
|
|
14
|
+
import { Duplex, DuplexOptions } from "stream";
|
|
15
|
+
import { SecureContextOptions } from "tls";
|
|
16
|
+
import { URL } from "url";
|
|
17
|
+
import { ZlibOptions } from "zlib";
|
|
18
|
+
|
|
19
|
+
// can not get all overload of BufferConstructor['from'], need to copy all it's first arguments here
|
|
20
|
+
// https://github.com/microsoft/TypeScript/issues/32164
|
|
21
|
+
type BufferLike =
|
|
22
|
+
| string
|
|
23
|
+
| Buffer
|
|
24
|
+
| DataView
|
|
25
|
+
| number
|
|
26
|
+
| ArrayBufferView
|
|
27
|
+
| Uint8Array
|
|
28
|
+
| ArrayBuffer
|
|
29
|
+
| SharedArrayBuffer
|
|
30
|
+
| Blob
|
|
31
|
+
| readonly any[]
|
|
32
|
+
| readonly number[]
|
|
33
|
+
| { valueOf(): ArrayBuffer }
|
|
34
|
+
| { valueOf(): SharedArrayBuffer }
|
|
35
|
+
| { valueOf(): Uint8Array }
|
|
36
|
+
| { valueOf(): readonly number[] }
|
|
37
|
+
| { valueOf(): string }
|
|
38
|
+
| { [Symbol.toPrimitive](hint: string): string };
|
|
39
|
+
|
|
40
|
+
// WebSocket socket.
|
|
41
|
+
declare class WebSocket extends EventEmitter {
|
|
42
|
+
/** The connection is not yet open. */
|
|
43
|
+
static readonly CONNECTING: 0;
|
|
44
|
+
/** The connection is open and ready to communicate. */
|
|
45
|
+
static readonly OPEN: 1;
|
|
46
|
+
/** The connection is in the process of closing. */
|
|
47
|
+
static readonly CLOSING: 2;
|
|
48
|
+
/** The connection is closed. */
|
|
49
|
+
static readonly CLOSED: 3;
|
|
50
|
+
|
|
51
|
+
binaryType: "nodebuffer" | "arraybuffer" | "fragments";
|
|
52
|
+
readonly bufferedAmount: number;
|
|
53
|
+
readonly extensions: string;
|
|
54
|
+
/** Indicates whether the websocket is paused */
|
|
55
|
+
readonly isPaused: boolean;
|
|
56
|
+
readonly protocol: string;
|
|
57
|
+
/** The current state of the connection */
|
|
58
|
+
readonly readyState:
|
|
59
|
+
| typeof WebSocket.CONNECTING
|
|
60
|
+
| typeof WebSocket.OPEN
|
|
61
|
+
| typeof WebSocket.CLOSING
|
|
62
|
+
| typeof WebSocket.CLOSED;
|
|
63
|
+
readonly url: string;
|
|
64
|
+
|
|
65
|
+
/** The connection is not yet open. */
|
|
66
|
+
readonly CONNECTING: 0;
|
|
67
|
+
/** The connection is open and ready to communicate. */
|
|
68
|
+
readonly OPEN: 1;
|
|
69
|
+
/** The connection is in the process of closing. */
|
|
70
|
+
readonly CLOSING: 2;
|
|
71
|
+
/** The connection is closed. */
|
|
72
|
+
readonly CLOSED: 3;
|
|
73
|
+
|
|
74
|
+
onopen: ((event: WebSocket.Event) => void) | null;
|
|
75
|
+
onerror: ((event: WebSocket.ErrorEvent) => void) | null;
|
|
76
|
+
onclose: ((event: WebSocket.CloseEvent) => void) | null;
|
|
77
|
+
onmessage: ((event: WebSocket.MessageEvent) => void) | null;
|
|
78
|
+
|
|
79
|
+
constructor(address: null);
|
|
80
|
+
constructor(address: string | URL, options?: WebSocket.ClientOptions | ClientRequestArgs);
|
|
81
|
+
constructor(
|
|
82
|
+
address: string | URL,
|
|
83
|
+
protocols?: string | string[],
|
|
84
|
+
options?: WebSocket.ClientOptions | ClientRequestArgs,
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
close(code?: number, data?: string | Buffer): void;
|
|
88
|
+
ping(data?: any, mask?: boolean, cb?: (err: Error) => void): void;
|
|
89
|
+
pong(data?: any, mask?: boolean, cb?: (err: Error) => void): void;
|
|
90
|
+
// https://github.com/websockets/ws/issues/2076#issuecomment-1250354722
|
|
91
|
+
send(data: BufferLike, cb?: (err?: Error) => void): void;
|
|
92
|
+
send(
|
|
93
|
+
data: BufferLike,
|
|
94
|
+
options: {
|
|
95
|
+
mask?: boolean | undefined;
|
|
96
|
+
binary?: boolean | undefined;
|
|
97
|
+
compress?: boolean | undefined;
|
|
98
|
+
fin?: boolean | undefined;
|
|
99
|
+
},
|
|
100
|
+
cb?: (err?: Error) => void,
|
|
101
|
+
): void;
|
|
102
|
+
terminate(): void;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Pause the websocket causing it to stop emitting events. Some events can still be
|
|
106
|
+
* emitted after this is called, until all buffered data is consumed. This method
|
|
107
|
+
* is a noop if the ready state is `CONNECTING` or `CLOSED`.
|
|
108
|
+
*/
|
|
109
|
+
pause(): void;
|
|
110
|
+
/**
|
|
111
|
+
* Make a paused socket resume emitting events. This method is a noop if the ready
|
|
112
|
+
* state is `CONNECTING` or `CLOSED`.
|
|
113
|
+
*/
|
|
114
|
+
resume(): void;
|
|
115
|
+
|
|
116
|
+
// HTML5 WebSocket events
|
|
117
|
+
addEventListener<K extends keyof WebSocket.WebSocketEventMap>(
|
|
118
|
+
type: K,
|
|
119
|
+
listener:
|
|
120
|
+
| ((event: WebSocket.WebSocketEventMap[K]) => void)
|
|
121
|
+
| { handleEvent(event: WebSocket.WebSocketEventMap[K]): void },
|
|
122
|
+
options?: WebSocket.EventListenerOptions,
|
|
123
|
+
): void;
|
|
124
|
+
removeEventListener<K extends keyof WebSocket.WebSocketEventMap>(
|
|
125
|
+
type: K,
|
|
126
|
+
listener:
|
|
127
|
+
| ((event: WebSocket.WebSocketEventMap[K]) => void)
|
|
128
|
+
| { handleEvent(event: WebSocket.WebSocketEventMap[K]): void },
|
|
129
|
+
): void;
|
|
130
|
+
|
|
131
|
+
// Events
|
|
132
|
+
on(event: "close", listener: (this: WebSocket, code: number, reason: Buffer) => void): this;
|
|
133
|
+
on(event: "error", listener: (this: WebSocket, error: Error) => void): this;
|
|
134
|
+
on(event: "upgrade", listener: (this: WebSocket, request: IncomingMessage) => void): this;
|
|
135
|
+
on(event: "message", listener: (this: WebSocket, data: WebSocket.RawData, isBinary: boolean) => void): this;
|
|
136
|
+
on(event: "open", listener: (this: WebSocket) => void): this;
|
|
137
|
+
on(event: "ping" | "pong", listener: (this: WebSocket, data: Buffer) => void): this;
|
|
138
|
+
on(event: "redirect", listener: (this: WebSocket, url: string, request: ClientRequest) => void): this;
|
|
139
|
+
on(
|
|
140
|
+
event: "unexpected-response",
|
|
141
|
+
listener: (this: WebSocket, request: ClientRequest, response: IncomingMessage) => void,
|
|
142
|
+
): this;
|
|
143
|
+
on(event: string | symbol, listener: (this: WebSocket, ...args: any[]) => void): this;
|
|
144
|
+
|
|
145
|
+
once(event: "close", listener: (this: WebSocket, code: number, reason: Buffer) => void): this;
|
|
146
|
+
once(event: "error", listener: (this: WebSocket, error: Error) => void): this;
|
|
147
|
+
once(event: "upgrade", listener: (this: WebSocket, request: IncomingMessage) => void): this;
|
|
148
|
+
once(event: "message", listener: (this: WebSocket, data: WebSocket.RawData, isBinary: boolean) => void): this;
|
|
149
|
+
once(event: "open", listener: (this: WebSocket) => void): this;
|
|
150
|
+
once(event: "ping" | "pong", listener: (this: WebSocket, data: Buffer) => void): this;
|
|
151
|
+
once(event: "redirect", listener: (this: WebSocket, url: string, request: ClientRequest) => void): this;
|
|
152
|
+
once(
|
|
153
|
+
event: "unexpected-response",
|
|
154
|
+
listener: (this: WebSocket, request: ClientRequest, response: IncomingMessage) => void,
|
|
155
|
+
): this;
|
|
156
|
+
once(event: string | symbol, listener: (this: WebSocket, ...args: any[]) => void): this;
|
|
157
|
+
|
|
158
|
+
off(event: "close", listener: (this: WebSocket, code: number, reason: Buffer) => void): this;
|
|
159
|
+
off(event: "error", listener: (this: WebSocket, error: Error) => void): this;
|
|
160
|
+
off(event: "upgrade", listener: (this: WebSocket, request: IncomingMessage) => void): this;
|
|
161
|
+
off(event: "message", listener: (this: WebSocket, data: WebSocket.RawData, isBinary: boolean) => void): this;
|
|
162
|
+
off(event: "open", listener: (this: WebSocket) => void): this;
|
|
163
|
+
off(event: "ping" | "pong", listener: (this: WebSocket, data: Buffer) => void): this;
|
|
164
|
+
off(event: "redirect", listener: (this: WebSocket, url: string, request: ClientRequest) => void): this;
|
|
165
|
+
off(
|
|
166
|
+
event: "unexpected-response",
|
|
167
|
+
listener: (this: WebSocket, request: ClientRequest, response: IncomingMessage) => void,
|
|
168
|
+
): this;
|
|
169
|
+
off(event: string | symbol, listener: (this: WebSocket, ...args: any[]) => void): this;
|
|
170
|
+
|
|
171
|
+
addListener(event: "close", listener: (code: number, reason: Buffer) => void): this;
|
|
172
|
+
addListener(event: "error", listener: (error: Error) => void): this;
|
|
173
|
+
addListener(event: "upgrade", listener: (request: IncomingMessage) => void): this;
|
|
174
|
+
addListener(event: "message", listener: (data: WebSocket.RawData, isBinary: boolean) => void): this;
|
|
175
|
+
addListener(event: "open", listener: () => void): this;
|
|
176
|
+
addListener(event: "ping" | "pong", listener: (data: Buffer) => void): this;
|
|
177
|
+
addListener(event: "redirect", listener: (url: string, request: ClientRequest) => void): this;
|
|
178
|
+
addListener(
|
|
179
|
+
event: "unexpected-response",
|
|
180
|
+
listener: (request: ClientRequest, response: IncomingMessage) => void,
|
|
181
|
+
): this;
|
|
182
|
+
addListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
183
|
+
|
|
184
|
+
removeListener(event: "close", listener: (code: number, reason: Buffer) => void): this;
|
|
185
|
+
removeListener(event: "error", listener: (error: Error) => void): this;
|
|
186
|
+
removeListener(event: "upgrade", listener: (request: IncomingMessage) => void): this;
|
|
187
|
+
removeListener(event: "message", listener: (data: WebSocket.RawData, isBinary: boolean) => void): this;
|
|
188
|
+
removeListener(event: "open", listener: () => void): this;
|
|
189
|
+
removeListener(event: "ping" | "pong", listener: (data: Buffer) => void): this;
|
|
190
|
+
removeListener(event: "redirect", listener: (url: string, request: ClientRequest) => void): this;
|
|
191
|
+
removeListener(
|
|
192
|
+
event: "unexpected-response",
|
|
193
|
+
listener: (request: ClientRequest, response: IncomingMessage) => void,
|
|
194
|
+
): this;
|
|
195
|
+
removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
declare const WebSocketAlias: typeof WebSocket;
|
|
199
|
+
interface WebSocketAlias extends WebSocket {} // eslint-disable-line @typescript-eslint/no-empty-interface
|
|
200
|
+
|
|
201
|
+
declare namespace WebSocket {
|
|
202
|
+
/**
|
|
203
|
+
* Data represents the raw message payload received over the WebSocket.
|
|
204
|
+
*/
|
|
205
|
+
type RawData = Buffer | ArrayBuffer | Buffer[];
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Data represents the message payload received over the WebSocket.
|
|
209
|
+
*/
|
|
210
|
+
type Data = string | Buffer | ArrayBuffer | Buffer[];
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* CertMeta represents the accepted types for certificate & key data.
|
|
214
|
+
*/
|
|
215
|
+
type CertMeta = string | string[] | Buffer | Buffer[];
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* VerifyClientCallbackSync is a synchronous callback used to inspect the
|
|
219
|
+
* incoming message. The return value (boolean) of the function determines
|
|
220
|
+
* whether or not to accept the handshake.
|
|
221
|
+
*/
|
|
222
|
+
type VerifyClientCallbackSync<Request extends IncomingMessage = IncomingMessage> = (info: {
|
|
223
|
+
origin: string;
|
|
224
|
+
secure: boolean;
|
|
225
|
+
req: Request;
|
|
226
|
+
}) => boolean;
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* VerifyClientCallbackAsync is an asynchronous callback used to inspect the
|
|
230
|
+
* incoming message. The return value (boolean) of the function determines
|
|
231
|
+
* whether or not to accept the handshake.
|
|
232
|
+
*/
|
|
233
|
+
type VerifyClientCallbackAsync<Request extends IncomingMessage = IncomingMessage> = (
|
|
234
|
+
info: { origin: string; secure: boolean; req: Request },
|
|
235
|
+
callback: (res: boolean, code?: number, message?: string, headers?: OutgoingHttpHeaders) => void,
|
|
236
|
+
) => void;
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* FinishRequestCallback is a callback for last minute customization of the
|
|
240
|
+
* headers. If finishRequest is set, then it has the responsibility to call
|
|
241
|
+
* request.end() once it is done setting request headers.
|
|
242
|
+
*/
|
|
243
|
+
type FinishRequestCallback = (request: ClientRequest, websocket: WebSocket) => void;
|
|
244
|
+
|
|
245
|
+
interface ClientOptions extends SecureContextOptions {
|
|
246
|
+
protocol?: string | undefined;
|
|
247
|
+
followRedirects?: boolean | undefined;
|
|
248
|
+
generateMask?(mask: Buffer): void;
|
|
249
|
+
handshakeTimeout?: number | undefined;
|
|
250
|
+
maxRedirects?: number | undefined;
|
|
251
|
+
perMessageDeflate?: boolean | PerMessageDeflateOptions | undefined;
|
|
252
|
+
localAddress?: string | undefined;
|
|
253
|
+
protocolVersion?: number | undefined;
|
|
254
|
+
headers?: { [key: string]: string } | undefined;
|
|
255
|
+
origin?: string | undefined;
|
|
256
|
+
agent?: Agent | undefined;
|
|
257
|
+
host?: string | undefined;
|
|
258
|
+
family?: number | undefined;
|
|
259
|
+
checkServerIdentity?(servername: string, cert: CertMeta): boolean;
|
|
260
|
+
rejectUnauthorized?: boolean | undefined;
|
|
261
|
+
allowSynchronousEvents?: boolean | undefined;
|
|
262
|
+
autoPong?: boolean | undefined;
|
|
263
|
+
maxPayload?: number | undefined;
|
|
264
|
+
skipUTF8Validation?: boolean | undefined;
|
|
265
|
+
createConnection?: typeof createConnection | undefined;
|
|
266
|
+
finishRequest?: FinishRequestCallback | undefined;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
interface PerMessageDeflateOptions {
|
|
270
|
+
serverNoContextTakeover?: boolean | undefined;
|
|
271
|
+
clientNoContextTakeover?: boolean | undefined;
|
|
272
|
+
serverMaxWindowBits?: number | undefined;
|
|
273
|
+
clientMaxWindowBits?: number | undefined;
|
|
274
|
+
zlibDeflateOptions?: {
|
|
275
|
+
flush?: number | undefined;
|
|
276
|
+
finishFlush?: number | undefined;
|
|
277
|
+
chunkSize?: number | undefined;
|
|
278
|
+
windowBits?: number | undefined;
|
|
279
|
+
level?: number | undefined;
|
|
280
|
+
memLevel?: number | undefined;
|
|
281
|
+
strategy?: number | undefined;
|
|
282
|
+
dictionary?: Buffer | Buffer[] | DataView | undefined;
|
|
283
|
+
info?: boolean | undefined;
|
|
284
|
+
} | undefined;
|
|
285
|
+
zlibInflateOptions?: ZlibOptions | undefined;
|
|
286
|
+
threshold?: number | undefined;
|
|
287
|
+
concurrencyLimit?: number | undefined;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
interface Event {
|
|
291
|
+
type: string;
|
|
292
|
+
target: WebSocket;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
interface ErrorEvent {
|
|
296
|
+
error: any;
|
|
297
|
+
message: string;
|
|
298
|
+
type: string;
|
|
299
|
+
target: WebSocket;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
interface CloseEvent {
|
|
303
|
+
wasClean: boolean;
|
|
304
|
+
code: number;
|
|
305
|
+
reason: string;
|
|
306
|
+
type: string;
|
|
307
|
+
target: WebSocket;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
interface MessageEvent {
|
|
311
|
+
data: Data;
|
|
312
|
+
type: string;
|
|
313
|
+
target: WebSocket;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
interface WebSocketEventMap {
|
|
317
|
+
open: Event;
|
|
318
|
+
error: ErrorEvent;
|
|
319
|
+
close: CloseEvent;
|
|
320
|
+
message: MessageEvent;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
interface EventListenerOptions {
|
|
324
|
+
once?: boolean | undefined;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
interface ServerOptions<
|
|
328
|
+
U extends typeof WebSocket.WebSocket = typeof WebSocket.WebSocket,
|
|
329
|
+
V extends typeof IncomingMessage = typeof IncomingMessage,
|
|
330
|
+
> {
|
|
331
|
+
host?: string | undefined;
|
|
332
|
+
port?: number | undefined;
|
|
333
|
+
backlog?: number | undefined;
|
|
334
|
+
server?: HTTPServer<V> | HTTPSServer<V> | undefined;
|
|
335
|
+
verifyClient?:
|
|
336
|
+
| VerifyClientCallbackAsync<InstanceType<V>>
|
|
337
|
+
| VerifyClientCallbackSync<InstanceType<V>>
|
|
338
|
+
| undefined;
|
|
339
|
+
handleProtocols?: (protocols: Set<string>, request: InstanceType<V>) => string | false;
|
|
340
|
+
path?: string | undefined;
|
|
341
|
+
noServer?: boolean | undefined;
|
|
342
|
+
allowSynchronousEvents?: boolean | undefined;
|
|
343
|
+
autoPong?: boolean | undefined;
|
|
344
|
+
clientTracking?: boolean | undefined;
|
|
345
|
+
perMessageDeflate?: boolean | PerMessageDeflateOptions | undefined;
|
|
346
|
+
maxPayload?: number | undefined;
|
|
347
|
+
skipUTF8Validation?: boolean | undefined;
|
|
348
|
+
WebSocket?: U | undefined;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
interface AddressInfo {
|
|
352
|
+
address: string;
|
|
353
|
+
family: string;
|
|
354
|
+
port: number;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
// WebSocket Server
|
|
358
|
+
class Server<
|
|
359
|
+
T extends typeof WebSocket.WebSocket = typeof WebSocket.WebSocket,
|
|
360
|
+
U extends typeof IncomingMessage = typeof IncomingMessage,
|
|
361
|
+
> extends EventEmitter {
|
|
362
|
+
options: ServerOptions<T, U>;
|
|
363
|
+
path: string;
|
|
364
|
+
clients: Set<InstanceType<T>>;
|
|
365
|
+
|
|
366
|
+
constructor(options?: ServerOptions<T, U>, callback?: () => void);
|
|
367
|
+
|
|
368
|
+
address(): AddressInfo | string | null;
|
|
369
|
+
close(cb?: (err?: Error) => void): void;
|
|
370
|
+
handleUpgrade(
|
|
371
|
+
request: InstanceType<U>,
|
|
372
|
+
socket: Duplex,
|
|
373
|
+
upgradeHead: Buffer,
|
|
374
|
+
callback: (client: InstanceType<T>, request: InstanceType<U>) => void,
|
|
375
|
+
): void;
|
|
376
|
+
shouldHandle(request: InstanceType<U>): boolean | Promise<boolean>;
|
|
377
|
+
|
|
378
|
+
// Events
|
|
379
|
+
on(
|
|
380
|
+
event: "connection",
|
|
381
|
+
cb: (this: Server<T>, websocket: InstanceType<T>, request: InstanceType<U>) => void,
|
|
382
|
+
): this;
|
|
383
|
+
on(event: "error", cb: (this: Server<T>, error: Error) => void): this;
|
|
384
|
+
on(event: "headers", cb: (this: Server<T>, headers: string[], request: InstanceType<U>) => void): this;
|
|
385
|
+
on(event: "close" | "listening", cb: (this: Server<T>) => void): this;
|
|
386
|
+
on(
|
|
387
|
+
event: "wsClientError",
|
|
388
|
+
cb: (this: Server<T>, error: Error, socket: Duplex, request: InstanceType<U>) => void,
|
|
389
|
+
): this;
|
|
390
|
+
on(event: string | symbol, listener: (this: Server<T>, ...args: any[]) => void): this;
|
|
391
|
+
|
|
392
|
+
once(
|
|
393
|
+
event: "connection",
|
|
394
|
+
cb: (this: Server<T>, websocket: InstanceType<T>, request: InstanceType<U>) => void,
|
|
395
|
+
): this;
|
|
396
|
+
once(event: "error", cb: (this: Server<T>, error: Error) => void): this;
|
|
397
|
+
once(event: "headers", cb: (this: Server<T>, headers: string[], request: InstanceType<U>) => void): this;
|
|
398
|
+
once(event: "close" | "listening", cb: (this: Server<T>) => void): this;
|
|
399
|
+
once(
|
|
400
|
+
event: "wsClientError",
|
|
401
|
+
cb: (this: Server<T>, error: Error, socket: Duplex, request: InstanceType<U>) => void,
|
|
402
|
+
): this;
|
|
403
|
+
once(event: string | symbol, listener: (this: Server<T>, ...args: any[]) => void): this;
|
|
404
|
+
|
|
405
|
+
off(
|
|
406
|
+
event: "connection",
|
|
407
|
+
cb: (this: Server<T>, socket: InstanceType<T>, request: InstanceType<U>) => void,
|
|
408
|
+
): this;
|
|
409
|
+
off(event: "error", cb: (this: Server<T>, error: Error) => void): this;
|
|
410
|
+
off(event: "headers", cb: (this: Server<T>, headers: string[], request: InstanceType<U>) => void): this;
|
|
411
|
+
off(event: "close" | "listening", cb: (this: Server<T>) => void): this;
|
|
412
|
+
off(
|
|
413
|
+
event: "wsClientError",
|
|
414
|
+
cb: (this: Server<T>, error: Error, socket: Duplex, request: InstanceType<U>) => void,
|
|
415
|
+
): this;
|
|
416
|
+
off(event: string | symbol, listener: (this: Server<T>, ...args: any[]) => void): this;
|
|
417
|
+
|
|
418
|
+
addListener(event: "connection", cb: (websocket: InstanceType<T>, request: InstanceType<U>) => void): this;
|
|
419
|
+
addListener(event: "error", cb: (error: Error) => void): this;
|
|
420
|
+
addListener(event: "headers", cb: (headers: string[], request: InstanceType<U>) => void): this;
|
|
421
|
+
addListener(event: "close" | "listening", cb: () => void): this;
|
|
422
|
+
addListener(event: "wsClientError", cb: (error: Error, socket: Duplex, request: InstanceType<U>) => void): this;
|
|
423
|
+
addListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
424
|
+
|
|
425
|
+
removeListener(event: "connection", cb: (websocket: InstanceType<T>, request: InstanceType<U>) => void): this;
|
|
426
|
+
removeListener(event: "error", cb: (error: Error) => void): this;
|
|
427
|
+
removeListener(event: "headers", cb: (headers: string[], request: InstanceType<U>) => void): this;
|
|
428
|
+
removeListener(event: "close" | "listening", cb: () => void): this;
|
|
429
|
+
removeListener(
|
|
430
|
+
event: "wsClientError",
|
|
431
|
+
cb: (error: Error, socket: Duplex, request: InstanceType<U>) => void,
|
|
432
|
+
): this;
|
|
433
|
+
removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
const WebSocketServer: typeof Server;
|
|
437
|
+
interface WebSocketServer extends Server {} // eslint-disable-line @typescript-eslint/no-empty-interface
|
|
438
|
+
const WebSocket: typeof WebSocketAlias;
|
|
439
|
+
interface WebSocket extends WebSocketAlias {} // eslint-disable-line @typescript-eslint/no-empty-interface
|
|
440
|
+
|
|
441
|
+
// WebSocket stream
|
|
442
|
+
function createWebSocketStream(websocket: WebSocket, options?: DuplexOptions): Duplex;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
export = WebSocket;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Microsoft Corporation.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"name":"ws","version":"8.18.1","license":"MIT","types":"index.d.ts","type":"commonjs"}
|
package/dist/chokidar.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/*! LICENSE: chokidar.js.LICENSE.txt */
|
|
2
|
-
import{EventEmitter as t}from"node:events";import{stat as e,unwatchFile as i,watch as s,watchFile as r}from"node:fs";import{lstat as a,open as h,readdir as n,realpath as o,stat as l}from"node:fs/promises";import{join as d,relative as c,resolve as f,sep as m}from"node:path";import{Readable as p}from"node:stream";import{type as _}from"node:os";import*as u from"node:path";let w="files",g="directories",y="files_directories",v={root:".",fileFilter:t=>!0,directoryFilter:t=>!0,type:w,lstat:!1,depth:0x80000000,alwaysStat:!1,highWaterMark:4096};Object.freeze(v);let P="READDIRP_RECURSIVE_ERROR",b=new Set(["ENOENT","EPERM","EACCES","ELOOP",P]),E=[g,"all",y,w],x=new Set([g,"all",y]),k=new Set(["all",y,w]),W="win32"===process.platform,D=t=>!0,F=t=>{if(void 0===t)return D;if("function"==typeof t)return t;if("string"==typeof t){let e=t.trim();return t=>t.basename===e}if(Array.isArray(t)){let e=t.map(t=>t.trim());return t=>e.some(e=>t.basename===e)}return D};class S extends p{parents;reading;parent;_stat;_maxDepth;_wantsDir;_wantsFile;_wantsEverything;_root;_isDirent;_statsProp;_rdOptions;_fileFilter;_directoryFilter;constructor(t={}){super({objectMode:!0,autoDestroy:!0,highWaterMark:t.highWaterMark});let e={...v,...t},{root:i,type:s}=e;this._fileFilter=F(e.fileFilter),this._directoryFilter=F(e.directoryFilter);let r=e.lstat?a:l;W?this._stat=t=>r(t,{bigint:!0}):this._stat=r,this._maxDepth=null!=e.depth&&Number.isSafeInteger(e.depth)?e.depth:v.depth,this._wantsDir=!!s&&x.has(s),this._wantsFile=!!s&&k.has(s),this._wantsEverything="all"===s,this._root=f(i),this._isDirent=!e.alwaysStat,this._statsProp=this._isDirent?"dirent":"stats",this._rdOptions={encoding:"utf8",withFileTypes:this._isDirent},this.parents=[this._exploreDir(i,1)],this.reading=!1,this.parent=void 0}async _read(t){if(!this.reading){this.reading=!0;try{for(;!this.destroyed&&t>0;){let e=this.parent,i=e&&e.files;if(i&&i.length>0){let{path:s,depth:r}=e,a=i.splice(0,t).map(t=>this._formatEntry(t,s));for(let e of(await Promise.all(a))){if(!e)continue;if(this.destroyed)return;let i=await this._getEntryType(e);"directory"===i&&this._directoryFilter(e)?(r<=this._maxDepth&&this.parents.push(this._exploreDir(e.fullPath,r+1)),this._wantsDir&&(this.push(e),t--)):("file"===i||this._includeAsFile(e))&&this._fileFilter(e)&&this._wantsFile&&(this.push(e),t--)}}else{let t=this.parents.pop();if(!t){this.push(null);break}if(this.parent=await t,this.destroyed)return}}}catch(t){this.destroy(t)}finally{this.reading=!1}}}async _exploreDir(t,e){let i;try{i=await n(t,this._rdOptions)}catch(t){this._onError(t)}return{files:i,depth:e,path:t}}async _formatEntry(t,e){let i,s=this._isDirent?t.name:t;try{let r=f(d(e,s));(i={path:c(this._root,r),fullPath:r,basename:s})[this._statsProp]=this._isDirent?t:await this._stat(r)}catch(t){this._onError(t);return}return i}_onError(t){b.has(t.code)&&!this.destroyed?this.emit("warn",t):this.destroy(t)}async _getEntryType(t){if(!t&&this._statsProp in t)return"";let e=t[this._statsProp];if(e.isFile())return"file";if(e.isDirectory())return"directory";if(e&&e.isSymbolicLink()){let e=t.fullPath;try{let t=await o(e),i=await a(t);if(i.isFile())return"file";if(i.isDirectory()){let i=t.length;if(e.startsWith(t)&&e.substr(i,1)===m){let i=Error(`Circular symlink detected: "${e}" points to "${t}"`);return i.code=P,this._onError(i)}return"directory"}}catch(t){return this._onError(t),""}}}_includeAsFile(t){let e=t&&t[this._statsProp];return e&&this._wantsEverything&&!e.isDirectory()}}let I=()=>{},R=process.platform,z="win32"===R,j="darwin"===R,C="linux"===R,M="freebsd"===R,T="OS400"===_(),A="all",O="ready",N="add",H="change",U="addDir",L="unlink",$="unlinkDir",q="raw",K="error",V={lstat:a,stat:l},G="listeners",B="errHandlers",J="rawEmitters",Q=[G,B,J],X=new Set(["3dm","3ds","3g2","3gp","7z","a","aac","adp","afdesign","afphoto","afpub","ai","aif","aiff","alz","ape","apk","appimage","ar","arj","asf","au","avi","bak","baml","bh","bin","bk","bmp","btif","bz2","bzip2","cab","caf","cgm","class","cmx","cpio","cr2","cur","dat","dcm","deb","dex","djvu","dll","dmg","dng","doc","docm","docx","dot","dotm","dra","DS_Store","dsk","dts","dtshd","dvb","dwg","dxf","ecelp4800","ecelp7470","ecelp9600","egg","eol","eot","epub","exe","f4v","fbs","fh","fla","flac","flatpak","fli","flv","fpx","fst","fvt","g3","gh","gif","graffle","gz","gzip","h261","h263","h264","icns","ico","ief","img","ipa","iso","jar","jpeg","jpg","jpgv","jpm","jxr","key","ktx","lha","lib","lvp","lz","lzh","lzma","lzo","m3u","m4a","m4v","mar","mdi","mht","mid","midi","mj2","mka","mkv","mmr","mng","mobi","mov","movie","mp3","mp4","mp4a","mpeg","mpg","mpga","mxu","nef","npx","numbers","nupkg","o","odp","ods","odt","oga","ogg","ogv","otf","ott","pages","pbm","pcx","pdb","pdf","pea","pgm","pic","png","pnm","pot","potm","potx","ppa","ppam","ppm","pps","ppsm","ppsx","ppt","pptm","pptx","psd","pya","pyc","pyo","pyv","qt","rar","ras","raw","resources","rgb","rip","rlc","rmf","rmvb","rpm","rtf","rz","s3m","s7z","scpt","sgi","shar","snap","sil","sketch","slk","smv","snk","so","stl","suo","sub","swf","tar","tbz","tbz2","tga","tgz","thmx","tif","tiff","tlz","ttc","ttf","txz","udf","uvh","uvi","uvm","uvp","uvs","uvu","viv","vob","war","wav","wax","wbmp","wdp","weba","webm","webp","whl","wim","wm","wma","wmv","wmx","woff","woff2","wrm","wvx","xbm","xif","xla","xlam","xls","xlsb","xlsm","xlsx","xlt","xltm","xltx","xm","xmind","xpi","xpm","xwd","xz","z","zip","zipx"]),Y=(t,e)=>{t instanceof Set?t.forEach(e):e(t)},Z=(t,e,i)=>{let s=t[e];s instanceof Set||(t[e]=s=new Set([s])),s.add(i)},tt=(t,e,i)=>{let s=t[e];s instanceof Set?s.delete(i):s===i&&delete t[e]},te=t=>t instanceof Set?0===t.size:!t,ti=new Map;function ts(t,e,i,r,a){try{return s(t,{persistent:e.persistent},(e,s)=>{i(t),a(e,s,{watchedPath:t}),s&&t!==s&&tr(u.resolve(t,s),G,u.join(t,s))})}catch(t){r(t);return}}let tr=(t,e,i,s,r)=>{let a=ti.get(t);a&&Y(a[e],t=>{t(i,s,r)})},ta=new Map;class th{fsw;_boundHandleError;constructor(t){this.fsw=t,this._boundHandleError=e=>t._handleError(e)}_watchWithNodeFs(t,e){let s,a=this.fsw.options,n=u.dirname(t),o=u.basename(t);this.fsw._getWatchedDir(n).add(o);let l=u.resolve(t),d={persistent:a.persistent};if(e||(e=I),a.usePolling)d.interval=a.interval!==a.binaryInterval&&X.has(u.extname(o).slice(1).toLowerCase())?a.binaryInterval:a.interval,s=((t,e,s,a)=>{let{listener:h,rawEmitter:n}=a,o=ta.get(e),l=o&&o.options;return l&&(l.persistent<s.persistent||l.interval>s.interval)&&(i(e),o=void 0),o?(Z(o,G,h),Z(o,J,n)):(o={listeners:h,rawEmitters:n,options:s,watcher:r(e,s,(i,s)=>{Y(o.rawEmitters,t=>{t(H,e,{curr:i,prev:s})});let r=i.mtimeMs;(i.size!==s.size||r>s.mtimeMs||0===r)&&Y(o.listeners,e=>e(t,i))})},ta.set(e,o)),()=>{tt(o,G,h),tt(o,J,n),te(o.listeners)&&(ta.delete(e),i(e),o.options=o.watcher=void 0,Object.freeze(o))}})(t,l,d,{listener:e,rawEmitter:this.fsw._emitRaw});else s=((t,e,i,s)=>{let r,{listener:a,errHandler:n,rawEmitter:o}=s,l=ti.get(e);if(!i.persistent){if(!(r=ts(t,i,a,n,o)))return;return r.close.bind(r)}if(l)Z(l,G,a),Z(l,B,n),Z(l,J,o);else{if(!(r=ts(t,i,tr.bind(null,e,G),n,tr.bind(null,e,J))))return;r.on(K,async i=>{let s=tr.bind(null,e,B);if(l&&(l.watcherUnusable=!0),z&&"EPERM"===i.code)try{let e=await h(t,"r");await e.close(),s(i)}catch(t){}else s(i)}),l={listeners:a,errHandlers:n,rawEmitters:o,watcher:r},ti.set(e,l)}return()=>{if(tt(l,G,a),tt(l,B,n),tt(l,J,o),te(l.listeners)){let t;l.watcher.close(),ti.delete(e),Q.forEach((t=l,e=>{let i=t[e];i instanceof Set?i.clear():delete t[e]})),l.watcher=void 0,Object.freeze(l)}}})(t,l,d,{listener:e,errHandler:this._boundHandleError,rawEmitter:this.fsw._emitRaw});return s}_handleFile(t,e,i){if(this.fsw.closed)return;let s=u.dirname(t),r=u.basename(t),a=this.fsw._getWatchedDir(s),h=e;if(a.has(r))return;let n=async(e,i)=>{if(this.fsw._throttle("watch",t,5))if(i&&0!==i.mtimeMs){if(a.has(r)){let e=i.atimeMs,s=i.mtimeMs;(!e||e<=s||s!==h.mtimeMs)&&this.fsw._emit(H,t,i),h=i}}else try{let i=await l(t);if(this.fsw.closed)return;let s=i.atimeMs,r=i.mtimeMs;if((!s||s<=r||r!==h.mtimeMs)&&this.fsw._emit(H,t,i),(j||C||M)&&h.ino!==i.ino){this.fsw._closeFile(e),h=i;let s=this._watchWithNodeFs(t,n);s&&this.fsw._addPathCloser(e,s)}else h=i}catch(t){this.fsw._remove(s,r)}},o=this._watchWithNodeFs(t,n);if(!(i&&this.fsw.options.ignoreInitial)&&this.fsw._isntIgnored(t)){if(!this.fsw._throttle(N,t,0))return;this.fsw._emit(N,t,e)}return o}async _handleSymlink(t,e,i,s){if(this.fsw.closed)return;let r=t.fullPath,a=this.fsw._getWatchedDir(e);if(!this.fsw.options.followSymlinks){let e;this.fsw._incrReadyCount();try{e=await o(i)}catch(t){return this.fsw._emitReady(),!0}if(this.fsw.closed)return;return a.has(s)?this.fsw._symlinkPaths.get(r)!==e&&(this.fsw._symlinkPaths.set(r,e),this.fsw._emit(H,i,t.stats)):(a.add(s),this.fsw._symlinkPaths.set(r,e),this.fsw._emit(N,i,t.stats)),this.fsw._emitReady(),!0}if(this.fsw._symlinkPaths.has(r))return!0;this.fsw._symlinkPaths.set(r,!0)}_handleRead(t,e,i,s,r,a,h){t=u.join(t,"");let n=s?`${t}:${s}`:t;if(!(h=this.fsw._throttle("readdir",n,1e3)))return;let o=this.fsw._getWatchedDir(i.path),l=new Set,d=this.fsw._readdirp(t,{fileFilter:t=>i.filterPath(t),directoryFilter:t=>i.filterDir(t)});if(d)return d.on("data",async h=>{if(this.fsw.closed){d=void 0;return}let n=h.path,c=u.join(t,n);if(l.add(n),!(h.stats.isSymbolicLink()&&await this._handleSymlink(h,t,c,n))){if(this.fsw.closed){d=void 0;return}n!==s&&(s||o.has(n))||(this.fsw._incrReadyCount(),c=u.join(r,u.relative(r,c)),this._addToNodeFs(c,e,i,a+1))}}).on(K,this._boundHandleError),new Promise((e,n)=>{if(!d)return n();d.once("end",()=>{if(this.fsw.closed){d=void 0;return}let n=!!h&&h.clear();e(void 0),o.getChildren().filter(e=>e!==t&&!l.has(e)).forEach(e=>{this.fsw._remove(t,e)}),d=void 0,n&&this._handleRead(t,!1,i,s,r,a,h)})})}async _handleDir(t,e,i,s,r,a,h){let n,o,l=this.fsw._getWatchedDir(u.dirname(t)),d=l.has(u.basename(t));i&&this.fsw.options.ignoreInitial||r||d||this.fsw._emit(U,t,e),l.add(u.basename(t)),this.fsw._getWatchedDir(t);let c=this.fsw.options.depth;if((null==c||s<=c)&&!this.fsw._symlinkPaths.has(h)){if(!r&&(await this._handleRead(t,i,a,r,t,s,n),this.fsw.closed))return;o=this._watchWithNodeFs(t,(e,i)=>{i&&0===i.mtimeMs||this._handleRead(e,!1,a,r,t,s,n)})}return o}async _addToNodeFs(t,e,i,s,r){let a=this.fsw._emitReady;if(this.fsw._isIgnored(t)||this.fsw.closed)return a(),!1;let h=this.fsw._getWatchHelpers(t);i&&(h.filterPath=t=>i.filterPath(t),h.filterDir=t=>i.filterDir(t));try{let i,n=await V[h.statMethod](h.watchPath);if(this.fsw.closed)return;if(this.fsw._isIgnored(h.watchPath,n))return a(),!1;let l=this.fsw.options.followSymlinks;if(n.isDirectory()){let a=u.resolve(t),d=l?await o(t):t;if(this.fsw.closed||(i=await this._handleDir(h.watchPath,n,e,s,r,h,d),this.fsw.closed))return;a!==d&&void 0!==d&&this.fsw._symlinkPaths.set(a,d)}else if(n.isSymbolicLink()){let r=l?await o(t):t;if(this.fsw.closed)return;let a=u.dirname(h.watchPath);if(this.fsw._getWatchedDir(a).add(h.watchPath),this.fsw._emit(N,h.watchPath,n),i=await this._handleDir(a,n,e,s,t,h,r),this.fsw.closed)return;void 0!==r&&this.fsw._symlinkPaths.set(u.resolve(t),r)}else i=this._handleFile(h.watchPath,n,e);return a(),i&&this.fsw._addPathCloser(t,i),!1}catch(e){if(this.fsw._handleError(e))return a(),t}}}let tn=/\\/g,to=/\/\//g,tl=/\..*\.(sw[px])$|~$|\.subl.*\.tmp/,td=/^\.[/\\]/;function tc(t){return Array.isArray(t)?t:[t]}let tf=t=>"object"==typeof t&&null!==t&&!(t instanceof RegExp);function tm(t,e,i){let s=function(t){if("string"!=typeof t)throw Error("string expected");t=(t=u.normalize(t)).replace(/\\/g,"/");let e=!1;return t.startsWith("//")&&(e=!0),t=t.replace(to,"/"),e&&(t="/"+t),t}(e);for(let e=0;e<t.length;e++)if((0,t[e])(s,i))return!0;return!1}let tp=t=>{let e=tc(t).flat();if(!e.every(t=>"string"==typeof t))throw TypeError(`Non-string provided as watch path: ${e}`);return e.map(tu)},t_=t=>{let e=t.replace(tn,"/"),i=!1;return e.startsWith("//")&&(i=!0),e=e.replace(to,"/"),i&&(e="/"+e),e},tu=t=>t_(u.normalize(t_(t))),tw=(t="")=>e=>"string"==typeof e?tu(u.isAbsolute(e)?e:u.join(t,e)):e,tg=Object.freeze(new Set);class ty{path;_removeWatcher;items;constructor(t,e){this.path=t,this._removeWatcher=e,this.items=new Set}add(t){let{items:e}=this;e&&"."!==t&&".."!==t&&e.add(t)}async remove(t){let{items:e}=this;if(!e||(e.delete(t),e.size>0))return;let i=this.path;try{await n(i)}catch(t){this._removeWatcher&&this._removeWatcher(u.dirname(i),u.basename(i))}}has(t){let{items:e}=this;if(e)return e.has(t)}getChildren(){let{items:t}=this;return t?[...t.values()]:[]}dispose(){this.items.clear(),this.path="",this._removeWatcher=I,this.items=tg,Object.freeze(this)}}class tv{fsw;path;watchPath;fullWatchPath;dirParts;followSymlinks;statMethod;constructor(t,e,i){this.fsw=i;let s=t;this.path=t=t.replace(td,""),this.watchPath=s,this.fullWatchPath=u.resolve(s),this.dirParts=[],this.dirParts.forEach(t=>{t.length>1&&t.pop()}),this.followSymlinks=e,this.statMethod=e?"stat":"lstat"}entryPath(t){return u.join(this.watchPath,u.relative(this.watchPath,t.fullPath))}filterPath(t){let{stats:e}=t;if(e&&e.isSymbolicLink())return this.filterDir(t);let i=this.entryPath(t);return this.fsw._isntIgnored(i,e)&&this.fsw._hasReadPermissions(e)}filterDir(t){return this.fsw._isntIgnored(this.entryPath(t),t.stats)}}class tP extends t{closed;options;_closers;_ignoredPaths;_throttled;_streams;_symlinkPaths;_watched;_pendingWrites;_pendingUnlinks;_readyCount;_emitReady;_closePromise;_userIgnored;_readyEmitted;_emitRaw;_boundRemove;_nodeFsHandler;constructor(t={}){super(),this.closed=!1,this._closers=new Map,this._ignoredPaths=new Set,this._throttled=new Map,this._streams=new Set,this._symlinkPaths=new Map,this._watched=new Map,this._pendingWrites=new Map,this._pendingUnlinks=new Map,this._readyCount=0,this._readyEmitted=!1;let e=t.awaitWriteFinish,i={stabilityThreshold:2e3,pollInterval:100},s={persistent:!0,ignoreInitial:!1,ignorePermissionErrors:!1,interval:100,binaryInterval:300,followSymlinks:!0,usePolling:!1,atomic:!0,...t,ignored:t.ignored?tc(t.ignored):tc([]),awaitWriteFinish:!0===e?i:"object"==typeof e&&{...i,...e}};T&&(s.usePolling=!0),void 0===s.atomic&&(s.atomic=!s.usePolling);let r=process.env.CHOKIDAR_USEPOLLING;if(void 0!==r){let t=r.toLowerCase();"false"===t||"0"===t?s.usePolling=!1:"true"===t||"1"===t?s.usePolling=!0:s.usePolling=!!t}let a=process.env.CHOKIDAR_INTERVAL;a&&(s.interval=Number.parseInt(a,10));let h=0;this._emitReady=()=>{++h>=this._readyCount&&(this._emitReady=I,this._readyEmitted=!0,process.nextTick(()=>this.emit(O)))},this._emitRaw=(...t)=>this.emit(q,...t),this._boundRemove=this._remove.bind(this),this.options=s,this._nodeFsHandler=new th(this),Object.freeze(s)}_addIgnoredPath(t){if(tf(t)){for(let e of this._ignoredPaths)if(tf(e)&&e.path===t.path&&e.recursive===t.recursive)return}this._ignoredPaths.add(t)}_removeIgnoredPath(t){if(this._ignoredPaths.delete(t),"string"==typeof t)for(let e of this._ignoredPaths)tf(e)&&e.path===t&&this._ignoredPaths.delete(e)}add(t,e,i){let{cwd:s}=this.options;this.closed=!1,this._closePromise=void 0;let r=tp(t);return s&&(r=r.map(t=>u.isAbsolute(t)?t:u.join(s,t))),r.forEach(t=>{this._removeIgnoredPath(t)}),this._userIgnored=void 0,this._readyCount||(this._readyCount=0),this._readyCount+=r.length,Promise.all(r.map(async t=>{let s=await this._nodeFsHandler._addToNodeFs(t,!i,void 0,0,e);return s&&this._emitReady(),s})).then(t=>{this.closed||t.forEach(t=>{t&&this.add(u.dirname(t),u.basename(e||t))})}),this}unwatch(t){if(this.closed)return this;let e=tp(t),{cwd:i}=this.options;return e.forEach(t=>{u.isAbsolute(t)||this._closers.has(t)||(i&&(t=u.join(i,t)),t=u.resolve(t)),this._closePath(t),this._addIgnoredPath(t),this._watched.has(t)&&this._addIgnoredPath({path:t,recursive:!0}),this._userIgnored=void 0}),this}close(){if(this._closePromise)return this._closePromise;this.closed=!0,this.removeAllListeners();let t=[];return this._closers.forEach(e=>e.forEach(e=>{let i=e();i instanceof Promise&&t.push(i)})),this._streams.forEach(t=>t.destroy()),this._userIgnored=void 0,this._readyCount=0,this._readyEmitted=!1,this._watched.forEach(t=>t.dispose()),this._closers.clear(),this._watched.clear(),this._streams.clear(),this._symlinkPaths.clear(),this._throttled.clear(),this._closePromise=t.length?Promise.all(t).then(()=>void 0):Promise.resolve(),this._closePromise}getWatched(){let t={};return this._watched.forEach((e,i)=>{t[(this.options.cwd?u.relative(this.options.cwd,i):i)||"."]=e.getChildren().sort()}),t}emitWithAll(t,e){this.emit(t,...e),t!==K&&this.emit(A,t,...e)}async _emit(t,e,i){let s;if(this.closed)return;let r=this.options;z&&(e=u.normalize(e)),r.cwd&&(e=u.relative(r.cwd,e));let a=[e];null!=i&&a.push(i);let h=r.awaitWriteFinish;if(h&&(s=this._pendingWrites.get(e)))return s.lastChange=new Date,this;if(r.atomic){if(t===L)return this._pendingUnlinks.set(e,[t,...a]),setTimeout(()=>{this._pendingUnlinks.forEach((t,e)=>{this.emit(...t),this.emit(A,...t),this._pendingUnlinks.delete(e)})},"number"==typeof r.atomic?r.atomic:100),this;t===N&&this._pendingUnlinks.has(e)&&(t=H,this._pendingUnlinks.delete(e))}if(h&&(t===N||t===H)&&this._readyEmitted){let i=(e,i)=>{e?(t=K,a[0]=e,this.emitWithAll(t,a)):i&&(a.length>1?a[1]=i:a.push(i),this.emitWithAll(t,a))};return this._awaitWriteFinish(e,h.stabilityThreshold,t,i),this}if(t===H&&!this._throttle(H,e,50))return this;if(r.alwaysStat&&void 0===i&&(t===N||t===U||t===H)){let t,i=r.cwd?u.join(r.cwd,e):e;try{t=await l(i)}catch(t){}if(!t||this.closed)return;a.push(t)}return this.emitWithAll(t,a),this}_handleError(t){let e=t&&t.code;return t&&"ENOENT"!==e&&"ENOTDIR"!==e&&(!this.options.ignorePermissionErrors||"EPERM"!==e&&"EACCES"!==e)&&this.emit(K,t),t||this.closed}_throttle(t,e,i){let s;this._throttled.has(t)||this._throttled.set(t,new Map);let r=this._throttled.get(t);if(!r)throw Error("invalid throttle");let a=r.get(e);if(a)return a.count++,!1;let h=()=>{let t=r.get(e),i=t?t.count:0;return r.delete(e),clearTimeout(s),t&&clearTimeout(t.timeoutObject),i},n={timeoutObject:s=setTimeout(h,i),clear:h,count:0};return r.set(e,n),n}_incrReadyCount(){return this._readyCount++}_awaitWriteFinish(t,i,s,r){let a,h=this.options.awaitWriteFinish;if("object"!=typeof h)return;let n=h.pollInterval,o=t;this.options.cwd&&!u.isAbsolute(t)&&(o=u.join(this.options.cwd,t));let l=new Date,d=this._pendingWrites;d.has(t)||(d.set(t,{lastChange:l,cancelWait:()=>(d.delete(t),clearTimeout(a),s)}),a=setTimeout(function s(h){e(o,(e,o)=>{if(e||!d.has(t)){e&&"ENOENT"!==e.code&&r(e);return}let l=Number(new Date);h&&o.size!==h.size&&(d.get(t).lastChange=l),l-d.get(t).lastChange>=i?(d.delete(t),r(void 0,o)):a=setTimeout(s,n,o)})},n))}_isIgnored(t,e){if(this.options.atomic&&tl.test(t))return!0;if(!this._userIgnored){let{cwd:t}=this.options,e=(this.options.ignored||[]).map(tw(t)),i=[...[...this._ignoredPaths].map(tw(t)),...e];this._userIgnored=function(t,e){if(null==t)throw TypeError("anymatch: specify first argument");let i=tc(t).map(t=>"function"==typeof t?t:"string"==typeof t?e=>t===e:t instanceof RegExp?e=>t.test(e):"object"==typeof t&&null!==t?e=>{if(t.path===e)return!0;if(t.recursive){let i=u.relative(t.path,e);return!!i&&!i.startsWith("..")&&!u.isAbsolute(i)}return!1}:()=>!1);return null==e?(t,e)=>tm(i,t,e):tm(i,e)}(i,void 0)}return this._userIgnored(t,e)}_isntIgnored(t,e){return!this._isIgnored(t,e)}_getWatchHelpers(t){return new tv(t,this.options.followSymlinks,this)}_getWatchedDir(t){let e=u.resolve(t);return this._watched.has(e)||this._watched.set(e,new ty(e,this._boundRemove)),this._watched.get(e)}_hasReadPermissions(t){return!!this.options.ignorePermissionErrors||!!(256&Number(t.mode))}_remove(t,e,i){let s=u.join(t,e),r=u.resolve(s);if(i=null!=i?i:this._watched.has(s)||this._watched.has(r),!this._throttle("remove",s,100))return;i||1!==this._watched.size||this.add(t,e,!0),this._getWatchedDir(s).getChildren().forEach(t=>this._remove(s,t));let a=this._getWatchedDir(t),h=a.has(e);a.remove(e),this._symlinkPaths.has(r)&&this._symlinkPaths.delete(r);let n=s;if(this.options.cwd&&(n=u.relative(this.options.cwd,s)),this.options.awaitWriteFinish&&this._pendingWrites.has(n)&&this._pendingWrites.get(n).cancelWait()===N)return;this._watched.delete(s),this._watched.delete(r);let o=i?$:L;h&&!this._isIgnored(s)&&this._emit(o,s),this._closePath(s)}_closePath(t){this._closeFile(t);let e=u.dirname(t);this._getWatchedDir(e).remove(u.basename(t))}_closeFile(t){let e=this._closers.get(t);e&&(e.forEach(t=>t()),this._closers.delete(t))}_addPathCloser(t,e){if(!e)return;let i=this._closers.get(t);i||(i=[],this._closers.set(t,i)),i.push(e)}_readdirp(t,e){if(this.closed)return;let i=function(t,e={}){let i=e.entryType||e.type;if("both"===i&&(i=y),i&&(e.type=i),t){if("string"!=typeof t)throw TypeError("readdirp: root argument must be a string. Usage: readdirp(root, options)");else if(i&&!E.includes(i))throw Error(`readdirp: Invalid type passed. Use one of ${E.join(", ")}`)}else throw Error("readdirp: root argument is required. Usage: readdirp(root, options)");return e.root=t,new S(e)}(t,{type:A,alwaysStat:!0,lstat:!0,...e,depth:0});return this._streams.add(i),i.once("close",()=>{i=void 0}),i.once("end",()=>{i&&(this._streams.delete(i),i=void 0)}),i}}export default{watch:function(t,e={}){let i=new tP(e);return i.add(t),i},FSWatcher:tP};
|
|
2
|
+
import{definePropertyGetters as t,makeNamespaceObject as e}from"./rslib-runtime.js";import{EventEmitter as i}from"node:events";import{stat as s,unwatchFile as r,watch as a,watchFile as h}from"node:fs";import{lstat as n,open as o,readdir as l,realpath as d,stat as c}from"node:fs/promises";import{join as f,relative as m,resolve as p,sep as _}from"node:path";import{Readable as u}from"node:stream";import{type as w}from"node:os";import*as g from"node:path";var y={};e(y),t(y,{FSWatcher:()=>tx,WatchHelper:()=>tE,default:()=>tW,watch:()=>tk});let v="files",P="directories",b="files_directories",E={root:".",fileFilter:t=>!0,directoryFilter:t=>!0,type:v,lstat:!1,depth:0x80000000,alwaysStat:!1,highWaterMark:4096};Object.freeze(E);let x="READDIRP_RECURSIVE_ERROR",k=new Set(["ENOENT","EPERM","EACCES","ELOOP",x]),W=[P,"all",b,v],D=new Set([P,"all",b]),F=new Set(["all",b,v]),S="win32"===process.platform,R=t=>!0,I=t=>{if(void 0===t)return R;if("function"==typeof t)return t;if("string"==typeof t){let e=t.trim();return t=>t.basename===e}if(Array.isArray(t)){let e=t.map(t=>t.trim());return t=>e.some(e=>t.basename===e)}return R};class z extends u{parents;reading;parent;_stat;_maxDepth;_wantsDir;_wantsFile;_wantsEverything;_root;_isDirent;_statsProp;_rdOptions;_fileFilter;_directoryFilter;constructor(t={}){super({objectMode:!0,autoDestroy:!0,highWaterMark:t.highWaterMark});let e={...E,...t},{root:i,type:s}=e;this._fileFilter=I(e.fileFilter),this._directoryFilter=I(e.directoryFilter);let r=e.lstat?n:c;S?this._stat=t=>r(t,{bigint:!0}):this._stat=r,this._maxDepth=null!=e.depth&&Number.isSafeInteger(e.depth)?e.depth:E.depth,this._wantsDir=!!s&&D.has(s),this._wantsFile=!!s&&F.has(s),this._wantsEverything="all"===s,this._root=p(i),this._isDirent=!e.alwaysStat,this._statsProp=this._isDirent?"dirent":"stats",this._rdOptions={encoding:"utf8",withFileTypes:this._isDirent},this.parents=[this._exploreDir(i,1)],this.reading=!1,this.parent=void 0}async _read(t){if(!this.reading){this.reading=!0;try{for(;!this.destroyed&&t>0;){let e=this.parent,i=e&&e.files;if(i&&i.length>0){let{path:s,depth:r}=e,a=i.splice(0,t).map(t=>this._formatEntry(t,s));for(let e of(await Promise.all(a))){if(!e)continue;if(this.destroyed)return;let i=await this._getEntryType(e);"directory"===i&&this._directoryFilter(e)?(r<=this._maxDepth&&this.parents.push(this._exploreDir(e.fullPath,r+1)),this._wantsDir&&(this.push(e),t--)):("file"===i||this._includeAsFile(e))&&this._fileFilter(e)&&this._wantsFile&&(this.push(e),t--)}}else{let t=this.parents.pop();if(!t){this.push(null);break}if(this.parent=await t,this.destroyed)return}}}catch(t){this.destroy(t)}finally{this.reading=!1}}}async _exploreDir(t,e){let i;try{i=await l(t,this._rdOptions)}catch(t){this._onError(t)}return{files:i,depth:e,path:t}}async _formatEntry(t,e){let i,s=this._isDirent?t.name:t;try{let r=p(f(e,s));(i={path:m(this._root,r),fullPath:r,basename:s})[this._statsProp]=this._isDirent?t:await this._stat(r)}catch(t){this._onError(t);return}return i}_onError(t){k.has(t.code)&&!this.destroyed?this.emit("warn",t):this.destroy(t)}async _getEntryType(t){if(!t&&this._statsProp in t)return"";let e=t[this._statsProp];if(e.isFile())return"file";if(e.isDirectory())return"directory";if(e&&e.isSymbolicLink()){let e=t.fullPath;try{let t=await d(e),i=await n(t);if(i.isFile())return"file";if(i.isDirectory()){let i=t.length;if(e.startsWith(t)&&e.substr(i,1)===_){let i=Error(`Circular symlink detected: "${e}" points to "${t}"`);return i.code=x,this._onError(i)}return"directory"}}catch(t){return this._onError(t),""}}}_includeAsFile(t){let e=t&&t[this._statsProp];return e&&this._wantsEverything&&!e.isDirectory()}}let j=()=>{},C=process.platform,M="win32"===C,T="darwin"===C,A="linux"===C,O="freebsd"===C,N="OS400"===w(),H="all",U="ready",L="add",$="change",K="addDir",q="unlink",V="unlinkDir",G="raw",B="error",J={lstat:n,stat:c},Q="listeners",X="errHandlers",Y="rawEmitters",Z=[Q,X,Y],tt=new Set(["3dm","3ds","3g2","3gp","7z","a","aac","adp","afdesign","afphoto","afpub","ai","aif","aiff","alz","ape","apk","appimage","ar","arj","asf","au","avi","bak","baml","bh","bin","bk","bmp","btif","bz2","bzip2","cab","caf","cgm","class","cmx","cpio","cr2","cur","dat","dcm","deb","dex","djvu","dll","dmg","dng","doc","docm","docx","dot","dotm","dra","DS_Store","dsk","dts","dtshd","dvb","dwg","dxf","ecelp4800","ecelp7470","ecelp9600","egg","eol","eot","epub","exe","f4v","fbs","fh","fla","flac","flatpak","fli","flv","fpx","fst","fvt","g3","gh","gif","graffle","gz","gzip","h261","h263","h264","icns","ico","ief","img","ipa","iso","jar","jpeg","jpg","jpgv","jpm","jxr","key","ktx","lha","lib","lvp","lz","lzh","lzma","lzo","m3u","m4a","m4v","mar","mdi","mht","mid","midi","mj2","mka","mkv","mmr","mng","mobi","mov","movie","mp3","mp4","mp4a","mpeg","mpg","mpga","mxu","nef","npx","numbers","nupkg","o","odp","ods","odt","oga","ogg","ogv","otf","ott","pages","pbm","pcx","pdb","pdf","pea","pgm","pic","png","pnm","pot","potm","potx","ppa","ppam","ppm","pps","ppsm","ppsx","ppt","pptm","pptx","psd","pya","pyc","pyo","pyv","qt","rar","ras","raw","resources","rgb","rip","rlc","rmf","rmvb","rpm","rtf","rz","s3m","s7z","scpt","sgi","shar","snap","sil","sketch","slk","smv","snk","so","stl","suo","sub","swf","tar","tbz","tbz2","tga","tgz","thmx","tif","tiff","tlz","ttc","ttf","txz","udf","uvh","uvi","uvm","uvp","uvs","uvu","viv","vob","war","wav","wax","wbmp","wdp","weba","webm","webp","whl","wim","wm","wma","wmv","wmx","woff","woff2","wrm","wvx","xbm","xif","xla","xlam","xls","xlsb","xlsm","xlsx","xlt","xltm","xltx","xm","xmind","xpi","xpm","xwd","xz","z","zip","zipx"]),te=(t,e)=>{t instanceof Set?t.forEach(e):e(t)},ti=(t,e,i)=>{let s=t[e];s instanceof Set||(t[e]=s=new Set([s])),s.add(i)},ts=(t,e,i)=>{let s=t[e];s instanceof Set?s.delete(i):s===i&&delete t[e]},tr=t=>t instanceof Set?0===t.size:!t,ta=new Map;function th(t,e,i,s,r){try{return a(t,{persistent:e.persistent},(e,s)=>{i(t),r(e,s,{watchedPath:t}),s&&t!==s&&tn(g.resolve(t,s),Q,g.join(t,s))})}catch(t){s(t);return}}let tn=(t,e,i,s,r)=>{let a=ta.get(t);a&&te(a[e],t=>{t(i,s,r)})},to=new Map;class tl{fsw;_boundHandleError;constructor(t){this.fsw=t,this._boundHandleError=e=>t._handleError(e)}_watchWithNodeFs(t,e){let i,s=this.fsw.options,a=g.dirname(t),n=g.basename(t);this.fsw._getWatchedDir(a).add(n);let l=g.resolve(t),d={persistent:s.persistent};if(e||(e=j),s.usePolling)d.interval=s.interval!==s.binaryInterval&&tt.has(g.extname(n).slice(1).toLowerCase())?s.binaryInterval:s.interval,i=((t,e,i,s)=>{let{listener:a,rawEmitter:n}=s,o=to.get(e),l=o&&o.options;return l&&(l.persistent<i.persistent||l.interval>i.interval)&&(r(e),o=void 0),o?(ti(o,Q,a),ti(o,Y,n)):(o={listeners:a,rawEmitters:n,options:i,watcher:h(e,i,(i,s)=>{te(o.rawEmitters,t=>{t($,e,{curr:i,prev:s})});let r=i.mtimeMs;(i.size!==s.size||r>s.mtimeMs||0===r)&&te(o.listeners,e=>e(t,i))})},to.set(e,o)),()=>{ts(o,Q,a),ts(o,Y,n),tr(o.listeners)&&(to.delete(e),r(e),o.options=o.watcher=void 0,Object.freeze(o))}})(t,l,d,{listener:e,rawEmitter:this.fsw._emitRaw});else i=((t,e,i,s)=>{let r,{listener:a,errHandler:h,rawEmitter:n}=s,l=ta.get(e);if(!i.persistent){if(!(r=th(t,i,a,h,n)))return;return r.close.bind(r)}if(l)ti(l,Q,a),ti(l,X,h),ti(l,Y,n);else{if(!(r=th(t,i,tn.bind(null,e,Q),h,tn.bind(null,e,Y))))return;r.on(B,async i=>{let s=tn.bind(null,e,X);if(l&&(l.watcherUnusable=!0),M&&"EPERM"===i.code)try{let e=await o(t,"r");await e.close(),s(i)}catch(t){}else s(i)}),l={listeners:a,errHandlers:h,rawEmitters:n,watcher:r},ta.set(e,l)}return()=>{if(ts(l,Q,a),ts(l,X,h),ts(l,Y,n),tr(l.listeners)){let t;l.watcher.close(),ta.delete(e),Z.forEach((t=l,e=>{let i=t[e];i instanceof Set?i.clear():delete t[e]})),l.watcher=void 0,Object.freeze(l)}}})(t,l,d,{listener:e,errHandler:this._boundHandleError,rawEmitter:this.fsw._emitRaw});return i}_handleFile(t,e,i){if(this.fsw.closed)return;let s=g.dirname(t),r=g.basename(t),a=this.fsw._getWatchedDir(s),h=e;if(a.has(r))return;let n=async(e,i)=>{if(this.fsw._throttle("watch",t,5))if(i&&0!==i.mtimeMs){if(a.has(r)){let e=i.atimeMs,s=i.mtimeMs;(!e||e<=s||s!==h.mtimeMs)&&this.fsw._emit($,t,i),h=i}}else try{let i=await c(t);if(this.fsw.closed)return;let s=i.atimeMs,r=i.mtimeMs;if((!s||s<=r||r!==h.mtimeMs)&&this.fsw._emit($,t,i),(T||A||O)&&h.ino!==i.ino){this.fsw._closeFile(e),h=i;let s=this._watchWithNodeFs(t,n);s&&this.fsw._addPathCloser(e,s)}else h=i}catch(t){this.fsw._remove(s,r)}},o=this._watchWithNodeFs(t,n);if(!(i&&this.fsw.options.ignoreInitial)&&this.fsw._isntIgnored(t)){if(!this.fsw._throttle(L,t,0))return;this.fsw._emit(L,t,e)}return o}async _handleSymlink(t,e,i,s){if(this.fsw.closed)return;let r=t.fullPath,a=this.fsw._getWatchedDir(e);if(!this.fsw.options.followSymlinks){let e;this.fsw._incrReadyCount();try{e=await d(i)}catch(t){return this.fsw._emitReady(),!0}if(this.fsw.closed)return;return a.has(s)?this.fsw._symlinkPaths.get(r)!==e&&(this.fsw._symlinkPaths.set(r,e),this.fsw._emit($,i,t.stats)):(a.add(s),this.fsw._symlinkPaths.set(r,e),this.fsw._emit(L,i,t.stats)),this.fsw._emitReady(),!0}if(this.fsw._symlinkPaths.has(r))return!0;this.fsw._symlinkPaths.set(r,!0)}_handleRead(t,e,i,s,r,a,h){t=g.join(t,"");let n=s?`${t}:${s}`:t;if(!(h=this.fsw._throttle("readdir",n,1e3)))return;let o=this.fsw._getWatchedDir(i.path),l=new Set,d=this.fsw._readdirp(t,{fileFilter:t=>i.filterPath(t),directoryFilter:t=>i.filterDir(t)});if(d)return d.on("data",async h=>{if(this.fsw.closed){d=void 0;return}let n=h.path,c=g.join(t,n);if(l.add(n),!(h.stats.isSymbolicLink()&&await this._handleSymlink(h,t,c,n))){if(this.fsw.closed){d=void 0;return}n!==s&&(s||o.has(n))||(this.fsw._incrReadyCount(),c=g.join(r,g.relative(r,c)),this._addToNodeFs(c,e,i,a+1))}}).on(B,this._boundHandleError),new Promise((e,n)=>{if(!d)return n();d.once("end",()=>{if(this.fsw.closed){d=void 0;return}let n=!!h&&h.clear();e(void 0),o.getChildren().filter(e=>e!==t&&!l.has(e)).forEach(e=>{this.fsw._remove(t,e)}),d=void 0,n&&this._handleRead(t,!1,i,s,r,a,h)})})}async _handleDir(t,e,i,s,r,a,h){let n,o,l=this.fsw._getWatchedDir(g.dirname(t)),d=l.has(g.basename(t));i&&this.fsw.options.ignoreInitial||r||d||this.fsw._emit(K,t,e),l.add(g.basename(t)),this.fsw._getWatchedDir(t);let c=this.fsw.options.depth;if((null==c||s<=c)&&!this.fsw._symlinkPaths.has(h)){if(!r&&(await this._handleRead(t,i,a,r,t,s,n),this.fsw.closed))return;o=this._watchWithNodeFs(t,(e,i)=>{i&&0===i.mtimeMs||this._handleRead(e,!1,a,r,t,s,n)})}return o}async _addToNodeFs(t,e,i,s,r){let a=this.fsw._emitReady;if(this.fsw._isIgnored(t)||this.fsw.closed)return a(),!1;let h=this.fsw._getWatchHelpers(t);i&&(h.filterPath=t=>i.filterPath(t),h.filterDir=t=>i.filterDir(t));try{let i,n=await J[h.statMethod](h.watchPath);if(this.fsw.closed)return;if(this.fsw._isIgnored(h.watchPath,n))return a(),!1;let o=this.fsw.options.followSymlinks;if(n.isDirectory()){let a=g.resolve(t),l=o?await d(t):t;if(this.fsw.closed||(i=await this._handleDir(h.watchPath,n,e,s,r,h,l),this.fsw.closed))return;a!==l&&void 0!==l&&this.fsw._symlinkPaths.set(a,l)}else if(n.isSymbolicLink()){let r=o?await d(t):t;if(this.fsw.closed)return;let a=g.dirname(h.watchPath);if(this.fsw._getWatchedDir(a).add(h.watchPath),this.fsw._emit(L,h.watchPath,n),i=await this._handleDir(a,n,e,s,t,h,r),this.fsw.closed)return;void 0!==r&&this.fsw._symlinkPaths.set(g.resolve(t),r)}else i=this._handleFile(h.watchPath,n,e);return a(),i&&this.fsw._addPathCloser(t,i),!1}catch(e){if(this.fsw._handleError(e))return a(),t}}}let td=/\\/g,tc=/\/\//g,tf=/\..*\.(sw[px])$|~$|\.subl.*\.tmp/,tm=/^\.[/\\]/;function tp(t){return Array.isArray(t)?t:[t]}let t_=t=>"object"==typeof t&&null!==t&&!(t instanceof RegExp);function tu(t,e,i){let s=function(t){if("string"!=typeof t)throw Error("string expected");t=(t=g.normalize(t)).replace(/\\/g,"/");let e=!1;return t.startsWith("//")&&(e=!0),t=t.replace(tc,"/"),e&&(t="/"+t),t}(e);for(let e=0;e<t.length;e++)if((0,t[e])(s,i))return!0;return!1}let tw=t=>{let e=tp(t).flat();if(!e.every(t=>"string"==typeof t))throw TypeError(`Non-string provided as watch path: ${e}`);return e.map(ty)},tg=t=>{let e=t.replace(td,"/"),i=!1;return e.startsWith("//")&&(i=!0),e=e.replace(tc,"/"),i&&(e="/"+e),e},ty=t=>tg(g.normalize(tg(t))),tv=(t="")=>e=>"string"==typeof e?ty(g.isAbsolute(e)?e:g.join(t,e)):e,tP=Object.freeze(new Set);class tb{path;_removeWatcher;items;constructor(t,e){this.path=t,this._removeWatcher=e,this.items=new Set}add(t){let{items:e}=this;e&&"."!==t&&".."!==t&&e.add(t)}async remove(t){let{items:e}=this;if(!e||(e.delete(t),e.size>0))return;let i=this.path;try{await l(i)}catch(t){this._removeWatcher&&this._removeWatcher(g.dirname(i),g.basename(i))}}has(t){let{items:e}=this;if(e)return e.has(t)}getChildren(){let{items:t}=this;return t?[...t.values()]:[]}dispose(){this.items.clear(),this.path="",this._removeWatcher=j,this.items=tP,Object.freeze(this)}}class tE{fsw;path;watchPath;fullWatchPath;dirParts;followSymlinks;statMethod;constructor(t,e,i){this.fsw=i;let s=t;this.path=t=t.replace(tm,""),this.watchPath=s,this.fullWatchPath=g.resolve(s),this.dirParts=[],this.dirParts.forEach(t=>{t.length>1&&t.pop()}),this.followSymlinks=e,this.statMethod=e?"stat":"lstat"}entryPath(t){return g.join(this.watchPath,g.relative(this.watchPath,t.fullPath))}filterPath(t){let{stats:e}=t;if(e&&e.isSymbolicLink())return this.filterDir(t);let i=this.entryPath(t);return this.fsw._isntIgnored(i,e)&&this.fsw._hasReadPermissions(e)}filterDir(t){return this.fsw._isntIgnored(this.entryPath(t),t.stats)}}class tx extends i{closed;options;_closers;_ignoredPaths;_throttled;_streams;_symlinkPaths;_watched;_pendingWrites;_pendingUnlinks;_readyCount;_emitReady;_closePromise;_userIgnored;_readyEmitted;_emitRaw;_boundRemove;_nodeFsHandler;constructor(t={}){super(),this.closed=!1,this._closers=new Map,this._ignoredPaths=new Set,this._throttled=new Map,this._streams=new Set,this._symlinkPaths=new Map,this._watched=new Map,this._pendingWrites=new Map,this._pendingUnlinks=new Map,this._readyCount=0,this._readyEmitted=!1;let e=t.awaitWriteFinish,i={stabilityThreshold:2e3,pollInterval:100},s={persistent:!0,ignoreInitial:!1,ignorePermissionErrors:!1,interval:100,binaryInterval:300,followSymlinks:!0,usePolling:!1,atomic:!0,...t,ignored:t.ignored?tp(t.ignored):tp([]),awaitWriteFinish:!0===e?i:"object"==typeof e&&{...i,...e}};N&&(s.usePolling=!0),void 0===s.atomic&&(s.atomic=!s.usePolling);let r=process.env.CHOKIDAR_USEPOLLING;if(void 0!==r){let t=r.toLowerCase();"false"===t||"0"===t?s.usePolling=!1:"true"===t||"1"===t?s.usePolling=!0:s.usePolling=!!t}let a=process.env.CHOKIDAR_INTERVAL;a&&(s.interval=Number.parseInt(a,10));let h=0;this._emitReady=()=>{++h>=this._readyCount&&(this._emitReady=j,this._readyEmitted=!0,process.nextTick(()=>this.emit(U)))},this._emitRaw=(...t)=>this.emit(G,...t),this._boundRemove=this._remove.bind(this),this.options=s,this._nodeFsHandler=new tl(this),Object.freeze(s)}_addIgnoredPath(t){if(t_(t)){for(let e of this._ignoredPaths)if(t_(e)&&e.path===t.path&&e.recursive===t.recursive)return}this._ignoredPaths.add(t)}_removeIgnoredPath(t){if(this._ignoredPaths.delete(t),"string"==typeof t)for(let e of this._ignoredPaths)t_(e)&&e.path===t&&this._ignoredPaths.delete(e)}add(t,e,i){let{cwd:s}=this.options;this.closed=!1,this._closePromise=void 0;let r=tw(t);return s&&(r=r.map(t=>g.isAbsolute(t)?t:g.join(s,t))),r.forEach(t=>{this._removeIgnoredPath(t)}),this._userIgnored=void 0,this._readyCount||(this._readyCount=0),this._readyCount+=r.length,Promise.all(r.map(async t=>{let s=await this._nodeFsHandler._addToNodeFs(t,!i,void 0,0,e);return s&&this._emitReady(),s})).then(t=>{this.closed||t.forEach(t=>{t&&this.add(g.dirname(t),g.basename(e||t))})}),this}unwatch(t){if(this.closed)return this;let e=tw(t),{cwd:i}=this.options;return e.forEach(t=>{g.isAbsolute(t)||this._closers.has(t)||(i&&(t=g.join(i,t)),t=g.resolve(t)),this._closePath(t),this._addIgnoredPath(t),this._watched.has(t)&&this._addIgnoredPath({path:t,recursive:!0}),this._userIgnored=void 0}),this}close(){if(this._closePromise)return this._closePromise;this.closed=!0,this.removeAllListeners();let t=[];return this._closers.forEach(e=>e.forEach(e=>{let i=e();i instanceof Promise&&t.push(i)})),this._streams.forEach(t=>t.destroy()),this._userIgnored=void 0,this._readyCount=0,this._readyEmitted=!1,this._watched.forEach(t=>t.dispose()),this._closers.clear(),this._watched.clear(),this._streams.clear(),this._symlinkPaths.clear(),this._throttled.clear(),this._closePromise=t.length?Promise.all(t).then(()=>void 0):Promise.resolve(),this._closePromise}getWatched(){let t={};return this._watched.forEach((e,i)=>{t[(this.options.cwd?g.relative(this.options.cwd,i):i)||"."]=e.getChildren().sort()}),t}emitWithAll(t,e){this.emit(t,...e),t!==B&&this.emit(H,t,...e)}async _emit(t,e,i){let s;if(this.closed)return;let r=this.options;M&&(e=g.normalize(e)),r.cwd&&(e=g.relative(r.cwd,e));let a=[e];null!=i&&a.push(i);let h=r.awaitWriteFinish;if(h&&(s=this._pendingWrites.get(e)))return s.lastChange=new Date,this;if(r.atomic){if(t===q)return this._pendingUnlinks.set(e,[t,...a]),setTimeout(()=>{this._pendingUnlinks.forEach((t,e)=>{this.emit(...t),this.emit(H,...t),this._pendingUnlinks.delete(e)})},"number"==typeof r.atomic?r.atomic:100),this;t===L&&this._pendingUnlinks.has(e)&&(t=$,this._pendingUnlinks.delete(e))}if(h&&(t===L||t===$)&&this._readyEmitted){let i=(e,i)=>{e?(t=B,a[0]=e,this.emitWithAll(t,a)):i&&(a.length>1?a[1]=i:a.push(i),this.emitWithAll(t,a))};return this._awaitWriteFinish(e,h.stabilityThreshold,t,i),this}if(t===$&&!this._throttle($,e,50))return this;if(r.alwaysStat&&void 0===i&&(t===L||t===K||t===$)){let t,i=r.cwd?g.join(r.cwd,e):e;try{t=await c(i)}catch(t){}if(!t||this.closed)return;a.push(t)}return this.emitWithAll(t,a),this}_handleError(t){let e=t&&t.code;return t&&"ENOENT"!==e&&"ENOTDIR"!==e&&(!this.options.ignorePermissionErrors||"EPERM"!==e&&"EACCES"!==e)&&this.emit(B,t),t||this.closed}_throttle(t,e,i){let s;this._throttled.has(t)||this._throttled.set(t,new Map);let r=this._throttled.get(t);if(!r)throw Error("invalid throttle");let a=r.get(e);if(a)return a.count++,!1;let h=()=>{let t=r.get(e),i=t?t.count:0;return r.delete(e),clearTimeout(s),t&&clearTimeout(t.timeoutObject),i},n={timeoutObject:s=setTimeout(h,i),clear:h,count:0};return r.set(e,n),n}_incrReadyCount(){return this._readyCount++}_awaitWriteFinish(t,e,i,r){let a,h=this.options.awaitWriteFinish;if("object"!=typeof h)return;let n=h.pollInterval,o=t;this.options.cwd&&!g.isAbsolute(t)&&(o=g.join(this.options.cwd,t));let l=new Date,d=this._pendingWrites;d.has(t)||(d.set(t,{lastChange:l,cancelWait:()=>(d.delete(t),clearTimeout(a),i)}),a=setTimeout(function i(h){s(o,(s,o)=>{if(s||!d.has(t)){s&&"ENOENT"!==s.code&&r(s);return}let l=Number(new Date);h&&o.size!==h.size&&(d.get(t).lastChange=l),l-d.get(t).lastChange>=e?(d.delete(t),r(void 0,o)):a=setTimeout(i,n,o)})},n))}_isIgnored(t,e){if(this.options.atomic&&tf.test(t))return!0;if(!this._userIgnored){let{cwd:t}=this.options,e=(this.options.ignored||[]).map(tv(t)),i=[...[...this._ignoredPaths].map(tv(t)),...e];this._userIgnored=function(t,e){if(null==t)throw TypeError("anymatch: specify first argument");let i=tp(t).map(t=>"function"==typeof t?t:"string"==typeof t?e=>t===e:t instanceof RegExp?e=>t.test(e):"object"==typeof t&&null!==t?e=>{if(t.path===e)return!0;if(t.recursive){let i=g.relative(t.path,e);return!!i&&!i.startsWith("..")&&!g.isAbsolute(i)}return!1}:()=>!1);return null==e?(t,e)=>tu(i,t,e):tu(i,e)}(i,void 0)}return this._userIgnored(t,e)}_isntIgnored(t,e){return!this._isIgnored(t,e)}_getWatchHelpers(t){return new tE(t,this.options.followSymlinks,this)}_getWatchedDir(t){let e=g.resolve(t);return this._watched.has(e)||this._watched.set(e,new tb(e,this._boundRemove)),this._watched.get(e)}_hasReadPermissions(t){return!!this.options.ignorePermissionErrors||!!(256&Number(t.mode))}_remove(t,e,i){let s=g.join(t,e),r=g.resolve(s);if(i=null!=i?i:this._watched.has(s)||this._watched.has(r),!this._throttle("remove",s,100))return;i||1!==this._watched.size||this.add(t,e,!0),this._getWatchedDir(s).getChildren().forEach(t=>this._remove(s,t));let a=this._getWatchedDir(t),h=a.has(e);a.remove(e),this._symlinkPaths.has(r)&&this._symlinkPaths.delete(r);let n=s;if(this.options.cwd&&(n=g.relative(this.options.cwd,s)),this.options.awaitWriteFinish&&this._pendingWrites.has(n)&&this._pendingWrites.get(n).cancelWait()===L)return;this._watched.delete(s),this._watched.delete(r);let o=i?V:q;h&&!this._isIgnored(s)&&this._emit(o,s),this._closePath(s)}_closePath(t){this._closeFile(t);let e=g.dirname(t);this._getWatchedDir(e).remove(g.basename(t))}_closeFile(t){let e=this._closers.get(t);e&&(e.forEach(t=>t()),this._closers.delete(t))}_addPathCloser(t,e){if(!e)return;let i=this._closers.get(t);i||(i=[],this._closers.set(t,i)),i.push(e)}_readdirp(t,e){if(this.closed)return;let i=function(t,e={}){let i=e.entryType||e.type;if("both"===i&&(i=b),i&&(e.type=i),t){if("string"!=typeof t)throw TypeError("readdirp: root argument must be a string. Usage: readdirp(root, options)");else if(i&&!W.includes(i))throw Error(`readdirp: Invalid type passed. Use one of ${W.join(", ")}`)}else throw Error("readdirp: root argument is required. Usage: readdirp(root, options)");return e.root=t,new z(e)}(t,{type:H,alwaysStat:!0,lstat:!0,...e,depth:0});return this._streams.add(i),i.once("close",()=>{i=void 0}),i.once("end",()=>{i&&(this._streams.delete(i),i=void 0)}),i}}function tk(t,e={}){let i=new tx(e);return i.add(t),i}let tW={watch:tk,FSWatcher:tx};export{y as chokidar_namespaceObject};
|
package/dist/client/hmr.js
CHANGED
package/dist/client/overlay.js
CHANGED
package/dist/cssUrlLoader.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import node_path from "node:path";
|
|
2
|
-
import { isCSSModules } from "./
|
|
2
|
+
import { isCSSModules } from "./c.js";
|
|
3
3
|
let HASH_PLACEHOLDER_REGEX = /\[(?:[^:\]]+:)?(?:chunkhash|contenthash|hash|fullhash)(?::[^\]]+)?]/i, getRelativePath = (root, resourcePath)=>{
|
|
4
4
|
let relativePath = node_path.relative(root, resourcePath);
|
|
5
5
|
if (relativePath && !('..' === relativePath || relativePath.startsWith(`..${node_path.sep}`)) && !node_path.isAbsolute(relativePath)) return relativePath.replace(/\\/g, '/');
|