configorama 0.4.0 → 0.4.2

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/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
  *
@@ -70,7 +71,7 @@ class Configorama {
70
71
  // Set opts to pass into JS file calls
71
72
  this.opts = Object.assign({}, {
72
73
  // Allow for unknown variable syntax to pass through without throwing errors
73
- passThroughUnknown: false,
74
+ allowUnknownVars: false,
74
75
  // Allow undefined to be an end result.
75
76
  allowUndefinedValues: false,
76
77
  }, options)
@@ -859,7 +860,7 @@ class Configorama {
859
860
 
860
861
  if (nestedVar) {
861
862
  const fallbackStr = getFallbackString(splitVars, nestedVar)
862
- if (!this.opts.passThroughUnknown) {
863
+ if (!this.opts.allowUnknownVars) {
863
864
  verifyVariable(nestedVar, valueObject, this.variableTypes, this.config)
864
865
  }
865
866
 
@@ -1193,7 +1194,7 @@ Like so: \${${variableString}, "fallbackValue"\}.`)
1193
1194
  const nestedVar = findNestedVariable(split, valueObject.originalSource)
1194
1195
 
1195
1196
  if (nestedVar) {
1196
- if (!this.opts.passThroughUnknown) {
1197
+ if (!this.opts.allowUnknownVars) {
1197
1198
  verifyVariable(nestedVar, valueObject, this.variableTypes, this.config)
1198
1199
  }
1199
1200
  const fallbackStr = getFallbackString(split, nestedVar)
@@ -1247,19 +1248,19 @@ Like so: \${${variableString}, "fallbackValue"\}.`)
1247
1248
  }
1248
1249
 
1249
1250
  /* Pass through unknown variables */
1250
- if (this.opts.passThroughUnknown) {
1251
- // console.log('passThroughUnknown propertyString', propertyString)
1251
+ if (this.opts.allowUnknownVars) {
1252
+ // console.log('allowUnknownVars propertyString', propertyString)
1252
1253
  const varMatches = propertyString.match(this.variableSyntax)
1253
- let passThroughUnknown = propertyString
1254
+ let allowUnknownVars = propertyString
1254
1255
  /* If variables found, encode them for passthrough */
1255
1256
  if (varMatches && varMatches.length) {
1256
1257
  varMatches.forEach((m) => {
1257
- passThroughUnknown = passThroughUnknown.replace(m, encodeUnknown(m))
1258
+ allowUnknownVars = allowUnknownVars.replace(m, encodeUnknown(m))
1258
1259
  })
1259
1260
  }
1260
- // console.log('passThroughUnknown propertyString:', propertyString)
1261
- // console.log('passThroughUnknown:', passThroughUnknown)
1262
- return Promise.resolve(passThroughUnknown)
1261
+ // console.log('allowUnknownVars propertyString:', propertyString)
1262
+ // console.log('allowUnknownVars:', allowUnknownVars)
1263
+ return Promise.resolve(allowUnknownVars)
1263
1264
  }
1264
1265
 
1265
1266
  const message = errorMessage.join('\n')
@@ -1299,7 +1300,7 @@ Like so: \${${variableString}, "fallbackValue"\}.`)
1299
1300
  }
1300
1301
 
1301
1302
  getValueFromFile(variableString) {
1302
- // console.log('From file', variableString)
1303
+ // console.log('From file', `"${variableString}"`)
1303
1304
  let matchedFileString = variableString.match(fileRefSyntax)[0]
1304
1305
  // console.log('matchedFileString', matchedFileString)
1305
1306
 
@@ -1325,12 +1326,15 @@ Like so: \${${variableString}, "fallbackValue"\}.`)
1325
1326
  }
1326
1327
  // console.log('argsToPass', argsToPass)
1327
1328
 
1328
- const relativePath = matchedFileString
1329
+ const relativePath = trimSurroundingQuotes(matchedFileString
1329
1330
  .replace(fileRefSyntax, (match, varName) => varName.trim())
1330
- .replace('~', os.homedir())
1331
+ .replace('~', os.homedir()))
1332
+
1331
1333
 
1332
1334
  let fullFilePath = (path.isAbsolute(relativePath) ? relativePath : path.join(this.configPath, relativePath))
1333
1335
 
1336
+ // console.log('fullFilePath', fullFilePath)
1337
+
1334
1338
  if (fs.existsSync(fullFilePath)) {
1335
1339
  // Get real path to handle potential symlinks (but don't fatal error)
1336
1340
  fullFilePath = fs.realpathSync(fullFilePath)
@@ -0,0 +1,5 @@
1
+ module.exports = function trimQuotes(str = '') {
2
+ return str
3
+ .replace(/^(")([^"\n]*?)(\1)$/, "$2")
4
+ .replace(/^(')([^'\n]*?)(\1)$/, "$2")
5
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "configorama",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "description": "Variable support for configuration files",
5
5
  "main": "lib/index.js",
6
6
  "files": [