webpack 4.41.4 → 4.42.1

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.
@@ -50,7 +50,8 @@ export type Externals =
50
50
  request: string,
51
51
  callback: (err?: Error, result?: string) => void
52
52
  ) => void)
53
- | ExternalItem)[];
53
+ | ExternalItem
54
+ )[];
54
55
  /**
55
56
  * This interface was referenced by `WebpackOptions`'s JSON-Schema
56
57
  * via the `definition` "ExternalItem".
@@ -131,7 +132,7 @@ export type RuleSetCondition =
131
132
  * This interface was referenced by `WebpackOptions`'s JSON-Schema
132
133
  * via the `definition` "RuleSetConditions".
133
134
  */
134
- export type RuleSetConditions = RuleSetConditionsRecursive;
135
+ export type RuleSetConditions = RuleSetCondition[];
135
136
  /**
136
137
  * One or multiple rule conditions
137
138
  *
@@ -180,7 +181,7 @@ export type RuleSetConditionAbsolute =
180
181
  * This interface was referenced by `WebpackOptions`'s JSON-Schema
181
182
  * via the `definition` "RuleSetConditionsAbsolute".
182
183
  */
183
- export type RuleSetConditionsAbsolute = RuleSetConditionsAbsoluteRecursive;
184
+ export type RuleSetConditionsAbsolute = RuleSetConditionAbsolute[];
184
185
  /**
185
186
  * This interface was referenced by `WebpackOptions`'s JSON-Schema
186
187
  * via the `definition` "RuleSetLoader".
@@ -391,7 +392,8 @@ export interface WebpackOptions {
391
392
  | "normal"
392
393
  | "detailed"
393
394
  | "verbose"
394
- | "errors-warnings");
395
+ | "errors-warnings"
396
+ );
395
397
  /**
396
398
  * Environment to build for
397
399
  */
@@ -404,7 +406,8 @@ export interface WebpackOptions {
404
406
  | "node-webkit"
405
407
  | "electron-main"
406
408
  | "electron-renderer"
407
- | "electron-preload")
409
+ | "electron-preload"
410
+ )
408
411
  | ((compiler: import("../lib/Compiler")) => void);
409
412
  /**
410
413
  * Enter watch mode, which rebuilds on file change.
@@ -1115,7 +1118,7 @@ export interface OutputOptions {
1115
1118
  /**
1116
1119
  * The filename of the Hot Update Chunks. They are inside the output.path directory.
1117
1120
  */
1118
- hotUpdateChunkFilename?: string | Function;
1121
+ hotUpdateChunkFilename?: string;
1119
1122
  /**
1120
1123
  * The JSONP function used by webpack for async loading of hot update chunks.
1121
1124
  */
