diff --git a/.gitignore b/.gitignore index 424cb9e7..616f9b01 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ release-gcp/ release-images/ node_modules node-* +/plugins diff --git a/ci/build/build-code-server.sh b/ci/build/build-code-server.sh index df528874..f0e4ddc3 100755 --- a/ci/build/build-code-server.sh +++ b/ci/build/build-code-server.sh @@ -18,7 +18,7 @@ main() { fi parcel build \ - --public-url "/static/$(git rev-parse HEAD)/dist" \ + --public-url "." \ --out-dir dist \ $([[ $MINIFY ]] || echo --no-minify) \ src/browser/register.ts \ diff --git a/ci/build/build-release.sh b/ci/build/build-release.sh index 6ef0d4d5..1cb00ad0 100755 --- a/ci/build/build-release.sh +++ b/ci/build/build-release.sh @@ -21,6 +21,12 @@ main() { rsync README.md "$RELEASE_PATH" rsync LICENSE.txt "$RELEASE_PATH" rsync ./lib/vscode/ThirdPartyNotices.txt "$RELEASE_PATH" + + # code-server exports types which can be imported and used by plugins. Those + # types import ipc.d.ts but it isn't included in the final vscode build so + # we'll copy it ourselves here. + mkdir -p "$RELEASE_PATH/lib/vscode/src/vs/server" + rsync ./lib/vscode/src/vs/server/ipc.d.ts "$RELEASE_PATH/lib/vscode/src/vs/server" } bundle_code_server() { diff --git a/ci/dev/vscode.patch b/ci/dev/vscode.patch index 03b9c5f6..cb7ee829 100644 --- a/ci/dev/vscode.patch +++ b/ci/dev/vscode.patch @@ -722,10 +722,10 @@ index eab8591492..26668701f7 100644 options.logService.error(`${logPrefix} socketFactory.connect() failed. Error:`); diff --git a/src/vs/server/browser/client.ts b/src/vs/server/browser/client.ts new file mode 100644 -index 0000000000..8fb2a87303 +index 0000000000..3c0703b717 --- /dev/null +++ b/src/vs/server/browser/client.ts -@@ -0,0 +1,208 @@ +@@ -0,0 +1,189 @@ +import { Emitter } from 'vs/base/common/event'; +import { URI } from 'vs/base/common/uri'; +import { localize } from 'vs/nls'; @@ -761,31 +761,12 @@ index 0000000000..8fb2a87303 +}; + +/** -+ * Get options embedded in the HTML from the server. ++ * Get options embedded in the HTML. + */ +export const getOptions = (): T => { -+ if (typeof document === "undefined") { -+ return {} as T; -+ } -+ const el = document.getElementById("coder-options"); + try { -+ if (!el) { -+ throw new Error("no options element"); -+ } -+ const value = el.getAttribute("data-settings"); -+ if (!value) { -+ throw new Error("no options value"); -+ } -+ const options = JSON.parse(value); -+ const parts = window.location.pathname.replace(/^\//g, "").split("/"); -+ parts[parts.length - 1] = options.base; -+ const url = new URL(window.location.origin + "/" + parts.join("/")); -+ return { -+ ...options, -+ base: normalize(url.pathname, true), -+ }; ++ return JSON.parse(document.getElementById("coder-options")!.getAttribute("data-settings")!); + } catch (error) { -+ console.warn(error); + return {} as T; + } +}; @@ -1306,17 +1287,15 @@ index 0000000000..56331ff1fc +require('../../bootstrap-amd').load('vs/server/entry'); diff --git a/src/vs/server/ipc.d.ts b/src/vs/server/ipc.d.ts new file mode 100644 -index 0000000000..0a9c95d50e +index 0000000000..7e1cd270c8 --- /dev/null +++ b/src/vs/server/ipc.d.ts -@@ -0,0 +1,117 @@ +@@ -0,0 +1,115 @@ +/** + * External interfaces for integration into code-server over IPC. No vs imports + * should be made in this file. + */ +export interface Options { -+ base: string -+ commit: string + disableTelemetry: boolean +} + diff --git a/ci/dev/watch.ts b/ci/dev/watch.ts index fd144653..ba386b75 100644 --- a/ci/dev/watch.ts +++ b/ci/dev/watch.ts @@ -37,6 +37,7 @@ class Watcher { const vscode = cp.spawn("yarn", ["watch"], { cwd: this.vscodeSourcePath }) const tsc = cp.spawn("tsc", ["--watch", "--pretty", "--preserveWatchOutput"], { cwd: this.rootPath }) + const plugin = cp.spawn("yarn", ["build", "--watch"], { cwd: process.env.PLUGIN_DIR }) const bundler = this.createBundler() const cleanup = (code?: number | null): void => { @@ -48,6 +49,10 @@ class Watcher { tsc.removeAllListeners() tsc.kill() + Watcher.log("killing plugin") + plugin.removeAllListeners() + plugin.kill() + if (server) { Watcher.log("killing server") server.removeAllListeners() @@ -69,6 +74,10 @@ class Watcher { Watcher.log("tsc terminated unexpectedly") cleanup(code) }) + plugin.on("exit", (code) => { + Watcher.log("plugin terminated unexpectedly") + cleanup(code) + }) const bundle = bundler.bundle().catch(() => { Watcher.log("parcel watcher terminated unexpectedly") cleanup(1) @@ -82,6 +91,7 @@ class Watcher { vscode.stderr.on("data", (d) => process.stderr.write(d)) tsc.stderr.on("data", (d) => process.stderr.write(d)) + plugin.stderr.on("data", (d) => process.stderr.write(d)) // From https://github.com/chalk/ansi-regex const pattern = [ @@ -140,6 +150,16 @@ class Watcher { bundle.then(restartServer) } }) + + onLine(plugin, (line, original) => { + // tsc outputs blank lines; skip them. + if (line !== "") { + console.log("[plugin]", original) + } + if (line.includes("Watching for file changes")) { + bundle.then(restartServer) + } + }) } private createBundler(out = "dist"): Bundler { @@ -150,7 +170,7 @@ class Watcher { cacheDir: path.join(this.rootPath, ".cache"), minify: !!process.env.MINIFY, logLevel: 1, - publicUrl: "/static/development/dist", + publicUrl: ".", }, ) } diff --git a/src/browser/media/manifest.json b/src/browser/media/manifest.json index 76ec15ce..b33be207 100644 --- a/src/browser/media/manifest.json +++ b/src/browser/media/manifest.json @@ -7,32 +7,32 @@ "description": "Run editors on a remote server.", "icons": [ { - "src": "{{BASE}}/static/{{COMMIT}}/src/browser/media/pwa-icon-96.png", + "src": "{{CS_STATIC_BASE}}/src/browser/media/pwa-icon-96.png", "type": "image/png", "sizes": "96x96" }, { - "src": "{{BASE}}/static/{{COMMIT}}/src/browser/media/pwa-icon-128.png", + "src": "{{CS_STATIC_BASE}}/src/browser/media/pwa-icon-128.png", "type": "image/png", "sizes": "128x128" }, { - "src": "{{BASE}}/static/{{COMMIT}}/src/browser/media/pwa-icon-192.png", + "src": "{{CS_STATIC_BASE}}/src/browser/media/pwa-icon-192.png", "type": "image/png", "sizes": "192x192" }, { - "src": "{{BASE}}/static/{{COMMIT}}/src/browser/media/pwa-icon-256.png", + "src": "{{CS_STATIC_BASE}}/src/browser/media/pwa-icon-256.png", "type": "image/png", "sizes": "256x256" }, { - "src": "{{BASE}}/static/{{COMMIT}}/src/browser/media/pwa-icon-384.png", + "src": "{{CS_STATIC_BASE}}/src/browser/media/pwa-icon-384.png", "type": "image/png", "sizes": "384x384" }, { - "src": "{{BASE}}/static/{{COMMIT}}/src/browser/media/pwa-icon-512.png", + "src": "{{CS_STATIC_BASE}}/src/browser/media/pwa-icon-512.png", "type": "image/png", "sizes": "512x512" } diff --git a/src/browser/pages/error.html b/src/browser/pages/error.html index 12d6efe2..9e6dd0b9 100644 --- a/src/browser/pages/error.html +++ b/src/browser/pages/error.html @@ -11,14 +11,10 @@ content="style-src 'self'; manifest-src 'self'; img-src 'self' data:; font-src 'self' data:;" /> {{ERROR_TITLE}} - code-server - - - - + + + + @@ -33,6 +29,6 @@ - + diff --git a/src/browser/pages/login.html b/src/browser/pages/login.html index 788055d6..586c9c66 100644 --- a/src/browser/pages/login.html +++ b/src/browser/pages/login.html @@ -11,14 +11,10 @@ content="style-src 'self'; script-src 'self' 'unsafe-inline'; manifest-src 'self'; img-src 'self' data:; font-src 'self' data:;" /> code-server login - - - - + + + + @@ -50,7 +46,7 @@ - + - - + +