@modern-js/server 2.0.0-beta.4 → 2.0.0-beta.7
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/CHANGELOG.md +99 -0
- package/dist/js/modern/dev-tools/dev-middleware/hmr-client/index.js +2 -2
- package/dist/js/modern/dev-tools/dev-middleware/index.js +22 -52
- package/dist/js/modern/dev-tools/https/index.js +19 -2
- package/dist/js/modern/index.js +1 -1
- package/dist/js/modern/server/dev-server.js +1 -2
- package/dist/js/node/constants.js +7 -3
- package/dist/js/node/dev-tools/dev-middleware/hmr-client/createSocketUrl.js +8 -3
- package/dist/js/node/dev-tools/dev-middleware/hmr-client/index.js +2 -2
- package/dist/js/node/dev-tools/dev-middleware/index.js +45 -75
- package/dist/js/node/dev-tools/dev-middleware/socket-server.js +5 -3
- package/dist/js/node/dev-tools/https/index.js +28 -13
- package/dist/js/node/dev-tools/mock/getMockData.js +29 -27
- package/dist/js/node/dev-tools/mock/index.js +13 -9
- package/dist/js/node/dev-tools/register/index.js +24 -22
- package/dist/js/node/dev-tools/watcher/dependency-tree.js +8 -3
- package/dist/js/node/dev-tools/watcher/index.js +23 -19
- package/dist/js/node/dev-tools/watcher/stats-cache.js +7 -3
- package/dist/js/node/index.js +8 -4
- package/dist/js/node/server/dev-server.js +39 -54
- package/dist/js/node/server/index.js +7 -3
- package/dist/js/node/types.js +15 -0
- package/dist/js/treeshaking/dev-tools/dev-middleware/hmr-client/index.js +156 -156
- package/dist/js/treeshaking/dev-tools/dev-middleware/index.js +23 -65
- package/dist/js/treeshaking/dev-tools/https/index.js +39 -7
- package/dist/js/treeshaking/index.js +1 -1
- package/dist/js/treeshaking/server/dev-server.js +1 -2
- package/dist/types/dev-tools/dev-middleware/index.d.ts +1 -8
- package/dist/types/dev-tools/https/index.d.ts +1 -1
- package/dist/types/types.d.ts +22 -5
- package/package.json +13 -10
- package/dist/js/modern/dev-tools/dev-middleware/dev-server-plugin.js +0 -32
- package/dist/js/node/dev-tools/dev-middleware/dev-server-plugin.js +0 -57
- package/dist/js/treeshaking/dev-tools/dev-middleware/dev-server-plugin.js +0 -74
- package/dist/types/dev-tools/dev-middleware/dev-server-plugin.d.ts +0 -8
- package/temp-fix-hmr.js +0 -483
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,104 @@
|
|
|
1
1
|
# @modern-js/server
|
|
2
2
|
|
|
3
|
+
## 2.0.0-beta.7
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- dda38c9c3e: chore: v2
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [c9e800d39a]
|
|
12
|
+
- Updated dependencies [edd1cfb1af]
|
|
13
|
+
- Updated dependencies [6bda14ed71]
|
|
14
|
+
- Updated dependencies [dda38c9c3e]
|
|
15
|
+
- Updated dependencies [8b8e1bb571]
|
|
16
|
+
- Updated dependencies [bbe4c4ab64]
|
|
17
|
+
- @modern-js/prod-server@2.0.0-beta.7
|
|
18
|
+
- @modern-js/utils@2.0.0-beta.7
|
|
19
|
+
- @modern-js/types@2.0.0-beta.7
|
|
20
|
+
- @modern-js/server-utils@2.0.0-beta.7
|
|
21
|
+
|
|
22
|
+
## 2.0.0-beta.6
|
|
23
|
+
|
|
24
|
+
### Major Changes
|
|
25
|
+
|
|
26
|
+
- dda38c9c3e: chore: v2
|
|
27
|
+
|
|
28
|
+
### Minor Changes
|
|
29
|
+
|
|
30
|
+
- b710adb843: feat: extract the data loader
|
|
31
|
+
feat: 提取 data loader
|
|
32
|
+
|
|
33
|
+
### Patch Changes
|
|
34
|
+
|
|
35
|
+
- 7879e8f711: refactor: remove enableModernMode config
|
|
36
|
+
|
|
37
|
+
refactor: 不再支持 enableModernMode 配置项
|
|
38
|
+
|
|
39
|
+
- d4e8e6fb90: fix: modernjs dev server can't start normaly
|
|
40
|
+
fix: modernjs dev 服务端不能正常启动
|
|
41
|
+
- 15bf09d9c8: feat: support completely custom server, export render() api for render single page
|
|
42
|
+
feat: 支持完全自定义 Server,导出 render() 方法用来渲染单个页面
|
|
43
|
+
- 61f21d1e77: fix: ignore the entire distPath for pia ssr bundle
|
|
44
|
+
fix: dist 目录的产物不应该被 ts-node 编译
|
|
45
|
+
- 4f277fe288: fix(server): remove peer dependencies warning
|
|
46
|
+
|
|
47
|
+
fix(server): 修复 peer dependencies 出现 warning 提示的问题
|
|
48
|
+
|
|
49
|
+
- cce8ecee2d: fix: handle some `TODO` & `FIXME`, change some tests
|
|
50
|
+
fix: 处理一些 `TODO` 和 `FIXME`, 修改了一些 tests
|
|
51
|
+
- ea7cf06257: chore: bump webpack/babel-loader/postcss-loader/tsconfig-paths
|
|
52
|
+
|
|
53
|
+
chore: 升级 webpack/babel-loader/postcss-loader/tsconfig-paths 版本
|
|
54
|
+
|
|
55
|
+
- ebbeed1ece: chore: dev server default cross origin
|
|
56
|
+
chore: 开发环境 Server 默认跨域
|
|
57
|
+
- 14b712da84: fix: use consistent alias type and default value across packages
|
|
58
|
+
|
|
59
|
+
fix: 在各个包中使用一致的 alias 类型定义和默认值
|
|
60
|
+
|
|
61
|
+
- Updated dependencies [9b915e0c10]
|
|
62
|
+
- Updated dependencies [7879e8f711]
|
|
63
|
+
- Updated dependencies [c9e800d39a]
|
|
64
|
+
- Updated dependencies [d4e8e6fb90]
|
|
65
|
+
- Updated dependencies [d032d49e09]
|
|
66
|
+
- Updated dependencies [6aca875011]
|
|
67
|
+
- Updated dependencies [15bf09d9c8]
|
|
68
|
+
- Updated dependencies [2e6031955e]
|
|
69
|
+
- Updated dependencies [7b7d12cf8f]
|
|
70
|
+
- Updated dependencies [7efeed4]
|
|
71
|
+
- Updated dependencies [92f0eade39]
|
|
72
|
+
- Updated dependencies [edd1cfb1af]
|
|
73
|
+
- Updated dependencies [cc971eabfc]
|
|
74
|
+
- Updated dependencies [5b9049f2e9]
|
|
75
|
+
- Updated dependencies [6bda14ed71]
|
|
76
|
+
- Updated dependencies [a8642da58f]
|
|
77
|
+
- Updated dependencies [92004d1906]
|
|
78
|
+
- Updated dependencies [b8bbe036c7]
|
|
79
|
+
- Updated dependencies [40ed5874c6]
|
|
80
|
+
- Updated dependencies [87c1ff86b9]
|
|
81
|
+
- Updated dependencies [c2bb0f1745]
|
|
82
|
+
- Updated dependencies [d5a31df781]
|
|
83
|
+
- Updated dependencies [dda38c9c3e]
|
|
84
|
+
- Updated dependencies [102d32e4ba]
|
|
85
|
+
- Updated dependencies [8b8e1bb571]
|
|
86
|
+
- Updated dependencies [3bbea92b2a]
|
|
87
|
+
- Updated dependencies [73cd29dd9f]
|
|
88
|
+
- Updated dependencies [b710adb843]
|
|
89
|
+
- Updated dependencies [cce8ecee2d]
|
|
90
|
+
- Updated dependencies [18aaf42249]
|
|
91
|
+
- Updated dependencies [ea7cf06257]
|
|
92
|
+
- Updated dependencies [bbe4c4ab64]
|
|
93
|
+
- Updated dependencies [e4558a0bc4]
|
|
94
|
+
- Updated dependencies [abf3421a75]
|
|
95
|
+
- Updated dependencies [543be9558e]
|
|
96
|
+
- Updated dependencies [14b712da84]
|
|
97
|
+
- @modern-js/server-utils@2.0.0-beta.6
|
|
98
|
+
- @modern-js/prod-server@2.0.0-beta.6
|
|
99
|
+
- @modern-js/types@2.0.0-beta.6
|
|
100
|
+
- @modern-js/utils@2.0.0-beta.6
|
|
101
|
+
|
|
3
102
|
## 2.0.0-beta.4
|
|
4
103
|
|
|
5
104
|
### Major Changes
|
|
@@ -13,7 +13,7 @@ var require_hmr_client = __commonJS({
|
|
|
13
13
|
connection.onclose = function() {
|
|
14
14
|
if (typeof console !== "undefined" && typeof console.info === "function") {
|
|
15
15
|
console.info(
|
|
16
|
-
"The development server has disconnected
|
|
16
|
+
"The development server has disconnected.\nRefresh the page if necessary."
|
|
17
17
|
);
|
|
18
18
|
}
|
|
19
19
|
};
|
|
@@ -50,7 +50,7 @@ var require_hmr_client = __commonJS({
|
|
|
50
50
|
for (let i = 0; i < formatted.warnings.length; i++) {
|
|
51
51
|
if (i === 5) {
|
|
52
52
|
console.warn(
|
|
53
|
-
"There were more warnings in other files
|
|
53
|
+
"There were more warnings in other files.\nYou can find a complete log in the terminal."
|
|
54
54
|
);
|
|
55
55
|
break;
|
|
56
56
|
}
|
|
@@ -35,20 +35,22 @@ var __async = (__this, __arguments, generator) => {
|
|
|
35
35
|
});
|
|
36
36
|
};
|
|
37
37
|
import { EventEmitter } from "events";
|
|
38
|
-
import webpackDevMiddleware from "@modern-js/utils/webpack-dev-middleware";
|
|
39
|
-
import DevServerPlugin from "./dev-server-plugin";
|
|
40
38
|
import SocketServer from "./socket-server";
|
|
41
39
|
const noop = () => {
|
|
42
40
|
};
|
|
41
|
+
function getHMRClientPath(client) {
|
|
42
|
+
const host = (client == null ? void 0 : client.host) ? `&host=${client.host}` : "";
|
|
43
|
+
const path = (client == null ? void 0 : client.path) ? `&path=${client.path}` : "";
|
|
44
|
+
const port = (client == null ? void 0 : client.port) ? `&port=${client.port}` : "";
|
|
45
|
+
const clientEntry = `${require.resolve("./hmr-client")}?${host}${path}${port}`;
|
|
46
|
+
return clientEntry;
|
|
47
|
+
}
|
|
43
48
|
class DevMiddleware extends EventEmitter {
|
|
44
|
-
constructor({
|
|
49
|
+
constructor({ dev, devMiddleware }) {
|
|
45
50
|
super();
|
|
46
|
-
this.compiler = compiler;
|
|
47
51
|
this.devOptions = dev;
|
|
48
52
|
this.socketServer = new SocketServer(dev);
|
|
49
|
-
if (
|
|
50
|
-
this.setupDevServerPlugin();
|
|
51
|
-
this.setupHooks();
|
|
53
|
+
if (devMiddleware) {
|
|
52
54
|
this.middleware = this.setupDevMiddleware(devMiddleware);
|
|
53
55
|
}
|
|
54
56
|
}
|
|
@@ -62,61 +64,29 @@ class DevMiddleware extends EventEmitter {
|
|
|
62
64
|
this.socketServer.close();
|
|
63
65
|
}));
|
|
64
66
|
}
|
|
65
|
-
setupDevServerPlugin() {
|
|
66
|
-
const { devOptions } = this;
|
|
67
|
-
if (this.compiler.compilers) {
|
|
68
|
-
this.compiler.compilers.forEach((target) => {
|
|
69
|
-
if (this.isClientCompiler(target)) {
|
|
70
|
-
new DevServerPlugin(devOptions).apply(target);
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
} else {
|
|
74
|
-
new DevServerPlugin(devOptions).apply(this.compiler);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
67
|
sockWrite(type, data) {
|
|
78
68
|
this.socketServer.sockWrite(type, data);
|
|
79
69
|
}
|
|
80
|
-
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
const { compile, invalid, done } = compiler.hooks;
|
|
89
|
-
compile.tap("modern-dev-server", invalidPlugin);
|
|
90
|
-
invalid.tap("modern-dev-server", invalidPlugin);
|
|
91
|
-
done.tap("modern-dev-server", (stats) => {
|
|
70
|
+
setupDevMiddleware(devMiddleware) {
|
|
71
|
+
const { devOptions } = this;
|
|
72
|
+
const callbacks = {
|
|
73
|
+
onInvalid: () => {
|
|
74
|
+
this.socketServer.sockWrite("invalid");
|
|
75
|
+
},
|
|
76
|
+
onDone: (stats) => {
|
|
92
77
|
this.socketServer.updateStats(stats);
|
|
93
78
|
this.emit("change", stats);
|
|
94
|
-
}
|
|
79
|
+
}
|
|
95
80
|
};
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
} else {
|
|
99
|
-
addHooks(this.compiler);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
setupDevMiddleware(devMiddleware = webpackDevMiddleware) {
|
|
103
|
-
const { devOptions } = this;
|
|
104
|
-
const middleware = devMiddleware(this.compiler, __spreadValues({
|
|
81
|
+
const enableHMR = this.devOptions.hot || this.devOptions.liveReload;
|
|
82
|
+
const middleware = devMiddleware(__spreadValues({
|
|
105
83
|
headers: devOptions.headers,
|
|
106
|
-
stats: false
|
|
84
|
+
stats: false,
|
|
85
|
+
callbacks,
|
|
86
|
+
hmrClientPath: enableHMR ? getHMRClientPath(devOptions.client) : void 0
|
|
107
87
|
}, devOptions.devMiddleware));
|
|
108
88
|
return middleware;
|
|
109
89
|
}
|
|
110
|
-
isClientCompiler(compiler) {
|
|
111
|
-
const { target } = compiler.options;
|
|
112
|
-
if (target) {
|
|
113
|
-
if (Array.isArray(target)) {
|
|
114
|
-
return !target.includes("node");
|
|
115
|
-
}
|
|
116
|
-
return target !== "node";
|
|
117
|
-
}
|
|
118
|
-
return compiler.name === "client";
|
|
119
|
-
}
|
|
120
90
|
}
|
|
121
91
|
export {
|
|
122
92
|
DevMiddleware as default
|
|
@@ -18,10 +18,27 @@ var __async = (__this, __arguments, generator) => {
|
|
|
18
18
|
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
19
|
});
|
|
20
20
|
};
|
|
21
|
-
import
|
|
22
|
-
const genHttpsOptions = (userOptions) => __async(void 0, null, function* () {
|
|
21
|
+
import { chalk, getPackageManager, logger } from "@modern-js/utils";
|
|
22
|
+
const genHttpsOptions = (userOptions, pwd) => __async(void 0, null, function* () {
|
|
23
23
|
const httpsOptions = typeof userOptions === "boolean" ? {} : userOptions;
|
|
24
24
|
if (!httpsOptions.key || !httpsOptions.cert) {
|
|
25
|
+
let devcertPath;
|
|
26
|
+
try {
|
|
27
|
+
devcertPath = require.resolve("devcert", { paths: [pwd, __dirname] });
|
|
28
|
+
} catch (err) {
|
|
29
|
+
const packageManager = yield getPackageManager(pwd);
|
|
30
|
+
const command = chalk.yellow.bold(
|
|
31
|
+
`${packageManager} install devcert@1.2.2 -D`
|
|
32
|
+
);
|
|
33
|
+
logger.error(
|
|
34
|
+
`You have enabled "dev.https" option, but the "devcert" package is not installed.`
|
|
35
|
+
);
|
|
36
|
+
logger.error(
|
|
37
|
+
`Please run ${command} to install manually, otherwise the https can not work.`
|
|
38
|
+
);
|
|
39
|
+
throw new Error('[https] "devcert" is not found.');
|
|
40
|
+
}
|
|
41
|
+
const devcert = require(devcertPath);
|
|
25
42
|
const selfsign = yield devcert.certificateFor(["localhost"]);
|
|
26
43
|
return selfsign;
|
|
27
44
|
}
|
package/dist/js/modern/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DevServer as Server } from "./server";
|
|
2
2
|
var src_default = (options) => {
|
|
3
3
|
if (options == null) {
|
|
4
|
-
throw new Error("can not start
|
|
4
|
+
throw new Error("can not start server without options");
|
|
5
5
|
}
|
|
6
6
|
const server = new Server(options);
|
|
7
7
|
return server.init();
|
|
@@ -68,7 +68,6 @@ class ModernDevServer extends ModernServer {
|
|
|
68
68
|
this.dev = this.getDevOptions(options);
|
|
69
69
|
this.devMiddleware = new DevMiddleware({
|
|
70
70
|
dev: this.dev,
|
|
71
|
-
compiler: options.compiler,
|
|
72
71
|
devMiddleware: options.devMiddleware
|
|
73
72
|
});
|
|
74
73
|
enableRegister(this.pwd, this.conf);
|
|
@@ -195,7 +194,7 @@ class ModernDevServer extends ModernServer {
|
|
|
195
194
|
const devHttpsOption = typeof dev === "object" && dev.https;
|
|
196
195
|
if (devHttpsOption) {
|
|
197
196
|
const { genHttpsOptions } = require("../dev-tools/https");
|
|
198
|
-
const httpsOptions = yield genHttpsOptions(devHttpsOption);
|
|
197
|
+
const httpsOptions = yield genHttpsOptions(devHttpsOption, this.pwd);
|
|
199
198
|
return createHttpsServer(httpsOptions, handler);
|
|
200
199
|
} else {
|
|
201
200
|
return createServer(handler);
|
|
@@ -15,11 +15,11 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
15
|
return to;
|
|
16
16
|
};
|
|
17
17
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var
|
|
19
|
-
__export(
|
|
18
|
+
var constants_exports = {};
|
|
19
|
+
__export(constants_exports, {
|
|
20
20
|
getDefaultDevOptions: () => getDefaultDevOptions
|
|
21
21
|
});
|
|
22
|
-
module.exports = __toCommonJS(
|
|
22
|
+
module.exports = __toCommonJS(constants_exports);
|
|
23
23
|
var import_utils = require("@modern-js/utils");
|
|
24
24
|
const getDefaultDevOptions = () => {
|
|
25
25
|
const network = (0, import_utils.getIpv4Interfaces)().find((item) => !item.internal);
|
|
@@ -36,3 +36,7 @@ const getDefaultDevOptions = () => {
|
|
|
36
36
|
liveReload: true
|
|
37
37
|
};
|
|
38
38
|
};
|
|
39
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
40
|
+
0 && (module.exports = {
|
|
41
|
+
getDefaultDevOptions
|
|
42
|
+
});
|
|
@@ -15,12 +15,12 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
15
|
return to;
|
|
16
16
|
};
|
|
17
17
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var
|
|
19
|
-
__export(
|
|
18
|
+
var createSocketUrl_exports = {};
|
|
19
|
+
__export(createSocketUrl_exports, {
|
|
20
20
|
createSocketUrl: () => createSocketUrl,
|
|
21
21
|
formatURL: () => formatURL
|
|
22
22
|
});
|
|
23
|
-
module.exports = __toCommonJS(
|
|
23
|
+
module.exports = __toCommonJS(createSocketUrl_exports);
|
|
24
24
|
var import_constants = require("@modern-js/utils/constants");
|
|
25
25
|
function createSocketUrl(resourceQuery) {
|
|
26
26
|
const searchParams = resourceQuery.substr(1).split("&");
|
|
@@ -58,3 +58,8 @@ function getSocketUrl(urlParts, location) {
|
|
|
58
58
|
pathname: path || import_constants.HMR_SOCK_PATH
|
|
59
59
|
});
|
|
60
60
|
}
|
|
61
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
62
|
+
0 && (module.exports = {
|
|
63
|
+
createSocketUrl,
|
|
64
|
+
formatURL
|
|
65
|
+
});
|
|
@@ -25,7 +25,7 @@ const connection = new WebSocket(socketUrl);
|
|
|
25
25
|
connection.onclose = function() {
|
|
26
26
|
if (typeof console !== "undefined" && typeof console.info === "function") {
|
|
27
27
|
console.info(
|
|
28
|
-
"The development server has disconnected
|
|
28
|
+
"The development server has disconnected.\nRefresh the page if necessary."
|
|
29
29
|
);
|
|
30
30
|
}
|
|
31
31
|
};
|
|
@@ -62,7 +62,7 @@ function handleWarnings(warnings) {
|
|
|
62
62
|
for (let i = 0; i < formatted.warnings.length; i++) {
|
|
63
63
|
if (i === 5) {
|
|
64
64
|
console.warn(
|
|
65
|
-
"There were more warnings in other files
|
|
65
|
+
"There were more warnings in other files.\nYou can find a complete log in the terminal."
|
|
66
66
|
);
|
|
67
67
|
break;
|
|
68
68
|
}
|
|
@@ -2,8 +2,22 @@ var __create = Object.create;
|
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
6
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
9
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
|
+
var __spreadValues = (a, b) => {
|
|
11
|
+
for (var prop in b || (b = {}))
|
|
12
|
+
if (__hasOwnProp.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
if (__getOwnPropSymbols)
|
|
15
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
16
|
+
if (__propIsEnum.call(b, prop))
|
|
17
|
+
__defNormalProp(a, prop, b[prop]);
|
|
18
|
+
}
|
|
19
|
+
return a;
|
|
20
|
+
};
|
|
7
21
|
var __export = (target, all) => {
|
|
8
22
|
for (var name in all)
|
|
9
23
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -21,31 +35,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
21
35
|
mod
|
|
22
36
|
));
|
|
23
37
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
-
var stdin_exports = {};
|
|
25
|
-
__export(stdin_exports, {
|
|
26
|
-
default: () => DevMiddleware
|
|
27
|
-
});
|
|
28
|
-
module.exports = __toCommonJS(stdin_exports);
|
|
29
|
-
var import_events = require("events");
|
|
30
|
-
var import_webpack_dev_middleware = __toESM(require("@modern-js/utils/webpack-dev-middleware"));
|
|
31
|
-
var import_dev_server_plugin = __toESM(require("./dev-server-plugin"));
|
|
32
|
-
var import_socket_server = __toESM(require("./socket-server"));
|
|
33
|
-
var __defProp2 = Object.defineProperty;
|
|
34
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
35
|
-
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
|
36
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
37
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
38
|
-
var __spreadValues = (a, b) => {
|
|
39
|
-
for (var prop in b || (b = {}))
|
|
40
|
-
if (__hasOwnProp2.call(b, prop))
|
|
41
|
-
__defNormalProp(a, prop, b[prop]);
|
|
42
|
-
if (__getOwnPropSymbols)
|
|
43
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
44
|
-
if (__propIsEnum.call(b, prop))
|
|
45
|
-
__defNormalProp(a, prop, b[prop]);
|
|
46
|
-
}
|
|
47
|
-
return a;
|
|
48
|
-
};
|
|
49
38
|
var __async = (__this, __arguments, generator) => {
|
|
50
39
|
return new Promise((resolve, reject) => {
|
|
51
40
|
var fulfilled = (value) => {
|
|
@@ -66,17 +55,28 @@ var __async = (__this, __arguments, generator) => {
|
|
|
66
55
|
step((generator = generator.apply(__this, __arguments)).next());
|
|
67
56
|
});
|
|
68
57
|
};
|
|
58
|
+
var dev_middleware_exports = {};
|
|
59
|
+
__export(dev_middleware_exports, {
|
|
60
|
+
default: () => DevMiddleware
|
|
61
|
+
});
|
|
62
|
+
module.exports = __toCommonJS(dev_middleware_exports);
|
|
63
|
+
var import_events = require("events");
|
|
64
|
+
var import_socket_server = __toESM(require("./socket-server"));
|
|
69
65
|
const noop = () => {
|
|
70
66
|
};
|
|
67
|
+
function getHMRClientPath(client) {
|
|
68
|
+
const host = (client == null ? void 0 : client.host) ? `&host=${client.host}` : "";
|
|
69
|
+
const path = (client == null ? void 0 : client.path) ? `&path=${client.path}` : "";
|
|
70
|
+
const port = (client == null ? void 0 : client.port) ? `&port=${client.port}` : "";
|
|
71
|
+
const clientEntry = `${require.resolve("./hmr-client")}?${host}${path}${port}`;
|
|
72
|
+
return clientEntry;
|
|
73
|
+
}
|
|
71
74
|
class DevMiddleware extends import_events.EventEmitter {
|
|
72
|
-
constructor({
|
|
75
|
+
constructor({ dev, devMiddleware }) {
|
|
73
76
|
super();
|
|
74
|
-
this.compiler = compiler;
|
|
75
77
|
this.devOptions = dev;
|
|
76
78
|
this.socketServer = new import_socket_server.default(dev);
|
|
77
|
-
if (
|
|
78
|
-
this.setupDevServerPlugin();
|
|
79
|
-
this.setupHooks();
|
|
79
|
+
if (devMiddleware) {
|
|
80
80
|
this.middleware = this.setupDevMiddleware(devMiddleware);
|
|
81
81
|
}
|
|
82
82
|
}
|
|
@@ -90,59 +90,29 @@ class DevMiddleware extends import_events.EventEmitter {
|
|
|
90
90
|
this.socketServer.close();
|
|
91
91
|
}));
|
|
92
92
|
}
|
|
93
|
-
setupDevServerPlugin() {
|
|
94
|
-
const { devOptions } = this;
|
|
95
|
-
if (this.compiler.compilers) {
|
|
96
|
-
this.compiler.compilers.forEach((target) => {
|
|
97
|
-
if (this.isClientCompiler(target)) {
|
|
98
|
-
new import_dev_server_plugin.default(devOptions).apply(target);
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
} else {
|
|
102
|
-
new import_dev_server_plugin.default(devOptions).apply(this.compiler);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
93
|
sockWrite(type, data) {
|
|
106
94
|
this.socketServer.sockWrite(type, data);
|
|
107
95
|
}
|
|
108
|
-
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
const { compile, invalid, done } = compiler.hooks;
|
|
117
|
-
compile.tap("modern-dev-server", invalidPlugin);
|
|
118
|
-
invalid.tap("modern-dev-server", invalidPlugin);
|
|
119
|
-
done.tap("modern-dev-server", (stats) => {
|
|
96
|
+
setupDevMiddleware(devMiddleware) {
|
|
97
|
+
const { devOptions } = this;
|
|
98
|
+
const callbacks = {
|
|
99
|
+
onInvalid: () => {
|
|
100
|
+
this.socketServer.sockWrite("invalid");
|
|
101
|
+
},
|
|
102
|
+
onDone: (stats) => {
|
|
120
103
|
this.socketServer.updateStats(stats);
|
|
121
104
|
this.emit("change", stats);
|
|
122
|
-
}
|
|
105
|
+
}
|
|
123
106
|
};
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
} else {
|
|
127
|
-
addHooks(this.compiler);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
setupDevMiddleware(devMiddleware = import_webpack_dev_middleware.default) {
|
|
131
|
-
const { devOptions } = this;
|
|
132
|
-
const middleware = devMiddleware(this.compiler, __spreadValues({
|
|
107
|
+
const enableHMR = this.devOptions.hot || this.devOptions.liveReload;
|
|
108
|
+
const middleware = devMiddleware(__spreadValues({
|
|
133
109
|
headers: devOptions.headers,
|
|
134
|
-
stats: false
|
|
110
|
+
stats: false,
|
|
111
|
+
callbacks,
|
|
112
|
+
hmrClientPath: enableHMR ? getHMRClientPath(devOptions.client) : void 0
|
|
135
113
|
}, devOptions.devMiddleware));
|
|
136
114
|
return middleware;
|
|
137
115
|
}
|
|
138
|
-
isClientCompiler(compiler) {
|
|
139
|
-
const { target } = compiler.options;
|
|
140
|
-
if (target) {
|
|
141
|
-
if (Array.isArray(target)) {
|
|
142
|
-
return !target.includes("node");
|
|
143
|
-
}
|
|
144
|
-
return target !== "node";
|
|
145
|
-
}
|
|
146
|
-
return compiler.name === "client";
|
|
147
|
-
}
|
|
148
116
|
}
|
|
117
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
118
|
+
0 && (module.exports = {});
|
|
@@ -21,11 +21,11 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
21
21
|
mod
|
|
22
22
|
));
|
|
23
23
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
-
var
|
|
25
|
-
__export(
|
|
24
|
+
var socket_server_exports = {};
|
|
25
|
+
__export(socket_server_exports, {
|
|
26
26
|
default: () => SocketServer
|
|
27
27
|
});
|
|
28
|
-
module.exports = __toCommonJS(
|
|
28
|
+
module.exports = __toCommonJS(socket_server_exports);
|
|
29
29
|
var import_ws = __toESM(require("ws"));
|
|
30
30
|
var import_utils = require("@modern-js/utils");
|
|
31
31
|
class SocketServer {
|
|
@@ -155,3 +155,5 @@ class SocketServer {
|
|
|
155
155
|
connection.send(message);
|
|
156
156
|
}
|
|
157
157
|
}
|
|
158
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
159
|
+
0 && (module.exports = {});
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
1
|
var __defProp = Object.defineProperty;
|
|
3
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
5
|
var __export = (target, all) => {
|
|
8
6
|
for (var name in all)
|
|
@@ -16,17 +14,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
14
|
}
|
|
17
15
|
return to;
|
|
18
16
|
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
-
mod
|
|
22
|
-
));
|
|
23
17
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
-
var stdin_exports = {};
|
|
25
|
-
__export(stdin_exports, {
|
|
26
|
-
genHttpsOptions: () => genHttpsOptions
|
|
27
|
-
});
|
|
28
|
-
module.exports = __toCommonJS(stdin_exports);
|
|
29
|
-
var devcert = __toESM(require("devcert"));
|
|
30
18
|
var __async = (__this, __arguments, generator) => {
|
|
31
19
|
return new Promise((resolve, reject) => {
|
|
32
20
|
var fulfilled = (value) => {
|
|
@@ -47,11 +35,38 @@ var __async = (__this, __arguments, generator) => {
|
|
|
47
35
|
step((generator = generator.apply(__this, __arguments)).next());
|
|
48
36
|
});
|
|
49
37
|
};
|
|
50
|
-
|
|
38
|
+
var https_exports = {};
|
|
39
|
+
__export(https_exports, {
|
|
40
|
+
genHttpsOptions: () => genHttpsOptions
|
|
41
|
+
});
|
|
42
|
+
module.exports = __toCommonJS(https_exports);
|
|
43
|
+
var import_utils = require("@modern-js/utils");
|
|
44
|
+
const genHttpsOptions = (userOptions, pwd) => __async(void 0, null, function* () {
|
|
51
45
|
const httpsOptions = typeof userOptions === "boolean" ? {} : userOptions;
|
|
52
46
|
if (!httpsOptions.key || !httpsOptions.cert) {
|
|
47
|
+
let devcertPath;
|
|
48
|
+
try {
|
|
49
|
+
devcertPath = require.resolve("devcert", { paths: [pwd, __dirname] });
|
|
50
|
+
} catch (err) {
|
|
51
|
+
const packageManager = yield (0, import_utils.getPackageManager)(pwd);
|
|
52
|
+
const command = import_utils.chalk.yellow.bold(
|
|
53
|
+
`${packageManager} install devcert@1.2.2 -D`
|
|
54
|
+
);
|
|
55
|
+
import_utils.logger.error(
|
|
56
|
+
`You have enabled "dev.https" option, but the "devcert" package is not installed.`
|
|
57
|
+
);
|
|
58
|
+
import_utils.logger.error(
|
|
59
|
+
`Please run ${command} to install manually, otherwise the https can not work.`
|
|
60
|
+
);
|
|
61
|
+
throw new Error('[https] "devcert" is not found.');
|
|
62
|
+
}
|
|
63
|
+
const devcert = require(devcertPath);
|
|
53
64
|
const selfsign = yield devcert.certificateFor(["localhost"]);
|
|
54
65
|
return selfsign;
|
|
55
66
|
}
|
|
56
67
|
return httpsOptions;
|
|
57
68
|
});
|
|
69
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
70
|
+
0 && (module.exports = {
|
|
71
|
+
genHttpsOptions
|
|
72
|
+
});
|