@modern-js/server 2.35.0 → 2.36.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 +31 -14
- package/dist/cjs/dev-tools/dev-middleware/index.js +43 -23
- 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 +45 -22
- package/dist/cjs/dev-tools/register/index.js +47 -21
- 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 +82 -60
- 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 -140
- package/dist/esm/dev-tools/dev-middleware/index.js +9 -9
- 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 +7 -5
- package/dist/esm/dev-tools/register/index.js +7 -4
- 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 +21 -19
- 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 -126
- package/dist/esm-node/dev-tools/dev-middleware/index.js +8 -8
- 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 +6 -5
- package/dist/esm-node/dev-tools/register/index.js +4 -1
- 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 +8 -8
- 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 -10
|
@@ -1,154 +1,162 @@
|
|
|
1
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
2
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
3
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
4
|
+
};
|
|
1
5
|
import stripAnsi from "@modern-js/utils/strip-ansi";
|
|
2
6
|
import { formatWebpackMessages } from "@modern-js/utils/universal/format-webpack";
|
|
3
7
|
import { createSocketUrl } from "./createSocketUrl";
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
var
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
var
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
console.clear
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
function handleSuccess() {
|
|
28
|
-
clearOutdatedErrors();
|
|
29
|
-
var isHotUpdate = !isFirstCompilation;
|
|
30
|
-
isFirstCompilation = false;
|
|
31
|
-
hasCompileErrors = false;
|
|
32
|
-
if (isHotUpdate) {
|
|
33
|
-
tryApplyUpdates();
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
function handleWarnings(warnings) {
|
|
37
|
-
var printWarnings = function printWarnings2() {
|
|
38
|
-
var formatted = formatWebpackMessages({
|
|
39
|
-
warnings: warnings,
|
|
40
|
-
errors: []
|
|
41
|
-
});
|
|
42
|
-
if (typeof console !== "undefined" && typeof console.warn === "function") {
|
|
43
|
-
for (var i = 0; i < formatted.warnings.length; i++) {
|
|
44
|
-
if (i === 5) {
|
|
45
|
-
console.warn("There were more warnings in other files.\nYou can find a complete log in the terminal.");
|
|
46
|
-
break;
|
|
8
|
+
var require_hmr_client = __commonJS({
|
|
9
|
+
"src/dev-tools/dev-middleware/hmr-client/index.ts"(exports, module) {
|
|
10
|
+
var hadRuntimeError = false;
|
|
11
|
+
var socketUrl = createSocketUrl(__resourceQuery);
|
|
12
|
+
var connection = new WebSocket(socketUrl);
|
|
13
|
+
connection.onopen = function() {
|
|
14
|
+
if (typeof console !== "undefined" && typeof console.info === "function") {
|
|
15
|
+
console.info("[HMR] connected.");
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
connection.onclose = function() {
|
|
19
|
+
if (typeof console !== "undefined" && typeof console.info === "function") {
|
|
20
|
+
console.info("[HMR] disconnected. Refresh the page if necessary.");
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
var isFirstCompilation = true;
|
|
24
|
+
var mostRecentCompilationHash = null;
|
|
25
|
+
var hasCompileErrors = false;
|
|
26
|
+
function clearOutdatedErrors() {
|
|
27
|
+
if (typeof console !== "undefined" && typeof console.clear === "function") {
|
|
28
|
+
if (hasCompileErrors) {
|
|
29
|
+
console.clear();
|
|
47
30
|
}
|
|
48
|
-
console.warn(stripAnsi(formatted.warnings[i]));
|
|
49
31
|
}
|
|
50
32
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
tryApplyUpdates();
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
function handleErrors(errors) {
|
|
62
|
-
clearOutdatedErrors();
|
|
63
|
-
isFirstCompilation = false;
|
|
64
|
-
hasCompileErrors = true;
|
|
65
|
-
var formatted = formatWebpackMessages({
|
|
66
|
-
errors: errors,
|
|
67
|
-
warnings: []
|
|
68
|
-
});
|
|
69
|
-
if (typeof console !== "undefined" && typeof console.error === "function") {
|
|
70
|
-
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
|
|
71
|
-
try {
|
|
72
|
-
for (var _iterator = formatted.errors[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
73
|
-
var error = _step.value;
|
|
74
|
-
console.error(stripAnsi(error));
|
|
33
|
+
function handleSuccess() {
|
|
34
|
+
clearOutdatedErrors();
|
|
35
|
+
var isHotUpdate = !isFirstCompilation;
|
|
36
|
+
isFirstCompilation = false;
|
|
37
|
+
hasCompileErrors = false;
|
|
38
|
+
if (isHotUpdate) {
|
|
39
|
+
tryApplyUpdates();
|
|
75
40
|
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
41
|
+
}
|
|
42
|
+
function handleWarnings(warnings) {
|
|
43
|
+
var printWarnings = function printWarnings2() {
|
|
44
|
+
var formatted = formatWebpackMessages({
|
|
45
|
+
warnings,
|
|
46
|
+
errors: []
|
|
47
|
+
});
|
|
48
|
+
if (typeof console !== "undefined" && typeof console.warn === "function") {
|
|
49
|
+
for (var i = 0; i < formatted.warnings.length; i++) {
|
|
50
|
+
if (i === 5) {
|
|
51
|
+
console.warn("There were more warnings in other files.\nYou can find a complete log in the terminal.");
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
console.warn(stripAnsi(formatted.warnings[i]));
|
|
55
|
+
}
|
|
83
56
|
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
|
|
57
|
+
};
|
|
58
|
+
clearOutdatedErrors();
|
|
59
|
+
var isHotUpdate = !isFirstCompilation;
|
|
60
|
+
isFirstCompilation = false;
|
|
61
|
+
hasCompileErrors = false;
|
|
62
|
+
printWarnings();
|
|
63
|
+
if (isHotUpdate) {
|
|
64
|
+
tryApplyUpdates();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function handleErrors(errors) {
|
|
68
|
+
clearOutdatedErrors();
|
|
69
|
+
isFirstCompilation = false;
|
|
70
|
+
hasCompileErrors = true;
|
|
71
|
+
var formatted = formatWebpackMessages({
|
|
72
|
+
errors,
|
|
73
|
+
warnings: []
|
|
74
|
+
});
|
|
75
|
+
if (typeof console !== "undefined" && typeof console.error === "function") {
|
|
76
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
|
|
77
|
+
try {
|
|
78
|
+
for (var _iterator = formatted.errors[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
79
|
+
var error = _step.value;
|
|
80
|
+
console.error(stripAnsi(error));
|
|
81
|
+
}
|
|
82
|
+
} catch (err) {
|
|
83
|
+
_didIteratorError = true;
|
|
84
|
+
_iteratorError = err;
|
|
85
|
+
} finally {
|
|
86
|
+
try {
|
|
87
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
88
|
+
_iterator.return();
|
|
89
|
+
}
|
|
90
|
+
} finally {
|
|
91
|
+
if (_didIteratorError) {
|
|
92
|
+
throw _iteratorError;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
87
95
|
}
|
|
88
96
|
}
|
|
89
97
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
function handleAvailableHash(hash) {
|
|
93
|
-
mostRecentCompilationHash = hash;
|
|
94
|
-
}
|
|
95
|
-
connection.onmessage = function(e) {
|
|
96
|
-
var message = JSON.parse(e.data);
|
|
97
|
-
switch (message.type) {
|
|
98
|
-
case "hash":
|
|
99
|
-
handleAvailableHash(message.data);
|
|
100
|
-
break;
|
|
101
|
-
case "still-ok":
|
|
102
|
-
case "ok":
|
|
103
|
-
handleSuccess();
|
|
104
|
-
break;
|
|
105
|
-
case "content-changed":
|
|
106
|
-
window.location.reload();
|
|
107
|
-
break;
|
|
108
|
-
case "warnings":
|
|
109
|
-
handleWarnings(message.data);
|
|
110
|
-
break;
|
|
111
|
-
case "errors":
|
|
112
|
-
handleErrors(message.data);
|
|
113
|
-
break;
|
|
114
|
-
default:
|
|
115
|
-
}
|
|
116
|
-
};
|
|
117
|
-
function isUpdateAvailable() {
|
|
118
|
-
return mostRecentCompilationHash !== __webpack_hash__;
|
|
119
|
-
}
|
|
120
|
-
function canApplyUpdates() {
|
|
121
|
-
return module.hot.status() === "idle";
|
|
122
|
-
}
|
|
123
|
-
function tryApplyUpdates() {
|
|
124
|
-
var handleApplyUpdates = function handleApplyUpdates2(err, updatedModules) {
|
|
125
|
-
var wantsForcedReload = err || !updatedModules || hadRuntimeError;
|
|
126
|
-
if (wantsForcedReload) {
|
|
127
|
-
window.location.reload();
|
|
128
|
-
return;
|
|
98
|
+
function handleAvailableHash(hash) {
|
|
99
|
+
mostRecentCompilationHash = hash;
|
|
129
100
|
}
|
|
130
|
-
|
|
131
|
-
|
|
101
|
+
connection.onmessage = function(e) {
|
|
102
|
+
var message = JSON.parse(e.data);
|
|
103
|
+
switch (message.type) {
|
|
104
|
+
case "hash":
|
|
105
|
+
handleAvailableHash(message.data);
|
|
106
|
+
break;
|
|
107
|
+
case "still-ok":
|
|
108
|
+
case "ok":
|
|
109
|
+
handleSuccess();
|
|
110
|
+
break;
|
|
111
|
+
case "content-changed":
|
|
112
|
+
window.location.reload();
|
|
113
|
+
break;
|
|
114
|
+
case "warnings":
|
|
115
|
+
handleWarnings(message.data);
|
|
116
|
+
break;
|
|
117
|
+
case "errors":
|
|
118
|
+
handleErrors(message.data);
|
|
119
|
+
break;
|
|
120
|
+
default:
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
function isUpdateAvailable() {
|
|
124
|
+
return mostRecentCompilationHash !== __webpack_hash__;
|
|
125
|
+
}
|
|
126
|
+
function canApplyUpdates() {
|
|
127
|
+
return module.hot.status() === "idle";
|
|
128
|
+
}
|
|
129
|
+
function tryApplyUpdates() {
|
|
130
|
+
var handleApplyUpdates = function handleApplyUpdates2(err, updatedModules) {
|
|
131
|
+
var wantsForcedReload = err || !updatedModules || hadRuntimeError;
|
|
132
|
+
if (wantsForcedReload) {
|
|
133
|
+
window.location.reload();
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
if (isUpdateAvailable()) {
|
|
137
|
+
tryApplyUpdates();
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
if (!module.hot) {
|
|
141
|
+
window.location.reload();
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
if (!isUpdateAvailable() || !canApplyUpdates()) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
var result = module.hot.check(
|
|
148
|
+
/* autoApply */
|
|
149
|
+
true,
|
|
150
|
+
handleApplyUpdates
|
|
151
|
+
);
|
|
152
|
+
if (result === null || result === void 0 ? void 0 : result.then) {
|
|
153
|
+
result.then(function(updatedModules) {
|
|
154
|
+
handleApplyUpdates(null, updatedModules);
|
|
155
|
+
}, function(err) {
|
|
156
|
+
handleApplyUpdates(err, null);
|
|
157
|
+
});
|
|
158
|
+
}
|
|
132
159
|
}
|
|
133
|
-
};
|
|
134
|
-
var _result;
|
|
135
|
-
if (!module.hot) {
|
|
136
|
-
window.location.reload();
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
if (!isUpdateAvailable() || !canApplyUpdates()) {
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
var result = module.hot.check(
|
|
143
|
-
/* autoApply */
|
|
144
|
-
true,
|
|
145
|
-
handleApplyUpdates
|
|
146
|
-
);
|
|
147
|
-
if ((_result = result) === null || _result === void 0 ? void 0 : _result.then) {
|
|
148
|
-
result.then(function(updatedModules) {
|
|
149
|
-
handleApplyUpdates(null, updatedModules);
|
|
150
|
-
}, function(err) {
|
|
151
|
-
handleApplyUpdates(err, null);
|
|
152
|
-
});
|
|
153
160
|
}
|
|
154
|
-
}
|
|
161
|
+
});
|
|
162
|
+
export default require_hmr_client();
|
|
@@ -7,19 +7,17 @@ import { _ as _inherits } from "@swc/helpers/_/_inherits";
|
|
|
7
7
|
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
|
8
8
|
import { _ as _create_super } from "@swc/helpers/_/_create_super";
|
|
9
9
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
10
|
-
import { sep } from "path";
|
|
11
10
|
import { EventEmitter } from "events";
|
|
12
11
|
import SocketServer from "./socketServer";
|
|
13
12
|
var noop = function() {
|
|
14
13
|
};
|
|
15
14
|
function getHMRClientPath(client) {
|
|
16
|
-
var
|
|
17
|
-
var
|
|
18
|
-
var
|
|
19
|
-
var
|
|
20
|
-
var port = ((_client3 = client) === null || _client3 === void 0 ? void 0 : _client3.port) ? "&port=".concat(client.port) : "";
|
|
15
|
+
var protocol = (client === null || client === void 0 ? void 0 : client.protocol) ? "&protocol=".concat(client.protocol) : "";
|
|
16
|
+
var host = (client === null || client === void 0 ? void 0 : client.host) ? "&host=".concat(client.host) : "";
|
|
17
|
+
var path = (client === null || client === void 0 ? void 0 : client.path) ? "&path=".concat(client.path) : "";
|
|
18
|
+
var port = (client === null || client === void 0 ? void 0 : client.port) ? "&port=".concat(client.port) : "";
|
|
21
19
|
var clientEntry = "".concat(require.resolve("@modern-js/server/hmr-client"), "?").concat(host).concat(path).concat(port).concat(protocol);
|
|
22
|
-
return clientEntry
|
|
20
|
+
return clientEntry;
|
|
23
21
|
}
|
|
24
22
|
var DevMiddleware = /* @__PURE__ */ function(EventEmitter2) {
|
|
25
23
|
"use strict";
|
|
@@ -85,7 +83,7 @@ var DevMiddleware = /* @__PURE__ */ function(EventEmitter2) {
|
|
|
85
83
|
var middleware = devMiddleware(_object_spread({
|
|
86
84
|
headers: devOptions.headers,
|
|
87
85
|
stats: false,
|
|
88
|
-
callbacks
|
|
86
|
+
callbacks,
|
|
89
87
|
hmrClientPath: enableHMR ? getHMRClientPath(devOptions.client) : void 0,
|
|
90
88
|
serverSideRender: true
|
|
91
89
|
}, devOptions.devMiddleware));
|
|
@@ -95,4 +93,6 @@ var DevMiddleware = /* @__PURE__ */ function(EventEmitter2) {
|
|
|
95
93
|
]);
|
|
96
94
|
return DevMiddleware2;
|
|
97
95
|
}(EventEmitter);
|
|
98
|
-
export {
|
|
96
|
+
export {
|
|
97
|
+
DevMiddleware as default
|
|
98
|
+
};
|
|
@@ -72,8 +72,8 @@ var SocketServer = /* @__PURE__ */ function() {
|
|
|
72
72
|
var _this = this;
|
|
73
73
|
this.sockets.forEach(function(socket) {
|
|
74
74
|
_this.send(socket, JSON.stringify({
|
|
75
|
-
type
|
|
76
|
-
data
|
|
75
|
+
type,
|
|
76
|
+
data
|
|
77
77
|
}));
|
|
78
78
|
});
|
|
79
79
|
}
|
|
@@ -83,8 +83,8 @@ var SocketServer = /* @__PURE__ */ function() {
|
|
|
83
83
|
key: "singleWrite",
|
|
84
84
|
value: function singleWrite(socket, type, data) {
|
|
85
85
|
this.send(socket, JSON.stringify({
|
|
86
|
-
type
|
|
87
|
-
data
|
|
86
|
+
type,
|
|
87
|
+
data
|
|
88
88
|
}));
|
|
89
89
|
}
|
|
90
90
|
},
|
|
@@ -193,4 +193,6 @@ var SocketServer = /* @__PURE__ */ function() {
|
|
|
193
193
|
]);
|
|
194
194
|
return SocketServer2;
|
|
195
195
|
}();
|
|
196
|
-
export {
|
|
196
|
+
export {
|
|
197
|
+
SocketServer as default
|
|
198
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
2
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
3
3
|
import { chalk, getPackageManager, logger } from "@modern-js/utils";
|
|
4
|
-
|
|
4
|
+
var genHttpsOptions = function() {
|
|
5
5
|
var _ref = _async_to_generator(function(userOptions, pwd) {
|
|
6
6
|
var httpsOptions, devcertPath, err, packageManager, command, devcert, selfsign;
|
|
7
7
|
return _ts_generator(this, function(_state) {
|
|
@@ -69,3 +69,6 @@ export var genHttpsOptions = function() {
|
|
|
69
69
|
return _ref.apply(this, arguments);
|
|
70
70
|
};
|
|
71
71
|
}();
|
|
72
|
+
export {
|
|
73
|
+
genHttpsOptions
|
|
74
|
+
};
|
|
@@ -46,7 +46,7 @@ var allowTypes = [
|
|
|
46
46
|
"object",
|
|
47
47
|
"function"
|
|
48
48
|
];
|
|
49
|
-
|
|
49
|
+
function getMockData_default(mockConfig) {
|
|
50
50
|
return Object.keys(mockConfig).reduce(function(acc, key) {
|
|
51
51
|
var handler = mockConfig[key];
|
|
52
52
|
var type = typeof handler === "undefined" ? "undefined" : _type_of(handler);
|
|
@@ -82,7 +82,7 @@ var parseKey = function(key) {
|
|
|
82
82
|
path: key
|
|
83
83
|
};
|
|
84
84
|
};
|
|
85
|
-
|
|
85
|
+
var getMatched = function(context, mockApiList) {
|
|
86
86
|
var targetPathname = context.path, targetMethod = context.method;
|
|
87
87
|
var matched = mockApiList.find(function(mockApi) {
|
|
88
88
|
var method = mockApi.method, pathname = mockApi.path;
|
|
@@ -96,3 +96,7 @@ export var getMatched = function(context, mockApiList) {
|
|
|
96
96
|
});
|
|
97
97
|
return matched;
|
|
98
98
|
};
|
|
99
|
+
export {
|
|
100
|
+
getMockData_default as default,
|
|
101
|
+
getMatched
|
|
102
|
+
};
|
|
@@ -4,9 +4,8 @@ import path from "path";
|
|
|
4
4
|
import { compatRequire, fs } from "@modern-js/utils";
|
|
5
5
|
import { AGGRED_DIR } from "@modern-js/prod-server";
|
|
6
6
|
import getMockData, { getMatched } from "./getMockData";
|
|
7
|
-
|
|
7
|
+
var createMockHandler = function(param) {
|
|
8
8
|
var pwd = param.pwd;
|
|
9
|
-
var _config;
|
|
10
9
|
var exts = [
|
|
11
10
|
".ts",
|
|
12
11
|
".js"
|
|
@@ -41,7 +40,7 @@ export var createMockHandler = function(param) {
|
|
|
41
40
|
}
|
|
42
41
|
var mod = compatRequire(filepath, false);
|
|
43
42
|
var tmp = mod.default, mockModule = tmp === void 0 ? mod : tmp, config = mod.config;
|
|
44
|
-
if ((
|
|
43
|
+
if ((config === null || config === void 0 ? void 0 : config.enable) === false) {
|
|
45
44
|
return null;
|
|
46
45
|
}
|
|
47
46
|
if (!mockModule) {
|
|
@@ -53,9 +52,9 @@ export var createMockHandler = function(param) {
|
|
|
53
52
|
}
|
|
54
53
|
return function() {
|
|
55
54
|
var _ref = _async_to_generator(function(context, next) {
|
|
56
|
-
var
|
|
55
|
+
var enableMock, res, matched;
|
|
57
56
|
return _ts_generator(this, function(_state) {
|
|
58
|
-
if (typeof (
|
|
57
|
+
if (typeof (config === null || config === void 0 ? void 0 : config.enable) === "function") {
|
|
59
58
|
enableMock = config.enable(context.req, context.res);
|
|
60
59
|
if (!enableMock) {
|
|
61
60
|
return [
|
|
@@ -84,3 +83,6 @@ export var createMockHandler = function(param) {
|
|
|
84
83
|
};
|
|
85
84
|
}();
|
|
86
85
|
};
|
|
86
|
+
export {
|
|
87
|
+
createMockHandler
|
|
88
|
+
};
|
|
@@ -9,13 +9,13 @@ var checkDep = function(depName, paths) {
|
|
|
9
9
|
var packagePath = "";
|
|
10
10
|
try {
|
|
11
11
|
packagePath = require.resolve(depName, {
|
|
12
|
-
paths
|
|
12
|
+
paths
|
|
13
13
|
});
|
|
14
14
|
} catch (error) {
|
|
15
15
|
}
|
|
16
16
|
return Boolean(packagePath);
|
|
17
17
|
};
|
|
18
|
-
|
|
18
|
+
var enableRegister = function(projectRoot, config) {
|
|
19
19
|
var registerDirs = [
|
|
20
20
|
"./api",
|
|
21
21
|
"./server",
|
|
@@ -40,7 +40,7 @@ export var enableRegister = function(projectRoot, config) {
|
|
|
40
40
|
var alias = config.source.alias;
|
|
41
41
|
var aliasConfig = getAliasConfig(alias, {
|
|
42
42
|
appDirectory: projectRoot,
|
|
43
|
-
tsconfigPath
|
|
43
|
+
tsconfigPath
|
|
44
44
|
});
|
|
45
45
|
var _aliasConfig_paths = aliasConfig.paths, paths = _aliasConfig_paths === void 0 ? {} : _aliasConfig_paths, _aliasConfig_absoluteBaseUrl = aliasConfig.absoluteBaseUrl, absoluteBaseUrl = _aliasConfig_absoluteBaseUrl === void 0 ? "./" : _aliasConfig_absoluteBaseUrl;
|
|
46
46
|
var tsPaths = Object.keys(paths).reduce(function(o, key) {
|
|
@@ -81,7 +81,7 @@ export var enableRegister = function(projectRoot, config) {
|
|
|
81
81
|
compiler: (_config_server = config.server) === null || _config_server === void 0 ? void 0 : _config_server.compiler
|
|
82
82
|
}
|
|
83
83
|
}), {
|
|
84
|
-
tsconfigPath
|
|
84
|
+
tsconfigPath,
|
|
85
85
|
syntax: "es6+",
|
|
86
86
|
type: "commonjs"
|
|
87
87
|
});
|
|
@@ -106,3 +106,6 @@ export var enableRegister = function(projectRoot, config) {
|
|
|
106
106
|
}));
|
|
107
107
|
}
|
|
108
108
|
};
|
|
109
|
+
export {
|
|
110
|
+
enableRegister
|
|
111
|
+
};
|
|
@@ -3,14 +3,14 @@ import { _ as _create_class } from "@swc/helpers/_/_create_class";
|
|
|
3
3
|
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
|
4
4
|
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
5
5
|
import minimatch from "minimatch";
|
|
6
|
-
|
|
6
|
+
var defaultIgnores = [
|
|
7
7
|
"**/coverage/**",
|
|
8
8
|
"**/node_modules/**",
|
|
9
9
|
"**/.*/**",
|
|
10
10
|
"**/*.d.ts",
|
|
11
11
|
"**/*.log"
|
|
12
12
|
];
|
|
13
|
-
|
|
13
|
+
var DependencyTree = /* @__PURE__ */ function() {
|
|
14
14
|
"use strict";
|
|
15
15
|
function DependencyTree2() {
|
|
16
16
|
_class_call_check(this, DependencyTree2);
|
|
@@ -41,7 +41,7 @@ export var DependencyTree = /* @__PURE__ */ function() {
|
|
|
41
41
|
if (!_this.shouldIgnore(path)) {
|
|
42
42
|
var module = cache[path];
|
|
43
43
|
_this.tree.set(module.filename, {
|
|
44
|
-
module
|
|
44
|
+
module,
|
|
45
45
|
parent: /* @__PURE__ */ new Set(),
|
|
46
46
|
children: /* @__PURE__ */ new Set()
|
|
47
47
|
});
|
|
@@ -103,3 +103,7 @@ export var DependencyTree = /* @__PURE__ */ function() {
|
|
|
103
103
|
]);
|
|
104
104
|
return DependencyTree2;
|
|
105
105
|
}();
|
|
106
|
+
export {
|
|
107
|
+
DependencyTree,
|
|
108
|
+
defaultIgnores
|
|
109
|
+
};
|
|
@@ -7,12 +7,12 @@ import path from "path";
|
|
|
7
7
|
import { fs, chokidar } from "@modern-js/utils";
|
|
8
8
|
import { DependencyTree } from "./dependencyTree";
|
|
9
9
|
import { StatsCache } from "./statsCache";
|
|
10
|
-
|
|
10
|
+
var defaultWatchOptions = {
|
|
11
11
|
// 初始化的时候不触发 add、addDir 事件
|
|
12
12
|
ignoreInitial: true,
|
|
13
13
|
ignored: /api\/typings\/.*/
|
|
14
14
|
};
|
|
15
|
-
|
|
15
|
+
var getWatchedFiles = function(watcher) {
|
|
16
16
|
var watched = watcher.getWatched();
|
|
17
17
|
var files = [];
|
|
18
18
|
Object.keys(watched).forEach(function(dir) {
|
|
@@ -22,7 +22,7 @@ export var getWatchedFiles = function(watcher) {
|
|
|
22
22
|
});
|
|
23
23
|
return files;
|
|
24
24
|
};
|
|
25
|
-
|
|
25
|
+
var mergeWatchOptions = function(options) {
|
|
26
26
|
var watchOptions = _object_spread({}, options);
|
|
27
27
|
if (watchOptions) {
|
|
28
28
|
var ignored = watchOptions.ignored;
|
|
@@ -131,4 +131,9 @@ var Watcher = /* @__PURE__ */ function() {
|
|
|
131
131
|
]);
|
|
132
132
|
return Watcher2;
|
|
133
133
|
}();
|
|
134
|
-
export {
|
|
134
|
+
export {
|
|
135
|
+
Watcher as default,
|
|
136
|
+
defaultWatchOptions,
|
|
137
|
+
getWatchedFiles,
|
|
138
|
+
mergeWatchOptions
|
|
139
|
+
};
|
|
@@ -3,7 +3,7 @@ import { _ as _create_class } from "@swc/helpers/_/_create_class";
|
|
|
3
3
|
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
|
4
4
|
import fs from "fs";
|
|
5
5
|
import crypto from "crypto";
|
|
6
|
-
|
|
6
|
+
var StatsCache = /* @__PURE__ */ function() {
|
|
7
7
|
"use strict";
|
|
8
8
|
function StatsCache2() {
|
|
9
9
|
_class_call_check(this, StatsCache2);
|
|
@@ -96,3 +96,6 @@ export var StatsCache = /* @__PURE__ */ function() {
|
|
|
96
96
|
]);
|
|
97
97
|
return StatsCache2;
|
|
98
98
|
}();
|
|
99
|
+
export {
|
|
100
|
+
StatsCache
|
|
101
|
+
};
|
package/dist/esm/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { DevServer as Server } from "./server";
|
|
2
|
-
|
|
3
|
-
export default function(options) {
|
|
2
|
+
function src_default(options) {
|
|
4
3
|
if (options == null) {
|
|
5
4
|
throw new Error("can not start server without options");
|
|
6
5
|
}
|
|
@@ -8,3 +7,7 @@ export default function(options) {
|
|
|
8
7
|
return server.init();
|
|
9
8
|
}
|
|
10
9
|
;
|
|
10
|
+
export {
|
|
11
|
+
Server,
|
|
12
|
+
src_default as default
|
|
13
|
+
};
|