rspack-plugin-mock 0.3.4 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,198 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/core/requestRecovery.ts
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/core/transform.ts
2
+
3
+
4
+
5
+
6
+
7
+
8
+ var _utils = require('@pengzhanbo/utils');
9
+
10
+ // src/core/utils.ts
11
+ var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs);
12
+ var _os = require('os'); var _os2 = _interopRequireDefault(_os);
13
+ var _path = require('path'); var _path2 = _interopRequireDefault(_path);
14
+ var _querystring = require('querystring');
15
+ var _url = require('url');
16
+ var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
17
+ var _memfs = require('memfs');
18
+ var _pathtoregexp = require('path-to-regexp');
19
+ var packageDir = getDirname(import.meta.url);
20
+ var vfs = _memfs.createFsFromVolume.call(void 0, new (0, _memfs.Volume)());
21
+ function isStream(stream) {
22
+ return stream !== null && typeof stream === "object" && typeof stream.pipe === "function";
23
+ }
24
+ function isReadableStream(stream) {
25
+ return isStream(stream) && stream.readable !== false && typeof stream._read === "function" && typeof stream._readableState === "object";
26
+ }
27
+ function getDirname(importMetaUrl) {
28
+ return _path2.default.dirname(_url.fileURLToPath.call(void 0, importMetaUrl));
29
+ }
30
+ var debug = _debug2.default.call(void 0, "rspack:mock");
31
+ function lookupFile(dir, formats, options) {
32
+ for (const format of formats) {
33
+ const fullPath = _path2.default.join(dir, format);
34
+ if (_fs2.default.existsSync(fullPath) && _fs2.default.statSync(fullPath).isFile()) {
35
+ const result = _optionalChain([options, 'optionalAccess', _ => _.pathOnly]) ? fullPath : _fs2.default.readFileSync(fullPath, "utf-8");
36
+ if (!_optionalChain([options, 'optionalAccess', _2 => _2.predicate]) || options.predicate(result))
37
+ return result;
38
+ }
39
+ }
40
+ const parentDir = _path2.default.dirname(dir);
41
+ if (parentDir !== dir && (!_optionalChain([options, 'optionalAccess', _3 => _3.rootDir]) || parentDir.startsWith(_optionalChain([options, 'optionalAccess', _4 => _4.rootDir])))) {
42
+ return lookupFile(parentDir, formats, options);
43
+ }
44
+ }
45
+ function doesProxyContextMatchUrl(context, url, req) {
46
+ if (typeof context === "function") {
47
+ return context(url, req);
48
+ }
49
+ return context[0] === "^" && new RegExp(context).test(url) || url.startsWith(context);
50
+ }
51
+ function parseParams(pattern, url) {
52
+ const urlMatch = _pathtoregexp.match.call(void 0, pattern, { decode: decodeURIComponent })(url) || {
53
+ params: {}
54
+ };
55
+ return urlMatch.params || {};
56
+ }
57
+ function urlParse(input) {
58
+ const url = new (0, _url.URL)(input, "http://example.com");
59
+ const pathname = decodeURIComponent(url.pathname);
60
+ const query = _querystring.parse.call(void 0, url.search.replace(/^\?/, ""));
61
+ return { pathname, query };
62
+ }
63
+ var windowsSlashRE = /\\/g;
64
+ var isWindows = _os2.default.platform() === "win32";
65
+ function slash(p) {
66
+ return p.replace(windowsSlashRE, "/");
67
+ }
68
+ function normalizePath(id) {
69
+ return _path2.default.posix.normalize(isWindows ? slash(id) : id);
70
+ }
71
+ function waitingFor(onSuccess, maxRetry = 5) {
72
+ return function wait(getter, retry = 0) {
73
+ const value = getter();
74
+ if (value) {
75
+ onSuccess(value);
76
+ } else if (retry < maxRetry) {
77
+ setTimeout(() => wait(getter, retry + 1), 100);
78
+ }
79
+ };
80
+ }
81
+
82
+ // src/core/validator.ts
83
+
84
+ function validate(request, validator) {
85
+ return isObjectSubset(request.headers, validator.headers) && isObjectSubset(request.body, validator.body) && isObjectSubset(request.params, validator.params) && isObjectSubset(request.query, validator.query) && isObjectSubset(request.refererQuery, validator.refererQuery);
86
+ }
87
+ function isObjectSubset(source, target) {
88
+ if (!target)
89
+ return true;
90
+ for (const key in target) {
91
+ if (!isIncluded(source[key], target[key]))
92
+ return false;
93
+ }
94
+ return true;
95
+ }
96
+ function isIncluded(source, target) {
97
+ if (_utils.isArray.call(void 0, source) && _utils.isArray.call(void 0, target)) {
98
+ const seen = /* @__PURE__ */ new Set();
99
+ return target.every(
100
+ (ti) => source.some((si, i) => {
101
+ if (seen.has(i))
102
+ return false;
103
+ const included = isIncluded(si, ti);
104
+ if (included)
105
+ seen.add(i);
106
+ return included;
107
+ })
108
+ );
109
+ }
110
+ if (_utils.isObject.call(void 0, source) && _utils.isObject.call(void 0, target))
111
+ return isObjectSubset(source, target);
112
+ return Object.is(source, target);
113
+ }
114
+
115
+ // src/core/transform.ts
116
+ function transformRawData(rawData) {
117
+ return rawData.filter((item) => item[0]).map(([raw, __filepath__]) => {
118
+ let mockConfig;
119
+ if (raw.default) {
120
+ if (Array.isArray(raw.default)) {
121
+ mockConfig = raw.default.map((item) => ({ ...item, __filepath__ }));
122
+ } else {
123
+ mockConfig = { ...raw.default, __filepath__ };
124
+ }
125
+ } else if ("url" in raw) {
126
+ mockConfig = { ...raw, __filepath__ };
127
+ } else {
128
+ mockConfig = [];
129
+ Object.keys(raw || {}).forEach((key) => {
130
+ if (Array.isArray(raw[key])) {
131
+ mockConfig.push(...raw[key].map((item) => ({ ...item, __filepath__ })));
132
+ } else {
133
+ mockConfig.push({ ...raw[key], __filepath__ });
134
+ }
135
+ });
136
+ }
137
+ return mockConfig;
138
+ });
139
+ }
140
+ function transformMockData(mockList) {
141
+ const list = [];
142
+ for (const [, handle] of mockList.entries()) {
143
+ if (handle)
144
+ list.push(..._utils.toArray.call(void 0, handle));
145
+ }
146
+ const mocks = {};
147
+ list.filter((mock) => _utils.isObject.call(void 0, mock) && mock.enabled !== false && mock.url).forEach((mock) => {
148
+ const { pathname, query } = urlParse(mock.url);
149
+ const list2 = mocks[pathname] ??= [];
150
+ const current = { ...mock, url: pathname };
151
+ if (current.ws !== true) {
152
+ const validator = current.validator;
153
+ if (!_utils.isEmptyObject.call(void 0, query)) {
154
+ if (_utils.isFunction.call(void 0, validator)) {
155
+ current.validator = function(request) {
156
+ return isObjectSubset(request.query, query) && validator(request);
157
+ };
158
+ } else if (validator) {
159
+ current.validator = { ...validator };
160
+ current.validator.query = current.validator.query ? { ...query, ...current.validator.query } : query;
161
+ } else {
162
+ current.validator = { query };
163
+ }
164
+ }
165
+ }
166
+ list2.push(current);
167
+ });
168
+ Object.keys(mocks).forEach((key) => {
169
+ mocks[key] = sortByValidator(mocks[key]);
170
+ });
171
+ return mocks;
172
+ }
173
+ function sortByValidator(mocks) {
174
+ return _utils.sortBy.call(void 0, mocks, (item) => {
175
+ if (item.ws === true)
176
+ return 0;
177
+ const { validator } = item;
178
+ if (!validator || _utils.isEmptyObject.call(void 0, validator))
179
+ return 2;
180
+ if (_utils.isFunction.call(void 0, validator))
181
+ return 0;
182
+ const count = Object.keys(validator).reduce(
183
+ (prev, key) => prev + keysCount(validator[key]),
184
+ 0
185
+ );
186
+ return 1 / count;
187
+ });
188
+ }
189
+ function keysCount(obj) {
190
+ if (!obj)
191
+ return 0;
192
+ return Object.keys(obj).length;
193
+ }
194
+
195
+ // src/core/requestRecovery.ts
2
196
  var _buffer = require('buffer');
