@@ -169,11 +169,7 @@ class Config {
169
169
if ( ! this . loaded ) {
170
170
throw new Error ( 'call config.load() before reading values' )
171
171
}
172
- // TODO single use?
173
- return this . #find( key )
174
- }
175
172
176
- #find ( key ) {
177
173
// have to look in reverse order
178
174
const entries = [ ...this . data . entries ( ) ]
179
175
for ( let i = entries . length - 1 ; i > - 1 ; i -- ) {
@@ -210,8 +206,11 @@ class Config {
210
206
throw new Error ( 'invalid config location param: ' + where )
211
207
}
212
208
this . #checkDeprecated( key )
213
- const { data } = this . data . get ( where )
209
+ const { data, raw } = this . data . get ( where )
214
210
data [ key ] = val
211
+ if ( [ 'global' , 'user' , 'project' ] . includes ( where ) ) {
212
+ raw [ key ] = val
213
+ }
215
214
216
215
// this is now dirty, the next call to this.valid will have to check it
217
216
this . data . get ( where ) [ _valid ] = null
@@ -244,7 +243,11 @@ class Config {
244
243
if ( ! confTypes . has ( where ) ) {
245
244
throw new Error ( 'invalid config location param: ' + where )
246
245
}
247
- delete this . data . get ( where ) . data [ key ]
246
+ const { data, raw } = this . data . get ( where )
247
+ delete data [ key ]
248
+ if ( [ 'global' , 'user' , 'project' ] . includes ( where ) ) {
249
+ delete raw [ key ]
250
+ }
248
251
}
249
252
250
253
async load ( ) {
@@ -537,6 +540,7 @@ class Config {
537
540
}
538
541
539
542
#loadObject ( obj , where , source , er = null ) {
543
+ // obj is the raw data read from the file
540
544
const conf = this . data . get ( where )
541
545
if ( conf . source ) {
542
546
const m = `double-loading "${ where } " configs from ${ source } , ` +
@@ -724,7 +728,9 @@ class Config {
724
728
}
725
729
}
726
730
727
- const iniData = ini . stringify ( conf . data ) . trim ( ) + '\n'
731
+ // We need the actual raw data before we called parseField so that we are
732
+ // saving the same content back to the file
733
+ const iniData = ini . stringify ( conf . raw ) . trim ( ) + '\n'
728
734
if ( ! iniData . trim ( ) ) {
729
735
// ignore the unlink error (eg, if file doesn't exist)
730
736
await unlink ( conf . source ) . catch ( er => { } )
@@ -873,7 +879,7 @@ class ConfigData {
873
879
#raw = null
874
880
constructor ( parent ) {
875
881
this . #data = Object . create ( parent && parent . data )
876
- this . #raw = null
882
+ this . #raw = { }
877
883
this [ _valid ] = true
878
884
}
879
885
@@ -897,7 +903,7 @@ class ConfigData {
897
903
}
898
904
899
905
set loadError ( e ) {
900
- if ( this [ _loadError ] || this . #raw) {
906
+ if ( this [ _loadError ] || ( Object . keys ( this . #raw) . length ) ) {
901
907
throw new Error ( 'cannot set ConfigData loadError after load' )
902
908
}
903
909
this [ _loadError ] = e
@@ -908,7 +914,7 @@ class ConfigData {
908
914
}
909
915
910
916
set raw ( r ) {
911
- if ( this . #raw || this [ _loadError ] ) {
917
+ if ( Object . keys ( this . #raw) . length || this [ _loadError ] ) {
912
918
throw new Error ( 'cannot set ConfigData raw after load' )
913
919
}
914
920
this . #raw = r
0 commit comments