Don't use depricated constructor

This commit is contained in:
Ryan Brandenburg
2018-08-23 15:54:03 -07:00
parent 24ebd9ff3e
commit c2f15f4199
18 changed files with 13975 additions and 970 deletions

View File

@@ -0,0 +1,28 @@
[cmdletbinding(SupportsShouldProcess = $true)]
param(
)
$ErrorActionPreference = 'Stop'
Set-StrictMode -Version 2
Push-Location "src"
try {
$dirs = Get-ChildItem -Directory
foreach($dir in $dirs)
{
Push-Location $dir
try{
if(Test-Path -Path "package.json")
{
npm install
npm run build
}
}
finally{
Pop-Location
}
}
}
finally {
Pop-Location
}

View File

@@ -1,75 +1,121 @@
(function(e, a) { for(var i in a) e[i] = a[i]; }(exports, /******/ (function(modules) { // webpackBootstrap (function(e, a) { for(var i in a) e[i] = a[i]; }(exports, /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache /******/ // The module cache
/******/ var installedModules = {}; /******/ var installedModules = {};
/******/
/******/ // The require function /******/ // The require function
/******/ function __webpack_require__(moduleId) { /******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache /******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) /******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports; /******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache) /******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = { /******/ var module = installedModules[moduleId] = {
/******/ exports: {}, /******/ i: moduleId,
/******/ id: moduleId, /******/ l: false,
/******/ loaded: false /******/ exports: {}
/******/ }; /******/ };
/******/
/******/ // Execute the module function /******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded /******/ // Flag the module as loaded
/******/ module.loaded = true; /******/ module.l = true;
/******/
/******/ // Return the exports of the module /******/ // Return the exports of the module
/******/ return module.exports; /******/ return module.exports;
/******/ } /******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__) /******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules; /******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache /******/ // expose the module cache
/******/ __webpack_require__.c = installedModules; /******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ }
/******/ };
/******/
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/
/******/ // create a fake namespace object
/******/ // mode & 1: value is a module id, require it
/******/ // mode & 2: merge all properties of value into the ns
/******/ // mode & 4: return value when already ns object
/******/ // mode & 8|1: behave like require
/******/ __webpack_require__.t = function(value, mode) {
/******/ if(mode & 1) value = __webpack_require__(value);
/******/ if(mode & 8) return value;
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ var ns = Object.create(null);
/******/ __webpack_require__.r(ns);
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ return ns;
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__ /******/ // __webpack_public_path__
/******/ __webpack_require__.p = ""; /******/ __webpack_require__.p = "";
/******/
/******/
/******/ // Load entry module and return exports /******/ // Load entry module and return exports
/******/ return __webpack_require__(0); /******/ return __webpack_require__(__webpack_require__.s = 0);
/******/ }) /******/ })
/************************************************************************/ /************************************************************************/
/******/ ([ /******/ ([
/* 0 */ /* 0 */
/***/ function(module, exports, __webpack_require__) { /***/ (function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(1); module.exports = __webpack_require__(1);
/***/ }, /***/ }),
/* 1 */ /* 1 */
/***/ function(module, exports, __webpack_require__) { /***/ (function(module, exports, __webpack_require__) {
"use strict"; "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. exports.__esModule = true;
__webpack_require__(2); // Limit dependencies to core Node modules. This means the code in this file has to be very low-level and unattractive,
var net = __webpack_require__(3); // but simplifies things for the consumer of this module.
var path = __webpack_require__(4); __webpack_require__(2);
var readline = __webpack_require__(5); var net = __webpack_require__(3);
var ArgsUtil_1 = __webpack_require__(6); var path = __webpack_require__(4);
var ExitWhenParentExits_1 = __webpack_require__(7); var readline = __webpack_require__(5);
var virtualConnectionServer = __webpack_require__(8); var ArgsUtil_1 = __webpack_require__(6);
// Webpack doesn't support dynamic requires for files not present at compile time, so grab a direct var ExitWhenParentExits_1 = __webpack_require__(7);
// reference to Node's runtime 'require' function. var virtualConnectionServer = __webpack_require__(8);
var dynamicRequire = eval('require'); // Webpack doesn't support dynamic requires for files not present at compile time, so grab a direct
// Signal to the .NET side when we're ready to accept invocations // reference to Node's runtime 'require' function.
var server = net.createServer().on('listening', function () { var dynamicRequire = eval('require');
// 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]'); console.log('[Microsoft.AspNetCore.NodeServices:Listening]');
}); });
// Each virtual connection represents a separate invocation // Each virtual connection represents a separate invocation
virtualConnectionServer.createInterface(server).on('connection', function (connection) { virtualConnectionServer.createInterface(server).on('connection', function (connection) {
readline.createInterface(connection, null).on('line', function (line) { readline.createInterface(connection, null).on('line', function (line) {
try { try {
// Get a reference to the function to invoke // Get a reference to the function to invoke
@@ -108,39 +154,39 @@
})); }));
} }
}); });
}); });
// Begin listening now. The underlying transport varies according to the runtime platform. // 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. // On Windows it's Named Pipes; on Linux/OSX it's Domain Sockets.
var useWindowsNamedPipes = /^win/.test(process.platform); var useWindowsNamedPipes = /^win/.test(process.platform);
var parsedArgs = ArgsUtil_1.parseArgs(process.argv); var parsedArgs = ArgsUtil_1.parseArgs(process.argv);
var listenAddress = (useWindowsNamedPipes ? '\\\\.\\pipe\\' : '/tmp/') + parsedArgs.listenAddress; var listenAddress = (useWindowsNamedPipes ? '\\\\.\\pipe\\' : '/tmp/') + parsedArgs.listenAddress;
server.listen(listenAddress); server.listen(listenAddress);
ExitWhenParentExits_1.exitWhenParentExits(parseInt(parsedArgs.parentPid)); ExitWhenParentExits_1.exitWhenParentExits(parseInt(parsedArgs.parentPid), /* ignoreSigint */ true);
/***/ }, /***/ }),
/* 2 */ /* 2 */
/***/ function(module, exports) { /***/ (function(module, exports) {
// When Node writes to stdout/strerr, we capture that and convert the lines into calls on the // When Node writes to stdout/strerr, we capture that and convert the lines into calls on the
// active .NET ILogger. But by default, stdout/stderr don't have any way of distinguishing // active .NET ILogger. But by default, stdout/stderr don't have any way of distinguishing
// linebreaks inside log messages from the linebreaks that delimit separate log messages, // linebreaks inside log messages from the linebreaks that delimit separate log messages,
// so multiline strings will end up being written to the ILogger as multiple independent // so multiline strings will end up being written to the ILogger as multiple independent
// log messages. This makes them very hard to make sense of, especially when they represent // log messages. This makes them very hard to make sense of, especially when they represent
// something like stack traces. // something like stack traces.
// //
// To fix this, we intercept stdout/stderr writes, and replace internal linebreaks with a // To fix this, we intercept stdout/stderr writes, and replace internal linebreaks with a
// marker token. When .NET receives the lines, it converts the marker tokens back to regular // marker token. When .NET receives the lines, it converts the marker tokens back to regular
// linebreaks within the logged messages. // linebreaks within the logged messages.
// //
// Note that it's better to do the interception at the stdout/stderr level, rather than at // Note that it's better to do the interception at the stdout/stderr level, rather than at
// the console.log/console.error (etc.) level, because this takes place after any native // the console.log/console.error (etc.) level, because this takes place after any native
// message formatting has taken place (e.g., inserting values for % placeholders). // message formatting has taken place (e.g., inserting values for % placeholders).
var findInternalNewlinesRegex = /\n(?!$)/g; var findInternalNewlinesRegex = /\n(?!$)/g;
var encodedNewline = '__ns_newline__'; var encodedNewline = '__ns_newline__';
encodeNewlinesWrittenToStream(process.stdout); encodeNewlinesWrittenToStream(process.stdout);
encodeNewlinesWrittenToStream(process.stderr); encodeNewlinesWrittenToStream(process.stderr);
function encodeNewlinesWrittenToStream(outputStream) { function encodeNewlinesWrittenToStream(outputStream) {
var origWriteFunction = outputStream.write; var origWriteFunction = outputStream.write;
outputStream.write = function (value) { outputStream.write = function (value) {
// Only interfere with the write if it's definitely a string // Only interfere with the write if it's definitely a string
@@ -153,36 +199,38 @@
origWriteFunction.apply(this, arguments); origWriteFunction.apply(this, arguments);
} }
}; };
} }
function encodeNewlinesInString(str) { function encodeNewlinesInString(str) {
return str.replace(findInternalNewlinesRegex, encodedNewline); return str.replace(findInternalNewlinesRegex, encodedNewline);
} }
/***/ }, /***/ }),
/* 3 */ /* 3 */
/***/ function(module, exports) { /***/ (function(module, exports) {
module.exports = require("net"); module.exports = require("net");
/***/ }, /***/ }),
/* 4 */ /* 4 */
/***/ function(module, exports) { /***/ (function(module, exports) {
module.exports = require("path"); module.exports = require("path");
/***/ }, /***/ }),
/* 5 */ /* 5 */
/***/ function(module, exports) { /***/ (function(module, exports) {
module.exports = require("readline"); module.exports = require("readline");
/***/ }, /***/ }),
/* 6 */ /* 6 */
/***/ function(module, exports) { /***/ (function(module, exports, __webpack_require__) {
"use strict"; "use strict";
function parseArgs(args) {
exports.__esModule = true;
function parseArgs(args) {
// Very simplistic parsing which is sufficient for the cases needed. We don't want to bring in any external // Very simplistic parsing which is sufficient for the cases needed. We don't want to bring in any external
// dependencies (such as an args-parsing library) to this file. // dependencies (such as an args-parsing library) to this file.
var result = {}; var result = {};
@@ -199,25 +247,27 @@
} }
}); });
return result; return result;
} }
exports.parseArgs = parseArgs; exports.parseArgs = parseArgs;
/***/ }, /***/ }),
/* 7 */ /* 7 */
/***/ function(module, exports) { /***/ (function(module, exports, __webpack_require__) {
/* "use strict";
In general, we want the Node child processes to be terminated as soon as the parent .NET processes exit,
because we have no further use for them. If the .NET process shuts down gracefully, it will run its
finalizers, one of which (in OutOfProcessNodeInstance.cs) will kill its associated Node process immediately.
But if the .NET process is terminated forcefully (e.g., on Linux/OSX with 'kill -9'), then it won't have /*
any opportunity to shut down its child processes, and by default they will keep running. In this case, it's In general, we want the Node child processes to be terminated as soon as the parent .NET processes exit,
up to the child process to detect this has happened and terminate itself. because we have no further use for them. If the .NET process shuts down gracefully, it will run its
finalizers, one of which (in OutOfProcessNodeInstance.cs) will kill its associated Node process immediately.
There are many possible approaches to detecting when a parent process has exited, most of which behave But if the .NET process is terminated forcefully (e.g., on Linux/OSX with 'kill -9'), then it won't have
differently between Windows and Linux/OS X: any opportunity to shut down its child processes, and by default they will keep running. In this case, it's
up to the child process to detect this has happened and terminate itself.
There are many possible approaches to detecting when a parent process has exited, most of which behave
differently between Windows and Linux/OS X:
- On Windows, the parent process can mark its child as being a 'job' that should auto-terminate when - On Windows, the parent process can mark its child as being a 'job' that should auto-terminate when
the parent does (http://stackoverflow.com/a/4657392). Not cross-platform. the parent does (http://stackoverflow.com/a/4657392). Not cross-platform.
@@ -237,12 +287,12 @@
process.stdout is still connected (without actually writing to it) but I haven't found any property whose process.stdout is still connected (without actually writing to it) but I haven't found any property whose
value changes until you actually try to write to it. value changes until you actually try to write to it.
Of these, the only cross-platform approach that is actually documented as a valid strategy is simply polling Of these, the only cross-platform approach that is actually documented as a valid strategy is simply polling
to check whether the parent PID is still running. So that's what we do here. to check whether the parent PID is still running. So that's what we do here.
*/ */
"use strict"; exports.__esModule = true;
var pollIntervalMs = 1000; var pollIntervalMs = 1000;
function exitWhenParentExits(parentPid) { function exitWhenParentExits(parentPid, ignoreSigint) {
setInterval(function () { setInterval(function () {
if (!processExists(parentPid)) { if (!processExists(parentPid)) {
// Can't log anything at this point, because out stdout was connected to the parent, // Can't log anything at this point, because out stdout was connected to the parent,
@@ -250,9 +300,27 @@
process.exit(); process.exit();
} }
}, pollIntervalMs); }, pollIntervalMs);
if (ignoreSigint) {
// Pressing ctrl+c in the terminal sends a SIGINT to all processes in the foreground process tree.
// By default, the Node process would then exit before the .NET process, because ASP.NET implements
// a delayed shutdown to allow ongoing requests to complete.
//
// This is problematic, because if Node exits first, the CopyToAsync code in ConditionalProxyMiddleware
// will experience a read fault, and logs a huge load of errors. Fortunately, since the Node process is
// already set up to shut itself down if it detects the .NET process is terminated, all we have to do is
// ignore the SIGINT. The Node process will then terminate automatically after the .NET process does.
//
// A better solution would be to have WebpackDevMiddleware listen for SIGINT and gracefully close any
// ongoing EventSource connections before letting the Node process exit, independently of the .NET
// process exiting. However, doing this well in general is very nontrivial (see all the discussion at
// https://github.com/nodejs/node/issues/2642).
process.on('SIGINT', function () {
console.log('Received SIGINT. Waiting for .NET process to exit...');
});
} }
exports.exitWhenParentExits = exitWhenParentExits; }
function processExists(pid) { exports.exitWhenParentExits = exitWhenParentExits;
function processExists(pid) {
try { try {
// Sending signal 0 - on all platforms - tests whether the process exists. As long as it doesn't // Sending signal 0 - on all platforms - tests whether the process exists. As long as it doesn't
// throw, that means it does exist. // throw, that means it does exist.
@@ -267,25 +335,27 @@
} }
return false; return false;
} }
} }
/***/ }, /***/ }),
/* 8 */ /* 8 */
/***/ function(module, exports, __webpack_require__) { /***/ (function(module, exports, __webpack_require__) {
"use strict"; "use strict";
var events_1 = __webpack_require__(9);
var VirtualConnection_1 = __webpack_require__(10); exports.__esModule = true;
// Keep this in sync with the equivalent constant in the .NET code. Both sides split up their transmissions into frames with this max length, var events_1 = __webpack_require__(9);
// and both will reject longer frames. var VirtualConnection_1 = __webpack_require__(10);
var MaxFrameBodyLength = 16 * 1024; // 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;
/**
* Accepts connections to a net.Server and adapts them to behave as multiplexed connections. That is, for each physical socket connection, * Accepts connections to a net.Server and adapts them to behave as multiplexed connections. That is, for each physical socket connection,
* we track a list of 'virtual connections' whose API is a Duplex stream. The remote clients may open and close as many virtual connections * we track a list of 'virtual connections' whose API is a Duplex stream. The remote clients may open and close as many virtual connections
* as they wish, reading and writing to them independently, without the overhead of establishing new physical connections each time. * as they wish, reading and writing to them independently, without the overhead of establishing new physical connections each time.
*/ */
function createInterface(server) { function createInterface(server) {
var emitter = new events_1.EventEmitter(); var emitter = new events_1.EventEmitter();
server.on('connection', function (socket) { server.on('connection', function (socket) {
// For each physical socket connection, maintain a set of virtual connections. Issue a notification whenever // For each physical socket connection, maintain a set of virtual connections. Issue a notification whenever
@@ -295,12 +365,12 @@
}); });
}); });
return emitter; return emitter;
} }
exports.createInterface = createInterface; exports.createInterface = createInterface;
/** /**
* Tracks the 'virtual connections' associated with a single physical socket connection. * Tracks the 'virtual connections' associated with a single physical socket connection.
*/ */
var VirtualConnectionsCollection = (function () { var VirtualConnectionsCollection = /** @class */ (function () {
function VirtualConnectionsCollection(_socket, _onVirtualConnectionCallback) { function VirtualConnectionsCollection(_socket, _onVirtualConnectionCallback) {
var _this = this; var _this = this;
this._socket = _socket; this._socket = _socket;
@@ -382,7 +452,7 @@
newVirtualConnection.on('finish', function () { newVirtualConnection.on('finish', function () {
// The virtual connection was closed locally. Clean up locally, and notify the remote that we're done. // The virtual connection was closed locally. Clean up locally, and notify the remote that we're done.
_this._onVirtualConnectionWasClosed(header.connectionIdString); _this._onVirtualConnectionWasClosed(header.connectionIdString);
_this._sendFrame(header.connectionIdBinary, new Buffer(0)); _this._sendFrame(header.connectionIdBinary, Buffer.alloc(0));
}); });
this._virtualConnections[header.connectionIdString] = newVirtualConnection; this._virtualConnections[header.connectionIdString] = newVirtualConnection;
this._onVirtualConnectionCallback(newVirtualConnection); this._onVirtualConnectionCallback(newVirtualConnection);
@@ -444,7 +514,7 @@
* Sends a number serialized in the correct format for .NET to receive as a System.Int32 * Sends a number serialized in the correct format for .NET to receive as a System.Int32
*/ */
VirtualConnectionsCollection.prototype._sendInt32LE = function (value, callback) { VirtualConnectionsCollection.prototype._sendInt32LE = function (value, callback) {
var buf = new Buffer(4); var buf = Buffer.alloc(4);
buf.writeInt32LE(value, 0); buf.writeInt32LE(value, 0);
this._socket.write(buf, callback); this._socket.write(buf, callback);
}; };
@@ -454,30 +524,40 @@
} }
}; };
return VirtualConnectionsCollection; return VirtualConnectionsCollection;
}()); }());
/***/ }, /***/ }),
/* 9 */ /* 9 */
/***/ function(module, exports) { /***/ (function(module, exports) {
module.exports = require("events"); module.exports = require("events");
/***/ }, /***/ }),
/* 10 */ /* 10 */
/***/ function(module, exports, __webpack_require__) { /***/ (function(module, exports, __webpack_require__) {
"use strict"; "use strict";
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
}
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; } function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}; };
var stream_1 = __webpack_require__(11); })();
/** exports.__esModule = true;
var stream_1 = __webpack_require__(11);
/**
* Represents a virtual connection. Multiple virtual connections may be multiplexed over a single physical socket connection. * Represents a virtual connection. Multiple virtual connections may be multiplexed over a single physical socket connection.
*/ */
var VirtualConnection = (function (_super) { var VirtualConnection = /** @class */ (function (_super) {
__extends(VirtualConnection, _super); __extends(VirtualConnection, _super);
function VirtualConnection(_beginWriteCallback) { function VirtualConnection(_beginWriteCallback) {
var _this = _super.call(this) || this; var _this = _super.call(this) || this;
@@ -497,7 +577,7 @@
}; };
VirtualConnection.prototype._write = function (chunk, encodingIfString, callback) { VirtualConnection.prototype._write = function (chunk, encodingIfString, callback) {
if (typeof chunk === 'string') { if (typeof chunk === 'string') {
chunk = new Buffer(chunk, encodingIfString); chunk = Buffer.from(chunk, encodingIfString);
} }
this._beginWriteCallback(chunk, callback); this._beginWriteCallback(chunk, callback);
}; };
@@ -510,15 +590,15 @@
} }
}; };
return VirtualConnection; return VirtualConnection;
}(stream_1.Duplex)); }(stream_1.Duplex));
exports.VirtualConnection = VirtualConnection; exports.VirtualConnection = VirtualConnection;
/***/ }, /***/ }),
/* 11 */ /* 11 */
/***/ function(module, exports) { /***/ (function(module, exports) {
module.exports = require("stream"); module.exports = require("stream");
/***/ } /***/ })
/******/ ]))); /******/ ])));

