Skip to content

Commit

Permalink
revert: fix: make sure manifest writes don't overlap (d6a20cf) (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
mastilver committed Aug 14, 2017
1 parent 02cbd20 commit 8176090
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 15 deletions.
23 changes: 10 additions & 13 deletions lib/plugin.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
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 @@ -145,23 +142,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) {
fse.outputFileSync(outputFile, json);
}

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);
});
});
});
compileCallback();
}.bind(this));
};

Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@
"homepage": "/~https://github.com/danethurber/webpack-manifest-plugin",
"dependencies": {
"fs-extra": "^0.30.0",
"lodash": ">=3.5 <5",
"mutexify": "^1.1.0"
"lodash": ">=3.5 <5"
},
"nyc": {
"reporter": [
Expand Down
16 changes: 16 additions & 0 deletions spec/plugin.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,22 @@ describe('ManifestPlugin', function() {
});
});

it('make manifest available to other webpack plugins', function(done) {
webpackCompile({
context: __dirname,
entry: './fixtures/file.js'
}, {}, function(manifest, stats) {
expect(manifest).toEqual({
'main.js': 'main.js'
});

expect(JSON.parse(stats.compilation.assets['manifest.json'].source())).toEqual({
'main.js': 'main.js'
});

done();
});
});
});

describe('with ExtractTextPlugin', function() {
Expand Down

0 comments on commit 8176090

Please sign in to comment.