vite-plugin-mock-dev-server 0.4.1 → 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -4
- package/README.zh-CN.md +19 -4
- package/dist/index.cjs +57 -36
- package/dist/index.d.ts +9 -12
- package/dist/index.js +58 -37
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -433,7 +433,22 @@ export default defineMock({
|
|
|
433
433
|
})
|
|
434
434
|
```
|
|
435
435
|
|
|
436
|
-
#### Example 8
|
|
436
|
+
#### Example 8:
|
|
437
|
+
Dynamic route matching
|
|
438
|
+
```ts
|
|
439
|
+
export default defineMock({
|
|
440
|
+
url: '/api/user/:userId',
|
|
441
|
+
body({ params }) {
|
|
442
|
+
return {
|
|
443
|
+
userId: params.userId,
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
})
|
|
447
|
+
```
|
|
448
|
+
|
|
449
|
+
The `userId` in the route will be resolved into the `request.params` object.
|
|
450
|
+
|
|
451
|
+
#### Example 9:
|
|
437
452
|
Use `mockjs`:
|
|
438
453
|
```ts
|
|
439
454
|
import Mock from 'mockjs'
|
|
@@ -448,7 +463,7 @@ export default defineMock({
|
|
|
448
463
|
```
|
|
449
464
|
You need installed `mockjs`
|
|
450
465
|
|
|
451
|
-
### Example
|
|
466
|
+
### Example 10:
|
|
452
467
|
Use `response` to customize the response
|
|
453
468
|
```ts
|
|
454
469
|
export default defineMock({
|
|
@@ -468,7 +483,7 @@ export default defineMock({
|
|
|
468
483
|
})
|
|
469
484
|
```
|
|
470
485
|
|
|
471
|
-
### Example
|
|
486
|
+
### Example 11:
|
|
472
487
|
Use json / json5
|
|
473
488
|
```json
|
|
474
489
|
{
|
|
@@ -480,7 +495,7 @@ Use json / json5
|
|
|
480
495
|
}
|
|
481
496
|
```
|
|
482
497
|
|
|
483
|
-
### Example
|
|
498
|
+
### Example 12:
|
|
484
499
|
|
|
485
500
|
multipart, upload file.
|
|
486
501
|
|
package/README.zh-CN.md
CHANGED
|
@@ -436,7 +436,22 @@ export default defineMock({
|
|
|
436
436
|
})
|
|
437
437
|
```
|
|
438
438
|
|
|
439
|
-
#### 示例8
|
|
439
|
+
#### 示例8:
|
|
440
|
+
动态路由匹配
|
|
441
|
+
```ts
|
|
442
|
+
export default defineMock({
|
|
443
|
+
url: '/api/user/:userId',
|
|
444
|
+
body({ params }) {
|
|
445
|
+
return {
|
|
446
|
+
userId: params.userId,
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
})
|
|
450
|
+
```
|
|
451
|
+
|
|
452
|
+
路由中的 `userId`将会解析到 `request.params` 对象中.
|
|
453
|
+
|
|
454
|
+
#### 示例9:
|
|
440
455
|
使用 `mockjs` 生成响应数据:
|
|
441
456
|
```ts
|
|
442
457
|
import Mock from 'mockjs'
|
|
@@ -451,7 +466,7 @@ export default defineMock({
|
|
|
451
466
|
```
|
|
452
467
|
请先安装 `mockjs`
|
|
453
468
|
|
|
454
|
-
### 示例
|
|
469
|
+
### 示例10:
|
|
455
470
|
使用 `response` 自定义响应
|
|
456
471
|
```ts
|
|
457
472
|
export default defineMock({
|
|
@@ -471,7 +486,7 @@ export default defineMock({
|
|
|
471
486
|
})
|
|
472
487
|
```
|
|
473
488
|
|
|
474
|
-
### 示例
|
|
489
|
+
### 示例11:
|
|
475
490
|
使用 json / json5
|
|
476
491
|
```json
|
|
477
492
|
{
|
|
@@ -483,7 +498,7 @@ export default defineMock({
|
|
|
483
498
|
}
|
|
484
499
|
```
|
|
485
500
|
|
|
486
|
-
### Example
|
|
501
|
+
### Example 12:
|
|
487
502
|
|
|
488
503
|
multipart, 文件上传.
|
|
489
504
|
|
package/dist/index.cjs
CHANGED
|
@@ -52,7 +52,7 @@ var import_vite = require("vite");
|
|
|
52
52
|
|
|
53
53
|
// package.json
|
|
54
54
|
var name = "vite-plugin-mock-dev-server";
|
|
55
|
-
var version = "0.4.
|
|
55
|
+
var version = "0.4.3";
|
|
56
56
|
|
|
57
57
|
// src/esbuildPlugin.ts
|
|
58
58
|
var import_promises = __toESM(require("fs/promises"), 1);
|
|
@@ -100,6 +100,7 @@ var import_node_fs = __toESM(require("fs"), 1);
|
|
|
100
100
|
var import_node_path2 = __toESM(require("path"), 1);
|
|
101
101
|
var import_node_url = require("url");
|
|
102
102
|
var import_debug = __toESM(require("debug"), 1);
|
|
103
|
+
var import_picocolors = __toESM(require("picocolors"), 1);
|
|
103
104
|
var isArray = (val) => Array.isArray(val);
|
|
104
105
|
var isFunction = (val) => typeof val === "function";
|
|
105
106
|
function sleep(timeout) {
|
|
@@ -116,6 +117,14 @@ var ensureArray = (thing) => {
|
|
|
116
117
|
return [];
|
|
117
118
|
return [thing];
|
|
118
119
|
};
|
|
120
|
+
var log = {
|
|
121
|
+
info(...args) {
|
|
122
|
+
console.info(import_picocolors.default.cyan("mock-dev-server: "), ...args);
|
|
123
|
+
},
|
|
124
|
+
error(...args) {
|
|
125
|
+
console.error("\n", import_picocolors.default.cyan("mock-dev-server: "), ...args, "\n");
|
|
126
|
+
}
|
|
127
|
+
};
|
|
119
128
|
function lookupFile(dir, formats, options) {
|
|
120
129
|
for (const format of formats) {
|
|
121
130
|
const fullPath = import_node_path2.default.join(dir, format);
|
|
@@ -319,6 +328,7 @@ async function buildMockEntry(inputFile, define) {
|
|
|
319
328
|
var import_node_url2 = require("url");
|
|
320
329
|
var import_http_status = __toESM(require("http-status"), 1);
|
|
321
330
|
var import_path_to_regexp = require("path-to-regexp");
|
|
331
|
+
var import_picocolors2 = __toESM(require("picocolors"), 1);
|
|
322
332
|
|
|
323
333
|
// src/parseReqBody.ts
|
|
324
334
|
var import_co_body = __toESM(require("co-body"), 1);
|
|
@@ -404,7 +414,7 @@ function baseMiddleware(mockLoader, { formidableOptions = {}, proxies }) {
|
|
|
404
414
|
pathname
|
|
405
415
|
) || { params: {} };
|
|
406
416
|
const params2 = urlMatch2.params || {};
|
|
407
|
-
const
|
|
417
|
+
const request2 = {
|
|
408
418
|
query,
|
|
409
419
|
refererQuery,
|
|
410
420
|
params: params2,
|
|
@@ -412,9 +422,9 @@ function baseMiddleware(mockLoader, { formidableOptions = {}, proxies }) {
|
|
|
412
422
|
headers: req.headers
|
|
413
423
|
};
|
|
414
424
|
if (isFunction(mock.validator)) {
|
|
415
|
-
return mock.validator(
|
|
425
|
+
return mock.validator(request2);
|
|
416
426
|
} else {
|
|
417
|
-
return validate(
|
|
427
|
+
return validate(request2, mock.validator);
|
|
418
428
|
}
|
|
419
429
|
}
|
|
420
430
|
return hasMock;
|
|
@@ -431,47 +441,53 @@ function baseMiddleware(mockLoader, { formidableOptions = {}, proxies }) {
|
|
|
431
441
|
pathname
|
|
432
442
|
) || { params: {} };
|
|
433
443
|
const params = urlMatch.params || {};
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
444
|
+
const request = req;
|
|
445
|
+
request.body = reqBody;
|
|
446
|
+
request.query = query;
|
|
447
|
+
request.refererQuery = refererQuery;
|
|
448
|
+
request.params = params;
|
|
438
449
|
res.setHeader("Content-Type", "application/json");
|
|
439
450
|
res.setHeader("Cache-Control", "no-cache,max-age=0");
|
|
440
|
-
res.setHeader("X-Mock", "generate by vite:mock-dev-server");
|
|
451
|
+
res.setHeader("X-Mock", "generate by vite:plugin-mock-dev-server");
|
|
441
452
|
if (currentMock.headers) {
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
});
|
|
453
|
+
try {
|
|
454
|
+
const headers = isFunction(currentMock.headers) ? await currentMock.headers(request) : currentMock.headers;
|
|
455
|
+
Object.keys(headers).forEach((key) => {
|
|
456
|
+
res.setHeader(key, headers[key]);
|
|
457
|
+
});
|
|
458
|
+
} catch (e) {
|
|
459
|
+
log.error(`${import_picocolors2.default.red("[headers error]")} ${req.url}
|
|
460
|
+
`, e);
|
|
461
|
+
}
|
|
452
462
|
}
|
|
453
463
|
if (currentMock.body) {
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
body
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
464
|
+
try {
|
|
465
|
+
let body;
|
|
466
|
+
if (isFunction(currentMock.body)) {
|
|
467
|
+
body = await currentMock.body(request);
|
|
468
|
+
} else {
|
|
469
|
+
body = currentMock.body;
|
|
470
|
+
}
|
|
471
|
+
res.end(JSON.stringify(body));
|
|
472
|
+
} catch (e) {
|
|
473
|
+
log.error(`${import_picocolors2.default.red("[body error]")} ${req.url}
|
|
474
|
+
`, e);
|
|
475
|
+
res.statusCode = 500;
|
|
476
|
+
res.statusMessage = getHTTPStatusText(res.statusCode);
|
|
477
|
+
res.end("");
|
|
465
478
|
}
|
|
466
|
-
res.end(JSON.stringify(body));
|
|
467
479
|
return;
|
|
468
480
|
}
|
|
469
481
|
if (currentMock.response) {
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
482
|
+
try {
|
|
483
|
+
await currentMock.response(request, res, next);
|
|
484
|
+
} catch (e) {
|
|
485
|
+
log.error(`${import_picocolors2.default.red("[response error]")} ${req.url}
|
|
486
|
+
`, e);
|
|
487
|
+
res.statusCode = 500;
|
|
488
|
+
res.statusMessage = getHTTPStatusText(res.statusCode);
|
|
489
|
+
res.end("");
|
|
490
|
+
}
|
|
475
491
|
return;
|
|
476
492
|
}
|
|
477
493
|
res.end("");
|
|
@@ -551,14 +567,17 @@ var _MockLoader = class extends import_node_events.default {
|
|
|
551
567
|
});
|
|
552
568
|
otherGlob.length > 0 && otherGlob.forEach((glob) => watcher.add(glob));
|
|
553
569
|
watcher.on("add", async (filepath) => {
|
|
570
|
+
filepath = (0, import_vite2.normalizePath)(filepath);
|
|
554
571
|
this.emit("mock:update", filepath);
|
|
555
572
|
debug("watcher:add", filepath);
|
|
556
573
|
});
|
|
557
574
|
watcher.on("change", async (filepath) => {
|
|
575
|
+
filepath = (0, import_vite2.normalizePath)(filepath);
|
|
558
576
|
this.emit("mock:update", filepath);
|
|
559
577
|
debug("watcher:change", filepath);
|
|
560
578
|
});
|
|
561
579
|
watcher.on("unlink", async (filepath) => {
|
|
580
|
+
filepath = (0, import_vite2.normalizePath)(filepath);
|
|
562
581
|
this.emit("mock:unlink", filepath);
|
|
563
582
|
debug("watcher:unlink", filepath);
|
|
564
583
|
});
|
|
@@ -575,12 +594,14 @@ var _MockLoader = class extends import_node_events.default {
|
|
|
575
594
|
cwd: this.cwd
|
|
576
595
|
});
|
|
577
596
|
this.depsWatcher.on("change", (filepath) => {
|
|
597
|
+
filepath = (0, import_vite2.normalizePath)(filepath);
|
|
578
598
|
const mockFiles = this.moduleDeps.get(filepath);
|
|
579
599
|
mockFiles && mockFiles.forEach((file) => {
|
|
580
600
|
this.emit("mock:update", file);
|
|
581
601
|
});
|
|
582
602
|
});
|
|
583
603
|
this.depsWatcher.on("unlink", (filepath) => {
|
|
604
|
+
filepath = (0, import_vite2.normalizePath)(filepath);
|
|
584
605
|
this.moduleDeps.delete(filepath);
|
|
585
606
|
});
|
|
586
607
|
this.on("update:deps", () => {
|
package/dist/index.d.ts
CHANGED
|
@@ -50,8 +50,9 @@ interface ServerBuildOption {
|
|
|
50
50
|
dist?: string;
|
|
51
51
|
}
|
|
52
52
|
type Method = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'TRACE' | 'OPTIONS';
|
|
53
|
+
type Headers = http.IncomingHttpHeaders;
|
|
53
54
|
type ResponseBody = Record<string, any> | any[] | string | number | null;
|
|
54
|
-
interface
|
|
55
|
+
interface ExtraRequest {
|
|
55
56
|
/**
|
|
56
57
|
* 请求地址中位于 `?` 后面的 queryString,已解析为 json
|
|
57
58
|
*/
|
|
@@ -69,17 +70,13 @@ interface ResponseReq {
|
|
|
69
70
|
*/
|
|
70
71
|
params: Record<string, any>;
|
|
71
72
|
/**
|
|
72
|
-
*
|
|
73
|
+
* 请求体中 headers
|
|
73
74
|
*/
|
|
74
|
-
headers:
|
|
75
|
+
headers: Headers;
|
|
75
76
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
interface ResponseHeaderFn {
|
|
80
|
-
(request: ResponseReq): Headers | Promise<Headers>;
|
|
81
|
-
}
|
|
82
|
-
type Headers = Record<string, any>;
|
|
77
|
+
type MockRequest = ExtraRequest & http.IncomingMessage;
|
|
78
|
+
type ResponseBodyFn = (request: MockRequest) => ResponseBody | Promise<ResponseBody>;
|
|
79
|
+
type ResponseHeaderFn = (request: MockRequest) => Headers | Promise<Headers>;
|
|
83
80
|
interface MockOptionsItem {
|
|
84
81
|
/**
|
|
85
82
|
* 需要做mock的接口地址,
|
|
@@ -136,7 +133,7 @@ interface MockOptionsItem {
|
|
|
136
133
|
*
|
|
137
134
|
* 在 req 中,还可以拿到 query、params、body等已解析的请求信息
|
|
138
135
|
*/
|
|
139
|
-
response?: (req:
|
|
136
|
+
response?: (req: MockRequest, res: http.ServerResponse<http.IncomingMessage>, next: Connect.NextFunction) => void | Promise<void>;
|
|
140
137
|
/**
|
|
141
138
|
* 请求验证器
|
|
142
139
|
*
|
|
@@ -144,7 +141,7 @@ interface MockOptionsItem {
|
|
|
144
141
|
* 但全部都在单个 mock中的 body或者 response 中写,内容会很庞杂,不好管理,
|
|
145
142
|
* 验证器的功能,允许你同时配置多条相同url的mock,通过验证器来判断使哪个mock生效。
|
|
146
143
|
*/
|
|
147
|
-
validator?: Partial<
|
|
144
|
+
validator?: Partial<ExtraRequest> | ((request: ExtraRequest) => boolean);
|
|
148
145
|
}
|
|
149
146
|
type MockOptions = MockOptionsItem[];
|
|
150
147
|
type FormidableFile = formidable.File | formidable.File[];
|
package/dist/index.js
CHANGED
|
@@ -9,7 +9,7 @@ import { createFilter } from "vite";
|
|
|
9
9
|
|
|
10
10
|
// package.json
|
|
11
11
|
var name = "vite-plugin-mock-dev-server";
|
|
12
|
-
var version = "0.4.
|
|
12
|
+
var version = "0.4.3";
|
|
13
13
|
|
|
14
14
|
// src/esbuildPlugin.ts
|
|
15
15
|
import fsp from "fs/promises";
|
|
@@ -57,6 +57,7 @@ import fs from "fs";
|
|
|
57
57
|
import path2 from "path";
|
|
58
58
|
import { fileURLToPath } from "url";
|
|
59
59
|
import Debug from "debug";
|
|
60
|
+
import colors from "picocolors";
|
|
60
61
|
var isArray = (val) => Array.isArray(val);
|
|
61
62
|
var isFunction = (val) => typeof val === "function";
|
|
62
63
|
function sleep(timeout) {
|
|
@@ -73,6 +74,14 @@ var ensureArray = (thing) => {
|
|
|
73
74
|
return [];
|
|
74
75
|
return [thing];
|
|
75
76
|
};
|
|
77
|
+
var log = {
|
|
78
|
+
info(...args) {
|
|
79
|
+
console.info(colors.cyan("mock-dev-server: "), ...args);
|
|
80
|
+
},
|
|
81
|
+
error(...args) {
|
|
82
|
+
console.error("\n", colors.cyan("mock-dev-server: "), ...args, "\n");
|
|
83
|
+
}
|
|
84
|
+
};
|
|
76
85
|
function lookupFile(dir, formats, options) {
|
|
77
86
|
for (const format of formats) {
|
|
78
87
|
const fullPath = path2.join(dir, format);
|
|
@@ -276,6 +285,7 @@ async function buildMockEntry(inputFile, define) {
|
|
|
276
285
|
import { parse as urlParse } from "url";
|
|
277
286
|
import HTTP_STATUS from "http-status";
|
|
278
287
|
import { match, pathToRegexp } from "path-to-regexp";
|
|
288
|
+
import colors2 from "picocolors";
|
|
279
289
|
|
|
280
290
|
// src/parseReqBody.ts
|
|
281
291
|
import bodyParser from "co-body";
|
|
@@ -361,7 +371,7 @@ function baseMiddleware(mockLoader, { formidableOptions = {}, proxies }) {
|
|
|
361
371
|
pathname
|
|
362
372
|
) || { params: {} };
|
|
363
373
|
const params2 = urlMatch2.params || {};
|
|
364
|
-
const
|
|
374
|
+
const request2 = {
|
|
365
375
|
query,
|
|
366
376
|
refererQuery,
|
|
367
377
|
params: params2,
|
|
@@ -369,9 +379,9 @@ function baseMiddleware(mockLoader, { formidableOptions = {}, proxies }) {
|
|
|
369
379
|
headers: req.headers
|
|
370
380
|
};
|
|
371
381
|
if (isFunction(mock.validator)) {
|
|
372
|
-
return mock.validator(
|
|
382
|
+
return mock.validator(request2);
|
|
373
383
|
} else {
|
|
374
|
-
return validate(
|
|
384
|
+
return validate(request2, mock.validator);
|
|
375
385
|
}
|
|
376
386
|
}
|
|
377
387
|
return hasMock;
|
|
@@ -388,47 +398,53 @@ function baseMiddleware(mockLoader, { formidableOptions = {}, proxies }) {
|
|
|
388
398
|
pathname
|
|
389
399
|
) || { params: {} };
|
|
390
400
|
const params = urlMatch.params || {};
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
401
|
+
const request = req;
|
|
402
|
+
request.body = reqBody;
|
|
403
|
+
request.query = query;
|
|
404
|
+
request.refererQuery = refererQuery;
|
|
405
|
+
request.params = params;
|
|
395
406
|
res.setHeader("Content-Type", "application/json");
|
|
396
407
|
res.setHeader("Cache-Control", "no-cache,max-age=0");
|
|
397
|
-
res.setHeader("X-Mock", "generate by vite:mock-dev-server");
|
|
408
|
+
res.setHeader("X-Mock", "generate by vite:plugin-mock-dev-server");
|
|
398
409
|
if (currentMock.headers) {
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
});
|
|
410
|
+
try {
|
|
411
|
+
const headers = isFunction(currentMock.headers) ? await currentMock.headers(request) : currentMock.headers;
|
|
412
|
+
Object.keys(headers).forEach((key) => {
|
|
413
|
+
res.setHeader(key, headers[key]);
|
|
414
|
+
});
|
|
415
|
+
} catch (e) {
|
|
416
|
+
log.error(`${colors2.red("[headers error]")} ${req.url}
|
|
417
|
+
`, e);
|
|
418
|
+
}
|
|
409
419
|
}
|
|
410
420
|
if (currentMock.body) {
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
body
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
421
|
+
try {
|
|
422
|
+
let body;
|
|
423
|
+
if (isFunction(currentMock.body)) {
|
|
424
|
+
body = await currentMock.body(request);
|
|
425
|
+
} else {
|
|
426
|
+
body = currentMock.body;
|
|
427
|
+
}
|
|
428
|
+
res.end(JSON.stringify(body));
|
|
429
|
+
} catch (e) {
|
|
430
|
+
log.error(`${colors2.red("[body error]")} ${req.url}
|
|
431
|
+
`, e);
|
|
432
|
+
res.statusCode = 500;
|
|
433
|
+
res.statusMessage = getHTTPStatusText(res.statusCode);
|
|
434
|
+
res.end("");
|
|
422
435
|
}
|
|
423
|
-
res.end(JSON.stringify(body));
|
|
424
436
|
return;
|
|
425
437
|
}
|
|
426
438
|
if (currentMock.response) {
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
439
|
+
try {
|
|
440
|
+
await currentMock.response(request, res, next);
|
|
441
|
+
} catch (e) {
|
|
442
|
+
log.error(`${colors2.red("[response error]")} ${req.url}
|
|
443
|
+
`, e);
|
|
444
|
+
res.statusCode = 500;
|
|
445
|
+
res.statusMessage = getHTTPStatusText(res.statusCode);
|
|
446
|
+
res.end("");
|
|
447
|
+
}
|
|
432
448
|
return;
|
|
433
449
|
}
|
|
434
450
|
res.end("");
|
|
@@ -451,7 +467,7 @@ import chokidar from "chokidar";
|
|
|
451
467
|
import { build as build2 } from "esbuild";
|
|
452
468
|
import fastGlob from "fast-glob";
|
|
453
469
|
import JSON52 from "json5";
|
|
454
|
-
import { createFilter as createFilter2 } from "vite";
|
|
470
|
+
import { createFilter as createFilter2, normalizePath } from "vite";
|
|
455
471
|
var _dirname = getDirname(import.meta.url);
|
|
456
472
|
var _require = createRequire(_dirname);
|
|
457
473
|
var _MockLoader = class extends EventEmitter {
|
|
@@ -508,14 +524,17 @@ var _MockLoader = class extends EventEmitter {
|
|
|
508
524
|
});
|
|
509
525
|
otherGlob.length > 0 && otherGlob.forEach((glob) => watcher.add(glob));
|
|
510
526
|
watcher.on("add", async (filepath) => {
|
|
527
|
+
filepath = normalizePath(filepath);
|
|
511
528
|
this.emit("mock:update", filepath);
|
|
512
529
|
debug("watcher:add", filepath);
|
|
513
530
|
});
|
|
514
531
|
watcher.on("change", async (filepath) => {
|
|
532
|
+
filepath = normalizePath(filepath);
|
|
515
533
|
this.emit("mock:update", filepath);
|
|
516
534
|
debug("watcher:change", filepath);
|
|
517
535
|
});
|
|
518
536
|
watcher.on("unlink", async (filepath) => {
|
|
537
|
+
filepath = normalizePath(filepath);
|
|
519
538
|
this.emit("mock:unlink", filepath);
|
|
520
539
|
debug("watcher:unlink", filepath);
|
|
521
540
|
});
|
|
@@ -532,12 +551,14 @@ var _MockLoader = class extends EventEmitter {
|
|
|
532
551
|
cwd: this.cwd
|
|
533
552
|
});
|
|
534
553
|
this.depsWatcher.on("change", (filepath) => {
|
|
554
|
+
filepath = normalizePath(filepath);
|
|
535
555
|
const mockFiles = this.moduleDeps.get(filepath);
|
|
536
556
|
mockFiles && mockFiles.forEach((file) => {
|
|
537
557
|
this.emit("mock:update", file);
|
|
538
558
|
});
|
|
539
559
|
});
|
|
540
560
|
this.depsWatcher.on("unlink", (filepath) => {
|
|
561
|
+
filepath = normalizePath(filepath);
|
|
541
562
|
this.moduleDeps.delete(filepath);
|
|
542
563
|
});
|
|
543
564
|
this.on("update:deps", () => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-mock-dev-server",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.3",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"vite",
|
|
6
6
|
"plugin",
|
|
@@ -39,7 +39,8 @@
|
|
|
39
39
|
"http-status": "^1.6.2",
|
|
40
40
|
"is-core-module": "^2.11.0",
|
|
41
41
|
"json5": "^2.2.3",
|
|
42
|
-
"path-to-regexp": "^6.2.1"
|
|
42
|
+
"path-to-regexp": "^6.2.1",
|
|
43
|
+
"picocolors": "^1.0.0"
|
|
43
44
|
},
|
|
44
45
|
"devDependencies": {
|
|
45
46
|
"@pengzhanbo/eslint-config-ts": "^0.3.2",
|