@@ -169,11 +169,7 @@ class Config {
169169 if ( ! this . loaded ) {
170170 throw new Error ( 'call config.load() before reading values' )
171171 }
172- // TODO single use?
173- return this . #find( key )
174- }
175172
176- #find ( key ) {
177173 // have to look in reverse order
178174 const entries = [ ...this . data . entries ( ) ]
179175 for ( let i = entries . length - 1 ; i > - 1 ; i -- ) {
@@ -210,8 +206,11 @@ class Config {
210206 throw new Error ( 'invalid config location param: ' + where )
211207 }
212208 this . #checkDeprecated( key )
213- const { data } = this . data . get ( where )
209+ const { data, raw } = this . data . get ( where )
214210 data [ key ] = val
211+ if ( [ 'global' , 'user' , 'project' ] . includes ( where ) ) {
212+ raw [ key ] = val
213+ }
215214
216215 // this is now dirty, the next call to this.valid will have to check it
217216 this . data . get ( where ) [ _valid ] = null
@@ -244,7 +243,11 @@ class Config {
244243 if ( ! confTypes . has ( where ) ) {
245244 throw new Error ( 'invalid config location param: ' + where )
246245 }
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+ }
248251 }
249252
250253 async load ( ) {
@@ -537,6 +540,7 @@ class Config {
537540 }
538541
539542 #loadObject ( obj , where , source , er = null ) {
543+ // obj is the raw data read from the file
540544 const conf = this . data . get ( where )
541545 if ( conf . source ) {
542546 const m = `double-loading "${ where } " configs from ${ source } , ` +
@@ -724,7 +728,9 @@ class Config {
724728 }
725729 }
726730
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'
728734 if ( ! iniData . trim ( ) ) {
729735 // ignore the unlink error (eg, if file doesn't exist)
730736 await unlink ( conf . source ) . catch ( er => { } )
@@ -873,7 +879,7 @@ class ConfigData {
873879 #raw = null
874880 constructor ( parent ) {
875881 this . #data = Object . create ( parent && parent . data )
876- this . #raw = null
882+ this . #raw = { }
877883 this [ _valid ] = true
878884 }
879885
@@ -897,7 +903,7 @@ class ConfigData {
897903 }
898904
899905 set loadError ( e ) {
900- if ( this [ _loadError ] || this . #raw) {
906+ if ( this [ _loadError ] || ( Object . keys ( this . #raw) . length ) ) {
901907 throw new Error ( 'cannot set ConfigData loadError after load' )
902908 }
903909 this [ _loadError ] = e
@@ -908,7 +914,7 @@ class ConfigData {
908914 }
909915
910916 set raw ( r ) {
911- if ( this . #raw || this [ _loadError ] ) {
917+ if ( Object . keys ( this . #raw) . length || this [ _loadError ] ) {
912918 throw new Error ( 'cannot set ConfigData raw after load' )
913919 }
914920 this . #raw = r
0 commit comments