From 93f1c7e0fcba718820d259e4d7994026c44f170e Mon Sep 17 00:00:00 2001 From: Maarten Winter Date: Tue, 9 Feb 2016 15:07:40 +0100 Subject: [PATCH 01/26] 5.0.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index caa0605..8ffbfc3 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Morten Siebuhr ", "name": "oconf", "description": "Configuration", - "version": "4.1.0", + "version": "5.0.0", "repository": { "type": "git", "url": "https://github.com/One-com/node-oconf.git" From e3a7d9d9527731ba29a005f93902e103fa24b267 Mon Sep 17 00:00:00 2001 From: Andreas Lind Date: Thu, 11 Feb 2016 14:15:05 +0100 Subject: [PATCH 02/26] Add support for #public-suffixed keys as suggested by @msiebuhr on #25. --- lib/index.js | 16 ++++++++++++- package.json | 3 ++- test/lib/index.spec.js | 54 +++++++++++++++++++++++++++++++++++++++++- 3 files changed, 70 insertions(+), 3 deletions(-) diff --git a/lib/index.js b/lib/index.js index f6f2837..7060a13 100644 --- a/lib/index.js +++ b/lib/index.js @@ -38,8 +38,11 @@ module.exports.load = function load(rootFileName, options) { if (typeof obj === 'object' && obj !== null) { var publicObj = Array.isArray(obj) ? [] : {}; + var hashPublicSuffixedKeys = []; Object.keys(obj).forEach(function (key) { - if (key !== '#public') { + if (/.+#public$/.test(key)) { + hashPublicSuffixedKeys.push(key); + } else if (key !== '#public') { // Have to extract public and non-public keys separately, otherwise we lose information var resolvedPublic = resolvePublic(obj[key], false, true); if (typeof resolvedPublic === 'object' && resolvedPublic !== null && Object.keys(resolvedPublic).length > 0) { @@ -49,6 +52,17 @@ module.exports.load = function load(rootFileName, options) { obj[key] = resolvePublic(obj[key], false, false); } }); + if (hashPublicSuffixedKeys.length > 0) { + obj['#public'] = obj['#public'] || {}; + hashPublicSuffixedKeys.forEach(function (hashPublicSuffixedKey) { + var keyWithoutSuffix = hashPublicSuffixedKey.replace(/#public$/, ''); + if (keyWithoutSuffix in obj['#public']) { + throw new Error(hashPublicSuffixedKey + ' clashes with ' + keyWithoutSuffix + ' inside #public block'); + } + obj['#public'][keyWithoutSuffix] = obj[hashPublicSuffixedKey]; + delete obj[hashPublicSuffixedKey]; + }); + } if (typeof obj['#public'] !== 'undefined') { if (!(typeof obj['#public'] === 'object' && obj['#public'] !== null && !Array.isArray(obj['#public']))) { diff --git a/package.json b/package.json index 8ffbfc3..d01ac30 100644 --- a/package.json +++ b/package.json @@ -47,6 +47,7 @@ "jscs": "1.10.0", "jshint": "2.5.11", "mocha": "*", - "unexpected": "10.8.1" + "unexpected": "10.8.1", + "unexpected-fs": "2.1.3" } } diff --git a/test/lib/index.spec.js b/test/lib/index.spec.js index 258839f..4395a6a 100644 --- a/test/lib/index.spec.js +++ b/test/lib/index.spec.js @@ -1,5 +1,5 @@ /*global describe, it, before*/ -var expect = require('unexpected'); +var expect = require('unexpected').clone().use(require('unexpected-fs')); var oconf = require('../../lib/index'); function testFile(filename) { @@ -387,4 +387,56 @@ describe('#public behaviour', function () { }, 'to throw', /^\#public must always be an object/); }); }); + + expect.addAssertion(' to resolve to ', function (expect, subject, value) { + return expect(function () { + expect(oconf.load('/testdata/config.cjson'), 'to equal', value); + }, 'with fs mocked out', { + '/testdata': { + 'config.cjson': JSON.stringify(subject) + } + }, 'not to error'); + }); + + expect.addAssertion(' to result in error ', function (expect, subject, value) { + return expect(function () { + expect(oconf.load('/testdata/config.cjson'), 'to equal', value); + }, 'with fs mocked out', { + '/testdata': { + 'config.cjson': JSON.stringify(subject) + } + }, 'to error', value); + }); + + describe('with a #public-suffixed key', function () { + it('treats the key as if contained inside a #public block', function () { + expect({ + foo: { + 'bar#public': 123, + quux: 456 + } + }, 'to resolve to', { + foo: { + bar: 123, + quux: 456 + }, + '#public': { + foo: { + bar: 123 + } + } + }); + }); + + it('complains if a #public-suffixed key shadows an entry inside a #public block', function () { + expect({ + foo: { + '#public': { + foo: 123 + }, + 'foo#public': 456 + } + }, 'to result in error', new Error('foo#public clashes with foo inside #public block')); + }); + }); }); From 5c819b72c988cf7c393aa0622fd614035eaf5226 Mon Sep 17 00:00:00 2001 From: Andreas Lind Date: Thu, 11 Feb 2016 14:22:12 +0100 Subject: [PATCH 03/26] 5.1.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d01ac30..c800108 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Morten Siebuhr ", "name": "oconf", "description": "Configuration", - "version": "5.0.0", + "version": "5.1.0", "repository": { "type": "git", "url": "https://github.com/One-com/node-oconf.git" From f6048e8d81d5162b58e5b525f9a33cb26733f890 Mon Sep 17 00:00:00 2001 From: Andreas Lind Date: Thu, 11 Feb 2016 15:49:10 +0100 Subject: [PATCH 04/26] Added some failing tests, seems like I didn't cover all the combinations of #public blocks and #public-suffixed keys. --- test/lib/index.spec.js | 62 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/test/lib/index.spec.js b/test/lib/index.spec.js index 4395a6a..e725893 100644 --- a/test/lib/index.spec.js +++ b/test/lib/index.spec.js @@ -438,5 +438,67 @@ describe('#public behaviour', function () { } }, 'to result in error', new Error('foo#public clashes with foo inside #public block')); }); + + it.skip('should allow overwriting a key inside a #public block with a #public-suffixed key of the same name', function () { + return expect(function () { + expect(oconf.load('/testdata/config.cjson'), 'to equal', { + foo: { + abc: 123 + }, + '#public': { + foo: { + abc: 123 + } + } + }); + }, 'with fs mocked out', { + '/testdata': { + 'config.cjson': JSON.stringify({ + '#include': '/testdata/included.cjson', + foo: { + 'abc#public': 123 + } + }), + 'included.cjson': JSON.stringify({ + foo: { + '#public': { + abc: 456 + } + } + }) + } + }, 'not to error'); + }); + + it.skip('should allow overwriting a #public-suffixed key with a key of the same name inside a #public block', function () { + return expect(function () { + expect(oconf.load('/testdata/config.cjson'), 'to equal', { + foo: { + abc: 123 + }, + '#public': { + foo: { + abc: 123 + } + } + }); + }, 'with fs mocked out', { + '/testdata': { + 'config.cjson': JSON.stringify({ + '#include': '/testdata/included.cjson', + foo: { + '#public': { + abc: 123 + } + } + }), + 'included.cjson': JSON.stringify({ + foo: { + 'abc#public': 456 + } + }) + } + }, 'not to error'); + }); }); }); From 300b6967a3d84c2f8aae446a31d7bd00a1f53119 Mon Sep 17 00:00:00 2001 From: Maarten Winter Date: Tue, 16 Feb 2016 11:51:22 +0100 Subject: [PATCH 05/26] Output the culprit when an unsupported combination of public and non-public properties is used --- lib/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index 7060a13..e57ec73 100644 --- a/lib/index.js +++ b/lib/index.js @@ -71,7 +71,7 @@ module.exports.load = function load(rootFileName, options) { Object.keys(obj['#public']).forEach(function (key) { if (key in obj) { - throw new Error('Unsupported combination of public and non-public properties, check your tree structure'); + throw new Error('Unsupported combination of public and non-public properties for key "' + key + '", check your tree structure: ' + JSON.stringify(obj)); } if (obj['#public'][key] !== 'undefined') { From a3fedc8f29c1929e8008bb950589ca466422172e Mon Sep 17 00:00:00 2001 From: Maarten Winter Date: Tue, 16 Feb 2016 11:51:45 +0100 Subject: [PATCH 06/26] 5.1.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c800108..df42155 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Morten Siebuhr ", "name": "oconf", "description": "Configuration", - "version": "5.1.0", + "version": "5.1.1", "repository": { "type": "git", "url": "https://github.com/One-com/node-oconf.git" From 64c40f5bdbeb2b7c21cc352d95298a14a5603a05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesper=20Birkestr=C3=B8m?= Date: Mon, 20 Jun 2016 17:25:48 +0200 Subject: [PATCH 07/26] Remove deprecated util.puts --- bin/oconf | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/bin/oconf b/bin/oconf index 1850979..57e1ec2 100755 --- a/bin/oconf +++ b/bin/oconf @@ -1,7 +1,5 @@ #!/usr/bin/env node - var oconf = require('../lib/index'); -var util = require('util'); var argp = require('optimist') .usage('Usage: $0 [--lint|--extract-option