GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — IgnorePlugin: add context argument to checkResource, deprecate checkC… · webpack/webpack@a9d465f

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • declarations/plugins
    • IgnorePlugin.d.ts
  • lib
    • IgnorePlugin.js
  • schemas/plugins
    • IgnorePlugin.json
  • test/configCases/ignore
    • checkContext
      • folder-a
        • ignored-module.js
        • normal-module.js
      • folder-b
        • ignored-module.js
        • normal-module.js
        • only-context-match-require.js
        • only-context-match.js
      • test.js
      • webpack.config.js
    • checkResource-one-argument
      • ignored-module.js
      • normal-module.js
      • test.js
      • webpack.config.js
    • checkResource-two-arguments
      • folder-a
        • ignored-module.js
        • normal-module.js
      • folder-b
        • ignored-module.js
        • normal-module.js
        • only-context-match-require.js
        • only-context-match.js
      • test.js
      • webpack.config.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎declarations/plugins/IgnorePlugin.d.ts‎

Copy file name to clipboardExpand all lines: declarations/plugins/IgnorePlugin.d.ts
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export type IgnorePluginOptions =
2121
*/
2222
checkContext?: ((context: string) => boolean);
2323
/**
24-
* A filter function for resource
24+
* A filter function for resource and context
2525
*/
26-
checkResource?: ((resource: string) => boolean);
26+
checkResource?: ((resource: string, context: string) => boolean);
2727
};
Collapse file

‎lib/IgnorePlugin.js‎

Copy file name to clipboardExpand all lines: lib/IgnorePlugin.js
+28-46Lines changed: 28 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -30,61 +30,43 @@ class IgnorePlugin {
3030
this.checkIgnore = this.checkIgnore.bind(this);
3131
}
3232

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-
6333
/**
6434
* Note that if "contextRegExp" is given, both the "resourceRegExp"
6535
* and "contextRegExp" have to match.
6636
*
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-
/**
8037
* @param {TODO} result result
8138
* @returns {TODO|null} returns result or null if result should be ignored
8239
*/
8340
checkIgnore(result) {
84-
// check if result is ignored
85-
if (this.checkResult(result)) {
86-
return null;
41+
if (
42+
"checkResource" in this.options &&
43+
this.options.checkResource(result.request, result.context)
44+
) {
45+
// TODO webpack 5 remove checkContext, as checkResource already gets context
46+
if ("checkContext" in this.options) {
47+
if (this.options.checkContext(result.context)) {
48+
return null;
49+
}
50+
} else {
51+
return null;
52+
}
8753
}
54+
55+
if (
56+
"resourceRegExp" in this.options &&
57+
this.options.resourceRegExp.test(result.request)
58+
) {
59+
if ("contextRegExp" in this.options) {
60+
// if "contextRegExp" is given,
61+
// both the "resourceRegExp" and "contextRegExp" have to match.
62+
if (this.options.contextRegExp.test(result.context)) {
63+
return null;
64+
}
65+
} else {
66+
return null;
67+
}
68+
}
69+
8870
return result;
8971
}
9072

Collapse file

‎schemas/plugins/IgnorePlugin.json‎

Copy file name to clipboardExpand all lines: schemas/plugins/IgnorePlugin.json
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727
"tsType": "((context: string) => boolean)"
2828
},
2929
"checkResource": {
30-
"description": "A filter function for resource",
30+
"description": "A filter function for resource and context",
3131
"instanceof": "Function",
32-
"tsType": "((resource: string) => boolean)"
32+
"tsType": "((resource: string, context: string) => boolean)"
3333
}
3434
}
3535
}
Collapse file

‎…heckContextFn/folder-a/ignored-module.js‎ ‎…/checkContext/folder-a/ignored-module.js‎test/configCases/ignore/checkContextFn/folder-a/ignored-module.js renamed to test/configCases/ignore/checkContext/folder-a/ignored-module.js test/configCases/ignore/checkContextFn/folder-a/ignored-module.js renamed to test/configCases/ignore/checkContext/folder-a/ignored-module.js

Copy file name to clipboard
File renamed without changes.
Collapse file

‎…checkContextFn/folder-a/normal-module.js‎ ‎…e/checkContext/folder-a/normal-module.js‎test/configCases/ignore/checkContextFn/folder-a/normal-module.js renamed to test/configCases/ignore/checkContext/folder-a/normal-module.js test/configCases/ignore/checkContextFn/folder-a/normal-module.js renamed to test/configCases/ignore/checkContext/folder-a/normal-module.js

Copy file name to clipboard
File renamed without changes.
Collapse file

‎…heckContextFn/folder-b/ignored-module.js‎ ‎…/checkContext/folder-b/ignored-module.js‎test/configCases/ignore/checkContextFn/folder-b/ignored-module.js renamed to test/configCases/ignore/checkContext/folder-b/ignored-module.js test/configCases/ignore/checkContextFn/folder-b/ignored-module.js renamed to test/configCases/ignore/checkContext/folder-b/ignored-module.js

Copy file name to clipboard
File renamed without changes.
Collapse file

‎…checkContextFn/folder-b/normal-module.js‎ ‎…e/checkContext/folder-b/normal-module.js‎test/configCases/ignore/checkContextFn/folder-b/normal-module.js renamed to test/configCases/ignore/checkContext/folder-b/normal-module.js test/configCases/ignore/checkContextFn/folder-b/normal-module.js renamed to test/configCases/ignore/checkContext/folder-b/normal-module.js

Copy file name to clipboard
File renamed without changes.
Collapse file

‎…n/folder-b/only-context-match-require.js‎ ‎…t/folder-b/only-context-match-require.js‎test/configCases/ignore/checkContextFn/folder-b/only-context-match-require.js renamed to test/configCases/ignore/checkContext/folder-b/only-context-match-require.js test/configCases/ignore/checkContextFn/folder-b/only-context-match-require.js renamed to test/configCases/ignore/checkContext/folder-b/only-context-match-require.js

Copy file name to clipboard
File renamed without changes.
Collapse file

‎…ContextFn/folder-b/only-context-match.js‎ ‎…ckContext/folder-b/only-context-match.js‎test/configCases/ignore/checkContextFn/folder-b/only-context-match.js renamed to test/configCases/ignore/checkContext/folder-b/only-context-match.js test/configCases/ignore/checkContextFn/folder-b/only-context-match.js renamed to test/configCases/ignore/checkContext/folder-b/only-context-match.js

Copy file name to clipboard
File renamed without changes.
Collapse file

‎…onfigCases/ignore/checkContextFn/test.js‎ ‎…/configCases/ignore/checkContext/test.js‎test/configCases/ignore/checkContextFn/test.js renamed to test/configCases/ignore/checkContext/test.js test/configCases/ignore/checkContextFn/test.js renamed to test/configCases/ignore/checkContext/test.js

Copy file name to clipboard
File renamed without changes.

0 commit comments

Comments
0 (0)
You are visitor 01402622 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.