Skip to content

Commit 1543595

Browse files
Correct Windows path handling in new aspnet-webpack feature
1 parent 3d77a21 commit 1543595

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
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.19",
3+
"version": "1.0.20",
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/WebpackDevMiddleware.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ function attachWebpackDevMiddleware(app: any, webpackConfig: webpack.Configurati
124124

125125
function copyRecursiveSync(from: typeof fs, to: typeof fs, rootDir: string, exclude: RegExp[]) {
126126
from.readdirSync(rootDir).forEach(filename => {
127-
const fullPath = path.join(rootDir, filename);
127+
const fullPath = pathJoinSafe(rootDir, filename);
128128
const shouldExclude = exclude.filter(re => re.test(fullPath)).length > 0;
129129
if (!shouldExclude) {
130130
const fileStat = from.statSync(fullPath);
@@ -138,6 +138,17 @@ function copyRecursiveSync(from: typeof fs, to: typeof fs, rootDir: string, excl
138138
});
139139
}
140140

141+
function pathJoinSafe(rootPath: string, filePath: string) {
142+
// On Windows, MemoryFileSystem's readdirSync output produces directory entries like 'C:'
143+
// which then trigger errors if you call statSync for them. Avoid this by detecting drive
144+
// names at the root, and adding a backslash (so 'C:' becomes 'C:\', which works).
145+
if (rootPath === '/' && path.sep === '\\' && filePath.match(/^[a-z0-9]+\:$/i)) {
146+
return filePath + '\\';
147+
} else {
148+
return path.join(rootPath, filePath);
149+
}
150+
}
151+
141152
function beginWebpackWatcher(webpackConfig: webpack.Configuration) {
142153
const compiler = webpack(webpackConfig);
143154
compiler.watch({ /* watchOptions */ }, (err, stats) => {

0 commit comments

Comments
 (0)