@modern-js/server 2.6.0 → 2.6.1-alpha.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.
- package/dist/cjs/dev-tools/dev-middleware/index.js +2 -2
- package/dist/cjs/dev-tools/dev-middleware/{socket-server.js → socketServer.js} +3 -3
- package/dist/cjs/dev-tools/watcher/{dependency-tree.js → dependencyTree.js} +3 -3
- package/dist/cjs/dev-tools/watcher/index.js +4 -4
- package/dist/cjs/dev-tools/watcher/{stats-cache.js → statsCache.js} +3 -3
- package/dist/cjs/server/{dev-server.js → devServer.js} +14 -6
- package/dist/cjs/server/index.js +2 -2
- package/dist/esm/dev-tools/dev-middleware/index.js +1 -1
- package/dist/esm/dev-tools/watcher/index.js +2 -2
- package/dist/esm/server/devServer.js +823 -0
- package/dist/esm/server/index.js +1 -1
- package/dist/esm-node/dev-tools/dev-middleware/index.js +1 -1
- package/dist/esm-node/dev-tools/watcher/index.js +2 -2
- package/dist/esm-node/server/{dev-server.js → devServer.js} +11 -3
- package/dist/esm-node/server/index.js +1 -1
- package/dist/js/modern/constants.js +19 -0
- package/dist/js/modern/dev-tools/dev-middleware/hmr-client/createSocketUrl.js +41 -0
- package/dist/js/modern/dev-tools/dev-middleware/hmr-client/index.js +146 -0
- package/dist/js/modern/dev-tools/dev-middleware/index.js +94 -0
- package/dist/js/modern/dev-tools/dev-middleware/socket-server.js +132 -0
- package/dist/js/modern/dev-tools/https/index.js +49 -0
- package/dist/js/modern/dev-tools/mock/getMockData.js +105 -0
- package/dist/js/modern/dev-tools/mock/index.js +70 -0
- package/dist/js/modern/dev-tools/register/index.js +112 -0
- package/dist/js/modern/dev-tools/watcher/dependency-tree.js +59 -0
- package/dist/js/modern/dev-tools/watcher/index.js +106 -0
- package/dist/js/modern/dev-tools/watcher/stats-cache.js +58 -0
- package/dist/js/modern/index.js +12 -0
- package/dist/js/modern/server/dev-server.js +294 -0
- package/dist/js/modern/server/index.js +16 -0
- package/dist/js/modern/types.js +0 -0
- package/dist/js/node/constants.js +42 -0
- package/dist/js/node/dev-tools/dev-middleware/hmr-client/createSocketUrl.js +65 -0
- package/dist/js/node/dev-tools/dev-middleware/hmr-client/index.js +155 -0
- package/dist/js/node/dev-tools/dev-middleware/index.js +119 -0
- package/dist/js/node/dev-tools/dev-middleware/socket-server.js +159 -0
- package/dist/js/node/dev-tools/https/index.js +72 -0
- package/dist/js/node/dev-tools/mock/getMockData.js +126 -0
- package/dist/js/node/dev-tools/mock/index.js +99 -0
- package/dist/js/node/dev-tools/register/index.js +139 -0
- package/dist/js/node/dev-tools/watcher/dependency-tree.js +89 -0
- package/dist/js/node/dev-tools/watcher/index.js +135 -0
- package/dist/js/node/dev-tools/watcher/stats-cache.js +87 -0
- package/dist/js/node/index.js +35 -0
- package/dist/js/node/server/dev-server.js +311 -0
- package/dist/js/node/server/index.js +39 -0
- package/dist/js/node/types.js +15 -0
- package/dist/js/treeshaking/constants.js +21 -0
- package/dist/js/treeshaking/dev-tools/dev-middleware/hmr-client/createSocketUrl.js +51 -0
- package/dist/js/treeshaking/dev-tools/dev-middleware/hmr-client/index.js +162 -0
- package/dist/js/treeshaking/dev-tools/dev-middleware/index.js +322 -0
- package/dist/js/treeshaking/dev-tools/dev-middleware/socket-server.js +209 -0
- package/dist/js/treeshaking/dev-tools/https/index.js +193 -0
- package/dist/js/treeshaking/dev-tools/mock/getMockData.js +318 -0
- package/dist/js/treeshaking/dev-tools/mock/index.js +207 -0
- package/dist/js/treeshaking/dev-tools/register/index.js +154 -0
- package/dist/js/treeshaking/dev-tools/watcher/dependency-tree.js +150 -0
- package/dist/js/treeshaking/dev-tools/watcher/index.js +200 -0
- package/dist/js/treeshaking/dev-tools/watcher/stats-cache.js +128 -0
- package/dist/js/treeshaking/index.js +9 -0
- package/dist/{esm → js/treeshaking}/server/dev-server.js +1 -2
- package/dist/js/treeshaking/server/index.js +92 -0
- package/dist/js/treeshaking/types.js +1 -0
- package/dist/types/server/{dev-server.d.ts → devServer.d.ts} +4 -1
- package/package.json +10 -10
- /package/dist/esm/dev-tools/dev-middleware/{socket-server.js → socketServer.js} +0 -0
- /package/dist/esm/dev-tools/watcher/{dependency-tree.js → dependencyTree.js} +0 -0
- /package/dist/esm/dev-tools/watcher/{stats-cache.js → statsCache.js} +0 -0
- /package/dist/esm-node/dev-tools/dev-middleware/{socket-server.js → socketServer.js} +0 -0
- /package/dist/esm-node/dev-tools/watcher/{dependency-tree.js → dependencyTree.js} +0 -0
- /package/dist/esm-node/dev-tools/watcher/{stats-cache.js → statsCache.js} +0 -0
- /package/dist/types/dev-tools/dev-middleware/{socket-server.d.ts → socketServer.d.ts} +0 -0
- /package/dist/types/dev-tools/watcher/{dependency-tree.d.ts → dependencyTree.d.ts} +0 -0
- /package/dist/types/dev-tools/watcher/{stats-cache.d.ts → statsCache.d.ts} +0 -0
|
@@ -0,0 +1,150 @@
|
|
|
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 };
|
|
@@ -0,0 +1,200 @@
|
|
|
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 };
|
|
@@ -0,0 +1,128 @@
|
|
|
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 };
|
|
@@ -0,0 +1,9 @@
|
|
|
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 };
|
|
@@ -432,8 +432,7 @@ var ModernDevServer = /*#__PURE__*/ function(ModernServer) {
|
|
|
432
432
|
},
|
|
433
433
|
{
|
|
434
434
|
key: "onInit",
|
|
435
|
-
value:
|
|
436
|
-
function onInit(runner, app) {
|
|
435
|
+
value: function onInit(runner, app) {
|
|
437
436
|
var _this = this;
|
|
438
437
|
var _this1 = this, _superprop_get_onInit = function() {
|
|
439
438
|
return _get(_getPrototypeOf(ModernDevServer.prototype), "onInit", _this);
|
|
@@ -0,0 +1,92 @@
|
|
|
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 _classCallCheck(instance, Constructor) {
|
|
8
|
+
if (!(instance instanceof Constructor)) {
|
|
9
|
+
throw new TypeError("Cannot call a class as a function");
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
function _getPrototypeOf(o) {
|
|
13
|
+
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
|
|
14
|
+
return o.__proto__ || Object.getPrototypeOf(o);
|
|
15
|
+
};
|
|
16
|
+
return _getPrototypeOf(o);
|
|
17
|
+
}
|
|
18
|
+
function _inherits(subClass, superClass) {
|
|
19
|
+
if (typeof superClass !== "function" && superClass !== null) {
|
|
20
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
21
|
+
}
|
|
22
|
+
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
23
|
+
constructor: {
|
|
24
|
+
value: subClass,
|
|
25
|
+
writable: true,
|
|
26
|
+
configurable: true
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
if (superClass) _setPrototypeOf(subClass, superClass);
|
|
30
|
+
}
|
|
31
|
+
function _possibleConstructorReturn(self, call) {
|
|
32
|
+
if (call && (_typeof(call) === "object" || typeof call === "function")) {
|
|
33
|
+
return call;
|
|
34
|
+
}
|
|
35
|
+
return _assertThisInitialized(self);
|
|
36
|
+
}
|
|
37
|
+
function _setPrototypeOf(o, p) {
|
|
38
|
+
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
|
|
39
|
+
o.__proto__ = p;
|
|
40
|
+
return o;
|
|
41
|
+
};
|
|
42
|
+
return _setPrototypeOf(o, p);
|
|
43
|
+
}
|
|
44
|
+
var _typeof = function(obj) {
|
|
45
|
+
"@swc/helpers - typeof";
|
|
46
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
47
|
+
};
|
|
48
|
+
function _isNativeReflectConstruct() {
|
|
49
|
+
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
|
|
50
|
+
if (Reflect.construct.sham) return false;
|
|
51
|
+
if (typeof Proxy === "function") return true;
|
|
52
|
+
try {
|
|
53
|
+
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
|
|
54
|
+
return true;
|
|
55
|
+
} catch (e) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function _createSuper(Derived) {
|
|
60
|
+
var hasNativeReflectConstruct = _isNativeReflectConstruct();
|
|
61
|
+
return function _createSuperInternal() {
|
|
62
|
+
var Super = _getPrototypeOf(Derived), result;
|
|
63
|
+
if (hasNativeReflectConstruct) {
|
|
64
|
+
var NewTarget = _getPrototypeOf(this).constructor;
|
|
65
|
+
result = Reflect.construct(Super, arguments, NewTarget);
|
|
66
|
+
} else {
|
|
67
|
+
result = Super.apply(this, arguments);
|
|
68
|
+
}
|
|
69
|
+
return _possibleConstructorReturn(this, result);
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
import { Server } from "@modern-js/prod-server";
|
|
73
|
+
import { ModernDevServer } from "./dev-server";
|
|
74
|
+
var createDevServer = function(options) {
|
|
75
|
+
return new ModernDevServer(options);
|
|
76
|
+
};
|
|
77
|
+
var DevServer = /*#__PURE__*/ function(Server) {
|
|
78
|
+
"use strict";
|
|
79
|
+
_inherits(DevServer, Server);
|
|
80
|
+
var _super = _createSuper(DevServer);
|
|
81
|
+
function DevServer(options) {
|
|
82
|
+
_classCallCheck(this, DevServer);
|
|
83
|
+
var _this;
|
|
84
|
+
_this = _super.call(this, options);
|
|
85
|
+
if (options.dev) {
|
|
86
|
+
_this.serverImpl = createDevServer;
|
|
87
|
+
}
|
|
88
|
+
return _this;
|
|
89
|
+
}
|
|
90
|
+
return DevServer;
|
|
91
|
+
}(Server);
|
|
92
|
+
export { DevServer };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
import { IncomingMessage, Server, ServerResponse } from 'http';
|
|
4
|
-
import { ServerHookRunner, ModernServer, BuildOptions } from '@modern-js/prod-server';
|
|
4
|
+
import { NextFunction, ServerHookRunner, ModernServer, BuildOptions } from '@modern-js/prod-server';
|
|
5
|
+
import type { ModernServerContext } from '@modern-js/types';
|
|
5
6
|
import { WatchEvent } from '../dev-tools/watcher';
|
|
6
7
|
import type { ModernDevServerOptions } from '../types';
|
|
7
8
|
export declare class ModernDevServer extends ModernServer {
|
|
8
9
|
private mockHandler;
|
|
9
10
|
private readonly dev;
|
|
11
|
+
private readonly appContext;
|
|
10
12
|
private readonly devMiddleware;
|
|
11
13
|
private watcher?;
|
|
12
14
|
constructor(options: ModernDevServerOptions);
|
|
@@ -26,6 +28,7 @@ export declare class ModernDevServer extends ModernServer {
|
|
|
26
28
|
event: WatchEvent;
|
|
27
29
|
}): void;
|
|
28
30
|
protected createContext(req: IncomingMessage, res: ServerResponse): import("@modern-js/prod-server/src/libs/context").ModernServerContext;
|
|
31
|
+
protected setupStaticMiddleware(_: string): (context: ModernServerContext, next: NextFunction) => Promise<void>;
|
|
29
32
|
private setupBeforeDevMiddleware;
|
|
30
33
|
private setupAfterDevMiddleware;
|
|
31
34
|
private cleanSSRCache;
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "2.6.0",
|
|
14
|
+
"version": "2.6.1-alpha.0",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"types": "./dist/types/index.d.ts",
|
|
17
17
|
"main": "./dist/cjs/index.js",
|
|
@@ -29,16 +29,19 @@
|
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@babel/core": "^7.18.0",
|
|
31
31
|
"@babel/register": "^7.17.7",
|
|
32
|
+
"@modern-js/prod-server": "2.6.0",
|
|
33
|
+
"@modern-js/server-utils": "2.6.0",
|
|
34
|
+
"@modern-js/types": "2.6.0",
|
|
35
|
+
"@modern-js/utils": "2.6.0",
|
|
32
36
|
"connect-history-api-fallback": "^2.0.0",
|
|
33
37
|
"minimatch": "^3.0.4",
|
|
34
38
|
"path-to-regexp": "^6.2.0",
|
|
35
|
-
"ws": "^8.2.0"
|
|
36
|
-
"@modern-js/prod-server": "2.6.0",
|
|
37
|
-
"@modern-js/types": "2.6.0",
|
|
38
|
-
"@modern-js/server-utils": "2.6.0",
|
|
39
|
-
"@modern-js/utils": "2.6.0"
|
|
39
|
+
"ws": "^8.2.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
+
"@modern-js/server-core": "2.6.0",
|
|
43
|
+
"@scripts/build": "2.6.0",
|
|
44
|
+
"@scripts/jest-config": "2.6.0",
|
|
42
45
|
"@types/connect-history-api-fallback": "^1.3.5",
|
|
43
46
|
"@types/jest": "^27",
|
|
44
47
|
"@types/minimatch": "^3.0.5",
|
|
@@ -50,10 +53,7 @@
|
|
|
50
53
|
"tsconfig-paths": "4.1.1",
|
|
51
54
|
"typescript": "^4",
|
|
52
55
|
"webpack": "^5.75.0",
|
|
53
|
-
"websocket": "^1"
|
|
54
|
-
"@modern-js/server-core": "2.6.0",
|
|
55
|
-
"@scripts/jest-config": "2.6.0",
|
|
56
|
-
"@scripts/build": "2.6.0"
|
|
56
|
+
"websocket": "^1"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
59
|
"devcert": "^1.0.0",
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|