@@ -45,18 +45,20 @@ class CommonJsStuffPlugin {
45
45
  .tap("CommonJsStuffPlugin", expr => {
46
46
  parser.state.module.buildMeta.moduleConcatenationBailout =
47
47
  "module.loaded";
48
- return ParserHelpers.toConstantDependency(parser, "module.l")(
49
- expr
50
- );
48
+ return ParserHelpers.toConstantDependency(
49
+ parser,
50
+ "module.l"
51
+ )(expr);
51
52
  });
52
53
  parser.hooks.expression
53
54
  .for("module.id")
54
55
  .tap("CommonJsStuffPlugin", expr => {
55
56
  parser.state.module.buildMeta.moduleConcatenationBailout =
56
57
  "module.id";
57
- return ParserHelpers.toConstantDependency(parser, "module.i")(
58
- expr
59
- );
58
+ return ParserHelpers.toConstantDependency(
59
+ parser,
60
+ "module.i"
61
+ )(expr);
60
62
  });
61
63
  parser.hooks.expression
62
64
  .for("module.exports")
@@ -119,6 +119,7 @@ class ConstPlugin {
119
119
 
120
120
  const handler = parser => {
121
121
  parser.hooks.statementIf.tap("ConstPlugin", statement => {
122
+ if (parser.scope.isAsmJs) return;
122
123
  const param = parser.evaluateExpression(statement.test);
123
124
  const bool = param.asBool();
124
125
  if (typeof bool === "boolean") {
@@ -189,6 +190,7 @@ class ConstPlugin {
189
190
  parser.hooks.expressionConditionalOperator.tap(
190
191
  "ConstPlugin",
191
192
  expression => {
193
+ if (parser.scope.isAsmJs) return;
192
194
  const param = parser.evaluateExpression(expression.test);
193
195
  const bool = param.asBool();
194
196
  if (typeof bool === "boolean") {
@@ -224,6 +226,7 @@ class ConstPlugin {
224
226
  parser.hooks.expressionLogicalOperator.tap(
225
227
  "ConstPlugin",
226
228
  expression => {
229
+ if (parser.scope.isAsmJs) return;
227
230
  if (
228
231
  expression.operator === "&&" ||
229
232
  expression.operator === "||"
@@ -309,6 +312,7 @@ class ConstPlugin {
309
312
  parser.hooks.evaluateIdentifier
310
313
  .for("__resourceQuery")
311
314
  .tap("ConstPlugin", expr => {
315
+ if (parser.scope.isAsmJs) return;
312
316
  if (!parser.state.module) return;
313
317
  return ParserHelpers.evaluateToString(
314
318
  getQuery(parser.state.module.resource)
@@ -317,6 +321,7 @@ class ConstPlugin {
317
321
  parser.hooks.expression
318
322
  .for("__resourceQuery")
319
323
  .tap("ConstPlugin", () => {
324
+ if (parser.scope.isAsmJs) return;
320
325
  if (!parser.state.module) return;
321
326
  parser.state.current.addVariable(
322
327
  "__resourceQuery",
@@ -190,9 +190,10 @@ class DefinePlugin {
190
190
  strCode
191
191
  )(expr);
192
192
  } else {
193
- return ParserHelpers.toConstantDependency(parser, strCode)(
194
- expr
195
- );
193
+ return ParserHelpers.toConstantDependency(
194
+ parser,
195
+ strCode
196
+ )(expr);
196
197
  }
197
198
  });
198
199
  }
@@ -255,9 +256,10 @@ class DefinePlugin {
255
256
  strCode
256
257
  )(expr);
257
258
  } else {
258
- return ParserHelpers.toConstantDependency(parser, strCode)(
259
- expr
260
- );
259
+ return ParserHelpers.toConstantDependency(
260
+ parser,
261
+ strCode
262
+ )(expr);
261
263
  }
262
264
  });
263
265
  parser.hooks.typeof.for(key).tap("DefinePlugin", expr => {
package/lib/DllPlugin.js CHANGED
@@ -5,8 +5,8 @@
5
5
  "use strict";
6
6
 
7
7
  const DllEntryPlugin = require("./DllEntryPlugin");
8
+ const FlagAllModulesAsUsedPlugin = require("./FlagAllModulesAsUsedPlugin");
8
9
  const LibManifestPlugin = require("./LibManifestPlugin");
9
- const FlagInitialModulesAsUsedPlugin = require("./FlagInitialModulesAsUsedPlugin");
10
10
 
11
11
  const validateOptions = require("schema-utils");
12
12
  const schema = require("../schemas/plugins/DllPlugin.json");
@@ -41,7 +41,7 @@ class DllPlugin {
41
41
  });
42
42
  new LibManifestPlugin(this.options).apply(compiler);
43
43
  if (!this.options.entryOnly) {
44
- new FlagInitialModulesAsUsedPlugin("DllPlugin").apply(compiler);
44
+ new FlagAllModulesAsUsedPlugin("DllPlugin").apply(compiler);
45
45
  }
46
46
  }
47
47
  }
@@ -6,6 +6,7 @@
6
6
 
7
7
  const { RawSource } = require("webpack-sources");
8
8
  const ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
9
+ const { absolutify } = require("./util/identifier");
9
10
 
10
11
  const cache = new WeakMap();
11
12
 
@@ -60,7 +61,11 @@ class EvalSourceMapDevToolModuleTemplatePlugin {
60
61
  obj[key] = sourceMap[key];
61
62
  return obj;
62
63
  }, {});
64
+ const context = this.compilation.compiler.options.context;
63
65
  const modules = sourceMap.sources.map(source => {
66
+ if (source.startsWith("webpack://")) {
67
+ source = absolutify(context, source.slice(10));
68
+ }
64
69
  const module = self.compilation.findModule(source);
65
70
  return module || source;
66
71
  });
@@ -0,0 +1,38 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Tobias Koppers @sokra
4
+ */
5
+
6
+ "use strict";
7
+
8
+ /** @typedef {import("./Compiler")} Compiler */
9
+
10
+ class FlagAllModulesAsUsedPlugin {
11
+ constructor(explanation) {
12
+ this.explanation = explanation;
13
+ }
14
+
15
+ /**
16
+ * @param {Compiler} compiler webpack compiler
17
+ * @returns {void}
18
+ */
19
+ apply(compiler) {
20
+ compiler.hooks.compilation.tap(
21
+ "FlagAllModulesAsUsedPlugin",
22
+ compilation => {
23
+ compilation.hooks.optimizeDependencies.tap(
24
+ "FlagAllModulesAsUsedPlugin",
25
+ modules => {
26
+ for (const module of modules) {
27
+ module.used = true;
28
+ module.usedExports = true;
29
+ module.addReason(null, null, this.explanation);
30
+ }
31
+ }
32
+ );
33
+ }
34
+ );
35
+ }
36
+ }
37
+
38
+ module.exports = FlagAllModulesAsUsedPlugin;
@@ -7,14 +7,9 @@
7
7
  const Queue = require("./util/Queue");
8
8
 
9
9
  const addToSet = (a, b) => {
10
- let changed = false;
11
10
  for (const item of b) {
12
- if (!a.has(item)) {
13
- a.add(item);
14
- changed = true;
15
- }
11
+ a.add(item);
16
12
  }
17
- return changed;
18
13
  };
19
14
 
20
15
  class FlagDependencyExportsPlugin {
@@ -61,14 +56,11 @@ class FlagDependencyExportsPlugin {
61
56
  // break if it should move to the worst state
62
57
  if (exports === true) {
63
58
  module.buildMeta.providedExports = true;
64
- notifyDependencies();
65
59
  return true;
66
60
  }
67
61
  // merge in new exports
68
62
  if (Array.isArray(exports)) {
69
- if (addToSet(moduleProvidedExports, exports)) {
70
- notifyDependencies();
71
- }
63
+ addToSet(moduleProvidedExports, exports);
72
64
  }
73
65
  // store dependencies
74
66
  const exportDeps = exportDesc.dependencies;
@@ -96,6 +88,26 @@ class FlagDependencyExportsPlugin {
96
88
  }
97
89
  };
98
90
 
91
+ const notifyDependenciesIfDifferent = (set, array) => {
92
+ const deps = dependencies.get(module);
93
+ if (deps !== undefined) {
94
+ if (set.size === array.length) {
95
+ let i = 0;
96
+ let different = false;
97
+ for (const item of set) {
98
+ if (item !== array[i++]) {
99
+ different = true;
100
+ break;
101
+ }
102
+ }
103
+ if (!different) return;
104
+ }
105
+ for (const dep of deps) {
106
+ queue.enqueue(dep);
107
+ }
108
+ }
109
+ };
110
+
99
111
  // Start with all modules without provided exports
100
112
  for (const module of modules) {
101
113
  if (module.buildInfo.temporaryProvidedExports) {
@@ -114,18 +126,25 @@ class FlagDependencyExportsPlugin {
114
126
  if (module.buildMeta.providedExports !== true) {
115
127
  moduleWithExports =
116
128
  module.buildMeta && module.buildMeta.exportsType;
117
- moduleProvidedExports = Array.isArray(
118
- module.buildMeta.providedExports
119
- )
120
- ? new Set(module.buildMeta.providedExports)
121
- : new Set();
129
+ moduleProvidedExports = new Set();
122
130
  providedExportsAreTemporary = false;
123
131
  processDependenciesBlock(module);
124
132
  module.buildInfo.temporaryProvidedExports = providedExportsAreTemporary;
125
133
  if (!moduleWithExports) {
134
+ notifyDependencies();
126
135
  module.buildMeta.providedExports = true;
136
+ } else if (module.buildMeta.providedExports === true) {
137
+ notifyDependencies();
138
+ } else if (!module.buildMeta.providedExports) {
127
139
  notifyDependencies();
128
- } else if (module.buildMeta.providedExports !== true) {
140
+ module.buildMeta.providedExports = Array.from(
141
+ moduleProvidedExports
142
+ );
143
+ } else {
144
+ notifyDependenciesIfDifferent(
145
+ moduleProvidedExports,
146
+ module.buildMeta.providedExports
147
+ );
129
148
  module.buildMeta.providedExports = Array.from(
130
149
  moduleProvidedExports
131
150
  );
@@ -93,7 +93,7 @@ class FlagDependencyUsagePlugin {
93
93
  };
94
94
 
95
95
  for (const module of modules) {
96
- module.used = false;
96
+ if (!module.used) module.used = false;
97
97
  }
98
98
 
99
99
  /** @type {[Module, DependenciesBlock, UsedExports][]} */
@@ -2,7 +2,17 @@
2
2
  MIT License http://www.opensource.org/licenses/mit-license.php
3
3
  Author Tobias Koppers @sokra
4
4
  */
5
- /*global $hash$ $requestTimeout$ installedModules $require$ hotDownloadManifest hotDownloadUpdateChunk hotDisposeChunk modules */
5
+ // eslint-disable no-unused-vars
6
+ var $hash$ = undefined;
7
+ var $requestTimeout$ = undefined;
8
+ var installedModules = undefined;
9
+ var $require$ = undefined;
10
+ var hotDownloadManifest = undefined;
11
+ var hotDownloadUpdateChunk = undefined;
12
+ var hotDisposeChunk = undefined;
13
+ var modules = undefined;
14
+ var chunkId = undefined;
15
+
6
16
  module.exports = function() {
7
17
  var hotApplyOnUpdate = true;
8
18
  // eslint-disable-next-line no-unused-vars
@@ -204,7 +214,6 @@ module.exports = function() {
204
214
  /*foreachInstalledChunks*/
205
215
  // eslint-disable-next-line no-lone-blocks
206
216
  {
207
- /*globals chunkId */
208
217
  hotEnsureUpdateChunk(chunkId);
209
218
  }
210
219
  if (
package/lib/Parser.js CHANGED
@@ -1229,7 +1229,7 @@ class Parser extends Tapable {
1229
1229
  this.walkPattern(param);
1230
1230
  }
1231
1231
  if (statement.body.type === "BlockStatement") {
1232
- this.detectStrictMode(statement.body.body);
1232
+ this.detectMode(statement.body.body);
1233
1233
  this.prewalkStatement(statement.body);
1234
1234
  this.walkStatement(statement.body);
1235
1235
  } else {
@@ -1697,7 +1697,7 @@ class Parser extends Tapable {
1697
1697
  this.walkPattern(param);
1698
1698
  }
1699
1699
  if (expression.body.type === "BlockStatement") {
1700
- this.detectStrictMode(expression.body.body);
1700
+ this.detectMode(expression.body.body);
1701
1701
  this.prewalkStatement(expression.body);
1702
1702
  this.walkStatement(expression.body);
1703
1703
  } else {
@@ -1713,7 +1713,7 @@ class Parser extends Tapable {
1713
1713
  this.walkPattern(param);
1714
1714
  }
1715
1715
  if (expression.body.type === "BlockStatement") {
1716
- this.detectStrictMode(expression.body.body);
1716
+ this.detectMode(expression.body.body);
1717
1717
  this.prewalkStatement(expression.body);
1718
1718
  this.walkStatement(expression.body);
1719
1719
  } else {
@@ -1894,6 +1894,7 @@ class Parser extends Tapable {
1894
1894
  this.scope.renames.set(params[i].name, param);
1895
1895
  }
1896
1896
  if (functionExpression.body.type === "BlockStatement") {
1897
+ this.detectMode(functionExpression.body.body);
1897
1898
  this.prewalkStatement(functionExpression.body);
1898
1899
  this.walkStatement(functionExpression.body);
1899
1900
  } else {
@@ -2001,6 +2002,7 @@ class Parser extends Tapable {
2001
2002
  inTry: false,
2002
2003
  inShorthand: false,
2003
2004
  isStrict: oldScope.isStrict,
2005
+ isAsmJs: oldScope.isAsmJs,
2004
2006
  definitions: oldScope.definitions.createChild(),
2005
2007
  renames: oldScope.renames.createChild()
2006
2008
  };
@@ -2024,6 +2026,7 @@ class Parser extends Tapable {
2024
2026
  inTry: false,
2025
2027
  inShorthand: false,
2026
2028
  isStrict: oldScope.isStrict,
2029
+ isAsmJs: oldScope.isAsmJs,
2027
2030
  definitions: oldScope.definitions.createChild(),
2028
2031
  renames: oldScope.renames.createChild()
2029
2032
  };
@@ -2049,6 +2052,7 @@ class Parser extends Tapable {
2049
2052
  inTry: oldScope.inTry,
2050
2053
  inShorthand: false,
2051
2054
  isStrict: oldScope.isStrict,
2055
+ isAsmJs: oldScope.isAsmJs,
2052
2056
  definitions: oldScope.definitions.createChild(),
2053
2057
  renames: oldScope.renames.createChild()
2054
2058
  };
@@ -2058,15 +2062,23 @@ class Parser extends Tapable {
2058
2062
  this.scope = oldScope;
2059
2063
  }
2060
2064
 
2065
+ // TODO webpack 5: remove this methods
2066
+ // only for backward-compat
2061
2067
  detectStrictMode(statements) {
2062
- const isStrict =
2068
+ this.detectMode(statements);
2069
+ }
2070
+
2071
+ detectMode(statements) {
2072
+ const isLiteral =
2063
2073
  statements.length >= 1 &&
2064
2074
  statements[0].type === "ExpressionStatement" &&
2065
- statements[0].expression.type === "Literal" &&
2066
- statements[0].expression.value === "use strict";
2067
- if (isStrict) {
2075
+ statements[0].expression.type === "Literal";
2076
+ if (isLiteral && statements[0].expression.value === "use strict") {
2068
2077
  this.scope.isStrict = true;
2069
2078
  }
2079
+ if (isLiteral && statements[0].expression.value === "use asm") {
2080
+ this.scope.isAsmJs = true;
2081
+ }
2070
2082
  }
2071
2083
 
2072
2084
  enterPatterns(patterns, onIdent) {
@@ -2272,13 +2284,14 @@ class Parser extends Tapable {
2272
2284
  inTry: false,
2273
2285
  inShorthand: false,
2274
2286
  isStrict: false,
2287
+ isAsmJs: false,
2275
2288
  definitions: new StackedSetMap(),
2276
2289
  renames: new StackedSetMap()
2277
2290
  };
2278
2291
  const state = (this.state = initialState || {});
2279
2292
  this.comments = comments;
2280
2293
  if (this.hooks.program.call(ast, comments) === undefined) {
2281
- this.detectStrictMode(ast.body);
2294
+ this.detectMode(ast.body);
2282
2295
  this.prewalkStatements(ast.body);
2283
2296
  this.blockPrewalkStatements(ast.body);
2284
2297
  this.walkStatements(ast.body);
@@ -62,9 +62,10 @@ class ProvidePlugin {
62
62
  return false;
63
63
  }
64
64
  if (scopedName) {
65
- ParserHelpers.toConstantDependency(parser, nameIdentifier)(
66
- expr
67
- );
65
+ ParserHelpers.toConstantDependency(
66
+ parser,
67
+ nameIdentifier
68
+ )(expr);
68
69
  }
69
70
  return true;
70
71
  });
@@ -9,6 +9,7 @@ const { ConcatSource, RawSource } = require("webpack-sources");
9
9
  const ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
10
10
  const SourceMapDevToolModuleOptionsPlugin = require("./SourceMapDevToolModuleOptionsPlugin");
11
11
  const createHash = require("./util/createHash");
12
+ const { absolutify } = require("./util/identifier");
12
13
 
13
14
  const validateOptions = require("schema-utils");
14
15
  const schema = require("../schemas/plugins/SourceMapDevToolPlugin.json");
@@ -68,16 +69,24 @@ const getTaskForFile = (file, asset, chunk, options, compilation) => {
68
69
  sourceMap = asset.map(options);
69
70
  source = asset.source();
70
71
  }
71
- if (sourceMap) {
72
- return {
73
- chunk,
74
- file,
75
- asset,
76
- source,
77
- sourceMap,
78
- modules: undefined
79
- };
80
- }
72
+ if (!sourceMap || typeof source !== "string") return;
73
+ const context = compilation.options.context;
74
+ const modules = sourceMap.sources.map(source => {
75
+ if (source.startsWith("webpack://")) {
76
+ source = absolutify(context, source.slice(10));
77
+ }
78
+ const module = compilation.findModule(source);
79
+ return module || source;
80
+ });
81
+
82
+ return {
83
+ chunk,
84
+ file,
85
+ asset,
86
+ source,
87
+ sourceMap,
88
+ modules
89
+ };
81
90
  };
82
91
 
83
92
  class SourceMapDevToolPlugin {
@@ -212,10 +221,7 @@ class SourceMapDevToolPlugin {
212
221
  );
213
222
 
214
223
  if (task) {
215
- const modules = task.sourceMap.sources.map(source => {
216
- const module = compilation.findModule(source);
217
- return module || source;
218
- });
224
+ const modules = task.modules;
219
225
 
220
226
  for (let idx = 0; idx < modules.length; idx++) {
221
227
  const module = modules[idx];
@@ -234,8 +240,6 @@ class SourceMapDevToolPlugin {
234
240
  }
235
241
  }
236
242
 
237
- task.modules = modules;
238
-
239
243
  tasks.push(task);
240
244
  }
241
245
  });
@@ -304,9 +304,13 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
304
304
  }
305
305
 
306
306
  if (Array.isArray(importedModule.buildMeta.providedExports)) {
307
+ const activeFromOtherStarExports = this._discoverActiveExportsFromOtherStartExports();
307
308
  return {
308
309
  exports: importedModule.buildMeta.providedExports.filter(
309
- id => id !== "default"
310
+ id =>
311
+ id !== "default" &&
312
+ !activeFromOtherStarExports.has(id) &&
313
+ !this.activeExports.has(id)
310
314
  ),
311
315
  dependencies: [importedModule]
312
316
  };
@@ -5,34 +5,31 @@
5
5
 
6
6
  "use strict";
7
7
 
8
- /**
9
- * @enum {string}
10
- */
11
8
  const LogType = Object.freeze({
12
- error: "error", // message, c style arguments
13
- warn: "warn", // message, c style arguments
14
- info: "info", // message, c style arguments
15
- log: "log", // message, c style arguments
16
- debug: "debug", // message, c style arguments
9
+ error: /** @type {"error"} */ ("error"), // message, c style arguments
10
+ warn: /** @type {"warn"} */ ("warn"), // message, c style arguments
11
+ info: /** @type {"info"} */ ("info"), // message, c style arguments
12
+ log: /** @type {"log"} */ ("log"), // message, c style arguments
13
+ debug: /** @type {"debug"} */ ("debug"), // message, c style arguments
17
14
 
18
- trace: "trace", // no arguments
15
+ trace: /** @type {"trace"} */ ("trace"), // no arguments
19
16
 
20
- group: "group", // [label]
21
- groupCollapsed: "groupCollapsed", // [label]
22
- groupEnd: "groupEnd", // [label]
17
+ group: /** @type {"group"} */ ("group"), // [label]
18
+ groupCollapsed: /** @type {"groupCollapsed"} */ ("groupCollapsed"), // [label]
19
+ groupEnd: /** @type {"groupEnd"} */ ("groupEnd"), // [label]
23
20
 
24
- profile: "profile", // [profileName]
25
- profileEnd: "profileEnd", // [profileName]
21
+ profile: /** @type {"profile"} */ ("profile"), // [profileName]
22
+ profileEnd: /** @type {"profileEnd"} */ ("profileEnd"), // [profileName]
26
23
 
27
- time: "time", // name, time as [seconds, nanoseconds]
24
+ time: /** @type {"time"} */ ("time"), // name, time as [seconds, nanoseconds]
28
25
 
29
- clear: "clear", // no arguments
30
- status: "status" // message, arguments
26
+ clear: /** @type {"clear"} */ ("clear"), // no arguments
27
+ status: /** @type {"status"} */ ("status") // message, arguments
31
28
  });
32
29
 
33
30
  exports.LogType = LogType;
34
31
 
35
- /** @typedef {keyof typeof LogType} LogTypeEnum */
32
+ /** @typedef {typeof LogType[keyof typeof LogType]} LogTypeEnum */
36
33
 
37
34
  const LOG_SYMBOL = Symbol("webpack logger raw log method");
38
35
  const TIMERS_SYMBOL = Symbol("webpack logger times");
@@ -2,7 +2,12 @@
2
2
  MIT License http://www.opensource.org/licenses/mit-license.php
3
3
  Author Tobias Koppers @sokra
4
4
  */
5
- /*global installedChunks $hotChunkFilename$ hotAddUpdateChunk $hotMainFilename$ */
5
+ // eslint-disable-next-line no-unused-vars
6
+ var $hotChunkFilename$ = undefined;
7
+ var hotAddUpdateChunk = undefined;
8
+ var installedChunks = undefined;
9
+ var $hotMainFilename$ = undefined;
10
+
6
11
  module.exports = function() {
7
12
  // eslint-disable-next-line no-unused-vars
8
13
  function hotDownloadUpdateChunk(chunkId) {
@@ -2,7 +2,13 @@
2
2
  MIT License http://www.opensource.org/licenses/mit-license.php
3
3
  Author Tobias Koppers @sokra
4
4
  */
5
- /*global installedChunks $hotChunkFilename$ $require$ hotAddUpdateChunk $hotMainFilename$ */
5
+ // eslint-disable-next-line no-unused-vars
6
+ var $hotChunkFilename$ = undefined;
7
+ var $require$ = undefined;
8
+ var hotAddUpdateChunk = undefined;
9
+ var $hotMainFilename$ = undefined;
10
+ var installedChunks = undefined;
11
+
6
12
  module.exports = function() {
7
13
  // eslint-disable-next-line no-unused-vars
8
14
  function hotDownloadUpdateChunk(chunkId) {
@@ -22,6 +22,23 @@ const createHash = require("../util/createHash");
22
22
  /** @typedef {import("../Dependency")} Dependency */
23
23
  /** @typedef {import("../Compilation")} Compilation */
24
24
  /** @typedef {import("../util/createHash").Hash} Hash */
25
+ /** @typedef {import("../RequestShortener")} RequestShortener */
26
+
27
+ const joinIterableWithComma = iterable => {
28
+ // This is more performant than Array.from().join(", ")
29
+ // as it doesn't create an array
30
+ let str = "";
31
+ let first = true;
32
+ for (const item of iterable) {
33
+ if (first) {
34
+ first = false;
35
+ } else {
36
+ str += ", ";
37
+ }
38
+ str += item;
39
+ }
40
+ return str;
41
+ };
25
42
 
26
43
  /**
27
44
  * @typedef {Object} ConcatenationEntry
@@ -287,6 +304,41 @@ const getPathInAst = (ast, node) => {
287
304
  }
288
305
  };
289
306
 
307
+ const getHarmonyExportImportedSpecifierDependencyExports = dep => {
308
+ const importModule = dep._module;
309
+ if (!importModule) return [];
310
+ if (dep._id) {
311
+ // export { named } from "module"
312
+ return [
313
+ {
314
+ name: dep.name,
315
+ id: dep._id,
316
+ module: importModule
317
+ }
318
+ ];
319
+ }
320
+ if (dep.name) {
321
+ // export * as abc from "module"
322
+ return [
323
+ {
324
+ name: dep.name,
325
+ id: true,
326
+ module: importModule
327
+ }
328
+ ];
329
+ }
330
+ // export * from "module"
331
+ return importModule.buildMeta.providedExports
332
+ .filter(exp => exp !== "default" && !dep.activeExports.has(exp))
333
+ .map(exp => {
334
+ return {
335
+ name: exp,
336
+ id: exp,
337
+ module: importModule
338
+ };
339
+ });
340
+ };
341
+
290
342
  class ConcatenatedModule extends Module {
291
343
  constructor(rootModule, modules, concatenationList) {
292
344
  super("javascript/esm", null);
@@ -626,10 +678,7 @@ class ConcatenatedModule extends Module {
626
678
  );
627
679
  innerDependencyTemplates.set(
628
680
  HarmonyExportSpecifierDependency,
629
- new HarmonyExportSpecifierDependencyConcatenatedTemplate(
630
- dependencyTemplates.get(HarmonyExportSpecifierDependency),
631
- this.rootModule
632
- )
681
+ new NullTemplate()
633
682
  );
634
683
  innerDependencyTemplates.set(
635
684
  HarmonyExportExpressionDependency,
@@ -640,19 +689,11 @@ class ConcatenatedModule extends Module {
640
689
  );
641
690
  innerDependencyTemplates.set(
642
691
  HarmonyExportImportedSpecifierDependency,
643
- new HarmonyExportImportedSpecifierDependencyConcatenatedTemplate(
644
- dependencyTemplates.get(HarmonyExportImportedSpecifierDependency),
645
- this.rootModule,
646
- moduleToInfoMap
647
- )
692
+ new NullTemplate()
648
693
  );
649
694
  innerDependencyTemplates.set(
650
695
  HarmonyCompatibilityDependency,
651
- new HarmonyCompatibilityDependencyConcatenatedTemplate(
652
- dependencyTemplates.get(HarmonyCompatibilityDependency),
653
- this.rootModule,
654
- moduleToInfoMap
655
- )
696
+ new NullTemplate()
656
697
  );
657
698
 
658
699
  // Must use full identifier in our cache here to ensure that the source
@@ -1105,11 +1146,62 @@ class ConcatenatedModule extends Module {
1105
1146
  }
1106
1147
  }
1107
1148
 
1149
+ // Map with all root exposed used exports
1150
+ /** @type {Map<string, function(RequestShortener): string>} */
1151
+ const exportsMap = new Map();
1152
+
1153
+ // Set with all root exposed unused exports
1154
+ /** @type {Set<string>} */
1155
+ const unusedExports = new Set();
1156
+
1157
+ for (const dep of this.rootModule.dependencies) {
1158
+ if (dep instanceof HarmonyExportSpecifierDependency) {
1159
+ const used = this.rootModule.isUsed(dep.name);
1160
+ if (used) {
1161
+ const info = moduleToInfoMap.get(this.rootModule);
1162
+ if (!exportsMap.has(used)) {
1163
+ exportsMap.set(
1164
+ used,
1165
+ () => `/* binding */ ${info.internalNames.get(dep.id)}`
1166
+ );
1167
+ }
1168
+ } else {
1169
+ unusedExports.add(dep.name || "namespace");
1170
+ }
1171
+ } else if (dep instanceof HarmonyExportImportedSpecifierDependency) {
1172
+ const exportDefs = getHarmonyExportImportedSpecifierDependencyExports(
1173
+ dep
1174
+ );
1175
+ for (const def of exportDefs) {
1176
+ const info = moduleToInfoMap.get(def.module);
1177
+ const used = dep.originModule.isUsed(def.name);
1178
+ if (used) {
1179
+ if (!exportsMap.has(used)) {
1180
+ exportsMap.set(used, requestShortener => {
1181
+ const finalName = getFinalName(
1182
+ info,
1183
+ def.id,
1184
+ moduleToInfoMap,
1185
+ requestShortener,
1186
+ false,
1187
+ this.rootModule.buildMeta.strictHarmonyModule
1188
+ );
1189
+ return `/* reexport */ ${finalName}`;
1190
+ });
1191
+ }
1192
+ } else {
1193
+ unusedExports.add(def.name);
1194
+ }
1195
+ }
1196
+ }
1197
+ }
1198
+
1108
1199
  const result = new ConcatSource();
1109
1200
 
1110
1201
  // add harmony compatibility flag (must be first because of possible circular dependencies)
1111
1202
  const usedExports = this.rootModule.usedExports;
1112
1203
  if (usedExports === true || usedExports === null) {
1204
+ result.add(`// ESM COMPAT FLAG\n`);
1113
1205
  result.add(
1114
1206
  runtimeTemplate.defineEsModuleFlagStatement({
1115
1207
  exportsArgument: this.exportsArgument
@@ -1117,9 +1209,33 @@ class ConcatenatedModule extends Module {
1117
1209
  );
1118
1210
  }
1119
1211
 
1212
+ // define exports
1213
+ if (exportsMap.size > 0) {
1214
+ result.add(`\n// EXPORTS\n`);
1215
+ for (const [key, value] of exportsMap) {
1216
+ result.add(
1217
+ `__webpack_require__.d(${this.exportsArgument}, ${JSON.stringify(
1218
+ key
1219
+ )}, function() { return ${value(requestShortener)}; });\n`
1220
+ );
1221
+ }
1222
+ }
1223
+
1224
+ // list unused exports
1225
+ if (unusedExports.size > 0) {
1226
+ result.add(
1227
+ `\n// UNUSED EXPORTS: ${joinIterableWithComma(unusedExports)}\n`
1228
+ );
1229
+ }
1230
+
1120
1231
  // define required namespace objects (must be before evaluation modules)
1121
1232
  for (const info of modulesWithInfo) {
1122
1233
  if (info.namespaceObjectSource) {
1234
+ result.add(
1235
+ `\n// NAMESPACE OBJECT: ${info.module.readableIdentifier(
1236
+ requestShortener
1237
+ )}\n`
1238
+ );
1123
1239
  result.add(info.namespaceObjectSource);
1124
1240
  }
1125
1241
  }
@@ -1321,38 +1437,6 @@ class HarmonyImportSideEffectDependencyConcatenatedTemplate {
1321
1437
  }
1322
1438
  }
1323
1439
 
1324
- class HarmonyExportSpecifierDependencyConcatenatedTemplate {
1325
- constructor(originalTemplate, rootModule) {
1326
- this.originalTemplate = originalTemplate;
1327
- this.rootModule = rootModule;
1328
- }
1329
-
1330
- getHarmonyInitOrder(dep) {
1331
- if (dep.originModule === this.rootModule) {
1332
- return this.originalTemplate.getHarmonyInitOrder(dep);
1333
- }
1334
- return NaN;
1335
- }
1336
-
1337
- harmonyInit(dep, source, runtime, dependencyTemplates) {
1338
- if (dep.originModule === this.rootModule) {
1339
- this.originalTemplate.harmonyInit(
1340
- dep,
1341
- source,
1342
- runtime,
1343
- dependencyTemplates
1344
- );
1345
- return;
1346
- }
1347
- }
1348
-
1349
- apply(dep, source, runtime, dependencyTemplates) {
1350
- if (dep.originModule === this.rootModule) {
1351
- this.originalTemplate.apply(dep, source, runtime, dependencyTemplates);
1352
- }
1353
- }
1354
- }
1355
-
1356
1440
  class HarmonyExportExpressionDependencyConcatenatedTemplate {
1357
1441
  constructor(originalTemplate, rootModule) {
1358
1442
  this.originalTemplate = originalTemplate;
@@ -1386,119 +1470,8 @@ class HarmonyExportExpressionDependencyConcatenatedTemplate {
1386
1470
  }
1387
1471
  }
1388
1472
 
1389
- class HarmonyExportImportedSpecifierDependencyConcatenatedTemplate {
1390
- constructor(originalTemplate, rootModule, modulesMap) {
1391
- this.originalTemplate = originalTemplate;
1392
- this.rootModule = rootModule;
1393
- this.modulesMap = modulesMap;
1394
- }
1395
-
1396
- getExports(dep) {
1397
- const importModule = dep._module;
1398
- if (dep._id) {
1399
- // export { named } from "module"
1400
- return [
1401
- {
1402
- name: dep.name,
1403
- id: dep._id,
1404
- module: importModule
1405
- }
1406
- ];
1407
- }
1408
- if (dep.name) {
1409
- // export * as abc from "module"
1410
- return [
1411
- {
1412
- name: dep.name,
1413
- id: true,
1414
- module: importModule
1415
- }
1416
- ];
1417
- }
1418
- // export * from "module"
1419
- return importModule.buildMeta.providedExports
1420
- .filter(exp => exp !== "default" && !dep.activeExports.has(exp))
1421
- .map(exp => {
1422
- return {
1423
- name: exp,
1424
- id: exp,
1425
- module: importModule
1426
- };
1427
- });
1428
- }
1429
-
1430
- getHarmonyInitOrder(dep) {
1431
- const module = dep._module;
1432
- const info = this.modulesMap.get(module);
1433
- if (!info) {
1434
- return this.originalTemplate.getHarmonyInitOrder(dep);
1435
- }
1436
- return NaN;
1437
- }
1438
-
1439
- harmonyInit(dep, source, runtime, dependencyTemplates) {
1440
- const module = dep._module;
1441
- const info = this.modulesMap.get(module);
1442
- if (!info) {
1443
- this.originalTemplate.harmonyInit(
1444
- dep,
1445
- source,
1446
- runtime,
1447
- dependencyTemplates
1448
- );
1449
- return;
1450
- }
1451
- }
1452
-
1453
- apply(dep, source, runtime, dependencyTemplates) {
1454
- if (dep.originModule === this.rootModule) {
1455
- if (this.modulesMap.get(dep._module)) {
1456
- const exportDefs = this.getExports(dep);
1457
- for (const def of exportDefs) {
1458
- const info = this.modulesMap.get(def.module);
1459
- const used = dep.originModule.isUsed(def.name);
1460
- if (!used) {
1461
- source.insert(
1462
- -1,
1463
- `/* unused concated harmony import ${def.name} */\n`
1464
- );
1465
- continue;
1466
- }
1467
- let finalName;
1468
- const strictFlag = dep.originModule.buildMeta.strictHarmonyModule
1469
- ? "_strict"
1470
- : "";
1471
- if (def.id === true) {
1472
- finalName = `__WEBPACK_MODULE_REFERENCE__${info.index}_ns${strictFlag}__`;
1473
- } else {
1474
- const exportData = Buffer.from(def.id, "utf-8").toString("hex");
1475
- finalName = `__WEBPACK_MODULE_REFERENCE__${info.index}_${exportData}${strictFlag}__`;
1476
- }
1477
- const exportsName = this.rootModule.exportsArgument;
1478
- const content =
1479
- `/* concated harmony reexport ${def.name} */` +
1480
- `__webpack_require__.d(${exportsName}, ` +
1481
- `${JSON.stringify(used)}, ` +
1482
- `function() { return ${finalName}; });\n`;
1483
- source.insert(-1, content);
1484
- }
1485
- } else {
1486
- this.originalTemplate.apply(dep, source, runtime, dependencyTemplates);
1487
- }
1488
- }
1489
- }
1490
- }
1491
-
1492
- class HarmonyCompatibilityDependencyConcatenatedTemplate {
1493
- constructor(originalTemplate, rootModule, modulesMap) {
1494
- this.originalTemplate = originalTemplate;
1495
- this.rootModule = rootModule;
1496
- this.modulesMap = modulesMap;
1497
- }
1498
-
1499
- apply(dep, source, runtime, dependencyTemplates) {
1500
- // do nothing
1501
- }
1473
+ class NullTemplate {
1474
+ apply() {}
1502
1475
  }
1503
1476
 
1504
1477
  module.exports = ConcatenatedModule;
@@ -1,6 +1,17 @@
1
1
  "use strict";
2
2
  const path = require("path");
3
3
 
4
+ /**
5
+ * @param {string} context context for relative path
6
+ * @param {string} relativePath path
7
+ * @returns {string} absolute path
8
+ */
9
+ const requestToAbsolute = (context, relativePath) => {
10
+ if (relativePath.startsWith("./") || relativePath.startsWith("../"))
11
+ return path.join(context, relativePath);
12
+ return relativePath;
13
+ };
14
+
4
15
  /**
5
16
  * @typedef {Object} MakeRelativePathsCache
6
17
  * @property {Map<string, Map<string, string>>=} relativePaths
@@ -100,3 +111,17 @@ exports.contextify = (context, request) => {
100
111
  })
101
112
  .join("!");
102
113
  };
114
+
115
+ /**
116
+ * @param {string} context absolute context path
117
+ * @param {string} request any request string
118
+ * @returns {string} a new request string using absolute paths when possible
119
+ */
120
+ const _absolutify = (context, request) => {
121
+ return request
122
+ .split("!")
123
+ .map(r => requestToAbsolute(context, r))
124
+ .join("!");
125
+ };
126
+
127
+ exports.absolutify = _absolutify;
@@ -2,7 +2,14 @@
2
2
  MIT License http://www.opensource.org/licenses/mit-license.php
3
3
  Author Tobias Koppers @sokra
4
4
  */
5
- /*globals hotAddUpdateChunk parentHotUpdateCallback document XMLHttpRequest $require$ $hotChunkFilename$ $hotMainFilename$ $crossOriginLoading$ */
5
+ // eslint-disable-next-line no-unused-vars
6
+ var hotAddUpdateChunk = undefined;
7
+ var parentHotUpdateCallback = undefined;
8
+ var $require$ = undefined;
9
+ var $hotMainFilename$ = undefined;
10
+ var $hotChunkFilename$ = undefined;
11
+ var $crossOriginLoading$ = undefined;
12
+
6
13
  module.exports = function() {
7
14
  // eslint-disable-next-line no-unused-vars
8
15
  function webpackHotUpdateCallback(chunkId, moreModules) {
@@ -2,7 +2,15 @@
2
2
  MIT License http://www.opensource.org/licenses/mit-license.php
3
3
  Author Tobias Koppers @sokra
4
4
  */
5
- /*globals installedChunks hotAddUpdateChunk parentHotUpdateCallback importScripts XMLHttpRequest $require$ $hotChunkFilename$ $hotMainFilename$ */
5
+ // eslint-disable-next-line no-unused-vars
6
+ var hotAddUpdateChunk = undefined;
7
+ var parentHotUpdateCallback = undefined;
8
+ var $require$ = undefined;
9
+ var $hotChunkFilename$ = undefined;
10
+ var $hotMainFilename$ = undefined;
11
+ var installedChunks = undefined;
12
+ var importScripts = undefined;
13
+
6
14
  module.exports = function() {
7
15
  // eslint-disable-next-line no-unused-vars
8
16
  function webpackHotUpdateCallback(chunkId, moreModules) {
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "webpack",
3
- "version": "4.41.4",
3
+ "version": "4.42.1",
4
4
  "author": "Tobias Koppers @sokra",
5
5
  "description": "Packs CommonJs/AMD modules for the browser. Allows to split your codebase into multiple bundles, which can be loaded on demand. Support loaders to preprocess files, i.e. json, jsx, es7, css, less, ... and your custom stuff.",
6
6
  "license": "MIT",
7
7
  "dependencies": {
8
- "@webassemblyjs/ast": "1.8.5",
9
- "@webassemblyjs/helper-module-context": "1.8.5",
10
- "@webassemblyjs/wasm-edit": "1.8.5",
11
- "@webassemblyjs/wasm-parser": "1.8.5",
8
+ "@webassemblyjs/ast": "1.9.0",
9
+ "@webassemblyjs/helper-module-context": "1.9.0",
10
+ "@webassemblyjs/wasm-edit": "1.9.0",
11
+ "@webassemblyjs/wasm-parser": "1.9.0",
12
12
  "acorn": "^6.2.1",
13
13
  "ajv": "^6.10.2",
14
14
  "ajv-keywords": "^3.4.1",
@@ -20,7 +20,7 @@
20
20
  "loader-utils": "^1.2.3",
21
21
  "memory-fs": "^0.4.1",
22
22
  "micromatch": "^3.1.10",
23
- "mkdirp": "^0.5.1",
23
+ "mkdirp": "^0.5.3",
24
24
  "neo-async": "^2.6.1",
25
25
  "node-libs-browser": "^2.2.1",
26
26
  "schema-utils": "^1.0.0",
@@ -30,10 +30,12 @@
30
30
  "webpack-sources": "^1.4.1"
31
31
  },
32
32
  "devDependencies": {
33
+ "@babel/core": "^7.7.2",
33
34
  "@types/node": "^10.12.21",
34
35
  "@types/tapable": "^1.0.1",
35
36
  "@types/webpack-sources": "^0.1.4",
36
37
  "@yarnpkg/lockfile": "^1.1.0",
38
+ "babel-loader": "^8.0.6",
37
39
  "benchmark": "^2.1.1",
38
40
  "bundle-loader": "~0.5.0",
39
41
  "coffee-loader": "^0.9.0",
@@ -78,6 +80,7 @@
78
80
  "vm-browserify": "~1.1.0",
79
81
  "wast-loader": "^1.5.5",
80
82
  "webpack-dev-middleware": "^3.5.1",
83
+ "webassembly-feature": "1.3.0",
81
84
  "worker-loader": "^2.0.0",
82
85
  "xxhashjs": "^0.2.1"
83
86
  },
@@ -940,16 +940,8 @@
940
940
  },
941
941
  "hotUpdateChunkFilename": {
942
942
  "description": "The filename of the Hot Update Chunks. They are inside the output.path directory.",
943
- "anyOf": [
944
- {
945
- "type": "string",
946
- "absolutePath": false
947
- },
948
- {
949
- "instanceof": "Function",
950
- "tsType": "Function"
951
- }
952
- ]
943
+ "type": "string",
944
+ "absolutePath": false
953
945
  },
954
946
  "hotUpdateFunction": {
955
947
  "description": "The JSONP function used by webpack for async loading of hot update chunks.",
@@ -1428,8 +1420,7 @@
1428
1420
  "$ref": "#/definitions/RuleSetCondition"
1429
1421
  }
1430
1422
  ]
1431
- },
1432
- "tsType": "RuleSetConditionsRecursive"
1423
+ }
1433
1424
  },
1434
1425
  "RuleSetConditionsAbsolute": {
1435
1426
  "type": "array",
@@ -1440,8 +1431,7 @@
1440
1431
  "$ref": "#/definitions/RuleSetConditionAbsolute"
1441
1432
  }
1442
1433
  ]
1443
- },
1444
- "tsType": "RuleSetConditionsAbsoluteRecursive"
1434
+ }
1445
1435
  },
1446
1436
  "RuleSetLoader": {
1447
1437
  "type": "string",
@@ -25,8 +25,6 @@ module.exports = ajv =>
25
25
  function callback(data) {
26
26
  let passes = true;
27
27
  const isExclamationMarkPresent = data.includes("!");
28
- const isCorrectAbsoluteOrRelativePath =
29
- expected === /^(?:[A-Za-z]:\\|\/)/.test(data);
30
28
 
31
29
  if (isExclamationMarkPresent) {
32
30
  callback.errors = [
@@ -40,8 +38,12 @@ module.exports = ajv =>
40
38
  ];
41
39
  passes = false;
42
40
  }
43
-
44
- if (!isCorrectAbsoluteOrRelativePath) {
41
+ // ?:[A-Za-z]:\\ - Windows absolute path
42
+ // \\\\ - Windows network absolute path
43
+ // \/ - Unix-like OS absolute path
44
+ const isCorrectAbsolutePath =
45
+ expected === /^(?:[A-Za-z]:\\|\\\\|\/)/.test(data);
46
+ if (!isCorrectAbsolutePath) {
45
47
  callback.errors = [getErrorFor(expected, data, schema)];
46
48
  passes = false;
47
49
  }