Skip to content

Commit 95e27d3

Browse files
authored
Merge pull request #159 from webpack/dev_tools
Update dev tools
2 parents 635c2c7 + 6a6e9b5 commit 95e27d3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+4165
-1748
lines changed

.editorconfig

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
root = true
22

3-
[*.js]
4-
indent_style=tab
5-
trim_trailing_whitespace=true
3+
[*]
4+
indent_style = tab
5+
indent_size = 2
6+
charset = utf-8
7+
trim_trailing_whitespace = true
8+
insert_final_newline = true
9+
max_line_length = 80
10+
11+
[*.{yml,yaml,json}]
12+
indent_style = space
13+
indent_size = 2
14+
15+
[*.md]
16+
trim_trailing_whitespace = false

.eslintrc

-53
This file was deleted.

.eslintrc.js

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
module.exports = {
2+
root: true,
3+
plugins: ["prettier", "node"],
4+
extends: [
5+
"eslint:recommended",
6+
"plugin:node/recommended",
7+
"plugin:prettier/recommended"
8+
],
9+
env: {
10+
node: true,
11+
es6: true
12+
},
13+
parserOptions: {
14+
ecmaVersion: 2017
15+
},
16+
rules: {
17+
"prettier/prettier": "error",
18+
"no-undef": "error",
19+
"no-extra-semi": "error",
20+
"no-template-curly-in-string": "error",
21+
"no-caller": "error",
22+
"no-control-regex": "off",
23+
yoda: "error",
24+
eqeqeq: "error",
25+
"global-require": "off",
26+
"brace-style": "off",
27+
"eol-last": "error",
28+
"no-extra-bind": "warn",
29+
"no-process-exit": "warn",
30+
"no-use-before-define": "off",
31+
"no-unused-vars": ["error", { args: "none" }],
32+
"no-unsafe-negation": "error",
33+
"no-loop-func": "warn",
34+
indent: "off",
35+
"no-console": "off",
36+
"valid-jsdoc": [
37+
"error",
38+
{
39+
prefer: {
40+
return: "returns",
41+
prop: "property",
42+
memberof: "DONTUSE",
43+
class: "DONTUSE",
44+
inheritdoc: "DONTUSE",
45+
description: "DONTUSE",
46+
readonly: "DONTUSE"
47+
},
48+
preferType: {
49+
"*": "any"
50+
},
51+
requireReturnType: true
52+
}
53+
],
54+
"node/no-unsupported-features": "error",
55+
"node/no-deprecated-api": "error",
56+
"node/no-missing-import": "error",
57+
"node/no-unpublished-bin": "error",
58+
"node/no-unpublished-require": "error",
59+
"node/process-exit-as-throw": "error"
60+
},
61+
overrides: [
62+
{
63+
files: ["test/**/*.js"],
64+
env: {
65+
mocha: true
66+
}
67+
}
68+
]
69+
};

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
/node_modules
2-
/coverage
2+
/coverage
3+
*.log
4+
.eslintcache

.jsbeautifyrc

-25
This file was deleted.

.prettierrc.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module.exports = {
2+
printWidth: 80,
3+
useTabs: true,
4+
tabWidth: 2,
5+
overrides: [
6+
{
7+
files: "*.json",
8+
options: {
9+
useTabs: false
10+
}
11+
}
12+
]
13+
};

lib/AliasFieldPlugin.js

