Skip to content

Commit

Permalink
Merge branch 'master' into feature/travis_yarn_command
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLarkInn committed Oct 26, 2016
2 parents 4b52657 + 39116a6 commit fad1db2
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 7 deletions.
5 changes: 4 additions & 1 deletion examples/README.md
Expand Up @@ -67,4 +67,7 @@ If you think an example is missing, please report it as issue. :)
# Building an Example

1. Run `npm install` in the root of the project.
2. Run `node build.js` in the specific example directory. (Ex: `cd examples/commonjs && node build.js`)
2. Run `npm link webpack` in the root of the project.
3. Run `node build.js` in the specific example directory. (Ex: `cd examples/commonjs && node build.js`)

Note: To build all examples run `npm run build:examples`
32 changes: 27 additions & 5 deletions lib/RuleSet.js
Expand Up @@ -51,7 +51,7 @@
<condition>: { and: [<condition>] }
<condition>: { or: [<condition>] }
<condition>: { not: [<condition>] }
<condition>: { test: <condition>, include: <condition>, exclude: <codition> }
<condition>: { test: <condition>, include: <condition>, exclude: <condition> }
normalized:
Expand Down Expand Up @@ -106,23 +106,37 @@ RuleSet.normalizeRule = function(rule) {
var newRule = {};
var useSource;
var resourceSource;
var condition;

if(rule.test || rule.include || rule.exclude) {
checkResourceSource("test + include + exclude");
newRule.resource = RuleSet.normalizeCondition({
condition = {
test: rule.test,
include: rule.include,
exclude: rule.exclude
});
};
try {
newRule.resource = RuleSet.normalizeCondition(condition);
} catch (error) {
throw new Error(RuleSet.buildErrorMessage(condition, error));
}
}

if(rule.resource) {
checkResourceSource("resource");
newRule.resource = RuleSet.normalizeCondition(rule.resource);
try {
newRule.resource = RuleSet.normalizeCondition(rule.resource);
} catch (error) {
throw new Error(RuleSet.buildErrorMessage(rule.resource, error));
}
}

if(rule.issuer) {
newRule.issuer = RuleSet.normalizeCondition(rule.issuer);
try {
newRule.issuer = RuleSet.normalizeCondition(rule.issuer);
} catch (error) {
throw new Error(RuleSet.buildErrorMessage(rule.issuer, error));
}
}

if(rule.loader && rule.loaders)
Expand Down Expand Up @@ -179,6 +193,14 @@ RuleSet.normalizeRule = function(rule) {
return newRule;
};

RuleSet.buildErrorMessage = function buildErrorMessage(condition, error) {
var conditionAsText = JSON.stringify(condition, function(key, value) {
return (value === undefined) ? "undefined" : value;
}, 2)
var message = error.message + " in " + conditionAsText;
return message;
};

RuleSet.normalizeUse = function normalizeUse(use) {
if(Array.isArray(use)) {
return use.map(RuleSet.normalizeUse).reduce(function(arr, items) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -65,7 +65,7 @@
"worker-loader": "~0.7.0"
},
"engines": {
"node": ">=0.6"
"node": ">=0.12"
},
"repository": {
"type": "git",
Expand Down
62 changes: 62 additions & 0 deletions test/RuleSet.test.js
Expand Up @@ -268,4 +268,66 @@ describe("RuleSet", function() {
(match(loader, 'style.css')).should.eql(['css']);
}, /No loader specified/)
});
describe('when exclude array holds an undefined item', function() {
function errorHasContext(err) {
if (/Expected condition but got falsy value/.test(err)
&& /test/.test(err)
&& /include/.test(err)
&& /exclude/.test(err)
&& /node_modules/.test(err)
&& /undefined/.test(err)) {
return true;
}
}
it('should throw with context', function() {
should.throws(function() {
var loader = new RuleSet([{
test: /\.css$/,
loader: 'css',
include: [
'src',
],
exclude: [
'node_modules',
undefined,
],
}]);
(match(loader, 'style.css')).should.eql(['css']);
}, errorHasContext)
});
it('in resource should throw with context', function() {
should.throws(function() {
var loader = new RuleSet([{
resource: {
test: /\.css$/,
include: [
'src',
],
exclude: [
'node_modules',
undefined,
],
},
}]);
(match(loader, 'style.css')).should.eql(['css']);
}, errorHasContext)
});
it('in issuer should throw with context', function() {
should.throws(function() {
var loader = new RuleSet([{
issuer: {
test: /\.css$/,
include: [
'src',
],
exclude: [
'node_modules',
undefined,
],
},
}]);
(match(loader, 'style.css')).should.eql(['css']);
}, errorHasContext)
});
});
});

0 comments on commit fad1db2

Please sign in to comment.