@adobe/aio-cli-lib-app-config 1.0.1-pre.2023-07-12.sha-fee15187 → 1.0.1-pre.2023-07-14.sha-628de670
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 +2 -2
- package/src/index.js +26 -9
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adobe/aio-cli-lib-app-config",
|
|
3
|
-
"version": "1.0.1-pre.2023-07-
|
|
3
|
+
"version": "1.0.1-pre.2023-07-14.sha-628de670",
|
|
4
4
|
"description": "node lib to provide a consistent interface to various config files that make up Adobe Developer App Builder applications and extensions",
|
|
5
5
|
"repository": "https://github.com/adobe/aio-cli-lib-app-config/",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -75,5 +75,5 @@
|
|
|
75
75
|
"./test/jest.setup.js"
|
|
76
76
|
]
|
|
77
77
|
},
|
|
78
|
-
"prereleaseSha": "
|
|
78
|
+
"prereleaseSha": "628de6708a25f55af14bf772b3a6e4d16d353ac4"
|
|
79
79
|
}
|
package/src/index.js
CHANGED
|
@@ -264,17 +264,28 @@ async function loadCommonConfig (/* istanbul ignore next */options = {}) {
|
|
|
264
264
|
// }
|
|
265
265
|
|
|
266
266
|
/**
|
|
267
|
-
* Resolve all includes, update relative paths and return a coalesced app
|
|
267
|
+
* Resolve all includes, update relative paths and return a coalesced app
|
|
268
|
+
* configuration object.
|
|
269
|
+
*
|
|
270
|
+
* Returns the appConfig along with an index of config keys to config file. The
|
|
271
|
+
* config file paths in the index are absolute.
|
|
268
272
|
*
|
|
269
273
|
* @param {string} appConfigFile path to the app.config.yaml
|
|
270
274
|
* @param {object} options options
|
|
271
|
-
* @param {object} options.absolutePaths boolean, true for
|
|
272
|
-
*
|
|
275
|
+
* @param {object} options.absolutePaths boolean, true for rewriting
|
|
276
|
+
* configuration paths to absolute, false for relative to the appConfigFile
|
|
277
|
+
* directory. Defaults to false. Note, that config values will never be
|
|
278
|
+
* rewritten as relative to the cwd. But also note that
|
|
279
|
+
* this option doesn't have any effect on the includeIndex paths which stay
|
|
280
|
+
* relative to the cwd.
|
|
281
|
+
* @returns {object} { config, includeIndex }
|
|
273
282
|
*/
|
|
274
283
|
async function coalesce (appConfigFile, options = {}) {
|
|
275
284
|
// this code is traversing app.config.yaml recursively to resolve all $includes directives
|
|
276
285
|
|
|
277
286
|
const absolutePaths = options.absolutePaths === undefined ? false : options.absolutePaths
|
|
287
|
+
const appRoot = path.dirname(appConfigFile)
|
|
288
|
+
|
|
278
289
|
const config = yaml.safeLoad(await fs.readFile(appConfigFile, 'utf8'))
|
|
279
290
|
// keep an index that will map keys like 'extensions.abc.runtimeManifest' to the config file where there are defined
|
|
280
291
|
const includeIndex = {}
|
|
@@ -358,7 +369,7 @@ async function coalesce (appConfigFile, options = {}) {
|
|
|
358
369
|
}
|
|
359
370
|
|
|
360
371
|
const appConfigWithIncludeIndex = { config, includeIndex }
|
|
361
|
-
rewritePathsInPlace(appConfigWithIncludeIndex, { absolutePaths })
|
|
372
|
+
rewritePathsInPlace(appConfigWithIncludeIndex, { absolutePaths, appRoot })
|
|
362
373
|
|
|
363
374
|
return appConfigWithIncludeIndex
|
|
364
375
|
}
|
|
@@ -466,7 +477,7 @@ function rewritePathsInPlace (appConfigWithIncludeIndex, options) {
|
|
|
466
477
|
|
|
467
478
|
if (typeof value === 'string' && PATH_KEYS.filter(reg => fullKey.match(reg)).length) {
|
|
468
479
|
// rewrite path value to be relative to the root instead of being relative to the config file that includes it
|
|
469
|
-
parentObj[key] = resolveToRoot(value, includedFromConfigFile,
|
|
480
|
+
parentObj[key] = resolveToRoot(value, includedFromConfigFile, options)
|
|
470
481
|
}
|
|
471
482
|
if (typeof value === 'object') {
|
|
472
483
|
// object or Array
|
|
@@ -685,10 +696,16 @@ async function buildSingleConfig (configName, singleUserConfig, commonConfig, in
|
|
|
685
696
|
function resolveToRoot (pathValue, includedFromConfigPath, options = {}) {
|
|
686
697
|
// path.resolve => support both absolute pathValue and relative (relative joins with
|
|
687
698
|
// config dir and process.cwd, absolute returns pathValue)
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
699
|
+
if (options.absolutePaths) {
|
|
700
|
+
return path.resolve(path.dirname(includedFromConfigPath), pathValue)
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
// relative paths
|
|
704
|
+
if (options.appRoot) {
|
|
705
|
+
// make sure path is relative to appRoot and not cwd
|
|
706
|
+
includedFromConfigPath = path.relative(options.appRoot, includedFromConfigPath)
|
|
707
|
+
}
|
|
708
|
+
return path.join(path.dirname(includedFromConfigPath), pathValue).split(path.sep).join(path.posix.sep)
|
|
692
709
|
}
|
|
693
710
|
|
|
694
711
|
module.exports = {
|