webpack 4.9.1 → 4.9.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.
@@ -8,11 +8,21 @@
8
8
  const { ConcatSource } = require("webpack-sources");
9
9
  const Template = require("./Template");
10
10
 
11
+ /** @typedef {import("./Compilation")} Compilation */
12
+
11
13
  class AmdMainTemplatePlugin {
14
+ /**
15
+ * @param {string} name the library name
16
+ */
12
17
  constructor(name) {
18
+ /** @type {string} */
13
19
  this.name = name;
14
20
  }
15
21
 
22
+ /**
23
+ * @param {Compilation} compilation the compilation instance
24
+ * @returns {void}
25
+ */
16
26
  apply(compilation) {
17
27
  const { mainTemplate, chunkTemplate } = compilation;
18
28
 
@@ -6,7 +6,15 @@
6
6
 
7
7
  const WebpackError = require("./WebpackError");
8
8
 
9
- module.exports = class AsyncDependencyToInitialChunkError extends WebpackError {
9
+ /** @typedef {import("./Module")} Module */
10
+
11
+ class AsyncDependencyToInitialChunkError extends WebpackError {
12
+ /**
13
+ * Creates an instance of AsyncDependencyToInitialChunkError.
14
+ * @param {string} chunkName Name of Chunk
15
+ * @param {Module} module module tied to dependency
16
+ * @param {TODO} loc location of dependency
17
+ */
10
18
  constructor(chunkName, module, loc) {
11
19
  super();
12
20
 
@@ -18,4 +26,6 @@ module.exports = class AsyncDependencyToInitialChunkError extends WebpackError {
18
26
 
19
27
  Error.captureStackTrace(this, this.constructor);
20
28
  }
21
- };
29
+ }
30
+
31
+ module.exports = AsyncDependencyToInitialChunkError;
@@ -6,7 +6,13 @@
6
6
 
7
7
  const WebpackError = require("./WebpackError");
8
8
 
9
- module.exports = class CaseSensitiveModulesWarning extends WebpackError {
9
+ /** @typedef {import("./Module")} Module */
10
+
11
+ class CaseSensitiveModulesWarning extends WebpackError {
12
+ /**
13
+ * Creates an instance of CaseSensitiveModulesWarning.
14
+ * @param {Module[]} modules modules that were detected
15
+ */
10
16
  constructor(modules) {
11
17
  super();
12
18
 
@@ -23,6 +29,11 @@ ${modulesList}`;
23
29
  Error.captureStackTrace(this, this.constructor);
24
30
  }
25
31
 
32
+ /**
33
+ * @private
34
+ * @param {Module[]} modules the modules to be sorted
35
+ * @returns {Module[]} sorted version of original modules
36
+ */
26
37
  _sort(modules) {
27
38
  return modules.slice().sort((a, b) => {
28
39
  a = a.identifier();
@@ -36,6 +47,11 @@ ${modulesList}`;
36
47
  });
37
48
  }
38
49
 
50
+ /**
51
+ * @private
52
+ * @param {Module[]} modules each module from throw
53
+ * @returns {string} each message from provided moduels
54
+ */
39
55
  _moduleMessages(modules) {
40
56
  return modules
41
57
  .map(m => {
@@ -50,4 +66,6 @@ ${modulesList}`;
50
66
  })
51
67
  .join("\n");
52
68
  }
53
- };
69
+ }
70
+
71
+ module.exports = CaseSensitiveModulesWarning;
@@ -6,15 +6,28 @@
6
6
 
7
7
  const { ConcatSource } = require("webpack-sources");
8
8
 
9
+ /** @typedef {import("./Compilation")} Compilation */
10
+
11
+ /**
12
+ * @param {string[]} accessor the accessor to convert to path
13
+ * @returns {string} the path
14
+ */
9
15
  const accessorToObjectAccess = accessor => {
10
16
  return accessor.map(a => `[${JSON.stringify(a)}]`).join("");
11
17
  };
12
18
 
13
19
  class ExportPropertyMainTemplatePlugin {
20
+ /**
21
+ * @param {string|string[]} property the name of the property to export
22
+ */
14
23
  constructor(property) {
15
24
  this.property = property;
16
25
  }
17
26
 
27
+ /**
28
+ * @param {Compilation} compilation the compilation instance
29
+ * @returns {void}
30
+ */
18
31
  apply(compilation) {
19
32
  const { mainTemplate, chunkTemplate } = compilation;
20
33
 
@@ -6,30 +6,45 @@
6
6
 
7
7
  const SetVarMainTemplatePlugin = require("./SetVarMainTemplatePlugin");
8
8
 
9
+ /** @typedef {import("./Compiler")} Compiler */
10
+
11
+ /**
12
+ * @param {string[]} accessor the accessor to convert to path
13
+ * @returns {string} the path
14
+ */
9
15
  const accessorToObjectAccess = accessor => {
10
- return accessor
11
- .map(a => {
12
- return `[${JSON.stringify(a)}]`;
13
- })
14
- .join("");
16
+ return accessor.map(a => `[${JSON.stringify(a)}]`).join("");
15
17
  };
16
18
 
17
- const accessorAccess = (base, accessor, joinWith) => {
18
- accessor = [].concat(accessor);
19
- return accessor
20
- .map((a, idx) => {
21
- a = base
22
- ? base + accessorToObjectAccess(accessor.slice(0, idx + 1))
23
- : accessor[0] + accessorToObjectAccess(accessor.slice(1, idx + 1));
24
- if (idx === accessor.length - 1) return a;
19
+ /**
20
+ * @param {string=} base the path prefix
21
+ * @param {string|string[]} accessor the accessor
22
+ * @param {string=} joinWith the element separator
23
+ * @returns {string} the path
24
+ */
25
+ const accessorAccess = (base, accessor, joinWith = "; ") => {
26
+ const accessors = Array.isArray(accessor) ? accessor : [accessor];
27
+ return accessors
28
+ .map((_, idx) => {
29
+ const a = base
30
+ ? base + accessorToObjectAccess(accessors.slice(0, idx + 1))
31
+ : accessors[0] + accessorToObjectAccess(accessors.slice(1, idx + 1));
32
+ if (idx === accessors.length - 1) return a;
25
33
  if (idx === 0 && typeof base === "undefined")
26
34
  return `${a} = typeof ${a} === "object" ? ${a} : {}`;
27
35
  return `${a} = ${a} || {}`;
28
36
  })
29
- .join(joinWith || "; ");
37
+ .join(joinWith);
30
38
  };
31
39
 
32
40
  class LibraryTemplatePlugin {
41
+ /**
42
+ * @param {string} name name of library
43
+ * @param {string} target type of library
44
+ * @param {boolean} umdNamedDefine setting this to true will name the UMD module
45
+ * @param {string|TODO} auxiliaryComment comment in the UMD wrapper
46
+ * @param {string|string[]} exportProperty which export should be exposed as library
47
+ */
33
48
  constructor(name, target, umdNamedDefine, auxiliaryComment, exportProperty) {
34
49
  this.name = name;
35
50
  this.target = target;
@@ -38,10 +53,14 @@ class LibraryTemplatePlugin {
38
53
  this.exportProperty = exportProperty;
39
54
  }
40
55
 
56
+ /**
57
+ * @param {Compiler} compiler the compiler instance
58
+ * @returns {void}
59
+ */
41
60
  apply(compiler) {
42
61
  compiler.hooks.thisCompilation.tap("LibraryTemplatePlugin", compilation => {
43
62
  if (this.exportProperty) {
44
- var ExportPropertyMainTemplatePlugin = require("./ExportPropertyMainTemplatePlugin");
63
+ const ExportPropertyMainTemplatePlugin = require("./ExportPropertyMainTemplatePlugin");
45
64
  new ExportPropertyMainTemplatePlugin(this.exportProperty).apply(
46
65
  compilation
47
66
  );
@@ -49,66 +68,80 @@ class LibraryTemplatePlugin {
49
68
  switch (this.target) {
50
69
  case "var":
51
70
  new SetVarMainTemplatePlugin(
52
- `var ${accessorAccess(false, this.name)}`
71
+ `var ${accessorAccess(undefined, this.name)}`,
72
+ false
53
73
  ).apply(compilation);
54
74
  break;
55
75
  case "assign":
56
76
  new SetVarMainTemplatePlugin(
57
- accessorAccess(undefined, this.name)
77
+ accessorAccess(undefined, this.name),
78
+ false
58
79
  ).apply(compilation);
59
80
  break;
60
81
  case "this":
61
82
  case "self":
62
83
  case "window":
63
- if (this.name)
84
+ if (this.name) {
64
85
  new SetVarMainTemplatePlugin(
65
- accessorAccess(this.target, this.name)
86
+ accessorAccess(this.target, this.name),
87
+ false
66
88
  ).apply(compilation);
67
- else
89
+ } else {
68
90
  new SetVarMainTemplatePlugin(this.target, true).apply(compilation);
91
+ }
69
92
  break;
70
93
  case "global":
71
- if (this.name)
94
+ if (this.name) {
72
95
  new SetVarMainTemplatePlugin(
73
96
  accessorAccess(
74
97
  compilation.runtimeTemplate.outputOptions.globalObject,
75
98
  this.name
76
- )
99
+ ),
100
+ false
77
101
  ).apply(compilation);
78
- else
102
+ } else {
79
103
  new SetVarMainTemplatePlugin(
80
104
  compilation.runtimeTemplate.outputOptions.globalObject,
81
105
  true
82
106
  ).apply(compilation);
107
+ }
83
108
  break;
84
109
  case "commonjs":
85
- if (this.name)
110
+ if (this.name) {
86
111
  new SetVarMainTemplatePlugin(
87
- accessorAccess("exports", this.name)
112
+ accessorAccess("exports", this.name),
113
+ false
88
114
  ).apply(compilation);
89
- else new SetVarMainTemplatePlugin("exports", true).apply(compilation);
115
+ } else {
116
+ new SetVarMainTemplatePlugin("exports", true).apply(compilation);
117
+ }
90
118
  break;
91
119
  case "commonjs2":
92
120
  case "commonjs-module":
93
- new SetVarMainTemplatePlugin("module.exports").apply(compilation);
121
+ new SetVarMainTemplatePlugin("module.exports", false).apply(
122
+ compilation
123
+ );
94
124
  break;
95
- case "amd":
96
- var AmdMainTemplatePlugin = require("./AmdMainTemplatePlugin");
125
+ case "amd": {
126
+ const AmdMainTemplatePlugin = require("./AmdMainTemplatePlugin");
97
127
  new AmdMainTemplatePlugin(this.name).apply(compilation);
98
128
  break;
129
+ }
99
130
  case "umd":
100
- case "umd2":
101
- var UmdMainTemplatePlugin = require("./UmdMainTemplatePlugin");
131
+ case "umd2": {
132
+ const UmdMainTemplatePlugin = require("./UmdMainTemplatePlugin");
102
133
  new UmdMainTemplatePlugin(this.name, {
103
134
  optionalAmdExternalAsGlobal: this.target === "umd2",
104
135
  namedDefine: this.umdNamedDefine,
105
136
  auxiliaryComment: this.auxiliaryComment
106
137
  }).apply(compilation);
107
138
  break;
108
- case "jsonp":
109
- var JsonpExportMainTemplatePlugin = require("./web/JsonpExportMainTemplatePlugin");
139
+ }
140
+ case "jsonp": {
141
+ const JsonpExportMainTemplatePlugin = require("./web/JsonpExportMainTemplatePlugin");
110
142
  new JsonpExportMainTemplatePlugin(this.name).apply(compilation);
111
143
  break;
144
+ }
112
145
  default:
113
146
  throw new Error(`${this.target} is not a valid Library target`);
114
147
  }
@@ -7,7 +7,15 @@
7
7
  const WebpackError = require("./WebpackError");
8
8
  const formatLocation = require("./formatLocation");
9
9
 
10
- module.exports = class ModuleDependencyError extends WebpackError {
10
+ /** @typedef {import("./Module")} Module */
11
+
12
+ class ModuleDependencyError extends WebpackError {
13
+ /**
14
+ * Creates an instance of ModuleDependencyError.
15
+ * @param {Module} module module tied to dependency
16
+ * @param {Error} err error thrown
17
+ * @param {TODO} loc location of dependency
18
+ */
11
19
  constructor(module, err, loc) {
12
20
  super();
13
21
 
@@ -22,4 +30,6 @@ module.exports = class ModuleDependencyError extends WebpackError {
22
30
 
23
31
  Error.captureStackTrace(this, this.constructor);
24
32
  }
25
- };
33
+ }
34
+
35
+ module.exports = ModuleDependencyError;
@@ -83,7 +83,7 @@ class ProgressPlugin {
83
83
  const states = new Array(compiler.compilers.length);
84
84
  compiler.compilers.forEach((compiler, idx) => {
85
85
  new ProgressPlugin((p, msg, ...args) => {
86
- states[idx] = args;
86
+ states[idx] = [p, msg, ...args];
87
87
  handler(
88
88
  states
89
89
  .map(state => (state && state[0]) || 0)
@@ -6,12 +6,24 @@
6
6
 
7
7
  const { ConcatSource } = require("webpack-sources");
8
8
 
9
+ /** @typedef {import("./Compilation")} Compilation */
10
+
9
11
  class SetVarMainTemplatePlugin {
12
+ /**
13
+ * @param {string} varExpression the accessor where the library is exported
14
+ * @param {boolean} copyObject specify copying the exports
15
+ */
10
16
  constructor(varExpression, copyObject) {
17
+ /** @type {string} */
11
18
  this.varExpression = varExpression;
19
+ /** @type {boolean} */
12
20
  this.copyObject = copyObject;
13
21
  }
14
22
 
23
+ /**
24
+ * @param {Compilation} compilation the compilation instance
25
+ * @returns {void}
26
+ */
15
27
  apply(compilation) {
16
28
  const { mainTemplate, chunkTemplate } = compilation;
17
29
 
@@ -7,22 +7,59 @@
7
7
  const { ConcatSource, OriginalSource } = require("webpack-sources");
8
8
  const Template = require("./Template");
9
9
 
10
- function accessorToObjectAccess(accessor) {
10
+ /** @typedef {import("./Compilation")} Compilation */
11
+
12
+ /**
13
+ * @param {string[]} accessor the accessor to convert to path
14
+ * @returns {string} the path
15
+ */
16
+ const accessorToObjectAccess = accessor => {
11
17
  return accessor.map(a => `[${JSON.stringify(a)}]`).join("");
12
- }
18
+ };
13
19
 
14
- function accessorAccess(base, accessor) {
15
- accessor = [].concat(accessor);
16
- return accessor
17
- .map((a, idx) => {
18
- a = base + accessorToObjectAccess(accessor.slice(0, idx + 1));
19
- if (idx === accessor.length - 1) return a;
20
+ /**
21
+ * @param {string=} base the path prefix
22
+ * @param {string|string[]} accessor the accessor
23
+ * @param {string=} joinWith the element separator
24
+ * @returns {string} the path
25
+ */
26
+ const accessorAccess = (base, accessor, joinWith = ", ") => {
27
+ const accessors = Array.isArray(accessor) ? accessor : [accessor];
28
+ return accessors
29
+ .map((_, idx) => {
30
+ const a = base
31
+ ? base + accessorToObjectAccess(accessors.slice(0, idx + 1))
32
+ : accessors[0] + accessorToObjectAccess(accessors.slice(1, idx + 1));
33
+ if (idx === accessors.length - 1) return a;
34
+ if (idx === 0 && typeof base === "undefined")
35
+ return `${a} = typeof ${a} === "object" ? ${a} : {}`;
20
36
  return `${a} = ${a} || {}`;
21
37
  })
22
- .join(", ");
23
- }
38
+ .join(joinWith);
39
+ };
40
+
41
+ /** @typedef {string | string[] | Record<string, string | string[]>} UmdMainTemplatePluginName */
42
+
43
+ /**
44
+ * @typedef {Object} AuxiliaryCommentObject
45
+ * @property {string} root
46
+ * @property {string} commonjs
47
+ * @property {string} commonjs2
48
+ * @property {string} amd
49
+ */
50
+
51
+ /**
52
+ * @typedef {Object} UmdMainTemplatePluginOption
53
+ * @property {boolean=} optionalAmdExternalAsGlobal
54
+ * @property {boolean} namedDefine
55
+ * @property {string | AuxiliaryCommentObject} auxiliaryComment
56
+ */
24
57
 
25
58
  class UmdMainTemplatePlugin {
59
+ /**
60
+ * @param {UmdMainTemplatePluginName} name the name of the UMD library
61
+ * @param {UmdMainTemplatePluginOption} options the plugin option
62
+ */
26
63
  constructor(name, options) {
27
64
  if (typeof name === "object" && !Array.isArray(name)) {
28
65
  this.name = name.root || name.amd || name.commonjs;
@@ -40,6 +77,10 @@ class UmdMainTemplatePlugin {
40
77
  this.auxiliaryComment = options.auxiliaryComment;
41
78
  }
42
79
 
80
+ /**
81
+ * @param {Compilation} compilation the compilation instance
82
+ * @returns {void}
83
+ */
43
84
  apply(compilation) {
44
85
  const { mainTemplate, chunkTemplate, runtimeTemplate } = compilation;
45
86
 
@@ -152,23 +193,27 @@ class UmdMainTemplatePlugin {
152
193
  amdFactory = "factory";
153
194
  }
154
195
 
196
+ const auxiliaryComment = this.auxiliaryComment;
197
+
198
+ const getAuxilaryComment = type => {
199
+ if (auxiliaryComment) {
200
+ if (typeof auxiliaryComment === "string")
201
+ return "\t//" + auxiliaryComment + "\n";
202
+ if (auxiliaryComment[type])
203
+ return "\t//" + auxiliaryComment[type] + "\n";
204
+ }
205
+ return "";
206
+ };
207
+
155
208
  return new ConcatSource(
156
209
  new OriginalSource(
157
210
  "(function webpackUniversalModuleDefinition(root, factory) {\n" +
158
- (this.auxiliaryComment && typeof this.auxiliaryComment === "string"
159
- ? " //" + this.auxiliaryComment + "\n"
160
- : this.auxiliaryComment.commonjs2
161
- ? " //" + this.auxiliaryComment.commonjs2 + "\n"
162
- : "") +
211
+ getAuxilaryComment("commonjs2") +
163
212
  " if(typeof exports === 'object' && typeof module === 'object')\n" +
164
213
  " module.exports = factory(" +
165
214
  externalsRequireArray("commonjs2") +
166
215
  ");\n" +
167
- (this.auxiliaryComment && typeof this.auxiliaryComment === "string"
168
- ? " //" + this.auxiliaryComment + "\n"
169
- : this.auxiliaryComment.amd
170
- ? " //" + this.auxiliaryComment.amd + "\n"
171
- : "") +
216
+ getAuxilaryComment("amd") +
172
217
  " else if(typeof define === 'function' && define.amd)\n" +
173
218
  (requiredExternals.length > 0
174
219
  ? this.names.amd && this.namedDefine === true
@@ -192,24 +237,14 @@ class UmdMainTemplatePlugin {
192
237
  ");\n"
193
238
  : " define([], " + amdFactory + ");\n") +
194
239
  (this.names.root || this.names.commonjs
195
- ? (this.auxiliaryComment &&
196
- typeof this.auxiliaryComment === "string"
197
- ? " //" + this.auxiliaryComment + "\n"
198
- : this.auxiliaryComment.commonjs
199
- ? " //" + this.auxiliaryComment.commonjs + "\n"
200
- : "") +
240
+ ? getAuxilaryComment("commonjs") +
201
241
  " else if(typeof exports === 'object')\n" +
202
242
  " exports[" +
203
243
  libraryName(this.names.commonjs || this.names.root) +
204
244
  "] = factory(" +
205
245
  externalsRequireArray("commonjs") +
206
246
  ");\n" +
207
- (this.auxiliaryComment &&
208
- typeof this.auxiliaryComment === "string"
209
- ? " //" + this.auxiliaryComment + "\n"
210
- : this.auxiliaryComment.root
211
- ? " //" + this.auxiliaryComment.root + "\n"
212
- : "") +
247
+ getAuxilaryComment("root") +
213
248
  " else\n" +
214
249
  " " +
215
250
  replaceKeys(
@@ -4,7 +4,11 @@
4
4
  */
5
5
  "use strict";
6
6
 
7
- module.exports = class WebpackError extends Error {
7
+ class WebpackError extends Error {
8
+ /**
9
+ * Creates an instance of WebpackError.
10
+ * @param {string=} message error message
11
+ */
8
12
  constructor(message) {
9
13
  super(message);
10
14
 
@@ -16,4 +20,6 @@ module.exports = class WebpackError extends Error {
16
20
  inspect() {
17
21
  return this.stack + (this.details ? `\n${this.details}` : "");
18
22
  }
19
- };
23
+ }
24
+
25
+ module.exports = WebpackError;
@@ -173,7 +173,6 @@ class JsonpMainTemplatePlugin {
173
173
  "onScriptComplete({ type: 'timeout', target: script });"
174
174
  ]),
175
175
  `}, ${chunkLoadTimeout});`,
176
- "script.onerror = script.onload = onScriptComplete;",
177
176
  "function onScriptComplete(event) {",
178
177
  Template.indent([
179
178
  "// avoid mem leaks in IE.",
@@ -196,7 +195,8 @@ class JsonpMainTemplatePlugin {
196
195
  ]),
197
196
  "}"
198
197
  ]),
199
- "};"
198
+ "};",
199
+ "script.onerror = script.onload = onScriptComplete;"
200
200
  ]);
201
201
  }
202
202
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webpack",
3
- "version": "4.9.1",
3
+ "version": "4.9.2",
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",