@modern-js/server 2.6.1-alpha.0 → 2.8.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.
Files changed (54) hide show
  1. package/CHANGELOG.md +45 -0
  2. package/README.md +2 -2
  3. package/dist/cjs/server/devServer.js +1 -1
  4. package/dist/esm/server/devServer.js +1 -1
  5. package/dist/esm-node/server/devServer.js +1 -1
  6. package/package.json +12 -12
  7. package/dist/js/modern/constants.js +0 -19
  8. package/dist/js/modern/dev-tools/dev-middleware/hmr-client/createSocketUrl.js +0 -41
  9. package/dist/js/modern/dev-tools/dev-middleware/hmr-client/index.js +0 -146
  10. package/dist/js/modern/dev-tools/dev-middleware/index.js +0 -94
  11. package/dist/js/modern/dev-tools/dev-middleware/socket-server.js +0 -132
  12. package/dist/js/modern/dev-tools/https/index.js +0 -49
  13. package/dist/js/modern/dev-tools/mock/getMockData.js +0 -105
  14. package/dist/js/modern/dev-tools/mock/index.js +0 -70
  15. package/dist/js/modern/dev-tools/register/index.js +0 -112
  16. package/dist/js/modern/dev-tools/watcher/dependency-tree.js +0 -59
  17. package/dist/js/modern/dev-tools/watcher/index.js +0 -106
  18. package/dist/js/modern/dev-tools/watcher/stats-cache.js +0 -58
  19. package/dist/js/modern/index.js +0 -12
  20. package/dist/js/modern/server/dev-server.js +0 -294
  21. package/dist/js/modern/server/index.js +0 -16
  22. package/dist/js/modern/types.js +0 -0
  23. package/dist/js/node/constants.js +0 -42
  24. package/dist/js/node/dev-tools/dev-middleware/hmr-client/createSocketUrl.js +0 -65
  25. package/dist/js/node/dev-tools/dev-middleware/hmr-client/index.js +0 -155
  26. package/dist/js/node/dev-tools/dev-middleware/index.js +0 -119
  27. package/dist/js/node/dev-tools/dev-middleware/socket-server.js +0 -159
  28. package/dist/js/node/dev-tools/https/index.js +0 -72
  29. package/dist/js/node/dev-tools/mock/getMockData.js +0 -126
  30. package/dist/js/node/dev-tools/mock/index.js +0 -99
  31. package/dist/js/node/dev-tools/register/index.js +0 -139
  32. package/dist/js/node/dev-tools/watcher/dependency-tree.js +0 -89
  33. package/dist/js/node/dev-tools/watcher/index.js +0 -135
  34. package/dist/js/node/dev-tools/watcher/stats-cache.js +0 -87
  35. package/dist/js/node/index.js +0 -35
  36. package/dist/js/node/server/dev-server.js +0 -311
  37. package/dist/js/node/server/index.js +0 -39
  38. package/dist/js/node/types.js +0 -15
  39. package/dist/js/treeshaking/constants.js +0 -21
  40. package/dist/js/treeshaking/dev-tools/dev-middleware/hmr-client/createSocketUrl.js +0 -51
  41. package/dist/js/treeshaking/dev-tools/dev-middleware/hmr-client/index.js +0 -162
  42. package/dist/js/treeshaking/dev-tools/dev-middleware/index.js +0 -322
  43. package/dist/js/treeshaking/dev-tools/dev-middleware/socket-server.js +0 -209
  44. package/dist/js/treeshaking/dev-tools/https/index.js +0 -193
  45. package/dist/js/treeshaking/dev-tools/mock/getMockData.js +0 -318
  46. package/dist/js/treeshaking/dev-tools/mock/index.js +0 -207
  47. package/dist/js/treeshaking/dev-tools/register/index.js +0 -154
  48. package/dist/js/treeshaking/dev-tools/watcher/dependency-tree.js +0 -150
  49. package/dist/js/treeshaking/dev-tools/watcher/index.js +0 -200
  50. package/dist/js/treeshaking/dev-tools/watcher/stats-cache.js +0 -128
  51. package/dist/js/treeshaking/index.js +0 -9
  52. package/dist/js/treeshaking/server/dev-server.js +0 -800
  53. package/dist/js/treeshaking/server/index.js +0 -92
  54. package/dist/js/treeshaking/types.js +0 -1
