Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'master' into chore-bump-webassemblyjs11
  • Loading branch information
sokra committed Sep 10, 2018
2 parents c9d6ec1 + c5eab67 commit e0e0061
Show file tree
Hide file tree
Showing 113 changed files with 1,029 additions and 678 deletions.
4 changes: 0 additions & 4 deletions .editorconfig
Expand Up @@ -8,10 +8,6 @@ trim_trailing_whitespace = true
insert_final_newline = true
max_line_length = 80

[.prettierrc]
indent_style = space
indent_size = 2

[*.{yml,yaml,json}]
indent_style = space
indent_size = 2
Expand Down
45 changes: 26 additions & 19 deletions .eslintrc.js
@@ -1,7 +1,11 @@
module.exports = {
root: true,
plugins: ["prettier", "node", "jest"],
extends: ["eslint:recommended", "plugin:node/recommended", "plugin:prettier/recommended"],
extends: [
"eslint:recommended",
"plugin:node/recommended",
"plugin:prettier/recommended"
],
env: {
node: true,
es6: true
Expand All @@ -16,8 +20,8 @@ module.exports = {
"no-template-curly-in-string": "error",
"no-caller": "error",
"no-control-regex": "off",
"yoda": "error",
"eqeqeq": "error",
yoda: "error",
eqeqeq: "error",
"global-require": "off",
"brace-style": "error",
"eol-last": "error",
Expand All @@ -27,23 +31,26 @@ module.exports = {
"no-unused-vars": ["error", { args: "none" }],
"no-unsafe-negation": "error",
"no-loop-func": "warn",
"indent": "off",
indent: "off",
"no-console": "off",
"valid-jsdoc": ["error", {
"prefer": {
"return": "returns",
"prop": "property",
"memberof": "DONTUSE",
"class": "DONTUSE",
"inheritdoc": "DONTUSE",
"description": "DONTUSE",
"readonly": "DONTUSE"
},
"preferType": {
"*": "any"
},
"requireReturnType": true
}],
"valid-jsdoc": [
"error",
{
prefer: {
return: "returns",
prop: "property",
memberof: "DONTUSE",
class: "DONTUSE",
inheritdoc: "DONTUSE",
description: "DONTUSE",
readonly: "DONTUSE"
},
preferType: {
"*": "any"
},
requireReturnType: true
}
],
"node/no-unsupported-features": "error",
"node/no-deprecated-api": "error",
"node/no-missing-import": "error",
Expand Down
19 changes: 5 additions & 14 deletions .prettierignore
@@ -1,17 +1,8 @@
# Ignore all paths.
**/*.*

# Enable prettier for the following paths.
!setup/**/*.js
!lib/**/*.js
!bin/*.js
!hot/*.js
!buildin/*.js
!benchmark/**/*.js
# Ignore test fixtures
test
!test/*.js
!tooling/*.js
!test/**/webpack.config.js

# Ignore example fixtures
examples
!examples/**/webpack.config.js
!schemas/**/*.js
!declarations.d.ts
!tsconfig.json
10 changes: 9 additions & 1 deletion .prettierrc.js
@@ -1,5 +1,13 @@
module.exports = {
printWidth: 80,
useTabs: true,
tabWidth: 2
tabWidth: 2,
overrides: [
{
files: "*.json",
options: {
useTabs: false
}
}
]
};
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Expand Up @@ -7,7 +7,7 @@ work is not in vain.

## Issues

Most of the time, if webpack is not working correctly for you it is a simple configuration issue.
Most of the time, if webpack is not working correctly for you, it is a simple configuration issue.

If you are still having difficulty after looking over your configuration carefully, please post
a question to [StackOverflow with the webpack tag](http://stackoverflow.com/tags/webpack). Questions
Expand Down Expand Up @@ -35,11 +35,11 @@ If you have created your own loader/plugin please include it on the relevant doc

## Submitting Changes

After getting some feedback, push to your fork and submit a pull request. We
After getting some feedbacks, push to your fork and submit a pull request. We
may suggest some changes or improvements or alternatives, but for small changes
your pull request should be accepted quickly.

Some things that will increase the chance that your pull request is accepted:
Something that will increase the chance that your pull request is accepted:

* [Write tests](./test/README.md)
* Follow the existing coding style
Expand Down
2 changes: 0 additions & 2 deletions README.md
Expand Up @@ -58,8 +58,6 @@ yarn add webpack --dev

<h2 align="center">Introduction</h2>

> This README reflects webpack v2.x and v3.x. The webpack v1.x documentation has been deprecated and deleted.
webpack is a bundler for modules. The main purpose is to bundle JavaScript
files for usage in a browser, yet it is also capable of transforming, bundling,
or packaging just about any resource or asset.
Expand Down
1 change: 1 addition & 0 deletions bin/webpack.js
Expand Up @@ -174,4 +174,5 @@ if (installedClis.length === 0) {
" and "
)} together. To work with the "webpack" command you need only one CLI package, please remove one of them or use them directly via their binary.`
);
process.exitCode = 1;
}
2 changes: 2 additions & 0 deletions hot/log.js
Expand Up @@ -30,9 +30,11 @@ module.exports = function(level, msg) {
}
};

/* eslint-disable node/no-unsupported-features/node-builtins */
var group = console.group || dummy;
var groupCollapsed = console.groupCollapsed || dummy;
var groupEnd = console.groupEnd || dummy;
/* eslint-enable node/no-unsupported-features/node-builtins */

module.exports.group = logGroup(group);

Expand Down
6 changes: 3 additions & 3 deletions lib/Chunk.js
Expand Up @@ -313,17 +313,17 @@ class Chunk {
* @returns {-1|0|1} this is a comparitor function like sort and returns -1, 0, or 1 based on sort order
*/
compareTo(otherChunk) {
this._modules.sort();
otherChunk._modules.sort();
if (this._modules.size > otherChunk._modules.size) return -1;
if (this._modules.size < otherChunk._modules.size) return 1;
this._modules.sort();
otherChunk._modules.sort();
const a = this._modules[Symbol.iterator]();
const b = otherChunk._modules[Symbol.iterator]();
// eslint-disable-next-line no-constant-condition
while (true) {
const aItem = a.next();
const bItem = b.next();
if (aItem.done) return 0;
const bItem = b.next();
const aModuleIdentifier = aItem.value.identifier();
const bModuleIdentifier = bItem.value.identifier();
if (aModuleIdentifier < bModuleIdentifier) return -1;
Expand Down
2 changes: 1 addition & 1 deletion lib/CompatibilityPlugin.js
Expand Up @@ -30,7 +30,7 @@ class CompatibilityPlugin {
.for("javascript/auto")
.tap("CompatibilityPlugin", (parser, parserOptions) => {
if (
typeof parserOptions.browserify !== "undefined" &&
parserOptions.browserify !== undefined &&
!parserOptions.browserify
)
return;
Expand Down
22 changes: 20 additions & 2 deletions lib/Compilation.js
Expand Up @@ -1025,6 +1025,7 @@ class Compilation extends Tapable {
addEntry(context, entry, name, callback) {
const slot = {
name: name,
// TODO webpack 5 remove `request`
request: null,
module: null
};
Expand All @@ -1033,7 +1034,14 @@ class Compilation extends Tapable {
slot.request = entry.request;
}

this._preparedEntrypoints.push(slot);
// TODO webpack 5: merge modules instead when multiple entry modules are supported
const idx = this._preparedEntrypoints.findIndex(slot => slot.name === name);
if (idx >= 0) {
// Overwrite existing entrypoint
this._preparedEntrypoints[idx] = slot;
} else {
this._preparedEntrypoints.push(slot);
}
this._addModuleChain(
context,
entry,
Expand All @@ -1049,7 +1057,9 @@ class Compilation extends Tapable {
slot.module = module;
} else {
const idx = this._preparedEntrypoints.indexOf(slot);
this._preparedEntrypoints.splice(idx, 1);
if (idx >= 0) {
this._preparedEntrypoints.splice(idx, 1);
}
}
return callback(null, module);
}
Expand Down Expand Up @@ -1572,6 +1582,9 @@ class Compilation extends Tapable {
/** @type {Map<DependenciesBlock, ChunkGroup>} */
const blockChunkGroups = new Map();

/** @type {Set<DependenciesBlock>} */
const blocksWithNestedBlocks = new Set();

const ADD_AND_ENTER_MODULE = 0;
const ENTER_MODULE = 1;
const PROCESS_BLOCK = 2;
Expand Down Expand Up @@ -1731,6 +1744,10 @@ class Compilation extends Tapable {

// Traverse all Blocks
iterationOfArrayCallback(blockInfo.blocks, iteratorBlock);

if (blockInfo.blocks.length > 0 && module !== block) {
blocksWithNestedBlocks.add(block);
}
break;
}
case LEAVE_MODULE: {
Expand Down Expand Up @@ -1792,6 +1809,7 @@ class Compilation extends Tapable {
*/
const filterFn = dep => {
const depChunkGroup = dep.chunkGroup;
if (blocksWithNestedBlocks.has(dep.block)) return true;
if (areModulesAvailable(depChunkGroup, newAvailableModules)) return false; // break all modules are already available
return true;
};
Expand Down
12 changes: 6 additions & 6 deletions lib/ContextReplacementPlugin.js
Expand Up @@ -60,13 +60,13 @@ class ContextReplacementPlugin {
cmf.hooks.beforeResolve.tap("ContextReplacementPlugin", result => {
if (!result) return;
if (resourceRegExp.test(result.request)) {
if (typeof newContentResource !== "undefined") {
if (newContentResource !== undefined) {
result.request = newContentResource;
}
if (typeof newContentRecursive !== "undefined") {
if (newContentRecursive !== undefined) {
result.recursive = newContentRecursive;
}
if (typeof newContentRegExp !== "undefined") {
if (newContentRegExp !== undefined) {
result.regExp = newContentRegExp;
}
if (typeof newContentCallback === "function") {
Expand All @@ -82,13 +82,13 @@ class ContextReplacementPlugin {
cmf.hooks.afterResolve.tap("ContextReplacementPlugin", result => {
if (!result) return;
if (resourceRegExp.test(result.resource)) {
if (typeof newContentResource !== "undefined") {
if (newContentResource !== undefined) {
result.resource = path.resolve(result.resource, newContentResource);
}
if (typeof newContentRecursive !== "undefined") {
if (newContentRecursive !== undefined) {
result.recursive = newContentRecursive;
}
if (typeof newContentRegExp !== "undefined") {
if (newContentRegExp !== undefined) {
result.regExp = newContentRegExp;
}
if (typeof newContentCreateContextMap === "function") {
Expand Down
2 changes: 1 addition & 1 deletion lib/EnvironmentPlugin.js
Expand Up @@ -60,7 +60,7 @@ class EnvironmentPlugin {
}

defs[`process.env.${key}`] =
typeof value === "undefined" ? "undefined" : JSON.stringify(value);
value === undefined ? "undefined" : JSON.stringify(value);

return defs;
}, {});
Expand Down
4 changes: 2 additions & 2 deletions lib/ExternalModuleFactoryPlugin.js
Expand Up @@ -27,7 +27,7 @@ class ExternalModuleFactoryPlugin {
}
if (value === false) return factory(data, callback);
if (value === true) value = dependency.request;
if (typeof type === "undefined" && /^[a-z0-9]+ /.test(value)) {
if (type === undefined && /^[a-z0-9]+ /.test(value)) {
const idx = value.indexOf(" ");
type = value.substr(0, idx);
value = value.substr(idx + 1);
Expand Down Expand Up @@ -81,7 +81,7 @@ class ExternalModuleFactoryPlugin {
dependency.request,
(err, value, type) => {
if (err) return callback(err);
if (typeof value !== "undefined") {
if (value !== undefined) {
handleExternal(value, type, callback);
} else {
callback();
Expand Down
4 changes: 2 additions & 2 deletions lib/HotModuleReplacement.runtime.js
Expand Up @@ -105,15 +105,15 @@ module.exports = function() {
// Module API
active: true,
accept: function(dep, callback) {
if (typeof dep === "undefined") hot._selfAccepted = true;
if (dep === undefined) hot._selfAccepted = true;
else if (typeof dep === "function") hot._selfAccepted = dep;
else if (typeof dep === "object")
for (var i = 0; i < dep.length; i++)
hot._acceptedDependencies[dep[i]] = callback || function() {};
else hot._acceptedDependencies[dep] = callback || function() {};
},
decline: function(dep) {
if (typeof dep === "undefined") hot._selfDeclined = true;
if (dep === undefined) hot._selfDeclined = true;
else if (typeof dep === "object")
for (var i = 0; i < dep.length; i++)
hot._declinedDependencies[dep[i]] = true;
Expand Down
6 changes: 1 addition & 5 deletions lib/HotModuleReplacementPlugin.js
Expand Up @@ -285,11 +285,7 @@ module.exports = class HotModuleReplacementPlugin {
compilation.assets[filename] = source;
hotUpdateMainContent.c[chunkId] = true;
currentChunk.files.push(filename);
compilation.hooks.chunkAsset.call(
"HotModuleReplacementPlugin",
currentChunk,
filename
);
compilation.hooks.chunkAsset.call(currentChunk, filename);
}
} else {
hotUpdateMainContent.c[chunkId] = false;
Expand Down

0 comments on commit e0e0061

Please sign in to comment.