Skip to content

Commit d6d2496

Browse files
committed
Move vscode JS to a separate file
Mostly to match everything else.
1 parent 751a5ea commit d6d2496

File tree

4 files changed

+59
-51
lines changed

4 files changed

+59
-51
lines changed

ci/build/build-code-server.sh

+3-2
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ main() {
2121
--public-url "." \
2222
--out-dir dist \
2323
$([[ $MINIFY ]] || echo --no-minify) \
24-
src/browser/login.ts \
2524
src/browser/register.ts \
26-
src/browser/serviceWorker.ts
25+
src/browser/serviceWorker.ts \
26+
src/browser/pages/login.ts \
27+
src/browser/pages/vscode.ts
2728
}
2829

2930
main "$@"

ci/dev/watch.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,10 @@ class Watcher {
165165
private createBundler(out = "dist"): Bundler {
166166
return new Bundler(
167167
[
168-
path.join(this.rootPath, "src/browser/login.ts"),
169168
path.join(this.rootPath, "src/browser/register.ts"),
170169
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"),
171172
],
172173
{
173174
outDir: path.join(this.rootPath, out),

src/browser/pages/vscode.html

+1-48
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

+53
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+
}

0 commit comments

Comments
 (0)