View File

@@ -27,7 +27,7 @@ export class VirtualConnection extends Duplex {
public _write(chunk: Buffer | string, encodingIfString: string, callback: EndWriteCallback) { public _write(chunk: Buffer | string, encodingIfString: string, callback: EndWriteCallback) {
if (typeof chunk === 'string') { if (typeof chunk === 'string') {
chunk = new Buffer(chunk as string, encodingIfString); chunk = Buffer.from(chunk as string, encodingIfString);
} }
this._beginWriteCallback(chunk as Buffer, callback); this._beginWriteCallback(chunk as Buffer, callback);

View File

@@ -113,7 +113,7 @@ class VirtualConnectionsCollection {
newVirtualConnection.on('finish', () => { newVirtualConnection.on('finish', () => {
// The virtual connection was closed locally. Clean up locally, and notify the remote that we're done. // The virtual connection was closed locally. Clean up locally, and notify the remote that we're done.
this._onVirtualConnectionWasClosed(header.connectionIdString); this._onVirtualConnectionWasClosed(header.connectionIdString);
this._sendFrame(header.connectionIdBinary, new Buffer(0)); this._sendFrame(header.connectionIdBinary, Buffer.alloc(0));
}); });
this._virtualConnections[header.connectionIdString] = newVirtualConnection; this._virtualConnections[header.connectionIdString] = newVirtualConnection;
@@ -180,7 +180,7 @@ class VirtualConnectionsCollection {
* Sends a number serialized in the correct format for .NET to receive as a System.Int32 * Sends a number serialized in the correct format for .NET to receive as a System.Int32
*/ */
private _sendInt32LE(value: number, callback?: EndWriteCallback) { private _sendInt32LE(value: number, callback?: EndWriteCallback) {
const buf = new Buffer(4); const buf = Buffer.alloc(4);
buf.writeInt32LE(value, 0); buf.writeInt32LE(value, 0);
this._socket.write(buf, callback); this._socket.write(buf, callback);
} }

File diff suppressed because it is too large Load Diff

View File

@@ -5,14 +5,15 @@
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1", "test": "echo \"Error: no test specified\" && exit 1",
"build": "./node_modules/.bin/webpack" "build": "webpack --mode production"
}, },
"author": "Microsoft", "author": "Microsoft",
"license": "Apache-2.0", "license": "Apache-2.0",
"devDependencies": { "devDependencies": {
"@types/node": "^6.0.42", "@types/node": "^10.9.2",
"ts-loader": "^0.8.2", "ts-loader": "^4.5.0",
"typescript": "^2.0.0", "typescript": "^3.0.1",
"webpack": "^1.13.1" "webpack": "^4.17.1",
"webpack-cli": "^3.1.0"
} }
} }

View File

@@ -1,12 +1,13 @@
const path = require('path');
module.exports = { module.exports = {
target: 'node', target: 'node',
externals: ['fs', 'net', 'events', 'readline', 'stream'],
resolve: { resolve: {
extensions: [ '.ts' ] extensions: [ '.ts' ]
}, },
module: { module: {
loaders: [ rules: [
{ test: /\.ts$/, loader: 'ts-loader' }, { test: /\.ts$/, use: 'ts-loader' },
] ]
}, },
entry: { entry: {
@@ -14,7 +15,10 @@ module.exports = {
}, },
output: { output: {
libraryTarget: 'commonjs', libraryTarget: 'commonjs',
path: './Content/Node', path: path.join(__dirname, 'Content', 'Node'),
filename: '[name].js' filename: '[name].js'
},
optimization: {
minimize: false
} }
}; };

View File

@@ -1,69 +1,121 @@
(function(e, a) { for(var i in a) e[i] = a[i]; }(exports, /******/ (function(modules) { // webpackBootstrap (function(e, a) { for(var i in a) e[i] = a[i]; }(exports, /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache /******/ // The module cache
/******/ var installedModules = {}; /******/ var installedModules = {};
/******/
/******/ // The require function /******/ // The require function
/******/ function __webpack_require__(moduleId) { /******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache /******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) /******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports; /******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache) /******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = { /******/ var module = installedModules[moduleId] = {
/******/ exports: {}, /******/ i: moduleId,
/******/ id: moduleId, /******/ l: false,
/******/ loaded: false /******/ exports: {}
/******/ }; /******/ };
/******/
/******/ // Execute the module function /******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded /******/ // Flag the module as loaded
/******/ module.loaded = true; /******/ module.l = true;
/******/
/******/ // Return the exports of the module /******/ // Return the exports of the module
/******/ return module.exports; /******/ return module.exports;
/******/ } /******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__) /******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules; /******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache /******/ // expose the module cache
/******/ __webpack_require__.c = installedModules; /******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ }
/******/ };
/******/
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/
/******/ // create a fake namespace object
/******/ // mode & 1: value is a module id, require it
/******/ // mode & 2: merge all properties of value into the ns
/******/ // mode & 4: return value when already ns object
/******/ // mode & 8|1: behave like require
/******/ __webpack_require__.t = function(value, mode) {
/******/ if(mode & 1) value = __webpack_require__(value);
/******/ if(mode & 8) return value;
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ var ns = Object.create(null);
/******/ __webpack_require__.r(ns);
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ return ns;
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__ /******/ // __webpack_public_path__
/******/ __webpack_require__.p = ""; /******/ __webpack_require__.p = "";
/******/
/******/
/******/ // Load entry module and return exports /******/ // Load entry module and return exports
/******/ return __webpack_require__(0); /******/ return __webpack_require__(__webpack_require__.s = 1);
/******/ }) /******/ })
/************************************************************************/ /************************************************************************/
/******/ ([ /******/ ([
/* 0 */ /* 0 */
/***/ function(module, exports, __webpack_require__) { /***/ (function(module, exports) {
module.exports = __webpack_require__(1); module.exports = require("path");
/***/ }),
/***/ },
/* 1 */ /* 1 */
/***/ function(module, exports, __webpack_require__) { /***/ (function(module, exports, __webpack_require__) {
"use strict"; module.exports = __webpack_require__(2);
// 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.
__webpack_require__(2); /***/ }),
__webpack_require__(4); /* 2 */
var http = __webpack_require__(5); /***/ (function(module, exports, __webpack_require__) {
var path = __webpack_require__(3);
var ArgsUtil_1 = __webpack_require__(6); "use strict";
var ExitWhenParentExits_1 = __webpack_require__(7);
// Webpack doesn't support dynamic requires for files not present at compile time, so grab a direct exports.__esModule = true;
// reference to Node's runtime 'require' function. // Limit dependencies to core Node modules. This means the code in this file has to be very low-level and unattractive,
var dynamicRequire = eval('require'); // but simplifies things for the consumer of this module.
var server = http.createServer(function (req, res) { __webpack_require__(3);
__webpack_require__(4);
var http = __webpack_require__(5);
var path = __webpack_require__(0);
var ArgsUtil_1 = __webpack_require__(6);
var ExitWhenParentExits_1 = __webpack_require__(7);
// 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 server = http.createServer(function (req, res) {
readRequestBodyAsJson(req, function (bodyJson) { readRequestBodyAsJson(req, function (bodyJson) {
var hasSentResult = false; var hasSentResult = false;
var callback = function (errorValue, successValue) { var callback = function (errorValue, successValue) {
@@ -117,39 +169,42 @@
callback(synchronousException, null); callback(synchronousException, null);
} }
}); });
}); });
var parsedArgs = ArgsUtil_1.parseArgs(process.argv); var parsedArgs = ArgsUtil_1.parseArgs(process.argv);
var requestedPortOrZero = parsedArgs.port || 0; // 0 means 'let the OS decide' var requestedPortOrZero = parsedArgs.port || 0; // 0 means 'let the OS decide'
server.listen(requestedPortOrZero, 'localhost', function () { server.listen(requestedPortOrZero, 'localhost', function () {
var addressInfo = server.address();
// Signal to HttpNodeHost which loopback IP address (IPv4 or IPv6) and port it should make its HTTP connections on // Signal to HttpNodeHost which loopback IP address (IPv4 or IPv6) and port it should make its HTTP connections on
console.log('[Microsoft.AspNetCore.NodeServices.HttpNodeHost:Listening on {' + server.address().address + '} port ' + server.address().port + '\]'); console.log('[Microsoft.AspNetCore.NodeServices.HttpNodeHost:Listening on {' + addressInfo.address + '} port ' + addressInfo.port + '\]');
// Signal to the NodeServices base class that we're ready to accept invocations // Signal to the NodeServices base class that we're ready to accept invocations
console.log('[Microsoft.AspNetCore.NodeServices:Listening]'); console.log('[Microsoft.AspNetCore.NodeServices:Listening]');
}); });
ExitWhenParentExits_1.exitWhenParentExits(parseInt(parsedArgs.parentPid), /* ignoreSigint */ true); ExitWhenParentExits_1.exitWhenParentExits(parseInt(parsedArgs.parentPid), /* ignoreSigint */ true);
function readRequestBodyAsJson(request, callback) { function readRequestBodyAsJson(request, callback) {
var requestBodyAsString = ''; var requestBodyAsString = '';
request.on('data', function (chunk) { requestBodyAsString += chunk; }); request.on('data', function (chunk) { requestBodyAsString += chunk; });
request.on('end', function () { callback(JSON.parse(requestBodyAsString)); }); request.on('end', function () { callback(JSON.parse(requestBodyAsString)); });
} }
function respondWithError(res, errorValue) { function respondWithError(res, errorValue) {
res.statusCode = 500; res.statusCode = 500;
res.end(JSON.stringify({ res.end(JSON.stringify({
errorMessage: errorValue.message || errorValue, errorMessage: errorValue.message || errorValue,
errorDetails: errorValue.stack || null errorDetails: errorValue.stack || null
})); }));
} }
/***/ }, /***/ }),
/* 2 */ /* 3 */
/***/ function(module, exports, __webpack_require__) { /***/ (function(module, exports, __webpack_require__) {
"use strict"; "use strict";
var path = __webpack_require__(3);
var startsWith = function (str, prefix) { return str.substring(0, prefix.length) === prefix; }; exports.__esModule = true;
var appRootDir = process.cwd(); var path = __webpack_require__(0);
function patchedLStat(pathToStatLong, fsReqWrap) { var startsWith = function (str, prefix) { return str.substring(0, prefix.length) === prefix; };
var appRootDir = process.cwd();
function patchedLStat(pathToStatLong, fsReqWrap) {
try { try {
// If the lstat completes without errors, we don't modify its behavior at all // If the lstat completes without errors, we don't modify its behavior at all
return origLStat.apply(this, arguments); return origLStat.apply(this, arguments);
@@ -172,12 +227,12 @@
throw ex; throw ex;
} }
} }
} }
; ;
// It's only necessary to apply this workaround on Windows // It's only necessary to apply this workaround on Windows
var appRootDirLong = null; var appRootDirLong = null;
var origLStat = null; var origLStat = null;
if (/^win/.test(process.platform)) { if (/^win/.test(process.platform)) {
try { try {
// Get the app's root dir in Node's internal "long" format (e.g., \\?\C:\dir\subdir) // Get the app's root dir in Node's internal "long" format (e.g., \\?\C:\dir\subdir)
appRootDirLong = path._makeLong(appRootDir); appRootDirLong = path._makeLong(appRootDir);
@@ -189,39 +244,35 @@
} }
} }
catch (ex) { catch (ex) {
// If some future version of Node throws (e.g., to prevent use of process.binding()),
// don't apply the patch, but still let the application run.
} }
} }
/***/ }, /***/ }),
/* 3 */
/***/ function(module, exports) {
module.exports = require("path");
/***/ },
/* 4 */ /* 4 */
/***/ function(module, exports) { /***/ (function(module, exports) {
// When Node writes to stdout/strerr, we capture that and convert the lines into calls on the // When Node writes to stdout/strerr, we capture that and convert the lines into calls on the
// active .NET ILogger. But by default, stdout/stderr don't have any way of distinguishing // active .NET ILogger. But by default, stdout/stderr don't have any way of distinguishing
// linebreaks inside log messages from the linebreaks that delimit separate log messages, // linebreaks inside log messages from the linebreaks that delimit separate log messages,
// so multiline strings will end up being written to the ILogger as multiple independent // so multiline strings will end up being written to the ILogger as multiple independent
// log messages. This makes them very hard to make sense of, especially when they represent // log messages. This makes them very hard to make sense of, especially when they represent
// something like stack traces. // something like stack traces.
// //
// To fix this, we intercept stdout/stderr writes, and replace internal linebreaks with a // To fix this, we intercept stdout/stderr writes, and replace internal linebreaks with a
// marker token. When .NET receives the lines, it converts the marker tokens back to regular // marker token. When .NET receives the lines, it converts the marker tokens back to regular
// linebreaks within the logged messages. // linebreaks within the logged messages.
// //
// Note that it's better to do the interception at the stdout/stderr level, rather than at // Note that it's better to do the interception at the stdout/stderr level, rather than at
// the console.log/console.error (etc.) level, because this takes place after any native // the console.log/console.error (etc.) level, because this takes place after any native
// message formatting has taken place (e.g., inserting values for % placeholders). // message formatting has taken place (e.g., inserting values for % placeholders).
var findInternalNewlinesRegex = /\n(?!$)/g; var findInternalNewlinesRegex = /\n(?!$)/g;
var encodedNewline = '__ns_newline__'; var encodedNewline = '__ns_newline__';
encodeNewlinesWrittenToStream(process.stdout); encodeNewlinesWrittenToStream(process.stdout);
encodeNewlinesWrittenToStream(process.stderr); encodeNewlinesWrittenToStream(process.stderr);
function encodeNewlinesWrittenToStream(outputStream) { function encodeNewlinesWrittenToStream(outputStream) {
var origWriteFunction = outputStream.write; var origWriteFunction = outputStream.write;
outputStream.write = function (value) { outputStream.write = function (value) {
// Only interfere with the write if it's definitely a string // Only interfere with the write if it's definitely a string
@@ -234,24 +285,26 @@
origWriteFunction.apply(this, arguments); origWriteFunction.apply(this, arguments);
} }
}; };
} }
function encodeNewlinesInString(str) { function encodeNewlinesInString(str) {
return str.replace(findInternalNewlinesRegex, encodedNewline); return str.replace(findInternalNewlinesRegex, encodedNewline);
} }
/***/ }, /***/ }),
/* 5 */ /* 5 */
/***/ function(module, exports) { /***/ (function(module, exports) {
module.exports = require("http"); module.exports = require("http");
/***/ }, /***/ }),
/* 6 */ /* 6 */
/***/ function(module, exports) { /***/ (function(module, exports, __webpack_require__) {
"use strict"; "use strict";
function parseArgs(args) {
exports.__esModule = true;
function parseArgs(args) {
// Very simplistic parsing which is sufficient for the cases needed. We don't want to bring in any external // Very simplistic parsing which is sufficient for the cases needed. We don't want to bring in any external
// dependencies (such as an args-parsing library) to this file. // dependencies (such as an args-parsing library) to this file.
var result = {}; var result = {};
@@ -268,25 +321,27 @@
} }
}); });
return result; return result;
} }
exports.parseArgs = parseArgs; exports.parseArgs = parseArgs;
/***/ }, /***/ }),
/* 7 */ /* 7 */
/***/ function(module, exports) { /***/ (function(module, exports, __webpack_require__) {
/* "use strict";
In general, we want the Node child processes to be terminated as soon as the parent .NET processes exit,
because we have no further use for them. If the .NET process shuts down gracefully, it will run its
finalizers, one of which (in OutOfProcessNodeInstance.cs) will kill its associated Node process immediately.
But if the .NET process is terminated forcefully (e.g., on Linux/OSX with 'kill -9'), then it won't have /*
any opportunity to shut down its child processes, and by default they will keep running. In this case, it's In general, we want the Node child processes to be terminated as soon as the parent .NET processes exit,
up to the child process to detect this has happened and terminate itself. because we have no further use for them. If the .NET process shuts down gracefully, it will run its
finalizers, one of which (in OutOfProcessNodeInstance.cs) will kill its associated Node process immediately.
There are many possible approaches to detecting when a parent process has exited, most of which behave But if the .NET process is terminated forcefully (e.g., on Linux/OSX with 'kill -9'), then it won't have
differently between Windows and Linux/OS X: any opportunity to shut down its child processes, and by default they will keep running. In this case, it's
up to the child process to detect this has happened and terminate itself.
There are many possible approaches to detecting when a parent process has exited, most of which behave
differently between Windows and Linux/OS X:
- On Windows, the parent process can mark its child as being a 'job' that should auto-terminate when - On Windows, the parent process can mark its child as being a 'job' that should auto-terminate when
the parent does (http://stackoverflow.com/a/4657392). Not cross-platform. the parent does (http://stackoverflow.com/a/4657392). Not cross-platform.
@@ -306,12 +361,12 @@
process.stdout is still connected (without actually writing to it) but I haven't found any property whose process.stdout is still connected (without actually writing to it) but I haven't found any property whose
value changes until you actually try to write to it. value changes until you actually try to write to it.
Of these, the only cross-platform approach that is actually documented as a valid strategy is simply polling Of these, the only cross-platform approach that is actually documented as a valid strategy is simply polling
to check whether the parent PID is still running. So that's what we do here. to check whether the parent PID is still running. So that's what we do here.
*/ */
"use strict"; exports.__esModule = true;
var pollIntervalMs = 1000; var pollIntervalMs = 1000;
function exitWhenParentExits(parentPid, ignoreSigint) { function exitWhenParentExits(parentPid, ignoreSigint) {
setInterval(function () { setInterval(function () {
if (!processExists(parentPid)) { if (!processExists(parentPid)) {
// Can't log anything at this point, because out stdout was connected to the parent, // Can't log anything at this point, because out stdout was connected to the parent,
@@ -337,9 +392,9 @@
console.log('Received SIGINT. Waiting for .NET process to exit...'); console.log('Received SIGINT. Waiting for .NET process to exit...');
}); });
} }
} }
exports.exitWhenParentExits = exitWhenParentExits; exports.exitWhenParentExits = exitWhenParentExits;
function processExists(pid) { function processExists(pid) {
try { try {
// Sending signal 0 - on all platforms - tests whether the process exists. As long as it doesn't // Sending signal 0 - on all platforms - tests whether the process exists. As long as it doesn't
// throw, that means it does exist. // throw, that means it does exist.
@@ -354,8 +409,8 @@
} }
return false; return false;
} }
} }
/***/ } /***/ })
/******/ ]))); /******/ ])));

