rspack-plugin-mock 1.2.0 → 1.3.0
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 +10 -2
- package/README.zh-CN.md +13 -5
- package/dist/{helper.d.cts → helper.d.mts} +60 -44
- package/dist/helper.mjs +4 -0
- package/dist/index.d.mts +13 -0
- package/dist/index.mjs +1 -0
- package/dist/json5-loader.cjs +1 -32
- package/dist/options-BUfaThYe.mjs +43 -0
- package/dist/rsbuild.d.mts +7 -0
- package/dist/rsbuild.mjs +1 -0
- package/dist/{mockWebsocket-DkVHpZCx.d.cts → server-4ETytB7L.d.mts} +44 -40
- package/dist/server.d.mts +3 -0
- package/dist/server.mjs +1 -0
- package/dist/{types-6lajtJPx.d.cts → types-Bt_OTa7I.d.mts} +139 -10
- package/dist/ws-BM06pHhL.mjs +1 -0
- package/package.json +40 -51
- package/dist/chunk-CUT6urMc.cjs +0 -30
- package/dist/helper.cjs +0 -140
- package/dist/helper.d.ts +0 -110
- package/dist/helper.js +0 -136
- package/dist/index.cjs +0 -86
- package/dist/index.d.cts +0 -13
- package/dist/index.d.ts +0 -13
- package/dist/index.js +0 -80
- package/dist/logger-C0V8Cvvd.cjs +0 -800
- package/dist/logger-C48_LmdS.js +0 -710
- package/dist/mockWebsocket-qLVAe-RI.d.ts +0 -85
- package/dist/resolvePluginOptions-Da5uqlBx.cjs +0 -506
- package/dist/resolvePluginOptions-DlkIkykz.js +0 -476
- package/dist/rsbuild.cjs +0 -176
- package/dist/rsbuild.d.cts +0 -7
- package/dist/rsbuild.d.ts +0 -7
- package/dist/rsbuild.js +0 -175
- package/dist/server.cjs +0 -9
- package/dist/server.d.cts +0 -27
- package/dist/server.d.ts +0 -27
- package/dist/server.js +0 -3
- package/dist/types-DPzh7nJq.d.ts +0 -572
package/README.md
CHANGED
|
@@ -235,10 +235,18 @@ export default defineMock({
|
|
|
235
235
|
|
|
236
236
|
Configure the matching context for `include` and `exclude`.
|
|
237
237
|
|
|
238
|
+
### options.dir
|
|
239
|
+
|
|
240
|
+
- **Type:** `string`
|
|
241
|
+
- **Default:** `mock` (relative to [`options.cwd`](#optionscwd))
|
|
242
|
+
- **Details:**
|
|
243
|
+
|
|
244
|
+
Configure the directory where mock files are located
|
|
245
|
+
|
|
238
246
|
### options.include
|
|
239
247
|
|
|
240
248
|
- **Type:** `string | string[]`
|
|
241
|
-
- **Default:** `['mock
|
|
249
|
+
- **Default:** `['**/*.mock.{js,ts,cjs,mjs,json,json5}']` (relative to [`options.dir`](#optionsdir))
|
|
242
250
|
- **Details:**
|
|
243
251
|
|
|
244
252
|
glob string matching mock includes files. see [picomatch](https://github.com/micromatch/picomatch#globbing-features)
|
|
@@ -246,7 +254,7 @@ export default defineMock({
|
|
|
246
254
|
### options.exclude
|
|
247
255
|
|
|
248
256
|
- **Type:** `string | string[]`
|
|
249
|
-
- **Default:** `[
|
|
257
|
+
- **Default:** `[]` (relative to [`options.dir`](#optionsdir))
|
|
250
258
|
- **Details:**
|
|
251
259
|
|
|
252
260
|
glob string matching mock excluded files. see [picomatch](https://github.com/micromatch/picomatch#globbing-features)
|
package/README.zh-CN.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
在 [Rspack](https://rspack.dev) and [Rsbuild](https://rsbuild.dev) 中注入 API mock 服务。
|
|
4
4
|
|
|
5
|
-
在 `rspack` 和 `rsbuild`
|
|
5
|
+
在 `rspack` 和 `rsbuild` 中实现与 [vite-plugin-mock-dev-server](https://github.com/pengzhanbo/vite-plugin-mock-dev-server) 完全一致的模拟开发服务。
|
|
6
6
|
|
|
7
7
|
<p align="center">
|
|
8
8
|
<a href="https://www.npmjs.com/package/rspack-plugin-mock"><img alt="npm" src="https://img.shields.io/npm/v/rspack-plugin-mock?style=flat-square&colorA=564341&colorB=EDED91"></a>
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
- ⚙️ 随意开启或关闭对某个接口的 mock配置
|
|
32
32
|
- 📀 支持多种响应体数据类型,包括 `text/json/buffer/stream`.
|
|
33
33
|
- ⚖️ rspack 中使用 `devServer.proxy` 配置, rsbuild 中使用 `server.proxy` 配置
|
|
34
|
-
- 🍕 支持在 mock文件中使用 `define`配置
|
|
35
|
-
- ⚓️ 支持在 mock文件中使用 `resolve.alias` 路径别名
|
|
34
|
+
- 🍕 支持在 mock 文件中使用 `define`配置
|
|
35
|
+
- ⚓️ 支持在 mock 文件中使用 `resolve.alias` 路径别名
|
|
36
36
|
- 📤 支持 multipart 类型,模拟文件上传
|
|
37
37
|
- 📥 支持模拟文件下载
|
|
38
38
|
- ⚜️ 支持模拟 `WebSocket` 和 `Server-Sent Events`
|
|
@@ -232,10 +232,18 @@ export default defineMock({
|
|
|
232
232
|
|
|
233
233
|
配置 `include` 和 `exclude` 的匹配上下文。
|
|
234
234
|
|
|
235
|
+
### options.dir
|
|
236
|
+
|
|
237
|
+
- **类型:** `string`
|
|
238
|
+
- **默认值:** `mock` (相对于 [`options.cwd`](#optionscwd))
|
|
239
|
+
- **详情:**
|
|
240
|
+
|
|
241
|
+
配置 mock 包的输出目录,相对于 [`options.cwd`](#optionscwd)
|
|
242
|
+
|
|
235
243
|
### options.include
|
|
236
244
|
|
|
237
245
|
- **类型:** `string | string[]`
|
|
238
|
-
- **默认值:** `[
|
|
246
|
+
- **默认值:** `[**/*.mock.{js,ts,cjs,mjs,json,json5}']` (相对于 [`options.dir`](#optionsdir))
|
|
239
247
|
- **详情:**
|
|
240
248
|
|
|
241
249
|
glob 字符串匹配 mock 包含的文件。 查看 [picomatch](https://github.com/micromatch/picomatch#globbing-features)
|
|
@@ -243,7 +251,7 @@ export default defineMock({
|
|
|
243
251
|
### options.exclude
|
|
244
252
|
|
|
245
253
|
- **类型:** `string | string[]`
|
|
246
|
-
- **默认值:** `[
|
|
254
|
+
- **默认值:** `[]` (相对于 [`options.dir`](#optionsdir))
|
|
247
255
|
- **详情:**
|
|
248
256
|
|
|
249
257
|
glob 字符串匹配 mock 排除的文件。 查看 [picomatch](https://github.com/micromatch/picomatch#globbing-features)
|
|
@@ -1,16 +1,69 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { IncomingMessage, OutgoingHttpHeaders, ServerResponse } from "node:http";
|
|
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-Bt_OTa7I.mjs";
|
|
3
2
|
import { Transform } from "node:stream";
|
|
3
|
+
import { IncomingMessage, OutgoingHttpHeaders, ServerResponse } from "node:http";
|
|
4
4
|
|
|
5
|
-
//#region src/
|
|
6
|
-
|
|
5
|
+
//#region src/helper/createSSEStream.d.ts
|
|
6
|
+
interface SSEMessage {
|
|
7
|
+
data?: string | object;
|
|
8
|
+
comment?: string;
|
|
9
|
+
event?: string;
|
|
10
|
+
id?: string;
|
|
11
|
+
retry?: number;
|
|
12
|
+
}
|
|
13
|
+
interface WriteHeaders {
|
|
14
|
+
writeHead?: (statusCode: number, headers?: OutgoingHttpHeaders) => WriteHeaders;
|
|
15
|
+
flushHeaders?: () => void;
|
|
16
|
+
}
|
|
17
|
+
type HeaderStream = NodeJS.WritableStream & WriteHeaders;
|
|
18
|
+
/**
|
|
19
|
+
* Transforms "messages" to W3C event stream content.
|
|
20
|
+
* See https://html.spec.whatwg.org/multipage/server-sent-events.html
|
|
21
|
+
* A message is an object with one or more of the following properties:
|
|
22
|
+
* - data (String or object, which gets turned into JSON)
|
|
23
|
+
* - event
|
|
24
|
+
* - id
|
|
25
|
+
* - retry
|
|
26
|
+
* - comment
|
|
27
|
+
*
|
|
28
|
+
* If constructed with a HTTP Request, it will optimise the socket for streaming.
|
|
29
|
+
* If this stream is piped to an HTTP Response, it will set appropriate headers.
|
|
30
|
+
*/
|
|
31
|
+
declare class SSEStream extends Transform {
|
|
32
|
+
constructor(req: IncomingMessage);
|
|
33
|
+
pipe<T extends HeaderStream>(destination: T, options?: {
|
|
34
|
+
end?: boolean;
|
|
35
|
+
}): T;
|
|
36
|
+
_transform(message: SSEMessage, encoding: string, callback: (error?: (Error | null), data?: any) => void): void;
|
|
37
|
+
write(message: SSEMessage, encoding?: BufferEncoding, cb?: (error: Error | null | undefined) => void): boolean;
|
|
38
|
+
write(message: SSEMessage, cb?: (error: Error | null | undefined) => void): boolean;
|
|
39
|
+
destroy(error?: Error): this;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* 创建一个 Server-sent events 写入流,用于支持模拟 EventSource
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* import { createSSEStream, defineMock } from 'vite-plugin-mock-dev-server'
|
|
47
|
+
*
|
|
48
|
+
* export default defineMock({
|
|
49
|
+
* url: '/api',
|
|
50
|
+
* response: (req, res) => {
|
|
51
|
+
* const sse = createSSEStream(req, res)
|
|
52
|
+
* sse.write({ event: 'message', data: { message: 'hello world' } })
|
|
53
|
+
* }
|
|
54
|
+
* })
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
declare function createSSEStream(req: IncomingMessage, res: ServerResponse): SSEStream;
|
|
58
|
+
//#endregion
|
|
59
|
+
//#region src/helper/defineMock.d.ts
|
|
7
60
|
/**
|
|
8
61
|
* mock config Type helper
|
|
9
62
|
*
|
|
10
63
|
* mock配置 类型帮助函数
|
|
11
64
|
* @param config see config docs:
|
|
12
|
-
* {@link https://vite-plugin-mock-dev-server.netlify.app/
|
|
13
|
-
* {@link https://vite-plugin-mock-dev-server.netlify.app/guide/mock-config zh-CN DOC}
|
|
65
|
+
* {@link https://vite-plugin-mock-dev-server.netlify.app/guide/mock-config en-US DOC} |
|
|
66
|
+
* {@link https://vite-plugin-mock-dev-server.netlify.app/zh/guide/mock-config zh-CN DOC}
|
|
14
67
|
*
|
|
15
68
|
* @example
|
|
16
69
|
* Mock Http Request
|
|
@@ -64,47 +117,10 @@ declare function defineMock(config: MockOptions): MockOptions;
|
|
|
64
117
|
*/
|
|
65
118
|
declare function createDefineMock(transformer: (mock: MockHttpItem | MockWebsocketItem) => MockHttpItem | MockWebsocketItem | void): typeof defineMock;
|
|
66
119
|
//#endregion
|
|
67
|
-
//#region src/
|
|
120
|
+
//#region src/helper/defineMockData.d.ts
|
|
68
121
|
type MockData<T = any> = readonly [() => T, (val: T | ((val: T) => T | void)) => void] & {
|
|
69
122
|
value: T;
|
|
70
123
|
};
|
|
71
124
|
declare function defineMockData<T = any>(key: string, initialData: T): MockData<T>;
|
|
72
125
|
//#endregion
|
|
73
|
-
//#region src/core/sse.d.ts
|
|
74
|
-
interface SSEMessage {
|
|
75
|
-
data?: string | object;
|
|
76
|
-
comment?: string;
|
|
77
|
-
event?: string;
|
|
78
|
-
id?: string;
|
|
79
|
-
retry?: number;
|
|
80
|
-
}
|
|
81
|
-
interface WriteHeaders {
|
|
82
|
-
writeHead?: (statusCode: number, headers?: OutgoingHttpHeaders) => WriteHeaders;
|
|
83
|
-
flushHeaders?: () => void;
|
|
84
|
-
}
|
|
85
|
-
type HeaderStream = NodeJS.WritableStream & WriteHeaders;
|
|
86
|
-
/**
|
|
87
|
-
* Transforms "messages" to W3C event stream content.
|
|
88
|
-
* See https://html.spec.whatwg.org/multipage/server-sent-events.html
|
|
89
|
-
* A message is an object with one or more of the following properties:
|
|
90
|
-
* - data (String or object, which gets turned into JSON)
|
|
91
|
-
* - event
|
|
92
|
-
* - id
|
|
93
|
-
* - retry
|
|
94
|
-
* - comment
|
|
95
|
-
*
|
|
96
|
-
* If constructed with a HTTP Request, it will optimise the socket for streaming.
|
|
97
|
-
* If this stream is piped to an HTTP Response, it will set appropriate headers.
|
|
98
|
-
*/
|
|
99
|
-
declare class SSEStream extends Transform {
|
|
100
|
-
constructor(req: IncomingMessage);
|
|
101
|
-
pipe<T extends HeaderStream>(destination: T, options?: {
|
|
102
|
-
end?: boolean;
|
|
103
|
-
}): T;
|
|
104
|
-
_transform(message: SSEMessage, encoding: string, callback: (error?: (Error | null), data?: any) => void): void;
|
|
105
|
-
write(message: SSEMessage, encoding?: BufferEncoding, cb?: (error: Error | null | undefined) => void): boolean;
|
|
106
|
-
write(message: SSEMessage, cb?: (error: Error | null | undefined) => void): boolean;
|
|
107
|
-
}
|
|
108
|
-
declare function createSSEStream(req: IncomingMessage, res: ServerResponse): SSEStream;
|
|
109
|
-
//#endregion
|
|
110
126
|
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.mjs
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import{Transform as e}from"node:stream";import{deepClone as t,deepEqual as n,isArray as r,isFunction as i}from"@pengzhanbo/utils";var a=class extends e{constructor(e){super({objectMode:!0}),e.socket.setKeepAlive(!0),e.socket.setNoDelay(!0),e.socket.setTimeout(0)}pipe(e,t){return e.writeHead&&(e.writeHead(200,{"Content-Type":`text/event-stream; charset=utf-8`,"Transfer-Encoding":`identity`,"Cache-Control":`no-cache`,Connection:`keep-alive`}),e.flushHeaders?.()),e.write(`:ok
|
|
2
|
+
|
|
3
|
+
`),super.pipe(e,t)}_transform(e,t,n){e.comment&&this.push(`: ${e.comment}\n`),e.event&&this.push(`event: ${e.event}\n`),e.id&&this.push(`id: ${e.id}\n`),e.retry&&this.push(`retry: ${e.retry}\n`),e.data&&this.push(o(e.data)),this.push(`
|
|
4
|
+
`),n()}write(e,...t){return super.write(e,...t)}destroy(e){return e&&this.write({event:`error`,data:e.message}),this.end(),this}};function o(e){return typeof e==`object`?o(JSON.stringify(e)):e.split(/\r\n|\r|\n/).map(e=>`data: ${e}\n`).join(``)}function s(e,t){let n=new a(e);return n.pipe(t),n}function c(e){return e}function l(e){return t=>(t=r(t)?t.map(t=>e(t)||t):e(t)||t,t)}const u=new Map,d=new WeakMap;var f=class{value;#e;#t;constructor(e){this.value=e,this.#e=t(e),this.#t=Date.now()}hotUpdate(e){Date.now()-this.#t<70||n(e,this.#e)||(this.value=e,this.#e=t(e),this.#t=Date.now())}};function p(e,t){let n=u.get(e);if(!n){let r=new f(t),i=u.get(e);i?n=i:(u.set(e,r),n=r)}if(n.hotUpdate(t),d.has(n))return d.get(n);let r=[()=>n.value,e=>{i(e)&&(e=e(n.value)??n.value),n.value=e}];return Object.defineProperty(r,`value`,{get(){return n.value},set(e){n.value=e}}),d.set(n,r),r}export{l as createDefineMock,s as createSSEStream,c as defineMock,p as defineMockData};
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
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-Bt_OTa7I.mjs";
|
|
2
|
+
import { HeaderStream, MockData, SSEMessage, createDefineMock, createSSEStream, defineMock, defineMockData } from "./helper.mjs";
|
|
3
|
+
import { a as processMockData, c as Logger, i as baseMiddleware, l as createLogger, n as mockWebSocket, o as processRawData, r as BaseMiddlewareOptions, s as sortByValidator, t as MockSocketOptions, u as logLevels } from "./server-4ETytB7L.mjs";
|
|
4
|
+
import { Compiler, RspackPluginInstance } from "@rspack/core";
|
|
5
|
+
|
|
6
|
+
//#region src/rspack.d.ts
|
|
7
|
+
declare class MockServerPlugin implements RspackPluginInstance {
|
|
8
|
+
options: MockServerPluginOptions;
|
|
9
|
+
constructor(options?: MockServerPluginOptions);
|
|
10
|
+
apply(compiler: Compiler): void;
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
13
|
+
export { BaseMiddlewareOptions, BodyParserOptions, ExtraRequest, type FormidableFile, HeaderStream, LogLevel, LogType, Logger, Method, MockData, type MockHttpItem, MockMatchPriority, MockMatchSpecialPriority, type MockOptions, type MockRequest, MockResponse, MockServerPlugin, type MockServerPluginOptions, MockSocketOptions, type MockWebsocketItem, ResponseBody, SSEMessage, ServerBuildOption, WebSocketSetupContext, baseMiddleware, createDefineMock, createLogger, createSSEStream, defineMock, defineMockData, logLevels, mockWebSocket, processMockData, processRawData, sortByValidator };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createDefineMock as e,createSSEStream as t,defineMock as n,defineMockData as r}from"./helper.mjs";import{a as i,d as a,f as o,i as s,n as c,o as l,r as u,s as d,t as f}from"./ws-BM06pHhL.mjs";import{i as p,n as m,r as h,t as g}from"./options-BUfaThYe.mjs";import"./server.mjs";import{isString as _,toArray as v}from"@pengzhanbo/utils";import y from"node:path";import b from"node:process";import x from"@rspack/core";const S=`rspack-plugin-mock`;var C=class{constructor(e={}){this.options=e}apply(e){let t=e.options,n=w(e,this.options);if(b.env.NODE_ENV!==`production`){let r=p(n),i=m(r,n),a=t.devServer?.setupMiddlewares,o=d(e=>{f(r,e,n)});t.devServer={...t.devServer,setupMiddlewares:(e,t)=>(e=a?.(e,t)||e,e=i(e,()=>{t.webSocketServer?.clients&&t.sendMessage(t.webSocketServer.clients,`static-changed`)})||e,o(()=>t.server),e)};let s=v(n.wsPrefix);if(t.devServer?.proxy?.length){let e=t.devServer.proxy;t.devServer.proxy=e.filter(e=>typeof e!=`function`&&e.ws===!0&&s.length?!v(e.context).filter(_).some(e=>s.includes(e)):!0).map(e=>{if(typeof e!=`function`&&!e.ws){let t=e.onProxyReq;e.onProxyReq=(e,n,...r)=>{t?.(e,n,...r),u(e,n)}}return e})}e.hooks.watchRun.tap(S,()=>r.run()),e.hooks.watchClose.tap(S,()=>r.close())}else n.build!==!1&&e.hooks.afterEmit.tap(S,()=>h(n,t.output.path||y.resolve(b.cwd(),`dist`)))}};function w(e,t={}){let n=e.options,r=n.resolve?.alias||{},i=n.context,a=n.plugins?.find(e=>e instanceof x.DefinePlugin),o=(n.devServer?.proxy||[]).flatMap(e=>typeof e!=`function`&&e.context&&!e.ws?e.context:[]);return g(t,{alias:r,context:i,plugins:v(a),proxies:o})}export{C as MockServerPlugin,c as baseMiddleware,e as createDefineMock,a as createLogger,t as createSSEStream,n as defineMock,r as defineMockData,o as logLevels,f as mockWebSocket,s as processMockData,i as processRawData,l as sortByValidator};
|
package/dist/json5-loader.cjs
CHANGED
|
@@ -1,32 +1 @@
|
|
|
1
|
-
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
-
key = keys[i];
|
|
11
|
-
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
-
get: ((k) => from[k]).bind(null, key),
|
|
13
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
-
value: mod,
|
|
20
|
-
enumerable: true
|
|
21
|
-
}) : target, mod));
|
|
22
|
-
|
|
23
|
-
//#endregion
|
|
24
|
-
const json5 = __toESM(require("json5"));
|
|
25
|
-
|
|
26
|
-
//#region src/json5-loader.cts
|
|
27
|
-
module.exports = function(content) {
|
|
28
|
-
if (!content) return "export default {}";
|
|
29
|
-
return `export default ${JSON.stringify(json5.default.parse(content))}`;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
//#endregion
|
|
1
|
+
var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require(`json5`);c=s(c),module.exports=function(e){return e?`export default ${JSON.stringify(c.default.parse(e))}`:`export default {}`};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import{_ as e,a as t,c as n,d as r,g as i,h as a,i as o,l as s,m as c,n as l,p as u,u as d}from"./ws-BM06pHhL.mjs";import{createRequire as f}from"node:module";import{isBoolean as p,toArray as m,uniq as h}from"@pengzhanbo/utils";import g from"node:path";import _ from"node:process";import*as v from"@rspack/core";import y,{promises as b}from"node:fs";import x from"node:fs/promises";import S from"ansis";import{glob as C}from"tinyglobby";import w from"is-core-module";import{loadPackageJSONSync as T}from"local-pkg";import{pathToFileURL as E}from"node:url";import D from"node:events";import O from"chokidar";import k from"cors";const A=f(import.meta.url);function j(e,t){let n=P(e),r=n.watch===!0;async function i(n,i){let a=`[rspack:mock]`,o=(...e)=>{i?i.compilation.getLogger(a).error(...e):console.error(S.red(a),...e)};if(n){o(n.stack||n),`details`in n&&o(n.details);return}i?.hasErrors()&&o(i.toJson().errors);let s=d.readFileSync(`/output.js`,`utf-8`),c=[];if(!r){let t=i?.toJson().modules||[],n=Object.keys(e.alias||{}).map(e=>e.replace(/\$$/g,``));for(let{name:e}of t)if(e?.startsWith(`external`)){let t=N(e);!w(t)&&!n.includes(t)&&c.push(N(e))}}await t({code:s,externals:c})}let a=v.rspack(n);return a.outputFileSystem=d,r?a.watch({},i):a.run(async(...e)=>{await i(...e),a.close(()=>{})}),a}function M(e){return new Promise(t=>{j({...e,watch:!1},e=>{t(e)})})}function N(e){let t=e.replace(`external `,``).slice(1,-1),[n,r]=t.split(`/`);return t[0]===`@`?`${n}/${r}`:n}function P({cwd:e,isEsm:t=!0,entryFile:n,plugins:r,alias:i,watch:a=!1}){let o=[`node >= 18.0.0`];i&&`@swc/helpers`in i&&delete i[`@swc/helpers`];let s=c(e),l=RegExp(`^(${s.join(`|`)})($|/)`,`i`);return{mode:`production`,context:e,entry:n,watch:a,target:`node${(_.versions.node||``).replace(/\.\d+$/,``)}`,externalsType:t?`module`:`commonjs2`,externals:[l],resolve:{alias:i,extensions:[`.js`,`.ts`,`.cjs`,`.mjs`,`.json5`,`.json`]},plugins:r,output:{library:{type:t?`module`:`commonjs2`},filename:`output.js`,module:t,path:`/`},experiments:{outputModule:t},optimization:{minimize:!a},node:{__dirname:!1,__filename:!1},module:{rules:[{test:/\.json5?$/,loader:A.resolve(`#json5-loader`),type:`javascript/auto`},{test:/\.[cm]?js$/,use:[{loader:`builtin:swc-loader`,options:{jsc:{parser:{syntax:`ecmascript`}},env:{targets:o}}}]},{test:/\.[cm]?ts$/,use:[{loader:`builtin:swc-loader`,options:{jsc:{parser:{syntax:`typescript`}},env:{targets:o}}}]}]}}}async function F({filepath:e,code:t,isESM:n,cwd:r}){e=g.resolve(r,e);let i=n?`.mjs`:`.cjs`,a=`${e}.timestamp-${Date.now()}${i}`,o=E(a).toString();await b.writeFile(a,t,`utf8`);try{let e=await import(o);return e.default||e}finally{try{y.unlinkSync(a)}catch{}}}function I(e){return new L(e)}var L=class extends D{cwd;mockWatcher;entryFile;deps=[];isESM=!1;_mockData={};watchInfo;compiler;constructor(e){super(),this.options=e,this.cwd=e.cwd||_.cwd();try{this.isESM=T(this.cwd)?.type===`module`}catch{}this.entryFile=g.resolve(_.cwd(),`node_modules/.cache/mock-server/mock-server.ts`)}get mockData(){return this._mockData}async run(){let{include:n,exclude:r}=this.options,{pattern:i,ignore:a,isMatch:c}=e(n,r);this.deps=(await C(i,{ignore:a,cwd:g.join(this.cwd,this.options.dir)})).map(e=>s(e)),this.updateMockEntry(),this.watchMockFiles(c);let{plugins:l,alias:u}=this.options;this.compiler=j({isEsm:this.isESM,cwd:this.cwd,plugins:l,entryFile:this.entryFile,alias:u,watch:!0},async({code:e})=>{try{this._mockData=o(t(await F({filepath:`mock.bundle.js`,code:e,isESM:this.isESM,cwd:this.cwd}))),this.emit(`update`,this.watchInfo||{})}catch(e){this.options.logger.error(e.stack||e.message)}})}close(){this.mockWatcher.close(),this.compiler?.close(()=>{}),this.emit(`close`)}updateAlias(e){this.options.alias={...this.options.alias,...e}}async updateMockEntry(){await H(this.entryFile,this.deps,this.cwd,this.options.dir)}watchMockFiles(e){let t=this.mockWatcher=O.watch(this.options.dir,{ignoreInitial:!0,cwd:this.cwd,ignored:(t,n)=>t.includes(`node_modules`)?!0:!!n?.isFile()&&!e(t)});t.on(`add`,t=>{t=s(t),e(t)&&(this.watchInfo={filepath:t,type:`add`},this.deps=h([...this.deps,t]),this.updateMockEntry())}),t.on(`change`,t=>{t=s(t),e(t)&&(this.watchInfo={filepath:t,type:`change`})}),t.on(`unlink`,async t=>{t=s(t),e(t)&&(this.watchInfo={filepath:t,type:`unlink`},this.deps=this.deps.filter(e=>e!==t),this.updateMockEntry())})}},R=`rspack-plugin-mock`,z=`1.3.0`;function B(e,t){let n=a(e.context),r=[R,`connect`,`cors`],i={name:`mock-server`,type:`module`,scripts:{start:`node index.js`},dependencies:{connect:`^3.7.0`,[R]:`^${z}`,cors:`^2.8.5`}};return t.filter(e=>!r.includes(e)).forEach(e=>{i.dependencies[e]=n[e]||`latest`}),JSON.stringify(i,null,2)}function V({proxies:e,wsPrefix:t,cookiesOptions:n,bodyParserOptions:r,priority:i,build:a}){let{serverPort:o,log:s}=a;return`import { createServer } from 'node:http';
|
|
2
|
+
import connect from 'connect';
|
|
3
|
+
import corsMiddleware from 'cors';
|
|
4
|
+
import {
|
|
5
|
+
baseMiddleware,
|
|
6
|
+
createLogger,
|
|
7
|
+
mockWebSocket,
|
|
8
|
+
processMockData,
|
|
9
|
+
processRawData
|
|
10
|
+
} from 'rspack-plugin-mock/server';
|
|
11
|
+
import rawData from './mock-data.js';
|
|
12
|
+
|
|
13
|
+
const app = connect();
|
|
14
|
+
const server = createServer(app);
|
|
15
|
+
const logger = createLogger('mock-server', '${s}');
|
|
16
|
+
const proxies = ${JSON.stringify(e)};
|
|
17
|
+
const wsProxies = ${JSON.stringify(m(t))};
|
|
18
|
+
const cookiesOptions = ${JSON.stringify(n)};
|
|
19
|
+
const bodyParserOptions = ${JSON.stringify(r)};
|
|
20
|
+
const priority = ${JSON.stringify(i)};
|
|
21
|
+
const mockConfig = {
|
|
22
|
+
mockData: processMockData(processRawData(rawData)),
|
|
23
|
+
on: () => {},
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
mockWebSocket(mockConfig, server, { wsProxies, cookiesOptions, logger });
|
|
27
|
+
|
|
28
|
+
app.use(corsMiddleware());
|
|
29
|
+
app.use(baseMiddleware(mockConfig, {
|
|
30
|
+
formidableOptions: { multiples: true },
|
|
31
|
+
proxies,
|
|
32
|
+
priority,
|
|
33
|
+
cookiesOptions,
|
|
34
|
+
bodyParserOptions,
|
|
35
|
+
logger,
|
|
36
|
+
}));
|
|
37
|
+
|
|
38
|
+
server.listen(${o});
|
|
39
|
+
|
|
40
|
+
console.log('listen: http://localhost:${o}');
|
|
41
|
+
`}async function H(e,t,n,r){let i=[],a=[];for(let[e,o]of t.entries()){let t=s(g.join(r,o)),c=s(g.join(n,t));i.push(`import * as m${e} from '${c}'`),a.push(`[m${e}, '${t}']`)}let o=`${i.join(`
|
|
42
|
+
`)}\n\nexport default [\n ${a.join(`,
|
|
43
|
+
`)}\n]`,c=g.dirname(e);y.existsSync(c)||await x.mkdir(c,{recursive:!0}),await x.writeFile(e,o,`utf8`)}async function U(t,n){let r=g.resolve(_.cwd(),`node_modules/.cache/mock-server/mock-server.ts`),{pattern:i,ignore:a}=e(t.include,t.exclude);await H(r,await C(i,{ignore:a,cwd:g.join(t.cwd,t.dir)}),t.cwd,t.dir);let{code:o,externals:s}=await M({entryFile:r,cwd:t.cwd,plugins:t.plugins,alias:t.alias});await x.unlink(r);let c=[{filename:`mock-data.js`,source:o},{filename:`index.js`,source:V(t)},{filename:`package.json`,source:B(t,s)}],l=g.resolve(n,t.build.dist);t.logger.info(`${S.green(`✓`)} generate mock server in ${S.cyan(g.relative(_.cwd(),l))}`),y.existsSync(l)||await x.mkdir(l,{recursive:!0});for(let{filename:e,source:n}of c){await x.writeFile(g.join(l,e),n,`utf8`);let r=(n.length/1024).toFixed(2),i=e.length<24?` `.repeat(24-e.length):``;t.logger.info(` ${S.green(e)}${i}${S.bold.dim(`${r} kB`)}`)}}function W(e,t){let r={},a=t.cors!==!1;a&&(r={...r,...typeof t.cors==`boolean`?{}:t.cors});let o=t.proxies;return a?function(t,a,s){let{pathname:c}=n(t.url);if(!c||o.length===0||!o.some(e=>i(e,t.url,t)))return s();let l=e.mockData;if(!Object.keys(l).find(e=>u(e,c)))return s();k(r)(t,a,s)}:void 0}function G(e,t){return function(n,r){n.unshift(l(e,t));let i=W(e,t);return i&&n.unshift(i),t.reload&&e.on(`update`,()=>r?.()),n}}function K({prefix:e=[],wsPrefix:t=[],cwd:n,dir:i=`mock`,include:a=[`**/*.mock.{js,ts,cjs,mjs,json,json5}`],exclude:o=[],reload:s=!1,log:c=`info`,cors:l=!0,formidableOptions:u={},build:d=!1,cookiesOptions:f={},bodyParserOptions:h={},priority:g={}},{alias:v,context:y,plugins:b,proxies:x}){let C=r(`rspack:mock`,p(c)?c?`info`:`error`:c),w=[...m(e),...x],T=m(t);return!w.length&&!T.length&&C.warn(`No proxy was configured, mock server will not work. See ${S.cyan(`https://vite-plugin-mock-dev-server.netlify.app/guide/usage`)}`),{prefix:e,wsPrefix:t,cwd:n||y||_.cwd(),dir:i,include:a,exclude:o,reload:s,cors:l,cookiesOptions:f,log:c,formidableOptions:{multiples:!0,...u},bodyParserOptions:h,priority:g,build:d?{serverPort:8080,dist:`mockServer`,log:`error`,...typeof d==`object`?d:{}}:!1,alias:v,plugins:b,proxies:w,wsProxies:T,logger:C}}export{I as i,G as n,U as r,K as t};
|
|
@@ -0,0 +1,7 @@
|
|
|
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-Bt_OTa7I.mjs";
|
|
2
|
+
import { RsbuildPlugin } from "@rsbuild/core";
|
|
3
|
+
|
|
4
|
+
//#region src/rsbuild.d.ts
|
|
5
|
+
declare function pluginMockServer(options?: MockServerPluginOptions): RsbuildPlugin;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { BodyParserOptions, ExtraRequest, FormidableFile, LogLevel, LogType, Method, MockHttpItem, MockMatchPriority, MockMatchSpecialPriority, MockOptions, MockRequest, MockResponse, MockServerPluginOptions, MockWebsocketItem, ResponseBody, ServerBuildOption, WebSocketSetupContext, pluginMockServer };
|
package/dist/rsbuild.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as e,t}from"./ws-BM06pHhL.mjs";import{i as n,n as r,r as i,t as a}from"./options-BUfaThYe.mjs";import{isArray as o,toArray as s}from"@pengzhanbo/utils";import c from"node:path";import l from"node:process";import u from"@rspack/core";import d from"ansis";import{createServer as f}from"node:http";import{getPortPromise as p}from"portfinder";function m(e={}){return{name:`plugin-mock-server`,setup(o){let d=o.getRsbuildConfig(),m=a(e,{proxies:v(d),alias:{},context:o.context.rootPath,plugins:[new u.DefinePlugin(d.source?.define||{})]});if(l.env.NODE_ENV===`production`){m.build&&o.onAfterBuild(async()=>{let e=o.getNormalizedConfig();await i(m,c.resolve(l.cwd(),e.output.distPath.root||`dist`))});return}let h=n(m);o.modifyRsbuildConfig(e=>{g(e);let t=r(h,m);e.dev??={},e.dev.setupMiddlewares=s(e.dev.setupMiddlewares),e.dev.setupMiddlewares.push((e,n)=>{t(e,()=>n.sockWrite(`static-changed`))})});let y=3079,b=s(m.wsPrefix).length>0;b&&o.modifyRsbuildConfig(async t=>{y=await p({port:(t.server?.port||y)+1}),_(t,e.wsPrefix||[],y)});let x;function S(){h.run(),b&&(x=f(),t(h,x,m),x.listen(y))}function C(){h.close(),x?.close()}o.onAfterCreateCompiler(({compiler:e})=>{`compilers`in e?e.compilers.forEach(e=>{h.updateAlias(e.options.resolve?.alias||{})}):h.updateAlias(e.options.resolve?.alias||{})}),o.onAfterStartDevServer(S),o.onAfterStartProdServer(S),o.onExit(C)}}}function h(e,t,n){console.error(d.red(e?.stack||e.message)),n.statusCode=500,n.end()}function g(t){if(t.server?.proxy){if(o(t.server.proxy))t.server.proxy=t.server.proxy.map(t=>{if(typeof t!=`function`&&!t.ws){let n=t.onProxyReq,r=t.onError;return{...t,onError:r||h,onProxyReq:(t,r,...i)=>{n?.(t,r,...i),e(t,r)}}}return t});else if(`target`in t.server.proxy){let n=t.server.proxy.onProxyReq;t.server.proxy.onProxyReq=(t,r,...i)=>{n?.(t,r,...i),e(t,r)},t.server.proxy.onError??=h}else if(t.server.proxy){let n=t.server.proxy;Object.keys(n).forEach(t=>{let r=n[t],i=typeof r==`string`?{target:r}:r;if(i.ws)return;let{onProxyReq:a,onError:o,...s}=i;n[t]={...s,onProxyReq:(t,n,...r)=>{a?.(t,n,...r),e(t,n)},onError:o||h}})}}}function _(e,t,n){e.server??={};let r=e.server.proxy??={},i=`ws://localhost:${n}`,a=s(t),c=e=>typeof e==`string`&&a.includes(e),l=new Set;function u(e){o(e.context)?e.context=e.context.filter(c):c(e.context)&&(l.add(e.context),e.target=i)}if(o(r)){for(let e of r)typeof e!=`function`&&e.context&&e.ws&&u(e);a.filter(e=>!l.has(e)).forEach(e=>r.push({context:e,target:i}))}else if(`target`in r){if(r.ws){u(r);let t=e.server.proxy=[r];a.filter(e=>!l.has(e)).forEach(e=>t.push({context:e,target:i}))}}else Object.entries(r).forEach(([,e])=>{typeof e!=`string`&&e.ws&&u(e)}),a.filter(e=>!l.has(e)).forEach(e=>{r[e]={target:i,ws:!0}})}function v(e){e.server??={};let t=e.server.proxy??={},n=[];if(o(t))for(let e of t)typeof e!=`function`&&e.context&&!e.ws&&n.push(...s(e.context));else `target`in t?t.ws||n.push(...s(t.context)):Object.entries(t).forEach(([e,t])=>{(typeof t==`string`||!t.ws)&&n.push(e)});return n}export{m as pluginMockServer};
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import { LogLevel,
|
|
2
|
-
import { Server } from "node:http";
|
|
1
|
+
import { g as ServerBuildOption, i as LogLevel, m as MockWebsocketItem, p as MockServerPluginOptions, s as MockHttpItem, u as MockOptions } from "./types-Bt_OTa7I.mjs";
|
|
3
2
|
import { Compiler, RspackOptionsNormalized, RspackPluginInstance } from "@rspack/core";
|
|
4
|
-
import {
|
|
3
|
+
import { Matcher } from "picomatch";
|
|
4
|
+
import Debug from "debug";
|
|
5
|
+
import "memfs";
|
|
5
6
|
import EventEmitter from "node:events";
|
|
7
|
+
import { FSWatcher } from "chokidar";
|
|
8
|
+
import { Server } from "node:http";
|
|
6
9
|
import { Http2SecureServer } from "node:http2";
|
|
7
10
|
|
|
8
|
-
//#region src/
|
|
11
|
+
//#region src/utils/logger.d.ts
|
|
9
12
|
interface Logger {
|
|
10
13
|
debug: (msg: string, level?: boolean | LogLevel) => void;
|
|
11
14
|
info: (msg: string, level?: boolean | LogLevel) => void;
|
|
@@ -15,62 +18,63 @@ interface Logger {
|
|
|
15
18
|
declare const logLevels: Record<LogLevel, number>;
|
|
16
19
|
declare function createLogger(prefix: string, defaultLevel?: LogLevel): Logger;
|
|
17
20
|
//#endregion
|
|
18
|
-
//#region src/
|
|
19
|
-
interface
|
|
20
|
-
alias
|
|
21
|
+
//#region src/options.d.ts
|
|
22
|
+
interface ResolvedCompilerOptions {
|
|
23
|
+
alias: Record<string, false | string | (string | false)[]>;
|
|
24
|
+
proxies: (string | ((pathname: string, req: any) => boolean))[];
|
|
25
|
+
wsProxies: (string | ((pathname: string, req: any) => boolean))[];
|
|
21
26
|
plugins: RspackPluginInstance[];
|
|
22
|
-
|
|
23
|
-
include: string | string[];
|
|
24
|
-
exclude: string | string[];
|
|
25
|
-
logger: Logger;
|
|
27
|
+
context?: string;
|
|
26
28
|
}
|
|
27
|
-
|
|
29
|
+
type ResolvePluginOptions = Required<Omit<MockServerPluginOptions, "build">> & ResolvedCompilerOptions & {
|
|
30
|
+
logger: Logger;
|
|
31
|
+
build: false | ServerBuildOption;
|
|
32
|
+
};
|
|
33
|
+
//#endregion
|
|
34
|
+
//#region src/compiler/processData.d.ts
|
|
35
|
+
declare function processRawData(rawData: (readonly [any, string])[]): (MockHttpItem | MockWebsocketItem | MockOptions)[];
|
|
36
|
+
declare function processMockData(mockList: (MockHttpItem | MockWebsocketItem | MockOptions)[]): Record<string, MockOptions>;
|
|
37
|
+
declare function sortByValidator(mocks: MockOptions): (MockHttpItem | MockWebsocketItem)[];
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region src/compiler/mockCompiler.d.ts
|
|
28
40
|
declare class MockCompiler extends EventEmitter {
|
|
29
|
-
options:
|
|
41
|
+
options: ResolvePluginOptions;
|
|
30
42
|
cwd: string;
|
|
31
43
|
mockWatcher: FSWatcher;
|
|
32
|
-
moduleType: "cjs" | "esm";
|
|
33
44
|
entryFile: string;
|
|
45
|
+
deps: string[];
|
|
46
|
+
isESM: boolean;
|
|
34
47
|
private _mockData;
|
|
35
|
-
private fileFilter;
|
|
36
48
|
private watchInfo?;
|
|
37
49
|
compiler?: Compiler | null;
|
|
38
|
-
constructor(options:
|
|
50
|
+
constructor(options: ResolvePluginOptions);
|
|
39
51
|
get mockData(): Record<string, MockOptions>;
|
|
40
52
|
run(): Promise<void>;
|
|
41
53
|
close(): void;
|
|
42
54
|
updateAlias(alias: Record<string, false | string | (string | false)[]>): void;
|
|
43
55
|
updateMockEntry(): Promise<void>;
|
|
44
|
-
|
|
45
|
-
watchMockFiles(): void;
|
|
56
|
+
watchMockFiles(isMatch: Matcher): void;
|
|
46
57
|
}
|
|
47
58
|
//#endregion
|
|
48
|
-
//#region src/core/
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
proxies: (string | ((pathname: string, req: any) => boolean))[];
|
|
52
|
-
wsProxies: (string | ((pathname: string, req: any) => boolean))[];
|
|
53
|
-
plugins: RspackPluginInstance[];
|
|
54
|
-
context?: string;
|
|
55
|
-
}
|
|
56
|
-
type ResolvePluginOptions = Required<Omit<MockServerPluginOptions, "build">> & ResolvedCompilerOptions & {
|
|
57
|
-
logger: Logger;
|
|
58
|
-
build: false | ServerBuildOption;
|
|
59
|
-
};
|
|
59
|
+
//#region src/core/types.d.ts
|
|
60
|
+
type SetupMiddlewaresFn = NonNullable<NonNullable<RspackOptionsNormalized["devServer"]>["setupMiddlewares"]>;
|
|
61
|
+
type Middleware = SetupMiddlewaresFn extends ((middlewares: (infer T)[], devServer: any) => void) ? T : never;
|
|
60
62
|
//#endregion
|
|
61
63
|
//#region src/core/mockMiddleware.d.ts
|
|
62
|
-
interface
|
|
63
|
-
alias: Record<string, false | string | (string | false)[]>;
|
|
64
|
+
interface BaseMiddlewareOptions extends Pick<MockServerPluginOptions, "formidableOptions" | "cookiesOptions" | "bodyParserOptions" | "priority"> {
|
|
64
65
|
proxies: (string | ((pathname: string, req: any) => boolean))[];
|
|
65
|
-
|
|
66
|
-
plugins: RspackPluginInstance[];
|
|
66
|
+
logger: Logger;
|
|
67
67
|
}
|
|
68
|
-
declare function
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
68
|
+
declare function baseMiddleware(compiler: MockCompiler, {
|
|
69
|
+
formidableOptions,
|
|
70
|
+
bodyParserOptions,
|
|
71
|
+
proxies,
|
|
72
|
+
cookiesOptions,
|
|
73
|
+
logger,
|
|
74
|
+
priority
|
|
75
|
+
}: BaseMiddlewareOptions): Middleware;
|
|
72
76
|
//#endregion
|
|
73
|
-
//#region src/core/
|
|
77
|
+
//#region src/core/ws.d.ts
|
|
74
78
|
interface MockSocketOptions {
|
|
75
79
|
wsProxies: (string | ((pathname: string, req: any) => boolean))[];
|
|
76
80
|
cookiesOptions: MockServerPluginOptions["cookiesOptions"];
|
|
@@ -82,4 +86,4 @@ declare function mockWebSocket(compiler: MockCompiler, httpServer: Server | Http
|
|
|
82
86
|
logger
|
|
83
87
|
}: MockSocketOptions): void;
|
|
84
88
|
//#endregion
|
|
85
|
-
export {
|
|
89
|
+
export { processMockData as a, Logger as c, baseMiddleware as i, createLogger as l, mockWebSocket as n, processRawData as o, BaseMiddlewareOptions as r, sortByValidator as s, MockSocketOptions as t, logLevels as u };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import "./types-Bt_OTa7I.mjs";
|
|
2
|
+
import { a as processMockData, c as Logger, i as baseMiddleware, l as createLogger, n as mockWebSocket, o as processRawData, r as BaseMiddlewareOptions, s as sortByValidator, t as MockSocketOptions, u as logLevels } from "./server-4ETytB7L.mjs";
|
|
3
|
+
export { BaseMiddlewareOptions, Logger, MockSocketOptions, baseMiddleware, createLogger, logLevels, mockWebSocket, processMockData, processRawData, sortByValidator };
|
package/dist/server.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as e,d as t,f as n,i as r,n as i,o as a,t as o}from"./ws-BM06pHhL.mjs";export{i as baseMiddleware,t as createLogger,n as logLevels,o as mockWebSocket,r as processMockData,e as processRawData,a as sortByValidator};
|