@@ -6,7 +6,6 @@ const {watchPath} = require('./path-watcher')
6
6
const CSON = require ( 'season' )
7
7
const Path = require ( 'path' )
8
8
const async = require ( 'async' )
9
- const temp = require ( 'temp' )
10
9
11
10
const EVENT_TYPES = new Set ( [
12
11
'created' ,
@@ -38,20 +37,18 @@ class ConfigFile {
38
37
this . reloadCallbacks = [ ]
39
38
40
39
// Use a queue to prevent multiple concurrent write to the same file.
41
- const writeQueue = async . queue ( ( data , callback ) => {
42
- ( async ( ) => {
43
- try {
44
- await writeCSONFileAtomically ( this . path , data )
45
- } catch ( error ) {
40
+ const writeQueue = async . queue ( ( data , callback ) =>
41
+ CSON . writeFile ( this . path , data , error => {
42
+ if ( error ) {
46
43
this . emitter . emit ( 'did-error' , dedent `
47
44
Failed to write \`${ Path . basename ( this . path ) } \`.
48
45
49
46
${ error . message }
50
47
` )
51
48
}
52
49
callback ( )
53
- } ) ( )
54
- } )
50
+ } )
51
+ )
55
52
56
53
this . requestLoad = _ . debounce ( ( ) => this . reload ( ) , 200 )
57
54
this . requestSave = _ . debounce ( ( data ) => writeQueue . push ( data ) , 200 )
@@ -119,27 +116,3 @@ class ConfigFile {
119
116
} )
120
117
}
121
118
}
122
-
123
- function writeCSONFile ( path , data ) {
124
- return new Promise ( ( resolve , reject ) => {
125
- CSON . writeFile ( path , data , error => {
126
- if ( error ) reject ( error )
127
- else resolve ( )
128
- } )
129
- } )
130
- }
131
-
132
- async function writeCSONFileAtomically ( path , data ) {
133
- const tempPath = temp . path ( )
134
- await writeCSONFile ( tempPath , data )
135
- await rename ( tempPath , path )
136
- }
137
-
138
- function rename ( oldPath , newPath ) {
139
- return new Promise ( ( resolve , reject ) => {
140
- fs . rename ( oldPath , newPath , error => {
141
- if ( error ) reject ( error )
142
- else resolve ( )
143
- } )
144
- } )
145
- }
0 commit comments