Skip to content

Commit f7790c9

Browse files
committed
Remove unused deep merge code
1 parent 150d378 commit f7790c9

File tree

3 files changed

+4
-59
lines changed

3 files changed

+4
-59
lines changed

src/node/settings.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as fs from "fs-extra"
22
import * as path from "path"
3-
import { extend, paths } from "./util"
3+
import { paths } from "./util"
44
import { logger } from "@coder/logger"
55
import { Route } from "./http"
66

@@ -30,12 +30,12 @@ export class SettingsProvider<T> {
3030

3131
/**
3232
* Write settings combined with current settings. On failure log a warning.
33-
* Settings can be shallow or deep merged.
33+
* Settings will be merged shallowly.
3434
*/
35-
public async write(settings: Partial<T>, shallow = true): Promise<void> {
35+
public async write(settings: Partial<T>): Promise<void> {
3636
try {
3737
const oldSettings = await this.read()
38-
const nextSettings = shallow ? Object.assign({}, oldSettings, settings) : extend(oldSettings, settings)
38+
const nextSettings = { ...oldSettings, ...settings }
3939
await fs.writeFile(this.settingsPath, JSON.stringify(nextSettings, null, 2))
4040
} catch (error) {
4141
logger.warn(error.message)

src/node/util.ts

-19
Original file line numberDiff line numberDiff line change
@@ -199,25 +199,6 @@ export const isObject = <T extends object>(obj: T): obj is T => {
199199
return !Array.isArray(obj) && typeof obj === "object" && obj !== null
200200
}
201201

202-
/**
203-
* Extend a with b and return a new object. Properties with objects will be
204-
* recursively merged while all other properties are just overwritten.
205-
*/
206-
export function extend<A, B>(a: A, b: B): A & B
207-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
208-
export function extend(...args: any[]): any {
209-
const c = {} as any // eslint-disable-line @typescript-eslint/no-explicit-any
210-
for (const obj of args) {
211-
if (!isObject(obj)) {
212-
continue
213-
}
214-
for (const key in obj) {
215-
c[key] = isObject(obj[key]) ? extend(c[key], obj[key]) : obj[key]
216-
}
217-
}
218-
return c
219-
}
220-
221202
/**
222203
* Taken from vs/base/common/charCode.ts. Copied for now instead of importing so
223204
* we don't have to set up a `vs` alias to be able to import with types (since

test/util.test.ts

-36
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,7 @@
11
import * as assert from "assert"
22
import { normalize } from "../src/common/util"
3-
import { extend } from "../src/node/util"
43

54
describe("util", () => {
6-
describe("extend", () => {
7-
it("should extend", () => {
8-
const a = { foo: { bar: 0, baz: 2 }, garply: 4, waldo: 6 }
9-
const b = { foo: { bar: 1, qux: 3 }, garply: "5", fred: 7 }
10-
const extended = extend(a, b)
11-
assert.deepEqual(extended, {
12-
foo: { bar: 1, baz: 2, qux: 3 },
13-
garply: "5",
14-
waldo: 6,
15-
fred: 7,
16-
})
17-
})
18-
19-
it("should make deep copies of the original objects", () => {
20-
const a = { foo: 0, bar: { frobnozzle: 2 }, mumble: { qux: { thud: 4 } } }
21-
const b = { foo: 1, bar: { chad: 3 } }
22-
const extended = extend(a, b)
23-
assert.notEqual(a.bar, extended.bar)
24-
assert.notEqual(b.bar, extended.bar)
25-
assert.notEqual(a.mumble, extended.mumble)
26-
assert.notEqual(a.mumble.qux, extended.mumble.qux)
27-
})
28-
29-
it("should handle mismatch in type", () => {
30-
const a = { foo: { bar: 0, baz: 2, qux: { mumble: 11 } }, garply: 4, waldo: { thud: 10 } }
31-
const b = { foo: { bar: [1], baz: { plugh: 8 }, qux: 12 }, garply: { nox: 9 }, waldo: 7 }
32-
const extended = extend(a, b)
33-
assert.deepEqual(extended, {
34-
foo: { bar: [1], baz: { plugh: 8 }, qux: 12 },
35-
garply: { nox: 9 },
36-
waldo: 7,
37-
})
38-
})
39-
})
40-
415
describe("normalize", () => {
426
it("should remove multiple slashes", () => {
437
assert.equal(normalize("//foo//bar//baz///mumble"), "/foo/bar/baz/mumble")

0 commit comments

Comments
 (0)