@modern-js/server 2.48.0 → 2.48.2
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/constants.js +1 -1
- package/dist/cjs/dev-tools/dev-middleware/index.js +0 -4
- package/dist/cjs/dev-tools/dev-middleware/socketServer.js +2 -7
- package/dist/cjs/dev-tools/watcher/dependencyTree.js +0 -3
- package/dist/cjs/dev-tools/watcher/index.js +1 -3
- package/dist/cjs/dev-tools/watcher/statsCache.js +2 -3
- package/dist/cjs/server/devServer.js +6 -40
- package/dist/cjs/server/devServerOld.js +3 -9
- package/dist/cjs/server/workerSSRRender.js +1 -1
- package/dist/esm/constants.js +1 -1
- package/dist/esm/dev-tools/dev-middleware/index.js +42 -58
- package/dist/esm/dev-tools/dev-middleware/socketServer.js +130 -179
- package/dist/esm/dev-tools/watcher/dependencyTree.js +59 -80
- package/dist/esm/dev-tools/watcher/index.js +63 -82
- package/dist/esm/dev-tools/watcher/statsCache.js +55 -76
- package/dist/esm/server/devServer.js +432 -522
- package/dist/esm/server/devServerOld.js +455 -515
- package/dist/esm/server/workerSSRRender.js +1 -1
- package/dist/esm-node/constants.js +1 -1
- package/dist/esm-node/dev-tools/dev-middleware/index.js +0 -4
- package/dist/esm-node/dev-tools/dev-middleware/socketServer.js +2 -7
- package/dist/esm-node/dev-tools/watcher/dependencyTree.js +0 -3
- package/dist/esm-node/dev-tools/watcher/index.js +1 -3
- package/dist/esm-node/dev-tools/watcher/statsCache.js +2 -3
- package/dist/esm-node/server/devServer.js +6 -40
- package/dist/esm-node/server/devServerOld.js +3 -9
- package/dist/esm-node/server/workerSSRRender.js +1 -1
- package/dist/types/server/devServer.d.ts +1 -1
- package/dist/types/server/devServerOld.d.ts +1 -1
- package/dist/types/types.d.ts +3 -3
- package/package.json +10 -10
|
@@ -1,196 +1,147 @@
|
|
|
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 ws from "ws";
|
|
5
3
|
import { logger } from "@modern-js/utils";
|
|
6
4
|
var SocketServer = /* @__PURE__ */ function() {
|
|
7
5
|
"use strict";
|
|
8
6
|
function SocketServer2(options) {
|
|
9
7
|
_class_call_check(this, SocketServer2);
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
_define_property(this, "options", void 0);
|
|
13
|
-
_define_property(this, "app", void 0);
|
|
14
|
-
_define_property(this, "stats", void 0);
|
|
15
|
-
_define_property(this, "timer", null);
|
|
8
|
+
this.sockets = [];
|
|
9
|
+
this.timer = null;
|
|
16
10
|
this.options = options;
|
|
17
11
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
});
|
|
31
|
-
this.app.on("upgrade", function(req, sock, head) {
|
|
32
|
-
if (!_this.wsServer.shouldHandle(req)) {
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
_this.wsServer.handleUpgrade(req, sock, head, function(connection) {
|
|
36
|
-
_this.wsServer.emit("connection", connection, req);
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
this.wsServer.on("error", function(err) {
|
|
40
|
-
logger.error(err);
|
|
41
|
-
});
|
|
42
|
-
this.timer = setInterval(function() {
|
|
43
|
-
_this.wsServer.clients.forEach(function(socket) {
|
|
44
|
-
var extWs = socket;
|
|
45
|
-
if (!extWs.isAlive) {
|
|
46
|
-
extWs.terminate();
|
|
47
|
-
} else {
|
|
48
|
-
extWs.isAlive = false;
|
|
49
|
-
extWs.ping(function() {
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
}, 3e4);
|
|
54
|
-
this.wsServer.on("connection", function(socket) {
|
|
55
|
-
_this.onConnect(socket);
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
)
|
|
59
|
-
},
|
|
60
|
-
{
|
|
61
|
-
key: "updateStats",
|
|
62
|
-
value: function updateStats(stats) {
|
|
63
|
-
this.stats = stats;
|
|
64
|
-
this.sendStats();
|
|
12
|
+
var _proto = SocketServer2.prototype;
|
|
13
|
+
_proto.prepare = function prepare(app) {
|
|
14
|
+
var _this = this;
|
|
15
|
+
var _this_options_client;
|
|
16
|
+
this.app = app;
|
|
17
|
+
this.wsServer = new ws.Server({
|
|
18
|
+
noServer: true,
|
|
19
|
+
path: (_this_options_client = this.options.client) === null || _this_options_client === void 0 ? void 0 : _this_options_client.path
|
|
20
|
+
});
|
|
21
|
+
this.app.on("upgrade", function(req, sock, head) {
|
|
22
|
+
if (!_this.wsServer.shouldHandle(req)) {
|
|
23
|
+
return;
|
|
65
24
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
25
|
+
_this.wsServer.handleUpgrade(req, sock, head, function(connection) {
|
|
26
|
+
_this.wsServer.emit("connection", connection, req);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
this.wsServer.on("error", function(err) {
|
|
30
|
+
logger.error(err);
|
|
31
|
+
});
|
|
32
|
+
this.timer = setInterval(function() {
|
|
33
|
+
_this.wsServer.clients.forEach(function(socket) {
|
|
34
|
+
var extWs = socket;
|
|
35
|
+
if (!extWs.isAlive) {
|
|
36
|
+
extWs.terminate();
|
|
37
|
+
} else {
|
|
38
|
+
extWs.isAlive = false;
|
|
39
|
+
extWs.ping(function() {
|
|
78
40
|
});
|
|
79
41
|
}
|
|
80
|
-
)
|
|
81
|
-
},
|
|
82
|
-
{
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
this.sendStats(true);
|
|
130
|
-
}
|
|
42
|
+
});
|
|
43
|
+
}, 3e4);
|
|
44
|
+
this.wsServer.on("connection", function(socket) {
|
|
45
|
+
_this.onConnect(socket);
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
_proto.updateStats = function updateStats(stats) {
|
|
49
|
+
this.stats = stats;
|
|
50
|
+
this.sendStats();
|
|
51
|
+
};
|
|
52
|
+
_proto.sockWrite = function sockWrite(type, data) {
|
|
53
|
+
var _this = this;
|
|
54
|
+
this.sockets.forEach(function(socket) {
|
|
55
|
+
_this.send(socket, JSON.stringify({
|
|
56
|
+
type,
|
|
57
|
+
data
|
|
58
|
+
}));
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
_proto.singleWrite = function singleWrite(socket, type, data) {
|
|
62
|
+
this.send(socket, JSON.stringify({
|
|
63
|
+
type,
|
|
64
|
+
data
|
|
65
|
+
}));
|
|
66
|
+
};
|
|
67
|
+
_proto.close = function close() {
|
|
68
|
+
this.sockets.forEach(function(socket) {
|
|
69
|
+
socket.close();
|
|
70
|
+
});
|
|
71
|
+
if (this.timer) {
|
|
72
|
+
clearInterval(this.timer);
|
|
73
|
+
this.timer = null;
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
_proto.onConnect = function onConnect(socket) {
|
|
77
|
+
var _this = this;
|
|
78
|
+
var connection = socket;
|
|
79
|
+
connection.isAlive = true;
|
|
80
|
+
connection.on("pong", function() {
|
|
81
|
+
connection.isAlive = true;
|
|
82
|
+
});
|
|
83
|
+
if (!connection) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
this.sockets.push(connection);
|
|
87
|
+
connection.on("close", function() {
|
|
88
|
+
var idx = _this.sockets.indexOf(connection);
|
|
89
|
+
if (idx >= 0) {
|
|
90
|
+
_this.sockets.splice(idx, 1);
|
|
131
91
|
}
|
|
132
|
-
}
|
|
133
|
-
{
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
key: "send",
|
|
183
|
-
value: (
|
|
184
|
-
// send message to connecting socket
|
|
185
|
-
function send(connection, message) {
|
|
186
|
-
if (connection.readyState !== 1) {
|
|
187
|
-
return;
|
|
188
|
-
}
|
|
189
|
-
connection.send(message);
|
|
190
|
-
}
|
|
191
|
-
)
|
|
92
|
+
});
|
|
93
|
+
if (this.options.hot) {
|
|
94
|
+
this.singleWrite(connection, "hot");
|
|
95
|
+
}
|
|
96
|
+
if (this.options.liveReload) {
|
|
97
|
+
this.singleWrite(connection, "liveReload");
|
|
98
|
+
}
|
|
99
|
+
if (this.stats) {
|
|
100
|
+
this.sendStats(true);
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
_proto.getStats = function getStats() {
|
|
104
|
+
var curStats = this.stats;
|
|
105
|
+
if (!curStats) {
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
var defaultStats = {
|
|
109
|
+
all: false,
|
|
110
|
+
hash: true,
|
|
111
|
+
assets: true,
|
|
112
|
+
warnings: true,
|
|
113
|
+
errors: true,
|
|
114
|
+
errorDetails: false
|
|
115
|
+
};
|
|
116
|
+
return curStats.toJson(defaultStats);
|
|
117
|
+
};
|
|
118
|
+
_proto.sendStats = function sendStats() {
|
|
119
|
+
var force = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : false;
|
|
120
|
+
var stats = this.getStats();
|
|
121
|
+
if (!stats) {
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
var shouldEmit = !force && stats && (!stats.errors || stats.errors.length === 0) && stats.assets && stats.assets.every(function(asset) {
|
|
125
|
+
return !asset.emitted;
|
|
126
|
+
});
|
|
127
|
+
if (shouldEmit) {
|
|
128
|
+
return this.sockWrite("still-ok");
|
|
129
|
+
}
|
|
130
|
+
this.sockWrite("hash", stats.hash);
|
|
131
|
+
if (stats.errors && stats.errors.length > 0) {
|
|
132
|
+
return this.sockWrite("errors", stats.errors);
|
|
133
|
+
} else if (stats.warnings && stats.warnings.length > 0) {
|
|
134
|
+
return this.sockWrite("warnings", stats.warnings);
|
|
135
|
+
} else {
|
|
136
|
+
return this.sockWrite("ok");
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
_proto.send = function send(connection, message) {
|
|
140
|
+
if (connection.readyState !== 1) {
|
|
141
|
+
return;
|
|
192
142
|
}
|
|
193
|
-
|
|
143
|
+
connection.send(message);
|
|
144
|
+
};
|
|
194
145
|
return SocketServer2;
|
|
195
146
|
}();
|
|
196
147
|
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 _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
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
|
|
46
|
-
_define_property(this, "watcher", void 0);
|
|
43
|
+
this.dependencyTree = null;
|
|
47
44
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
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 {
|