Skip to content

Commit f2d7565

Browse files
committed
Replace "whitelist" option with "allowlist"
The term "whitelist" is a metaphorical term used to say "allow these items". While it is extremely common in technical works, it can inadvertantly promote the trope of "white is good, black is bad". For more details on the term and why "allowlist" is a suitable, more technically accurate replacement, see: https://tools.ietf.org/id/draft-knodel-terminology-01.html#rfc.section.1.2 BREAKING CHANGE: The "whitelist" option has been removed and replaced with "allowlist"
1 parent cfa1c5b commit f2d7565

File tree

4 files changed

+16
-16
lines changed

4 files changed

+16
-16
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ This library scans the `node_modules` folder for all node_modules names, and bui
3636
### Configuration
3737
This library accepts an `options` object.
3838

39-
#### `options.whitelist (=[])`
40-
An array for the `externals` to whitelist, so they **will** be included in the bundle. Can accept exact strings (`'module_name'`), regex patterns (`/^module_name/`), or a function that accepts the module name and returns whether it should be included.
41-
<br/>**Important** - if you have set aliases in your webpack config with the exact same names as modules in *node_modules*, you need to whitelist them so Webpack will know they should be bundled.
39+
#### `options.allowlist (=[])`
40+
An array for the `externals` to allow, so they **will** be included in the bundle. Can accept exact strings (`'module_name'`), regex patterns (`/^module_name/`), or a function that accepts the module name and returns whether it should be included.
41+
<br/>**Important** - if you have set aliases in your webpack config with the exact same names as modules in *node_modules*, you need to allowlist them so Webpack will know they should be bundled.
4242

4343
#### `options.importType (='commonjs')`
4444
The method in which unbundled modules will be required in the code. Best to leave as `commonjs` for node modules.
@@ -75,7 +75,7 @@ module.exports = {
7575
target: 'node', // important in order not to bundle built-in modules like path, fs, etc.
7676
externals: [nodeExternals({
7777
// this WILL include `jquery` and `webpack/hot/dev-server` in the bundle, as well as `lodash/*`
78-
whitelist: ['jquery', 'webpack/hot/dev-server', /^lodash/]
78+
allowlist: ['jquery', 'webpack/hot/dev-server', /^lodash/]
7979
})],
8080
...
8181
};
@@ -99,12 +99,12 @@ However, this will leave unbundled **all non-relative requires**, so it does not
9999
This library scans the `node_modules` folder, so it only leaves unbundled the actual node modules that are being used.
100100

101101
#### How can I bundle required assets (i.e css files) from node_modules?
102-
Using the `whitelist` option, this is possible. We can simply tell Webpack to bundle all files with extensions that are not js/jsx/json, using this [regex](https://regexper.com/#%5C.(%3F!(%3F%3Ajs%7Cjson)%24).%7B1%2C5%7D%24):
102+
Using the `allowlist` option, this is possible. We can simply tell Webpack to bundle all files with extensions that are not js/jsx/json, using this [regex](https://regexper.com/#%5C.(%3F!(%3F%3Ajs%7Cjson)%24).%7B1%2C5%7D%24):
103103
```js
104104
...
105105
nodeExternals({
106106
// load non-javascript files with extensions, presumably via loaders
107-
whitelist: [/\.(?!(?:jsx?|json)$).{1,5}$/i],
107+
allowlist: [/\.(?!(?:jsx?|json)$).{1,5}$/i],
108108
}),
109109
...
110110
```

index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function getModuleName(request, includeAbsolutePaths) {
2020

2121
module.exports = function nodeExternals(options) {
2222
options = options || {};
23-
var whitelist = [].concat(options.whitelist || []);
23+
var allowlist = [].concat(options.allowlist || []);
2424
var binaryDirs = [].concat(options.binaryDirs || ['.bin']);
2525
var importType = options.importType || 'commonjs';
2626
var modulesDir = options.modulesDir || 'node_modules';
@@ -38,7 +38,7 @@ module.exports = function nodeExternals(options) {
3838
// return an externals function
3939
return function(context, request, callback){
4040
var moduleName = getModuleName(request, includeAbsolutePaths);
41-
if (utils.contains(nodeModules, moduleName) && !utils.containsPattern(whitelist, request)) {
41+
if (utils.contains(nodeModules, moduleName) && !utils.containsPattern(allowlist, request)) {
4242
if (typeof importType === 'function') {
4343
return callback(null, importType(request));
4444
}
@@ -48,4 +48,4 @@ module.exports = function nodeExternals(options) {
4848
};
4949
callback();
5050
}
51-
};
51+
};

test/library.spec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,13 @@ describe('reads from a file', function() {
132132
});
133133
});
134134

135-
// Test whitelist
136-
describe('respects a whitelist', function() {
135+
// Test allowlist
136+
describe('respects a allowlist', function() {
137137

138138
before(function(){
139139
mockNodeModules();
140140
context.instance = nodeExternals({
141-
whitelist: ['moduleA/sub-module', 'moduleA/another-sub/index.js', 'moduleC', function (m) {
141+
allowlist: ['moduleA/sub-module', 'moduleA/another-sub/index.js', 'moduleC', function (m) {
142142
return m == 'moduleF';
143143
}, /^moduleD/]
144144
});
@@ -244,4 +244,4 @@ describe('when modules dir does not exist', function() {
244244
after(function(){
245245
restoreMock()
246246
});
247-
})
247+
})

test/webpack.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ describe('actual webpack bundling', function() {
1111

1212
describe('basic tests', function() {
1313
it('should output modules without bundling', webpackAssertion({}, ['module-a', 'module-b'], ['module-c']));
14-
it('should honor a whitelist', webpackAssertion({ whitelist: ['module-a'] }, ['module-b'], ['module-a', 'module-c']));
14+
it('should honor a allowlist', webpackAssertion({ allowlist: ['module-a'] }, ['module-b'], ['module-a', 'module-c']));
1515
});
1616

1717
describe('with webpack aliased module in node_modules', function() {
1818
before(function() {
1919
return testUtils.copyModules(['module-c']);
2020
});
21-
it('should bundle aliased modules', webpackAssertion({ whitelist: ['module-c'] }, ['module-a', 'module-b'], ['module-c']));
21+
it('should bundle aliased modules', webpackAssertion({ allowlist: ['module-c'] }, ['module-a', 'module-b'], ['module-c']));
2222
})
2323

2424
after(function() {
2525
testUtils.removeModules(['module-a', 'module-b', 'module-c']);
2626
});
27-
});
27+
});

0 commit comments

Comments
 (0)