File tree Expand file tree Collapse file tree 5 files changed +32
-5
lines changed Expand file tree Collapse file tree 5 files changed +32
-5
lines changed Original file line number Diff line number Diff line change @@ -331,6 +331,10 @@ config.load('example.ts')
331
331
// You can also use safeLoad to not reload files that were already loaded
332
332
config .safeLoad (' app.ts' ) // Will just return without errors, but app.ts will not be reloaded.
333
333
334
+ // And you can also load an configuration file without extension.
335
+ // Config class will verify the Env NODE_TS to get the .js or .ts extension file
336
+ config .safeLoad (' app' )
337
+
334
338
console .log (Config .get (' app.name' )) // 'secjs'
335
339
```
336
340
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " @secjs/utils" ,
3
- "version" : " 1.7.5 " ,
3
+ "version" : " 1.7.6 " ,
4
4
"description" : " " ,
5
5
"license" : " MIT" ,
6
6
"author" : " João Lenon" ,
Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ export class Config {
25
25
keys . forEach ( key => ( config = config [ key ] ) )
26
26
}
27
27
28
- if ( ! config ) config = defaultValue
28
+ if ( config === undefined ) config = defaultValue
29
29
30
30
return config
31
31
}
@@ -53,10 +53,13 @@ export class Config {
53
53
throw new InternalServerException ( content )
54
54
}
55
55
56
- if ( Config . configs . get ( name ) ) return
56
+ if ( Config . configs . has ( name ) ) return
57
57
if ( base . includes ( '.map' ) || base . includes ( '.d.ts' ) ) return
58
58
59
- const file = new File ( `${ dir } /${ base } ` ) . loadSync ( )
59
+ const fileExtension = process . env . NODE_TS === 'true' ? 'ts' : 'js'
60
+ const fileBase = `${ name } .${ fileExtension } `
61
+
62
+ const file = new File ( `${ dir } /${ fileBase } ` ) . loadSync ( )
60
63
const fileContent = file . getContentSync ( ) . toString ( )
61
64
62
65
if (
@@ -87,6 +90,6 @@ export class Config {
87
90
}
88
91
89
92
Config . debug . log ( `Loading ${ name } configuration file` )
90
- Config . configs . set ( name , require ( ` ${ dir } / ${ name } ` ) . default )
93
+ Config . configs . set ( name , require ( file . path ) . default )
91
94
}
92
95
}
Original file line number Diff line number Diff line change @@ -33,6 +33,14 @@ describe('\n Config Class', () => {
33
33
expect ( Config . get ( 'test-ondemand.hello' ) ) . toBe ( true )
34
34
} )
35
35
36
+ it ( 'should be able to load configuration file without extension' , async ( ) => {
37
+ const config = new Config ( )
38
+
39
+ config . load ( Path . tests ( 'stubs/no-extension' ) )
40
+
41
+ expect ( Config . get ( 'no-extension.extension' ) ) . toBe ( false )
42
+ } )
43
+
36
44
it ( 'should throw an error when file is trying to use Config.get() to get information from other config file but this config file is trying to use Config.get() to this same file' , async ( ) => {
37
45
try {
38
46
new Config ( ) . load ( Path . tests ( 'stubs/infinite-callA.ts' ) )
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @secjs /utils
3
+ *
4
+ * (c) João Lenon <lenon@secjs.com.br>
5
+ *
6
+ * For the full copyright and license information, please view the LICENSE
7
+ * file that was distributed with this source code.
8
+ */
9
+
10
+ export default {
11
+ extension : false ,
12
+ }
You can’t perform that action at this time.
0 commit comments