Move file-watching logic into .NET to avoid Node's fs.watch issues on Windows (#128)

This commit is contained in:
SteveSandersonMS
2016-07-07 14:25:54 +01:00
parent ce127f0d70
commit eec370e938
10 changed files with 111 additions and 150 deletions

View File

@@ -44,7 +44,7 @@
/* 0 */
/***/ function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(7);
module.exports = __webpack_require__(5);
/***/ },
@@ -83,54 +83,19 @@
/***/ },
/* 5 */
/***/ function(module, exports, __webpack_require__) {
"use strict";
var fs = __webpack_require__(6);
var path = __webpack_require__(3);
function autoQuitOnFileChange(rootDir, extensions) {
// Note: This will only work on Windows/OS X, because the 'recursive' option isn't supported on Linux.
// Consider using a different watch mechanism (though ideally without forcing further NPM dependencies).
fs.watch(rootDir, { persistent: false, recursive: true }, function (event, filename) {
var ext = path.extname(filename);
if (extensions.indexOf(ext) >= 0) {
console.log('Restarting due to file change: ' + filename);
// Temporarily, the file-watching logic is in Node, so we signal it's time to restart by
// sending the following message back to .NET. Soon the file-watching logic will move over
// to the .NET side, and this whole file can be removed.
console.log('[Microsoft.AspNetCore.NodeServices:Restart]');
}
});
}
exports.autoQuitOnFileChange = autoQuitOnFileChange;
/***/ },
/* 6 */
/***/ function(module, exports) {
module.exports = require("fs");
/***/ },
/* 7 */
/***/ function(module, exports, __webpack_require__) {
"use strict";
// Limit dependencies to core Node modules. This means the code in this file has to be very low-level and unattractive,
// but simplifies things for the consumer of this module.
var net = __webpack_require__(8);
var net = __webpack_require__(6);
var path = __webpack_require__(3);
var readline = __webpack_require__(9);
var readline = __webpack_require__(7);
var ArgsUtil_1 = __webpack_require__(4);
var AutoQuit_1 = __webpack_require__(5);
var virtualConnectionServer = __webpack_require__(10);
var virtualConnectionServer = __webpack_require__(8);
// Webpack doesn't support dynamic requires for files not present at compile time, so grab a direct
// reference to Node's runtime 'require' function.
var dynamicRequire = eval('require');
var parsedArgs = ArgsUtil_1.parseArgs(process.argv);
if (parsedArgs.watch) {
AutoQuit_1.autoQuitOnFileChange(process.cwd(), parsedArgs.watch.split(','));
}
// Signal to the .NET side when we're ready to accept invocations
var server = net.createServer().on('listening', function () {
console.log('[Microsoft.AspNetCore.NodeServices:Listening]');
@@ -179,29 +144,30 @@
// Begin listening now. The underlying transport varies according to the runtime platform.
// On Windows it's Named Pipes; on Linux/OSX it's Domain Sockets.
var useWindowsNamedPipes = /^win/.test(process.platform);
var parsedArgs = ArgsUtil_1.parseArgs(process.argv);
var listenAddress = (useWindowsNamedPipes ? '\\\\.\\pipe\\' : '/tmp/') + parsedArgs.listenAddress;
server.listen(listenAddress);
/***/ },
/* 8 */
/* 6 */
/***/ function(module, exports) {
module.exports = require("net");
/***/ },
/* 9 */
/* 7 */
/***/ function(module, exports) {
module.exports = require("readline");
/***/ },
/* 10 */
/* 8 */
/***/ function(module, exports, __webpack_require__) {
"use strict";
var events_1 = __webpack_require__(11);
var VirtualConnection_1 = __webpack_require__(12);
var events_1 = __webpack_require__(9);
var VirtualConnection_1 = __webpack_require__(10);
// Keep this in sync with the equivalent constant in the .NET code. Both sides split up their transmissions into frames with this max length,
// and both will reject longer frames.
var MaxFrameBodyLength = 16 * 1024;
@@ -382,13 +348,13 @@
/***/ },
/* 11 */
/* 9 */
/***/ function(module, exports) {
module.exports = require("events");
/***/ },
/* 12 */
/* 10 */
/***/ function(module, exports, __webpack_require__) {
"use strict";
@@ -397,7 +363,7 @@
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var stream_1 = __webpack_require__(13);
var stream_1 = __webpack_require__(11);
/**
* Represents a virtual connection. Multiple virtual connections may be multiplexed over a single physical socket connection.
*/
@@ -438,7 +404,7 @@
/***/ },
/* 13 */
/* 11 */
/***/ function(module, exports) {
module.exports = require("stream");