mirror of
https://github.com/aspnet/JavaScriptServices.git
synced 2025-12-23 01:58:29 +00:00
Amend aspnet-webpack for better node-inspector support
This commit is contained in:
@@ -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": {
|
||||
|
||||
@@ -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) {
|
||||
return new Promise<T>((resolve, reject) => {
|
||||
// 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 }));
|
||||
}
|
||||
|
||||
// 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<T>(fileContent);
|
||||
const moduleInstance = requireFromString<T>(fileContent, fakeModulePath);
|
||||
resolve(moduleInstance);
|
||||
} catch(ex) {
|
||||
reject(ex);
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
export namespace requirefromstring {
|
||||
export function requireFromString<T>(fileContent: string): T;
|
||||
export function requireFromString<T>(fileContent: string, filename?: string): T;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user