@modern-js/server 2.35.1 → 2.37.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/dist/cjs/constants.js +26 -9
- package/dist/cjs/dev-tools/dev-middleware/hmr-client/createSocketUrl.js +27 -17
- package/dist/cjs/dev-tools/dev-middleware/hmr-client/index.js +30 -12
- package/dist/cjs/dev-tools/dev-middleware/index.js +39 -18
- package/dist/cjs/dev-tools/dev-middleware/socketServer.js +41 -19
- package/dist/cjs/dev-tools/https/index.js +29 -12
- package/dist/cjs/dev-tools/mock/getMockData.js +27 -18
- package/dist/cjs/dev-tools/mock/index.js +43 -18
- package/dist/cjs/dev-tools/register/index.js +48 -24
- package/dist/cjs/dev-tools/watcher/dependencyTree.js +43 -24
- package/dist/cjs/dev-tools/watcher/index.js +50 -34
- package/dist/cjs/dev-tools/watcher/statsCache.js +45 -19
- package/dist/cjs/index.js +27 -18
- package/dist/cjs/server/devServer.js +80 -55
- package/dist/cjs/server/index.js +28 -11
- package/dist/cjs/server/workerSSRRender.js +38 -12
- package/dist/cjs/types.js +15 -3
- package/dist/esm/constants.js +4 -1
- package/dist/esm/dev-tools/dev-middleware/hmr-client/createSocketUrl.js +6 -2
- package/dist/esm/dev-tools/dev-middleware/hmr-client/index.js +148 -139
- package/dist/esm/dev-tools/dev-middleware/index.js +5 -4
- package/dist/esm/dev-tools/dev-middleware/socketServer.js +7 -5
- package/dist/esm/dev-tools/https/index.js +4 -1
- package/dist/esm/dev-tools/mock/getMockData.js +6 -2
- package/dist/esm/dev-tools/mock/index.js +4 -1
- package/dist/esm/dev-tools/register/index.js +7 -6
- package/dist/esm/dev-tools/watcher/dependencyTree.js +7 -3
- package/dist/esm/dev-tools/watcher/index.js +9 -4
- package/dist/esm/dev-tools/watcher/statsCache.js +4 -1
- package/dist/esm/index.js +5 -2
- package/dist/esm/server/devServer.js +17 -14
- package/dist/esm/server/index.js +4 -1
- package/dist/esm/server/workerSSRRender.js +6 -3
- package/dist/esm/types.js +0 -1
- package/dist/esm-node/constants.js +4 -1
- package/dist/esm-node/dev-tools/dev-middleware/hmr-client/createSocketUrl.js +6 -2
- package/dist/esm-node/dev-tools/dev-middleware/hmr-client/index.js +134 -125
- package/dist/esm-node/dev-tools/dev-middleware/index.js +4 -3
- package/dist/esm-node/dev-tools/dev-middleware/socketServer.js +3 -1
- package/dist/esm-node/dev-tools/https/index.js +4 -1
- package/dist/esm-node/dev-tools/mock/getMockData.js +6 -2
- package/dist/esm-node/dev-tools/mock/index.js +4 -1
- package/dist/esm-node/dev-tools/register/index.js +5 -4
- package/dist/esm-node/dev-tools/watcher/dependencyTree.js +6 -2
- package/dist/esm-node/dev-tools/watcher/index.js +9 -4
- package/dist/esm-node/dev-tools/watcher/statsCache.js +4 -1
- package/dist/esm-node/index.js +5 -2
- package/dist/esm-node/server/devServer.js +4 -1
- package/dist/esm-node/server/index.js +4 -1
- package/dist/esm-node/server/workerSSRRender.js +4 -1
- package/dist/esm-node/types.js +0 -1
- package/package.json +10 -11
package/dist/cjs/constants.js
CHANGED
|
@@ -1,18 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
9
15
|
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var constants_exports = {};
|
|
20
|
+
__export(constants_exports, {
|
|
21
|
+
getDefaultDevOptions: () => getDefaultDevOptions
|
|
10
22
|
});
|
|
11
|
-
|
|
23
|
+
module.exports = __toCommonJS(constants_exports);
|
|
24
|
+
var import_constants = require("@modern-js/utils/universal/constants");
|
|
12
25
|
const getDefaultDevOptions = () => {
|
|
13
26
|
return {
|
|
14
27
|
client: {
|
|
15
|
-
path:
|
|
28
|
+
path: import_constants.HMR_SOCK_PATH,
|
|
16
29
|
// By default it is set to the port number of the dev server
|
|
17
30
|
port: "",
|
|
18
31
|
// By default it is set to "location.hostname"
|
|
@@ -30,3 +43,7 @@ const getDefaultDevOptions = () => {
|
|
|
30
43
|
liveReload: true
|
|
31
44
|
};
|
|
32
45
|
};
|
|
46
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
47
|
+
0 && (module.exports = {
|
|
48
|
+
getDefaultDevOptions
|
|
49
|
+
});
|
|
@@ -1,23 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
6
7
|
for (var name in all)
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return createSocketUrl;
|
|
15
|
-
},
|
|
16
|
-
formatURL: function() {
|
|
17
|
-
return formatURL;
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
15
|
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var createSocketUrl_exports = {};
|
|
20
|
+
__export(createSocketUrl_exports, {
|
|
21
|
+
createSocketUrl: () => createSocketUrl,
|
|
22
|
+
formatURL: () => formatURL
|
|
19
23
|
});
|
|
20
|
-
|
|
24
|
+
module.exports = __toCommonJS(createSocketUrl_exports);
|
|
25
|
+
var import_constants = require("@modern-js/utils/universal/constants");
|
|
21
26
|
function createSocketUrl(resourceQuery) {
|
|
22
27
|
const searchParams = resourceQuery.substr(1).split("&");
|
|
23
28
|
const options = {};
|
|
@@ -46,6 +51,11 @@ function getSocketUrl(urlParts, location) {
|
|
|
46
51
|
protocol: protocol || (location.protocol === "https:" ? "wss" : "ws"),
|
|
47
52
|
hostname: host || location.hostname,
|
|
48
53
|
port: port || location.port,
|
|
49
|
-
pathname: path ||
|
|
54
|
+
pathname: path || import_constants.HMR_SOCK_PATH
|
|
50
55
|
});
|
|
51
56
|
}
|
|
57
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
58
|
+
0 && (module.exports = {
|
|
59
|
+
createSocketUrl,
|
|
60
|
+
formatURL
|
|
61
|
+
});
|
|
@@ -1,13 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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") {
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
12
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
}
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
18
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
19
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
20
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
var import_strip_ansi = __toESM(require("@modern-js/utils/strip-ansi"));
|
|
25
|
+
var import_format_webpack = require("@modern-js/utils/universal/format-webpack");
|
|
26
|
+
var import_createSocketUrl = require("./createSocketUrl");
|
|
9
27
|
const hadRuntimeError = false;
|
|
10
|
-
const socketUrl = (0,
|
|
28
|
+
const socketUrl = (0, import_createSocketUrl.createSocketUrl)(__resourceQuery);
|
|
11
29
|
const connection = new WebSocket(socketUrl);
|
|
12
30
|
connection.onopen = function() {
|
|
13
31
|
if (typeof console !== "undefined" && typeof console.info === "function") {
|
|
@@ -44,7 +62,7 @@ function handleWarnings(warnings) {
|
|
|
44
62
|
isFirstCompilation = false;
|
|
45
63
|
hasCompileErrors = false;
|
|
46
64
|
function printWarnings() {
|
|
47
|
-
const formatted = (0,
|
|
65
|
+
const formatted = (0, import_format_webpack.formatWebpackMessages)({
|
|
48
66
|
warnings,
|
|
49
67
|
errors: []
|
|
50
68
|
});
|
|
@@ -54,7 +72,7 @@ function handleWarnings(warnings) {
|
|
|
54
72
|
console.warn("There were more warnings in other files.\nYou can find a complete log in the terminal.");
|
|
55
73
|
break;
|
|
56
74
|
}
|
|
57
|
-
console.warn((0,
|
|
75
|
+
console.warn((0, import_strip_ansi.default)(formatted.warnings[i]));
|
|
58
76
|
}
|
|
59
77
|
}
|
|
60
78
|
}
|
|
@@ -67,13 +85,13 @@ function handleErrors(errors) {
|
|
|
67
85
|
clearOutdatedErrors();
|
|
68
86
|
isFirstCompilation = false;
|
|
69
87
|
hasCompileErrors = true;
|
|
70
|
-
const formatted = (0,
|
|
88
|
+
const formatted = (0, import_format_webpack.formatWebpackMessages)({
|
|
71
89
|
errors,
|
|
72
90
|
warnings: []
|
|
73
91
|
});
|
|
74
92
|
if (typeof console !== "undefined" && typeof console.error === "function") {
|
|
75
93
|
for (const error of formatted.errors) {
|
|
76
|
-
console.error((0,
|
|
94
|
+
console.error((0, import_strip_ansi.default)(error));
|
|
77
95
|
}
|
|
78
96
|
}
|
|
79
97
|
}
|
|
@@ -1,18 +1,39 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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 __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
9
17
|
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var dev_middleware_exports = {};
|
|
30
|
+
__export(dev_middleware_exports, {
|
|
31
|
+
default: () => DevMiddleware
|
|
10
32
|
});
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const _socketServer = /* @__PURE__ */ _interop_require_default._(require("./socketServer"));
|
|
33
|
+
module.exports = __toCommonJS(dev_middleware_exports);
|
|
34
|
+
var import_define_property = require("@swc/helpers/_/_define_property");
|
|
35
|
+
var import_events = require("events");
|
|
36
|
+
var import_socketServer = __toESM(require("./socketServer"));
|
|
16
37
|
const noop = () => {
|
|
17
38
|
};
|
|
18
39
|
function getHMRClientPath(client) {
|
|
@@ -21,9 +42,9 @@ function getHMRClientPath(client) {
|
|
|
21
42
|
const path = (client === null || client === void 0 ? void 0 : client.path) ? `&path=${client.path}` : "";
|
|
22
43
|
const port = (client === null || client === void 0 ? void 0 : client.port) ? `&port=${client.port}` : "";
|
|
23
44
|
const clientEntry = `${require.resolve("@modern-js/server/hmr-client")}?${host}${path}${port}${protocol}`;
|
|
24
|
-
return clientEntry
|
|
45
|
+
return clientEntry;
|
|
25
46
|
}
|
|
26
|
-
class DevMiddleware extends
|
|
47
|
+
class DevMiddleware extends import_events.EventEmitter {
|
|
27
48
|
init(app) {
|
|
28
49
|
app.on("listening", () => {
|
|
29
50
|
this.socketServer.prepare(app);
|
|
@@ -61,11 +82,11 @@ class DevMiddleware extends _events.EventEmitter {
|
|
|
61
82
|
}
|
|
62
83
|
constructor({ dev, devMiddleware }) {
|
|
63
84
|
super();
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
85
|
+
(0, import_define_property._)(this, "middleware", void 0);
|
|
86
|
+
(0, import_define_property._)(this, "devOptions", void 0);
|
|
87
|
+
(0, import_define_property._)(this, "socketServer", void 0);
|
|
67
88
|
this.devOptions = dev;
|
|
68
|
-
this.socketServer = new
|
|
89
|
+
this.socketServer = new import_socketServer.default(dev);
|
|
69
90
|
if (devMiddleware) {
|
|
70
91
|
this.middleware = this.setupDevMiddleware(devMiddleware);
|
|
71
92
|
}
|
|
@@ -1,23 +1,45 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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 __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
9
17
|
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var socketServer_exports = {};
|
|
30
|
+
__export(socketServer_exports, {
|
|
31
|
+
default: () => SocketServer
|
|
10
32
|
});
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
33
|
+
module.exports = __toCommonJS(socketServer_exports);
|
|
34
|
+
var import_define_property = require("@swc/helpers/_/_define_property");
|
|
35
|
+
var import_ws = __toESM(require("ws"));
|
|
36
|
+
var import_utils = require("@modern-js/utils");
|
|
15
37
|
class SocketServer {
|
|
16
38
|
// create socket, install socket handler, bind socket event
|
|
17
39
|
prepare(app) {
|
|
18
40
|
var _this_options_client;
|
|
19
41
|
this.app = app;
|
|
20
|
-
this.wsServer = new
|
|
42
|
+
this.wsServer = new import_ws.default.Server({
|
|
21
43
|
noServer: true,
|
|
22
44
|
path: (_this_options_client = this.options.client) === null || _this_options_client === void 0 ? void 0 : _this_options_client.path
|
|
23
45
|
});
|
|
@@ -30,7 +52,7 @@ class SocketServer {
|
|
|
30
52
|
});
|
|
31
53
|
});
|
|
32
54
|
this.wsServer.on("error", (err) => {
|
|
33
|
-
|
|
55
|
+
import_utils.logger.error(err);
|
|
34
56
|
});
|
|
35
57
|
this.timer = setInterval(() => {
|
|
36
58
|
this.wsServer.clients.forEach((socket) => {
|
|
@@ -145,12 +167,12 @@ class SocketServer {
|
|
|
145
167
|
connection.send(message);
|
|
146
168
|
}
|
|
147
169
|
constructor(options) {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
170
|
+
(0, import_define_property._)(this, "wsServer", void 0);
|
|
171
|
+
(0, import_define_property._)(this, "sockets", []);
|
|
172
|
+
(0, import_define_property._)(this, "options", void 0);
|
|
173
|
+
(0, import_define_property._)(this, "app", void 0);
|
|
174
|
+
(0, import_define_property._)(this, "stats", void 0);
|
|
175
|
+
(0, import_define_property._)(this, "timer", null);
|
|
154
176
|
this.options = options;
|
|
155
177
|
}
|
|
156
178
|
}
|
|
@@ -1,14 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
9
15
|
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var https_exports = {};
|
|
20
|
+
__export(https_exports, {
|
|
21
|
+
genHttpsOptions: () => genHttpsOptions
|
|
10
22
|
});
|
|
11
|
-
|
|
23
|
+
module.exports = __toCommonJS(https_exports);
|
|
24
|
+
var import_utils = require("@modern-js/utils");
|
|
12
25
|
const genHttpsOptions = async (userOptions, pwd) => {
|
|
13
26
|
const httpsOptions = typeof userOptions === "boolean" ? {} : userOptions;
|
|
14
27
|
if (!httpsOptions.key || !httpsOptions.cert) {
|
|
@@ -21,10 +34,10 @@ const genHttpsOptions = async (userOptions, pwd) => {
|
|
|
21
34
|
]
|
|
22
35
|
});
|
|
23
36
|
} catch (err) {
|
|
24
|
-
const packageManager = await (0,
|
|
25
|
-
const command =
|
|
26
|
-
|
|
27
|
-
|
|
37
|
+
const packageManager = await (0, import_utils.getPackageManager)(pwd);
|
|
38
|
+
const command = import_utils.chalk.yellow.bold(`${packageManager} add devcert@1.2.2 -D`);
|
|
39
|
+
import_utils.logger.error(`You have enabled "dev.https" option, but the "devcert" package is not installed.`);
|
|
40
|
+
import_utils.logger.error(`Please run ${command} to install manually, otherwise the https can not work.`);
|
|
28
41
|
throw new Error('[https] "devcert" is not found.');
|
|
29
42
|
}
|
|
30
43
|
const devcert = require(devcertPath);
|
|
@@ -35,3 +48,7 @@ const genHttpsOptions = async (userOptions, pwd) => {
|
|
|
35
48
|
}
|
|
36
49
|
return httpsOptions;
|
|
37
50
|
};
|
|
51
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
52
|
+
0 && (module.exports = {
|
|
53
|
+
genHttpsOptions
|
|
54
|
+
});
|
|
@@ -1,23 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
6
7
|
for (var name in all)
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return _default;
|
|
15
|
-
},
|
|
16
|
-
getMatched: function() {
|
|
17
|
-
return getMatched;
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
15
|
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var getMockData_exports = {};
|
|
20
|
+
__export(getMockData_exports, {
|
|
21
|
+
default: () => getMockData_default,
|
|
22
|
+
getMatched: () => getMatched
|
|
19
23
|
});
|
|
20
|
-
|
|
24
|
+
module.exports = __toCommonJS(getMockData_exports);
|
|
25
|
+
var import_path_to_regexp = require("path-to-regexp");
|
|
21
26
|
const VALID_METHODS = [
|
|
22
27
|
"get",
|
|
23
28
|
"post",
|
|
@@ -44,7 +49,7 @@ const allowTypes = [
|
|
|
44
49
|
"object",
|
|
45
50
|
"function"
|
|
46
51
|
];
|
|
47
|
-
|
|
52
|
+
var getMockData_default = (mockConfig) => Object.keys(mockConfig).reduce((acc, key) => {
|
|
48
53
|
const handler = mockConfig[key];
|
|
49
54
|
const type = typeof handler;
|
|
50
55
|
if (!allowTypes.includes(type)) {
|
|
@@ -84,7 +89,7 @@ const getMatched = (context, mockApiList) => {
|
|
|
84
89
|
const matched = mockApiList.find((mockApi) => {
|
|
85
90
|
const { method, path: pathname } = mockApi;
|
|
86
91
|
if (method.toLowerCase() === targetMethod.toLowerCase()) {
|
|
87
|
-
return (0,
|
|
92
|
+
return (0, import_path_to_regexp.match)(pathname, {
|
|
88
93
|
encode: encodeURI,
|
|
89
94
|
decode: decodeURIComponent
|
|
90
95
|
})(targetPathname);
|
|
@@ -93,3 +98,7 @@ const getMatched = (context, mockApiList) => {
|
|
|
93
98
|
});
|
|
94
99
|
return matched;
|
|
95
100
|
};
|
|
101
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
102
|
+
0 && (module.exports = {
|
|
103
|
+
getMatched
|
|
104
|
+
});
|
|
@@ -1,19 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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 __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
9
17
|
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var mock_exports = {};
|
|
30
|
+
__export(mock_exports, {
|
|
31
|
+
createMockHandler: () => createMockHandler
|
|
10
32
|
});
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const _getMockData = /* @__PURE__ */ _interop_require_wildcard._(require("./getMockData"));
|
|
33
|
+
module.exports = __toCommonJS(mock_exports);
|
|
34
|
+
var import_path = __toESM(require("path"));
|
|
35
|
+
var import_utils = require("@modern-js/utils");
|
|
36
|
+
var import_prod_server = require("@modern-js/prod-server");
|
|
37
|
+
var import_getMockData = __toESM(require("./getMockData"));
|
|
17
38
|
const createMockHandler = ({ pwd }) => {
|
|
18
39
|
const exts = [
|
|
19
40
|
".ts",
|
|
@@ -21,8 +42,8 @@ const createMockHandler = ({ pwd }) => {
|
|
|
21
42
|
];
|
|
22
43
|
let filepath = "";
|
|
23
44
|
for (const ext of exts) {
|
|
24
|
-
const maybeMatch =
|
|
25
|
-
if (
|
|
45
|
+
const maybeMatch = import_path.default.join(pwd, `${import_prod_server.AGGRED_DIR.mock}/index${ext}`);
|
|
46
|
+
if (import_utils.fs.existsSync(maybeMatch)) {
|
|
26
47
|
filepath = maybeMatch;
|
|
27
48
|
break;
|
|
28
49
|
}
|
|
@@ -30,7 +51,7 @@ const createMockHandler = ({ pwd }) => {
|
|
|
30
51
|
if (!filepath) {
|
|
31
52
|
return null;
|
|
32
53
|
}
|
|
33
|
-
const mod = (0,
|
|
54
|
+
const mod = (0, import_utils.compatRequire)(filepath, false);
|
|
34
55
|
const { default: mockModule = mod, config } = mod;
|
|
35
56
|
if ((config === null || config === void 0 ? void 0 : config.enable) === false) {
|
|
36
57
|
return null;
|
|
@@ -38,7 +59,7 @@ const createMockHandler = ({ pwd }) => {
|
|
|
38
59
|
if (!mockModule) {
|
|
39
60
|
throw new Error(`Mock file ${filepath} parsed failed!`);
|
|
40
61
|
}
|
|
41
|
-
const apiList = (0,
|
|
62
|
+
const apiList = (0, import_getMockData.default)(mockModule);
|
|
42
63
|
if (!apiList || apiList.length === 0) {
|
|
43
64
|
return null;
|
|
44
65
|
}
|
|
@@ -50,7 +71,7 @@ const createMockHandler = ({ pwd }) => {
|
|
|
50
71
|
}
|
|
51
72
|
}
|
|
52
73
|
const { res } = context;
|
|
53
|
-
const matched = (0,
|
|
74
|
+
const matched = (0, import_getMockData.getMatched)(context, apiList);
|
|
54
75
|
if (!matched) {
|
|
55
76
|
return next();
|
|
56
77
|
}
|
|
@@ -58,3 +79,7 @@ const createMockHandler = ({ pwd }) => {
|
|
|
58
79
|
return matched.handler(context, next);
|
|
59
80
|
};
|
|
60
81
|
};
|
|
82
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
83
|
+
0 && (module.exports = {
|
|
84
|
+
createMockHandler
|
|
85
|
+
});
|