configorama 0.3.9 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/lib/main.js +94 -19
- package/lib/utils/trimSurroundingQuotes.js +5 -0
- package/package.json +2 -1
- package/package-lock.json +0 -4426
package/README.md
CHANGED
|
@@ -317,6 +317,10 @@ How is this different than the serverless variable system?
|
|
|
317
317
|
${merge('one', 'two')} => 'onetwo'
|
|
318
318
|
```
|
|
319
319
|
|
|
320
|
+
## Alt libs
|
|
321
|
+
|
|
322
|
+
- https://github.com/01alchemist/sls-yaml
|
|
323
|
+
|
|
320
324
|
## Inspiration
|
|
321
325
|
|
|
322
326
|
This is forked out of the [serverless framework](https://github.com/serverless/serverless/) variable system.
|
package/lib/main.js
CHANGED
|
@@ -29,6 +29,7 @@ const PromiseTracker = require('./utils/PromiseTracker')
|
|
|
29
29
|
const handleSignalEvents = require('./utils/handleSignalEvents')
|
|
30
30
|
const formatFunctionArgs = require('./utils/formatFunctionArgs')
|
|
31
31
|
const cloudFormationSchema = require('./utils/cloudformationSchema')
|
|
32
|
+
const trimSurroundingQuotes = require('./utils/trimSurroundingQuotes')
|
|
32
33
|
/**
|
|
33
34
|
* Maintainer's notes:
|
|
34
35
|
*
|
|
@@ -54,6 +55,7 @@ const selfRefSyntax = RegExp(/^self:/g)
|
|
|
54
55
|
const funcRegex = /(\w+)\s*\(((?:[^()]+)*)?\s*\)\s*/
|
|
55
56
|
const funcStartOfLineRegex = /^(\w+)\s*\(((?:[^()]+)*)?\s*\)\s*/
|
|
56
57
|
const subFunctionRegex = /(\w+):(\w+)\s*\(((?:[^()]+)*)?\s*\)\s*/
|
|
58
|
+
const base64WrapperRegex = /\[_\[([A-Za-z0-9+/=\s]*)\]_\]/g
|
|
57
59
|
const logLines = '─────────────────────────────────────────────────'
|
|
58
60
|
const DEBUG = false
|
|
59
61
|
|
|
@@ -374,7 +376,7 @@ class Configorama {
|
|
|
374
376
|
const transform = this.runFunction.bind(this)
|
|
375
377
|
const varSyntax = this.variableSyntax
|
|
376
378
|
// Traverse resolved object and run functions
|
|
377
|
-
|
|
379
|
+
// console.log('this.config', this.config)
|
|
378
380
|
traverse(this.config).forEach(function (rawValue) {
|
|
379
381
|
/* Pass through unknown variables */
|
|
380
382
|
if (!configoramaOpts.allowUndefinedValues && typeof rawValue === 'undefined') {
|
|
@@ -407,15 +409,13 @@ class Configorama {
|
|
|
407
409
|
this.update(funcVal)
|
|
408
410
|
}
|
|
409
411
|
}
|
|
412
|
+
|
|
413
|
+
|
|
410
414
|
/* Allow for unknown variables to pass through */
|
|
411
415
|
if (rawValue.match(/>passthrough/)) {
|
|
412
|
-
const
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
if (matches) {
|
|
416
|
-
const actualValue = Buffer.from(matches[1], 'base64').toString('ascii')
|
|
417
|
-
this.update(actualValue)
|
|
418
|
-
}
|
|
416
|
+
const newValues = decodeUnknown(rawValue)
|
|
417
|
+
// console.log('>>>> newValues', newValues)
|
|
418
|
+
this.update(newValues)
|
|
419
419
|
}
|
|
420
420
|
}
|
|
421
421
|
})
|
|
@@ -778,14 +778,13 @@ class Configorama {
|
|
|
778
778
|
* value for all instances of the given matched string.
|
|
779
779
|
*/
|
|
780
780
|
populateVariable(valueObject, matchedString, valueToPopulate) {
|
|
781
|
+
let property = valueObject.value
|
|
781
782
|
if (DEBUG) {
|
|
782
783
|
console.log('------')
|
|
783
784
|
console.log('populateVariable: valueToPopulate', valueToPopulate)
|
|
784
|
-
console.log('matchedString', matchedString)
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
if (DEBUG) {
|
|
788
|
-
console.log('property', property)
|
|
785
|
+
console.log('populateVariable: matchedString', matchedString)
|
|
786
|
+
console.log('populateVariable: valueObject', valueObject)
|
|
787
|
+
console.log('populateVariable: property', property)
|
|
789
788
|
console.log('------')
|
|
790
789
|
}
|
|
791
790
|
|
|
@@ -803,10 +802,36 @@ class Configorama {
|
|
|
803
802
|
// console.log('xxxx', rep)
|
|
804
803
|
// console.log('valueToPopulate', valueToPopulate)
|
|
805
804
|
// }
|
|
806
|
-
|
|
805
|
+
|
|
806
|
+
|
|
807
|
+
let currentMatchedString = matchedString
|
|
808
|
+
/* Address fall through values if found */
|
|
809
|
+
if (valueToPopulate.match(/>passthrough/)) {
|
|
810
|
+
const decoded = decodeUnknown(valueToPopulate)
|
|
811
|
+
if (decoded === property) {
|
|
812
|
+
currentMatchedString = valueObject.value
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
/*
|
|
817
|
+
console.log('>------')
|
|
818
|
+
console.log('isString og matchedString', matchedString)
|
|
819
|
+
console.log('isString replaceThis: matchedString', currentMatchedString)
|
|
820
|
+
console.log('isString withThis: valueToPopulate', valueToPopulate)
|
|
821
|
+
console.log('isString decode:', decodeUnknown(valueToPopulate))
|
|
822
|
+
console.log('isString inThis: property', property)
|
|
823
|
+
console.log('isString currentMatchedString', currentMatchedString)
|
|
824
|
+
console.log('>------')
|
|
825
|
+
/** */
|
|
826
|
+
|
|
827
|
+
// (replaceThis, withThis, inThis)
|
|
828
|
+
property = replaceall(currentMatchedString, valueToPopulate, property)
|
|
829
|
+
// console.log('property', property)
|
|
830
|
+
|
|
807
831
|
// if (property.match(/^> function /g)) {
|
|
808
832
|
// console.log('REPLACE after', property)
|
|
809
833
|
// }
|
|
834
|
+
|
|
810
835
|
// partial replacement, number
|
|
811
836
|
} else if (_.isNumber(valueToPopulate)) {
|
|
812
837
|
property = replaceall(matchedString, String(valueToPopulate), property)
|
|
@@ -861,7 +886,9 @@ ${valueObject.path}: ${valueObject.originalSource}
|
|
|
861
886
|
}
|
|
862
887
|
|
|
863
888
|
if (property && typeof property === 'string') {
|
|
889
|
+
// console.log('property', property)
|
|
864
890
|
const prop = cleanVariable(property, this.variableSyntax)
|
|
891
|
+
// console.log('prop', prop)
|
|
865
892
|
if (property.match(/^> function /g) && prop) {
|
|
866
893
|
// console.log('PRPOpropertyproperty', property)
|
|
867
894
|
// console.log('Prop', prop)
|
|
@@ -914,7 +941,9 @@ ${valueObject.path}: ${valueObject.originalSource}
|
|
|
914
941
|
// property = newer
|
|
915
942
|
// }
|
|
916
943
|
}
|
|
917
|
-
|
|
944
|
+
// console.log('XXXX property', property)
|
|
945
|
+
// console.log('XXXX path', valueObject.path)
|
|
946
|
+
// console.log('XXXX originalSource', valueObject.originalSource)
|
|
918
947
|
return {
|
|
919
948
|
value: property,
|
|
920
949
|
path: valueObject.path,
|
|
@@ -1220,7 +1249,17 @@ Like so: \${${variableString}, "fallbackValue"\}.`)
|
|
|
1220
1249
|
|
|
1221
1250
|
/* Pass through unknown variables */
|
|
1222
1251
|
if (this.opts.passThroughUnknown) {
|
|
1223
|
-
|
|
1252
|
+
// console.log('passThroughUnknown propertyString', propertyString)
|
|
1253
|
+
const varMatches = propertyString.match(this.variableSyntax)
|
|
1254
|
+
let passThroughUnknown = propertyString
|
|
1255
|
+
/* If variables found, encode them for passthrough */
|
|
1256
|
+
if (varMatches && varMatches.length) {
|
|
1257
|
+
varMatches.forEach((m) => {
|
|
1258
|
+
passThroughUnknown = passThroughUnknown.replace(m, encodeUnknown(m))
|
|
1259
|
+
})
|
|
1260
|
+
}
|
|
1261
|
+
// console.log('passThroughUnknown propertyString:', propertyString)
|
|
1262
|
+
// console.log('passThroughUnknown:', passThroughUnknown)
|
|
1224
1263
|
return Promise.resolve(passThroughUnknown)
|
|
1225
1264
|
}
|
|
1226
1265
|
|
|
@@ -1261,7 +1300,7 @@ Like so: \${${variableString}, "fallbackValue"\}.`)
|
|
|
1261
1300
|
}
|
|
1262
1301
|
|
|
1263
1302
|
getValueFromFile(variableString) {
|
|
1264
|
-
// console.log('From file', variableString)
|
|
1303
|
+
// console.log('From file', `"${variableString}"`)
|
|
1265
1304
|
let matchedFileString = variableString.match(fileRefSyntax)[0]
|
|
1266
1305
|
// console.log('matchedFileString', matchedFileString)
|
|
1267
1306
|
|
|
@@ -1287,12 +1326,15 @@ Like so: \${${variableString}, "fallbackValue"\}.`)
|
|
|
1287
1326
|
}
|
|
1288
1327
|
// console.log('argsToPass', argsToPass)
|
|
1289
1328
|
|
|
1290
|
-
const relativePath = matchedFileString
|
|
1329
|
+
const relativePath = trimSurroundingQuotes(matchedFileString
|
|
1291
1330
|
.replace(fileRefSyntax, (match, varName) => varName.trim())
|
|
1292
|
-
.replace('~', os.homedir())
|
|
1331
|
+
.replace('~', os.homedir()))
|
|
1332
|
+
|
|
1293
1333
|
|
|
1294
1334
|
let fullFilePath = (path.isAbsolute(relativePath) ? relativePath : path.join(this.configPath, relativePath))
|
|
1295
1335
|
|
|
1336
|
+
// console.log('fullFilePath', fullFilePath)
|
|
1337
|
+
|
|
1296
1338
|
if (fs.existsSync(fullFilePath)) {
|
|
1297
1339
|
// Get real path to handle potential symlinks (but don't fatal error)
|
|
1298
1340
|
fullFilePath = fs.realpathSync(fullFilePath)
|
|
@@ -1587,6 +1629,39 @@ Remove or update the \${${variableString}} to fix
|
|
|
1587
1629
|
return isRealVariable
|
|
1588
1630
|
}
|
|
1589
1631
|
|
|
1632
|
+
function encodeUnknown(v) {
|
|
1633
|
+
return `>passthrough[_[${Buffer.from(v).toString('base64')}]_]`
|
|
1634
|
+
}
|
|
1635
|
+
|
|
1636
|
+
function decodeUnknown(rawValue) {
|
|
1637
|
+
const x = findUnknownValues(rawValue)
|
|
1638
|
+
let val = rawValue.replace(/>passthrough/g, '')
|
|
1639
|
+
if (x.length) {
|
|
1640
|
+
x.forEach(({ match, value }) => {
|
|
1641
|
+
// console.log('match', match)
|
|
1642
|
+
const decodedValue = Buffer.from(value, 'base64').toString('ascii')
|
|
1643
|
+
// console.log('decodedValue', decodedValue)
|
|
1644
|
+
val = val.replace(match, decodedValue)
|
|
1645
|
+
})
|
|
1646
|
+
}
|
|
1647
|
+
return val
|
|
1648
|
+
}
|
|
1649
|
+
|
|
1650
|
+
function findUnknownValues(text) {
|
|
1651
|
+
let matches
|
|
1652
|
+
let links = []
|
|
1653
|
+
while ((matches = base64WrapperRegex.exec(text)) !== null) {
|
|
1654
|
+
if (matches.index === base64WrapperRegex.lastIndex) {
|
|
1655
|
+
base64WrapperRegex.lastIndex++ // avoid infinite loops with zero-width matches
|
|
1656
|
+
}
|
|
1657
|
+
links.push({
|
|
1658
|
+
match: matches[0],
|
|
1659
|
+
value: matches[1]
|
|
1660
|
+
})
|
|
1661
|
+
}
|
|
1662
|
+
return links
|
|
1663
|
+
}
|
|
1664
|
+
|
|
1590
1665
|
function isPromise(obj) { // eslint-disable-line
|
|
1591
1666
|
return !!obj && (typeof obj === 'object' || typeof obj === 'function') && typeof obj.then === 'function'
|
|
1592
1667
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "configorama",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "Variable support for configuration files",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"files": [
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"scripts": {
|
|
13
13
|
"docs": "node ./scripts/docs.js",
|
|
14
14
|
"test": "ava -v",
|
|
15
|
+
"test:api": "ava ./tests/api/api.test.js -v",
|
|
15
16
|
"watch": "npm test -- --watch -v",
|
|
16
17
|
"publish": "git push origin && git push origin --tags",
|
|
17
18
|
"release:patch": "npm version patch && npm publish",
|