From 79872c1bde1276861455ed72e216c469c4fd45a3 Mon Sep 17 00:00:00 2001 From: SteveSandersonMS Date: Tue, 26 Jul 2016 16:38:46 +0100 Subject: [PATCH] Amend aspnet-webpack for better node-inspector support --- .../npm/aspnet-webpack/package.json | 2 +- .../npm/aspnet-webpack/src/LoadViaWebpack.ts | 13 ++++++++++++- .../src/typings/require-from-string.d.ts | 2 +- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.AspNetCore.SpaServices/npm/aspnet-webpack/package.json b/src/Microsoft.AspNetCore.SpaServices/npm/aspnet-webpack/package.json index 6ff72aa..6e12ac7 100644 --- a/src/Microsoft.AspNetCore.SpaServices/npm/aspnet-webpack/package.json +++ b/src/Microsoft.AspNetCore.SpaServices/npm/aspnet-webpack/package.json @@ -1,6 +1,6 @@ { "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.", "main": "index.js", "scripts": { diff --git a/src/Microsoft.AspNetCore.SpaServices/npm/aspnet-webpack/src/LoadViaWebpack.ts b/src/Microsoft.AspNetCore.SpaServices/npm/aspnet-webpack/src/LoadViaWebpack.ts index a6f6fa7..c41d7e8 100644 --- a/src/Microsoft.AspNetCore.SpaServices/npm/aspnet-webpack/src/LoadViaWebpack.ts +++ b/src/Microsoft.AspNetCore.SpaServices/npm/aspnet-webpack/src/LoadViaWebpack.ts @@ -35,6 +35,12 @@ export function loadViaWebpack(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(webpackConfigPath: string, modulePath: string) { return new Promise((resolve, reject) => { // Load the Webpack config and make alterations needed for loading the output into Node @@ -94,8 +100,13 @@ function loadViaWebpackNoCache(webpackConfigPath: string, modulePath: string) + 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 moduleInstance = requireFromString(fileContent); + const moduleInstance = requireFromString(fileContent, fakeModulePath); resolve(moduleInstance); } catch(ex) { reject(ex); diff --git a/src/Microsoft.AspNetCore.SpaServices/npm/aspnet-webpack/src/typings/require-from-string.d.ts b/src/Microsoft.AspNetCore.SpaServices/npm/aspnet-webpack/src/typings/require-from-string.d.ts index 80e4645..ba41884 100644 --- a/src/Microsoft.AspNetCore.SpaServices/npm/aspnet-webpack/src/typings/require-from-string.d.ts +++ b/src/Microsoft.AspNetCore.SpaServices/npm/aspnet-webpack/src/typings/require-from-string.d.ts @@ -1,3 +1,3 @@ export namespace requirefromstring { - export function requireFromString(fileContent: string): T; + export function requireFromString(fileContent: string, filename?: string): T; }