webpack 4.27.1 → 4.28.3

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.
@@ -21,7 +21,7 @@ export type IgnorePluginOptions =
21
21
  */
22
22
  checkContext?: ((context: string) => boolean);
23
23
  /**
24
- * A filter function for resource
24
+ * A filter function for resource and context
25
25
  */
26
- checkResource?: ((resource: string) => boolean);
26
+ checkResource?: ((resource: string, context: string) => boolean);
27
27
  };
@@ -30,61 +30,47 @@ class IgnorePlugin {
30
30
  this.checkIgnore = this.checkIgnore.bind(this);
31
31
  }
32
32
 
33
- /**
34
- * @param {string} resource resource
35
- * @returns {boolean} returns true if a "resourceRegExp" exists
36
- * and the resource given matches the regexp.
37
- */
38
- checkResource(resource) {
39
- if ("checkResource" in this.options && this.options.checkResource) {
40
- return this.options.checkResource(resource);
41
- }
42
- if ("resourceRegExp" in this.options && this.options.resourceRegExp) {
43
- return this.options.resourceRegExp.test(resource);
44
- }
45
- return false;
46
- }
47
-
48
- /**
49
- * @param {string} context context
50
- * @returns {boolean} returns true if "contextRegExp" does not exist
51
- * or if context matches the given regexp.
52
- */
53
- checkContext(context) {
54
- if ("checkContext" in this.options && this.options.checkContext) {
55
- return this.options.checkContext(context);
56
- }
57
- if ("contextRegExp" in this.options && this.options.contextRegExp) {
58
- return this.options.contextRegExp.test(context);
59
- }
60
- return true;
61
- }
62
-
63
33
  /**
64
34
  * Note that if "contextRegExp" is given, both the "resourceRegExp"
65
35
  * and "contextRegExp" have to match.
66
36
  *
67
- * @param {TODO} result result
68
- * @returns {boolean} returns true if result should be ignored
69
- */
70
- checkResult(result) {
71
- if (!result) {
72
- return true;
73
- }
74
- return (
75
- this.checkResource(result.request) && this.checkContext(result.context)
76
- );
77
- }
78
-
79
- /**
80
37
  * @param {TODO} result result
81
38
  * @returns {TODO|null} returns result or null if result should be ignored
82
39
  */
83
40
  checkIgnore(result) {
84
- // check if result is ignored
85
- if (this.checkResult(result)) {
86
- return null;
41
+ if (!result) return result;
42
+
43
+ if (
44
+ "checkResource" in this.options &&
45
+ this.options.checkResource &&
46
+ this.options.checkResource(result.request, result.context)
47
+ ) {
48
+ // TODO webpack 5 remove checkContext, as checkResource already gets context
49
+ if ("checkContext" in this.options && this.options.checkContext) {
50
+ if (this.options.checkContext(result.context)) {
51
+ return null;
52
+ }
53
+ } else {
54
+ return null;
55
+ }
87
56
  }
57
+
58
+ if (
59
+ "resourceRegExp" in this.options &&
60
+ this.options.resourceRegExp &&
61
+ this.options.resourceRegExp.test(result.request)
62
+ ) {
63
+ if ("contextRegExp" in this.options && this.options.contextRegExp) {
64
+ // if "contextRegExp" is given,
65
+ // both the "resourceRegExp" and "contextRegExp" have to match.
66
+ if (this.options.contextRegExp.test(result.context)) {
67
+ return null;
68
+ }
69
+ } else {
70
+ return null;
71
+ }
72
+ }
73
+
88
74
  return result;
89
75
  }
90
76
 
@@ -1,4 +1,6 @@
1
1
  const fs = require("fs");
2
+ const path = require("path");
3
+ const mkdirp = require("mkdirp");
2
4
  const { Tracer } = require("chrome-trace-event");
3
5
  const validateOptions = require("schema-utils");
4
6
  const schema = require("../../schemas/plugins/debug/ProfilingPlugin.json");
@@ -93,6 +95,10 @@ const createTrace = outputPath => {
93
95
  noStream: true
94
96
  });
95
97
  const profiler = new Profiler(inspector);
