Amend aspnet-webpack for better node-inspector support

This commit is contained in:
SteveSandersonMS
2016-07-26 16:38:46 +01:00
parent 2fe06ea784
commit 79872c1bde
3 changed files with 14 additions and 3 deletions

View File

@@ -1,6 +1,6 @@
{ {
"name": "aspnet-webpack", "name": "aspnet-webpack",
"version": "1.0.6", "version": "1.0.7",
"description": "Helpers for using Webpack in ASP.NET Core projects. Works in conjunction with the Microsoft.AspNetCore.SpaServices NuGet package.", "description": "Helpers for using Webpack in ASP.NET Core projects. Works in conjunction with the Microsoft.AspNetCore.SpaServices NuGet package.",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {

View File

@@ -35,6 +35,12 @@ export function loadViaWebpack<T>(webpackConfigPath: string, modulePath: string,
}) })
} }
function setExtension(filePath: string, newExtension: string) {
const oldExtensionIfAny = path.extname(filePath);
const basenameWithoutExtension = path.basename(filePath, oldExtensionIfAny);
return path.join(path.dirname(filePath), basenameWithoutExtension) + newExtension;
}
function loadViaWebpackNoCache<T>(webpackConfigPath: string, modulePath: string) { function loadViaWebpackNoCache<T>(webpackConfigPath: string, modulePath: string) {
return new Promise<T>((resolve, reject) => { return new Promise<T>((resolve, reject) => {
// Load the Webpack config and make alterations needed for loading the output into Node // Load the Webpack config and make alterations needed for loading the output into Node
@@ -94,8 +100,13 @@ function loadViaWebpackNoCache<T>(webpackConfigPath: string, modulePath: string)
+ stats.toString({ chunks: false })); + stats.toString({ chunks: false }));
} }
// The dynamically-built module will only appear in node-inspector if it has some nonempty
// file path. The following value is arbitrary (since there's no real compiled file on disk)
// but is sufficient to enable debugging.
const fakeModulePath = setExtension(modulePath, '.js');
const fileContent = compiler.outputFileSystem.readFileSync(outputVirtualPath, 'utf8'); const fileContent = compiler.outputFileSystem.readFileSync(outputVirtualPath, 'utf8');
const moduleInstance = requireFromString<T>(fileContent); const moduleInstance = requireFromString<T>(fileContent, fakeModulePath);
resolve(moduleInstance); resolve(moduleInstance);
} catch(ex) { } catch(ex) {
reject(ex); reject(ex);

View File

@@ -1,3 +1,3 @@
export namespace requirefromstring { export namespace requirefromstring {
export function requireFromString<T>(fileContent: string): T; export function requireFromString<T>(fileContent: string, filename?: string): T;
} }