Skip to content

Commit 6dd05c8

Browse files
Fix dot-paths in dynamic objects
Previously nested constructs containing dot-paths as keys would lead to a crash like "cannot find configuration param 'dot.path'". With some careful hacking around paths we can at least enable this use-case for dynamic objects - it is completely untested/unsupported for regular overlaying. Previous PR that was not merged: mozilla#315
1 parent 95f4ab3 commit 6dd05c8

File tree

8 files changed

+32
-14
lines changed

8 files changed

+32
-14
lines changed

lerna.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"packages": [
33
"packages/*"
44
],
5-
"version": "6.0.0"
5+
"version": "6.0.1-alpha.1"
66
}

packages/convict-format-with-moment/package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"timestamp",
1010
"moment"
1111
],
12-
"version": "6.0.0",
12+
"version": "6.0.1-alpha.1",
1313
"license": "Apache-2.0",
1414
"homepage": "https://github.com/mozilla/node-convict",
1515
"repository": {
@@ -26,5 +26,6 @@
2626
],
2727
"dependencies": {
2828
"moment": "^2.24.0"
29-
}
29+
},
30+
"gitHead": "d345d374498df65397206426d3753fcf5f9701e2"
3031
}

packages/convict-format-with-validator/package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"url",
1111
"validator"
1212
],
13-
"version": "6.0.0",
13+
"version": "6.0.1-alpha.1",
1414
"license": "Apache-2.0",
1515
"homepage": "https://github.com/mozilla/node-convict",
1616
"repository": {
@@ -27,5 +27,6 @@
2727
],
2828
"dependencies": {
2929
"validator": "^11.1.0"
30-
}
30+
},
31+
"gitHead": "d345d374498df65397206426d3753fcf5f9701e2"
3132
}

packages/convict/package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"author": "Lloyd Hilaiel <[email protected]> (http://lloyd.io)",
3-
"name": "convict",
3+
"name": "@atlassian/convict",
44
"description": "Featureful configuration management library for Node.js (nested structure, schema validation, etc.)",
55
"keywords": [
66
"configuration",
@@ -17,7 +17,7 @@
1717
"yaml",
1818
"toml"
1919
],
20-
"version": "6.0.0",
20+
"version": "6.0.1-alpha.1",
2121
"license": "Apache-2.0",
2222
"homepage": "https://github.com/mozilla/node-convict",
2323
"repository": {
@@ -35,5 +35,6 @@
3535
"dependencies": {
3636
"lodash.clonedeep": "^4.5.0",
3737
"yargs-parser": "^18.1.3"
38-
}
38+
},
39+
"gitHead": "d345d374498df65397206426d3753fcf5f9701e2"
3940
}

packages/convict/src/main.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ const ALLOWED_OPTION_STRICT = 'strict'
7373
const ALLOWED_OPTION_WARN = 'warn'
7474

7575
function flatten(obj, useProperties) {
76-
const stack = Object.keys(obj)
76+
const stack = Object.keys(obj).map(k => [k])
7777
let key
7878

7979
const entries = []
@@ -85,9 +85,9 @@ function flatten(obj, useProperties) {
8585
if (useProperties) {
8686
if ('_cvtProperties' in val) {
8787
val = val._cvtProperties
88-
key = key + '._cvtProperties'
88+
key.push('_cvtProperties')
8989
} else {
90-
entries.push([key, val])
90+
entries.push([key.join('.'), val])
9191
continue
9292
}
9393
}
@@ -96,12 +96,12 @@ function flatten(obj, useProperties) {
9696
// Don't filter out empty objects
9797
if (subkeys.length > 0) {
9898
subkeys.forEach(function(subkey) {
99-
stack.push(key + '.' + subkey)
99+
stack.push(key.concat([subkey]))
100100
})
101101
continue
102102
}
103103
}
104-
entries.push([key, val])
104+
entries.push([key.join('.'), val])
105105
}
106106

107107
const flattened = {}
@@ -431,7 +431,7 @@ function loadFile(path) {
431431

432432
function walk(obj, path, initializeMissing) {
433433
if (path) {
434-
const ar = path.split('.')
434+
const ar = Array.isArray(path) ? cloneDeep(path) : path.split('.')
435435
while (ar.length) {
436436
const k = ar.shift()
437437
if (initializeMissing && obj[k] == null) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict'
2+
3+
exports.conf = {
4+
dynamic: {format: Object, default: null}
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"dynamic": {
3+
"dot.path": {}
4+
}
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"dynamic": {
3+
"dot.path": {}
4+
}
5+
}

0 commit comments

Comments
 (0)