Use upstream server (#4414)
* Flesh out fixes to align with upstream. * Update route handlers to better reflect fallback behavior. * Add platform to vscode-reh-web task Our strategy has been to build once and then recompile native modules for individual platforms. It looks like VS Code builds from scratch for each platform. But we can target any platform, grab the pre-packaged folder, then continue with own packaging. In the future we may want to rework to match upstream. * Fix issue where workspace args are not parsed. * Fix issues surrounding opening files within code-server's terminal. * Readd parent wrapper for hot reload. * Allow more errors. * Fix issues surrounding Coder link. * Add dir creation and fix cli It seems VS Code explodes when certain directories do not exist so import the reh agent instead of the server component since it creates the directories (require patching thus the VS Code update). Also the CLI (for installing extensions) did not seem to be working so point that to the same place since it also exports a function for running that part of the CLI. * Remove hardcoded VSCODE_DEV=1 This causes VS Code to use the development HTML file. Move this to the watch command instead. I deleted the other stuff before it as well since in the latest main.js they do not have this code so I figure we should be safe to omit it. * Fix mismatching commit between client and server * Mostly restore command-line parity Restore most everything and remove the added server arguments. This will let us add and remove options after later so we can contain the number of breaking changes. To accomplish this a hard separation is added between the CLI arguments and the server arguments. The separation between user-provided arguments and arguments with defaults is also made more clear. The extra directory flags have been left out as they were buggy and should be implemented upstream although I think there are better solutions anyway. locale and install-source are unsupported with the web remote and are left removed. It is unclear whether they were used before anyway. Some restored flags still need to have their behavior re-implemented. * Fix static endpoint not emitting 404s This fixes the last failing unit test. Fix a missing dependency, add some generic reverse proxy support for the protocol, and add back a missing nfpm fix. * Import missing logError * Fix 403 errors * Add code-server version to about dialog * Use user settings to disable welcome page The workspace setting seems to be recognized but if so it is having no effect. * Update VS Code cache step with new build directories Co-authored-by: Asher <ash@coder.com>
This commit is contained in:
parent
31d5823d10
commit
1b60ef418c
|
@ -142,9 +142,9 @@ jobs:
|
||||||
path: |
|
path: |
|
||||||
vendor/modules/code-oss-dev/.build
|
vendor/modules/code-oss-dev/.build
|
||||||
vendor/modules/code-oss-dev/out-build
|
vendor/modules/code-oss-dev/out-build
|
||||||
vendor/modules/code-oss-dev/out-vscode-server
|
vendor/modules/code-oss-dev/out-vscode-reh-web
|
||||||
vendor/modules/code-oss-dev/out-vscode-server-min
|
vendor/modules/code-oss-dev/out-vscode-reh-web-min
|
||||||
key: vscode-server-build-${{ steps.vscode-rev.outputs.rev }}
|
key: vscode-reh-build-${{ steps.vscode-rev.outputs.rev }}
|
||||||
|
|
||||||
- name: Build vscode
|
- name: Build vscode
|
||||||
if: steps.cache-vscode.outputs.cache-hit != 'true'
|
if: steps.cache-vscode.outputs.cache-hit != 'true'
|
||||||
|
|
|
@ -67,7 +67,7 @@ EOF
|
||||||
bundle_vscode() {
|
bundle_vscode() {
|
||||||
mkdir -p "$VSCODE_OUT_PATH"
|
mkdir -p "$VSCODE_OUT_PATH"
|
||||||
rsync "$VSCODE_SRC_PATH/yarn.lock" "$VSCODE_OUT_PATH"
|
rsync "$VSCODE_SRC_PATH/yarn.lock" "$VSCODE_OUT_PATH"
|
||||||
rsync "$VSCODE_SRC_PATH/out-vscode-server${MINIFY:+-min}/" "$VSCODE_OUT_PATH/out"
|
rsync "$VSCODE_SRC_PATH/out-vscode-reh-web${MINIFY:+-min}/" "$VSCODE_OUT_PATH/out"
|
||||||
|
|
||||||
rsync "$VSCODE_SRC_PATH/.build/extensions/" "$VSCODE_OUT_PATH/extensions"
|
rsync "$VSCODE_SRC_PATH/.build/extensions/" "$VSCODE_OUT_PATH/extensions"
|
||||||
if [ "$KEEP_MODULES" = 0 ]; then
|
if [ "$KEEP_MODULES" = 0 ]; then
|
||||||
|
@ -88,7 +88,7 @@ bundle_vscode() {
|
||||||
cat << EOF
|
cat << EOF
|
||||||
{
|
{
|
||||||
"enableTelemetry": true,
|
"enableTelemetry": true,
|
||||||
"commit": "$(git rev-parse HEAD)",
|
"commit": "$(cd "$VSCODE_SRC_PATH" && git rev-parse HEAD)",
|
||||||
"quality": "stable",
|
"quality": "stable",
|
||||||
"date": $(jq -n 'now | todate')
|
"date": $(jq -n 'now | todate')
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,9 +11,8 @@ main() {
|
||||||
|
|
||||||
cd vendor/modules/code-oss-dev
|
cd vendor/modules/code-oss-dev
|
||||||
|
|
||||||
# extensions-ci compiles extensions and includes their media.
|
# Any platform works since we have our own packaging step (for now).
|
||||||
# compile-web compiles web extensions. TODO: Unsure if used.
|
yarn gulp "vscode-reh-web-linux-x64${MINIFY:+-min}"
|
||||||
yarn gulp extensions-ci compile-web "vscode-server${MINIFY:+-min}"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
main "$@"
|
main "$@"
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
"lint": "./ci/dev/lint.sh",
|
"lint": "./ci/dev/lint.sh",
|
||||||
"test": "echo 'Run yarn test:unit or yarn test:e2e' && exit 1",
|
"test": "echo 'Run yarn test:unit or yarn test:e2e' && exit 1",
|
||||||
"ci": "./ci/dev/ci.sh",
|
"ci": "./ci/dev/ci.sh",
|
||||||
"watch": "VSCODE_IPC_HOOK_CLI= NODE_OPTIONS='--max_old_space_size=32384 --trace-warnings' ts-node ./ci/dev/watch.ts",
|
"watch": "VSCODE_DEV=1 VSCODE_IPC_HOOK_CLI= NODE_OPTIONS='--max_old_space_size=32384 --trace-warnings' ts-node ./ci/dev/watch.ts",
|
||||||
"icons": "./ci/dev/gen_icons.sh",
|
"icons": "./ci/dev/gen_icons.sh",
|
||||||
"coverage": "codecov"
|
"coverage": "codecov"
|
||||||
},
|
},
|
||||||
|
|
147
src/node/cli.ts
147
src/node/cli.ts
|
@ -3,7 +3,15 @@ import { promises as fs } from "fs"
|
||||||
import yaml from "js-yaml"
|
import yaml from "js-yaml"
|
||||||
import * as os from "os"
|
import * as os from "os"
|
||||||
import * as path from "path"
|
import * as path from "path"
|
||||||
import { canConnect, generateCertificate, generatePassword, humanPath, paths, isNodeJSErrnoException } from "./util"
|
import {
|
||||||
|
canConnect,
|
||||||
|
generateCertificate,
|
||||||
|
generatePassword,
|
||||||
|
humanPath,
|
||||||
|
paths,
|
||||||
|
isNodeJSErrnoException,
|
||||||
|
isFile,
|
||||||
|
} from "./util"
|
||||||
|
|
||||||
const DEFAULT_SOCKET_PATH = path.join(os.tmpdir(), "vscode-ipc")
|
const DEFAULT_SOCKET_PATH = path.join(os.tmpdir(), "vscode-ipc")
|
||||||
|
|
||||||
|
@ -31,27 +39,13 @@ export enum LogLevel {
|
||||||
|
|
||||||
export class OptionalString extends Optional<string> {}
|
export class OptionalString extends Optional<string> {}
|
||||||
|
|
||||||
export interface Args
|
/**
|
||||||
extends Pick<
|
* Arguments that the user explicitly provided on the command line. All
|
||||||
CodeServerLib.NativeParsedArgs,
|
* arguments must be optional.
|
||||||
| "_"
|
*
|
||||||
| "user-data-dir"
|
* For arguments with defaults see DefaultedArgs.
|
||||||
| "enable-proposed-api"
|
*/
|
||||||
| "extensions-dir"
|
export interface UserProvidedArgs {
|
||||||
| "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"
|
|
||||||
> {
|
|
||||||
config?: string
|
config?: string
|
||||||
auth?: AuthType
|
auth?: AuthType
|
||||||
password?: string
|
password?: string
|
||||||
|
@ -59,25 +53,39 @@ export interface Args
|
||||||
cert?: OptionalString
|
cert?: OptionalString
|
||||||
"cert-host"?: string
|
"cert-host"?: string
|
||||||
"cert-key"?: string
|
"cert-key"?: string
|
||||||
"disable-telemetry"?: boolean
|
|
||||||
"disable-update-check"?: boolean
|
"disable-update-check"?: boolean
|
||||||
enable?: string[]
|
enable?: string[]
|
||||||
help?: boolean
|
help?: boolean
|
||||||
host?: string
|
host?: string
|
||||||
|
port?: number
|
||||||
json?: boolean
|
json?: boolean
|
||||||
log?: LogLevel
|
log?: LogLevel
|
||||||
open?: boolean
|
open?: boolean
|
||||||
port?: number
|
|
||||||
"bind-addr"?: string
|
"bind-addr"?: string
|
||||||
socket?: string
|
socket?: string
|
||||||
version?: boolean
|
version?: boolean
|
||||||
force?: boolean
|
|
||||||
"show-versions"?: boolean
|
|
||||||
"proxy-domain"?: string[]
|
"proxy-domain"?: string[]
|
||||||
"reuse-window"?: boolean
|
"reuse-window"?: boolean
|
||||||
"new-window"?: boolean
|
"new-window"?: boolean
|
||||||
|
"ignore-last-opened"?: boolean
|
||||||
link?: OptionalString
|
link?: OptionalString
|
||||||
|
verbose?: boolean
|
||||||
|
/* Positional arguments. */
|
||||||
|
_?: string[]
|
||||||
|
|
||||||
|
// VS Code flags.
|
||||||
|
"disable-telemetry"?: boolean
|
||||||
|
force?: boolean
|
||||||
|
"user-data-dir"?: string
|
||||||
|
"enable-proposed-api"?: string[]
|
||||||
|
"extensions-dir"?: string
|
||||||
|
"builtin-extensions-dir"?: string
|
||||||
|
"install-extension"?: string[]
|
||||||
|
"uninstall-extension"?: string[]
|
||||||
|
"list-extensions"?: boolean
|
||||||
|
"locate-extension"?: string[]
|
||||||
|
"show-versions"?: boolean
|
||||||
|
category?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Option<T> {
|
interface Option<T> {
|
||||||
|
@ -121,7 +129,7 @@ type Options<T> = {
|
||||||
[P in keyof T]: Option<OptionType<T[P]>>
|
[P in keyof T]: Option<OptionType<T[P]>>
|
||||||
}
|
}
|
||||||
|
|
||||||
const options: Options<Required<Args>> = {
|
const options: Options<Required<UserProvidedArgs>> = {
|
||||||
auth: { type: AuthType, description: "The type of authentication to use." },
|
auth: { type: AuthType, description: "The type of authentication to use." },
|
||||||
password: {
|
password: {
|
||||||
type: "string",
|
type: "string",
|
||||||
|
@ -178,12 +186,10 @@ const options: Options<Required<Args>> = {
|
||||||
"user-data-dir": { type: "string", path: true, description: "Path to the user data directory." },
|
"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." },
|
"extensions-dir": { type: "string", path: true, description: "Path to the extensions directory." },
|
||||||
"builtin-extensions-dir": { type: "string", path: true },
|
"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." },
|
"list-extensions": { type: "boolean", description: "List installed VS Code extensions." },
|
||||||
force: { type: "boolean", description: "Avoid prompts when installing VS Code extensions." },
|
force: { type: "boolean", description: "Avoid prompts when installing VS Code extensions." },
|
||||||
"install-source": { type: "string" },
|
|
||||||
"locate-extension": { type: "string[]" },
|
"locate-extension": { type: "string[]" },
|
||||||
|
category: { type: "string" },
|
||||||
"install-extension": {
|
"install-extension": {
|
||||||
type: "string[]",
|
type: "string[]",
|
||||||
description:
|
description:
|
||||||
|
@ -214,7 +220,6 @@ const options: Options<Required<Args>> = {
|
||||||
description: "Force to open a file or folder in an already opened window.",
|
description: "Force to open a file or folder in an already opened window.",
|
||||||
},
|
},
|
||||||
|
|
||||||
locale: { type: "string" },
|
|
||||||
log: { type: LogLevel },
|
log: { type: LogLevel },
|
||||||
verbose: { type: "boolean", short: "vvv", description: "Enable verbose logging." },
|
verbose: { type: "boolean", short: "vvv", description: "Enable verbose logging." },
|
||||||
|
|
||||||
|
@ -271,12 +276,16 @@ export function splitOnFirstEquals(str: string): string[] {
|
||||||
return split
|
return split
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse arguments into UserProvidedArgs. This should not go beyond checking
|
||||||
|
* that arguments are valid types and have values when required.
|
||||||
|
*/
|
||||||
export const parse = (
|
export const parse = (
|
||||||
argv: string[],
|
argv: string[],
|
||||||
opts?: {
|
opts?: {
|
||||||
configFile?: string
|
configFile?: string
|
||||||
},
|
},
|
||||||
): Args => {
|
): UserProvidedArgs => {
|
||||||
const error = (msg: string): Error => {
|
const error = (msg: string): Error => {
|
||||||
if (opts?.configFile) {
|
if (opts?.configFile) {
|
||||||
msg = `error reading ${opts.configFile}: ${msg}`
|
msg = `error reading ${opts.configFile}: ${msg}`
|
||||||
|
@ -285,7 +294,7 @@ export const parse = (
|
||||||
return new Error(msg)
|
return new Error(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
const args: Args = { _: [] }
|
const args: UserProvidedArgs = {}
|
||||||
let ended = false
|
let ended = false
|
||||||
|
|
||||||
for (let i = 0; i < argv.length; ++i) {
|
for (let i = 0; i < argv.length; ++i) {
|
||||||
|
@ -299,17 +308,17 @@ export const parse = (
|
||||||
|
|
||||||
// Options start with a dash and require a value if non-boolean.
|
// Options start with a dash and require a value if non-boolean.
|
||||||
if (!ended && arg.startsWith("-")) {
|
if (!ended && arg.startsWith("-")) {
|
||||||
let key: keyof Args | undefined
|
let key: keyof UserProvidedArgs | undefined
|
||||||
let value: string | undefined
|
let value: string | undefined
|
||||||
if (arg.startsWith("--")) {
|
if (arg.startsWith("--")) {
|
||||||
const split = splitOnFirstEquals(arg.replace(/^--/, ""))
|
const split = splitOnFirstEquals(arg.replace(/^--/, ""))
|
||||||
key = split[0] as keyof Args
|
key = split[0] as keyof UserProvidedArgs
|
||||||
value = split[1]
|
value = split[1]
|
||||||
} else {
|
} else {
|
||||||
const short = arg.replace(/^-/, "")
|
const short = arg.replace(/^-/, "")
|
||||||
const pair = Object.entries(options).find(([, v]) => v.short === short)
|
const pair = Object.entries(options).find(([, v]) => v.short === short)
|
||||||
if (pair) {
|
if (pair) {
|
||||||
key = pair[0] as keyof Args
|
key = pair[0] as keyof UserProvidedArgs
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -384,6 +393,10 @@ export const parse = (
|
||||||
}
|
}
|
||||||
|
|
||||||
// Everything else goes into _.
|
// Everything else goes into _.
|
||||||
|
if (typeof args._ === "undefined") {
|
||||||
|
args._ = []
|
||||||
|
}
|
||||||
|
|
||||||
args._.push(arg)
|
args._.push(arg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -397,6 +410,11 @@ export const parse = (
|
||||||
return args
|
return args
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User-provided arguments with defaults. The distinction between user-provided
|
||||||
|
* args and defaulted args exists so we can tell the difference between end
|
||||||
|
* values and what the user actually provided on the command line.
|
||||||
|
*/
|
||||||
export interface DefaultedArgs extends ConfigArgs {
|
export interface DefaultedArgs extends ConfigArgs {
|
||||||
auth: AuthType
|
auth: AuthType
|
||||||
cert?: {
|
cert?: {
|
||||||
|
@ -410,6 +428,10 @@ export interface DefaultedArgs extends ConfigArgs {
|
||||||
usingEnvHashedPassword: boolean
|
usingEnvHashedPassword: boolean
|
||||||
"extensions-dir": string
|
"extensions-dir": string
|
||||||
"user-data-dir": string
|
"user-data-dir": string
|
||||||
|
/* Positional arguments. */
|
||||||
|
_: []
|
||||||
|
folder: string
|
||||||
|
workspace: string
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -417,7 +439,7 @@ export interface DefaultedArgs extends ConfigArgs {
|
||||||
* with the defaults set. Arguments from the CLI are prioritized over config
|
* with the defaults set. Arguments from the CLI are prioritized over config
|
||||||
* arguments.
|
* arguments.
|
||||||
*/
|
*/
|
||||||
export async function setDefaults(cliArgs: Args, configArgs?: ConfigArgs): Promise<DefaultedArgs> {
|
export async function setDefaults(cliArgs: UserProvidedArgs, configArgs?: ConfigArgs): Promise<DefaultedArgs> {
|
||||||
const args = Object.assign({}, configArgs || {}, cliArgs)
|
const args = Object.assign({}, configArgs || {}, cliArgs)
|
||||||
|
|
||||||
if (!args["user-data-dir"]) {
|
if (!args["user-data-dir"]) {
|
||||||
|
@ -472,7 +494,7 @@ export async function setDefaults(cliArgs: Args, configArgs?: ConfigArgs): Promi
|
||||||
args.auth = AuthType.Password
|
args.auth = AuthType.Password
|
||||||
}
|
}
|
||||||
|
|
||||||
const addr = bindAddrFromAllSources(configArgs || { _: [] }, cliArgs)
|
const addr = bindAddrFromAllSources(configArgs || {}, cliArgs)
|
||||||
args.host = addr.host
|
args.host = addr.host
|
||||||
args.port = addr.port
|
args.port = addr.port
|
||||||
|
|
||||||
|
@ -513,8 +535,29 @@ export async function setDefaults(cliArgs: Args, configArgs?: ConfigArgs): Promi
|
||||||
const proxyDomains = new Set((args["proxy-domain"] || []).map((d) => d.replace(/^\*\./, "")))
|
const proxyDomains = new Set((args["proxy-domain"] || []).map((d) => d.replace(/^\*\./, "")))
|
||||||
args["proxy-domain"] = Array.from(proxyDomains)
|
args["proxy-domain"] = Array.from(proxyDomains)
|
||||||
|
|
||||||
|
if (typeof args._ === "undefined") {
|
||||||
|
args._ = []
|
||||||
|
}
|
||||||
|
|
||||||
|
let workspace = ""
|
||||||
|
let folder = ""
|
||||||
|
if (args._.length) {
|
||||||
|
const lastEntry = path.resolve(process.cwd(), args._[args._.length - 1])
|
||||||
|
const entryIsFile = await isFile(lastEntry)
|
||||||
|
|
||||||
|
if (entryIsFile && path.extname(lastEntry) === ".code-workspace") {
|
||||||
|
workspace = lastEntry
|
||||||
|
args._.pop()
|
||||||
|
} else if (!entryIsFile) {
|
||||||
|
folder = lastEntry
|
||||||
|
args._.pop()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...args,
|
...args,
|
||||||
|
workspace,
|
||||||
|
folder,
|
||||||
usingEnvPassword,
|
usingEnvPassword,
|
||||||
usingEnvHashedPassword,
|
usingEnvHashedPassword,
|
||||||
} as DefaultedArgs // TODO: Technically no guarantee this is fulfilled.
|
} as DefaultedArgs // TODO: Technically no guarantee this is fulfilled.
|
||||||
|
@ -539,7 +582,7 @@ cert: false
|
||||||
`
|
`
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ConfigArgs extends Args {
|
interface ConfigArgs extends UserProvidedArgs {
|
||||||
config: string
|
config: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -581,7 +624,7 @@ export async function readConfigFile(configPath?: string): Promise<ConfigArgs> {
|
||||||
*/
|
*/
|
||||||
export function parseConfigFile(configFile: string, configPath: string): ConfigArgs {
|
export function parseConfigFile(configFile: string, configPath: string): ConfigArgs {
|
||||||
if (!configFile) {
|
if (!configFile) {
|
||||||
return { _: [], config: configPath }
|
return { config: configPath }
|
||||||
}
|
}
|
||||||
|
|
||||||
const config = yaml.load(configFile, {
|
const config = yaml.load(configFile, {
|
||||||
|
@ -628,7 +671,7 @@ interface Addr {
|
||||||
* This function creates the bind address
|
* This function creates the bind address
|
||||||
* using the CLI args.
|
* using the CLI args.
|
||||||
*/
|
*/
|
||||||
export function bindAddrFromArgs(addr: Addr, args: Args): Addr {
|
export function bindAddrFromArgs(addr: Addr, args: UserProvidedArgs): Addr {
|
||||||
addr = { ...addr }
|
addr = { ...addr }
|
||||||
if (args["bind-addr"]) {
|
if (args["bind-addr"]) {
|
||||||
addr = parseBindAddr(args["bind-addr"])
|
addr = parseBindAddr(args["bind-addr"])
|
||||||
|
@ -646,7 +689,7 @@ export function bindAddrFromArgs(addr: Addr, args: Args): Addr {
|
||||||
return addr
|
return addr
|
||||||
}
|
}
|
||||||
|
|
||||||
function bindAddrFromAllSources(...argsConfig: Args[]): Addr {
|
function bindAddrFromAllSources(...argsConfig: UserProvidedArgs[]): Addr {
|
||||||
let addr: Addr = {
|
let addr: Addr = {
|
||||||
host: "localhost",
|
host: "localhost",
|
||||||
port: 8080,
|
port: 8080,
|
||||||
|
@ -683,30 +726,34 @@ export async function readSocketPath(path: string): Promise<string | undefined>
|
||||||
/**
|
/**
|
||||||
* Determine if it looks like the user is trying to open a file or folder in an
|
* Determine if it looks like the user is trying to open a file or folder in an
|
||||||
* existing instance. The arguments here should be the arguments the user
|
* existing instance. The arguments here should be the arguments the user
|
||||||
* explicitly passed on the command line, not defaults or the configuration.
|
* explicitly passed on the command line, *NOT DEFAULTS* or the configuration.
|
||||||
*/
|
*/
|
||||||
export const shouldOpenInExistingInstance = async (args: Args): Promise<string | undefined> => {
|
export const shouldOpenInExistingInstance = async (args: UserProvidedArgs): Promise<string | undefined> => {
|
||||||
// Always use the existing instance if we're running from VS Code's terminal.
|
// Always use the existing instance if we're running from VS Code's terminal.
|
||||||
if (process.env.VSCODE_IPC_HOOK_CLI) {
|
if (process.env.VSCODE_IPC_HOOK_CLI) {
|
||||||
|
logger.debug("Found VSCODE_IPC_HOOK_CLI")
|
||||||
return process.env.VSCODE_IPC_HOOK_CLI
|
return process.env.VSCODE_IPC_HOOK_CLI
|
||||||
}
|
}
|
||||||
|
|
||||||
// If these flags are set then assume the user is trying to open in an
|
// If these flags are set then assume the user is trying to open in an
|
||||||
// existing instance since these flags have no effect otherwise.
|
// existing instance since these flags have no effect otherwise.
|
||||||
const openInFlagCount = ["reuse-window", "new-window"].reduce((prev, cur) => {
|
const openInFlagCount = ["reuse-window", "new-window"].reduce((prev, cur) => {
|
||||||
return args[cur as keyof Args] ? prev + 1 : prev
|
return args[cur as keyof UserProvidedArgs] ? prev + 1 : prev
|
||||||
}, 0)
|
}, 0)
|
||||||
if (openInFlagCount > 0) {
|
if (openInFlagCount > 0) {
|
||||||
|
logger.debug("Found --reuse-window or --new-window")
|
||||||
return readSocketPath(DEFAULT_SOCKET_PATH)
|
return readSocketPath(DEFAULT_SOCKET_PATH)
|
||||||
}
|
}
|
||||||
|
|
||||||
// It's possible the user is trying to spawn another instance of code-server.
|
// It's possible the user is trying to spawn another instance of code-server.
|
||||||
// Check if any unrelated flags are set (check against one because `_` always
|
// 1. Check if any unrelated flags are set (this should only run when
|
||||||
// exists), that a file or directory was passed, and that the socket is
|
// code-server is invoked exactly like this: `code-server my-file`).
|
||||||
// active.
|
// 2. That a file or directory was passed.
|
||||||
if (Object.keys(args).length === 1 && args._.length > 0) {
|
// 3. That the socket is active.
|
||||||
|
if (Object.keys(args).length === 1 && typeof args._ !== "undefined" && args._.length > 0) {
|
||||||
const socketPath = await readSocketPath(DEFAULT_SOCKET_PATH)
|
const socketPath = await readSocketPath(DEFAULT_SOCKET_PATH)
|
||||||
if (socketPath && (await canConnect(socketPath))) {
|
if (socketPath && (await canConnect(socketPath))) {
|
||||||
|
logger.debug("Found existing code-server socket")
|
||||||
return socketPath
|
return socketPath
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ export function getPackageJson(relativePath: string): JSONSchemaForNPMPackageJso
|
||||||
|
|
||||||
const pkg = getPackageJson("../../package.json")
|
const pkg = getPackageJson("../../package.json")
|
||||||
|
|
||||||
|
export const pkgName = pkg.name || "code-server"
|
||||||
export const version = pkg.version || "development"
|
export const version = pkg.version || "development"
|
||||||
export const commit = pkg.commit || "development"
|
export const commit = pkg.commit || "development"
|
||||||
export const rootPath = path.resolve(__dirname, "../..")
|
export const rootPath = path.resolve(__dirname, "../..")
|
||||||
|
|
|
@ -1,13 +1,32 @@
|
||||||
import { logger } from "@coder/logger"
|
import { logger } from "@coder/logger"
|
||||||
import { optionDescriptions, parse, readConfigFile, setDefaults, shouldOpenInExistingInstance } from "./cli"
|
import { optionDescriptions, parse, readConfigFile, setDefaults, shouldOpenInExistingInstance } from "./cli"
|
||||||
import { commit, version } from "./constants"
|
import { commit, pkgName, version } from "./constants"
|
||||||
import { openInExistingInstance, runCodeServer, runVsCodeCli, shouldSpawnCliProcess } from "./main"
|
import { openInExistingInstance, runCodeServer, runVsCodeCli, shouldSpawnCliProcess } from "./main"
|
||||||
import { monkeyPatchProxyProtocols } from "./proxy_agent"
|
import { monkeyPatchProxyProtocols } from "./proxy_agent"
|
||||||
|
import { loadAMDModule } from "./util"
|
||||||
import { isChild, wrapper } from "./wrapper"
|
import { isChild, wrapper } from "./wrapper"
|
||||||
|
|
||||||
|
const cliPipe = process.env["VSCODE_IPC_HOOK_CLI"] as string
|
||||||
|
const cliCommand = process.env["VSCODE_CLIENT_COMMAND"] as string
|
||||||
|
|
||||||
async function entry(): Promise<void> {
|
async function entry(): Promise<void> {
|
||||||
monkeyPatchProxyProtocols()
|
monkeyPatchProxyProtocols()
|
||||||
|
|
||||||
|
if (cliPipe || cliCommand) {
|
||||||
|
const remoteAgentMain = await loadAMDModule<CodeServerLib.RemoteCLIMain>("vs/server/remoteCli", "main")
|
||||||
|
|
||||||
|
remoteAgentMain(
|
||||||
|
{
|
||||||
|
productName: pkgName,
|
||||||
|
version,
|
||||||
|
commit,
|
||||||
|
executableName: pkgName,
|
||||||
|
},
|
||||||
|
process.argv.slice(2),
|
||||||
|
)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// There's no need to check flags like --help or to spawn in an existing
|
// There's no need to check flags like --help or to spawn in an existing
|
||||||
// instance for the child process because these would have already happened in
|
// instance for the child process because these would have already happened in
|
||||||
// the parent and the child wouldn't have been spawned. We also get the
|
// the parent and the child wouldn't have been spawned. We also get the
|
||||||
|
@ -30,6 +49,8 @@ async function entry(): Promise<void> {
|
||||||
console.log("code-server", version, commit)
|
console.log("code-server", version, commit)
|
||||||
console.log("")
|
console.log("")
|
||||||
console.log(`Usage: code-server [options] [path]`)
|
console.log(`Usage: code-server [options] [path]`)
|
||||||
|
console.log(` - Opening a directory: code-server ./path/to/your/project`)
|
||||||
|
console.log(` - Opening a saved workspace: code-server ./path/to/your/project.code-workspace`)
|
||||||
console.log("")
|
console.log("")
|
||||||
console.log("Options")
|
console.log("Options")
|
||||||
optionDescriptions().forEach((description) => {
|
optionDescriptions().forEach((description) => {
|
||||||
|
@ -53,12 +74,14 @@ async function entry(): Promise<void> {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (await shouldSpawnCliProcess(args)) {
|
if (shouldSpawnCliProcess(args)) {
|
||||||
return runVsCodeCli()
|
logger.debug("Found VS Code arguments; spawning VS Code CLI")
|
||||||
|
return runVsCodeCli(args)
|
||||||
}
|
}
|
||||||
|
|
||||||
const socketPath = await shouldOpenInExistingInstance(cliArgs)
|
const socketPath = await shouldOpenInExistingInstance(cliArgs)
|
||||||
if (socketPath) {
|
if (socketPath) {
|
||||||
|
logger.debug("Trying to open in existing instance")
|
||||||
return openInExistingInstance(args, socketPath)
|
return openInExistingInstance(args, socketPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,19 +4,22 @@ import path from "path"
|
||||||
import { Disposable } from "../common/emitter"
|
import { Disposable } from "../common/emitter"
|
||||||
import { plural } from "../common/util"
|
import { plural } from "../common/util"
|
||||||
import { createApp, ensureAddress } from "./app"
|
import { createApp, ensureAddress } from "./app"
|
||||||
import { AuthType, DefaultedArgs, Feature } from "./cli"
|
import { AuthType, DefaultedArgs, Feature, UserProvidedArgs } from "./cli"
|
||||||
import { coderCloudBind } from "./coder_cloud"
|
import { coderCloudBind } from "./coder_cloud"
|
||||||
import { commit, version, vsRootPath } from "./constants"
|
import { commit, version } from "./constants"
|
||||||
import { register } from "./routes"
|
import { register } from "./routes"
|
||||||
import { humanPath, isFile, loadAMDModule, open } from "./util"
|
import { humanPath, isFile, loadAMDModule, open } from "./util"
|
||||||
|
|
||||||
export const shouldSpawnCliProcess = async (args: CodeServerLib.NativeParsedArgs): Promise<boolean> => {
|
/**
|
||||||
const shouldSpawn = await loadAMDModule<(argv: CodeServerLib.NativeParsedArgs) => boolean>(
|
* Return true if the user passed an extension-related VS Code flag.
|
||||||
"vs/code/node/cli",
|
*/
|
||||||
"shouldSpawnCliProcess",
|
export const shouldSpawnCliProcess = (args: UserProvidedArgs): boolean => {
|
||||||
|
return (
|
||||||
|
!!args["list-extensions"] ||
|
||||||
|
!!args["install-extension"] ||
|
||||||
|
!!args["uninstall-extension"] ||
|
||||||
|
!!args["locate-extension"]
|
||||||
)
|
)
|
||||||
|
|
||||||
return shouldSpawn(args)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -24,37 +27,18 @@ export const shouldSpawnCliProcess = async (args: CodeServerLib.NativeParsedArgs
|
||||||
* such as when managing extensions.
|
* such as when managing extensions.
|
||||||
* @deprecated This should be removed when code-server merges with lib/vscode.
|
* @deprecated This should be removed when code-server merges with lib/vscode.
|
||||||
*/
|
*/
|
||||||
export const runVsCodeCli = async (): Promise<void> => {
|
export const runVsCodeCli = async (args: DefaultedArgs): Promise<void> => {
|
||||||
logger.debug("Running VS Code CLI")
|
logger.debug("Running VS Code CLI")
|
||||||
|
|
||||||
// Delete `VSCODE_CWD` very early even before
|
// See ../../vendor/modules/code-oss-dev/src/vs/server/main.js.
|
||||||
// importing bootstrap files. We have seen
|
const spawnCli = await loadAMDModule<CodeServerLib.SpawnCli>("vs/server/remoteExtensionHostAgent", "spawnCli")
|
||||||
// reports where `code .` would use the wrong
|
|
||||||
// current working directory due to our variable
|
|
||||||
// somehow escaping to the parent shell
|
|
||||||
// (https://github.com/microsoft/vscode/issues/126399)
|
|
||||||
delete process.env["VSCODE_CWD"]
|
|
||||||
|
|
||||||
const bootstrap = require(path.join(vsRootPath, "out", "bootstrap"))
|
|
||||||
const bootstrapNode = require(path.join(vsRootPath, "out", "bootstrap-node"))
|
|
||||||
const product = require(path.join(vsRootPath, "product.json"))
|
|
||||||
|
|
||||||
// Avoid Monkey Patches from Application Insights
|
|
||||||
bootstrap.avoidMonkeyPatchFromAppInsights()
|
|
||||||
|
|
||||||
// Enable portable support
|
|
||||||
bootstrapNode.configurePortable(product)
|
|
||||||
|
|
||||||
// Enable ASAR support
|
|
||||||
bootstrap.enableASARSupport()
|
|
||||||
|
|
||||||
// Signal processes that we got launched as CLI
|
|
||||||
process.env["VSCODE_CLI"] = "1"
|
|
||||||
|
|
||||||
const cliProcessMain = await loadAMDModule<CodeServerLib.IMainCli["main"]>("vs/code/node/cli", "initialize")
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await cliProcessMain(process.argv)
|
await spawnCli({
|
||||||
|
...args,
|
||||||
|
// For some reason VS Code takes the port as a string.
|
||||||
|
port: typeof args.port !== "undefined" ? args.port.toString() : undefined,
|
||||||
|
})
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
logger.error("Got error from VS Code", error)
|
logger.error("Got error from VS Code", error)
|
||||||
}
|
}
|
||||||
|
@ -70,8 +54,9 @@ export const openInExistingInstance = async (args: DefaultedArgs, socketPath: st
|
||||||
forceReuseWindow: args["reuse-window"],
|
forceReuseWindow: args["reuse-window"],
|
||||||
forceNewWindow: args["new-window"],
|
forceNewWindow: args["new-window"],
|
||||||
}
|
}
|
||||||
for (let i = 0; i < args._.length; i++) {
|
const paths = args._ || []
|
||||||
const fp = path.resolve(args._[i])
|
for (let i = 0; i < paths.length; i++) {
|
||||||
|
const fp = path.resolve(paths[i])
|
||||||
if (await isFile(fp)) {
|
if (await isFile(fp)) {
|
||||||
pipeArgs.fileURIs.push(fp)
|
pipeArgs.fileURIs.push(fp)
|
||||||
} else {
|
} else {
|
||||||
|
@ -120,11 +105,17 @@ export const runCodeServer = async (
|
||||||
}
|
}
|
||||||
|
|
||||||
const app = await createApp(args)
|
const app = await createApp(args)
|
||||||
const serverAddress = ensureAddress(app.server, args.cert ? "https" : "http")
|
const protocol = args.cert ? "https" : "http"
|
||||||
|
const serverAddress = ensureAddress(app.server, protocol)
|
||||||
const disposeRoutes = await register(app, args)
|
const disposeRoutes = await register(app, args)
|
||||||
|
|
||||||
logger.info(`Using config file ${humanPath(args.config)}`)
|
logger.info(`Using config file ${humanPath(args.config)}`)
|
||||||
logger.info(`HTTP server listening on ${serverAddress.toString()} ${args.link ? "(randomized by --link)" : ""}`)
|
logger.info(
|
||||||
|
`${protocol.toUpperCase()} server listening on ${serverAddress.toString()} ${
|
||||||
|
args.link ? "(randomized by --link)" : ""
|
||||||
|
}`,
|
||||||
|
)
|
||||||
|
|
||||||
if (args.auth === AuthType.Password) {
|
if (args.auth === AuthType.Password) {
|
||||||
logger.info(" - Authentication is enabled")
|
logger.info(" - Authentication is enabled")
|
||||||
if (args.usingEnvPassword) {
|
if (args.usingEnvPassword) {
|
||||||
|
|
|
@ -8,7 +8,7 @@ import { rootPath } from "../constants"
|
||||||
import { replaceTemplates } from "../http"
|
import { replaceTemplates } from "../http"
|
||||||
import { escapeHtml, getMediaMime } from "../util"
|
import { escapeHtml, getMediaMime } from "../util"
|
||||||
|
|
||||||
const notFoundCodes = ["ENOENT", "EISDIR", "FileNotFound"]
|
const notFoundCodes = ["ENOENT", "EISDIR"]
|
||||||
export const errorHandler: express.ErrorRequestHandler = async (err, req, res, next) => {
|
export const errorHandler: express.ErrorRequestHandler = async (err, req, res, next) => {
|
||||||
if (notFoundCodes.includes(err.code)) {
|
if (notFoundCodes.includes(err.code)) {
|
||||||
err.status = HttpCode.NotFound
|
err.status = HttpCode.NotFound
|
||||||
|
|
|
@ -121,6 +121,7 @@ export const register = async (app: App, args: DefaultedArgs): Promise<Disposabl
|
||||||
"/_static",
|
"/_static",
|
||||||
express.static(rootPath, {
|
express.static(rootPath, {
|
||||||
cacheControl: commit !== "development",
|
cacheControl: commit !== "development",
|
||||||
|
fallthrough: false,
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
import * as express from "express"
|
import * as express from "express"
|
||||||
import path from "path"
|
import { DefaultedArgs } from "../cli"
|
||||||
import { AuthType, DefaultedArgs } from "../cli"
|
|
||||||
import { version as codeServerVersion, vsRootPath } from "../constants"
|
|
||||||
import { ensureAuthenticated, authenticated, redirect } from "../http"
|
import { ensureAuthenticated, authenticated, redirect } from "../http"
|
||||||
import { loadAMDModule } from "../util"
|
import { loadAMDModule } from "../util"
|
||||||
import { Router as WsRouter, WebsocketRouter } from "../wsRouter"
|
import { Router as WsRouter, WebsocketRouter } from "../wsRouter"
|
||||||
|
@ -10,47 +8,23 @@ import { errorHandler } from "./errors"
|
||||||
export interface VSServerResult {
|
export interface VSServerResult {
|
||||||
router: express.Router
|
router: express.Router
|
||||||
wsRouter: WebsocketRouter
|
wsRouter: WebsocketRouter
|
||||||
codeServerMain: CodeServerLib.IServerProcessMain
|
codeServerMain: CodeServerLib.IServerAPI
|
||||||
}
|
}
|
||||||
|
|
||||||
export const createVSServerRouter = async (args: DefaultedArgs): Promise<VSServerResult> => {
|
export const createVSServerRouter = async (args: DefaultedArgs): Promise<VSServerResult> => {
|
||||||
// Delete `VSCODE_CWD` very early even before
|
// See ../../../vendor/modules/code-oss-dev/src/vs/server/main.js.
|
||||||
// importing bootstrap files. We have seen
|
const createVSServer = await loadAMDModule<CodeServerLib.CreateServer>(
|
||||||
// reports where `code .` would use the wrong
|
"vs/server/remoteExtensionHostAgent",
|
||||||
// current working directory due to our variable
|
"createServer",
|
||||||
// somehow escaping to the parent shell
|
)
|
||||||
// (https://github.com/microsoft/vscode/issues/126399)
|
|
||||||
delete process.env["VSCODE_CWD"]
|
|
||||||
|
|
||||||
const bootstrap = require(path.join(vsRootPath, "out", "bootstrap"))
|
const codeServerMain = await createVSServer(null, {
|
||||||
const bootstrapNode = require(path.join(vsRootPath, "out", "bootstrap-node"))
|
connectionToken: "0000",
|
||||||
const product = require(path.join(vsRootPath, "product.json"))
|
...args,
|
||||||
|
// For some reason VS Code takes the port as a string.
|
||||||
// Avoid Monkey Patches from Application Insights
|
port: typeof args.port !== "undefined" ? args.port.toString() : undefined,
|
||||||
bootstrap.avoidMonkeyPatchFromAppInsights()
|
|
||||||
|
|
||||||
// Enable portable support
|
|
||||||
bootstrapNode.configurePortable(product)
|
|
||||||
|
|
||||||
// Enable ASAR support
|
|
||||||
bootstrap.enableASARSupport()
|
|
||||||
|
|
||||||
// Signal processes that we got launched as CLI
|
|
||||||
process.env["VSCODE_CLI"] = "1"
|
|
||||||
|
|
||||||
const createVSServer = await loadAMDModule<CodeServerLib.CreateVSServer>("vs/server/entry", "createVSServer")
|
|
||||||
|
|
||||||
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 router = express.Router()
|
const router = express.Router()
|
||||||
const wsRouter = WsRouter()
|
const wsRouter = WsRouter()
|
||||||
|
|
||||||
|
@ -66,13 +40,19 @@ export const createVSServerRouter = async (args: DefaultedArgs): Promise<VSServe
|
||||||
})
|
})
|
||||||
|
|
||||||
router.all("*", ensureAuthenticated, (req, res, next) => {
|
router.all("*", ensureAuthenticated, (req, res, next) => {
|
||||||
req.on("error", (error) => errorHandler(error, req, res, next))
|
req.on("error", (error: any) => {
|
||||||
|
if (error instanceof Error && ["EntryNotFound", "FileNotFound", "HttpError"].includes(error.message)) {
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
|
||||||
netServer.emit("request", req, res)
|
errorHandler(error, req, res, next)
|
||||||
|
})
|
||||||
|
|
||||||
|
codeServerMain.handleRequest(req, res)
|
||||||
})
|
})
|
||||||
|
|
||||||
wsRouter.ws("/", ensureAuthenticated, (req) => {
|
wsRouter.ws("/", ensureAuthenticated, (req) => {
|
||||||
netServer.emit("upgrade", req, req.socket, req.head)
|
codeServerMain.handleUpgrade(req, req.socket)
|
||||||
|
|
||||||
req.socket.resume()
|
req.socket.resume()
|
||||||
})
|
})
|
||||||
|
|
|
@ -506,6 +506,14 @@ type AMDModule<T> = { [exportName: string]: T }
|
||||||
* @param exportName Given name of export in the file
|
* @param exportName Given name of export in the file
|
||||||
*/
|
*/
|
||||||
export const loadAMDModule = async <T>(amdPath: string, exportName: string): Promise<T> => {
|
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) => {
|
const module = await new Promise<AMDModule<T>>((resolve, reject) => {
|
||||||
require(path.join(vsRootPath, "out/bootstrap-amd")).load(amdPath, resolve, reject)
|
require(path.join(vsRootPath, "out/bootstrap-amd")).load(amdPath, resolve, reject)
|
||||||
})
|
})
|
||||||
|
|
|
@ -3,6 +3,7 @@ import * as cp from "child_process"
|
||||||
import { promises as fs } from "fs"
|
import { promises as fs } from "fs"
|
||||||
import * as path from "path"
|
import * as path from "path"
|
||||||
import { Page } from "playwright"
|
import { Page } from "playwright"
|
||||||
|
import { logError } from "../../../src/common/util"
|
||||||
import { onLine } from "../../../src/node/util"
|
import { onLine } from "../../../src/node/util"
|
||||||
import { PASSWORD, workspaceDir } from "../../utils/constants"
|
import { PASSWORD, workspaceDir } from "../../utils/constants"
|
||||||
import { idleTimer, tmpdir } from "../../utils/helpers"
|
import { idleTimer, tmpdir } from "../../utils/helpers"
|
||||||
|
@ -51,9 +52,9 @@ export class CodeServer {
|
||||||
*/
|
*/
|
||||||
private async createWorkspace(): Promise<string> {
|
private async createWorkspace(): Promise<string> {
|
||||||
const dir = await tmpdir(workspaceDir)
|
const dir = await tmpdir(workspaceDir)
|
||||||
await fs.mkdir(path.join(dir, ".vscode"))
|
await fs.mkdir(path.join(dir, "User"))
|
||||||
await fs.writeFile(
|
await fs.writeFile(
|
||||||
path.join(dir, ".vscode/settings.json"),
|
path.join(dir, "User/settings.json"),
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
"workbench.startupEditor": "none",
|
"workbench.startupEditor": "none",
|
||||||
}),
|
}),
|
||||||
|
@ -129,7 +130,7 @@ export class CodeServer {
|
||||||
if (resolved) {
|
if (resolved) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const match = line.trim().match(/HTTP server listening on (https?:\/\/[.:\d]+)\/?$/)
|
const match = line.trim().match(/HTTPS? server listening on (https?:\/\/[.:\d]+)\/?$/)
|
||||||
if (match) {
|
if (match) {
|
||||||
// Cookies don't seem to work on IP address so swap to localhost.
|
// Cookies don't seem to work on IP address so swap to localhost.
|
||||||
// TODO: Investigate whether this is a bug with code-server.
|
// TODO: Investigate whether this is a bug with code-server.
|
||||||
|
|
|
@ -45,7 +45,6 @@ describe("createApp", () => {
|
||||||
it("should return an Express app, a WebSockets Express app and an http server", async () => {
|
it("should return an Express app, a WebSockets Express app and an http server", async () => {
|
||||||
const defaultArgs = await setDefaults({
|
const defaultArgs = await setDefaults({
|
||||||
port,
|
port,
|
||||||
_: [],
|
|
||||||
})
|
})
|
||||||
const app = await createApp(defaultArgs)
|
const app = await createApp(defaultArgs)
|
||||||
|
|
||||||
|
@ -62,7 +61,6 @@ describe("createApp", () => {
|
||||||
it("should handle error events on the server", async () => {
|
it("should handle error events on the server", async () => {
|
||||||
const defaultArgs = await setDefaults({
|
const defaultArgs = await setDefaults({
|
||||||
port,
|
port,
|
||||||
_: [],
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const app = await createApp(defaultArgs)
|
const app = await createApp(defaultArgs)
|
||||||
|
@ -85,7 +83,6 @@ describe("createApp", () => {
|
||||||
const port = 2
|
const port = 2
|
||||||
const defaultArgs = await setDefaults({
|
const defaultArgs = await setDefaults({
|
||||||
port,
|
port,
|
||||||
_: [],
|
|
||||||
})
|
})
|
||||||
|
|
||||||
async function masterBall() {
|
async function masterBall() {
|
||||||
|
@ -105,7 +102,6 @@ describe("createApp", () => {
|
||||||
it("should unlink a socket before listening on the socket", async () => {
|
it("should unlink a socket before listening on the socket", async () => {
|
||||||
await promises.writeFile(tmpFilePath, "")
|
await promises.writeFile(tmpFilePath, "")
|
||||||
const defaultArgs = await setDefaults({
|
const defaultArgs = await setDefaults({
|
||||||
_: [],
|
|
||||||
socket: tmpFilePath,
|
socket: tmpFilePath,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -121,7 +117,6 @@ describe("createApp", () => {
|
||||||
const defaultArgs = await setDefaults({
|
const defaultArgs = await setDefaults({
|
||||||
port,
|
port,
|
||||||
cert,
|
cert,
|
||||||
_: [],
|
|
||||||
["cert-key"]: testCertificate.certKey,
|
["cert-key"]: testCertificate.certKey,
|
||||||
})
|
})
|
||||||
const app = await createApp(defaultArgs)
|
const app = await createApp(defaultArgs)
|
||||||
|
|
|
@ -4,23 +4,19 @@ import * as net from "net"
|
||||||
import * as os from "os"
|
import * as os from "os"
|
||||||
import * as path from "path"
|
import * as path from "path"
|
||||||
import {
|
import {
|
||||||
Args,
|
UserProvidedArgs,
|
||||||
bindAddrFromArgs,
|
bindAddrFromArgs,
|
||||||
defaultConfigFile,
|
defaultConfigFile,
|
||||||
parse,
|
parse,
|
||||||
|
readSocketPath,
|
||||||
setDefaults,
|
setDefaults,
|
||||||
shouldOpenInExistingInstance,
|
shouldOpenInExistingInstance,
|
||||||
splitOnFirstEquals,
|
splitOnFirstEquals,
|
||||||
readSocketPath,
|
|
||||||
} from "../../../src/node/cli"
|
} from "../../../src/node/cli"
|
||||||
import { shouldSpawnCliProcess } from "../../../src/node/main"
|
import { shouldSpawnCliProcess } from "../../../src/node/main"
|
||||||
import { generatePassword, paths } from "../../../src/node/util"
|
import { generatePassword, paths } from "../../../src/node/util"
|
||||||
import { useEnv, tmpdir } from "../../utils/helpers"
|
import { useEnv, tmpdir } from "../../utils/helpers"
|
||||||
|
|
||||||
type Mutable<T> = {
|
|
||||||
-readonly [P in keyof T]: T[P]
|
|
||||||
}
|
|
||||||
|
|
||||||
describe("parser", () => {
|
describe("parser", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
delete process.env.LOG_LEVEL
|
delete process.env.LOG_LEVEL
|
||||||
|
@ -40,66 +36,71 @@ describe("parser", () => {
|
||||||
usingEnvHashedPassword: false,
|
usingEnvHashedPassword: false,
|
||||||
"extensions-dir": path.join(paths.data, "extensions"),
|
"extensions-dir": path.join(paths.data, "extensions"),
|
||||||
"user-data-dir": paths.data,
|
"user-data-dir": paths.data,
|
||||||
|
_: [],
|
||||||
|
workspace: "",
|
||||||
|
folder: "",
|
||||||
}
|
}
|
||||||
|
|
||||||
it("should parse nothing", () => {
|
it("should parse nothing", async () => {
|
||||||
expect(parse([])).toStrictEqual({ _: [] })
|
expect(parse([])).toStrictEqual({})
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should parse all available options", () => {
|
it("should parse all available options", async () => {
|
||||||
expect(
|
expect(
|
||||||
parse([
|
parse(
|
||||||
"--enable",
|
[
|
||||||
"feature1",
|
["--enable", "feature1"],
|
||||||
"--enable",
|
["--enable", "feature2"],
|
||||||
"feature2",
|
|
||||||
"--bind-addr=192.169.0.1:8080",
|
"--bind-addr=192.169.0.1:8080",
|
||||||
"--auth",
|
|
||||||
"none",
|
["--auth", "none"],
|
||||||
"--extensions-dir",
|
|
||||||
"foo",
|
["--extensions-dir", "path/to/ext/dir"],
|
||||||
"--builtin-extensions-dir",
|
|
||||||
"foobar",
|
["--builtin-extensions-dir", "path/to/builtin/ext/dir"],
|
||||||
"--extra-extensions-dir",
|
|
||||||
"nozzle",
|
|
||||||
"1",
|
"1",
|
||||||
"--extra-builtin-extensions-dir",
|
|
||||||
"bazzle",
|
|
||||||
"--verbose",
|
"--verbose",
|
||||||
"2",
|
"2",
|
||||||
"--log",
|
|
||||||
"error",
|
["--log", "error"],
|
||||||
|
|
||||||
"--help",
|
"--help",
|
||||||
|
|
||||||
"--open",
|
"--open",
|
||||||
|
|
||||||
"--socket=mumble",
|
"--socket=mumble",
|
||||||
|
|
||||||
"3",
|
"3",
|
||||||
"--user-data-dir",
|
|
||||||
"bar",
|
["--user-data-dir", "path/to/user/dir"],
|
||||||
"--cert=baz",
|
|
||||||
"--cert-key",
|
["--cert=path/to/cert", "--cert-key", "path/to/cert/key"],
|
||||||
"qux",
|
|
||||||
"--version",
|
"--version",
|
||||||
|
|
||||||
"--json",
|
"--json",
|
||||||
|
|
||||||
"--port=8081",
|
"--port=8081",
|
||||||
"--host",
|
|
||||||
"0.0.0.0",
|
["--host", "0.0.0.0"],
|
||||||
"4",
|
"4",
|
||||||
"--",
|
"--",
|
||||||
"-5",
|
"--5",
|
||||||
"--6",
|
].flat(),
|
||||||
]),
|
),
|
||||||
).toEqual({
|
).toEqual({
|
||||||
_: ["1", "2", "3", "4", "-5", "--6"],
|
_: ["1", "2", "3", "4", "--5"],
|
||||||
auth: "none",
|
auth: "none",
|
||||||
"builtin-extensions-dir": path.resolve("foobar"),
|
"builtin-extensions-dir": path.resolve("path/to/builtin/ext/dir"),
|
||||||
"cert-key": path.resolve("qux"),
|
"extensions-dir": path.resolve("path/to/ext/dir"),
|
||||||
|
"user-data-dir": path.resolve("path/to/user/dir"),
|
||||||
|
"cert-key": path.resolve("path/to/cert/key"),
|
||||||
cert: {
|
cert: {
|
||||||
value: path.resolve("baz"),
|
value: path.resolve("path/to/cert"),
|
||||||
},
|
},
|
||||||
enable: ["feature1", "feature2"],
|
enable: ["feature1", "feature2"],
|
||||||
"extensions-dir": path.resolve("foo"),
|
|
||||||
"extra-builtin-extensions-dir": [path.resolve("bazzle")],
|
|
||||||
"extra-extensions-dir": [path.resolve("nozzle")],
|
|
||||||
help: true,
|
help: true,
|
||||||
host: "0.0.0.0",
|
host: "0.0.0.0",
|
||||||
json: true,
|
json: true,
|
||||||
|
@ -107,16 +108,14 @@ describe("parser", () => {
|
||||||
open: true,
|
open: true,
|
||||||
port: 8081,
|
port: 8081,
|
||||||
socket: path.resolve("mumble"),
|
socket: path.resolve("mumble"),
|
||||||
"user-data-dir": path.resolve("bar"),
|
|
||||||
verbose: true,
|
verbose: true,
|
||||||
version: true,
|
version: true,
|
||||||
"bind-addr": "192.169.0.1:8080",
|
"bind-addr": "192.169.0.1:8080",
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should work with short options", () => {
|
it("should work with short options", async () => {
|
||||||
expect(parse(["-vvv", "-v"])).toEqual({
|
expect(parse(["-vvv", "-v"])).toEqual({
|
||||||
_: [],
|
|
||||||
verbose: true,
|
verbose: true,
|
||||||
version: true,
|
version: true,
|
||||||
})
|
})
|
||||||
|
@ -124,13 +123,12 @@ describe("parser", () => {
|
||||||
|
|
||||||
it("should use log level env var", async () => {
|
it("should use log level env var", async () => {
|
||||||
const args = parse([])
|
const args = parse([])
|
||||||
expect(args).toEqual({ _: [] })
|
expect(args).toEqual({})
|
||||||
|
|
||||||
process.env.LOG_LEVEL = "debug"
|
process.env.LOG_LEVEL = "debug"
|
||||||
const defaults = await setDefaults(args)
|
const defaults = await setDefaults(args)
|
||||||
expect(defaults).toStrictEqual({
|
expect(defaults).toStrictEqual({
|
||||||
...defaults,
|
...defaults,
|
||||||
_: [],
|
|
||||||
log: "debug",
|
log: "debug",
|
||||||
verbose: false,
|
verbose: false,
|
||||||
})
|
})
|
||||||
|
@ -141,7 +139,6 @@ describe("parser", () => {
|
||||||
const updated = await setDefaults(args)
|
const updated = await setDefaults(args)
|
||||||
expect(updated).toStrictEqual({
|
expect(updated).toStrictEqual({
|
||||||
...updated,
|
...updated,
|
||||||
_: [],
|
|
||||||
log: "trace",
|
log: "trace",
|
||||||
verbose: true,
|
verbose: true,
|
||||||
})
|
})
|
||||||
|
@ -152,7 +149,6 @@ describe("parser", () => {
|
||||||
it("should prefer --log to env var and --verbose to --log", async () => {
|
it("should prefer --log to env var and --verbose to --log", async () => {
|
||||||
let args = parse(["--log", "info"])
|
let args = parse(["--log", "info"])
|
||||||
expect(args).toEqual({
|
expect(args).toEqual({
|
||||||
_: [],
|
|
||||||
log: "info",
|
log: "info",
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -160,7 +156,6 @@ describe("parser", () => {
|
||||||
const defaults = await setDefaults(args)
|
const defaults = await setDefaults(args)
|
||||||
expect(defaults).toEqual({
|
expect(defaults).toEqual({
|
||||||
...defaults,
|
...defaults,
|
||||||
_: [],
|
|
||||||
log: "info",
|
log: "info",
|
||||||
verbose: false,
|
verbose: false,
|
||||||
})
|
})
|
||||||
|
@ -171,7 +166,6 @@ describe("parser", () => {
|
||||||
const updated = await setDefaults(args)
|
const updated = await setDefaults(args)
|
||||||
expect(updated).toEqual({
|
expect(updated).toEqual({
|
||||||
...defaults,
|
...defaults,
|
||||||
_: [],
|
|
||||||
log: "info",
|
log: "info",
|
||||||
verbose: false,
|
verbose: false,
|
||||||
})
|
})
|
||||||
|
@ -180,7 +174,6 @@ describe("parser", () => {
|
||||||
|
|
||||||
args = parse(["--log", "info", "--verbose"])
|
args = parse(["--log", "info", "--verbose"])
|
||||||
expect(args).toEqual({
|
expect(args).toEqual({
|
||||||
_: [],
|
|
||||||
log: "info",
|
log: "info",
|
||||||
verbose: true,
|
verbose: true,
|
||||||
})
|
})
|
||||||
|
@ -189,7 +182,6 @@ describe("parser", () => {
|
||||||
const updatedAgain = await setDefaults(args)
|
const updatedAgain = await setDefaults(args)
|
||||||
expect(updatedAgain).toEqual({
|
expect(updatedAgain).toEqual({
|
||||||
...defaults,
|
...defaults,
|
||||||
_: [],
|
|
||||||
log: "trace",
|
log: "trace",
|
||||||
verbose: true,
|
verbose: true,
|
||||||
})
|
})
|
||||||
|
@ -202,7 +194,6 @@ describe("parser", () => {
|
||||||
const defaults = await setDefaults(parse([]))
|
const defaults = await setDefaults(parse([]))
|
||||||
expect(defaults).toEqual({
|
expect(defaults).toEqual({
|
||||||
...defaults,
|
...defaults,
|
||||||
_: [],
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -224,9 +215,8 @@ describe("parser", () => {
|
||||||
expect(() => parse(["--foo"])).toThrowError(/Unknown option --foo/)
|
expect(() => parse(["--foo"])).toThrowError(/Unknown option --foo/)
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should not error if the value is optional", () => {
|
it("should not error if the value is optional", async () => {
|
||||||
expect(parse(["--cert"])).toEqual({
|
expect(parse(["--cert"])).toEqual({
|
||||||
_: [],
|
|
||||||
cert: {
|
cert: {
|
||||||
value: undefined,
|
value: undefined,
|
||||||
},
|
},
|
||||||
|
@ -237,26 +227,23 @@ describe("parser", () => {
|
||||||
expect(() => parse(["--socket", "--socket-path-value"])).toThrowError(/--socket requires a value/)
|
expect(() => parse(["--socket", "--socket-path-value"])).toThrowError(/--socket requires a value/)
|
||||||
// If you actually had a path like this you would do this instead:
|
// If you actually had a path like this you would do this instead:
|
||||||
expect(parse(["--socket", "./--socket-path-value"])).toEqual({
|
expect(parse(["--socket", "./--socket-path-value"])).toEqual({
|
||||||
_: [],
|
|
||||||
socket: path.resolve("--socket-path-value"),
|
socket: path.resolve("--socket-path-value"),
|
||||||
})
|
})
|
||||||
expect(() => parse(["--cert", "--socket-path-value"])).toThrowError(/Unknown option --socket-path-value/)
|
expect(() => parse(["--cert", "--socket-path-value"])).toThrowError(/Unknown option --socket-path-value/)
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should allow positional arguments before options", () => {
|
it("should allow positional arguments before options", async () => {
|
||||||
expect(parse(["foo", "test", "--auth", "none"])).toEqual({
|
expect(parse(["test", "--auth", "none"])).toEqual({
|
||||||
_: ["foo", "test"],
|
_: ["test"],
|
||||||
auth: "none",
|
auth: "none",
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should support repeatable flags", () => {
|
it("should support repeatable flags", async () => {
|
||||||
expect(parse(["--proxy-domain", "*.coder.com"])).toEqual({
|
expect(parse(["--proxy-domain", "*.coder.com"])).toEqual({
|
||||||
_: [],
|
|
||||||
"proxy-domain": ["*.coder.com"],
|
"proxy-domain": ["*.coder.com"],
|
||||||
})
|
})
|
||||||
expect(parse(["--proxy-domain", "*.coder.com", "--proxy-domain", "test.com"])).toEqual({
|
expect(parse(["--proxy-domain", "*.coder.com", "--proxy-domain", "test.com"])).toEqual({
|
||||||
_: [],
|
|
||||||
"proxy-domain": ["*.coder.com", "test.com"],
|
"proxy-domain": ["*.coder.com", "test.com"],
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -264,7 +251,6 @@ describe("parser", () => {
|
||||||
it("should enforce cert-key with cert value or otherwise generate one", async () => {
|
it("should enforce cert-key with cert value or otherwise generate one", async () => {
|
||||||
const args = parse(["--cert"])
|
const args = parse(["--cert"])
|
||||||
expect(args).toEqual({
|
expect(args).toEqual({
|
||||||
_: [],
|
|
||||||
cert: {
|
cert: {
|
||||||
value: undefined,
|
value: undefined,
|
||||||
},
|
},
|
||||||
|
@ -272,7 +258,6 @@ describe("parser", () => {
|
||||||
expect(() => parse(["--cert", "test"])).toThrowError(/--cert-key is missing/)
|
expect(() => parse(["--cert", "test"])).toThrowError(/--cert-key is missing/)
|
||||||
const defaultArgs = await setDefaults(args)
|
const defaultArgs = await setDefaults(args)
|
||||||
expect(defaultArgs).toEqual({
|
expect(defaultArgs).toEqual({
|
||||||
_: [],
|
|
||||||
...defaults,
|
...defaults,
|
||||||
cert: {
|
cert: {
|
||||||
value: path.join(paths.data, "localhost.crt"),
|
value: path.join(paths.data, "localhost.crt"),
|
||||||
|
@ -285,7 +270,6 @@ describe("parser", () => {
|
||||||
const args = parse("--cert test --cert-key test --socket test --host 0.0.0.0 --port 8888 --link test".split(" "))
|
const args = parse("--cert test --cert-key test --socket test --host 0.0.0.0 --port 8888 --link test".split(" "))
|
||||||
const defaultArgs = await setDefaults(args)
|
const defaultArgs = await setDefaults(args)
|
||||||
expect(defaultArgs).toEqual({
|
expect(defaultArgs).toEqual({
|
||||||
_: [],
|
|
||||||
...defaults,
|
...defaults,
|
||||||
auth: "none",
|
auth: "none",
|
||||||
host: "localhost",
|
host: "localhost",
|
||||||
|
@ -302,14 +286,11 @@ describe("parser", () => {
|
||||||
it("should use env var password", async () => {
|
it("should use env var password", async () => {
|
||||||
process.env.PASSWORD = "test"
|
process.env.PASSWORD = "test"
|
||||||
const args = parse([])
|
const args = parse([])
|
||||||
expect(args).toEqual({
|
expect(args).toEqual({})
|
||||||
_: [],
|
|
||||||
})
|
|
||||||
|
|
||||||
const defaultArgs = await setDefaults(args)
|
const defaultArgs = await setDefaults(args)
|
||||||
expect(defaultArgs).toEqual({
|
expect(defaultArgs).toEqual({
|
||||||
...defaults,
|
...defaults,
|
||||||
_: [],
|
|
||||||
password: "test",
|
password: "test",
|
||||||
usingEnvPassword: true,
|
usingEnvPassword: true,
|
||||||
})
|
})
|
||||||
|
@ -319,14 +300,11 @@ describe("parser", () => {
|
||||||
process.env.HASHED_PASSWORD =
|
process.env.HASHED_PASSWORD =
|
||||||
"$argon2i$v=19$m=4096,t=3,p=1$0qR/o+0t00hsbJFQCKSfdQ$oFcM4rL6o+B7oxpuA4qlXubypbBPsf+8L531U7P9HYY" // test
|
"$argon2i$v=19$m=4096,t=3,p=1$0qR/o+0t00hsbJFQCKSfdQ$oFcM4rL6o+B7oxpuA4qlXubypbBPsf+8L531U7P9HYY" // test
|
||||||
const args = parse([])
|
const args = parse([])
|
||||||
expect(args).toEqual({
|
expect(args).toEqual({})
|
||||||
_: [],
|
|
||||||
})
|
|
||||||
|
|
||||||
const defaultArgs = await setDefaults(args)
|
const defaultArgs = await setDefaults(args)
|
||||||
expect(defaultArgs).toEqual({
|
expect(defaultArgs).toEqual({
|
||||||
...defaults,
|
...defaults,
|
||||||
_: [],
|
|
||||||
"hashed-password":
|
"hashed-password":
|
||||||
"$argon2i$v=19$m=4096,t=3,p=1$0qR/o+0t00hsbJFQCKSfdQ$oFcM4rL6o+B7oxpuA4qlXubypbBPsf+8L531U7P9HYY",
|
"$argon2i$v=19$m=4096,t=3,p=1$0qR/o+0t00hsbJFQCKSfdQ$oFcM4rL6o+B7oxpuA4qlXubypbBPsf+8L531U7P9HYY",
|
||||||
usingEnvHashedPassword: true,
|
usingEnvHashedPassword: true,
|
||||||
|
@ -348,27 +326,23 @@ describe("parser", () => {
|
||||||
it("should filter proxy domains", async () => {
|
it("should filter proxy domains", async () => {
|
||||||
const args = parse(["--proxy-domain", "*.coder.com", "--proxy-domain", "coder.com", "--proxy-domain", "coder.org"])
|
const args = parse(["--proxy-domain", "*.coder.com", "--proxy-domain", "coder.com", "--proxy-domain", "coder.org"])
|
||||||
expect(args).toEqual({
|
expect(args).toEqual({
|
||||||
_: [],
|
|
||||||
"proxy-domain": ["*.coder.com", "coder.com", "coder.org"],
|
"proxy-domain": ["*.coder.com", "coder.com", "coder.org"],
|
||||||
})
|
})
|
||||||
|
|
||||||
const defaultArgs = await setDefaults(args)
|
const defaultArgs = await setDefaults(args)
|
||||||
expect(defaultArgs).toEqual({
|
expect(defaultArgs).toEqual({
|
||||||
...defaults,
|
...defaults,
|
||||||
_: [],
|
|
||||||
"proxy-domain": ["coder.com", "coder.org"],
|
"proxy-domain": ["coder.com", "coder.org"],
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
it("should allow '=,$/' in strings", async () => {
|
it("should allow '=,$/' in strings", async () => {
|
||||||
const args = parse([
|
const args = parse([
|
||||||
"--enable-proposed-api",
|
"--disable-update-check",
|
||||||
"$argon2i$v=19$m=4096,t=3,p=1$0qr/o+0t00hsbjfqcksfdq$ofcm4rl6o+b7oxpua4qlxubypbbpsf+8l531u7p9hyy",
|
"$argon2i$v=19$m=4096,t=3,p=1$0qr/o+0t00hsbjfqcksfdq$ofcm4rl6o+b7oxpua4qlxubypbbpsf+8l531u7p9hyy",
|
||||||
])
|
])
|
||||||
expect(args).toEqual({
|
expect(args).toEqual({
|
||||||
_: [],
|
"disable-update-check": true,
|
||||||
"enable-proposed-api": [
|
_: ["$argon2i$v=19$m=4096,t=3,p=1$0qr/o+0t00hsbjfqcksfdq$ofcm4rl6o+b7oxpua4qlxubypbbpsf+8l531u7p9hyy"],
|
||||||
"$argon2i$v=19$m=4096,t=3,p=1$0qr/o+0t00hsbjfqcksfdq$ofcm4rl6o+b7oxpua4qlxubypbbpsf+8l531u7p9hyy",
|
|
||||||
],
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
it("should parse options with double-dash and multiple equal signs ", async () => {
|
it("should parse options with double-dash and multiple equal signs ", async () => {
|
||||||
|
@ -381,7 +355,6 @@ describe("parser", () => {
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
expect(args).toEqual({
|
expect(args).toEqual({
|
||||||
_: [],
|
|
||||||
"hashed-password":
|
"hashed-password":
|
||||||
"$argon2i$v=19$m=4096,t=3,p=1$0qr/o+0t00hsbjfqcksfdq$ofcm4rl6o+b7oxpua4qlxubypbbpsf+8l531u7p9hyy",
|
"$argon2i$v=19$m=4096,t=3,p=1$0qr/o+0t00hsbjfqcksfdq$ofcm4rl6o+b7oxpua4qlxubypbbpsf+8l531u7p9hyy",
|
||||||
})
|
})
|
||||||
|
@ -389,7 +362,6 @@ describe("parser", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("cli", () => {
|
describe("cli", () => {
|
||||||
let args: Mutable<Args> = { _: [] }
|
|
||||||
let testDir: string
|
let testDir: string
|
||||||
const vscodeIpcPath = path.join(os.tmpdir(), "vscode-ipc")
|
const vscodeIpcPath = path.join(os.tmpdir(), "vscode-ipc")
|
||||||
|
|
||||||
|
@ -401,20 +373,21 @@ describe("cli", () => {
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
delete process.env.VSCODE_IPC_HOOK_CLI
|
delete process.env.VSCODE_IPC_HOOK_CLI
|
||||||
args = { _: [] }
|
|
||||||
await fs.rmdir(vscodeIpcPath, { recursive: true })
|
await fs.rmdir(vscodeIpcPath, { recursive: true })
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should use existing if inside code-server", async () => {
|
it("should use existing if inside code-server", async () => {
|
||||||
process.env.VSCODE_IPC_HOOK_CLI = "test"
|
process.env.VSCODE_IPC_HOOK_CLI = "test"
|
||||||
|
const args: UserProvidedArgs = {}
|
||||||
expect(await shouldOpenInExistingInstance(args)).toStrictEqual("test")
|
expect(await shouldOpenInExistingInstance(args)).toStrictEqual("test")
|
||||||
|
|
||||||
args.port = 8081
|
args.port = 8081
|
||||||
args._.push("./file")
|
args._ = ["./file"]
|
||||||
expect(await shouldOpenInExistingInstance(args)).toStrictEqual("test")
|
expect(await shouldOpenInExistingInstance(args)).toStrictEqual("test")
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should use existing if --reuse-window is set", async () => {
|
it("should use existing if --reuse-window is set", async () => {
|
||||||
|
const args: UserProvidedArgs = {}
|
||||||
args["reuse-window"] = true
|
args["reuse-window"] = true
|
||||||
await expect(shouldOpenInExistingInstance(args)).resolves.toStrictEqual(undefined)
|
await expect(shouldOpenInExistingInstance(args)).resolves.toStrictEqual(undefined)
|
||||||
|
|
||||||
|
@ -426,6 +399,7 @@ describe("cli", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should use existing if --new-window is set", async () => {
|
it("should use existing if --new-window is set", async () => {
|
||||||
|
const args: UserProvidedArgs = {}
|
||||||
args["new-window"] = true
|
args["new-window"] = true
|
||||||
expect(await shouldOpenInExistingInstance(args)).toStrictEqual(undefined)
|
expect(await shouldOpenInExistingInstance(args)).toStrictEqual(undefined)
|
||||||
|
|
||||||
|
@ -437,9 +411,10 @@ describe("cli", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should use existing if no unrelated flags are set, has positional, and socket is active", async () => {
|
it("should use existing if no unrelated flags are set, has positional, and socket is active", async () => {
|
||||||
|
const args: UserProvidedArgs = {}
|
||||||
expect(await shouldOpenInExistingInstance(args)).toStrictEqual(undefined)
|
expect(await shouldOpenInExistingInstance(args)).toStrictEqual(undefined)
|
||||||
|
|
||||||
args._.push("./file")
|
args._ = ["./file"]
|
||||||
expect(await shouldOpenInExistingInstance(args)).toStrictEqual(undefined)
|
expect(await shouldOpenInExistingInstance(args)).toStrictEqual(undefined)
|
||||||
|
|
||||||
const socketPath = path.join(testDir, "socket")
|
const socketPath = path.join(testDir, "socket")
|
||||||
|
@ -489,9 +464,7 @@ describe("splitOnFirstEquals", () => {
|
||||||
|
|
||||||
describe("shouldSpawnCliProcess", () => {
|
describe("shouldSpawnCliProcess", () => {
|
||||||
it("should return false if no 'extension' related args passed in", async () => {
|
it("should return false if no 'extension' related args passed in", async () => {
|
||||||
const args = {
|
const args = {}
|
||||||
_: [],
|
|
||||||
}
|
|
||||||
const actual = await shouldSpawnCliProcess(args)
|
const actual = await shouldSpawnCliProcess(args)
|
||||||
const expected = false
|
const expected = false
|
||||||
|
|
||||||
|
@ -500,7 +473,6 @@ describe("shouldSpawnCliProcess", () => {
|
||||||
|
|
||||||
it("should return true if 'list-extensions' passed in", async () => {
|
it("should return true if 'list-extensions' passed in", async () => {
|
||||||
const args = {
|
const args = {
|
||||||
_: [],
|
|
||||||
["list-extensions"]: true,
|
["list-extensions"]: true,
|
||||||
}
|
}
|
||||||
const actual = await shouldSpawnCliProcess(args)
|
const actual = await shouldSpawnCliProcess(args)
|
||||||
|
@ -511,7 +483,6 @@ describe("shouldSpawnCliProcess", () => {
|
||||||
|
|
||||||
it("should return true if 'install-extension' passed in", async () => {
|
it("should return true if 'install-extension' passed in", async () => {
|
||||||
const args = {
|
const args = {
|
||||||
_: [],
|
|
||||||
["install-extension"]: ["hello.world"],
|
["install-extension"]: ["hello.world"],
|
||||||
}
|
}
|
||||||
const actual = await shouldSpawnCliProcess(args)
|
const actual = await shouldSpawnCliProcess(args)
|
||||||
|
@ -521,8 +492,7 @@ describe("shouldSpawnCliProcess", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should return true if 'uninstall-extension' passed in", async () => {
|
it("should return true if 'uninstall-extension' passed in", async () => {
|
||||||
const args = {
|
const args: UserProvidedArgs = {
|
||||||
_: [],
|
|
||||||
["uninstall-extension"]: ["hello.world"],
|
["uninstall-extension"]: ["hello.world"],
|
||||||
}
|
}
|
||||||
const actual = await shouldSpawnCliProcess(args)
|
const actual = await shouldSpawnCliProcess(args)
|
||||||
|
@ -534,9 +504,7 @@ describe("shouldSpawnCliProcess", () => {
|
||||||
|
|
||||||
describe("bindAddrFromArgs", () => {
|
describe("bindAddrFromArgs", () => {
|
||||||
it("should return the bind address", () => {
|
it("should return the bind address", () => {
|
||||||
const args = {
|
const args: UserProvidedArgs = {}
|
||||||
_: [],
|
|
||||||
}
|
|
||||||
|
|
||||||
const addr = {
|
const addr = {
|
||||||
host: "localhost",
|
host: "localhost",
|
||||||
|
@ -550,8 +518,7 @@ describe("bindAddrFromArgs", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should use the bind-address if set in args", () => {
|
it("should use the bind-address if set in args", () => {
|
||||||
const args = {
|
const args: UserProvidedArgs = {
|
||||||
_: [],
|
|
||||||
["bind-addr"]: "localhost:3000",
|
["bind-addr"]: "localhost:3000",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -570,8 +537,7 @@ describe("bindAddrFromArgs", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should use the host if set in args", () => {
|
it("should use the host if set in args", () => {
|
||||||
const args = {
|
const args: UserProvidedArgs = {
|
||||||
_: [],
|
|
||||||
["host"]: "coder",
|
["host"]: "coder",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -593,9 +559,7 @@ describe("bindAddrFromArgs", () => {
|
||||||
const [setValue, resetValue] = useEnv("PORT")
|
const [setValue, resetValue] = useEnv("PORT")
|
||||||
setValue("8000")
|
setValue("8000")
|
||||||
|
|
||||||
const args = {
|
const args: UserProvidedArgs = {}
|
||||||
_: [],
|
|
||||||
}
|
|
||||||
|
|
||||||
const addr = {
|
const addr = {
|
||||||
host: "localhost",
|
host: "localhost",
|
||||||
|
@ -613,8 +577,7 @@ describe("bindAddrFromArgs", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should set port if in args", () => {
|
it("should set port if in args", () => {
|
||||||
const args = {
|
const args: UserProvidedArgs = {
|
||||||
_: [],
|
|
||||||
port: 3000,
|
port: 3000,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -636,8 +599,7 @@ describe("bindAddrFromArgs", () => {
|
||||||
const [setValue, resetValue] = useEnv("PORT")
|
const [setValue, resetValue] = useEnv("PORT")
|
||||||
setValue("8000")
|
setValue("8000")
|
||||||
|
|
||||||
const args = {
|
const args: UserProvidedArgs = {
|
||||||
_: [],
|
|
||||||
port: 3000,
|
port: 3000,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,8 @@ describe("plugin", () => {
|
||||||
usingEnvHashedPassword: false,
|
usingEnvHashedPassword: false,
|
||||||
"extensions-dir": "",
|
"extensions-dir": "",
|
||||||
"user-data-dir": "",
|
"user-data-dir": "",
|
||||||
|
workspace: "",
|
||||||
|
folder: "",
|
||||||
}
|
}
|
||||||
next()
|
next()
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,6 @@
|
||||||
"postinstall": "./postinstall.sh"
|
"postinstall": "./postinstall.sh"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"code-oss-dev": "cdr/vscode#3fc885904886003d88d1f300d6158bee486f644f"
|
"code-oss-dev": "cdr/vscode#d62e8db202f80db7a42233cd56d04e6806109fb1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -296,9 +296,9 @@ clone-response@^1.0.2:
|
||||||
dependencies:
|
dependencies:
|
||||||
mimic-response "^1.0.0"
|
mimic-response "^1.0.0"
|
||||||
|
|
||||||
code-oss-dev@cdr/vscode#3fc885904886003d88d1f300d6158bee486f644f:
|
code-oss-dev@cdr/vscode#d62e8db202f80db7a42233cd56d04e6806109fb1:
|
||||||
version "1.61.1"
|
version "1.61.1"
|
||||||
resolved "https://codeload.github.com/cdr/vscode/tar.gz/3fc885904886003d88d1f300d6158bee486f644f"
|
resolved "https://codeload.github.com/cdr/vscode/tar.gz/d62e8db202f80db7a42233cd56d04e6806109fb1"
|
||||||
dependencies:
|
dependencies:
|
||||||
"@microsoft/applicationinsights-web" "^2.6.4"
|
"@microsoft/applicationinsights-web" "^2.6.4"
|
||||||
"@vscode/sqlite3" "4.0.12"
|
"@vscode/sqlite3" "4.0.12"
|
||||||
|
|
Loading…
Reference in New Issue