@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
|
@@ -22,7 +22,7 @@ import { enableRegister } from "../dev-tools/register";
|
|
|
22
22
|
import Watcher, { mergeWatchOptions } from "../dev-tools/watcher";
|
|
23
23
|
import DevMiddleware from "../dev-tools/dev-middleware";
|
|
24
24
|
import { workerSSRRender } from "./workerSSRRender";
|
|
25
|
-
|
|
25
|
+
var ModernDevServer = /* @__PURE__ */ function(ModernServer2) {
|
|
26
26
|
"use strict";
|
|
27
27
|
_inherits(ModernDevServer2, ModernServer2);
|
|
28
28
|
var _super = _create_super(ModernDevServer2);
|
|
@@ -98,8 +98,8 @@ export var ModernDevServer = /* @__PURE__ */ function(ModernServer2) {
|
|
|
98
98
|
}, serverOptions);
|
|
99
99
|
});
|
|
100
100
|
return {
|
|
101
|
-
befores
|
|
102
|
-
afters
|
|
101
|
+
befores,
|
|
102
|
+
afters
|
|
103
103
|
};
|
|
104
104
|
}
|
|
105
105
|
},
|
|
@@ -187,12 +187,12 @@ export var ModernDevServer = /* @__PURE__ */ function(ModernServer2) {
|
|
|
187
187
|
var forceCSR = typeof ssrConfig === "object" ? ssrConfig.forceCSR : false;
|
|
188
188
|
return createRenderHandler({
|
|
189
189
|
ssrRender: workerSSRRender,
|
|
190
|
-
distDir
|
|
191
|
-
staticGenerate
|
|
192
|
-
conf
|
|
193
|
-
forceCSR
|
|
190
|
+
distDir,
|
|
191
|
+
staticGenerate,
|
|
192
|
+
conf,
|
|
193
|
+
forceCSR,
|
|
194
194
|
nonce: (_conf_security = conf.security) === null || _conf_security === void 0 ? void 0 : _conf_security.nonce,
|
|
195
|
-
metaName
|
|
195
|
+
metaName
|
|
196
196
|
});
|
|
197
197
|
}
|
|
198
198
|
return _get(_get_prototype_of(ModernDevServer2.prototype), "getRenderHandler", this).call(this);
|
|
@@ -210,8 +210,7 @@ export var ModernDevServer = /* @__PURE__ */ function(ModernServer2) {
|
|
|
210
210
|
case 0:
|
|
211
211
|
pwd = _this.pwd, dev = _this.dev, devMiddleware = _this.devMiddleware, conf = _this.conf;
|
|
212
212
|
isUseStreamingSSR = function(routes) {
|
|
213
|
-
|
|
214
|
-
return (_routes = routes) === null || _routes === void 0 ? void 0 : _routes.some(function(r) {
|
|
213
|
+
return routes === null || routes === void 0 ? void 0 : routes.some(function(r) {
|
|
215
214
|
return r.isStream === true;
|
|
216
215
|
});
|
|
217
216
|
};
|
|
@@ -274,7 +273,7 @@ export var ModernDevServer = /* @__PURE__ */ function(ModernServer2) {
|
|
|
274
273
|
next();
|
|
275
274
|
});
|
|
276
275
|
_this.mockHandler = createMockHandler({
|
|
277
|
-
pwd
|
|
276
|
+
pwd
|
|
278
277
|
});
|
|
279
278
|
_this.addHandler(function(ctx, next) {
|
|
280
279
|
if (_this.mockHandler) {
|
|
@@ -445,7 +444,7 @@ export var ModernDevServer = /* @__PURE__ */ function(ModernServer2) {
|
|
|
445
444
|
1
|
|
446
445
|
];
|
|
447
446
|
_this1.mockHandler = createMockHandler({
|
|
448
|
-
pwd
|
|
447
|
+
pwd
|
|
449
448
|
});
|
|
450
449
|
return [
|
|
451
450
|
3,
|
|
@@ -461,7 +460,7 @@ export var ModernDevServer = /* @__PURE__ */ function(ModernServer2) {
|
|
|
461
460
|
success = _this1.runner.onApiChange([
|
|
462
461
|
{
|
|
463
462
|
filename: filepath,
|
|
464
|
-
event
|
|
463
|
+
event
|
|
465
464
|
}
|
|
466
465
|
]);
|
|
467
466
|
if (!(success !== true))
|
|
@@ -472,7 +471,7 @@ export var ModernDevServer = /* @__PURE__ */ function(ModernServer2) {
|
|
|
472
471
|
return [
|
|
473
472
|
4,
|
|
474
473
|
_superprop_get_onServerChange().call(_this1, {
|
|
475
|
-
filepath
|
|
474
|
+
filepath
|
|
476
475
|
})
|
|
477
476
|
];
|
|
478
477
|
case 2:
|
|
@@ -599,11 +598,11 @@ export var ModernDevServer = /* @__PURE__ */ function(ModernServer2) {
|
|
|
599
598
|
key: "startWatcher",
|
|
600
599
|
value: function startWatcher() {
|
|
601
600
|
var _this = this;
|
|
602
|
-
var
|
|
601
|
+
var _this_conf_server;
|
|
603
602
|
var _this1 = this, pwd = _this1.pwd, distDir = _this1.distDir, appContext = _this1.appContext;
|
|
604
603
|
var mock = AGGRED_DIR.mock;
|
|
605
|
-
var apiDir = (
|
|
606
|
-
var sharedDir = (
|
|
604
|
+
var apiDir = (appContext === null || appContext === void 0 ? void 0 : appContext.apiDirectory) || API_DIR;
|
|
605
|
+
var sharedDir = (appContext === null || appContext === void 0 ? void 0 : appContext.sharedDirectory) || SHARED_DIR;
|
|
607
606
|
var defaultWatched = [
|
|
608
607
|
"".concat(mock, "/**/*"),
|
|
609
608
|
"".concat(SERVER_DIR, "/**/*"),
|
|
@@ -627,8 +626,8 @@ export var ModernDevServer = /* @__PURE__ */ function(ModernServer2) {
|
|
|
627
626
|
watcher.cleanDepCache(filepath);
|
|
628
627
|
}
|
|
629
628
|
_this.onServerChange({
|
|
630
|
-
filepath
|
|
631
|
-
event
|
|
629
|
+
filepath,
|
|
630
|
+
event
|
|
632
631
|
});
|
|
633
632
|
});
|
|
634
633
|
this.watcher = watcher;
|
|
@@ -637,3 +636,6 @@ export var ModernDevServer = /* @__PURE__ */ function(ModernServer2) {
|
|
|
637
636
|
]);
|
|
638
637
|
return ModernDevServer2;
|
|
639
638
|
}(ModernServer);
|
|
639
|
+
export {
|
|
640
|
+
ModernDevServer
|
|
641
|
+
};
|
package/dist/esm/server/index.js
CHANGED
|
@@ -6,7 +6,7 @@ import { ModernDevServer } from "./devServer";
|
|
|
6
6
|
var createDevServer = function(options) {
|
|
7
7
|
return new ModernDevServer(options);
|
|
8
8
|
};
|
|
9
|
-
|
|
9
|
+
var DevServer = /* @__PURE__ */ function(Server2) {
|
|
10
10
|
"use strict";
|
|
11
11
|
_inherits(DevServer2, Server2);
|
|
12
12
|
var _super = _create_super(DevServer2);
|
|
@@ -21,3 +21,6 @@ export var DevServer = /* @__PURE__ */ function(Server2) {
|
|
|
21
21
|
}
|
|
22
22
|
return DevServer2;
|
|
23
23
|
}(Server);
|
|
24
|
+
export {
|
|
25
|
+
DevServer
|
|
26
|
+
};
|
|
@@ -3,7 +3,7 @@ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
|
3
3
|
import axios from "axios";
|
|
4
4
|
import { mime } from "@modern-js/utils";
|
|
5
5
|
var PORT = 9230;
|
|
6
|
-
|
|
6
|
+
function workerSSRRender(ctx, renderOptions, _runner) {
|
|
7
7
|
return _workerSSRRender.apply(this, arguments);
|
|
8
8
|
}
|
|
9
9
|
function _workerSSRRender() {
|
|
@@ -20,8 +20,8 @@ function _workerSSRRender() {
|
|
|
20
20
|
axios.get(url, {
|
|
21
21
|
timeout: 5e3,
|
|
22
22
|
responseType: "text",
|
|
23
|
-
headers
|
|
24
|
-
params
|
|
23
|
+
headers,
|
|
24
|
+
params
|
|
25
25
|
})
|
|
26
26
|
];
|
|
27
27
|
case 1:
|
|
@@ -38,3 +38,6 @@ function _workerSSRRender() {
|
|
|
38
38
|
});
|
|
39
39
|
return _workerSSRRender.apply(this, arguments);
|
|
40
40
|
}
|
|
41
|
+
export {
|
|
42
|
+
workerSSRRender
|
|
43
|
+
};
|
package/dist/esm/types.js
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { HMR_SOCK_PATH } from "@modern-js/utils/universal/constants";
|
|
2
|
-
|
|
2
|
+
const getDefaultDevOptions = () => {
|
|
3
3
|
return {
|
|
4
4
|
client: {
|
|
5
5
|
path: HMR_SOCK_PATH,
|
|
@@ -20,3 +20,6 @@ export const getDefaultDevOptions = () => {
|
|
|
20
20
|
liveReload: true
|
|
21
21
|
};
|
|
22
22
|
};
|
|
23
|
+
export {
|
|
24
|
+
getDefaultDevOptions
|
|
25
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { HMR_SOCK_PATH } from "@modern-js/utils/universal/constants";
|
|
2
|
-
|
|
2
|
+
function createSocketUrl(resourceQuery) {
|
|
3
3
|
const searchParams = resourceQuery.substr(1).split("&");
|
|
4
4
|
const options = {};
|
|
5
5
|
for (const pair of searchParams) {
|
|
@@ -9,7 +9,7 @@ export function createSocketUrl(resourceQuery) {
|
|
|
9
9
|
const currentLocation = self.location;
|
|
10
10
|
return getSocketUrl(options, currentLocation);
|
|
11
11
|
}
|
|
12
|
-
|
|
12
|
+
function formatURL({ port, protocol, hostname, pathname }) {
|
|
13
13
|
if (window.URL) {
|
|
14
14
|
const url = new URL("http://localhost");
|
|
15
15
|
url.port = port;
|
|
@@ -30,3 +30,7 @@ function getSocketUrl(urlParts, location) {
|
|
|
30
30
|
pathname: path || HMR_SOCK_PATH
|
|
31
31
|
});
|
|
32
32
|
}
|
|
33
|
+
export {
|
|
34
|
+
createSocketUrl,
|
|
35
|
+
formatURL
|
|
36
|
+
};
|
|
@@ -1,137 +1,145 @@
|
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
let
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
console.clear
|
|
8
|
+
var require_hmr_client = __commonJS({
|
|
9
|
+
"src/dev-tools/dev-middleware/hmr-client/index.ts"(exports, module) {
|
|
10
|
+
const hadRuntimeError = false;
|
|
11
|
+
const socketUrl = createSocketUrl(__resourceQuery);
|
|
12
|
+
const 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
|
+
let isFirstCompilation = true;
|
|
24
|
+
let mostRecentCompilationHash = null;
|
|
25
|
+
let hasCompileErrors = false;
|
|
26
|
+
function clearOutdatedErrors() {
|
|
27
|
+
if (typeof console !== "undefined" && typeof console.clear === "function") {
|
|
28
|
+
if (hasCompileErrors) {
|
|
29
|
+
console.clear();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
24
32
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
33
|
+
function handleSuccess() {
|
|
34
|
+
clearOutdatedErrors();
|
|
35
|
+
const isHotUpdate = !isFirstCompilation;
|
|
36
|
+
isFirstCompilation = false;
|
|
37
|
+
hasCompileErrors = false;
|
|
38
|
+
if (isHotUpdate) {
|
|
39
|
+
tryApplyUpdates();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function handleWarnings(warnings) {
|
|
43
|
+
clearOutdatedErrors();
|
|
44
|
+
const isHotUpdate = !isFirstCompilation;
|
|
45
|
+
isFirstCompilation = false;
|
|
46
|
+
hasCompileErrors = false;
|
|
47
|
+
function printWarnings() {
|
|
48
|
+
const formatted = formatWebpackMessages({
|
|
49
|
+
warnings,
|
|
50
|
+
errors: []
|
|
51
|
+
});
|
|
52
|
+
if (typeof console !== "undefined" && typeof console.warn === "function") {
|
|
53
|
+
for (let i = 0; i < formatted.warnings.length; i++) {
|
|
54
|
+
if (i === 5) {
|
|
55
|
+
console.warn("There were more warnings in other files.\nYou can find a complete log in the terminal.");
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
console.warn(stripAnsi(formatted.warnings[i]));
|
|
59
|
+
}
|
|
51
60
|
}
|
|
52
|
-
|
|
61
|
+
}
|
|
62
|
+
printWarnings();
|
|
63
|
+
if (isHotUpdate) {
|
|
64
|
+
tryApplyUpdates();
|
|
53
65
|
}
|
|
54
66
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
});
|
|
69
|
-
if (typeof console !== "undefined" && typeof console.error === "function") {
|
|
70
|
-
for (const error of formatted.errors) {
|
|
71
|
-
console.error(stripAnsi(error));
|
|
67
|
+
function handleErrors(errors) {
|
|
68
|
+
clearOutdatedErrors();
|
|
69
|
+
isFirstCompilation = false;
|
|
70
|
+
hasCompileErrors = true;
|
|
71
|
+
const formatted = formatWebpackMessages({
|
|
72
|
+
errors,
|
|
73
|
+
warnings: []
|
|
74
|
+
});
|
|
75
|
+
if (typeof console !== "undefined" && typeof console.error === "function") {
|
|
76
|
+
for (const error of formatted.errors) {
|
|
77
|
+
console.error(stripAnsi(error));
|
|
78
|
+
}
|
|
79
|
+
}
|
|
72
80
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
function handleAvailableHash(hash) {
|
|
76
|
-
mostRecentCompilationHash = hash;
|
|
77
|
-
}
|
|
78
|
-
connection.onmessage = function(e) {
|
|
79
|
-
const message = JSON.parse(e.data);
|
|
80
|
-
switch (message.type) {
|
|
81
|
-
case "hash":
|
|
82
|
-
handleAvailableHash(message.data);
|
|
83
|
-
break;
|
|
84
|
-
case "still-ok":
|
|
85
|
-
case "ok":
|
|
86
|
-
handleSuccess();
|
|
87
|
-
break;
|
|
88
|
-
case "content-changed":
|
|
89
|
-
window.location.reload();
|
|
90
|
-
break;
|
|
91
|
-
case "warnings":
|
|
92
|
-
handleWarnings(message.data);
|
|
93
|
-
break;
|
|
94
|
-
case "errors":
|
|
95
|
-
handleErrors(message.data);
|
|
96
|
-
break;
|
|
97
|
-
default:
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
function isUpdateAvailable() {
|
|
101
|
-
return mostRecentCompilationHash !== __webpack_hash__;
|
|
102
|
-
}
|
|
103
|
-
function canApplyUpdates() {
|
|
104
|
-
return module.hot.status() === "idle";
|
|
105
|
-
}
|
|
106
|
-
function tryApplyUpdates() {
|
|
107
|
-
var _result;
|
|
108
|
-
if (!module.hot) {
|
|
109
|
-
window.location.reload();
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
if (!isUpdateAvailable() || !canApplyUpdates()) {
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
function handleApplyUpdates(err, updatedModules) {
|
|
116
|
-
const wantsForcedReload = err || !updatedModules || hadRuntimeError;
|
|
117
|
-
if (wantsForcedReload) {
|
|
118
|
-
window.location.reload();
|
|
119
|
-
return;
|
|
81
|
+
function handleAvailableHash(hash) {
|
|
82
|
+
mostRecentCompilationHash = hash;
|
|
120
83
|
}
|
|
121
|
-
|
|
122
|
-
|
|
84
|
+
connection.onmessage = function(e) {
|
|
85
|
+
const message = JSON.parse(e.data);
|
|
86
|
+
switch (message.type) {
|
|
87
|
+
case "hash":
|
|
88
|
+
handleAvailableHash(message.data);
|
|
89
|
+
break;
|
|
90
|
+
case "still-ok":
|
|
91
|
+
case "ok":
|
|
92
|
+
handleSuccess();
|
|
93
|
+
break;
|
|
94
|
+
case "content-changed":
|
|
95
|
+
window.location.reload();
|
|
96
|
+
break;
|
|
97
|
+
case "warnings":
|
|
98
|
+
handleWarnings(message.data);
|
|
99
|
+
break;
|
|
100
|
+
case "errors":
|
|
101
|
+
handleErrors(message.data);
|
|
102
|
+
break;
|
|
103
|
+
default:
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
function isUpdateAvailable() {
|
|
107
|
+
return mostRecentCompilationHash !== __webpack_hash__;
|
|
108
|
+
}
|
|
109
|
+
function canApplyUpdates() {
|
|
110
|
+
return module.hot.status() === "idle";
|
|
111
|
+
}
|
|
112
|
+
function tryApplyUpdates() {
|
|
113
|
+
if (!module.hot) {
|
|
114
|
+
window.location.reload();
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
if (!isUpdateAvailable() || !canApplyUpdates()) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
function handleApplyUpdates(err, updatedModules) {
|
|
121
|
+
const wantsForcedReload = err || !updatedModules || hadRuntimeError;
|
|
122
|
+
if (wantsForcedReload) {
|
|
123
|
+
window.location.reload();
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
if (isUpdateAvailable()) {
|
|
127
|
+
tryApplyUpdates();
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
const result = module.hot.check(
|
|
131
|
+
/* autoApply */
|
|
132
|
+
true,
|
|
133
|
+
handleApplyUpdates
|
|
134
|
+
);
|
|
135
|
+
if (result === null || result === void 0 ? void 0 : result.then) {
|
|
136
|
+
result.then((updatedModules) => {
|
|
137
|
+
handleApplyUpdates(null, updatedModules);
|
|
138
|
+
}, (err) => {
|
|
139
|
+
handleApplyUpdates(err, null);
|
|
140
|
+
});
|
|
141
|
+
}
|
|
123
142
|
}
|
|
124
143
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
true,
|
|
128
|
-
handleApplyUpdates
|
|
129
|
-
);
|
|
130
|
-
if ((_result = result) === null || _result === void 0 ? void 0 : _result.then) {
|
|
131
|
-
result.then((updatedModules) => {
|
|
132
|
-
handleApplyUpdates(null, updatedModules);
|
|
133
|
-
}, (err) => {
|
|
134
|
-
handleApplyUpdates(err, null);
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
}
|
|
144
|
+
});
|
|
145
|
+
export default require_hmr_client();
|
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
|
2
|
-
import { sep } from "path";
|
|
3
2
|
import { EventEmitter } from "events";
|
|
4
3
|
import SocketServer from "./socketServer";
|
|
5
4
|
const noop = () => {
|
|
6
5
|
};
|
|
7
6
|
function getHMRClientPath(client) {
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const port = ((_client3 = client) === null || _client3 === void 0 ? void 0 : _client3.port) ? `&port=${client.port}` : "";
|
|
7
|
+
const protocol = (client === null || client === void 0 ? void 0 : client.protocol) ? `&protocol=${client.protocol}` : "";
|
|
8
|
+
const host = (client === null || client === void 0 ? void 0 : client.host) ? `&host=${client.host}` : "";
|
|
9
|
+
const path = (client === null || client === void 0 ? void 0 : client.path) ? `&path=${client.path}` : "";
|
|
10
|
+
const port = (client === null || client === void 0 ? void 0 : client.port) ? `&port=${client.port}` : "";
|
|
13
11
|
const clientEntry = `${require.resolve("@modern-js/server/hmr-client")}?${host}${path}${port}${protocol}`;
|
|
14
|
-
return clientEntry
|
|
12
|
+
return clientEntry;
|
|
15
13
|
}
|
|
16
14
|
class DevMiddleware extends EventEmitter {
|
|
17
15
|
init(app) {
|
|
@@ -61,4 +59,6 @@ class DevMiddleware extends EventEmitter {
|
|
|
61
59
|
}
|
|
62
60
|
}
|
|
63
61
|
}
|
|
64
|
-
export {
|
|
62
|
+
export {
|
|
63
|
+
DevMiddleware as default
|
|
64
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { chalk, getPackageManager, logger } from "@modern-js/utils";
|
|
2
|
-
|
|
2
|
+
const genHttpsOptions = async (userOptions, pwd) => {
|
|
3
3
|
const httpsOptions = typeof userOptions === "boolean" ? {} : userOptions;
|
|
4
4
|
if (!httpsOptions.key || !httpsOptions.cert) {
|
|
5
5
|
let devcertPath;
|
|
@@ -25,3 +25,6 @@ export const genHttpsOptions = async (userOptions, pwd) => {
|
|
|
25
25
|
}
|
|
26
26
|
return httpsOptions;
|
|
27
27
|
};
|
|
28
|
+
export {
|
|
29
|
+
genHttpsOptions
|
|
30
|
+
};
|
|
@@ -25,7 +25,7 @@ const allowTypes = [
|
|
|
25
25
|
"object",
|
|
26
26
|
"function"
|
|
27
27
|
];
|
|
28
|
-
|
|
28
|
+
var getMockData_default = (mockConfig) => Object.keys(mockConfig).reduce((acc, key) => {
|
|
29
29
|
const handler = mockConfig[key];
|
|
30
30
|
const type = typeof handler;
|
|
31
31
|
if (!allowTypes.includes(type)) {
|
|
@@ -60,7 +60,7 @@ const parseKey = (key) => {
|
|
|
60
60
|
path: key
|
|
61
61
|
};
|
|
62
62
|
};
|
|
63
|
-
|
|
63
|
+
const getMatched = (context, mockApiList) => {
|
|
64
64
|
const { path: targetPathname, method: targetMethod } = context;
|
|
65
65
|
const matched = mockApiList.find((mockApi) => {
|
|
66
66
|
const { method, path: pathname } = mockApi;
|
|
@@ -74,3 +74,7 @@ export const getMatched = (context, mockApiList) => {
|
|
|
74
74
|
});
|
|
75
75
|
return matched;
|
|
76
76
|
};
|
|
77
|
+
export {
|
|
78
|
+
getMockData_default as default,
|
|
79
|
+
getMatched
|
|
80
|
+
};
|
|
@@ -2,8 +2,7 @@ import path from "path";
|
|
|
2
2
|
import { compatRequire, fs } from "@modern-js/utils";
|
|
3
3
|
import { AGGRED_DIR } from "@modern-js/prod-server";
|
|
4
4
|
import getMockData, { getMatched } from "./getMockData";
|
|
5
|
-
|
|
6
|
-
var _config;
|
|
5
|
+
const createMockHandler = ({ pwd }) => {
|
|
7
6
|
const exts = [
|
|
8
7
|
".ts",
|
|
9
8
|
".js"
|
|
@@ -21,7 +20,7 @@ export const createMockHandler = ({ pwd }) => {
|
|
|
21
20
|
}
|
|
22
21
|
const mod = compatRequire(filepath, false);
|
|
23
22
|
const { default: mockModule = mod, config } = mod;
|
|
24
|
-
if ((
|
|
23
|
+
if ((config === null || config === void 0 ? void 0 : config.enable) === false) {
|
|
25
24
|
return null;
|
|
26
25
|
}
|
|
27
26
|
if (!mockModule) {
|
|
@@ -32,8 +31,7 @@ export const createMockHandler = ({ pwd }) => {
|
|
|
32
31
|
return null;
|
|
33
32
|
}
|
|
34
33
|
return async (context, next) => {
|
|
35
|
-
|
|
36
|
-
if (typeof ((_config2 = config) === null || _config2 === void 0 ? void 0 : _config2.enable) === "function") {
|
|
34
|
+
if (typeof (config === null || config === void 0 ? void 0 : config.enable) === "function") {
|
|
37
35
|
const enableMock = config.enable(context.req, context.res);
|
|
38
36
|
if (!enableMock) {
|
|
39
37
|
return next();
|
|
@@ -48,3 +46,6 @@ export const createMockHandler = ({ pwd }) => {
|
|
|
48
46
|
return matched.handler(context, next);
|
|
49
47
|
};
|
|
50
48
|
};
|
|
49
|
+
export {
|
|
50
|
+
createMockHandler
|
|
51
|
+
};
|
|
@@ -12,7 +12,7 @@ const checkDep = (depName, paths) => {
|
|
|
12
12
|
}
|
|
13
13
|
return Boolean(packagePath);
|
|
14
14
|
};
|
|
15
|
-
|
|
15
|
+
const enableRegister = (projectRoot, config) => {
|
|
16
16
|
const registerDirs = [
|
|
17
17
|
"./api",
|
|
18
18
|
"./server",
|
|
@@ -107,3 +107,6 @@ export const enableRegister = (projectRoot, config) => {
|
|
|
107
107
|
});
|
|
108
108
|
}
|
|
109
109
|
};
|
|
110
|
+
export {
|
|
111
|
+
enableRegister
|
|
112
|
+
};
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
|
2
2
|
import minimatch from "minimatch";
|
|
3
|
-
|
|
3
|
+
const defaultIgnores = [
|
|
4
4
|
"**/coverage/**",
|
|
5
5
|
"**/node_modules/**",
|
|
6
6
|
"**/.*/**",
|
|
7
7
|
"**/*.d.ts",
|
|
8
8
|
"**/*.log"
|
|
9
9
|
];
|
|
10
|
-
|
|
10
|
+
class DependencyTree {
|
|
11
11
|
getNode(path) {
|
|
12
12
|
return this.tree.get(path);
|
|
13
13
|
}
|
|
@@ -64,3 +64,7 @@ export class DependencyTree {
|
|
|
64
64
|
];
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
|
+
export {
|
|
68
|
+
DependencyTree,
|
|
69
|
+
defaultIgnores
|
|
70
|
+
};
|
|
@@ -3,12 +3,12 @@ import path from "path";
|
|
|
3
3
|
import { fs, chokidar } from "@modern-js/utils";
|
|
4
4
|
import { DependencyTree } from "./dependencyTree";
|
|
5
5
|
import { StatsCache } from "./statsCache";
|
|
6
|
-
|
|
6
|
+
const defaultWatchOptions = {
|
|
7
7
|
// 初始化的时候不触发 add、addDir 事件
|
|
8
8
|
ignoreInitial: true,
|
|
9
9
|
ignored: /api\/typings\/.*/
|
|
10
10
|
};
|
|
11
|
-
|
|
11
|
+
const getWatchedFiles = (watcher) => {
|
|
12
12
|
const watched = watcher.getWatched();
|
|
13
13
|
const files = [];
|
|
14
14
|
Object.keys(watched).forEach((dir) => {
|
|
@@ -18,7 +18,7 @@ export const getWatchedFiles = (watcher) => {
|
|
|
18
18
|
});
|
|
19
19
|
return files;
|
|
20
20
|
};
|
|
21
|
-
|
|
21
|
+
const mergeWatchOptions = (options) => {
|
|
22
22
|
const watchOptions = {
|
|
23
23
|
...options
|
|
24
24
|
};
|
|
@@ -94,4 +94,9 @@ class Watcher {
|
|
|
94
94
|
_define_property(this, "watcher", void 0);
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
|
-
export {
|
|
97
|
+
export {
|
|
98
|
+
Watcher as default,
|
|
99
|
+
defaultWatchOptions,
|
|
100
|
+
getWatchedFiles,
|
|
101
|
+
mergeWatchOptions
|
|
102
|
+
};
|