@modern-js/server 2.0.0-beta.3 → 2.0.0-beta.6
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 +159 -0
- package/dist/js/modern/constants.js +10 -9
- package/dist/js/modern/dev-tools/dev-middleware/dev-server-plugin.js +14 -20
- package/dist/js/modern/dev-tools/dev-middleware/hmr-client/createSocketUrl.js +14 -19
- package/dist/js/modern/dev-tools/dev-middleware/hmr-client/index.js +134 -184
- package/dist/js/modern/dev-tools/dev-middleware/hmr-client/types.d.js +0 -0
- package/dist/js/modern/dev-tools/dev-middleware/index.js +65 -60
- package/dist/js/modern/dev-tools/dev-middleware/socket-server.js +33 -59
- package/dist/js/modern/dev-tools/https/global.d.js +0 -0
- package/dist/js/modern/dev-tools/https/index.js +28 -5
- package/dist/js/modern/dev-tools/mock/getMockData.js +71 -45
- package/dist/js/modern/dev-tools/mock/index.js +34 -15
- package/dist/js/modern/dev-tools/register/index.js +71 -54
- package/dist/js/modern/dev-tools/watcher/dependency-tree.js +25 -34
- package/dist/js/modern/dev-tools/watcher/index.js +51 -33
- package/dist/js/modern/dev-tools/watcher/stats-cache.js +13 -20
- package/dist/js/modern/index.js +7 -4
- package/dist/js/modern/server/dev-server.js +191 -215
- package/dist/js/modern/server/index.js +7 -4
- package/dist/js/node/constants.js +31 -14
- package/dist/js/node/dev-tools/dev-middleware/dev-server-plugin.js +38 -24
- package/dist/js/node/dev-tools/dev-middleware/hmr-client/createSocketUrl.js +36 -24
- package/dist/js/node/dev-tools/dev-middleware/hmr-client/index.js +56 -98
- package/dist/js/node/dev-tools/dev-middleware/hmr-client/types.d.js +0 -0
- package/dist/js/node/dev-tools/dev-middleware/index.js +94 -72
- package/dist/js/node/dev-tools/dev-middleware/socket-server.js +59 -66
- package/dist/js/node/dev-tools/https/global.d.js +0 -0
- package/dist/js/node/dev-tools/https/index.js +56 -13
- package/dist/js/node/dev-tools/mock/getMockData.js +90 -51
- package/dist/js/node/dev-tools/mock/index.js +66 -28
- package/dist/js/node/dev-tools/register/index.js +100 -64
- package/dist/js/node/dev-tools/watcher/dependency-tree.js +55 -43
- package/dist/js/node/dev-tools/watcher/index.js +83 -47
- package/dist/js/node/dev-tools/watcher/stats-cache.js +44 -30
- package/dist/js/node/index.js +29 -15
- package/dist/js/node/server/dev-server.js +220 -237
- package/dist/js/node/server/index.js +30 -11
- package/dist/js/node/types.js +15 -0
- package/dist/js/treeshaking/constants.js +21 -0
- package/dist/js/treeshaking/dev-tools/dev-middleware/dev-server-plugin.js +74 -0
- package/dist/js/treeshaking/dev-tools/dev-middleware/hmr-client/createSocketUrl.js +51 -0
- package/dist/js/treeshaking/dev-tools/dev-middleware/hmr-client/index.js +157 -0
- package/dist/js/treeshaking/dev-tools/dev-middleware/hmr-client/types.d.js +1 -0
- package/dist/js/treeshaking/dev-tools/dev-middleware/index.js +363 -0
- package/dist/js/treeshaking/dev-tools/dev-middleware/socket-server.js +209 -0
- package/dist/js/treeshaking/dev-tools/https/global.d.js +1 -0
- package/dist/js/treeshaking/dev-tools/https/index.js +161 -0
- package/dist/js/treeshaking/dev-tools/mock/getMockData.js +327 -0
- package/dist/js/treeshaking/dev-tools/mock/index.js +191 -0
- package/dist/js/treeshaking/dev-tools/register/index.js +153 -0
- package/dist/js/treeshaking/dev-tools/watcher/dependency-tree.js +150 -0
- package/dist/js/treeshaking/dev-tools/watcher/index.js +200 -0
- package/dist/js/treeshaking/dev-tools/watcher/stats-cache.js +128 -0
- package/dist/js/treeshaking/index.js +9 -0
- package/dist/js/treeshaking/server/dev-server.js +800 -0
- package/dist/js/treeshaking/server/index.js +92 -0
- package/dist/js/treeshaking/types.js +1 -0
- package/dist/types/dev-tools/mock/getMockData.d.ts +2 -0
- package/dist/types/dev-tools/watcher/dependency-tree.d.ts +2 -0
- package/dist/types/dev-tools/watcher/index.d.ts +1 -1
- package/dist/types/index.d.ts +2 -0
- package/package.json +15 -12
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,164 @@
|
|
|
1
1
|
# @modern-js/server
|
|
2
2
|
|
|
3
|
+
## 2.0.0-beta.6
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- dda38c9c3e: chore: v2
|
|
8
|
+
|
|
9
|
+
### Minor Changes
|
|
10
|
+
|
|
11
|
+
- b710adb843: feat: extract the data loader
|
|
12
|
+
feat: 提取 data loader
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- 7879e8f711: refactor: remove enableModernMode config
|
|
17
|
+
|
|
18
|
+
refactor: 不再支持 enableModernMode 配置项
|
|
19
|
+
|
|
20
|
+
- d4e8e6fb90: fix: modernjs dev server can't start normaly
|
|
21
|
+
fix: modernjs dev 服务端不能正常启动
|
|
22
|
+
- 15bf09d9c8: feat: support completely custom server, export render() api for render single page
|
|
23
|
+
feat: 支持完全自定义 Server,导出 render() 方法用来渲染单个页面
|
|
24
|
+
- 61f21d1e77: fix: ignore the entire distPath for pia ssr bundle
|
|
25
|
+
fix: dist 目录的产物不应该被 ts-node 编译
|
|
26
|
+
- 4f277fe288: fix(server): remove peer dependencies warning
|
|
27
|
+
|
|
28
|
+
fix(server): 修复 peer dependencies 出现 warning 提示的问题
|
|
29
|
+
|
|
30
|
+
- cce8ecee2d: fix: handle some `TODO` & `FIXME`, change some tests
|
|
31
|
+
fix: 处理一些 `TODO` 和 `FIXME`, 修改了一些 tests
|
|
32
|
+
- ea7cf06257: chore: bump webpack/babel-loader/postcss-loader/tsconfig-paths
|
|
33
|
+
|
|
34
|
+
chore: 升级 webpack/babel-loader/postcss-loader/tsconfig-paths 版本
|
|
35
|
+
|
|
36
|
+
- ebbeed1ece: chore: dev server default cross origin
|
|
37
|
+
chore: 开发环境 Server 默认跨域
|
|
38
|
+
- 14b712da84: fix: use consistent alias type and default value across packages
|
|
39
|
+
|
|
40
|
+
fix: 在各个包中使用一致的 alias 类型定义和默认值
|
|
41
|
+
|
|
42
|
+
- Updated dependencies [9b915e0c10]
|
|
43
|
+
- Updated dependencies [7879e8f711]
|
|
44
|
+
- Updated dependencies [c9e800d39a]
|
|
45
|
+
- Updated dependencies [d4e8e6fb90]
|
|
46
|
+
- Updated dependencies [d032d49e09]
|
|
47
|
+
- Updated dependencies [6aca875011]
|
|
48
|
+
- Updated dependencies [15bf09d9c8]
|
|
49
|
+
- Updated dependencies [2e6031955e]
|
|
50
|
+
- Updated dependencies [7b7d12cf8f]
|
|
51
|
+
- Updated dependencies [7efeed4]
|
|
52
|
+
- Updated dependencies [92f0eade39]
|
|
53
|
+
- Updated dependencies [edd1cfb1af]
|
|
54
|
+
- Updated dependencies [cc971eabfc]
|
|
55
|
+
- Updated dependencies [5b9049f2e9]
|
|
56
|
+
- Updated dependencies [6bda14ed71]
|
|
57
|
+
- Updated dependencies [a8642da58f]
|
|
58
|
+
- Updated dependencies [92004d1906]
|
|
59
|
+
- Updated dependencies [b8bbe036c7]
|
|
60
|
+
- Updated dependencies [40ed5874c6]
|
|
61
|
+
- Updated dependencies [87c1ff86b9]
|
|
62
|
+
- Updated dependencies [c2bb0f1745]
|
|
63
|
+
- Updated dependencies [d5a31df781]
|
|
64
|
+
- Updated dependencies [dda38c9c3e]
|
|
65
|
+
- Updated dependencies [102d32e4ba]
|
|
66
|
+
- Updated dependencies [8b8e1bb571]
|
|
67
|
+
- Updated dependencies [3bbea92b2a]
|
|
68
|
+
- Updated dependencies [73cd29dd9f]
|
|
69
|
+
- Updated dependencies [b710adb843]
|
|
70
|
+
- Updated dependencies [cce8ecee2d]
|
|
71
|
+
- Updated dependencies [18aaf42249]
|
|
72
|
+
- Updated dependencies [ea7cf06257]
|
|
73
|
+
- Updated dependencies [bbe4c4ab64]
|
|
74
|
+
- Updated dependencies [e4558a0bc4]
|
|
75
|
+
- Updated dependencies [abf3421a75]
|
|
76
|
+
- Updated dependencies [543be9558e]
|
|
77
|
+
- Updated dependencies [14b712da84]
|
|
78
|
+
- @modern-js/server-utils@2.0.0-beta.6
|
|
79
|
+
- @modern-js/prod-server@2.0.0-beta.6
|
|
80
|
+
- @modern-js/types@2.0.0-beta.6
|
|
81
|
+
- @modern-js/utils@2.0.0-beta.6
|
|
82
|
+
|
|
83
|
+
## 2.0.0-beta.4
|
|
84
|
+
|
|
85
|
+
### Major Changes
|
|
86
|
+
|
|
87
|
+
- dda38c9c3e: chore: v2
|
|
88
|
+
|
|
89
|
+
### Minor Changes
|
|
90
|
+
|
|
91
|
+
- b710adb843: feat: extract the data loader
|
|
92
|
+
feat: 提取 data loader
|
|
93
|
+
|
|
94
|
+
### Patch Changes
|
|
95
|
+
|
|
96
|
+
- 7879e8f: refactor: remove enableModernMode config
|
|
97
|
+
|
|
98
|
+
refactor: 不再支持 enableModernMode 配置项
|
|
99
|
+
|
|
100
|
+
- d4e8e6fb90: fix: modernjs dev server can't start normaly
|
|
101
|
+
fix: modernjs dev 服务端不能正常启动
|
|
102
|
+
- 15bf09d9c8: feat: support completely custom server, export render() api for render single page
|
|
103
|
+
feat: 支持完全自定义 Server,导出 render() 方法用来渲染单个页面
|
|
104
|
+
- 61f21d1e77: fix: ignore the entire distPath for pia ssr bundle
|
|
105
|
+
fix: dist 目录的产物不应该被 ts-node 编译
|
|
106
|
+
- 4f277fe: fix(server): remove peer dependencies warning
|
|
107
|
+
|
|
108
|
+
fix(server): 修复 peer dependencies 出现 warning 提示的问题
|
|
109
|
+
|
|
110
|
+
- cce8ecee2d: fix: handle some `TODO` & `FIXME`, change some tests
|
|
111
|
+
fix: 处理一些 `TODO` 和 `FIXME`, 修改了一些 tests
|
|
112
|
+
- ea7cf06: chore: bump webpack/babel-loader/postcss-loader/tsconfig-paths
|
|
113
|
+
|
|
114
|
+
chore: 升级 webpack/babel-loader/postcss-loader/tsconfig-paths 版本
|
|
115
|
+
|
|
116
|
+
- ebbeed1ece: chore: dev server default cross origin
|
|
117
|
+
chore: 开发环境 Server 默认跨域
|
|
118
|
+
- 14b712da84: fix: use consistent alias type and default value across packages
|
|
119
|
+
|
|
120
|
+
fix: 在各个包中使用一致的 alias 类型定义和默认值
|
|
121
|
+
|
|
122
|
+
- Updated dependencies [9b915e0c10]
|
|
123
|
+
- Updated dependencies [7879e8f]
|
|
124
|
+
- Updated dependencies [c9e800d39a]
|
|
125
|
+
- Updated dependencies [d4e8e6fb90]
|
|
126
|
+
- Updated dependencies [d032d49e09]
|
|
127
|
+
- Updated dependencies [6aca875]
|
|
128
|
+
- Updated dependencies [15bf09d9c8]
|
|
129
|
+
- Updated dependencies [2e6031955e]
|
|
130
|
+
- Updated dependencies [7b7d12c]
|
|
131
|
+
- Updated dependencies [92f0eade39]
|
|
132
|
+
- Updated dependencies [edd1cfb1af]
|
|
133
|
+
- Updated dependencies [cc971eabfc]
|
|
134
|
+
- Updated dependencies [5b9049f2e9]
|
|
135
|
+
- Updated dependencies [6bda14ed71]
|
|
136
|
+
- Updated dependencies [a8642da58f]
|
|
137
|
+
- Updated dependencies [92004d1906]
|
|
138
|
+
- Updated dependencies [b8bbe036c7]
|
|
139
|
+
- Updated dependencies [40ed5874c6]
|
|
140
|
+
- Updated dependencies [87c1ff86b9]
|
|
141
|
+
- Updated dependencies [c2bb0f1745]
|
|
142
|
+
- Updated dependencies [d5a31df781]
|
|
143
|
+
- Updated dependencies [dda38c9c3e]
|
|
144
|
+
- Updated dependencies [102d32e4ba]
|
|
145
|
+
- Updated dependencies [8b8e1bb571]
|
|
146
|
+
- Updated dependencies [3bbea92b2a]
|
|
147
|
+
- Updated dependencies [73cd29dd9f]
|
|
148
|
+
- Updated dependencies [b710adb843]
|
|
149
|
+
- Updated dependencies [cce8ecee2d]
|
|
150
|
+
- Updated dependencies [18aaf42249]
|
|
151
|
+
- Updated dependencies [ea7cf06]
|
|
152
|
+
- Updated dependencies [bbe4c4a]
|
|
153
|
+
- Updated dependencies [e4558a0]
|
|
154
|
+
- Updated dependencies [abf3421a75]
|
|
155
|
+
- Updated dependencies [543be9558e]
|
|
156
|
+
- Updated dependencies [14b712da84]
|
|
157
|
+
- @modern-js/server-utils@2.0.0-beta.4
|
|
158
|
+
- @modern-js/prod-server@2.0.0-beta.4
|
|
159
|
+
- @modern-js/types@2.0.0-beta.4
|
|
160
|
+
- @modern-js/utils@2.0.0-beta.4
|
|
161
|
+
|
|
3
162
|
## 2.0.0-beta.3
|
|
4
163
|
|
|
5
164
|
### Major Changes
|
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
import { getIpv4Interfaces, HMR_SOCK_PATH } from
|
|
2
|
-
|
|
3
|
-
const network = getIpv4Interfaces().find(item => !item.internal);
|
|
1
|
+
import { getIpv4Interfaces, HMR_SOCK_PATH } from "@modern-js/utils";
|
|
2
|
+
const getDefaultDevOptions = () => {
|
|
3
|
+
const network = getIpv4Interfaces().find((item) => !item.internal);
|
|
4
4
|
return {
|
|
5
5
|
client: {
|
|
6
|
-
port:
|
|
6
|
+
port: "8080",
|
|
7
7
|
path: HMR_SOCK_PATH,
|
|
8
|
-
host: (network
|
|
8
|
+
host: (network == null ? void 0 : network.address) || "localhost"
|
|
9
9
|
},
|
|
10
10
|
https: false,
|
|
11
|
-
devMiddleware: {
|
|
12
|
-
writeToDisk: true
|
|
13
|
-
},
|
|
11
|
+
devMiddleware: { writeToDisk: true },
|
|
14
12
|
watch: true,
|
|
15
13
|
hot: true,
|
|
16
14
|
liveReload: true
|
|
17
15
|
};
|
|
18
|
-
};
|
|
16
|
+
};
|
|
17
|
+
export {
|
|
18
|
+
getDefaultDevOptions
|
|
19
|
+
};
|
|
@@ -1,38 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
export default class DevServerPlugin {
|
|
1
|
+
class DevServerPlugin {
|
|
3
2
|
constructor(options) {
|
|
4
|
-
_defineProperty(this, "options", void 0);
|
|
5
3
|
this.options = options;
|
|
6
4
|
}
|
|
7
5
|
injectHMRClient(compiler) {
|
|
8
|
-
const {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
const path = client !== null && client !== void 0 && client.path ? `&path=${client.path}` : '';
|
|
13
|
-
const port = client !== null && client !== void 0 && client.port ? `&port=${client.port}` : '';
|
|
6
|
+
const { client } = this.options;
|
|
7
|
+
const host = (client == null ? void 0 : client.host) ? `&host=${client.host}` : "";
|
|
8
|
+
const path = (client == null ? void 0 : client.path) ? `&path=${client.path}` : "";
|
|
9
|
+
const port = (client == null ? void 0 : client.port) ? `&port=${client.port}` : "";
|
|
14
10
|
const clientEntry = `${require.resolve("./hmr-client")}?${host}${path}${port}`;
|
|
15
|
-
|
|
16
|
-
// use a hook to add entries if available
|
|
17
11
|
new compiler.webpack.EntryPlugin(compiler.context, clientEntry, {
|
|
18
|
-
name:
|
|
12
|
+
name: void 0
|
|
19
13
|
}).apply(compiler);
|
|
20
14
|
}
|
|
21
15
|
apply(compiler) {
|
|
22
16
|
if (this.options.hot || this.options.liveReload) {
|
|
23
17
|
this.injectHMRClient(compiler);
|
|
24
18
|
}
|
|
25
|
-
|
|
26
|
-
// Todo remove, client must inject.
|
|
27
19
|
const compilerOptions = compiler.options;
|
|
28
|
-
const {
|
|
29
|
-
HotModuleReplacementPlugin
|
|
30
|
-
} = compiler.webpack;
|
|
20
|
+
const { HotModuleReplacementPlugin } = compiler.webpack;
|
|
31
21
|
compilerOptions.plugins = compilerOptions.plugins || [];
|
|
32
|
-
if (!compilerOptions.plugins.find(
|
|
33
|
-
|
|
22
|
+
if (!compilerOptions.plugins.find(
|
|
23
|
+
(p) => p.constructor === HotModuleReplacementPlugin
|
|
24
|
+
)) {
|
|
34
25
|
const plugin = new HotModuleReplacementPlugin();
|
|
35
26
|
plugin.apply(compiler);
|
|
36
27
|
}
|
|
37
28
|
}
|
|
38
|
-
}
|
|
29
|
+
}
|
|
30
|
+
export {
|
|
31
|
+
DevServerPlugin as default
|
|
32
|
+
};
|
|
@@ -1,46 +1,41 @@
|
|
|
1
|
-
import { HMR_SOCK_PATH } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const searchParams = resourceQuery.substr(1).split('&');
|
|
1
|
+
import { HMR_SOCK_PATH } from "@modern-js/utils/constants";
|
|
2
|
+
function createSocketUrl(resourceQuery) {
|
|
3
|
+
const searchParams = resourceQuery.substr(1).split("&");
|
|
5
4
|
const options = {};
|
|
6
5
|
for (const pair of searchParams) {
|
|
7
|
-
const ary = pair.split(
|
|
6
|
+
const ary = pair.split("=");
|
|
8
7
|
options[ary[0]] = decodeURIComponent(ary[1]);
|
|
9
8
|
}
|
|
10
9
|
const currentLocation = self.location;
|
|
11
10
|
return getSocketUrl(options, currentLocation);
|
|
12
11
|
}
|
|
13
|
-
|
|
12
|
+
function formatURL({
|
|
14
13
|
port,
|
|
15
14
|
protocol,
|
|
16
15
|
hostname,
|
|
17
16
|
pathname
|
|
18
17
|
}) {
|
|
19
18
|
if (window.URL) {
|
|
20
|
-
|
|
21
|
-
const url = new URL('http://localhost');
|
|
19
|
+
const url = new URL("http://localhost");
|
|
22
20
|
url.port = port;
|
|
23
21
|
url.hostname = hostname;
|
|
24
22
|
url.protocol = protocol;
|
|
25
23
|
url.pathname = pathname;
|
|
26
24
|
return url.toString();
|
|
27
25
|
}
|
|
28
|
-
|
|
29
|
-
// compatible with IE11
|
|
30
|
-
const colon = protocol.indexOf(':') === -1 ? ':' : '';
|
|
26
|
+
const colon = protocol.indexOf(":") === -1 ? ":" : "";
|
|
31
27
|
return `${protocol}${colon}//${hostname}:${port}${pathname}`;
|
|
32
28
|
}
|
|
33
29
|
function getSocketUrl(urlParts, location) {
|
|
34
|
-
const {
|
|
35
|
-
host,
|
|
36
|
-
port,
|
|
37
|
-
path,
|
|
38
|
-
protocol
|
|
39
|
-
} = urlParts;
|
|
30
|
+
const { host, port, path, protocol } = urlParts;
|
|
40
31
|
return formatURL({
|
|
41
|
-
protocol: protocol || location.protocol ===
|
|
32
|
+
protocol: protocol || location.protocol === "https:" ? "wss" : "ws",
|
|
42
33
|
hostname: host || location.hostname,
|
|
43
34
|
port: port || location.port,
|
|
44
35
|
pathname: path || HMR_SOCK_PATH
|
|
45
36
|
});
|
|
46
|
-
}
|
|
37
|
+
}
|
|
38
|
+
export {
|
|
39
|
+
createSocketUrl,
|
|
40
|
+
formatURL
|
|
41
|
+
};
|
|
@@ -1,193 +1,143 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
*
|
|
5
|
-
* Tips: this package will be bundled and running in the browser, do not import from the entry of @modern-js/utils.
|
|
6
|
-
*/
|
|
7
|
-
import stripAnsi from '@modern-js/utils/strip-ansi';
|
|
8
|
-
import { formatWebpackMessages } from '@modern-js/utils/format';
|
|
9
|
-
import { createSocketUrl } from "./createSocketUrl";
|
|
10
|
-
|
|
11
|
-
// declare any to fix the type of `module.hot`
|
|
12
|
-
|
|
13
|
-
// TODO hadRuntimeError should be fixed.
|
|
14
|
-
// We need to keep track of if there has been a runtime error.
|
|
15
|
-
// Essentially, we cannot guarantee application state was not corrupted by the
|
|
16
|
-
// runtime error. To prevent confusing behavior, we forcibly reload the entire
|
|
17
|
-
// application. This is handled below when we are notified of a compile (code
|
|
18
|
-
// change).
|
|
19
|
-
// See https://github.com/facebook/create-react-app/issues/3096
|
|
20
|
-
const hadRuntimeError = false;
|
|
21
|
-
|
|
22
|
-
// Connect to Dev Server
|
|
23
|
-
const socketUrl = createSocketUrl(__resourceQuery);
|
|
24
|
-
const connection = new WebSocket(socketUrl);
|
|
25
|
-
|
|
26
|
-
// Unlike WebpackDevServer client, we won't try to reconnect
|
|
27
|
-
// to avoid spamming the console. Disconnect usually happens
|
|
28
|
-
// when developer stops the server.
|
|
29
|
-
connection.onclose = function () {
|
|
30
|
-
if (typeof console !== 'undefined' && typeof console.info === 'function') {
|
|
31
|
-
console.info('The development server has disconnected.\nRefresh the page if necessary.');
|
|
32
|
-
}
|
|
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;
|
|
33
4
|
};
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
5
|
+
import stripAnsi from "@modern-js/utils/strip-ansi";
|
|
6
|
+
import { formatWebpackMessages } from "@modern-js/utils/format";
|
|
7
|
+
import { createSocketUrl } from "./createSocketUrl";
|
|
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.onclose = function() {
|
|
14
|
+
if (typeof console !== "undefined" && typeof console.info === "function") {
|
|
15
|
+
console.info(
|
|
16
|
+
"The development server has disconnected.\nRefresh the page if necessary."
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
let isFirstCompilation = true;
|
|
21
|
+
let mostRecentCompilationHash = null;
|
|
22
|
+
let hasCompileErrors = false;
|
|
23
|
+
function clearOutdatedErrors() {
|
|
24
|
+
if (typeof console !== "undefined" && typeof console.clear === "function") {
|
|
25
|
+
if (hasCompileErrors) {
|
|
26
|
+
console.clear();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
46
29
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
for (let i = 0; i < formatted.warnings.length; i++) {
|
|
77
|
-
if (i === 5) {
|
|
78
|
-
console.warn('There were more warnings in other files.\n' + 'You can find a complete log in the terminal.');
|
|
79
|
-
break;
|
|
30
|
+
function handleSuccess() {
|
|
31
|
+
clearOutdatedErrors();
|
|
32
|
+
const isHotUpdate = !isFirstCompilation;
|
|
33
|
+
isFirstCompilation = false;
|
|
34
|
+
hasCompileErrors = false;
|
|
35
|
+
if (isHotUpdate) {
|
|
36
|
+
tryApplyUpdates();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function handleWarnings(warnings) {
|
|
40
|
+
clearOutdatedErrors();
|
|
41
|
+
const isHotUpdate = !isFirstCompilation;
|
|
42
|
+
isFirstCompilation = false;
|
|
43
|
+
hasCompileErrors = false;
|
|
44
|
+
function printWarnings() {
|
|
45
|
+
const formatted = formatWebpackMessages({
|
|
46
|
+
warnings,
|
|
47
|
+
errors: []
|
|
48
|
+
});
|
|
49
|
+
if (typeof console !== "undefined" && typeof console.warn === "function") {
|
|
50
|
+
for (let i = 0; i < formatted.warnings.length; i++) {
|
|
51
|
+
if (i === 5) {
|
|
52
|
+
console.warn(
|
|
53
|
+
"There were more warnings in other files.\nYou can find a complete log in the terminal."
|
|
54
|
+
);
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
console.warn(stripAnsi(formatted.warnings[i]));
|
|
58
|
+
}
|
|
80
59
|
}
|
|
81
|
-
|
|
60
|
+
}
|
|
61
|
+
printWarnings();
|
|
62
|
+
if (isHotUpdate) {
|
|
63
|
+
tryApplyUpdates();
|
|
82
64
|
}
|
|
83
65
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
hasCompileErrors = true;
|
|
98
|
-
|
|
99
|
-
// "Massage" webpack messages.
|
|
100
|
-
const formatted = formatWebpackMessages({
|
|
101
|
-
errors,
|
|
102
|
-
warnings: []
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
// Also log them to the console.
|
|
106
|
-
if (typeof console !== 'undefined' && typeof console.error === 'function') {
|
|
107
|
-
for (const error of formatted.errors) {
|
|
108
|
-
console.error(stripAnsi(error));
|
|
66
|
+
function handleErrors(errors) {
|
|
67
|
+
clearOutdatedErrors();
|
|
68
|
+
isFirstCompilation = false;
|
|
69
|
+
hasCompileErrors = true;
|
|
70
|
+
const formatted = formatWebpackMessages({
|
|
71
|
+
errors,
|
|
72
|
+
warnings: []
|
|
73
|
+
});
|
|
74
|
+
if (typeof console !== "undefined" && typeof console.error === "function") {
|
|
75
|
+
for (const error of formatted.errors) {
|
|
76
|
+
console.error(stripAnsi(error));
|
|
77
|
+
}
|
|
78
|
+
}
|
|
109
79
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
case 'warnings':
|
|
138
|
-
handleWarnings(message.data);
|
|
139
|
-
break;
|
|
140
|
-
case 'errors':
|
|
141
|
-
handleErrors(message.data);
|
|
142
|
-
break;
|
|
143
|
-
default:
|
|
144
|
-
// Do nothing.
|
|
145
|
-
}
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
// Is there a newer version of this code available?
|
|
149
|
-
function isUpdateAvailable() {
|
|
150
|
-
// __webpack_hash__ is the hash of the current compilation.
|
|
151
|
-
// It's a global variable injected by webpack.
|
|
152
|
-
return mostRecentCompilationHash !== __webpack_hash__;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
// webpack disallows updates in other states.
|
|
156
|
-
function canApplyUpdates() {
|
|
157
|
-
return module.hot.status() === 'idle';
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
// Attempt to update code on the fly, fall back to a hard reload.
|
|
161
|
-
function tryApplyUpdates() {
|
|
162
|
-
if (!module.hot) {
|
|
163
|
-
// HotModuleReplacementPlugin is not in webpack configuration.
|
|
164
|
-
window.location.reload();
|
|
165
|
-
return;
|
|
166
|
-
}
|
|
167
|
-
if (!isUpdateAvailable() || !canApplyUpdates()) {
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
function handleApplyUpdates(err, updatedModules) {
|
|
171
|
-
const wantsForcedReload = err || !updatedModules || hadRuntimeError;
|
|
172
|
-
if (wantsForcedReload) {
|
|
173
|
-
window.location.reload();
|
|
174
|
-
return;
|
|
80
|
+
function handleAvailableHash(hash) {
|
|
81
|
+
mostRecentCompilationHash = hash;
|
|
82
|
+
}
|
|
83
|
+
connection.onmessage = function(e) {
|
|
84
|
+
const message = JSON.parse(e.data);
|
|
85
|
+
switch (message.type) {
|
|
86
|
+
case "hash":
|
|
87
|
+
handleAvailableHash(message.data);
|
|
88
|
+
break;
|
|
89
|
+
case "still-ok":
|
|
90
|
+
case "ok":
|
|
91
|
+
handleSuccess();
|
|
92
|
+
break;
|
|
93
|
+
case "content-changed":
|
|
94
|
+
window.location.reload();
|
|
95
|
+
break;
|
|
96
|
+
case "warnings":
|
|
97
|
+
handleWarnings(message.data);
|
|
98
|
+
break;
|
|
99
|
+
case "errors":
|
|
100
|
+
handleErrors(message.data);
|
|
101
|
+
break;
|
|
102
|
+
default:
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
function isUpdateAvailable() {
|
|
106
|
+
return mostRecentCompilationHash !== __webpack_hash__;
|
|
175
107
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
108
|
+
function canApplyUpdates() {
|
|
109
|
+
return module.hot.status() === "idle";
|
|
110
|
+
}
|
|
111
|
+
function tryApplyUpdates() {
|
|
112
|
+
if (!module.hot) {
|
|
113
|
+
window.location.reload();
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
if (!isUpdateAvailable() || !canApplyUpdates()) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
function handleApplyUpdates(err, updatedModules) {
|
|
120
|
+
const wantsForcedReload = err || !updatedModules || hadRuntimeError;
|
|
121
|
+
if (wantsForcedReload) {
|
|
122
|
+
window.location.reload();
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
if (isUpdateAvailable()) {
|
|
126
|
+
tryApplyUpdates();
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
const result = module.hot.check(true, handleApplyUpdates);
|
|
130
|
+
if (result == null ? void 0 : result.then) {
|
|
131
|
+
result.then(
|
|
132
|
+
(updatedModules) => {
|
|
133
|
+
handleApplyUpdates(null, updatedModules);
|
|
134
|
+
},
|
|
135
|
+
(err) => {
|
|
136
|
+
handleApplyUpdates(err, null);
|
|
137
|
+
}
|
|
138
|
+
);
|
|
139
|
+
}
|
|
179
140
|
}
|
|
180
141
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
const result = module.hot.check( /* autoApply */true, handleApplyUpdates);
|
|
184
|
-
|
|
185
|
-
// // webpack 2 returns a Promise instead of invoking a callback
|
|
186
|
-
if (result !== null && result !== void 0 && result.then) {
|
|
187
|
-
result.then(updatedModules => {
|
|
188
|
-
handleApplyUpdates(null, updatedModules);
|
|
189
|
-
}, err => {
|
|
190
|
-
handleApplyUpdates(err, null);
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
}
|
|
142
|
+
});
|
|
143
|
+
export default require_hmr_client();
|
|
File without changes
|