configorama 1.0.0 → 1.0.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/package.json +1 -1
- package/src/main.js +16 -2
- package/src/resolvers/valueFromFile.js +7 -3
package/package.json
CHANGED
package/src/main.js
CHANGED
|
@@ -49,6 +49,20 @@ function isNestedFilterArgument(property, matchedString) {
|
|
|
49
49
|
const closeParenIdx = property.indexOf(')', matchIdx)
|
|
50
50
|
return pipeIdx !== -1 && matchIdx > pipeIdx && openParenIdx > pipeIdx && closeParenIdx > matchIdx
|
|
51
51
|
}
|
|
52
|
+
|
|
53
|
+
function resolveConfigFilePath(filePath) {
|
|
54
|
+
const absolutePath = path.resolve(filePath)
|
|
55
|
+
try {
|
|
56
|
+
return fs.realpathSync(absolutePath)
|
|
57
|
+
} catch (err) {
|
|
58
|
+
return absolutePath
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function getConfigFileDirectory(filePath) {
|
|
63
|
+
return path.dirname(resolveConfigFilePath(filePath))
|
|
64
|
+
}
|
|
65
|
+
|
|
52
66
|
const dotProp = require('dot-prop')
|
|
53
67
|
|
|
54
68
|
function resolveStaticFilterArg(arg, config) {
|
|
@@ -212,7 +226,7 @@ class Configorama {
|
|
|
212
226
|
}
|
|
213
227
|
|
|
214
228
|
this.safetyPolicy = normalizeSafetyPolicy(this.settings, {
|
|
215
|
-
configDir: options.configDir || (typeof fileOrObject === 'string' ?
|
|
229
|
+
configDir: options.configDir || (typeof fileOrObject === 'string' ? getConfigFileDirectory(fileOrObject) : process.cwd())
|
|
216
230
|
})
|
|
217
231
|
|
|
218
232
|
assertCustomResolversAllowed(options.variableSources, this.safetyPolicy)
|
|
@@ -317,7 +331,7 @@ class Configorama {
|
|
|
317
331
|
assertSafeConfigInput(fileOrObject, this.safetyPolicy)
|
|
318
332
|
// read and parse file
|
|
319
333
|
const fileContents = fs.readFileSync(fileOrObject, 'utf-8')
|
|
320
|
-
const fileDirectory =
|
|
334
|
+
const fileDirectory = getConfigFileDirectory(fileOrObject)
|
|
321
335
|
const fileType = path.extname(fileOrObject)
|
|
322
336
|
|
|
323
337
|
this.configFilePath = fileOrObject
|
|
@@ -85,7 +85,7 @@ function parseFileContents(content, filePath) {
|
|
|
85
85
|
if (ext === 'toml' || ext === 'tml') {
|
|
86
86
|
return TOML.parse(content)
|
|
87
87
|
}
|
|
88
|
-
if (ext
|
|
88
|
+
if (isIniLikeExtension(ext)) {
|
|
89
89
|
return INI.parse(content)
|
|
90
90
|
}
|
|
91
91
|
|
|
@@ -93,6 +93,10 @@ function parseFileContents(content, filePath) {
|
|
|
93
93
|
return content
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
+
function isIniLikeExtension(ext) {
|
|
97
|
+
return ext === 'ini' || ext === 'env'
|
|
98
|
+
}
|
|
99
|
+
|
|
96
100
|
/**
|
|
97
101
|
* Resolves a value from a file reference
|
|
98
102
|
* @param {object} ctx - Context object with instance properties
|
|
@@ -407,7 +411,7 @@ ${JSON.stringify(options.context, null, 2)}`,
|
|
|
407
411
|
if (fileExtension === 'toml' || fileExtension === 'tml') {
|
|
408
412
|
valueToPopulate = JSON.stringify(TOML.parse(valueToPopulate))
|
|
409
413
|
}
|
|
410
|
-
if (fileExtension
|
|
414
|
+
if (isIniLikeExtension(fileExtension)) {
|
|
411
415
|
valueToPopulate = INI.toJson(valueToPopulate)
|
|
412
416
|
}
|
|
413
417
|
if (fileExtension === 'tf' || fileExtension === 'hcl') {
|
|
@@ -447,7 +451,7 @@ Please use ":" or "." to reference sub properties. ${deepPropertiesStr}`
|
|
|
447
451
|
return Promise.resolve(valueToPopulate)
|
|
448
452
|
}
|
|
449
453
|
|
|
450
|
-
if (fileExtension
|
|
454
|
+
if (isIniLikeExtension(fileExtension)) {
|
|
451
455
|
valueToPopulate = INI.parse(valueToPopulate)
|
|
452
456
|
return Promise.resolve(valueToPopulate)
|
|
453
457
|
}
|