Skip to content

Commit 3c90b1e

Browse files
authored
Merge pull request #1969 from cdr/qol
qol changes
2 parents 0dcf469 + d8568eb commit 3c90b1e

14 files changed

+89
-125
lines changed

.eslintrc.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ rules:
2323
no-dupe-class-members: off
2424
"@typescript-eslint/no-use-before-define": off
2525
"@typescript-eslint/no-non-null-assertion": off
26+
eqeqeq: error
27+
import/order:
28+
[error, { alphabetize: { order: "asc" }, groups: [["builtin", "external", "internal"], "parent", "sibling"] }]
2629

2730
settings:
2831
# Does not work with CommonJS unfortunately.

ci/build/build-code-server.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ MINIFY=${MINIFY-true}
99
main() {
1010
cd "$(dirname "${0}")/../.."
1111

12-
tsc --outDir out --tsBuildInfoFile .cache/out.tsbuildinfo
12+
tsc
13+
1314
# If out/node/entry.js does not already have the shebang,
1415
# we make sure to add it and make it executable.
1516
if ! grep -q -m1 "^#!/usr/bin/env node" out/node/entry.js; then
@@ -22,7 +23,9 @@ main() {
2223
--out-dir dist \
2324
$([[ $MINIFY ]] || echo --no-minify) \
2425
src/browser/register.ts \
25-
src/browser/serviceWorker.ts
26+
src/browser/serviceWorker.ts \
27+
src/browser/pages/login.ts \
28+
src/browser/pages/vscode.ts
2629
}
2730

2831
main "$@"

ci/dev/watch.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,12 @@ class Watcher {
164164

165165
private createBundler(out = "dist"): Bundler {
166166
return new Bundler(
167-
[path.join(this.rootPath, "src/browser/register.ts"), path.join(this.rootPath, "src/browser/serviceWorker.ts")],
167+
[
168+
path.join(this.rootPath, "src/browser/register.ts"),
169+
path.join(this.rootPath, "src/browser/serviceWorker.ts"),
170+
path.join(this.rootPath, "src/browser/pages/login.ts"),
171+
path.join(this.rootPath, "src/browser/pages/vscode.ts"),
172+
],
168173
{
169174
outDir: path.join(this.rootPath, out),
170175
cacheDir: path.join(this.rootPath, ".cache"),

src/browser/pages/login.html

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,5 @@ <h1 class="main">Welcome to code-server</h1>
4747
</div>
4848
</body>
4949
<script data-cfasync="false" src="{{CS_STATIC_BASE}}/dist/register.js"></script>
50-
<script>
51-
const parts = window.location.pathname.replace(/^\//g, "").split("/")
52-
parts[parts.length - 1] = "{{BASE}}"
53-
const url = new URL(window.location.origin + "/" + parts.join("/"))
54-
document.getElementById("base").value = url.pathname
55-
</script>
50+
<script data-cfasync="false" src="{{CS_STATIC_BASE}}/dist/login.js"></script>
5651
</html>

src/browser/pages/login.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { getOptions } from "../../common/util"
2+
3+
const options = getOptions()
4+
const el = document.getElementById("base") as HTMLInputElement
5+
if (el) {
6+
el.value = options.base
7+
}

src/browser/pages/vscode.html

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -43,47 +43,7 @@
4343
<body aria-label=""></body>
4444

4545
<!-- Startup (do not modify order of script tags!) -->
46-
<script>
47-
let nlsConfig
48-
try {
49-
nlsConfig = JSON.parse(document.getElementById("vscode-remote-nls-configuration").getAttribute("data-settings"))
50-
if (nlsConfig._resolvedLanguagePackCoreLocation) {
51-
const bundles = Object.create(null)
52-
nlsConfig.loadBundle = (bundle, language, cb) => {
53-
let result = bundles[bundle]
54-
if (result) {
55-
return cb(undefined, result)
56-
}
57-
// FIXME: Only works if path separators are /.
58-
const path = nlsConfig._resolvedLanguagePackCoreLocation + "/" + bundle.replace(/\//g, "!") + ".nls.json"
59-
fetch(`{{BASE}}/resource/?path=${encodeURIComponent(path)}`)
60-
.then((response) => response.json())
61-
.then((json) => {
62-
bundles[bundle] = json
63-
cb(undefined, json)
64-
})
65-
.catch(cb)
66-
}
67-
}
68-
} catch (error) {
69-
/* Probably fine. */
70-
}
71-
self.require = {
72-
baseUrl: "{{CS_STATIC_BASE}}/lib/vscode/out",
73-
paths: {
74-
"vscode-textmate": `../node_modules/vscode-textmate/release/main`,
75-
"vscode-oniguruma": `../node_modules/vscode-oniguruma/release/main`,
76-
xterm: `../node_modules/xterm/lib/xterm.js`,
77-
"xterm-addon-search": `../node_modules/xterm-addon-search/lib/xterm-addon-search.js`,
78-
"xterm-addon-unicode11": `../node_modules/xterm-addon-unicode11/lib/xterm-addon-unicode11.js`,
79-
"xterm-addon-webgl": `../node_modules/xterm-addon-webgl/lib/xterm-addon-webgl.js`,
80-
"semver-umd": `../node_modules/semver-umd/lib/semver-umd.js`,
81-
"iconv-lite-umd": `../node_modules/iconv-lite-umd/lib/iconv-lite-umd.js`,
82-
jschardet: `../node_modules/jschardet/dist/jschardet.min.js`,
83-
},
84-
"vs/nls": nlsConfig,
85-
}
86-
</script>
46+
<script data-cfasync="false" src="{{CS_STATIC_BASE}}/dist/pages/vscode.js"></script>
8747
<script data-cfasync="false" src="{{CS_STATIC_BASE}}/dist/register.js"></script>
8848
<script data-cfasync="false" src="{{CS_STATIC_BASE}}/lib/vscode/out/vs/loader.js"></script>
8949
<!-- PROD_ONLY
@@ -93,11 +53,4 @@
9353
<script>
9454
require(["vs/code/browser/workbench/workbench"], function () {})
9555
</script>
96-
<script>
97-
try {
98-
document.body.style.background = JSON.parse(localStorage.getItem("colorThemeData")).colorMap["editor.background"]
99-
} catch (error) {
100-
// Oh well.
101-
}
102-
</script>
10356
</html>

src/browser/pages/vscode.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { getOptions } from "../../common/util"
2+
3+
const options = getOptions()
4+
5+
// TODO: Add proper types.
6+
/* eslint-disable @typescript-eslint/no-explicit-any */
7+
8+
let nlsConfig: any
9+
try {
10+
nlsConfig = JSON.parse(document.getElementById("vscode-remote-nls-configuration")!.getAttribute("data-settings")!)
11+
if (nlsConfig._resolvedLanguagePackCoreLocation) {
12+
const bundles = Object.create(null)
13+
nlsConfig.loadBundle = (bundle: any, _language: any, cb: any): void => {
14+
const result = bundles[bundle]
15+
if (result) {
16+
return cb(undefined, result)
17+
}
18+
// FIXME: Only works if path separators are /.
19+
const path = nlsConfig._resolvedLanguagePackCoreLocation + "/" + bundle.replace(/\//g, "!") + ".nls.json"
20+
fetch(`{{BASE}}/resource/?path=${encodeURIComponent(path)}`)
21+
.then((response) => response.json())
22+
.then((json) => {
23+
bundles[bundle] = json
24+
cb(undefined, json)
25+
})
26+
.catch(cb)
27+
}
28+
}
29+
} catch (error) {
30+
/* Probably fine. */
31+
}
32+
33+
;(self.require as any) = {
34+
baseUrl: `${options.csStaticBase}/lib/vscode/out`,
35+
paths: {
36+
"vscode-textmate": `../node_modules/vscode-textmate/release/main`,
37+
"vscode-oniguruma": `../node_modules/vscode-oniguruma/release/main`,
38+
xterm: `../node_modules/xterm/lib/xterm.js`,
39+
"xterm-addon-search": `../node_modules/xterm-addon-search/lib/xterm-addon-search.js`,
40+
"xterm-addon-unicode11": `../node_modules/xterm-addon-unicode11/lib/xterm-addon-unicode11.js`,
41+
"xterm-addon-webgl": `../node_modules/xterm-addon-webgl/lib/xterm-addon-webgl.js`,
42+
"semver-umd": `../node_modules/semver-umd/lib/semver-umd.js`,
43+
"iconv-lite-umd": `../node_modules/iconv-lite-umd/lib/iconv-lite-umd.js`,
44+
jschardet: `../node_modules/jschardet/dist/jschardet.min.js`,
45+
},
46+
"vs/nls": nlsConfig,
47+
}
48+
49+
try {
50+
document.body.style.background = JSON.parse(localStorage.getItem("colorThemeData")!).colorMap["editor.background"]
51+
} catch (error) {
52+
// Oh well.
53+
}

src/node/cli.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ export const parse = (
176176
const arg = argv[i]
177177

178178
// -- signals the end of option parsing.
179-
if (!ended && arg == "--") {
179+
if (!ended && arg === "--") {
180180
ended = true
181181
continue
182182
}
@@ -224,7 +224,7 @@ export const parse = (
224224
throw error(`--${key} requires a value`)
225225
}
226226

227-
if (option.type == OptionalString && value == "false") {
227+
if (option.type === OptionalString && value === "false") {
228228
continue
229229
}
230230

src/node/http.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,7 @@ export class HttpServer {
868868
// isn't setting the host header to match the access domain.
869869
host === "localhost"
870870
) {
871+
logger.debug("no valid cookie doman", field("host", host))
871872
return undefined
872873
}
873874

@@ -877,6 +878,7 @@ export class HttpServer {
877878
}
878879
})
879880

881+
logger.debug("got cookie doman", field("host", host))
880882
return host ? `Domain=${host}` : undefined
881883
}
882884

src/node/settings.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
import { logger } from "@coder/logger"
12
import * as fs from "fs-extra"
23
import * as path from "path"
3-
import { extend, paths } from "./util"
4-
import { logger } from "@coder/logger"
54
import { Route } from "./http"
5+
import { paths } from "./util"
66

77
export type Settings = { [key: string]: Settings | string | boolean | number }
88

@@ -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

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import * as cp from "child_process"
22
import * as crypto from "crypto"
3+
import envPaths from "env-paths"
34
import * as fs from "fs-extra"
45
import * as os from "os"
56
import * as path from "path"
67
import * as util from "util"
7-
import envPaths from "env-paths"
88
import xdgBasedir from "xdg-basedir"
99

1010
export const tmpdir = path.join(os.tmpdir(), "code-server")
@@ -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/socket.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import * as net from "net"
66
import * as path from "path"
77
import * as tls from "tls"
88
import { Emitter } from "../src/common/emitter"
9-
import { generateCertificate, tmpdir } from "../src/node/util"
109
import { SocketProxyProvider } from "../src/node/socket"
10+
import { generateCertificate, tmpdir } from "../src/node/util"
1111

1212
describe("SocketProxyProvider", () => {
1313
const provider = new SocketProxyProvider()

test/util.test.ts

Lines changed: 0 additions & 36 deletions
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")

tsconfig.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,15 @@
88
"noUnusedLocals": true,
99
"forceConsistentCasingInFileNames": true,
1010
"outDir": "./out",
11-
"allowJs": false,
12-
"jsx": "react",
1311
"declaration": true,
1412
"experimentalDecorators": true,
1513
"esModuleInterop": true,
1614
"allowSyntheticDefaultImports": true,
1715
"sourceMap": true,
18-
"tsBuildInfoFile": "./.tsbuildinfo",
16+
"tsBuildInfoFile": "./.cache/tsbuildinfo",
1917
"incremental": true,
2018
"rootDir": "./src",
2119
"typeRoots": ["./node_modules/@types", "./typings"]
2220
},
23-
"include": ["./src/**/*.ts", "./src/**/*.tsx"]
21+
"include": ["./src/**/*.ts"]
2422
}

0 commit comments

Comments
 (0)