@modern-js/server 2.6.1-alpha.0 → 2.7.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 (50) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/package.json +10 -10
  3. package/dist/js/modern/constants.js +0 -19
  4. package/dist/js/modern/dev-tools/dev-middleware/hmr-client/createSocketUrl.js +0 -41
  5. package/dist/js/modern/dev-tools/dev-middleware/hmr-client/index.js +0 -146
  6. package/dist/js/modern/dev-tools/dev-middleware/index.js +0 -94
  7. package/dist/js/modern/dev-tools/dev-middleware/socket-server.js +0 -132
  8. package/dist/js/modern/dev-tools/https/index.js +0 -49
  9. package/dist/js/modern/dev-tools/mock/getMockData.js +0 -105
  10. package/dist/js/modern/dev-tools/mock/index.js +0 -70
  11. package/dist/js/modern/dev-tools/register/index.js +0 -112
  12. package/dist/js/modern/dev-tools/watcher/dependency-tree.js +0 -59
  13. package/dist/js/modern/dev-tools/watcher/index.js +0 -106
  14. package/dist/js/modern/dev-tools/watcher/stats-cache.js +0 -58
  15. package/dist/js/modern/index.js +0 -12
  16. package/dist/js/modern/server/dev-server.js +0 -294
  17. package/dist/js/modern/server/index.js +0 -16
  18. package/dist/js/modern/types.js +0 -0
  19. package/dist/js/node/constants.js +0 -42
  20. package/dist/js/node/dev-tools/dev-middleware/hmr-client/createSocketUrl.js +0 -65
  21. package/dist/js/node/dev-tools/dev-middleware/hmr-client/index.js +0 -155
  22. package/dist/js/node/dev-tools/dev-middleware/index.js +0 -119
  23. package/dist/js/node/dev-tools/dev-middleware/socket-server.js +0 -159
  24. package/dist/js/node/dev-tools/https/index.js +0 -72
  25. package/dist/js/node/dev-tools/mock/getMockData.js +0 -126
  26. package/dist/js/node/dev-tools/mock/index.js +0 -99
  27. package/dist/js/node/dev-tools/register/index.js +0 -139
  28. package/dist/js/node/dev-tools/watcher/dependency-tree.js +0 -89
  29. package/dist/js/node/dev-tools/watcher/index.js +0 -135
  30. package/dist/js/node/dev-tools/watcher/stats-cache.js +0 -87
  31. package/dist/js/node/index.js +0 -35
  32. package/dist/js/node/server/dev-server.js +0 -311
  33. package/dist/js/node/server/index.js +0 -39
  34. package/dist/js/node/types.js +0 -15
  35. package/dist/js/treeshaking/constants.js +0 -21
  36. package/dist/js/treeshaking/dev-tools/dev-middleware/hmr-client/createSocketUrl.js +0 -51
  37. package/dist/js/treeshaking/dev-tools/dev-middleware/hmr-client/index.js +0 -162
  38. package/dist/js/treeshaking/dev-tools/dev-middleware/index.js +0 -322
  39. package/dist/js/treeshaking/dev-tools/dev-middleware/socket-server.js +0 -209
  40. package/dist/js/treeshaking/dev-tools/https/index.js +0 -193
  41. package/dist/js/treeshaking/dev-tools/mock/getMockData.js +0 -318
  42. package/dist/js/treeshaking/dev-tools/mock/index.js +0 -207
  43. package/dist/js/treeshaking/dev-tools/register/index.js +0 -154
  44. package/dist/js/treeshaking/dev-tools/watcher/dependency-tree.js +0 -150
  45. package/dist/js/treeshaking/dev-tools/watcher/index.js +0 -200
  46. package/dist/js/treeshaking/dev-tools/watcher/stats-cache.js +0 -128
  47. package/dist/js/treeshaking/index.js +0 -9
  48. package/dist/js/treeshaking/server/dev-server.js +0 -800
  49. package/dist/js/treeshaking/server/index.js +0 -92
  50. package/dist/js/treeshaking/types.js +0 -1
