configorama 0.6.13 → 0.6.14

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": "configorama",
3
- "version": "0.6.13",
3
+ "version": "0.6.14",
4
4
  "description": "Variable support for configuration files",
5
5
  "main": "src/index.js",
6
6
  "types": "index.d.ts",
@@ -4,7 +4,7 @@
4
4
  const fs = require('fs')
5
5
  const { trim } = require('../utils/lodash')
6
6
  const { splitCsv } = require('../utils/strings/splitCsv')
7
- const { resolveFilePathFromMatch } = require('../utils/paths/getFullFilePath')
7
+ const { resolveFilePathFromMatch, resolveFilePath } = require('../utils/paths/getFullFilePath')
8
8
  const { findNestedVariables } = require('../utils/variables/findNestedVariables')
9
9
  const { makeBox } = require('@davidwells/box-logger')
10
10
  const { encodeJsSyntax } = require('../utils/encoders/js-fixes')
@@ -94,19 +94,48 @@ async function getValueFromFile(ctx, variableString, options) {
94
94
  const fileDetails = resolveFilePathFromMatch(matchedFileString, syntax, ctx.configPath)
95
95
  // console.log('fileDetails', fileDetails)
96
96
 
97
- const { fullFilePath, resolvedPath, relativePath } = fileDetails
97
+ let { fullFilePath, resolvedPath, relativePath } = fileDetails
98
+
99
+ // Check for file path overrides
100
+ let wasOverridden = false
101
+ let originalFilePath = null
102
+ const filePathOverrides = ctx.opts && ctx.opts.filePathOverrides
103
+ if (filePathOverrides) {
104
+ // Try matching against relativePath (e.g., './env.yml')
105
+ const overrideKey = Object.keys(filePathOverrides).find((key) => {
106
+ // Normalize paths for comparison
107
+ const normalizedKey = key.replace(/^\.\//, '')
108
+ const normalizedRelPath = relativePath.replace(/^\.\//, '')
109
+ return normalizedKey === normalizedRelPath || key === relativePath
110
+ })
111
+
112
+ if (overrideKey) {
113
+ originalFilePath = fullFilePath
114
+ const overridePath = filePathOverrides[overrideKey]
115
+ // Resolve the override path (could be relative or absolute)
116
+ fullFilePath = resolveFilePath(overridePath, ctx.configPath)
117
+ resolvedPath = overridePath
118
+ wasOverridden = true
119
+ }
120
+ }
98
121
 
99
122
  const exists = fs.existsSync(fullFilePath)
100
123
 
101
- ctx.fileRefsFound.push({
102
- // location: options.context.path.join('.'),
124
+ const fileRefEntry = {
103
125
  filePath: fullFilePath,
104
126
  relativePath,
105
127
  resolvedVariableString: options.context.value,
106
128
  originalVariableString: options.context.originalSource,
107
129
  containsVariables: options.context.value !== options.context.originalSource,
108
130
  exists,
109
- })
131
+ }
132
+
133
+ if (wasOverridden) {
134
+ fileRefEntry.wasOverridden = true
135
+ fileRefEntry.originalFilePath = originalFilePath
136
+ }
137
+
138
+ ctx.fileRefsFound.push(fileRefEntry)
110
139
 
111
140
  let fileExtension = resolvedPath.split('.')
112
141
 
@@ -304,26 +304,37 @@ async function enrichMetadata(
304
304
  }
305
305
  }
306
306
 
307
+ // Add overrideFilePath to references if file was overridden
308
+ for (const refData of references) {
309
+ const details = fileDetailsMap.get(refData.resolvedPath)
310
+ if (details && details.wasOverridden) {
311
+ refData.overrideFilePath = details.filePath
312
+ }
313
+ }
314
+
307
315
  const byConfigPath = []
308
316
  if (references.length > 0) {
309
317
  for (const resolvedFileData of references) {
310
318
  const details = fileDetailsMap.get(resolvedFileData.resolvedPath)
311
319
  if (details) {
312
320
  for (const ref of resolvedFileData.refs) {
321
+ // Use original file path if overridden, otherwise use the resolved path
322
+ const filePath = details.wasOverridden ? details.originalFilePath : details.filePath
313
323
  const confDetails = {
314
324
  location: ref.location,
315
- filePath: details.filePath,
325
+ filePath: filePath,
316
326
  relativePath: details.relativePath,
317
327
  originalVariableString: ref.originalVariableString,
318
328
  resolvedVariableString: details.resolvedVariableString,
319
329
  containsVariables: !!ref.hasInnerVariable,
320
330
  exists: details.exists,
321
- // Get glob patterns from the individual ref, default to empty array
322
-
323
331
  }
324
332
  if (ref.pattern) {
325
333
  confDetails.pattern = ref.pattern
326
334
  }
335
+ if (details.wasOverridden) {
336
+ confDetails.overrideFilePath = details.filePath
337
+ }
327
338
  byConfigPath.push(confDetails)
328
339
  }
329
340
  }
@@ -338,6 +349,25 @@ async function enrichMetadata(
338
349
  if (references.length > 0) {
339
350
  metadata.fileDependencies.references = references
340
351
  }
352
+
353
+ // Collect unique overridden files from fileRefsFound
354
+ const overriddenFilesMap = new Map()
355
+ for (const ref of fileRefsFound) {
356
+ if (ref.wasOverridden) {
357
+ // Use originalFilePath as key to dedupe
358
+ if (!overriddenFilesMap.has(ref.originalFilePath)) {
359
+ overriddenFilesMap.set(ref.originalFilePath, {
360
+ originalPath: ref.originalFilePath,
361
+ overridePath: ref.filePath,
362
+ relativePath: ref.relativePath,
363
+ })
364
+ }
365
+ }
366
+ }
367
+
368
+ if (overriddenFilesMap.size > 0) {
369
+ metadata.fileDependencies.overriddenFiles = Array.from(overriddenFilesMap.values())
370
+ }
341
371
  }
342
372
 
343
373
  // Build uniqueVariables rollup - group by base variable (without fallbacks)
@@ -29,7 +29,7 @@ function resolveFilePath(pathToResolve, basePath) {
29
29
  return fullFilePath
30
30
  }
31
31
 
32
- module.exports = function getFullPath(fileString, cwd) {
32
+ function getFullPath(fileString, cwd) {
33
33
  const configPath = cwd || process.cwd()
34
34
  const relativePath = fileString.replace('~', os.homedir())
35
35
  return resolveFilePath(relativePath, configPath)
@@ -54,4 +54,6 @@ function resolveFilePathFromMatch(matchedFileString, syntax, configPath) {
54
54
  return { fullFilePath, resolvedPath, relativePath }
55
55
  }
56
56
 
57
+ module.exports = getFullPath
57
58
  module.exports.resolveFilePathFromMatch = resolveFilePathFromMatch
59
+ module.exports.resolveFilePath = resolveFilePath