Correct Windows path handling in new aspnet-webpack feature

This commit is contained in:
SteveSandersonMS
2016-10-11 18:11:47 +01:00
parent 3d77a21bc6
commit 1543595c01
2 changed files with 13 additions and 2 deletions

View File

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

View File

@@ -124,7 +124,7 @@ function attachWebpackDevMiddleware(app: any, webpackConfig: webpack.Configurati
function copyRecursiveSync(from: typeof fs, to: typeof fs, rootDir: string, exclude: RegExp[]) {
from.readdirSync(rootDir).forEach(filename => {
const fullPath = path.join(rootDir, filename);
const fullPath = pathJoinSafe(rootDir, filename);
const shouldExclude = exclude.filter(re => re.test(fullPath)).length > 0;
if (!shouldExclude) {
const fileStat = from.statSync(fullPath);
@@ -138,6 +138,17 @@ function copyRecursiveSync(from: typeof fs, to: typeof fs, rootDir: string, excl
});
}
function pathJoinSafe(rootPath: string, filePath: string) {
// On Windows, MemoryFileSystem's readdirSync output produces directory entries like 'C:'
// which then trigger errors if you call statSync for them. Avoid this by detecting drive
// names at the root, and adding a backslash (so 'C:' becomes 'C:\', which works).
if (rootPath === '/' && path.sep === '\\' && filePath.match(/^[a-z0-9]+\:$/i)) {
return filePath + '\\';
} else {
return path.join(rootPath, filePath);
}
}
function beginWebpackWatcher(webpackConfig: webpack.Configuration) {
const compiler = webpack(webpackConfig);
compiler.watch({ /* watchOptions */ }, (err, stats) => {