Skip to content

Commit d554794

Browse files
author
einarlove
committed
Merge branch 'master' into patch-1
2 parents 5f5dbd5 + 9380bd4 commit d554794

136 files changed

Lines changed: 3623 additions & 1008 deletions

File tree

Some content is hidden

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

‎appveyor.yml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ init:
77
# what combinations to test
88
environment:
99
matrix:
10+
- nodejs_version: 7
1011
- nodejs_version: 6
1112

1213
install:
13-
- ps: Install-Product node (Get-NodeJsLatestBuild $env:nodejs_version) x64
14+
- ps: Install-Product node $env:nodejs_version x64
1415
- npm install yarn -g
1516
- yarn install
1617
- yarn link

‎bin/config-yargs.js‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,12 @@ module.exports = function(yargs) {
154154
describe: "Watch the filesystem for changes",
155155
group: BASIC_GROUP
156156
},
157+
"save": {
158+
type: "boolean",
159+
alias: "s",
160+
describe: "Rebuilds on save regardless of changes in watch mode",
161+
group: BASIC_GROUP
162+
},
157163
"watch-stdin": {
158164
type: "boolean",
159165
alias: "stdin",

‎bin/webpack.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,9 @@ function processOptions(options) {
331331
process.stdout.write(JSON.stringify(stats.toJson(outputOptions), null, 2) + "\n");
332332
} else if(stats.hash !== lastHash) {
333333
lastHash = stats.hash;
334+
process.stdout.write("\n" + new Date() + "\n" + "\n");
334335
process.stdout.write(stats.toString(outputOptions) + "\n");
336+
if(argv.s) lastHash = null;
335337
}
336338
if(!options.watch && stats.hasErrors()) {
337339
process.on("exit", function() {

‎circle.yml‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
general:
2+
artifacts:
3+
- "./coverage"
4+
5+
machine:
6+
node:
7+
version: 4.7.0
8+
9+
dependencies:
10+
pre:
11+
- npm install -g yarn
12+
override:
13+
- yarn install
14+
post:
15+
- yarn link || true && yarn link webpack
16+
17+
test:
18+
pre:
19+
- npm run travis:lint
20+
override:
21+
- npm run travis:test:
22+
parallel: true
23+
files:
24+
- test/ConfigTestCases.test.js
25+
- test/TestCases.test.js
26+
- test/Stats.test.js
27+
- test/**/*.test.js

‎lib/APIPlugin.js‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"use strict";
66

77
const ConstDependency = require("./dependencies/ConstDependency");
8-
const BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
8+
const ParserHelpers = require("./ParserHelpers");
99

1010
const NullFactory = require("./NullFactory");
1111

@@ -43,9 +43,8 @@ class APIPlugin {
4343
parser.state.current.addDependency(dep);
4444
return true;
4545
});
46-
parser.plugin(`evaluate typeof ${key}`, expr => {
47-
return new BasicEvaluatedExpression().setString(REPLACEMENT_TYPES[key]).setRange(expr.range);
48-
});
46+
47+
parser.plugin(`evaluate typeof ${key}`, ParserHelpers.evaluateToString(REPLACEMENT_TYPES[key]));
4948
});
5049
IGNORES.forEach(key => {
5150
parser.plugin(key, () => true);

‎lib/Compilation.js‎

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
"use strict";
66

77
const async = require("async");
8-
8+
const crypto = require("crypto");
99
const Tapable = require("tapable");
1010
const EntryModuleNotFoundError = require("./EntryModuleNotFoundError");
1111
const ModuleNotFoundError = require("./ModuleNotFoundError");
1212
const ModuleDependencyWarning = require("./ModuleDependencyWarning");
13+
const ModuleDependencyError = require("./ModuleDependencyError");
1314
const Module = require("./Module");
1415
const Chunk = require("./Chunk");
1516
const Entrypoint = require("./Entrypoint");
@@ -498,7 +499,7 @@ class Compilation extends Tapable {
498499

499500
finish() {
500501
this.applyPlugins1("finish-modules", this.modules);
501-
this.modules.forEach(m => this.reportDependencyWarnings(m, [m]));
502+
this.modules.forEach(m => this.reportDependencyErrorsAndWarnings(m, [m]));
502503
}
503504

504505
unseal() {
@@ -550,8 +551,6 @@ class Compilation extends Tapable {
550551

551552
const shouldRecord = self.applyPluginsBailResult("should-record") !== false;
552553

553-
self.sortItemsBeforeIds();
554-
555554
self.applyPlugins2("revive-modules", self.modules, self.records);
556555
self.applyPlugins1("optimize-module-order", self.modules);
557556
self.applyPlugins1("advanced-optimize-module-order", self.modules);
@@ -628,7 +627,7 @@ class Compilation extends Tapable {
628627
});
629628
}
630629

631-
reportDependencyWarnings(module, blocks) {
630+
reportDependencyErrorsAndWarnings(module, blocks) {
632631
blocks.forEach(block => {
633632
block.dependencies.forEach(d => {
634633
const warnings = d.getWarnings();
@@ -638,8 +637,15 @@ class Compilation extends Tapable {
638637
this.warnings.push(warning);
639638
});
640639
}
640+
const errors = d.getErrors();
641+
if(errors) {
642+
errors.forEach(w => {
643+
const warning = new ModuleDependencyError(module, w, d.loc);
644+
this.errors.push(warning);
645+
});
646+
}
641647
});
642-
this.reportDependencyWarnings(module, block.blocks);
648+
this.reportDependencyErrorsAndWarnings(module, block.blocks);
643649
});
644650
}
645651

@@ -896,10 +902,6 @@ class Compilation extends Tapable {
896902
});
897903
}
898904

899-
sortItemsBeforeIds() {
900-
901-
}
902-
903905
sortItemsWithModuleIds() {
904906
this.modules.sort(byId);
905907
this.modules.forEach(module => module.sortItems());
@@ -955,7 +957,7 @@ class Compilation extends Tapable {
955957
const hashFunction = outputOptions.hashFunction;
956958
const hashDigest = outputOptions.hashDigest;
957959
const hashDigestLength = outputOptions.hashDigestLength;
958-
const hash = require("crypto").createHash(hashFunction);
960+
const hash = crypto.createHash(hashFunction);
959961
if(outputOptions.hashSalt)
960962
hash.update(outputOptions.hashSalt);
961963
this.mainTemplate.updateHash(hash);
@@ -975,7 +977,7 @@ class Compilation extends Tapable {
975977
});
976978
for(let i = 0; i < chunks.length; i++) {
977979
chunk = chunks[i];
978-
const chunkHash = require("crypto").createHash(hashFunction);
980+
const chunkHash = crypto.createHash(hashFunction);
979981
if(outputOptions.hashSalt)
980982
hash.update(outputOptions.hashSalt);
981983
chunk.updateHash(chunkHash);
@@ -998,7 +1000,7 @@ class Compilation extends Tapable {
9981000
const hashFunction = outputOptions.hashFunction;
9991001
const hashDigest = outputOptions.hashDigest;
10001002
const hashDigestLength = outputOptions.hashDigestLength;
1001-
const hash = require("crypto").createHash(hashFunction);
1003+
const hash = crypto.createHash(hashFunction);
10021004
hash.update(this.fullHash);
10031005
hash.update(update);
10041006
this.fullHash = hash.digest(hashDigest);

‎lib/ConstPlugin.js‎

Lines changed: 51 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,61 +2,63 @@
22
MIT License http://www.opensource.org/licenses/mit-license.php
33
Author Tobias Koppers @sokra
44
*/
5-
var ConstDependency = require("./dependencies/ConstDependency");
6-
var BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
5+
"use strict";
76

8-
var NullFactory = require("./NullFactory");
7+
const ConstDependency = require("./dependencies/ConstDependency");
8+
const BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
9+
const NullFactory = require("./NullFactory");
910

10-
function getQuery(request) {
11-
var i = request.indexOf("?");
12-
return i < 0 ? "" : request.substr(i);
11+
const getQuery = (request) => {
12+
const i = request.indexOf("?");
13+
return request.indexOf("?") < 0 ? "" : request.substr(i);
1314
}
1415

15-
function ConstPlugin() {}
16-
module.exports = ConstPlugin;
17-
18-
ConstPlugin.prototype.apply = function(compiler) {
19-
compiler.plugin("compilation", function(compilation, params) {
20-
compilation.dependencyFactories.set(ConstDependency, new NullFactory());
21-
compilation.dependencyTemplates.set(ConstDependency, new ConstDependency.Template());
16+
class ConstPlugin {
17+
apply(compiler) {
18+
compiler.plugin("compilation", (compilation, params) => {
19+
compilation.dependencyFactories.set(ConstDependency, new NullFactory());
20+
compilation.dependencyTemplates.set(ConstDependency, new ConstDependency.Template());
2221

23-
params.normalModuleFactory.plugin("parser", function(parser) {
24-
parser.plugin("statement if", function(statement) {
25-
var param = this.evaluateExpression(statement.test);
26-
var bool = param.asBool();
27-
if(typeof bool === "boolean") {
28-
if(statement.test.type !== "Literal") {
29-
var dep = new ConstDependency(bool + "", param.range);
30-
dep.loc = statement.loc;
31-
this.state.current.addDependency(dep);
22+
params.normalModuleFactory.plugin("parser", parser => {
23+
parser.plugin("statement if", function(statement) {
24+
const param = this.evaluateExpression(statement.test);
25+
const bool = param.asBool();
26+
if(typeof bool === "boolean") {
27+
if(statement.test.type !== "Literal") {
28+
const dep = new ConstDependency(`${bool}`, param.range);
29+
dep.loc = statement.loc;
30+
this.state.current.addDependency(dep);
31+
}
32+
return bool;
3233
}
33-
return bool;
34-
}
35-
});
36-
parser.plugin("expression ?:", function(expression) {
37-
var param = this.evaluateExpression(expression.test);
38-
var bool = param.asBool();
39-
if(typeof bool === "boolean") {
40-
if(expression.test.type !== "Literal") {
41-
var dep = new ConstDependency(" " + bool + "", param.range);
42-
dep.loc = expression.loc;
43-
this.state.current.addDependency(dep);
34+
});
35+
parser.plugin("expression ?:", function(expression) {
36+
const param = this.evaluateExpression(expression.test);
37+
const bool = param.asBool();
38+
if(typeof bool === "boolean") {
39+
if(expression.test.type !== "Literal") {
40+
const dep = new ConstDependency(` ${bool}`, param.range);
41+
dep.loc = expression.loc;
42+
this.state.current.addDependency(dep);
43+
}
44+
return bool;
4445
}
45-
return bool;
46-
}
47-
});
48-
parser.plugin("evaluate Identifier __resourceQuery", function(expr) {
49-
if(!this.state.module) return;
50-
var res = new BasicEvaluatedExpression();
51-
res.setString(getQuery(this.state.module.resource));
52-
res.setRange(expr.range);
53-
return res;
54-
});
55-
parser.plugin("expression __resourceQuery", function() {
56-
if(!this.state.module) return;
57-
this.state.current.addVariable("__resourceQuery", JSON.stringify(getQuery(this.state.module.resource)));
58-
return true;
46+
});
47+
parser.plugin("evaluate Identifier __resourceQuery", function(expr) {
48+
if(!this.state.module) return;
49+
const res = new BasicEvaluatedExpression();
50+
res.setString(getQuery(this.state.module.resource));
51+
res.setRange(expr.range);
52+
return res;
53+
});
54+
parser.plugin("expression __resourceQuery", function() {
55+
if(!this.state.module) return;
56+
this.state.current.addVariable("__resourceQuery", JSON.stringify(getQuery(this.state.module.resource)));
57+
return true;
58+
});
5959
});
6060
});
61-
});
62-
};
61+
}
62+
}
63+
64+
module.exports = ConstPlugin;

‎lib/DefinePlugin.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
const ConstDependency = require("./dependencies/ConstDependency");
88
const BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
9+
const ParserHelpers = require("./ParserHelpers");
910
const NullFactory = require("./NullFactory");
1011

1112
class DefinePlugin {
@@ -101,7 +102,7 @@ class DefinePlugin {
101102
let code = stringifyObj(obj);
102103
parser.plugin("can-rename " + key, () => true);
103104
parser.plugin("evaluate Identifier " + key, (expr) => new BasicEvaluatedExpression().setRange(expr.range));
104-
parser.plugin("evaluate typeof " + key, expr => new BasicEvaluatedExpression().setString("object").setRange(expr.range));
105+
parser.plugin("evaluate typeof " + key, ParserHelpers.evaluateToString("object"));
105106
parser.plugin("expression " + key, (expr) => {
106107
let dep = new ConstDependency(code, expr.range);
107108
dep.loc = expr.loc;

‎lib/DependenciesBlock.js‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,16 @@ DependenciesBlock.prototype.unseal = function() {
5656
this.blocks.forEach(unseal);
5757
};
5858

59-
DependenciesBlock.prototype.hasDependencies = function() {
60-
return this.dependencies.length > 0 ||
61-
this.blocks.concat(this.variables).some(function(item) {
62-
return item.hasDependencies();
63-
});
59+
DependenciesBlock.prototype.hasDependencies = function(filter) {
60+
if(filter) {
61+
if(this.dependencies.some(filter)) return true;
62+
} else {
63+
if(this.dependencies.length > 0) return true;
64+
}
65+
66+
return this.blocks.concat(this.variables).some(function(item) {
67+
return item.hasDependencies(filter);
68+
});
6469
};
6570

6671
DependenciesBlock.prototype.sortItems = function() {

‎lib/DependenciesBlockVariable.js‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,13 @@ class DependenciesBlockVariable {
3838
});
3939
}
4040

41-
hasDependencies() {
42-
return this.dependencies.length > 0;
41+
hasDependencies(filter) {
42+
if(filter) {
43+
if(this.dependencies.some(filter)) return true;
44+
} else {
45+
if(this.dependencies.length > 0) return true;
46+
}
47+
return false;
4348
}
4449
}
4550

0 commit comments

Comments
 (0)