View File

@@ -6,6 +6,7 @@ import * as http from 'http';
import * as path from 'path'; import * as path from 'path';
import { parseArgs } from './Util/ArgsUtil'; import { parseArgs } from './Util/ArgsUtil';
import { exitWhenParentExits } from './Util/ExitWhenParentExits'; import { exitWhenParentExits } from './Util/ExitWhenParentExits';
import { AddressInfo } from 'net';
// Webpack doesn't support dynamic requires for files not present at compile time, so grab a direct // Webpack doesn't support dynamic requires for files not present at compile time, so grab a direct
// reference to Node's runtime 'require' function. // reference to Node's runtime 'require' function.
@@ -70,8 +71,10 @@ const server = http.createServer((req, res) => {
const parsedArgs = parseArgs(process.argv); const parsedArgs = parseArgs(process.argv);
const requestedPortOrZero = parsedArgs.port || 0; // 0 means 'let the OS decide' const requestedPortOrZero = parsedArgs.port || 0; // 0 means 'let the OS decide'
server.listen(requestedPortOrZero, 'localhost', function () { server.listen(requestedPortOrZero, 'localhost', function () {
const addressInfo = server.address() as AddressInfo;
// Signal to HttpNodeHost which loopback IP address (IPv4 or IPv6) and port it should make its HTTP connections on // Signal to HttpNodeHost which loopback IP address (IPv4 or IPv6) and port it should make its HTTP connections on
console.log('[Microsoft.AspNetCore.NodeServices.HttpNodeHost:Listening on {' + server.address().address + '} port ' + server.address().port + '\]'); console.log('[Microsoft.AspNetCore.NodeServices.HttpNodeHost:Listening on {' + addressInfo.address + '} port ' + addressInfo.port + '\]');
// Signal to the NodeServices base class that we're ready to accept invocations // Signal to the NodeServices base class that we're ready to accept invocations
console.log('[Microsoft.AspNetCore.NodeServices:Listening]'); console.log('[Microsoft.AspNetCore.NodeServices:Listening]');

File diff suppressed because it is too large Load Diff

View File

@@ -5,14 +5,15 @@
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1", "test": "echo \"Error: no test specified\" && exit 1",
"build": "./node_modules/.bin/webpack" "build": "webpack --mode production"
}, },
"author": "Microsoft", "author": "Microsoft",
"license": "Apache-2.0", "license": "Apache-2.0",
"devDependencies": { "devDependencies": {
"@types/node": "^6.0.42", "@types/node": "^10.9.2",
"ts-loader": "^0.8.2", "ts-loader": "^4.5.0",
"typescript": "^2.0.0", "typescript": "^3.0.1",
"webpack": "^1.13.1" "webpack": "^4.17.1",
"webpack-cli": "^3.1.0"
} }
} }

View File

@@ -1,12 +1,13 @@
const path = require('path');
module.exports = { module.exports = {
target: 'node', target: 'node',
externals: ['fs', 'net', 'events', 'readline', 'stream'],
resolve: { resolve: {
extensions: [ '.ts' ] extensions: [ '.ts' ]
}, },
module: { module: {
loaders: [ rules: [
{ test: /\.ts$/, loader: 'ts-loader' }, { test: /\.ts$/, use: 'ts-loader' },
] ]
}, },
entry: { entry: {
@@ -14,7 +15,10 @@ module.exports = {
}, },
output: { output: {
libraryTarget: 'commonjs', libraryTarget: 'commonjs',
path: './Content/Node', path: path.join(__dirname, 'Content', 'Node'),
filename: '[name].js' filename: '[name].js'
},
optimization: {
minimize: false
} }
}; };

View File

@@ -1,75 +1,121 @@
(function(e, a) { for(var i in a) e[i] = a[i]; }(exports, /******/ (function(modules) { // webpackBootstrap (function(e, a) { for(var i in a) e[i] = a[i]; }(exports, /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache /******/ // The module cache
/******/ var installedModules = {}; /******/ var installedModules = {};
/******/
/******/ // The require function /******/ // The require function
/******/ function __webpack_require__(moduleId) { /******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache /******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) /******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports; /******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache) /******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = { /******/ var module = installedModules[moduleId] = {
/******/ exports: {}, /******/ i: moduleId,
/******/ id: moduleId, /******/ l: false,
/******/ loaded: false /******/ exports: {}
/******/ }; /******/ };
/******/
/******/ // Execute the module function /******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded /******/ // Flag the module as loaded
/******/ module.loaded = true; /******/ module.l = true;
/******/
/******/ // Return the exports of the module /******/ // Return the exports of the module
/******/ return module.exports; /******/ return module.exports;
/******/ } /******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__) /******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules; /******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache /******/ // expose the module cache
/******/ __webpack_require__.c = installedModules; /******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ }
/******/ };
/******/
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/
/******/ // create a fake namespace object
/******/ // mode & 1: value is a module id, require it
/******/ // mode & 2: merge all properties of value into the ns
/******/ // mode & 4: return value when already ns object
/******/ // mode & 8|1: behave like require
/******/ __webpack_require__.t = function(value, mode) {
/******/ if(mode & 1) value = __webpack_require__(value);
/******/ if(mode & 8) return value;
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ var ns = Object.create(null);
/******/ __webpack_require__.r(ns);
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ return ns;
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__ /******/ // __webpack_public_path__
/******/ __webpack_require__.p = ""; /******/ __webpack_require__.p = "";
/******/
/******/
/******/ // Load entry module and return exports /******/ // Load entry module and return exports
/******/ return __webpack_require__(0); /******/ return __webpack_require__(__webpack_require__.s = 0);
/******/ }) /******/ })
/************************************************************************/ /************************************************************************/
/******/ ([ /******/ ([
/* 0 */ /* 0 */
/***/ function(module, exports, __webpack_require__) { /***/ (function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(1); module.exports = __webpack_require__(1);
/***/ }, /***/ }),
/* 1 */ /* 1 */
/***/ function(module, exports, __webpack_require__) { /***/ (function(module, exports, __webpack_require__) {
"use strict"; "use strict";
var path = __webpack_require__(2);
// Separate declaration and export just to add type checking on function signature exports.__esModule = true;
exports.renderToString = renderToStringImpl; var path = __webpack_require__(2);
// This function is invoked by .NET code (via NodeServices). Its job is to hand off execution to the application's // Separate declaration and export just to add type checking on function signature
// prerendering boot function. It can operate in two modes: exports.renderToString = renderToStringImpl;
// [1] Legacy mode // This function is invoked by .NET code (via NodeServices). Its job is to hand off execution to the application's
// This is for backward compatibility with projects created with templates older than the generator version 0.6.0. // prerendering boot function. It can operate in two modes:
// In this mode, we don't really do anything here - we just load the 'aspnet-prerendering' NPM module (which must // [1] Legacy mode
// exist in node_modules, and must be v1.x (not v2+)), and pass through all the parameters to it. Code in // This is for backward compatibility with projects created with templates older than the generator version 0.6.0.
// 'aspnet-prerendering' v1.x will locate the boot function and invoke it. // In this mode, we don't really do anything here - we just load the 'aspnet-prerendering' NPM module (which must
// The drawback to this mode is that, for it to work, you have to deploy node_modules to production. // exist in node_modules, and must be v1.x (not v2+)), and pass through all the parameters to it. Code in
// [2] Current mode // 'aspnet-prerendering' v1.x will locate the boot function and invoke it.
// This is for projects created with the Yeoman generator 0.6.0+ (or projects manually updated). In this mode, // The drawback to this mode is that, for it to work, you have to deploy node_modules to production.
// we don't invoke 'require' at runtime at all. All our dependencies are bundled into the NuGet package, so you // [2] Current mode
// don't have to deploy node_modules to production. // This is for projects created with the Yeoman generator 0.6.0+ (or projects manually updated). In this mode,
// To determine whether we're in mode [1] or [2], the code locates your prerendering boot function, and checks whether // we don't invoke 'require' at runtime at all. All our dependencies are bundled into the NuGet package, so you
// a certain flag is attached to the function instance. // don't have to deploy node_modules to production.
function renderToStringImpl(callback, applicationBasePath, bootModule, absoluteRequestUrl, requestPathAndQuery, customDataParameter, overrideTimeoutMilliseconds) { // To determine whether we're in mode [1] or [2], the code locates your prerendering boot function, and checks whether
// a certain flag is attached to the function instance.
function renderToStringImpl(callback, applicationBasePath, bootModule, absoluteRequestUrl, requestPathAndQuery, customDataParameter, overrideTimeoutMilliseconds) {
try { try {
var forceLegacy = isLegacyAspNetPrerendering(); var forceLegacy = isLegacyAspNetPrerendering();
var renderToStringFunc = !forceLegacy && findRenderToStringFunc(applicationBasePath, bootModule); var renderToStringFunc = !forceLegacy && findRenderToStringFunc(applicationBasePath, bootModule);
@@ -99,9 +145,9 @@
+ '\nCurrent directory is: ' + '\nCurrent directory is: '
+ process.cwd()); + process.cwd());
} }
} }
; ;
function findBootModule(applicationBasePath, bootModule) { function findBootModule(applicationBasePath, bootModule) {
var bootModuleNameFullPath = path.resolve(applicationBasePath, bootModule.moduleName); var bootModuleNameFullPath = path.resolve(applicationBasePath, bootModule.moduleName);
if (bootModule.webpackConfig) { if (bootModule.webpackConfig) {
// If you're using asp-prerender-webpack-config, you're definitely in legacy mode // If you're using asp-prerender-webpack-config, you're definitely in legacy mode
@@ -110,8 +156,8 @@
else { else {
return require(bootModuleNameFullPath); return require(bootModuleNameFullPath);
} }
} }
function findRenderToStringFunc(applicationBasePath, bootModule) { function findRenderToStringFunc(applicationBasePath, bootModule) {
// First try to load the module // First try to load the module
var foundBootModule = findBootModule(applicationBasePath, bootModule); var foundBootModule = findBootModule(applicationBasePath, bootModule);
if (foundBootModule === null) { if (foundBootModule === null) {
@@ -125,7 +171,7 @@
} }
else if (typeof foundBootModule !== 'function') { else if (typeof foundBootModule !== 'function') {
// TypeScript-style default export // TypeScript-style default export
renderToStringFunc = foundBootModule.default; renderToStringFunc = foundBootModule["default"];
} }
else { else {
// Native default export // Native default export
@@ -141,12 +187,12 @@
} }
} }
return renderToStringFunc; return renderToStringFunc;
} }
function isLegacyAspNetPrerendering() { function isLegacyAspNetPrerendering() {
var version = getAspNetPrerenderingPackageVersion(); var version = getAspNetPrerenderingPackageVersion();
return version && /^1\./.test(version); return version && /^1\./.test(version);
} }
function getAspNetPrerenderingPackageVersion() { function getAspNetPrerenderingPackageVersion() {
try { try {
var packageEntryPoint = require.resolve('aspnet-prerendering'); var packageEntryPoint = require.resolve('aspnet-prerendering');
var packageDir = path.dirname(packageEntryPoint); var packageDir = path.dirname(packageEntryPoint);
@@ -159,20 +205,20 @@
// which will be the case in production based on latest templates). // which will be the case in production based on latest templates).
return null; return null;
} }
} }
/***/ }, /***/ }),
/* 2 */ /* 2 */
/***/ function(module, exports) { /***/ (function(module, exports) {
module.exports = require("path"); module.exports = require("path");
/***/ }, /***/ }),
/* 3 */ /* 3 */
/***/ function(module, exports) { /***/ (function(module, exports) {
module.exports = require("aspnet-prerendering"); module.exports = require("aspnet-prerendering");
/***/ } /***/ })
/******/ ]))); /******/ ])));

