webpack 3.5.5 → 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/HotModuleReplacement.runtime.js +602 -601
- package/lib/Module.js +250 -249
- package/lib/NormalModule.js +556 -555
- package/lib/OptionsDefaulter.js +73 -71
- package/lib/SourceMapDevToolPlugin.js +209 -207
- package/lib/Template.js +176 -166
- 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 -814
- package/lib/webpack.js +119 -118
- package/package.json +1 -1
package/lib/NormalModule.js
CHANGED
@@ -1,555 +1,556 @@
|
|
1
|
-
/*
|
2
|
-
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
-
Author Tobias Koppers @sokra
|
4
|
-
*/
|
5
|
-
"use strict";
|
6
|
-
|
7
|
-
const path = require("path");
|
8
|
-
const NativeModule = require("module");
|
9
|
-
const crypto = require("crypto");
|
10
|
-
|
11
|
-
const SourceMapSource = require("webpack-sources").SourceMapSource;
|
12
|
-
const OriginalSource = require("webpack-sources").OriginalSource;
|
13
|
-
const RawSource = require("webpack-sources").RawSource;
|
14
|
-
const ReplaceSource = require("webpack-sources").ReplaceSource;
|
15
|
-
const CachedSource = require("webpack-sources").CachedSource;
|
16
|
-
const LineToLineMappedSource = require("webpack-sources").LineToLineMappedSource;
|
17
|
-
|
18
|
-
const WebpackError = require("./WebpackError");
|
19
|
-
const Module = require("./Module");
|
20
|
-
const ModuleParseError = require("./ModuleParseError");
|
21
|
-
const ModuleBuildError = require("./ModuleBuildError");
|
22
|
-
const ModuleError = require("./ModuleError");
|
23
|
-
const ModuleWarning = require("./ModuleWarning");
|
24
|
-
|
25
|
-
const runLoaders = require("loader-runner").runLoaders;
|
26
|
-
const getContext = require("loader-runner").getContext;
|
27
|
-
|
28
|
-
function asString(buf) {
|
29
|
-
if(Buffer.isBuffer(buf)) {
|
30
|
-
return buf.toString("utf-8");
|
31
|
-
}
|
32
|
-
return buf;
|
33
|
-
}
|
34
|
-
|
35
|
-
function contextify(context, request) {
|
36
|
-
return request.split("!").map(function(r) {
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
}
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
this.
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
}
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
this.
|
65
|
-
this.
|
66
|
-
this.
|
67
|
-
this.
|
68
|
-
this.
|
69
|
-
this.
|
70
|
-
this.
|
71
|
-
this.
|
72
|
-
this.
|
73
|
-
this.
|
74
|
-
this.
|
75
|
-
this.
|
76
|
-
this.
|
77
|
-
this.
|
78
|
-
this.
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
return this.resource;
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
module
|
127
|
-
module.
|
128
|
-
module.
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
if
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
this.
|
190
|
-
this.
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
const
|
200
|
-
const
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
return
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
this.
|
220
|
-
this.
|
221
|
-
this.
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
if
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
//
|
239
|
-
// returns "
|
240
|
-
|
241
|
-
|
242
|
-
//
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
//
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
this.
|
268
|
-
this.
|
269
|
-
this.
|
270
|
-
this.
|
271
|
-
this.
|
272
|
-
this.
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
this.
|
277
|
-
this.
|
278
|
-
this.
|
279
|
-
|
280
|
-
|
281
|
-
if
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
// if
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
const
|
303
|
-
this
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
template
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
const
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
*
|
340
|
-
*
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
*
|
357
|
-
*
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
const
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
// if
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
current
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
*
|
393
|
-
*
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
*
|
409
|
-
*
|
410
|
-
*
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
*
|
416
|
-
*
|
417
|
-
*
|
418
|
-
*
|
419
|
-
*
|
420
|
-
*
|
421
|
-
*
|
422
|
-
*
|
423
|
-
*
|
424
|
-
*
|
425
|
-
*
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
if
|
451
|
-
|
452
|
-
const
|
453
|
-
|
454
|
-
source.insert(
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
const
|
499
|
-
|
500
|
-
if
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
//
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
//
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
//
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
hash.update(
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
this.
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Tobias Koppers @sokra
|
4
|
+
*/
|
5
|
+
"use strict";
|
6
|
+
|
7
|
+
const path = require("path");
|
8
|
+
const NativeModule = require("module");
|
9
|
+
const crypto = require("crypto");
|
10
|
+
|
11
|
+
const SourceMapSource = require("webpack-sources").SourceMapSource;
|
12
|
+
const OriginalSource = require("webpack-sources").OriginalSource;
|
13
|
+
const RawSource = require("webpack-sources").RawSource;
|
14
|
+
const ReplaceSource = require("webpack-sources").ReplaceSource;
|
15
|
+
const CachedSource = require("webpack-sources").CachedSource;
|
16
|
+
const LineToLineMappedSource = require("webpack-sources").LineToLineMappedSource;
|
17
|
+
|
18
|
+
const WebpackError = require("./WebpackError");
|
19
|
+
const Module = require("./Module");
|
20
|
+
const ModuleParseError = require("./ModuleParseError");
|
21
|
+
const ModuleBuildError = require("./ModuleBuildError");
|
22
|
+
const ModuleError = require("./ModuleError");
|
23
|
+
const ModuleWarning = require("./ModuleWarning");
|
24
|
+
|
25
|
+
const runLoaders = require("loader-runner").runLoaders;
|
26
|
+
const getContext = require("loader-runner").getContext;
|
27
|
+
|
28
|
+
function asString(buf) {
|
29
|
+
if(Buffer.isBuffer(buf)) {
|
30
|
+
return buf.toString("utf-8");
|
31
|
+
}
|
32
|
+
return buf;
|
33
|
+
}
|
34
|
+
|
35
|
+
function contextify(context, request) {
|
36
|
+
return request.split("!").map(function(r) {
|
37
|
+
const splitPath = r.split("?");
|
38
|
+
splitPath[0] = path.relative(context, splitPath[0]);
|
39
|
+
if(path.sep === "\\")
|
40
|
+
splitPath[0] = splitPath[0].replace(/\\/g, "/");
|
41
|
+
if(splitPath[0].indexOf("../") !== 0)
|
42
|
+
splitPath[0] = "./" + splitPath[0];
|
43
|
+
return splitPath.join("?");
|
44
|
+
}).join("!");
|
45
|
+
}
|
46
|
+
|
47
|
+
class NonErrorEmittedError extends WebpackError {
|
48
|
+
constructor(error) {
|
49
|
+
super();
|
50
|
+
|
51
|
+
this.name = "NonErrorEmittedError";
|
52
|
+
this.message = "(Emitted value instead of an instance of Error) " + error;
|
53
|
+
|
54
|
+
Error.captureStackTrace(this, this.constructor);
|
55
|
+
}
|
56
|
+
}
|
57
|
+
|
58
|
+
const dependencyTemplatesHashMap = new WeakMap();
|
59
|
+
|
60
|
+
class NormalModule extends Module {
|
61
|
+
|
62
|
+
constructor(request, userRequest, rawRequest, loaders, resource, parser) {
|
63
|
+
super();
|
64
|
+
this.request = request;
|
65
|
+
this.userRequest = userRequest;
|
66
|
+
this.rawRequest = rawRequest;
|
67
|
+
this.parser = parser;
|
68
|
+
this.resource = resource;
|
69
|
+
this.context = getContext(resource);
|
70
|
+
this.loaders = loaders;
|
71
|
+
this.fileDependencies = [];
|
72
|
+
this.contextDependencies = [];
|
73
|
+
this.warnings = [];
|
74
|
+
this.errors = [];
|
75
|
+
this.error = null;
|
76
|
+
this._source = null;
|
77
|
+
this.assets = {};
|
78
|
+
this.built = false;
|
79
|
+
this._cachedSource = null;
|
80
|
+
}
|
81
|
+
|
82
|
+
identifier() {
|
83
|
+
return this.request;
|
84
|
+
}
|
85
|
+
|
86
|
+
readableIdentifier(requestShortener) {
|
87
|
+
return requestShortener.shorten(this.userRequest);
|
88
|
+
}
|
89
|
+
|
90
|
+
libIdent(options) {
|
91
|
+
return contextify(options.context, this.userRequest);
|
92
|
+
}
|
93
|
+
|
94
|
+
nameForCondition() {
|
95
|
+
const idx = this.resource.indexOf("?");
|
96
|
+
if(idx >= 0) return this.resource.substr(0, idx);
|
97
|
+
return this.resource;
|
98
|
+
}
|
99
|
+
|
100
|
+
createSourceForAsset(name, content, sourceMap) {
|
101
|
+
if(!sourceMap) {
|
102
|
+
return new RawSource(content);
|
103
|
+
}
|
104
|
+
|
105
|
+
if(typeof sourceMap === "string") {
|
106
|
+
return new OriginalSource(content, sourceMap);
|
107
|
+
}
|
108
|
+
|
109
|
+
return new SourceMapSource(content, name, sourceMap);
|
110
|
+
}
|
111
|
+
|
112
|
+
createLoaderContext(resolver, options, compilation, fs) {
|
113
|
+
const loaderContext = {
|
114
|
+
version: 2,
|
115
|
+
emitWarning: (warning) => {
|
116
|
+
if(!(warning instanceof Error))
|
117
|
+
warning = new NonErrorEmittedError(warning);
|
118
|
+
this.warnings.push(new ModuleWarning(this, warning));
|
119
|
+
},
|
120
|
+
emitError: (error) => {
|
121
|
+
if(!(error instanceof Error))
|
122
|
+
error = new NonErrorEmittedError(error);
|
123
|
+
this.errors.push(new ModuleError(this, error));
|
124
|
+
},
|
125
|
+
exec: (code, filename) => {
|
126
|
+
const module = new NativeModule(filename, this);
|
127
|
+
module.paths = NativeModule._nodeModulePaths(this.context);
|
128
|
+
module.filename = filename;
|
129
|
+
module._compile(code, filename);
|
130
|
+
return module.exports;
|
131
|
+
},
|
132
|
+
resolve(context, request, callback) {
|
133
|
+
resolver.resolve({}, context, request, callback);
|
134
|
+
},
|
135
|
+
resolveSync(context, request) {
|
136
|
+
return resolver.resolveSync({}, context, request);
|
137
|
+
},
|
138
|
+
emitFile: (name, content, sourceMap) => {
|
139
|
+
this.assets[name] = this.createSourceForAsset(name, content, sourceMap);
|
140
|
+
},
|
141
|
+
options: options,
|
142
|
+
webpack: true,
|
143
|
+
sourceMap: !!this.useSourceMap,
|
144
|
+
_module: this,
|
145
|
+
_compilation: compilation,
|
146
|
+
_compiler: compilation.compiler,
|
147
|
+
fs: fs,
|
148
|
+
};
|
149
|
+
|
150
|
+
compilation.applyPlugins("normal-module-loader", loaderContext, this);
|
151
|
+
if(options.loader)
|
152
|
+
Object.assign(loaderContext, options.loader);
|
153
|
+
|
154
|
+
return loaderContext;
|
155
|
+
}
|
156
|
+
|
157
|
+
createSource(source, resourceBuffer, sourceMap) {
|
158
|
+
// if there is no identifier return raw source
|
159
|
+
if(!this.identifier) {
|
160
|
+
return new RawSource(source);
|
161
|
+
}
|
162
|
+
|
163
|
+
// from here on we assume we have an identifier
|
164
|
+
const identifier = this.identifier();
|
165
|
+
|
166
|
+
if(this.lineToLine && resourceBuffer) {
|
167
|
+
return new LineToLineMappedSource(
|
168
|
+
source, identifier, asString(resourceBuffer));
|
169
|
+
}
|
170
|
+
|
171
|
+
if(this.useSourceMap && sourceMap) {
|
172
|
+
return new SourceMapSource(source, identifier, sourceMap);
|
173
|
+
}
|
174
|
+
|
175
|
+
return new OriginalSource(source, identifier);
|
176
|
+
}
|
177
|
+
|
178
|
+
doBuild(options, compilation, resolver, fs, callback) {
|
179
|
+
this.cacheable = false;
|
180
|
+
const loaderContext = this.createLoaderContext(resolver, options, compilation, fs);
|
181
|
+
|
182
|
+
runLoaders({
|
183
|
+
resource: this.resource,
|
184
|
+
loaders: this.loaders,
|
185
|
+
context: loaderContext,
|
186
|
+
readResource: fs.readFile.bind(fs)
|
187
|
+
}, (err, result) => {
|
188
|
+
if(result) {
|
189
|
+
this.cacheable = result.cacheable;
|
190
|
+
this.fileDependencies = result.fileDependencies;
|
191
|
+
this.contextDependencies = result.contextDependencies;
|
192
|
+
}
|
193
|
+
|
194
|
+
if(err) {
|
195
|
+
const error = new ModuleBuildError(this, err);
|
196
|
+
return callback(error);
|
197
|
+
}
|
198
|
+
|
199
|
+
const resourceBuffer = result.resourceBuffer;
|
200
|
+
const source = result.result[0];
|
201
|
+
const sourceMap = result.result[1];
|
202
|
+
|
203
|
+
if(!Buffer.isBuffer(source) && typeof source !== "string") {
|
204
|
+
const error = new ModuleBuildError(this, new Error("Final loader didn't return a Buffer or String"));
|
205
|
+
return callback(error);
|
206
|
+
}
|
207
|
+
|
208
|
+
this._source = this.createSource(asString(source), resourceBuffer, sourceMap);
|
209
|
+
return callback();
|
210
|
+
});
|
211
|
+
}
|
212
|
+
|
213
|
+
disconnect() {
|
214
|
+
this.built = false;
|
215
|
+
super.disconnect();
|
216
|
+
}
|
217
|
+
|
218
|
+
markModuleAsErrored(error) {
|
219
|
+
this.meta = null;
|
220
|
+
this.error = error;
|
221
|
+
this.errors.push(this.error);
|
222
|
+
this._source = new RawSource("throw new Error(" + JSON.stringify(this.error.message) + ");");
|
223
|
+
}
|
224
|
+
|
225
|
+
applyNoParseRule(rule, content) {
|
226
|
+
// must start with "rule" if rule is a string
|
227
|
+
if(typeof rule === "string") {
|
228
|
+
return content.indexOf(rule) === 0;
|
229
|
+
}
|
230
|
+
|
231
|
+
if(typeof rule === "function") {
|
232
|
+
return rule(content);
|
233
|
+
}
|
234
|
+
// we assume rule is a regexp
|
235
|
+
return rule.test(content);
|
236
|
+
}
|
237
|
+
|
238
|
+
// check if module should not be parsed
|
239
|
+
// returns "true" if the module should !not! be parsed
|
240
|
+
// returns "false" if the module !must! be parsed
|
241
|
+
shouldPreventParsing(noParseRule, request) {
|
242
|
+
// if no noParseRule exists, return false
|
243
|
+
// the module !must! be parsed.
|
244
|
+
if(!noParseRule) {
|
245
|
+
return false;
|
246
|
+
}
|
247
|
+
|
248
|
+
// we only have one rule to check
|
249
|
+
if(!Array.isArray(noParseRule)) {
|
250
|
+
// returns "true" if the module is !not! to be parsed
|
251
|
+
return this.applyNoParseRule(noParseRule, request);
|
252
|
+
}
|
253
|
+
|
254
|
+
for(let i = 0; i < noParseRule.length; i++) {
|
255
|
+
const rule = noParseRule[i];
|
256
|
+
// early exit on first truthy match
|
257
|
+
// this module is !not! to be parsed
|
258
|
+
if(this.applyNoParseRule(rule, request)) {
|
259
|
+
return true;
|
260
|
+
}
|
261
|
+
}
|
262
|
+
// no match found, so this module !should! be parsed
|
263
|
+
return false;
|
264
|
+
}
|
265
|
+
|
266
|
+
build(options, compilation, resolver, fs, callback) {
|
267
|
+
this.buildTimestamp = Date.now();
|
268
|
+
this.built = true;
|
269
|
+
this._source = null;
|
270
|
+
this.error = null;
|
271
|
+
this.errors.length = 0;
|
272
|
+
this.warnings.length = 0;
|
273
|
+
this.meta = {};
|
274
|
+
|
275
|
+
return this.doBuild(options, compilation, resolver, fs, (err) => {
|
276
|
+
this.dependencies.length = 0;
|
277
|
+
this.variables.length = 0;
|
278
|
+
this.blocks.length = 0;
|
279
|
+
this._cachedSource = null;
|
280
|
+
|
281
|
+
// if we have an error mark module as failed and exit
|
282
|
+
if(err) {
|
283
|
+
this.markModuleAsErrored(err);
|
284
|
+
return callback();
|
285
|
+
}
|
286
|
+
|
287
|
+
// check if this module should !not! be parsed.
|
288
|
+
// if so, exit here;
|
289
|
+
const noParseRule = options.module && options.module.noParse;
|
290
|
+
if(this.shouldPreventParsing(noParseRule, this.request)) {
|
291
|
+
return callback();
|
292
|
+
}
|
293
|
+
|
294
|
+
try {
|
295
|
+
this.parser.parse(this._source.source(), {
|
296
|
+
current: this,
|
297
|
+
module: this,
|
298
|
+
compilation: compilation,
|
299
|
+
options: options
|
300
|
+
});
|
301
|
+
} catch(e) {
|
302
|
+
const source = this._source.source();
|
303
|
+
const error = new ModuleParseError(this, source, e);
|
304
|
+
this.markModuleAsErrored(error);
|
305
|
+
return callback();
|
306
|
+
}
|
307
|
+
return callback();
|
308
|
+
});
|
309
|
+
}
|
310
|
+
|
311
|
+
getHashDigest(dependencyTemplates) {
|
312
|
+
let dtHash = dependencyTemplatesHashMap.get("hash");
|
313
|
+
const hash = crypto.createHash("md5");
|
314
|
+
this.updateHash(hash);
|
315
|
+
hash.update(`${dtHash}`);
|
316
|
+
return hash.digest("hex");
|
317
|
+
}
|
318
|
+
|
319
|
+
sourceDependency(dependency, dependencyTemplates, source, outputOptions, requestShortener) {
|
320
|
+
const template = dependencyTemplates.get(dependency.constructor);
|
321
|
+
if(!template) throw new Error("No template for dependency: " + dependency.constructor.name);
|
322
|
+
template.apply(dependency, source, outputOptions, requestShortener, dependencyTemplates);
|
323
|
+
}
|
324
|
+
|
325
|
+
sourceVariables(variable, availableVars, dependencyTemplates, outputOptions, requestShortener) {
|
326
|
+
const name = variable.name;
|
327
|
+
const expr = variable.expressionSource(dependencyTemplates, outputOptions, requestShortener);
|
328
|
+
|
329
|
+
if(availableVars.some(v => v.name === name && v.expression.source() === expr.source())) {
|
330
|
+
return;
|
331
|
+
}
|
332
|
+
return {
|
333
|
+
name: name,
|
334
|
+
expression: expr
|
335
|
+
};
|
336
|
+
}
|
337
|
+
|
338
|
+
/*
|
339
|
+
* creates the start part of a IIFE around the module to inject a variable name
|
340
|
+
* (function(...){ <- this part
|
341
|
+
* }.call(...))
|
342
|
+
*/
|
343
|
+
variableInjectionFunctionWrapperStartCode(varNames) {
|
344
|
+
const args = varNames.join(", ");
|
345
|
+
return `/* WEBPACK VAR INJECTION */(function(${args}) {`;
|
346
|
+
}
|
347
|
+
|
348
|
+
contextArgument(block) {
|
349
|
+
if(this === block) {
|
350
|
+
return this.exportsArgument || "exports";
|
351
|
+
}
|
352
|
+
return "this";
|
353
|
+
}
|
354
|
+
|
355
|
+
/*
|
356
|
+
* creates the end part of a IIFE around the module to inject a variable name
|
357
|
+
* (function(...){
|
358
|
+
* }.call(...)) <- this part
|
359
|
+
*/
|
360
|
+
variableInjectionFunctionWrapperEndCode(varExpressions, block) {
|
361
|
+
const firstParam = this.contextArgument(block);
|
362
|
+
const furtherParams = varExpressions.map(e => e.source()).join(", ");
|
363
|
+
return `}.call(${firstParam}, ${furtherParams}))`;
|
364
|
+
}
|
365
|
+
|
366
|
+
splitVariablesInUniqueNamedChunks(vars) {
|
367
|
+
const startState = [
|
368
|
+
[]
|
369
|
+
];
|
370
|
+
return vars.reduce((chunks, variable) => {
|
371
|
+
const current = chunks[chunks.length - 1];
|
372
|
+
// check if variable with same name exists already
|
373
|
+
// if so create a new chunk of variables.
|
374
|
+
const variableNameAlreadyExists = current.some(v => v.name === variable.name);
|
375
|
+
|
376
|
+
if(variableNameAlreadyExists) {
|
377
|
+
// start new chunk with current variable
|
378
|
+
chunks.push([variable]);
|
379
|
+
} else {
|
380
|
+
// else add it to current chunk
|
381
|
+
current.push(variable);
|
382
|
+
}
|
383
|
+
return chunks;
|
384
|
+
}, startState);
|
385
|
+
}
|
386
|
+
|
387
|
+
sourceBlock(block, availableVars, dependencyTemplates, source, outputOptions, requestShortener) {
|
388
|
+
block.dependencies.forEach((dependency) => this.sourceDependency(
|
389
|
+
dependency, dependencyTemplates, source, outputOptions, requestShortener));
|
390
|
+
|
391
|
+
/**
|
392
|
+
* Get the variables of all blocks that we need to inject.
|
393
|
+
* These will contain the variable name and its expression.
|
394
|
+
* The name will be added as a paramter in a IIFE the expression as its value.
|
395
|
+
*/
|
396
|
+
const vars = block.variables.reduce((result, value) => {
|
397
|
+
const variable = this.sourceVariables(
|
398
|
+
value, availableVars, dependencyTemplates, outputOptions, requestShortener);
|
399
|
+
|
400
|
+
if(variable) {
|
401
|
+
result.push(variable);
|
402
|
+
}
|
403
|
+
|
404
|
+
return result;
|
405
|
+
}, []);
|
406
|
+
|
407
|
+
/**
|
408
|
+
* if we actually have variables
|
409
|
+
* this is important as how #splitVariablesInUniqueNamedChunks works
|
410
|
+
* it will always return an array in an array which would lead to a IIFE wrapper around
|
411
|
+
* a module if we do this with an empty vars array.
|
412
|
+
*/
|
413
|
+
if(vars.length > 0) {
|
414
|
+
/**
|
415
|
+
* Split all variables up into chunks of unique names.
|
416
|
+
* e.g. imagine you have the following variable names that need to be injected:
|
417
|
+
* [foo, bar, baz, foo, some, more]
|
418
|
+
* we can not inject "foo" twice, therefore we just make two IIFEs like so:
|
419
|
+
* (function(foo, bar, baz){
|
420
|
+
* (function(foo, some, more){
|
421
|
+
* ...
|
422
|
+
* }(...));
|
423
|
+
* }(...));
|
424
|
+
*
|
425
|
+
* "splitVariablesInUniqueNamedChunks" splits the variables shown above up to this:
|
426
|
+
* [[foo, bar, baz], [foo, some, more]]
|
427
|
+
*/
|
428
|
+
const injectionVariableChunks = this.splitVariablesInUniqueNamedChunks(vars);
|
429
|
+
|
430
|
+
// create all the beginnings of IIFEs
|
431
|
+
const functionWrapperStarts = injectionVariableChunks.map((variableChunk) => {
|
432
|
+
return this.variableInjectionFunctionWrapperStartCode(
|
433
|
+
variableChunk.map(variable => variable.name)
|
434
|
+
);
|
435
|
+
});
|
436
|
+
|
437
|
+
// and all the ends
|
438
|
+
const functionWrapperEnds = injectionVariableChunks.map((variableChunk) => {
|
439
|
+
return this.variableInjectionFunctionWrapperEndCode(
|
440
|
+
variableChunk.map(variable => variable.expression), block
|
441
|
+
);
|
442
|
+
});
|
443
|
+
|
444
|
+
// join them to one big string
|
445
|
+
const varStartCode = functionWrapperStarts.join("");
|
446
|
+
|
447
|
+
// reverse the ends first before joining them, as the last added must be the inner most
|
448
|
+
const varEndCode = functionWrapperEnds.reverse().join("");
|
449
|
+
|
450
|
+
// if we have anything, add it to the source
|
451
|
+
if(varStartCode && varEndCode) {
|
452
|
+
const start = block.range ? block.range[0] : -10;
|
453
|
+
const end = block.range ? block.range[1] : (this._source.size() + 1);
|
454
|
+
source.insert(start + 0.5, varStartCode);
|
455
|
+
source.insert(end + 0.5, "\n/* WEBPACK VAR INJECTION */" + varEndCode);
|
456
|
+
}
|
457
|
+
}
|
458
|
+
|
459
|
+
block.blocks.forEach((block) =>
|
460
|
+
this.sourceBlock(
|
461
|
+
block,
|
462
|
+
availableVars.concat(vars),
|
463
|
+
dependencyTemplates,
|
464
|
+
source,
|
465
|
+
outputOptions,
|
466
|
+
requestShortener
|
467
|
+
)
|
468
|
+
);
|
469
|
+
}
|
470
|
+
|
471
|
+
source(dependencyTemplates, outputOptions, requestShortener) {
|
472
|
+
const hashDigest = this.getHashDigest(dependencyTemplates);
|
473
|
+
if(this._cachedSource && this._cachedSource.hash === hashDigest) {
|
474
|
+
return this._cachedSource.source;
|
475
|
+
}
|
476
|
+
|
477
|
+
if(!this._source) {
|
478
|
+
return new RawSource("throw new Error('No source available');");
|
479
|
+
}
|
480
|
+
|
481
|
+
const source = new ReplaceSource(this._source);
|
482
|
+
this._cachedSource = {
|
483
|
+
source: source,
|
484
|
+
hash: hashDigest
|
485
|
+
};
|
486
|
+
|
487
|
+
this.sourceBlock(this, [], dependencyTemplates, source, outputOptions, requestShortener);
|
488
|
+
return new CachedSource(source);
|
489
|
+
}
|
490
|
+
|
491
|
+
originalSource() {
|
492
|
+
return this._source;
|
493
|
+
}
|
494
|
+
|
495
|
+
getHighestTimestamp(keys, timestampsByKey) {
|
496
|
+
let highestTimestamp = 0;
|
497
|
+
for(let i = 0; i < keys.length; i++) {
|
498
|
+
const key = keys[i];
|
499
|
+
const timestamp = timestampsByKey[key];
|
500
|
+
// if there is no timestamp yet, early return with Infinity
|
501
|
+
if(!timestamp) return Infinity;
|
502
|
+
highestTimestamp = Math.max(highestTimestamp, timestamp);
|
503
|
+
}
|
504
|
+
return highestTimestamp;
|
505
|
+
}
|
506
|
+
|
507
|
+
needRebuild(fileTimestamps, contextTimestamps) {
|
508
|
+
const highestFileDepTimestamp = this.getHighestTimestamp(
|
509
|
+
this.fileDependencies, fileTimestamps);
|
510
|
+
// if the hightest is Infinity, we need a rebuild
|
511
|
+
// exit early here.
|
512
|
+
if(highestFileDepTimestamp === Infinity) {
|
513
|
+
return true;
|
514
|
+
}
|
515
|
+
|
516
|
+
const highestContextDepTimestamp = this.getHighestTimestamp(
|
517
|
+
this.contextDependencies, contextTimestamps);
|
518
|
+
|
519
|
+
// Again if the hightest is Infinity, we need a rebuild
|
520
|
+
// exit early here.
|
521
|
+
if(highestContextDepTimestamp === Infinity) {
|
522
|
+
return true;
|
523
|
+
}
|
524
|
+
|
525
|
+
// else take the highest of file and context timestamps and compare
|
526
|
+
// to last build timestamp
|
527
|
+
return Math.max(highestContextDepTimestamp, highestFileDepTimestamp) >= this.buildTimestamp;
|
528
|
+
}
|
529
|
+
|
530
|
+
size() {
|
531
|
+
return this._source ? this._source.size() : -1;
|
532
|
+
}
|
533
|
+
|
534
|
+
updateHashWithSource(hash) {
|
535
|
+
if(!this._source) {
|
536
|
+
hash.update("null");
|
537
|
+
return;
|
538
|
+
}
|
539
|
+
hash.update("source");
|
540
|
+
this._source.updateHash(hash);
|
541
|
+
}
|
542
|
+
|
543
|
+
updateHashWithMeta(hash) {
|
544
|
+
hash.update("meta");
|
545
|
+
hash.update(JSON.stringify(this.meta));
|
546
|
+
}
|
547
|
+
|
548
|
+
updateHash(hash) {
|
549
|
+
this.updateHashWithSource(hash);
|
550
|
+
this.updateHashWithMeta(hash);
|
551
|
+
super.updateHash(hash);
|
552
|
+
}
|
553
|
+
|
554
|
+
}
|
555
|
+
|
556
|
+
module.exports = NormalModule;
|