Skip to content
This repository has been archived by the owner on Jun 18, 2019. It is now read-only.

Commit

Permalink
v2.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mdreizin committed Nov 20, 2015
2 parents 4ca05a6 + fd822d1 commit 1a18cb9
Show file tree
Hide file tree
Showing 18 changed files with 83 additions and 70 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
sudo: false
language: node_js
node_js:
- '4.2'
- '4.1'
- '4.0'
- '0.12'
- 'iojs'
matrix:
fast_finish: true
os:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ module.exports = new WebpackConfig().extend({

var WebpackConfig = require('webpack-config');

// Please use `process.env.WEBPACK_ENV || process.env.NODE_ENV` to set `[env]` or override it via `WebpackConfig.environment.set({ env: 'dev' })`.
// Please use `process.env.WEBPACK_ENV || process.env.NODE_ENV` to set `[env]` variable or override it via `WebpackConfig.environment.set({ env: 'dev' })`.
module.exports = new WebpackConfig().extend('./conf/webpack.[env].config.js');

```
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ matrix:
fast_finish: true
environment:
matrix:
- nodejs_version: 4.2
- nodejs_version: 4.1
- nodejs_version: 4.0
- nodejs_version: 1.0
- nodejs_version: 0.12
platform:
- x86
Expand Down
7 changes: 4 additions & 3 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ Resolves path

* [ConfigVisitor](#ConfigVisitor)
* [new ConfigVisitor(loader, pathResolver, [excludeFields])](#new_ConfigVisitor_new)
* [.visit(...arguments)](#ConfigVisitor+visit) ⇒ <code>Object.&lt;String, Config&gt;</code>
* [.visit(options, context)](#ConfigVisitor+visit) ⇒ <code>Object.&lt;String, Config&gt;</code>

<a name="new_ConfigVisitor_new"></a>
### new ConfigVisitor(loader, pathResolver, [excludeFields])
Expand All @@ -408,14 +408,15 @@ Resolves path
| [excludeFields] | <code>Array.&lt;String&gt;</code> | <code>[&#x27;filename&#x27;]</code> |

<a name="ConfigVisitor+visit"></a>
### configVisitor.visit(...arguments) ⇒ <code>Object.&lt;String, Config&gt;</code>
### configVisitor.visit(options, context) ⇒ <code>Object.&lt;String, Config&gt;</code>
Returns `visited` configs

**Kind**: instance method of <code>[ConfigVisitor](#ConfigVisitor)</code>

| Param | Type |
| --- | --- |
| ...arguments | <code>ExtendOptions</code> |
| options | <code>Array.&lt;ExtendOptions&gt;</code> |
| context | <code>\*</code> |

<a name="ConfigCloneMixin"></a>
## ConfigCloneMixin
Expand Down
5 changes: 3 additions & 2 deletions lib/configExtendMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var _ = require('lodash'),
/**
* Extend options
* @alias ExtendOptions
* @typedef {(String|String[]|Object<String,Function>|Object<String,Boolean>)}
* @typedef {(String[]|Object<String,Function>|Object<String,Boolean>)}
*/

/**
Expand All @@ -24,7 +24,8 @@ var ConfigExtendMixin = {
var configVisitor = this.constructor.visitor;

if (configVisitor instanceof ConfigVisitor) {
var visited = configVisitor.visit.apply(configVisitor, arguments);
var options = _.flatten(_.toArray(arguments), true),
visited = configVisitor.visit(options, this);

_.forEach(visited, function (value) {
this.merge(value);
Expand Down
19 changes: 11 additions & 8 deletions lib/configVisitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,11 @@ function ConfigVisitor(loader, pathResolver, excludeFields) {
/**
* Converts `arguments` to `Object<String,Function>` transforms
* @private
* @param {...ExtendOptions} arguments
* @param {ExtendOptions[]} options
* @returns {Object<String,Function>}
*/
ConfigVisitor.prototype.toTransforms = function() {
var args = _.flatten(_.toArray(arguments), true);

var transforms = _.reduce(args, function(acc, value) {
ConfigVisitor.prototype.toTransforms = function(options) {
var transforms = _.reduce(options, function(acc, value) {
if (_.isString(value)) {
acc[value] = defaultTransform;
} else if (_.isObject(value)) {
Expand All @@ -60,18 +58,23 @@ ConfigVisitor.prototype.toTransforms = function() {

/**
* Returns `visited` configs
* @param {...ExtendOptions} arguments
* @param {ExtendOptions[]} options
* @param {*} context
* @returns {Object<String,Config>}
*/
ConfigVisitor.prototype.visit = function() {
ConfigVisitor.prototype.visit = function(options, context) {
var visited = {},
transforms = this.toTransforms(arguments);
transforms = this.toTransforms(options);

_.forEach(transforms, function(value, key) {
if (!_.has(visited, key)) {
var currentConfig = this.loader.load(key);

if (_.isFunction(value)) {
if (context) {
value = _.bind(value, context);
}

currentConfig = value(currentConfig);
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,5 @@
"dependencies": {
"lodash": "^3.10.1"
},
"version": "2.0.0"
"version": "2.1.0"
}
2 changes: 1 addition & 1 deletion test/configCloneMixin.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var expect = require('expect.js'),

describe('ConfigCloneMixin', function () {
context('#clone()', function() {
it('should return clone of "Config"', function() {
it('should return clone of `Config`', function() {
var config = new Config();

config.merge({
Expand Down
2 changes: 1 addition & 1 deletion test/configDefaultsMixin.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var expect = require('expect.js'),

describe('ConfigDefaultsMixin', function () {
context('#defaults()', function() {
it('should add missing "options"', function() {
it('should add missing `options`', function() {
var config = new Config(),
date1 = new Date(),
date2 = new Date();
Expand Down
6 changes: 3 additions & 3 deletions test/configEnvironment.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ describe('ConfigEnvironment', function () {
delete process.env.NODE_ENV;
});

it('should return "process.env.WEBPACK_ENV"', function() {
it('should return `process.env.WEBPACK_ENV`', function() {
expect(configEnvironment.get('WEBPACK_ENV')).to.eql('foo');
});

it('should return "process.env.NODE_ENV"', function() {
it('should return `process.env.NODE_ENV`', function() {
expect(configEnvironment.get('NODE_ENV')).to.eql('bar');
});

it('should return "env"', function() {
it('should return `env`', function() {
expect(configEnvironment.get('env')).to.eql('foo');
});
});
Expand Down
14 changes: 7 additions & 7 deletions test/configExtendMixin.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('ConfigExtendMixin', function () {
Config.visitor = configVisitor;

context('#extend()', function() {
it('should extend via "String"', function() {
it('should extend via `String`', function() {
var config = new Config();

config.extend('./test/fixtures/webpack.5.config.js');
Expand All @@ -40,7 +40,7 @@ describe('ConfigExtendMixin', function () {
});
});

it('should extend via "String[]"', function() {
it('should extend via `String[]`', function() {
var config = new Config();

config.extend([
Expand All @@ -61,7 +61,7 @@ describe('ConfigExtendMixin', function () {
});
});

it('should extend via "Object<String,Function>"', function() {
it('should extend via `Object<String,Function>`', function() {
var config = new Config();

function configTransform(x) {
Expand All @@ -86,7 +86,7 @@ describe('ConfigExtendMixin', function () {
});
});

it('should extend via "Object<String,Boolean>"', function() {
it('should extend via `Object<String,Boolean>`', function() {
var config = new Config();

config.extend({
Expand All @@ -108,7 +108,7 @@ describe('ConfigExtendMixin', function () {
});
});

it('should pass "Config" to transform "Function"', function() {
it('should pass `Config` to transform `Function`', function() {
var config = new Config();

function configTransform(x) {
Expand All @@ -128,7 +128,7 @@ describe('ConfigExtendMixin', function () {
});
});

it('should accept plain "Object" which was returned from transform "Function"', function() {
it('should accept plain `Object` which was returned from transform `Function`', function() {
var config = new Config();

function configTransform() {
Expand All @@ -146,7 +146,7 @@ describe('ConfigExtendMixin', function () {
});
});

it('should return empty "Object" when transform "Function" does not return nothing', function() {
it('should return empty `Object` when transform `Function` does not return nothing', function() {
var config = new Config();

function configTransform() {}
Expand Down
12 changes: 6 additions & 6 deletions test/configFactory.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('ConfigFactory', function () {
var configFactory = new ConfigFactory();

context('#create()', function() {
it('should create "Config" from "Object"', function() {
it('should create `Config` from `Object`', function() {
var config = configFactory.create({
foo: 'foo1'
});
Expand All @@ -20,7 +20,7 @@ describe('ConfigFactory', function () {
});
});

it('should create "Config[]" from "Object[]"', function() {
it('should create `Config[]` from `Object[]`', function() {
var configs = configFactory.create([{
foo: 'foo1'
}]);
Expand All @@ -33,7 +33,7 @@ describe('ConfigFactory', function () {
});
});

it('should create "Config" from "Object" via "Function"', function() {
it('should create `Config` from `Object` via `Function`', function() {
var config = configFactory.create(function() {
return {
foo: 'foo1'
Expand All @@ -47,7 +47,7 @@ describe('ConfigFactory', function () {
});
});

it('should create "Config[]" from "Object[]" via "Function"', function() {
it('should create `Config[]` from `Object[]` via `Function`', function() {
var configs = configFactory.create(function() {
return [{
foo: 'foo1'
Expand All @@ -62,7 +62,7 @@ describe('ConfigFactory', function () {
});
});

it('should create "Config" from "Config"', function() {
it('should create `Config` from `Config`', function() {
var config = configFactory.create(new Config().merge({
foo: 'foo1'
}));
Expand All @@ -74,7 +74,7 @@ describe('ConfigFactory', function () {
});
});

it('should create "Config[]" from "Config[]"', function() {
it('should create `Config[]` from `Config[]`', function() {
var configs = configFactory.create([new Config().merge({
foo: 'foo1'
})]);
Expand Down
2 changes: 1 addition & 1 deletion test/configFinder.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('ConfigFinder', function () {
});
});

it('should return "null" when config does not exist', function() {
it('should return `null` when config does not exist', function() {
var config = configFinder.closest('./webpack.config.js');

expect(config).to.eql(null);
Expand Down
6 changes: 3 additions & 3 deletions test/configLoader.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('ConfigLoader', function () {
fs.remove(path.dirname(filename), done);
});

it('should return same configs when "useCache" is "true"', function() {
it('should return same configs when `useCache` is `true`', function() {
var config1 = configLoader.load(filename);

updateConfig();
Expand All @@ -42,7 +42,7 @@ describe('ConfigLoader', function () {
expect(config1.toObject()).to.eql(config2.toObject());
});

it('should return different configs when "useCache" is "false"', function () {
it('should return different configs when `useCache` is `false`', function () {
var config1 = configLoader.load(filename);

configLoader.useCache = false;
Expand All @@ -54,7 +54,7 @@ describe('ConfigLoader', function () {
expect(config1.toObject()).not.to.eql(config2.toObject());
});

it('should throw exception if "filename" does not exist', function () {
it('should throw exception if `filename` does not exist', function () {
expect(configLoader.load).withArgs('./test/fixtures/webpack.not-found.config.js').to.throwError();
});
});
Expand Down
2 changes: 1 addition & 1 deletion test/configMergeMixin.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var expect = require('expect.js'),

describe('ConfigMergeMixin', function () {
context('#merge()', function() {
it('should merge "options"', function() {
it('should merge `options`', function() {
var config = new Config();

config.merge({
Expand Down
8 changes: 4 additions & 4 deletions test/configNameResolver.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,25 @@ describe('ConfigNameResolver', function () {
configNameResolver = new ConfigNameResolver(configEnvironment);

context('#resolve()', function() {
it('should replace "[env]" with "bar"', function() {
it('should replace `[env]` with `bar`', function() {
var filename = configNameResolver.resolve('webpack.[env].config.js');

expect(filename).to.eql('webpack.bar.config.js');
});

it('should replace "[webpack_env]" with "foo"', function() {
it('should replace `[webpack_env]` with `foo`', function() {
var filename = configNameResolver.resolve('webpack.[webpack_env].config.js');

expect(filename).to.eql('webpack.foo.config.js');
});

it('should replace "[node_env]" with "bar"', function() {
it('should replace `[node_env]` with `bar`', function() {
var filename = configNameResolver.resolve('webpack.[node_env].config.js');

expect(filename).to.eql('webpack.bar.config.js');
});

it('should replace "[rev]" with "1"', function() {
it('should replace `[rev]` with `1`', function() {
var filename = configNameResolver.resolve('webpack.[rev].config.js');

expect(filename).to.eql('webpack.1.config.js');
Expand Down
2 changes: 1 addition & 1 deletion test/configToObjectMixin.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var expect = require('expect.js'),

describe('ConfigToObjectMixin', function () {
context('#toObject()', function() {
it('should return plain "Object"', function() {
it('should return plain `Object`', function() {
var config = new Config();

config.merge({
Expand Down
Loading

0 comments on commit 1a18cb9

Please sign in to comment.