webpack 4.16.1 → 4.16.5
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/hot/log.js +2 -0
- package/lib/Chunk.js +32 -10
- package/lib/ChunkGroup.js +3 -3
- package/lib/Compilation.js +58 -13
- package/lib/ContextExclusionPlugin.js +11 -0
- package/lib/ContextModule.js +116 -30
- package/lib/ContextModuleFactory.js +6 -0
- package/lib/DelegatedModule.js +5 -0
- package/lib/DependenciesBlock.js +1 -1
- package/lib/DllModule.js +6 -0
- package/lib/DllReferencePlugin.js +51 -3
- package/lib/ExternalModule.js +6 -0
- package/lib/Generator.js +11 -3
- package/lib/HotModuleReplacementPlugin.js +1 -5
- package/lib/Module.js +52 -12
- package/lib/MultiModule.js +6 -0
- package/lib/NodeStuffPlugin.js +18 -0
- package/lib/NormalModule.js +6 -0
- package/lib/Parser.js +12 -3
- package/lib/RuntimeTemplate.js +12 -0
- package/lib/Stats.js +19 -2
- package/lib/Template.js +44 -43
- package/lib/WatchIgnorePlugin.js +18 -18
- package/lib/debug/ProfilingPlugin.js +1 -1
- package/lib/dependencies/CommonJsRequireDependencyParserPlugin.js +6 -0
- package/lib/dependencies/ContextDependencyHelpers.js +78 -43
- package/lib/dependencies/ContextDependencyTemplateAsId.js +1 -0
- package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +1 -0
- package/lib/node/NodeTargetPlugin.js +1 -0
- package/lib/optimize/ConcatenatedModule.js +5 -0
- package/lib/util/SortableSet.js +1 -0
- package/lib/util/StackedSetMap.js +12 -3
- package/lib/wasm/WebAssemblyGenerator.js +22 -5
- package/lib/wasm/WebAssemblyJavascriptGenerator.js +16 -2
- package/lib/webpack.js +1 -0
- package/package.json +8 -16
package/lib/Module.js
CHANGED
@@ -14,6 +14,7 @@ const Template = require("./Template");
|
|
14
14
|
/** @typedef {import("./Chunk")} Chunk */
|
15
15
|
/** @typedef {import("./RequestShortener")} RequestShortener */
|
16
16
|
/** @typedef {import("./WebpackError")} WebpackError */
|
17
|
+
/** @typedef {import("./util/createHash").Hash} Hash */
|
17
18
|
|
18
19
|
const EMPTY_RESOLVE_OPTIONS = {};
|
19
20
|
|
@@ -298,6 +299,10 @@ class Module extends DependenciesBlock {
|
|
298
299
|
return true;
|
299
300
|
}
|
300
301
|
|
302
|
+
/**
|
303
|
+
* @param {Hash} hash the hash used to track dependencies
|
304
|
+
* @returns {void}
|
305
|
+
*/
|
301
306
|
updateHash(hash) {
|
302
307
|
hash.update(`${this.id}`);
|
303
308
|
hash.update(JSON.stringify(this.usedExports));
|
@@ -339,17 +344,35 @@ class Module extends DependenciesBlock {
|
|
339
344
|
// TODO remove in webpack 5
|
340
345
|
Object.defineProperty(Module.prototype, "forEachChunk", {
|
341
346
|
configurable: false,
|
342
|
-
value: util.deprecate(
|
343
|
-
|
344
|
-
|
347
|
+
value: util.deprecate(
|
348
|
+
/**
|
349
|
+
* @deprecated
|
350
|
+
* @param {function(any, any, Set<any>): void} fn callback function
|
351
|
+
* @returns {void}
|
352
|
+
* @this {Module}
|
353
|
+
*/
|
354
|
+
function(fn) {
|
355
|
+
this._chunks.forEach(fn);
|
356
|
+
},
|
357
|
+
"Module.forEachChunk: Use for(const chunk of module.chunksIterable) instead"
|
358
|
+
)
|
345
359
|
});
|
346
360
|
|
347
361
|
// TODO remove in webpack 5
|
348
362
|
Object.defineProperty(Module.prototype, "mapChunks", {
|
349
363
|
configurable: false,
|
350
|
-
value: util.deprecate(
|
351
|
-
|
352
|
-
|
364
|
+
value: util.deprecate(
|
365
|
+
/**
|
366
|
+
* @deprecated
|
367
|
+
* @param {function(any, any): void} fn Mapper function
|
368
|
+
* @returns {Array<TODO>} Array of chunks mapped
|
369
|
+
* @this {Module}
|
370
|
+
*/
|
371
|
+
function(fn) {
|
372
|
+
return Array.from(this._chunks, fn);
|
373
|
+
},
|
374
|
+
"Module.mapChunks: Use Array.from(module.chunksIterable, fn) instead"
|
375
|
+
)
|
353
376
|
});
|
354
377
|
|
355
378
|
// TODO remove in webpack 5
|
@@ -366,12 +389,29 @@ Object.defineProperty(Module.prototype, "entry", {
|
|
366
389
|
// TODO remove in webpack 5
|
367
390
|
Object.defineProperty(Module.prototype, "meta", {
|
368
391
|
configurable: false,
|
369
|
-
get: util.deprecate(
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
392
|
+
get: util.deprecate(
|
393
|
+
/**
|
394
|
+
* @deprecated
|
395
|
+
* @returns {void}
|
396
|
+
* @this {Module}
|
397
|
+
*/
|
398
|
+
function() {
|
399
|
+
return this.buildMeta;
|
400
|
+
},
|
401
|
+
"Module.meta was renamed to Module.buildMeta"
|
402
|
+
),
|
403
|
+
set: util.deprecate(
|
404
|
+
/**
|
405
|
+
* @deprecated
|
406
|
+
* @param {TODO} value Value
|
407
|
+
* @returns {void}
|
408
|
+
* @this {Module}
|
409
|
+
*/
|
410
|
+
function(value) {
|
411
|
+
this.buildMeta = value;
|
412
|
+
},
|
413
|
+
"Module.meta was renamed to Module.buildMeta"
|
414
|
+
)
|
375
415
|
});
|
376
416
|
|
377
417
|
/** @type {function(): string} */
|
package/lib/MultiModule.js
CHANGED
@@ -8,6 +8,8 @@ const Module = require("./Module");
|
|
8
8
|
const Template = require("./Template");
|
9
9
|
const { RawSource } = require("webpack-sources");
|
10
10
|
|
11
|
+
/** @typedef {import("./util/createHash").Hash} Hash */
|
12
|
+
|
11
13
|
class MultiModule extends Module {
|
12
14
|
constructor(context, dependencies, name) {
|
13
15
|
super("javascript/dynamic", context);
|
@@ -45,6 +47,10 @@ class MultiModule extends Module {
|
|
45
47
|
return 16 + this.dependencies.length * 12;
|
46
48
|
}
|
47
49
|
|
50
|
+
/**
|
51
|
+
* @param {Hash} hash the hash used to track dependencies
|
52
|
+
* @returns {void}
|
53
|
+
*/
|
48
54
|
updateHash(hash) {
|
49
55
|
hash.update("multi module");
|
50
56
|
hash.update(this.name || "");
|
package/lib/NodeStuffPlugin.js
CHANGED
@@ -108,6 +108,24 @@ class NodeStuffPlugin {
|
|
108
108
|
"require.extensions is not supported by webpack. Use a loader instead."
|
109
109
|
)
|
110
110
|
);
|
111
|
+
parser.hooks.expression
|
112
|
+
.for("require.main.require")
|
113
|
+
.tap(
|
114
|
+
"NodeStuffPlugin",
|
115
|
+
ParserHelpers.expressionIsUnsupported(
|
116
|
+
parser,
|
117
|
+
"require.main.require is not supported by webpack."
|
118
|
+
)
|
119
|
+
);
|
120
|
+
parser.hooks.expression
|
121
|
+
.for("module.parent.require")
|
122
|
+
.tap(
|
123
|
+
"NodeStuffPlugin",
|
124
|
+
ParserHelpers.expressionIsUnsupported(
|
125
|
+
parser,
|
126
|
+
"module.parent.require is not supported by webpack."
|
127
|
+
)
|
128
|
+
);
|
111
129
|
parser.hooks.expression
|
112
130
|
.for("module.loaded")
|
113
131
|
.tap("NodeStuffPlugin", expr => {
|
package/lib/NormalModule.js
CHANGED
@@ -24,6 +24,8 @@ const ModuleWarning = require("./ModuleWarning");
|
|
24
24
|
const createHash = require("./util/createHash");
|
25
25
|
const contextify = require("./util/identifier").contextify;
|
26
26
|
|
27
|
+
/** @typedef {import("./util/createHash").Hash} Hash */
|
28
|
+
|
27
29
|
const asString = buf => {
|
28
30
|
if (Buffer.isBuffer(buf)) {
|
29
31
|
return buf.toString("utf-8");
|
@@ -527,6 +529,10 @@ class NormalModule extends Module {
|
|
527
529
|
return this._source ? this._source.size() : -1;
|
528
530
|
}
|
529
531
|
|
532
|
+
/**
|
533
|
+
* @param {Hash} hash the hash used to track dependencies
|
534
|
+
* @returns {void}
|
535
|
+
*/
|
530
536
|
updateHash(hash) {
|
531
537
|
hash.update(this._buildHash);
|
532
538
|
super.updateHash(hash);
|
package/lib/Parser.js
CHANGED
@@ -2185,9 +2185,18 @@ class Parser extends Tapable {
|
|
2185
2185
|
// TODO remove in webpack 5
|
2186
2186
|
Object.defineProperty(Parser.prototype, "getCommentOptions", {
|
2187
2187
|
configurable: false,
|
2188
|
-
value: util.deprecate(
|
2189
|
-
|
2190
|
-
|
2188
|
+
value: util.deprecate(
|
2189
|
+
/**
|
2190
|
+
* @deprecated
|
2191
|
+
* @param {TODO} range Range
|
2192
|
+
* @returns {void}
|
2193
|
+
* @this {Parser}
|
2194
|
+
*/
|
2195
|
+
function(range) {
|
2196
|
+
return this.parseCommentOptions(range).options;
|
2197
|
+
},
|
2198
|
+
"Parser.getCommentOptions: Use Parser.parseCommentOptions(range) instead"
|
2199
|
+
)
|
2191
2200
|
});
|
2192
2201
|
|
2193
2202
|
module.exports = Parser;
|
package/lib/RuntimeTemplate.js
CHANGED
@@ -6,6 +6,8 @@
|
|
6
6
|
|
7
7
|
const Template = require("./Template");
|
8
8
|
|
9
|
+
/** @typedef {import("./Module")} Module */
|
10
|
+
|
9
11
|
module.exports = class RuntimeTemplate {
|
10
12
|
constructor(outputOptions, requestShortener) {
|
11
13
|
this.outputOptions = outputOptions || {};
|
@@ -188,6 +190,16 @@ module.exports = class RuntimeTemplate {
|
|
188
190
|
return `${promise || "Promise.resolve()"}.then(${getModuleFunction})`;
|
189
191
|
}
|
190
192
|
|
193
|
+
/**
|
194
|
+
*
|
195
|
+
* @param {Object} options options object
|
196
|
+
* @param {boolean=} options.update whether a new variable should be created or the existing one updated
|
197
|
+
* @param {Module} options.module the module
|
198
|
+
* @param {string} options.request the request that should be printed as comment
|
199
|
+
* @param {string} options.importVar name of the import variable
|
200
|
+
* @param {Module} options.originModule module in which the statement is emitted
|
201
|
+
* @returns {string} the import statement
|
202
|
+
*/
|
191
203
|
importStatement({ update, module, request, importVar, originModule }) {
|
192
204
|
if (!module) {
|
193
205
|
return this.missingModuleStatement({
|
package/lib/Stats.js
CHANGED
@@ -8,6 +8,7 @@ const RequestShortener = require("./RequestShortener");
|
|
8
8
|
const SizeFormatHelpers = require("./SizeFormatHelpers");
|
9
9
|
const formatLocation = require("./formatLocation");
|
10
10
|
const identifierUtils = require("./util/identifier");
|
11
|
+
const compareLocations = require("./compareLocations");
|
11
12
|
|
12
13
|
const optionsOrFallback = (...args) => {
|
13
14
|
let optionValues = [];
|
@@ -523,6 +524,23 @@ class Stats {
|
|
523
524
|
}
|
524
525
|
if (showReasons) {
|
525
526
|
obj.reasons = module.reasons
|
527
|
+
.sort((a, b) => {
|
528
|
+
if (a.module && !b.module) return -1;
|
529
|
+
if (!a.module && b.module) return 1;
|
530
|
+
if (a.module && b.module) {
|
531
|
+
const cmp = compareId(a.module.id, b.module.id);
|
532
|
+
if (cmp) return cmp;
|
533
|
+
}
|
534
|
+
if (a.dependency && !b.dependency) return -1;
|
535
|
+
if (!a.dependency && b.dependency) return 1;
|
536
|
+
if (a.dependency && b.dependency) {
|
537
|
+
const cmp = compareLocations(a.dependency.loc, b.dependency.loc);
|
538
|
+
if (cmp) return cmp;
|
539
|
+
if (a.dependency.type < b.dependency.type) return -1;
|
540
|
+
if (a.dependency.type > b.dependency.type) return 1;
|
541
|
+
}
|
542
|
+
return 0;
|
543
|
+
})
|
526
544
|
.map(reason => {
|
527
545
|
const obj = {
|
528
546
|
moduleId: reason.module ? reason.module.id : null,
|
@@ -548,8 +566,7 @@ class Stats {
|
|
548
566
|
}
|
549
567
|
}
|
550
568
|
return obj;
|
551
|
-
})
|
552
|
-
.sort(compareId);
|
569
|
+
});
|
553
570
|
}
|
554
571
|
if (showUsedExports) {
|
555
572
|
if (module.used === true) {
|
package/lib/Template.js
CHANGED
@@ -27,7 +27,7 @@ const MATCH_PADDED_HYPHENS_REPLACE_REGEX = /^-|-$/g;
|
|
27
27
|
/**
|
28
28
|
* @typedef {Object} HasId
|
29
29
|
* @property {number | string} id
|
30
|
-
|
30
|
+
*/
|
31
31
|
|
32
32
|
/**
|
33
33
|
* @typedef {function(Module, number): boolean} ModuleFilterPredicate
|
@@ -39,8 +39,8 @@ const MATCH_PADDED_HYPHENS_REPLACE_REGEX = /^-|-$/g;
|
|
39
39
|
* @returns {-1|0|1} the sort value
|
40
40
|
*/
|
41
41
|
const stringifyIdSortPredicate = (a, b) => {
|
42
|
-
|
43
|
-
|
42
|
+
const aId = a.id + "";
|
43
|
+
const bId = b.id + "";
|
44
44
|
if (aId < bId) return -1;
|
45
45
|
if (aId > bId) return 1;
|
46
46
|
return 0;
|
@@ -59,6 +59,7 @@ class Template {
|
|
59
59
|
.replace(INDENT_MULTILINE_REGEX, "")
|
60
60
|
.replace(LINE_SEPARATOR_REGEX, "\n");
|
61
61
|
}
|
62
|
+
|
62
63
|
/**
|
63
64
|
* @param {string} str the string converted to identifier
|
64
65
|
* @returns {string} created identifier
|
@@ -128,31 +129,28 @@ class Template {
|
|
128
129
|
|
129
130
|
/**
|
130
131
|
*
|
131
|
-
* @param {string | string[]}
|
132
|
+
* @param {string | string[]} s string to convert to identity
|
132
133
|
* @returns {string} converted identity
|
133
134
|
*/
|
134
|
-
static indent(
|
135
|
-
if (Array.isArray(
|
136
|
-
return
|
135
|
+
static indent(s) {
|
136
|
+
if (Array.isArray(s)) {
|
137
|
+
return s.map(Template.indent).join("\n");
|
137
138
|
} else {
|
138
|
-
str =
|
139
|
+
const str = s.trimRight();
|
139
140
|
if (!str) return "";
|
140
|
-
|
141
|
+
const ind = str[0] === "\n" ? "" : "\t";
|
141
142
|
return ind + str.replace(/\n([^\n])/g, "\n\t$1");
|
142
143
|
}
|
143
144
|
}
|
144
145
|
|
145
146
|
/**
|
146
147
|
*
|
147
|
-
* @param {string|string[]}
|
148
|
+
* @param {string|string[]} s string to create prefix for
|
148
149
|
* @param {string} prefix prefix to compose
|
149
150
|
* @returns {string} returns new prefix string
|
150
151
|
*/
|
151
|
-
static prefix(
|
152
|
-
|
153
|
-
str = str.join("\n");
|
154
|
-
}
|
155
|
-
str = str.trim();
|
152
|
+
static prefix(s, prefix) {
|
153
|
+
const str = Template.asString(s).trim();
|
156
154
|
if (!str) return "";
|
157
155
|
const ind = str[0] === "\n" ? "" : prefix;
|
158
156
|
return ind + str.replace(/\n([^\n])/g, "\n" + prefix + "$1");
|
@@ -181,8 +179,8 @@ class Template {
|
|
181
179
|
* or false if not every module has a number based id
|
182
180
|
*/
|
183
181
|
static getModulesArrayBounds(modules) {
|
184
|
-
|
185
|
-
|
182
|
+
let maxId = -Infinity;
|
183
|
+
let minId = Infinity;
|
186
184
|
for (const module of modules) {
|
187
185
|
if (typeof module.id !== "number") return false;
|
188
186
|
if (maxId < module.id) maxId = /** @type {number} */ (module.id);
|
@@ -192,15 +190,11 @@ class Template {
|
|
192
190
|
// add minId x ',' instead of 'Array(minId).concat(…)'
|
193
191
|
minId = 0;
|
194
192
|
}
|
195
|
-
|
196
|
-
.map(module =>
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
.reduce((a, b) => {
|
201
|
-
return a + b;
|
202
|
-
}, -1);
|
203
|
-
var arrayOverhead = minId === 0 ? maxId : 16 + ("" + minId).length + maxId;
|
193
|
+
const objectOverhead = modules
|
194
|
+
.map(module => (module.id + "").length + 2)
|
195
|
+
.reduce((a, b) => a + b, -1);
|
196
|
+
const arrayOverhead =
|
197
|
+
minId === 0 ? maxId : 16 + ("" + minId).length + maxId;
|
204
198
|
return arrayOverhead < objectOverhead ? [minId, maxId] : false;
|
205
199
|
}
|
206
200
|
|
@@ -217,13 +211,13 @@ class Template {
|
|
217
211
|
filterFn,
|
218
212
|
moduleTemplate,
|
219
213
|
dependencyTemplates,
|
220
|
-
prefix
|
214
|
+
prefix = ""
|
221
215
|
) {
|
222
|
-
|
223
|
-
var source = new ConcatSource();
|
216
|
+
const source = new ConcatSource();
|
224
217
|
const modules = chunk.getModules().filter(filterFn);
|
218
|
+
let removedModules;
|
225
219
|
if (chunk instanceof HotUpdateChunk) {
|
226
|
-
|
220
|
+
removedModules = chunk.removedModules;
|
227
221
|
}
|
228
222
|
if (
|
229
223
|
modules.length === 0 &&
|
@@ -233,7 +227,7 @@ class Template {
|
|
233
227
|
return source;
|
234
228
|
}
|
235
229
|
/** @type {{id: string|number, source: Source|string}[]} */
|
236
|
-
|
230
|
+
const allModules = modules.map(module => {
|
237
231
|
return {
|
238
232
|
id: module.id,
|
239
233
|
source: moduleTemplate.render(module, dependencyTemplates, {
|
@@ -249,38 +243,45 @@ class Template {
|
|
249
243
|
});
|
250
244
|
}
|
251
245
|
}
|
252
|
-
|
253
|
-
|
246
|
+
const bounds = Template.getModulesArrayBounds(allModules);
|
254
247
|
if (bounds) {
|
255
248
|
// Render a spare array
|
256
|
-
|
257
|
-
|
258
|
-
if (minId !== 0)
|
249
|
+
const minId = bounds[0];
|
250
|
+
const maxId = bounds[1];
|
251
|
+
if (minId !== 0) {
|
252
|
+
source.add(`Array(${minId}).concat(`);
|
253
|
+
}
|
259
254
|
source.add("[\n");
|
260
255
|
const modules = new Map();
|
261
256
|
for (const module of allModules) {
|
262
257
|
modules.set(module.id, module);
|
263
258
|
}
|
264
|
-
for (
|
265
|
-
|
266
|
-
if (idx !== minId)
|
267
|
-
|
259
|
+
for (let idx = minId; idx <= maxId; idx++) {
|
260
|
+
const module = modules.get(idx);
|
261
|
+
if (idx !== minId) {
|
262
|
+
source.add(",\n");
|
263
|
+
}
|
264
|
+
source.add(`/* ${idx} */`);
|
268
265
|
if (module) {
|
269
266
|
source.add("\n");
|
270
267
|
source.add(module.source);
|
271
268
|
}
|
272
269
|
}
|
273
270
|
source.add("\n" + prefix + "]");
|
274
|
-
if (minId !== 0)
|
271
|
+
if (minId !== 0) {
|
272
|
+
source.add(")");
|
273
|
+
}
|
275
274
|
} else {
|
276
275
|
// Render an object
|
277
276
|
source.add("{\n");
|
278
277
|
allModules.sort(stringifyIdSortPredicate).forEach((module, idx) => {
|
279
|
-
if (idx !== 0)
|
278
|
+
if (idx !== 0) {
|
279
|
+
source.add(",\n");
|
280
|
+
}
|
280
281
|
source.add(`\n/***/ ${JSON.stringify(module.id)}:\n`);
|
281
282
|
source.add(module.source);
|
282
283
|
});
|
283
|
-
source.add(
|
284
|
+
source.add(`\n\n${prefix}}`);
|
284
285
|
}
|
285
286
|
return source;
|
286
287
|
}
|
package/lib/WatchIgnorePlugin.js
CHANGED
@@ -7,24 +7,6 @@
|
|
7
7
|
const validateOptions = require("schema-utils");
|
8
8
|
const schema = require("../schemas/plugins/WatchIgnorePlugin.json");
|
9
9
|
|
10
|
-
class WatchIgnorePlugin {
|
11
|
-
constructor(paths) {
|
12
|
-
validateOptions(schema, paths, "Watch Ignore Plugin");
|
13
|
-
this.paths = paths;
|
14
|
-
}
|
15
|
-
|
16
|
-
apply(compiler) {
|
17
|
-
compiler.hooks.afterEnvironment.tap("WatchIgnorePlugin", () => {
|
18
|
-
compiler.watchFileSystem = new IgnoringWatchFileSystem(
|
19
|
-
compiler.watchFileSystem,
|
20
|
-
this.paths
|
21
|
-
);
|
22
|
-
});
|
23
|
-
}
|
24
|
-
}
|
25
|
-
|
26
|
-
module.exports = WatchIgnorePlugin;
|
27
|
-
|
28
10
|
class IgnoringWatchFileSystem {
|
29
11
|
constructor(wfs, paths) {
|
30
12
|
this.wfs = wfs;
|
@@ -98,3 +80,21 @@ class IgnoringWatchFileSystem {
|
|
98
80
|
};
|
99
81
|
}
|
100
82
|
}
|
83
|
+
|
84
|
+
class WatchIgnorePlugin {
|
85
|
+
constructor(paths) {
|
86
|
+
validateOptions(schema, paths, "Watch Ignore Plugin");
|
87
|
+
this.paths = paths;
|
88
|
+
}
|
89
|
+
|
90
|
+
apply(compiler) {
|
91
|
+
compiler.hooks.afterEnvironment.tap("WatchIgnorePlugin", () => {
|
92
|
+
compiler.watchFileSystem = new IgnoringWatchFileSystem(
|
93
|
+
compiler.watchFileSystem,
|
94
|
+
this.paths
|
95
|
+
);
|
96
|
+
});
|
97
|
+
}
|
98
|
+
}
|
99
|
+
|
100
|
+
module.exports = WatchIgnorePlugin;
|
@@ -5,7 +5,7 @@ const schema = require("../../schemas/plugins/debug/ProfilingPlugin.json");
|
|
5
5
|
let inspector = undefined;
|
6
6
|
|
7
7
|
try {
|
8
|
-
// eslint-disable-next-line node/no-
|
8
|
+
// eslint-disable-next-line node/no-unsupported-features/node-builtins
|
9
9
|
inspector = require("inspector");
|
10
10
|
} catch (e) {
|
11
11
|
console.log("Unable to CPU profile in < node 8.0");
|
@@ -125,6 +125,12 @@ class CommonJsRequireDependencyParserPlugin {
|
|
125
125
|
parser.hooks.new
|
126
126
|
.for("require")
|
127
127
|
.tap("CommonJsRequireDependencyParserPlugin", createHandler(true));
|
128
|
+
parser.hooks.call
|
129
|
+
.for("module.require")
|
130
|
+
.tap("CommonJsRequireDependencyParserPlugin", createHandler(false));
|
131
|
+
parser.hooks.new
|
132
|
+
.for("module.require")
|
133
|
+
.tap("CommonJsRequireDependencyParserPlugin", createHandler(true));
|
128
134
|
}
|
129
135
|
}
|
130
136
|
module.exports = CommonJsRequireDependencyParserPlugin;
|
@@ -15,6 +15,32 @@ const quotemeta = str => {
|
|
15
15
|
return str.replace(/[-[\]\\/{}()*+?.^$|]/g, "\\$&");
|
16
16
|
};
|
17
17
|
|
18
|
+
const splitContextFromPrefix = prefix => {
|
19
|
+
const idx = prefix.lastIndexOf("/");
|
20
|
+
let context = ".";
|
21
|
+
if (idx >= 0) {
|
22
|
+
context = prefix.substr(0, idx);
|
23
|
+
prefix = `.${prefix.substr(idx)}`;
|
24
|
+
}
|
25
|
+
return {
|
26
|
+
context,
|
27
|
+
prefix
|
28
|
+
};
|
29
|
+
};
|
30
|
+
|
31
|
+
const splitQueryFromPostfix = postfix => {
|
32
|
+
const idx = postfix.indexOf("?");
|
33
|
+
let query = "";
|
34
|
+
if (idx >= 0) {
|
35
|
+
query = postfix.substr(idx);
|
36
|
+
postfix = postfix.substr(0, idx);
|
37
|
+
}
|
38
|
+
return {
|
39
|
+
postfix,
|
40
|
+
query
|
41
|
+
};
|
42
|
+
};
|
43
|
+
|
18
44
|
ContextDependencyHelpers.create = (
|
19
45
|
Dep,
|
20
46
|
range,
|
@@ -23,38 +49,30 @@ ContextDependencyHelpers.create = (
|
|
23
49
|
options,
|
24
50
|
contextOptions
|
25
51
|
) => {
|
26
|
-
let dep;
|
27
|
-
let prefix;
|
28
|
-
let postfix;
|
29
|
-
let prefixRange;
|
30
|
-
let valueRange;
|
31
|
-
let idx;
|
32
|
-
let context;
|
33
|
-
let regExp;
|
34
52
|
if (param.isTemplateString()) {
|
35
|
-
|
36
|
-
|
53
|
+
let prefixRaw = param.quasis[0].string;
|
54
|
+
let postfixRaw =
|
37
55
|
param.quasis.length > 1
|
38
56
|
? param.quasis[param.quasis.length - 1].string
|
39
57
|
: "";
|
40
|
-
prefixRange = [param.quasis[0].range[0], param.quasis[0].range[1]];
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
}
|
58
|
+
const prefixRange = [param.quasis[0].range[0], param.quasis[0].range[1]];
|
59
|
+
const postfixRange =
|
60
|
+
param.quasis.length > 1
|
61
|
+
? param.quasis[param.quasis.length - 1].range
|
62
|
+
: "";
|
63
|
+
const valueRange = param.range;
|
64
|
+
const { context, prefix } = splitContextFromPrefix(prefixRaw);
|
65
|
+
const { postfix, query } = splitQueryFromPostfix(postfixRaw);
|
48
66
|
// If there are more than two quasis, maybe the generated RegExp can be more precise?
|
49
|
-
regExp = new RegExp(
|
67
|
+
const regExp = new RegExp(
|
50
68
|
`^${quotemeta(prefix)}${options.wrappedContextRegExp.source}${quotemeta(
|
51
69
|
postfix
|
52
70
|
)}$`
|
53
71
|
);
|
54
|
-
dep = new Dep(
|
72
|
+
const dep = new Dep(
|
55
73
|
Object.assign(
|
56
74
|
{
|
57
|
-
request: context,
|
75
|
+
request: context + query,
|
58
76
|
recursive: options.wrappedContextRecursive,
|
59
77
|
regExp,
|
60
78
|
mode: "sync"
|
@@ -65,12 +83,20 @@ ContextDependencyHelpers.create = (
|
|
65
83
|
valueRange
|
66
84
|
);
|
67
85
|
dep.loc = expr.loc;
|
68
|
-
|
69
|
-
|
86
|
+
const replaces = [];
|
87
|
+
if (prefixRange && prefix !== prefixRaw) {
|
88
|
+
replaces.push({
|
70
89
|
range: prefixRange,
|
71
90
|
value: prefix
|
72
|
-
}
|
73
|
-
|
91
|
+
});
|
92
|
+
}
|
93
|
+
if (postfixRange && postfix !== postfixRaw) {
|
94
|
+
replaces.push({
|
95
|
+
range: postfixRange,
|
96
|
+
value: postfix
|
97
|
+
});
|
98
|
+
}
|
99
|
+
dep.replaces = replaces;
|
74
100
|
dep.critical =
|
75
101
|
options.wrappedContextCritical &&
|
76
102
|
"a part of the request of a dependency is an expression";
|
@@ -80,30 +106,26 @@ ContextDependencyHelpers.create = (
|
|
80
106
|
((param.prefix && param.prefix.isString()) ||
|
81
107
|
(param.postfix && param.postfix.isString()))
|
82
108
|
) {
|
83
|
-
|
84
|
-
|
109
|
+
let prefixRaw =
|
110
|
+
param.prefix && param.prefix.isString() ? param.prefix.string : "";
|
111
|
+
let postfixRaw =
|
85
112
|
param.postfix && param.postfix.isString() ? param.postfix.string : "";
|
86
|
-
prefixRange =
|
113
|
+
const prefixRange =
|
87
114
|
param.prefix && param.prefix.isString() ? param.prefix.range : null;
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
if (idx >= 0) {
|
95
|
-
context = prefix.substr(0, idx);
|
96
|
-
prefix = `.${prefix.substr(idx)}`;
|
97
|
-
}
|
98
|
-
regExp = new RegExp(
|
115
|
+
const postfixRange =
|
116
|
+
param.postfix && param.postfix.isString() ? param.postfix.range : null;
|
117
|
+
const valueRange = param.range;
|
118
|
+
const { context, prefix } = splitContextFromPrefix(prefixRaw);
|
119
|
+
const { postfix, query } = splitQueryFromPostfix(postfixRaw);
|
120
|
+
const regExp = new RegExp(
|
99
121
|
`^${quotemeta(prefix)}${options.wrappedContextRegExp.source}${quotemeta(
|
100
122
|
postfix
|
101
123
|
)}$`
|
102
124
|
);
|
103
|
-
dep = new Dep(
|
125
|
+
const dep = new Dep(
|
104
126
|
Object.assign(
|
105
127
|
{
|
106
|
-
request: context,
|
128
|
+
request: context + query,
|
107
129
|
recursive: options.wrappedContextRecursive,
|
108
130
|
regExp,
|
109
131
|
mode: "sync"
|
@@ -114,13 +136,26 @@ ContextDependencyHelpers.create = (
|
|
114
136
|
valueRange
|
115
137
|
);
|
116
138
|
dep.loc = expr.loc;
|
117
|
-
|
139
|
+
const replaces = [];
|
140
|
+
if (prefixRange && prefix !== prefixRaw) {
|
141
|
+
replaces.push({
|
142
|
+
range: prefixRange,
|
143
|
+
value: JSON.stringify(prefix)
|
144
|
+
});
|
145
|
+
}
|
146
|
+
if (postfixRange && postfix !== postfixRaw) {
|
147
|
+
replaces.push({
|
148
|
+
range: postfixRange,
|
149
|
+
value: JSON.stringify(postfix)
|
150
|
+
});
|
151
|
+
}
|
152
|
+
dep.replaces = replaces;
|
118
153
|
dep.critical =
|
119
154
|
options.wrappedContextCritical &&
|
120
155
|
"a part of the request of a dependency is an expression";
|
121
156
|
return dep;
|
122
157
|
} else {
|
123
|
-
dep = new Dep(
|
158
|
+
const dep = new Dep(
|
124
159
|
Object.assign(
|
125
160
|
{
|
126
161
|
request: options.exprContextRequest,
|