Skip to content

Commit

Permalink
fix: make sure manifest writes don't overlap (#56)
Browse files Browse the repository at this point in the history
* fix: make sure manifest writes don't overlap

* fix: make sure absolute file path is respected
  • Loading branch information
mastilver authored Aug 9, 2017
1 parent 87de35d commit d6a20cf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
27 changes: 15 additions & 12 deletions lib/plugin.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
var path = require('path');
var fse = require('fs-extra');
var _ = require('lodash');
var mutexify = require('mutexify');

var lock = mutexify();

function ManifestPlugin(opts) {
this.opts = _.assign({
Expand Down Expand Up @@ -142,23 +145,23 @@ ManifestPlugin.prototype.apply = function(compiler) {

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

compilation.assets[outputName] = {
source: function() {
return json;
},
size: function() {
return json.length;
}
};
var outputFolder = compilation.options.output.path;
var outputFile = path.resolve(compilation.options.output.path, this.opts.fileName);

if (this.opts.writeToFileEmit) {
var outputFolder = compilation.options.output.path;
var outputFile = path.join(outputFolder, this.opts.fileName);

fse.outputFileSync(outputFile, json);
}

compileCallback();
compiler.outputFileSystem.mkdirp(path.dirname(outputFile), function(err) {
if (err) return compileCallback(err);

lock(function(release) {
compiler.outputFileSystem.writeFile(outputFile, json, function(err) {
release();
compileCallback(err);
});
});
});
}.bind(this));
};

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
"homepage": "https://github.com/danethurber/webpack-manifest-plugin",
"dependencies": {
"fs-extra": "^0.30.0",
"lodash": ">=3.5 <5"
"lodash": ">=3.5 <5",
"mutexify": "^1.1.0"
},
"nyc": {
"reporter": [
Expand Down

0 comments on commit d6a20cf

Please sign in to comment.