From f7790c9719d0948fcb2c94e62fb4c1646200d6aa Mon Sep 17 00:00:00 2001 From: Asher Date: Tue, 4 Aug 2020 15:12:15 -0500 Subject: [PATCH] Remove unused deep merge code --- src/node/settings.ts | 8 ++++---- src/node/util.ts | 19 ------------------- test/util.test.ts | 36 ------------------------------------ 3 files changed, 4 insertions(+), 59 deletions(-) diff --git a/src/node/settings.ts b/src/node/settings.ts index 7564b531..213cd1a2 100644 --- a/src/node/settings.ts +++ b/src/node/settings.ts @@ -1,6 +1,6 @@ import * as fs from "fs-extra" import * as path from "path" -import { extend, paths } from "./util" +import { paths } from "./util" import { logger } from "@coder/logger" import { Route } from "./http" @@ -30,12 +30,12 @@ export class SettingsProvider { /** * Write settings combined with current settings. On failure log a warning. - * Settings can be shallow or deep merged. + * Settings will be merged shallowly. */ - public async write(settings: Partial, shallow = true): Promise { + public async write(settings: Partial): Promise { try { const oldSettings = await this.read() - const nextSettings = shallow ? Object.assign({}, oldSettings, settings) : extend(oldSettings, settings) + const nextSettings = { ...oldSettings, ...settings } await fs.writeFile(this.settingsPath, JSON.stringify(nextSettings, null, 2)) } catch (error) { logger.warn(error.message) diff --git a/src/node/util.ts b/src/node/util.ts index a6f8f9b5..a70d7ef6 100644 --- a/src/node/util.ts +++ b/src/node/util.ts @@ -199,25 +199,6 @@ export const isObject = (obj: T): obj is T => { return !Array.isArray(obj) && typeof obj === "object" && obj !== null } -/** - * Extend a with b and return a new object. Properties with objects will be - * recursively merged while all other properties are just overwritten. - */ -export function extend(a: A, b: B): A & B -// eslint-disable-next-line @typescript-eslint/no-explicit-any -export function extend(...args: any[]): any { - const c = {} as any // eslint-disable-line @typescript-eslint/no-explicit-any - for (const obj of args) { - if (!isObject(obj)) { - continue - } - for (const key in obj) { - c[key] = isObject(obj[key]) ? extend(c[key], obj[key]) : obj[key] - } - } - return c -} - /** * Taken from vs/base/common/charCode.ts. Copied for now instead of importing so * we don't have to set up a `vs` alias to be able to import with types (since diff --git a/test/util.test.ts b/test/util.test.ts index 28fb9fc8..978d3ee5 100644 --- a/test/util.test.ts +++ b/test/util.test.ts @@ -1,43 +1,7 @@ import * as assert from "assert" import { normalize } from "../src/common/util" -import { extend } from "../src/node/util" describe("util", () => { - describe("extend", () => { - it("should extend", () => { - const a = { foo: { bar: 0, baz: 2 }, garply: 4, waldo: 6 } - const b = { foo: { bar: 1, qux: 3 }, garply: "5", fred: 7 } - const extended = extend(a, b) - assert.deepEqual(extended, { - foo: { bar: 1, baz: 2, qux: 3 }, - garply: "5", - waldo: 6, - fred: 7, - }) - }) - - it("should make deep copies of the original objects", () => { - const a = { foo: 0, bar: { frobnozzle: 2 }, mumble: { qux: { thud: 4 } } } - const b = { foo: 1, bar: { chad: 3 } } - const extended = extend(a, b) - assert.notEqual(a.bar, extended.bar) - assert.notEqual(b.bar, extended.bar) - assert.notEqual(a.mumble, extended.mumble) - assert.notEqual(a.mumble.qux, extended.mumble.qux) - }) - - it("should handle mismatch in type", () => { - const a = { foo: { bar: 0, baz: 2, qux: { mumble: 11 } }, garply: 4, waldo: { thud: 10 } } - const b = { foo: { bar: [1], baz: { plugh: 8 }, qux: 12 }, garply: { nox: 9 }, waldo: 7 } - const extended = extend(a, b) - assert.deepEqual(extended, { - foo: { bar: [1], baz: { plugh: 8 }, qux: 12 }, - garply: { nox: 9 }, - waldo: 7, - }) - }) - }) - describe("normalize", () => { it("should remove multiple slashes", () => { assert.equal(normalize("//foo//bar//baz///mumble"), "/foo/bar/baz/mumble")