@modern-js/server 2.48.0 → 2.48.1

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 (31) hide show
  1. package/dist/cjs/constants.js +1 -1
  2. package/dist/cjs/dev-tools/dev-middleware/index.js +0 -4
  3. package/dist/cjs/dev-tools/dev-middleware/socketServer.js +2 -7
  4. package/dist/cjs/dev-tools/watcher/dependencyTree.js +0 -3
  5. package/dist/cjs/dev-tools/watcher/index.js +1 -3
  6. package/dist/cjs/dev-tools/watcher/statsCache.js +2 -3
  7. package/dist/cjs/server/devServer.js +4 -11
  8. package/dist/cjs/server/devServerOld.js +3 -9
  9. package/dist/cjs/server/workerSSRRender.js +1 -1
  10. package/dist/esm/constants.js +1 -1
  11. package/dist/esm/dev-tools/dev-middleware/index.js +42 -58
  12. package/dist/esm/dev-tools/dev-middleware/socketServer.js +130 -179
  13. package/dist/esm/dev-tools/watcher/dependencyTree.js +59 -80
  14. package/dist/esm/dev-tools/watcher/index.js +63 -82
  15. package/dist/esm/dev-tools/watcher/statsCache.js +55 -76
  16. package/dist/esm/server/devServer.js +433 -494
  17. package/dist/esm/server/devServerOld.js +455 -515
  18. package/dist/esm/server/workerSSRRender.js +1 -1
  19. package/dist/esm-node/constants.js +1 -1
  20. package/dist/esm-node/dev-tools/dev-middleware/index.js +0 -4
  21. package/dist/esm-node/dev-tools/dev-middleware/socketServer.js +2 -7
  22. package/dist/esm-node/dev-tools/watcher/dependencyTree.js +0 -3
  23. package/dist/esm-node/dev-tools/watcher/index.js +1 -3
  24. package/dist/esm-node/dev-tools/watcher/statsCache.js +2 -3
  25. package/dist/esm-node/server/devServer.js +4 -11
  26. package/dist/esm-node/server/devServerOld.js +3 -9
  27. package/dist/esm-node/server/workerSSRRender.js +1 -1
  28. package/dist/types/server/devServer.d.ts +1 -1
  29. package/dist/types/server/devServerOld.d.ts +1 -1
  30. package/dist/types/types.d.ts +2 -2
  31. package/package.json +10 -10
@@ -1,6 +1,4 @@
1
1
  import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
2
- import { _ as _create_class } from "@swc/helpers/_/_create_class";
3
- import { _ as _define_property } from "@swc/helpers/_/_define_property";
4
2
  import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
5
3
  import minimatch from "minimatch";
