@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.
Files changed (36) hide show
  1. package/CHANGELOG.md +99 -0
  2. package/dist/js/modern/dev-tools/dev-middleware/hmr-client/index.js +2 -2
  3. package/dist/js/modern/dev-tools/dev-middleware/index.js +22 -52
  4. package/dist/js/modern/dev-tools/https/index.js +19 -2
  5. package/dist/js/modern/index.js +1 -1
  6. package/dist/js/modern/server/dev-server.js +1 -2
  7. package/dist/js/node/constants.js +7 -3
  8. package/dist/js/node/dev-tools/dev-middleware/hmr-client/createSocketUrl.js +8 -3
  9. package/dist/js/node/dev-tools/dev-middleware/hmr-client/index.js +2 -2
  10. package/dist/js/node/dev-tools/dev-middleware/index.js +45 -75
  11. package/dist/js/node/dev-tools/dev-middleware/socket-server.js +5 -3
  12. package/dist/js/node/dev-tools/https/index.js +28 -13
  13. package/dist/js/node/dev-tools/mock/getMockData.js +29 -27
  14. package/dist/js/node/dev-tools/mock/index.js +13 -9
  15. package/dist/js/node/dev-tools/register/index.js +24 -22
  16. package/dist/js/node/dev-tools/watcher/dependency-tree.js +8 -3
  17. package/dist/js/node/dev-tools/watcher/index.js +23 -19
  18. package/dist/js/node/dev-tools/watcher/stats-cache.js +7 -3
  19. package/dist/js/node/index.js +8 -4
  20. package/dist/js/node/server/dev-server.js +39 -54
  21. package/dist/js/node/server/index.js +7 -3
  22. package/dist/js/node/types.js +15 -0
  23. package/dist/js/treeshaking/dev-tools/dev-middleware/hmr-client/index.js +156 -156
  24. package/dist/js/treeshaking/dev-tools/dev-middleware/index.js +23 -65
  25. package/dist/js/treeshaking/dev-tools/https/index.js +39 -7
  26. package/dist/js/treeshaking/index.js +1 -1
  27. package/dist/js/treeshaking/server/dev-server.js +1 -2
  28. package/dist/types/dev-tools/dev-middleware/index.d.ts +1 -8
  29. package/dist/types/dev-tools/https/index.d.ts +1 -1
  30. package/dist/types/types.d.ts +22 -5
  31. package/package.json +13 -10
  32. package/dist/js/modern/dev-tools/dev-middleware/dev-server-plugin.js +0 -32
  33. package/dist/js/node/dev-tools/dev-middleware/dev-server-plugin.js +0 -57
  34. package/dist/js/treeshaking/dev-tools/dev-middleware/dev-server-plugin.js +0 -74
  35. package/dist/types/dev-tools/dev-middleware/dev-server-plugin.d.ts +0 -8
  36. package/temp-fix-hmr.js +0 -483