+51-29
Original file line numberDiff line numberDiff line change
@@ -16,37 +16,59 @@ module.exports = class AliasFieldPlugin {
1616

1717
apply(resolver) {
1818
const target = resolver.ensureHook(this.target);
19-
resolver.getHook(this.source).tapAsync("AliasFieldPlugin", (request, resolveContext, callback) => {
20-
if(!request.descriptionFileData) return callback();
21-
const innerRequest = getInnerRequest(resolver, request);
22-
if(!innerRequest) return callback();
23-
const fieldData = DescriptionFileUtils.getField(request.descriptionFileData, this.field);
24-
if(typeof fieldData !== "object") {
25-
if(resolveContext.log) resolveContext.log("Field '" + this.field + "' doesn't contain a valid alias configuration");
26-
return callback();
27-
}
28-
const data1 = fieldData[innerRequest];
29-
const data2 = fieldData[innerRequest.replace(/^\.\//, "")];
30-
const data = typeof data1 !== "undefined" ? data1 : data2;
31-
if(data === innerRequest) return callback();
32-
if(data === undefined) return callback();
33-
if(data === false) {
34-
const ignoreObj = Object.assign({}, request, {
35-
path: false
19+
resolver
20+
.getHook(this.source)
21+
.tapAsync("AliasFieldPlugin", (request, resolveContext, callback) => {
22+
if (!request.descriptionFileData) return callback();
23+
const innerRequest = getInnerRequest(resolver, request);
24+
if (!innerRequest) return callback();
25+
const fieldData = DescriptionFileUtils.getField(
26+
request.descriptionFileData,
27+
this.field
28+
);
29+
if (typeof fieldData !== "object") {
30+
if (resolveContext.log)
31+
resolveContext.log(
32+
"Field '" +
33+
this.field +
34+
"' doesn't contain a valid alias configuration"
35+
);
36+
return callback();
37+
}
38+
const data1 = fieldData[innerRequest];
39+
const data2 = fieldData[innerRequest.replace(/^\.\//, "")];
40+
const data = typeof data1 !== "undefined" ? data1 : data2;
41+
if (data === innerRequest) return callback();
42+
if (data === undefined) return callback();
43+
if (data === false) {
44+
const ignoreObj = Object.assign({}, request, {
45+
path: false
46+
});
47+
return callback(null, ignoreObj);
48+
}
49+
const obj = Object.assign({}, request, {
50+
path: request.descriptionFileRoot,
51+
request: data
3652
});
37-
return callback(null, ignoreObj);
38-
}
39-
const obj = Object.assign({}, request, {
40-
path: request.descriptionFileRoot,
41-
request: data
42-
});
43-
resolver.doResolve(target, obj, "aliased from description file " + request.descriptionFilePath + " with mapping '" + innerRequest + "' to '" + data + "'", resolveContext, (err, result) => {
44-
if(err) return callback(err);
53+
resolver.doResolve(
54+
target,
55+
obj,
56+
"aliased from description file " +
57+
request.descriptionFilePath +
58+
" with mapping '" +
59+
innerRequest +
60+
"' to '" +
61+
data +
62+
"'",
63+
resolveContext,
64+
(err, result) => {
65+
if (err) return callback(err);
4566

46-
// Don't allow other aliasing or raw request
47-
if(result === undefined) return callback(null, null);
48-
callback(null, result);
67+
// Don't allow other aliasing or raw request
68+
if (result === undefined) return callback(null, null);
69+
callback(null, result);
70+
}
71+
);
4972
});
50-
});
5173
}
5274
};

lib/AliasPlugin.js

+43-22
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ function startsWith(string, searchString) {
99
const searchLength = searchString.length;
1010

1111
// early out if the search length is greater than the search string
12-
if(searchLength > stringLength) {
12+
if (searchLength > stringLength) {
1313
return false;
1414
}
1515
let index = -1;
16-
while(++index < searchLength) {
17-
if(string.charCodeAt(index) !== searchString.charCodeAt(index)) {
16+
while (++index < searchLength) {
17+
if (string.charCodeAt(index) !== searchString.charCodeAt(index)) {
1818
return false;
1919
}
2020
}
@@ -30,27 +30,48 @@ module.exports = class AliasPlugin {
3030

3131
apply(resolver) {
3232
const target = resolver.ensureHook(this.target);
33-
resolver.getHook(this.source).tapAsync("AliasPlugin", (request, resolveContext, callback) => {
34-
const innerRequest = request.request || request.path;
35-
if(!innerRequest) return callback();
36-
for(const item of this.options) {
37-
if(innerRequest === item.name || (!item.onlyModule && startsWith(innerRequest, item.name + "/"))) {
38-
if(innerRequest !== item.alias && !startsWith(innerRequest, item.alias + "/")) {
39-
const newRequestStr = item.alias + innerRequest.substr(item.name.length);
40-
const obj = Object.assign({}, request, {
41-
request: newRequestStr
42-
});
43-
return resolver.doResolve(target, obj, "aliased with mapping '" + item.name + "': '" + item.alias + "' to '" + newRequestStr + "'", resolveContext, (err, result) => {
44-
if(err) return callback(err);
33+
resolver
34+
.getHook(this.source)
35+
.tapAsync("AliasPlugin", (request, resolveContext, callback) => {
36+
const innerRequest = request.request || request.path;
37+
if (!innerRequest) return callback();
38+
for (const item of this.options) {
39+
if (
40+
innerRequest === item.name ||
41+
(!item.onlyModule && startsWith(innerRequest, item.name + "/"))
42+
) {
43+
if (
44+
innerRequest !== item.alias &&
45+
!startsWith(innerRequest, item.alias + "/")
46+
) {
47+
const newRequestStr =
48+
item.alias + innerRequest.substr(item.name.length);
49+
const obj = Object.assign({}, request, {
50+
request: newRequestStr
51+
});
52+
return resolver.doResolve(
53+
target,
54+
obj,
55+
"aliased with mapping '" +
56+
item.name +
57+
"': '" +
58+
item.alias +
59+
"' to '" +
60+
newRequestStr +
61+
"'",
62+
resolveContext,
63+
(err, result) => {
64+
if (err) return callback(err);
4565

46-
// Don't allow other aliasing or raw request
47-
if(result === undefined) return callback(null, null);
48-
callback(null, result);
49-
});
66+
// Don't allow other aliasing or raw request
67+
if (result === undefined) return callback(null, null);
68+
callback(null, result);
69+
}
70+
);
71+
}
5072
}
5173
}
52-
}
53-
return callback();
54-
});
74+
return callback();
75+
});
5576
}
5677
};

lib/AppendPlugin.js

+15-6
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,21 @@ module.exports = class AppendPlugin {
1313

1414
apply(resolver) {
1515
const target = resolver.ensureHook(this.target);
16-
resolver.getHook(this.source).tapAsync("AppendPlugin", (request, resolveContext, callback) => {
17-
const obj = Object.assign({}, request, {
18-
path: request.path + this.appending,
19-
relativePath: request.relativePath && (request.relativePath + this.appending)
16+
resolver
17+
.getHook(this.source)
18+
.tapAsync("AppendPlugin", (request, resolveContext, callback) => {
19+
const obj = Object.assign({}, request, {
20+
path: request.path + this.appending,
21+
relativePath:
22+
request.relativePath && request.relativePath + this.appending
23+
});
24+
resolver.doResolve(
25+
target,
26+
obj,
27+
this.appending,
28+
resolveContext,
29+
callback
30+
);
2031
});
21-
resolver.doResolve(target, obj, this.appending, resolveContext, callback);
22-
});
2332
}
2433
};

0 commit comments

Comments
 (0)