cindel 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +675 -0
- package/README.md +546 -0
- package/dist/client/file-loader.d.ts +24 -0
- package/dist/client/file-loader.d.ts.map +1 -0
- package/dist/client/hmr-client.d.ts +185 -0
- package/dist/client/hmr-client.d.ts.map +1 -0
- package/dist/client.d.ts +3 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.iife.js +2232 -0
- package/dist/client.iife.js.map +7 -0
- package/dist/client.iife.min.js +2 -0
- package/dist/client.iife.min.js.map +7 -0
- package/dist/client.js +2221 -0
- package/dist/client.js.map +7 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1142 -0
- package/dist/index.js.map +7 -0
- package/dist/server/file-watcher.d.ts +93 -0
- package/dist/server/file-watcher.d.ts.map +1 -0
- package/dist/server/hmr-server.d.ts +378 -0
- package/dist/server/hmr-server.d.ts.map +1 -0
- package/dist/server/routes.d.ts +2 -0
- package/dist/server/routes.d.ts.map +1 -0
- package/dist/server/ws-proxy.d.ts +5 -0
- package/dist/server/ws-proxy.d.ts.map +1 -0
- package/dist/shared/constants.d.ts +24 -0
- package/dist/shared/constants.d.ts.map +1 -0
- package/dist/shared/logger.d.ts +39 -0
- package/dist/shared/logger.d.ts.map +1 -0
- package/dist/shared/utils.d.ts +13 -0
- package/dist/shared/utils.d.ts.map +1 -0
- package/package.json +64 -0
|
@@ -0,0 +1,2232 @@
|
|
|
1
|
+
var HMR = (() => {
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
9
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
10
|
+
};
|
|
11
|
+
var __export = (target, all) => {
|
|
12
|
+
for (var name in all)
|
|
13
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
14
|
+
};
|
|
15
|
+
var __copyProps = (to, from, except, desc) => {
|
|
16
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
17
|
+
for (let key of __getOwnPropNames(from))
|
|
18
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
19
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
22
|
+
};
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
24
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
25
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
26
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
27
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
28
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
29
|
+
mod
|
|
30
|
+
));
|
|
31
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
32
|
+
|
|
33
|
+
// node_modules/picomatch/lib/constants.js
|
|
34
|
+
var require_constants = __commonJS({
|
|
35
|
+
"node_modules/picomatch/lib/constants.js"(exports, module) {
|
|
36
|
+
"use strict";
|
|
37
|
+
var WIN_SLASH = "\\\\/";
|
|
38
|
+
var WIN_NO_SLASH = `[^${WIN_SLASH}]`;
|
|
39
|
+
var DOT_LITERAL = "\\.";
|
|
40
|
+
var PLUS_LITERAL = "\\+";
|
|
41
|
+
var QMARK_LITERAL = "\\?";
|
|
42
|
+
var SLASH_LITERAL = "\\/";
|
|
43
|
+
var ONE_CHAR = "(?=.)";
|
|
44
|
+
var QMARK = "[^/]";
|
|
45
|
+
var END_ANCHOR = `(?:${SLASH_LITERAL}|$)`;
|
|
46
|
+
var START_ANCHOR = `(?:^|${SLASH_LITERAL})`;
|
|
47
|
+
var DOTS_SLASH = `${DOT_LITERAL}{1,2}${END_ANCHOR}`;
|
|
48
|
+
var NO_DOT = `(?!${DOT_LITERAL})`;
|
|
49
|
+
var NO_DOTS = `(?!${START_ANCHOR}${DOTS_SLASH})`;
|
|
50
|
+
var NO_DOT_SLASH = `(?!${DOT_LITERAL}{0,1}${END_ANCHOR})`;
|
|
51
|
+
var NO_DOTS_SLASH = `(?!${DOTS_SLASH})`;
|
|
52
|
+
var QMARK_NO_DOT = `[^.${SLASH_LITERAL}]`;
|
|
53
|
+
var STAR = `${QMARK}*?`;
|
|
54
|
+
var SEP = "/";
|
|
55
|
+
var POSIX_CHARS = {
|
|
56
|
+
DOT_LITERAL,
|
|
57
|
+
PLUS_LITERAL,
|
|
58
|
+
QMARK_LITERAL,
|
|
59
|
+
SLASH_LITERAL,
|
|
60
|
+
ONE_CHAR,
|
|
61
|
+
QMARK,
|
|
62
|
+
END_ANCHOR,
|
|
63
|
+
DOTS_SLASH,
|
|
64
|
+
NO_DOT,
|
|
65
|
+
NO_DOTS,
|
|
66
|
+
NO_DOT_SLASH,
|
|
67
|
+
NO_DOTS_SLASH,
|
|
68
|
+
QMARK_NO_DOT,
|
|
69
|
+
STAR,
|
|
70
|
+
START_ANCHOR,
|
|
71
|
+
SEP
|
|
72
|
+
};
|
|
73
|
+
var WINDOWS_CHARS = {
|
|
74
|
+
...POSIX_CHARS,
|
|
75
|
+
SLASH_LITERAL: `[${WIN_SLASH}]`,
|
|
76
|
+
QMARK: WIN_NO_SLASH,
|
|
77
|
+
STAR: `${WIN_NO_SLASH}*?`,
|
|
78
|
+
DOTS_SLASH: `${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$)`,
|
|
79
|
+
NO_DOT: `(?!${DOT_LITERAL})`,
|
|
80
|
+
NO_DOTS: `(?!(?:^|[${WIN_SLASH}])${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$))`,
|
|
81
|
+
NO_DOT_SLASH: `(?!${DOT_LITERAL}{0,1}(?:[${WIN_SLASH}]|$))`,
|
|
82
|
+
NO_DOTS_SLASH: `(?!${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$))`,
|
|
83
|
+
QMARK_NO_DOT: `[^.${WIN_SLASH}]`,
|
|
84
|
+
START_ANCHOR: `(?:^|[${WIN_SLASH}])`,
|
|
85
|
+
END_ANCHOR: `(?:[${WIN_SLASH}]|$)`,
|
|
86
|
+
SEP: "\\"
|
|
87
|
+
};
|
|
88
|
+
var POSIX_REGEX_SOURCE = {
|
|
89
|
+
alnum: "a-zA-Z0-9",
|
|
90
|
+
alpha: "a-zA-Z",
|
|
91
|
+
ascii: "\\x00-\\x7F",
|
|
92
|
+
blank: " \\t",
|
|
93
|
+
cntrl: "\\x00-\\x1F\\x7F",
|
|
94
|
+
digit: "0-9",
|
|
95
|
+
graph: "\\x21-\\x7E",
|
|
96
|
+
lower: "a-z",
|
|
97
|
+
print: "\\x20-\\x7E ",
|
|
98
|
+
punct: "\\-!\"#$%&'()\\*+,./:;<=>?@[\\]^_`{|}~",
|
|
99
|
+
space: " \\t\\r\\n\\v\\f",
|
|
100
|
+
upper: "A-Z",
|
|
101
|
+
word: "A-Za-z0-9_",
|
|
102
|
+
xdigit: "A-Fa-f0-9"
|
|
103
|
+
};
|
|
104
|
+
module.exports = {
|
|
105
|
+
MAX_LENGTH: 1024 * 64,
|
|
106
|
+
POSIX_REGEX_SOURCE,
|
|
107
|
+
// regular expressions
|
|
108
|
+
REGEX_BACKSLASH: /\\(?![*+?^${}(|)[\]])/g,
|
|
109
|
+
REGEX_NON_SPECIAL_CHARS: /^[^@![\].,$*+?^{}()|\\/]+/,
|
|
110
|
+
REGEX_SPECIAL_CHARS: /[-*+?.^${}(|)[\]]/,
|
|
111
|
+
REGEX_SPECIAL_CHARS_BACKREF: /(\\?)((\W)(\3*))/g,
|
|
112
|
+
REGEX_SPECIAL_CHARS_GLOBAL: /([-*+?.^${}(|)[\]])/g,
|
|
113
|
+
REGEX_REMOVE_BACKSLASH: /(?:\[.*?[^\\]\]|\\(?=.))/g,
|
|
114
|
+
// Replace globs with equivalent patterns to reduce parsing time.
|
|
115
|
+
REPLACEMENTS: {
|
|
116
|
+
__proto__: null,
|
|
117
|
+
"***": "*",
|
|
118
|
+
"**/**": "**",
|
|
119
|
+
"**/**/**": "**"
|
|
120
|
+
},
|
|
121
|
+
// Digits
|
|
122
|
+
CHAR_0: 48,
|
|
123
|
+
/* 0 */
|
|
124
|
+
CHAR_9: 57,
|
|
125
|
+
/* 9 */
|
|
126
|
+
// Alphabet chars.
|
|
127
|
+
CHAR_UPPERCASE_A: 65,
|
|
128
|
+
/* A */
|
|
129
|
+
CHAR_LOWERCASE_A: 97,
|
|
130
|
+
/* a */
|
|
131
|
+
CHAR_UPPERCASE_Z: 90,
|
|
132
|
+
/* Z */
|
|
133
|
+
CHAR_LOWERCASE_Z: 122,
|
|
134
|
+
/* z */
|
|
135
|
+
CHAR_LEFT_PARENTHESES: 40,
|
|
136
|
+
/* ( */
|
|
137
|
+
CHAR_RIGHT_PARENTHESES: 41,
|
|
138
|
+
/* ) */
|
|
139
|
+
CHAR_ASTERISK: 42,
|
|
140
|
+
/* * */
|
|
141
|
+
// Non-alphabetic chars.
|
|
142
|
+
CHAR_AMPERSAND: 38,
|
|
143
|
+
/* & */
|
|
144
|
+
CHAR_AT: 64,
|
|
145
|
+
/* @ */
|
|
146
|
+
CHAR_BACKWARD_SLASH: 92,
|
|
147
|
+
/* \ */
|
|
148
|
+
CHAR_CARRIAGE_RETURN: 13,
|
|
149
|
+
/* \r */
|
|
150
|
+
CHAR_CIRCUMFLEX_ACCENT: 94,
|
|
151
|
+
/* ^ */
|
|
152
|
+
CHAR_COLON: 58,
|
|
153
|
+
/* : */
|
|
154
|
+
CHAR_COMMA: 44,
|
|
155
|
+
/* , */
|
|
156
|
+
CHAR_DOT: 46,
|
|
157
|
+
/* . */
|
|
158
|
+
CHAR_DOUBLE_QUOTE: 34,
|
|
159
|
+
/* " */
|
|
160
|
+
CHAR_EQUAL: 61,
|
|
161
|
+
/* = */
|
|
162
|
+
CHAR_EXCLAMATION_MARK: 33,
|
|
163
|
+
/* ! */
|
|
164
|
+
CHAR_FORM_FEED: 12,
|
|
165
|
+
/* \f */
|
|
166
|
+
CHAR_FORWARD_SLASH: 47,
|
|
167
|
+
/* / */
|
|
168
|
+
CHAR_GRAVE_ACCENT: 96,
|
|
169
|
+
/* ` */
|
|
170
|
+
CHAR_HASH: 35,
|
|
171
|
+
/* # */
|
|
172
|
+
CHAR_HYPHEN_MINUS: 45,
|
|
173
|
+
/* - */
|
|
174
|
+
CHAR_LEFT_ANGLE_BRACKET: 60,
|
|
175
|
+
/* < */
|
|
176
|
+
CHAR_LEFT_CURLY_BRACE: 123,
|
|
177
|
+
/* { */
|
|
178
|
+
CHAR_LEFT_SQUARE_BRACKET: 91,
|
|
179
|
+
/* [ */
|
|
180
|
+
CHAR_LINE_FEED: 10,
|
|
181
|
+
/* \n */
|
|
182
|
+
CHAR_NO_BREAK_SPACE: 160,
|
|
183
|
+
/* \u00A0 */
|
|
184
|
+
CHAR_PERCENT: 37,
|
|
185
|
+
/* % */
|
|
186
|
+
CHAR_PLUS: 43,
|
|
187
|
+
/* + */
|
|
188
|
+
CHAR_QUESTION_MARK: 63,
|
|
189
|
+
/* ? */
|
|
190
|
+
CHAR_RIGHT_ANGLE_BRACKET: 62,
|
|
191
|
+
/* > */
|
|
192
|
+
CHAR_RIGHT_CURLY_BRACE: 125,
|
|
193
|
+
/* } */
|
|
194
|
+
CHAR_RIGHT_SQUARE_BRACKET: 93,
|
|
195
|
+
/* ] */
|
|
196
|
+
CHAR_SEMICOLON: 59,
|
|
197
|
+
/* ; */
|
|
198
|
+
CHAR_SINGLE_QUOTE: 39,
|
|
199
|
+
/* ' */
|
|
200
|
+
CHAR_SPACE: 32,
|
|
201
|
+
/* */
|
|
202
|
+
CHAR_TAB: 9,
|
|
203
|
+
/* \t */
|
|
204
|
+
CHAR_UNDERSCORE: 95,
|
|
205
|
+
/* _ */
|
|
206
|
+
CHAR_VERTICAL_LINE: 124,
|
|
207
|
+
/* | */
|
|
208
|
+
CHAR_ZERO_WIDTH_NOBREAK_SPACE: 65279,
|
|
209
|
+
/* \uFEFF */
|
|
210
|
+
/**
|
|
211
|
+
* Create EXTGLOB_CHARS
|
|
212
|
+
*/
|
|
213
|
+
extglobChars(chars) {
|
|
214
|
+
return {
|
|
215
|
+
"!": { type: "negate", open: "(?:(?!(?:", close: `))${chars.STAR})` },
|
|
216
|
+
"?": { type: "qmark", open: "(?:", close: ")?" },
|
|
217
|
+
"+": { type: "plus", open: "(?:", close: ")+" },
|
|
218
|
+
"*": { type: "star", open: "(?:", close: ")*" },
|
|
219
|
+
"@": { type: "at", open: "(?:", close: ")" }
|
|
220
|
+
};
|
|
221
|
+
},
|
|
222
|
+
/**
|
|
223
|
+
* Create GLOB_CHARS
|
|
224
|
+
*/
|
|
225
|
+
globChars(win32) {
|
|
226
|
+
return win32 === true ? WINDOWS_CHARS : POSIX_CHARS;
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
// node_modules/picomatch/lib/utils.js
|
|
233
|
+
var require_utils = __commonJS({
|
|
234
|
+
"node_modules/picomatch/lib/utils.js"(exports) {
|
|
235
|
+
"use strict";
|
|
236
|
+
var {
|
|
237
|
+
REGEX_BACKSLASH,
|
|
238
|
+
REGEX_REMOVE_BACKSLASH,
|
|
239
|
+
REGEX_SPECIAL_CHARS,
|
|
240
|
+
REGEX_SPECIAL_CHARS_GLOBAL
|
|
241
|
+
} = require_constants();
|
|
242
|
+
exports.isObject = (val) => val !== null && typeof val === "object" && !Array.isArray(val);
|
|
243
|
+
exports.hasRegexChars = (str) => REGEX_SPECIAL_CHARS.test(str);
|
|
244
|
+
exports.isRegexChar = (str) => str.length === 1 && exports.hasRegexChars(str);
|
|
245
|
+
exports.escapeRegex = (str) => str.replace(REGEX_SPECIAL_CHARS_GLOBAL, "\\$1");
|
|
246
|
+
exports.toPosixSlashes = (str) => str.replace(REGEX_BACKSLASH, "/");
|
|
247
|
+
exports.isWindows = () => {
|
|
248
|
+
if (typeof navigator !== "undefined" && navigator.platform) {
|
|
249
|
+
const platform = navigator.platform.toLowerCase();
|
|
250
|
+
return platform === "win32" || platform === "windows";
|
|
251
|
+
}
|
|
252
|
+
if (typeof process !== "undefined" && process.platform) {
|
|
253
|
+
return process.platform === "win32";
|
|
254
|
+
}
|
|
255
|
+
return false;
|
|
256
|
+
};
|
|
257
|
+
exports.removeBackslashes = (str) => {
|
|
258
|
+
return str.replace(REGEX_REMOVE_BACKSLASH, (match) => {
|
|
259
|
+
return match === "\\" ? "" : match;
|
|
260
|
+
});
|
|
261
|
+
};
|
|
262
|
+
exports.escapeLast = (input, char, lastIdx) => {
|
|
263
|
+
const idx = input.lastIndexOf(char, lastIdx);
|
|
264
|
+
if (idx === -1) return input;
|
|
265
|
+
if (input[idx - 1] === "\\") return exports.escapeLast(input, char, idx - 1);
|
|
266
|
+
return `${input.slice(0, idx)}\\${input.slice(idx)}`;
|
|
267
|
+
};
|
|
268
|
+
exports.removePrefix = (input, state = {}) => {
|
|
269
|
+
let output = input;
|
|
270
|
+
if (output.startsWith("./")) {
|
|
271
|
+
output = output.slice(2);
|
|
272
|
+
state.prefix = "./";
|
|
273
|
+
}
|
|
274
|
+
return output;
|
|
275
|
+
};
|
|
276
|
+
exports.wrapOutput = (input, state = {}, options = {}) => {
|
|
277
|
+
const prepend = options.contains ? "" : "^";
|
|
278
|
+
const append = options.contains ? "" : "$";
|
|
279
|
+
let output = `${prepend}(?:${input})${append}`;
|
|
280
|
+
if (state.negated === true) {
|
|
281
|
+
output = `(?:^(?!${output}).*$)`;
|
|
282
|
+
}
|
|
283
|
+
return output;
|
|
284
|
+
};
|
|
285
|
+
exports.basename = (path, { windows } = {}) => {
|
|
286
|
+
const segs = path.split(windows ? /[\\/]/ : "/");
|
|
287
|
+
const last = segs[segs.length - 1];
|
|
288
|
+
if (last === "") {
|
|
289
|
+
return segs[segs.length - 2];
|
|
290
|
+
}
|
|
291
|
+
return last;
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
// node_modules/picomatch/lib/scan.js
|
|
297
|
+
var require_scan = __commonJS({
|
|
298
|
+
"node_modules/picomatch/lib/scan.js"(exports, module) {
|
|
299
|
+
"use strict";
|
|
300
|
+
var utils = require_utils();
|
|
301
|
+
var {
|
|
302
|
+
CHAR_ASTERISK,
|
|
303
|
+
/* * */
|
|
304
|
+
CHAR_AT,
|
|
305
|
+
/* @ */
|
|
306
|
+
CHAR_BACKWARD_SLASH,
|
|
307
|
+
/* \ */
|
|
308
|
+
CHAR_COMMA,
|
|
309
|
+
/* , */
|
|
310
|
+
CHAR_DOT,
|
|
311
|
+
/* . */
|
|
312
|
+
CHAR_EXCLAMATION_MARK,
|
|
313
|
+
/* ! */
|
|
314
|
+
CHAR_FORWARD_SLASH,
|
|
315
|
+
/* / */
|
|
316
|
+
CHAR_LEFT_CURLY_BRACE,
|
|
317
|
+
/* { */
|
|
318
|
+
CHAR_LEFT_PARENTHESES,
|
|
319
|
+
/* ( */
|
|
320
|
+
CHAR_LEFT_SQUARE_BRACKET,
|
|
321
|
+
/* [ */
|
|
322
|
+
CHAR_PLUS,
|
|
323
|
+
/* + */
|
|
324
|
+
CHAR_QUESTION_MARK,
|
|
325
|
+
/* ? */
|
|
326
|
+
CHAR_RIGHT_CURLY_BRACE,
|
|
327
|
+
/* } */
|
|
328
|
+
CHAR_RIGHT_PARENTHESES,
|
|
329
|
+
/* ) */
|
|
330
|
+
CHAR_RIGHT_SQUARE_BRACKET
|
|
331
|
+
/* ] */
|
|
332
|
+
} = require_constants();
|
|
333
|
+
var isPathSeparator = (code) => {
|
|
334
|
+
return code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH;
|
|
335
|
+
};
|
|
336
|
+
var depth = (token) => {
|
|
337
|
+
if (token.isPrefix !== true) {
|
|
338
|
+
token.depth = token.isGlobstar ? Infinity : 1;
|
|
339
|
+
}
|
|
340
|
+
};
|
|
341
|
+
var scan = (input, options) => {
|
|
342
|
+
const opts = options || {};
|
|
343
|
+
const length = input.length - 1;
|
|
344
|
+
const scanToEnd = opts.parts === true || opts.scanToEnd === true;
|
|
345
|
+
const slashes = [];
|
|
346
|
+
const tokens = [];
|
|
347
|
+
const parts = [];
|
|
348
|
+
let str = input;
|
|
349
|
+
let index = -1;
|
|
350
|
+
let start = 0;
|
|
351
|
+
let lastIndex = 0;
|
|
352
|
+
let isBrace = false;
|
|
353
|
+
let isBracket = false;
|
|
354
|
+
let isGlob = false;
|
|
355
|
+
let isExtglob = false;
|
|
356
|
+
let isGlobstar = false;
|
|
357
|
+
let braceEscaped = false;
|
|
358
|
+
let backslashes = false;
|
|
359
|
+
let negated = false;
|
|
360
|
+
let negatedExtglob = false;
|
|
361
|
+
let finished = false;
|
|
362
|
+
let braces = 0;
|
|
363
|
+
let prev;
|
|
364
|
+
let code;
|
|
365
|
+
let token = { value: "", depth: 0, isGlob: false };
|
|
366
|
+
const eos = () => index >= length;
|
|
367
|
+
const peek = () => str.charCodeAt(index + 1);
|
|
368
|
+
const advance = () => {
|
|
369
|
+
prev = code;
|
|
370
|
+
return str.charCodeAt(++index);
|
|
371
|
+
};
|
|
372
|
+
while (index < length) {
|
|
373
|
+
code = advance();
|
|
374
|
+
let next;
|
|
375
|
+
if (code === CHAR_BACKWARD_SLASH) {
|
|
376
|
+
backslashes = token.backslashes = true;
|
|
377
|
+
code = advance();
|
|
378
|
+
if (code === CHAR_LEFT_CURLY_BRACE) {
|
|
379
|
+
braceEscaped = true;
|
|
380
|
+
}
|
|
381
|
+
continue;
|
|
382
|
+
}
|
|
383
|
+
if (braceEscaped === true || code === CHAR_LEFT_CURLY_BRACE) {
|
|
384
|
+
braces++;
|
|
385
|
+
while (eos() !== true && (code = advance())) {
|
|
386
|
+
if (code === CHAR_BACKWARD_SLASH) {
|
|
387
|
+
backslashes = token.backslashes = true;
|
|
388
|
+
advance();
|
|
389
|
+
continue;
|
|
390
|
+
}
|
|
391
|
+
if (code === CHAR_LEFT_CURLY_BRACE) {
|
|
392
|
+
braces++;
|
|
393
|
+
continue;
|
|
394
|
+
}
|
|
395
|
+
if (braceEscaped !== true && code === CHAR_DOT && (code = advance()) === CHAR_DOT) {
|
|
396
|
+
isBrace = token.isBrace = true;
|
|
397
|
+
isGlob = token.isGlob = true;
|
|
398
|
+
finished = true;
|
|
399
|
+
if (scanToEnd === true) {
|
|
400
|
+
continue;
|
|
401
|
+
}
|
|
402
|
+
break;
|
|
403
|
+
}
|
|
404
|
+
if (braceEscaped !== true && code === CHAR_COMMA) {
|
|
405
|
+
isBrace = token.isBrace = true;
|
|
406
|
+
isGlob = token.isGlob = true;
|
|
407
|
+
finished = true;
|
|
408
|
+
if (scanToEnd === true) {
|
|
409
|
+
continue;
|
|
410
|
+
}
|
|
411
|
+
break;
|
|
412
|
+
}
|
|
413
|
+
if (code === CHAR_RIGHT_CURLY_BRACE) {
|
|
414
|
+
braces--;
|
|
415
|
+
if (braces === 0) {
|
|
416
|
+
braceEscaped = false;
|
|
417
|
+
isBrace = token.isBrace = true;
|
|
418
|
+
finished = true;
|
|
419
|
+
break;
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
if (scanToEnd === true) {
|
|
424
|
+
continue;
|
|
425
|
+
}
|
|
426
|
+
break;
|
|
427
|
+
}
|
|
428
|
+
if (code === CHAR_FORWARD_SLASH) {
|
|
429
|
+
slashes.push(index);
|
|
430
|
+
tokens.push(token);
|
|
431
|
+
token = { value: "", depth: 0, isGlob: false };
|
|
432
|
+
if (finished === true) continue;
|
|
433
|
+
if (prev === CHAR_DOT && index === start + 1) {
|
|
434
|
+
start += 2;
|
|
435
|
+
continue;
|
|
436
|
+
}
|
|
437
|
+
lastIndex = index + 1;
|
|
438
|
+
continue;
|
|
439
|
+
}
|
|
440
|
+
if (opts.noext !== true) {
|
|
441
|
+
const isExtglobChar = code === CHAR_PLUS || code === CHAR_AT || code === CHAR_ASTERISK || code === CHAR_QUESTION_MARK || code === CHAR_EXCLAMATION_MARK;
|
|
442
|
+
if (isExtglobChar === true && peek() === CHAR_LEFT_PARENTHESES) {
|
|
443
|
+
isGlob = token.isGlob = true;
|
|
444
|
+
isExtglob = token.isExtglob = true;
|
|
445
|
+
finished = true;
|
|
446
|
+
if (code === CHAR_EXCLAMATION_MARK && index === start) {
|
|
447
|
+
negatedExtglob = true;
|
|
448
|
+
}
|
|
449
|
+
if (scanToEnd === true) {
|
|
450
|
+
while (eos() !== true && (code = advance())) {
|
|
451
|
+
if (code === CHAR_BACKWARD_SLASH) {
|
|
452
|
+
backslashes = token.backslashes = true;
|
|
453
|
+
code = advance();
|
|
454
|
+
continue;
|
|
455
|
+
}
|
|
456
|
+
if (code === CHAR_RIGHT_PARENTHESES) {
|
|
457
|
+
isGlob = token.isGlob = true;
|
|
458
|
+
finished = true;
|
|
459
|
+
break;
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
continue;
|
|
463
|
+
}
|
|
464
|
+
break;
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
if (code === CHAR_ASTERISK) {
|
|
468
|
+
if (prev === CHAR_ASTERISK) isGlobstar = token.isGlobstar = true;
|
|
469
|
+
isGlob = token.isGlob = true;
|
|
470
|
+
finished = true;
|
|
471
|
+
if (scanToEnd === true) {
|
|
472
|
+
continue;
|
|
473
|
+
}
|
|
474
|
+
break;
|
|
475
|
+
}
|
|
476
|
+
if (code === CHAR_QUESTION_MARK) {
|
|
477
|
+
isGlob = token.isGlob = true;
|
|
478
|
+
finished = true;
|
|
479
|
+
if (scanToEnd === true) {
|
|
480
|
+
continue;
|
|
481
|
+
}
|
|
482
|
+
break;
|
|
483
|
+
}
|
|
484
|
+
if (code === CHAR_LEFT_SQUARE_BRACKET) {
|
|
485
|
+
while (eos() !== true && (next = advance())) {
|
|
486
|
+
if (next === CHAR_BACKWARD_SLASH) {
|
|
487
|
+
backslashes = token.backslashes = true;
|
|
488
|
+
advance();
|
|
489
|
+
continue;
|
|
490
|
+
}
|
|
491
|
+
if (next === CHAR_RIGHT_SQUARE_BRACKET) {
|
|
492
|
+
isBracket = token.isBracket = true;
|
|
493
|
+
isGlob = token.isGlob = true;
|
|
494
|
+
finished = true;
|
|
495
|
+
break;
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
if (scanToEnd === true) {
|
|
499
|
+
continue;
|
|
500
|
+
}
|
|
501
|
+
break;
|
|
502
|
+
}
|
|
503
|
+
if (opts.nonegate !== true && code === CHAR_EXCLAMATION_MARK && index === start) {
|
|
504
|
+
negated = token.negated = true;
|
|
505
|
+
start++;
|
|
506
|
+
continue;
|
|
507
|
+
}
|
|
508
|
+
if (opts.noparen !== true && code === CHAR_LEFT_PARENTHESES) {
|
|
509
|
+
isGlob = token.isGlob = true;
|
|
510
|
+
if (scanToEnd === true) {
|
|
511
|
+
while (eos() !== true && (code = advance())) {
|
|
512
|
+
if (code === CHAR_LEFT_PARENTHESES) {
|
|
513
|
+
backslashes = token.backslashes = true;
|
|
514
|
+
code = advance();
|
|
515
|
+
continue;
|
|
516
|
+
}
|
|
517
|
+
if (code === CHAR_RIGHT_PARENTHESES) {
|
|
518
|
+
finished = true;
|
|
519
|
+
break;
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
continue;
|
|
523
|
+
}
|
|
524
|
+
break;
|
|
525
|
+
}
|
|
526
|
+
if (isGlob === true) {
|
|
527
|
+
finished = true;
|
|
528
|
+
if (scanToEnd === true) {
|
|
529
|
+
continue;
|
|
530
|
+
}
|
|
531
|
+
break;
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
if (opts.noext === true) {
|
|
535
|
+
isExtglob = false;
|
|
536
|
+
isGlob = false;
|
|
537
|
+
}
|
|
538
|
+
let base = str;
|
|
539
|
+
let prefix = "";
|
|
540
|
+
let glob = "";
|
|
541
|
+
if (start > 0) {
|
|
542
|
+
prefix = str.slice(0, start);
|
|
543
|
+
str = str.slice(start);
|
|
544
|
+
lastIndex -= start;
|
|
545
|
+
}
|
|
546
|
+
if (base && isGlob === true && lastIndex > 0) {
|
|
547
|
+
base = str.slice(0, lastIndex);
|
|
548
|
+
glob = str.slice(lastIndex);
|
|
549
|
+
} else if (isGlob === true) {
|
|
550
|
+
base = "";
|
|
551
|
+
glob = str;
|
|
552
|
+
} else {
|
|
553
|
+
base = str;
|
|
554
|
+
}
|
|
555
|
+
if (base && base !== "" && base !== "/" && base !== str) {
|
|
556
|
+
if (isPathSeparator(base.charCodeAt(base.length - 1))) {
|
|
557
|
+
base = base.slice(0, -1);
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
if (opts.unescape === true) {
|
|
561
|
+
if (glob) glob = utils.removeBackslashes(glob);
|
|
562
|
+
if (base && backslashes === true) {
|
|
563
|
+
base = utils.removeBackslashes(base);
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
const state = {
|
|
567
|
+
prefix,
|
|
568
|
+
input,
|
|
569
|
+
start,
|
|
570
|
+
base,
|
|
571
|
+
glob,
|
|
572
|
+
isBrace,
|
|
573
|
+
isBracket,
|
|
574
|
+
isGlob,
|
|
575
|
+
isExtglob,
|
|
576
|
+
isGlobstar,
|
|
577
|
+
negated,
|
|
578
|
+
negatedExtglob
|
|
579
|
+
};
|
|
580
|
+
if (opts.tokens === true) {
|
|
581
|
+
state.maxDepth = 0;
|
|
582
|
+
if (!isPathSeparator(code)) {
|
|
583
|
+
tokens.push(token);
|
|
584
|
+
}
|
|
585
|
+
state.tokens = tokens;
|
|
586
|
+
}
|
|
587
|
+
if (opts.parts === true || opts.tokens === true) {
|
|
588
|
+
let prevIndex;
|
|
589
|
+
for (let idx = 0; idx < slashes.length; idx++) {
|
|
590
|
+
const n = prevIndex ? prevIndex + 1 : start;
|
|
591
|
+
const i = slashes[idx];
|
|
592
|
+
const value = input.slice(n, i);
|
|
593
|
+
if (opts.tokens) {
|
|
594
|
+
if (idx === 0 && start !== 0) {
|
|
595
|
+
tokens[idx].isPrefix = true;
|
|
596
|
+
tokens[idx].value = prefix;
|
|
597
|
+
} else {
|
|
598
|
+
tokens[idx].value = value;
|
|
599
|
+
}
|
|
600
|
+
depth(tokens[idx]);
|
|
601
|
+
state.maxDepth += tokens[idx].depth;
|
|
602
|
+
}
|
|
603
|
+
if (idx !== 0 || value !== "") {
|
|
604
|
+
parts.push(value);
|
|
605
|
+
}
|
|
606
|
+
prevIndex = i;
|
|
607
|
+
}
|
|
608
|
+
if (prevIndex && prevIndex + 1 < input.length) {
|
|
609
|
+
const value = input.slice(prevIndex + 1);
|
|
610
|
+
parts.push(value);
|
|
611
|
+
if (opts.tokens) {
|
|
612
|
+
tokens[tokens.length - 1].value = value;
|
|
613
|
+
depth(tokens[tokens.length - 1]);
|
|
614
|
+
state.maxDepth += tokens[tokens.length - 1].depth;
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
state.slashes = slashes;
|
|
618
|
+
state.parts = parts;
|
|
619
|
+
}
|
|
620
|
+
return state;
|
|
621
|
+
};
|
|
622
|
+
module.exports = scan;
|
|
623
|
+
}
|
|
624
|
+
});
|
|
625
|
+
|
|
626
|
+
// node_modules/picomatch/lib/parse.js
|
|
627
|
+
var require_parse = __commonJS({
|
|
628
|
+
"node_modules/picomatch/lib/parse.js"(exports, module) {
|
|
629
|
+
"use strict";
|
|
630
|
+
var constants = require_constants();
|
|
631
|
+
var utils = require_utils();
|
|
632
|
+
var {
|
|
633
|
+
MAX_LENGTH,
|
|
634
|
+
POSIX_REGEX_SOURCE,
|
|
635
|
+
REGEX_NON_SPECIAL_CHARS,
|
|
636
|
+
REGEX_SPECIAL_CHARS_BACKREF,
|
|
637
|
+
REPLACEMENTS
|
|
638
|
+
} = constants;
|
|
639
|
+
var expandRange = (args, options) => {
|
|
640
|
+
if (typeof options.expandRange === "function") {
|
|
641
|
+
return options.expandRange(...args, options);
|
|
642
|
+
}
|
|
643
|
+
args.sort();
|
|
644
|
+
const value = `[${args.join("-")}]`;
|
|
645
|
+
try {
|
|
646
|
+
new RegExp(value);
|
|
647
|
+
} catch (ex) {
|
|
648
|
+
return args.map((v) => utils.escapeRegex(v)).join("..");
|
|
649
|
+
}
|
|
650
|
+
return value;
|
|
651
|
+
};
|
|
652
|
+
var syntaxError = (type, char) => {
|
|
653
|
+
return `Missing ${type}: "${char}" - use "\\\\${char}" to match literal characters`;
|
|
654
|
+
};
|
|
655
|
+
var parse = (input, options) => {
|
|
656
|
+
if (typeof input !== "string") {
|
|
657
|
+
throw new TypeError("Expected a string");
|
|
658
|
+
}
|
|
659
|
+
input = REPLACEMENTS[input] || input;
|
|
660
|
+
const opts = { ...options };
|
|
661
|
+
const max = typeof opts.maxLength === "number" ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
|
|
662
|
+
let len = input.length;
|
|
663
|
+
if (len > max) {
|
|
664
|
+
throw new SyntaxError(`Input length: ${len}, exceeds maximum allowed length: ${max}`);
|
|
665
|
+
}
|
|
666
|
+
const bos = { type: "bos", value: "", output: opts.prepend || "" };
|
|
667
|
+
const tokens = [bos];
|
|
668
|
+
const capture = opts.capture ? "" : "?:";
|
|
669
|
+
const PLATFORM_CHARS = constants.globChars(opts.windows);
|
|
670
|
+
const EXTGLOB_CHARS = constants.extglobChars(PLATFORM_CHARS);
|
|
671
|
+
const {
|
|
672
|
+
DOT_LITERAL,
|
|
673
|
+
PLUS_LITERAL,
|
|
674
|
+
SLASH_LITERAL,
|
|
675
|
+
ONE_CHAR,
|
|
676
|
+
DOTS_SLASH,
|
|
677
|
+
NO_DOT,
|
|
678
|
+
NO_DOT_SLASH,
|
|
679
|
+
NO_DOTS_SLASH,
|
|
680
|
+
QMARK,
|
|
681
|
+
QMARK_NO_DOT,
|
|
682
|
+
STAR,
|
|
683
|
+
START_ANCHOR
|
|
684
|
+
} = PLATFORM_CHARS;
|
|
685
|
+
const globstar = (opts2) => {
|
|
686
|
+
return `(${capture}(?:(?!${START_ANCHOR}${opts2.dot ? DOTS_SLASH : DOT_LITERAL}).)*?)`;
|
|
687
|
+
};
|
|
688
|
+
const nodot = opts.dot ? "" : NO_DOT;
|
|
689
|
+
const qmarkNoDot = opts.dot ? QMARK : QMARK_NO_DOT;
|
|
690
|
+
let star = opts.bash === true ? globstar(opts) : STAR;
|
|
691
|
+
if (opts.capture) {
|
|
692
|
+
star = `(${star})`;
|
|
693
|
+
}
|
|
694
|
+
if (typeof opts.noext === "boolean") {
|
|
695
|
+
opts.noextglob = opts.noext;
|
|
696
|
+
}
|
|
697
|
+
const state = {
|
|
698
|
+
input,
|
|
699
|
+
index: -1,
|
|
700
|
+
start: 0,
|
|
701
|
+
dot: opts.dot === true,
|
|
702
|
+
consumed: "",
|
|
703
|
+
output: "",
|
|
704
|
+
prefix: "",
|
|
705
|
+
backtrack: false,
|
|
706
|
+
negated: false,
|
|
707
|
+
brackets: 0,
|
|
708
|
+
braces: 0,
|
|
709
|
+
parens: 0,
|
|
710
|
+
quotes: 0,
|
|
711
|
+
globstar: false,
|
|
712
|
+
tokens
|
|
713
|
+
};
|
|
714
|
+
input = utils.removePrefix(input, state);
|
|
715
|
+
len = input.length;
|
|
716
|
+
const extglobs = [];
|
|
717
|
+
const braces = [];
|
|
718
|
+
const stack = [];
|
|
719
|
+
let prev = bos;
|
|
720
|
+
let value;
|
|
721
|
+
const eos = () => state.index === len - 1;
|
|
722
|
+
const peek = state.peek = (n = 1) => input[state.index + n];
|
|
723
|
+
const advance = state.advance = () => input[++state.index] || "";
|
|
724
|
+
const remaining = () => input.slice(state.index + 1);
|
|
725
|
+
const consume = (value2 = "", num = 0) => {
|
|
726
|
+
state.consumed += value2;
|
|
727
|
+
state.index += num;
|
|
728
|
+
};
|
|
729
|
+
const append = (token) => {
|
|
730
|
+
state.output += token.output != null ? token.output : token.value;
|
|
731
|
+
consume(token.value);
|
|
732
|
+
};
|
|
733
|
+
const negate = () => {
|
|
734
|
+
let count = 1;
|
|
735
|
+
while (peek() === "!" && (peek(2) !== "(" || peek(3) === "?")) {
|
|
736
|
+
advance();
|
|
737
|
+
state.start++;
|
|
738
|
+
count++;
|
|
739
|
+
}
|
|
740
|
+
if (count % 2 === 0) {
|
|
741
|
+
return false;
|
|
742
|
+
}
|
|
743
|
+
state.negated = true;
|
|
744
|
+
state.start++;
|
|
745
|
+
return true;
|
|
746
|
+
};
|
|
747
|
+
const increment = (type) => {
|
|
748
|
+
state[type]++;
|
|
749
|
+
stack.push(type);
|
|
750
|
+
};
|
|
751
|
+
const decrement = (type) => {
|
|
752
|
+
state[type]--;
|
|
753
|
+
stack.pop();
|
|
754
|
+
};
|
|
755
|
+
const push = (tok) => {
|
|
756
|
+
if (prev.type === "globstar") {
|
|
757
|
+
const isBrace = state.braces > 0 && (tok.type === "comma" || tok.type === "brace");
|
|
758
|
+
const isExtglob = tok.extglob === true || extglobs.length && (tok.type === "pipe" || tok.type === "paren");
|
|
759
|
+
if (tok.type !== "slash" && tok.type !== "paren" && !isBrace && !isExtglob) {
|
|
760
|
+
state.output = state.output.slice(0, -prev.output.length);
|
|
761
|
+
prev.type = "star";
|
|
762
|
+
prev.value = "*";
|
|
763
|
+
prev.output = star;
|
|
764
|
+
state.output += prev.output;
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
if (extglobs.length && tok.type !== "paren") {
|
|
768
|
+
extglobs[extglobs.length - 1].inner += tok.value;
|
|
769
|
+
}
|
|
770
|
+
if (tok.value || tok.output) append(tok);
|
|
771
|
+
if (prev && prev.type === "text" && tok.type === "text") {
|
|
772
|
+
prev.output = (prev.output || prev.value) + tok.value;
|
|
773
|
+
prev.value += tok.value;
|
|
774
|
+
return;
|
|
775
|
+
}
|
|
776
|
+
tok.prev = prev;
|
|
777
|
+
tokens.push(tok);
|
|
778
|
+
prev = tok;
|
|
779
|
+
};
|
|
780
|
+
const extglobOpen = (type, value2) => {
|
|
781
|
+
const token = { ...EXTGLOB_CHARS[value2], conditions: 1, inner: "" };
|
|
782
|
+
token.prev = prev;
|
|
783
|
+
token.parens = state.parens;
|
|
784
|
+
token.output = state.output;
|
|
785
|
+
const output = (opts.capture ? "(" : "") + token.open;
|
|
786
|
+
increment("parens");
|
|
787
|
+
push({ type, value: value2, output: state.output ? "" : ONE_CHAR });
|
|
788
|
+
push({ type: "paren", extglob: true, value: advance(), output });
|
|
789
|
+
extglobs.push(token);
|
|
790
|
+
};
|
|
791
|
+
const extglobClose = (token) => {
|
|
792
|
+
let output = token.close + (opts.capture ? ")" : "");
|
|
793
|
+
let rest;
|
|
794
|
+
if (token.type === "negate") {
|
|
795
|
+
let extglobStar = star;
|
|
796
|
+
if (token.inner && token.inner.length > 1 && token.inner.includes("/")) {
|
|
797
|
+
extglobStar = globstar(opts);
|
|
798
|
+
}
|
|
799
|
+
if (extglobStar !== star || eos() || /^\)+$/.test(remaining())) {
|
|
800
|
+
output = token.close = `)$))${extglobStar}`;
|
|
801
|
+
}
|
|
802
|
+
if (token.inner.includes("*") && (rest = remaining()) && /^\.[^\\/.]+$/.test(rest)) {
|
|
803
|
+
const expression = parse(rest, { ...options, fastpaths: false }).output;
|
|
804
|
+
output = token.close = `)${expression})${extglobStar})`;
|
|
805
|
+
}
|
|
806
|
+
if (token.prev.type === "bos") {
|
|
807
|
+
state.negatedExtglob = true;
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
push({ type: "paren", extglob: true, value, output });
|
|
811
|
+
decrement("parens");
|
|
812
|
+
};
|
|
813
|
+
if (opts.fastpaths !== false && !/(^[*!]|[/()[\]{}"])/.test(input)) {
|
|
814
|
+
let backslashes = false;
|
|
815
|
+
let output = input.replace(REGEX_SPECIAL_CHARS_BACKREF, (m, esc, chars, first, rest, index) => {
|
|
816
|
+
if (first === "\\") {
|
|
817
|
+
backslashes = true;
|
|
818
|
+
return m;
|
|
819
|
+
}
|
|
820
|
+
if (first === "?") {
|
|
821
|
+
if (esc) {
|
|
822
|
+
return esc + first + (rest ? QMARK.repeat(rest.length) : "");
|
|
823
|
+
}
|
|
824
|
+
if (index === 0) {
|
|
825
|
+
return qmarkNoDot + (rest ? QMARK.repeat(rest.length) : "");
|
|
826
|
+
}
|
|
827
|
+
return QMARK.repeat(chars.length);
|
|
828
|
+
}
|
|
829
|
+
if (first === ".") {
|
|
830
|
+
return DOT_LITERAL.repeat(chars.length);
|
|
831
|
+
}
|
|
832
|
+
if (first === "*") {
|
|
833
|
+
if (esc) {
|
|
834
|
+
return esc + first + (rest ? star : "");
|
|
835
|
+
}
|
|
836
|
+
return star;
|
|
837
|
+
}
|
|
838
|
+
return esc ? m : `\\${m}`;
|
|
839
|
+
});
|
|
840
|
+
if (backslashes === true) {
|
|
841
|
+
if (opts.unescape === true) {
|
|
842
|
+
output = output.replace(/\\/g, "");
|
|
843
|
+
} else {
|
|
844
|
+
output = output.replace(/\\+/g, (m) => {
|
|
845
|
+
return m.length % 2 === 0 ? "\\\\" : m ? "\\" : "";
|
|
846
|
+
});
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
if (output === input && opts.contains === true) {
|
|
850
|
+
state.output = input;
|
|
851
|
+
return state;
|
|
852
|
+
}
|
|
853
|
+
state.output = utils.wrapOutput(output, state, options);
|
|
854
|
+
return state;
|
|
855
|
+
}
|
|
856
|
+
while (!eos()) {
|
|
857
|
+
value = advance();
|
|
858
|
+
if (value === "\0") {
|
|
859
|
+
continue;
|
|
860
|
+
}
|
|
861
|
+
if (value === "\\") {
|
|
862
|
+
const next = peek();
|
|
863
|
+
if (next === "/" && opts.bash !== true) {
|
|
864
|
+
continue;
|
|
865
|
+
}
|
|
866
|
+
if (next === "." || next === ";") {
|
|
867
|
+
continue;
|
|
868
|
+
}
|
|
869
|
+
if (!next) {
|
|
870
|
+
value += "\\";
|
|
871
|
+
push({ type: "text", value });
|
|
872
|
+
continue;
|
|
873
|
+
}
|
|
874
|
+
const match = /^\\+/.exec(remaining());
|
|
875
|
+
let slashes = 0;
|
|
876
|
+
if (match && match[0].length > 2) {
|
|
877
|
+
slashes = match[0].length;
|
|
878
|
+
state.index += slashes;
|
|
879
|
+
if (slashes % 2 !== 0) {
|
|
880
|
+
value += "\\";
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
if (opts.unescape === true) {
|
|
884
|
+
value = advance();
|
|
885
|
+
} else {
|
|
886
|
+
value += advance();
|
|
887
|
+
}
|
|
888
|
+
if (state.brackets === 0) {
|
|
889
|
+
push({ type: "text", value });
|
|
890
|
+
continue;
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
if (state.brackets > 0 && (value !== "]" || prev.value === "[" || prev.value === "[^")) {
|
|
894
|
+
if (opts.posix !== false && value === ":") {
|
|
895
|
+
const inner = prev.value.slice(1);
|
|
896
|
+
if (inner.includes("[")) {
|
|
897
|
+
prev.posix = true;
|
|
898
|
+
if (inner.includes(":")) {
|
|
899
|
+
const idx = prev.value.lastIndexOf("[");
|
|
900
|
+
const pre = prev.value.slice(0, idx);
|
|
901
|
+
const rest2 = prev.value.slice(idx + 2);
|
|
902
|
+
const posix = POSIX_REGEX_SOURCE[rest2];
|
|
903
|
+
if (posix) {
|
|
904
|
+
prev.value = pre + posix;
|
|
905
|
+
state.backtrack = true;
|
|
906
|
+
advance();
|
|
907
|
+
if (!bos.output && tokens.indexOf(prev) === 1) {
|
|
908
|
+
bos.output = ONE_CHAR;
|
|
909
|
+
}
|
|
910
|
+
continue;
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
if (value === "[" && peek() !== ":" || value === "-" && peek() === "]") {
|
|
916
|
+
value = `\\${value}`;
|
|
917
|
+
}
|
|
918
|
+
if (value === "]" && (prev.value === "[" || prev.value === "[^")) {
|
|
919
|
+
value = `\\${value}`;
|
|
920
|
+
}
|
|
921
|
+
if (opts.posix === true && value === "!" && prev.value === "[") {
|
|
922
|
+
value = "^";
|
|
923
|
+
}
|
|
924
|
+
prev.value += value;
|
|
925
|
+
append({ value });
|
|
926
|
+
continue;
|
|
927
|
+
}
|
|
928
|
+
if (state.quotes === 1 && value !== '"') {
|
|
929
|
+
value = utils.escapeRegex(value);
|
|
930
|
+
prev.value += value;
|
|
931
|
+
append({ value });
|
|
932
|
+
continue;
|
|
933
|
+
}
|
|
934
|
+
if (value === '"') {
|
|
935
|
+
state.quotes = state.quotes === 1 ? 0 : 1;
|
|
936
|
+
if (opts.keepQuotes === true) {
|
|
937
|
+
push({ type: "text", value });
|
|
938
|
+
}
|
|
939
|
+
continue;
|
|
940
|
+
}
|
|
941
|
+
if (value === "(") {
|
|
942
|
+
increment("parens");
|
|
943
|
+
push({ type: "paren", value });
|
|
944
|
+
continue;
|
|
945
|
+
}
|
|
946
|
+
if (value === ")") {
|
|
947
|
+
if (state.parens === 0 && opts.strictBrackets === true) {
|
|
948
|
+
throw new SyntaxError(syntaxError("opening", "("));
|
|
949
|
+
}
|
|
950
|
+
const extglob = extglobs[extglobs.length - 1];
|
|
951
|
+
if (extglob && state.parens === extglob.parens + 1) {
|
|
952
|
+
extglobClose(extglobs.pop());
|
|
953
|
+
continue;
|
|
954
|
+
}
|
|
955
|
+
push({ type: "paren", value, output: state.parens ? ")" : "\\)" });
|
|
956
|
+
decrement("parens");
|
|
957
|
+
continue;
|
|
958
|
+
}
|
|
959
|
+
if (value === "[") {
|
|
960
|
+
if (opts.nobracket === true || !remaining().includes("]")) {
|
|
961
|
+
if (opts.nobracket !== true && opts.strictBrackets === true) {
|
|
962
|
+
throw new SyntaxError(syntaxError("closing", "]"));
|
|
963
|
+
}
|
|
964
|
+
value = `\\${value}`;
|
|
965
|
+
} else {
|
|
966
|
+
increment("brackets");
|
|
967
|
+
}
|
|
968
|
+
push({ type: "bracket", value });
|
|
969
|
+
continue;
|
|
970
|
+
}
|
|
971
|
+
if (value === "]") {
|
|
972
|
+
if (opts.nobracket === true || prev && prev.type === "bracket" && prev.value.length === 1) {
|
|
973
|
+
push({ type: "text", value, output: `\\${value}` });
|
|
974
|
+
continue;
|
|
975
|
+
}
|
|
976
|
+
if (state.brackets === 0) {
|
|
977
|
+
if (opts.strictBrackets === true) {
|
|
978
|
+
throw new SyntaxError(syntaxError("opening", "["));
|
|
979
|
+
}
|
|
980
|
+
push({ type: "text", value, output: `\\${value}` });
|
|
981
|
+
continue;
|
|
982
|
+
}
|
|
983
|
+
decrement("brackets");
|
|
984
|
+
const prevValue = prev.value.slice(1);
|
|
985
|
+
if (prev.posix !== true && prevValue[0] === "^" && !prevValue.includes("/")) {
|
|
986
|
+
value = `/${value}`;
|
|
987
|
+
}
|
|
988
|
+
prev.value += value;
|
|
989
|
+
append({ value });
|
|
990
|
+
if (opts.literalBrackets === false || utils.hasRegexChars(prevValue)) {
|
|
991
|
+
continue;
|
|
992
|
+
}
|
|
993
|
+
const escaped = utils.escapeRegex(prev.value);
|
|
994
|
+
state.output = state.output.slice(0, -prev.value.length);
|
|
995
|
+
if (opts.literalBrackets === true) {
|
|
996
|
+
state.output += escaped;
|
|
997
|
+
prev.value = escaped;
|
|
998
|
+
continue;
|
|
999
|
+
}
|
|
1000
|
+
prev.value = `(${capture}${escaped}|${prev.value})`;
|
|
1001
|
+
state.output += prev.value;
|
|
1002
|
+
continue;
|
|
1003
|
+
}
|
|
1004
|
+
if (value === "{" && opts.nobrace !== true) {
|
|
1005
|
+
increment("braces");
|
|
1006
|
+
const open = {
|
|
1007
|
+
type: "brace",
|
|
1008
|
+
value,
|
|
1009
|
+
output: "(",
|
|
1010
|
+
outputIndex: state.output.length,
|
|
1011
|
+
tokensIndex: state.tokens.length
|
|
1012
|
+
};
|
|
1013
|
+
braces.push(open);
|
|
1014
|
+
push(open);
|
|
1015
|
+
continue;
|
|
1016
|
+
}
|
|
1017
|
+
if (value === "}") {
|
|
1018
|
+
const brace = braces[braces.length - 1];
|
|
1019
|
+
if (opts.nobrace === true || !brace) {
|
|
1020
|
+
push({ type: "text", value, output: value });
|
|
1021
|
+
continue;
|
|
1022
|
+
}
|
|
1023
|
+
let output = ")";
|
|
1024
|
+
if (brace.dots === true) {
|
|
1025
|
+
const arr = tokens.slice();
|
|
1026
|
+
const range = [];
|
|
1027
|
+
for (let i = arr.length - 1; i >= 0; i--) {
|
|
1028
|
+
tokens.pop();
|
|
1029
|
+
if (arr[i].type === "brace") {
|
|
1030
|
+
break;
|
|
1031
|
+
}
|
|
1032
|
+
if (arr[i].type !== "dots") {
|
|
1033
|
+
range.unshift(arr[i].value);
|
|
1034
|
+
}
|
|
1035
|
+
}
|
|
1036
|
+
output = expandRange(range, opts);
|
|
1037
|
+
state.backtrack = true;
|
|
1038
|
+
}
|
|
1039
|
+
if (brace.comma !== true && brace.dots !== true) {
|
|
1040
|
+
const out = state.output.slice(0, brace.outputIndex);
|
|
1041
|
+
const toks = state.tokens.slice(brace.tokensIndex);
|
|
1042
|
+
brace.value = brace.output = "\\{";
|
|
1043
|
+
value = output = "\\}";
|
|
1044
|
+
state.output = out;
|
|
1045
|
+
for (const t of toks) {
|
|
1046
|
+
state.output += t.output || t.value;
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1049
|
+
push({ type: "brace", value, output });
|
|
1050
|
+
decrement("braces");
|
|
1051
|
+
braces.pop();
|
|
1052
|
+
continue;
|
|
1053
|
+
}
|
|
1054
|
+
if (value === "|") {
|
|
1055
|
+
if (extglobs.length > 0) {
|
|
1056
|
+
extglobs[extglobs.length - 1].conditions++;
|
|
1057
|
+
}
|
|
1058
|
+
push({ type: "text", value });
|
|
1059
|
+
continue;
|
|
1060
|
+
}
|
|
1061
|
+
if (value === ",") {
|
|
1062
|
+
let output = value;
|
|
1063
|
+
const brace = braces[braces.length - 1];
|
|
1064
|
+
if (brace && stack[stack.length - 1] === "braces") {
|
|
1065
|
+
brace.comma = true;
|
|
1066
|
+
output = "|";
|
|
1067
|
+
}
|
|
1068
|
+
push({ type: "comma", value, output });
|
|
1069
|
+
continue;
|
|
1070
|
+
}
|
|
1071
|
+
if (value === "/") {
|
|
1072
|
+
if (prev.type === "dot" && state.index === state.start + 1) {
|
|
1073
|
+
state.start = state.index + 1;
|
|
1074
|
+
state.consumed = "";
|
|
1075
|
+
state.output = "";
|
|
1076
|
+
tokens.pop();
|
|
1077
|
+
prev = bos;
|
|
1078
|
+
continue;
|
|
1079
|
+
}
|
|
1080
|
+
push({ type: "slash", value, output: SLASH_LITERAL });
|
|
1081
|
+
continue;
|
|
1082
|
+
}
|
|
1083
|
+
if (value === ".") {
|
|
1084
|
+
if (state.braces > 0 && prev.type === "dot") {
|
|
1085
|
+
if (prev.value === ".") prev.output = DOT_LITERAL;
|
|
1086
|
+
const brace = braces[braces.length - 1];
|
|
1087
|
+
prev.type = "dots";
|
|
1088
|
+
prev.output += value;
|
|
1089
|
+
prev.value += value;
|
|
1090
|
+
brace.dots = true;
|
|
1091
|
+
continue;
|
|
1092
|
+
}
|
|
1093
|
+
if (state.braces + state.parens === 0 && prev.type !== "bos" && prev.type !== "slash") {
|
|
1094
|
+
push({ type: "text", value, output: DOT_LITERAL });
|
|
1095
|
+
continue;
|
|
1096
|
+
}
|
|
1097
|
+
push({ type: "dot", value, output: DOT_LITERAL });
|
|
1098
|
+
continue;
|
|
1099
|
+
}
|
|
1100
|
+
if (value === "?") {
|
|
1101
|
+
const isGroup = prev && prev.value === "(";
|
|
1102
|
+
if (!isGroup && opts.noextglob !== true && peek() === "(" && peek(2) !== "?") {
|
|
1103
|
+
extglobOpen("qmark", value);
|
|
1104
|
+
continue;
|
|
1105
|
+
}
|
|
1106
|
+
if (prev && prev.type === "paren") {
|
|
1107
|
+
const next = peek();
|
|
1108
|
+
let output = value;
|
|
1109
|
+
if (prev.value === "(" && !/[!=<:]/.test(next) || next === "<" && !/<([!=]|\w+>)/.test(remaining())) {
|
|
1110
|
+
output = `\\${value}`;
|
|
1111
|
+
}
|
|
1112
|
+
push({ type: "text", value, output });
|
|
1113
|
+
continue;
|
|
1114
|
+
}
|
|
1115
|
+
if (opts.dot !== true && (prev.type === "slash" || prev.type === "bos")) {
|
|
1116
|
+
push({ type: "qmark", value, output: QMARK_NO_DOT });
|
|
1117
|
+
continue;
|
|
1118
|
+
}
|
|
1119
|
+
push({ type: "qmark", value, output: QMARK });
|
|
1120
|
+
continue;
|
|
1121
|
+
}
|
|
1122
|
+
if (value === "!") {
|
|
1123
|
+
if (opts.noextglob !== true && peek() === "(") {
|
|
1124
|
+
if (peek(2) !== "?" || !/[!=<:]/.test(peek(3))) {
|
|
1125
|
+
extglobOpen("negate", value);
|
|
1126
|
+
continue;
|
|
1127
|
+
}
|
|
1128
|
+
}
|
|
1129
|
+
if (opts.nonegate !== true && state.index === 0) {
|
|
1130
|
+
negate();
|
|
1131
|
+
continue;
|
|
1132
|
+
}
|
|
1133
|
+
}
|
|
1134
|
+
if (value === "+") {
|
|
1135
|
+
if (opts.noextglob !== true && peek() === "(" && peek(2) !== "?") {
|
|
1136
|
+
extglobOpen("plus", value);
|
|
1137
|
+
continue;
|
|
1138
|
+
}
|
|
1139
|
+
if (prev && prev.value === "(" || opts.regex === false) {
|
|
1140
|
+
push({ type: "plus", value, output: PLUS_LITERAL });
|
|
1141
|
+
continue;
|
|
1142
|
+
}
|
|
1143
|
+
if (prev && (prev.type === "bracket" || prev.type === "paren" || prev.type === "brace") || state.parens > 0) {
|
|
1144
|
+
push({ type: "plus", value });
|
|
1145
|
+
continue;
|
|
1146
|
+
}
|
|
1147
|
+
push({ type: "plus", value: PLUS_LITERAL });
|
|
1148
|
+
continue;
|
|
1149
|
+
}
|
|
1150
|
+
if (value === "@") {
|
|
1151
|
+
if (opts.noextglob !== true && peek() === "(" && peek(2) !== "?") {
|
|
1152
|
+
push({ type: "at", extglob: true, value, output: "" });
|
|
1153
|
+
continue;
|
|
1154
|
+
}
|
|
1155
|
+
push({ type: "text", value });
|
|
1156
|
+
continue;
|
|
1157
|
+
}
|
|
1158
|
+
if (value !== "*") {
|
|
1159
|
+
if (value === "$" || value === "^") {
|
|
1160
|
+
value = `\\${value}`;
|
|
1161
|
+
}
|
|
1162
|
+
const match = REGEX_NON_SPECIAL_CHARS.exec(remaining());
|
|
1163
|
+
if (match) {
|
|
1164
|
+
value += match[0];
|
|
1165
|
+
state.index += match[0].length;
|
|
1166
|
+
}
|
|
1167
|
+
push({ type: "text", value });
|
|
1168
|
+
continue;
|
|
1169
|
+
}
|
|
1170
|
+
if (prev && (prev.type === "globstar" || prev.star === true)) {
|
|
1171
|
+
prev.type = "star";
|
|
1172
|
+
prev.star = true;
|
|
1173
|
+
prev.value += value;
|
|
1174
|
+
prev.output = star;
|
|
1175
|
+
state.backtrack = true;
|
|
1176
|
+
state.globstar = true;
|
|
1177
|
+
consume(value);
|
|
1178
|
+
continue;
|
|
1179
|
+
}
|
|
1180
|
+
let rest = remaining();
|
|
1181
|
+
if (opts.noextglob !== true && /^\([^?]/.test(rest)) {
|
|
1182
|
+
extglobOpen("star", value);
|
|
1183
|
+
continue;
|
|
1184
|
+
}
|
|
1185
|
+
if (prev.type === "star") {
|
|
1186
|
+
if (opts.noglobstar === true) {
|
|
1187
|
+
consume(value);
|
|
1188
|
+
continue;
|
|
1189
|
+
}
|
|
1190
|
+
const prior = prev.prev;
|
|
1191
|
+
const before = prior.prev;
|
|
1192
|
+
const isStart = prior.type === "slash" || prior.type === "bos";
|
|
1193
|
+
const afterStar = before && (before.type === "star" || before.type === "globstar");
|
|
1194
|
+
if (opts.bash === true && (!isStart || rest[0] && rest[0] !== "/")) {
|
|
1195
|
+
push({ type: "star", value, output: "" });
|
|
1196
|
+
continue;
|
|
1197
|
+
}
|
|
1198
|
+
const isBrace = state.braces > 0 && (prior.type === "comma" || prior.type === "brace");
|
|
1199
|
+
const isExtglob = extglobs.length && (prior.type === "pipe" || prior.type === "paren");
|
|
1200
|
+
if (!isStart && prior.type !== "paren" && !isBrace && !isExtglob) {
|
|
1201
|
+
push({ type: "star", value, output: "" });
|
|
1202
|
+
continue;
|
|
1203
|
+
}
|
|
1204
|
+
while (rest.slice(0, 3) === "/**") {
|
|
1205
|
+
const after = input[state.index + 4];
|
|
1206
|
+
if (after && after !== "/") {
|
|
1207
|
+
break;
|
|
1208
|
+
}
|
|
1209
|
+
rest = rest.slice(3);
|
|
1210
|
+
consume("/**", 3);
|
|
1211
|
+
}
|
|
1212
|
+
if (prior.type === "bos" && eos()) {
|
|
1213
|
+
prev.type = "globstar";
|
|
1214
|
+
prev.value += value;
|
|
1215
|
+
prev.output = globstar(opts);
|
|
1216
|
+
state.output = prev.output;
|
|
1217
|
+
state.globstar = true;
|
|
1218
|
+
consume(value);
|
|
1219
|
+
continue;
|
|
1220
|
+
}
|
|
1221
|
+
if (prior.type === "slash" && prior.prev.type !== "bos" && !afterStar && eos()) {
|
|
1222
|
+
state.output = state.output.slice(0, -(prior.output + prev.output).length);
|
|
1223
|
+
prior.output = `(?:${prior.output}`;
|
|
1224
|
+
prev.type = "globstar";
|
|
1225
|
+
prev.output = globstar(opts) + (opts.strictSlashes ? ")" : "|$)");
|
|
1226
|
+
prev.value += value;
|
|
1227
|
+
state.globstar = true;
|
|
1228
|
+
state.output += prior.output + prev.output;
|
|
1229
|
+
consume(value);
|
|
1230
|
+
continue;
|
|
1231
|
+
}
|
|
1232
|
+
if (prior.type === "slash" && prior.prev.type !== "bos" && rest[0] === "/") {
|
|
1233
|
+
const end = rest[1] !== void 0 ? "|$" : "";
|
|
1234
|
+
state.output = state.output.slice(0, -(prior.output + prev.output).length);
|
|
1235
|
+
prior.output = `(?:${prior.output}`;
|
|
1236
|
+
prev.type = "globstar";
|
|
1237
|
+
prev.output = `${globstar(opts)}${SLASH_LITERAL}|${SLASH_LITERAL}${end})`;
|
|
1238
|
+
prev.value += value;
|
|
1239
|
+
state.output += prior.output + prev.output;
|
|
1240
|
+
state.globstar = true;
|
|
1241
|
+
consume(value + advance());
|
|
1242
|
+
push({ type: "slash", value: "/", output: "" });
|
|
1243
|
+
continue;
|
|
1244
|
+
}
|
|
1245
|
+
if (prior.type === "bos" && rest[0] === "/") {
|
|
1246
|
+
prev.type = "globstar";
|
|
1247
|
+
prev.value += value;
|
|
1248
|
+
prev.output = `(?:^|${SLASH_LITERAL}|${globstar(opts)}${SLASH_LITERAL})`;
|
|
1249
|
+
state.output = prev.output;
|
|
1250
|
+
state.globstar = true;
|
|
1251
|
+
consume(value + advance());
|
|
1252
|
+
push({ type: "slash", value: "/", output: "" });
|
|
1253
|
+
continue;
|
|
1254
|
+
}
|
|
1255
|
+
state.output = state.output.slice(0, -prev.output.length);
|
|
1256
|
+
prev.type = "globstar";
|
|
1257
|
+
prev.output = globstar(opts);
|
|
1258
|
+
prev.value += value;
|
|
1259
|
+
state.output += prev.output;
|
|
1260
|
+
state.globstar = true;
|
|
1261
|
+
consume(value);
|
|
1262
|
+
continue;
|
|
1263
|
+
}
|
|
1264
|
+
const token = { type: "star", value, output: star };
|
|
1265
|
+
if (opts.bash === true) {
|
|
1266
|
+
token.output = ".*?";
|
|
1267
|
+
if (prev.type === "bos" || prev.type === "slash") {
|
|
1268
|
+
token.output = nodot + token.output;
|
|
1269
|
+
}
|
|
1270
|
+
push(token);
|
|
1271
|
+
continue;
|
|
1272
|
+
}
|
|
1273
|
+
if (prev && (prev.type === "bracket" || prev.type === "paren") && opts.regex === true) {
|
|
1274
|
+
token.output = value;
|
|
1275
|
+
push(token);
|
|
1276
|
+
continue;
|
|
1277
|
+
}
|
|
1278
|
+
if (state.index === state.start || prev.type === "slash" || prev.type === "dot") {
|
|
1279
|
+
if (prev.type === "dot") {
|
|
1280
|
+
state.output += NO_DOT_SLASH;
|
|
1281
|
+
prev.output += NO_DOT_SLASH;
|
|
1282
|
+
} else if (opts.dot === true) {
|
|
1283
|
+
state.output += NO_DOTS_SLASH;
|
|
1284
|
+
prev.output += NO_DOTS_SLASH;
|
|
1285
|
+
} else {
|
|
1286
|
+
state.output += nodot;
|
|
1287
|
+
prev.output += nodot;
|
|
1288
|
+
}
|
|
1289
|
+
if (peek() !== "*") {
|
|
1290
|
+
state.output += ONE_CHAR;
|
|
1291
|
+
prev.output += ONE_CHAR;
|
|
1292
|
+
}
|
|
1293
|
+
}
|
|
1294
|
+
push(token);
|
|
1295
|
+
}
|
|
1296
|
+
while (state.brackets > 0) {
|
|
1297
|
+
if (opts.strictBrackets === true) throw new SyntaxError(syntaxError("closing", "]"));
|
|
1298
|
+
state.output = utils.escapeLast(state.output, "[");
|
|
1299
|
+
decrement("brackets");
|
|
1300
|
+
}
|
|
1301
|
+
while (state.parens > 0) {
|
|
1302
|
+
if (opts.strictBrackets === true) throw new SyntaxError(syntaxError("closing", ")"));
|
|
1303
|
+
state.output = utils.escapeLast(state.output, "(");
|
|
1304
|
+
decrement("parens");
|
|
1305
|
+
}
|
|
1306
|
+
while (state.braces > 0) {
|
|
1307
|
+
if (opts.strictBrackets === true) throw new SyntaxError(syntaxError("closing", "}"));
|
|
1308
|
+
state.output = utils.escapeLast(state.output, "{");
|
|
1309
|
+
decrement("braces");
|
|
1310
|
+
}
|
|
1311
|
+
if (opts.strictSlashes !== true && (prev.type === "star" || prev.type === "bracket")) {
|
|
1312
|
+
push({ type: "maybe_slash", value: "", output: `${SLASH_LITERAL}?` });
|
|
1313
|
+
}
|
|
1314
|
+
if (state.backtrack === true) {
|
|
1315
|
+
state.output = "";
|
|
1316
|
+
for (const token of state.tokens) {
|
|
1317
|
+
state.output += token.output != null ? token.output : token.value;
|
|
1318
|
+
if (token.suffix) {
|
|
1319
|
+
state.output += token.suffix;
|
|
1320
|
+
}
|
|
1321
|
+
}
|
|
1322
|
+
}
|
|
1323
|
+
return state;
|
|
1324
|
+
};
|
|
1325
|
+
parse.fastpaths = (input, options) => {
|
|
1326
|
+
const opts = { ...options };
|
|
1327
|
+
const max = typeof opts.maxLength === "number" ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
|
|
1328
|
+
const len = input.length;
|
|
1329
|
+
if (len > max) {
|
|
1330
|
+
throw new SyntaxError(`Input length: ${len}, exceeds maximum allowed length: ${max}`);
|
|
1331
|
+
}
|
|
1332
|
+
input = REPLACEMENTS[input] || input;
|
|
1333
|
+
const {
|
|
1334
|
+
DOT_LITERAL,
|
|
1335
|
+
SLASH_LITERAL,
|
|
1336
|
+
ONE_CHAR,
|
|
1337
|
+
DOTS_SLASH,
|
|
1338
|
+
NO_DOT,
|
|
1339
|
+
NO_DOTS,
|
|
1340
|
+
NO_DOTS_SLASH,
|
|
1341
|
+
STAR,
|
|
1342
|
+
START_ANCHOR
|
|
1343
|
+
} = constants.globChars(opts.windows);
|
|
1344
|
+
const nodot = opts.dot ? NO_DOTS : NO_DOT;
|
|
1345
|
+
const slashDot = opts.dot ? NO_DOTS_SLASH : NO_DOT;
|
|
1346
|
+
const capture = opts.capture ? "" : "?:";
|
|
1347
|
+
const state = { negated: false, prefix: "" };
|
|
1348
|
+
let star = opts.bash === true ? ".*?" : STAR;
|
|
1349
|
+
if (opts.capture) {
|
|
1350
|
+
star = `(${star})`;
|
|
1351
|
+
}
|
|
1352
|
+
const globstar = (opts2) => {
|
|
1353
|
+
if (opts2.noglobstar === true) return star;
|
|
1354
|
+
return `(${capture}(?:(?!${START_ANCHOR}${opts2.dot ? DOTS_SLASH : DOT_LITERAL}).)*?)`;
|
|
1355
|
+
};
|
|
1356
|
+
const create = (str) => {
|
|
1357
|
+
switch (str) {
|
|
1358
|
+
case "*":
|
|
1359
|
+
return `${nodot}${ONE_CHAR}${star}`;
|
|
1360
|
+
case ".*":
|
|
1361
|
+
return `${DOT_LITERAL}${ONE_CHAR}${star}`;
|
|
1362
|
+
case "*.*":
|
|
1363
|
+
return `${nodot}${star}${DOT_LITERAL}${ONE_CHAR}${star}`;
|
|
1364
|
+
case "*/*":
|
|
1365
|
+
return `${nodot}${star}${SLASH_LITERAL}${ONE_CHAR}${slashDot}${star}`;
|
|
1366
|
+
case "**":
|
|
1367
|
+
return nodot + globstar(opts);
|
|
1368
|
+
case "**/*":
|
|
1369
|
+
return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${slashDot}${ONE_CHAR}${star}`;
|
|
1370
|
+
case "**/*.*":
|
|
1371
|
+
return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${slashDot}${star}${DOT_LITERAL}${ONE_CHAR}${star}`;
|
|
1372
|
+
case "**/.*":
|
|
1373
|
+
return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${DOT_LITERAL}${ONE_CHAR}${star}`;
|
|
1374
|
+
default: {
|
|
1375
|
+
const match = /^(.*?)\.(\w+)$/.exec(str);
|
|
1376
|
+
if (!match) return;
|
|
1377
|
+
const source2 = create(match[1]);
|
|
1378
|
+
if (!source2) return;
|
|
1379
|
+
return source2 + DOT_LITERAL + match[2];
|
|
1380
|
+
}
|
|
1381
|
+
}
|
|
1382
|
+
};
|
|
1383
|
+
const output = utils.removePrefix(input, state);
|
|
1384
|
+
let source = create(output);
|
|
1385
|
+
if (source && opts.strictSlashes !== true) {
|
|
1386
|
+
source += `${SLASH_LITERAL}?`;
|
|
1387
|
+
}
|
|
1388
|
+
return source;
|
|
1389
|
+
};
|
|
1390
|
+
module.exports = parse;
|
|
1391
|
+
}
|
|
1392
|
+
});
|
|
1393
|
+
|
|
1394
|
+
// node_modules/picomatch/lib/picomatch.js
|
|
1395
|
+
var require_picomatch = __commonJS({
|
|
1396
|
+
"node_modules/picomatch/lib/picomatch.js"(exports, module) {
|
|
1397
|
+
"use strict";
|
|
1398
|
+
var scan = require_scan();
|
|
1399
|
+
var parse = require_parse();
|
|
1400
|
+
var utils = require_utils();
|
|
1401
|
+
var constants = require_constants();
|
|
1402
|
+
var isObject = (val) => val && typeof val === "object" && !Array.isArray(val);
|
|
1403
|
+
var picomatch2 = (glob, options, returnState = false) => {
|
|
1404
|
+
if (Array.isArray(glob)) {
|
|
1405
|
+
const fns = glob.map((input) => picomatch2(input, options, returnState));
|
|
1406
|
+
const arrayMatcher = (str) => {
|
|
1407
|
+
for (const isMatch of fns) {
|
|
1408
|
+
const state2 = isMatch(str);
|
|
1409
|
+
if (state2) return state2;
|
|
1410
|
+
}
|
|
1411
|
+
return false;
|
|
1412
|
+
};
|
|
1413
|
+
return arrayMatcher;
|
|
1414
|
+
}
|
|
1415
|
+
const isState = isObject(glob) && glob.tokens && glob.input;
|
|
1416
|
+
if (glob === "" || typeof glob !== "string" && !isState) {
|
|
1417
|
+
throw new TypeError("Expected pattern to be a non-empty string");
|
|
1418
|
+
}
|
|
1419
|
+
const opts = options || {};
|
|
1420
|
+
const posix = opts.windows;
|
|
1421
|
+
const regex = isState ? picomatch2.compileRe(glob, options) : picomatch2.makeRe(glob, options, false, true);
|
|
1422
|
+
const state = regex.state;
|
|
1423
|
+
delete regex.state;
|
|
1424
|
+
let isIgnored = () => false;
|
|
1425
|
+
if (opts.ignore) {
|
|
1426
|
+
const ignoreOpts = { ...options, ignore: null, onMatch: null, onResult: null };
|
|
1427
|
+
isIgnored = picomatch2(opts.ignore, ignoreOpts, returnState);
|
|
1428
|
+
}
|
|
1429
|
+
const matcher = (input, returnObject = false) => {
|
|
1430
|
+
const { isMatch, match, output } = picomatch2.test(input, regex, options, { glob, posix });
|
|
1431
|
+
const result = { glob, state, regex, posix, input, output, match, isMatch };
|
|
1432
|
+
if (typeof opts.onResult === "function") {
|
|
1433
|
+
opts.onResult(result);
|
|
1434
|
+
}
|
|
1435
|
+
if (isMatch === false) {
|
|
1436
|
+
result.isMatch = false;
|
|
1437
|
+
return returnObject ? result : false;
|
|
1438
|
+
}
|
|
1439
|
+
if (isIgnored(input)) {
|
|
1440
|
+
if (typeof opts.onIgnore === "function") {
|
|
1441
|
+
opts.onIgnore(result);
|
|
1442
|
+
}
|
|
1443
|
+
result.isMatch = false;
|
|
1444
|
+
return returnObject ? result : false;
|
|
1445
|
+
}
|
|
1446
|
+
if (typeof opts.onMatch === "function") {
|
|
1447
|
+
opts.onMatch(result);
|
|
1448
|
+
}
|
|
1449
|
+
return returnObject ? result : true;
|
|
1450
|
+
};
|
|
1451
|
+
if (returnState) {
|
|
1452
|
+
matcher.state = state;
|
|
1453
|
+
}
|
|
1454
|
+
return matcher;
|
|
1455
|
+
};
|
|
1456
|
+
picomatch2.test = (input, regex, options, { glob, posix } = {}) => {
|
|
1457
|
+
if (typeof input !== "string") {
|
|
1458
|
+
throw new TypeError("Expected input to be a string");
|
|
1459
|
+
}
|
|
1460
|
+
if (input === "") {
|
|
1461
|
+
return { isMatch: false, output: "" };
|
|
1462
|
+
}
|
|
1463
|
+
const opts = options || {};
|
|
1464
|
+
const format = opts.format || (posix ? utils.toPosixSlashes : null);
|
|
1465
|
+
let match = input === glob;
|
|
1466
|
+
let output = match && format ? format(input) : input;
|
|
1467
|
+
if (match === false) {
|
|
1468
|
+
output = format ? format(input) : input;
|
|
1469
|
+
match = output === glob;
|
|
1470
|
+
}
|
|
1471
|
+
if (match === false || opts.capture === true) {
|
|
1472
|
+
if (opts.matchBase === true || opts.basename === true) {
|
|
1473
|
+
match = picomatch2.matchBase(input, regex, options, posix);
|
|
1474
|
+
} else {
|
|
1475
|
+
match = regex.exec(output);
|
|
1476
|
+
}
|
|
1477
|
+
}
|
|
1478
|
+
return { isMatch: Boolean(match), match, output };
|
|
1479
|
+
};
|
|
1480
|
+
picomatch2.matchBase = (input, glob, options) => {
|
|
1481
|
+
const regex = glob instanceof RegExp ? glob : picomatch2.makeRe(glob, options);
|
|
1482
|
+
return regex.test(utils.basename(input));
|
|
1483
|
+
};
|
|
1484
|
+
picomatch2.isMatch = (str, patterns, options) => picomatch2(patterns, options)(str);
|
|
1485
|
+
picomatch2.parse = (pattern, options) => {
|
|
1486
|
+
if (Array.isArray(pattern)) return pattern.map((p) => picomatch2.parse(p, options));
|
|
1487
|
+
return parse(pattern, { ...options, fastpaths: false });
|
|
1488
|
+
};
|
|
1489
|
+
picomatch2.scan = (input, options) => scan(input, options);
|
|
1490
|
+
picomatch2.compileRe = (state, options, returnOutput = false, returnState = false) => {
|
|
1491
|
+
if (returnOutput === true) {
|
|
1492
|
+
return state.output;
|
|
1493
|
+
}
|
|
1494
|
+
const opts = options || {};
|
|
1495
|
+
const prepend = opts.contains ? "" : "^";
|
|
1496
|
+
const append = opts.contains ? "" : "$";
|
|
1497
|
+
let source = `${prepend}(?:${state.output})${append}`;
|
|
1498
|
+
if (state && state.negated === true) {
|
|
1499
|
+
source = `^(?!${source}).*$`;
|
|
1500
|
+
}
|
|
1501
|
+
const regex = picomatch2.toRegex(source, options);
|
|
1502
|
+
if (returnState === true) {
|
|
1503
|
+
regex.state = state;
|
|
1504
|
+
}
|
|
1505
|
+
return regex;
|
|
1506
|
+
};
|
|
1507
|
+
picomatch2.makeRe = (input, options = {}, returnOutput = false, returnState = false) => {
|
|
1508
|
+
if (!input || typeof input !== "string") {
|
|
1509
|
+
throw new TypeError("Expected a non-empty string");
|
|
1510
|
+
}
|
|
1511
|
+
let parsed = { negated: false, fastpaths: true };
|
|
1512
|
+
if (options.fastpaths !== false && (input[0] === "." || input[0] === "*")) {
|
|
1513
|
+
parsed.output = parse.fastpaths(input, options);
|
|
1514
|
+
}
|
|
1515
|
+
if (!parsed.output) {
|
|
1516
|
+
parsed = parse(input, options);
|
|
1517
|
+
}
|
|
1518
|
+
return picomatch2.compileRe(parsed, options, returnOutput, returnState);
|
|
1519
|
+
};
|
|
1520
|
+
picomatch2.toRegex = (source, options) => {
|
|
1521
|
+
try {
|
|
1522
|
+
const opts = options || {};
|
|
1523
|
+
return new RegExp(source, opts.flags || (opts.nocase ? "i" : ""));
|
|
1524
|
+
} catch (err) {
|
|
1525
|
+
if (options && options.debug === true) throw err;
|
|
1526
|
+
return /$^/;
|
|
1527
|
+
}
|
|
1528
|
+
};
|
|
1529
|
+
picomatch2.constants = constants;
|
|
1530
|
+
module.exports = picomatch2;
|
|
1531
|
+
}
|
|
1532
|
+
});
|
|
1533
|
+
|
|
1534
|
+
// node_modules/picomatch/index.js
|
|
1535
|
+
var require_picomatch2 = __commonJS({
|
|
1536
|
+
"node_modules/picomatch/index.js"(exports, module) {
|
|
1537
|
+
"use strict";
|
|
1538
|
+
var pico = require_picomatch();
|
|
1539
|
+
var utils = require_utils();
|
|
1540
|
+
function picomatch2(glob, options, returnState = false) {
|
|
1541
|
+
if (options && (options.windows === null || options.windows === void 0)) {
|
|
1542
|
+
options = { ...options, windows: utils.isWindows() };
|
|
1543
|
+
}
|
|
1544
|
+
return pico(glob, options, returnState);
|
|
1545
|
+
}
|
|
1546
|
+
Object.assign(picomatch2, pico);
|
|
1547
|
+
module.exports = picomatch2;
|
|
1548
|
+
}
|
|
1549
|
+
});
|
|
1550
|
+
|
|
1551
|
+
// src/client.js
|
|
1552
|
+
var client_exports = {};
|
|
1553
|
+
__export(client_exports, {
|
|
1554
|
+
FileLoader: () => FileLoader,
|
|
1555
|
+
HMRClient: () => HMRClient,
|
|
1556
|
+
default: () => HMRClient
|
|
1557
|
+
});
|
|
1558
|
+
|
|
1559
|
+
// src/client/file-loader.js
|
|
1560
|
+
var FileLoader = class {
|
|
1561
|
+
constructor(httpUrl) {
|
|
1562
|
+
this.httpUrl = httpUrl;
|
|
1563
|
+
this.loadQueue = /* @__PURE__ */ new Map();
|
|
1564
|
+
}
|
|
1565
|
+
async loadFile(path) {
|
|
1566
|
+
const isCSS = path.endsWith(".css");
|
|
1567
|
+
const isModule = path.endsWith(".mjs");
|
|
1568
|
+
if (isCSS) return await this.loadCSS(path);
|
|
1569
|
+
if (isModule) return await this.loadModule(path);
|
|
1570
|
+
return await this.loadScript(path);
|
|
1571
|
+
}
|
|
1572
|
+
// Load CSS atomically: append new <link>, wait for it to load, then remove
|
|
1573
|
+
// the old one. This fixes the brief flash of unstyled content that
|
|
1574
|
+
// happens when you remove the old sheet before the new one is parsed.
|
|
1575
|
+
async loadCSS(path) {
|
|
1576
|
+
const existing = document.querySelector(`link[data-file="${path}"]`);
|
|
1577
|
+
const url = this.makeUrl(path);
|
|
1578
|
+
const link = document.createElement("link");
|
|
1579
|
+
link.rel = "stylesheet";
|
|
1580
|
+
link.href = url;
|
|
1581
|
+
link.setAttribute("data-file", path);
|
|
1582
|
+
return new Promise((resolve, reject) => {
|
|
1583
|
+
link.onload = () => {
|
|
1584
|
+
if (existing) existing.remove();
|
|
1585
|
+
resolve(true);
|
|
1586
|
+
};
|
|
1587
|
+
link.onerror = () => {
|
|
1588
|
+
link.remove();
|
|
1589
|
+
reject(new Error(`Failed to load CSS: ${path}`));
|
|
1590
|
+
};
|
|
1591
|
+
document.head.appendChild(link);
|
|
1592
|
+
});
|
|
1593
|
+
}
|
|
1594
|
+
// Replace the existing module script with a cache busted URL.
|
|
1595
|
+
// Changing the URL makes the browser treat it as a new module
|
|
1596
|
+
// and execute it from scratch.
|
|
1597
|
+
async loadModule(path) {
|
|
1598
|
+
const url = this.makeUrl(path);
|
|
1599
|
+
const existing = document.querySelector(`script[data-file="${path}"]`);
|
|
1600
|
+
if (existing) existing.remove();
|
|
1601
|
+
const script = document.createElement("script");
|
|
1602
|
+
script.type = "module";
|
|
1603
|
+
script.src = url;
|
|
1604
|
+
script.setAttribute("data-file", path);
|
|
1605
|
+
return new Promise((resolve, reject) => {
|
|
1606
|
+
script.onload = () => resolve(true);
|
|
1607
|
+
script.onerror = () => reject(new Error(`Failed to execute module: ${path}`));
|
|
1608
|
+
document.head.appendChild(script);
|
|
1609
|
+
});
|
|
1610
|
+
}
|
|
1611
|
+
async loadScript(path) {
|
|
1612
|
+
const url = this.makeUrl(path);
|
|
1613
|
+
const existing = document.querySelector(`script[data-file="${path}"]`);
|
|
1614
|
+
if (existing) existing.remove();
|
|
1615
|
+
const script = document.createElement("script");
|
|
1616
|
+
script.src = url;
|
|
1617
|
+
script.setAttribute("data-file", path);
|
|
1618
|
+
return new Promise((resolve, reject) => {
|
|
1619
|
+
script.onload = () => resolve(true);
|
|
1620
|
+
script.onerror = () => reject(new Error(`Failed to load script: ${path}`));
|
|
1621
|
+
document.head.appendChild(script);
|
|
1622
|
+
});
|
|
1623
|
+
}
|
|
1624
|
+
// Debounce reloads within 100ms.
|
|
1625
|
+
// Calls in the same window share a single load and all receive the result.
|
|
1626
|
+
// Fixes prior behavior where only the last caller's Promise resolved.
|
|
1627
|
+
async reloadFile(path) {
|
|
1628
|
+
return new Promise((resolve, reject) => {
|
|
1629
|
+
if (this.loadQueue.has(path)) {
|
|
1630
|
+
const entry = this.loadQueue.get(path);
|
|
1631
|
+
clearTimeout(entry.timeout);
|
|
1632
|
+
entry.resolvers.push({ resolve, reject });
|
|
1633
|
+
entry.timeout = setTimeout(() => this._flushReload(path), 100);
|
|
1634
|
+
} else {
|
|
1635
|
+
const entry = {
|
|
1636
|
+
timeout: setTimeout(() => this._flushReload(path), 100),
|
|
1637
|
+
resolvers: [{ resolve, reject }]
|
|
1638
|
+
};
|
|
1639
|
+
this.loadQueue.set(path, entry);
|
|
1640
|
+
}
|
|
1641
|
+
});
|
|
1642
|
+
}
|
|
1643
|
+
async _flushReload(path) {
|
|
1644
|
+
const entry = this.loadQueue.get(path);
|
|
1645
|
+
this.loadQueue.delete(path);
|
|
1646
|
+
try {
|
|
1647
|
+
const success = await this.loadFile(path);
|
|
1648
|
+
for (const { resolve } of entry.resolvers) resolve(success);
|
|
1649
|
+
} catch (e) {
|
|
1650
|
+
for (const { reject } of entry.resolvers) reject(e);
|
|
1651
|
+
}
|
|
1652
|
+
}
|
|
1653
|
+
async removeFile(path) {
|
|
1654
|
+
if (this.loadQueue.has(path)) {
|
|
1655
|
+
const entry = this.loadQueue.get(path);
|
|
1656
|
+
clearTimeout(entry.timeout);
|
|
1657
|
+
for (const { reject } of entry.resolvers) reject(new Error(`File removed: ${path}`));
|
|
1658
|
+
this.loadQueue.delete(path);
|
|
1659
|
+
}
|
|
1660
|
+
const el = document.querySelector(`[data-file="${path}"]`);
|
|
1661
|
+
if (el) {
|
|
1662
|
+
el.remove();
|
|
1663
|
+
await new Promise((r) => setTimeout(r, 0));
|
|
1664
|
+
}
|
|
1665
|
+
}
|
|
1666
|
+
// Cache bust with timestamp + random to avoid duplicate URLs on rapid reloads.
|
|
1667
|
+
makeUrl(path) {
|
|
1668
|
+
const cb = `${Date.now()}-${Math.random().toString(36).slice(2, 11)}`;
|
|
1669
|
+
return `${this.httpUrl}${path}?cb=${cb}`;
|
|
1670
|
+
}
|
|
1671
|
+
};
|
|
1672
|
+
|
|
1673
|
+
// src/shared/constants.js
|
|
1674
|
+
var HMR_ACTIONS = {
|
|
1675
|
+
RELOAD: "reload",
|
|
1676
|
+
ADD: "add",
|
|
1677
|
+
REMOVE: "remove",
|
|
1678
|
+
INIT: "init"
|
|
1679
|
+
};
|
|
1680
|
+
|
|
1681
|
+
// src/shared/utils.js
|
|
1682
|
+
var import_picomatch = __toESM(require_picomatch2(), 1);
|
|
1683
|
+
var matcherCache = /* @__PURE__ */ new Map();
|
|
1684
|
+
function matchGlob(file, patterns) {
|
|
1685
|
+
return patterns.some((pattern) => {
|
|
1686
|
+
if (!matcherCache.has(pattern)) matcherCache.set(pattern, (0, import_picomatch.default)(pattern));
|
|
1687
|
+
return matcherCache.get(pattern)(file);
|
|
1688
|
+
});
|
|
1689
|
+
}
|
|
1690
|
+
function formatTime() {
|
|
1691
|
+
return (/* @__PURE__ */ new Date()).toLocaleTimeString("en-US", {
|
|
1692
|
+
hour12: false,
|
|
1693
|
+
hour: "2-digit",
|
|
1694
|
+
minute: "2-digit",
|
|
1695
|
+
second: "2-digit"
|
|
1696
|
+
});
|
|
1697
|
+
}
|
|
1698
|
+
function getFileName(path) {
|
|
1699
|
+
return path.split("/").pop();
|
|
1700
|
+
}
|
|
1701
|
+
function getFilePath(path) {
|
|
1702
|
+
const parts = path.split("/");
|
|
1703
|
+
parts.pop();
|
|
1704
|
+
return parts.join("/") || ".";
|
|
1705
|
+
}
|
|
1706
|
+
function normalizeUrl(url) {
|
|
1707
|
+
return url.endsWith("/") ? url : url + "/";
|
|
1708
|
+
}
|
|
1709
|
+
function wsUrlToHttpUrl(wsUrl) {
|
|
1710
|
+
const u = new URL(wsUrl);
|
|
1711
|
+
return `${u.protocol === "wss:" ? "https" : "http"}://${u.host}/`;
|
|
1712
|
+
}
|
|
1713
|
+
function httpUrlToWsUrl(httpUrl, wsPath) {
|
|
1714
|
+
const u = new URL(httpUrl);
|
|
1715
|
+
return `${u.protocol === "https:" ? "wss" : "ws"}://${u.host}${wsPath}`;
|
|
1716
|
+
}
|
|
1717
|
+
function resolveConnectionUrls(options, wsPath = "/hmr") {
|
|
1718
|
+
if (typeof options === "string") {
|
|
1719
|
+
return { wsUrl: options, httpUrl: wsUrlToHttpUrl(options) };
|
|
1720
|
+
}
|
|
1721
|
+
if (typeof options === "number") {
|
|
1722
|
+
options = { port: options };
|
|
1723
|
+
}
|
|
1724
|
+
if (typeof options !== "object" || options === null) {
|
|
1725
|
+
throw new Error("Options must be a string, number, or object");
|
|
1726
|
+
}
|
|
1727
|
+
if (options.wsUrl && options.httpUrl) {
|
|
1728
|
+
return { wsUrl: options.wsUrl, httpUrl: normalizeUrl(options.httpUrl) };
|
|
1729
|
+
}
|
|
1730
|
+
if (options.wsUrl) {
|
|
1731
|
+
return { wsUrl: options.wsUrl, httpUrl: wsUrlToHttpUrl(options.wsUrl) };
|
|
1732
|
+
}
|
|
1733
|
+
if (options.httpUrl) {
|
|
1734
|
+
const httpUrl = normalizeUrl(options.httpUrl);
|
|
1735
|
+
return { wsUrl: httpUrlToWsUrl(httpUrl, wsPath), httpUrl };
|
|
1736
|
+
}
|
|
1737
|
+
if (options.port) {
|
|
1738
|
+
const host = options.host || "localhost";
|
|
1739
|
+
const secure = options.secure || false;
|
|
1740
|
+
const wsProtocol = secure ? "wss" : "ws";
|
|
1741
|
+
const httpProtocol = secure ? "https" : "http";
|
|
1742
|
+
const wsUrl = `${wsProtocol}://${host}:${options.port}${wsPath}`;
|
|
1743
|
+
const httpUrl = normalizeUrl(`${httpProtocol}://${host}:${options.port}`);
|
|
1744
|
+
return { wsUrl, httpUrl };
|
|
1745
|
+
}
|
|
1746
|
+
throw new Error("Must provide wsUrl, httpUrl, port, or host+port");
|
|
1747
|
+
}
|
|
1748
|
+
|
|
1749
|
+
// src/client/hmr-client.js
|
|
1750
|
+
var HMRClient = class {
|
|
1751
|
+
/**
|
|
1752
|
+
* `options` can be a shorthand or a full config object:
|
|
1753
|
+
* - **number** treated as `{ port: n }`, connects to `ws://localhost:<n>`
|
|
1754
|
+
* - **string** treated as a full WebSocket URL
|
|
1755
|
+
* - **object** full config, see below
|
|
1756
|
+
*
|
|
1757
|
+
* @param {Object} options - setting options jsdoc to `Object` only for the sake of auto complete.
|
|
1758
|
+
* @param {string} [options.wsUrl] - Explicit WebSocket URL. Takes priority over host/port.
|
|
1759
|
+
* @param {string} [options.httpUrl] - Explicit HTTP base URL for fetching files. Derived from `wsUrl` if omitted.
|
|
1760
|
+
* @param {boolean} [options.watchFiles=true] Server side file watching is enabled by default.
|
|
1761
|
+
* @param {string} [options.host='localhost'] - Hostname (used when building from `port`)
|
|
1762
|
+
* @param {number} [options.port] - Port number
|
|
1763
|
+
* @param {boolean} [options.secure=false] - Use `wss://` and `https://`
|
|
1764
|
+
* @param {boolean} [options.autoReconnect=true] - Reconnect on disconnect with exponential backoff.
|
|
1765
|
+
* @param {number} [options.reconnectDelay=2000] - Base reconnect delay in ms
|
|
1766
|
+
* @param {number} [options.maxReconnectDelay=30000] - Maximum reconnect delay cap in ms
|
|
1767
|
+
* @param {string[]} [options.skip] - Glob patterns for files that should never be loaded (e.g. `['_*\/**']`)
|
|
1768
|
+
* @param {function(string, string[]): boolean} [options.filterSkip] - Custom skip logic. Receives `(filePath, allFiles)`. Combined with `skip` via OR.
|
|
1769
|
+
* @param {string[]} [options.cold] - Glob patterns for files that require a full page reload. Merged with the server's `cold` config on connect. A `cold` event is emitted instead of hot reloading.
|
|
1770
|
+
* @param {function(string): boolean} [options.filterCold] - Custom cold file logic. Receives `(filePath)`. Combined with `cold` via OR.
|
|
1771
|
+
* @param {function(string, string[]): string|null} [options.getOverrideTarget] - Given a changed file, return the path of the original it replaces, or `null`. Receives `(filePath, allFiles)`. When matched, the original is unloaded before the override loads.
|
|
1772
|
+
* @param {function(string): void} [options.onFileLoaded] - Called after each file loads or reloads. Receives `(filePath)`.
|
|
1773
|
+
* @param {function(string[]): string[]} [options.sortFiles] - Custom sort for the initial file load order. Default sorts CSS before JS, cold files first.
|
|
1774
|
+
*/
|
|
1775
|
+
constructor(options) {
|
|
1776
|
+
const opts = typeof options === "object" && !Array.isArray(options) ? options : {};
|
|
1777
|
+
const wsPath = opts.wsPath || "/hmr";
|
|
1778
|
+
const { wsUrl, httpUrl } = resolveConnectionUrls(options, wsPath);
|
|
1779
|
+
this.wsUrl = wsUrl;
|
|
1780
|
+
this.httpUrl = httpUrl;
|
|
1781
|
+
this.watchFiles = true;
|
|
1782
|
+
this._autoReconnectDefault = opts.autoReconnect !== false;
|
|
1783
|
+
this.autoReconnect = this._autoReconnectDefault;
|
|
1784
|
+
this.reconnectDelay = opts.reconnectDelay || 2e3;
|
|
1785
|
+
this.maxReconnectDelay = opts.maxReconnectDelay || 3e4;
|
|
1786
|
+
this._coldPatterns = opts.cold || null;
|
|
1787
|
+
this._filterCold = opts.filterCold || null;
|
|
1788
|
+
this.shouldSkipFile = this.makeFilter(opts.skip || null, opts.filterSkip || null);
|
|
1789
|
+
this.isColdFile = this.makeFilter(this._coldPatterns, this._filterCold);
|
|
1790
|
+
this.allFiles = [];
|
|
1791
|
+
this.getOverrideTarget = opts.getOverrideTarget || null;
|
|
1792
|
+
this.onFileLoaded = opts.onFileLoaded || null;
|
|
1793
|
+
this.sortFiles = opts.sortFiles || this.defaultSortFiles.bind(this);
|
|
1794
|
+
this.socket = null;
|
|
1795
|
+
this.reconnectAttempts = 0;
|
|
1796
|
+
this.isConnected = false;
|
|
1797
|
+
this.eventHandlers = /* @__PURE__ */ new Map();
|
|
1798
|
+
this._reconnectTimer = null;
|
|
1799
|
+
this._messageQueue = [];
|
|
1800
|
+
this._processingMessages = false;
|
|
1801
|
+
this.fileLoader = new FileLoader(this.httpUrl);
|
|
1802
|
+
this.overrideMap = /* @__PURE__ */ new Map();
|
|
1803
|
+
this._reverseOverrideMap = /* @__PURE__ */ new Map();
|
|
1804
|
+
this.logStyles = {
|
|
1805
|
+
info: { symbol: "\u2139", color: "#76fffd" },
|
|
1806
|
+
success: { symbol: "\u25B6", color: "#68ff51" },
|
|
1807
|
+
warning: { symbol: "\u232C", color: "#ff8400" },
|
|
1808
|
+
error: { symbol: "\u2716", color: "#ff0000" },
|
|
1809
|
+
add: { symbol: "\u2295", color: "#22c55e" },
|
|
1810
|
+
remove: { symbol: "\u2296", color: "#f87171" },
|
|
1811
|
+
inject: { symbol: "\u2398", color: "#facc15" },
|
|
1812
|
+
disconnect: { symbol: "\u2726", color: "#ef4444" },
|
|
1813
|
+
override: { symbol: "\u29EB", color: "#ff8400" },
|
|
1814
|
+
skip: { symbol: "\u2298", color: "#888888" },
|
|
1815
|
+
cold: { symbol: "\u2744", color: "#60a5fa" }
|
|
1816
|
+
};
|
|
1817
|
+
}
|
|
1818
|
+
defaultSortFiles(files) {
|
|
1819
|
+
const coldSet = new Set(files.filter((f) => this.isColdFile(f)));
|
|
1820
|
+
return [...files].sort((a, b) => {
|
|
1821
|
+
const aIsCSS = a.endsWith(".css");
|
|
1822
|
+
const bIsCSS = b.endsWith(".css");
|
|
1823
|
+
if (aIsCSS && !bIsCSS) return -1;
|
|
1824
|
+
if (!aIsCSS && bIsCSS) return 1;
|
|
1825
|
+
const coldA = coldSet.has(a);
|
|
1826
|
+
const coldB = coldSet.has(b);
|
|
1827
|
+
if (coldA && !coldB) return -1;
|
|
1828
|
+
if (!coldA && coldB) return 1;
|
|
1829
|
+
return a.localeCompare(b);
|
|
1830
|
+
});
|
|
1831
|
+
}
|
|
1832
|
+
makeFilter(patterns, callback) {
|
|
1833
|
+
if (patterns && callback) {
|
|
1834
|
+
return (file, allFiles) => {
|
|
1835
|
+
return matchGlob(file, patterns) || callback(file, allFiles);
|
|
1836
|
+
};
|
|
1837
|
+
}
|
|
1838
|
+
if (patterns) {
|
|
1839
|
+
return (file) => matchGlob(file, patterns);
|
|
1840
|
+
}
|
|
1841
|
+
if (callback) {
|
|
1842
|
+
return callback;
|
|
1843
|
+
}
|
|
1844
|
+
return () => false;
|
|
1845
|
+
}
|
|
1846
|
+
log(type, message) {
|
|
1847
|
+
const { symbol, color } = this.logStyles[type] || this.logStyles.info;
|
|
1848
|
+
const time = formatTime();
|
|
1849
|
+
console.log(`%c${symbol} [${time}] ${message}`, `color: ${color}; font-weight: bold;`);
|
|
1850
|
+
}
|
|
1851
|
+
logInitFileGroup(files, overrideMap, isColdFile) {
|
|
1852
|
+
if (!files.length) return;
|
|
1853
|
+
const overrideCount = files.filter((f) => overrideMap.has(f)).length;
|
|
1854
|
+
const coldCount = files.filter((f) => isColdFile(f)).length;
|
|
1855
|
+
const jsCount = files.filter((f) => f.endsWith(".js") || f.endsWith(".cjs") || f.endsWith(".mjs")).length;
|
|
1856
|
+
const cssCount = files.filter((f) => f.endsWith(".css")).length;
|
|
1857
|
+
const parts = [];
|
|
1858
|
+
if (overrideCount) parts.push(`${overrideCount} overridden`);
|
|
1859
|
+
if (coldCount) parts.push(`${coldCount} cold`);
|
|
1860
|
+
if (cssCount) parts.push(`${jsCount} JS, ${cssCount} CSS`);
|
|
1861
|
+
const suffix = parts.length ? ` (${parts.join(", ")})` : "";
|
|
1862
|
+
const title = `Loading ${files.length} initial file${files.length !== 1 ? "s" : ""}${suffix}`;
|
|
1863
|
+
const { symbol, color } = this.logStyles.inject;
|
|
1864
|
+
console.groupCollapsed(
|
|
1865
|
+
`%c${symbol} [${formatTime()}] ${title}`,
|
|
1866
|
+
`color: ${color}; font-weight: bold;`
|
|
1867
|
+
);
|
|
1868
|
+
files.forEach((file) => {
|
|
1869
|
+
const fileName = getFileName(file);
|
|
1870
|
+
const filePath = getFilePath(file);
|
|
1871
|
+
const isOverride = overrideMap.has(file);
|
|
1872
|
+
const isCold = isColdFile(file);
|
|
1873
|
+
if (isOverride) {
|
|
1874
|
+
const target = getFileName(overrideMap.get(file));
|
|
1875
|
+
const targetPath = getFilePath(overrideMap.get(file));
|
|
1876
|
+
console.log(
|
|
1877
|
+
`%c\u2514\u2500 ${fileName} -> ${target}%c (${filePath} -> ${targetPath})`,
|
|
1878
|
+
`color: ${this.logStyles.override.color}; font-weight: bold;`,
|
|
1879
|
+
"color: #888888; font-style: italic;"
|
|
1880
|
+
);
|
|
1881
|
+
} else if (isCold) {
|
|
1882
|
+
console.log(
|
|
1883
|
+
`%c\u2514\u2500 ${fileName}%c (${filePath})`,
|
|
1884
|
+
`color: ${this.logStyles.cold.color}; font-weight: bold;`,
|
|
1885
|
+
"color: #888888; font-style: italic;"
|
|
1886
|
+
);
|
|
1887
|
+
} else {
|
|
1888
|
+
console.log(
|
|
1889
|
+
`\u2514\u2500 %c${fileName}%c (${filePath})`,
|
|
1890
|
+
"color: #ffffff; font-weight: bold;",
|
|
1891
|
+
"color: #888888; font-style: italic;"
|
|
1892
|
+
);
|
|
1893
|
+
}
|
|
1894
|
+
});
|
|
1895
|
+
console.groupEnd();
|
|
1896
|
+
}
|
|
1897
|
+
buildOverrideMap(files) {
|
|
1898
|
+
this.overrideMap.clear();
|
|
1899
|
+
this._reverseOverrideMap.clear();
|
|
1900
|
+
const overrideFiles = /* @__PURE__ */ new Set();
|
|
1901
|
+
const originalFiles = /* @__PURE__ */ new Set();
|
|
1902
|
+
if (!this.getOverrideTarget) {
|
|
1903
|
+
return files;
|
|
1904
|
+
}
|
|
1905
|
+
for (const file of files) {
|
|
1906
|
+
const target = this.getOverrideTarget(file, files);
|
|
1907
|
+
if (target) {
|
|
1908
|
+
this.overrideMap.set(file, target);
|
|
1909
|
+
if (!this._reverseOverrideMap.has(target)) {
|
|
1910
|
+
this._reverseOverrideMap.set(target, /* @__PURE__ */ new Set());
|
|
1911
|
+
}
|
|
1912
|
+
this._reverseOverrideMap.get(target).add(file);
|
|
1913
|
+
overrideFiles.add(file);
|
|
1914
|
+
originalFiles.add(target);
|
|
1915
|
+
}
|
|
1916
|
+
}
|
|
1917
|
+
return files.filter((f) => !originalFiles.has(f));
|
|
1918
|
+
}
|
|
1919
|
+
async processInitFiles(files) {
|
|
1920
|
+
const filtered = [];
|
|
1921
|
+
const skipped = [];
|
|
1922
|
+
for (const f of files) {
|
|
1923
|
+
(this.shouldSkipFile(f, files) ? skipped : filtered).push(f);
|
|
1924
|
+
}
|
|
1925
|
+
if (skipped.length > 0) {
|
|
1926
|
+
console.groupCollapsed(
|
|
1927
|
+
`%c${this.logStyles.skip.symbol} [${formatTime()}] Skipped ${skipped.length} file${skipped.length !== 1 ? "s" : ""}`,
|
|
1928
|
+
`color: ${this.logStyles.skip.color}; font-weight: bold;`
|
|
1929
|
+
);
|
|
1930
|
+
skipped.forEach((f) => console.log(` \u2514\u2500 ${getFileName(f)}`));
|
|
1931
|
+
console.groupEnd();
|
|
1932
|
+
}
|
|
1933
|
+
const withOverrides = this.buildOverrideMap(filtered);
|
|
1934
|
+
const sorted2 = this.sortFiles(withOverrides);
|
|
1935
|
+
this.logInitFileGroup(sorted2, this.overrideMap, this.isColdFile.bind(this));
|
|
1936
|
+
for (const file of sorted2) {
|
|
1937
|
+
await this.fileLoader.loadFile(file);
|
|
1938
|
+
if (this.onFileLoaded) this.onFileLoaded(file);
|
|
1939
|
+
}
|
|
1940
|
+
this.log("success", `HMR client ready (${sorted2.length} files loaded)`);
|
|
1941
|
+
}
|
|
1942
|
+
async handleFileChange(file, action, serverCold = false) {
|
|
1943
|
+
if (this.shouldSkipFile(file, this.allFiles)) {
|
|
1944
|
+
this.log("skip", `Skipping ${action}: ${getFileName(file)}`);
|
|
1945
|
+
return;
|
|
1946
|
+
}
|
|
1947
|
+
if (this._reverseOverrideMap.has(file)) {
|
|
1948
|
+
this.log("skip", `Skipping ${action}: ${getFileName(file)} (overridden)`);
|
|
1949
|
+
return;
|
|
1950
|
+
}
|
|
1951
|
+
if (this.getOverrideTarget) {
|
|
1952
|
+
const newTarget = this.getOverrideTarget(file, this.allFiles);
|
|
1953
|
+
const previousTarget = this.overrideMap.get(file);
|
|
1954
|
+
if (previousTarget && previousTarget !== newTarget) {
|
|
1955
|
+
const siblings = this._reverseOverrideMap.get(previousTarget);
|
|
1956
|
+
if (siblings) {
|
|
1957
|
+
siblings.delete(file);
|
|
1958
|
+
if (siblings.size === 0) this._reverseOverrideMap.delete(previousTarget);
|
|
1959
|
+
}
|
|
1960
|
+
this.overrideMap.delete(file);
|
|
1961
|
+
}
|
|
1962
|
+
if (newTarget) {
|
|
1963
|
+
this.log("override", `${getFileName(file)} -> ${getFileName(newTarget)}`);
|
|
1964
|
+
await this.fileLoader.removeFile(newTarget);
|
|
1965
|
+
this.overrideMap.set(file, newTarget);
|
|
1966
|
+
if (!this._reverseOverrideMap.has(newTarget)) {
|
|
1967
|
+
this._reverseOverrideMap.set(newTarget, /* @__PURE__ */ new Set());
|
|
1968
|
+
}
|
|
1969
|
+
this._reverseOverrideMap.get(newTarget).add(file);
|
|
1970
|
+
}
|
|
1971
|
+
}
|
|
1972
|
+
const isCold = serverCold || this.isColdFile(file);
|
|
1973
|
+
if (isCold) {
|
|
1974
|
+
this.log("cold", `Cold file changed: ${getFileName(file)}`);
|
|
1975
|
+
this.emit("cold", file);
|
|
1976
|
+
return;
|
|
1977
|
+
}
|
|
1978
|
+
const fileName = getFileName(file);
|
|
1979
|
+
const filePath = getFilePath(file);
|
|
1980
|
+
const actionType = action === HMR_ACTIONS.RELOAD ? "warning" : "add";
|
|
1981
|
+
this.log(actionType, `HMR ${action}: ${fileName}`);
|
|
1982
|
+
console.log(`%c \u2514\u2500 Path: ${filePath}`, "color: #888888; font-style: italic;");
|
|
1983
|
+
if (action === HMR_ACTIONS.RELOAD) {
|
|
1984
|
+
await this.fileLoader.reloadFile(file);
|
|
1985
|
+
} else {
|
|
1986
|
+
await this.fileLoader.loadFile(file);
|
|
1987
|
+
}
|
|
1988
|
+
if (this.onFileLoaded) {
|
|
1989
|
+
this.onFileLoaded(file);
|
|
1990
|
+
}
|
|
1991
|
+
this.emit(action, file);
|
|
1992
|
+
}
|
|
1993
|
+
async handleFileRemove(file) {
|
|
1994
|
+
if (this.shouldSkipFile(file, this.allFiles)) {
|
|
1995
|
+
this.log("skip", `Skipping remove: ${getFileName(file)}`);
|
|
1996
|
+
return;
|
|
1997
|
+
}
|
|
1998
|
+
const fileName = getFileName(file);
|
|
1999
|
+
const filePath = getFilePath(file);
|
|
2000
|
+
this.log("remove", `HMR remove: ${fileName}`);
|
|
2001
|
+
console.log(`%c \u2514\u2500 Path: ${filePath}`, "color: #888888; font-style: italic;");
|
|
2002
|
+
const overriddenFile = this.overrideMap.get(file);
|
|
2003
|
+
if (overriddenFile) {
|
|
2004
|
+
this.overrideMap.delete(file);
|
|
2005
|
+
const remainingOverrides = this._reverseOverrideMap.get(overriddenFile);
|
|
2006
|
+
if (remainingOverrides) {
|
|
2007
|
+
remainingOverrides.delete(file);
|
|
2008
|
+
if (remainingOverrides.size === 0) {
|
|
2009
|
+
this._reverseOverrideMap.delete(overriddenFile);
|
|
2010
|
+
this.log("override", `Restoring: ${getFileName(overriddenFile)}`);
|
|
2011
|
+
const originalExists = this.allFiles.includes(overriddenFile);
|
|
2012
|
+
if (originalExists) {
|
|
2013
|
+
try {
|
|
2014
|
+
await this.fileLoader.loadFile(overriddenFile);
|
|
2015
|
+
} catch (e) {
|
|
2016
|
+
this.log("error", `Failed to restore original: ${getFileName(overriddenFile)} - ${e.message}`);
|
|
2017
|
+
this.allFiles = this.allFiles.filter((f) => f !== overriddenFile);
|
|
2018
|
+
}
|
|
2019
|
+
} else {
|
|
2020
|
+
this.log("warning", `Original file no longer tracked, skipping restore: ${getFileName(overriddenFile)}`);
|
|
2021
|
+
}
|
|
2022
|
+
}
|
|
2023
|
+
}
|
|
2024
|
+
}
|
|
2025
|
+
await this.fileLoader.removeFile(file);
|
|
2026
|
+
this.emit(HMR_ACTIONS.REMOVE, file);
|
|
2027
|
+
}
|
|
2028
|
+
async handleMessage(data) {
|
|
2029
|
+
if (data.type === HMR_ACTIONS.INIT) {
|
|
2030
|
+
this.emit(HMR_ACTIONS.INIT, data);
|
|
2031
|
+
this.watchFiles = data.config?.watchFiles ?? true;
|
|
2032
|
+
if (!this.watchFiles) {
|
|
2033
|
+
this.log("info", "Static snapshot mode -> live watching disabled");
|
|
2034
|
+
}
|
|
2035
|
+
if (data.config?.cold?.length) {
|
|
2036
|
+
const merged = [.../* @__PURE__ */ new Set([...this._coldPatterns || [], ...data.config.cold])];
|
|
2037
|
+
this.isColdFile = this.makeFilter(merged, this._filterCold);
|
|
2038
|
+
}
|
|
2039
|
+
if (data.files && data.files.length > 0) {
|
|
2040
|
+
this.allFiles = [...data.files];
|
|
2041
|
+
await this.processInitFiles(data.files);
|
|
2042
|
+
} else {
|
|
2043
|
+
const modeLabel = this.watchFiles ? "HMR ready" : "Static snapshot ready";
|
|
2044
|
+
this.log("success", `${modeLabel} (${sorted.length} files loaded)`);
|
|
2045
|
+
}
|
|
2046
|
+
return;
|
|
2047
|
+
}
|
|
2048
|
+
const { action, file } = data;
|
|
2049
|
+
if (!action || !file) return;
|
|
2050
|
+
if (action === HMR_ACTIONS.ADD) {
|
|
2051
|
+
this.allFiles = [...this.allFiles, file];
|
|
2052
|
+
}
|
|
2053
|
+
if (action === HMR_ACTIONS.REMOVE) {
|
|
2054
|
+
this.allFiles = this.allFiles.filter((f) => f !== file);
|
|
2055
|
+
}
|
|
2056
|
+
if (action === HMR_ACTIONS.RELOAD || action === HMR_ACTIONS.ADD) {
|
|
2057
|
+
await this.handleFileChange(file, action, data.cold ?? false);
|
|
2058
|
+
}
|
|
2059
|
+
if (action === HMR_ACTIONS.REMOVE) {
|
|
2060
|
+
await this.handleFileRemove(file);
|
|
2061
|
+
}
|
|
2062
|
+
}
|
|
2063
|
+
/**
|
|
2064
|
+
* Register an event handler
|
|
2065
|
+
* @param {'init'|'reload'|'add'|'remove'|'cold'|'connect'|'disconnect'|'error'} event - Event name
|
|
2066
|
+
* @param {Function} handler - Event handler function
|
|
2067
|
+
* @returns {HMRClient} This client for chaining
|
|
2068
|
+
*/
|
|
2069
|
+
on(event, handler) {
|
|
2070
|
+
if (!this.eventHandlers.has(event)) {
|
|
2071
|
+
this.eventHandlers.set(event, []);
|
|
2072
|
+
}
|
|
2073
|
+
this.eventHandlers.get(event).push(handler);
|
|
2074
|
+
return this;
|
|
2075
|
+
}
|
|
2076
|
+
/**
|
|
2077
|
+
* Register a one-time event handler that auto-removes itself after the first call
|
|
2078
|
+
* @param {'init'|'reload'|'add'|'remove'|'cold'|'connect'|'disconnect'|'error'} event - Event name
|
|
2079
|
+
* @param {Function} handler - Event handler function
|
|
2080
|
+
* @returns {HMRClient} This client for chaining
|
|
2081
|
+
*/
|
|
2082
|
+
once(event, handler) {
|
|
2083
|
+
const wrapper = (...args) => {
|
|
2084
|
+
this.off(event, wrapper);
|
|
2085
|
+
handler(...args);
|
|
2086
|
+
};
|
|
2087
|
+
wrapper._original = handler;
|
|
2088
|
+
return this.on(event, wrapper);
|
|
2089
|
+
}
|
|
2090
|
+
/**
|
|
2091
|
+
* Remove a previously registered event handler
|
|
2092
|
+
* @param {'init'|'reload'|'add'|'remove'|'cold'|'connect'|'disconnect'|'error'} event - Event name
|
|
2093
|
+
* @param {Function} handler - The exact handler reference passed to `on()`
|
|
2094
|
+
* @returns {HMRClient} This client for chaining
|
|
2095
|
+
*/
|
|
2096
|
+
off(event, handler) {
|
|
2097
|
+
const handlers = this.eventHandlers.get(event);
|
|
2098
|
+
if (!handlers) return this;
|
|
2099
|
+
if (!handler) {
|
|
2100
|
+
this.eventHandlers.delete(event);
|
|
2101
|
+
return this;
|
|
2102
|
+
}
|
|
2103
|
+
const remaining = handlers.filter((h) => h !== handler && h._original !== handler);
|
|
2104
|
+
if (remaining.length === handlers.length) return this;
|
|
2105
|
+
if (remaining.length === 0) {
|
|
2106
|
+
this.eventHandlers.delete(event);
|
|
2107
|
+
} else {
|
|
2108
|
+
this.eventHandlers.set(event, remaining);
|
|
2109
|
+
}
|
|
2110
|
+
return this;
|
|
2111
|
+
}
|
|
2112
|
+
emit(event, ...args) {
|
|
2113
|
+
const handlers = this.eventHandlers.get(event);
|
|
2114
|
+
if (!handlers) return;
|
|
2115
|
+
for (const handler of [...handlers]) {
|
|
2116
|
+
handler(...args);
|
|
2117
|
+
}
|
|
2118
|
+
}
|
|
2119
|
+
// Push an incoming message onto the serial queue and drain it if not already
|
|
2120
|
+
// running. This ensures handleMessage calls never execute concurrently, a
|
|
2121
|
+
// rapid pair of change events for the same file would otherwise race between
|
|
2122
|
+
// removeFile and loadFile and could leave the DOM in a broken state.
|
|
2123
|
+
_enqueueMessage(data) {
|
|
2124
|
+
this._messageQueue.push(data);
|
|
2125
|
+
if (!this._processingMessages) this._drainMessageQueue();
|
|
2126
|
+
}
|
|
2127
|
+
async _drainMessageQueue() {
|
|
2128
|
+
this._processingMessages = true;
|
|
2129
|
+
while (this._messageQueue.length > 0) {
|
|
2130
|
+
const data = this._messageQueue.shift();
|
|
2131
|
+
try {
|
|
2132
|
+
await this.handleMessage(data);
|
|
2133
|
+
} catch (e) {
|
|
2134
|
+
this.log("error", `Message handling error: ${e.message}`);
|
|
2135
|
+
}
|
|
2136
|
+
}
|
|
2137
|
+
this._processingMessages = false;
|
|
2138
|
+
}
|
|
2139
|
+
/**
|
|
2140
|
+
* Connect to the HMR server
|
|
2141
|
+
* @returns {Promise<void>}
|
|
2142
|
+
*/
|
|
2143
|
+
connect() {
|
|
2144
|
+
this.autoReconnect = this._autoReconnectDefault;
|
|
2145
|
+
if (this._reconnectTimer) {
|
|
2146
|
+
clearTimeout(this._reconnectTimer);
|
|
2147
|
+
this._reconnectTimer = null;
|
|
2148
|
+
}
|
|
2149
|
+
if (this.socket) {
|
|
2150
|
+
this.socket.onopen = null;
|
|
2151
|
+
this.socket.onclose = null;
|
|
2152
|
+
this.socket.onerror = null;
|
|
2153
|
+
this.socket.onmessage = null;
|
|
2154
|
+
this.socket.close();
|
|
2155
|
+
this.socket = null;
|
|
2156
|
+
}
|
|
2157
|
+
return new Promise((resolve, reject) => {
|
|
2158
|
+
let settled = false;
|
|
2159
|
+
try {
|
|
2160
|
+
this.socket = new WebSocket(this.wsUrl);
|
|
2161
|
+
this.socket.onopen = () => {
|
|
2162
|
+
settled = true;
|
|
2163
|
+
this.isConnected = true;
|
|
2164
|
+
this.reconnectAttempts = 0;
|
|
2165
|
+
this._messageQueue = [];
|
|
2166
|
+
this._processingMessages = false;
|
|
2167
|
+
this.log("success", "HMR connected");
|
|
2168
|
+
this.emit("connect");
|
|
2169
|
+
resolve();
|
|
2170
|
+
};
|
|
2171
|
+
this.socket.onclose = () => {
|
|
2172
|
+
this.isConnected = false;
|
|
2173
|
+
this.socket = null;
|
|
2174
|
+
this.emit("disconnect");
|
|
2175
|
+
if (this.autoReconnect) {
|
|
2176
|
+
const delay = Math.min(
|
|
2177
|
+
this.reconnectDelay * Math.pow(1.5, this.reconnectAttempts++),
|
|
2178
|
+
this.maxReconnectDelay
|
|
2179
|
+
);
|
|
2180
|
+
const msg = settled ? `HMR disconnected, retrying in ${(delay / 1e3).toFixed(1)}s...` : `HMR connection failed, retrying in ${(delay / 1e3).toFixed(1)}s...`;
|
|
2181
|
+
this.log("disconnect", msg);
|
|
2182
|
+
this._reconnectTimer = setTimeout(() => {
|
|
2183
|
+
this.connect().catch((error) => {
|
|
2184
|
+
this.log("error", `Reconnect attempt failed: ${error.message}`);
|
|
2185
|
+
this.emit("error", error);
|
|
2186
|
+
});
|
|
2187
|
+
}, delay);
|
|
2188
|
+
} else {
|
|
2189
|
+
if (settled) this.log("disconnect", "HMR disconnected");
|
|
2190
|
+
}
|
|
2191
|
+
};
|
|
2192
|
+
this.socket.onerror = (error) => {
|
|
2193
|
+
const errorMsg = error.message || "Connection failed";
|
|
2194
|
+
this.log("error", `HMR error: ${errorMsg}`);
|
|
2195
|
+
this.emit("error", error);
|
|
2196
|
+
if (!settled) {
|
|
2197
|
+
settled = true;
|
|
2198
|
+
reject(error);
|
|
2199
|
+
}
|
|
2200
|
+
};
|
|
2201
|
+
this.socket.onmessage = (event) => {
|
|
2202
|
+
try {
|
|
2203
|
+
const data = JSON.parse(event.data);
|
|
2204
|
+
this._enqueueMessage(data);
|
|
2205
|
+
} catch (e) {
|
|
2206
|
+
this.log("error", `Failed to parse message: ${e.message}`);
|
|
2207
|
+
}
|
|
2208
|
+
};
|
|
2209
|
+
} catch (error) {
|
|
2210
|
+
this.log("error", `Failed to create WebSocket: ${error.message}`);
|
|
2211
|
+
reject(error);
|
|
2212
|
+
}
|
|
2213
|
+
});
|
|
2214
|
+
}
|
|
2215
|
+
/**
|
|
2216
|
+
* Disconnect from the HMR server and clean up
|
|
2217
|
+
*/
|
|
2218
|
+
disconnect() {
|
|
2219
|
+
this.autoReconnect = false;
|
|
2220
|
+
this.reconnectAttempts = 0;
|
|
2221
|
+
this.isConnected = false;
|
|
2222
|
+
clearTimeout(this._reconnectTimer);
|
|
2223
|
+
this._reconnectTimer = null;
|
|
2224
|
+
if (this.socket) {
|
|
2225
|
+
this.socket.close();
|
|
2226
|
+
this.socket = null;
|
|
2227
|
+
}
|
|
2228
|
+
}
|
|
2229
|
+
};
|
|
2230
|
+
return __toCommonJS(client_exports);
|
|
2231
|
+
})();
|
|
2232
|
+
//# sourceMappingURL=client.iife.js.map
|