@@ -1,209 +0,0 @@
1
- function _classCallCheck(instance, Constructor) {
2
- if (!(instance instanceof Constructor)) {
3
- throw new TypeError("Cannot call a class as a function");
4
- }
5
- }
6
- function _defineProperties(target, props) {
7
- for(var i = 0; i < props.length; i++){
8
- var descriptor = props[i];
9
- descriptor.enumerable = descriptor.enumerable || false;
10
- descriptor.configurable = true;
11
- if ("value" in descriptor) descriptor.writable = true;
12
- Object.defineProperty(target, descriptor.key, descriptor);
13
- }
14
- }
15
- function _createClass(Constructor, protoProps, staticProps) {
16
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
17
- if (staticProps) _defineProperties(Constructor, staticProps);
18
- return Constructor;
19
- }
20
- function _defineProperty(obj, key, value) {
21
- if (key in obj) {
22
- Object.defineProperty(obj, key, {
23
- value: value,
24
- enumerable: true,
25
- configurable: true,
26
- writable: true
27
- });
28
- } else {
29
- obj[key] = value;
30
- }
31
- return obj;
32
- }
33
- import ws from "ws";
34
- import { logger } from "@modern-js/utils";
35
- var SocketServer = /*#__PURE__*/ function() {
36
- "use strict";
37
- function SocketServer(options) {
38
- _classCallCheck(this, SocketServer);
39
- _defineProperty(this, "wsServer", void 0);
40
- _defineProperty(this, "sockets", []);
41
- _defineProperty(this, "options", void 0);
42
- _defineProperty(this, "app", void 0);
43
- _defineProperty(this, "stats", void 0);
44
- _defineProperty(this, "timer", null);
45
- this.options = options;
46
- }
47
- _createClass(SocketServer, [
48
- {
49
- key: "prepare",
50
- value: function prepare(app) {
51
- var _this = this;
52
- var _this_options_client;
53
- this.app = app;
54
- this.wsServer = new ws.Server({
55
- noServer: true,
56
- path: (_this_options_client = this.options.client) === null || _this_options_client === void 0 ? void 0 : _this_options_client.path
57
- });
58
- this.app.on("upgrade", function(req, sock, head) {
59
- if (!_this.wsServer.shouldHandle(req)) {
60
- return;
61
- }
62
- _this.wsServer.handleUpgrade(req, sock, head, function(connection) {
63
- _this.wsServer.emit("connection", connection, req);
64
- });
65
- });
66
- this.wsServer.on("error", function(err) {
67
- logger.error(err);
68
- });
69
- this.timer = setInterval(function() {
70
- _this.wsServer.clients.forEach(function(socket) {
71
- var extWs = socket;
72
- if (!extWs.isAlive) {
73
- extWs.terminate();
74
- } else {
75
- extWs.isAlive = false;
76
- extWs.ping(function() {});
77
- }
78
- });
79
- }, 3e4);
80
- this.wsServer.on("connection", function(socket) {
81
- _this.onConnect(socket);
82
- });
83
- }
84
- },
85
- {
86
- key: "updateStats",
87
- value: function updateStats(stats) {
88
- this.stats = stats;
89
- this.sendStats();
90
- }
91
- },
92
- {
93
- key: "sockWrite",
94
- value: function sockWrite(type, data) {
95
- var _this = this;
96
- this.sockets.forEach(function(socket) {
97
- _this.send(socket, JSON.stringify({
98
- type: type,
99
- data: data
100
- }));
101
- });
102
- }
103
- },
104
- {
105
- key: "singleWrite",
106
- value: function singleWrite(socket, type, data) {
107
- this.send(socket, JSON.stringify({
108
- type: type,
109
- data: data
110
- }));
111
- }
112
- },
113
- {
114
- key: "close",
115
- value: function close() {
116
- this.sockets.forEach(function(socket) {
117
- socket.close();
118
- });
119
- if (this.timer) {
120
- clearInterval(this.timer);
121
- this.timer = null;
122
- }
123
- }
124
- },
125
- {
126
- key: "onConnect",
127
- value: function onConnect(socket) {
128
- var _this = this;
129
- var connection = socket;
130
- connection.isAlive = true;
131
- connection.on("pong", function() {
132
- connection.isAlive = true;
133
- });
134
- if (!connection) {
135
- return;
136
- }
137
- this.sockets.push(connection);
138
- connection.on("close", function() {
139
- var idx = _this.sockets.indexOf(connection);
140
- if (idx >= 0) {
141
- _this.sockets.splice(idx, 1);
142
- }
143
- });
144
- if (this.options.hot || this.options.hot === "only") {
145
- this.singleWrite(connection, "hot");
146
- }
147
- if (this.options.liveReload) {
148
- this.singleWrite(connection, "liveReload");
149
- }
150
- if (this.stats) {
151
- this.sendStats(true);
152
- }
153
- }
154
- },
155
- {
156
- key: "getStats",
157
- value: function getStats() {
158
- var curStats = this.stats;
159
- if (!curStats) {
160
- return null;
161
- }
162
- var defaultStats = {
163
- all: false,
164
- hash: true,
165
- assets: true,
166
- warnings: true,
167
- errors: true,
168
- errorDetails: false
169
- };
170
- return curStats.toJson(defaultStats);
171
- }
172
- },
173
- {
174
- key: "sendStats",
175
- value: function sendStats() {
176
- var force = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : false;
177
- var stats = this.getStats();
178
- if (!stats) {
179
- return null;
180
- }
181
- var shouldEmit = !force && stats && (!stats.errors || stats.errors.length === 0) && stats.assets && stats.assets.every(function(asset) {
182
- return !asset.emitted;
183
- });
184
- if (shouldEmit) {
185
- return this.sockWrite("still-ok");
186
- }
187
- this.sockWrite("hash", stats.hash);
188
- if (stats.errors && stats.errors.length > 0) {
189
- return this.sockWrite("errors", stats.errors);
190
- } else if (stats.warnings && stats.warnings.length > 0) {
191
- return this.sockWrite("warnings", stats.warnings);
192
- } else {
193
- return this.sockWrite("ok");
194
- }
195
- }
196
- },
197
- {
198
- key: "send",
199
- value: function send(connection, message) {
200
- if (connection.readyState !== 1) {
201
- return;
202
- }
203
- connection.send(message);
204
- }
205
- }
206
- ]);
207
- return SocketServer;
208
- }();
209
- export { SocketServer as default };
@@ -1,193 +0,0 @@
1
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
2
- try {
3
- var info = gen[key](arg);
4
- var value = info.value;
5
- } catch (error) {
6
- reject(error);
7
- return;
8
- }
9
- if (info.done) {
10
- resolve(value);
11
- } else {
12
- Promise.resolve(value).then(_next, _throw);
13
- }
14
- }
15
- function _asyncToGenerator(fn) {
16
- return function() {
17
- var self = this, args = arguments;
18
- return new Promise(function(resolve, reject) {
19
- var gen = fn.apply(self, args);
20
- function _next(value) {
21
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
22
- }
23
- function _throw(err) {
24
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
25
- }
26
- _next(undefined);
27
- });
28
- };
29
- }
30
- var __generator = this && this.__generator || function(thisArg, body) {
31
- var f, y, t, g, _ = {
32
- label: 0,
33
- sent: function() {
34
- if (t[0] & 1) throw t[1];
35
- return t[1];
36
- },
37
- trys: [],
38
- ops: []
39
- };
40
- return(g = {
41
- next: verb(0),
42
- "throw": verb(1),
43
- "return": verb(2)
44
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
45
- return this;
46
- }), g);
47
- function verb(n) {
48
- return function(v) {
49
- return step([
50
- n,
51
- v
52
- ]);
53
- };
54
- }
55
- function step(op) {
56
- if (f) throw new TypeError("Generator is already executing.");
57
- while(_)try {
58
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
59
- if (y = 0, t) op = [
60
- op[0] & 2,
61
- t.value
62
- ];
63
- switch(op[0]){
64
- case 0:
65
- case 1:
66
- t = op;
67
- break;
68
- case 4:
69
- _.label++;
70
- return {
71
- value: op[1],
72
- done: false
73
- };
74
- case 5:
75
- _.label++;
76
- y = op[1];
77
- op = [
78
- 0
79
- ];
80
- continue;
81
- case 7:
82
- op = _.ops.pop();
83
- _.trys.pop();
84
- continue;
85
- default:
86
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
87
- _ = 0;
88
- continue;
89
- }
90
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
91
- _.label = op[1];
92
- break;
93
- }
94
- if (op[0] === 6 && _.label < t[1]) {
95
- _.label = t[1];
96
- t = op;
97
- break;
98
- }
99
- if (t && _.label < t[2]) {
100
- _.label = t[2];
101
- _.ops.push(op);
102
- break;
103
- }
104
- if (t[2]) _.ops.pop();
105
- _.trys.pop();
106
- continue;
107
- }
108
- op = body.call(thisArg, _);
109
- } catch (e) {
110
- op = [
111
- 6,
112
- e
113
- ];
114
- y = 0;
115
- } finally{
116
- f = t = 0;
117
- }
118
- if (op[0] & 5) throw op[1];
119
- return {
120
- value: op[0] ? op[1] : void 0,
121
- done: true
122
- };
123
- }
124
- };
125
- import { chalk, getPackageManager, logger } from "@modern-js/utils";
126
- var genHttpsOptions = function() {
127
- var _ref = _asyncToGenerator(function(userOptions, pwd) {
128
- var httpsOptions, devcertPath, err, packageManager, command, devcert, selfsign;
129
- return __generator(this, function(_state) {
130
- switch(_state.label){
131
- case 0:
132
- httpsOptions = typeof userOptions === "boolean" ? {} : userOptions;
133
- if (!(!httpsOptions.key || !httpsOptions.cert)) return [
134
- 3,
135
- 6
136
- ];
137
- _state.label = 1;
138
- case 1:
139
- _state.trys.push([
140
- 1,
141
- 2,
142
- ,
143
- 4
144
- ]);
145
- devcertPath = require.resolve("devcert", {
146
- paths: [
147
- pwd,
148
- __dirname
149
- ]
150
- });
151
- return [
152
- 3,
153
- 4
154
- ];
155
- case 2:
156
- err = _state.sent();
157
- return [
158
- 4,
159
- getPackageManager(pwd)
160
- ];
161
- case 3:
162
- packageManager = _state.sent();
163
- command = chalk.yellow.bold("".concat(packageManager, " install devcert@1.2.2 -D"));
164
- logger.error('You have enabled "dev.https" option, but the "devcert" package is not installed.');
165
- logger.error("Please run ".concat(command, " to install manually, otherwise the https can not work."));
166
- throw new Error('[https] "devcert" is not found.');
167
- case 4:
168
- devcert = require(devcertPath);
169
- return [
170
- 4,
171
- devcert.certificateFor([
172
- "localhost"
173
- ])
174
- ];
175
- case 5:
176
- selfsign = _state.sent();
177
- return [
178
- 2,
179
- selfsign
180
- ];
181
- case 6:
182
- return [
183
- 2,
184
- httpsOptions
185
- ];
186
- }
187
- });
188
- });
189
- return function genHttpsOptions(userOptions, pwd) {
190
- return _ref.apply(this, arguments);
191
- };
192
- }();
193
- export { genHttpsOptions };