Skip to content

Commit d6a20cf

Browse files
authored
fix: make sure manifest writes don't overlap (#56)
* fix: make sure manifest writes don't overlap * fix: make sure absolute file path is respected
1 parent 87de35d commit d6a20cf

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

lib/plugin.js

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
var path = require('path');
22
var fse = require('fs-extra');
33
var _ = require('lodash');
4+
var mutexify = require('mutexify');
5+
6+
var lock = mutexify();
47

58
function ManifestPlugin(opts) {
69
this.opts = _.assign({
@@ -142,23 +145,23 @@ ManifestPlugin.prototype.apply = function(compiler) {
142145

143146
var json = JSON.stringify(manifest, null, 2);
144147

145-
compilation.assets[outputName] = {
146-
source: function() {
147-
return json;
148-
},
149-
size: function() {
150-
return json.length;
151-
}
152-
};
148+
var outputFolder = compilation.options.output.path;
149+
var outputFile = path.resolve(compilation.options.output.path, this.opts.fileName);
153150

154151
if (this.opts.writeToFileEmit) {
155-
var outputFolder = compilation.options.output.path;
156-
var outputFile = path.join(outputFolder, this.opts.fileName);
157-
158152
fse.outputFileSync(outputFile, json);
159153
}
160154

161-
compileCallback();
155+
compiler.outputFileSystem.mkdirp(path.dirname(outputFile), function(err) {
156+
if (err) return compileCallback(err);
157+
158+
lock(function(release) {
159+
compiler.outputFileSystem.writeFile(outputFile, json, function(err) {
160+
release();
161+
compileCallback(err);
162+
});
163+
});
164+
});
162165
}.bind(this));
163166
};
164167

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
"homepage": "https://github.com/danethurber/webpack-manifest-plugin",
4141
"dependencies": {
4242
"fs-extra": "^0.30.0",
43-
"lodash": ">=3.5 <5"
43+
"lodash": ">=3.5 <5",
44+
"mutexify": "^1.1.0"
4445
},
4546
"nyc": {
4647
"reporter": [

0 commit comments

Comments
 (0)