rspack-plugin-mock 0.3.3 → 0.3.4
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.
|
@@ -418,6 +418,7 @@ var _chokidar = require('chokidar'); var _chokidar2 = _interopRequireDefault(_ch
|
|
|
418
418
|
// src/core/loadFromCode.ts
|
|
419
419
|
|
|
420
420
|
|
|
421
|
+
var _url = require('url');
|
|
421
422
|
async function loadFromCode({
|
|
422
423
|
filepath,
|
|
423
424
|
code,
|
|
@@ -428,9 +429,10 @@ async function loadFromCode({
|
|
|
428
429
|
const fileBase = `${filepath}.timestamp-${Date.now()}`;
|
|
429
430
|
const ext = isESM ? ".mjs" : ".cjs";
|
|
430
431
|
const fileNameTmp = `${fileBase}${ext}`;
|
|
432
|
+
const fileUrl = _url.pathToFileURL.call(void 0, fileNameTmp).toString();
|
|
431
433
|
await _fs.promises.writeFile(fileNameTmp, code, "utf8");
|
|
432
434
|
try {
|
|
433
|
-
const result = await
|
|
435
|
+
const result = await import(fileUrl);
|
|
434
436
|
return result.default || result;
|
|
435
437
|
} finally {
|
|
436
438
|
try {
|
|
@@ -418,6 +418,7 @@ import { toArray as toArray3 } from "@pengzhanbo/utils";
|
|
|
418
418
|
// src/core/loadFromCode.ts
|
|
419
419
|
import path2 from "path";
|
|
420
420
|
import fs2, { promises as fsp2 } from "fs";
|
|
421
|
+
import { pathToFileURL } from "url";
|
|
421
422
|
async function loadFromCode({
|
|
422
423
|
filepath,
|
|
423
424
|
code,
|
|
@@ -428,9 +429,10 @@ async function loadFromCode({
|
|
|
428
429
|
const fileBase = `${filepath}.timestamp-${Date.now()}`;
|
|
429
430
|
const ext = isESM ? ".mjs" : ".cjs";
|
|
430
431
|
const fileNameTmp = `${fileBase}${ext}`;
|
|
432
|
+
const fileUrl = pathToFileURL(fileNameTmp).toString();
|
|
431
433
|
await fsp2.writeFile(fileNameTmp, code, "utf8");
|
|
432
434
|
try {
|
|
433
|
-
const result = await import(
|
|
435
|
+
const result = await import(fileUrl);
|
|
434
436
|
return result.default || result;
|
|
435
437
|
} finally {
|
|
436
438
|
try {
|
package/dist/index.cjs
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
var
|
|
7
|
+
var _chunkHLMEDDGXcjs = require('./chunk-HLMEDDGX.cjs');
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
@@ -25,8 +25,8 @@ var MockServerPlugin = class {
|
|
|
25
25
|
const compilerOptions = compiler.options;
|
|
26
26
|
const options = resolvePluginOptions2(compiler, this.options);
|
|
27
27
|
if (_process2.default.env.NODE_ENV !== "production") {
|
|
28
|
-
const mockCompiler =
|
|
29
|
-
const mockMiddleware =
|
|
28
|
+
const mockCompiler = _chunkHLMEDDGXcjs.createMockCompiler.call(void 0, options);
|
|
29
|
+
const mockMiddleware = _chunkHLMEDDGXcjs.createMockMiddleware.call(void 0, mockCompiler, options);
|
|
30
30
|
const setupMiddlewares = _optionalChain([compilerOptions, 'access', _ => _.devServer, 'optionalAccess', _2 => _2.setupMiddlewares]);
|
|
31
31
|
const waitServer = _chunkZEC4FWWYcjs.waitingFor.call(void 0, (server) => {
|
|
32
32
|
_chunkZEC4FWWYcjs.mockWebSocket.call(void 0, mockCompiler, server, options);
|
|
@@ -66,7 +66,7 @@ var MockServerPlugin = class {
|
|
|
66
66
|
compiler.hooks.watchRun.tap(PLUGIN_NAME, () => mockCompiler.run());
|
|
67
67
|
compiler.hooks.watchClose.tap(PLUGIN_NAME, () => mockCompiler.close());
|
|
68
68
|
} else if (options.build !== false) {
|
|
69
|
-
compiler.hooks.afterEmit.tap(PLUGIN_NAME, () =>
|
|
69
|
+
compiler.hooks.afterEmit.tap(PLUGIN_NAME, () => _chunkHLMEDDGXcjs.buildMockServer.call(void 0,
|
|
70
70
|
options,
|
|
71
71
|
compilerOptions.output.path || _path2.default.resolve(_process2.default.cwd(), "dist")
|
|
72
72
|
));
|
|
@@ -86,7 +86,7 @@ function resolvePluginOptions2(compiler, options) {
|
|
|
86
86
|
}
|
|
87
87
|
return [];
|
|
88
88
|
});
|
|
89
|
-
return
|
|
89
|
+
return _chunkHLMEDDGXcjs.resolvePluginOptions.call(void 0, options, {
|
|
90
90
|
alias,
|
|
91
91
|
context,
|
|
92
92
|
plugins: _utils.toArray.call(void 0, definePluginInstance),
|
|
@@ -100,4 +100,4 @@ function resolvePluginOptions2(compiler, options) {
|
|
|
100
100
|
|
|
101
101
|
|
|
102
102
|
|
|
103
|
-
exports.MockCompiler =
|
|
103
|
+
exports.MockCompiler = _chunkHLMEDDGXcjs.MockCompiler; exports.MockServerPlugin = MockServerPlugin; exports.createMockCompiler = _chunkHLMEDDGXcjs.createMockCompiler; exports.createMockMiddleware = _chunkHLMEDDGXcjs.createMockMiddleware; exports.mockWebSocket = _chunkZEC4FWWYcjs.mockWebSocket; exports.resolvePluginOptions = resolvePluginOptions2;
|
package/dist/index.js
CHANGED
package/dist/rsbuild.cjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunkHLMEDDGXcjs = require('./chunk-HLMEDDGX.cjs');
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
@@ -22,7 +22,7 @@ function pluginMockServer(options = {}) {
|
|
|
22
22
|
name: "plugin-mock-server",
|
|
23
23
|
setup(api) {
|
|
24
24
|
const rsbuildConfig = api.getRsbuildConfig();
|
|
25
|
-
const resolvedOptions =
|
|
25
|
+
const resolvedOptions = _chunkHLMEDDGXcjs.resolvePluginOptions.call(void 0, options, {
|
|
26
26
|
proxies: resolveConfigProxies(rsbuildConfig),
|
|
27
27
|
alias: {},
|
|
28
28
|
context: api.context.rootPath,
|
|
@@ -32,7 +32,7 @@ function pluginMockServer(options = {}) {
|
|
|
32
32
|
if (resolvedOptions.build) {
|
|
33
33
|
api.onAfterBuild(async () => {
|
|
34
34
|
const config = api.getNormalizedConfig();
|
|
35
|
-
await
|
|
35
|
+
await _chunkHLMEDDGXcjs.buildMockServer.call(void 0,
|
|
36
36
|
resolvedOptions,
|
|
37
37
|
_path2.default.resolve(_process2.default.cwd(), config.output.distPath.root || "dist")
|
|
38
38
|
);
|
|
@@ -40,10 +40,10 @@ function pluginMockServer(options = {}) {
|
|
|
40
40
|
}
|
|
41
41
|
return;
|
|
42
42
|
}
|
|
43
|
-
const mockCompiler =
|
|
43
|
+
const mockCompiler = _chunkHLMEDDGXcjs.createMockCompiler.call(void 0, resolvedOptions);
|
|
44
44
|
api.modifyRsbuildConfig((config) => {
|
|
45
45
|
updateServerProxyConfigByHttpMock(config);
|
|
46
|
-
const mockMiddleware =
|
|
46
|
+
const mockMiddleware = _chunkHLMEDDGXcjs.createMockMiddleware.call(void 0, mockCompiler, resolvedOptions);
|
|
47
47
|
config.dev ??= {};
|
|
48
48
|
config.dev.setupMiddlewares ??= [];
|
|
49
49
|
config.dev.setupMiddlewares.push((middlewares, server2) => {
|
package/dist/rsbuild.js
CHANGED
package/package.json
CHANGED