configorama 0.6.9 → 0.6.10

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.
@@ -13,6 +13,7 @@ const stringRefSyntax = stringResolver.match
13
13
 
14
14
  // https://regex101.com/r/4uPmpt/1
15
15
  const commasOutsideOfParens = /(?!<(?:\(|\[)[^)\]]+),(?![^(\[]+(?:\)|\]))/
16
+ const PLACEHOLDER_REGEX = /__PLACEHOLDER_(\d+)__/g
16
17
  // const commasOutOfParens = /(?!(?:\()[^)\]]+),(?![^(\[]+(?:\)))/g
17
18
  function splitByComma(string, regexPattern) {
18
19
  // Handle empty or undefined input
@@ -96,7 +97,7 @@ function splitByComma(string, regexPattern) {
96
97
 
97
98
  // Restore placeholders in the result
98
99
  return result.map(item => {
99
- return item.replace(/__PLACEHOLDER_(\d+)__/g, (match, index) => {
100
+ return item.replace(PLACEHOLDER_REGEX, (match, index) => {
100
101
  return placeholders[parseInt(index)]
101
102
  })
102
103
  })
@@ -8,16 +8,16 @@ function splitCsv(str, splitter) {
8
8
  const splitSyntax = splitter || ','
9
9
  // Split at comma SPACE ", "
10
10
  return str.split(splitSyntax).reduce(
11
- (accum, curr) => {
12
- if (accum.isConcatting) {
13
- accum.soFar[accum.soFar.length - 1] += ',' + curr
11
+ (acc, curr) => {
12
+ if (acc.isConcatting) {
13
+ acc.soFar[acc.soFar.length - 1] += ',' + curr
14
14
  } else {
15
- accum.soFar.push(curr)
15
+ acc.soFar.push(curr)
16
16
  }
17
17
  if (curr.split('"').length % 2 == 0) {
18
- accum.isConcatting = !accum.isConcatting
18
+ acc.isConcatting = !acc.isConcatting
19
19
  }
20
- return accum
20
+ return acc
21
21
  },
22
22
  {
23
23
  soFar: [],
@@ -1,65 +0,0 @@
1
- const path = require('path')
2
- const fs = require('fs')
3
-
4
- function resolveAlias(filePath, configDir) {
5
- try {
6
- // If no alias prefix, return original path
7
- if (!filePath.startsWith('@')) {
8
- return filePath
9
- }
10
-
11
- // Find tsconfig.json
12
- const tsconfigPath = path.join(configDir, 'tsconfig.json')
13
- if (!fs.existsSync(tsconfigPath)) {
14
- console.warn(`Warning: No tsconfig.json found in ${configDir}`)
15
- return filePath
16
- }
17
-
18
- // Read and parse tsconfig.json
19
- const tsconfig = JSON.parse(fs.readFileSync(tsconfigPath, 'utf8'))
20
- const aliasMappings = tsconfig.compilerOptions?.paths || {}
21
-
22
- // Extract the alias prefix and path
23
- const match = filePath.match(/^(@[^/]+)(\/.*)$/)
24
- if (!match) {
25
- return filePath
26
- }
27
-
28
- const [, aliasPrefix, restPath] = match
29
- const aliasKey = `${aliasPrefix}/*`
30
-
31
- // Check if we have a mapping for this alias
32
- if (aliasMappings[aliasKey]) {
33
- // Get the mapped path and normalize it
34
- const mappedPath = aliasMappings[aliasKey][0]
35
- const basePath = path.resolve(configDir, mappedPath.replace('*', ''))
36
- const relativeRest = restPath.replace(/^\//, '')
37
- const resolvedPath = path.join(basePath, relativeRest)
38
-
39
- // Log the resolution for debugging
40
- console.log(`Resolving ${filePath} to ${resolvedPath}`)
41
-
42
- return resolvedPath
43
- }
44
-
45
- // Try exact match without wildcard
46
- const exactKey = aliasPrefix
47
- if (aliasMappings[exactKey]) {
48
- const mappedPath = aliasMappings[exactKey][0]
49
- const resolvedPath = path.resolve(configDir, mappedPath)
50
-
51
- console.log(`Resolving ${filePath} to ${resolvedPath}`)
52
- return resolvedPath
53
- }
54
-
55
- // Fall back to original path if no alias matched
56
- return filePath
57
-
58
- } catch (error) {
59
- // If alias resolution fails, fall back to original path
60
- console.warn(`Warning: Failed to resolve alias for "${filePath}":`, error.message)
61
- return filePath
62
- }
63
- }
64
-
65
- module.exports = resolveAlias
package/src/utils/x.js DELETED
@@ -1,173 +0,0 @@
1
- process.env.foo = 'foo'
2
- process.env.opt_stage = 'stage'
3
- process.env.opt_stageOne = 'stageOne'
4
- process.env.opt_stageTwo = 'stageTwo'
5
-
6
- function getResolvers() {
7
- return {
8
- 'file': async function fileResolver(arg) {
9
- return 'filevalue'
10
- },
11
- 'env:': async function envResolver(key) {
12
- return process.env[key]
13
- },
14
- 'opt:': async function optResolver(key) {
15
- return process.env[`opt_${key}`] || null
16
- }
17
- }
18
- }
19
-
20
- async function resolveVariables(variableArray) {
21
- // Sort by resolveOrder to ensure inner variables are resolved first
22
- const sortedArray = [...variableArray].sort((a, b) => a.resolveOrder - b.resolveOrder)
23
- const resolvedValues = {}
24
- const resolvers = getResolvers()
25
-
26
- for (const item of sortedArray) {
27
- let resolvedValue = null
28
-
29
- if (item.hasFallback) {
30
- // Try to resolve the primary value
31
- const resolver = resolvers[item.varType]
32
- const primaryKey = item.valueBeforeFallback.replace(`${item.varType}`, '')
33
- resolvedValue = await resolver(primaryKey)
34
-
35
- // If primary value is null, try fallbacks in order
36
- if (resolvedValue === null) {
37
- for (const fallback of item.fallbackValues) {
38
- if (fallback.isVariable) {
39
- // This is a reference to another variable that should be already resolved
40
- const placeholderMatch = fallback.variable.match(/__VAR_(\d+)__/)
41
- if (placeholderMatch) {
42
- resolvedValue = resolvedValues[`__VAR_${placeholderMatch[1]}__`]
43
- if (resolvedValue !== null) break
44
- } else {
45
- // It's a direct variable reference
46
- const varType = fallback.variable.split(':')[0] + ':'
47
- const varKey = fallback.variable.replace(`${varType}`, '')
48
- resolvedValue = await resolvers[varType](varKey)
49
- if (resolvedValue !== null) break
50
- }
51
- } else {
52
- // It's a literal value
53
- resolvedValue = fallback.variable.replace(/"/g, '')
54
- break
55
- }
56
- }
57
- }
58
- } else if (item.varType.startsWith('file')) {
59
- // Handle file type specially as it requires the resolved path
60
- let filePath = item.varString
61
- for (const [placeholder, value] of Object.entries(resolvedValues)) {
62
- filePath = filePath.replace(placeholder, value)
63
- }
64
- resolvedValue = await resolvers['file'](filePath)
65
- } else {
66
- // Simple variable resolution
67
- const resolver = resolvers[item.varType]
68
- const key = item.variable.replace(`${item.varType}`, '')
69
- resolvedValue = await resolver(key)
70
- }
71
-
72
- resolvedValues[item.placeholder] = resolvedValue
73
- }
74
-
75
- return resolvedValues
76
- }
77
-
78
-
79
- const array = [
80
- {
81
- location: 'xyz',
82
- value: '${file(./config.${opt:stage, ${opt:stageOne, ${env:foo}}, ${opt:stageTwo}, "three" }.json)}',
83
- fullMatch: '${env:foo}',
84
- variable: 'env:foo',
85
- varString: 'env:foo',
86
- resolveOrder: 1,
87
- start: 45,
88
- end: 55,
89
- placeholder: '__VAR_0__',
90
- varType: 'env:'
91
- },
92
- {
93
- location: 'xyz',
94
- value: '${file(./config.${opt:stage, ${opt:stageOne, ${env:foo}}, ${opt:stageTwo}, "three" }.json)}',
95
- fullMatch: '${opt:stageOne, ${env:foo}}',
96
- variable: 'opt:stageOne, ${env:foo}',
97
- varString: 'opt:stageOne, __VAR_0__',
98
- resolveOrder: 2,
99
- start: 29,
100
- end: 55,
101
- placeholder: '__VAR_1__',
102
- varType: 'opt:',
103
- hasFallback: true,
104
- valueBeforeFallback: 'opt:stageOne',
105
- fallbackValues: [
106
- {
107
- isVariable: true,
108
- variable: 'env:foo',
109
- fullMatch: '${env:foo}'
110
- }
111
- ]
112
- },
113
- {
114
- location: 'xyz',
115
- value: '${file(./config.${opt:stage, ${opt:stageOne, ${env:foo}}, ${opt:stageTwo}, "three" }.json)}',
116
- fullMatch: '${opt:stageTwo}',
117
- variable: 'opt:stageTwo',
118
- varString: 'opt:stageTwo',
119
- resolveOrder: 3,
120
- start: 40,
121
- end: 55,
122
- placeholder: '__VAR_2__',
123
- varType: 'opt:'
124
- },
125
- {
126
- location: 'xyz',
127
- value: '${file(./config.${opt:stage, ${opt:stageOne, ${env:foo}}, ${opt:stageTwo}, "three" }.json)}',
128
- fullMatch: '${opt:stage, ${opt:stageOne, ${env:foo}}, ${opt:stageTwo}, "three" }',
129
- variable: 'opt:stage, ${opt:stageOne, ${env:foo}}, ${opt:stageTwo}, "three"',
130
- varString: 'opt:stage, __VAR_1__, __VAR_2__, "three"',
131
- resolveOrder: 4,
132
- start: 16,
133
- end: 60,
134
- placeholder: '__VAR_3__',
135
- varType: 'opt:',
136
- hasFallback: true,
137
- valueBeforeFallback: 'opt:stage',
138
- fallbackValues: [
139
- {
140
- isVariable: true,
141
- variable: 'opt:stageOne, ${env:foo}',
142
- fullMatch: '${opt:stageOne, ${env:foo}}'
143
- },
144
- {
145
- isVariable: true,
146
- variable: 'opt:stageTwo',
147
- fullMatch: '${opt:stageTwo}'
148
- },
149
- { isVariable: false, variable: '"three"', fullMatch: '"three"' }
150
- ]
151
- },
152
- {
153
- location: 'xyz',
154
- value: '${file(./config.${opt:stage, ${opt:stageOne, ${env:foo}}, ${opt:stageTwo}, "three" }.json)}',
155
- fullMatch: '${file(./config.${opt:stage, ${opt:stageOne, ${env:foo}}, ${opt:stageTwo}, "three" }.json)}',
156
- variable: 'file(./config.${opt:stage, ${opt:stageOne, ${env:foo}}, ${opt:stageTwo}, "three" }.json)',
157
- varString: 'file(./config.__VAR_3__.json)',
158
- resolveOrder: 5,
159
- start: 0,
160
- end: 32,
161
- placeholder: '__VAR_4__',
162
- varType: 'file(./config.__VAR_3__.json)'
163
- }
164
- ]
165
-
166
-
167
- resolveVariables(array)
168
- .then((res) => {
169
- console.log('res', res)
170
- })
171
- .catch((err) => {
172
- console.log('err', err)
173
- })