98
+ if (/\/|\\/.test(outputPath)) {
99
+ const dirPath = path.dirname(outputPath);
100
+ mkdirp.sync(dirPath);
101
+ }
96
102
  const fsStream = fs.createWriteStream(outputPath);
97
103
 
98
104
  let counter = 0;
@@ -116,9 +116,6 @@ module.exports = class NodeSourcePlugin {
116
116
  normalModuleFactory.hooks.parser
117
117
  .for("javascript/dynamic")
118
118
  .tap("NodeSourcePlugin", handler);
119
- normalModuleFactory.hooks.parser
120
- .for("javascript/esm")
121
- .tap("NodeSourcePlugin", handler);
122
119
  }
123
120
  );
124
121
  compiler.hooks.afterResolvers.tap("NodeSourcePlugin", compiler => {
@@ -12,12 +12,11 @@ module.exports = function() {
12
12
 
13
13
  // eslint-disable-next-line no-unused-vars
14
14
  function hotDownloadUpdateChunk(chunkId) {
15
- var head = document.getElementsByTagName("head")[0];
16
15
  var script = document.createElement("script");
17
16
  script.charset = "utf-8";
18
17
  script.src = $require$.p + $hotChunkFilename$;
19
18
  if ($crossOriginLoading$) script.crossOrigin = $crossOriginLoading$;
20
- head.appendChild(script);
19
+ document.head.appendChild(script);
21
20
  }
22
21
 
23
22
  // eslint-disable-next-line no-unused-vars
@@ -282,9 +282,8 @@ class JsonpMainTemplatePlugin {
282
282
  "promises.push(installedChunkData[2] = promise);",
283
283
  "",
284
284
  "// start chunk loading",
285
- "var head = document.getElementsByTagName('head')[0];",
286
285
  mainTemplate.hooks.jsonpScript.call("", chunk, hash),
287
- "head.appendChild(script);"
286
+ "document.head.appendChild(script);"
288
287
  ]),
289
288
  "}"
290
289
  ]),
@@ -310,14 +309,13 @@ class JsonpMainTemplatePlugin {
310
309
  "var chunkPreloadData = chunkPreloadMap[chunkId];",
311
310
  "if(chunkPreloadData) {",
312
311
  Template.indent([
313
- "var head = document.getElementsByTagName('head')[0];",
314
312
  "chunkPreloadData.forEach(function(chunkId) {",
315
313
  Template.indent([
316
314
  "if(installedChunks[chunkId] === undefined) {",
317
315
  Template.indent([
318
316
  "installedChunks[chunkId] = null;",
319
317
  mainTemplate.hooks.linkPreload.call("", chunk, hash),
320
- "head.appendChild(link);"
318
+ "document.head.appendChild(link);"
321
319
  ]),
322
320
  "}"
323
321
  ]),
@@ -388,14 +386,13 @@ class JsonpMainTemplatePlugin {
388
386
  withPrefetch
389
387
  ? Template.asString([
390
388
  "// chunk prefetching for javascript",
391
- "var head = document.getElementsByTagName('head')[0];",
392
389
  "prefetchChunks.forEach(function(chunkId) {",
393
390
  Template.indent([
394
391
  "if(installedChunks[chunkId] === undefined) {",
395
392
  Template.indent([
396
393
  "installedChunks[chunkId] = null;",
397
394
  mainTemplate.hooks.linkPrefetch.call("", chunk, hash),
398
- "head.appendChild(link);"
395
+ "document.head.appendChild(link);"
399
396
  ]),
400
397
  "}"
401
398
  ]),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webpack",
3
- "version": "4.27.1",
3
+ "version": "4.28.3",
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",
@@ -27,9 +27,9 @@
27
27
  "tsType": "((context: string) => boolean)"
28
28
  },
29
29
  "checkResource": {
30
- "description": "A filter function for resource",
30
+ "description": "A filter function for resource and context",
31
31
  "instanceof": "Function",
32
- "tsType": "((resource: string) => boolean)"
32
+ "tsType": "((resource: string, context: string) => boolean)"
33
33
  }
34
34
  }
35
35
  }