Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
3c10163
Flesh out fixes to align with upstream.
GirlBossRush Oct 28, 2021
0e7eb7e
Update route handlers to better reflect fallback behavior.
GirlBossRush Oct 29, 2021
ad787bb
Bump vendor.
GirlBossRush Oct 29, 2021
19c9c23
Touch up build, tests.
GirlBossRush Oct 29, 2021
062ce32
bump vscode.
GirlBossRush Nov 4, 2021
2481711
Add platform to vscode-reh-web task
code-asher Nov 4, 2021
dde9a08
Fix issue where workspace args are not parsed.
GirlBossRush Nov 4, 2021
26733fd
Update CLI test.
GirlBossRush Nov 4, 2021
059893f
Update CLI tests.
GirlBossRush Nov 4, 2021
9945428
Fix issues surrounding opening files within code-server's terminal.
GirlBossRush Nov 4, 2021
93adec7
Bump vendor.
GirlBossRush Nov 4, 2021
28e0d78
Update VS Code
code-asher Nov 5, 2021
4cf13f4
Merge remote-tracking branch 'origin/main' into upstream-server-fixes
code-asher Nov 5, 2021
76e6ccc
Readd parent wrapper for hot reload.
GirlBossRush Nov 5, 2021
efada23
Allow more errors.
GirlBossRush Nov 5, 2021
1f7e8a1
Bump vscode.
GirlBossRush Nov 5, 2021
914aad2
Fix issues surrounding Coder link.
GirlBossRush Nov 5, 2021
a413abf
Add dir creation and fix cli
code-asher Nov 5, 2021
55d878e
Remove hardcoded VSCODE_DEV=1
code-asher Nov 8, 2021
d03c9f5
Fix mismatching commit between client and server
code-asher Nov 8, 2021
8244463
Mostly restore command-line parity
code-asher Nov 8, 2021
d5ed30f
Fix static endpoint not emitting 404s
code-asher Nov 8, 2021
30b9923
Update VS Code
code-asher Nov 8, 2021
a281ccd
Import missing logError
code-asher Nov 9, 2021
7d48b82
Fix 403 errors
code-asher Nov 9, 2021
fc94ac9
Add code-server version to about dialog
code-asher Nov 9, 2021
89cc5a9
Use user settings to disable welcome page
code-asher Nov 10, 2021
e022788
Update VS Code cache step with new build directories
code-asher Nov 10, 2021
c8f2b12
Merge branch 'main' into upstream-server-fixes
code-asher Nov 10, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Flesh out fixes to align with upstream.
  • Loading branch information
