webpack 4.17.3 → 4.19.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.
package/README.md CHANGED
@@ -221,7 +221,7 @@ or are automatically applied via regex from your webpack configuration.
221
221
  |<a href="https://github.com/webpack/style-loader">`<style>`</a>|![style-npm]|![style-size]|Add exports of a module as style to DOM|
222
222
  |<a href="https://github.com/webpack/css-loader"><img width="48" height="48" src="https://worldvectorlogo.com/logos/css-3.svg"></a>|![css-npm]|![css-size]|Loads CSS file with resolved imports and returns CSS code|
223
223
  |<a href="https://github.com/webpack/less-loader"><img width="48" height="48" src="https://worldvectorlogo.com/logos/less-63.svg"></a>|![less-npm]|![less-size]|Loads and compiles a LESS file|
224
- |<a href="https://github.com/jtangelder/sass-loader"><img width="48" height="48" src="https://worldvectorlogo.com/logos/sass-1.svg"></a>|![sass-npm]|![sass-size]|Loads and compiles a SASS/SCSS file|
224
+ |<a href="https://github.com/jtangelder/sass-loader"><img width="48" height="48" src="https://worldvectorlogo.com/logos/sass-1.svg"></a>|![sass-npm]|![sass-size]|Loads and compiles a Sass/SCSS file|
225
225
  |<a href="https://github.com/shama/stylus-loader"><img width="48" height="48" src="https://worldvectorlogo.com/logos/stylus.svg"></a>|![stylus-npm]|![stylus-size]|Loads and compiles a Stylus file|
