Skip to content
This repository has been archived by the owner on Sep 25, 2020. It is now read-only.

Flattening of configChain.store mangles arrays #5

Closed
lxe opened this issue Sep 23, 2014 · 7 comments
Closed

Flattening of configChain.store mangles arrays #5

lxe opened this issue Sep 23, 2014 · 7 comments

Comments

@lxe
Copy link
Contributor

lxe commented Sep 23, 2014

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
Copy link
Contributor Author

lxe commented Sep 23, 2014

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

@Raynos
Copy link
Contributor

Raynos commented Sep 23, 2014

@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
Copy link
Contributor

Raynos commented Sep 23, 2014

Looks like a deep-merge bug.

@lxe
Copy link
Contributor Author

lxe commented Sep 23, 2014

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

@Raynos
Copy link
Contributor

Raynos commented Sep 23, 2014

@Raynos
Copy link
Contributor

Raynos commented Sep 23, 2014

Updated flatten-prototypes in zero-config

@Raynos Raynos closed this as completed Sep 23, 2014
@Raynos
Copy link
Contributor

Raynos commented Sep 23, 2014

Published v3.0.1

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants