uber-node / zero-config

A zero configuration configuration loader
MIT License
116 stars 10 forks source link

Flattening of configChain.store mangles arrays #5

Closed lxe closed 9 years ago

lxe commented 9 years ago
var zeroConfig = require('zero-config')
var config = zeroConfig(process.cwd(), {
  seed: { 
     array: ['bar', 'baz']
  } 
});

console.log(JSON.stringify(config.get(), false, '  '));
// {
//   "seed": {
//     "0": "bar",
//     "1": "baz"
//   }
// } // Object where should be an array

Investigating further (duplicating the flow of get-config-state):

var cc = require('config-chain');
var flatten = require('flatten-prototypes');
var config = cc(
  // seed
  { seed :    ['bar', 'baz'] },

  // defaults
  { defaults: ['bar', 'baz'] }
);

console.log(JSON.stringify(config.store, false, '  '));
// {
//   "seed": [
//     "bar",
//     "baz"
//   ]
// }
// // NOTE: no 'defautls!' (because they are not hasownproperty)

var flatConfig = flatten(config.store);
console.log(JSON.stringify(flatConfig, false, '  '));

// {
//   "defaults": [
//     "bar",
//     "baz"
//   ],
//   "seed": {
//     "0": "bar",
//     "1": "baz"
//   }
// }
// 'seed' array is mangled
lxe commented 9 years ago

I think this have something to do with ConfigChain's ProtoList store

Raynos commented 9 years ago

@lxe the seed value is not supposed to be an array. It's supposed to be an object.

If you find any bugs with nested arrays, let me know.

Raynos commented 9 years ago

Looks like a deep-merge bug.

lxe commented 9 years ago

@Raynos happens with all arrays, not necessarily top-level.

Raynos commented 9 years ago

See https://github.com/uber/flatten-prototypes/pull/4

Raynos commented 9 years ago

Updated flatten-prototypes in zero-config

Raynos commented 9 years ago

Published v3.0.1