refactor: write route.query via settings.write
I added a shallow parameter, because the query should not be extends, but should be replaced directly.
This commit is contained in:
@@ -2,6 +2,7 @@ import * as fs from "fs-extra"
|
||||
import * as path from "path"
|
||||
import { extend, paths } from "./util"
|
||||
import { logger } from "@coder/logger"
|
||||
import { Route } from "./http"
|
||||
|
||||
export type Settings = { [key: string]: Settings | string | boolean | number }
|
||||
|
||||
@@ -31,9 +32,11 @@ export class SettingsProvider<T> {
|
||||
* Write settings combined with current settings. On failure log a warning.
|
||||
* Objects will be merged and everything else will be replaced.
|
||||
*/
|
||||
public async write(settings: Partial<T>): Promise<void> {
|
||||
public async write(settings: Partial<T>, shallow?: boolean): Promise<void> {
|
||||
try {
|
||||
await fs.writeFile(this.settingsPath, JSON.stringify(extend(await this.read(), settings), null, 2))
|
||||
const oldSettings = await this.read()
|
||||
const nextSettings = shallow ? Object.assign({}, oldSettings, settings) : extend(oldSettings, settings)
|
||||
await fs.writeFile(this.settingsPath, JSON.stringify(nextSettings, null, 2))
|
||||
} catch (error) {
|
||||
logger.warn(error.message)
|
||||
}
|
||||
@@ -55,6 +58,7 @@ export interface CoderSettings extends UpdateSettings {
|
||||
url: string
|
||||
workspace: boolean
|
||||
}
|
||||
query: Route["query"]
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user