vite-plugin-mock-dev-server 2.0.0 → 2.0.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/{helper-BbR8Si2U.js → helper-BXYm8ulO.js} +1 -1
- package/dist/helper.d.ts +2 -2
- package/dist/helper.js +1 -1
- package/dist/{index-CJc2Oax2.d.ts → index-HdmSyOec.d.ts} +2 -2
- package/dist/index.d.ts +3 -3
- package/dist/index.js +28 -39
- package/dist/{server-D-sv_WW9.js → server-4Xi0IyG-.js} +28 -29
- package/dist/{server-tcT2vAaP.d.ts → server-nb5Kby5K.d.ts} +4 -4
- package/dist/server.d.ts +2 -2
- package/dist/server.js +1 -1
- package/dist/{types-BtCJqeLH.d.ts → types-BYW0Xh7Y.d.ts} +1 -1
- package/dist/types.d.ts +1 -1
- package/package.json +7 -7
package/dist/helper.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { HeaderStream,
|
|
1
|
+
import { _ as WebSocketSetupContext, a as LogType, c as MockMatchPriority, d as MockRequest, f as MockResponse, g as ServerBuildOption, h as ResponseBody, i as LogLevel, l as MockMatchSpecialPriority, m as MockWebsocketItem, n as ExtraRequest, o as Method, p as MockServerPluginOptions, r as FormidableFile, s as MockHttpItem, t as BodyParserOptions, u as MockOptions } from "./types-BYW0Xh7Y.js";
|
|
2
|
+
import { a as HeaderStream, i as defineMock, n as defineMockData, o as SSEMessage, r as createDefineMock, s as createSSEStream, t as MockData } from "./index-HdmSyOec.js";
|
|
3
3
|
export { BodyParserOptions, ExtraRequest, FormidableFile, HeaderStream, LogLevel, LogType, Method, MockData, MockHttpItem, MockMatchPriority, MockMatchSpecialPriority, MockOptions, MockRequest, MockResponse, MockServerPluginOptions, MockWebsocketItem, ResponseBody, SSEMessage, ServerBuildOption, WebSocketSetupContext, createDefineMock, createSSEStream, defineMock, defineMockData };
|
package/dist/helper.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { i as createSSEStream, n as createDefineMock, r as defineMock, t as defineMockData } from "./helper-BXYm8ulO.js";
|
|
2
2
|
|
|
3
3
|
export { createDefineMock, createSSEStream, defineMock, defineMockData };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MockHttpItem, MockOptions
|
|
1
|
+
import { m as MockWebsocketItem, s as MockHttpItem, u as MockOptions } from "./types-BYW0Xh7Y.js";
|
|
2
2
|
import { Transform } from "node:stream";
|
|
3
3
|
import { IncomingMessage, OutgoingHttpHeaders, ServerResponse } from "node:http";
|
|
4
4
|
|
|
@@ -123,4 +123,4 @@ type MockData<T = any> = readonly [() => T, (val: T | ((val: T) => T | void)) =>
|
|
|
123
123
|
};
|
|
124
124
|
declare function defineMockData<T = any>(key: string, initialData: T): MockData<T>;
|
|
125
125
|
//#endregion
|
|
126
|
-
export { HeaderStream,
|
|
126
|
+
export { HeaderStream as a, defineMock as i, defineMockData as n, SSEMessage as o, createDefineMock as r, createSSEStream as s, MockData as t };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { HeaderStream,
|
|
3
|
-
import {
|
|
1
|
+
import { _ as WebSocketSetupContext, a as LogType, c as MockMatchPriority, d as MockRequest, f as MockResponse, g as ServerBuildOption, h as ResponseBody, i as LogLevel, l as MockMatchSpecialPriority, m as MockWebsocketItem, n as ExtraRequest, o as Method, p as MockServerPluginOptions, r as FormidableFile, s as MockHttpItem, t as BodyParserOptions, u as MockOptions } from "./types-BYW0Xh7Y.js";
|
|
2
|
+
import { a as HeaderStream, i as defineMock, n as defineMockData, o as SSEMessage, r as createDefineMock, s as createSSEStream, t as MockData } from "./index-HdmSyOec.js";
|
|
3
|
+
import { a as createLogger, c as processRawData, i as Logger, l as sortByValidator, n as CreateMockMiddlewareOptions, o as logLevels, r as createMockMiddleware, s as processMockData, t as mockWebSocket } from "./server-nb5Kby5K.js";
|
|
4
4
|
import { Plugin } from "vite";
|
|
5
5
|
|
|
6
6
|
//#region src/plugin.d.ts
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { a as processRawData, c as debug, d as logLevels, f as isPathMatch, h as createMatcher, i as processMockData, l as normalizePath, m as doesProxyContextMatchUrl, n as createMockMiddleware, o as sortByValidator, p as isPackageExists, r as recoverRequest, s as urlParse, t as mockWebSocket, u as createLogger } from "./server-4Xi0IyG-.js";
|
|
2
|
+
import { i as createSSEStream, n as createDefineMock, r as defineMock, t as defineMockData } from "./helper-BXYm8ulO.js";
|
|
3
3
|
import { isArray, isBoolean, promiseParallel, toArray, uniq } from "@pengzhanbo/utils";
|
|
4
4
|
import fs, { promises } from "node:fs";
|
|
5
5
|
import fsp from "node:fs/promises";
|
|
6
6
|
import path from "node:path";
|
|
7
7
|
import process from "node:process";
|
|
8
8
|
import ansis from "ansis";
|
|
9
|
-
import { getPackageInfoSync,
|
|
9
|
+
import { getPackageInfoSync, loadPackageJSON, loadPackageJSONSync } from "local-pkg";
|
|
10
10
|
import { pathToFileURL } from "node:url";
|
|
11
11
|
import JSON5 from "json5";
|
|
12
12
|
import EventEmitter from "node:events";
|
|
@@ -40,9 +40,8 @@ const jsonLoader = {
|
|
|
40
40
|
name: "json-loader",
|
|
41
41
|
setup(build) {
|
|
42
42
|
build.onLoad({ filter: /\.json$/ }, async ({ path: path$1 }) => {
|
|
43
|
-
const content = await fsp.readFile(path$1, "utf-8");
|
|
44
43
|
return {
|
|
45
|
-
contents: `export default ${
|
|
44
|
+
contents: `export default ${await fsp.readFile(path$1, "utf-8")}`,
|
|
46
45
|
loader: "js"
|
|
47
46
|
};
|
|
48
47
|
});
|
|
@@ -68,13 +67,12 @@ function aliasPlugin(alias) {
|
|
|
68
67
|
const matchedEntry = alias.find(({ find: find$1 }) => aliasMatches(find$1, id));
|
|
69
68
|
if (!matchedEntry) return null;
|
|
70
69
|
const { find, replacement } = matchedEntry;
|
|
71
|
-
const result = await build.resolve(id.replace(find, replacement), {
|
|
72
|
-
kind: "import-statement",
|
|
73
|
-
resolveDir: replacement,
|
|
74
|
-
namespace: "file"
|
|
75
|
-
});
|
|
76
70
|
return {
|
|
77
|
-
path:
|
|
71
|
+
path: (await build.resolve(id.replace(find, replacement), {
|
|
72
|
+
kind: "import-statement",
|
|
73
|
+
resolveDir: replacement,
|
|
74
|
+
namespace: "file"
|
|
75
|
+
})).path,
|
|
78
76
|
external: false
|
|
79
77
|
};
|
|
80
78
|
});
|
|
@@ -97,8 +95,7 @@ async function transformWithEsbuild(entryPoint, { isESM = true, define, alias, c
|
|
|
97
95
|
const filename = path.basename(entryPoint);
|
|
98
96
|
const dirname = path.dirname(filepath);
|
|
99
97
|
try {
|
|
100
|
-
const
|
|
101
|
-
const result = await build({
|
|
98
|
+
const result = await (await esbuild())({
|
|
102
99
|
entryPoints: [entryPoint],
|
|
103
100
|
outfile: "out.js",
|
|
104
101
|
write: false,
|
|
@@ -201,12 +198,12 @@ async function transformWithRolldown(entryPoint, { isESM = true, define, alias,
|
|
|
201
198
|
file: "out.js"
|
|
202
199
|
},
|
|
203
200
|
platform: "node",
|
|
204
|
-
define: {
|
|
201
|
+
transform: { define: {
|
|
205
202
|
...define,
|
|
206
203
|
__dirname: JSON.stringify(dirname),
|
|
207
204
|
__filename: JSON.stringify(filename),
|
|
208
205
|
...isESM ? {} : { "import.meta.url": JSON.stringify(pathToFileURL(filepath)) }
|
|
209
|
-
},
|
|
206
|
+
} },
|
|
210
207
|
external(id) {
|
|
211
208
|
if (isAlias(id)) return false;
|
|
212
209
|
if (id[0] !== "." && !path.isAbsolute(id) && id !== "vite-plugin-mock-dev-server") return true;
|
|
@@ -232,11 +229,9 @@ async function transformWithRolldown(entryPoint, { isESM = true, define, alias,
|
|
|
232
229
|
|
|
233
230
|
//#endregion
|
|
234
231
|
//#region src/compiler/compile.ts
|
|
235
|
-
const hasRolldown = isPackageExists("rolldown");
|
|
236
|
-
const hasEsbuild = isPackageExists("esbuild");
|
|
237
232
|
async function transform(entryPoint, options) {
|
|
238
|
-
if (
|
|
239
|
-
if (
|
|
233
|
+
if (await isPackageExists("rolldown")) return transformWithRolldown(entryPoint, options);
|
|
234
|
+
if (await isPackageExists("esbuild")) return transformWithEsbuild(entryPoint, options);
|
|
240
235
|
throw new Error("rolldown or esbuild not found");
|
|
241
236
|
}
|
|
242
237
|
async function compile(filepath, options) {
|
|
@@ -248,14 +243,13 @@ async function compile(filepath, options) {
|
|
|
248
243
|
...options,
|
|
249
244
|
isESM
|
|
250
245
|
});
|
|
251
|
-
const data = await loadFromCode({
|
|
252
|
-
filepath,
|
|
253
|
-
code,
|
|
254
|
-
isESM,
|
|
255
|
-
cwd: options.cwd || process.cwd()
|
|
256
|
-
}) || {};
|
|
257
246
|
return {
|
|
258
|
-
data
|
|
247
|
+
data: await loadFromCode({
|
|
248
|
+
filepath,
|
|
249
|
+
code,
|
|
250
|
+
isESM,
|
|
251
|
+
cwd: options.cwd || process.cwd()
|
|
252
|
+
}) || {},
|
|
259
253
|
deps
|
|
260
254
|
};
|
|
261
255
|
}
|
|
@@ -273,13 +267,13 @@ var Compiler = class extends EventEmitter {
|
|
|
273
267
|
depsWatcher;
|
|
274
268
|
isESM = false;
|
|
275
269
|
_mockData = {};
|
|
270
|
+
options;
|
|
276
271
|
constructor(options) {
|
|
277
272
|
super();
|
|
278
273
|
this.options = options;
|
|
279
274
|
this.cwd = options.cwd || process.cwd();
|
|
280
275
|
try {
|
|
281
|
-
|
|
282
|
-
this.isESM = pkg?.type === "module";
|
|
276
|
+
this.isESM = loadPackageJSONSync(this.cwd)?.type === "module";
|
|
283
277
|
} catch {}
|
|
284
278
|
}
|
|
285
279
|
get mockData() {
|
|
@@ -340,8 +334,7 @@ var Compiler = class extends EventEmitter {
|
|
|
340
334
|
updateModuleDeps(filepath, deps) {
|
|
341
335
|
for (const dep of deps) {
|
|
342
336
|
if (!this.moduleDeps.has(dep)) this.moduleDeps.set(dep, /* @__PURE__ */ new Set());
|
|
343
|
-
|
|
344
|
-
cur.add(filepath);
|
|
337
|
+
this.moduleDeps.get(dep).add(filepath);
|
|
345
338
|
}
|
|
346
339
|
this.emit("update:deps");
|
|
347
340
|
}
|
|
@@ -378,8 +371,7 @@ var Compiler = class extends EventEmitter {
|
|
|
378
371
|
});
|
|
379
372
|
watcher.on("change", (filepath) => {
|
|
380
373
|
filepath = normalizePath(filepath);
|
|
381
|
-
|
|
382
|
-
mockFiles?.forEach((file) => this.emit("mock:update", file));
|
|
374
|
+
this.moduleDeps.get(filepath)?.forEach((file) => this.emit("mock:update", file));
|
|
383
375
|
});
|
|
384
376
|
watcher.on("unlink", (filepath) => {
|
|
385
377
|
filepath = normalizePath(filepath);
|
|
@@ -419,7 +411,7 @@ export default processMockData(mockList);`;
|
|
|
419
411
|
//#endregion
|
|
420
412
|
//#region package.json
|
|
421
413
|
var name = "vite-plugin-mock-dev-server";
|
|
422
|
-
var version = "
|
|
414
|
+
var version = "2.0.2";
|
|
423
415
|
|
|
424
416
|
//#endregion
|
|
425
417
|
//#region src/build/packageJson.ts
|
|
@@ -575,8 +567,7 @@ function createCorsMiddleware(compiler, { proxies, cors: corsOptions }) {
|
|
|
575
567
|
const { pathname } = urlParse(req.url);
|
|
576
568
|
if (!pathname || proxies.length === 0 || !proxies.some((context) => doesProxyContextMatchUrl(context, req.url))) return next();
|
|
577
569
|
const mockData = compiler.mockData;
|
|
578
|
-
|
|
579
|
-
if (!mockUrl) return next();
|
|
570
|
+
if (!Object.keys(mockData).find((pattern) => isPathMatch(pattern, pathname))) return next();
|
|
580
571
|
cors(corsOptions)(req, res, next);
|
|
581
572
|
};
|
|
582
573
|
}
|
|
@@ -821,12 +812,10 @@ function serverPlugin(options) {
|
|
|
821
812
|
config.logger.warn("");
|
|
822
813
|
},
|
|
823
814
|
configureServer({ middlewares, httpServer, ws }) {
|
|
824
|
-
|
|
825
|
-
middlewareList.forEach((middleware) => middlewares.use(middleware));
|
|
815
|
+
initMockMiddlewares(resolvedOptions, httpServer, ws).forEach((middleware) => middlewares.use(middleware));
|
|
826
816
|
},
|
|
827
817
|
configurePreviewServer({ middlewares, httpServer }) {
|
|
828
|
-
|
|
829
|
-
middlewareList.forEach((middleware) => middlewares.use(middleware));
|
|
818
|
+
initMockMiddlewares(resolvedOptions, httpServer).forEach((middleware) => middlewares.use(middleware));
|
|
830
819
|
}
|
|
831
820
|
};
|
|
832
821
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isArray, isBoolean, isEmptyObject, isFunction, isPlainObject, random, sleep, sortBy, timestamp, toArray, uniq } from "@pengzhanbo/utils";
|
|
1
|
+
import { hasOwn, isArray, isBoolean, isEmptyObject, isFunction, isPlainObject, random, sleep, sortBy, timestamp, toArray, uniq } from "@pengzhanbo/utils";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import ansis from "ansis";
|
|
4
4
|
import picomatch from "picomatch";
|
|
@@ -22,11 +22,10 @@ function createMatcher(include, exclude) {
|
|
|
22
22
|
if (item[0] === "!") ignore.push(item.slice(1));
|
|
23
23
|
else pattern.push(item);
|
|
24
24
|
});
|
|
25
|
-
const isMatch = picomatch(pattern, { ignore });
|
|
26
25
|
return {
|
|
27
26
|
pattern,
|
|
28
27
|
ignore,
|
|
29
|
-
isMatch
|
|
28
|
+
isMatch: picomatch(pattern, { ignore })
|
|
30
29
|
};
|
|
31
30
|
}
|
|
32
31
|
|
|
@@ -44,6 +43,20 @@ function isStream(stream) {
|
|
|
44
43
|
function isReadableStream(stream) {
|
|
45
44
|
return isStream(stream) && stream.readable !== false && typeof stream._read === "function" && typeof stream._readableState === "object";
|
|
46
45
|
}
|
|
46
|
+
const PACKAGE_CACHE = {};
|
|
47
|
+
async function isPackageExists(mod) {
|
|
48
|
+
if (hasOwn(PACKAGE_CACHE, mod)) return PACKAGE_CACHE[mod];
|
|
49
|
+
try {
|
|
50
|
+
if (import.meta.resolve) PACKAGE_CACHE[mod] = !!import.meta.resolve(mod);
|
|
51
|
+
else {
|
|
52
|
+
await import(mod);
|
|
53
|
+
PACKAGE_CACHE[mod] = true;
|
|
54
|
+
}
|
|
55
|
+
return PACKAGE_CACHE[mod];
|
|
56
|
+
} catch {}
|
|
57
|
+
PACKAGE_CACHE[mod] = false;
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
47
60
|
|
|
48
61
|
//#endregion
|
|
49
62
|
//#region src/utils/isObjectSubset.ts
|
|
@@ -101,15 +114,14 @@ function createLogger(prefix, defaultLevel = "info") {
|
|
|
101
114
|
prefix = `[${prefix}]`;
|
|
102
115
|
function output(type, msg, level) {
|
|
103
116
|
level = isBoolean(level) ? level ? defaultLevel : "error" : level;
|
|
104
|
-
|
|
105
|
-
if (thresh >= logLevels[type]) {
|
|
117
|
+
if (logLevels[level] >= logLevels[type]) {
|
|
106
118
|
const method = type === "info" || type === "debug" ? "log" : type;
|
|
107
119
|
const tag = type === "debug" ? ansis.magenta.bold(prefix) : type === "info" ? ansis.cyan.bold(prefix) : type === "warn" ? ansis.yellow.bold(prefix) : ansis.red.bold(prefix);
|
|
108
120
|
const format = `${ansis.dim((/* @__PURE__ */ new Date()).toLocaleTimeString())} ${tag} ${msg}`;
|
|
109
121
|
console[method](format);
|
|
110
122
|
}
|
|
111
123
|
}
|
|
112
|
-
|
|
124
|
+
return {
|
|
113
125
|
debug(msg, level = defaultLevel) {
|
|
114
126
|
output("debug", msg, level);
|
|
115
127
|
},
|
|
@@ -123,7 +135,6 @@ function createLogger(prefix, defaultLevel = "info") {
|
|
|
123
135
|
output("error", msg, level);
|
|
124
136
|
}
|
|
125
137
|
};
|
|
126
|
-
return logger;
|
|
127
138
|
}
|
|
128
139
|
|
|
129
140
|
//#endregion
|
|
@@ -146,11 +157,9 @@ function normalizePath(id) {
|
|
|
146
157
|
*/
|
|
147
158
|
function urlParse(input) {
|
|
148
159
|
const url = new URL(input, "http://example.com");
|
|
149
|
-
const pathname = decodeURIComponent(url.pathname);
|
|
150
|
-
const query = parse$1(url.search.replace(/^\?/, ""));
|
|
151
160
|
return {
|
|
152
|
-
pathname,
|
|
153
|
-
query
|
|
161
|
+
pathname: decodeURIComponent(url.pathname),
|
|
162
|
+
query: parse$1(url.search.replace(/^\?/, ""))
|
|
154
163
|
};
|
|
155
164
|
}
|
|
156
165
|
|
|
@@ -219,8 +228,7 @@ function sortByValidator(mocks) {
|
|
|
219
228
|
const { validator } = item;
|
|
220
229
|
if (!validator || isEmptyObject(validator)) return 2;
|
|
221
230
|
if (isFunction(validator)) return 0;
|
|
222
|
-
|
|
223
|
-
return 1 / count;
|
|
231
|
+
return 1 / Object.keys(validator).reduce((prev, key) => prev + keysCount(validator[key]), 0);
|
|
224
232
|
});
|
|
225
233
|
}
|
|
226
234
|
function keysCount(obj) {
|
|
@@ -255,7 +263,6 @@ async function parseRequestBody(req, formidableOptions, bodyParserOptions = {})
|
|
|
255
263
|
} catch (e) {
|
|
256
264
|
console.error(e);
|
|
257
265
|
}
|
|
258
|
-
return void 0;
|
|
259
266
|
}
|
|
260
267
|
const DEFAULT_FORMIDABLE_OPTIONS = {
|
|
261
268
|
keepExtensions: true,
|
|
@@ -326,8 +333,7 @@ function requestLog(request, filepath) {
|
|
|
326
333
|
function fineMockData(mockList, logger, { pathname, method, request }) {
|
|
327
334
|
return mockList.find((mock) => {
|
|
328
335
|
if (!pathname || !mock || !mock.url || mock.ws) return false;
|
|
329
|
-
|
|
330
|
-
if (!methods.includes(method)) return false;
|
|
336
|
+
if (!(mock.method ? isArray(mock.method) ? mock.method : [mock.method] : ["GET", "POST"]).includes(method)) return false;
|
|
331
337
|
const hasMock = isPathMatch(mock.url, pathname);
|
|
332
338
|
if (hasMock && mock.validator) {
|
|
333
339
|
const params = parseRequestParams(mock.url, pathname);
|
|
@@ -382,8 +388,7 @@ function sortFn(rule) {
|
|
|
382
388
|
const tokens = getTokens(rule);
|
|
383
389
|
let w = 0;
|
|
384
390
|
for (let i = 0; i < tokens.length; i++) {
|
|
385
|
-
|
|
386
|
-
if (token.type !== "text") w += 10 ** (i + 1);
|
|
391
|
+
if (tokens[i].type !== "text") w += 10 ** (i + 1);
|
|
387
392
|
w += 10 ** (i + 1);
|
|
388
393
|
}
|
|
389
394
|
return w;
|
|
@@ -392,8 +397,7 @@ function preSort(rules) {
|
|
|
392
397
|
let matched = [];
|
|
393
398
|
const preMatch = [];
|
|
394
399
|
for (const rule of rules) {
|
|
395
|
-
const
|
|
396
|
-
const len = tokens.filter((token) => token.type !== "text").length;
|
|
400
|
+
const len = getTokens(rule).filter((token) => token.type !== "text").length;
|
|
397
401
|
if (!preMatch[len]) preMatch[len] = [];
|
|
398
402
|
preMatch[len].push(rule);
|
|
399
403
|
}
|
|
@@ -454,12 +458,8 @@ function matchingWeight(rules, url, priority) {
|
|
|
454
458
|
function twoPartMatch(rules) {
|
|
455
459
|
const statics = [];
|
|
456
460
|
const dynamics = [];
|
|
457
|
-
for (const rule of rules)
|
|
458
|
-
|
|
459
|
-
const dym = tokens.filter((token) => token.type !== "text");
|
|
460
|
-
if (dym.length > 0) dynamics.push(rule);
|
|
461
|
-
else statics.push(rule);
|
|
462
|
-
}
|
|
461
|
+
for (const rule of rules) if (getTokens(rule).filter((token) => token.type !== "text").length > 0) dynamics.push(rule);
|
|
462
|
+
else statics.push(rule);
|
|
463
463
|
return [statics, dynamics];
|
|
464
464
|
}
|
|
465
465
|
|
|
@@ -777,8 +777,7 @@ function mockWebSocket(compiler, server, { wsProxies: proxies, cookiesOptions, l
|
|
|
777
777
|
server?.on("close", () => {
|
|
778
778
|
for (const wssMap of poolMap.values()) {
|
|
779
779
|
for (const wss of wssMap.values()) {
|
|
780
|
-
|
|
781
|
-
cleanupRunner(wssContext.cleanupList);
|
|
780
|
+
cleanupRunner(wssContextMap.get(wss).cleanupList);
|
|
782
781
|
wss.close();
|
|
783
782
|
}
|
|
784
783
|
wssMap.clear();
|
|
@@ -793,4 +792,4 @@ function cleanupRunner(cleanupList) {
|
|
|
793
792
|
}
|
|
794
793
|
|
|
795
794
|
//#endregion
|
|
796
|
-
export {
|
|
795
|
+
export { processRawData as a, debug as c, logLevels as d, isPathMatch as f, createMatcher as h, processMockData as i, normalizePath as l, doesProxyContextMatchUrl as m, createMockMiddleware as n, sortByValidator as o, isPackageExists as p, recoverRequest as r, urlParse as s, mockWebSocket as t, createLogger as u };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import EventEmitter from "node:events";
|
|
1
|
+
import { g as ServerBuildOption, i as LogLevel, m as MockWebsocketItem, p as MockServerPluginOptions, s as MockHttpItem, u as MockOptions } from "./types-BYW0Xh7Y.js";
|
|
3
2
|
import { Matcher } from "picomatch";
|
|
3
|
+
import EventEmitter from "node:events";
|
|
4
4
|
import { CorsOptions } from "cors";
|
|
5
5
|
import { Server } from "node:http";
|
|
6
6
|
import { Alias, Connect } from "vite";
|
|
@@ -42,7 +42,6 @@ type ResolvedMockServerPluginOptions = Required<Omit<MockServerPluginOptions, "b
|
|
|
42
42
|
* Mock 文件加载编译,并转换为 Mock 数据
|
|
43
43
|
*/
|
|
44
44
|
declare class Compiler extends EventEmitter {
|
|
45
|
-
options: ResolvedMockServerPluginOptions;
|
|
46
45
|
private moduleCache;
|
|
47
46
|
private moduleDeps;
|
|
48
47
|
cwd: string;
|
|
@@ -50,6 +49,7 @@ declare class Compiler extends EventEmitter {
|
|
|
50
49
|
private depsWatcher;
|
|
51
50
|
private isESM;
|
|
52
51
|
private _mockData;
|
|
52
|
+
options: ResolvedMockServerPluginOptions;
|
|
53
53
|
constructor(options: ResolvedMockServerPluginOptions);
|
|
54
54
|
get mockData(): Record<string, MockOptions>;
|
|
55
55
|
run(watch?: boolean): void;
|
|
@@ -85,4 +85,4 @@ declare function mockWebSocket(compiler: Compiler, server: Server | Http2SecureS
|
|
|
85
85
|
logger
|
|
86
86
|
}: ResolvedMockServerPluginOptions): void;
|
|
87
87
|
//#endregion
|
|
88
|
-
export {
|
|
88
|
+
export { createLogger as a, processRawData as c, Logger as i, sortByValidator as l, CreateMockMiddlewareOptions as n, logLevels as o, createMockMiddleware as r, processMockData as s, mockWebSocket as t };
|
package/dist/server.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import "./types-
|
|
2
|
-
import {
|
|
1
|
+
import "./types-BYW0Xh7Y.js";
|
|
2
|
+
import { a as createLogger, c as processRawData, i as Logger, l as sortByValidator, n as CreateMockMiddlewareOptions, o as logLevels, r as createMockMiddleware, s as processMockData, t as mockWebSocket } from "./server-nb5Kby5K.js";
|
|
3
3
|
export { CreateMockMiddlewareOptions, Logger, createLogger, createMockMiddleware, logLevels, mockWebSocket, processMockData, processRawData, sortByValidator };
|
package/dist/server.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as processRawData, d as logLevels, i as processMockData, n as createMockMiddleware, o as sortByValidator, t as mockWebSocket, u as createLogger } from "./server-4Xi0IyG-.js";
|
|
2
2
|
|
|
3
3
|
export { createLogger, createMockMiddleware, logLevels, mockWebSocket, processMockData, processRawData, sortByValidator };
|
|
@@ -578,4 +578,4 @@ type FormidableFile = formidable.File | formidable.File[];
|
|
|
578
578
|
type LogType = "info" | "warn" | "error" | "debug";
|
|
579
579
|
type LogLevel = LogType | "silent";
|
|
580
580
|
//#endregion
|
|
581
|
-
export {
|
|
581
|
+
export { WebSocketSetupContext as _, LogType as a, MockMatchPriority as c, MockRequest as d, MockResponse as f, ServerBuildOption as g, ResponseBody as h, LogLevel as i, MockMatchSpecialPriority as l, MockWebsocketItem as m, ExtraRequest as n, Method as o, MockServerPluginOptions as p, FormidableFile as r, MockHttpItem as s, BodyParserOptions as t, MockOptions as u };
|
package/dist/types.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { _ as WebSocketSetupContext, a as LogType, c as MockMatchPriority, d as MockRequest, f as MockResponse, g as ServerBuildOption, h as ResponseBody, i as LogLevel, l as MockMatchSpecialPriority, m as MockWebsocketItem, n as ExtraRequest, o as Method, p as MockServerPluginOptions, r as FormidableFile, s as MockHttpItem, t as BodyParserOptions, u as MockOptions } from "./types-BYW0Xh7Y.js";
|
|
2
2
|
export { BodyParserOptions, ExtraRequest, FormidableFile, LogLevel, LogType, Method, MockHttpItem, MockMatchPriority, MockMatchSpecialPriority, MockOptions, MockRequest, MockResponse, MockServerPluginOptions, MockWebsocketItem, ResponseBody, ServerBuildOption, WebSocketSetupContext };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-mock-dev-server",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.0.
|
|
4
|
+
"version": "2.0.2",
|
|
5
5
|
"author": "pengzhanbo <q942450674@outlook.com> (https://github.com/pengzhanbo)",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://vite-plugin-mock-dev-server.netlify.app",
|
|
@@ -61,26 +61,26 @@
|
|
|
61
61
|
},
|
|
62
62
|
"dependencies": {
|
|
63
63
|
"@pengzhanbo/utils": "^2.1.0",
|
|
64
|
-
"ansis": "^4.
|
|
64
|
+
"ansis": "^4.2.0",
|
|
65
65
|
"chokidar": "^4.0.3",
|
|
66
66
|
"co-body": "^6.2.0",
|
|
67
67
|
"cookies": "^0.9.1",
|
|
68
68
|
"cors": "^2.8.5",
|
|
69
|
-
"debug": "^4.4.
|
|
69
|
+
"debug": "^4.4.3",
|
|
70
70
|
"formidable": "3.5.4",
|
|
71
71
|
"http-status": "^2.1.0",
|
|
72
72
|
"is-core-module": "^2.16.1",
|
|
73
73
|
"json5": "^2.2.3",
|
|
74
74
|
"local-pkg": "^1.1.2",
|
|
75
75
|
"mime-types": "^3.0.1",
|
|
76
|
-
"path-to-regexp": "^8.
|
|
76
|
+
"path-to-regexp": "^8.3.0",
|
|
77
77
|
"picomatch": "^4.0.3",
|
|
78
|
-
"tinyglobby": "^0.2.
|
|
78
|
+
"tinyglobby": "^0.2.15",
|
|
79
79
|
"ws": "^8.18.3"
|
|
80
80
|
},
|
|
81
81
|
"devDependencies": {
|
|
82
|
-
"esbuild": "^0.25.
|
|
83
|
-
"rolldown": "^1.0.0-beta.
|
|
82
|
+
"esbuild": "^0.25.11",
|
|
83
|
+
"rolldown": "^1.0.0-beta.45",
|
|
84
84
|
"vite": "npm:rolldown-vite@latest"
|
|
85
85
|
},
|
|
86
86
|
"publishConfig": {
|