Skip to content
This repository was archived by the owner on Apr 8, 2020. It is now read-only.

Commit 79872c1

Browse files
Amend aspnet-webpack for better node-inspector support
1 parent 2fe06ea commit 79872c1

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

src/Microsoft.AspNetCore.SpaServices/npm/aspnet-webpack/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "aspnet-webpack",
3-
"version": "1.0.6",
3+
"version": "1.0.7",
44
"description": "Helpers for using Webpack in ASP.NET Core projects. Works in conjunction with the Microsoft.AspNetCore.SpaServices NuGet package.",
55
"main": "index.js",
66
"scripts": {

src/Microsoft.AspNetCore.SpaServices/npm/aspnet-webpack/src/LoadViaWebpack.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ export function loadViaWebpack<T>(webpackConfigPath: string, modulePath: string,
3535
})
3636
}
3737

38+
function setExtension(filePath: string, newExtension: string) {
39+
const oldExtensionIfAny = path.extname(filePath);
40+
const basenameWithoutExtension = path.basename(filePath, oldExtensionIfAny);
41+
return path.join(path.dirname(filePath), basenameWithoutExtension) + newExtension;
42+
}
43+
3844
function loadViaWebpackNoCache<T>(webpackConfigPath: string, modulePath: string) {
3945
return new Promise<T>((resolve, reject) => {
4046
// 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)
94100
+ stats.toString({ chunks: false }));
95101
}
96102

103+
// The dynamically-built module will only appear in node-inspector if it has some nonempty
104+
// file path. The following value is arbitrary (since there's no real compiled file on disk)
105+
// but is sufficient to enable debugging.
106+
const fakeModulePath = setExtension(modulePath, '.js');
107+
97108
const fileContent = compiler.outputFileSystem.readFileSync(outputVirtualPath, 'utf8');
98-
const moduleInstance = requireFromString<T>(fileContent);
109+
const moduleInstance = requireFromString<T>(fileContent, fakeModulePath);
99110
resolve(moduleInstance);
100111
} catch(ex) {
101112
reject(ex);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export namespace requirefromstring {
2-
export function requireFromString<T>(fileContent: string): T;
2+
export function requireFromString<T>(fileContent: string, filename?: string): T;
33
}

0 commit comments

Comments
 (0)