package/temp-fix-hmr.js DELETED
@@ -1,483 +0,0 @@
1
- // FIXME: 临时修复 HMR 代码
2
- // TODO: 修复 HMR 问题后移除
3
- // eslint-disable-next-line eslint-comments/disable-enable-pair
4
- /* eslint-disable max-lines */
5
-
6
- const path = require('path');
7
- const { fs } = require('@modern-js/utils');
8
-
9
- fs.outputFileSync(
10
- path.join(
11
- __dirname,
12
- 'dist/js/node/dev-tools/dev-middleware/hmr-client/index.js',
13
- ),
14
- `var __create = Object.create;
15
- var __defProp = Object.defineProperty;
16
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
17
- var __getOwnPropNames = Object.getOwnPropertyNames;
18
- var __getProtoOf = Object.getPrototypeOf;
19
- var __hasOwnProp = Object.prototype.hasOwnProperty;
20
- var __copyProps = (to, from, except, desc) => {
21
- if (from && typeof from === "object" || typeof from === "function") {
22
- for (let key of __getOwnPropNames(from))
23
- if (!__hasOwnProp.call(to, key) && key !== except)
24
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
25
- }
26
- return to;
27
- };
28
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
29
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
30
- mod
31
- ));
32
- var import_strip_ansi = __toESM(require("@modern-js/utils/strip-ansi"));
33
- var import_format = require("@modern-js/utils/format");
34
- var import_createSocketUrl = require("./createSocketUrl");
35
- const hadRuntimeError = false;
36
- const socketUrl = (0, import_createSocketUrl.createSocketUrl)(__resourceQuery);
37
- const connection = new WebSocket(socketUrl);
38
- connection.onclose = function() {
39
- if (typeof console !== "undefined" && typeof console.info === "function") {
40
- console.info(
41
- "The development server has disconnected. Refresh the page if necessary."
42
- );
43
- }
44
- };
45
- let isFirstCompilation = true;
46
- let mostRecentCompilationHash = null;
47
- let hasCompileErrors = false;
48
- function clearOutdatedErrors() {
49
- if (typeof console !== "undefined" && typeof console.clear === "function") {
50
- if (hasCompileErrors) {
51
- console.clear();
52
- }
53
- }
54
- }
55
- function handleSuccess() {
56
- clearOutdatedErrors();
57
- const isHotUpdate = !isFirstCompilation;
58
- isFirstCompilation = false;
59
- hasCompileErrors = false;
60
- if (isHotUpdate) {
61
- tryApplyUpdates();
62
- }
63
- }
64
- function handleWarnings(warnings) {
65
- clearOutdatedErrors();
66
- const isHotUpdate = !isFirstCompilation;
67
- isFirstCompilation = false;
68
- hasCompileErrors = false;
69
- function printWarnings() {
70
- const formatted = (0, import_format.formatWebpackMessages)({
71
- warnings,
72
- errors: []
73
- });
74
- if (typeof console !== "undefined" && typeof console.warn === "function") {
75
- for (let i = 0; i < formatted.warnings.length; i++) {
76
- if (i === 5) {
77
- console.warn(
78
- "There were more warnings in other files. You can find a complete log in the terminal."
79
- );
80
- break;
81
- }
82
- console.warn((0, import_strip_ansi.default)(formatted.warnings[i]));
83
- }
84
- }
85
- }
86
- printWarnings();
87
- if (isHotUpdate) {
88
- tryApplyUpdates();
89
- }
90
- }
91
- function handleErrors(errors) {
92
- clearOutdatedErrors();
93
- isFirstCompilation = false;
94
- hasCompileErrors = true;
95
- const formatted = (0, import_format.formatWebpackMessages)({
96
- errors,
97
- warnings: []
98
- });
99
- if (typeof console !== "undefined" && typeof console.error === "function") {
100
- for (const error of formatted.errors) {
101
- console.error((0, import_strip_ansi.default)(error));
102
- }
103
- }
104
- }
105
- function handleAvailableHash(hash) {
106
- mostRecentCompilationHash = hash;
107
- }
108
- connection.onmessage = function(e) {
109
- const message = JSON.parse(e.data);
110
- switch (message.type) {
111
- case "hash":
112
- handleAvailableHash(message.data);
113
- break;
114
- case "still-ok":
115
- case "ok":
116
- handleSuccess();
117
- break;
118
- case "content-changed":
119
- window.location.reload();
120
- break;
121
- case "warnings":
122
- handleWarnings(message.data);
123
- break;
124
- case "errors":
125
- handleErrors(message.data);
126
- break;
127
- default:
128
- }
129
- };
130
- function isUpdateAvailable() {
131
- return mostRecentCompilationHash !== __webpack_hash__;
132
- }
133
- function canApplyUpdates() {
134
- return module.hot.status() === "idle";
135
- }
136
- function tryApplyUpdates() {
137
- if (!module.hot) {
138
- window.location.reload();
139
- return;
140
- }
141
- if (!isUpdateAvailable() || !canApplyUpdates()) {
142
- return;
143
- }
144
- function handleApplyUpdates(err, updatedModules) {
145
- const wantsForcedReload = err || !updatedModules || hadRuntimeError;
146
- if (wantsForcedReload) {
147
- window.location.reload();
148
- return;
149
- }
150
- if (isUpdateAvailable()) {
151
- tryApplyUpdates();
152
- }
153
- }
154
- const result = module.hot.check(true, handleApplyUpdates);
155
- if (result == null ? void 0 : result.then) {
156
- result.then(
157
- (updatedModules) => {
158
- handleApplyUpdates(null, updatedModules);
159
- },
160
- (err) => {
161
- handleApplyUpdates(err, null);
162
- }
163
- );
164
- }
165
- }
166
- `,
167
- );
168
-
169
- fs.outputFileSync(
170
- path.join(
171
- __dirname,
172
- 'dist/js/modern/dev-tools/dev-middleware/hmr-client/index.js',
173
- ),
174
- `var __getOwnPropNames = Object.getOwnPropertyNames;
175
- var __commonJS = (cb, mod) => function __require() {
176
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
177
- };
178
- import stripAnsi from "@modern-js/utils/strip-ansi";
179
- import { formatWebpackMessages } from "@modern-js/utils/format";
180
- import { createSocketUrl } from "./createSocketUrl";
181
- var require_hmr_client = __commonJS({
182
- "src/dev-tools/dev-middleware/hmr-client/index.ts"(exports, module) {
183
- const hadRuntimeError = false;
184
- const socketUrl = createSocketUrl(__resourceQuery);
185
- const connection = new WebSocket(socketUrl);
186
- connection.onclose = function() {
187
- if (typeof console !== "undefined" && typeof console.info === "function") {
188
- console.info(
189
- "The development server has disconnected. Refresh the page if necessary."
190
- );
191
- }
192
- };
193
- let isFirstCompilation = true;
194
- let mostRecentCompilationHash = null;
195
- let hasCompileErrors = false;
196
- function clearOutdatedErrors() {
197
- if (typeof console !== "undefined" && typeof console.clear === "function") {
198
- if (hasCompileErrors) {
199
- console.clear();
200
- }
201
- }
202
- }
203
- function handleSuccess() {
204
- clearOutdatedErrors();
205
- const isHotUpdate = !isFirstCompilation;
206
- isFirstCompilation = false;
207
- hasCompileErrors = false;
208
- if (isHotUpdate) {
209
- tryApplyUpdates();
210
- }
211
- }
212
- function handleWarnings(warnings) {
213
- clearOutdatedErrors();
214
- const isHotUpdate = !isFirstCompilation;
215
- isFirstCompilation = false;
216
- hasCompileErrors = false;
217
- function printWarnings() {
218
- const formatted = formatWebpackMessages({
219
- warnings,
220
- errors: []
221
- });
222
- if (typeof console !== "undefined" && typeof console.warn === "function") {
223
- for (let i = 0; i < formatted.warnings.length; i++) {
224
- if (i === 5) {
225
- console.warn(
226
- "There were more warnings in other files. You can find a complete log in the terminal."
227
- );
228
- break;
229
- }
230
- console.warn(stripAnsi(formatted.warnings[i]));
231
- }
232
- }
233
- }
234
- printWarnings();
235
- if (isHotUpdate) {
236
- tryApplyUpdates();
237
- }
238
- }
239
- function handleErrors(errors) {
240
- clearOutdatedErrors();
241
- isFirstCompilation = false;
242
- hasCompileErrors = true;
243
- const formatted = formatWebpackMessages({
244
- errors,
245
- warnings: []
246
- });
247
- if (typeof console !== "undefined" && typeof console.error === "function") {
248
- for (const error of formatted.errors) {
249
- console.error(stripAnsi(error));
250
- }
251
- }
252
- }
253
- function handleAvailableHash(hash) {
254
- mostRecentCompilationHash = hash;
255
- }
256
- connection.onmessage = function(e) {
257
- const message = JSON.parse(e.data);
258
- switch (message.type) {
259
- case "hash":
260
- handleAvailableHash(message.data);
261
- break;
262
- case "still-ok":
263
- case "ok":
264
- handleSuccess();
265
- break;
266
- case "content-changed":
267
- window.location.reload();
268
- break;
269
- case "warnings":
270
- handleWarnings(message.data);
271
- break;
272
- case "errors":
273
- handleErrors(message.data);
274
- break;
275
- default:
276
- }
277
- };
278
- function isUpdateAvailable() {
279
- return mostRecentCompilationHash !== __webpack_hash__;
280
- }
281
- function canApplyUpdates() {
282
- return module.hot.status() === "idle";
283
- }
284
- function tryApplyUpdates() {
285
- if (!module.hot) {
286
- window.location.reload();
287
- return;
288
- }
289
- if (!isUpdateAvailable() || !canApplyUpdates()) {
290
- return;
291
- }
292
- function handleApplyUpdates(err, updatedModules) {
293
- const wantsForcedReload = err || !updatedModules || hadRuntimeError;
294
- if (wantsForcedReload) {
295
- window.location.reload();
296
- return;
297
- }
298
- if (isUpdateAvailable()) {
299
- tryApplyUpdates();
300
- }
301
- }
302
- const result = module.hot.check(true, handleApplyUpdates);
303
- if (result == null ? void 0 : result.then) {
304
- result.then(
305
- (updatedModules) => {
306
- handleApplyUpdates(null, updatedModules);
307
- },
308
- (err) => {
309
- handleApplyUpdates(err, null);
310
- }
311
- );
312
- }
313
- }
314
- }
315
- });
316
- export default require_hmr_client();
317
- `,
318
- );
319
-
320
- fs.outputFileSync(
321
- path.join(
322
- __dirname,
323
- 'dist/js/treeshaking/dev-tools/dev-middleware/hmr-client/index.js',
324
- ),
325
- `var __getOwnPropNames = Object.getOwnPropertyNames;
326
- var __commonJS = function(cb, mod) {
327
- return function __require() {
328
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = {
329
- exports: {}
330
- }).exports, mod), mod.exports;
331
- };
332
- };
333
- import stripAnsi from "@modern-js/utils/strip-ansi";
334
- import { formatWebpackMessages } from "@modern-js/utils/format";
335
- import { createSocketUrl } from "./createSocketUrl";
336
- var require_hmr_client = __commonJS({
337
- "src/dev-tools/dev-middleware/hmr-client/index.ts": function(exports, module) {
338
- var clearOutdatedErrors = function clearOutdatedErrors() {
339
- if (typeof console !== "undefined" && typeof console.clear === "function") {
340
- if (hasCompileErrors) {
341
- console.clear();
342
- }
343
- }
344
- };
345
- var handleSuccess = function handleSuccess() {
346
- clearOutdatedErrors();
347
- var isHotUpdate = !isFirstCompilation;
348
- isFirstCompilation = false;
349
- hasCompileErrors = false;
350
- if (isHotUpdate) {
351
- tryApplyUpdates();
352
- }
353
- };
354
- var handleWarnings = function handleWarnings(warnings) {
355
- clearOutdatedErrors();
356
- var isHotUpdate = !isFirstCompilation;
357
- isFirstCompilation = false;
358
- hasCompileErrors = false;
359
- function printWarnings() {
360
- var formatted = formatWebpackMessages({
361
- warnings: warnings,
362
- errors: []
363
- });
364
- if (typeof console !== "undefined" && typeof console.warn === "function") {
365
- for(var i = 0; i < formatted.warnings.length; i++){
366
- if (i === 5) {
367
- console.warn("There were more warnings in other files. You can find a complete log in the terminal.");
368
- break;
369
- }
370
- console.warn(stripAnsi(formatted.warnings[i]));
371
- }
372
- }
373
- }
374
- printWarnings();
375
- if (isHotUpdate) {
376
- tryApplyUpdates();
377
- }
378
- };
379
- var handleErrors = function handleErrors(errors) {
380
- clearOutdatedErrors();
381
- isFirstCompilation = false;
382
- hasCompileErrors = true;
383
- var formatted = formatWebpackMessages({
384
- errors: errors,
385
- warnings: []
386
- });
387
- if (typeof console !== "undefined" && typeof console.error === "function") {
388
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
389
- try {
390
- for(var _iterator = formatted.errors[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
391
- var error = _step.value;
392
- console.error(stripAnsi(error));
393
- }
394
- } catch (err) {
395
- _didIteratorError = true;
396
- _iteratorError = err;
397
- } finally{
398
- try {
399
- if (!_iteratorNormalCompletion && _iterator.return != null) {
400
- _iterator.return();
401
- }
402
- } finally{
403
- if (_didIteratorError) {
404
- throw _iteratorError;
405
- }
406
- }
407
- }
408
- }
409
- };
410
- var handleAvailableHash = function handleAvailableHash(hash) {
411
- mostRecentCompilationHash = hash;
412
- };
413
- var isUpdateAvailable = function isUpdateAvailable() {
414
- return mostRecentCompilationHash !== __webpack_hash__;
415
- };
416
- var canApplyUpdates = function canApplyUpdates() {
417
- return module.hot.status() === "idle";
418
- };
419
- var hadRuntimeError = false;
420
- var socketUrl = createSocketUrl(__resourceQuery);
421
- var connection = new WebSocket(socketUrl);
422
- connection.onclose = function() {
423
- if (typeof console !== "undefined" && typeof console.info === "function") {
424
- console.info("The development server has disconnected. Refresh the page if necessary.");
425
- }
426
- };
427
- var isFirstCompilation = true;
428
- var mostRecentCompilationHash = null;
429
- var hasCompileErrors = false;
430
- connection.onmessage = function(e) {
431
- var message = JSON.parse(e.data);
432
- switch(message.type){
433
- case "hash":
434
- handleAvailableHash(message.data);
435
- break;
436
- case "still-ok":
437
- case "ok":
438
- handleSuccess();
439
- break;
440
- case "content-changed":
441
- window.location.reload();
442
- break;
443
- case "warnings":
444
- handleWarnings(message.data);
445
- break;
446
- case "errors":
447
- handleErrors(message.data);
448
- break;
449
- default:
450
- }
451
- };
452
- function tryApplyUpdates() {
453
- if (!module.hot) {
454
- window.location.reload();
455
- return;
456
- }
457
- if (!isUpdateAvailable() || !canApplyUpdates()) {
458
- return;
459
- }
460
- function handleApplyUpdates(err, updatedModules) {
461
- var wantsForcedReload = err || !updatedModules || hadRuntimeError;
462
- if (wantsForcedReload) {
463
- window.location.reload();
464
- return;
465
- }
466
- if (isUpdateAvailable()) {
467
- tryApplyUpdates();
468
- }
469
- }
470
- var result = module.hot.check(true, handleApplyUpdates);
471
- if (result === null || result === void 0 ? void 0 : result.then) {
472
- result.then(function(updatedModules) {
473
- handleApplyUpdates(null, updatedModules);
474
- }, function(err) {
475
- handleApplyUpdates(err, null);
476
- });
477
- }
478
- }
479
- }
480
- });
481
- export default require_hmr_client();
482
- `,
483
- );