6
4
  var defaultIgnores = [
@@ -14,93 +12,74 @@ var DependencyTree = /* @__PURE__ */ function() {
14
12
  "use strict";
15
13
  function DependencyTree2() {
16
14
  _class_call_check(this, DependencyTree2);
17
- _define_property(this, "tree", void 0);
18
- _define_property(this, "ignore", void 0);
19
15
  this.tree = /* @__PURE__ */ new Map();
20
16
  this.ignore = _to_consumable_array(defaultIgnores);
21
17
  }
22
- _create_class(DependencyTree2, [
23
- {
24
- key: "getNode",
25
- value: function getNode(path) {
26
- return this.tree.get(path);
18
+ var _proto = DependencyTree2.prototype;
19
+ _proto.getNode = function getNode(path) {
20
+ return this.tree.get(path);
21
+ };
22
+ _proto.update = function update(cache) {
23
+ var _this = this;
24
+ this.tree.clear();
25
+ Object.keys(cache).forEach(function(path) {
26
+ if (!_this.shouldIgnore(path)) {
27
+ var module = cache[path];
28
+ _this.tree.set(module.filename, {
29
+ module,
30
+ parent: /* @__PURE__ */ new Set(),
31
+ children: /* @__PURE__ */ new Set()
32
+ });
27
33
  }
28
- },
29
- {
30
- key: "update",
31
- value: (
32
- /**
33
- * update dependency tree
34
- *
35
- * @param cache
36
- */
37
- function update(cache) {
38
- var _this = this;
39
- this.tree.clear();
40
- Object.keys(cache).forEach(function(path) {
41
- if (!_this.shouldIgnore(path)) {
42
- var module = cache[path];
43
- _this.tree.set(module.filename, {
44
- module,
45
- parent: /* @__PURE__ */ new Set(),
46
- children: /* @__PURE__ */ new Set()
47
- });
48
- }
49
- });
50
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
51
- try {
52
- var _this1 = this, _loop = function() {
53
- var treeNode = _step.value;
54
- var parent = treeNode.module.parent;
55
- var children = treeNode.module.children;
56
- if (parent && !_this1.shouldIgnore(parent.filename)) {
57
- var parentTreeNode = _this1.tree.get(parent.filename);
58
- if (parentTreeNode) {
59
- treeNode.parent.add(parentTreeNode);
60
- }
61
- }
62
- children.forEach(function(child) {
63
- if (!_this.shouldIgnore(child.filename)) {
64
- var childTreeNode = _this.tree.get(child.filename);
65
- if (childTreeNode) {
66
- treeNode.children.add(childTreeNode);
67
- childTreeNode.parent.add(treeNode);
68
- }
69
- }
70
- });
71
- };
72
- for (var _iterator = this.tree.values()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)
73
- _loop();
74
- } catch (err) {
75
- _didIteratorError = true;
76
- _iteratorError = err;
77
- } finally {
78
- try {
79
- if (!_iteratorNormalCompletion && _iterator.return != null) {
80
- _iterator.return();
81
- }
82
- } finally {
83
- if (_didIteratorError) {
84
- throw _iteratorError;
85
- }
34
+ });
35
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
36
+ try {
37
+ var _this1 = this, _loop = function() {
38
+ var treeNode = _step.value;
39
+ var parent = treeNode.module.parent;
40
+ var children = treeNode.module.children;
41
+ if (parent && !_this1.shouldIgnore(parent.filename)) {
42
+ var parentTreeNode = _this1.tree.get(parent.filename);
43
+ if (parentTreeNode) {
44
+ treeNode.parent.add(parentTreeNode);
45
+ }
46
+ }
47
+ children.forEach(function(child) {
48
+ if (!_this.shouldIgnore(child.filename)) {
49
+ var childTreeNode = _this.tree.get(child.filename);
50
+ if (childTreeNode) {
51
+ treeNode.children.add(childTreeNode);
52
+ childTreeNode.parent.add(treeNode);
86
53
  }
87
54
  }
55
+ });
56
+ };
57
+ for (var _iterator = this.tree.values()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)
58
+ _loop();
59
+ } catch (err) {
60
+ _didIteratorError = true;
61
+ _iteratorError = err;
62
+ } finally {
63
+ try {
64
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
65
+ _iterator.return();
66
+ }
67
+ } finally {
68
+ if (_didIteratorError) {
69
+ throw _iteratorError;
88
70
  }
89
- )
90
- },
91
- {
92
- key: "shouldIgnore",
93
- value: function shouldIgnore(path) {
94
- return !path || Boolean(this.ignore.find(function(rule) {
95
- return minimatch.match([
96
- path
97
- ], rule, {
98
- dot: true
99
- }).length > 0;
100
- }));
101
71
  }
102
72
  }
103
- ]);
73
+ };
74
+ _proto.shouldIgnore = function shouldIgnore(path) {
75
+ return !path || Boolean(this.ignore.find(function(rule) {
76
+ return minimatch.match([
77
+ path
78
+ ], rule, {
79
+ dot: true
80
+ }).length > 0;
81
+ }));
82
+ };
104
83
  return DependencyTree2;
105
84
  }();
106
85
  export {
@@ -1,6 +1,4 @@
1
1
  import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
2
- import { _ as _create_class } from "@swc/helpers/_/_create_class";
3
- import { _ as _define_property } from "@swc/helpers/_/_define_property";
4
2
  import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
5
3
  import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
6
4
  import path from "path";
@@ -42,93 +40,76 @@ var Watcher = /* @__PURE__ */ function() {
42
40
  "use strict";
43
41
  function Watcher2() {
44
42
  _class_call_check(this, Watcher2);
45
- _define_property(this, "dependencyTree", null);
46
- _define_property(this, "watcher", void 0);
43
+ this.dependencyTree = null;
47
44
  }
48
- _create_class(Watcher2, [
49
- {
50
- key: "listen",
51
- value: function listen(files, options, callback) {
52
- var watched = files.filter(Boolean);
53
- var filenames = watched.map(function(filename) {
54
- return filename.replace(/\\/g, "/");
55
- });
56
- var cache = new StatsCache();
57
- var watcher = chokidar.watch(filenames, options);
58
- watcher.on("ready", function() {
59
- cache.add(getWatchedFiles(watcher));
60
- });
61
- watcher.on("change", function(changed) {
62
- if (!fs.existsSync(changed) || cache.isDiff(changed)) {
63
- cache.refresh(changed);
64
- callback(changed, "change");
65
- }
66
- });
67
- watcher.on("add", function(changed) {
68
- if (!cache.has(changed)) {
69
- cache.add([
70
- changed
71
- ]);
72
- callback(changed, "add");
73
- }
74
- });
75
- watcher.on("unlink", function(changed) {
76
- cache.del(changed);
77
- callback(changed, "unlink");
78
- });
79
- this.watcher = watcher;
80
- }
81
- },
82
- {
83
- key: "createDepTree",
84
- value: function createDepTree() {
85
- this.dependencyTree = new DependencyTree();
45
+ var _proto = Watcher2.prototype;
46
+ _proto.listen = function listen(files, options, callback) {
47
+ var watched = files.filter(Boolean);
48
+ var filenames = watched.map(function(filename) {
49
+ return filename.replace(/\\/g, "/");
50
+ });
51
+ var cache = new StatsCache();
52
+ var watcher = chokidar.watch(filenames, options);
53
+ watcher.on("ready", function() {
54
+ cache.add(getWatchedFiles(watcher));
55
+ });
56
+ watcher.on("change", function(changed) {
57
+ if (!fs.existsSync(changed) || cache.isDiff(changed)) {
58
+ cache.refresh(changed);
59
+ callback(changed, "change");
86
60
  }
87
- },
88
- {
89
- key: "updateDepTree",
90
- value: function updateDepTree() {
91
- var _this_dependencyTree;
92
- (_this_dependencyTree = this.dependencyTree) === null || _this_dependencyTree === void 0 ? void 0 : _this_dependencyTree.update(require.cache);
61
+ });
62
+ watcher.on("add", function(changed) {
63
+ if (!cache.has(changed)) {
64
+ cache.add([
65
+ changed
66
+ ]);
67
+ callback(changed, "add");
93
68
  }
94
- },
95
- {
96
- key: "cleanDepCache",
97
- value: function cleanDepCache(filepath) {
98
- var _this_dependencyTree;
99
- var node = (_this_dependencyTree = this.dependencyTree) === null || _this_dependencyTree === void 0 ? void 0 : _this_dependencyTree.getNode(filepath);
100
- if (node && require.cache[filepath]) {
101
- delete require.cache[filepath];
102
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
103
- try {
104
- for (var _iterator = node.parent.values()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
105
- var parentNode = _step.value;
106
- this.cleanDepCache(parentNode.module.filename);
107
- }
108
- } catch (err) {
109
- _didIteratorError = true;
110
- _iteratorError = err;
111
- } finally {
112
- try {
113
- if (!_iteratorNormalCompletion && _iterator.return != null) {
114
- _iterator.return();
115
- }
116
- } finally {
117
- if (_didIteratorError) {
118
- throw _iteratorError;
119
- }
120
- }
69
+ });
70
+ watcher.on("unlink", function(changed) {
71
+ cache.del(changed);
72
+ callback(changed, "unlink");
73
+ });
74
+ this.watcher = watcher;
75
+ };
76
+ _proto.createDepTree = function createDepTree() {
77
+ this.dependencyTree = new DependencyTree();
78
+ };
79
+ _proto.updateDepTree = function updateDepTree() {
80
+ var _this_dependencyTree;
81
+ (_this_dependencyTree = this.dependencyTree) === null || _this_dependencyTree === void 0 ? void 0 : _this_dependencyTree.update(require.cache);
82
+ };
83
+ _proto.cleanDepCache = function cleanDepCache(filepath) {
84
+ var _this_dependencyTree;
85
+ var node = (_this_dependencyTree = this.dependencyTree) === null || _this_dependencyTree === void 0 ? void 0 : _this_dependencyTree.getNode(filepath);
86
+ if (node && require.cache[filepath]) {
87
+ delete require.cache[filepath];
88
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
89
+ try {
90
+ for (var _iterator = node.parent.values()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
91
+ var parentNode = _step.value;
92
+ this.cleanDepCache(parentNode.module.filename);
93
+ }
94
+ } catch (err) {
95
+ _didIteratorError = true;
96
+ _iteratorError = err;
97
+ } finally {
98
+ try {
99
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
100
+ _iterator.return();
101
+ }
102
+ } finally {
103
+ if (_didIteratorError) {
104
+ throw _iteratorError;
121
105
  }
122
106
  }
123
107
  }
124
- },
125
- {
126
- key: "close",
127
- value: function close() {
128
- return this.watcher.close();
129
- }
130
108
  }
131
- ]);
109
+ };
110
+ _proto.close = function close() {
111
+ return this.watcher.close();
112
+ };
132
113
  return Watcher2;
133
114
  }();
134
115
  export {
@@ -1,99 +1,78 @@
1
1
  import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
2
- import { _ as _create_class } from "@swc/helpers/_/_create_class";
3
- import { _ as _define_property } from "@swc/helpers/_/_define_property";
4
2
  import fs from "fs";
5
3
  import crypto from "crypto";
6
4
  var StatsCache = /* @__PURE__ */ function() {
7
5
  "use strict";
8
6
  function StatsCache2() {
9
7
  _class_call_check(this, StatsCache2);
10
- _define_property(this, "cachedHash", {});
11
- _define_property(this, "cachedSize", {});
8
+ this.cachedHash = {};
9
+ this.cachedSize = {};
12
10
  }
13
- _create_class(StatsCache2, [
14
- {
15
- key: "add",
16
- value: function add(files) {
17
- var _this = this, cachedHash = _this.cachedHash, cachedSize = _this.cachedSize;
18
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
19
- try {
20
- for (var _iterator = files[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
21
- var filename = _step.value;
22
- if (fs.existsSync(filename)) {
23
- var stats = fs.statSync(filename);
24
- if (stats.isFile() && !cachedHash[filename]) {
25
- cachedHash[filename] = this.hash(stats, filename);
26
- cachedSize[filename] = stats.size;
27
- }
28
- }
29
- }
30
- } catch (err) {
31
- _didIteratorError = true;
32
- _iteratorError = err;
33
- } finally {
34
- try {
35
- if (!_iteratorNormalCompletion && _iterator.return != null) {
36
- _iterator.return();
37
- }
38
- } finally {
39
- if (_didIteratorError) {
40
- throw _iteratorError;
41
- }
42
- }
43
- }
44
- }
45
- },
46
- {
47
- key: "refresh",
48
- value: function refresh(filename) {
49
- var _this = this, cachedHash = _this.cachedHash, cachedSize = _this.cachedSize;
11
+ var _proto = StatsCache2.prototype;
12
+ _proto.add = function add(files) {
13
+ var _this = this, cachedHash = _this.cachedHash, cachedSize = _this.cachedSize;
14
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
15
+ try {
16
+ for (var _iterator = files[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
17
+ var filename = _step.value;
50
18
  if (fs.existsSync(filename)) {
51
19
  var stats = fs.statSync(filename);
52
- if (stats.isFile()) {
20
+ if (stats.isFile() && !cachedHash[filename]) {
53
21
  cachedHash[filename] = this.hash(stats, filename);
54
22
  cachedSize[filename] = stats.size;
55
23
  }
56
24
  }
57
25
  }
58
- },
59
- {
60
- key: "del",
61
- value: function del(filename) {
62
- if (this.cachedHash[filename]) {
63
- delete this.cachedHash[filename];
64
- delete this.cachedSize[filename];
65
- }
66
- }
67
- },
68
- {
69
- key: "isDiff",
70
- value: function isDiff(filename) {
71
- var _this = this, cachedHash = _this.cachedHash, cachedSize = _this.cachedSize;
72
- var stats = fs.statSync(filename);
73
- var hash = cachedHash[filename];
74
- var size = cachedSize[filename];
75
- if (stats.size !== size) {
76
- return true;
26
+ } catch (err) {
27
+ _didIteratorError = true;
28
+ _iteratorError = err;
29
+ } finally {
30
+ try {
31
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
32
+ _iterator.return();
77
33
  }
78
- if (this.hash(stats, filename) !== hash) {
79
- return true;
34
+ } finally {
35
+ if (_didIteratorError) {
36
+ throw _iteratorError;
80
37
  }
81
- return false;
82
38
  }
83
- },
84
- {
85
- key: "has",
86
- value: function has(filename) {
87
- return Boolean(this.cachedHash[filename]);
88
- }
89
- },
90
- {
91
- key: "hash",
92
- value: function hash(stats, filename) {
93
- return crypto.createHash("md5").update(fs.readFileSync(filename)).digest("hex");
39
+ }
40
+ };
41
+ _proto.refresh = function refresh(filename) {
42
+ var _this = this, cachedHash = _this.cachedHash, cachedSize = _this.cachedSize;
43
+ if (fs.existsSync(filename)) {
44
+ var stats = fs.statSync(filename);
45
+ if (stats.isFile()) {
46
+ cachedHash[filename] = this.hash(stats, filename);
47
+ cachedSize[filename] = stats.size;
94
48
  }
95
49
  }
96
- ]);
50
+ };
51
+ _proto.del = function del(filename) {
52
+ if (this.cachedHash[filename]) {
53
+ delete this.cachedHash[filename];
54
+ delete this.cachedSize[filename];
55
+ }
56
+ };
57
+ _proto.isDiff = function isDiff(filename) {
58
+ var _this = this, cachedHash = _this.cachedHash, cachedSize = _this.cachedSize;
59
+ var stats = fs.statSync(filename);
60
+ var hash = cachedHash[filename];
61
+ var size = cachedSize[filename];
62
+ if (stats.size !== size) {
63
+ return true;
64
+ }
65
+ if (this.hash(stats, filename) !== hash) {
66
+ return true;
67
+ }
68
+ return false;
69
+ };
70
+ _proto.has = function has(filename) {
71
+ return Boolean(this.cachedHash[filename]);
72
+ };
73
+ _proto.hash = function hash(stats, filename) {
74
+ return crypto.createHash("md5").update(fs.readFileSync(filename)).digest("hex");
75
+ };
97
76
  return StatsCache2;
98
77
  }();
99
78
  export {