vite-plugin-mock-dev-server 1.5.0 → 1.5.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.
- package/dist/index.cjs +18 -12
- package/dist/index.js +17 -11
- package/package.json +18 -19
package/dist/index.cjs
CHANGED
|
@@ -44,7 +44,7 @@ __export(src_exports, {
|
|
|
44
44
|
});
|
|
45
45
|
module.exports = __toCommonJS(src_exports);
|
|
46
46
|
|
|
47
|
-
// node_modules/.pnpm/tsup@8.
|
|
47
|
+
// node_modules/.pnpm/tsup@8.1.0_postcss@8.4.38_typescript@5.5.2/node_modules/tsup/assets/cjs_shims.js
|
|
48
48
|
var getImportMetaUrl = () => typeof document === "undefined" ? new URL("file:" + __filename).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
|
|
49
49
|
var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
50
50
|
|
|
@@ -98,8 +98,9 @@ function lookupFile(dir, formats, options) {
|
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
100
|
const parentDir = import_node_path.default.dirname(dir);
|
|
101
|
-
if (parentDir !== dir && (!(options == null ? void 0 : options.rootDir) || parentDir.startsWith(options == null ? void 0 : options.rootDir)))
|
|
101
|
+
if (parentDir !== dir && (!(options == null ? void 0 : options.rootDir) || parentDir.startsWith(options == null ? void 0 : options.rootDir))) {
|
|
102
102
|
return lookupFile(parentDir, formats, options);
|
|
103
|
+
}
|
|
103
104
|
}
|
|
104
105
|
function ensureProxies(serverProxy = {}) {
|
|
105
106
|
const httpProxies = [];
|
|
@@ -107,10 +108,11 @@ function ensureProxies(serverProxy = {}) {
|
|
|
107
108
|
Object.keys(serverProxy).forEach((key) => {
|
|
108
109
|
var _a, _b;
|
|
109
110
|
const value = serverProxy[key];
|
|
110
|
-
if (typeof value === "string" || !value.ws && !((_a = value.target) == null ? void 0 : _a.toString().startsWith("ws:")) && !((_b = value.target) == null ? void 0 : _b.toString().startsWith("wss:")))
|
|
111
|
+
if (typeof value === "string" || !value.ws && !((_a = value.target) == null ? void 0 : _a.toString().startsWith("ws:")) && !((_b = value.target) == null ? void 0 : _b.toString().startsWith("wss:"))) {
|
|
111
112
|
httpProxies.push(key);
|
|
112
|
-
else
|
|
113
|
+
} else {
|
|
113
114
|
wsProxies.push(key);
|
|
115
|
+
}
|
|
114
116
|
});
|
|
115
117
|
return { httpProxies, wsProxies };
|
|
116
118
|
}
|
|
@@ -344,7 +346,7 @@ function canJsonParse(value) {
|
|
|
344
346
|
|
|
345
347
|
// src/build.ts
|
|
346
348
|
var packageName = true ? "vite-plugin-mock-dev-server" : "vite-plugin-mock-dev-server";
|
|
347
|
-
var packageVersion = true ? "1.5.
|
|
349
|
+
var packageVersion = true ? "1.5.1" : "latest";
|
|
348
350
|
async function generateMockServer(ctx, config, options) {
|
|
349
351
|
const include = (0, import_utils2.toArray)(options.include);
|
|
350
352
|
const exclude = (0, import_utils2.toArray)(options.exclude);
|
|
@@ -676,8 +678,7 @@ function twoPartMatch(rules) {
|
|
|
676
678
|
const dym = tokens.filter((token) => typeof token !== "string");
|
|
677
679
|
if (dym.length > 0)
|
|
678
680
|
dynamics.push(rule);
|
|
679
|
-
else
|
|
680
|
-
statics.push(rule);
|
|
681
|
+
else statics.push(rule);
|
|
681
682
|
}
|
|
682
683
|
return [statics, dynamics];
|
|
683
684
|
}
|
|
@@ -818,12 +819,14 @@ function baseMiddleware(mockLoader, {
|
|
|
818
819
|
return async function(req, res, next) {
|
|
819
820
|
const startTime = (0, import_utils6.timestamp)();
|
|
820
821
|
const { query, pathname } = urlParse(req.url);
|
|
821
|
-
if (!pathname || proxies.length === 0 || !proxies.some((context) => doesProxyContextMatchUrl(context, req.url)))
|
|
822
|
+
if (!pathname || proxies.length === 0 || !proxies.some((context) => doesProxyContextMatchUrl(context, req.url))) {
|
|
822
823
|
return next();
|
|
824
|
+
}
|
|
823
825
|
const mockData = mockLoader.mockData;
|
|
824
826
|
const mockUrls = matchingWeight(Object.keys(mockData), pathname, priority);
|
|
825
|
-
if (mockUrls.length === 0)
|
|
827
|
+
if (mockUrls.length === 0) {
|
|
826
828
|
return next();
|
|
829
|
+
}
|
|
827
830
|
collectRequest(req);
|
|
828
831
|
const { query: refererQuery } = urlParse(req.headers.referer || "");
|
|
829
832
|
const reqBody = await parseReqBody(req, formidableOptions, bodyParserOptions);
|
|
@@ -1034,8 +1037,9 @@ function sendData(res, raw, type) {
|
|
|
1034
1037
|
}
|
|
1035
1038
|
}
|
|
1036
1039
|
async function realDelay(startTime, delay) {
|
|
1037
|
-
if (!delay || typeof delay === "number" && delay <= 0 || (0, import_utils6.isArray)(delay) && delay.length !== 2)
|
|
1040
|
+
if (!delay || typeof delay === "number" && delay <= 0 || (0, import_utils6.isArray)(delay) && delay.length !== 2) {
|
|
1038
1041
|
return;
|
|
1042
|
+
}
|
|
1039
1043
|
let realDelay2 = 0;
|
|
1040
1044
|
if ((0, import_utils6.isArray)(delay)) {
|
|
1041
1045
|
const [min, max] = delay;
|
|
@@ -1433,8 +1437,9 @@ ${e}
|
|
|
1433
1437
|
});
|
|
1434
1438
|
httpServer == null ? void 0 : httpServer.on("upgrade", (req, socket, head) => {
|
|
1435
1439
|
const { pathname, query } = urlParse(req.url);
|
|
1436
|
-
if (!pathname || proxies.length === 0 || !proxies.some((context) => doesProxyContextMatchUrl(context, req.url)))
|
|
1440
|
+
if (!pathname || proxies.length === 0 || !proxies.some((context) => doesProxyContextMatchUrl(context, req.url))) {
|
|
1437
1441
|
return;
|
|
1442
|
+
}
|
|
1438
1443
|
const mockData = loader.mockData;
|
|
1439
1444
|
const mockUrl = Object.keys(mockData).find((key) => {
|
|
1440
1445
|
return (0, import_path_to_regexp4.pathToRegexp)(key).test(pathname);
|
|
@@ -1571,8 +1576,9 @@ function corsMiddleware(mockLoader, proxies, config, options) {
|
|
|
1571
1576
|
const { pathname } = urlParse(req.url);
|
|
1572
1577
|
if (!pathname || proxies.length === 0 || !proxies.some(
|
|
1573
1578
|
(context) => doesProxyContextMatchUrl(context, req.url)
|
|
1574
|
-
))
|
|
1579
|
+
)) {
|
|
1575
1580
|
return next();
|
|
1581
|
+
}
|
|
1576
1582
|
const mockData = mockLoader.mockData;
|
|
1577
1583
|
const mockUrl = Object.keys(mockData).find(
|
|
1578
1584
|
(key) => (0, import_path_to_regexp5.pathToRegexp)(key).test(pathname)
|
package/dist/index.js
CHANGED
|
@@ -48,8 +48,9 @@ function lookupFile(dir, formats, options) {
|
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
const parentDir = path.dirname(dir);
|
|
51
|
-
if (parentDir !== dir && (!(options == null ? void 0 : options.rootDir) || parentDir.startsWith(options == null ? void 0 : options.rootDir)))
|
|
51
|
+
if (parentDir !== dir && (!(options == null ? void 0 : options.rootDir) || parentDir.startsWith(options == null ? void 0 : options.rootDir))) {
|
|
52
52
|
return lookupFile(parentDir, formats, options);
|
|
53
|
+
}
|
|
53
54
|
}
|
|
54
55
|
function ensureProxies(serverProxy = {}) {
|
|
55
56
|
const httpProxies = [];
|
|
@@ -57,10 +58,11 @@ function ensureProxies(serverProxy = {}) {
|
|
|
57
58
|
Object.keys(serverProxy).forEach((key) => {
|
|
58
59
|
var _a, _b;
|
|
59
60
|
const value = serverProxy[key];
|
|
60
|
-
if (typeof value === "string" || !value.ws && !((_a = value.target) == null ? void 0 : _a.toString().startsWith("ws:")) && !((_b = value.target) == null ? void 0 : _b.toString().startsWith("wss:")))
|
|
61
|
+
if (typeof value === "string" || !value.ws && !((_a = value.target) == null ? void 0 : _a.toString().startsWith("ws:")) && !((_b = value.target) == null ? void 0 : _b.toString().startsWith("wss:"))) {
|
|
61
62
|
httpProxies.push(key);
|
|
62
|
-
else
|
|
63
|
+
} else {
|
|
63
64
|
wsProxies.push(key);
|
|
65
|
+
}
|
|
64
66
|
});
|
|
65
67
|
return { httpProxies, wsProxies };
|
|
66
68
|
}
|
|
@@ -294,7 +296,7 @@ function canJsonParse(value) {
|
|
|
294
296
|
|
|
295
297
|
// src/build.ts
|
|
296
298
|
var packageName = true ? "vite-plugin-mock-dev-server" : "vite-plugin-mock-dev-server";
|
|
297
|
-
var packageVersion = true ? "1.5.
|
|
299
|
+
var packageVersion = true ? "1.5.1" : "latest";
|
|
298
300
|
async function generateMockServer(ctx, config, options) {
|
|
299
301
|
const include = toArray(options.include);
|
|
300
302
|
const exclude = toArray(options.exclude);
|
|
@@ -639,8 +641,7 @@ function twoPartMatch(rules) {
|
|
|
639
641
|
const dym = tokens.filter((token) => typeof token !== "string");
|
|
640
642
|
if (dym.length > 0)
|
|
641
643
|
dynamics.push(rule);
|
|
642
|
-
else
|
|
643
|
-
statics.push(rule);
|
|
644
|
+
else statics.push(rule);
|
|
644
645
|
}
|
|
645
646
|
return [statics, dynamics];
|
|
646
647
|
}
|
|
@@ -781,12 +782,14 @@ function baseMiddleware(mockLoader, {
|
|
|
781
782
|
return async function(req, res, next) {
|
|
782
783
|
const startTime = timestamp();
|
|
783
784
|
const { query, pathname } = urlParse(req.url);
|
|
784
|
-
if (!pathname || proxies.length === 0 || !proxies.some((context) => doesProxyContextMatchUrl(context, req.url)))
|
|
785
|
+
if (!pathname || proxies.length === 0 || !proxies.some((context) => doesProxyContextMatchUrl(context, req.url))) {
|
|
785
786
|
return next();
|
|
787
|
+
}
|
|
786
788
|
const mockData = mockLoader.mockData;
|
|
787
789
|
const mockUrls = matchingWeight(Object.keys(mockData), pathname, priority);
|
|
788
|
-
if (mockUrls.length === 0)
|
|
790
|
+
if (mockUrls.length === 0) {
|
|
789
791
|
return next();
|
|
792
|
+
}
|
|
790
793
|
collectRequest(req);
|
|
791
794
|
const { query: refererQuery } = urlParse(req.headers.referer || "");
|
|
792
795
|
const reqBody = await parseReqBody(req, formidableOptions, bodyParserOptions);
|
|
@@ -997,8 +1000,9 @@ function sendData(res, raw, type) {
|
|
|
997
1000
|
}
|
|
998
1001
|
}
|
|
999
1002
|
async function realDelay(startTime, delay) {
|
|
1000
|
-
if (!delay || typeof delay === "number" && delay <= 0 || isArray3(delay) && delay.length !== 2)
|
|
1003
|
+
if (!delay || typeof delay === "number" && delay <= 0 || isArray3(delay) && delay.length !== 2) {
|
|
1001
1004
|
return;
|
|
1005
|
+
}
|
|
1002
1006
|
let realDelay2 = 0;
|
|
1003
1007
|
if (isArray3(delay)) {
|
|
1004
1008
|
const [min, max] = delay;
|
|
@@ -1402,8 +1406,9 @@ ${e}
|
|
|
1402
1406
|
});
|
|
1403
1407
|
httpServer == null ? void 0 : httpServer.on("upgrade", (req, socket, head) => {
|
|
1404
1408
|
const { pathname, query } = urlParse(req.url);
|
|
1405
|
-
if (!pathname || proxies.length === 0 || !proxies.some((context) => doesProxyContextMatchUrl(context, req.url)))
|
|
1409
|
+
if (!pathname || proxies.length === 0 || !proxies.some((context) => doesProxyContextMatchUrl(context, req.url))) {
|
|
1406
1410
|
return;
|
|
1411
|
+
}
|
|
1407
1412
|
const mockData = loader.mockData;
|
|
1408
1413
|
const mockUrl = Object.keys(mockData).find((key) => {
|
|
1409
1414
|
return pathToRegexp3(key).test(pathname);
|
|
@@ -1540,8 +1545,9 @@ function corsMiddleware(mockLoader, proxies, config, options) {
|
|
|
1540
1545
|
const { pathname } = urlParse(req.url);
|
|
1541
1546
|
if (!pathname || proxies.length === 0 || !proxies.some(
|
|
1542
1547
|
(context) => doesProxyContextMatchUrl(context, req.url)
|
|
1543
|
-
))
|
|
1548
|
+
)) {
|
|
1544
1549
|
return next();
|
|
1550
|
+
}
|
|
1545
1551
|
const mockData = mockLoader.mockData;
|
|
1546
1552
|
const mockUrl = Object.keys(mockData).find(
|
|
1547
1553
|
(key) => pathToRegexp4(key).test(pathname)
|
package/package.json
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-mock-dev-server",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.5.
|
|
5
|
-
"packageManager": "pnpm@8.15.5",
|
|
4
|
+
"version": "1.5.1",
|
|
6
5
|
"author": "pengzhanbo <q942450674@outlook.com> (https://github.com/pengzhanbo)",
|
|
7
6
|
"license": "MIT",
|
|
8
7
|
"homepage": "https://vite-plugin-mock-dev-server.netlify.app",
|
|
@@ -46,23 +45,23 @@
|
|
|
46
45
|
"@pengzhanbo/utils": "^1.1.2",
|
|
47
46
|
"@rollup/pluginutils": "^5.1.0",
|
|
48
47
|
"chokidar": "^3.6.0",
|
|
49
|
-
"co-body": "^6.
|
|
48
|
+
"co-body": "^6.2.0",
|
|
50
49
|
"cookies": "^0.9.1",
|
|
51
50
|
"cors": "^2.8.5",
|
|
52
|
-
"debug": "^4.3.
|
|
53
|
-
"esbuild": "^0.
|
|
51
|
+
"debug": "^4.3.5",
|
|
52
|
+
"esbuild": "^0.21.5",
|
|
54
53
|
"fast-glob": "^3.3.2",
|
|
55
54
|
"formidable": "2.1.2",
|
|
56
55
|
"http-status": "^1.7.4",
|
|
57
|
-
"is-core-module": "^2.
|
|
56
|
+
"is-core-module": "^2.14.0",
|
|
58
57
|
"json5": "^2.2.3",
|
|
59
58
|
"mime-types": "^2.1.35",
|
|
60
|
-
"path-to-regexp": "
|
|
61
|
-
"picocolors": "^1.0.
|
|
62
|
-
"ws": "^8.
|
|
59
|
+
"path-to-regexp": "6.2.2",
|
|
60
|
+
"picocolors": "^1.0.1",
|
|
61
|
+
"ws": "^8.17.1"
|
|
63
62
|
},
|
|
64
63
|
"devDependencies": {
|
|
65
|
-
"@pengzhanbo/eslint-config": "^1.
|
|
64
|
+
"@pengzhanbo/eslint-config": "^1.11.2",
|
|
66
65
|
"@types/co-body": "^6.1.3",
|
|
67
66
|
"@types/cookies": "^0.9.0",
|
|
68
67
|
"@types/cors": "^2.8.17",
|
|
@@ -70,17 +69,17 @@
|
|
|
70
69
|
"@types/formidable": "2.0.6",
|
|
71
70
|
"@types/is-core-module": "^2.2.2",
|
|
72
71
|
"@types/mime-types": "^2.1.4",
|
|
73
|
-
"@types/node": "^20.
|
|
72
|
+
"@types/node": "^20.14.9",
|
|
74
73
|
"@types/ws": "^8.5.10",
|
|
75
|
-
"bumpp": "^9.4.
|
|
76
|
-
"conventional-changelog-cli": "^
|
|
77
|
-
"eslint": "^
|
|
74
|
+
"bumpp": "^9.4.1",
|
|
75
|
+
"conventional-changelog-cli": "^5.0.0",
|
|
76
|
+
"eslint": "^9.6.0",
|
|
78
77
|
"mockjs": "^1.1.0",
|
|
79
|
-
"tsup": "^8.0
|
|
80
|
-
"typescript": "^5.
|
|
81
|
-
"vite": "^5.2
|
|
82
|
-
"vitepress": "^1.
|
|
83
|
-
"vitest": "^1.
|
|
78
|
+
"tsup": "^8.1.0",
|
|
79
|
+
"typescript": "^5.5.2",
|
|
80
|
+
"vite": "^5.3.2",
|
|
81
|
+
"vitepress": "^1.2.3",
|
|
82
|
+
"vitest": "^1.6.0"
|
|
84
83
|
},
|
|
85
84
|
"scripts": {
|
|
86
85
|
"build": "tsup && node ./deprecate.mjs",
|