Skip to content

Commit b2a6085

Browse files
authored
Merge pull request webpack#4644 from sendilkumarn/libmanifest
refactor(es6): LibManifestPlugin
2 parents f96ba51 + cd688f8 commit b2a6085

9 files changed

+71
-66
lines changed

lib/AutomaticPrefetchPlugin.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55
"use strict";
66

7-
const async = require("async");
7+
const asyncLib = require("async");
88
const PrefetchDependency = require("./dependencies/PrefetchDependency");
99
const NormalModule = require("./NormalModule");
1010

@@ -27,7 +27,7 @@ class AutomaticPrefetchPlugin {
2727
});
2828
compiler.plugin("make", (compilation, callback) => {
2929
if(!lastModules) return callback();
30-
async.forEach(lastModules, (m, callback) => {
30+
asyncLib.forEach(lastModules, (m, callback) => {
3131
compilation.prefetch(m.context || compiler.context, new PrefetchDependency(m.request), callback);
3232
}, callback);
3333
});

lib/CachePlugin.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55
"use strict";
66

7-
const async = require("async");
7+
const asyncLib = require("async");
88

99
class CachePlugin {
1010
constructor(cache) {
@@ -35,7 +35,7 @@ class CachePlugin {
3535
if(!compiler._lastCompilationFileDependencies) return callback();
3636
const fs = compiler.inputFileSystem;
3737
const fileTs = compiler.fileTimestamps = {};
38-
async.forEach(compiler._lastCompilationFileDependencies, (file, callback) => {
38+
asyncLib.forEach(compiler._lastCompilationFileDependencies, (file, callback) => {
3939
fs.stat(file, (err, stat) => {
4040
if(err) {
4141
if(err.code === "ENOENT") return callback();

lib/Compilation.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55
"use strict";
66

7-
const async = require("async");
7+
const asyncLib = require("async");
88
const crypto = require("crypto");
99
const Tapable = require("tapable");
1010
const EntryModuleNotFoundError = require("./EntryModuleNotFoundError");
@@ -207,7 +207,7 @@ class Compilation extends Tapable {
207207
}
208208
factories[i] = [factory, dependencies[i]];
209209
}
210-
async.forEach(factories, function iteratorFactory(item, callback) {
210+
asyncLib.forEach(factories, function iteratorFactory(item, callback) {
211211
const dependencies = item[1];
212212

213213
const errorAndCallback = function errorAndCallback(err) {

lib/ContextModuleFactory.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
MIT License http://www.opensource.org/licenses/mit-license.php
33
Author Tobias Koppers @sokra
44
*/
5-
var async = require("async");
5+
var asyncLib = require("async");
66
var path = require("path");
77

88
var Tapable = require("tapable");
@@ -61,15 +61,15 @@ ContextModuleFactory.prototype.create = function(data, callback) {
6161

6262
var resolvers = module.resolvers;
6363

64-
async.parallel([
64+
asyncLib.parallel([
6565
function(callback) {
6666
resolvers.context.resolve({}, context, resource, function(err, result) {
6767
if(err) return callback(err);
6868
callback(null, result);
6969
});
7070
},
7171
function(callback) {
72-
async.map(loaders, function(loader, callback) {
72+
asyncLib.map(loaders, function(loader, callback) {
7373
resolvers.loader.resolve({}, context, loader, function(err, result) {
7474
if(err) return callback(err);
7575
callback(null, result);
@@ -106,7 +106,7 @@ ContextModuleFactory.prototype.resolveDependencies = function resolveDependencie
106106
fs.readdir(directory, function(err, files) {
107107
if(err) return callback(err);
108108
if(!files || files.length === 0) return callback(null, []);
109-
async.map(files.filter(function(p) {
109+
asyncLib.map(files.filter(function(p) {
110110
return p.indexOf(".") !== 0;
111111
}), function(seqment, callback) {
112112

lib/LibManifestPlugin.js

Lines changed: 51 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,52 +2,57 @@
22
MIT License http://www.opensource.org/licenses/mit-license.php
33
Author Tobias Koppers @sokra
44
*/
5-
var path = require("path");
6-
var async = require("async");
5+
"use strict";
76

8-
function LibManifestPlugin(options) {
9-
this.options = options;
7+
const path = require("path");
8+
const asyncLib = require("async");
9+
10+
class LibManifestPlugin {
11+
constructor(options) {
12+
this.options = options;
13+
}
14+
15+
apply(compiler) {
16+
compiler.plugin("emit", (compilation, callback) => {
17+
asyncLib.forEach(compilation.chunks, (chunk, callback) => {
18+
if(!chunk.isInitial()) {
19+
callback();
20+
return;
21+
}
22+
const targetPath = compilation.getPath(this.options.path, {
23+
hash: compilation.hash,
24+
chunk
25+
});
26+
const name = this.options.name && compilation.getPath(this.options.name, {
27+
hash: compilation.hash,
28+
chunk
29+
});
30+
const manifest = {
31+
name,
32+
type: this.options.type,
33+
content: chunk.modules.reduce((obj, module) => {
34+
if(module.libIdent) {
35+
const ident = module.libIdent({
36+
context: this.options.context || compiler.options.context
37+
});
38+
if(ident) {
39+
obj[ident] = {
40+
id: module.id,
41+
meta: module.meta,
42+
exports: Array.isArray(module.providedExports) ? module.providedExports : undefined
43+
};
44+
}
45+
}
46+
return obj;
47+
}, {})
48+
};
49+
const content = new Buffer(JSON.stringify(manifest, null, 2), "utf8"); //eslint-disable-line
50+
compiler.outputFileSystem.mkdirp(path.dirname(targetPath), err => {
51+
if(err) return callback(err);
52+
compiler.outputFileSystem.writeFile(targetPath, content, callback);
53+
});
54+
}, callback);
55+
});
56+
}
1057
}
1158
module.exports = LibManifestPlugin;
12-
LibManifestPlugin.prototype.apply = function(compiler) {
13-
compiler.plugin("emit", function(compilation, callback) {
14-
async.forEach(compilation.chunks, function(chunk, callback) {
15-
if(!chunk.isInitial()) {
16-
callback();
17-
return;
18-
}
19-
var targetPath = compilation.getPath(this.options.path, {
20-
hash: compilation.hash,
21-
chunk: chunk
22-
});
23-
var name = this.options.name && compilation.getPath(this.options.name, {
24-
hash: compilation.hash,
25-
chunk: chunk
26-
});
27-
var manifest = {
28-
name: name,
29-
type: this.options.type,
30-
content: chunk.modules.reduce(function(obj, module) {
31-
if(module.libIdent) {
32-
var ident = module.libIdent({
33-
context: this.options.context || compiler.options.context
34-
});
35-
if(ident) {
36-
obj[ident] = {
37-
id: module.id,
38-
meta: module.meta,
39-
exports: Array.isArray(module.providedExports) ? module.providedExports : undefined
40-
};
41-
}
42-
}
43-
return obj;
44-
}.bind(this), {})
45-
};
46-
var content = new Buffer(JSON.stringify(manifest, null, 2), "utf8"); //eslint-disable-line
47-
compiler.outputFileSystem.mkdirp(path.dirname(targetPath), function(err) {
48-
if(err) return callback(err);
49-
compiler.outputFileSystem.writeFile(targetPath, content, callback);
50-
});
51-
}.bind(this), callback);
52-
}.bind(this));
53-
};

lib/MultiCompiler.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Author Tobias Koppers @sokra
44
*/
55
var Tapable = require("tapable");
6-
var async = require("async");
6+
var asyncLib = require("async");
77
var MultiWatching = require("./MultiWatching");
88
var MultiStats = require("./MultiStats");
99

@@ -100,7 +100,7 @@ function runWithDependencies(compilers, fn, callback) {
100100

101101
function runCompilers(callback) {
102102
if(remainingCompilers.length === 0) return callback();
103-
async.map(getReadyCompilers(), function(compiler, callback) {
103+
asyncLib.map(getReadyCompilers(), function(compiler, callback) {
104104
fn(compiler, function(err) {
105105
if(err) return callback(err);
106106
fulfilledNames[compiler.name] = true;

lib/MultiWatching.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55
"use strict";
66

7-
const async = require("async");
7+
const asyncLib = require("async");
88

99
class MultiWatching {
1010
constructor(watchings, compiler) {
@@ -19,7 +19,7 @@ class MultiWatching {
1919
close(callback) {
2020
if(callback === undefined) callback = () => { /*do nothing*/ };
2121

22-
async.forEach(this.watchings, (watching, finishedCallback) => {
22+
asyncLib.forEach(this.watchings, (watching, finishedCallback) => {
2323
watching.close(finishedCallback);
2424
}, err => {
2525
this.compiler.applyPlugins("watch-close");

lib/NormalModuleFactory.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55
"use strict";
66

7-
const async = require("async");
7+
const asyncLib = require("async");
88
const Tapable = require("tapable");
99
const NormalModule = require("./NormalModule");
1010
const RawModule = require("./RawModule");
@@ -118,7 +118,7 @@ class NormalModuleFactory extends Tapable {
118118
let resource = elements.pop();
119119
elements = elements.map(identToLoaderRequest);
120120

121-
async.parallel([
121+
asyncLib.parallel([
122122
callback => this.resolveRequestArray(contextInfo, context, elements, this.resolvers.loader, callback),
123123
callback => {
124124
if(resource === "" || resource[0] === "?")
@@ -194,7 +194,7 @@ class NormalModuleFactory extends Tapable {
194194
settings[r.type] = r.value;
195195
}
196196
});
197-
async.parallel([
197+
asyncLib.parallel([
198198
this.resolveRequestArray.bind(this, contextInfo, this.context, useLoadersPost, this.resolvers.loader),
199199
this.resolveRequestArray.bind(this, contextInfo, this.context, useLoaders, this.resolvers.loader),
200200
this.resolveRequestArray.bind(this, contextInfo, this.context, useLoadersPre, this.resolvers.loader)
@@ -257,7 +257,7 @@ class NormalModuleFactory extends Tapable {
257257

258258
resolveRequestArray(contextInfo, context, array, resolver, callback) {
259259
if(array.length === 0) return callback(null, []);
260-
async.map(array, (item, callback) => {
260+
asyncLib.map(array, (item, callback) => {
261261
resolver.resolve(contextInfo, context, item.loader, (err, result) => {
262262
if(err && /^[^/]*$/.test(item.loader) && !/-loader$/.test(item.loader)) {
263263
return resolver.resolve(contextInfo, context, item.loader + "-loader", err2 => {

test/BenchmarkTestCases.benchmark.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
const should = require("should");
44
const path = require("path");
55
const fs = require("fs");
6-
const async = require("async");
6+
const asyncLib = require("async");
77
var Test = require("mocha/lib/test");
88

99
const webpack = require("../lib/webpack");
@@ -31,7 +31,7 @@ describe("BenchmarkTestCases", function() {
3131
const rootPath = path.join(__dirname, "..");
3232
getBaselineRevs(rootPath, (err, baselineRevisions) => {
3333
if(err) return done(err);
34-
async.eachSeries(baselineRevisions, (baselineInfo, callback) => {
34+
asyncLib.eachSeries(baselineRevisions, (baselineInfo, callback) => {
3535
const baselineRevision = baselineInfo.rev;
3636
const baselinePath = path.resolve(baselinesPath, baselineRevision);
3737
if(fs.existsSync(path.resolve(baselinePath, ".git"))) {

0 commit comments

Comments
 (0)