3
197
  var requestCollectCache = /* @__PURE__ */ new WeakMap();
4
198
  function collectRequest(req) {
@@ -31,11 +225,11 @@ function rewriteRequest(proxyReq, req) {
31
225
 
32
226
 
33
227
 
34
- var _utils = require('@pengzhanbo/utils');
228
+
35
229
  var _cookies = require('cookies'); var _cookies2 = _interopRequireDefault(_cookies);
36
230
  var _httpstatus = require('http-status'); var _httpstatus2 = _interopRequireDefault(_httpstatus);
37
231
  var _mimetypes = require('mime-types'); var mime = _interopRequireWildcard(_mimetypes);
38
- var _pathtoregexp = require('path-to-regexp');
232
+
39
233
  var _picocolors = require('picocolors'); var _picocolors2 = _interopRequireDefault(_picocolors);
40
234
 
41
235
  // src/core/matchingWeight.ts
@@ -191,7 +385,7 @@ async function parseReqBody(req, formidableOptions, bodyParserOptions = {}) {
191
385
  const method = req.method.toUpperCase();
192
386
  if (["GET", "DELETE", "HEAD"].includes(method))
193
387
  return void 0;
194
- const type = _optionalChain([req, 'access', _ => _.headers, 'access', _2 => _2["content-type"], 'optionalAccess', _3 => _3.toLocaleLowerCase, 'call', _4 => _4()]) || "";
388
+ const type = _optionalChain([req, 'access', _5 => _5.headers, 'access', _6 => _6["content-type"], 'optionalAccess', _7 => _7.toLocaleLowerCase, 'call', _8 => _8()]) || "";
195
389
  const { limit, formLimit, jsonLimit, textLimit, ...rest } = bodyParserOptions;
196
390
  try {
197
391
  if (type.startsWith("application/json")) {
@@ -232,111 +426,6 @@ async function parseMultipart(req, options) {
232
426
  });
233
427
  }
234
428
 
235
- // src/core/utils.ts
236
- var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs);
237
- var _path = require('path'); var _path2 = _interopRequireDefault(_path);
238
- var _querystring = require('querystring');
239
- var _url = require('url');
240
- var _os = require('os'); var _os2 = _interopRequireDefault(_os);
241
- var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
242
-
243
- var _memfs = require('memfs');
244
- var packageDir = getDirname(import.meta.url);
245
- var vfs = _memfs.createFsFromVolume.call(void 0, new (0, _memfs.Volume)());
246
- function isStream(stream) {
247
- return stream !== null && typeof stream === "object" && typeof stream.pipe === "function";
248
- }
249
- function isReadableStream(stream) {
250
- return isStream(stream) && stream.readable !== false && typeof stream._read === "function" && typeof stream._readableState === "object";
251
- }
252
- function getDirname(importMetaUrl) {
253
- return _path2.default.dirname(_url.fileURLToPath.call(void 0, importMetaUrl));
254
- }
255
- var debug = _debug2.default.call(void 0, "rspack:mock");
256
- function lookupFile(dir, formats, options) {
257
- for (const format of formats) {
258
- const fullPath = _path2.default.join(dir, format);
259
- if (_fs2.default.existsSync(fullPath) && _fs2.default.statSync(fullPath).isFile()) {
260
- const result = _optionalChain([options, 'optionalAccess', _5 => _5.pathOnly]) ? fullPath : _fs2.default.readFileSync(fullPath, "utf-8");
261
- if (!_optionalChain([options, 'optionalAccess', _6 => _6.predicate]) || options.predicate(result))
262
- return result;
263
- }
264
- }
265
- const parentDir = _path2.default.dirname(dir);
266
- if (parentDir !== dir && (!_optionalChain([options, 'optionalAccess', _7 => _7.rootDir]) || parentDir.startsWith(_optionalChain([options, 'optionalAccess', _8 => _8.rootDir])))) {
267
- return lookupFile(parentDir, formats, options);
268
- }
269
- }
270
- function doesProxyContextMatchUrl(context, url, req) {
271
- if (typeof context === "function") {
272
- return context(url, req);
273
- }
274
- return context[0] === "^" && new RegExp(context).test(url) || url.startsWith(context);
275
- }
276
- function parseParams(pattern, url) {
277
- const urlMatch = _pathtoregexp.match.call(void 0, pattern, { decode: decodeURIComponent })(url) || {
278
- params: {}
279
- };
280
- return urlMatch.params || {};
281
- }
282
- function urlParse(input) {
283
- const url = new (0, _url.URL)(input, "http://example.com");
284
- const pathname = decodeURIComponent(url.pathname);
285
- const query = _querystring.parse.call(void 0, url.search.replace(/^\?/, ""));
286
- return { pathname, query };
287
- }
288
- var windowsSlashRE = /\\/g;
289
- var isWindows = _os2.default.platform() === "win32";
290
- function slash(p) {
291
- return p.replace(windowsSlashRE, "/");
292
- }
293
- function normalizePath(id) {
294
- return _path2.default.posix.normalize(isWindows ? slash(id) : id);
295
- }
296
- function waitingFor(onSuccess, maxRetry = 5) {
297
- return function wait(getter, retry = 0) {
298
- const value = getter();
299
- if (value) {
300
- onSuccess(value);
301
- } else if (retry < maxRetry) {
302
- setTimeout(() => wait(getter, retry + 1), 100);
303
- }
304
- };
305
- }
306
-
307
- // src/core/validator.ts
308
-
309
- function validate(request, validator) {
310
- return isObjectSubset(request.headers, validator.headers) && isObjectSubset(request.body, validator.body) && isObjectSubset(request.params, validator.params) && isObjectSubset(request.query, validator.query) && isObjectSubset(request.refererQuery, validator.refererQuery);
311
- }
312
- function isObjectSubset(source, target) {
313
- if (!target)
314
- return true;
315
- for (const key in target) {
316
- if (!isIncluded(source[key], target[key]))
317
- return false;
318
- }
319
- return true;
320
- }
321
- function isIncluded(source, target) {
322
- if (_utils.isArray.call(void 0, source) && _utils.isArray.call(void 0, target)) {
323
- const seen = /* @__PURE__ */ new Set();
324
- return target.every(
325
- (ti) => source.some((si, i) => {
326
- if (seen.has(i))
327
- return false;
328
- const included = isIncluded(si, ti);
329
- if (included)
330
- seen.add(i);
331
- return included;
332
- })
333
- );
334
- }
335
- if (_utils.isObject.call(void 0, source) && _utils.isObject.call(void 0, target))
336
- return isObjectSubset(source, target);
337
- return Object.is(source, target);
338
- }
339
-
340
429
  // src/core/baseMiddleware.ts
341
430
  function baseMiddleware(compiler, {
342
431
  formidableOptions = {},
@@ -600,134 +689,6 @@ function requestLog(request, filepath) {
600
689
  return `${ms} ${pathname}${qs}${ps}${bs}${file}`;
601
690
  }
602
691
 
603
- // src/core/logger.ts
604
-
605
-
606
- var logLevels = {
607
- silent: 0,
608
- error: 1,
609
- warn: 2,
610
- info: 3,
611
- debug: 4
612
- };
613
- function createLogger(prefix, defaultLevel = "info") {
614
- prefix = `[${prefix}]`;
615
- function output(type, msg, level) {
616
- level = _utils.isBoolean.call(void 0, level) ? level ? defaultLevel : "error" : level;
617
- const thresh = logLevels[level];
618
- if (thresh >= logLevels[type]) {
619
- const method = type === "info" || type === "debug" ? "log" : type;
620
- const tag = type === "debug" ? _picocolors2.default.magenta(_picocolors2.default.bold(prefix)) : type === "info" ? _picocolors2.default.cyan(_picocolors2.default.bold(prefix)) : type === "warn" ? _picocolors2.default.yellow(_picocolors2.default.bold(prefix)) : _picocolors2.default.red(_picocolors2.default.bold(prefix));
621
- const format = `${_picocolors2.default.dim(
622
- (/* @__PURE__ */ new Date()).toLocaleTimeString()
623
- )} ${tag} ${msg}`;
624
- console[method](format);
625
- }
626
- }
627
- const logger = {
628
- debug(msg, level = defaultLevel) {
629
- output("debug", msg, level);
630
- },
631
- info(msg, level = defaultLevel) {
632
- output("info", msg, level);
633
- },
634
- warn(msg, level = defaultLevel) {
635
- output("warn", msg, level);
636
- },
637
- error(msg, level = defaultLevel) {
638
- output("error", msg, level);
639
- }
640
- };
641
- return logger;
642
- }
643
-
644
- // src/core/transform.ts
645
-
646
-
647
-
648
-
649
-
650
-
651
-
652
- function transformRawData(rawData) {
653
- return rawData.filter((item) => item[0]).map(([raw, __filepath__]) => {
654
- let mockConfig;
655
- if (raw.default) {
656
- if (Array.isArray(raw.default)) {
657
- mockConfig = raw.default.map((item) => ({ ...item, __filepath__ }));
658
- } else {
659
- mockConfig = { ...raw.default, __filepath__ };
660
- }
661
- } else if ("url" in raw) {
662
- mockConfig = { ...raw, __filepath__ };
663
- } else {
664
- mockConfig = [];
665
- Object.keys(raw || {}).forEach((key) => {
666
- if (Array.isArray(raw[key])) {
667
- mockConfig.push(...raw[key].map((item) => ({ ...item, __filepath__ })));
668
- } else {
669
- mockConfig.push({ ...raw[key], __filepath__ });
670
- }
671
- });
672
- }
673
- return mockConfig;
674
- });
675
- }
676
- function transformMockData(mockList) {
677
- const list = [];
678
- for (const [, handle] of mockList.entries()) {
679
- if (handle)
680
- list.push(..._utils.toArray.call(void 0, handle));
681
- }
682
- const mocks = {};
683
- list.filter((mock) => _utils.isObject.call(void 0, mock) && mock.enabled !== false && mock.url).forEach((mock) => {
684
- const { pathname, query } = urlParse(mock.url);
685
- const list2 = mocks[pathname] ??= [];
686
- const current = { ...mock, url: pathname };
687
- if (current.ws !== true) {
688
- const validator = current.validator;
689
- if (!_utils.isEmptyObject.call(void 0, query)) {
690
- if (_utils.isFunction.call(void 0, validator)) {
691
- current.validator = function(request) {
692
- return isObjectSubset(request.query, query) && validator(request);
693
- };
694
- } else if (validator) {
695
- current.validator = { ...validator };
696
- current.validator.query = current.validator.query ? { ...query, ...current.validator.query } : query;
697
- } else {
698
- current.validator = { query };
699
- }
700
- }
701
- }
702
- list2.push(current);
703
- });
704
- Object.keys(mocks).forEach((key) => {
705
- mocks[key] = sortByValidator(mocks[key]);
706
- });
707
- return mocks;
708
- }
709
- function sortByValidator(mocks) {
710
- return _utils.sortBy.call(void 0, mocks, (item) => {
711
- if (item.ws === true)
712
- return 0;
713
- const { validator } = item;
714
- if (!validator || _utils.isEmptyObject.call(void 0, validator))
715
- return 2;
716
- if (_utils.isFunction.call(void 0, validator))
717
- return 0;
718
- const count = Object.keys(validator).reduce(
719
- (prev, key) => prev + keysCount(validator[key]),
720
- 0
721
- );
722
- return 1 / count;
723
- });
724
- }
725
- function keysCount(obj) {
726
- if (!obj)
727
- return 0;
728
- return Object.keys(obj).length;
729
- }
730
-
731
692
  // src/core/mockWebsocket.ts
732
693
 
733
694
 
@@ -747,12 +708,6 @@ function mockWebSocket(compiler, httpServer, {
747
708
  poolMap.set(mockUrl, wssMap = /* @__PURE__ */ new Map());
748
709
  return wssMap;
749
710
  };
750
- const getWss = (wssMap, pathname) => {
751
- let wss = wssMap.get(pathname);
752
- if (!wss)
753
- wssMap.set(pathname, wss = new (0, _ws.WebSocketServer)({ noServer: true }));
754
- return wss;
755
- };
756
711
  const addHmr = (filepath, mockUrl) => {
757
712
  let urlList = hmrMap.get(filepath);
758
713
  if (!urlList)
@@ -784,14 +739,6 @@ ${e}
784
739
  );
785
740
  }
786
741
  };
787
- const emitConnection = (wss, ws, req, connectionList) => {
788
- wss.emit("connection", ws, req);
789
- ws.on("close", () => {
790
- const i = connectionList.findIndex((item) => item.ws === ws);
791
- if (i !== -1)
792
- connectionList.splice(i, 1);
793
- });
794
- };
795
742
  const restartWss = (wssMap, wss, mock, pathname, filepath) => {
796
743
  const { cleanupList, connectionList, context } = wssContextMap.get(wss);
797
744
  cleanupRunner(cleanupList);
@@ -879,12 +826,67 @@ ${e}
879
826
  hmrMap.clear();
880
827
  })]);
