Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
config
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
libs
config
Commits
a680b8f8
Commit
a680b8f8
authored
1 year ago
by
Sigmund, Dominik
Browse files
Options
Downloads
Patches
Plain Diff
Fix constructor
parent
d24103ad
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!8
Fix constructor
Pipeline
#65508
passed
1 year ago
Stage: test
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
index.js
+3
-2
3 additions, 2 deletions
index.js
index.test.js
+11
-11
11 additions, 11 deletions
index.test.js
package.json
+1
-1
1 addition, 1 deletion
package.json
with
15 additions
and
14 deletions
index.js
+
3
−
2
View file @
a680b8f8
...
...
@@ -2,7 +2,7 @@ var fs = require('fs')
var
path
=
require
(
'
path
'
)
var
merge
=
require
(
'
lodash.merge
'
)
module
.
exports
=
function
(
basePath
=
undefined
,
envPrefix
=
undefined
)
{
function
createConfig
(
basePath
=
undefined
,
envPrefix
=
undefined
)
{
let
configDefaults
let
configLocal
let
envPrefixUpper
=
envPrefix
?
envPrefix
.
toUpperCase
()
+
"
_
"
:
''
...
...
@@ -104,4 +104,5 @@ module.exports = function(basePath = undefined, envPrefix = undefined) {
}
config
.
_reload
()
return
config
}
\ No newline at end of file
}
module
.
exports
=
{
createConfig
};
\ No newline at end of file
This diff is collapsed.
Click to expand it.
index.test.js
+
11
−
11
View file @
a680b8f8
const
fs
=
require
(
'
fs
'
).
promises
const
Config
=
require
(
'
./index
'
)
const
create
Config
=
require
(
'
./index
'
)
.
createConfig
let
jsonDefaults
=
{
setting
:
"
defaultvalue
"
,
...
...
@@ -25,7 +25,7 @@ describe('config', function() {
it
(
'
should only have values from config.defaults.json
'
,
async
function
()
{
await
fs
.
writeFile
(
'
config.defaults.json
'
,
JSON
.
stringify
(
jsonDefaults
))
let
config
=
new
Config
()
let
config
=
create
Config
()
await
fs
.
unlink
(
'
config.defaults.json
'
)
expect
(
config
.
setting
).
toBe
(
'
defaultvalue
'
)
...
...
@@ -34,7 +34,7 @@ describe('config', function() {
it
(
'
should only have values from config.json
'
,
async
function
()
{
await
fs
.
writeFile
(
'
config.json
'
,
JSON
.
stringify
(
jsonLocals
))
let
config
=
new
Config
()
let
config
=
create
Config
()
await
fs
.
unlink
(
'
config.json
'
)
expect
(
config
.
setting
).
toBe
(
'
localvalue
'
)
...
...
@@ -44,7 +44,7 @@ describe('config', function() {
it
(
'
should have both values with preference to config.json
'
,
async
function
()
{
await
fs
.
writeFile
(
'
config.defaults.json
'
,
JSON
.
stringify
(
jsonDefaults
))
await
fs
.
writeFile
(
'
config.json
'
,
JSON
.
stringify
(
jsonLocals
))
let
config
=
new
Config
()
let
config
=
create
Config
()
await
fs
.
unlink
(
'
config.json
'
)
await
fs
.
unlink
(
'
config.defaults.json
'
)
...
...
@@ -57,7 +57,7 @@ describe('config', function() {
await
fs
.
mkdir
(
'
tmp
'
)
await
fs
.
writeFile
(
'
tmp/config.defaults.json
'
,
JSON
.
stringify
(
jsonDefaults
))
await
fs
.
writeFile
(
'
tmp/config.json
'
,
JSON
.
stringify
(
jsonLocals
))
let
config
=
new
Config
(
'
tmp
'
)
let
config
=
create
Config
(
'
tmp
'
)
await
fs
.
unlink
(
'
tmp/config.json
'
)
await
fs
.
unlink
(
'
tmp/config.defaults.json
'
)
await
fs
.
rmdir
(
'
tmp
'
)
...
...
@@ -75,7 +75,7 @@ describe('config', function() {
process
.
env
[
'
ANOTHER_MORE
'
]
=
'
false
'
process
.
env
[
'
EVEN_DEEPER_KEY
'
]
=
'
true
'
let
config
=
new
Config
()
let
config
=
create
Config
()
await
fs
.
unlink
(
'
config.json
'
)
await
fs
.
unlink
(
'
config.defaults.json
'
)
...
...
@@ -98,7 +98,7 @@ describe('config', function() {
process
.
env
[
'
P_ANOTHER_MORE
'
]
=
'
false
'
process
.
env
[
'
P_EVEN_DEEPER_KEY
'
]
=
'
true
'
let
config
=
new
Config
(
undefined
,
'
p
'
)
let
config
=
create
Config
(
undefined
,
'
p
'
)
await
fs
.
unlink
(
'
config.json
'
)
await
fs
.
unlink
(
'
config.defaults.json
'
)
...
...
@@ -119,7 +119,7 @@ describe('config', function() {
await
fs
.
writeFile
(
'
config.json
'
,
JSON
.
stringify
(
jsonLocals
))
await
fs
.
writeFile
(
'
file.txt
'
,
'
value-from-file
'
)
let
config
=
new
Config
()
let
config
=
create
Config
()
await
fs
.
unlink
(
'
config.json
'
)
await
fs
.
unlink
(
'
config.defaults.json
'
)
...
...
@@ -133,7 +133,7 @@ describe('config', function() {
await
fs
.
writeFile
(
'
config.defaults.json
'
,
JSON
.
stringify
(
jsonDefaults
))
await
fs
.
writeFile
(
'
config.json
'
,
JSON
.
stringify
(
jsonLocals
))
let
config
=
new
Config
()
let
config
=
create
Config
()
await
fs
.
unlink
(
'
config.json
'
)
await
fs
.
unlink
(
'
config.defaults.json
'
)
...
...
@@ -146,7 +146,7 @@ describe('config', function() {
await
fs
.
writeFile
(
'
config.defaults.json
'
,
JSON
.
stringify
(
jsonDefaults
))
await
fs
.
writeFile
(
'
config.json
'
,
JSON
.
stringify
(
jsonLocals
))
let
config
=
new
Config
()
let
config
=
create
Config
()
expect
(
config
.
setting
).
toBe
(
'
localvalue
'
)
...
...
@@ -165,7 +165,7 @@ describe('config', function() {
await
fs
.
writeFile
(
'
config.defaults.json
'
,
JSON
.
stringify
(
jsonDefaults
))
await
fs
.
writeFile
(
'
config.json
'
,
JSON
.
stringify
(
jsonLocals
))
let
config
=
new
Config
()
let
config
=
create
Config
()
await
fs
.
unlink
(
'
config.json
'
)
await
fs
.
unlink
(
'
config.defaults.json
'
)
...
...
This diff is collapsed.
Click to expand it.
package.json
+
1
−
1
View file @
a680b8f8
{
"name"
:
"@libs/config"
,
"version"
:
"1.13.
5
"
,
"version"
:
"1.13.
6
"
,
"description"
:
"Simple Config with ENV Support"
,
"main"
:
"index.js"
,
"scripts"
:
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment