Skip to content

Instantly share code, notes, and snippets.

@mfncooper
Created February 4, 2013 02:13
Show Gist options
  • Save mfncooper/4704670 to your computer and use it in GitHub Desktop.
Save mfncooper/4704670 to your computer and use it in GitHub Desktop.
Illustrates "Bug in specialising config for publishing", https://github.com/isaacs/npm/issues/3121 Creating an npmconf.Conf instance from an existing instance results in the correct lookup chain, but loses named configs.
// Illustrates "Bug in specialising config for publishing"
// https://github.com/isaacs/npm/issues/3121
var npmconf = require('npmconf');
npmconf.load({ abc: 'my_cli_value'}, function (err, conf) {
// Print some entries from the initial config
console.log("Original config:");
console.log("\tabc: ", conf.get('abc', 'cli'));
console.log("\ttag: ", conf.get('tag'));
// Create a publishConfig
var publishConfig = { tag: 'new_tag' },
pubConf = new npmconf.Conf(conf);
// Prepend publishConfig in the same way that npm's 'publish' does
pubConf.unshift(Object.keys(publishConfig).reduce(function (s, k) {
s[k] = publishConfig[k];
return s;
}, {}));
// Print the same entries as above, but different tag now
console.log("Publish config:");
console.log("\tabc: ", pubConf.get('abc', 'cli')); // undefined; no named configs now
console.log("\ttag: ", pubConf.get('tag'));
// Try to set some values in pubConf
pubConf.set('abc', 'my_internal_value'); // okay; not a named config
pubConf.set('tag', 'another_new_tag', 'user'); // error; no named configs exist
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment