Skip to content

Commit 05c39c4

Browse files
authored
Merge pull request #12 from SecJS/refactor/len-update-utils-type
fix: Adjust file extension in matcher
2 parents 405ef1d + e2e2bc9 commit 05c39c4

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@secjs/config",
3-
"version": "1.0.7",
3+
"version": "1.0.8",
44
"description": "",
55
"license": "MIT",
66
"author": "João Lenon",

src/Config.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,14 @@ export class Config {
9999
const fileContent = file.getContentSync().toString()
100100

101101
if (fileContent.includes('Config.get')) {
102-
const matches = fileContent.match(/\(([^)]+)\)/g)
102+
const matches = fileContent.match(/Config.get\(([^)]+)\)/g)
103103

104-
for (const match of matches) {
104+
for (let match of matches) {
105+
match = match.replace('Config.get', '').replace(/[(^)']/g, '')
105106
if (this.configs.get(`env-${match}`)) continue
106107

107-
const filePath = `${dir}/${
108-
match.replace(/[(^)']/g, '').split('.')[0]
109-
}.ts`
108+
const extension = process.env.NODE_TS === 'true' ? 'ts' : 'js'
109+
const filePath = `${dir}/${match.split('.')[0]}.${extension}`
110110

111111
this.loadOnDemand(filePath, files, callNumber + 1)
112112
}

tests/config.spec.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ import { Config } from '../src/Config'
22
import { rm, writeFile } from 'fs/promises'
33

44
describe('\n Config', () => {
5-
beforeAll(() => (process.env.DB_NAME = 'testing'))
5+
beforeAll(() => {
6+
process.env.NODE_TS = 'true'
7+
process.env.DB_NAME = 'testing'
8+
})
69

710
it('should be able to get environment variables', async () => {
811
await new Config().load()

0 commit comments

Comments
 (0)