View File

@@ -1,65 +1,112 @@
(function(e, a) { for(var i in a) e[i] = a[i]; }(exports, /******/ (function(modules) { // webpackBootstrap (function(e, a) { for(var i in a) e[i] = a[i]; }(exports, /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache /******/ // The module cache
/******/ var installedModules = {}; /******/ var installedModules = {};
/******/
/******/ // The require function /******/ // The require function
/******/ function __webpack_require__(moduleId) { /******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache /******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) /******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports; /******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache) /******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = { /******/ var module = installedModules[moduleId] = {
/******/ exports: {}, /******/ i: moduleId,
/******/ id: moduleId, /******/ l: false,
/******/ loaded: false /******/ exports: {}
/******/ }; /******/ };
/******/
/******/ // Execute the module function /******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded /******/ // Flag the module as loaded
/******/ module.loaded = true; /******/ module.l = true;
/******/
/******/ // Return the exports of the module /******/ // Return the exports of the module
/******/ return module.exports; /******/ return module.exports;
/******/ } /******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__) /******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules; /******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache /******/ // expose the module cache
/******/ __webpack_require__.c = installedModules; /******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ }
/******/ };
/******/
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/
/******/ // create a fake namespace object
/******/ // mode & 1: value is a module id, require it
/******/ // mode & 2: merge all properties of value into the ns
/******/ // mode & 4: return value when already ns object
/******/ // mode & 8|1: behave like require
/******/ __webpack_require__.t = function(value, mode) {
/******/ if(mode & 1) value = __webpack_require__(value);
/******/ if(mode & 8) return value;
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ var ns = Object.create(null);
/******/ __webpack_require__.r(ns);
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ return ns;
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__ /******/ // __webpack_public_path__
/******/ __webpack_require__.p = ""; /******/ __webpack_require__.p = "";
/******/
/******/
/******/ // Load entry module and return exports /******/ // Load entry module and return exports
/******/ return __webpack_require__(0); /******/ return __webpack_require__(__webpack_require__.s = 4);
/******/ }) /******/ })
/************************************************************************/ /************************************************************************/
/******/ ([ /******/ ([
/* 0 */ /* 0 */,
/***/ function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(4);
/***/ },
/* 1 */, /* 1 */,
/* 2 */, /* 2 */,
/* 3 */, /* 3 */,
/* 4 */ /* 4 */
/***/ function(module, exports, __webpack_require__) { /***/ (function(module, exports, __webpack_require__) {
"use strict"; module.exports = __webpack_require__(5);
// Pass through the invocation to the 'aspnet-webpack' package, verifying that it can be loaded
function createWebpackDevServer(callback) {
/***/ }),
/* 5 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
exports.__esModule = true;
// Pass through the invocation to the 'aspnet-webpack' package, verifying that it can be loaded
function createWebpackDevServer(callback) {
var aspNetWebpack; var aspNetWebpack;
try { try {
aspNetWebpack = __webpack_require__(5); aspNetWebpack = __webpack_require__(6);
} }
catch (ex) { catch (ex) {
// Developers sometimes have trouble with badly-configured Node installations, where it's unable // Developers sometimes have trouble with badly-configured Node installations, where it's unable
@@ -72,15 +119,15 @@
return; return;
} }
return aspNetWebpack.createWebpackDevServer.apply(this, arguments); return aspNetWebpack.createWebpackDevServer.apply(this, arguments);
} }
exports.createWebpackDevServer = createWebpackDevServer; exports.createWebpackDevServer = createWebpackDevServer;
/***/ }, /***/ }),
/* 5 */ /* 6 */
/***/ function(module, exports) { /***/ (function(module, exports) {
module.exports = require("aspnet-webpack"); module.exports = require("aspnet-webpack");
/***/ } /***/ })
/******/ ]))); /******/ ])));