881
828
  }
829
+ function getWss(wssMap, pathname) {
830
+ let wss = wssMap.get(pathname);
831
+ if (!wss)
832
+ wssMap.set(pathname, wss = new (0, _ws.WebSocketServer)({ noServer: true }));
833
+ return wss;
834
+ }
835
+ function emitConnection(wss, ws, req, connectionList) {
836
+ wss.emit("connection", ws, req);
837
+ ws.on("close", () => {
838
+ const i = connectionList.findIndex((item) => item.ws === ws);
839
+ if (i !== -1)
840
+ connectionList.splice(i, 1);
841
+ });
842
+ }
882
843
  function cleanupRunner(cleanupList) {
883
844
  let cleanup;
884
845
  while (cleanup = cleanupList.shift())
885
846
  _optionalChain([cleanup, 'optionalCall', _15 => _15()]);
886
847
  }
887
848
 
849
+ // src/core/logger.ts
850
+
851
+
852
+ var logLevels = {
853
+ silent: 0,
854
+ error: 1,
855
+ warn: 2,
856
+ info: 3,
857
+ debug: 4
858
+ };
859
+ function createLogger(prefix, defaultLevel = "info") {
860
+ prefix = `[${prefix}]`;
861
+ function output(type, msg, level) {
862
+ level = _utils.isBoolean.call(void 0, level) ? level ? defaultLevel : "error" : level;
863
+ const thresh = logLevels[level];
864
+ if (thresh >= logLevels[type]) {
865
+ const method = type === "info" || type === "debug" ? "log" : type;
866
+ const tag = type === "debug" ? _picocolors2.default.magenta(_picocolors2.default.bold(prefix)) : type === "info" ? _picocolors2.default.cyan(_picocolors2.default.bold(prefix)) : type === "warn" ? _picocolors2.default.yellow(_picocolors2.default.bold(prefix)) : _picocolors2.default.red(_picocolors2.default.bold(prefix));
867
+ const format = `${_picocolors2.default.dim(
868
+ (/* @__PURE__ */ new Date()).toLocaleTimeString()
869
+ )} ${tag} ${msg}`;
870
+ console[method](format);
871
+ }
872
+ }
873
+ const logger = {
874
+ debug(msg, level = defaultLevel) {
875
+ output("debug", msg, level);
876
+ },
877
+ info(msg, level = defaultLevel) {
878
+ output("info", msg, level);
879
+ },
880
+ warn(msg, level = defaultLevel) {
881
+ output("warn", msg, level);
882
+ },
883
+ error(msg, level = defaultLevel) {
884
+ output("error", msg, level);
885
+ }
886
+ };
887
+ return logger;
888
+ }
889
+
888
890
 