@@ -1,51 +0,0 @@
1
- import { HMR_SOCK_PATH } from "@modern-js/utils/constants";
2
- function createSocketUrl(resourceQuery) {
3
- var searchParams = resourceQuery.substr(1).split("&");
4
- var options = {};
5
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
6
- try {
7
- for(var _iterator = searchParams[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
8
- var pair = _step.value;
9
- var ary = pair.split("=");
10
- options[ary[0]] = decodeURIComponent(ary[1]);
11
- }
12
- } catch (err) {
13
- _didIteratorError = true;
14
- _iteratorError = err;
15
- } finally{
16
- try {
17
- if (!_iteratorNormalCompletion && _iterator.return != null) {
18
- _iterator.return();
19
- }
20
- } finally{
21
- if (_didIteratorError) {
22
- throw _iteratorError;
23
- }
24
- }
25
- }
26
- var currentLocation = self.location;
27
- return getSocketUrl(options, currentLocation);
28
- }
29
- function formatURL(param) {
30
- var port = param.port, protocol = param.protocol, hostname = param.hostname, pathname = param.pathname;
31
- if (window.URL) {
32
- var url = new URL("http://localhost");
33
- url.port = port;
34
- url.hostname = hostname;
35
- url.protocol = protocol;
36
- url.pathname = pathname;
37
- return url.toString();
38
- }
39
- var colon = protocol.indexOf(":") === -1 ? ":" : "";
40
- return "".concat(protocol).concat(colon, "//").concat(hostname, ":").concat(port).concat(pathname);
41
- }
42
- function getSocketUrl(urlParts, location) {
43
- var host = urlParts.host, port = urlParts.port, path = urlParts.path, protocol = urlParts.protocol;
44
- return formatURL({
45
- protocol: protocol || (location.protocol === "https:" ? "wss" : "ws"),
46
- hostname: host || location.hostname,
47
- port: port || location.port,
48
- pathname: path || HMR_SOCK_PATH
49
- });
50
- }
51
- export { createSocketUrl, formatURL };
@@ -1,162 +0,0 @@
1
- var __getOwnPropNames = Object.getOwnPropertyNames;
2
- var __commonJS = function(cb, mod) {
3
- return function __require() {
4
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = {
5
- exports: {}
6
- }).exports, mod), mod.exports;
7
- };
8
- };
9
- import stripAnsi from "@modern-js/utils/strip-ansi";
10
- import { formatWebpackMessages } from "@modern-js/utils/format";
11
- import { createSocketUrl } from "./createSocketUrl";
12
- var require_hmr_client = __commonJS({
13
- "src/dev-tools/dev-middleware/hmr-client/index.ts": function(exports, module) {
14
- var clearOutdatedErrors = function clearOutdatedErrors() {
15
- if (typeof console !== "undefined" && typeof console.clear === "function") {
16
- if (hasCompileErrors) {
17
- console.clear();
18
- }
19
- }
20
- };
21
- var handleSuccess = function handleSuccess() {
22
- clearOutdatedErrors();
23
- var isHotUpdate = !isFirstCompilation;
24
- isFirstCompilation = false;
25
- hasCompileErrors = false;
26
- if (isHotUpdate) {
27
- tryApplyUpdates();
28
- }
29
- };
30
- var handleWarnings = function handleWarnings(warnings) {
31
- clearOutdatedErrors();
32
- var isHotUpdate = !isFirstCompilation;
33
- isFirstCompilation = false;
34
- hasCompileErrors = false;
35
- function printWarnings() {
36
- var formatted = formatWebpackMessages({
37
- warnings: warnings,
38
- errors: []
39
- });
40
- if (typeof console !== "undefined" && typeof console.warn === "function") {
41
- for(var i = 0; i < formatted.warnings.length; i++){
42
- if (i === 5) {
43
- console.warn("There were more warnings in other files.\nYou can find a complete log in the terminal.");
44
- break;
45
- }
46
- console.warn(stripAnsi(formatted.warnings[i]));
47
- }
48
- }
49
- }
50
- printWarnings();
51
- if (isHotUpdate) {
52
- tryApplyUpdates();
53
- }
54
- };
55
- var handleErrors = function handleErrors(errors) {
56
- clearOutdatedErrors();
57
- isFirstCompilation = false;
58
- hasCompileErrors = true;
59
- var formatted = formatWebpackMessages({
60
- errors: errors,
61
- warnings: []
62
- });
63
- if (typeof console !== "undefined" && typeof console.error === "function") {
64
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
65
- try {
66
- for(var _iterator = formatted.errors[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
67
- var error = _step.value;
68
- console.error(stripAnsi(error));
69
- }
70
- } catch (err) {
71
- _didIteratorError = true;
72
- _iteratorError = err;
73
- } finally{
74
- try {
75
- if (!_iteratorNormalCompletion && _iterator.return != null) {
76
- _iterator.return();
77
- }
78
- } finally{
79
- if (_didIteratorError) {
80
- throw _iteratorError;
81
- }
82
- }
83
- }
84
- }
85
- };
86
- var handleAvailableHash = function handleAvailableHash(hash) {
87
- mostRecentCompilationHash = hash;
88
- };
89
- var isUpdateAvailable = function isUpdateAvailable() {
90
- return mostRecentCompilationHash !== __webpack_hash__;
91
- };
92
- var canApplyUpdates = function canApplyUpdates() {
93
- return module.hot.status() === "idle";
94
- };
95
- var hadRuntimeError = false;
96
- var socketUrl = createSocketUrl(__resourceQuery);
97
- var connection = new WebSocket(socketUrl);
98
- connection.onopen = function() {
99
- if (typeof console !== "undefined" && typeof console.debug === "function") {
100
- console.debug("[HMR] connected.");
101
- }
102
- };
103
- connection.onclose = function() {
104
- if (typeof console !== "undefined" && typeof console.info === "function") {
105
- console.debug("[HMR] disconnected. Refresh the page if necessary.");
106
- }
107
- };
108
- var isFirstCompilation = true;
109
- var mostRecentCompilationHash = null;
110
- var hasCompileErrors = false;
111
- connection.onmessage = function(e) {
112
- var message = JSON.parse(e.data);
113
- switch(message.type){
114
- case "hash":
115
- handleAvailableHash(message.data);
116
- break;
117
- case "still-ok":
118
- case "ok":
119
- handleSuccess();
120
- break;
121
- case "content-changed":
122
- window.location.reload();
123
- break;
124
- case "warnings":
125
- handleWarnings(message.data);
126
- break;
127
- case "errors":
128
- handleErrors(message.data);
129
- break;
130
- default:
131
- }
132
- };
133
- function tryApplyUpdates() {
134
- if (!module.hot) {
135
- window.location.reload();
136
- return;
137
- }
138
- if (!isUpdateAvailable() || !canApplyUpdates()) {
139
- return;
140
- }
141
- function handleApplyUpdates(err, updatedModules) {
142
- var wantsForcedReload = err || !updatedModules || hadRuntimeError;
143
- if (wantsForcedReload) {
144
- window.location.reload();
145
- return;
146
- }
147
- if (isUpdateAvailable()) {
148
- tryApplyUpdates();
149
- }
150
- }
151
- var result = module.hot.check(true, handleApplyUpdates);
152
- if (result === null || result === void 0 ? void 0 : result.then) {
153
- result.then(function(updatedModules) {
154
- handleApplyUpdates(null, updatedModules);
155
- }, function(err) {
156
- handleApplyUpdates(err, null);
157
- });
158
- }
159
- }
160
- }
161
- });
162
- export default require_hmr_client();
@@ -1,322 +0,0 @@
1
- function _assertThisInitialized(self) {
2
- if (self === void 0) {
3
- throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
4
- }
5
- return self;
6
- }
7
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
8
- try {
9
- var info = gen[key](arg);
10
- var value = info.value;
11
- } catch (error) {
12
- reject(error);
13
- return;
14
- }
15
- if (info.done) {
16
- resolve(value);
17
- } else {
18
- Promise.resolve(value).then(_next, _throw);
19
- }
20
- }
21
- function _asyncToGenerator(fn) {
22
- return function() {
23
- var self = this, args = arguments;
24
- return new Promise(function(resolve, reject) {
25
- var gen = fn.apply(self, args);
26
- function _next(value) {
27
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
28
- }
29
- function _throw(err) {
30
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
31
- }
32
- _next(undefined);
33
- });
34
- };
35
- }
36
- function _classCallCheck(instance, Constructor) {
37
- if (!(instance instanceof Constructor)) {
38
- throw new TypeError("Cannot call a class as a function");
39
- }
40
- }
41
- function _defineProperties(target, props) {
42
- for(var i = 0; i < props.length; i++){
43
- var descriptor = props[i];
44
- descriptor.enumerable = descriptor.enumerable || false;
45
- descriptor.configurable = true;
46
- if ("value" in descriptor) descriptor.writable = true;
47
- Object.defineProperty(target, descriptor.key, descriptor);
48
- }
49
- }
50
- function _createClass(Constructor, protoProps, staticProps) {
51
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
52
- if (staticProps) _defineProperties(Constructor, staticProps);
53
- return Constructor;
54
- }
55
- function _defineProperty(obj, key, value) {
56
- if (key in obj) {
57
- Object.defineProperty(obj, key, {
58
- value: value,
59
- enumerable: true,
60
- configurable: true,
61
- writable: true
62
- });
63
- } else {
64
- obj[key] = value;
65
- }
66
- return obj;
67
- }
68
- function _getPrototypeOf(o) {
69
- _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
70
- return o.__proto__ || Object.getPrototypeOf(o);
71
- };
72
- return _getPrototypeOf(o);
73
- }
74
- function _inherits(subClass, superClass) {
75
- if (typeof superClass !== "function" && superClass !== null) {
76
- throw new TypeError("Super expression must either be null or a function");
77
- }
78
- subClass.prototype = Object.create(superClass && superClass.prototype, {
79
- constructor: {
80
- value: subClass,
81
- writable: true,
82
- configurable: true
83
- }
84
- });
85
- if (superClass) _setPrototypeOf(subClass, superClass);
86
- }
87
- function _objectSpread(target) {
88
- for(var i = 1; i < arguments.length; i++){
89
- var source = arguments[i] != null ? arguments[i] : {};
90
- var ownKeys = Object.keys(source);
91
- if (typeof Object.getOwnPropertySymbols === "function") {
92
- ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
93
- return Object.getOwnPropertyDescriptor(source, sym).enumerable;
94
- }));
95
- }
96
- ownKeys.forEach(function(key) {
97
- _defineProperty(target, key, source[key]);
98
- });
99
- }
100
- return target;
101
- }
102
- function _possibleConstructorReturn(self, call) {
103
- if (call && (_typeof(call) === "object" || typeof call === "function")) {
104
- return call;
105
- }
106
- return _assertThisInitialized(self);
107
- }
108
- function _setPrototypeOf(o, p) {
109
- _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
110
- o.__proto__ = p;
111
- return o;
112
- };
113
- return _setPrototypeOf(o, p);
114
- }
115
- var _typeof = function(obj) {
116
- "@swc/helpers - typeof";
117
- return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
118
- };
119
- function _isNativeReflectConstruct() {
120
- if (typeof Reflect === "undefined" || !Reflect.construct) return false;
121
- if (Reflect.construct.sham) return false;
122
- if (typeof Proxy === "function") return true;
123
- try {
124
- Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
125
- return true;
126
- } catch (e) {
127
- return false;
128
- }
129
- }
130
- function _createSuper(Derived) {
131
- var hasNativeReflectConstruct = _isNativeReflectConstruct();
132
- return function _createSuperInternal() {
133
- var Super = _getPrototypeOf(Derived), result;
134
- if (hasNativeReflectConstruct) {
135
- var NewTarget = _getPrototypeOf(this).constructor;
136
- result = Reflect.construct(Super, arguments, NewTarget);
137
- } else {
138
- result = Super.apply(this, arguments);
139
- }
140
- return _possibleConstructorReturn(this, result);
141
- };
142
- }
143
- var __generator = this && this.__generator || function(thisArg, body) {
144
- var f, y, t, g, _ = {
145
- label: 0,
146
- sent: function() {
147
- if (t[0] & 1) throw t[1];
148
- return t[1];
149
- },
150
- trys: [],
151
- ops: []
152
- };
153
- return g = {
154
- next: verb(0),
155
- "throw": verb(1),
156
- "return": verb(2)
157
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
158
- return this;
159
- }), g;
160
- function verb(n) {
161
- return function(v) {
162
- return step([
163
- n,
164
- v
165
- ]);
166
- };
167
- }
168
- function step(op) {
169
- if (f) throw new TypeError("Generator is already executing.");
170
- while(_)try {
171
- 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;
172
- if (y = 0, t) op = [
173
- op[0] & 2,
174
- t.value
175
- ];
176
- switch(op[0]){
177
- case 0:
178
- case 1:
179
- t = op;
180
- break;
181
- case 4:
182
- _.label++;
183
- return {
184
- value: op[1],
185
- done: false
186
- };
187
- case 5:
188
- _.label++;
189
- y = op[1];
190
- op = [
191
- 0
192
- ];
193
- continue;
194
- case 7:
195
- op = _.ops.pop();
196
- _.trys.pop();
197
- continue;
198
- default:
199
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
200
- _ = 0;
201
- continue;
202
- }
203
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
204
- _.label = op[1];
205
- break;
206
- }
207
- if (op[0] === 6 && _.label < t[1]) {
208
- _.label = t[1];
209
- t = op;
210
- break;
211
- }
212
- if (t && _.label < t[2]) {
213
- _.label = t[2];
214
- _.ops.push(op);
215
- break;
216
- }
217
- if (t[2]) _.ops.pop();
218
- _.trys.pop();
219
- continue;
220
- }
221
- op = body.call(thisArg, _);
222
- } catch (e) {
223
- op = [
224
- 6,
225
- e
226
- ];
227
- y = 0;
228
- } finally{
229
- f = t = 0;
230
- }
231
- if (op[0] & 5) throw op[1];
232
- return {
233
- value: op[0] ? op[1] : void 0,
234
- done: true
235
- };
236
- }
237
- };
238
- import { EventEmitter } from "events";
239
- import SocketServer from "./socket-server";
240
- var noop = function() {};
241
- function getHMRClientPath(client) {
242
- var protocol = (client === null || client === void 0 ? void 0 : client.protocol) ? "&protocol=".concat(client.protocol) : "";
243
- var host = (client === null || client === void 0 ? void 0 : client.host) ? "&host=".concat(client.host) : "";
244
- var path = (client === null || client === void 0 ? void 0 : client.path) ? "&path=".concat(client.path) : "";
245
- var port = (client === null || client === void 0 ? void 0 : client.port) ? "&port=".concat(client.port) : "";
246
- var clientEntry = "".concat(require.resolve("./hmr-client"), "?").concat(host).concat(path).concat(port).concat(protocol);
247
- return clientEntry;
248
- }
249
- var DevMiddleware = /*#__PURE__*/ function(EventEmitter) {
250
- "use strict";
251
- _inherits(DevMiddleware, EventEmitter);
252
- var _super = _createSuper(DevMiddleware);
253
- function DevMiddleware(param) {
254
- var dev = param.dev, devMiddleware = param.devMiddleware;
255
- _classCallCheck(this, DevMiddleware);
256
- var _this;
257
- _this = _super.call(this);
258
- _defineProperty(_assertThisInitialized(_this), "middleware", void 0);
259
- _defineProperty(_assertThisInitialized(_this), "devOptions", void 0);
260
- _defineProperty(_assertThisInitialized(_this), "socketServer", void 0);
261
- _this.devOptions = dev;
262
- _this.socketServer = new SocketServer(dev);
263
- if (devMiddleware) {
264
- _this.middleware = _this.setupDevMiddleware(devMiddleware);
265
- }
266
- return _this;
267
- }
268
- _createClass(DevMiddleware, [
269
- {
270
- key: "init",
271
- value: function init(app) {
272
- var _this = this;
273
- app.on("listening", function() {
274
- _this.socketServer.prepare(app);
275
- });
276
- var _this1 = this;
277
- app.on("close", /*#__PURE__*/ _asyncToGenerator(function() {
278
- var _this_middleware;
279
- return __generator(this, function(_state) {
280
- (_this_middleware = _this1.middleware) === null || _this_middleware === void 0 ? void 0 : _this_middleware.close(noop);
281
- _this1.socketServer.close();
282
- return [
283
- 2
284
- ];
285
- });
286
- }));
287
- }
288
- },
289
- {
290
- key: "sockWrite",
291
- value: function sockWrite(type, data) {
292
- this.socketServer.sockWrite(type, data);
293
- }
294
- },
295
- {
296
- key: "setupDevMiddleware",
297
- value: function setupDevMiddleware(devMiddleware) {
298
- var _this = this;
299
- var devOptions = this.devOptions;
300
- var callbacks = {
301
- onInvalid: function() {
302
- _this.socketServer.sockWrite("invalid");
303
- },
304
- onDone: function(stats) {
305
- _this.socketServer.updateStats(stats);
306
- _this.emit("change", stats);
307
- }
308
- };
309
- var enableHMR = this.devOptions.hot || this.devOptions.liveReload;
310
- var middleware = devMiddleware(_objectSpread({
311
- headers: devOptions.headers,
312
- stats: false,
313
- callbacks: callbacks,
314
- hmrClientPath: enableHMR ? getHMRClientPath(devOptions.client) : void 0
315
- }, devOptions.devMiddleware));
316
- return middleware;
317
- }
318
- }
319
- ]);
320
- return DevMiddleware;
321
- }(EventEmitter);
322
- export { DevMiddleware as default };