226
226
  |<a href="https://github.com/postcss/postcss-loader"><img width="48" height="48" src="https://worldvectorlogo.com/logos/postcss.svg"></a>|![postcss-npm]|![postcss-size]|Loads and transforms a CSS/SSS file using [PostCSS](http://postcss.org)|
227
227
 
@@ -9,6 +9,7 @@ const { Tapable, SyncWaterfallHook, SyncHook } = require("tapable");
9
9
  /** @typedef {import("./ModuleTemplate")} ModuleTemplate */
10
10
  /** @typedef {import("./Chunk")} Chunk */
11
11
  /** @typedef {import("./Module")} Module} */
12
+ /** @typedef {import("./Dependency").DependencyTemplate} DependencyTemplate} */
12
13
  /** @typedef {import("./util/createHash").Hash} Hash} */
13
14
 
14
15
  /**
@@ -71,12 +72,15 @@ module.exports = class ChunkTemplate extends Tapable {
71
72
  }
72
73
 
73
74
  /**
75
+ * TODO webpack 5: remove moduleTemplate and dependencyTemplates
74
76
  * Updates hash with chunk-specific information from this template
75
77
  * @param {Hash} hash the hash to update
76
78
  * @param {Chunk} chunk the chunk
79
+ * @param {ModuleTemplate} moduleTemplate ModuleTemplate instance for render
80
+ * @param {Map<Function, DependencyTemplate>} dependencyTemplates dependency templates
77
81
  * @returns {void}
78
82
  */
79
- updateHashForChunk(hash, chunk) {
83
+ updateHashForChunk(hash, chunk, moduleTemplate, dependencyTemplates) {
80
84
  this.updateHash(hash);
81
85
  this.hooks.hashForChunk.call(hash, chunk);
82
86
  }
@@ -455,9 +455,10 @@ class Compilation extends Tapable {
455
455
  this.children = [];
456
456
  /** @type {Map<DepConstructor, ModuleFactory>} */
457
457
  this.dependencyFactories = new Map();
458
- /** @type {Map<DepConstructor|string, DependencyTemplate|string>} */
458
+ /** @type {Map<DepConstructor, DependencyTemplate>} */
459
459
  this.dependencyTemplates = new Map();
460
460
  // TODO refactor this in webpack 5 to a custom DependencyTemplates class with a hash property
461
+ // @ts-ignore
461
462
  this.dependencyTemplates.set("hash", "");
462
463
  this.childrenCounters = {};
463
464
  /** @type {Set<number|string>} */
@@ -2259,7 +2260,12 @@ class Compilation extends Tapable {
2259
2260
  const template = chunk.hasRuntime()
2260
2261
  ? this.mainTemplate
2261
2262
  : this.chunkTemplate;
2262
- template.updateHashForChunk(chunkHash, chunk);
2263
+ template.updateHashForChunk(
2264
+ chunkHash,
2265
+ chunk,
2266
+ this.moduleTemplates.javascript,
2267
+ this.dependencyTemplates
2268
+ );
2263
2269
  this.hooks.chunkHash.call(chunk, chunkHash);
2264
2270
  chunk.hash = chunkHash.digest(hashDigest);
2265
2271
  hash.update(chunk.hash);
@@ -74,7 +74,9 @@ class ExternalModule extends Module {
74
74
  .slice(1)
75
75
  .map(r => `[${JSON.stringify(r)}]`)
76
76
  .join("");
77
- return `module.exports = require(${moduleName})${objectLookup};`;
77
+ return `module.exports = require(${JSON.stringify(
78
+ moduleName
79
+ )})${objectLookup};`;
78
80
  }
79
81
 
80
82
  checkExternalVariable(variableToCheck, request) {
@@ -94,15 +96,25 @@ class ExternalModule extends Module {
94
96
  }
95
97
 
96
98
  getSourceForDefaultCase(optional, request) {
99
+ if (!Array.isArray(request)) {
100
+ // make it an array as the look up works the same basically
101
+ request = [request];
102
+ }
103
+
104
+ const variableName = request[0];
97
105
  const missingModuleError = optional
98
- ? this.checkExternalVariable(request, request)
106
+ ? this.checkExternalVariable(variableName, request.join("."))
99
107
  : "";
100
- return `${missingModuleError}module.exports = ${request};`;
108
+ const objectLookup = request
109
+ .slice(1)
110
+ .map(r => `[${JSON.stringify(r)}]`)
111
+ .join("");
112
+ return `${missingModuleError}module.exports = ${variableName}${objectLookup};`;
101
113
  }
102
114
 
103
115
  getSourceString(runtime) {
104
116
  const request =
105
- typeof this.request === "object"
117
+ typeof this.request === "object" && !Array.isArray(this.request)
106
118
  ? this.request[this.externalType]
107
119
  : this.request;
108
120
  switch (this.externalType) {
@@ -137,7 +137,12 @@ class JavascriptModulesPlugin {
137
137
  : compilation.chunkTemplate;
138
138
  hash.update(`${chunk.id} `);
139
139
  hash.update(chunk.ids ? chunk.ids.join(",") : "");
140
- template.updateHashForChunk(hash, chunk);
140
+ template.updateHashForChunk(
141
+ hash,
142
+ chunk,
143
+ compilation.moduleTemplates.javascript,
144
+ compilation.dependencyTemplates
145
+ );
141
146
  for (const m of chunk.modulesIterable) {
142
147
  if (typeof m.source === "function") {
143
148
  hash.update(m.hash);
@@ -361,14 +361,14 @@ module.exports = class MainTemplate extends Tapable {
361
361
  }
362
362
 
363
363
  /**
364
- *
364
+ * TODO webpack 5: remove moduleTemplate and dependencyTemplates
365
365
  * @param {string} hash hash to be used for render call
366
366
  * @param {Chunk} chunk Chunk instance
367
367
  * @param {ModuleTemplate} moduleTemplate ModuleTemplate instance for render
368
368
  * @param {Map<Function, DependencyTemplate>} dependencyTemplates dependency templates
369
- * @returns {ConcatSource} the newly generated source from rendering
369
+ * @returns {string[]} the generated source of the bootstrap code
370
370
  */
371
- render(hash, chunk, moduleTemplate, dependencyTemplates) {
371
+ renderBootstrap(hash, chunk, moduleTemplate, dependencyTemplates) {
372
372
  const buf = [];
373
373
  buf.push(
374
374
  this.hooks.bootstrap.call(
@@ -392,6 +392,23 @@ module.exports = class MainTemplate extends Tapable {
392
392
  buf.push("");
393
393
  buf.push(Template.asString(this.hooks.beforeStartup.call("", chunk, hash)));
394
394
  buf.push(Template.asString(this.hooks.startup.call("", chunk, hash)));
395
+ return buf;
396
+ }
397
+
398
+ /**
399
+ * @param {string} hash hash to be used for render call
400
+ * @param {Chunk} chunk Chunk instance
401
+ * @param {ModuleTemplate} moduleTemplate ModuleTemplate instance for render
402
+ * @param {Map<Function, DependencyTemplate>} dependencyTemplates dependency templates
403
+ * @returns {ConcatSource} the newly generated source from rendering
404
+ */
405
+ render(hash, chunk, moduleTemplate, dependencyTemplates) {
406
+ const buf = this.renderBootstrap(
407
+ hash,
408
+ chunk,
409
+ moduleTemplate,
410
+ dependencyTemplates
411
+ );
395
412
  let source = this.hooks.render.call(
396
413
  new OriginalSource(
397
414
  Template.prefix(buf, " \t") + "\n",
@@ -486,19 +503,29 @@ module.exports = class MainTemplate extends Tapable {
486
503
  updateHash(hash) {
487
504
  hash.update("maintemplate");
488
505
  hash.update("3");
489
- hash.update(this.outputOptions.publicPath + "");
490
506
  this.hooks.hash.call(hash);
491
507
  }
492
508
 
493
509
  /**
510
+ * TODO webpack 5: remove moduleTemplate and dependencyTemplates
494
511
  * Updates hash with chunk-specific information from this template
495
512
  * @param {Hash} hash the hash to update
496
513
  * @param {Chunk} chunk the chunk
514
+ * @param {ModuleTemplate} moduleTemplate ModuleTemplate instance for render
515
+ * @param {Map<Function, DependencyTemplate>} dependencyTemplates dependency templates
497
516
  * @returns {void}
498
517
  */
499
- updateHashForChunk(hash, chunk) {
518
+ updateHashForChunk(hash, chunk, moduleTemplate, dependencyTemplates) {
500
519
  this.updateHash(hash);
501
520
  this.hooks.hashForChunk.call(hash, chunk);
521
+ for (const line of this.renderBootstrap(
522
+ "0000",
523
+ chunk,
524
+ moduleTemplate,
525
+ dependencyTemplates
526
+ )) {
527
+ hash.update(line);
528
+ }
502
529
  }
503
530
 
504
531
  useChunkHash(chunk) {
@@ -84,7 +84,7 @@ class SourceMapDevToolPlugin {
84
84
  const fallbackModuleFilenameTemplate = this.fallbackModuleFilenameTemplate;
85
85
  const requestShortener = compiler.requestShortener;
86
86
  const options = this.options;
87
- options.test = options.test || /\.(js|css)($|\?)/i;
87
+ options.test = options.test || /\.(m?js|css)($|\?)/i;
88
88
 
89
89
  const matchObject = ModuleFilenameHelpers.matchObject.bind(
90
90
  undefined,
@@ -327,7 +327,11 @@ class WebpackOptionsDefaulter extends OptionsDefaulter {
327
327
  this.set("resolve.extensions", [".wasm", ".mjs", ".js", ".json"]);
328
328
  this.set("resolve.mainFiles", ["index"]);
329
329
  this.set("resolve.aliasFields", "make", options => {
330
- if (options.target === "web" || options.target === "webworker") {
330
+ if (
331
+ options.target === "web" ||
332
+ options.target === "webworker" ||
333
+ options.target === "electron-renderer"
334
+ ) {
331
335
  return ["browser"];
332
336
  } else {
333
337
  return [];
@@ -54,10 +54,25 @@ module.exports = class HarmonyExportDependencyParserPlugin {
54
54
  parser.hooks.exportExpression.tap(
55
55
  "HarmonyExportDependencyParserPlugin",
56
56
  (statement, expr) => {
57
+ const comments = parser.getComments([
58
+ statement.range[0],
59
+ expr.range[0]
60
+ ]);
57
61
  const dep = new HarmonyExportExpressionDependency(
58
62
  parser.state.module,
59
63
  expr.range,
60
- statement.range
64
+ statement.range,
65
+ comments
66
+ .map(c => {
67
+ switch (c.type) {
68
+ case "Block":
69
+ return `/*${c.value}*/`;
70
+ case "Line":
71
+ return `//${c.value}\n`;
72
+ }
73
+ return "";
74
+ })
75
+ .join("")
61
76
  );
62
77
  dep.loc = Object.create(statement.loc);
63
78
  dep.loc.index = -1;
@@ -6,11 +6,12 @@
6
6
  const NullDependency = require("./NullDependency");
7
7
 
8
8
  class HarmonyExportExpressionDependency extends NullDependency {
9
- constructor(originModule, range, rangeStatement) {
9
+ constructor(originModule, range, rangeStatement, prefix) {
10
10
  super();
11
11
  this.originModule = originModule;
12
12
  this.range = range;
13
13
  this.rangeStatement = rangeStatement;
14
+ this.prefix = prefix;
14
15
  }
15
16
 
16
17
  get type() {
@@ -31,7 +32,11 @@ HarmonyExportExpressionDependency.Template = class HarmonyExportDependencyTempla
31
32
  const content = this.getContent(dep.originModule, used);
32
33
 
33
34
  if (dep.range) {
34
- source.replace(dep.rangeStatement[0], dep.range[0] - 1, content + "(");
35
+ source.replace(
36
+ dep.rangeStatement[0],
37
+ dep.range[0] - 1,
38
+ content + "(" + dep.prefix
39
+ );
35
40
  source.replace(dep.range[1], dep.rangeStatement[1] - 1, ");");
36
41
  return;
37
42
  }
@@ -96,7 +96,7 @@ module.exports = class NodeMainTemplatePlugin {
96
96
  "var promise = new Promise(function(resolve, reject) {",
97
97
  Template.indent([
98
98
  "installedChunkData = installedChunks[chunkId] = [resolve, reject];",
99
- "var filename = __dirname + " +
99
+ "var filename = require('path').join(__dirname, " +
100
100
  mainTemplate.getAssetPath(
101
101
  JSON.stringify(`/${chunkFilename}`),
102
102
  {
@@ -155,7 +155,7 @@ module.exports = class NodeMainTemplatePlugin {
155
155
  contentHashType: "javascript"
156
156
  }
157
157
  ) +
158
- ";",
158
+ ");",
159
159
  "require('fs').readFile(filename, 'utf-8', function(err, content) {",
160
160
  Template.indent(
161
161
  [
@@ -315,9 +315,7 @@ module.exports = class NodeMainTemplatePlugin {
315
315
  );
316
316
  mainTemplate.hooks.hash.tap("NodeMainTemplatePlugin", hash => {
317
317
  hash.update("node");
318
- hash.update("3");
319
- hash.update(mainTemplate.outputOptions.filename + "");
320
- hash.update(mainTemplate.outputOptions.chunkFilename + "");
318
+ hash.update("4");
321
319
  });
322
320
  }
323
321
  };
@@ -335,23 +335,8 @@ class WasmMainTemplatePlugin {
335
335
  );
336
336
  mainTemplate.hooks.hash.tap("WasmMainTemplatePlugin", hash => {
337
337
  hash.update("WasmMainTemplatePlugin");
338
- hash.update("1");
339
- hash.update(`${mainTemplate.outputOptions.webassemblyModuleFilename}`);
340
- hash.update(`${this.mangleImports}`);
338
+ hash.update("2");
341
339
  });
342
- mainTemplate.hooks.hashForChunk.tap(
343
- "WasmMainTemplatePlugin",
344
- (hash, chunk) => {
345
- const chunkModuleMaps = chunk.getChunkModuleMaps(m =>
346
- m.type.startsWith("webassembly")
347
- );
348
- hash.update(JSON.stringify(chunkModuleMaps.id));
349
- const wasmModules = getAllWasmModules(chunk);
350
- for (const module of wasmModules) {
351
- hash.update(module.hash);
352
- }
353
- }
354
- );
355
340
  }
356
341
  }
357
342
 
@@ -9,7 +9,6 @@ const Template = require("../Template");
9
9
  const WebAssemblyUtils = require("./WebAssemblyUtils");
10
10
  const { RawSource } = require("webpack-sources");
11
11
 
12
- const { shrinkPaddedLEB128 } = require("@webassemblyjs/wasm-opt");
13
12
  const { editWithAST, addWithAST } = require("@webassemblyjs/wasm-edit");
14
13
  const { decode } = require("@webassemblyjs/wasm-parser");
15
14
  const t = require("@webassemblyjs/ast");
@@ -30,17 +29,6 @@ const WebAssemblyExportImportedDependency = require("../dependencies/WebAssembly
30
29
  * @typedef {(ArrayBuffer) => ArrayBuffer} ArrayBufferTransform
31
30
  */
32
31
 
33
- /**
34
- * Run some preprocessing on the binary before wasm-edit
35
- *
36
- * @param {ArrayBuffer} ab - original binary
37
- * @returns {ArrayBufferTransform} transform
38
- */
39
- const preprocess = ab => {
40
- const optBin = shrinkPaddedLEB128(new Uint8Array(ab));
41
- return optBin.buffer;
42
- };
43
-
44
32
  /**
45
33
  * @template T
46
34
  * @param {Function[]} fns transforms
@@ -382,7 +370,6 @@ class WebAssemblyGenerator extends Generator {
382
370
  */
383
371
  generate(module, dependencyTemplates, runtimeTemplate, type) {
384
372
  let bin = module.originalSource().source();
385
- bin = preprocess(bin);
386
373
 
387
374
  const initFuncId = t.identifier(
388
375
  Array.isArray(module.usedExports)
@@ -581,11 +581,7 @@ ${globalObject}[${JSON.stringify(hotUpdateFunction)}] = ${runtimeSource}`;
581
581
  );
582
582
  mainTemplate.hooks.hash.tap("JsonpMainTemplatePlugin", hash => {
583
583
  hash.update("jsonp");
584
- hash.update("5");
585
- hash.update(`${mainTemplate.outputOptions.globalObject}`);
586
- hash.update(`${mainTemplate.outputOptions.chunkFilename}`);
587
- hash.update(`${mainTemplate.outputOptions.jsonpFunction}`);
588
- hash.update(`${mainTemplate.outputOptions.hotUpdateFunction}`);
584
+ hash.update("6");
589
585
  });
590
586
  }
591
587
  }
@@ -184,12 +184,7 @@ class WebWorkerMainTemplatePlugin {
184
184
  );
185
185
  mainTemplate.hooks.hash.tap("WebWorkerMainTemplatePlugin", hash => {
186
186
  hash.update("webworker");
187
- hash.update("3");
188
- hash.update(`${mainTemplate.outputOptions.publicPath}`);
189
- hash.update(`${mainTemplate.outputOptions.filename}`);
190
- hash.update(`${mainTemplate.outputOptions.chunkFilename}`);
191
- hash.update(`${mainTemplate.outputOptions.chunkCallbackName}`);
192
- hash.update(`${mainTemplate.outputOptions.globalObject}`);
187
+ hash.update("4");
193
188
  });
194
189
  }
195
190
  }
package/package.json CHANGED
@@ -1,15 +1,14 @@
1
1
  {
2
2
  "name": "webpack",
3
- "version": "4.17.3",
3
+ "version": "4.19.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.5.13",
9
- "@webassemblyjs/helper-module-context": "1.5.13",
10
- "@webassemblyjs/wasm-edit": "1.5.13",
11
- "@webassemblyjs/wasm-opt": "1.5.13",
12
- "@webassemblyjs/wasm-parser": "1.5.13",
8
+ "@webassemblyjs/ast": "1.7.6",
9
+ "@webassemblyjs/helper-module-context": "1.7.6",
10
+ "@webassemblyjs/wasm-edit": "1.7.6",
11
+ "@webassemblyjs/wasm-parser": "1.7.6",
13
12
  "acorn": "^5.6.2",
14
13
  "acorn-dynamic-import": "^3.0.0",
15
14
  "ajv": "^6.1.0",
@@ -26,7 +25,7 @@
26
25
  "neo-async": "^2.5.0",
27
26
  "node-libs-browser": "^2.0.0",
28
27
  "schema-utils": "^0.4.4",
29
- "tapable": "^1.0.0",
28
+ "tapable": "^1.1.0",
30
29
  "uglifyjs-webpack-plugin": "^1.2.4",
31
30
  "watchpack": "^1.5.0",
32
31
  "webpack-sources": "^1.2.0"
@@ -123,6 +123,9 @@
123
123
  {
124
124
  "type": "object"
125
125
  },
126
+ {
127
+ "$ref": "#/definitions/common.arrayOfStringValues"
128
+ },
126
129
  {
127
130
  "type": "boolean"
128
131
  }