webpack 3.5.2 → 3.5.6
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.
- package/README.md +567 -567
- package/bin/config-yargs.js +1 -1
- package/bin/convert-argv.js +4 -4
- package/lib/Compilation.js +178 -144
- package/lib/Compiler.js +17 -17
- package/lib/ContextModuleFactory.js +6 -6
- package/lib/HotModuleReplacement.runtime.js +602 -594
- package/lib/Module.js +250 -248
- package/lib/NormalModule.js +556 -555
- package/lib/OptionsDefaulter.js +73 -71
- package/lib/Parser.js +10 -10
- package/lib/SourceMapDevToolPlugin.js +209 -207
- package/lib/Template.js +176 -166
- package/lib/UmdMainTemplatePlugin.js +6 -6
- package/lib/WebpackOptionsDefaulter.js +129 -115
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +285 -286
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +124 -121
- package/lib/dependencies/HarmonyModulesHelpers.js +85 -85
- package/lib/optimize/ConcatenatedModule.js +814 -807
- package/lib/optimize/EnsureChunkConditionsPlugin.js +1 -0
- package/lib/optimize/ModuleConcatenationPlugin.js +9 -0
- package/lib/util/Semaphore.js +32 -0
- package/lib/webpack.js +119 -118
- package/package.json +1 -1
- package/schemas/webpackOptionsSchema.json +5 -0
package/bin/config-yargs.js
CHANGED
package/bin/convert-argv.js
CHANGED
@@ -166,12 +166,12 @@ module.exports = function(yargs, argv, convertOptions) {
|
|
166
166
|
options.watchOptions.aggregateTimeout = +argv["watch-aggregate-timeout"];
|
167
167
|
}
|
168
168
|
|
169
|
-
if(argv["watch-poll"]) {
|
169
|
+
if(typeof argv["watch-poll"] !== undefined) {
|
170
170
|
options.watchOptions = options.watchOptions || {};
|
171
|
-
if(
|
172
|
-
options.watchOptions.poll = +argv["watch-poll"];
|
173
|
-
else
|
171
|
+
if(argv["watch-poll"] === "true" || argv["watch-poll"] === "")
|
174
172
|
options.watchOptions.poll = true;
|
173
|
+
else if(!isNaN(argv["watch-poll"]))
|
174
|
+
options.watchOptions.poll = +argv["watch-poll"];
|
175
175
|
}
|
176
176
|
|
177
177
|
if(argv["watch-stdin"]) {
|
package/lib/Compilation.js
CHANGED
@@ -22,6 +22,7 @@ const Dependency = require("./Dependency");
|
|
22
22
|
const ChunkRenderError = require("./ChunkRenderError");
|
23
23
|
const CachedSource = require("webpack-sources").CachedSource;
|
24
24
|
const Stats = require("./Stats");
|
25
|
+
const Semaphore = require("./util/Semaphore");
|
25
26
|
|
26
27
|
function byId(a, b) {
|
27
28
|
if(a.id < b.id) return -1;
|
@@ -62,6 +63,8 @@ class Compilation extends Tapable {
|
|
62
63
|
this.hotUpdateChunkTemplate = new HotUpdateChunkTemplate(this.outputOptions);
|
63
64
|
this.moduleTemplate = new ModuleTemplate(this.outputOptions);
|
64
65
|
|
66
|
+
this.semaphore = new Semaphore(options.parallelism || 100);
|
67
|
+
|
65
68
|
this.entries = [];
|
66
69
|
this.preparedChunks = [];
|
67
70
|
this.entrypoints = {};
|
@@ -229,120 +232,128 @@ class Compilation extends Tapable {
|
|
229
232
|
callback();
|
230
233
|
};
|
231
234
|
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
235
|
+
_this.semaphore.acquire(() => {
|
236
|
+
const factory = item[0];
|
237
|
+
factory.create({
|
238
|
+
contextInfo: {
|
239
|
+
issuer: module.nameForCondition && module.nameForCondition(),
|
240
|
+
compiler: _this.compiler.name
|
241
|
+
},
|
242
|
+
context: module.context,
|
243
|
+
dependencies: dependencies
|
244
|
+
}, function factoryCallback(err, dependentModule) {
|
245
|
+
let afterFactory;
|
246
|
+
|
247
|
+
function isOptional() {
|
248
|
+
return dependencies.filter(d => !d.optional).length === 0;
|
249
|
+
}
|
246
250
|
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
251
|
+
function errorOrWarningAndCallback(err) {
|
252
|
+
if(isOptional()) {
|
253
|
+
return warningAndCallback(err);
|
254
|
+
} else {
|
255
|
+
return errorAndCallback(err);
|
256
|
+
}
|
252
257
|
}
|
253
|
-
}
|
254
258
|
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
259
|
+
function iterationDependencies(depend) {
|
260
|
+
for(let index = 0; index < depend.length; index++) {
|
261
|
+
const dep = depend[index];
|
262
|
+
dep.module = dependentModule;
|
263
|
+
dependentModule.addReason(module, dep);
|
264
|
+
}
|
260
265
|
}
|
261
|
-
}
|
262
266
|
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
267
|
+
if(err) {
|
268
|
+
_this.semaphore.release();
|
269
|
+
return errorOrWarningAndCallback(new ModuleNotFoundError(module, err, dependencies));
|
270
|
+
}
|
271
|
+
if(!dependentModule) {
|
272
|
+
_this.semaphore.release();
|
273
|
+
return process.nextTick(callback);
|
274
|
+
}
|
275
|
+
if(_this.profile) {
|
276
|
+
if(!dependentModule.profile) {
|
277
|
+
dependentModule.profile = {};
|
278
|
+
}
|
279
|
+
afterFactory = Date.now();
|
280
|
+
dependentModule.profile.factory = afterFactory - start;
|
272
281
|
}
|
273
|
-
afterFactory = Date.now();
|
274
|
-
dependentModule.profile.factory = afterFactory - start;
|
275
|
-
}
|
276
282
|
|
277
|
-
|
278
|
-
|
283
|
+
dependentModule.issuer = module;
|
284
|
+
const newModule = _this.addModule(dependentModule, cacheGroup);
|
279
285
|
|
280
|
-
|
281
|
-
|
286
|
+
if(!newModule) { // from cache
|
287
|
+
dependentModule = _this.getModule(dependentModule);
|
282
288
|
|
283
|
-
|
284
|
-
|
285
|
-
|
289
|
+
if(dependentModule.optional) {
|
290
|
+
dependentModule.optional = isOptional();
|
291
|
+
}
|
286
292
|
|
287
|
-
|
293
|
+
iterationDependencies(dependencies);
|
288
294
|
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
295
|
+
if(_this.profile) {
|
296
|
+
if(!module.profile) {
|
297
|
+
module.profile = {};
|
298
|
+
}
|
299
|
+
const time = Date.now() - start;
|
300
|
+
if(!module.profile.dependencies || time > module.profile.dependencies) {
|
301
|
+
module.profile.dependencies = time;
|
302
|
+
}
|
296
303
|
}
|
304
|
+
|
305
|
+
_this.semaphore.release();
|
306
|
+
return process.nextTick(callback);
|
297
307
|
}
|
298
308
|
|
299
|
-
|
300
|
-
|
309
|
+
if(newModule instanceof Module) {
|
310
|
+
if(_this.profile) {
|
311
|
+
newModule.profile = dependentModule.profile;
|
312
|
+
}
|
301
313
|
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
}
|
314
|
+
newModule.optional = isOptional();
|
315
|
+
newModule.issuer = dependentModule.issuer;
|
316
|
+
dependentModule = newModule;
|
306
317
|
|
307
|
-
|
308
|
-
newModule.issuer = dependentModule.issuer;
|
309
|
-
dependentModule = newModule;
|
318
|
+
iterationDependencies(dependencies);
|
310
319
|
|
311
|
-
|
320
|
+
if(_this.profile) {
|
321
|
+
const afterBuilding = Date.now();
|
322
|
+
module.profile.building = afterBuilding - afterFactory;
|
323
|
+
}
|
312
324
|
|
313
|
-
|
314
|
-
|
315
|
-
|
325
|
+
_this.semaphore.release();
|
326
|
+
if(recursive) {
|
327
|
+
return process.nextTick(_this.processModuleDependencies.bind(_this, dependentModule, callback));
|
328
|
+
} else {
|
329
|
+
return process.nextTick(callback);
|
330
|
+
}
|
316
331
|
}
|
317
332
|
|
318
|
-
|
319
|
-
return process.nextTick(_this.processModuleDependencies.bind(_this, dependentModule, callback));
|
320
|
-
} else {
|
321
|
-
return process.nextTick(callback);
|
322
|
-
}
|
323
|
-
}
|
333
|
+
dependentModule.optional = isOptional();
|
324
334
|
|
325
|
-
|
335
|
+
iterationDependencies(dependencies);
|
326
336
|
|
327
|
-
|
337
|
+
_this.buildModule(dependentModule, isOptional(), module, dependencies, err => {
|
338
|
+
if(err) {
|
339
|
+
_this.semaphore.release();
|
340
|
+
return errorOrWarningAndCallback(err);
|
341
|
+
}
|
328
342
|
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
343
|
+
if(_this.profile) {
|
344
|
+
const afterBuilding = Date.now();
|
345
|
+
dependentModule.profile.building = afterBuilding - afterFactory;
|
346
|
+
}
|
333
347
|
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
348
|
+
_this.semaphore.release();
|
349
|
+
if(recursive) {
|
350
|
+
_this.processModuleDependencies(dependentModule, callback);
|
351
|
+
} else {
|
352
|
+
return callback();
|
353
|
+
}
|
354
|
+
});
|
338
355
|
|
339
|
-
if(recursive) {
|
340
|
-
_this.processModuleDependencies(dependentModule, callback);
|
341
|
-
} else {
|
342
|
-
return callback();
|
343
|
-
}
|
344
356
|
});
|
345
|
-
|
346
357
|
});
|
347
358
|
}, function finalCallbackAddModuleDependencies(err) {
|
348
359
|
// In V8, the Error objects keep a reference to the functions on the stack. These warnings &
|
@@ -362,13 +373,13 @@ class Compilation extends Tapable {
|
|
362
373
|
_addModuleChain(context, dependency, onModule, callback) {
|
363
374
|
const start = this.profile && Date.now();
|
364
375
|
|
365
|
-
const errorAndCallback = this.bail ?
|
376
|
+
const errorAndCallback = this.bail ? (err) => {
|
366
377
|
callback(err);
|
367
|
-
} :
|
378
|
+
} : (err) => {
|
368
379
|
err.dependencies = [dependency];
|
369
380
|
this.errors.push(err);
|
370
381
|
callback();
|
371
|
-
}
|
382
|
+
};
|
372
383
|
|
373
384
|
if(typeof dependency !== "object" || dependency === null || !dependency.constructor) {
|
374
385
|
throw new Error("Parameter 'dependency' must be a Dependency");
|
@@ -379,79 +390,85 @@ class Compilation extends Tapable {
|
|
379
390
|
throw new Error(`No dependency factory available for this dependency type: ${dependency.constructor.name}`);
|
380
391
|
}
|
381
392
|
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
let afterFactory;
|
395
|
-
|
396
|
-
if(this.profile) {
|
397
|
-
if(!module.profile) {
|
398
|
-
module.profile = {};
|
393
|
+
this.semaphore.acquire(() => {
|
394
|
+
moduleFactory.create({
|
395
|
+
contextInfo: {
|
396
|
+
issuer: "",
|
397
|
+
compiler: this.compiler.name
|
398
|
+
},
|
399
|
+
context: context,
|
400
|
+
dependencies: [dependency]
|
401
|
+
}, (err, module) => {
|
402
|
+
if(err) {
|
403
|
+
this.semaphore.release();
|
404
|
+
return errorAndCallback(new EntryModuleNotFoundError(err));
|
399
405
|
}
|
400
|
-
afterFactory = Date.now();
|
401
|
-
module.profile.factory = afterFactory - start;
|
402
|
-
}
|
403
|
-
|
404
|
-
const result = this.addModule(module);
|
405
|
-
if(!result) {
|
406
|
-
module = this.getModule(module);
|
407
406
|
|
408
|
-
|
407
|
+
let afterFactory;
|
409
408
|
|
410
409
|
if(this.profile) {
|
411
|
-
|
412
|
-
|
410
|
+
if(!module.profile) {
|
411
|
+
module.profile = {};
|
412
|
+
}
|
413
|
+
afterFactory = Date.now();
|
414
|
+
module.profile.factory = afterFactory - start;
|
413
415
|
}
|
414
416
|
|
415
|
-
|
416
|
-
|
417
|
+
const result = this.addModule(module);
|
418
|
+
if(!result) {
|
419
|
+
module = this.getModule(module);
|
417
420
|
|
418
|
-
|
419
|
-
if(this.profile) {
|
420
|
-
result.profile = module.profile;
|
421
|
-
}
|
421
|
+
onModule(module);
|
422
422
|
|
423
|
-
|
423
|
+
if(this.profile) {
|
424
|
+
const afterBuilding = Date.now();
|
425
|
+
module.profile.building = afterBuilding - afterFactory;
|
426
|
+
}
|
424
427
|
|
425
|
-
|
428
|
+
this.semaphore.release();
|
429
|
+
return callback(null, module);
|
430
|
+
}
|
426
431
|
|
427
|
-
|
428
|
-
|
429
|
-
|
432
|
+
if(result instanceof Module) {
|
433
|
+
if(this.profile) {
|
434
|
+
result.profile = module.profile;
|
435
|
+
}
|
430
436
|
|
431
|
-
|
437
|
+
module = result;
|
432
438
|
|
433
|
-
|
434
|
-
if(err) {
|
435
|
-
return errorAndCallback(err);
|
436
|
-
}
|
439
|
+
onModule(module);
|
437
440
|
|
438
|
-
|
439
|
-
|
440
|
-
module.profile.building = afterBuilding - afterFactory;
|
441
|
+
moduleReady.call(this);
|
442
|
+
return;
|
441
443
|
}
|
442
444
|
|
443
|
-
|
444
|
-
});
|
445
|
+
onModule(module);
|
445
446
|
|
446
|
-
|
447
|
-
this.processModuleDependencies(module, err => {
|
447
|
+
this.buildModule(module, false, null, null, (err) => {
|
448
448
|
if(err) {
|
449
|
-
|
449
|
+
this.semaphore.release();
|
450
|
+
return errorAndCallback(err);
|
450
451
|
}
|
451
452
|
|
452
|
-
|
453
|
+
if(this.profile) {
|
454
|
+
const afterBuilding = Date.now();
|
455
|
+
module.profile.building = afterBuilding - afterFactory;
|
456
|
+
}
|
457
|
+
|
458
|
+
moduleReady.call(this);
|
453
459
|
});
|
454
|
-
|
460
|
+
|
461
|
+
function moduleReady() {
|
462
|
+
this.semaphore.release();
|
463
|
+
this.processModuleDependencies(module, err => {
|
464
|
+
if(err) {
|
465
|
+
return callback(err);
|
466
|
+
}
|
467
|
+
|
468
|
+
return callback(null, module);
|
469
|
+
});
|
470
|
+
}
|
471
|
+
});
|
455
472
|
});
|
456
473
|
}
|
457
474
|
|
@@ -1103,6 +1120,17 @@ class Compilation extends Tapable {
|
|
1103
1120
|
for(let indexChunk = 0; indexChunk < chunks.length; indexChunk++) {
|
1104
1121
|
chunks[indexChunk].sortItems();
|
1105
1122
|
}
|
1123
|
+
|
1124
|
+
const byMessage = (a, b) => {
|
1125
|
+
const ma = `${a.message}`;
|
1126
|
+
const mb = `${b.message}`;
|
1127
|
+
if(ma < mb) return -1;
|
1128
|
+
if(mb < ma) return 1;
|
1129
|
+
return 0;
|
1130
|
+
};
|
1131
|
+
|
1132
|
+
this.errors.sort(byMessage);
|
1133
|
+
this.warnings.sort(byMessage);
|
1106
1134
|
}
|
1107
1135
|
|
1108
1136
|
summarizeDependencies() {
|
@@ -1171,6 +1199,12 @@ class Compilation extends Tapable {
|
|
1171
1199
|
this.children.forEach(function(child) {
|
1172
1200
|
hash.update(child.hash);
|
1173
1201
|
});
|
1202
|
+
this.warnings.forEach(function(warning) {
|
1203
|
+
hash.update(`${warning.message}`);
|
1204
|
+
});
|
1205
|
+
this.errors.forEach(function(error) {
|
1206
|
+
hash.update(`${error.message}`);
|
1207
|
+
});
|
1174
1208
|
// clone needed as sort below is inplace mutation
|
1175
1209
|
const chunks = this.chunks.slice();
|
1176
1210
|
/**
|
package/lib/Compiler.js
CHANGED
@@ -201,7 +201,7 @@ class Compiler extends Tapable {
|
|
201
201
|
});
|
202
202
|
});
|
203
203
|
},
|
204
|
-
apply:
|
204
|
+
apply: () => {
|
205
205
|
const args = arguments;
|
206
206
|
if(!deprecationReported) {
|
207
207
|
console.warn("webpack: Using compiler.parser is deprecated.\n" +
|
@@ -214,7 +214,7 @@ class Compiler extends Tapable {
|
|
214
214
|
parser.apply.apply(parser, args);
|
215
215
|
});
|
216
216
|
});
|
217
|
-
}
|
217
|
+
}
|
218
218
|
};
|
219
219
|
|
220
220
|
this.options = {};
|
@@ -313,13 +313,7 @@ class Compiler extends Tapable {
|
|
313
313
|
emitAssets(compilation, callback) {
|
314
314
|
let outputPath;
|
315
315
|
|
316
|
-
|
317
|
-
if(err) return callback(err);
|
318
|
-
outputPath = compilation.getPath(this.outputPath);
|
319
|
-
this.outputFileSystem.mkdirp(outputPath, emitFiles.bind(this));
|
320
|
-
});
|
321
|
-
|
322
|
-
function emitFiles(err) {
|
316
|
+
const emitFiles = (err) => {
|
323
317
|
if(err) return callback(err);
|
324
318
|
|
325
319
|
require("async").forEach(Object.keys(compilation.assets), (file, callback) => {
|
@@ -330,12 +324,7 @@ class Compiler extends Tapable {
|
|
330
324
|
targetFile = targetFile.substr(0, queryStringIdx);
|
331
325
|
}
|
332
326
|
|
333
|
-
|
334
|
-
const dir = path.dirname(targetFile);
|
335
|
-
this.outputFileSystem.mkdirp(this.outputFileSystem.join(outputPath, dir), writeOut.bind(this));
|
336
|
-
} else writeOut.call(this);
|
337
|
-
|
338
|
-
function writeOut(err) {
|
327
|
+
const writeOut = (err) => {
|
339
328
|
if(err) return callback(err);
|
340
329
|
const targetPath = this.outputFileSystem.join(outputPath, targetFile);
|
341
330
|
const source = compilation.assets[file];
|
@@ -352,14 +341,25 @@ class Compiler extends Tapable {
|
|
352
341
|
source.existsAt = targetPath;
|
353
342
|
source.emitted = true;
|
354
343
|
this.outputFileSystem.writeFile(targetPath, content, callback);
|
355
|
-
}
|
344
|
+
};
|
345
|
+
|
346
|
+
if(targetFile.match(/\/|\\/)) {
|
347
|
+
const dir = path.dirname(targetFile);
|
348
|
+
this.outputFileSystem.mkdirp(this.outputFileSystem.join(outputPath, dir), writeOut);
|
349
|
+
} else writeOut();
|
356
350
|
|
357
351
|
}, err => {
|
358
352
|
if(err) return callback(err);
|
359
353
|
|
360
354
|
afterEmit.call(this);
|
361
355
|
});
|
362
|
-
}
|
356
|
+
};
|
357
|
+
|
358
|
+
this.applyPluginsAsync("emit", compilation, err => {
|
359
|
+
if(err) return callback(err);
|
360
|
+
outputPath = compilation.getPath(this.outputPath);
|
361
|
+
this.outputFileSystem.mkdirp(outputPath, emitFiles);
|
362
|
+
});
|
363
363
|
|
364
364
|
function afterEmit() {
|
365
365
|
this.applyPluginsAsyncSeries1("after-emit", compilation, err => {
|
@@ -103,16 +103,16 @@ module.exports = class ContextModuleFactory extends Tapable {
|
|
103
103
|
if(!regExp || !resource)
|
104
104
|
return callback(null, []);
|
105
105
|
(function addDirectory(directory, callback) {
|
106
|
-
fs.readdir(directory,
|
106
|
+
fs.readdir(directory, (err, files) => {
|
107
107
|
if(err) return callback(err);
|
108
108
|
if(!files || files.length === 0) return callback(null, []);
|
109
109
|
asyncLib.map(files.filter(function(p) {
|
110
110
|
return p.indexOf(".") !== 0;
|
111
|
-
}),
|
111
|
+
}), (seqment, callback) => {
|
112
112
|
|
113
113
|
const subResource = path.join(directory, seqment);
|
114
114
|
|
115
|
-
fs.stat(subResource,
|
115
|
+
fs.stat(subResource, (err, stat) => {
|
116
116
|
if(err) return callback(err);
|
117
117
|
|
118
118
|
if(stat.isDirectory()) {
|
@@ -141,9 +141,9 @@ module.exports = class ContextModuleFactory extends Tapable {
|
|
141
141
|
|
142
142
|
} else callback();
|
143
143
|
|
144
|
-
}
|
144
|
+
});
|
145
145
|
|
146
|
-
}
|
146
|
+
}, (err, result) => {
|
147
147
|
if(err) return callback(err);
|
148
148
|
|
149
149
|
if(!result) return callback(null, []);
|
@@ -154,7 +154,7 @@ module.exports = class ContextModuleFactory extends Tapable {
|
|
154
154
|
return a.concat(i);
|
155
155
|
}, []));
|
156
156
|
});
|
157
|
-
}
|
157
|
+
});
|
158
158
|
}.call(this, resource, callback));
|
159
159
|
}
|
160
160
|
};
|