rspack-plugin-mock 0.3.0 → 0.3.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/README.md +7 -7
- package/dist/chunk-4HRWYJ3E.cjs +546 -0
- package/dist/{chunk-YSJVV4SH.js → chunk-EY46RSAC.js} +84 -604
- package/dist/{chunk-I54ZNZWL.cjs → chunk-ZEC4FWWY.cjs} +83 -603
- package/dist/chunk-ZYUUWKWW.js +546 -0
- package/dist/helper.cjs +16 -5
- package/dist/helper.d.cts +2 -2
- package/dist/helper.d.ts +2 -2
- package/dist/helper.js +15 -4
- package/dist/index.cjs +103 -34
- package/dist/index.d.cts +14 -69
- package/dist/index.d.ts +14 -69
- package/dist/index.js +93 -24
- package/dist/mockWebsocket-CPuTAvL0.d.ts +76 -0
- package/dist/mockWebsocket-Dc9CZBfv.d.cts +76 -0
- package/dist/rsbuild.cjs +11 -9
- package/dist/rsbuild.d.cts +1 -1
- package/dist/rsbuild.d.ts +1 -1
- package/dist/rsbuild.js +4 -2
- package/dist/server.cjs +18 -0
- package/dist/server.d.cts +31 -0
- package/dist/server.d.ts +31 -0
- package/dist/server.js +18 -0
- package/dist/{types-C770q3L0.d.cts → types-BgpcN3jm.d.cts} +1 -1
- package/dist/{types-C770q3L0.d.ts → types-BgpcN3jm.d.ts} +1 -1
- package/package.json +11 -6
- package/dist/chunk-HTOWPFQ7.js +0 -20
- package/dist/chunk-KE2LVHUP.cjs +0 -20
- package/dist/chunk-OYBMX3GQ.cjs +0 -97
- package/dist/chunk-P5FOCSCE.js +0 -97
- package/dist/rspack-BB-Jtq4f.d.cts +0 -32
- package/dist/rspack-h3uerEgg.d.ts +0 -32
- package/dist/rspack.cjs +0 -9
- package/dist/rspack.d.cts +0 -11
- package/dist/rspack.d.ts +0 -11
- package/dist/rspack.js +0 -9
package/dist/rsbuild.cjs
CHANGED
|
@@ -3,9 +3,11 @@
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
|
|
6
|
+
var _chunk4HRWYJ3Ecjs = require('./chunk-4HRWYJ3E.cjs');
|
|
6
7
|
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
|
|
10
|
+
var _chunkZEC4FWWYcjs = require('./chunk-ZEC4FWWY.cjs');
|
|
9
11
|
|
|
10
12
|
// src/rsbuild.ts
|
|
11
13
|
var _process = require('process'); var _process2 = _interopRequireDefault(_process);
|
|
@@ -20,7 +22,7 @@ function pluginMockServer(options = {}) {
|
|
|
20
22
|
name: "plugin-mock-server",
|
|
21
23
|
setup(api) {
|
|
22
24
|
const rsbuildConfig = api.getRsbuildConfig();
|
|
23
|
-
const resolvedOptions =
|
|
25
|
+
const resolvedOptions = _chunk4HRWYJ3Ecjs.resolvePluginOptions.call(void 0, options, {
|
|
24
26
|
proxies: resolveConfigProxies(rsbuildConfig),
|
|
25
27
|
alias: {},
|
|
26
28
|
context: api.context.rootPath,
|
|
@@ -30,7 +32,7 @@ function pluginMockServer(options = {}) {
|
|
|
30
32
|
if (resolvedOptions.build) {
|
|
31
33
|
api.onAfterBuild(async () => {
|
|
32
34
|
const config = api.getNormalizedConfig();
|
|
33
|
-
await
|
|
35
|
+
await _chunk4HRWYJ3Ecjs.buildMockServer.call(void 0,
|
|
34
36
|
resolvedOptions,
|
|
35
37
|
_path2.default.resolve(_process2.default.cwd(), config.output.distPath.root || "dist")
|
|
36
38
|
);
|
|
@@ -38,10 +40,10 @@ function pluginMockServer(options = {}) {
|
|
|
38
40
|
}
|
|
39
41
|
return;
|
|
40
42
|
}
|
|
41
|
-
const mockCompiler =
|
|
43
|
+
const mockCompiler = _chunk4HRWYJ3Ecjs.createMockCompiler.call(void 0, resolvedOptions);
|
|
42
44
|
api.modifyRsbuildConfig((config) => {
|
|
43
45
|
updateServerProxyConfigByHttpMock(config);
|
|
44
|
-
const mockMiddleware =
|
|
46
|
+
const mockMiddleware = _chunk4HRWYJ3Ecjs.createMockMiddleware.call(void 0, mockCompiler, resolvedOptions);
|
|
45
47
|
config.dev ??= {};
|
|
46
48
|
config.dev.setupMiddlewares ??= [];
|
|
47
49
|
config.dev.setupMiddlewares.push((middlewares, server2) => {
|
|
@@ -62,7 +64,7 @@ function pluginMockServer(options = {}) {
|
|
|
62
64
|
mockCompiler.run();
|
|
63
65
|
if (shouldMockWs) {
|
|
64
66
|
server = _http.createServer.call(void 0, );
|
|
65
|
-
|
|
67
|
+
_chunkZEC4FWWYcjs.mockWebSocket.call(void 0, mockCompiler, server, resolvedOptions);
|
|
66
68
|
server.listen(port);
|
|
67
69
|
}
|
|
68
70
|
}
|
|
@@ -103,7 +105,7 @@ function updateServerProxyConfigByHttpMock(config) {
|
|
|
103
105
|
onError: onError || onProxyError,
|
|
104
106
|
onProxyReq: (proxyReq, req, ...args) => {
|
|
105
107
|
_optionalChain([onProxyReq, 'optionalCall', _16 => _16(proxyReq, req, ...args)]);
|
|
106
|
-
|
|
108
|
+
_chunkZEC4FWWYcjs.rewriteRequest.call(void 0, proxyReq, req);
|
|
107
109
|
}
|
|
108
110
|
};
|
|
109
111
|
}
|
|
@@ -113,7 +115,7 @@ function updateServerProxyConfigByHttpMock(config) {
|
|
|
113
115
|
const onProxyReq = config.server.proxy.onProxyReq;
|
|
114
116
|
config.server.proxy.onProxyReq = (proxyReq, req, ...args) => {
|
|
115
117
|
_optionalChain([onProxyReq, 'optionalCall', _17 => _17(proxyReq, req, ...args)]);
|
|
116
|
-
|
|
118
|
+
_chunkZEC4FWWYcjs.rewriteRequest.call(void 0, proxyReq, req);
|
|
117
119
|
};
|
|
118
120
|
config.server.proxy.onError ??= onProxyError;
|
|
119
121
|
} else if (config.server.proxy) {
|
|
@@ -128,7 +130,7 @@ function updateServerProxyConfigByHttpMock(config) {
|
|
|
128
130
|
...rest,
|
|
129
131
|
onProxyReq: (proxyReq, req, ...args) => {
|
|
130
132
|
_optionalChain([onProxyReq, 'optionalCall', _18 => _18(proxyReq, req, ...args)]);
|
|
131
|
-
|
|
133
|
+
_chunkZEC4FWWYcjs.rewriteRequest.call(void 0, proxyReq, req);
|
|
132
134
|
},
|
|
133
135
|
onError: onError || onProxyError
|
|
134
136
|
};
|
package/dist/rsbuild.d.cts
CHANGED
package/dist/rsbuild.d.ts
CHANGED
package/dist/rsbuild.js
CHANGED
|
@@ -2,10 +2,12 @@ import {
|
|
|
2
2
|
buildMockServer,
|
|
3
3
|
createMockCompiler,
|
|
4
4
|
createMockMiddleware,
|
|
5
|
+
resolvePluginOptions
|
|
6
|
+
} from "./chunk-ZYUUWKWW.js";
|
|
7
|
+
import {
|
|
5
8
|
mockWebSocket,
|
|
6
|
-
resolvePluginOptions,
|
|
7
9
|
rewriteRequest
|
|
8
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-EY46RSAC.js";
|
|
9
11
|
|
|
10
12
|
// src/rsbuild.ts
|
|
11
13
|
import process from "process";
|
package/dist/server.cjs
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
var _chunkZEC4FWWYcjs = require('./chunk-ZEC4FWWY.cjs');
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
exports.baseMiddleware = _chunkZEC4FWWYcjs.baseMiddleware; exports.createLogger = _chunkZEC4FWWYcjs.createLogger; exports.logLevels = _chunkZEC4FWWYcjs.logLevels; exports.mockWebSocket = _chunkZEC4FWWYcjs.mockWebSocket; exports.sortByValidator = _chunkZEC4FWWYcjs.sortByValidator; exports.transformMockData = _chunkZEC4FWWYcjs.transformMockData; exports.transformRawData = _chunkZEC4FWWYcjs.transformRawData;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { M as MockServerPluginOptions, a as MockHttpItem, b as MockWebsocketItem, c as MockOptions } from './types-BgpcN3jm.cjs';
|
|
2
|
+
import { L as Logger, f as MockCompiler, a as Middleware } from './mockWebsocket-Dc9CZBfv.cjs';
|
|
3
|
+
export { b as MockSocketOptions, g as createLogger, l as logLevels, m as mockWebSocket } from './mockWebsocket-Dc9CZBfv.cjs';
|
|
4
|
+
import 'node:buffer';
|
|
5
|
+
import 'node:http';
|
|
6
|
+
import 'node:stream';
|
|
7
|
+
import 'cookies';
|
|
8
|
+
import 'cors';
|
|
9
|
+
import 'formidable';
|
|
10
|
+
import 'ws';
|
|
11
|
+
import 'co-body';
|
|
12
|
+
import '@rspack/core';
|
|
13
|
+
import 'node:http2';
|
|
14
|
+
import 'node:events';
|
|
15
|
+
import 'node:fs';
|
|
16
|
+
|
|
17
|
+
interface BaseMiddlewareOptions {
|
|
18
|
+
formidableOptions: MockServerPluginOptions['formidableOptions'];
|
|
19
|
+
cookiesOptions: MockServerPluginOptions['cookiesOptions'];
|
|
20
|
+
bodyParserOptions: MockServerPluginOptions['bodyParserOptions'];
|
|
21
|
+
proxies: (string | ((pathname: string, req: any) => boolean))[];
|
|
22
|
+
logger: Logger;
|
|
23
|
+
priority: MockServerPluginOptions['priority'];
|
|
24
|
+
}
|
|
25
|
+
declare function baseMiddleware(compiler: MockCompiler, { formidableOptions, bodyParserOptions, proxies, cookiesOptions, logger, priority, }: BaseMiddlewareOptions): Middleware;
|
|
26
|
+
|
|
27
|
+
declare function transformRawData(rawData: (readonly [any, string])[]): (MockHttpItem | MockWebsocketItem | MockOptions)[];
|
|
28
|
+
declare function transformMockData(mockList: (MockHttpItem | MockWebsocketItem | MockOptions)[]): Record<string, MockOptions>;
|
|
29
|
+
declare function sortByValidator(mocks: MockOptions): (MockHttpItem | MockWebsocketItem)[];
|
|
30
|
+
|
|
31
|
+
export { type BaseMiddlewareOptions, Logger, baseMiddleware, sortByValidator, transformMockData, transformRawData };
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { M as MockServerPluginOptions, a as MockHttpItem, b as MockWebsocketItem, c as MockOptions } from './types-BgpcN3jm.js';
|
|
2
|
+
import { L as Logger, f as MockCompiler, a as Middleware } from './mockWebsocket-CPuTAvL0.js';
|
|
3
|
+
export { b as MockSocketOptions, g as createLogger, l as logLevels, m as mockWebSocket } from './mockWebsocket-CPuTAvL0.js';
|
|
4
|
+
import 'node:buffer';
|
|
5
|
+
import 'node:http';
|
|
6
|
+
import 'node:stream';
|
|
7
|
+
import 'cookies';
|
|
8
|
+
import 'cors';
|
|
9
|
+
import 'formidable';
|
|
10
|
+
import 'ws';
|
|
11
|
+
import 'co-body';
|
|
12
|
+
import '@rspack/core';
|
|
13
|
+
import 'node:http2';
|
|
14
|
+
import 'node:events';
|
|
15
|
+
import 'node:fs';
|
|
16
|
+
|
|
17
|
+
interface BaseMiddlewareOptions {
|
|
18
|
+
formidableOptions: MockServerPluginOptions['formidableOptions'];
|
|
19
|
+
cookiesOptions: MockServerPluginOptions['cookiesOptions'];
|
|
20
|
+
bodyParserOptions: MockServerPluginOptions['bodyParserOptions'];
|
|
21
|
+
proxies: (string | ((pathname: string, req: any) => boolean))[];
|
|
22
|
+
logger: Logger;
|
|
23
|
+
priority: MockServerPluginOptions['priority'];
|
|
24
|
+
}
|
|
25
|
+
declare function baseMiddleware(compiler: MockCompiler, { formidableOptions, bodyParserOptions, proxies, cookiesOptions, logger, priority, }: BaseMiddlewareOptions): Middleware;
|
|
26
|
+
|
|
27
|
+
declare function transformRawData(rawData: (readonly [any, string])[]): (MockHttpItem | MockWebsocketItem | MockOptions)[];
|
|
28
|
+
declare function transformMockData(mockList: (MockHttpItem | MockWebsocketItem | MockOptions)[]): Record<string, MockOptions>;
|
|
29
|
+
declare function sortByValidator(mocks: MockOptions): (MockHttpItem | MockWebsocketItem)[];
|
|
30
|
+
|
|
31
|
+
export { type BaseMiddlewareOptions, Logger, baseMiddleware, sortByValidator, transformMockData, transformRawData };
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import {
|
|
2
|
+
baseMiddleware,
|
|
3
|
+
createLogger,
|
|
4
|
+
logLevels,
|
|
5
|
+
mockWebSocket,
|
|
6
|
+
sortByValidator,
|
|
7
|
+
transformMockData,
|
|
8
|
+
transformRawData
|
|
9
|
+
} from "./chunk-EY46RSAC.js";
|
|
10
|
+
export {
|
|
11
|
+
baseMiddleware,
|
|
12
|
+
createLogger,
|
|
13
|
+
logLevels,
|
|
14
|
+
mockWebSocket,
|
|
15
|
+
sortByValidator,
|
|
16
|
+
transformMockData,
|
|
17
|
+
transformRawData
|
|
18
|
+
};
|
|
@@ -567,4 +567,4 @@ type FormidableFile = formidable.File | formidable.File[];
|
|
|
567
567
|
type LogType = 'info' | 'warn' | 'error' | 'debug';
|
|
568
568
|
type LogLevel = LogType | 'silent';
|
|
569
569
|
|
|
570
|
-
export type { BodyParserOptions as B, ExtraRequest as E, FormidableFile as F,
|
|
570
|
+
export type { BodyParserOptions as B, ExtraRequest as E, FormidableFile as F, LogType as L, MockServerPluginOptions as M, ResponseBody as R, ServerBuildOption as S, WebSocketSetupContext as W, MockHttpItem as a, MockWebsocketItem as b, MockOptions as c, MockMatchPriority as d, MockMatchSpecialPriority as e, Method as f, MockRequest as g, MockResponse as h, LogLevel as i };
|
|
@@ -567,4 +567,4 @@ type FormidableFile = formidable.File | formidable.File[];
|
|
|
567
567
|
type LogType = 'info' | 'warn' | 'error' | 'debug';
|
|
568
568
|
type LogLevel = LogType | 'silent';
|
|
569
569
|
|
|
570
|
-
export type { BodyParserOptions as B, ExtraRequest as E, FormidableFile as F,
|
|
570
|
+
export type { BodyParserOptions as B, ExtraRequest as E, FormidableFile as F, LogType as L, MockServerPluginOptions as M, ResponseBody as R, ServerBuildOption as S, WebSocketSetupContext as W, MockHttpItem as a, MockWebsocketItem as b, MockOptions as c, MockMatchPriority as d, MockMatchSpecialPriority as e, Method as f, MockRequest as g, MockResponse as h, LogLevel as i };
|
package/package.json
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rspack-plugin-mock",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.3.
|
|
4
|
+
"version": "0.3.2",
|
|
5
5
|
"description": "inject api mock server to development server",
|
|
6
6
|
"author": "pengzhanbo <q942450674@outlook.com> (https://github.com/pengzhanbo)",
|
|
7
7
|
"license": "MIT",
|
|
8
|
+
"homepage": "https://github.com/pengzhanbo/rspack-plugin-mock",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/pengzhanbo/rspack-plugin-mock"
|
|
12
|
+
},
|
|
8
13
|
"keywords": [
|
|
9
14
|
"mock",
|
|
10
15
|
"mock server",
|
|
@@ -24,14 +29,14 @@
|
|
|
24
29
|
"default": "./dist/index.cjs"
|
|
25
30
|
}
|
|
26
31
|
},
|
|
27
|
-
"./
|
|
32
|
+
"./server": {
|
|
28
33
|
"import": {
|
|
29
|
-
"types": "./dist/
|
|
30
|
-
"default": "./dist/
|
|
34
|
+
"types": "./dist/server.d.ts",
|
|
35
|
+
"default": "./dist/server.js"
|
|
31
36
|
},
|
|
32
37
|
"require": {
|
|
33
|
-
"types": "./dist/
|
|
34
|
-
"default": "./dist/
|
|
38
|
+
"types": "./dist/server.d.cts",
|
|
39
|
+
"default": "./dist/server.cjs"
|
|
35
40
|
}
|
|
36
41
|
},
|
|
37
42
|
"./rsbuild": {
|
package/dist/chunk-HTOWPFQ7.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
// src/core/defineMock.ts
|
|
2
|
-
import { isArray } from "@pengzhanbo/utils";
|
|
3
|
-
function defineMock(config) {
|
|
4
|
-
return config;
|
|
5
|
-
}
|
|
6
|
-
function createDefineMock(transformer) {
|
|
7
|
-
const define = (config) => {
|
|
8
|
-
if (isArray(config))
|
|
9
|
-
config = config.map((item) => transformer(item) || item);
|
|
10
|
-
else
|
|
11
|
-
config = transformer(config) || config;
|
|
12
|
-
return config;
|
|
13
|
-
};
|
|
14
|
-
return define;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export {
|
|
18
|
-
defineMock,
|
|
19
|
-
createDefineMock
|
|
20
|
-
};
|
package/dist/chunk-KE2LVHUP.cjs
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/core/defineMock.ts
|
|
2
|
-
var _utils = require('@pengzhanbo/utils');
|
|
3
|
-
function defineMock(config) {
|
|
4
|
-
return config;
|
|
5
|
-
}
|
|
6
|
-
function createDefineMock(transformer) {
|
|
7
|
-
const define = (config) => {
|
|
8
|
-
if (_utils.isArray.call(void 0, config))
|
|
9
|
-
config = config.map((item) => transformer(item) || item);
|
|
10
|
-
else
|
|
11
|
-
config = transformer(config) || config;
|
|
12
|
-
return config;
|
|
13
|
-
};
|
|
14
|
-
return define;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
exports.defineMock = defineMock; exports.createDefineMock = createDefineMock;
|
package/dist/chunk-OYBMX3GQ.cjs
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
var _chunkI54ZNZWLcjs = require('./chunk-I54ZNZWL.cjs');
|
|
10
|
-
|
|
11
|
-
// src/rspack.ts
|
|
12
|
-
var _process = require('process'); var _process2 = _interopRequireDefault(_process);
|
|
13
|
-
var _path = require('path'); var _path2 = _interopRequireDefault(_path);
|
|
14
|
-
var _core = require('@rspack/core'); var _core2 = _interopRequireDefault(_core);
|
|
15
|
-
var _utils = require('@pengzhanbo/utils');
|
|
16
|
-
var PLUGIN_NAME = "rspack-plugin-mock";
|
|
17
|
-
var MockServerPlugin = class {
|
|
18
|
-
constructor(options = {}) {
|
|
19
|
-
this.options = options;
|
|
20
|
-
}
|
|
21
|
-
apply(compiler) {
|
|
22
|
-
const compilerOptions = compiler.options;
|
|
23
|
-
const options = resolvePluginOptions2(compiler, this.options);
|
|
24
|
-
if (_process2.default.env.NODE_ENV !== "production") {
|
|
25
|
-
const mockCompiler = _chunkI54ZNZWLcjs.createMockCompiler.call(void 0, options);
|
|
26
|
-
const mockMiddleware = _chunkI54ZNZWLcjs.createMockMiddleware.call(void 0, mockCompiler, options);
|
|
27
|
-
const setupMiddlewares = _optionalChain([compilerOptions, 'access', _ => _.devServer, 'optionalAccess', _2 => _2.setupMiddlewares]);
|
|
28
|
-
const waitServer = _chunkI54ZNZWLcjs.waitingFor.call(void 0, (server) => {
|
|
29
|
-
_chunkI54ZNZWLcjs.mockWebSocket.call(void 0, mockCompiler, server, options);
|
|
30
|
-
});
|
|
31
|
-
compilerOptions.devServer = {
|
|
32
|
-
...compilerOptions.devServer,
|
|
33
|
-
setupMiddlewares: (middlewares, devServer) => {
|
|
34
|
-
middlewares = _optionalChain([setupMiddlewares, 'optionalCall', _3 => _3(middlewares, devServer)]) || middlewares;
|
|
35
|
-
const reload = () => {
|
|
36
|
-
if (_optionalChain([devServer, 'access', _4 => _4.webSocketServer, 'optionalAccess', _5 => _5.clients]))
|
|
37
|
-
devServer.sendMessage(devServer.webSocketServer.clients, "static-changed");
|
|
38
|
-
};
|
|
39
|
-
middlewares = mockMiddleware(middlewares, reload) || middlewares;
|
|
40
|
-
waitServer(() => devServer.server);
|
|
41
|
-
return middlewares;
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
const proxy = _optionalChain([compilerOptions, 'access', _6 => _6.devServer, 'optionalAccess', _7 => _7.proxy]) || [];
|
|
45
|
-
const wsPrefix = _utils.toArray.call(void 0, options.wsPrefix);
|
|
46
|
-
if (proxy.length) {
|
|
47
|
-
compilerOptions.devServer.proxy = proxy.map((item) => {
|
|
48
|
-
if (typeof item !== "function" && !item.ws) {
|
|
49
|
-
const onProxyReq = item.onProxyReq;
|
|
50
|
-
item.onProxyReq = (proxyReq, req, ...args) => {
|
|
51
|
-
_optionalChain([onProxyReq, 'optionalCall', _8 => _8(proxyReq, req, ...args)]);
|
|
52
|
-
_chunkI54ZNZWLcjs.rewriteRequest.call(void 0, proxyReq, req);
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
return item;
|
|
56
|
-
}).filter((item) => {
|
|
57
|
-
if (typeof item !== "function" && item.ws === true && wsPrefix.length) {
|
|
58
|
-
return !_utils.toArray.call(void 0, item.context).filter(_utils.isString).some((context) => wsPrefix.includes(context));
|
|
59
|
-
}
|
|
60
|
-
return true;
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
compiler.hooks.watchRun.tap(PLUGIN_NAME, () => mockCompiler.run());
|
|
64
|
-
compiler.hooks.watchClose.tap(PLUGIN_NAME, () => mockCompiler.close());
|
|
65
|
-
} else if (options.build !== false) {
|
|
66
|
-
compiler.hooks.afterEmit.tap(PLUGIN_NAME, () => _chunkI54ZNZWLcjs.buildMockServer.call(void 0,
|
|
67
|
-
options,
|
|
68
|
-
compilerOptions.output.path || _path2.default.resolve(_process2.default.cwd(), "dist")
|
|
69
|
-
));
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
function resolvePluginOptions2(compiler, options) {
|
|
74
|
-
const compilerOptions = compiler.options;
|
|
75
|
-
const alias = _optionalChain([compilerOptions, 'access', _9 => _9.resolve, 'optionalAccess', _10 => _10.alias]) || {};
|
|
76
|
-
const context = compilerOptions.context;
|
|
77
|
-
const definePluginInstance = _optionalChain([compilerOptions, 'access', _11 => _11.plugins, 'optionalAccess', _12 => _12.find, 'call', _13 => _13(
|
|
78
|
-
(plugin) => plugin instanceof _core2.default.DefinePlugin
|
|
79
|
-
)]);
|
|
80
|
-
const proxies = (_optionalChain([compilerOptions, 'access', _14 => _14.devServer, 'optionalAccess', _15 => _15.proxy]) || []).flatMap((item) => {
|
|
81
|
-
if (typeof item !== "function" && item.context && !item.ws) {
|
|
82
|
-
return item.context;
|
|
83
|
-
}
|
|
84
|
-
return [];
|
|
85
|
-
});
|
|
86
|
-
return _chunkI54ZNZWLcjs.resolvePluginOptions.call(void 0, options, {
|
|
87
|
-
alias,
|
|
88
|
-
context,
|
|
89
|
-
plugins: _utils.toArray.call(void 0, definePluginInstance),
|
|
90
|
-
proxies
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
exports.MockServerPlugin = MockServerPlugin; exports.resolvePluginOptions = resolvePluginOptions2;
|
package/dist/chunk-P5FOCSCE.js
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
buildMockServer,
|
|
3
|
-
createMockCompiler,
|
|
4
|
-
createMockMiddleware,
|
|
5
|
-
mockWebSocket,
|
|
6
|
-
resolvePluginOptions,
|
|
7
|
-
rewriteRequest,
|
|
8
|
-
waitingFor
|
|
9
|
-
} from "./chunk-YSJVV4SH.js";
|
|
10
|
-
|
|
11
|
-
// src/rspack.ts
|
|
12
|
-
import process from "process";
|
|
13
|
-
import path from "path";
|
|
14
|
-
import rspack from "@rspack/core";
|
|
15
|
-
import { isString, toArray } from "@pengzhanbo/utils";
|
|
16
|
-
var PLUGIN_NAME = "rspack-plugin-mock";
|
|
17
|
-
var MockServerPlugin = class {
|
|
18
|
-
constructor(options = {}) {
|
|
19
|
-
this.options = options;
|
|
20
|
-
}
|
|
21
|
-
apply(compiler) {
|
|
22
|
-
const compilerOptions = compiler.options;
|
|
23
|
-
const options = resolvePluginOptions2(compiler, this.options);
|
|
24
|
-
if (process.env.NODE_ENV !== "production") {
|
|
25
|
-
const mockCompiler = createMockCompiler(options);
|
|
26
|
-
const mockMiddleware = createMockMiddleware(mockCompiler, options);
|
|
27
|
-
const setupMiddlewares = compilerOptions.devServer?.setupMiddlewares;
|
|
28
|
-
const waitServer = waitingFor((server) => {
|
|
29
|
-
mockWebSocket(mockCompiler, server, options);
|
|
30
|
-
});
|
|
31
|
-
compilerOptions.devServer = {
|
|
32
|
-
...compilerOptions.devServer,
|
|
33
|
-
setupMiddlewares: (middlewares, devServer) => {
|
|
34
|
-
middlewares = setupMiddlewares?.(middlewares, devServer) || middlewares;
|
|
35
|
-
const reload = () => {
|
|
36
|
-
if (devServer.webSocketServer?.clients)
|
|
37
|
-
devServer.sendMessage(devServer.webSocketServer.clients, "static-changed");
|
|
38
|
-
};
|
|
39
|
-
middlewares = mockMiddleware(middlewares, reload) || middlewares;
|
|
40
|
-
waitServer(() => devServer.server);
|
|
41
|
-
return middlewares;
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
const proxy = compilerOptions.devServer?.proxy || [];
|
|
45
|
-
const wsPrefix = toArray(options.wsPrefix);
|
|
46
|
-
if (proxy.length) {
|
|
47
|
-
compilerOptions.devServer.proxy = proxy.map((item) => {
|
|
48
|
-
if (typeof item !== "function" && !item.ws) {
|
|
49
|
-
const onProxyReq = item.onProxyReq;
|
|
50
|
-
item.onProxyReq = (proxyReq, req, ...args) => {
|
|
51
|
-
onProxyReq?.(proxyReq, req, ...args);
|
|
52
|
-
rewriteRequest(proxyReq, req);
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
return item;
|
|
56
|
-
}).filter((item) => {
|
|
57
|
-
if (typeof item !== "function" && item.ws === true && wsPrefix.length) {
|
|
58
|
-
return !toArray(item.context).filter(isString).some((context) => wsPrefix.includes(context));
|
|
59
|
-
}
|
|
60
|
-
return true;
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
compiler.hooks.watchRun.tap(PLUGIN_NAME, () => mockCompiler.run());
|
|
64
|
-
compiler.hooks.watchClose.tap(PLUGIN_NAME, () => mockCompiler.close());
|
|
65
|
-
} else if (options.build !== false) {
|
|
66
|
-
compiler.hooks.afterEmit.tap(PLUGIN_NAME, () => buildMockServer(
|
|
67
|
-
options,
|
|
68
|
-
compilerOptions.output.path || path.resolve(process.cwd(), "dist")
|
|
69
|
-
));
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
function resolvePluginOptions2(compiler, options) {
|
|
74
|
-
const compilerOptions = compiler.options;
|
|
75
|
-
const alias = compilerOptions.resolve?.alias || {};
|
|
76
|
-
const context = compilerOptions.context;
|
|
77
|
-
const definePluginInstance = compilerOptions.plugins?.find(
|
|
78
|
-
(plugin) => plugin instanceof rspack.DefinePlugin
|
|
79
|
-
);
|
|
80
|
-
const proxies = (compilerOptions.devServer?.proxy || []).flatMap((item) => {
|
|
81
|
-
if (typeof item !== "function" && item.context && !item.ws) {
|
|
82
|
-
return item.context;
|
|
83
|
-
}
|
|
84
|
-
return [];
|
|
85
|
-
});
|
|
86
|
-
return resolvePluginOptions(options, {
|
|
87
|
-
alias,
|
|
88
|
-
context,
|
|
89
|
-
plugins: toArray(definePluginInstance),
|
|
90
|
-
proxies
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export {
|
|
95
|
-
MockServerPlugin,
|
|
96
|
-
resolvePluginOptions2 as resolvePluginOptions
|
|
97
|
-
};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { RspackPluginInstance, Compiler } from '@rspack/core';
|
|
2
|
-
import { L as LogLevel, M as MockServerPluginOptions, S as ServerBuildOption } from './types-C770q3L0.cjs';
|
|
3
|
-
|
|
4
|
-
interface Logger {
|
|
5
|
-
debug: (msg: string, level?: boolean | LogLevel) => void;
|
|
6
|
-
info: (msg: string, level?: boolean | LogLevel) => void;
|
|
7
|
-
warn: (msg: string, level?: boolean | LogLevel) => void;
|
|
8
|
-
error: (msg: string, level?: boolean | LogLevel) => void;
|
|
9
|
-
}
|
|
10
|
-
declare const logLevels: Record<LogLevel, number>;
|
|
11
|
-
declare function createLogger(prefix: string, defaultLevel?: LogLevel): Logger;
|
|
12
|
-
|
|
13
|
-
interface ResolvedCompilerOptions {
|
|
14
|
-
alias: Record<string, false | string | (string | false)[]>;
|
|
15
|
-
proxies: (string | ((pathname: string, req: any) => boolean))[];
|
|
16
|
-
wsProxies: (string | ((pathname: string, req: any) => boolean))[];
|
|
17
|
-
plugins: RspackPluginInstance[];
|
|
18
|
-
context?: string;
|
|
19
|
-
}
|
|
20
|
-
type ResolvePluginOptions = Required<Omit<MockServerPluginOptions, 'build'>> & ResolvedCompilerOptions & {
|
|
21
|
-
logger: Logger;
|
|
22
|
-
build: false | ServerBuildOption;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
declare class MockServerPlugin implements RspackPluginInstance {
|
|
26
|
-
options: MockServerPluginOptions;
|
|
27
|
-
constructor(options?: MockServerPluginOptions);
|
|
28
|
-
apply(compiler: Compiler): void;
|
|
29
|
-
}
|
|
30
|
-
declare function resolvePluginOptions(compiler: Compiler, options: MockServerPluginOptions): ResolvePluginOptions;
|
|
31
|
-
|
|
32
|
-
export { type Logger as L, MockServerPlugin as M, type ResolvePluginOptions as R, createLogger as c, logLevels as l, resolvePluginOptions as r };
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { RspackPluginInstance, Compiler } from '@rspack/core';
|
|
2
|
-
import { L as LogLevel, M as MockServerPluginOptions, S as ServerBuildOption } from './types-C770q3L0.js';
|
|
3
|
-
|
|
4
|
-
interface Logger {
|
|
5
|
-
debug: (msg: string, level?: boolean | LogLevel) => void;
|
|
6
|
-
info: (msg: string, level?: boolean | LogLevel) => void;
|
|
7
|
-
warn: (msg: string, level?: boolean | LogLevel) => void;
|
|
8
|
-
error: (msg: string, level?: boolean | LogLevel) => void;
|
|
9
|
-
}
|
|
10
|
-
declare const logLevels: Record<LogLevel, number>;
|
|
11
|
-
declare function createLogger(prefix: string, defaultLevel?: LogLevel): Logger;
|
|
12
|
-
|
|
13
|
-
interface ResolvedCompilerOptions {
|
|
14
|
-
alias: Record<string, false | string | (string | false)[]>;
|
|
15
|
-
proxies: (string | ((pathname: string, req: any) => boolean))[];
|
|
16
|
-
wsProxies: (string | ((pathname: string, req: any) => boolean))[];
|
|
17
|
-
plugins: RspackPluginInstance[];
|
|
18
|
-
context?: string;
|
|
19
|
-
}
|
|
20
|
-
type ResolvePluginOptions = Required<Omit<MockServerPluginOptions, 'build'>> & ResolvedCompilerOptions & {
|
|
21
|
-
logger: Logger;
|
|
22
|
-
build: false | ServerBuildOption;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
declare class MockServerPlugin implements RspackPluginInstance {
|
|
26
|
-
options: MockServerPluginOptions;
|
|
27
|
-
constructor(options?: MockServerPluginOptions);
|
|
28
|
-
apply(compiler: Compiler): void;
|
|
29
|
-
}
|
|
30
|
-
declare function resolvePluginOptions(compiler: Compiler, options: MockServerPluginOptions): ResolvePluginOptions;
|
|
31
|
-
|
|
32
|
-
export { type Logger as L, MockServerPlugin as M, type ResolvePluginOptions as R, createLogger as c, logLevels as l, resolvePluginOptions as r };
|
package/dist/rspack.cjs
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var _chunkOYBMX3GQcjs = require('./chunk-OYBMX3GQ.cjs');
|
|
5
|
-
require('./chunk-I54ZNZWL.cjs');
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
exports.MockServerPlugin = _chunkOYBMX3GQcjs.MockServerPlugin; exports.resolvePluginOptions = _chunkOYBMX3GQcjs.resolvePluginOptions;
|
package/dist/rspack.d.cts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import '@rspack/core';
|
|
2
|
-
import './types-C770q3L0.cjs';
|
|
3
|
-
export { M as MockServerPlugin, r as resolvePluginOptions } from './rspack-BB-Jtq4f.cjs';
|
|
4
|
-
import 'node:buffer';
|
|
5
|
-
import 'node:http';
|
|
6
|
-
import 'node:stream';
|
|
7
|
-
import 'cookies';
|
|
8
|
-
import 'cors';
|
|
9
|
-
import 'formidable';
|
|
10
|
-
import 'ws';
|
|
11
|
-
import 'co-body';
|
package/dist/rspack.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import '@rspack/core';
|
|
2
|
-
import './types-C770q3L0.js';
|
|
3
|
-
export { M as MockServerPlugin, r as resolvePluginOptions } from './rspack-h3uerEgg.js';
|
|
4
|
-
import 'node:buffer';
|
|
5
|
-
import 'node:http';
|
|
6
|
-
import 'node:stream';
|
|
7
|
-
import 'cookies';
|
|
8
|
-
import 'cors';
|
|
9
|
-
import 'formidable';
|
|
10
|
-
import 'ws';
|
|
11
|
-
import 'co-body';
|