vite-plugin-mock-dev-server 0.4.0 → 0.4.2
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/dist/index.cjs +13 -6
- package/dist/index.js +14 -7
- package/package.json +1 -1
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.2";
|
|
56
56
|
|
|
57
57
|
// src/esbuildPlugin.ts
|
|
58
58
|
var import_promises = __toESM(require("fs/promises"), 1);
|
|
@@ -324,21 +324,22 @@ var import_path_to_regexp = require("path-to-regexp");
|
|
|
324
324
|
var import_co_body = __toESM(require("co-body"), 1);
|
|
325
325
|
var import_formidable = __toESM(require("formidable"), 1);
|
|
326
326
|
async function parseReqBody(req, options) {
|
|
327
|
+
var _a;
|
|
327
328
|
const method = req.method.toUpperCase();
|
|
328
329
|
if (["GET", "DELETE", "HEAD"].includes(method))
|
|
329
330
|
return void 0;
|
|
330
|
-
const type = req.headers["content-type"];
|
|
331
|
+
const type = ((_a = req.headers["content-type"]) == null ? void 0 : _a.toLocaleLowerCase()) || "";
|
|
331
332
|
try {
|
|
332
|
-
if (type
|
|
333
|
+
if (type.startsWith("application/json")) {
|
|
333
334
|
return await import_co_body.default.json(req);
|
|
334
335
|
}
|
|
335
|
-
if (type
|
|
336
|
+
if (type.startsWith("application/x-www-form-urlencoded")) {
|
|
336
337
|
return await import_co_body.default.form(req);
|
|
337
338
|
}
|
|
338
|
-
if (type
|
|
339
|
+
if (type.startsWith("text/plain")) {
|
|
339
340
|
return await import_co_body.default.text(req);
|
|
340
341
|
}
|
|
341
|
-
if (type
|
|
342
|
+
if (type.startsWith("multipart/form-data")) {
|
|
342
343
|
return await parseMultipart(req, options);
|
|
343
344
|
}
|
|
344
345
|
} catch (e) {
|
|
@@ -435,6 +436,7 @@ function baseMiddleware(mockLoader, { formidableOptions = {}, proxies }) {
|
|
|
435
436
|
req.refererQuery = refererQuery;
|
|
436
437
|
req.params = params;
|
|
437
438
|
res.setHeader("Content-Type", "application/json");
|
|
439
|
+
res.setHeader("Cache-Control", "no-cache,max-age=0");
|
|
438
440
|
res.setHeader("X-Mock", "generate by vite:mock-dev-server");
|
|
439
441
|
if (currentMock.headers) {
|
|
440
442
|
const headers = isFunction(currentMock.headers) ? await currentMock.headers({
|
|
@@ -549,14 +551,17 @@ var _MockLoader = class extends import_node_events.default {
|
|
|
549
551
|
});
|
|
550
552
|
otherGlob.length > 0 && otherGlob.forEach((glob) => watcher.add(glob));
|
|
551
553
|
watcher.on("add", async (filepath) => {
|
|
554
|
+
filepath = (0, import_vite2.normalizePath)(filepath);
|
|
552
555
|
this.emit("mock:update", filepath);
|
|
553
556
|
debug("watcher:add", filepath);
|
|
554
557
|
});
|
|
555
558
|
watcher.on("change", async (filepath) => {
|
|
559
|
+
filepath = (0, import_vite2.normalizePath)(filepath);
|
|
556
560
|
this.emit("mock:update", filepath);
|
|
557
561
|
debug("watcher:change", filepath);
|
|
558
562
|
});
|
|
559
563
|
watcher.on("unlink", async (filepath) => {
|
|
564
|
+
filepath = (0, import_vite2.normalizePath)(filepath);
|
|
560
565
|
this.emit("mock:unlink", filepath);
|
|
561
566
|
debug("watcher:unlink", filepath);
|
|
562
567
|
});
|
|
@@ -573,12 +578,14 @@ var _MockLoader = class extends import_node_events.default {
|
|
|
573
578
|
cwd: this.cwd
|
|
574
579
|
});
|
|
575
580
|
this.depsWatcher.on("change", (filepath) => {
|
|
581
|
+
filepath = (0, import_vite2.normalizePath)(filepath);
|
|
576
582
|
const mockFiles = this.moduleDeps.get(filepath);
|
|
577
583
|
mockFiles && mockFiles.forEach((file) => {
|
|
578
584
|
this.emit("mock:update", file);
|
|
579
585
|
});
|
|
580
586
|
});
|
|
581
587
|
this.depsWatcher.on("unlink", (filepath) => {
|
|
588
|
+
filepath = (0, import_vite2.normalizePath)(filepath);
|
|
582
589
|
this.moduleDeps.delete(filepath);
|
|
583
590
|
});
|
|
584
591
|
this.on("update:deps", () => {
|
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.2";
|
|
13
13
|
|
|
14
14
|
// src/esbuildPlugin.ts
|
|
15
15
|
import fsp from "fs/promises";
|
|
@@ -281,21 +281,22 @@ import { match, pathToRegexp } from "path-to-regexp";
|
|
|
281
281
|
import bodyParser from "co-body";
|
|
282
282
|
import formidable from "formidable";
|
|
283
283
|
async function parseReqBody(req, options) {
|
|
284
|
+
var _a;
|
|
284
285
|
const method = req.method.toUpperCase();
|
|
285
286
|
if (["GET", "DELETE", "HEAD"].includes(method))
|
|
286
287
|
return void 0;
|
|
287
|
-
const type = req.headers["content-type"];
|
|
288
|
+
const type = ((_a = req.headers["content-type"]) == null ? void 0 : _a.toLocaleLowerCase()) || "";
|
|
288
289
|
try {
|
|
289
|
-
if (type
|
|
290
|
+
if (type.startsWith("application/json")) {
|
|
290
291
|
return await bodyParser.json(req);
|
|
291
292
|
}
|
|
292
|
-
if (type
|
|
293
|
+
if (type.startsWith("application/x-www-form-urlencoded")) {
|
|
293
294
|
return await bodyParser.form(req);
|
|
294
295
|
}
|
|
295
|
-
if (type
|
|
296
|
+
if (type.startsWith("text/plain")) {
|
|
296
297
|
return await bodyParser.text(req);
|
|
297
298
|
}
|
|
298
|
-
if (type
|
|
299
|
+
if (type.startsWith("multipart/form-data")) {
|
|
299
300
|
return await parseMultipart(req, options);
|
|
300
301
|
}
|
|
301
302
|
} catch (e) {
|
|
@@ -392,6 +393,7 @@ function baseMiddleware(mockLoader, { formidableOptions = {}, proxies }) {
|
|
|
392
393
|
req.refererQuery = refererQuery;
|
|
393
394
|
req.params = params;
|
|
394
395
|
res.setHeader("Content-Type", "application/json");
|
|
396
|
+
res.setHeader("Cache-Control", "no-cache,max-age=0");
|
|
395
397
|
res.setHeader("X-Mock", "generate by vite:mock-dev-server");
|
|
396
398
|
if (currentMock.headers) {
|
|
397
399
|
const headers = isFunction(currentMock.headers) ? await currentMock.headers({
|
|
@@ -449,7 +451,7 @@ import chokidar from "chokidar";
|
|
|
449
451
|
import { build as build2 } from "esbuild";
|
|
450
452
|
import fastGlob from "fast-glob";
|
|
451
453
|
import JSON52 from "json5";
|
|
452
|
-
import { createFilter as createFilter2 } from "vite";
|
|
454
|
+
import { createFilter as createFilter2, normalizePath } from "vite";
|
|
453
455
|
var _dirname = getDirname(import.meta.url);
|
|
454
456
|
var _require = createRequire(_dirname);
|
|
455
457
|
var _MockLoader = class extends EventEmitter {
|
|
@@ -506,14 +508,17 @@ var _MockLoader = class extends EventEmitter {
|
|
|
506
508
|
});
|
|
507
509
|
otherGlob.length > 0 && otherGlob.forEach((glob) => watcher.add(glob));
|
|
508
510
|
watcher.on("add", async (filepath) => {
|
|
511
|
+
filepath = normalizePath(filepath);
|
|
509
512
|
this.emit("mock:update", filepath);
|
|
510
513
|
debug("watcher:add", filepath);
|
|
511
514
|
});
|
|
512
515
|
watcher.on("change", async (filepath) => {
|
|
516
|
+
filepath = normalizePath(filepath);
|
|
513
517
|
this.emit("mock:update", filepath);
|
|
514
518
|
debug("watcher:change", filepath);
|
|
515
519
|
});
|
|
516
520
|
watcher.on("unlink", async (filepath) => {
|
|
521
|
+
filepath = normalizePath(filepath);
|
|
517
522
|
this.emit("mock:unlink", filepath);
|
|
518
523
|
debug("watcher:unlink", filepath);
|
|
519
524
|
});
|
|
@@ -530,12 +535,14 @@ var _MockLoader = class extends EventEmitter {
|
|
|
530
535
|
cwd: this.cwd
|
|
531
536
|
});
|
|
532
537
|
this.depsWatcher.on("change", (filepath) => {
|
|
538
|
+
filepath = normalizePath(filepath);
|
|
533
539
|
const mockFiles = this.moduleDeps.get(filepath);
|
|
534
540
|
mockFiles && mockFiles.forEach((file) => {
|
|
535
541
|
this.emit("mock:update", file);
|
|
536
542
|
});
|
|
537
543
|
});
|
|
538
544
|
this.depsWatcher.on("unlink", (filepath) => {
|
|
545
|
+
filepath = normalizePath(filepath);
|
|
539
546
|
this.moduleDeps.delete(filepath);
|
|
540
547
|
});
|
|
541
548
|
this.on("update:deps", () => {
|