webpack 2.3.3 → 2.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/README.md +148 -133
  2. package/lib/APIPlugin.js +0 -6
  3. package/lib/AsyncDependenciesBlock.js +1 -1
  4. package/lib/AutomaticPrefetchPlugin.js +2 -2
  5. package/lib/BannerPlugin.js +30 -8
  6. package/lib/CachePlugin.js +2 -2
  7. package/lib/CaseSensitiveModulesWarning.js +6 -3
  8. package/lib/ChunkRenderError.js +3 -1
  9. package/lib/ChunkTemplate.js +2 -2
  10. package/lib/Compilation.js +17 -17
  11. package/lib/Compiler.js +30 -25
  12. package/lib/ContextModule.js +4 -3
  13. package/lib/ContextModuleFactory.js +5 -5
  14. package/lib/DelegatedModule.js +69 -63
  15. package/lib/DependenciesBlock.js +65 -59
  16. package/lib/Dependency.js +1 -0
  17. package/lib/EntryModuleNotFoundError.js +16 -10
  18. package/lib/ExtendedAPIPlugin.js +7 -2
  19. package/lib/ExternalModule.js +1 -1
  20. package/lib/ExternalModuleFactoryPlugin.js +26 -23
  21. package/lib/FlagDependencyUsagePlugin.js +63 -75
  22. package/lib/HotModuleReplacement.runtime.js +25 -27
  23. package/lib/HotModuleReplacementPlugin.js +3 -5
  24. package/lib/IgnorePlugin.js +48 -17
  25. package/lib/JsonpChunkTemplatePlugin.js +24 -24
  26. package/lib/JsonpMainTemplatePlugin.js +182 -182
  27. package/lib/LibManifestPlugin.js +51 -46
  28. package/lib/MainTemplate.js +17 -18
  29. package/lib/Module.js +158 -160
  30. package/lib/ModuleBuildError.js +4 -2
  31. package/lib/ModuleDependencyError.js +2 -1
  32. package/lib/ModuleDependencyWarning.js +2 -1
  33. package/lib/ModuleError.js +2 -2
  34. package/lib/ModuleFilenameHelpers.js +27 -27
  35. package/lib/ModuleNotFoundError.js +3 -1
  36. package/lib/ModuleParseError.js +6 -4
  37. package/lib/ModuleWarning.js +2 -2
  38. package/lib/MultiCompiler.js +3 -4
  39. package/lib/MultiStats.js +3 -3
  40. package/lib/MultiWatching.js +2 -2
  41. package/lib/NamedChunksPlugin.js +30 -0
  42. package/lib/NodeStuffPlugin.js +80 -79
  43. package/lib/NormalModule.js +7 -3
  44. package/lib/NormalModuleFactory.js +244 -240
  45. package/lib/Parser.js +1256 -1079
  46. package/lib/ProgressPlugin.js +2 -2
  47. package/lib/RawModule.js +1 -1
  48. package/lib/RecordIdsPlugin.js +5 -9
  49. package/lib/SetVarMainTemplatePlugin.js +1 -1
  50. package/lib/SourceMapDevToolPlugin.js +153 -157
  51. package/lib/Stats.js +34 -6
  52. package/lib/TemplatedPathPlugin.js +1 -0
  53. package/lib/UnsupportedFeatureWarning.js +2 -1
  54. package/lib/WebpackError.js +11 -0
  55. package/lib/WebpackOptionsApply.js +4 -4
  56. package/lib/WebpackOptionsValidationError.js +2 -3
  57. package/lib/dependencies/AMDDefineDependency.js +10 -6
  58. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +8 -1
  59. package/lib/dependencies/AMDPlugin.js +3 -3
  60. package/lib/dependencies/ContextDependencyHelpers.js +19 -16
  61. package/lib/dependencies/CriticalDependencyWarning.js +4 -1
  62. package/lib/dependencies/DepBlockHelpers.js +3 -3
  63. package/lib/dependencies/HarmonyCompatibilityDependency.js +1 -1
  64. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +3 -3
  65. package/lib/dependencies/ImportContextDependency.js +2 -1
  66. package/lib/dependencies/ImportDependenciesBlock.js +2 -2
  67. package/lib/dependencies/ImportParserPlugin.js +16 -2
  68. package/lib/dependencies/RequireEnsureDependenciesBlock.js +11 -3
  69. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +42 -13
  70. package/lib/dependencies/RequireEnsureDependency.js +9 -2
  71. package/lib/formatLocation.js +44 -27
  72. package/lib/optimize/AggressiveSplittingPlugin.js +10 -17
  73. package/lib/optimize/CommonsChunkPlugin.js +2 -2
  74. package/lib/performance/AssetsOverSizeLimitWarning.js +4 -1
  75. package/lib/performance/EntrypointsOverSizeLimitWarning.js +5 -1
  76. package/lib/performance/NoAsyncChunksWarning.js +5 -1
  77. package/lib/removeAndDo.js +6 -4
  78. package/lib/util/identifier.js +16 -0
  79. package/lib/webpack.js +2 -1
  80. package/package.json +7 -4
  81. package/schemas/webpackOptionsSchema.json +35 -0
