@@ -2,6 +2,7 @@ import * as fs from "fs-extra"
2
2
import * as path from "path"
3
3
import { extend , paths } from "./util"
4
4
import { logger } from "@coder/logger"
5
+ import { Route } from "./http"
5
6
6
7
export type Settings = { [ key : string ] : Settings | string | boolean | number }
7
8
@@ -29,11 +30,13 @@ export class SettingsProvider<T> {
29
30
30
31
/**
31
32
* Write settings combined with current settings. On failure log a warning.
32
- * Objects will be merged and everything else will be replaced .
33
+ * Settings can be shallow or deep merged .
33
34
*/
34
- public async write ( settings : Partial < T > ) : Promise < void > {
35
+ public async write ( settings : Partial < T > , shallow = true ) : Promise < void > {
35
36
try {
36
- await fs . writeFile ( this . settingsPath , JSON . stringify ( extend ( await this . read ( ) , settings ) , null , 2 ) )
37
+ const oldSettings = await this . read ( )
38
+ const nextSettings = shallow ? Object . assign ( { } , oldSettings , settings ) : extend ( oldSettings , settings )
39
+ await fs . writeFile ( this . settingsPath , JSON . stringify ( nextSettings , null , 2 ) )
37
40
} catch ( error ) {
38
41
logger . warn ( error . message )
39
42
}
@@ -55,6 +58,7 @@ export interface CoderSettings extends UpdateSettings {
55
58
url : string
56
59
workspace : boolean
57
60
}
61
+ query : Route [ "query" ]
58
62
}
59
63
60
64
/**
0 commit comments