vite-plugin-mock-dev-server 0.3.4 → 0.3.6
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 +14 -2
- package/README.zh-CN.md +14 -2
- package/dist/index.cjs +10 -5
- package/dist/index.d.ts +4 -4
- package/dist/index.js +6 -1
- package/package.json +18 -12
package/README.md
CHANGED
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
<p align="center">
|
|
9
9
|
<a href="https://www.npmjs.com/package/vite-plugin-mock-dev-server"><img alt="npm" src="https://img.shields.io/npm/v/vite-plugin-mock-dev-server?style=flat-square"></a>
|
|
10
10
|
<img alt="node-current" src="https://img.shields.io/node/v/vite-plugin-mock-dev-server?style=flat-square">
|
|
11
|
-
<img alt="
|
|
12
|
-
<img alt="
|
|
11
|
+
<img alt="npm peer dependency version" src="https://img.shields.io/npm/dependency-version/vite-plugin-mock-dev-server/peer/vite?style=flat-square">
|
|
12
|
+
<img alt="GitHub" src="https://img.shields.io/github/license/pengzhanbo/vite-plugin-mock-dev-server?style=flat-square">
|
|
13
13
|
</p>
|
|
14
14
|
<br>
|
|
15
15
|
<p align="center">
|
|
@@ -34,6 +34,10 @@
|
|
|
34
34
|
- ⚖️ Use `server.proxy`
|
|
35
35
|
- 🍕 Support `viteConfig.define` in mock file
|
|
36
36
|
|
|
37
|
+
## Documentation
|
|
38
|
+
|
|
39
|
+
See the [documentation](https://vite-plugin-mock-dev-server.netlify.app/) to learn more.
|
|
40
|
+
[](https://app.netlify.com/sites/vite-plugin-mock-dev-server/deploys)
|
|
37
41
|
|
|
38
42
|
## Usage
|
|
39
43
|
|
|
@@ -411,3 +415,11 @@ Use json / json5
|
|
|
411
415
|
}
|
|
412
416
|
}
|
|
413
417
|
```
|
|
418
|
+
|
|
419
|
+
## Archives
|
|
420
|
+
|
|
421
|
+
[awesome-vite](https://github.com/vitejs/awesome-vite#helpers)
|
|
422
|
+
|
|
423
|
+
## LICENSE
|
|
424
|
+
|
|
425
|
+
[GPL-3.0](/LICENSE)
|
package/README.zh-CN.md
CHANGED
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
<p align="center">
|
|
11
11
|
<a href="https://www.npmjs.com/package/vite-plugin-mock-dev-server"><img alt="npm" src="https://img.shields.io/npm/v/vite-plugin-mock-dev-server?style=flat-square"></a>
|
|
12
12
|
<img alt="node-current" src="https://img.shields.io/node/v/vite-plugin-mock-dev-server?style=flat-square">
|
|
13
|
-
<img alt="
|
|
14
|
-
<img alt="
|
|
13
|
+
<img alt="npm peer dependency version" src="https://img.shields.io/npm/dependency-version/vite-plugin-mock-dev-server/peer/vite?style=flat-square">
|
|
14
|
+
<img alt="GitHub" src="https://img.shields.io/github/license/pengzhanbo/vite-plugin-mock-dev-server?style=flat-square">
|
|
15
15
|
</p>
|
|
16
16
|
<br>
|
|
17
17
|
<p align="center">
|
|
@@ -36,6 +36,10 @@
|
|
|
36
36
|
- 🍕 支持在 mock文件中使用 `viteConfig.define`配置字段
|
|
37
37
|
|
|
38
38
|
|
|
39
|
+
## 文档
|
|
40
|
+
|
|
41
|
+
查看 [Documentation](https://vite-plugin-mock-dev-server.netlify.app/) 了解更多。
|
|
42
|
+
[](https://app.netlify.com/sites/vite-plugin-mock-dev-server/deploys)
|
|
39
43
|
## 使用
|
|
40
44
|
|
|
41
45
|
### 安装
|
|
@@ -403,3 +407,11 @@ export default defineMock({
|
|
|
403
407
|
}
|
|
404
408
|
}
|
|
405
409
|
```
|
|
410
|
+
|
|
411
|
+
## Archives
|
|
412
|
+
|
|
413
|
+
[awesome-vite](https://github.com/vitejs/awesome-vite#helpers)
|
|
414
|
+
|
|
415
|
+
## LICENSE
|
|
416
|
+
|
|
417
|
+
[GPL-3.0](/LICENSE)
|
package/dist/index.cjs
CHANGED
|
@@ -33,7 +33,7 @@ __export(src_exports, {
|
|
|
33
33
|
module.exports = __toCommonJS(src_exports);
|
|
34
34
|
|
|
35
35
|
// src/mockMiddleware.ts
|
|
36
|
-
var
|
|
36
|
+
var import_node_url3 = require("url");
|
|
37
37
|
var import_path_to_regexp = require("path-to-regexp");
|
|
38
38
|
|
|
39
39
|
// src/MockLoader.ts
|
|
@@ -41,7 +41,7 @@ var import_node_events = __toESM(require("events"), 1);
|
|
|
41
41
|
var import_node_fs2 = __toESM(require("fs"), 1);
|
|
42
42
|
var import_node_module = require("module");
|
|
43
43
|
var import_node_path2 = __toESM(require("path"), 1);
|
|
44
|
-
var
|
|
44
|
+
var import_node_url2 = require("url");
|
|
45
45
|
var import_pluginutils = require("@rollup/pluginutils");
|
|
46
46
|
var import_chokidar = __toESM(require("chokidar"), 1);
|
|
47
47
|
var import_esbuild = require("esbuild");
|
|
@@ -51,12 +51,16 @@ var import_json5 = __toESM(require("json5"), 1);
|
|
|
51
51
|
// src/utils.ts
|
|
52
52
|
var import_node_fs = __toESM(require("fs"), 1);
|
|
53
53
|
var import_node_path = __toESM(require("path"), 1);
|
|
54
|
+
var import_node_url = require("url");
|
|
54
55
|
var import_debug = __toESM(require("debug"), 1);
|
|
55
56
|
var isArray = (val) => Array.isArray(val);
|
|
56
57
|
var isFunction = (val) => typeof val === "function";
|
|
57
58
|
function sleep(timeout) {
|
|
58
59
|
return new Promise((resolve) => setTimeout(resolve, timeout));
|
|
59
60
|
}
|
|
61
|
+
function getDirname(importMetaUrl) {
|
|
62
|
+
return import_node_path.default.dirname((0, import_node_url.fileURLToPath)(importMetaUrl));
|
|
63
|
+
}
|
|
60
64
|
var debug = (0, import_debug.default)("vite:plugin-mock-dev-server");
|
|
61
65
|
function lookupFile(dir, formats, options) {
|
|
62
66
|
for (const format of formats) {
|
|
@@ -76,7 +80,8 @@ function lookupFile(dir, formats, options) {
|
|
|
76
80
|
|
|
77
81
|
// src/MockLoader.ts
|
|
78
82
|
var import_meta = {};
|
|
79
|
-
var
|
|
83
|
+
var _dirname = typeof __dirname !== "undefined" ? __dirname : getDirname(import_meta.url);
|
|
84
|
+
var _require = (0, import_node_module.createRequire)(_dirname);
|
|
80
85
|
var _MockLoader = class extends import_node_events.default {
|
|
81
86
|
constructor(options) {
|
|
82
87
|
super();
|
|
@@ -237,7 +242,7 @@ var _MockLoader = class extends import_node_events.default {
|
|
|
237
242
|
if (isESM) {
|
|
238
243
|
const fileBase = `${filepath}.timestamp-${Date.now()}`;
|
|
239
244
|
const fileNameTmp = `${fileBase}.mjs`;
|
|
240
|
-
const fileUrl = `${(0,
|
|
245
|
+
const fileUrl = `${(0, import_node_url2.pathToFileURL)(fileBase)}.mjs`;
|
|
241
246
|
await import_node_fs2.default.promises.writeFile(fileNameTmp, code, "utf8");
|
|
242
247
|
try {
|
|
243
248
|
return await import(fileUrl);
|
|
@@ -360,7 +365,7 @@ async function mockServerMiddleware(httpServer, config, options) {
|
|
|
360
365
|
return next();
|
|
361
366
|
}
|
|
362
367
|
const method = req.method.toUpperCase();
|
|
363
|
-
const { query, pathname } = (0,
|
|
368
|
+
const { query, pathname } = (0, import_node_url3.parse)(req.url, true);
|
|
364
369
|
const reqBody = await parseReqBody(req);
|
|
365
370
|
const currentMock = loader.mockList.find((mock) => {
|
|
366
371
|
if (!pathname || !mock || !mock.url)
|
package/dist/index.d.ts
CHANGED
|
@@ -14,8 +14,8 @@ interface MockServerPluginOptions {
|
|
|
14
14
|
*/
|
|
15
15
|
exclude?: string | string[];
|
|
16
16
|
}
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
type Method = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'TRACE' | 'OPTIONS';
|
|
18
|
+
type ResponseBody = Record<string, any> | any[] | string | number | null;
|
|
19
19
|
interface ResponseReq {
|
|
20
20
|
/**
|
|
21
21
|
* 请求地址中位于 `?` 后面的 queryString,已解析为 json
|
|
@@ -40,7 +40,7 @@ interface ResponseBodyFn {
|
|
|
40
40
|
interface ResponseHeaderFn {
|
|
41
41
|
(request: ResponseReq): Headers | Promise<Headers>;
|
|
42
42
|
}
|
|
43
|
-
|
|
43
|
+
type Headers = Record<string, any>;
|
|
44
44
|
interface MockOptionsItem {
|
|
45
45
|
/**
|
|
46
46
|
* 需要做mock的接口地址,
|
|
@@ -107,7 +107,7 @@ interface MockOptionsItem {
|
|
|
107
107
|
*/
|
|
108
108
|
validator?: Partial<ResponseReq> | ((request: ResponseReq) => boolean);
|
|
109
109
|
}
|
|
110
|
-
|
|
110
|
+
type MockOptions = MockOptionsItem[];
|
|
111
111
|
|
|
112
112
|
declare function mockDevServerPlugin({ include, exclude, }?: MockServerPluginOptions): Plugin;
|
|
113
113
|
|
package/dist/index.js
CHANGED
|
@@ -17,12 +17,16 @@ import JSON5 from "json5";
|
|
|
17
17
|
// src/utils.ts
|
|
18
18
|
import fs from "fs";
|
|
19
19
|
import path from "path";
|
|
20
|
+
import { fileURLToPath } from "url";
|
|
20
21
|
import Debug from "debug";
|
|
21
22
|
var isArray = (val) => Array.isArray(val);
|
|
22
23
|
var isFunction = (val) => typeof val === "function";
|
|
23
24
|
function sleep(timeout) {
|
|
24
25
|
return new Promise((resolve) => setTimeout(resolve, timeout));
|
|
25
26
|
}
|
|
27
|
+
function getDirname(importMetaUrl) {
|
|
28
|
+
return path.dirname(fileURLToPath(importMetaUrl));
|
|
29
|
+
}
|
|
26
30
|
var debug = Debug("vite:plugin-mock-dev-server");
|
|
27
31
|
function lookupFile(dir, formats, options) {
|
|
28
32
|
for (const format of formats) {
|
|
@@ -41,7 +45,8 @@ function lookupFile(dir, formats, options) {
|
|
|
41
45
|
}
|
|
42
46
|
|
|
43
47
|
// src/MockLoader.ts
|
|
44
|
-
var
|
|
48
|
+
var _dirname = typeof __dirname !== "undefined" ? __dirname : getDirname(import.meta.url);
|
|
49
|
+
var _require = createRequire(_dirname);
|
|
45
50
|
var _MockLoader = class extends EventEmitter {
|
|
46
51
|
constructor(options) {
|
|
47
52
|
super();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-mock-dev-server",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.6",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"vite",
|
|
6
6
|
"plugin",
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"type": "git",
|
|
13
13
|
"url": "https://github.com/pengzhanbo/vite-plugin-mock-dev-server"
|
|
14
14
|
},
|
|
15
|
+
"homepage": "https://vite-plugin-mock-dev-server.netlify.app",
|
|
15
16
|
"author": "pengzhanbo <q942450674@outlook.com> (https://github.com/pengzhanbo)",
|
|
16
17
|
"license": "GPL-3.0",
|
|
17
18
|
"type": "module",
|
|
@@ -46,11 +47,10 @@
|
|
|
46
47
|
"chokidar": "^3.5.3",
|
|
47
48
|
"co-body": "^6.1.0",
|
|
48
49
|
"debug": "^4.3.4",
|
|
49
|
-
"esbuild": "^0.
|
|
50
|
+
"esbuild": "^0.16.9",
|
|
50
51
|
"fast-glob": "^3.2.12",
|
|
51
|
-
"json5": "^2.2.
|
|
52
|
-
"path-to-regexp": "^6.2.1"
|
|
53
|
-
"vite": "^3.2.0"
|
|
52
|
+
"json5": "^2.2.2",
|
|
53
|
+
"path-to-regexp": "^6.2.1"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@pengzhanbo/eslint-config-ts": "^0.2.10",
|
|
@@ -59,23 +59,29 @@
|
|
|
59
59
|
"@types/debug": "^4.1.7",
|
|
60
60
|
"@types/node": "^18.11.7",
|
|
61
61
|
"bumpp": "^8.2.1",
|
|
62
|
-
"eslint": "^8.
|
|
62
|
+
"eslint": "^8.30.0",
|
|
63
63
|
"mockjs": "^1.1.0",
|
|
64
|
-
"prettier": "^2.
|
|
65
|
-
"tsup": "^6.
|
|
66
|
-
"typescript": "^4.
|
|
67
|
-
"vite
|
|
64
|
+
"prettier": "^2.8.1",
|
|
65
|
+
"tsup": "^6.5.0",
|
|
66
|
+
"typescript": "^4.9.4",
|
|
67
|
+
"vite": "^4.0.2",
|
|
68
|
+
"vite-plugin-mock-dev-server": "file:",
|
|
69
|
+
"vitepress": "1.0.0-alpha.32",
|
|
70
|
+
"vue": "^3.2.45"
|
|
68
71
|
},
|
|
69
72
|
"peerDependencies": {
|
|
70
73
|
"vite": ">=3.0.0"
|
|
71
74
|
},
|
|
72
|
-
"packageManager": "pnpm@7.
|
|
75
|
+
"packageManager": "pnpm@7.18.2",
|
|
73
76
|
"engines": {
|
|
74
|
-
"node": ">=16"
|
|
77
|
+
"node": "^14.18.0 || >=16"
|
|
75
78
|
},
|
|
76
79
|
"scripts": {
|
|
77
80
|
"dev": "DEBUG=vite:plugin-mock-dev-server vite example --config ./example/vite.config.ts",
|
|
78
81
|
"build": "tsup",
|
|
82
|
+
"docs:dev": "vitepress dev docs",
|
|
83
|
+
"docs:build": "vitepress build docs",
|
|
84
|
+
"docs:preview": "vitepress preview docs",
|
|
79
85
|
"release": "bumpp package.json --commit --push --tag && pnpm publish --access public"
|
|
80
86
|
}
|
|
81
87
|
}
|