diff --git a/src/Microsoft.AspNetCore.SpaServices/npm/aspnet-webpack/package.json b/src/Microsoft.AspNetCore.SpaServices/npm/aspnet-webpack/package.json index b31a56f..ef077ec 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.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": { diff --git a/src/Microsoft.AspNetCore.SpaServices/npm/aspnet-webpack/src/WebpackDevMiddleware.ts b/src/Microsoft.AspNetCore.SpaServices/npm/aspnet-webpack/src/WebpackDevMiddleware.ts index 4c85af0..f0e9770 100644 --- a/src/Microsoft.AspNetCore.SpaServices/npm/aspnet-webpack/src/WebpackDevMiddleware.ts +++ b/src/Microsoft.AspNetCore.SpaServices/npm/aspnet-webpack/src/WebpackDevMiddleware.ts @@ -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) => {