webpack 4.10.1 → 4.12.0
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/lib/AmdMainTemplatePlugin.js +3 -1
- package/lib/AsyncDependencyToInitialChunkError.js +4 -4
- package/lib/BannerPlugin.js +3 -1
- package/lib/BasicEvaluatedExpression.js +14 -11
- package/lib/CachePlugin.js +12 -5
- package/lib/CaseSensitiveModulesWarning.js +41 -45
- package/lib/Chunk.js +56 -19
- package/lib/ChunkGroup.js +14 -6
- package/lib/CommentCompilationWarning.js +22 -0
- package/lib/Compilation.js +72 -29
- package/lib/Compiler.js +22 -10
- package/lib/ConstPlugin.js +25 -9
- package/lib/ContextModule.js +88 -36
- package/lib/ContextModuleFactory.js +18 -7
- package/lib/ContextReplacementPlugin.js +14 -7
- package/lib/DefinePlugin.js +15 -6
- package/lib/DependenciesBlock.js +3 -1
- package/lib/DependenciesBlockVariable.js +2 -1
- package/lib/DllPlugin.js +4 -2
- package/lib/DynamicEntryPlugin.js +4 -2
- package/lib/EntryModuleNotFoundError.js +21 -22
- package/lib/ErrorHelpers.js +5 -2
- package/lib/EvalSourceMapDevToolPlugin.js +2 -1
- package/lib/FlagDependencyUsagePlugin.js +11 -5
- package/lib/FunctionModuleTemplatePlugin.js +8 -6
- package/lib/HarmonyLinkingError.js +1 -2
- package/lib/HotModuleReplacement.runtime.js +13 -4
- package/lib/HotModuleReplacementPlugin.js +13 -6
- package/lib/JavascriptGenerator.js +2 -1
- package/lib/JavascriptModulesPlugin.js +4 -9
- package/lib/JsonParser.js +2 -1
- package/lib/LibraryTemplatePlugin.js +2 -1
- package/lib/LoaderOptionsPlugin.js +2 -1
- package/lib/MainTemplate.js +2 -1
- package/lib/Module.js +13 -5
- package/lib/ModuleBuildError.js +22 -12
- package/lib/ModuleDependencyError.js +4 -4
- package/lib/ModuleDependencyWarning.js +4 -4
- package/lib/ModuleError.js +13 -5
- package/lib/ModuleFilenameHelpers.js +20 -8
- package/lib/ModuleNotFoundError.js +23 -26
- package/lib/ModuleParseError.js +27 -14
- package/lib/ModuleWarning.js +13 -7
- package/lib/MultiCompiler.js +19 -7
- package/lib/MultiModule.js +5 -2
- package/lib/NodeStuffPlugin.js +2 -1
- package/lib/NormalModule.js +80 -16
- package/lib/NormalModuleFactory.js +67 -24
- package/lib/OptionsDefaulter.js +7 -3
- package/lib/Parser.js +182 -75
- package/lib/ParserHelpers.js +6 -3
- package/lib/ProgressPlugin.js +17 -2
- package/lib/RawModule.js +4 -2
- package/lib/RecordIdsPlugin.js +77 -9
- package/lib/RemovedPluginError.js +1 -3
- package/lib/RequestShortener.js +15 -6
- package/lib/RuleSet.js +51 -18
- package/lib/RuntimeTemplate.js +21 -10
- package/lib/SourceMapDevToolPlugin.js +4 -3
- package/lib/Stats.js +74 -31
- package/lib/Template.js +7 -4
- package/lib/TemplatedPathPlugin.js +6 -3
- package/lib/UmdMainTemplatePlugin.js +8 -3
- package/lib/UnsupportedFeatureWarning.js +22 -21
- package/lib/WarnCaseSensitiveModulesPlugin.js +2 -1
- package/lib/Watching.js +3 -2
- package/lib/WebpackOptionsApply.js +51 -23
- package/lib/WebpackOptionsDefaulter.js +15 -9
- package/lib/WebpackOptionsValidationError.js +63 -34
- package/lib/debug/ProfilingPlugin.js +11 -2
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +17 -8
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +8 -4
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +4 -2
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +7 -3
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +6 -3
- package/lib/dependencies/ImportParserPlugin.js +42 -11
- package/lib/dependencies/LoaderPlugin.js +12 -7
- package/lib/dependencies/LocalModulesHelpers.js +13 -6
- package/lib/dependencies/RequireContextPlugin.js +4 -2
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +8 -4
- package/lib/dependencies/SystemPlugin.js +6 -6
- package/lib/dependencies/WebAssemblyExportImportedDependency.js +29 -0
- package/lib/dependencies/WebAssemblyImportDependency.js +1 -1
- package/lib/formatLocation.js +15 -7
- package/lib/node/NodeMainTemplateAsync.runtime.js +1 -1
- package/lib/node/NodeMainTemplatePlugin.js +6 -3
- package/lib/node/NodeSourcePlugin.js +9 -5
- package/lib/node/NodeWatchFileSystem.js +29 -12
- package/lib/node/ReadFileCompileWasmTemplatePlugin.js +11 -2
- package/lib/optimize/AggressiveSplittingPlugin.js +12 -6
- package/lib/optimize/ConcatenatedModule.js +19 -8
- package/lib/optimize/MergeDuplicateChunksPlugin.js +6 -3
- package/lib/optimize/ModuleConcatenationPlugin.js +23 -10
- package/lib/optimize/OccurrenceOrderPlugin.js +11 -4
- package/lib/optimize/RemoveParentModulesPlugin.js +17 -7
- package/lib/optimize/SideEffectsFlagPlugin.js +14 -3
- package/lib/optimize/SplitChunksPlugin.js +33 -20
- package/lib/performance/AssetsOverSizeLimitWarning.js +7 -7
- package/lib/performance/EntrypointsOverSizeLimitWarning.js +6 -7
- package/lib/performance/NoAsyncChunksWarning.js +5 -5
- package/lib/util/SortableSet.js +5 -2
- package/lib/util/StackedSetMap.js +12 -5
- package/lib/wasm/UnsupportedWebAssemblyFeatureError.js +1 -2
- package/lib/wasm/WasmFinalizeExportsPlugin.js +66 -0
- package/lib/wasm/WasmMainTemplatePlugin.js +87 -43
- package/lib/wasm/WebAssemblyGenerator.js +117 -74
- package/lib/wasm/WebAssemblyJavascriptGenerator.js +92 -49
- package/lib/wasm/WebAssemblyModulesPlugin.js +11 -1
- package/lib/wasm/WebAssemblyParser.js +96 -24
- package/lib/wasm/WebAssemblyUtils.js +17 -6
- package/lib/web/FetchCompileWasmTemplatePlugin.js +13 -1
- package/lib/web/JsonpChunkTemplatePlugin.js +7 -0
- package/lib/web/JsonpMainTemplate.runtime.js +2 -1
- package/lib/web/JsonpMainTemplatePlugin.js +68 -63
- package/lib/webpack.js +2 -1
- package/lib/webworker/WebWorkerMainTemplate.runtime.js +2 -1
- package/package.json +12 -11
- package/schemas/WebpackOptions.json +8 -0
@@ -30,15 +30,23 @@ const getSchemaPartText = (schemaPart, additionalPath) => {
|
|
30
30
|
if (inner) schemaPart = inner;
|
31
31
|
}
|
32
32
|
}
|
33
|
-
while (schemaPart.$ref)
|
33
|
+
while (schemaPart.$ref) {
|
34
|
+
schemaPart = getSchemaPart(schemaPart.$ref);
|
35
|
+
}
|
34
36
|
let schemaText = WebpackOptionsValidationError.formatSchema(schemaPart);
|
35
|
-
if (schemaPart.description)
|
37
|
+
if (schemaPart.description) {
|
38
|
+
schemaText += `\n-> ${schemaPart.description}`;
|
39
|
+
}
|
36
40
|
return schemaText;
|
37
41
|
};
|
38
42
|
|
39
43
|
const getSchemaPartDescription = schemaPart => {
|
40
|
-
while (schemaPart.$ref)
|
41
|
-
|
44
|
+
while (schemaPart.$ref) {
|
45
|
+
schemaPart = getSchemaPart(schemaPart.$ref);
|
46
|
+
}
|
47
|
+
if (schemaPart.description) {
|
48
|
+
return `\n-> ${schemaPart.description}`;
|
49
|
+
}
|
42
50
|
return "";
|
43
51
|
};
|
44
52
|
|
@@ -61,23 +69,23 @@ const indent = (str, prefix, firstLine) => {
|
|
61
69
|
|
62
70
|
class WebpackOptionsValidationError extends WebpackError {
|
63
71
|
constructor(validationErrors) {
|
64
|
-
super(
|
72
|
+
super(
|
73
|
+
"Invalid configuration object. " +
|
74
|
+
"Webpack has been initialised using a configuration object that does not match the API schema.\n" +
|
75
|
+
validationErrors
|
76
|
+
.map(
|
77
|
+
err =>
|
78
|
+
" - " +
|
79
|
+
indent(
|
80
|
+
WebpackOptionsValidationError.formatValidationError(err),
|
81
|
+
" ",
|
82
|
+
false
|
83
|
+
)
|
84
|
+
)
|
85
|
+
.join("\n")
|
86
|
+
);
|
65
87
|
|
66
88
|
this.name = "WebpackOptionsValidationError";
|
67
|
-
this.message =
|
68
|
-
"Invalid configuration object. " +
|
69
|
-
"Webpack has been initialised using a configuration object that does not match the API schema.\n" +
|
70
|
-
validationErrors
|
71
|
-
.map(
|
72
|
-
err =>
|
73
|
-
" - " +
|
74
|
-
indent(
|
75
|
-
WebpackOptionsValidationError.formatValidationError(err),
|
76
|
-
" ",
|
77
|
-
false
|
78
|
-
)
|
79
|
-
)
|
80
|
-
.join("\n");
|
81
89
|
this.validationErrors = validationErrors;
|
82
90
|
|
83
91
|
Error.captureStackTrace(this, this.constructor);
|
@@ -87,12 +95,15 @@ class WebpackOptionsValidationError extends WebpackError {
|
|
87
95
|
prevSchemas = prevSchemas || [];
|
88
96
|
|
89
97
|
const formatInnerSchema = (innerSchema, addSelf) => {
|
90
|
-
if (!addSelf)
|
98
|
+
if (!addSelf) {
|
91
99
|
return WebpackOptionsValidationError.formatSchema(
|
92
100
|
innerSchema,
|
93
101
|
prevSchemas
|
94
102
|
);
|
95
|
-
|
103
|
+
}
|
104
|
+
if (prevSchemas.includes(innerSchema)) {
|
105
|
+
return "(recursive)";
|
106
|
+
}
|
96
107
|
return WebpackOptionsValidationError.formatSchema(
|
97
108
|
innerSchema,
|
98
109
|
prevSchemas.concat(schema)
|
@@ -100,15 +111,21 @@ class WebpackOptionsValidationError extends WebpackError {
|
|
100
111
|
};
|
101
112
|
|
102
113
|
if (schema.type === "string") {
|
103
|
-
if (schema.minLength === 1)
|
104
|
-
|
114
|
+
if (schema.minLength === 1) {
|
115
|
+
return "non-empty string";
|
116
|
+
}
|
117
|
+
if (schema.minLength > 1) {
|
105
118
|
return `string (min length ${schema.minLength})`;
|
119
|
+
}
|
106
120
|
return "string";
|
107
|
-
}
|
121
|
+
}
|
122
|
+
if (schema.type === "boolean") {
|
108
123
|
return "boolean";
|
109
|
-
}
|
124
|
+
}
|
125
|
+
if (schema.type === "number") {
|
110
126
|
return "number";
|
111
|
-
}
|
127
|
+
}
|
128
|
+
if (schema.type === "object") {
|
112
129
|
if (schema.properties) {
|
113
130
|
const required = schema.required || [];
|
114
131
|
return `object { ${Object.keys(schema.properties)
|
@@ -125,7 +142,8 @@ class WebpackOptionsValidationError extends WebpackError {
|
|
125
142
|
)} }`;
|
126
143
|
}
|
127
144
|
return "object";
|
128
|
-
}
|
145
|
+
}
|
146
|
+
if (schema.type === "array") {
|
129
147
|
return `[${formatInnerSchema(schema.items)}]`;
|
130
148
|
}
|
131
149
|
|
@@ -135,12 +153,22 @@ class WebpackOptionsValidationError extends WebpackError {
|
|
135
153
|
case "RegExp":
|
136
154
|
return "RegExp";
|
137
155
|
}
|
138
|
-
|
139
|
-
if (schema
|
140
|
-
|
141
|
-
|
142
|
-
if (schema.
|
156
|
+
|
157
|
+
if (schema.$ref) {
|
158
|
+
return formatInnerSchema(getSchemaPart(schema.$ref), true);
|
159
|
+
}
|
160
|
+
if (schema.allOf) {
|
161
|
+
return schema.allOf.map(formatInnerSchema).join(" & ");
|
162
|
+
}
|
163
|
+
if (schema.oneOf) {
|
164
|
+
return schema.oneOf.map(formatInnerSchema).join(" | ");
|
165
|
+
}
|
166
|
+
if (schema.anyOf) {
|
167
|
+
return schema.anyOf.map(formatInnerSchema).join(" | ");
|
168
|
+
}
|
169
|
+
if (schema.enum) {
|
143
170
|
return schema.enum.map(item => JSON.stringify(item)).join(" | ");
|
171
|
+
}
|
144
172
|
return JSON.stringify(schema, null, 2);
|
145
173
|
}
|
146
174
|
|
@@ -283,14 +311,15 @@ class WebpackOptionsValidationError extends WebpackError {
|
|
283
311
|
err.keyword === "minItems" ||
|
284
312
|
err.keyword === "minProperties"
|
285
313
|
) {
|
286
|
-
if (err.params.limit === 1)
|
314
|
+
if (err.params.limit === 1) {
|
287
315
|
return `${dataPath} should not be empty.${getSchemaPartDescription(
|
288
316
|
err.parentSchema
|
289
317
|
)}`;
|
290
|
-
else
|
318
|
+
} else {
|
291
319
|
return `${dataPath} ${err.message}${getSchemaPartDescription(
|
292
320
|
err.parentSchema
|
293
321
|
)}`;
|
322
|
+
}
|
294
323
|
} else if (err.keyword === "absolutePath") {
|
295
324
|
const baseMessage = `${dataPath}: ${
|
296
325
|
err.message
|
@@ -71,9 +71,18 @@ class Profiler {
|
|
71
71
|
}
|
72
72
|
}
|
73
73
|
|
74
|
+
/**
|
75
|
+
* @typedef {Object} Trace
|
76
|
+
* @description an object that wraps Tracer and Profiler with a counter
|
77
|
+
* @property {Tracer} trace instance of Tracer
|
78
|
+
* @property {number} counter Counter
|
79
|
+
* @property {Profiler} profiler instance of Profiler
|
80
|
+
* @property {Function} end the end function
|
81
|
+
*/
|
82
|
+
|
74
83
|
/**
|
75
84
|
* @param {string} outputPath The location where to write the log.
|
76
|
-
* @returns {
|
85
|
+
* @returns {Trace} The trace object
|
77
86
|
*/
|
78
87
|
function createTrace(outputPath) {
|
79
88
|
const trace = new Tracer({
|
@@ -325,7 +334,7 @@ const makeInterceptorFor = (instance, tracer) => hookName => ({
|
|
325
334
|
|
326
335
|
/**
|
327
336
|
* @param {string} hookName Name of the hook to profile.
|
328
|
-
* @param {
|
337
|
+
* @param {Trace} tracer The trace object.
|
329
338
|
* @param {object} options Options for the profiled fn.
|
330
339
|
* @param {string} options.name Plugin name
|
331
340
|
* @param {string} options.type Plugin type (sync | async | promise)
|
@@ -215,11 +215,14 @@ class AMDDefineDependencyParserPlugin {
|
|
215
215
|
let fnParams = null;
|
216
216
|
let fnParamsOffset = 0;
|
217
217
|
if (fn) {
|
218
|
-
if (isUnboundFunctionExpression(fn))
|
219
|
-
|
218
|
+
if (isUnboundFunctionExpression(fn)) {
|
219
|
+
fnParams = fn.params;
|
220
|
+
} else if (isBoundFunctionExpression(fn)) {
|
220
221
|
fnParams = fn.callee.object.params;
|
221
222
|
fnParamsOffset = fn.arguments.length - 1;
|
222
|
-
if (fnParamsOffset < 0)
|
223
|
+
if (fnParamsOffset < 0) {
|
224
|
+
fnParamsOffset = 0;
|
225
|
+
}
|
223
226
|
}
|
224
227
|
}
|
225
228
|
let fnRenames = parser.scope.renames.createChild();
|
@@ -234,7 +237,7 @@ class AMDDefineDependencyParserPlugin {
|
|
234
237
|
namedModule
|
235
238
|
);
|
236
239
|
if (!result) return;
|
237
|
-
if (fnParams)
|
240
|
+
if (fnParams) {
|
238
241
|
fnParams = fnParams.slice(fnParamsOffset).filter((param, idx) => {
|
239
242
|
if (identifiers[idx]) {
|
240
243
|
fnRenames.set(param.name, identifiers[idx]);
|
@@ -242,9 +245,10 @@ class AMDDefineDependencyParserPlugin {
|
|
242
245
|
}
|
243
246
|
return true;
|
244
247
|
});
|
248
|
+
}
|
245
249
|
} else {
|
246
250
|
const identifiers = ["require", "exports", "module"];
|
247
|
-
if (fnParams)
|
251
|
+
if (fnParams) {
|
248
252
|
fnParams = fnParams.slice(fnParamsOffset).filter((param, idx) => {
|
249
253
|
if (identifiers[idx]) {
|
250
254
|
fnRenames.set(param.name, identifiers[idx]);
|
@@ -252,6 +256,7 @@ class AMDDefineDependencyParserPlugin {
|
|
252
256
|
}
|
253
257
|
return true;
|
254
258
|
});
|
259
|
+
}
|
255
260
|
}
|
256
261
|
let inTry;
|
257
262
|
if (fn && isUnboundFunctionExpression(fn)) {
|
@@ -274,12 +279,16 @@ class AMDDefineDependencyParserPlugin {
|
|
274
279
|
() => {
|
275
280
|
parser.scope.renames = fnRenames;
|
276
281
|
parser.scope.inTry = inTry;
|
277
|
-
if (fn.callee.object.body.type === "BlockStatement")
|
282
|
+
if (fn.callee.object.body.type === "BlockStatement") {
|
278
283
|
parser.walkStatement(fn.callee.object.body);
|
279
|
-
else
|
284
|
+
} else {
|
285
|
+
parser.walkExpression(fn.callee.object.body);
|
286
|
+
}
|
280
287
|
}
|
281
288
|
);
|
282
|
-
if (fn.arguments)
|
289
|
+
if (fn.arguments) {
|
290
|
+
parser.walkExpressions(fn.arguments);
|
291
|
+
}
|
283
292
|
} else if (fn || obj) {
|
284
293
|
parser.walkExpression(fn || obj);
|
285
294
|
}
|
@@ -30,9 +30,11 @@ class AMDRequireDependenciesBlockParserPlugin {
|
|
30
30
|
return !["require", "module", "exports"].includes(i.name);
|
31
31
|
}),
|
32
32
|
() => {
|
33
|
-
if (fnData.fn.body.type === "BlockStatement")
|
33
|
+
if (fnData.fn.body.type === "BlockStatement") {
|
34
34
|
parser.walkStatement(fnData.fn.body);
|
35
|
-
else
|
35
|
+
} else {
|
36
|
+
parser.walkExpression(fnData.fn.body);
|
37
|
+
}
|
36
38
|
}
|
37
39
|
);
|
38
40
|
parser.walkExpressions(fnData.expressions);
|
@@ -212,14 +214,16 @@ class AMDRequireDependenciesBlockParserPlugin {
|
|
212
214
|
if (!result) {
|
213
215
|
dep = new UnsupportedDependency("unsupported", expr.range);
|
214
216
|
old.addDependency(dep);
|
215
|
-
if (parser.state.module)
|
217
|
+
if (parser.state.module) {
|
216
218
|
parser.state.module.errors.push(
|
217
219
|
new UnsupportedFeatureWarning(
|
218
220
|
parser.state.module,
|
219
221
|
"Cannot statically analyse 'require(…, …)' in line " +
|
220
|
-
expr.loc.start.line
|
222
|
+
expr.loc.start.line,
|
223
|
+
expr.loc
|
221
224
|
)
|
222
225
|
);
|
226
|
+
}
|
223
227
|
dep = null;
|
224
228
|
return true;
|
225
229
|
}
|
@@ -58,14 +58,16 @@ module.exports = class HarmonyDetectionParserPlugin {
|
|
58
58
|
|
59
59
|
const skipInHarmony = () => {
|
60
60
|
const module = parser.state.module;
|
61
|
-
if (module && module.buildMeta && module.buildMeta.exportsType)
|
61
|
+
if (module && module.buildMeta && module.buildMeta.exportsType) {
|
62
62
|
return true;
|
63
|
+
}
|
63
64
|
};
|
64
65
|
|
65
66
|
const nullInHarmony = () => {
|
66
67
|
const module = parser.state.module;
|
67
|
-
if (module && module.buildMeta && module.buildMeta.exportsType)
|
68
|
+
if (module && module.buildMeta && module.buildMeta.exportsType) {
|
68
69
|
return null;
|
70
|
+
}
|
69
71
|
};
|
70
72
|
|
71
73
|
const nonHarmonyIdentifiers = ["define", "exports"];
|
@@ -255,8 +255,10 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
|
|
255
255
|
otherImportedModule &&
|
256
256
|
Array.isArray(otherImportedModule.buildMeta.providedExports)
|
257
257
|
) {
|
258
|
-
for (const exportName of otherImportedModule.buildMeta
|
258
|
+
for (const exportName of otherImportedModule.buildMeta
|
259
|
+
.providedExports) {
|
259
260
|
result.add(exportName);
|
261
|
+
}
|
260
262
|
}
|
261
263
|
}
|
262
264
|
return result;
|
@@ -563,12 +565,14 @@ HarmonyExportImportedSpecifierDependency.Template = class HarmonyExportImportedS
|
|
563
565
|
|
564
566
|
// Filter out exports which are defined by other exports
|
565
567
|
// and filter out default export because it cannot be reexported with *
|
566
|
-
if (activeExports.size > 0)
|
568
|
+
if (activeExports.size > 0) {
|
567
569
|
content +=
|
568
570
|
"if(" +
|
569
571
|
JSON.stringify(Array.from(activeExports).concat("default")) +
|
570
572
|
".indexOf(__WEBPACK_IMPORT_KEY__) < 0) ";
|
571
|
-
else
|
573
|
+
} else {
|
574
|
+
content += "if(__WEBPACK_IMPORT_KEY__ !== 'default') ";
|
575
|
+
}
|
572
576
|
const exportsName = dep.originModule.exportsArgument;
|
573
577
|
return (
|
574
578
|
content +
|
@@ -42,8 +42,9 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
42
42
|
(statement, source, id, name) => {
|
43
43
|
parser.scope.definitions.delete(name);
|
44
44
|
parser.scope.renames.set(name, "imported var");
|
45
|
-
if (!parser.state.harmonySpecifier)
|
45
|
+
if (!parser.state.harmonySpecifier) {
|
46
46
|
parser.state.harmonySpecifier = new Map();
|
47
|
+
}
|
47
48
|
parser.state.harmonySpecifier.set(name, {
|
48
49
|
source,
|
49
50
|
id,
|
@@ -152,16 +153,18 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
152
153
|
return true;
|
153
154
|
});
|
154
155
|
// TODO webpack 5: refactor this, no custom hooks
|
155
|
-
if (!parser.hooks.hotAcceptCallback)
|
156
|
+
if (!parser.hooks.hotAcceptCallback) {
|
156
157
|
parser.hooks.hotAcceptCallback = new SyncBailHook([
|
157
158
|
"expression",
|
158
159
|
"requests"
|
159
160
|
]);
|
160
|
-
|
161
|
+
}
|
162
|
+
if (!parser.hooks.hotAcceptWithoutCallback) {
|
161
163
|
parser.hooks.hotAcceptWithoutCallback = new SyncBailHook([
|
162
164
|
"expression",
|
163
165
|
"requests"
|
164
166
|
]);
|
167
|
+
}
|
165
168
|
parser.hooks.hotAcceptCallback.tap(
|
166
169
|
"HarmonyImportDependencyParserPlugin",
|
167
170
|
(expr, requests) => {
|
@@ -10,6 +10,7 @@ const ImportDependenciesBlock = require("./ImportDependenciesBlock");
|
|
10
10
|
const ImportEagerDependency = require("./ImportEagerDependency");
|
11
11
|
const ContextDependencyHelpers = require("./ContextDependencyHelpers");
|
12
12
|
const UnsupportedFeatureWarning = require("../UnsupportedFeatureWarning");
|
13
|
+
const CommentCompilationWarning = require("../CommentCompilationWarning");
|
13
14
|
|
14
15
|
class ImportParserPlugin {
|
15
16
|
constructor(options) {
|
@@ -18,10 +19,11 @@ class ImportParserPlugin {
|
|
18
19
|
|
19
20
|
apply(parser) {
|
20
21
|
parser.hooks.importCall.tap("ImportParserPlugin", expr => {
|
21
|
-
if (expr.arguments.length !== 1)
|
22
|
+
if (expr.arguments.length !== 1) {
|
22
23
|
throw new Error(
|
23
24
|
"Incorrect number of arguments provided to 'import(module: string) -> Promise'."
|
24
25
|
);
|
26
|
+
}
|
25
27
|
|
26
28
|
const param = parser.evaluateExpression(expr.arguments[0]);
|
27
29
|
|
@@ -31,7 +33,26 @@ class ImportParserPlugin {
|
|
31
33
|
let exclude = null;
|
32
34
|
const groupOptions = {};
|
33
35
|
|
34
|
-
const
|
36
|
+
const {
|
37
|
+
options: importOptions,
|
38
|
+
errors: commentErrors
|
39
|
+
} = parser.parseCommentOptions(expr.range);
|
40
|
+
|
41
|
+
if (commentErrors) {
|
42
|
+
for (const e of commentErrors) {
|
43
|
+
const { comment } = e;
|
44
|
+
parser.state.module.warnings.push(
|
45
|
+
new CommentCompilationWarning(
|
46
|
+
`Compilation error while processing magic comment(-s): /*${
|
47
|
+
comment.value
|
48
|
+
}*/: ${e.message}`,
|
49
|
+
parser.state.module,
|
50
|
+
comment.loc
|
51
|
+
)
|
52
|
+
);
|
53
|
+
}
|
54
|
+
}
|
55
|
+
|
35
56
|
if (importOptions) {
|
36
57
|
if (typeof importOptions.webpackIgnore !== "undefined") {
|
37
58
|
if (typeof importOptions.webpackIgnore !== "boolean") {
|
@@ -40,7 +61,8 @@ class ImportParserPlugin {
|
|
40
61
|
parser.state.module,
|
41
62
|
`\`webpackIgnore\` expected a boolean, but received: ${
|
42
63
|
importOptions.webpackIgnore
|
43
|
-
}
|
64
|
+
}.`,
|
65
|
+
expr.loc
|
44
66
|
)
|
45
67
|
);
|
46
68
|
} else {
|
@@ -57,7 +79,8 @@ class ImportParserPlugin {
|
|
57
79
|
parser.state.module,
|
58
80
|
`\`webpackChunkName\` expected a string, but received: ${
|
59
81
|
importOptions.webpackChunkName
|
60
|
-
}
|
82
|
+
}.`,
|
83
|
+
expr.loc
|
61
84
|
)
|
62
85
|
);
|
63
86
|
} else {
|
@@ -71,7 +94,8 @@ class ImportParserPlugin {
|
|
71
94
|
parser.state.module,
|
72
95
|
`\`webpackMode\` expected a string, but received: ${
|
73
96
|
importOptions.webpackMode
|
74
|
-
}
|
97
|
+
}.`,
|
98
|
+
expr.loc
|
75
99
|
)
|
76
100
|
);
|
77
101
|
} else {
|
@@ -89,7 +113,8 @@ class ImportParserPlugin {
|
|
89
113
|
parser.state.module,
|
90
114
|
`\`webpackPrefetch\` expected true or a number, but received: ${
|
91
115
|
importOptions.webpackPrefetch
|
92
|
-
}
|
116
|
+
}.`,
|
117
|
+
expr.loc
|
93
118
|
)
|
94
119
|
);
|
95
120
|
}
|
@@ -105,7 +130,8 @@ class ImportParserPlugin {
|
|
105
130
|
parser.state.module,
|
106
131
|
`\`webpackPreload\` expected true or a number, but received: ${
|
107
132
|
importOptions.webpackPreload
|
108
|
-
}
|
133
|
+
}.`,
|
134
|
+
expr.loc
|
109
135
|
)
|
110
136
|
);
|
111
137
|
}
|
@@ -120,7 +146,8 @@ class ImportParserPlugin {
|
|
120
146
|
parser.state.module,
|
121
147
|
`\`webpackInclude\` expected a regular expression, but received: ${
|
122
148
|
importOptions.webpackInclude
|
123
|
-
}
|
149
|
+
}.`,
|
150
|
+
expr.loc
|
124
151
|
)
|
125
152
|
);
|
126
153
|
} else {
|
@@ -137,7 +164,8 @@ class ImportParserPlugin {
|
|
137
164
|
parser.state.module,
|
138
165
|
`\`webpackExclude\` expected a regular expression, but received: ${
|
139
166
|
importOptions.webpackExclude
|
140
|
-
}
|
167
|
+
}.`,
|
168
|
+
expr.loc
|
141
169
|
)
|
142
170
|
);
|
143
171
|
} else {
|
@@ -151,7 +179,8 @@ class ImportParserPlugin {
|
|
151
179
|
parser.state.module.warnings.push(
|
152
180
|
new UnsupportedFeatureWarning(
|
153
181
|
parser.state.module,
|
154
|
-
`\`webpackMode\` expected 'lazy', 'eager' or 'weak', but received: ${mode}
|
182
|
+
`\`webpackMode\` expected 'lazy', 'eager' or 'weak', but received: ${mode}.`,
|
183
|
+
expr.loc
|
155
184
|
)
|
156
185
|
);
|
157
186
|
}
|
@@ -194,7 +223,8 @@ class ImportParserPlugin {
|
|
194
223
|
parser.state.module.warnings.push(
|
195
224
|
new UnsupportedFeatureWarning(
|
196
225
|
parser.state.module,
|
197
|
-
`\`webpackMode\` expected 'lazy', 'lazy-once', 'eager' or 'weak', but received: ${mode}
|
226
|
+
`\`webpackMode\` expected 'lazy', 'lazy-once', 'eager' or 'weak', but received: ${mode}.`,
|
227
|
+
expr.loc
|
198
228
|
)
|
199
229
|
);
|
200
230
|
mode = "lazy";
|
@@ -229,4 +259,5 @@ class ImportParserPlugin {
|
|
229
259
|
});
|
230
260
|
}
|
231
261
|
}
|
262
|
+
|
232
263
|
module.exports = ImportParserPlugin;
|
@@ -28,7 +28,7 @@ class LoaderPlugin {
|
|
28
28
|
const factory = compilation.dependencyFactories.get(
|
29
29
|
dep.constructor
|
30
30
|
);
|
31
|
-
if (factory === undefined)
|
31
|
+
if (factory === undefined) {
|
32
32
|
return callback(
|
33
33
|
new Error(
|
34
34
|
`No module factory available for dependency type: ${
|
@@ -36,6 +36,7 @@ class LoaderPlugin {
|
|
36
36
|
}`
|
37
37
|
)
|
38
38
|
);
|
39
|
+
}
|
39
40
|
compilation.semaphore.release();
|
40
41
|
compilation.addModuleDependencies(
|
41
42
|
module,
|
@@ -50,16 +51,20 @@ class LoaderPlugin {
|
|
50
51
|
true,
|
51
52
|
err => {
|
52
53
|
compilation.semaphore.acquire(() => {
|
53
|
-
if (err)
|
54
|
-
|
55
|
-
|
54
|
+
if (err) {
|
55
|
+
return callback(err);
|
56
|
+
}
|
57
|
+
if (!dep.module) {
|
56
58
|
return callback(new Error("Cannot load the module"));
|
57
|
-
|
58
|
-
if (dep.module.error)
|
59
|
-
|
59
|
+
}
|
60
|
+
if (dep.module.error) {
|
61
|
+
return callback(dep.module.error);
|
62
|
+
}
|
63
|
+
if (!dep.module._source) {
|
60
64
|
throw new Error(
|
61
65
|
"The module created for a LoaderDependency must have a property _source"
|
62
66
|
);
|
67
|
+
}
|
63
68
|
let source, map;
|
64
69
|
const moduleSource = dep.module._source;
|
65
70
|
if (moduleSource.sourceAndMap) {
|
@@ -10,21 +10,26 @@ const LocalModulesHelpers = exports;
|
|
10
10
|
const lookup = (parent, mod) => {
|
11
11
|
if (mod.charAt(0) !== ".") return mod;
|
12
12
|
|
13
|
-
var path = parent.split("/")
|
14
|
-
|
13
|
+
var path = parent.split("/");
|
14
|
+
var segs = mod.split("/");
|
15
15
|
path.pop();
|
16
16
|
|
17
17
|
for (let i = 0; i < segs.length; i++) {
|
18
18
|
const seg = segs[i];
|
19
|
-
if (seg === "..")
|
20
|
-
|
19
|
+
if (seg === "..") {
|
20
|
+
path.pop();
|
21
|
+
} else if (seg !== ".") {
|
22
|
+
path.push(seg);
|
23
|
+
}
|
21
24
|
}
|
22
25
|
|
23
26
|
return path.join("/");
|
24
27
|
};
|
25
28
|
|
26
29
|
LocalModulesHelpers.addLocalModule = (state, name) => {
|
27
|
-
if (!state.localModules)
|
30
|
+
if (!state.localModules) {
|
31
|
+
state.localModules = [];
|
32
|
+
}
|
28
33
|
const m = new LocalModule(state.module, name, state.localModules.length);
|
29
34
|
state.localModules.push(m);
|
30
35
|
return m;
|
@@ -37,7 +42,9 @@ LocalModulesHelpers.getLocalModule = (state, name, namedModule) => {
|
|
37
42
|
name = lookup(namedModule, name);
|
38
43
|
}
|
39
44
|
for (let i = 0; i < state.localModules.length; i++) {
|
40
|
-
if (state.localModules[i].name === name)
|
45
|
+
if (state.localModules[i].name === name) {
|
46
|
+
return state.localModules[i];
|
47
|
+
}
|
41
48
|
}
|
42
49
|
return null;
|
43
50
|
};
|
@@ -11,10 +11,12 @@ const RequireContextDependencyParserPlugin = require("./RequireContextDependency
|
|
11
11
|
|
12
12
|
class RequireContextPlugin {
|
13
13
|
constructor(modulesDirectories, extensions, mainFiles) {
|
14
|
-
if (!Array.isArray(modulesDirectories))
|
14
|
+
if (!Array.isArray(modulesDirectories)) {
|
15
15
|
throw new Error("modulesDirectories must be an array");
|
16
|
-
|
16
|
+
}
|
17
|
+
if (!Array.isArray(extensions)) {
|
17
18
|
throw new Error("extensions must be an array");
|
19
|
+
}
|
18
20
|
this.modulesDirectories = modulesDirectories;
|
19
21
|
this.extensions = extensions;
|
20
22
|
this.mainFiles = mainFiles;
|
@@ -86,9 +86,11 @@ module.exports = class RequireEnsureDependenciesBlockParserPlugin {
|
|
86
86
|
return;
|
87
87
|
}
|
88
88
|
if (successExpression) {
|
89
|
-
if (successExpression.fn.body.type === "BlockStatement")
|
89
|
+
if (successExpression.fn.body.type === "BlockStatement") {
|
90
90
|
parser.walkStatement(successExpression.fn.body);
|
91
|
-
else
|
91
|
+
} else {
|
92
|
+
parser.walkExpression(successExpression.fn.body);
|
93
|
+
}
|
92
94
|
}
|
93
95
|
old.addBlock(dep);
|
94
96
|
} finally {
|
@@ -98,9 +100,11 @@ module.exports = class RequireEnsureDependenciesBlockParserPlugin {
|
|
98
100
|
parser.walkExpression(successExpressionArg);
|
99
101
|
}
|
100
102
|
if (errorExpression) {
|
101
|
-
if (errorExpression.fn.body.type === "BlockStatement")
|
103
|
+
if (errorExpression.fn.body.type === "BlockStatement") {
|
102
104
|
parser.walkStatement(errorExpression.fn.body);
|
103
|
-
else
|
105
|
+
} else {
|
106
|
+
parser.walkExpression(errorExpression.fn.body);
|
107
|
+
}
|
104
108
|
} else if (errorExpressionArg) {
|
105
109
|
parser.walkExpression(errorExpressionArg);
|
106
110
|
}
|
@@ -108,15 +108,15 @@ class SystemPlugin {
|
|
108
108
|
|
109
109
|
class SystemImportDeprecationWarning extends WebpackError {
|
110
110
|
constructor(module, loc) {
|
111
|
-
super(
|
111
|
+
super(
|
112
|
+
"System.import() is deprecated and will be removed soon. Use import() instead.\n" +
|
113
|
+
"For more info visit https://webpack.js.org/guides/code-splitting/"
|
114
|
+
);
|
112
115
|
|
113
116
|
this.name = "SystemImportDeprecationWarning";
|
114
|
-
this.message =
|
115
|
-
"System.import() is deprecated and will be removed soon. Use import() instead.\n" +
|
116
|
-
"For more info visit https://webpack.js.org/guides/code-splitting/";
|
117
117
|
|
118
|
-
this.
|
119
|
-
this.
|
118
|
+
this.module = module;
|
119
|
+
this.loc = loc;
|
120
120
|
|
121
121
|
Error.captureStackTrace(this, this.constructor);
|
122
122
|
}
|