889
891
 
890
892
 
@@ -901,4 +903,4 @@ function cleanupRunner(cleanupList) {
901
903
 
902
904
 
903
905
 
904
- exports.packageDir = packageDir; exports.vfs = vfs; exports.lookupFile = lookupFile; exports.doesProxyContextMatchUrl = doesProxyContextMatchUrl; exports.urlParse = urlParse; exports.normalizePath = normalizePath; exports.waitingFor = waitingFor; exports.rewriteRequest = rewriteRequest; exports.baseMiddleware = baseMiddleware; exports.logLevels = logLevels; exports.createLogger = createLogger; exports.transformRawData = transformRawData; exports.transformMockData = transformMockData; exports.sortByValidator = sortByValidator; exports.mockWebSocket = mockWebSocket;
906
+ exports.packageDir = packageDir; exports.vfs = vfs; exports.lookupFile = lookupFile; exports.doesProxyContextMatchUrl = doesProxyContextMatchUrl; exports.urlParse = urlParse; exports.normalizePath = normalizePath; exports.waitingFor = waitingFor; exports.transformRawData = transformRawData; exports.transformMockData = transformMockData; exports.sortByValidator = sortByValidator; exports.rewriteRequest = rewriteRequest; exports.baseMiddleware = baseMiddleware; exports.mockWebSocket = mockWebSocket; exports.logLevels = logLevels; exports.createLogger = createLogger;