@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,150 +0,0 @@
1
- function _arrayLikeToArray(arr, len) {
2
- if (len == null || len > arr.length) len = arr.length;
3
- for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
4
- return arr2;
5
- }
6
- function _arrayWithoutHoles(arr) {
7
- if (Array.isArray(arr)) return _arrayLikeToArray(arr);
8
- }
9
- function _classCallCheck(instance, Constructor) {
10
- if (!(instance instanceof Constructor)) {
11
- throw new TypeError("Cannot call a class as a function");
12
- }
13
- }
14
- function _defineProperties(target, props) {
15
- for(var i = 0; i < props.length; i++){
16
- var descriptor = props[i];
17
- descriptor.enumerable = descriptor.enumerable || false;
18
- descriptor.configurable = true;
19
- if ("value" in descriptor) descriptor.writable = true;
20
- Object.defineProperty(target, descriptor.key, descriptor);
21
- }
22
- }
23
- function _createClass(Constructor, protoProps, staticProps) {
24
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
25
- if (staticProps) _defineProperties(Constructor, staticProps);
26
- return Constructor;
27
- }
28
- function _defineProperty(obj, key, value) {
29
- if (key in obj) {
30
- Object.defineProperty(obj, key, {
31
- value: value,
32
- enumerable: true,
33
- configurable: true,
34
- writable: true
35
- });
36
- } else {
37
- obj[key] = value;
38
- }
39
- return obj;
40
- }
41
- function _iterableToArray(iter) {
42
- if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
43
- }
44
- function _nonIterableSpread() {
45
- throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
46
- }
47
- function _toConsumableArray(arr) {
48
- return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
49
- }
50
- function _unsupportedIterableToArray(o, minLen) {
51
- if (!o) return;
52
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
53
- var n = Object.prototype.toString.call(o).slice(8, -1);
54
- if (n === "Object" && o.constructor) n = o.constructor.name;
55
- if (n === "Map" || n === "Set") return Array.from(n);
56
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
57
- }
58
- import minimatch from "minimatch";
59
- var defaultIgnores = [
60
- "**/bower_components/**",
61
- "**/coverage/**",
62
- "**/node_modules/**",
63
- "**/.*/**",
64
- "**/*.d.ts",
65
- "**/*.log"
66
- ];
67
- var DependencyTree = /*#__PURE__*/ function() {
68
- "use strict";
69
- function DependencyTree() {
70
- _classCallCheck(this, DependencyTree);
71
- _defineProperty(this, "tree", void 0);
72
- _defineProperty(this, "ignore", void 0);
73
- this.tree = /* @__PURE__ */ new Map();
74
- this.ignore = _toConsumableArray(defaultIgnores);
75
- }
76
- _createClass(DependencyTree, [
77
- {
78
- key: "getNode",
79
- value: function getNode(path) {
80
- return this.tree.get(path);
81
- }
82
- },
83
- {
84
- key: "update",
85
- value: function update(cache) {
86
- var _this = this;
87
- this.tree.clear();
88
- Object.keys(cache).forEach(function(path) {
89
- if (!_this.shouldIgnore(path)) {
90
- var module = cache[path];
91
- _this.tree.set(module.filename, {
92
- module: module,
93
- parent: /* @__PURE__ */ new Set(),
94
- children: /* @__PURE__ */ new Set()
95
- });
96
- }
97
- });
98
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
99
- try {
100
- var _this1 = this, _loop = function() {
101
- var treeNode = _step.value;
102
- var parent = treeNode.module.parent;
103
- var children = treeNode.module.children;
104
- if (parent && !_this1.shouldIgnore(parent.filename)) {
105
- var parentTreeNode = _this1.tree.get(parent.filename);
106
- if (parentTreeNode) {
107
- treeNode.parent.add(parentTreeNode);
108
- }
109
- }
110
- children.forEach(function(child) {
111
- if (!_this.shouldIgnore(child.filename)) {
112
- var childTreeNode = _this.tree.get(child.filename);
113
- if (childTreeNode) {
114
- treeNode.children.add(childTreeNode);
115
- childTreeNode.parent.add(treeNode);
116
- }
117
- }
118
- });
119
- };
120
- for(var _iterator = this.tree.values()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop();
121
- } catch (err) {
122
- _didIteratorError = true;
123
- _iteratorError = err;
124
- } finally{
125
- try {
126
- if (!_iteratorNormalCompletion && _iterator.return != null) {
127
- _iterator.return();
128
- }
129
- } finally{
130
- if (_didIteratorError) {
131
- throw _iteratorError;
132
- }
133
- }
134
- }
135
- }
136
- },
137
- {
138
- key: "shouldIgnore",
139
- value: function shouldIgnore(path) {
140
- return !path || Boolean(this.ignore.find(function(rule) {
141
- return minimatch.match([
142
- path
143
- ], rule).length > 0;
144
- }));
145
- }
146
- }
147
- ]);
148
- return DependencyTree;
149
- }();
150
- export { DependencyTree, defaultIgnores };
@@ -1,200 +0,0 @@
1
- function _arrayLikeToArray(arr, len) {
2
- if (len == null || len > arr.length) len = arr.length;
3
- for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
4
- return arr2;
5
- }
6
- function _arrayWithoutHoles(arr) {
7
- if (Array.isArray(arr)) return _arrayLikeToArray(arr);
8
- }
9
- function _classCallCheck(instance, Constructor) {
10
- if (!(instance instanceof Constructor)) {
11
- throw new TypeError("Cannot call a class as a function");
12
- }
13
- }
14
- function _defineProperties(target, props) {
15
- for(var i = 0; i < props.length; i++){
16
- var descriptor = props[i];
17
- descriptor.enumerable = descriptor.enumerable || false;
18
- descriptor.configurable = true;
19
- if ("value" in descriptor) descriptor.writable = true;
20
- Object.defineProperty(target, descriptor.key, descriptor);
21
- }
22
- }
23
- function _createClass(Constructor, protoProps, staticProps) {
24
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
25
- if (staticProps) _defineProperties(Constructor, staticProps);
26
- return Constructor;
27
- }
28
- function _defineProperty(obj, key, value) {
29
- if (key in obj) {
30
- Object.defineProperty(obj, key, {
31
- value: value,
32
- enumerable: true,
33
- configurable: true,
34
- writable: true
35
- });
36
- } else {
37
- obj[key] = value;
38
- }
39
- return obj;
40
- }
41
- function _iterableToArray(iter) {
42
- if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
43
- }
44
- function _nonIterableSpread() {
45
- throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
46
- }
47
- function _objectSpread(target) {
48
- for(var i = 1; i < arguments.length; i++){
49
- var source = arguments[i] != null ? arguments[i] : {};
50
- var ownKeys = Object.keys(source);
51
- if (typeof Object.getOwnPropertySymbols === "function") {
52
- ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
53
- return Object.getOwnPropertyDescriptor(source, sym).enumerable;
54
- }));
55
- }
56
- ownKeys.forEach(function(key) {
57
- _defineProperty(target, key, source[key]);
58
- });
59
- }
60
- return target;
61
- }
62
- function _toConsumableArray(arr) {
63
- return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
64
- }
65
- function _unsupportedIterableToArray(o, minLen) {
66
- if (!o) return;
67
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
68
- var n = Object.prototype.toString.call(o).slice(8, -1);
69
- if (n === "Object" && o.constructor) n = o.constructor.name;
70
- if (n === "Map" || n === "Set") return Array.from(n);
71
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
72
- }
73
- import path from "path";
74
- import { fs, chokidar } from "@modern-js/utils";
75
- import { DependencyTree } from "./dependency-tree";
76
- import { StatsCache } from "./stats-cache";
77
- var defaultWatchOptions = {
78
- ignoreInitial: true,
79
- ignored: /api\/typings\/.*/
80
- };
81
- var getWatchedFiles = function(watcher) {
82
- var watched = watcher.getWatched();
83
- var files = [];
84
- Object.keys(watched).forEach(function(dir) {
85
- watched[dir].forEach(function(fileName) {
86
- files.push(path.join(dir, fileName));
87
- });
88
- });
89
- return files;
90
- };
91
- var mergeWatchOptions = function(options) {
92
- var watchOptions = _objectSpread({}, options);
93
- if (watchOptions) {
94
- var ignored = watchOptions.ignored;
95
- var finalIgnored = ignored ? [
96
- defaultWatchOptions.ignored
97
- ].concat(_toConsumableArray(Array.isArray(ignored) ? ignored : [
98
- ignored
99
- ])) : ignored;
100
- if (finalIgnored) {
101
- watchOptions.ignored = finalIgnored;
102
- }
103
- }
104
- var finalWatchOptions = _objectSpread({}, defaultWatchOptions, watchOptions);
105
- return finalWatchOptions;
106
- };
107
- var Watcher = /*#__PURE__*/ function() {
108
- "use strict";
109
- function Watcher() {
110
- _classCallCheck(this, Watcher);
111
- _defineProperty(this, "dependencyTree", null);
112
- _defineProperty(this, "watcher", void 0);
113
- }
114
- _createClass(Watcher, [
115
- {
116
- key: "listen",
117
- value: function listen(files, options, callback) {
118
- var watched = files.filter(Boolean);
119
- var filenames = watched.map(function(filename) {
120
- return filename.replace(/\\/g, "/");
121
- });
122
- var cache = new StatsCache();
123
- var watcher = chokidar.watch(filenames, options);
124
- watcher.on("ready", function() {
125
- cache.add(getWatchedFiles(watcher));
126
- });
127
- watcher.on("change", function(changed) {
128
- if (!fs.existsSync(changed) || cache.isDiff(changed)) {
129
- cache.refresh(changed);
130
- callback(changed, "change");
131
- }
132
- });
133
- watcher.on("add", function(changed) {
134
- if (!cache.has(changed)) {
135
- cache.add([
136
- changed
137
- ]);
138
- callback(changed, "add");
139
- }
140
- });
141
- watcher.on("unlink", function(changed) {
142
- cache.del(changed);
143
- callback(changed, "unlink");
144
- });
145
- this.watcher = watcher;
146
- }
147
- },
148
- {
149
- key: "createDepTree",
150
- value: function createDepTree() {
151
- this.dependencyTree = new DependencyTree();
152
- }
153
- },
154
- {
155
- key: "updateDepTree",
156
- value: function updateDepTree() {
157
- var _this_dependencyTree;
158
- (_this_dependencyTree = this.dependencyTree) === null || _this_dependencyTree === void 0 ? void 0 : _this_dependencyTree.update(require.cache);
159
- }
160
- },
161
- {
162
- key: "cleanDepCache",
163
- value: function cleanDepCache(filepath) {
164
- var _this_dependencyTree;
165
- var node = (_this_dependencyTree = this.dependencyTree) === null || _this_dependencyTree === void 0 ? void 0 : _this_dependencyTree.getNode(filepath);
166
- if (node && require.cache[filepath]) {
167
- delete require.cache[filepath];
168
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
169
- try {
170
- for(var _iterator = node.parent.values()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
171
- var parentNode = _step.value;
172
- this.cleanDepCache(parentNode.module.filename);
173
- }
174
- } catch (err) {
175
- _didIteratorError = true;
176
- _iteratorError = err;
177
- } finally{
178
- try {
179
- if (!_iteratorNormalCompletion && _iterator.return != null) {
180
- _iterator.return();
181
- }
182
- } finally{
183
- if (_didIteratorError) {
184
- throw _iteratorError;
185
- }
186
- }
187
- }
188
- }
189
- }
190
- },
191
- {
192
- key: "close",
193
- value: function close() {
194
- return this.watcher.close();
195
- }
196
- }
197
- ]);
198
- return Watcher;
199
- }();
200
- export { Watcher as default, defaultWatchOptions, getWatchedFiles, mergeWatchOptions };
@@ -1,128 +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 fs from "fs";
34
- import crypto from "crypto";
35
- var StatsCache = /*#__PURE__*/ function() {
36
- "use strict";
37
- function StatsCache() {
38
- _classCallCheck(this, StatsCache);
39
- _defineProperty(this, "cachedHash", {});
40
- _defineProperty(this, "cachedSize", {});
41
- }
42
- _createClass(StatsCache, [
43
- {
44
- key: "add",
45
- value: function add(files) {
46
- var _this = this, cachedHash = _this.cachedHash, cachedSize = _this.cachedSize;
47
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
48
- try {
49
- for(var _iterator = files[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
50
- var filename = _step.value;
51
- if (fs.existsSync(filename)) {
52
- var stats = fs.statSync(filename);
53
- if (stats.isFile() && !cachedHash[filename]) {
54
- cachedHash[filename] = this.hash(stats, filename);
55
- cachedSize[filename] = stats.size;
56
- }
57
- }
58
- }
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;
70
- }
71
- }
72
- }
73
- }
74
- },
75
- {
76
- key: "refresh",
77
- value: function refresh(filename) {
78
- var _this = this, cachedHash = _this.cachedHash, cachedSize = _this.cachedSize;
79
- if (fs.existsSync(filename)) {
80
- var stats = fs.statSync(filename);
81
- if (stats.isFile()) {
82
- cachedHash[filename] = this.hash(stats, filename);
83
- cachedSize[filename] = stats.size;
84
- }
85
- }
86
- }
87
- },
88
- {
89
- key: "del",
90
- value: function del(filename) {
91
- if (this.cachedHash[filename]) {
92
- delete this.cachedHash[filename];
93
- delete this.cachedSize[filename];
94
- }
95
- }
96
- },
97
- {
98
- key: "isDiff",
99
- value: function isDiff(filename) {
100
- var _this = this, cachedHash = _this.cachedHash, cachedSize = _this.cachedSize;
101
- var stats = fs.statSync(filename);
102
- var hash = cachedHash[filename];
103
- var size = cachedSize[filename];
104
- if (stats.size !== size) {
105
- return true;
106
- }
107
- if (this.hash(stats, filename) !== hash) {
108
- return true;
109
- }
110
- return false;
111
- }
112
- },
113
- {
114
- key: "has",
115
- value: function has(filename) {
116
- return Boolean(this.cachedHash[filename]);
117
- }
118
- },
119
- {
120
- key: "hash",
121
- value: function hash(stats, filename) {
122
- return crypto.createHash("md5").update(fs.readFileSync(filename)).digest("hex");
123
- }
124
- }
125
- ]);
126
- return StatsCache;
127
- }();
128
- export { StatsCache };
@@ -1,9 +0,0 @@
1
- import { DevServer as Server } from "./server";
2
- var src_default = function(options) {
3
- if (options == null) {
4
- throw new Error("can not start server without options");
5
- }
6
- var server = new Server(options);
7
- return server.init();
8
- };
9
- export { Server, src_default as default };