@@ -4,10 +4,12 @@
4
4
  */
5
5
  "use strict";
6
6
 
7
- class ChunkRenderError extends Error {
7
+ const WebpackError = require("./WebpackError");
8
8
 
9
+ class ChunkRenderError extends WebpackError {
9
10
  constructor(chunk, file, error) {
10
11
  super();
12
+
11
13
  this.name = "ChunkRenderError";
12
14
  this.error = error;
13
15
  this.message = error.message;
@@ -13,8 +13,8 @@ module.exports = class ChunkTemplate extends Template {
13
13
  }
14
14
 
15
15
  render(chunk, moduleTemplate, dependencyTemplates) {
16
- const modules = this.renderChunkModules(chunk, moduleTemplate, dependencyTemplates);
17
- const core = this.applyPluginsWaterfall("modules", modules, chunk, moduleTemplate, dependencyTemplates);
16
+ const moduleSources = this.renderChunkModules(chunk, moduleTemplate, dependencyTemplates);
17
+ const core = this.applyPluginsWaterfall("modules", moduleSources, chunk, moduleTemplate, dependencyTemplates);
18
18
  let source = this.applyPluginsWaterfall("render", core, chunk, moduleTemplate, dependencyTemplates);
19
19
  if(chunk.hasEntryModule()) {
20
20
  source = this.applyPluginsWaterfall("render-with-entry", source, chunk);
@@ -4,7 +4,7 @@
4
4
  */
5
5
  "use strict";
6
6
 
7
- const async = require("async");
7
+ const asyncLib = require("async");
8
8
  const crypto = require("crypto");
9
9
  const Tapable = require("tapable");
10
10
  const EntryModuleNotFoundError = require("./EntryModuleNotFoundError");
@@ -14,7 +14,6 @@ const ModuleDependencyError = require("./ModuleDependencyError");
14
14
  const Module = require("./Module");
15
15
  const Chunk = require("./Chunk");
16
16
  const Entrypoint = require("./Entrypoint");
17
- const Stats = require("./Stats");
18
17
  const MainTemplate = require("./MainTemplate");
19
18
  const ChunkTemplate = require("./ChunkTemplate");
20
19
  const HotUpdateChunkTemplate = require("./HotUpdateChunkTemplate");
@@ -22,6 +21,7 @@ const ModuleTemplate = require("./ModuleTemplate");
22
21
  const Dependency = require("./Dependency");
23
22
  const ChunkRenderError = require("./ChunkRenderError");
24
23
  const CachedSource = require("webpack-sources").CachedSource;
24
+ const Stats = require("./Stats");
25
25
 
26
26
  function byId(a, b) {
27
27
  if(a.id < b.id) return -1;
@@ -82,6 +82,10 @@ class Compilation extends Tapable {
82
82
  this.dependencyTemplates = new Map();
83
83
  }
84
84
 
85
+ getStats() {
86
+ return new Stats(this);
87
+ }
88
+
85
89
  templatesPlugin(name, fn) {
86
90
  this.mainTemplate.plugin(name, fn);
87
91
  this.chunkTemplate.plugin(name, fn);
@@ -197,7 +201,7 @@ class Compilation extends Tapable {
197
201
 
198
202
  addModuleDependencies(module, dependencies, bail, cacheGroup, recursive, callback) {
199
203
  let _this = this;
200
- const start = _this.profile && +new Date();
204
+ const start = _this.profile && Date.now();
201
205
 
202
206
  const factories = [];
203
207
  for(let i = 0; i < dependencies.length; i++) {
@@ -207,7 +211,7 @@ class Compilation extends Tapable {
207
211
  }
208
212
  factories[i] = [factory, dependencies[i]];
209
213
  }
210
- async.forEach(factories, function iteratorFactory(item, callback) {
214
+ asyncLib.forEach(factories, function iteratorFactory(item, callback) {
211
215
  const dependencies = item[1];
212
216
 
213
217
  const errorAndCallback = function errorAndCallback(err) {
@@ -266,7 +270,7 @@ class Compilation extends Tapable {
266
270
  if(!dependentModule.profile) {
267
271
  dependentModule.profile = {};
268
272
  }
269
- afterFactory = +new Date();
273
+ afterFactory = Date.now();
270
274
  dependentModule.profile.factory = afterFactory - start;
271
275
  }
272
276
 
@@ -286,7 +290,7 @@ class Compilation extends Tapable {
286
290
  if(!module.profile) {
287
291
  module.profile = {};
288
292
  }
289
- const time = +new Date() - start;
293
+ const time = Date.now() - start;
290
294
  if(!module.profile.dependencies || time > module.profile.dependencies) {
291
295
  module.profile.dependencies = time;
292
296
  }
@@ -307,7 +311,7 @@ class Compilation extends Tapable {
307
311
  iterationDependencies(dependencies);
308
312
 
309
313
  if(_this.profile) {
310
- const afterBuilding = +new Date();
314
+ const afterBuilding = Date.now();
311
315
  module.profile.building = afterBuilding - afterFactory;
312
316
  }
313
317
 
@@ -328,7 +332,7 @@ class Compilation extends Tapable {
328
332
  }
329
333
 
330
334
  if(_this.profile) {
331
- const afterBuilding = +new Date();
335
+ const afterBuilding = Date.now();
332
336
  dependentModule.profile.building = afterBuilding - afterFactory;
333
337
  }
334
338
 
@@ -356,7 +360,7 @@ class Compilation extends Tapable {
356
360
  }
357
361
 
358
362
  _addModuleChain(context, dependency, onModule, callback) {
359
- const start = this.profile && +new Date();
363
+ const start = this.profile && Date.now();
360
364
 
361
365
  const errorAndCallback = this.bail ? function errorAndCallback(err) {
362
366
  callback(err);
@@ -393,7 +397,7 @@ class Compilation extends Tapable {
393
397
  if(!module.profile) {
394
398
  module.profile = {};
395
399
  }
396
- afterFactory = +new Date();
400
+ afterFactory = Date.now();
397
401
  module.profile.factory = afterFactory - start;
398
402
  }
399
403
 
@@ -404,7 +408,7 @@ class Compilation extends Tapable {
404
408
  onModule(module);
405
409
 
406
410
  if(this.profile) {
407
- const afterBuilding = +new Date();
411
+ const afterBuilding = Date.now();
408
412
  module.profile.building = afterBuilding - afterFactory;
409
413
  }
410
414
 
@@ -432,7 +436,7 @@ class Compilation extends Tapable {
432
436
  }
433
437
 
434
438
  if(this.profile) {
435
- const afterBuilding = +new Date();
439
+ const afterBuilding = Date.now();
436
440
  module.profile.building = afterBuilding - afterFactory;
437
441
  }
438
442
 
@@ -474,7 +478,7 @@ class Compilation extends Tapable {
474
478
  const idx = this.preparedChunks.indexOf(slot);
475
479
  this.preparedChunks.splice(idx, 1);
476
480
  }
477
- return callback();
481
+ return callback(null, module);
478
482
  });
479
483
  }
480
484
 
@@ -1214,10 +1218,6 @@ class Compilation extends Tapable {
1214
1218
  return this.mainTemplate.applyPluginsWaterfall("asset-path", filename, data);
1215
1219
  }
1216
1220
 
1217
- getStats() {
1218
- return new Stats(this);
1219
- }
1220
-
1221
1221
  createChildCompiler(name, outputOptions) {
1222
1222
  return this.compiler.createChildCompiler(this, name, outputOptions);
1223
1223
  }
package/lib/Compiler.js CHANGED
@@ -6,15 +6,13 @@ var path = require("path");
6
6
  var Tapable = require("tapable");
7
7
 
8
8
  var Compilation = require("./Compilation");
9
-
9
+ var Stats = require("./Stats");
10
10
  var NormalModuleFactory = require("./NormalModuleFactory");
11
11
  var ContextModuleFactory = require("./ContextModuleFactory");
12
12
 
13
13
  function Watching(compiler, watchOptions, handler) {
14
14
  this.startTime = null;
15
15
  this.invalid = false;
16
- this.error = null;
17
- this.stats = null;
18
16
  this.handler = handler;
19
17
  this.closed = false;
20
18
  if(typeof watchOptions === "number") {
@@ -38,7 +36,7 @@ function Watching(compiler, watchOptions, handler) {
38
36
 
39
37
  Watching.prototype._go = function() {
40
38
  var self = this;
41
- self.startTime = new Date().getTime();
39
+ self.startTime = Date.now();
42
40
  self.running = true;
43
41
  self.invalid = false;
44
42
  self.compiler.applyPluginsAsync("watch-run", self, function(err) {
@@ -61,9 +59,9 @@ Watching.prototype._go = function() {
61
59
  if(compilation.applyPluginsBailResult("need-additional-pass")) {
62
60
  compilation.needAdditionalPass = true;
63
61
 
64
- var stats = compilation.getStats();
62
+ var stats = new Stats(compilation);
65
63
  stats.startTime = self.startTime;
66
- stats.endTime = new Date().getTime();
64
+ stats.endTime = Date.now();
67
65
  self.compiler.applyPlugins("done", stats);
68
66
 
69
67
  self.compiler.applyPluginsAsync("additional-pass", function(err) {
@@ -79,22 +77,29 @@ Watching.prototype._go = function() {
79
77
  });
80
78
  };
81
79
 
80
+ Watching.prototype._getStats = function(compilation) {
81
+ var stats = new Stats(compilation);
82
+ stats.startTime = this.startTime;
83
+ stats.endTime = Date.now();
84
+ return stats;
85
+ };
86
+
82
87
  Watching.prototype._done = function(err, compilation) {
83
88
  this.running = false;
84
89
  if(this.invalid) return this._go();
85
- this.error = err || null;
86
- this.stats = compilation ? compilation.getStats() : null;
87
- if(this.stats) {
88
- this.stats.startTime = this.startTime;
89
- this.stats.endTime = new Date().getTime();
90
+
91
+ var stats = compilation ? this._getStats(compilation) : null;
92
+ if(err) {
93
+ this.compiler.applyPlugins("failed", err);
94
+ this.handler(err, stats);
95
+ return;
90
96
  }
91
- if(this.stats)
92
- this.compiler.applyPlugins("done", this.stats);
93
- else
94
- this.compiler.applyPlugins("failed", this.error);
95
- this.handler(this.error, this.stats);
96
- if(!this.error && !this.closed)
97
+
98
+ this.compiler.applyPlugins("done", stats);
99
+ this.handler(null, stats);
100
+ if(!this.closed) {
97
101
  this.watch(compilation.fileDependencies, compilation.contextDependencies, compilation.missingDependencies);
102
+ }
98
103
  };
99
104
 
100
105
  Watching.prototype.watch = function(files, dirs, missing) {
@@ -217,7 +222,7 @@ Compiler.prototype.watch = function(watchOptions, handler) {
217
222
 
218
223
  Compiler.prototype.run = function(callback) {
219
224
  var self = this;
220
- var startTime = new Date().getTime();
225
+ var startTime = Date.now();
221
226
 
222
227
  self.applyPluginsAsync("before-run", self, function(err) {
223
228
  if(err) return callback(err);
@@ -232,9 +237,9 @@ Compiler.prototype.run = function(callback) {
232
237
  if(err) return callback(err);
233
238
 
234
239
  if(self.applyPluginsBailResult("should-emit", compilation) === false) {
235
- var stats = compilation.getStats();
240
+ var stats = new Stats(compilation);
236
241
  stats.startTime = startTime;
237
- stats.endTime = new Date().getTime();
242
+ stats.endTime = Date.now();
238
243
  self.applyPlugins("done", stats);
239
244
  return callback(null, stats);
240
245
  }
@@ -245,9 +250,9 @@ Compiler.prototype.run = function(callback) {
245
250
  if(compilation.applyPluginsBailResult("need-additional-pass")) {
246
251
  compilation.needAdditionalPass = true;
247
252
 
248
- var stats = compilation.getStats();
253
+ var stats = new Stats(compilation);
249
254
  stats.startTime = startTime;
250
- stats.endTime = new Date().getTime();
255
+ stats.endTime = Date.now();
251
256
  self.applyPlugins("done", stats);
252
257
 
253
258
  self.applyPluginsAsync("additional-pass", function(err) {
@@ -260,9 +265,9 @@ Compiler.prototype.run = function(callback) {
260
265
  self.emitRecords(function(err) {
261
266
  if(err) return callback(err);
262
267
 
263
- var stats = compilation.getStats();
268
+ var stats = new Stats(compilation);
264
269
  stats.startTime = startTime;
265
- stats.endTime = new Date().getTime();
270
+ stats.endTime = Date.now();
266
271
  self.applyPlugins("done", stats);
267
272
  return callback(null, stats);
268
273
  });
@@ -391,7 +396,7 @@ Compiler.prototype.readRecords = function readRecords(callback) {
391
396
  if(err) return callback(err);
392
397
 
393
398
  try {
394
- self.records = JSON.parse(content);
399
+ self.records = JSON.parse(content.toString("utf-8"));
395
400
  } catch(e) {
396
401
  e.message = "Cannot parse records: " + e.message;
397
402
  return callback(e);
@@ -10,7 +10,7 @@ const RawSource = require("webpack-sources").RawSource;
10
10
  const AsyncDependenciesBlock = require("./AsyncDependenciesBlock");
11
11
 
12
12
  class ContextModule extends Module {
13
- constructor(resolveDependencies, context, recursive, regExp, addon, isAsync) {
13
+ constructor(resolveDependencies, context, recursive, regExp, addon, isAsync, chunkName) {
14
14
  super();
15
15
  this.resolveDependencies = resolveDependencies;
16
16
  this.context = context;
@@ -21,6 +21,7 @@ class ContextModule extends Module {
21
21
  this.cacheable = true;
22
22
  this.contextDependencies = [context];
23
23
  this.built = false;
24
+ this.chunkName = chunkName;
24
25
  }
25
26
 
26
27
  prettyRegExp(regexString) {
@@ -98,7 +99,7 @@ class ContextModule extends Module {
98
99
 
99
100
  build(options, compilation, resolver, fs, callback) {
100
101
  this.built = true;
101
- this.builtTime = new Date().getTime();
102
+ this.builtTime = Date.now();
102
103
  this.resolveDependencies(fs, this.context, this.recursive, this.regExp, (err, dependencies) => {
103
104
  if(err) return callback(err);
104
105
 
@@ -125,7 +126,7 @@ class ContextModule extends Module {
125
126
  // if we are async however create a new async dependency block
126
127
  // and add that block to this context
127
128
  dependencies.forEach(dep => {
128
- const block = new AsyncDependenciesBlock(null, dep.module, dep.loc);
129
+ const block = new AsyncDependenciesBlock(this.chunkName, dep.module, dep.loc);
129
130
  block.addDependency(dep);
130
131
  this.addBlock(block);
131
132
  });
@@ -2,7 +2,7 @@
2
2
  MIT License http://www.opensource.org/licenses/mit-license.php
3
3
  Author Tobias Koppers @sokra
4
4
  */
5
- var async = require("async");
5
+ var asyncLib = require("async");
6
6
  var path = require("path");
7
7
 
8
8
  var Tapable = require("tapable");
@@ -61,7 +61,7 @@ ContextModuleFactory.prototype.create = function(data, callback) {
61
61
 
62
62
  var resolvers = module.resolvers;
63
63
 
64
- async.parallel([
64
+ asyncLib.parallel([
65
65
  function(callback) {
66
66
  resolvers.context.resolve({}, context, resource, function(err, result) {
67
67
  if(err) return callback(err);
@@ -69,7 +69,7 @@ ContextModuleFactory.prototype.create = function(data, callback) {
69
69
  });
70
70
  },
71
71
  function(callback) {
72
- async.map(loaders, function(loader, callback) {
72
+ asyncLib.map(loaders, function(loader, callback) {
73
73
  resolvers.loader.resolve({}, context, loader, function(err, result) {
74
74
  if(err) return callback(err);
75
75
  callback(null, result);
@@ -93,7 +93,7 @@ ContextModuleFactory.prototype.create = function(data, callback) {
93
93
  // Ignored
94
94
  if(!result) return callback();
95
95
 
96
- return callback(null, new ContextModule(result.resolveDependencies, result.resource, result.recursive, result.regExp, result.loaders, result.async));
96
+ return callback(null, new ContextModule(result.resolveDependencies, result.resource, result.recursive, result.regExp, result.loaders, result.async, dependency.chunkName));
97
97
  });
98
98
  });
99
99
  });
@@ -106,7 +106,7 @@ ContextModuleFactory.prototype.resolveDependencies = function resolveDependencie
106
106
  fs.readdir(directory, function(err, files) {
107
107
  if(err) return callback(err);
108
108
  if(!files || files.length === 0) return callback(null, []);
109
- async.map(files.filter(function(p) {
109
+ asyncLib.map(files.filter(function(p) {
110
110
  return p.indexOf(".") !== 0;
111
111
  }), function(seqment, callback) {
112
112
 
@@ -2,79 +2,85 @@
2
2
  MIT License http://www.opensource.org/licenses/mit-license.php
3
3
  Author Tobias Koppers @sokra
4
4
  */
5
- var Module = require("./Module");
6
- var OriginalSource = require("webpack-sources").OriginalSource;
7
- var RawSource = require("webpack-sources").RawSource;
8
- var WebpackMissingModule = require("./dependencies/WebpackMissingModule");
9
- var DelegatedSourceDependency = require("./dependencies/DelegatedSourceDependency");
5
+ "use strict";
10
6
 
11
- function DelegatedModule(sourceRequest, data, type, userRequest) {
12
- Module.call(this);
13
- this.sourceRequest = sourceRequest;
14
- this.request = data.id;
15
- this.meta = data.meta;
16
- this.type = type;
17
- this.userRequest = userRequest;
18
- this.built = false;
19
- this.delegateData = data;
20
- }
21
- module.exports = DelegatedModule;
7
+ const Module = require("./Module");
8
+ const OriginalSource = require("webpack-sources").OriginalSource;
9
+ const RawSource = require("webpack-sources").RawSource;
10
+ const WebpackMissingModule = require("./dependencies/WebpackMissingModule");
11
+ const DelegatedSourceDependency = require("./dependencies/DelegatedSourceDependency");
22
12
 
23
- DelegatedModule.prototype = Object.create(Module.prototype);
24
- DelegatedModule.prototype.constructor = DelegatedModule;
13
+ class DelegatedModule extends Module {
14
+ constructor(sourceRequest, data, type, userRequest) {
15
+ super();
16
+ this.sourceRequest = sourceRequest;
17
+ this.request = data.id;
18
+ this.meta = data.meta;
19
+ this.type = type;
20
+ this.userRequest = userRequest;
21
+ this.built = false;
22
+ this.delegated = true;
23
+ this.delegateData = data;
24
+ }
25
25
 
26
- DelegatedModule.prototype.delegated = true;
26
+ identifier() {
27
+ return `delegated ${JSON.stringify(this.request)} from ${this.sourceRequest}`;
28
+ }
27
29
 
28
- DelegatedModule.prototype.identifier = function() {
29
- return "delegated " + JSON.stringify(this.request) + " from " + this.sourceRequest;
30
- };
30
+ readableIdentifier() {
31
+ return `delegated ${this.userRequest} from ${this.sourceRequest}`;
32
+ }
31
33
 
32
- DelegatedModule.prototype.readableIdentifier = function() {
33
- return "delegated " + this.userRequest + " from " + this.sourceRequest;
34
- };
34
+ needRebuild() {
35
+ return false;
36
+ }
35
37
 
36
- DelegatedModule.prototype.needRebuild = function() {
37
- return false;
38
- };
38
+ build(options, compilation, resolver, fs, callback) {
39
+ this.built = true;
40
+ this.builtTime = Date.now();
41
+ this.usedExports = true;
42
+ this.providedExports = this.delegateData.exports || true;
43
+ this.dependencies.length = 0;
44
+ this.addDependency(new DelegatedSourceDependency(this.sourceRequest));
45
+ callback();
46
+ }
39
47
 
40
- DelegatedModule.prototype.build = function(options, compilation, resolver, fs, callback) {
41
- this.built = true;
42
- this.builtTime = new Date().getTime();
43
- this.usedExports = true;
44
- this.providedExports = this.delegateData.exports || true;
45
- this.dependencies.length = 0;
46
- this.addDependency(new DelegatedSourceDependency(this.sourceRequest));
47
- callback();
48
- };
48
+ unbuild() {
49
+ this.built = false;
50
+ super.unbuild();
51
+ }
49
52
 
50
- DelegatedModule.prototype.unbuild = function() {
51
- this.built = false;
52
- Module.prototype.unbuild.call(this);
53
- };
53
+ source() {
54
+ const sourceModule = this.dependencies[0].module;
55
+ let str;
54
56
 
55
- DelegatedModule.prototype.source = function() {
56
- var sourceModule = this.dependencies[0].module;
57
- var str;
58
- if(!sourceModule) {
59
- str = WebpackMissingModule.moduleCode(this.sourceRequest);
60
- } else {
61
- str = "module.exports = (__webpack_require__(" + sourceModule.id + "))";
62
- switch(this.type) {
63
- case "require":
64
- str += "(" + JSON.stringify(this.request) + ");";
65
- break;
66
- case "object":
67
- str += "[" + JSON.stringify(this.request) + "];";
68
- break;
57
+ if(!sourceModule) {
58
+ str = WebpackMissingModule.moduleCode(this.sourceRequest);
59
+ } else {
60
+ str = `module.exports = (__webpack_require__(${sourceModule.id}))`;
61
+
62
+ switch(this.type) {
63
+ case "require":
64
+ str += `(${JSON.stringify(this.request)})`;
65
+ break;
66
+ case "object":
67
+ str += `[${JSON.stringify(this.request)}]`;
68
+ break;
69
+ }
70
+
71
+ str += ";";
72
+ }
73
+
74
+ if(this.useSourceMap) {
75
+ return new OriginalSource(str, this.identifier());
76
+ } else {
77
+ return new RawSource(str);
69
78
  }
70
79
  }
71
- if(this.useSourceMap) {
72
- return new OriginalSource(str, this.identifier());
73
- } else {
74
- return new RawSource(str);
80
+
81
+ size() {
82
+ return 42;
75
83
  }
76
- };
84
+ }
77
85
 
78
- DelegatedModule.prototype.size = function() {
79
- return 42;
80
- };
86
+ module.exports = DelegatedModule;
@@ -1,75 +1,81 @@
1
1
  /*
2
- MIT License http://www.opensource.org/licenses/mit-license.php
3
- Author Tobias Koppers @sokra
4
- */
5
- var DependenciesBlockVariable = require("./DependenciesBlockVariable");
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Tobias Koppers @sokra
4
+ */
5
+ "use strict";
6
6
 
7
- function DependenciesBlock() {
8
- this.dependencies = [];
9
- this.blocks = [];
10
- this.variables = [];
7
+ const DependenciesBlockVariable = require("./DependenciesBlockVariable");
8
+
9
+ function disconnect(i) {
10
+ i.disconnect();
11
11
  }
12
- module.exports = DependenciesBlock;
13
12
 
14
- DependenciesBlock.prototype.addBlock = function(block) {
15
- this.blocks.push(block);
16
- block.parent = this;
17
- };
13
+ function unseal(i) {
14
+ i.unseal();
15
+ }
16
+
17
+ class DependenciesBlock {
18
+ constructor() {
19
+ this.dependencies = [];
20
+ this.blocks = [];
21
+ this.variables = [];
22
+ }
23
+
24
+ addBlock(block) {
25
+ this.blocks.push(block);
26
+ block.parent = this;
27
+ }
28
+
29
+ addVariable(name, expression, dependencies) {
30
+ for(let v of this.variables) {
31
+ if(v.name === name && v.expression === expression) {
32
+ return;
33
+ }
34
+ }
35
+ this.variables.push(new DependenciesBlockVariable(name, expression, dependencies));
36
+ }
18
37
 
19
- DependenciesBlock.prototype.addVariable = function(name, expression, dependencies) {
20
- for(var i = 0; i < this.variables.length; i++) {
21
- var v = this.variables[i];
22
- if(v.name === name && v.expression === expression) return;
38
+ addDependency(dependency) {
39
+ this.dependencies.push(dependency);
23
40
  }
24
- this.variables.push(new DependenciesBlockVariable(name, expression, dependencies));
25
- };
26
41
 
27
- DependenciesBlock.prototype.addDependency = function(dependency) {
28
- this.dependencies.push(dependency);
29
- };
42
+ updateHash(hash) {
43
+ function updateHash(i) {
44
+ i.updateHash(hash);
45
+ }
30
46
 
31
- DependenciesBlock.prototype.updateHash = function(hash) {
32
- this.dependencies.forEach(function(d) {
33
- d.updateHash(hash);
34
- });
35
- this.blocks.forEach(function(b) {
36
- b.updateHash(hash);
37
- });
38
- this.variables.forEach(function(v) {
39
- v.updateHash(hash);
40
- });
41
- };
47
+ this.dependencies.forEach(updateHash);
48
+ this.blocks.forEach(updateHash);
49
+ this.variables.forEach(updateHash);
50
+ }
42
51
 
43
- DependenciesBlock.prototype.disconnect = function() {
44
- function disconnect(i) {
45
- i.disconnect();
52
+ disconnect() {
53
+ this.dependencies.forEach(disconnect);
54
+ this.blocks.forEach(disconnect);
55
+ this.variables.forEach(disconnect);
46
56
  }
47
- this.dependencies.forEach(disconnect);
48
- this.blocks.forEach(disconnect);
49
- this.variables.forEach(disconnect);
50
- };
51
57
 
52
- DependenciesBlock.prototype.unseal = function() {
53
- function unseal(i) {
54
- i.unseal();
58
+ unseal() {
59
+ this.blocks.forEach(unseal);
55
60
  }
56
- this.blocks.forEach(unseal);
57
- };
58
61
 
59
- DependenciesBlock.prototype.hasDependencies = function(filter) {
60
- if(filter) {
61
- if(this.dependencies.some(filter)) return true;
62
- } else {
63
- if(this.dependencies.length > 0) return true;
62
+ hasDependencies(filter) {
63
+ if(filter) {
64
+ if(this.dependencies.some(filter)) {
65
+ return true;
66
+ }
67
+ } else {
68
+ if(this.dependencies.length > 0) {
69
+ return true;
70
+ }
71
+ }
72
+
73
+ return this.blocks.concat(this.variables).some(item => item.hasDependencies(filter));
64
74
  }
65
75
 
66
- return this.blocks.concat(this.variables).some(function(item) {
67
- return item.hasDependencies(filter);
68
- });
69
- };
76
+ sortItems() {
77
+ this.blocks.forEach(block => block.sortItems());
78
+ }
79
+ }
70
80
 
71
- DependenciesBlock.prototype.sortItems = function() {
72
- this.blocks.forEach(function(block) {
73
- block.sortItems();
74
- });
75
- };
81
+ module.exports = DependenciesBlock;
package/lib/Dependency.js CHANGED
@@ -44,6 +44,7 @@ class Dependency {
44
44
  this.module = null;
45
45
  }
46
46
 
47
+ // TODO: remove in webpack 3
47
48
  compare(a, b) {
48
49
  return compareLocations(a.loc, b.loc);
49
50
  }