webpack 4.10.1 → 4.10.2
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/BannerPlugin.js +3 -1
- package/lib/BasicEvaluatedExpression.js +14 -11
- package/lib/CachePlugin.js +12 -5
- package/lib/Chunk.js +44 -16
- package/lib/ChunkGroup.js +13 -5
- package/lib/Compilation.js +70 -28
- 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/ErrorHelpers.js +5 -2
- package/lib/EvalSourceMapDevToolPlugin.js +2 -1
- package/lib/FlagDependencyUsagePlugin.js +11 -5
- package/lib/FunctionModuleTemplatePlugin.js +8 -6
- package/lib/HotModuleReplacement.runtime.js +7 -3
- 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 +9 -5
- package/lib/ModuleFilenameHelpers.js +20 -8
- package/lib/MultiCompiler.js +19 -7
- package/lib/MultiModule.js +5 -2
- package/lib/NodeStuffPlugin.js +2 -1
- package/lib/NormalModule.js +11 -4
- package/lib/NormalModuleFactory.js +30 -12
- package/lib/OptionsDefaulter.js +7 -3
- package/lib/Parser.js +137 -59
- package/lib/ParserHelpers.js +5 -2
- package/lib/ProgressPlugin.js +2 -2
- package/lib/RawModule.js +4 -2
- package/lib/RecordIdsPlugin.js +11 -7
- package/lib/RequestShortener.js +13 -6
- package/lib/RuleSet.js +39 -18
- package/lib/RuntimeTemplate.js +21 -10
- package/lib/SourceMapDevToolPlugin.js +4 -3
- package/lib/Stats.js +64 -28
- package/lib/Template.js +4 -2
- package/lib/TemplatedPathPlugin.js +6 -3
- package/lib/UmdMainTemplatePlugin.js +8 -3
- package/lib/WarnCaseSensitiveModulesPlugin.js +2 -1
- package/lib/Watching.js +3 -2
- package/lib/WebpackOptionsApply.js +32 -16
- package/lib/WebpackOptionsDefaulter.js +7 -4
- package/lib/WebpackOptionsValidationError.js +48 -19
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +17 -8
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +6 -3
- 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 +2 -1
- 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/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/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 +3 -2
- package/lib/optimize/SplitChunksPlugin.js +33 -20
- package/lib/util/SortableSet.js +5 -2
- package/lib/util/StackedSetMap.js +12 -5
- package/lib/wasm/WasmMainTemplatePlugin.js +4 -2
- package/lib/wasm/WebAssemblyGenerator.js +7 -0
- package/lib/web/JsonpMainTemplate.runtime.js +2 -1
- package/lib/web/JsonpMainTemplatePlugin.js +2 -1
- package/lib/webpack.js +2 -1
- package/lib/webworker/WebWorkerMainTemplate.runtime.js +2 -1
- package/package.json +9 -9
@@ -136,10 +136,11 @@ class WebpackOptionsDefaulter extends OptionsDefaulter {
|
|
136
136
|
}
|
137
137
|
});
|
138
138
|
this.set("output.devtoolNamespace", "make", options => {
|
139
|
-
if (Array.isArray(options.output.library))
|
139
|
+
if (Array.isArray(options.output.library)) {
|
140
140
|
return options.output.library.join(".");
|
141
|
-
else if (typeof options.output.library === "object")
|
141
|
+
} else if (typeof options.output.library === "object") {
|
142
142
|
return options.output.library.root || "";
|
143
|
+
}
|
143
144
|
return options.output.library || "";
|
144
145
|
});
|
145
146
|
this.set("output.libraryTarget", "var");
|
@@ -305,9 +306,11 @@ class WebpackOptionsDefaulter extends OptionsDefaulter {
|
|
305
306
|
this.set("resolve.extensions", [".wasm", ".mjs", ".js", ".json"]);
|
306
307
|
this.set("resolve.mainFiles", ["index"]);
|
307
308
|
this.set("resolve.aliasFields", "make", options => {
|
308
|
-
if (options.target === "web" || options.target === "webworker")
|
309
|
+
if (options.target === "web" || options.target === "webworker") {
|
309
310
|
return ["browser"];
|
310
|
-
else
|
311
|
+
} else {
|
312
|
+
return [];
|
313
|
+
}
|
311
314
|
});
|
312
315
|
this.set("resolve.mainFields", "make", options => {
|
313
316
|
if (
|
@@ -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
|
|
@@ -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
|
@@ -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,7 +214,7 @@ 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,
|
@@ -220,6 +222,7 @@ class AMDRequireDependenciesBlockParserPlugin {
|
|
220
222
|
expr.loc.start.line
|
221
223
|
)
|
222
224
|
);
|
225
|
+
}
|
223
226
|
dep = null;
|
224
227
|
return true;
|
225
228
|
}
|
@@ -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) => {
|
@@ -18,10 +18,11 @@ class ImportParserPlugin {
|
|
18
18
|
|
19
19
|
apply(parser) {
|
20
20
|
parser.hooks.importCall.tap("ImportParserPlugin", expr => {
|
21
|
-
if (expr.arguments.length !== 1)
|
21
|
+
if (expr.arguments.length !== 1) {
|
22
22
|
throw new Error(
|
23
23
|
"Incorrect number of arguments provided to 'import(module: string) -> Promise'."
|
24
24
|
);
|
25
|
+
}
|
25
26
|
|
26
27
|
const param = parser.evaluateExpression(expr.arguments[0]);
|
27
28
|
|
@@ -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
|
}
|
package/lib/formatLocation.js
CHANGED
@@ -14,11 +14,15 @@ const formatPosition = pos => {
|
|
14
14
|
case "number":
|
15
15
|
return `${pos}`;
|
16
16
|
case "object":
|
17
|
-
if (typeof pos.line === "number" && typeof pos.column === "number")
|
17
|
+
if (typeof pos.line === "number" && typeof pos.column === "number") {
|
18
18
|
return `${pos.line}:${pos.column}`;
|
19
|
-
else if (typeof pos.line === "number")
|
20
|
-
|
21
|
-
else
|
19
|
+
} else if (typeof pos.line === "number") {
|
20
|
+
return `${pos.line}:?`;
|
21
|
+
} else if (typeof pos.index === "number") {
|
22
|
+
return `+${pos.index}`;
|
23
|
+
} else {
|
24
|
+
return "";
|
25
|
+
}
|
22
26
|
default:
|
23
27
|
return "";
|
24
28
|
}
|
@@ -39,11 +43,15 @@ const formatLocation = loc => {
|
|
39
43
|
typeof loc.end.line === "number" &&
|
40
44
|
typeof loc.end.column === "number" &&
|
41
45
|
loc.start.line === loc.end.line
|
42
|
-
)
|
46
|
+
) {
|
43
47
|
return `${formatPosition(loc.start)}-${loc.end.column}`;
|
44
|
-
|
48
|
+
} else {
|
49
|
+
return `${formatPosition(loc.start)}-${formatPosition(loc.end)}`;
|
50
|
+
}
|
51
|
+
}
|
52
|
+
if (loc.start) {
|
53
|
+
return formatPosition(loc.start);
|
45
54
|
}
|
46
|
-
if (loc.start) return formatPosition(loc.start);
|
47
55
|
return formatPosition(loc);
|
48
56
|
default:
|
49
57
|
return "";
|
@@ -116,10 +116,11 @@ module.exports = class NodeMainTemplatePlugin {
|
|
116
116
|
hashWithLength: length => {
|
117
117
|
const shortChunkHashMap = {};
|
118
118
|
for (const chunkId of Object.keys(chunkMaps.hash)) {
|
119
|
-
if (typeof chunkMaps.hash[chunkId] === "string")
|
119
|
+
if (typeof chunkMaps.hash[chunkId] === "string") {
|
120
120
|
shortChunkHashMap[chunkId] = chunkMaps.hash[
|
121
121
|
chunkId
|
122
122
|
].substr(0, length);
|
123
|
+
}
|
123
124
|
}
|
124
125
|
return `" + ${JSON.stringify(
|
125
126
|
shortChunkHashMap
|
@@ -201,10 +202,11 @@ module.exports = class NodeMainTemplatePlugin {
|
|
201
202
|
hashWithLength: length => {
|
202
203
|
const shortChunkHashMap = {};
|
203
204
|
for (const chunkId of Object.keys(chunkMaps.hash)) {
|
204
|
-
if (typeof chunkMaps.hash[chunkId] === "string")
|
205
|
+
if (typeof chunkMaps.hash[chunkId] === "string") {
|
205
206
|
shortChunkHashMap[chunkId] = chunkMaps.hash[
|
206
207
|
chunkId
|
207
208
|
].substr(0, length);
|
209
|
+
}
|
208
210
|
}
|
209
211
|
return `" + ${JSON.stringify(
|
210
212
|
shortChunkHashMap
|
@@ -278,11 +280,12 @@ module.exports = class NodeMainTemplatePlugin {
|
|
278
280
|
hashWithLength: length => {
|
279
281
|
const shortChunkHashMap = {};
|
280
282
|
for (const chunkId of Object.keys(chunkMaps.hash)) {
|
281
|
-
if (typeof chunkMaps.hash[chunkId] === "string")
|
283
|
+
if (typeof chunkMaps.hash[chunkId] === "string") {
|
282
284
|
shortChunkHashMap[chunkId] = chunkMaps.hash[chunkId].substr(
|
283
285
|
0,
|
284
286
|
length
|
285
287
|
);
|
288
|
+
}
|
286
289
|
}
|
287
290
|
return `" + ${JSON.stringify(shortChunkHashMap)}[chunkId] + "`;
|
288
291
|
},
|
@@ -13,22 +13,26 @@ module.exports = class NodeSourcePlugin {
|
|
13
13
|
}
|
14
14
|
apply(compiler) {
|
15
15
|
const options = this.options;
|
16
|
-
if (options === false)
|
16
|
+
if (options === false) {
|
17
17
|
// allow single kill switch to turn off this plugin
|
18
18
|
return;
|
19
|
+
}
|
19
20
|
|
20
21
|
const getPathToModule = (module, type) => {
|
21
22
|
if (type === true || (type === undefined && nodeLibsBrowser[module])) {
|
22
|
-
if (!nodeLibsBrowser[module])
|
23
|
+
if (!nodeLibsBrowser[module]) {
|
23
24
|
throw new Error(
|
24
25
|
`No browser version for node.js core module ${module} available`
|
25
26
|
);
|
27
|
+
}
|
26
28
|
return nodeLibsBrowser[module];
|
27
29
|
} else if (type === "mock") {
|
28
30
|
return require.resolve(`node-libs-browser/mock/${module}`);
|
29
31
|
} else if (type === "empty") {
|
30
32
|
return require.resolve("node-libs-browser/mock/empty");
|
31
|
-
} else
|
33
|
+
} else {
|
34
|
+
return module;
|
35
|
+
}
|
32
36
|
};
|
33
37
|
|
34
38
|
const addExpression = (parser, name, module, type, suffix) => {
|
@@ -58,9 +62,9 @@ module.exports = class NodeSourcePlugin {
|
|
58
62
|
if (parserOptions.node === false) return;
|
59
63
|
|
60
64
|
let localOptions = options;
|
61
|
-
if (parserOptions.node)
|
65
|
+
if (parserOptions.node) {
|
62
66
|
localOptions = Object.assign({}, localOptions, parserOptions.node);
|
63
|
-
|
67
|
+
}
|
64
68
|
if (localOptions.global) {
|
65
69
|
parser.hooks.expression
|
66
70
|
.for("global")
|