@modern-js/server 2.25.1-alpha.0 → 2.25.2
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 +29 -0
- package/package.json +9 -9
- package/dist/js/modern/constants.js +0 -19
- package/dist/js/modern/dev-tools/dev-middleware/hmr-client/createSocketUrl.js +0 -41
- package/dist/js/modern/dev-tools/dev-middleware/hmr-client/index.js +0 -143
- package/dist/js/modern/dev-tools/dev-middleware/index.js +0 -94
- package/dist/js/modern/dev-tools/dev-middleware/socket-server.js +0 -132
- package/dist/js/modern/dev-tools/https/index.js +0 -49
- package/dist/js/modern/dev-tools/mock/getMockData.js +0 -114
- package/dist/js/modern/dev-tools/mock/index.js +0 -54
- package/dist/js/modern/dev-tools/register/index.js +0 -111
- package/dist/js/modern/dev-tools/watcher/dependency-tree.js +0 -59
- package/dist/js/modern/dev-tools/watcher/index.js +0 -106
- package/dist/js/modern/dev-tools/watcher/stats-cache.js +0 -58
- package/dist/js/modern/index.js +0 -12
- package/dist/js/modern/server/dev-server.js +0 -293
- package/dist/js/modern/server/index.js +0 -16
- package/dist/js/modern/types.js +0 -0
- package/dist/js/node/constants.js +0 -42
- package/dist/js/node/dev-tools/dev-middleware/hmr-client/createSocketUrl.js +0 -65
- package/dist/js/node/dev-tools/dev-middleware/hmr-client/index.js +0 -152
- package/dist/js/node/dev-tools/dev-middleware/index.js +0 -119
- package/dist/js/node/dev-tools/dev-middleware/socket-server.js +0 -159
- package/dist/js/node/dev-tools/https/index.js +0 -72
- package/dist/js/node/dev-tools/mock/getMockData.js +0 -135
- package/dist/js/node/dev-tools/mock/index.js +0 -83
- package/dist/js/node/dev-tools/register/index.js +0 -138
- package/dist/js/node/dev-tools/watcher/dependency-tree.js +0 -89
- package/dist/js/node/dev-tools/watcher/index.js +0 -135
- package/dist/js/node/dev-tools/watcher/stats-cache.js +0 -87
- package/dist/js/node/index.js +0 -35
- package/dist/js/node/server/dev-server.js +0 -310
- package/dist/js/node/server/index.js +0 -39
- package/dist/js/node/types.js +0 -15
- package/dist/js/treeshaking/constants.js +0 -21
- package/dist/js/treeshaking/dev-tools/dev-middleware/hmr-client/createSocketUrl.js +0 -51
- package/dist/js/treeshaking/dev-tools/dev-middleware/hmr-client/index.js +0 -157
- package/dist/js/treeshaking/dev-tools/dev-middleware/index.js +0 -322
- package/dist/js/treeshaking/dev-tools/dev-middleware/socket-server.js +0 -209
- package/dist/js/treeshaking/dev-tools/https/index.js +0 -193
- package/dist/js/treeshaking/dev-tools/mock/getMockData.js +0 -327
- package/dist/js/treeshaking/dev-tools/mock/index.js +0 -191
- package/dist/js/treeshaking/dev-tools/register/index.js +0 -153
- package/dist/js/treeshaking/dev-tools/watcher/dependency-tree.js +0 -150
- package/dist/js/treeshaking/dev-tools/watcher/index.js +0 -200
- package/dist/js/treeshaking/dev-tools/watcher/stats-cache.js +0 -128
- package/dist/js/treeshaking/index.js +0 -9
- package/dist/js/treeshaking/server/dev-server.js +0 -799
- package/dist/js/treeshaking/server/index.js +0 -92
- package/dist/js/treeshaking/types.js +0 -1
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Server } from "@modern-js/prod-server";
|
|
2
|
-
import { ModernDevServer } from "./dev-server";
|
|
3
|
-
const createDevServer = (options) => {
|
|
4
|
-
return new ModernDevServer(options);
|
|
5
|
-
};
|
|
6
|
-
class DevServer extends Server {
|
|
7
|
-
constructor(options) {
|
|
8
|
-
super(options);
|
|
9
|
-
if (options.dev) {
|
|
10
|
-
this.serverImpl = createDevServer;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
export {
|
|
15
|
-
DevServer
|
|
16
|
-
};
|
package/dist/js/modern/types.js
DELETED
|
File without changes
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var constants_exports = {};
|
|
19
|
-
__export(constants_exports, {
|
|
20
|
-
getDefaultDevOptions: () => getDefaultDevOptions
|
|
21
|
-
});
|
|
22
|
-
module.exports = __toCommonJS(constants_exports);
|
|
23
|
-
var import_utils = require("@modern-js/utils");
|
|
24
|
-
const getDefaultDevOptions = () => {
|
|
25
|
-
const network = (0, import_utils.getIpv4Interfaces)().find((item) => !item.internal);
|
|
26
|
-
return {
|
|
27
|
-
client: {
|
|
28
|
-
port: "8080",
|
|
29
|
-
path: import_utils.HMR_SOCK_PATH,
|
|
30
|
-
host: (network == null ? void 0 : network.address) || "localhost"
|
|
31
|
-
},
|
|
32
|
-
https: false,
|
|
33
|
-
devMiddleware: { writeToDisk: true },
|
|
34
|
-
watch: true,
|
|
35
|
-
hot: true,
|
|
36
|
-
liveReload: true
|
|
37
|
-
};
|
|
38
|
-
};
|
|
39
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
40
|
-
0 && (module.exports = {
|
|
41
|
-
getDefaultDevOptions
|
|
42
|
-
});
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var createSocketUrl_exports = {};
|
|
19
|
-
__export(createSocketUrl_exports, {
|
|
20
|
-
createSocketUrl: () => createSocketUrl,
|
|
21
|
-
formatURL: () => formatURL
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(createSocketUrl_exports);
|
|
24
|
-
var import_constants = require("@modern-js/utils/constants");
|
|
25
|
-
function createSocketUrl(resourceQuery) {
|
|
26
|
-
const searchParams = resourceQuery.substr(1).split("&");
|
|
27
|
-
const options = {};
|
|
28
|
-
for (const pair of searchParams) {
|
|
29
|
-
const ary = pair.split("=");
|
|
30
|
-
options[ary[0]] = decodeURIComponent(ary[1]);
|
|
31
|
-
}
|
|
32
|
-
const currentLocation = self.location;
|
|
33
|
-
return getSocketUrl(options, currentLocation);
|
|
34
|
-
}
|
|
35
|
-
function formatURL({
|
|
36
|
-
port,
|
|
37
|
-
protocol,
|
|
38
|
-
hostname,
|
|
39
|
-
pathname
|
|
40
|
-
}) {
|
|
41
|
-
if (window.URL) {
|
|
42
|
-
const url = new URL("http://localhost");
|
|
43
|
-
url.port = port;
|
|
44
|
-
url.hostname = hostname;
|
|
45
|
-
url.protocol = protocol;
|
|
46
|
-
url.pathname = pathname;
|
|
47
|
-
return url.toString();
|
|
48
|
-
}
|
|
49
|
-
const colon = protocol.indexOf(":") === -1 ? ":" : "";
|
|
50
|
-
return `${protocol}${colon}//${hostname}:${port}${pathname}`;
|
|
51
|
-
}
|
|
52
|
-
function getSocketUrl(urlParts, location) {
|
|
53
|
-
const { host, port, path, protocol } = urlParts;
|
|
54
|
-
return formatURL({
|
|
55
|
-
protocol: protocol || (location.protocol === "https:" ? "wss" : "ws"),
|
|
56
|
-
hostname: host || location.hostname,
|
|
57
|
-
port: port || location.port,
|
|
58
|
-
pathname: path || import_constants.HMR_SOCK_PATH
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
62
|
-
0 && (module.exports = {
|
|
63
|
-
createSocketUrl,
|
|
64
|
-
formatURL
|
|
65
|
-
});
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __copyProps = (to, from, except, desc) => {
|
|
8
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
9
|
-
for (let key of __getOwnPropNames(from))
|
|
10
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
11
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
12
|
-
}
|
|
13
|
-
return to;
|
|
14
|
-
};
|
|
15
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
16
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
17
|
-
mod
|
|
18
|
-
));
|
|
19
|
-
var import_strip_ansi = __toESM(require("@modern-js/utils/strip-ansi"));
|
|
20
|
-
var import_format = require("@modern-js/utils/format");
|
|
21
|
-
var import_createSocketUrl = require("./createSocketUrl");
|
|
22
|
-
const hadRuntimeError = false;
|
|
23
|
-
const socketUrl = (0, import_createSocketUrl.createSocketUrl)(__resourceQuery);
|
|
24
|
-
const connection = new WebSocket(socketUrl);
|
|
25
|
-
connection.onclose = function() {
|
|
26
|
-
if (typeof console !== "undefined" && typeof console.info === "function") {
|
|
27
|
-
console.info(
|
|
28
|
-
"The development server has disconnected.\nRefresh the page if necessary."
|
|
29
|
-
);
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
let isFirstCompilation = true;
|
|
33
|
-
let mostRecentCompilationHash = null;
|
|
34
|
-
let hasCompileErrors = false;
|
|
35
|
-
function clearOutdatedErrors() {
|
|
36
|
-
if (typeof console !== "undefined" && typeof console.clear === "function") {
|
|
37
|
-
if (hasCompileErrors) {
|
|
38
|
-
console.clear();
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
function handleSuccess() {
|
|
43
|
-
clearOutdatedErrors();
|
|
44
|
-
const isHotUpdate = !isFirstCompilation;
|
|
45
|
-
isFirstCompilation = false;
|
|
46
|
-
hasCompileErrors = false;
|
|
47
|
-
if (isHotUpdate) {
|
|
48
|
-
tryApplyUpdates();
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
function handleWarnings(warnings) {
|
|
52
|
-
clearOutdatedErrors();
|
|
53
|
-
const isHotUpdate = !isFirstCompilation;
|
|
54
|
-
isFirstCompilation = false;
|
|
55
|
-
hasCompileErrors = false;
|
|
56
|
-
function printWarnings() {
|
|
57
|
-
const formatted = (0, import_format.formatWebpackMessages)({
|
|
58
|
-
warnings,
|
|
59
|
-
errors: []
|
|
60
|
-
});
|
|
61
|
-
if (typeof console !== "undefined" && typeof console.warn === "function") {
|
|
62
|
-
for (let i = 0; i < formatted.warnings.length; i++) {
|
|
63
|
-
if (i === 5) {
|
|
64
|
-
console.warn(
|
|
65
|
-
"There were more warnings in other files.\nYou can find a complete log in the terminal."
|
|
66
|
-
);
|
|
67
|
-
break;
|
|
68
|
-
}
|
|
69
|
-
console.warn((0, import_strip_ansi.default)(formatted.warnings[i]));
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
printWarnings();
|
|
74
|
-
if (isHotUpdate) {
|
|
75
|
-
tryApplyUpdates();
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
function handleErrors(errors) {
|
|
79
|
-
clearOutdatedErrors();
|
|
80
|
-
isFirstCompilation = false;
|
|
81
|
-
hasCompileErrors = true;
|
|
82
|
-
const formatted = (0, import_format.formatWebpackMessages)({
|
|
83
|
-
errors,
|
|
84
|
-
warnings: []
|
|
85
|
-
});
|
|
86
|
-
if (typeof console !== "undefined" && typeof console.error === "function") {
|
|
87
|
-
for (const error of formatted.errors) {
|
|
88
|
-
console.error((0, import_strip_ansi.default)(error));
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
function handleAvailableHash(hash) {
|
|
93
|
-
mostRecentCompilationHash = hash;
|
|
94
|
-
}
|
|
95
|
-
connection.onmessage = function(e) {
|
|
96
|
-
const 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
|
-
if (!module.hot) {
|
|
125
|
-
window.location.reload();
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
if (!isUpdateAvailable() || !canApplyUpdates()) {
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
function handleApplyUpdates(err, updatedModules) {
|
|
132
|
-
const wantsForcedReload = err || !updatedModules || hadRuntimeError;
|
|
133
|
-
if (wantsForcedReload) {
|
|
134
|
-
window.location.reload();
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
if (isUpdateAvailable()) {
|
|
138
|
-
tryApplyUpdates();
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
const result = module.hot.check(true, handleApplyUpdates);
|
|
142
|
-
if (result == null ? void 0 : result.then) {
|
|
143
|
-
result.then(
|
|
144
|
-
(updatedModules) => {
|
|
145
|
-
handleApplyUpdates(null, updatedModules);
|
|
146
|
-
},
|
|
147
|
-
(err) => {
|
|
148
|
-
handleApplyUpdates(err, null);
|
|
149
|
-
}
|
|
150
|
-
);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
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
|
-
};
|
|
21
|
-
var __export = (target, all) => {
|
|
22
|
-
for (var name in all)
|
|
23
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
24
|
-
};
|
|
25
|
-
var __copyProps = (to, from, except, desc) => {
|
|
26
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
27
|
-
for (let key of __getOwnPropNames(from))
|
|
28
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
29
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
30
|
-
}
|
|
31
|
-
return to;
|
|
32
|
-
};
|
|
33
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
34
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
35
|
-
mod
|
|
36
|
-
));
|
|
37
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
38
|
-
var __async = (__this, __arguments, generator) => {
|
|
39
|
-
return new Promise((resolve, reject) => {
|
|
40
|
-
var fulfilled = (value) => {
|
|
41
|
-
try {
|
|
42
|
-
step(generator.next(value));
|
|
43
|
-
} catch (e) {
|
|
44
|
-
reject(e);
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
var rejected = (value) => {
|
|
48
|
-
try {
|
|
49
|
-
step(generator.throw(value));
|
|
50
|
-
} catch (e) {
|
|
51
|
-
reject(e);
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
55
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
56
|
-
});
|
|
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"));
|
|
65
|
-
const noop = () => {
|
|
66
|
-
};
|
|
67
|
-
function getHMRClientPath(client) {
|
|
68
|
-
const protocol = (client == null ? void 0 : client.protocol) ? `&protocol=${client.protocol}` : "";
|
|
69
|
-
const host = (client == null ? void 0 : client.host) ? `&host=${client.host}` : "";
|
|
70
|
-
const path = (client == null ? void 0 : client.path) ? `&path=${client.path}` : "";
|
|
71
|
-
const port = (client == null ? void 0 : client.port) ? `&port=${client.port}` : "";
|
|
72
|
-
const clientEntry = `${require.resolve("./hmr-client")}?${host}${path}${port}${protocol}`;
|
|
73
|
-
return clientEntry;
|
|
74
|
-
}
|
|
75
|
-
class DevMiddleware extends import_events.EventEmitter {
|
|
76
|
-
constructor({ dev, devMiddleware }) {
|
|
77
|
-
super();
|
|
78
|
-
this.devOptions = dev;
|
|
79
|
-
this.socketServer = new import_socket_server.default(dev);
|
|
80
|
-
if (devMiddleware) {
|
|
81
|
-
this.middleware = this.setupDevMiddleware(devMiddleware);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
init(app) {
|
|
85
|
-
app.on("listening", () => {
|
|
86
|
-
this.socketServer.prepare(app);
|
|
87
|
-
});
|
|
88
|
-
app.on("close", () => __async(this, null, function* () {
|
|
89
|
-
var _a;
|
|
90
|
-
(_a = this.middleware) == null ? void 0 : _a.close(noop);
|
|
91
|
-
this.socketServer.close();
|
|
92
|
-
}));
|
|
93
|
-
}
|
|
94
|
-
sockWrite(type, data) {
|
|
95
|
-
this.socketServer.sockWrite(type, data);
|
|
96
|
-
}
|
|
97
|
-
setupDevMiddleware(devMiddleware) {
|
|
98
|
-
const { devOptions } = this;
|
|
99
|
-
const callbacks = {
|
|
100
|
-
onInvalid: () => {
|
|
101
|
-
this.socketServer.sockWrite("invalid");
|
|
102
|
-
},
|
|
103
|
-
onDone: (stats) => {
|
|
104
|
-
this.socketServer.updateStats(stats);
|
|
105
|
-
this.emit("change", stats);
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
const enableHMR = this.devOptions.hot || this.devOptions.liveReload;
|
|
109
|
-
const middleware = devMiddleware(__spreadValues({
|
|
110
|
-
headers: devOptions.headers,
|
|
111
|
-
stats: false,
|
|
112
|
-
callbacks,
|
|
113
|
-
hmrClientPath: enableHMR ? getHMRClientPath(devOptions.client) : void 0
|
|
114
|
-
}, devOptions.devMiddleware));
|
|
115
|
-
return middleware;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
119
|
-
0 && (module.exports = {});
|
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
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
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
-
var socket_server_exports = {};
|
|
25
|
-
__export(socket_server_exports, {
|
|
26
|
-
default: () => SocketServer
|
|
27
|
-
});
|
|
28
|
-
module.exports = __toCommonJS(socket_server_exports);
|
|
29
|
-
var import_ws = __toESM(require("ws"));
|
|
30
|
-
var import_utils = require("@modern-js/utils");
|
|
31
|
-
class SocketServer {
|
|
32
|
-
constructor(options) {
|
|
33
|
-
this.sockets = [];
|
|
34
|
-
this.timer = null;
|
|
35
|
-
this.options = options;
|
|
36
|
-
}
|
|
37
|
-
prepare(app) {
|
|
38
|
-
var _a;
|
|
39
|
-
this.app = app;
|
|
40
|
-
this.wsServer = new import_ws.default.Server({
|
|
41
|
-
noServer: true,
|
|
42
|
-
path: (_a = this.options.client) == null ? void 0 : _a.path
|
|
43
|
-
});
|
|
44
|
-
this.app.on("upgrade", (req, sock, head) => {
|
|
45
|
-
if (!this.wsServer.shouldHandle(req)) {
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
this.wsServer.handleUpgrade(req, sock, head, (connection) => {
|
|
49
|
-
this.wsServer.emit("connection", connection, req);
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
this.wsServer.on("error", (err) => {
|
|
53
|
-
import_utils.logger.error(err);
|
|
54
|
-
});
|
|
55
|
-
this.timer = setInterval(() => {
|
|
56
|
-
this.wsServer.clients.forEach((socket) => {
|
|
57
|
-
const extWs = socket;
|
|
58
|
-
if (!extWs.isAlive) {
|
|
59
|
-
extWs.terminate();
|
|
60
|
-
} else {
|
|
61
|
-
extWs.isAlive = false;
|
|
62
|
-
extWs.ping(() => {
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
}, 3e4);
|
|
67
|
-
this.wsServer.on("connection", (socket) => {
|
|
68
|
-
this.onConnect(socket);
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
updateStats(stats) {
|
|
72
|
-
this.stats = stats;
|
|
73
|
-
this.sendStats();
|
|
74
|
-
}
|
|
75
|
-
sockWrite(type, data) {
|
|
76
|
-
this.sockets.forEach((socket) => {
|
|
77
|
-
this.send(socket, JSON.stringify({ type, data }));
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
singleWrite(socket, type, data) {
|
|
81
|
-
this.send(socket, JSON.stringify({ type, data }));
|
|
82
|
-
}
|
|
83
|
-
close() {
|
|
84
|
-
this.sockets.forEach((socket) => {
|
|
85
|
-
socket.close();
|
|
86
|
-
});
|
|
87
|
-
if (this.timer) {
|
|
88
|
-
clearInterval(this.timer);
|
|
89
|
-
this.timer = null;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
onConnect(socket) {
|
|
93
|
-
const connection = socket;
|
|
94
|
-
connection.isAlive = true;
|
|
95
|
-
connection.on("pong", () => {
|
|
96
|
-
connection.isAlive = true;
|
|
97
|
-
});
|
|
98
|
-
if (!connection) {
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
this.sockets.push(connection);
|
|
102
|
-
connection.on("close", () => {
|
|
103
|
-
const idx = this.sockets.indexOf(connection);
|
|
104
|
-
if (idx >= 0) {
|
|
105
|
-
this.sockets.splice(idx, 1);
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
if (this.options.hot || this.options.hot === "only") {
|
|
109
|
-
this.singleWrite(connection, "hot");
|
|
110
|
-
}
|
|
111
|
-
if (this.options.liveReload) {
|
|
112
|
-
this.singleWrite(connection, "liveReload");
|
|
113
|
-
}
|
|
114
|
-
if (this.stats) {
|
|
115
|
-
this.sendStats(true);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
getStats() {
|
|
119
|
-
const curStats = this.stats;
|
|
120
|
-
if (!curStats) {
|
|
121
|
-
return null;
|
|
122
|
-
}
|
|
123
|
-
const defaultStats = {
|
|
124
|
-
all: false,
|
|
125
|
-
hash: true,
|
|
126
|
-
assets: true,
|
|
127
|
-
warnings: true,
|
|
128
|
-
errors: true,
|
|
129
|
-
errorDetails: false
|
|
130
|
-
};
|
|
131
|
-
return curStats.toJson(defaultStats);
|
|
132
|
-
}
|
|
133
|
-
sendStats(force = false) {
|
|
134
|
-
const stats = this.getStats();
|
|
135
|
-
if (!stats) {
|
|
136
|
-
return null;
|
|
137
|
-
}
|
|
138
|
-
const shouldEmit = !force && stats && (!stats.errors || stats.errors.length === 0) && stats.assets && stats.assets.every((asset) => !asset.emitted);
|
|
139
|
-
if (shouldEmit) {
|
|
140
|
-
return this.sockWrite("still-ok");
|
|
141
|
-
}
|
|
142
|
-
this.sockWrite("hash", stats.hash);
|
|
143
|
-
if (stats.errors && stats.errors.length > 0) {
|
|
144
|
-
return this.sockWrite("errors", stats.errors);
|
|
145
|
-
} else if (stats.warnings && stats.warnings.length > 0) {
|
|
146
|
-
return this.sockWrite("warnings", stats.warnings);
|
|
147
|
-
} else {
|
|
148
|
-
return this.sockWrite("ok");
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
send(connection, message) {
|
|
152
|
-
if (connection.readyState !== 1) {
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
connection.send(message);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
159
|
-
0 && (module.exports = {});
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var __async = (__this, __arguments, generator) => {
|
|
19
|
-
return new Promise((resolve, reject) => {
|
|
20
|
-
var fulfilled = (value) => {
|
|
21
|
-
try {
|
|
22
|
-
step(generator.next(value));
|
|
23
|
-
} catch (e) {
|
|
24
|
-
reject(e);
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
var rejected = (value) => {
|
|
28
|
-
try {
|
|
29
|
-
step(generator.throw(value));
|
|
30
|
-
} catch (e) {
|
|
31
|
-
reject(e);
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
35
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
36
|
-
});
|
|
37
|
-
};
|
|
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* () {
|
|
45
|
-
const httpsOptions = typeof userOptions === "boolean" ? {} : userOptions;
|
|
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);
|
|
64
|
-
const selfsign = yield devcert.certificateFor(["localhost"]);
|
|
65
|
-
return selfsign;
|
|
66
|
-
}
|
|
67
|
-
return httpsOptions;
|
|
68
|
-
});
|
|
69
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
70
|
-
0 && (module.exports = {
|
|
71
|
-
genHttpsOptions
|
|
72
|
-
});
|