configorama 0.6.9 → 0.6.11

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/cli.js CHANGED
@@ -5,6 +5,8 @@ const minimist = require('minimist')
5
5
  const Configorama = require('./src/main')
6
6
  const deepLog = require('./src/utils/deep-log')
7
7
  const { logHeader } = require('./src/utils/logs')
8
+ const configorama = require('./src')
9
+ const { makeBox } = require('@davidwells/box-logger')
8
10
 
9
11
  // Parse command line arguments
10
12
  const argv = minimist(process.argv.slice(2), {
@@ -77,32 +79,39 @@ if (!fs.existsSync(inputFile)) {
77
79
  const options = {
78
80
  allowUnknownVars: argv['allow-unknown'] || false,
79
81
  allowUndefinedValues: argv['allow-undefined'] || false,
82
+ allowUnknownFileRefs: argv['allow-unknown-file-refs'] || false,
83
+ returnMetadata: argv['return-metadata'] || false,
84
+ returnPreResolvedVariableDetails: argv['setup'] || false,
80
85
  dynamicArgs: argv
81
86
  }
82
87
 
88
+ const dynamicArgs = options.dynamicArgs || {}
89
+ const {
90
+ _,
91
+ verbose,
92
+ v,
93
+ verify,
94
+ debug,
95
+ d,
96
+ help,
97
+ h,
98
+ version,
99
+ f,
100
+ format,
101
+ list,
102
+ l,
103
+ info,
104
+ i,
105
+ 'allow-unknown': allowUnknown,
106
+ 'allow-undefined': allowUndefined,
107
+ 'allow-unknown-file-refs': allowUnknownFileRefs,
108
+ 'return-metadata': returnMetadata,
109
+ ...rest
110
+ } = dynamicArgs
111
+
112
+
83
113
  if (options.dynamicArgs.verbose) {
84
114
  logHeader('Config Input Options')
85
- const dynamicArgs = options.dynamicArgs || {}
86
- const {
87
- _,
88
- verbose,
89
- v,
90
- verify,
91
- debug,
92
- d,
93
- help,
94
- h,
95
- version,
96
- f,
97
- format,
98
- list,
99
- l,
100
- info,
101
- i,
102
- 'allow-unknown': allowUnknown,
103
- 'allow-undefined': allowUndefined,
104
- ...rest
105
- } = dynamicArgs
106
115
 
107
116
  console.log()
108
117
  if (Object.keys(rest).length) {
@@ -118,12 +127,11 @@ if (argv._.length) {
118
127
  isSetupMode = argv._.includes('setup')
119
128
  }
120
129
 
121
- // Create Configorama instance
122
- const configorama = new Configorama(inputFile, options)
123
- // console.log('configorama', configorama)
130
+ // Set -- flags as options
131
+ options.options = rest
124
132
 
125
133
  // Process the configuration
126
- configorama.init(argv)
134
+ configorama(inputFile, options)
127
135
  .then((config) => {
128
136
  let output
129
137
 
@@ -131,15 +139,27 @@ configorama.init(argv)
131
139
  switch (argv.format.toLowerCase()) {
132
140
  case 'yaml':
133
141
  case 'yml':
134
- const YAML = require('./lib/parsers/yaml')
142
+ const YAML = require('./src/parsers/yaml')
135
143
  output = YAML.dump(config)
136
144
  break
145
+ case 'esm':
146
+ case 'mjs':
147
+ case 'module':
148
+ output = `export default ${JSON.stringify(config, null, 2)}`
149
+ break
137
150
  case 'js':
151
+ case 'cjs':
152
+ case 'commonjs':
138
153
  case 'javascript':
139
154
  output = `module.exports = ${JSON.stringify(config, null, 2)}`
140
155
  break
141
156
  case 'json':
157
+ case 'json5':
142
158
  default:
159
+ if (returnMetadata) {
160
+ // turn regex into string
161
+ config.variableSyntax = config.variableSyntax ? config.variableSyntax.source : undefined
162
+ }
143
163
  output = JSON.stringify(config, null, 2)
144
164
  }
145
165
 
@@ -151,11 +171,20 @@ configorama.init(argv)
151
171
  if (!argv.verbose) {
152
172
  console.log(output)
153
173
  }
174
+ if (argv.format && argv.verbose) {
175
+ console.log('Output Format:', argv.format)
176
+ console.log(output)
177
+ }
154
178
  }
155
179
  })
156
180
  .catch((error) => {
157
- console.error(`Error processing configuration: ${inputFile}`)
158
- console.error(error.message)
181
+ const errorMsg = makeBox({
182
+ title: `Error Processing Configuration: ${inputFile}`,
183
+ minWidth: '100%',
184
+ content: error.message,
185
+ type: 'error',
186
+ })
187
+ console.log(errorMsg)
159
188
  if (argv.debug) {
160
189
  console.error(error.stack)
161
190
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "configorama",
3
- "version": "0.6.9",
3
+ "version": "0.6.11",
4
4
  "description": "Variable support for configuration files",
5
5
  "main": "src/index.js",
6
6
  "types": "index.d.ts",
@@ -17,6 +17,7 @@
17
17
  "configorama": "./cli.js"
18
18
  },
19
19
  "scripts": {
20
+ "info": "repomix --include \"cli.js,src/**/*.js\" --ignore \"**/*.test.js\" --copy",
20
21
  "docs": "node ./scripts/docs.js",
21
22
  "t": "./scripts/run-tests.sh",
22
23
  "test": "npm run test:lib && uvu tests \".*\\.test.js$\" ",
@@ -37,7 +38,8 @@
37
38
  "url": "https://github.com/DavidWells/configorama"
38
39
  },
39
40
  "dependencies": {
40
- "@davidwells/box-logger": "^1.0.20",
41
+ "@clack/prompts": "^0.11.0",
42
+ "@davidwells/box-logger": "^2.0.3",
41
43
  "@iarna/toml": "^2.2.5",
42
44
  "alias-hq": "^6.2.3",
43
45
  "dot-prop": "^5.3.0",
package/src/index.js CHANGED
@@ -28,15 +28,52 @@ module.exports = async (configPathOrObject, settings = {}) => {
28
28
  if (settings.returnMetadata) {
29
29
  const metadata = instance.collectVariableMetadata()
30
30
 
31
+ // console.log('instance.fileRefsFound', instance.fileRefsFound)
32
+ // console.log('instance.resolutionTracking', instance.resolutionTracking)
33
+ // process.exit(1)
34
+
31
35
  // Enrich metadata with resolution tracking data collected during execution
32
- const enrichedMetadata = enrichMetadata(metadata, instance.resolutionTracking, instance.variableSyntax)
36
+ const enrichedMetadata = enrichMetadata(
37
+ metadata,
38
+ instance.resolutionTracking,
39
+ instance.variableSyntax,
40
+ instance.fileRefsFound,
41
+ instance.originalConfig,
42
+ instance.configFilePath,
43
+ Object.keys(instance.filters)
44
+ )
45
+
46
+ // Add resolvedPropertyValue to resolutionTracking
47
+ const resolutionHistoryWithResolvedValues = {}
48
+ for (const pathKey in instance.resolutionTracking) {
49
+ const tracking = instance.resolutionTracking[pathKey]
50
+ const keys = pathKey.split('.')
51
+ let resolvedValue = config
52
+
53
+ // Navigate to the resolved value in the config
54
+ for (const key of keys) {
55
+ if (resolvedValue && typeof resolvedValue === 'object') {
56
+ resolvedValue = resolvedValue[key]
57
+ } else {
58
+ resolvedValue = undefined
59
+ break
60
+ }
61
+ }
62
+
63
+ resolutionHistoryWithResolvedValues[pathKey] = {
64
+ ...tracking,
65
+ resolvedPropertyValue: resolvedValue
66
+ }
67
+ }
33
68
 
34
69
  return {
70
+ variableSyntax: instance.variableSyntax,
71
+ variableTypes: instance.variableTypes,
35
72
  config,
36
73
  originalConfig: instance.originalConfig,
37
74
  metadata: enrichedMetadata,
38
75
  // Include resolution history per path for debugging and advanced use cases
39
- resolutionHistory: instance.resolutionTracking
76
+ resolutionHistory: resolutionHistoryWithResolvedValues,
40
77
  }
41
78
  }
42
79