View File

@@ -1,7 +1,5 @@
/// <reference path="../npm/aspnet-prerendering/src/PrerenderingInterfaces.d.ts" /> import { BootModuleInfo, RenderToStringFunc, RenderToStringCallback } from '../npm/aspnet-prerendering/src/PrerenderingInterfaces';
import * as url from 'url';
import * as path from 'path'; import * as path from 'path';
import * as fs from 'fs';
declare var __non_webpack_require__; declare var __non_webpack_require__;
// Separate declaration and export just to add type checking on function signature // Separate declaration and export just to add type checking on function signature

File diff suppressed because it is too large Load Diff

View File

@@ -5,14 +5,15 @@
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1", "test": "echo \"Error: no test specified\" && exit 1",
"build": "./node_modules/.bin/webpack" "build": "webpack --mode production"
}, },
"author": "Microsoft", "author": "Microsoft",
"license": "Apache-2.0", "license": "Apache-2.0",
"devDependencies": { "devDependencies": {
"@types/node": "^6.0.42", "@types/node": "^10.9.2",
"ts-loader": "^0.8.2", "ts-loader": "^4.5.0",
"typescript": "^2.0.0", "typescript": "^3.0.1",
"webpack": "^1.13.1" "webpack": "^4.17.1",
"webpack-cli": "^3.1.0"
} }
} }

View File

@@ -1,3 +1,5 @@
const path = require('path');
module.exports = { module.exports = {
target: 'node', target: 'node',
externals: [ externals: [
@@ -10,8 +12,8 @@ module.exports = {
extensions: [ '.ts' ] extensions: [ '.ts' ]
}, },
module: { module: {
loaders: [ rules: [
{ test: /\.ts$/, loader: 'ts-loader' }, { test: /\.ts$/, use: 'ts-loader' },
] ]
}, },
entry: { entry: {
@@ -20,7 +22,10 @@ module.exports = {
}, },
output: { output: {
libraryTarget: 'commonjs', libraryTarget: 'commonjs',
path: './Content/Node', path: path.join(__dirname, 'Content', 'Node'),
filename: '[name].js' filename: '[name].js'
},
optimization: {
minimize: false
} }
}; };