Skip to content

Commit 0616dda

Browse files
8bitDesignermichael-ciniawsky
authored andcommitted
fix: use os.tmpdir() to safely store _karma_webpack_ (#279)
1 parent 68506b4 commit 0616dda

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/karma-webpack.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
var os = require('os')
12
var _ = require('lodash')
23
var path = require('path')
34
var async = require('async')
@@ -47,8 +48,8 @@ function Plugin(
4748

4849
// Must have the common _karma_webpack_ prefix on path here to avoid
4950
// https://github.com/webpack/webpack/issues/645
50-
webpackOptions.output.path = '/_karma_webpack_/' + indexPath
51-
webpackOptions.output.publicPath = '/_karma_webpack_/' + publicPath
51+
webpackOptions.output.path = path.join(os.tmpdir(), '_karma_webpack_', indexPath)
52+
webpackOptions.output.publicPath = path.join(os.tmpdir(), '_karma_webpack_', publicPath)
5253
webpackOptions.output.filename = '[name]'
5354
if (includeIndex) {
5455
webpackOptions.output.jsonpFunction = 'webpackJsonp' + index
@@ -132,11 +133,11 @@ function Plugin(
132133
}
133134
}.bind(this))
134135

135-
webpackMiddlewareOptions.publicPath = '/_karma_webpack_/'
136+
webpackMiddlewareOptions.publicPath = path.join(os.tmpdir(), '_karma_webpack_')
136137
var middleware = this.middleware = new webpackDevMiddleware(compiler, webpackMiddlewareOptions)
137138

138139
customFileHandlers.push({
139-
urlRegex: /^\/_karma_webpack_\/.*/,
140+
urlRegex: new RegExp('^' + os.tmpdir() + '\/_karma_webpack_\/.*/'),
140141
handler: function(req, res) {
141142
middleware(req, res, function() {
142143
res.statusCode = 404
@@ -197,7 +198,7 @@ Plugin.prototype.readFile = function(file, callback) {
197198
var doRead = function() {
198199
if (optionsCount > 1) {
199200
async.times(optionsCount, function(idx, callback) {
200-
middleware.fileSystem.readFile('/_karma_webpack_/' + idx + '/' + file.replace(/\\/g, '/'), callback)
201+
middleware.fileSystem.readFile(path.join(os.tmpdir(), '_karma_webpack_', idx, file.replace(/\\/g, '/')), callback)
201202
}, function(err, contents) {
202203
if (err) {
203204
return callback(err)
@@ -214,7 +215,7 @@ Plugin.prototype.readFile = function(file, callback) {
214215
})
215216
} else {
216217
try {
217-
var fileContents = middleware.fileSystem.readFileSync('/_karma_webpack_/' + file.replace(/\\/g, '/'))
218+
var fileContents = middleware.fileSystem.readFileSync(path.join(os.tmpdir(), '_karma_webpack_', file.replace(/\\/g, '/')))
218219

219220
callback(undefined, fileContents)
220221
} catch (e) {

0 commit comments

Comments
 (0)