@adobe/aio-cli-lib-app-config 1.0.1-pre.2023-07-10.sha-32c62844 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/aio-cli-lib-app-config",
3
- "version": "1.0.1-pre.2023-07-10.sha-32c62844",
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": "32c628440bb4e52c8b3db916d6081c6e94dc1521"
78
+ "prereleaseSha": "628de6708a25f55af14bf772b3a6e4d16d353ac4"
79
79
  }
@@ -22,6 +22,7 @@
22
22
  "patternProperties": {
23
23
  "^[A-Za-z0-9-_/\\-]+$": {
24
24
  "$ref": "#/definitions/application",
25
+ "type": "object",
25
26
  "properties": {
26
27
  "operations": {
27
28
  "type": "object",
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 configuration object.
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 absolute paths, default for relative to appConfigFile directory.
272
- * @returns {object} single appConfig with resolved includes
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, { absolutePaths: options.absolutePaths })
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
- return options.absolutePaths
689
- ? path.resolve(path.dirname(includedFromConfigPath), pathValue)
690
- // if relative keep unix paths
691
- : path.join(path.dirname(includedFromConfigPath), pathValue).split(path.sep).join(path.posix.sep)
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 = {