GirlBossRush authored and jsjoeio committed Nov 3, 2021
commit 3c101634526ba6b2ec0caf7e205d6930893129b4
2 changes: 1 addition & 1 deletion src/node/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const listen = (server: http.Server, { host, port, socket }: ListenOptions) => {
server.listen(socket, onListen)
} else {
// [] is the correct format when using :: but Node errors with them.
server.listen(port, host.replace(/^\[|\]$/g, ""), onListen)
server.listen(parseInt(port, 10), host.replace(/^\[|\]$/g, ""), onListen)
}
})
}
Expand Down
100 changes: 56 additions & 44 deletions src/node/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,7 @@ export enum LogLevel {

export class OptionalString extends Optional<string> {}

export interface Args
extends Pick<
CodeServerLib.NativeParsedArgs,
| "_"
| "user-data-dir"
| "enable-proposed-api"
| "extensions-dir"
| "builtin-extensions-dir"
| "extra-extensions-dir"
| "extra-builtin-extensions-dir"
| "ignore-last-opened"
| "locale"
| "log"
| "verbose"
| "install-source"
| "list-extensions"
| "install-extension"
| "uninstall-extension"
| "locate-extension"
// | "telemetry"
> {
export interface Args extends CodeServerLib.ServerParsedArgs {
config?: string
auth?: AuthType
password?: string
Expand All @@ -67,7 +47,6 @@ export interface Args
json?: boolean
log?: LogLevel
open?: boolean
port?: number
"bind-addr"?: string
socket?: string
version?: boolean
Expand All @@ -76,6 +55,7 @@ export interface Args
"proxy-domain"?: string[]
"reuse-window"?: boolean
"new-window"?: boolean
verbose?: boolean

link?: OptionalString
}
Expand Down Expand Up @@ -169,7 +149,7 @@ const options: Options<Required<Args>> = {

// These two have been deprecated by bindAddr.
host: { type: "string", description: "" },
port: { type: "number", description: "" },
port: { type: "string", description: "" },

socket: { type: "string", path: true, description: "Path to a socket (bind-addr will be ignored)." },
version: { type: "boolean", short: "v", description: "Display version information." },
Expand All @@ -178,31 +158,18 @@ const options: Options<Required<Args>> = {
"user-data-dir": { type: "string", path: true, description: "Path to the user data directory." },
"extensions-dir": { type: "string", path: true, description: "Path to the extensions directory." },
"builtin-extensions-dir": { type: "string", path: true },
"extra-extensions-dir": { type: "string[]", path: true },
"extra-builtin-extensions-dir": { type: "string[]", path: true },
"list-extensions": { type: "boolean", description: "List installed VS Code extensions." },
force: { type: "boolean", description: "Avoid prompts when installing VS Code extensions." },
"install-source": { type: "string" },
"locate-extension": { type: "string[]" },
"install-extension": {
type: "string[]",
description:
"Install or update a VS Code extension by id or vsix. The identifier of an extension is `${publisher}.${name}`.\n" +
"To install a specific version provide `@${version}`. For example: '[email protected]'.",
},
"enable-proposed-api": {
type: "string[]",
description:
"Enable proposed API features for extensions. Can receive one or more extension IDs to enable individually.",
},
"uninstall-extension": { type: "string[]", description: "Uninstall a VS Code extension by id." },
"show-versions": { type: "boolean", description: "Show VS Code extension versions." },
"proxy-domain": { type: "string[]", description: "Domain used for proxying ports." },
"ignore-last-opened": {
type: "boolean",
short: "e",
description: "Ignore the last opened directory or workspace in favor of an empty window.",
},
"new-window": {
type: "boolean",
short: "n",
Expand All @@ -214,7 +181,6 @@ const options: Options<Required<Args>> = {
description: "Force to open a file or folder in an already opened window.",
},

locale: { type: "string" },
log: { type: LogLevel },
verbose: { type: "boolean", short: "vvv", description: "Enable verbose logging." },

Expand All @@ -227,6 +193,43 @@ const options: Options<Required<Args>> = {
`,
beta: true,
},

connectionToken: { type: "string" },
"connection-secret": {
type: "string",
description:
"Path to file that contains the connection token. This will require that all incoming connections know the secret.",
},
"socket-path": { type: "string" },
driver: { type: "string" },
"start-server": { type: "boolean" },
"print-startup-performance": { type: "boolean" },
"print-ip-address": { type: "boolean" },
"disable-websocket-compression": { type: "boolean" },

fileWatcherPolling: { type: "string" },

"enable-remote-auto-shutdown": { type: "boolean" },
"remote-auto-shutdown-without-delay": { type: "boolean" },

"without-browser-env-var": { type: "boolean" },
"extensions-download-dir": { type: "string" },
"install-builtin-extension": { type: "string[]" },

category: {
type: "string",
description: "Filters installed extensions by provided category, when using --list-extensions.",
},
"do-not-sync": { type: "boolean" },
"force-disable-user-env": { type: "boolean" },

folder: { type: "string" },
workspace: { type: "string" },
"web-user-data-dir": { type: "string" },
"use-host-proxy": { type: "string" },
"enable-sync": { type: "boolean" },
"github-auth": { type: "string" },
logsPath: { type: "string" },
}

export const optionDescriptions = (): string[] => {
Expand Down Expand Up @@ -271,6 +274,14 @@ export function splitOnFirstEquals(str: string): string[] {
return split
}

const createDefaultArgs = (): Args => {
return {
_: [],
workspace: "",
folder: "",
}
}

export const parse = (
argv: string[],
opts?: {
Expand All @@ -285,7 +296,8 @@ export const parse = (
return new Error(msg)
}

const args: Args = { _: [] }
// TODO: parse workspace and folder.
const args: Args = createDefaultArgs()
let ended = false

for (let i = 0; i < argv.length; ++i) {
Expand Down Expand Up @@ -403,7 +415,7 @@ export interface DefaultedArgs extends ConfigArgs {
value: string
}
host: string
port: number
port: string
"proxy-domain": string[]
verbose: boolean
usingEnvPassword: boolean
Expand Down Expand Up @@ -472,15 +484,15 @@ export async function setDefaults(cliArgs: Args, configArgs?: ConfigArgs): Promi
args.auth = AuthType.Password
}

const addr = bindAddrFromAllSources(configArgs || { _: [] }, cliArgs)
const addr = bindAddrFromAllSources(configArgs || createDefaultArgs(), cliArgs)
args.host = addr.host
args.port = addr.port
args.port = addr.port.toString()

// If we're being exposed to the cloud, we listen on a random address and
// disable auth.
if (args.link) {
args.host = "localhost"
args.port = 0
args.port = "0"
args.socket = undefined
args.cert = undefined
args.auth = AuthType.None
Expand Down Expand Up @@ -581,7 +593,7 @@ export async function readConfigFile(configPath?: string): Promise<ConfigArgs> {
*/
export function parseConfigFile(configFile: string, configPath: string): ConfigArgs {
if (!configFile) {
return { _: [], config: configPath }
return { ...createDefaultArgs(), config: configPath }
}

const config = yaml.load(configFile, {
Expand Down Expand Up @@ -641,7 +653,7 @@ export function bindAddrFromArgs(addr: Addr, args: Args): Addr {
addr.port = parseInt(process.env.PORT, 10)
}
if (args.port !== undefined) {
addr.port = args.port
addr.port = parseInt(args.port, 10)
}
return addr
}
Expand Down
14 changes: 8 additions & 6 deletions src/node/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ import { startLink } from "./link"
import { register } from "./routes"
import { humanPath, isFile, loadAMDModule, open } from "./util"

export const shouldSpawnCliProcess = async (args: CodeServerLib.NativeParsedArgs): Promise<boolean> => {
const shouldSpawn = await loadAMDModule<(argv: CodeServerLib.NativeParsedArgs) => boolean>(
"vs/code/node/cli",
"shouldSpawnCliProcess",
export const shouldSpawnCliProcess = async (args: CodeServerLib.ServerParsedArgs): Promise<boolean> => {
return (
!args["start-server"] &&
(!!args["list-extensions"] ||
!!args["install-extension"] ||
!!args["install-builtin-extension"] ||
!!args["uninstall-extension"] ||
!!args["locate-extension"])
)

return shouldSpawn(args)
}

/**
Expand Down
29 changes: 13 additions & 16 deletions src/node/routes/vscode.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as express from "express"
import path from "path"
import { AuthType, DefaultedArgs } from "../cli"
import { version as codeServerVersion, vsRootPath } from "../constants"
import { DefaultedArgs } from "../cli"
import { vsRootPath } from "../constants"
import { ensureAuthenticated, authenticated, redirect } from "../http"
import { loadAMDModule } from "../util"
import { Router as WsRouter, WebsocketRouter } from "../wsRouter"
Expand All @@ -10,7 +10,7 @@ import { errorHandler } from "./errors"
export interface VSServerResult {
router: express.Router
wsRouter: WebsocketRouter
codeServerMain: CodeServerLib.IServerProcessMain
codeServerMain: CodeServerLib.IServerAPI
}

export const createVSServerRouter = async (args: DefaultedArgs): Promise<VSServerResult> => {
Expand All @@ -37,19 +37,15 @@ export const createVSServerRouter = async (args: DefaultedArgs): Promise<VSServe

// Signal processes that we got launched as CLI
process.env["VSCODE_CLI"] = "1"
// Seems to be necessary to load modules properly.
process.env["VSCODE_DEV"] = "1"

const createVSServer = await loadAMDModule<CodeServerLib.CreateVSServer>("vs/server/entry", "createVSServer")
const createVSServer = await loadAMDModule<CodeServerLib.CreateServer>(
"vs/server/remoteExtensionHostAgentServer",
"createServer",
)

const serverUrl = new URL(`${args.cert ? "https" : "http"}://${args.host}:${args.port}`)
const codeServerMain = await createVSServer({
codeServerVersion,
serverUrl,
args,
authed: args.auth !== AuthType.None,
disableUpdateCheck: !!args["disable-update-check"],
})

const netServer = await codeServerMain.startup({ listenWhenReady: false })
const codeServerMain = await createVSServer(null, { ...args, connectionToken: "0000" }, args["user-data-dir"])

const router = express.Router()
const wsRouter = WsRouter()
Expand All @@ -68,11 +64,12 @@ export const createVSServerRouter = async (args: DefaultedArgs): Promise<VSServe
router.all("*", ensureAuthenticated, (req, res, next) => {
req.on("error", (error) => errorHandler(error, req, res, next))

netServer.emit("request", req, res)
codeServerMain.handleRequest(req, res)
})

wsRouter.ws("/", ensureAuthenticated, (req) => {
netServer.emit("upgrade", req, req.socket, req.head)
codeServerMain.handleUpgrade(req, req.socket)
// netServer.emit("upgrade", req, req.socket, req.head)

req.socket.resume()
})
Expand Down
8 changes: 8 additions & 0 deletions src/node/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,14 @@ type AMDModule<T> = { [exportName: string]: T }
* @param exportName Given name of export in the file
*/
export const loadAMDModule = async <T>(amdPath: string, exportName: string): Promise<T> => {
// Set default remote native node modules path, if unset
process.env["VSCODE_INJECT_NODE_MODULE_LOOKUP_PATH"] =
process.env["VSCODE_INJECT_NODE_MODULE_LOOKUP_PATH"] || path.join(vsRootPath, "remote", "node_modules")

require(path.join(vsRootPath, "out/bootstrap-node")).injectNodeModuleLookupPath(
process.env["VSCODE_INJECT_NODE_MODULE_LOOKUP_PATH"],
)

const module = await new Promise<AMDModule<T>>((resolve, reject) => {
require(path.join(vsRootPath, "out/bootstrap-amd")).load(amdPath, resolve, reject)
})
Expand Down