From d1e36ddb3cf682e7722cd1cbf6e3adc7cb3efd85 Mon Sep 17 00:00:00 2001 From: Joe Previte Date: Mon, 4 Oct 2021 16:18:42 -0700 Subject: [PATCH 01/39] fix(testing): revert change & fix playwright tests From 53743afbd0ea560f6d5573152df196bd88ce613e Mon Sep 17 00:00:00 2001 From: Joe Previte Date: Tue, 5 Oct 2021 14:24:05 -0700 Subject: [PATCH 02/39] fix(constants): add type to import statement --- src/node/constants.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/node/constants.ts b/src/node/constants.ts index 8b46a986449b..343457a54256 100644 --- a/src/node/constants.ts +++ b/src/node/constants.ts @@ -1,5 +1,5 @@ import { logger } from "@coder/logger" -import { JSONSchemaForNPMPackageJsonFiles } from "@schemastore/package" +import type { JSONSchemaForNPMPackageJsonFiles } from "@schemastore/package" import * as os from "os" import * as path from "path" From 1e649202533c5b10cb7cbe6371f00ecffb4ce58e Mon Sep 17 00:00:00 2001 From: Joe Previte Date: Wed, 6 Oct 2021 11:32:48 -0700 Subject: [PATCH 03/39] refactor(e2e): delete browser test This test was originally added to ensure playwright was working. At this point, we know it works so removing this test because it doesn't help with anything specific to code-server and only adds unnecessary code to the codebase plus increases the e2e test job duration. --- test/e2e/browser.test.ts | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 test/e2e/browser.test.ts diff --git a/test/e2e/browser.test.ts b/test/e2e/browser.test.ts deleted file mode 100644 index fab3ac8a2de3..000000000000 --- a/test/e2e/browser.test.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { describe, test, expect } from "./baseFixture" - -// This is a "gut-check" test to make sure playwright is working as expected -describe("browser", true, () => { - test("browser should display correct userAgent", async ({ codeServerPage, browserName }) => { - const displayNames = { - chromium: "Chrome", - firefox: "Firefox", - webkit: "Safari", - } - const userAgent = await codeServerPage.page.evaluate(() => navigator.userAgent) - - expect(userAgent).toContain(displayNames[browserName]) - }) -}) From 35381c07492527598a41575533c68d91e3ce8a49 Mon Sep 17 00:00:00 2001 From: Joe Previte Date: Thu, 7 Oct 2021 12:26:33 -0700 Subject: [PATCH 04/39] chore(e2e): use 1 worker for e2e test I don't know if it's a resources issue, playwright, or code-server but it seems like the e2e tests choke when multiple workers are used. This change is okay because our CI runner only has 2 cores so it would only use 1 worker anyway, but by specifying it in our playwright config, we ensure more stability in our e2e tests working correctly. See these PRs: - https://github.com/cdr/code-server/pull/3263 - https://github.com/cdr/code-server/pull/4310 --- test/playwright.config.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/test/playwright.config.ts b/test/playwright.config.ts index 679dd33f9399..2182c324783d 100644 --- a/test/playwright.config.ts +++ b/test/playwright.config.ts @@ -7,6 +7,7 @@ const config: PlaywrightTestConfig = { testDir: path.join(__dirname, "e2e"), // Search for tests in this directory. timeout: 60000, // Each test is given 60 seconds. retries: process.env.CI ? 2 : 1, // Retry in CI due to flakiness. + workers: 1, globalSetup: require.resolve("./utils/globalSetup.ts"), reporter: "list", // Put any shared options on the top level. From 4805186768c608adf97035acea40fc54a8cff051 Mon Sep 17 00:00:00 2001 From: Joe Previte Date: Thu, 7 Oct 2021 12:29:00 -0700 Subject: [PATCH 05/39] revert(vscode): add missing route with redirect --- src/node/routes/vscode.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/node/routes/vscode.ts b/src/node/routes/vscode.ts index 4244d2ceae1d..9c072fae89c1 100644 --- a/src/node/routes/vscode.ts +++ b/src/node/routes/vscode.ts @@ -3,7 +3,7 @@ import { Server } from "http" import path from "path" import { AuthType, DefaultedArgs } from "../cli" import { version as codeServerVersion, vsRootPath } from "../constants" -import { ensureAuthenticated } from "../http" +import { ensureAuthenticated, authenticated, redirect } from "../http" import { loadAMDModule } from "../util" import { Router as WsRouter, WebsocketRouter } from "../wsRouter" import { errorHandler } from "./errors" @@ -53,6 +53,17 @@ export const createVSServerRouter = async (args: DefaultedArgs): Promise { + const isAuthenticated = await authenticated(req) + if (!isAuthenticated) { + return redirect(req, res, "login", { + // req.baseUrl can be blank if already at the root. + to: req.baseUrl && req.baseUrl !== "/" ? req.baseUrl : undefined, + }) + } + next() + }) + router.all("*", ensureAuthenticated, (req, res, next) => { req.on("error", (error) => errorHandler(error, req, res, next)) From 0b080f58423c672a710feb317067c4c83a849153 Mon Sep 17 00:00:00 2001 From: Joe Previte Date: Thu, 7 Oct 2021 12:29:38 -0700 Subject: [PATCH 06/39] chore(vscode): update to latest fork --- src/common/util.ts | 4 +++- src/node/http.ts | 13 +++++++++++-- vendor/package.json | 2 +- vendor/yarn.lock | 4 ++-- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/common/util.ts b/src/common/util.ts index 20470ad4e189..69df5b12971a 100644 --- a/src/common/util.ts +++ b/src/common/util.ts @@ -1,3 +1,5 @@ +import { ClientConfiguration } from "../node/http" + /** * Split a string up to the delimiter. If the delimiter doesn't exist the first * item will have all the text and the second item will be an empty string. @@ -53,7 +55,7 @@ export const resolveBase = (base?: string): string => { /** * Get client-side configuration embedded in the HTML or query params. */ -export const getClientConfiguration = (): T => { +export const getClientConfiguration = (): T => { let config: T try { config = JSON.parse(document.getElementById("coder-options")!.getAttribute("data-settings")!) diff --git a/src/node/http.ts b/src/node/http.ts index 8254e4abf25b..d88d8610bdd4 100644 --- a/src/node/http.ts +++ b/src/node/http.ts @@ -10,6 +10,15 @@ import { version as codeServerVersion } from "./constants" import { Heart } from "./heart" import { getPasswordMethod, IsCookieValidArgs, isCookieValid, sanitizeString, escapeHtml, escapeJSON } from "./util" +/** + * Base options included on every page. + */ +export interface ClientConfiguration { + codeServerVersion: string + base: string + csStaticBase: string +} + declare global { // eslint-disable-next-line @typescript-eslint/no-namespace namespace Express { @@ -20,7 +29,7 @@ declare global { } } -export const createClientConfiguration = (req: express.Request): CodeServerLib.ClientConfiguration => { +export const createClientConfiguration = (req: express.Request): ClientConfiguration => { const base = relativeRoot(req) return { @@ -38,7 +47,7 @@ export const replaceTemplates = ( content: string, extraOpts?: Omit, ): string => { - const serverOptions: CodeServerLib.ClientConfiguration = { + const serverOptions: ClientConfiguration = { ...createClientConfiguration(req), ...extraOpts, } diff --git a/vendor/package.json b/vendor/package.json index 1460cfe12a42..73499f2c9c9d 100644 --- a/vendor/package.json +++ b/vendor/package.json @@ -7,6 +7,6 @@ "postinstall": "./postinstall.sh" }, "devDependencies": { - "code-oss-dev": "cdr/vscode#65b2462c212d415fbf521489307e58e5b691818b" + "code-oss-dev": "cdr/vscode#f3bb8843b16719989eaa74ada0992cab87a3d4a2" } } diff --git a/vendor/yarn.lock b/vendor/yarn.lock index a0be752254b5..7460cc78b3bf 100644 --- a/vendor/yarn.lock +++ b/vendor/yarn.lock @@ -296,9 +296,9 @@ clone-response@^1.0.2: dependencies: mimic-response "^1.0.0" -code-oss-dev@cdr/vscode#65b2462c212d415fbf521489307e58e5b691818b: +code-oss-dev@cdr/vscode#f3bb8843b16719989eaa74ada0992cab87a3d4a2: version "1.60.2" - resolved "https://codeload.github.com/cdr/vscode/tar.gz/65b2462c212d415fbf521489307e58e5b691818b" + resolved "https://codeload.github.com/cdr/vscode/tar.gz/f3bb8843b16719989eaa74ada0992cab87a3d4a2" dependencies: "@microsoft/applicationinsights-web" "^2.6.4" "@vscode/sqlite3" "4.0.12" From d7e7e436e7431bbe12b6202c85aac2e04282502d Mon Sep 17 00:00:00 2001 From: Teffen Ellis Date: Fri, 15 Oct 2021 17:30:09 -0400 Subject: [PATCH 07/39] Touch up compilation step. --- ci/build/build-release.sh | 2 +- ci/build/build-vscode.sh | 8 +++----- vendor/package.json | 2 +- vendor/yarn.lock | 4 ++-- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/ci/build/build-release.sh b/ci/build/build-release.sh index f7b7df2662dc..dde13445cde3 100755 --- a/ci/build/build-release.sh +++ b/ci/build/build-release.sh @@ -68,7 +68,7 @@ EOF bundle_vscode() { mkdir -p "$VSCODE_OUT_PATH" rsync "$VSCODE_SRC_PATH/yarn.lock" "$VSCODE_OUT_PATH" - rsync "$VSCODE_SRC_PATH/out-vscode${MINIFY:+-min}/" "$VSCODE_OUT_PATH/out" + rsync "$VSCODE_SRC_PATH/out-vscode-server${MINIFY:+-min}/" "$VSCODE_OUT_PATH/out" rsync "$VSCODE_SRC_PATH/.build/extensions/" "$VSCODE_OUT_PATH/extensions" if [ "$KEEP_MODULES" = 0 ]; then diff --git a/ci/build/build-vscode.sh b/ci/build/build-vscode.sh index 91e83e7f0cdc..9dd326cd87e6 100755 --- a/ci/build/build-vscode.sh +++ b/ci/build/build-vscode.sh @@ -11,12 +11,10 @@ main() { cd vendor/modules/code-oss-dev - yarn gulp compile-build compile-extensions-build compile-extension-media compile-web - - yarn gulp optimize --gulpfile ./coder.js - if [[ $MINIFY ]]; then - yarn gulp minify --gulpfile ./coder.js + yarn compile-server + else + yarn compile-server-min fi } diff --git a/vendor/package.json b/vendor/package.json index 73499f2c9c9d..cc006b980447 100644 --- a/vendor/package.json +++ b/vendor/package.json @@ -7,6 +7,6 @@ "postinstall": "./postinstall.sh" }, "devDependencies": { - "code-oss-dev": "cdr/vscode#f3bb8843b16719989eaa74ada0992cab87a3d4a2" + "code-oss-dev": "cdr/vscode#1d4b6bef22eecd50319adf11698d6692c1064deb" } } diff --git a/vendor/yarn.lock b/vendor/yarn.lock index 7460cc78b3bf..1bec93c5f943 100644 --- a/vendor/yarn.lock +++ b/vendor/yarn.lock @@ -296,9 +296,9 @@ clone-response@^1.0.2: dependencies: mimic-response "^1.0.0" -code-oss-dev@cdr/vscode#f3bb8843b16719989eaa74ada0992cab87a3d4a2: +code-oss-dev@cdr/vscode#1d4b6bef22eecd50319adf11698d6692c1064deb: version "1.60.2" - resolved "https://codeload.github.com/cdr/vscode/tar.gz/f3bb8843b16719989eaa74ada0992cab87a3d4a2" + resolved "https://codeload.github.com/cdr/vscode/tar.gz/1d4b6bef22eecd50319adf11698d6692c1064deb" dependencies: "@microsoft/applicationinsights-web" "^2.6.4" "@vscode/sqlite3" "4.0.12" From 717bb7900a50ec5f9dd686f88ca937b0ed716348 Mon Sep 17 00:00:00 2001 From: Teffen Ellis Date: Fri, 15 Oct 2021 18:00:38 -0400 Subject: [PATCH 08/39] Bump vendor. --- vendor/package.json | 2 +- vendor/yarn.lock | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/vendor/package.json b/vendor/package.json index cc006b980447..b20a78016197 100644 --- a/vendor/package.json +++ b/vendor/package.json @@ -7,6 +7,6 @@ "postinstall": "./postinstall.sh" }, "devDependencies": { - "code-oss-dev": "cdr/vscode#1d4b6bef22eecd50319adf11698d6692c1064deb" + "code-oss-dev": "cdr/vscode#c545b85566f30f79afa006edbfc3d50f305966a2" } } diff --git a/vendor/yarn.lock b/vendor/yarn.lock index 1bec93c5f943..de554f629fb4 100644 --- a/vendor/yarn.lock +++ b/vendor/yarn.lock @@ -296,9 +296,9 @@ clone-response@^1.0.2: dependencies: mimic-response "^1.0.0" -code-oss-dev@cdr/vscode#1d4b6bef22eecd50319adf11698d6692c1064deb: +code-oss-dev@cdr/vscode#c545b85566f30f79afa006edbfc3d50f305966a2: version "1.60.2" - resolved "https://codeload.github.com/cdr/vscode/tar.gz/1d4b6bef22eecd50319adf11698d6692c1064deb" + resolved "https://codeload.github.com/cdr/vscode/tar.gz/c545b85566f30f79afa006edbfc3d50f305966a2" dependencies: "@microsoft/applicationinsights-web" "^2.6.4" "@vscode/sqlite3" "4.0.12" From 5a286264c5b33130d780c90039026dd394b99d8d Mon Sep 17 00:00:00 2001 From: Asher Date: Mon, 18 Oct 2021 15:51:30 +0000 Subject: [PATCH 09/39] Fix VS Code minification step --- ci/build/build-vscode.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/build/build-vscode.sh b/ci/build/build-vscode.sh index 9dd326cd87e6..91b80990de8b 100755 --- a/ci/build/build-vscode.sh +++ b/ci/build/build-vscode.sh @@ -12,9 +12,9 @@ main() { cd vendor/modules/code-oss-dev if [[ $MINIFY ]]; then - yarn compile-server - else yarn compile-server-min + else + yarn compile-server fi } From e22a0e5546e5de97dfacd80a939361f8fcf8baf0 Mon Sep 17 00:00:00 2001 From: Asher Date: Wed, 13 Oct 2021 19:18:38 +0000 Subject: [PATCH 10/39] Move ClientConfiguration to common Common code must not import Node code as it is imported by the browser. --- src/common/http.ts | 9 +++++++++ src/common/util.ts | 2 +- src/node/http.ts | 11 +---------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/common/http.ts b/src/common/http.ts index c08c8673b477..31d7ba51dedd 100644 --- a/src/common/http.ts +++ b/src/common/http.ts @@ -18,3 +18,12 @@ export class HttpError extends Error { this.name = this.constructor.name } } + +/** + * Base options included on every page. + */ +export interface ClientConfiguration { + codeServerVersion: string + base: string + csStaticBase: string +} diff --git a/src/common/util.ts b/src/common/util.ts index 69df5b12971a..038a48dd74d9 100644 --- a/src/common/util.ts +++ b/src/common/util.ts @@ -1,4 +1,4 @@ -import { ClientConfiguration } from "../node/http" +import { ClientConfiguration } from "./http" /** * Split a string up to the delimiter. If the delimiter doesn't exist the first diff --git a/src/node/http.ts b/src/node/http.ts index d88d8610bdd4..03e23f10ebf8 100644 --- a/src/node/http.ts +++ b/src/node/http.ts @@ -3,22 +3,13 @@ import * as express from "express" import * as expressCore from "express-serve-static-core" import path from "path" import qs from "qs" -import { HttpCode, HttpError } from "../common/http" +import { ClientConfiguration, HttpCode, HttpError } from "../common/http" import { normalize } from "../common/util" import { AuthType, DefaultedArgs } from "./cli" import { version as codeServerVersion } from "./constants" import { Heart } from "./heart" import { getPasswordMethod, IsCookieValidArgs, isCookieValid, sanitizeString, escapeHtml, escapeJSON } from "./util" -/** - * Base options included on every page. - */ -export interface ClientConfiguration { - codeServerVersion: string - base: string - csStaticBase: string -} - declare global { // eslint-disable-next-line @typescript-eslint/no-namespace namespace Express { From 036ee861bf81cb031c7ffb8957098872b6b39dc7 Mon Sep 17 00:00:00 2001 From: Asher Date: Wed, 13 Oct 2021 19:06:35 +0000 Subject: [PATCH 11/39] Ensure lib directory exists before curling cURL errors now because VS Code was moved and the directory does not exist. --- ci/build/build-code-server.sh | 2 ++ ci/build/npm-postinstall.sh | 3 +++ 2 files changed, 5 insertions(+) diff --git a/ci/build/build-code-server.sh b/ci/build/build-code-server.sh index b3b1967a65c8..2b834f96262d 100755 --- a/ci/build/build-code-server.sh +++ b/ci/build/build-code-server.sh @@ -20,6 +20,8 @@ main() { source ./ci/lib.sh OS="$(uname | tr '[:upper:]' '[:lower:]')" + mkdir -p ./lib + if ! [ -f ./lib/coder-cloud-agent ]; then echo "Downloading the cloud agent..." diff --git a/ci/build/npm-postinstall.sh b/ci/build/npm-postinstall.sh index 38412ee7baff..99b897ec909a 100755 --- a/ci/build/npm-postinstall.sh +++ b/ci/build/npm-postinstall.sh @@ -57,6 +57,9 @@ main() { esac OS="$(uname | tr '[:upper:]' '[:lower:]')" + + mkdir -p ./lib + if curl -fsSL "https://github.com/cdr/cloud-agent/releases/latest/download/cloud-agent-$OS-$ARCH" -o ./lib/coder-cloud-agent; then chmod +x ./lib/coder-cloud-agent else From 1acb0a1b9f3d5ac8c692cd2406a873dfba7911e0 Mon Sep 17 00:00:00 2001 From: Asher Date: Wed, 13 Oct 2021 19:18:08 +0000 Subject: [PATCH 12/39] Update incorrect e2e test help output Revert workers change as well; this can be overridden when desired. --- ci/dev/test-e2e.sh | 11 +++++++++-- test/playwright.config.ts | 8 ++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/ci/dev/test-e2e.sh b/ci/dev/test-e2e.sh index f42deb837552..bca78c5558b6 100755 --- a/ci/dev/test-e2e.sh +++ b/ci/dev/test-e2e.sh @@ -1,6 +1,13 @@ #!/usr/bin/env bash set -euo pipefail +help() { + echo >&2 " You can build with 'yarn watch' or you can build a release" + echo >&2 " For example: 'yarn build && yarn build:vscode && KEEP_MODULES=1 yarn release'" + echo >&2 " Then 'CODE_SERVER_TEST_ENTRY=./release yarn test:e2e'" + echo >&2 " You can manually run that release with 'node ./release'" +} + main() { cd "$(dirname "$0")/../.." @@ -21,13 +28,13 @@ main() { # wrong (native modules version issues, incomplete build, etc). if [[ ! -d $dir/out ]]; then echo >&2 "No code-server build detected" - echo >&2 "You can build it with 'yarn build' or 'yarn watch'" + help exit 1 fi if [[ ! -d $dir/vendor/modules/code-oss-dev/out ]]; then echo >&2 "No VS Code build detected" - echo >&2 "You can build it with 'yarn build:vscode' or 'yarn watch'" + help exit 1 fi diff --git a/test/playwright.config.ts b/test/playwright.config.ts index 2182c324783d..2f77fb9cbbcc 100644 --- a/test/playwright.config.ts +++ b/test/playwright.config.ts @@ -2,12 +2,16 @@ import { PlaywrightTestConfig } from "@playwright/test" import path from "path" -// Run tests in three browsers. +// The default configuration runs all tests in three browsers with workers equal +// to half the available threads. See 'yarn test:e2e --help' to customize from +// the command line. For example: +// yarn test:e2e --workers 1 # Run with one worker +// yarn test:e2e --project Chromium # Only run on Chromium +// yarn test:e2e --grep login # Run tests matching "login" const config: PlaywrightTestConfig = { testDir: path.join(__dirname, "e2e"), // Search for tests in this directory. timeout: 60000, // Each test is given 60 seconds. retries: process.env.CI ? 2 : 1, // Retry in CI due to flakiness. - workers: 1, globalSetup: require.resolve("./utils/globalSetup.ts"), reporter: "list", // Put any shared options on the top level. From 467eaeffba0ea515354a97cb1d3be329f59be61a Mon Sep 17 00:00:00 2001 From: Asher Date: Tue, 19 Oct 2021 18:42:17 +0000 Subject: [PATCH 13/39] Add back extension compilation step --- ci/build/build-vscode.sh | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/ci/build/build-vscode.sh b/ci/build/build-vscode.sh index 91b80990de8b..59bd6759b38b 100755 --- a/ci/build/build-vscode.sh +++ b/ci/build/build-vscode.sh @@ -11,11 +11,9 @@ main() { cd vendor/modules/code-oss-dev - if [[ $MINIFY ]]; then - yarn compile-server-min - else - yarn compile-server - fi + # extensions-ci compiles extensions and includes their media. + # compile-web compiles web extensions. TODO: Unsure if used. + yarn gulp extensions-ci compile-web "vscode-server${MINIFY:+-min}" } main "$@" From fd7f1eca0ade17f25732cd68dd3f3ae836c449c5 Mon Sep 17 00:00:00 2001 From: Asher Date: Tue, 19 Oct 2021 20:01:59 +0000 Subject: [PATCH 14/39] Include missing resources in release This includes a favicon, for example. I opted to include the entire directory to make sure we do not miss anything. Some of the other stuff looks potentially useful (like completions). --- ci/build/build-release.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ci/build/build-release.sh b/ci/build/build-release.sh index dde13445cde3..852511166953 100755 --- a/ci/build/build-release.sh +++ b/ci/build/build-release.sh @@ -80,9 +80,8 @@ bundle_vscode() { rsync "$VSCODE_SRC_PATH/extensions/yarn.lock" "$VSCODE_OUT_PATH/extensions" rsync "$VSCODE_SRC_PATH/extensions/postinstall.js" "$VSCODE_OUT_PATH/extensions" - mkdir -p "$VSCODE_OUT_PATH/resources/"{linux,web} - rsync "$VSCODE_SRC_PATH/resources/linux/" "$VSCODE_OUT_PATH/resources/linux/" - rsync "$VSCODE_SRC_PATH/resources/web/" "$VSCODE_OUT_PATH/resources/web/" + mkdir -p "$VSCODE_OUT_PATH/resources/" + rsync "$VSCODE_SRC_PATH/resources/" "$VSCODE_OUT_PATH/resources/" # Add the commit and date and enable telemetry. This just makes telemetry # available; telemetry can still be disabled by flag or setting. From 70edeb98d85e42b2de77eaf56112d94a1c9d8f46 Mon Sep 17 00:00:00 2001 From: Asher Date: Tue, 19 Oct 2021 22:08:44 +0000 Subject: [PATCH 15/39] Set quality property in product configuration When httpWebWorkerExtensionHostIframe.html is fetched it uses the web endpoint template (in which we do not include the commit) but if the quality is not set it prepends the commit to the web endpoint instead. The new static endpoint does not use/handle commits so this 404s. Long-term we might want to make the new static endpoint use commits like the old one but we will also need to update the various other static URLs to include the commit. For now I just fixed this by adding the quality since: 1. Probably faster than trying to find and update all static uses. 2. VS Code probably expects it anyway. 3. Gives us better control over the endpoint. --- ci/build/build-release.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/ci/build/build-release.sh b/ci/build/build-release.sh index 852511166953..263b8c3b802f 100755 --- a/ci/build/build-release.sh +++ b/ci/build/build-release.sh @@ -90,6 +90,7 @@ bundle_vscode() { { "enableTelemetry": true, "commit": "$(git rev-parse HEAD)", + "quality": "stable", "date": $(jq -n 'now | todate') } EOF From 6208a2b55206a87f8532526f26b19bb9626ebd64 Mon Sep 17 00:00:00 2001 From: Asher Date: Wed, 20 Oct 2021 00:12:14 +0000 Subject: [PATCH 16/39] Update VS Code This fixes several build issues. --- vendor/package.json | 2 +- vendor/yarn.lock | 142 ++++++++++++++++++++++---------------------- 2 files changed, 72 insertions(+), 72 deletions(-) diff --git a/vendor/package.json b/vendor/package.json index b20a78016197..6c376a192931 100644 --- a/vendor/package.json +++ b/vendor/package.json @@ -7,6 +7,6 @@ "postinstall": "./postinstall.sh" }, "devDependencies": { - "code-oss-dev": "cdr/vscode#c545b85566f30f79afa006edbfc3d50f305966a2" + "code-oss-dev": "cdr/vscode#ca8377e81abfd081afb9b258a56a727be63eb837" } } diff --git a/vendor/yarn.lock b/vendor/yarn.lock index de554f629fb4..5fd9694345c8 100644 --- a/vendor/yarn.lock +++ b/vendor/yarn.lock @@ -128,10 +128,10 @@ dependencies: nan "2.14.2" -"@vscode/vscode-languagedetection@1.0.20": - version "1.0.20" - resolved "https://registry.yarnpkg.com/@vscode/vscode-languagedetection/-/vscode-languagedetection-1.0.20.tgz#21c1ae29491cfa33dbea4c6f13d1884e640e4f67" - integrity sha512-y4fs4FCirszla1GaJxqSg/qAql1nvmV1GB/cfr/ioSh8s17pekb/rmJ6oqBksoQ+EA4LL9SToeOIHLZf9X7JNg== +"@vscode/vscode-languagedetection@1.0.21": + version "1.0.21" + resolved "https://registry.yarnpkg.com/@vscode/vscode-languagedetection/-/vscode-languagedetection-1.0.21.tgz#89b48f293f6aa3341bb888c1118d16ff13b032d3" + integrity sha512-zSUH9HYCw5qsCtd7b31yqkpaCU6jhtkKLkvOOA8yTrIRfBSOFb8PPhgmMicD7B/m+t4PwOJXzU1XDtrM9Fd3/g== agent-base@4, agent-base@^4.3.0: version "4.3.0" @@ -296,13 +296,13 @@ clone-response@^1.0.2: dependencies: mimic-response "^1.0.0" -code-oss-dev@cdr/vscode#c545b85566f30f79afa006edbfc3d50f305966a2: - version "1.60.2" - resolved "https://codeload.github.com/cdr/vscode/tar.gz/c545b85566f30f79afa006edbfc3d50f305966a2" +code-oss-dev@cdr/vscode#ca8377e81abfd081afb9b258a56a727be63eb837: + version "1.61.1" + resolved "https://codeload.github.com/cdr/vscode/tar.gz/ca8377e81abfd081afb9b258a56a727be63eb837" dependencies: "@microsoft/applicationinsights-web" "^2.6.4" "@vscode/sqlite3" "4.0.12" - "@vscode/vscode-languagedetection" "1.0.20" + "@vscode/vscode-languagedetection" "1.0.21" applicationinsights "1.0.8" chokidar "3.5.1" graceful-fs "4.2.6" @@ -315,34 +315,34 @@ code-oss-dev@cdr/vscode#c545b85566f30f79afa006edbfc3d50f305966a2: native-is-elevated "0.4.3" native-watchdog "1.3.0" node-pty "0.11.0-beta7" - nsfw "2.1.2" path-to-regexp "^6.2.0" spdlog "^0.13.0" sudo-prompt "9.2.1" tar-stream "^2.2.0" tas-client-umd "0.1.4" v8-inspect-profiler "^0.0.22" + vscode-nsfw "2.1.8" vscode-oniguruma "1.5.1" vscode-proxy-agent "^0.11.0" vscode-regexpp "^3.1.0" - vscode-ripgrep "^1.12.0" + vscode-ripgrep "^1.12.1" vscode-textmate "5.4.0" - xterm "4.14.0-beta.22" - xterm-addon-search "0.9.0-beta.4" - xterm-addon-serialize "0.6.0-beta.8" - xterm-addon-unicode11 "0.3.0-beta.6" - xterm-addon-webgl "0.12.0-beta.10" - xterm-headless "4.14.0-beta.12" + xterm "4.15.0-beta.3" + xterm-addon-search "0.9.0-beta.5" + xterm-addon-serialize "0.7.0-beta.1" + xterm-addon-unicode11 "0.3.0" + xterm-addon-webgl "0.12.0-beta.13" + xterm-headless "4.15.0-beta.3" yauzl "^2.9.2" yazl "^2.4.3" optionalDependencies: - electron "13.1.8" + electron "13.5.1" keytar "7.2.0" native-keymap "2.2.1" vscode-windows-registry "1.0.3" windows-foreground-love "0.4.0" windows-mutex "0.4.1" - windows-process-tree "0.3.0" + windows-process-tree "^0.3.2" code-point-at@^1.0.0: version "1.1.0" @@ -483,10 +483,10 @@ duplexer3@^0.1.4: resolved "https://registry.yarnpkg.com/duplexer3/-/duplexer3-0.1.4.tgz#ee01dd1cac0ed3cbc7fdbea37dc0a8f1ce002ce2" integrity sha1-7gHdHKwO08vH/b6jfcCo8c4ALOI= -electron@13.1.8: - version "13.1.8" - resolved "https://registry.yarnpkg.com/electron/-/electron-13.1.8.tgz#a6def6eca7cafc7b068a8f71a069e521ba803182" - integrity sha512-ei2ZyyG81zUOlvm5Zxri668TdH5GNLY0wF+XrC2FRCqa8AABAPjJIWTRkhFEr/H6PDVPNZjMPvSs3XhHyVVk2g== +electron@13.5.1: + version "13.5.1" + resolved "https://registry.yarnpkg.com/electron/-/electron-13.5.1.tgz#76c02c39be228532f886a170b472cbd3d93f0d0f" + integrity sha512-ZyxhIhmdaeE3xiIGObf0zqEyCyuIDqZQBv9NKX8w5FNzGm87j4qR0H1+GQg6vz+cA1Nnv1x175Zvimzc0/UwEQ== dependencies: "@electron/get" "^1.0.1" "@types/node" "^14.6.2" @@ -990,16 +990,16 @@ node-abi@^2.21.0: dependencies: semver "^5.4.1" -node-addon-api@*: - version "4.1.0" - resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-4.1.0.tgz#f1722f1f60793584632ffffb79e12ca042c48bd0" - integrity sha512-Zz1o1BDX2VtduiAt6kgiUl8jX1Vm3NMboljFYKQJ6ee8AGfiTvM2mlZFI3xPbqjs80rCQgiVJI/DjQ/1QJ0HwA== - node-addon-api@^3.0.0, node-addon-api@^3.0.2: version "3.2.1" resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-3.2.1.tgz#81325e0a2117789c0128dab65e7e38f07ceba161" integrity sha512-mmcei9JghVNDYydghQmeDX8KoAm0FAiYyIcUt/N4nhyAipB17pllZQDOJD2fotxABnt4Mdz+dKTO7eftLg4d0A== +node-addon-api@^4.2.0: + version "4.2.0" + resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-4.2.0.tgz#117cbb5a959dff0992e1c586ae0393573e4d2a87" + integrity sha512-eazsqzwG2lskuzBqCGPi7Ac2UgOoMz8JVOXVhTvvPDYhthvNpefx8jWD8Np7Gv+2Sz0FlPWZk0nJV0z598Wn8Q== + node-pty@0.11.0-beta7: version "0.11.0-beta7" resolved "https://registry.yarnpkg.com/node-pty/-/node-pty-0.11.0-beta7.tgz#aed0888b5032d96c54d8473455e6adfae3bbebbe" @@ -1035,13 +1035,6 @@ npmlog@^4.0.1: gauge "~2.7.3" set-blocking "~2.0.0" -nsfw@2.1.2: - version "2.1.2" - resolved "https://registry.yarnpkg.com/nsfw/-/nsfw-2.1.2.tgz#4fa841e7f7122b60b2e1f61187d1b57ad3403428" - integrity sha512-zGPdt32aJ5b1laK9rvgXQmXGAagrx3VkcMt0JePtu6wBfzC1o4xLCM3kq7FxZxUnxyxYhODyBYzpt3H16FhaGA== - dependencies: - node-addon-api "*" - number-is-nan@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/number-is-nan/-/number-is-nan-1.0.1.tgz#097b602b53422a522c1afb8790318336941a011d" @@ -1469,6 +1462,13 @@ v8-inspect-profiler@^0.0.22: dependencies: chrome-remote-interface "0.28.2" +vscode-nsfw@2.1.8: + version "2.1.8" + resolved "https://registry.yarnpkg.com/vscode-nsfw/-/vscode-nsfw-2.1.8.tgz#88f5e56b22b2fd0be582e73eb1158ea8257f6c6c" + integrity sha512-tFnxPIuM65czw/Kjz8KXD88fIJtnCjzQ0ighS0a1yasVv6jKkANAlGffiOitTLMkDjvFCY8OyP6xjarTkpu/VQ== + dependencies: + node-addon-api "^4.2.0" + vscode-oniguruma@1.5.1: version "1.5.1" resolved "https://registry.yarnpkg.com/vscode-oniguruma/-/vscode-oniguruma-1.5.1.tgz#9ca10cd3ada128bd6380344ea28844243d11f695" @@ -1494,10 +1494,10 @@ vscode-regexpp@^3.1.0: resolved "https://registry.yarnpkg.com/vscode-regexpp/-/vscode-regexpp-3.1.0.tgz#42d059b6fffe99bd42939c0d013f632f0cad823f" integrity sha512-pqtN65VC1jRLawfluX4Y80MMG0DHJydWhe5ZwMHewZD6sys4LbU6lHwFAHxeuaVE6Y6+xZOtAw+9hvq7/0ejkg== -vscode-ripgrep@^1.12.0: - version "1.12.0" - resolved "https://registry.yarnpkg.com/vscode-ripgrep/-/vscode-ripgrep-1.12.0.tgz#8fee3f892349f2bf1c7ef9743e3bbccb108ad9d7" - integrity sha512-tn+bM7RbVElyuIGjIFyuSZZSuqodDjPNVQeHdo9w7EOIFEOuNtXuZ82s/Sy59lG/gJyMEkXjXjKunbUNNa5kOw== +vscode-ripgrep@^1.12.1: + version "1.12.1" + resolved "https://registry.yarnpkg.com/vscode-ripgrep/-/vscode-ripgrep-1.12.1.tgz#4a319809d4010ea230659ce605fddacd1e36a589" + integrity sha512-4edKlcXNSKdC9mIQmQ9Wl25v0SF5DOK31JlvKHKHYV4co0V2MjI9pbDPdmogwbtiykz+kFV/cKnZH2TgssEasQ== dependencies: https-proxy-agent "^4.0.0" proxy-from-env "^1.1.0" @@ -1539,10 +1539,10 @@ windows-mutex@0.4.1: bindings "^1.2.1" nan "^2.14.0" -windows-process-tree@0.3.0: - version "0.3.0" - resolved "https://registry.yarnpkg.com/windows-process-tree/-/windows-process-tree-0.3.0.tgz#cf0d9291b22fba2a7f5a687c8272866e28fbcafd" - integrity sha512-0bKI4gcd5MOsOpn2TdStCSlnjThtH6BdHrocekY9qCgTqgEtdaUs0B5BaqyzF9jXoTSwz38NMdE1F55o4fgv9Q== +windows-process-tree@^0.3.2: + version "0.3.2" + resolved "https://registry.yarnpkg.com/windows-process-tree/-/windows-process-tree-0.3.2.tgz#8c39f39e7707e09fd74638a7ef644b5f389096d3" + integrity sha512-x8Y4KOV8tUhhPiO0TH7wOMTZ677rw7VEwq+dTuHHiLTClkrNXWSY3XzP6ez3fs2Cab4FajrtmiqRs0jTMZHfyw== dependencies: nan "^2.13.2" @@ -1566,35 +1566,35 @@ xregexp@2.0.0: resolved "https://registry.yarnpkg.com/xregexp/-/xregexp-2.0.0.tgz#52a63e56ca0b84a7f3a5f3d61872f126ad7a5943" integrity sha1-UqY+VsoLhKfzpfPWGHLxJq16WUM= -xterm-addon-search@0.9.0-beta.4: - version "0.9.0-beta.4" - resolved "https://registry.yarnpkg.com/xterm-addon-search/-/xterm-addon-search-0.9.0-beta.4.tgz#e332f99d5eb5991f8c0e361c9b0d45b23f454323" - integrity sha512-PMzAPtUOjQjJcqpjB2k9BkbjOZPH4PFuQkBtln2599mCPeA9WdA++FpVN6WdBHgeIR5QILoT4pWg0hA8USInzg== - -xterm-addon-serialize@0.6.0-beta.8: - version "0.6.0-beta.8" - resolved "https://registry.yarnpkg.com/xterm-addon-serialize/-/xterm-addon-serialize-0.6.0-beta.8.tgz#b07c56ef86c79935a64c1cbd9930dcbd67631c5d" - integrity sha512-KAy+QTRXCWkctMuuNo1O78q74H1CqrHu2FwOUQiHg6SBkqaTSA+WqRj9RCeD5eb5tyCR22kCticyFUSXeboLow== - -xterm-addon-unicode11@0.3.0-beta.6: - version "0.3.0-beta.6" - resolved "https://registry.yarnpkg.com/xterm-addon-unicode11/-/xterm-addon-unicode11-0.3.0-beta.6.tgz#8914f377757d5078e7b4daee7d3e2b7428b6edf0" - integrity sha512-Qwa18yMhtacf9Jtxy+UuxHfjIeIjaX9q0LUfHtZU8/Lwjh+bGcn8E8IABVSGvXZgPNKw/4TqEpgLFexn+sfc5g== - -xterm-addon-webgl@0.12.0-beta.10: - version "0.12.0-beta.10" - resolved "https://registry.yarnpkg.com/xterm-addon-webgl/-/xterm-addon-webgl-0.12.0-beta.10.tgz#ba23287043da8172f4f9e53babb620f54ad36189" - integrity sha512-mzMOAqgM95FAgzcVzCH/Q0NfN0CTMHVDWCCFyg4B5ZcsuRiQKqQQw0HS+5uOQDtoZEDl2BqGFby7pGpENWGjZQ== - -xterm-headless@4.14.0-beta.12: - version "4.14.0-beta.12" - resolved "https://registry.yarnpkg.com/xterm-headless/-/xterm-headless-4.14.0-beta.12.tgz#06454c63a2e7ca36abbaa0774f7db0d6d7286eff" - integrity sha512-VRtNpNbMvg0mQ3fj7tuC8/thXx5MfzqviSg2KU48mtNMhisGQSH6mL5Q7hgXs7J5m7d2nm3SyklRhQ5ztxRpQg== - -xterm@4.14.0-beta.22: - version "4.14.0-beta.22" - resolved "https://registry.yarnpkg.com/xterm/-/xterm-4.14.0-beta.22.tgz#89e1060927f6542645f53584bfcd35cec08abe5a" - integrity sha512-zl4d2fmjAoCB+G0O5tq2kNkoe7dnnrcY2Daj6VFPPV6nItyXrgRzlKWNfTjKYunC3kU2ApYy+FnHulO7lWuXSw== +xterm-addon-search@0.9.0-beta.5: + version "0.9.0-beta.5" + resolved "https://registry.yarnpkg.com/xterm-addon-search/-/xterm-addon-search-0.9.0-beta.5.tgz#e0e60a203d1c9d6c8af933648a46865dba299302" + integrity sha512-ylfqim0ISBvuuX83LQwgu/06p5GC545QsAo9SssXw03TPpIrcd0zwaVMEnhOftSIzM9EKRRsyx3GbBjgUdiF5w== + +xterm-addon-serialize@0.7.0-beta.1: + version "0.7.0-beta.1" + resolved "https://registry.yarnpkg.com/xterm-addon-serialize/-/xterm-addon-serialize-0.7.0-beta.1.tgz#0168ae7b07a4ce3c2445fce10efe91848717ca2e" + integrity sha512-Qt//GUsTix1FFMWJSFYreppn6nfFqFQaLL9Z9sper62/M3Ip4O+dN/bhrtd5pydBl5iqlHixJls3fu/bj3RHjA== + +xterm-addon-unicode11@0.3.0: + version "0.3.0" + resolved "https://registry.yarnpkg.com/xterm-addon-unicode11/-/xterm-addon-unicode11-0.3.0.tgz#e4435c3c91a5294a7eb8b79c380acbb28a659463" + integrity sha512-x5fHDZT2j9tlTlHnzPHt++9uKZ2kJ/lYQOj3L6xJA22xoJsS8UQRw/5YIFg2FUHqEAbV77Z1fZij/9NycMSH/A== + +xterm-addon-webgl@0.12.0-beta.13: + version "0.12.0-beta.13" + resolved "https://registry.yarnpkg.com/xterm-addon-webgl/-/xterm-addon-webgl-0.12.0-beta.13.tgz#95ecf99531adcce1349f2ddfc834a40af681780e" + integrity sha512-oPQHkFcuCB+x60wilGXFS+viZbOGNFijmuHEWehCUcLFQP5Mph0/6qXLZjgn47728QvCxU7HnXPqcD7JSxe0Tg== + +xterm-headless@4.15.0-beta.3: + version "4.15.0-beta.3" + resolved "https://registry.yarnpkg.com/xterm-headless/-/xterm-headless-4.15.0-beta.3.tgz#b1ba884e2e2feef17d92eaf3ff59b0b20c059dd8" + integrity sha512-MmC75/XUz9z1fHBdJV0Mx9Fje+8hegocT1NfWUNLri3+XFvy5/UbLRhrGUw/lxWKgthseV6eqI44QTNh7fVTQg== + +xterm@4.15.0-beta.3: + version "4.15.0-beta.3" + resolved "https://registry.yarnpkg.com/xterm/-/xterm-4.15.0-beta.3.tgz#123ec4303be390e61cd24ae29872b9fa4e73ad30" + integrity sha512-CXzu0xDHsrOxzC+Tm9ju+eqq0VFiYZPuzPAtfoKOp2PW+wt4fRkM4kysrdLdfE2kz6qyRckRxl+3l7VzlJHVCA== yallist@^4.0.0: version "4.0.0" From 2d628cc7123e59084b114559fc62c0867eee3813 Mon Sep 17 00:00:00 2001 From: Teffen Ellis Date: Thu, 21 Oct 2021 10:52:30 -0400 Subject: [PATCH 17/39] Bump vscode. --- vendor/package.json | 2 +- vendor/yarn.lock | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/vendor/package.json b/vendor/package.json index 6c376a192931..7a9e4593a8e4 100644 --- a/vendor/package.json +++ b/vendor/package.json @@ -7,6 +7,6 @@ "postinstall": "./postinstall.sh" }, "devDependencies": { - "code-oss-dev": "cdr/vscode#ca8377e81abfd081afb9b258a56a727be63eb837" + "code-oss-dev": "cdr/vscode#c1eb071574b93f64b1cc4df55824bfc928d8a2fe" } } diff --git a/vendor/yarn.lock b/vendor/yarn.lock index 5fd9694345c8..d76aa664e322 100644 --- a/vendor/yarn.lock +++ b/vendor/yarn.lock @@ -296,9 +296,9 @@ clone-response@^1.0.2: dependencies: mimic-response "^1.0.0" -code-oss-dev@cdr/vscode#ca8377e81abfd081afb9b258a56a727be63eb837: +code-oss-dev@cdr/vscode#c1eb071574b93f64b1cc4df55824bfc928d8a2fe: version "1.61.1" - resolved "https://codeload.github.com/cdr/vscode/tar.gz/ca8377e81abfd081afb9b258a56a727be63eb837" + resolved "https://codeload.github.com/cdr/vscode/tar.gz/c1eb071574b93f64b1cc4df55824bfc928d8a2fe" dependencies: "@microsoft/applicationinsights-web" "^2.6.4" "@vscode/sqlite3" "4.0.12" From 891eb613721dba98011614838b1cb1b9ba4dd58d Mon Sep 17 00:00:00 2001 From: Teffen Ellis Date: Thu, 21 Oct 2021 11:22:02 -0400 Subject: [PATCH 18/39] Bump. --- vendor/package.json | 2 +- vendor/yarn.lock | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/vendor/package.json b/vendor/package.json index 7a9e4593a8e4..fba132a42aab 100644 --- a/vendor/package.json +++ b/vendor/package.json @@ -7,6 +7,6 @@ "postinstall": "./postinstall.sh" }, "devDependencies": { - "code-oss-dev": "cdr/vscode#c1eb071574b93f64b1cc4df55824bfc928d8a2fe" + "code-oss-dev": "cdr/vscode#66ac45b69d0161f1fc418166eed4affb6e949d9d" } } diff --git a/vendor/yarn.lock b/vendor/yarn.lock index d76aa664e322..63b4218a48a6 100644 --- a/vendor/yarn.lock +++ b/vendor/yarn.lock @@ -296,9 +296,9 @@ clone-response@^1.0.2: dependencies: mimic-response "^1.0.0" -code-oss-dev@cdr/vscode#c1eb071574b93f64b1cc4df55824bfc928d8a2fe: +code-oss-dev@cdr/vscode#66ac45b69d0161f1fc418166eed4affb6e949d9d: version "1.61.1" - resolved "https://codeload.github.com/cdr/vscode/tar.gz/c1eb071574b93f64b1cc4df55824bfc928d8a2fe" + resolved "https://codeload.github.com/cdr/vscode/tar.gz/66ac45b69d0161f1fc418166eed4affb6e949d9d" dependencies: "@microsoft/applicationinsights-web" "^2.6.4" "@vscode/sqlite3" "4.0.12" From e81a37e4994df35896b381e714c54c4db4f16f89 Mon Sep 17 00:00:00 2001 From: Teffen Ellis Date: Thu, 21 Oct 2021 12:12:15 -0400 Subject: [PATCH 19/39] Bump. --- vendor/package.json | 2 +- vendor/yarn.lock | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/vendor/package.json b/vendor/package.json index fba132a42aab..049088165440 100644 --- a/vendor/package.json +++ b/vendor/package.json @@ -7,6 +7,6 @@ "postinstall": "./postinstall.sh" }, "devDependencies": { - "code-oss-dev": "cdr/vscode#66ac45b69d0161f1fc418166eed4affb6e949d9d" + "code-oss-dev": "cdr/vscode#6310f73bbded91cfadc64c08d9be503bf2f633cc" } } diff --git a/vendor/yarn.lock b/vendor/yarn.lock index 63b4218a48a6..8f908c46a0cf 100644 --- a/vendor/yarn.lock +++ b/vendor/yarn.lock @@ -296,9 +296,9 @@ clone-response@^1.0.2: dependencies: mimic-response "^1.0.0" -code-oss-dev@cdr/vscode#66ac45b69d0161f1fc418166eed4affb6e949d9d: +code-oss-dev@cdr/vscode#6310f73bbded91cfadc64c08d9be503bf2f633cc: version "1.61.1" - resolved "https://codeload.github.com/cdr/vscode/tar.gz/66ac45b69d0161f1fc418166eed4affb6e949d9d" + resolved "https://codeload.github.com/cdr/vscode/tar.gz/6310f73bbded91cfadc64c08d9be503bf2f633cc" dependencies: "@microsoft/applicationinsights-web" "^2.6.4" "@vscode/sqlite3" "4.0.12" From b4bda0478ab6e766a1bc4b6c7d8d40e80cd1e727 Mon Sep 17 00:00:00 2001 From: Teffen Ellis Date: Thu, 21 Oct 2021 12:50:10 -0400 Subject: [PATCH 20/39] Use CLI directly. --- src/node/cli.ts | 15 --------------- src/node/entry.ts | 15 ++++----------- src/node/main.ts | 38 ++++++++++++++++++++++++++++++++++---- vendor/package.json | 2 +- vendor/yarn.lock | 4 ++-- 5 files changed, 41 insertions(+), 33 deletions(-) diff --git a/src/node/cli.ts b/src/node/cli.ts index fe9b3fc13142..c608e1765914 100644 --- a/src/node/cli.ts +++ b/src/node/cli.ts @@ -652,21 +652,6 @@ function bindAddrFromAllSources(...argsConfig: Args[]): Addr { return addr } -export const shouldRunVsCodeCli = (args: Args): boolean => { - // Create new interface with only Arg keys - // keyof Args - // Turn that into an array - // Array<...> - type ExtensionArgs = Array - const extensionRelatedArgs: ExtensionArgs = ["list-extensions", "install-extension", "uninstall-extension"] - - const argKeys = Object.keys(args) - - // If any of the extensionRelatedArgs are included in args - // then we don't want to run the vscode cli - return extensionRelatedArgs.some((arg) => argKeys.includes(arg)) -} - /** * 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 diff --git a/src/node/entry.ts b/src/node/entry.ts index f0600b1de716..2bec20d250d3 100644 --- a/src/node/entry.ts +++ b/src/node/entry.ts @@ -1,14 +1,7 @@ import { logger } from "@coder/logger" -import { - optionDescriptions, - parse, - readConfigFile, - setDefaults, - shouldOpenInExistingInstance, - shouldRunVsCodeCli, -} from "./cli" +import { optionDescriptions, parse, readConfigFile, setDefaults, shouldOpenInExistingInstance } from "./cli" import { commit, version } from "./constants" -import { openInExistingInstance, runCodeServer, runVsCodeCli } from "./main" +import { openInExistingInstance, runCodeServer, runVsCodeCli, shouldSpawnCliProcess } from "./main" import { monkeyPatchProxyProtocols } from "./proxy_agent" import { isChild, wrapper } from "./wrapper" @@ -59,8 +52,8 @@ async function entry(): Promise { return } - if (shouldRunVsCodeCli(args)) { - return runVsCodeCli(args) + if (await shouldSpawnCliProcess(args)) { + return runVsCodeCli() } const socketPath = await shouldOpenInExistingInstance(cliArgs) diff --git a/src/node/main.ts b/src/node/main.ts index 582cf8165515..163009b4afbd 100644 --- a/src/node/main.ts +++ b/src/node/main.ts @@ -5,23 +5,53 @@ import { plural } from "../common/util" import { createApp, ensureAddress } from "./app" import { AuthType, DefaultedArgs, Feature } from "./cli" import { coderCloudBind } from "./coder_cloud" -import { commit, version } from "./constants" +import { commit, version, vsRootPath } from "./constants" import { startLink } from "./link" import { register } from "./routes" import { humanPath, isFile, loadAMDModule, open } from "./util" +export const shouldSpawnCliProcess = async (args: DefaultedArgs): Promise => { + const shouldSpawn = await loadAMDModule<(argv: DefaultedArgs) => boolean>("vs/code/node/cli", "shouldSpawnCliProcess") + + return shouldSpawn(args) +} + /** * This is useful when an CLI arg should be passed to VS Code directly, * such as when managing extensions. * @deprecated This should be removed when code-server merges with lib/vscode. */ -export const runVsCodeCli = async (args: DefaultedArgs): Promise => { +export const runVsCodeCli = async (): Promise => { logger.debug("Running VS Code CLI") - const cliProcessMain = await loadAMDModule("vs/code/node/cliProcessMain", "main") + // Delete `VSCODE_CWD` very early even before + // importing bootstrap files. We have seen + // 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("vs/code/node/cli", "initialize") try { - await cliProcessMain(args) + await cliProcessMain(process.argv) } catch (error: any) { logger.error("Got error from VS Code", error) } diff --git a/vendor/package.json b/vendor/package.json index 049088165440..34a0dba18e19 100644 --- a/vendor/package.json +++ b/vendor/package.json @@ -7,6 +7,6 @@ "postinstall": "./postinstall.sh" }, "devDependencies": { - "code-oss-dev": "cdr/vscode#6310f73bbded91cfadc64c08d9be503bf2f633cc" + "code-oss-dev": "cdr/vscode#54bde0ad8502bd34c91dc65b8430bf7710048009" } } diff --git a/vendor/yarn.lock b/vendor/yarn.lock index 8f908c46a0cf..49a3f2497f25 100644 --- a/vendor/yarn.lock +++ b/vendor/yarn.lock @@ -296,9 +296,9 @@ clone-response@^1.0.2: dependencies: mimic-response "^1.0.0" -code-oss-dev@cdr/vscode#6310f73bbded91cfadc64c08d9be503bf2f633cc: +code-oss-dev@cdr/vscode#54bde0ad8502bd34c91dc65b8430bf7710048009: version "1.61.1" - resolved "https://codeload.github.com/cdr/vscode/tar.gz/6310f73bbded91cfadc64c08d9be503bf2f633cc" + resolved "https://codeload.github.com/cdr/vscode/tar.gz/54bde0ad8502bd34c91dc65b8430bf7710048009" dependencies: "@microsoft/applicationinsights-web" "^2.6.4" "@vscode/sqlite3" "4.0.12" From 353c2a12b2162ca70e31e5f85419463a4b16cc06 Mon Sep 17 00:00:00 2001 From: Teffen Ellis Date: Thu, 7 Oct 2021 17:37:51 -0400 Subject: [PATCH 21/39] Update tests to reflect new upstream behavior. --- src/common/http.ts | 9 ---- src/common/util.ts | 31 ------------- src/node/cli.ts | 13 ++++-- src/node/http.ts | 11 ++++- src/node/main.ts | 7 ++- test/unit/common/util.test.ts | 65 ---------------------------- test/unit/node/cli.test.ts | 20 ++++----- test/unit/node/routes/static.test.ts | 4 +- 8 files changed, 36 insertions(+), 124 deletions(-) diff --git a/src/common/http.ts b/src/common/http.ts index 31d7ba51dedd..c08c8673b477 100644 --- a/src/common/http.ts +++ b/src/common/http.ts @@ -18,12 +18,3 @@ export class HttpError extends Error { this.name = this.constructor.name } } - -/** - * Base options included on every page. - */ -export interface ClientConfiguration { - codeServerVersion: string - base: string - csStaticBase: string -} diff --git a/src/common/util.ts b/src/common/util.ts index 038a48dd74d9..f8c25dd102ea 100644 --- a/src/common/util.ts +++ b/src/common/util.ts @@ -1,5 +1,3 @@ -import { ClientConfiguration } from "./http" - /** * Split a string up to the delimiter. If the delimiter doesn't exist the first * item will have all the text and the second item will be an empty string. @@ -52,35 +50,6 @@ export const resolveBase = (base?: string): string => { return normalize(url.pathname) } -/** - * Get client-side configuration embedded in the HTML or query params. - */ -export const getClientConfiguration = (): T => { - let config: T - try { - config = JSON.parse(document.getElementById("coder-options")!.getAttribute("data-settings")!) - } catch (error) { - config = {} as T - } - - // You can also pass options in stringified form to the options query - // variable. Options provided here will override the ones in the options - // element. - const params = new URLSearchParams(location.search) - const queryOpts = params.get("options") - if (queryOpts) { - config = { - ...config, - ...JSON.parse(queryOpts), - } - } - - config.base = resolveBase(config.base) - config.csStaticBase = resolveBase(config.csStaticBase) - - return config -} - /** * Wrap the value in an array if it's not already an array. If the value is * undefined return an empty array. diff --git a/src/node/cli.ts b/src/node/cli.ts index c608e1765914..5fb53e6adbdb 100644 --- a/src/node/cli.ts +++ b/src/node/cli.ts @@ -32,6 +32,7 @@ export class OptionalString extends Optional {} export interface Args extends Pick< CodeServerLib.NativeParsedArgs, + | "_" | "user-data-dir" | "enable-proposed-api" | "extensions-dir" @@ -42,7 +43,12 @@ export interface Args | "locale" | "log" | "verbose" - | "_" + | "install-source" + | "list-extensions" + | "install-extension" + | "uninstall-extension" + | "locate-extension" + // | "telemetry" > { config?: string auth?: AuthType @@ -64,10 +70,7 @@ export interface Args socket?: string version?: boolean force?: boolean - "list-extensions"?: boolean - "install-extension"?: string[] "show-versions"?: boolean - "uninstall-extension"?: string[] "proxy-domain"?: string[] "reuse-window"?: boolean "new-window"?: boolean @@ -177,6 +180,8 @@ const options: Options> = { "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: diff --git a/src/node/http.ts b/src/node/http.ts index 03e23f10ebf8..d88d8610bdd4 100644 --- a/src/node/http.ts +++ b/src/node/http.ts @@ -3,13 +3,22 @@ import * as express from "express" import * as expressCore from "express-serve-static-core" import path from "path" import qs from "qs" -import { ClientConfiguration, HttpCode, HttpError } from "../common/http" +import { HttpCode, HttpError } from "../common/http" import { normalize } from "../common/util" import { AuthType, DefaultedArgs } from "./cli" import { version as codeServerVersion } from "./constants" import { Heart } from "./heart" import { getPasswordMethod, IsCookieValidArgs, isCookieValid, sanitizeString, escapeHtml, escapeJSON } from "./util" +/** + * Base options included on every page. + */ +export interface ClientConfiguration { + codeServerVersion: string + base: string + csStaticBase: string +} + declare global { // eslint-disable-next-line @typescript-eslint/no-namespace namespace Express { diff --git a/src/node/main.ts b/src/node/main.ts index 163009b4afbd..2d58b8c75aca 100644 --- a/src/node/main.ts +++ b/src/node/main.ts @@ -10,8 +10,11 @@ import { startLink } from "./link" import { register } from "./routes" import { humanPath, isFile, loadAMDModule, open } from "./util" -export const shouldSpawnCliProcess = async (args: DefaultedArgs): Promise => { - const shouldSpawn = await loadAMDModule<(argv: DefaultedArgs) => boolean>("vs/code/node/cli", "shouldSpawnCliProcess") +export const shouldSpawnCliProcess = async (args: CodeServerLib.NativeParsedArgs): Promise => { + const shouldSpawn = await loadAMDModule<(argv: CodeServerLib.NativeParsedArgs) => boolean>( + "vs/code/node/cli", + "shouldSpawnCliProcess", + ) return shouldSpawn(args) } diff --git a/test/unit/common/util.test.ts b/test/unit/common/util.test.ts index 4cf76cffcb23..4e7f063edb6f 100644 --- a/test/unit/common/util.test.ts +++ b/test/unit/common/util.test.ts @@ -110,71 +110,6 @@ describe("util", () => { }) }) - describe("getOptions", () => { - beforeEach(() => { - const location: LocationLike = { - pathname: "/healthz", - origin: "http://localhost:8080", - // search: "?environmentId=600e0187-0909d8a00cb0a394720d4dce", - } - - // Because resolveBase is not a pure function - // and relies on the global location to be set - // we set it before all the tests - // and tell TS that our location should be looked at - // as Location (even though it's missing some properties) - global.location = location as Location - }) - - afterEach(() => { - jest.restoreAllMocks() - }) - - it("should return options with base and cssStaticBase even if it doesn't exist", () => { - expect(util.getClientConfiguration()).toStrictEqual({ - base: "", - csStaticBase: "", - }) - }) - - it("should return options when they do exist", () => { - // Mock getElementById - const spy = jest.spyOn(document, "getElementById") - // Create a fake element and set the attribute - const mockElement = document.createElement("div") - mockElement.setAttribute( - "data-settings", - '{"base":".","csStaticBase":"./static/development/Users/jp/Dev/code-server","logLevel":2,"disableUpdateCheck":false}', - ) - // Return mockElement from the spy - // this way, when we call "getElementById" - // it returns the element - spy.mockImplementation(() => mockElement) - - expect(util.getClientConfiguration()).toStrictEqual({ - base: "", - csStaticBase: "/static/development/Users/jp/Dev/code-server", - disableUpdateCheck: false, - logLevel: 2, - }) - }) - - it("should include queryOpts", () => { - // Trying to understand how the implementation works - // 1. It grabs the search params from location.search (i.e. ?) - // 2. it then grabs the "options" param if it exists - // 3. then it creates a new options object - // spreads the original options - // then parses the queryOpts - location.search = '?options={"logLevel":2}' - expect(util.getClientConfiguration()).toStrictEqual({ - base: "", - csStaticBase: "", - logLevel: 2, - }) - }) - }) - describe("arrayify", () => { it("should return value it's already an array", () => { expect(util.arrayify(["hello", "world"])).toStrictEqual(["hello", "world"]) diff --git a/test/unit/node/cli.test.ts b/test/unit/node/cli.test.ts index 94321dd0854b..7ff7ac2ec24b 100644 --- a/test/unit/node/cli.test.ts +++ b/test/unit/node/cli.test.ts @@ -10,10 +10,10 @@ import { parse, setDefaults, shouldOpenInExistingInstance, - shouldRunVsCodeCli, splitOnFirstEquals, } from "../../../src/node/cli" import { tmpdir } from "../../../src/node/constants" +import { shouldSpawnCliProcess } from "../../../src/node/main" import { generatePassword, paths } from "../../../src/node/util" import { useEnv } from "../../utils/helpers" @@ -486,45 +486,45 @@ describe("splitOnFirstEquals", () => { }) }) -describe("shouldRunVsCodeCli", () => { - it("should return false if no 'extension' related args passed in", () => { +describe("shouldSpawnCliProcess", () => { + it("should return false if no 'extension' related args passed in", async () => { const args = { _: [], } - const actual = shouldRunVsCodeCli(args) + const actual = await shouldSpawnCliProcess(args) const expected = false expect(actual).toBe(expected) }) - it("should return true if 'list-extensions' passed in", () => { + it("should return true if 'list-extensions' passed in", async () => { const args = { _: [], ["list-extensions"]: true, } - const actual = shouldRunVsCodeCli(args) + const actual = await shouldSpawnCliProcess(args) const expected = true expect(actual).toBe(expected) }) - it("should return true if 'install-extension' passed in", () => { + it("should return true if 'install-extension' passed in", async () => { const args = { _: [], ["install-extension"]: ["hello.world"], } - const actual = shouldRunVsCodeCli(args) + const actual = await shouldSpawnCliProcess(args) const expected = true expect(actual).toBe(expected) }) - it("should return true if 'uninstall-extension' passed in", () => { + it("should return true if 'uninstall-extension' passed in", async () => { const args = { _: [], ["uninstall-extension"]: ["hello.world"], } - const actual = shouldRunVsCodeCli(args) + const actual = await shouldSpawnCliProcess(args) const expected = true expect(actual).toBe(expected) diff --git a/test/unit/node/routes/static.test.ts b/test/unit/node/routes/static.test.ts index 49d4716a7386..119170c75821 100644 --- a/test/unit/node/routes/static.test.ts +++ b/test/unit/node/routes/static.test.ts @@ -7,7 +7,7 @@ import * as integration from "../../../utils/integration" const NOT_FOUND = { code: 404, - message: "Not Found", + message: /not found/i, } describe("/_static", () => { @@ -44,7 +44,7 @@ describe("/_static", () => { expect(resp.status).toBe(NOT_FOUND.code) const content = await resp.json() - expect(content.error).toContain(NOT_FOUND.message) + expect(content.error).toMatch(NOT_FOUND.message) }) } From c1b40a541ff0fbfa8ba6bf3468bd0e19511a9543 Mon Sep 17 00:00:00 2001 From: Asher Date: Thu, 21 Oct 2021 18:49:00 +0000 Subject: [PATCH 22/39] Move unit tests to after the build Our code has new dependencies on VS Code that are pulled in when the unit tests run. Because of this we need to build VS Code before running the unit tests (as it only pulls built code). --- .github/workflows/ci.yaml | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 497203afe674..f952c8d39ee5 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -19,8 +19,6 @@ jobs: name: Pre-build checks runs-on: ubuntu-latest timeout-minutes: 15 - env: - CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} steps: - name: Checkout repo uses: actions/checkout@v2 @@ -54,14 +52,6 @@ jobs: run: yarn lint if: success() - - name: Run code-server unit tests - run: yarn test:unit - if: success() - - - name: Upload coverage report to Codecov - run: yarn coverage - if: success() - audit-ci: name: Run audit-ci needs: prebuild @@ -98,6 +88,8 @@ jobs: needs: prebuild runs-on: ubuntu-latest timeout-minutes: 30 + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} steps: - uses: actions/checkout@v2 with: @@ -154,6 +146,17 @@ jobs: if: steps.cache-vscode.outputs.cache-hit != 'true' run: yarn build:vscode + # Our code imports code from VS Code's output directory meaning VS Code + # must be built before running these tests. + # TODO: Move to its own step? + - name: Run code-server unit tests + run: yarn test:unit + if: success() + + - name: Upload coverage report to Codecov + run: yarn coverage + if: success() + # The release package does not contain any native modules # and is neutral to architecture/os/libc version. - name: Create release package From fd423877635aef66a4583616f50492d71f5fcb3d Mon Sep 17 00:00:00 2001 From: Asher Date: Thu, 21 Oct 2021 20:29:38 +0000 Subject: [PATCH 23/39] Upgrade proxy-agent dependencies This resolves a security report with one of its dependencies (vm2). --- yarn.lock | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/yarn.lock b/yarn.lock index 1156343ec198..89c24822c2da 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1090,9 +1090,9 @@ cookie@0.4.0: integrity sha512-+Hp8fLp57wnUSt0tY0tHEXh4voZRDnoIrZPqlo3DPiI4y9lwg/jqx+1Om94/W6ZaPDOUbnjOt/99w66zk+l1Xg== core-util-is@~1.0.0: - version "1.0.2" - resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7" - integrity sha1-tf1UIgqivFq1eqtxQMlAdUUDwac= + version "1.0.3" + resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.3.tgz#a6042d3634c2b27e9328f837b965fac83808db85" + integrity sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ== cosmiconfig@^7.0.0: version "7.0.0" @@ -1148,10 +1148,10 @@ debug@3.1.0: dependencies: ms "2.0.0" -debug@4, debug@^4.0.0, debug@^4.0.1, debug@^4.1.0, debug@^4.1.1, debug@^4.3.1: - version "4.3.1" - resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.1.tgz#f0d229c505e0c6d8c49ac553d1b13dc183f6b2ee" - integrity sha512-doEwdvm4PCeK4K3RQN2ZC2BYUBaxwLARCqZmMjtF8a51J2Rb0xpVloFRnCODwqjpwnAoao4pelN8l3RJdv3gRQ== +debug@4: + version "4.3.2" + resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.2.tgz#f0a49c18ac8779e31d4a0c6029dfb76873c7428b" + integrity sha512-mOp8wKcvj7XxC78zLgw/ZA+6TSgkoE2C/ienthhRD298T7UNwAg9diBpLRxC0mOezLl4B0xV7M0cCO6P/O0Xhw== dependencies: ms "2.1.2" @@ -1162,6 +1162,13 @@ debug@^3.2.7: dependencies: ms "^2.1.1" +debug@^4.0.0, debug@^4.0.1, debug@^4.1.0, debug@^4.1.1, debug@^4.3.1: + version "4.3.1" + resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.1.tgz#f0d229c505e0c6d8c49ac553d1b13dc183f6b2ee" + integrity sha512-doEwdvm4PCeK4K3RQN2ZC2BYUBaxwLARCqZmMjtF8a51J2Rb0xpVloFRnCODwqjpwnAoao4pelN8l3RJdv3gRQ== + dependencies: + ms "2.1.2" + decamelize-keys@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/decamelize-keys/-/decamelize-keys-1.1.0.tgz#d171a87933252807eb3cb61dc1c1445d078df2d9" @@ -4401,9 +4408,9 @@ vfile@^4.0.0: vfile-message "^2.0.0" vm2@^3.9.3: - version "3.9.3" - resolved "https://registry.yarnpkg.com/vm2/-/vm2-3.9.3.tgz#29917f6cc081cc43a3f580c26c5b553fd3c91f40" - integrity sha512-smLS+18RjXYMl9joyJxMNI9l4w7biW8ilSDaVRvFBDwOH8P0BK1ognFQTpg0wyQ6wIKLTblHJvROW692L/E53Q== + version "3.9.5" + resolved "https://registry.yarnpkg.com/vm2/-/vm2-3.9.5.tgz#5288044860b4bbace443101fcd3bddb2a0aa2496" + integrity sha512-LuCAHZN75H9tdrAiLFf030oW7nJV5xwNMuk1ymOZwopmuK3d2H4L1Kv4+GFHgarKiLfXXLFU+7LDABHnwOkWng== which-boxed-primitive@^1.0.2: version "1.0.2" From dd8124f9064627be9f8dc40028429970c1133ec8 Mon Sep 17 00:00:00 2001 From: Asher Date: Thu, 21 Oct 2021 21:00:17 +0000 Subject: [PATCH 24/39] Symlink VS Code output directory before unit tests This is necessary now that we import from the out directory. --- .github/workflows/ci.yaml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index f952c8d39ee5..ccd83cd9caf6 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -147,7 +147,12 @@ jobs: run: yarn build:vscode # Our code imports code from VS Code's output directory meaning VS Code - # must be built before running these tests. + # must be built before running these tests. It looks for `out` in order + # to works during development (for release we move `out-build` to `out`) + # so symlink `out` to `out-build` as this is a production build. + - name: Link vscode + run: ln -s out-build vendor/modules/code-oss-dev/out + # TODO: Move to its own step? - name: Run code-server unit tests run: yarn test:unit From 6efc7b4a040b877f5e29f59e8e2c3985d7e493ff Mon Sep 17 00:00:00 2001 From: Teffen Ellis Date: Thu, 21 Oct 2021 21:38:20 -0400 Subject: [PATCH 25/39] Fix issues surrounding persistent processes between tests. --- package.json | 2 +- src/node/app.ts | 11 +- src/node/link.ts | 17 +- src/node/main.ts | 50 +- src/node/routes/index.ts | 11 +- src/node/routes/vscode.ts | 15 +- test/package.json | 12 +- test/unit/browser/pages/login.test.ts | 59 +- test/unit/node/app.test.ts | 14 +- test/unit/node/proxy.test.ts | 6 +- test/unit/node/routes/login.test.ts | 6 + test/unit/node/routes/static.test.ts | 6 + test/utils/httpserver.ts | 50 +- test/utils/integration.ts | 4 +- test/yarn.lock | 2363 ++++++++++--------------- vendor/package.json | 2 +- vendor/yarn.lock | 4 +- 17 files changed, 1113 insertions(+), 1519 deletions(-) diff --git a/package.json b/package.json index 1b0c1277bf02..4d52857d8d69 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "release:prep": "./ci/build/release-prep.sh", "test:e2e": "./ci/dev/test-e2e.sh", "test:standalone-release": "./ci/build/test-standalone-release.sh", - "test:unit": "./ci/dev/test-unit.sh", + "test:unit": "./ci/dev/test-unit.sh --forceExit --detectOpenHandles", "test:scripts": "./ci/dev/test-scripts.sh", "package": "./ci/build/build-packages.sh", "postinstall": "./ci/dev/postinstall.sh", diff --git a/src/node/app.ts b/src/node/app.ts index b2bfc74f5060..908747b243ef 100644 --- a/src/node/app.ts +++ b/src/node/app.ts @@ -68,15 +68,18 @@ export const createApp = async (args: DefaultedArgs): Promise<[Express, Express, * Get the address of a server as a string (protocol *is* included) while * ensuring there is one (will throw if there isn't). */ -export const ensureAddress = (server: http.Server): string => { +export const ensureAddress = (server: http.Server, protocol: string): URL => { const addr = server.address() + if (!addr) { - throw new Error("server has no address") + throw new Error("Server has no address") } + if (typeof addr !== "string") { - return `http://${addr.address}:${addr.port}` + return new URL(`${protocol}://${addr.address}:${addr.port}`) } - return addr + + return new URL(addr) } /** diff --git a/src/node/link.ts b/src/node/link.ts index 5dfe795228da..28b0cc3ddfa5 100644 --- a/src/node/link.ts +++ b/src/node/link.ts @@ -1,22 +1,11 @@ import { logger } from "@coder/logger" -import { spawn } from "child_process" +import { ChildProcessWithoutNullStreams, spawn } from "child_process" import path from "path" -export function startLink(port: number): Promise { +export function startLink(port: number): ChildProcessWithoutNullStreams { logger.debug(`running link targetting ${port}`) - const agent = spawn(path.resolve(__dirname, "../../lib/linkup"), ["--devurl", `code:${port}:code-server`], { + return spawn(path.resolve(__dirname, "../../lib/linkup"), ["--devurl", `code:${port}:code-server`], { shell: false, }) - return new Promise((res, rej) => { - agent.on("error", rej) - agent.on("close", (code) => { - if (code !== 0) { - return rej({ - message: `Link exited with ${code}`, - }) - } - res() - }) - }) } diff --git a/src/node/main.ts b/src/node/main.ts index 2d58b8c75aca..aa4608165f16 100644 --- a/src/node/main.ts +++ b/src/node/main.ts @@ -1,6 +1,8 @@ import { field, logger } from "@coder/logger" +import { ChildProcessWithoutNullStreams } from "child_process" import http from "http" import path from "path" +import { Disposable } from "../common/emitter" import { plural } from "../common/util" import { createApp, ensureAddress } from "./app" import { AuthType, DefaultedArgs, Feature } from "./cli" @@ -105,7 +107,9 @@ export const openInExistingInstance = async (args: DefaultedArgs, socketPath: st vscode.end() } -export const runCodeServer = async (args: DefaultedArgs): Promise => { +export const runCodeServer = async ( + args: DefaultedArgs, +): Promise<{ dispose: Disposable["dispose"]; server: http.Server }> => { logger.info(`code-server ${version} ${commit}`) logger.info(`Using user-data-dir ${humanPath(args["user-data-dir"])}`) @@ -118,11 +122,11 @@ export const runCodeServer = async (args: DefaultedArgs): Promise = } const [app, wsApp, server] = await createApp(args) - const serverAddress = ensureAddress(server) - await register(app, wsApp, server, args) + const serverAddress = ensureAddress(server, args.cert ? "https" : "http") + const disposeApp = await register(app, wsApp, server, args) logger.info(`Using config file ${humanPath(args.config)}`) - logger.info(`HTTP server listening on ${serverAddress} ${args.link ? "(randomized by --link)" : ""}`) + logger.info(`HTTP server listening on ${serverAddress.toString()} ${args.link ? "(randomized by --link)" : ""}`) if (args.auth === AuthType.Password) { logger.info(" - Authentication is enabled") if (args.usingEnvPassword) { @@ -148,19 +152,26 @@ export const runCodeServer = async (args: DefaultedArgs): Promise = } if (args.link) { - await coderCloudBind(serverAddress.replace(/^https?:\/\//, ""), args.link.value) + await coderCloudBind(serverAddress.host, args.link.value) logger.info(" - Connected to cloud agent") } + let linkAgent: undefined | ChildProcessWithoutNullStreams + try { - const port = parseInt(serverAddress.split(":").pop() as string, 10) - startLink(port).catch((ex) => { - logger.debug("Link daemon exited!", field("error", ex)) - }) + linkAgent = startLink(parseInt(serverAddress.port, 10)) } catch (error) { logger.debug("Failed to start link daemon!", error as any) } + linkAgent?.on("error", (error) => { + logger.debug("[Link daemon]", field("error", error)) + }) + + linkAgent?.on("close", (code) => { + logger.debug("[Link daemon]", field("code", `Closed with code ${code}`)) + }) + if (args.enable && args.enable.length > 0) { logger.info("Enabling the following experimental features:") args.enable.forEach((feature) => { @@ -178,14 +189,25 @@ export const runCodeServer = async (args: DefaultedArgs): Promise = if (!args.socket && args.open) { // The web socket doesn't seem to work if browsing with 0.0.0.0. - const openAddress = serverAddress.replace("://0.0.0.0", "://localhost") + if (serverAddress.hostname === "0.0.0.0") { + serverAddress.hostname = "localhost" + } + try { - await open(openAddress) - logger.info(`Opened ${openAddress}`) + await open(serverAddress.toString()) + logger.info(`Opened ${serverAddress}`) } catch (error) { - logger.error("Failed to open", field("address", openAddress), field("error", error)) + logger.error("Failed to open", field("address", serverAddress.toString()), field("error", error)) } } - return server + const dispose = () => { + disposeApp() + linkAgent?.kill() + } + + return { + server, + dispose, + } } diff --git a/src/node/routes/index.ts b/src/node/routes/index.ts index 13232f703aeb..5917615afa59 100644 --- a/src/node/routes/index.ts +++ b/src/node/routes/index.ts @@ -6,6 +6,7 @@ import http from "http" import * as path from "path" import * as tls from "tls" import * as pluginapi from "../../../typings/pluginapi" +import { Disposable } from "../../common/emitter" import { HttpCode, HttpError } from "../../common/http" import { plural } from "../../common/util" import { AuthType, DefaultedArgs } from "../cli" @@ -33,7 +34,7 @@ export const register = async ( wsApp: express.Express, server: http.Server, args: DefaultedArgs, -): Promise => { +): Promise => { const heart = new Heart(path.join(paths.data, "heartbeat"), async () => { return new Promise((resolve, reject) => { server.getConnections((error, count) => { @@ -161,14 +162,14 @@ export const register = async ( } } - server.on("close", () => { - vscode?.vscodeServer.close() - }) - app.use(() => { throw new HttpError("Not Found", HttpCode.NotFound) }) app.use(errorHandler) wsApp.use(wsErrorHandler) + + return () => { + vscode?.codeServerMain.dispose() + } } diff --git a/src/node/routes/vscode.ts b/src/node/routes/vscode.ts index 9c072fae89c1..a2b02512bba0 100644 --- a/src/node/routes/vscode.ts +++ b/src/node/routes/vscode.ts @@ -1,5 +1,4 @@ import * as express from "express" -import { Server } from "http" import path from "path" import { AuthType, DefaultedArgs } from "../cli" import { version as codeServerVersion, vsRootPath } from "../constants" @@ -11,7 +10,7 @@ import { errorHandler } from "./errors" export interface VSServerResult { router: express.Router wsRouter: WebsocketRouter - vscodeServer: Server + codeServerMain: CodeServerLib.IServerProcessMain } export const createVSServerRouter = async (args: DefaultedArgs): Promise => { @@ -39,10 +38,10 @@ export const createVSServerRouter = async (args: DefaultedArgs): Promise("vs/server/entry", "createVSServer") + const createVSServer = await loadAMDModule("vs/server/entry", "createVSServer") const serverUrl = new URL(`${args.cert ? "https" : "http"}://${args.host}:${args.port}`) - const vscodeServer = await vscodeServerMain({ + const codeServerMain = await createVSServer({ codeServerVersion, serverUrl, args, @@ -50,6 +49,8 @@ export const createVSServerRouter = async (args: DefaultedArgs): Promise { req.on("error", (error) => errorHandler(error, req, res, next)) - vscodeServer.emit("request", req, res) + netServer.emit("request", req, res) }) wsRouter.ws("/", ensureAuthenticated, (req) => { - vscodeServer.emit("upgrade", req, req.socket, req.head) + netServer.emit("upgrade", req, req.socket, req.head) req.socket.resume() }) @@ -79,6 +80,6 @@ export const createVSServerRouter = async (args: DefaultedArgs): Promise { spy.mockImplementation(() => mockElement) }) }) - describe("there is not an element with id 'base'", () => { - let spy: jest.SpyInstance + // TODO: Is this still used? + // describe("there is not an element with id 'base'", () => { + // let spy: jest.SpyInstance - beforeAll(() => { - // This is important because we're manually requiring the file - // If you don't call this before all tests - // the module registry from other tests may cause side effects. - jest.resetModuleRegistry() - }) + // beforeAll(() => { + // // This is important because we're manually requiring the file + // // If you don't call this before all tests + // // the module registry from other tests may cause side effects. + // jest.resetModules() + // }) - beforeEach(() => { - const dom = new JSDOM() - global.document = dom.window.document - spy = jest.spyOn(document, "getElementById") + // beforeEach(() => { + // const dom = new JSDOM() + // global.document = dom.window.document + // spy = jest.spyOn(document, "getElementById") - const location: LocationLike = { - pathname: "/healthz", - origin: "http://localhost:8080", - } + // const location: LocationLike = { + // pathname: "/healthz", + // origin: "http://localhost:8080", + // } - global.location = location as Location - }) + // global.location = location as Location + // }) - afterEach(() => { - spy.mockClear() - jest.resetModules() - // Reset the global.document - global.document = undefined as any as Document - global.location = undefined as any as Location - }) + // afterEach(() => { + // spy.mockClear() + // jest.resetModules() + // // Reset the global.document + // global.document = undefined as any as Document + // global.location = undefined as any as Location + // }) - afterAll(() => { - jest.restoreAllMocks() - }) - }) + // afterAll(() => { + // jest.restoreAllMocks() + // }) + // }) }) diff --git a/test/unit/node/app.test.ts b/test/unit/node/app.test.ts index 89626882be73..2a3bf0210bca 100644 --- a/test/unit/node/app.test.ts +++ b/test/unit/node/app.test.ts @@ -156,18 +156,12 @@ describe("ensureAddress", () => { }) it("should throw and error if no address", () => { - expect(() => ensureAddress(mockServer)).toThrow("server has no address") - }) - it("should return the address if it exists and not a string", async () => { - const port = await getAvailablePort() - mockServer.listen(port) - const address = ensureAddress(mockServer) - expect(address).toBe(`http://:::${port}`) + expect(() => ensureAddress(mockServer, "http")).toThrow("Server has no address") }) it("should return the address if it exists", async () => { - mockServer.address = () => "http://localhost:8080" - const address = ensureAddress(mockServer) - expect(address).toBe(`http://localhost:8080`) + mockServer.address = () => "http://localhost:8080/" + const address = ensureAddress(mockServer, "http") + expect(address.toString()).toBe(`http://localhost:8080/`) }) }) diff --git a/test/unit/node/proxy.test.ts b/test/unit/node/proxy.test.ts index fe349bddac0e..1a0b8c6f10bf 100644 --- a/test/unit/node/proxy.test.ts +++ b/test/unit/node/proxy.test.ts @@ -1,7 +1,7 @@ import bodyParser from "body-parser" import * as express from "express" import * as http from "http" -import * as nodeFetch from "node-fetch" +import nodeFetch from "node-fetch" import { HttpCode } from "../../../src/common/http" import { proxy } from "../../../src/node/proxy" import { getAvailablePort } from "../../utils/helpers" @@ -202,13 +202,13 @@ describe("proxy (standalone)", () => { it("should return a 500 when proxy target errors ", async () => { // Close the proxy target so that proxy errors await proxyTarget.close() - const errorResp = await nodeFetch.default(`${URL}/error`) + const errorResp = await nodeFetch(`${URL}/error`) expect(errorResp.status).toBe(HttpCode.ServerError) expect(errorResp.statusText).toBe("Internal Server Error") }) it("should proxy correctly", async () => { - const resp = await nodeFetch.default(`${URL}/route`) + const resp = await nodeFetch(`${URL}/route`) expect(resp.status).toBe(200) expect(resp.statusText).toBe("OK") }) diff --git a/test/unit/node/routes/login.test.ts b/test/unit/node/routes/login.test.ts index 038461b4a95a..e8547ef18126 100644 --- a/test/unit/node/routes/login.test.ts +++ b/test/unit/node/routes/login.test.ts @@ -63,6 +63,12 @@ describe("login", () => { } }) + afterAll(async () => { + if (_codeServer) { + _codeServer.dispose() + } + }) + it("should return HTML with 'Missing password' message", async () => { const resp = await codeServer().fetch("/login", { method: "POST" }) diff --git a/test/unit/node/routes/static.test.ts b/test/unit/node/routes/static.test.ts index 119170c75821..c9f3187817ac 100644 --- a/test/unit/node/routes/static.test.ts +++ b/test/unit/node/routes/static.test.ts @@ -38,6 +38,12 @@ describe("/_static", () => { } }) + afterAll(async () => { + if (_codeServer) { + _codeServer.dispose() + } + }) + function commonTests() { it("should return a 404 when a file is not provided", async () => { const resp = await codeServer().fetch(`/_static/`) diff --git a/test/utils/httpserver.ts b/test/utils/httpserver.ts index bbd25a6cfff0..1c0bcb11fa79 100644 --- a/test/utils/httpserver.ts +++ b/test/utils/httpserver.ts @@ -2,8 +2,9 @@ import { logger } from "@coder/logger" import * as express from "express" import * as http from "http" import * as net from "net" -import * as nodeFetch from "node-fetch" +import nodeFetch, { RequestInit, Response } from "node-fetch" import Websocket from "ws" +import { Disposable } from "../../src/common/emitter" import * as util from "../../src/common/util" import { ensureAddress } from "../../src/node/app" import { handleUpgrade } from "../../src/node/wsRouter" @@ -14,11 +15,13 @@ export class HttpServer { private cleanupTimeout?: NodeJS.Timeout // See usage in test/integration.ts - public constructor(private readonly hs = http.createServer()) { + public constructor(private readonly hs = http.createServer(), private _dispose?: Disposable["dispose"]) { this.hs.on("connection", (socket) => { this.sockets.add(socket) + socket.on("close", () => { this.sockets.delete(socket) + if (this.cleanupTimeout && this.sockets.size === 0) { clearTimeout(this.cleanupTimeout) this.cleanupTimeout = undefined @@ -34,20 +37,17 @@ export class HttpServer { public listen(fn: http.RequestListener): Promise { this.hs.on("request", fn) - let resolved = false - return new Promise((res, rej) => { + return new Promise((resolve, reject) => { + this.hs.on("error", reject) + this.hs.listen(0, "localhost", () => { - res() - resolved = true - }) + this.hs.off("error", reject) + resolve() - this.hs.on("error", (err) => { - if (!resolved) { - rej(err) - } else { + this.hs.on("error", (err) => { // Promise resolved earlier so this is some other error. util.logError(logger, "http server error", err) - } + }) }) }) } @@ -63,15 +63,15 @@ export class HttpServer { * close cleans up the server. */ public close(): Promise { - return new Promise((res, rej) => { + return new Promise((resolve, reject) => { // Close will not actually close anything; it just waits until everything // is closed. this.hs.close((err) => { if (err) { - rej(err) - return + return reject(err) } - res() + + resolve() }) // If there are sockets remaining we might need to force close them or @@ -80,6 +80,7 @@ export class HttpServer { // Give sockets a chance to close up shop. this.cleanupTimeout = setTimeout(() => { this.cleanupTimeout = undefined + for (const socket of this.sockets.values()) { console.warn("a socket was left hanging") socket.destroy() @@ -89,19 +90,30 @@ export class HttpServer { }) } + public dispose() { + console.log("Disposing HTTP Server") + this._dispose?.() + } + /** * fetch fetches the request path. * The request path must be rooted! */ - public fetch(requestPath: string, opts?: nodeFetch.RequestInit): Promise { - return nodeFetch.default(`${ensureAddress(this.hs)}${requestPath}`, opts) + public fetch(requestPath: string, opts?: RequestInit): Promise { + const address = ensureAddress(this.hs, "http") + address.pathname = requestPath + + return nodeFetch(address.toString(), opts) } /** * Open a websocket against the requset path. */ public ws(requestPath: string): Websocket { - return new Websocket(`${ensureAddress(this.hs).replace("http:", "ws:")}${requestPath}`) + const address = ensureAddress(this.hs, "ws") + address.pathname = requestPath + + return new Websocket(address.toString()) } public port(): number { diff --git a/test/utils/integration.ts b/test/utils/integration.ts index 5c4f0cc6aa7f..bf00f89e4f18 100644 --- a/test/utils/integration.ts +++ b/test/utils/integration.ts @@ -9,7 +9,7 @@ export async function setup(argv: string[], configFile?: string): Promise= 2.1.2 < 3", safer-buffer@^2.0.2, safer-buffer@^2.1.0, safer-buffer@~2.1.0: version "2.1.2" resolved "https://registry.yarnpkg.com/safer-buffer/-/safer-buffer-2.1.2.tgz#44fa161b0187b9549dd84bb91802f9bd8385cd6a" integrity sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg== -sane@^4.0.3: - version "4.1.0" - resolved "https://registry.yarnpkg.com/sane/-/sane-4.1.0.tgz#ed881fd922733a6c461bc189dc2b6c006f3ffded" - integrity sha512-hhbzAgTIX8O7SHfp2c8/kREfEn4qO/9q8C9beyY6+tvZ87EpoZ3i1RIEvp27YBswnNbY9mWd6paKVmKbAgLfZA== - dependencies: - "@cnakazawa/watch" "^1.0.3" - anymatch "^2.0.0" - capture-exit "^2.0.0" - exec-sh "^0.3.2" - execa "^1.0.0" - fb-watchman "^2.0.0" - micromatch "^3.1.4" - minimist "^1.1.1" - walker "~1.0.5" - -saxes@^5.0.0: +saxes@^5.0.0, saxes@^5.0.1: version "5.0.1" resolved "https://registry.yarnpkg.com/saxes/-/saxes-5.0.1.tgz#eebab953fa3b7608dbe94e5dadb15c888fa6696d" integrity sha512-5LBh1Tls8c9xgGjw3QrMwETmTMVk0oFgvrFSvWx62llR2hcEInrKNZ2GZCCuuy2lvWrdl5jhbpeqc5hRYKFOcw== dependencies: xmlchars "^2.2.0" -"semver@2 || 3 || 4 || 5", semver@^5.4.1, semver@^5.5.0: - version "5.7.1" - resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.1.tgz#a954f931aeba508d307bbf069eff0c01c96116f7" - integrity sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ== - semver@7.x, semver@^7.3.2: version "7.3.4" resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.4.tgz#27aaa7d2e4ca76452f98d3add093a72c943edc97" @@ -4051,6 +3773,11 @@ semver@7.x, semver@^7.3.2: dependencies: lru-cache "^6.0.0" +semver@^5.4.1: + version "5.7.1" + resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.1.tgz#a954f931aeba508d307bbf069eff0c01c96116f7" + integrity sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ== + semver@^6.0.0, semver@^6.3.0: version "6.3.0" resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d" @@ -4063,12 +3790,12 @@ semver@^7.3.4: dependencies: lru-cache "^6.0.0" -set-blocking@^2.0.0, set-blocking@~2.0.0: +set-blocking@~2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/set-blocking/-/set-blocking-2.0.0.tgz#045f9782d011ae9a6803ddd382b24392b3d890f7" integrity sha1-BF+XgtARrppoA93TgrJDkrPYkPc= -set-value@^2.0.0, set-value@^2.0.1, set-value@^4.0.1: +set-value@^4.0.1: version "4.1.0" resolved "https://registry.yarnpkg.com/set-value/-/set-value-4.1.0.tgz#aa433662d87081b75ad88a4743bd450f044e7d09" integrity sha512-zTEg4HL0RwVrqcWs3ztF+x1vkxfm0lP+MQQFPiMJTKVceBwEV0A569Ou8l9IYQG8jOZdMVI1hGsc0tmeD2o/Lw== @@ -4076,13 +3803,6 @@ set-value@^2.0.0, set-value@^2.0.1, set-value@^4.0.1: is-plain-object "^2.0.4" is-primitive "^3.0.1" -shebang-command@^1.2.0: - version "1.2.0" - resolved "https://registry.yarnpkg.com/shebang-command/-/shebang-command-1.2.0.tgz#44aac65b695b03398968c39f363fee5deafdf1ea" - integrity sha1-RKrGW2lbAzmJaMOfNj/uXer98eo= - dependencies: - shebang-regex "^1.0.0" - shebang-command@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/shebang-command/-/shebang-command-2.0.0.tgz#ccd0af4f8835fbdc265b82461aaf0c36663f34ea" @@ -4090,26 +3810,21 @@ shebang-command@^2.0.0: dependencies: shebang-regex "^3.0.0" -shebang-regex@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-1.0.0.tgz#da42f49740c0b42db2ca9728571cb190c98efea3" - integrity sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM= - shebang-regex@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-3.0.0.tgz#ae16f1644d873ecad843b0307b143362d4c42172" integrity sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A== -shellwords@^0.1.1: - version "0.1.1" - resolved "https://registry.yarnpkg.com/shellwords/-/shellwords-0.1.1.tgz#d6b9181c1a48d397324c84871efbcfc73fc0654b" - integrity sha512-vFwSUfQvqybiICwZY5+DAWIPLKsWO31Q91JSKl3UYv+K5c2QRPzn0qzec6QPu1Qc9eHYItiP3NdJqNVqetYAww== - signal-exit@^3.0.0, signal-exit@^3.0.2: version "3.0.3" resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.3.tgz#a1410c2edd8f077b08b4e253c8eacfcaf057461c" integrity sha512-VUJ49FC8U1OxwZLxIbTTrDvLnf/6TDgxZcK8wxR8zs13xpx7xbG60ndBlhNrFi2EMuFRoeDoJO7wthSLq42EjA== +signal-exit@^3.0.3: + version "3.0.5" + resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.5.tgz#9e3e8cc0c75a99472b44321033a7702e7738252f" + integrity sha512-KWcOiKeQj6ZyXx7zq4YxSMgHRlod4czeBQZrPb8OKcohcqAXShm7E20kEMle9WBt26hFcAf0qLOcp5zmY7kOqQ== + sisteransi@^1.0.5: version "1.0.5" resolved "https://registry.yarnpkg.com/sisteransi/-/sisteransi-1.0.5.tgz#134d681297756437cc05ca01370d3a7a571075ed" @@ -4120,47 +3835,6 @@ slash@^3.0.0: resolved "https://registry.yarnpkg.com/slash/-/slash-3.0.0.tgz#6539be870c165adbd5240220dbe361f1bc4d4634" integrity sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q== -snapdragon-node@^2.0.1: - version "2.1.1" - resolved "https://registry.yarnpkg.com/snapdragon-node/-/snapdragon-node-2.1.1.tgz#6c175f86ff14bdb0724563e8f3c1b021a286853b" - integrity sha512-O27l4xaMYt/RSQ5TR3vpWCAB5Kb/czIcqUFOM/C4fYcLnbZUc1PkjTAMjof2pBWaSTwOUd6qUHcFGVGj7aIwnw== - dependencies: - define-property "^1.0.0" - isobject "^3.0.0" - snapdragon-util "^3.0.1" - -snapdragon-util@^3.0.1: - version "3.0.1" - resolved "https://registry.yarnpkg.com/snapdragon-util/-/snapdragon-util-3.0.1.tgz#f956479486f2acd79700693f6f7b805e45ab56e2" - integrity sha512-mbKkMdQKsjX4BAL4bRYTj21edOf8cN7XHdYUJEe+Zn99hVEYcMvKPct1IqNe7+AZPirn8BCDOQBHQZknqmKlZQ== - dependencies: - kind-of "^3.2.0" - -snapdragon@^0.8.1: - version "0.8.2" - resolved "https://registry.yarnpkg.com/snapdragon/-/snapdragon-0.8.2.tgz#64922e7c565b0e14204ba1aa7d6964278d25182d" - integrity sha512-FtyOnWN/wCHTVXOMwvSv26d+ko5vWlIDD6zoUJ7LW8vh+ZBC8QdljveRP+crNrtBwioEUWy/4dMtbBjA4ioNlg== - dependencies: - base "^0.11.1" - debug "^2.2.0" - define-property "^0.2.5" - extend-shallow "^2.0.1" - map-cache "^0.2.2" - source-map "^0.5.6" - source-map-resolve "^0.5.0" - use "^3.1.0" - -source-map-resolve@^0.5.0: - version "0.5.3" - resolved "https://registry.yarnpkg.com/source-map-resolve/-/source-map-resolve-0.5.3.tgz#190866bece7553e1f8f267a2ee82c606b5509a1a" - integrity sha512-Htz+RnsXWk5+P2slx5Jh3Q66vhQj1Cllm0zvnaY98+NFx+Dv2CF/f5O/t8x+KaNdrdIAsruNzoh/KpialbqAnw== - dependencies: - atob "^2.1.2" - decode-uri-component "^0.2.0" - resolve-url "^0.2.1" - source-map-url "^0.4.0" - urix "^0.1.0" - source-map-support@^0.4.18: version "0.4.18" resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.4.18.tgz#0286a6de8be42641338594e97ccea75f0a2c585f" @@ -4168,7 +3842,7 @@ source-map-support@^0.4.18: dependencies: source-map "^0.5.6" -source-map-support@^0.5.19, source-map-support@^0.5.6: +source-map-support@^0.5.6: version "0.5.19" resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.19.tgz#a98b62f86dcaf4f67399648c085291ab9e8fed61" integrity sha512-Wonm7zOCIJzBGQdB+thsPar0kYuCIzYvxZwlBa87yi/Mdjv7Tip2cyVbLj5o0cFPN4EVkuTwb3GDDyUx2DGnGw== @@ -4176,11 +3850,6 @@ source-map-support@^0.5.19, source-map-support@^0.5.6: buffer-from "^1.0.0" source-map "^0.6.0" -source-map-url@^0.4.0: - version "0.4.0" - resolved "https://registry.yarnpkg.com/source-map-url/-/source-map-url-0.4.0.tgz#3e935d7ddd73631b97659956d55128e87b5084a3" - integrity sha1-PpNdfd1zYxuXZZlW1VEo6HtQhKM= - source-map@^0.5.0, source-map@^0.5.6: version "0.5.7" resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.7.tgz#8a039d2d1021d22d1ea14c80d8ea468ba2ef3fcc" @@ -4196,39 +3865,6 @@ source-map@^0.7.3: resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.7.3.tgz#5302f8169031735226544092e64981f751750383" integrity sha512-CkCj6giN3S+n9qrYiBTX5gystlENnRW5jZeNLHpe6aue+SrHcG5VYwujhW9s4dY31mEGsxBDrHR6oI69fTXsaQ== -spdx-correct@^3.0.0: - version "3.1.1" - resolved "https://registry.yarnpkg.com/spdx-correct/-/spdx-correct-3.1.1.tgz#dece81ac9c1e6713e5f7d1b6f17d468fa53d89a9" - integrity sha512-cOYcUWwhCuHCXi49RhFRCyJEK3iPj1Ziz9DpViV3tbZOwXD49QzIN3MpOLJNxh2qwq2lJJZaKMVw9qNi4jTC0w== - dependencies: - spdx-expression-parse "^3.0.0" - spdx-license-ids "^3.0.0" - -spdx-exceptions@^2.1.0: - version "2.3.0" - resolved "https://registry.yarnpkg.com/spdx-exceptions/-/spdx-exceptions-2.3.0.tgz#3f28ce1a77a00372683eade4a433183527a2163d" - integrity sha512-/tTrYOC7PPI1nUAgx34hUpqXuyJG+DTHJTnIULG4rDygi4xu/tfgmq1e1cIRwRzwZgo4NLySi+ricLkZkw4i5A== - -spdx-expression-parse@^3.0.0: - version "3.0.1" - resolved "https://registry.yarnpkg.com/spdx-expression-parse/-/spdx-expression-parse-3.0.1.tgz#cf70f50482eefdc98e3ce0a6833e4a53ceeba679" - integrity sha512-cbqHunsQWnJNE6KhVSMsMeH5H/L9EpymbzqTQ3uLwNCLZ1Q481oWaofqH7nO6V07xlXwY6PhQdQ2IedWx/ZK4Q== - dependencies: - spdx-exceptions "^2.1.0" - spdx-license-ids "^3.0.0" - -spdx-license-ids@^3.0.0: - version "3.0.7" - resolved "https://registry.yarnpkg.com/spdx-license-ids/-/spdx-license-ids-3.0.7.tgz#e9c18a410e5ed7e12442a549fbd8afa767038d65" - integrity sha512-U+MTEOO0AiDzxwFvoa4JVnMV6mZlJKk2sBLt90s7G0Gd0Mlknc7kxEn3nuDPNZRta7O2uy8oLcZLVT+4sqNZHQ== - -split-string@^3.0.2: - version "3.1.0" - resolved "https://registry.yarnpkg.com/split-string/-/split-string-3.1.0.tgz#7cb09dda3a86585705c64b39a6466038682e8fe2" - integrity sha512-NzNVhJDYpwceVVii8/Hu6DKfD2G+NrQHlS/V/qgv763EYudVwEcMQNxd2lh+0VrUByXN/oJkl5grOhYWvQUYiw== - dependencies: - extend-shallow "^3.0.0" - sprintf-js@~1.0.2: version "1.0.3" resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c" @@ -4256,14 +3892,6 @@ stack-utils@^2.0.2, stack-utils@^2.0.3: dependencies: escape-string-regexp "^2.0.0" -static-extend@^0.1.1: - version "0.1.2" - resolved "https://registry.yarnpkg.com/static-extend/-/static-extend-0.1.2.tgz#60809c39cbff55337226fd5e0b520f341f1fb5c6" - integrity sha1-YICcOcv/VTNyJv1eC1IPNB8ftcY= - dependencies: - define-property "^0.2.5" - object-copy "^0.1.0" - stealthy-require@^1.1.1: version "1.1.1" resolved "https://registry.yarnpkg.com/stealthy-require/-/stealthy-require-1.1.1.tgz#35b09875b4ff49f26a777e509b3090a3226bf24b" @@ -4343,11 +3971,6 @@ strip-bom@^4.0.0: resolved "https://registry.yarnpkg.com/strip-bom/-/strip-bom-4.0.0.tgz#9c3505c1db45bcedca3d9cf7a16f5c5aa3901878" integrity sha512-3xurFv5tEgii33Zi8Jtp55wEIILR9eh34FAW00PZf+JnSsTmV/ioewSgQl97JHvgjoRGwPShsWm+IdrxB35d0w== -strip-eof@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/strip-eof/-/strip-eof-1.0.0.tgz#bb43ff5598a6eb05d89b59fcd129c983313606bf" - integrity sha1-u0P/VZim6wXYm1n80SnJgzE2Br8= - strip-final-newline@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/strip-final-newline/-/strip-final-newline-2.0.0.tgz#89b852fb2fcbe936f6f4b3187afb0a12c1ab58ad" @@ -4370,10 +3993,10 @@ superagent@^6.1.0: readable-stream "^3.6.0" semver "^7.3.2" -supertest@^6.1.1: - version "6.1.1" - resolved "https://registry.yarnpkg.com/supertest/-/supertest-6.1.1.tgz#4fe6ddfdad4ef3eb72926046c6c625217771d9ae" - integrity sha512-3WDAWfqdNifCURjGUHZFv3u5nMg5tFtFRCTJOcSZXdlYZ0gqVF3UMhA7IJDP8nDXnR3gocbQ6s0bpiPnsoFeQw== +supertest@^6.1.6: + version "6.1.6" + resolved "https://registry.yarnpkg.com/supertest/-/supertest-6.1.6.tgz#6151c518f4c5ced2ac2aadb9f96f1bf8198174c8" + integrity sha512-0hACYGNJ8OHRg8CRITeZOdbjur7NLuNs0mBjVhdpxi7hP6t3QIbOzLON5RTUmZcy2I9riuII3+Pr2C7yztrIIg== dependencies: methods "^1.1.2" superagent "^6.1.0" @@ -4392,6 +4015,13 @@ supports-color@^7.0.0, supports-color@^7.1.0: dependencies: has-flag "^4.0.0" +supports-color@^8.0.0: + version "8.1.1" + resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-8.1.1.tgz#cd6fc17e28500cff56c1b86c0a7fd4a54a73005c" + integrity sha512-MpUEN2OodtUzxvKQl72cUF7RQ5EiHsGvSsVG0ia9c5RbWGL2CI4C7EpPS8UTBIplnlzZiNuV56w+FuNxy3ty2Q== + dependencies: + has-flag "^4.0.0" + supports-hyperlinks@^2.0.0: version "2.1.0" resolved "https://registry.yarnpkg.com/supports-hyperlinks/-/supports-hyperlinks-2.1.0.tgz#f663df252af5f37c5d49bbd7eeefa9e0b9e59e47" @@ -4434,10 +4064,10 @@ test-exclude@^6.0.0: glob "^7.1.4" minimatch "^3.0.4" -throat@^5.0.0: - version "5.0.0" - resolved "https://registry.yarnpkg.com/throat/-/throat-5.0.0.tgz#c5199235803aad18754a667d659b5e72ce16764b" - integrity sha512-fcwX4mndzpLQKBS1DVYhGAcYaYt7vsHNIvQV+WXMvnow5cgjPphq5CaayLaGsjRdSCKZFNGt7/GYAuXaNOiYCA== +throat@^6.0.1: + version "6.0.1" + resolved "https://registry.yarnpkg.com/throat/-/throat-6.0.1.tgz#d514fedad95740c12c2d7fc70ea863eb51ade375" + integrity sha512-8hmiGIJMDlwjg7dlJ4yKGLK8EsYqKgPWbG3b4wjJddKNwc7N7Dpn08Df4szr/sZdMVeOstrdYSsqzX6BYbcB+w== tmpl@1.0.x, tmpl@^1.0.5: version "1.0.5" @@ -4449,21 +4079,6 @@ to-fast-properties@^2.0.0: resolved "https://registry.yarnpkg.com/to-fast-properties/-/to-fast-properties-2.0.0.tgz#dc5e698cbd079265bc73e0377681a4e4e83f616e" integrity sha1-3F5pjL0HkmW8c+A3doGk5Og/YW4= -to-object-path@^0.3.0: - version "0.3.0" - resolved "https://registry.yarnpkg.com/to-object-path/-/to-object-path-0.3.0.tgz#297588b7b0e7e0ac08e04e672f85c1f4999e17af" - integrity sha1-KXWIt7Dn4KwI4E5nL4XB9JmeF68= - dependencies: - kind-of "^3.0.2" - -to-regex-range@^2.1.0: - version "2.1.1" - resolved "https://registry.yarnpkg.com/to-regex-range/-/to-regex-range-2.1.1.tgz#7c80c17b9dfebe599e27367e0d4dd5590141db38" - integrity sha1-fIDBe53+vlmeJzZ+DU3VWQFB2zg= - dependencies: - is-number "^3.0.0" - repeat-string "^1.6.1" - to-regex-range@^5.0.1: version "5.0.1" resolved "https://registry.yarnpkg.com/to-regex-range/-/to-regex-range-5.0.1.tgz#1648c44aae7c8d988a326018ed72f5b4dd0392e4" @@ -4471,16 +4086,6 @@ to-regex-range@^5.0.1: dependencies: is-number "^7.0.0" -to-regex@^3.0.1, to-regex@^3.0.2: - version "3.0.2" - resolved "https://registry.yarnpkg.com/to-regex/-/to-regex-3.0.2.tgz#13cfdd9b336552f30b51f33a8ae1b42a7a7599ce" - integrity sha512-FWtleNAtZ/Ki2qtqej2CXTOayOH9bHDQF+Q48VpWyDXjbYxA4Yz8iDB31zXOBUlOHHKidDbqGVrTUvQMPmBGBw== - dependencies: - define-property "^2.0.2" - extend-shallow "^3.0.2" - regex-not "^1.0.2" - safe-regex "^1.1.0" - tough-cookie@^2.3.3, tough-cookie@~2.5.0: version "2.5.0" resolved "https://registry.yarnpkg.com/tough-cookie/-/tough-cookie-2.5.0.tgz#cd9fb2a0aa1d5a12b473bd9fb96fa3dcff65ade2" @@ -4498,6 +4103,15 @@ tough-cookie@^3.0.1: psl "^1.1.28" punycode "^2.1.1" +tough-cookie@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/tough-cookie/-/tough-cookie-4.0.0.tgz#d822234eeca882f991f0f908824ad2622ddbece4" + integrity sha512-tHdtEpQCMrc1YLrMaqXXcj6AxhYi/xgit6mZu1+EDWUn+qhUf8wMQoFIy9NXuq23zAwtcB0t/MjACGR18pcRbg== + dependencies: + psl "^1.1.33" + punycode "^2.1.1" + universalify "^0.1.2" + tr46@^2.0.2: version "2.0.2" resolved "https://registry.yarnpkg.com/tr46/-/tr46-2.0.2.tgz#03273586def1595ae08fedb38d7733cee91d2479" @@ -4505,20 +4119,24 @@ tr46@^2.0.2: dependencies: punycode "^2.1.1" -ts-jest@^26.4.4: - version "26.4.4" - resolved "https://registry.yarnpkg.com/ts-jest/-/ts-jest-26.4.4.tgz#61f13fb21ab400853c532270e52cc0ed7e502c49" - integrity sha512-3lFWKbLxJm34QxyVNNCgXX1u4o/RV0myvA2y2Bxm46iGIjKlaY0own9gIckbjZJPn+WaJEnfPPJ20HHGpoq4yg== +tr46@^2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/tr46/-/tr46-2.1.0.tgz#fa87aa81ca5d5941da8cbf1f9b749dc969a4e240" + integrity sha512-15Ih7phfcdP5YxqiB+iDtLoaTz4Nd35+IiAv0kQ5FNKHzXgdWqPoTIqEDDJmXceQt4JZk6lVPT8lnDlPpGDppw== + dependencies: + punycode "^2.1.1" + +ts-jest@^27.0.7: + version "27.0.7" + resolved "https://registry.yarnpkg.com/ts-jest/-/ts-jest-27.0.7.tgz#fb7c8c8cb5526ab371bc1b23d06e745652cca2d0" + integrity sha512-O41shibMqzdafpuP+CkrOL7ykbmLh+FqQrXEmV9CydQ5JBk0Sj0uAEF5TNNe94fZWKm3yYvWa/IbyV4Yg1zK2Q== dependencies: - "@types/jest" "26.x" bs-logger "0.x" - buffer-from "1.x" fast-json-stable-stringify "2.x" - jest-util "^26.1.0" + jest-util "^27.0.0" json5 "2.x" lodash.memoize "4.x" make-error "1.x" - mkdirp "1.x" semver "7.x" yargs-parser "20.x" @@ -4551,16 +4169,6 @@ type-fest@^0.11.0: resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.11.0.tgz#97abf0872310fed88a5c466b25681576145e33f1" integrity sha512-OdjXJxnCN1AvyLSzeKIgXTXxV+99ZuXl3Hpo9XpJAv9MBcHrrJOQ5kV7ypXOuQie+AmWG25hLbiKdwYTifzcfQ== -type-fest@^0.6.0: - version "0.6.0" - resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.6.0.tgz#8d2a2370d3df886eb5c90ada1c5bf6188acf838b" - integrity sha512-q+MB8nYR1KDLrgr4G5yemftpMC7/QLqVndBmEEdqzmNj5dcFOO4Oo8qlwZE3ULT3+Zim1F8Kq4cBnikNhlCMlg== - -type-fest@^0.8.1: - version "0.8.1" - resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.8.1.tgz#09e249ebde851d3b1e48d27c105444667f17b83d" - integrity sha512-4dbzIzqvjtgiM5rw1k5rEHtBANKmdudhGyBEajN01fEyhaAIhsoKNy6y7+IN93IfpFtwY9iqi7kD+xwKhQsNJA== - typedarray-to-buffer@^3.1.5: version "3.1.5" resolved "https://registry.yarnpkg.com/typedarray-to-buffer/-/typedarray-to-buffer-3.1.5.tgz#a97ee7a9ff42691b9f783ff1bc5112fe3fca9080" @@ -4568,23 +4176,10 @@ typedarray-to-buffer@^3.1.5: dependencies: is-typedarray "^1.0.0" -union-value@^1.0.0: - version "1.0.1" - resolved "https://registry.yarnpkg.com/union-value/-/union-value-1.0.1.tgz#0b6fe7b835aecda61c6ea4d4f02c14221e109847" - integrity sha512-tJfXmxMeWYnczCVs7XAEvIV7ieppALdyepWMkHkwciRpZraG/xwT+s2JN8+pr1+8jCRf80FFzvr+MpQeeoF4Xg== - dependencies: - arr-union "^3.1.0" - get-value "^2.0.6" - is-extendable "^0.1.1" - set-value "^2.0.1" - -unset-value@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/unset-value/-/unset-value-1.0.0.tgz#8376873f7d2335179ffb1e6fc3a8ed0dfc8ab559" - integrity sha1-g3aHP30jNRef+x5vw6jtDfyKtVk= - dependencies: - has-value "^0.3.1" - isobject "^3.0.0" +universalify@^0.1.2: + version "0.1.2" + resolved "https://registry.yarnpkg.com/universalify/-/universalify-0.1.2.tgz#b646f69be3942dabcecc9d6639c80dc105efaa66" + integrity sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg== uri-js@^4.2.2: version "4.4.1" @@ -4593,16 +4188,6 @@ uri-js@^4.2.2: dependencies: punycode "^2.1.0" -urix@^0.1.0: - version "0.1.0" - resolved "https://registry.yarnpkg.com/urix/-/urix-0.1.0.tgz#da937f7a62e21fec1fd18d49b35c2935067a6c72" - integrity sha1-2pN/emLiH+wf0Y1Js1wpNQZ6bHI= - -use@^3.1.0: - version "3.1.1" - resolved "https://registry.yarnpkg.com/use/-/use-3.1.1.tgz#d50c8cac79a19fbc20f2911f56eb973f4e10070f" - integrity sha512-cwESVXlO3url9YWlFW/TA9cshCEhtu7IKJ/p5soJ/gGpj7vbvFrAY/eIioQ6Dw23KjZhYgiIo8HOs1nQ2vr/oQ== - util-deprecate@^1.0.1, util-deprecate@~1.0.1: version "1.0.2" resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf" @@ -4613,28 +4198,15 @@ uuid@^3.3.2: resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.4.0.tgz#b23e4358afa8a202fe7a100af1f5f883f02007ee" integrity sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A== -uuid@^8.3.0: - version "8.3.2" - resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2" - integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg== - -v8-to-istanbul@^7.0.0: - version "7.1.0" - resolved "https://registry.yarnpkg.com/v8-to-istanbul/-/v8-to-istanbul-7.1.0.tgz#5b95cef45c0f83217ec79f8fc7ee1c8b486aee07" - integrity sha512-uXUVqNUCLa0AH1vuVxzi+MI4RfxEOKt9pBgKwHbgH7st8Kv2P1m+jvWNnektzBh5QShF3ODgKmUFCf38LnVz1g== +v8-to-istanbul@^8.1.0: + version "8.1.0" + resolved "https://registry.yarnpkg.com/v8-to-istanbul/-/v8-to-istanbul-8.1.0.tgz#0aeb763894f1a0a1676adf8a8b7612a38902446c" + integrity sha512-/PRhfd8aTNp9Ggr62HPzXg2XasNFGy5PBt0Rp04du7/8GNNSgxFL6WBTkgMKSL9bFjH+8kKEG3f37FmxiTqUUA== dependencies: "@types/istanbul-lib-coverage" "^2.0.1" convert-source-map "^1.6.0" source-map "^0.7.3" -validate-npm-package-license@^3.0.1: - version "3.0.4" - resolved "https://registry.yarnpkg.com/validate-npm-package-license/-/validate-npm-package-license-3.0.4.tgz#fc91f6b9c7ba15c857f4cb2c5defeec39d4f410a" - integrity sha512-DpKm2Ui/xN7/HQKCtpZxoRWBhZ9Z0kqtygG8XCgNQ8ZlDnxuQmWhj566j8fN4Cu3/JmbhsDo7fcAJq4s9h27Ew== - dependencies: - spdx-correct "^3.0.0" - spdx-expression-parse "^3.0.0" - verror@1.10.0: version "1.10.0" resolved "https://registry.yarnpkg.com/verror/-/verror-1.10.0.tgz#3a105ca17053af55d6e270c1f8288682e18da400" @@ -4658,7 +4230,7 @@ w3c-xmlserializer@^2.0.0: dependencies: xml-name-validator "^3.0.0" -walker@^1.0.7, walker@~1.0.5: +walker@^1.0.7: version "1.0.7" resolved "https://registry.yarnpkg.com/walker/-/walker-1.0.7.tgz#2f7f9b8fd10d677262b18a884e28d19618e028fb" integrity sha1-L3+bj9ENZ3JisYqITijRlhjgKPs= @@ -4696,19 +4268,16 @@ whatwg-url@^8.0.0: tr46 "^2.0.2" webidl-conversions "^6.1.0" -which-module@^2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/which-module/-/which-module-2.0.0.tgz#d9ef07dce77b9902b8a3a8fa4b31c3e3f7e6e87a" - integrity sha1-2e8H3Od7mQK4o6j6SzHD4/fm6Ho= - -which@^1.2.9: - version "1.3.1" - resolved "https://registry.yarnpkg.com/which/-/which-1.3.1.tgz#a45043d54f5805316da8d62f9f50918d3da70b0a" - integrity sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ== +whatwg-url@^8.5.0: + version "8.7.0" + resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-8.7.0.tgz#656a78e510ff8f3937bc0bcbe9f5c0ac35941b77" + integrity sha512-gAojqb/m9Q8a5IV96E3fHJM70AzCkgt4uXYX2O7EmuyOnLrViCQlsEBmF9UQIu3/aeAIp2U17rtbpZWNntQqdg== dependencies: - isexe "^2.0.0" + lodash "^4.7.0" + tr46 "^2.1.0" + webidl-conversions "^6.1.0" -which@^2.0.1, which@^2.0.2: +which@^2.0.1: version "2.0.2" resolved "https://registry.yarnpkg.com/which/-/which-2.0.2.tgz#7c6a8dd0a636a0327e10b59c9286eee93f3f51b1" integrity sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA== @@ -4727,10 +4296,10 @@ word-wrap@~1.2.3: resolved "https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.2.3.tgz#610636f6b1f703891bd34771ccb17fb93b47079c" integrity sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ== -wrap-ansi@^6.2.0: - version "6.2.0" - resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-6.2.0.tgz#e9393ba07102e6c91a3b221478f0257cd2856e53" - integrity sha512-r6lPcBGxZXlIcymEu7InxDMhdW0KDxpLgoFLcguasxCaJ/SOIZwINatK9KY/tf+ZrlywOKU0UDj3ATXUBfxJXA== +wrap-ansi@^7.0.0: + version "7.0.0" + resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" + integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== dependencies: ansi-styles "^4.0.0" string-width "^4.1.0" @@ -4756,13 +4325,10 @@ ws@^7.2.3, ws@^7.4.6: resolved "https://registry.yarnpkg.com/ws/-/ws-7.4.6.tgz#5654ca8ecdeee47c33a9a4bf6d28e2be2980377c" integrity sha512-YmhHDO4MzaDLB+M9ym/mDA5z0naX8j7SIlT8f8z+I0VtzsRbekxEutHSme7NPS2qE8StCYQNUnfWdXta/Yu85A== -wtfnode@^0.9.0: - version "0.9.0" - resolved "https://registry.yarnpkg.com/wtfnode/-/wtfnode-0.9.0.tgz#f0f880e11309b7120b14fecda39f363f78b66a70" - integrity sha512-IKHfNAFZwfm0uCt/zuFADN3mHyoB+ZrmwFpRGOxKPIXV0tifqpIaTH3NvImA7yy7GimsAayZGTaNvOmavKzE+A== - dependencies: - coffeescript "^2.5.1" - source-map-support "^0.5.19" +wtfnode@^0.9.1: + version "0.9.1" + resolved "https://registry.yarnpkg.com/wtfnode/-/wtfnode-0.9.1.tgz#c385679d2df6fb4d64d734eeeaab767fcee3e0d3" + integrity sha512-Ip6C2KeQPl/F3aP1EfOnPoQk14Udd9lffpoqWDNH3Xt78svxPbv53ngtmtfI0q2Te3oTq79XKTnRNXVIn/GsPA== xml-name-validator@^3.0.0: version "3.0.0" @@ -4774,10 +4340,10 @@ xmlchars@^2.2.0: resolved "https://registry.yarnpkg.com/xmlchars/-/xmlchars-2.2.0.tgz#060fe1bcb7f9c76fe2a17db86a9bc3ab894210cb" integrity sha512-JZnDKK8B0RCDw84FNdDAIpZK+JuJw+s7Lz8nksI7SIuU3UXJJslUthsi+uWBUYOwPFwW7W7PRLRfUKpxjtjFCw== -y18n@^4.0.0: - version "4.0.1" - resolved "https://registry.yarnpkg.com/y18n/-/y18n-4.0.1.tgz#8db2b83c31c5d75099bb890b23f3094891e247d4" - integrity sha512-wNcy4NvjMYL8gogWWYAO7ZFWFfHcbdbE57tZO8e4cbpj8tfUcwrwqSl3ad8HxpYWCdXcJUCeKKZS62Av1affwQ== +y18n@^5.0.5: + version "5.0.8" + resolved "https://registry.yarnpkg.com/y18n/-/y18n-5.0.8.tgz#7f4934d0f7ca8c56f95314939ddcd2dd91ce1d55" + integrity sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA== yallist@^4.0.0: version "4.0.0" @@ -4789,30 +4355,23 @@ yargs-parser@20.x: resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-20.2.4.tgz#b42890f14566796f85ae8e3a25290d205f154a54" integrity sha512-WOkpgNhPTlE73h4VFAFsOnomJVaovO8VqLDzy5saChRBFQFBoMYirowyW+Q9HB4HFF4Z7VZTiG3iSzJJA29yRA== -yargs-parser@^18.1.2: - version "18.1.3" - resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-18.1.3.tgz#be68c4975c6b2abf469236b0c870362fab09a7b0" - integrity sha512-o50j0JeToy/4K6OZcaQmW6lyXXKhq7csREXcDwk2omFPJEwUNOVtJKvmDr9EI1fAJZUyZcRF7kxGBWmRXudrCQ== - dependencies: - camelcase "^5.0.0" - decamelize "^1.2.0" +yargs-parser@^20.2.2: + version "20.2.9" + resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-20.2.9.tgz#2eb7dc3b0289718fc295f362753845c41a0c94ee" + integrity sha512-y11nGElTIV+CT3Zv9t7VKl+Q3hTQoT9a1Qzezhhl6Rp21gJ/IVTW7Z3y9EWXhuUBC2Shnf+DX0antecpAwSP8w== -yargs@^15.4.1: - version "15.4.1" - resolved "https://registry.yarnpkg.com/yargs/-/yargs-15.4.1.tgz#0d87a16de01aee9d8bec2bfbf74f67851730f4f8" - integrity sha512-aePbxDmcYW++PaqBsJ+HYUFwCdv4LVvdnhBy78E57PIor8/OVvhMrADFFEDh8DHDFRv/O9i3lPhsENjO7QX0+A== +yargs@^16.2.0: + version "16.2.0" + resolved "https://registry.yarnpkg.com/yargs/-/yargs-16.2.0.tgz#1c82bf0f6b6a66eafce7ef30e376f49a12477f66" + integrity sha512-D1mvvtDG0L5ft/jGWkLpG1+m0eQxOfaBvTNELraWj22wSVUMWxZUvYgJYcKh6jGGIkJFhH4IZPQhR4TKpc8mBw== dependencies: - cliui "^6.0.0" - decamelize "^1.2.0" - find-up "^4.1.0" - get-caller-file "^2.0.1" + cliui "^7.0.2" + escalade "^3.1.1" + get-caller-file "^2.0.5" require-directory "^2.1.1" - require-main-filename "^2.0.0" - set-blocking "^2.0.0" string-width "^4.2.0" - which-module "^2.0.0" - y18n "^4.0.0" - yargs-parser "^18.1.2" + y18n "^5.0.5" + yargs-parser "^20.2.2" yauzl@^2.10.0: version "2.10.0" diff --git a/vendor/package.json b/vendor/package.json index 34a0dba18e19..f54eb5390412 100644 --- a/vendor/package.json +++ b/vendor/package.json @@ -7,6 +7,6 @@ "postinstall": "./postinstall.sh" }, "devDependencies": { - "code-oss-dev": "cdr/vscode#54bde0ad8502bd34c91dc65b8430bf7710048009" + "code-oss-dev": "cdr/vscode#8148759b500aaa2ac4f9999ea4b853a7779eb622" } } diff --git a/vendor/yarn.lock b/vendor/yarn.lock index 49a3f2497f25..eaa138615c81 100644 --- a/vendor/yarn.lock +++ b/vendor/yarn.lock @@ -296,9 +296,9 @@ clone-response@^1.0.2: dependencies: mimic-response "^1.0.0" -code-oss-dev@cdr/vscode#54bde0ad8502bd34c91dc65b8430bf7710048009: +code-oss-dev@cdr/vscode#8148759b500aaa2ac4f9999ea4b853a7779eb622: version "1.61.1" - resolved "https://codeload.github.com/cdr/vscode/tar.gz/54bde0ad8502bd34c91dc65b8430bf7710048009" + resolved "https://codeload.github.com/cdr/vscode/tar.gz/8148759b500aaa2ac4f9999ea4b853a7779eb622" dependencies: "@microsoft/applicationinsights-web" "^2.6.4" "@vscode/sqlite3" "4.0.12" From 6d777c11db57ddd30a157a8a47997fea4f606e2b Mon Sep 17 00:00:00 2001 From: Asher Date: Fri, 22 Oct 2021 15:23:14 +0000 Subject: [PATCH 26/39] Update VS Code cache directories These were renamed so the cached paths need to be updated. I changed the key as well to force a rebuild. --- .github/workflows/ci.yaml | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index ccd83cd9caf6..b35b25b0d6d3 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -138,20 +138,22 @@ jobs: path: | vendor/modules/code-oss-dev/.build vendor/modules/code-oss-dev/out-build - vendor/modules/code-oss-dev/out-vscode - vendor/modules/code-oss-dev/out-vscode-min - key: vscode-build-${{ steps.vscode-rev.outputs.rev }} + vendor/modules/code-oss-dev/out-vscode-server + vendor/modules/code-oss-dev/out-vscode-server-min + key: vscode-server-build-${{ steps.vscode-rev.outputs.rev }} - name: Build vscode if: steps.cache-vscode.outputs.cache-hit != 'true' run: yarn build:vscode - # Our code imports code from VS Code's output directory meaning VS Code + # Our code imports code from VS Code's `out` directory meaning VS Code # must be built before running these tests. It looks for `out` in order - # to works during development (for release we move `out-build` to `out`) - # so symlink `out` to `out-build` as this is a production build. - - name: Link vscode - run: ln -s out-build vendor/modules/code-oss-dev/out + # to work during development but production creates `out-build`, + # `out-vscode-server, and `out-vscode-server-min` so symlink to one of + # those (during release we move `out-vscode-server-min` to out so using + # that gives the closest environment to release). + - name: Link VS Code build + run: ln -s out-vscode-server-min vendor/modules/code-oss-dev/out # TODO: Move to its own step? - name: Run code-server unit tests From 64b6f71b738f3613f99a31a0521d4fe5aded3cae Mon Sep 17 00:00:00 2001 From: Asher Date: Fri, 22 Oct 2021 17:29:29 +0000 Subject: [PATCH 27/39] Move test symlink to script This way it works for local testing as well. I had to use out-build instead of out-vscode-server-min because Jest throws some obscure error about a handlebars haste map. --- .github/workflows/ci.yaml | 9 +-------- ci/dev/test-unit.sh | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index b35b25b0d6d3..6ba0793fb580 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -147,14 +147,7 @@ jobs: run: yarn build:vscode # Our code imports code from VS Code's `out` directory meaning VS Code - # must be built before running these tests. It looks for `out` in order - # to work during development but production creates `out-build`, - # `out-vscode-server, and `out-vscode-server-min` so symlink to one of - # those (during release we move `out-vscode-server-min` to out so using - # that gives the closest environment to release). - - name: Link VS Code build - run: ln -s out-vscode-server-min vendor/modules/code-oss-dev/out - + # must be built before running these tests. # TODO: Move to its own step? - name: Run code-server unit tests run: yarn test:unit diff --git a/ci/dev/test-unit.sh b/ci/dev/test-unit.sh index 65fa94001e39..f82413b93288 100755 --- a/ci/dev/test-unit.sh +++ b/ci/dev/test-unit.sh @@ -3,12 +3,26 @@ set -euo pipefail main() { cd "$(dirname "$0")/../.." - cd test/unit/node/test-plugin + + source ./ci/lib.sh + + pushd test/unit/node/test-plugin make -s out/index.js + popd + + # Our code imports from `out` in order to work during development but if you + # have only built for production you will have not have this directory. In + # that case symlink `out` to a production build directory. + local vscode="vendor/modules/code-oss-dev" + local link="$vscode/out" + local target="out-build" + if [[ ! -e $link ]] && [[ -d $vscode/$target ]]; then + ln -s "$target" "$link" + fi + # We must keep jest in a sub-directory. See ../../test/package.json for more # information. We must also run it from the root otherwise coverage will not # include our source files. - cd "$OLDPWD" CS_DISABLE_PLUGINS=true ./test/node_modules/.bin/jest "$@" } From 752fe7cc60b43988784511331b6babec77d704d9 Mon Sep 17 00:00:00 2001 From: Asher Date: Fri, 22 Oct 2021 18:21:12 +0000 Subject: [PATCH 28/39] Fix listening on a socket --- src/node/app.ts | 7 +++++-- src/node/coder_cloud.ts | 12 +++++++----- src/node/link.ts | 9 +++++++-- src/node/main.ts | 27 ++++++++++----------------- src/node/util.ts | 16 ++++++++++++---- test/utils/httpserver.ts | 8 +++++++- 6 files changed, 48 insertions(+), 31 deletions(-) diff --git a/src/node/app.ts b/src/node/app.ts index 908747b243ef..d0e17a37ca9b 100644 --- a/src/node/app.ts +++ b/src/node/app.ts @@ -67,8 +67,10 @@ export const createApp = async (args: DefaultedArgs): Promise<[Express, Express, /** * Get the address of a server as a string (protocol *is* included) while * ensuring there is one (will throw if there isn't). + * + * The address might be a URL or it might be a pipe or socket path. */ -export const ensureAddress = (server: http.Server, protocol: string): URL => { +export const ensureAddress = (server: http.Server, protocol: string): URL | string => { const addr = server.address() if (!addr) { @@ -79,7 +81,8 @@ export const ensureAddress = (server: http.Server, protocol: string): URL => { return new URL(`${protocol}://${addr.address}:${addr.port}`) } - return new URL(addr) + // If this is a string then it is a pipe or Unix socket. + return addr } /** diff --git a/src/node/coder_cloud.ts b/src/node/coder_cloud.ts index 7bca6342a6de..fe9d30f727dc 100644 --- a/src/node/coder_cloud.ts +++ b/src/node/coder_cloud.ts @@ -33,9 +33,11 @@ function runAgent(...args: string[]): Promise { }) } -export function coderCloudBind(csAddr: string, serverName = ""): Promise { - // addr needs to be in host:port format. - // So we trim the protocol. - csAddr = csAddr.replace(/^https?:\/\//, "") - return runAgent("bind", `--code-server-addr=${csAddr}`, serverName) +export function coderCloudBind(address: URL | string, serverName = ""): Promise { + if (typeof address === "string") { + throw new Error("Cannot link socket paths") + } + + // Address needs to be in hostname:port format without the protocol. + return runAgent("bind", `--code-server-addr=${address.host}`, serverName) } diff --git a/src/node/link.ts b/src/node/link.ts index 28b0cc3ddfa5..8c21210f9205 100644 --- a/src/node/link.ts +++ b/src/node/link.ts @@ -2,8 +2,13 @@ import { logger } from "@coder/logger" import { ChildProcessWithoutNullStreams, spawn } from "child_process" import path from "path" -export function startLink(port: number): ChildProcessWithoutNullStreams { - logger.debug(`running link targetting ${port}`) +export function startLink(address: URL | string): ChildProcessWithoutNullStreams { + if (typeof address === "string") { + throw new Error("Cannot link socket paths") + } + + const port = parseInt(address.port, 10) + logger.debug(`running link targeting ${port}`) return spawn(path.resolve(__dirname, "../../lib/linkup"), ["--devurl", `code:${port}:code-server`], { shell: false, diff --git a/src/node/main.ts b/src/node/main.ts index aa4608165f16..057b7ec2e24b 100644 --- a/src/node/main.ts +++ b/src/node/main.ts @@ -152,26 +152,24 @@ export const runCodeServer = async ( } if (args.link) { - await coderCloudBind(serverAddress.host, args.link.value) + await coderCloudBind(serverAddress, args.link.value) logger.info(" - Connected to cloud agent") } let linkAgent: undefined | ChildProcessWithoutNullStreams try { - linkAgent = startLink(parseInt(serverAddress.port, 10)) + linkAgent = startLink(serverAddress) + linkAgent.on("error", (error) => { + logger.debug("[Link daemon]", field("error", error)) + }) + linkAgent.on("close", (code) => { + logger.debug("[Link daemon]", field("code", `Closed with code ${code}`)) + }) } catch (error) { logger.debug("Failed to start link daemon!", error as any) } - linkAgent?.on("error", (error) => { - logger.debug("[Link daemon]", field("error", error)) - }) - - linkAgent?.on("close", (code) => { - logger.debug("[Link daemon]", field("code", `Closed with code ${code}`)) - }) - if (args.enable && args.enable.length > 0) { logger.info("Enabling the following experimental features:") args.enable.forEach((feature) => { @@ -187,14 +185,9 @@ export const runCodeServer = async ( ) } - if (!args.socket && args.open) { - // The web socket doesn't seem to work if browsing with 0.0.0.0. - if (serverAddress.hostname === "0.0.0.0") { - serverAddress.hostname = "localhost" - } - + if (args.open) { try { - await open(serverAddress.toString()) + await open(serverAddress) logger.info(`Opened ${serverAddress}`) } catch (error) { logger.error("Failed to open", field("address", serverAddress.toString()), field("error", error)) diff --git a/src/node/util.ts b/src/node/util.ts index 4f3078a623f2..ebb380a90fb6 100644 --- a/src/node/util.ts +++ b/src/node/util.ts @@ -393,9 +393,17 @@ export const isWsl = async (): Promise => { } /** - * Try opening a URL using whatever the system has set for opening URLs. + * Try opening an address using whatever the system has set for opening URLs. */ -export const open = async (url: string): Promise => { +export const open = async (address: URL | string): Promise => { + if (typeof address === "string") { + throw new Error("Cannot open socket paths") + } + // Web sockets do not seem to work if browsing with 0.0.0.0. + const url = new URL(address) + if (url.hostname === "0.0.0.0") { + url.hostname = "localhost" + } const args = [] as string[] const options = {} as cp.SpawnOptions const platform = (await isWsl()) ? "wsl" : process.platform @@ -403,9 +411,9 @@ export const open = async (url: string): Promise => { if (platform === "win32" || platform === "wsl") { command = platform === "wsl" ? "cmd.exe" : "cmd" args.push("/c", "start", '""', "/b") - url = url.replace(/&/g, "^&") + url.search = url.search.replace(/&/g, "^&") } - const proc = cp.spawn(command, [...args, url], options) + const proc = cp.spawn(command, [...args, url.toString()], options) await new Promise((resolve, reject) => { proc.on("error", reject) proc.on("close", (code) => { diff --git a/test/utils/httpserver.ts b/test/utils/httpserver.ts index 1c0bcb11fa79..b7795c3cfdda 100644 --- a/test/utils/httpserver.ts +++ b/test/utils/httpserver.ts @@ -101,16 +101,22 @@ export class HttpServer { */ public fetch(requestPath: string, opts?: RequestInit): Promise { const address = ensureAddress(this.hs, "http") + if (typeof address === "string") { + throw new Error("Cannot fetch socket path") + } address.pathname = requestPath return nodeFetch(address.toString(), opts) } /** - * Open a websocket against the requset path. + * Open a websocket against the request path. */ public ws(requestPath: string): Websocket { const address = ensureAddress(this.hs, "ws") + if (typeof address === "string") { + throw new Error("Cannot open websocket to socket path") + } address.pathname = requestPath return new Websocket(address.toString()) From 0cfd2455d6c5e93703878a7c23ea988a4d9c0519 Mon Sep 17 00:00:00 2001 From: Asher Date: Tue, 26 Oct 2021 15:45:38 +0000 Subject: [PATCH 29/39] Update VS Code It contains fixes for missing files in the build. --- vendor/package.json | 2 +- vendor/yarn.lock | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/vendor/package.json b/vendor/package.json index f54eb5390412..d7d800f136ad 100644 --- a/vendor/package.json +++ b/vendor/package.json @@ -7,6 +7,6 @@ "postinstall": "./postinstall.sh" }, "devDependencies": { - "code-oss-dev": "cdr/vscode#8148759b500aaa2ac4f9999ea4b853a7779eb622" + "code-oss-dev": "cdr/vscode#3fc885904886003d88d1f300d6158bee486f644f" } } diff --git a/vendor/yarn.lock b/vendor/yarn.lock index eaa138615c81..3050d752d480 100644 --- a/vendor/yarn.lock +++ b/vendor/yarn.lock @@ -296,9 +296,9 @@ clone-response@^1.0.2: dependencies: mimic-response "^1.0.0" -code-oss-dev@cdr/vscode#8148759b500aaa2ac4f9999ea4b853a7779eb622: +code-oss-dev@cdr/vscode#3fc885904886003d88d1f300d6158bee486f644f: version "1.61.1" - resolved "https://codeload.github.com/cdr/vscode/tar.gz/8148759b500aaa2ac4f9999ea4b853a7779eb622" + resolved "https://codeload.github.com/cdr/vscode/tar.gz/3fc885904886003d88d1f300d6158bee486f644f" dependencies: "@microsoft/applicationinsights-web" "^2.6.4" "@vscode/sqlite3" "4.0.12" From 51a48ba7510cd75f2f7ea05a625531790de177ab Mon Sep 17 00:00:00 2001 From: Asher Date: Tue, 26 Oct 2021 17:19:12 +0000 Subject: [PATCH 30/39] Standardize disposals --- src/node/main.ts | 11 ++++------- src/node/routes/index.ts | 10 ++++------ test/unit/node/plugin.test.ts | 2 +- test/unit/node/proxy.test.ts | 4 ++-- test/unit/node/routes/health.test.ts | 2 +- test/unit/node/routes/login.test.ts | 8 +------- test/unit/node/routes/static.test.ts | 8 +------- test/utils/httpserver.ts | 11 ++++------- 8 files changed, 18 insertions(+), 38 deletions(-) diff --git a/src/node/main.ts b/src/node/main.ts index 057b7ec2e24b..7e8874d7af78 100644 --- a/src/node/main.ts +++ b/src/node/main.ts @@ -157,7 +157,6 @@ export const runCodeServer = async ( } let linkAgent: undefined | ChildProcessWithoutNullStreams - try { linkAgent = startLink(serverAddress) linkAgent.on("error", (error) => { @@ -194,13 +193,11 @@ export const runCodeServer = async ( } } - const dispose = () => { - disposeApp() - linkAgent?.kill() - } - return { server, - dispose, + dispose: () => { + disposeApp() + linkAgent?.kill() + }, } } diff --git a/src/node/routes/index.ts b/src/node/routes/index.ts index 5917615afa59..267b3c2163bb 100644 --- a/src/node/routes/index.ts +++ b/src/node/routes/index.ts @@ -15,7 +15,6 @@ import { Heart } from "../heart" import { ensureAuthenticated, redirect } from "../http" import { PluginAPI } from "../plugin" import { getMediaMime, paths } from "../util" -import { wrapper } from "../wrapper" import * as apps from "./apps" import * as domainProxy from "./domainProxy" import { errorHandler, wsErrorHandler } from "./errors" @@ -46,9 +45,6 @@ export const register = async ( }) }) }) - server.on("close", () => { - heart.dispose() - }) app.disable("x-powered-by") wsApp.disable("x-powered-by") @@ -114,13 +110,13 @@ export const register = async ( }) }) + let pluginApi: PluginAPI if (!process.env.CS_DISABLE_PLUGINS) { const workingDir = args._ && args._.length > 0 ? path.resolve(args._[args._.length - 1]) : undefined - const pluginApi = new PluginAPI(logger, process.env.CS_PLUGIN, process.env.CS_PLUGIN_PATH, workingDir) + pluginApi = new PluginAPI(logger, process.env.CS_PLUGIN, process.env.CS_PLUGIN_PATH, workingDir) await pluginApi.loadPlugins() pluginApi.mount(app, wsApp) app.use("/api/applications", ensureAuthenticated, apps.router(pluginApi)) - wrapper.onDispose(() => pluginApi.dispose()) } app.use(express.json()) @@ -170,6 +166,8 @@ export const register = async ( wsApp.use(wsErrorHandler) return () => { + heart.dispose() + pluginApi?.dispose() vscode?.codeServerMain.dispose() } } diff --git a/test/unit/node/plugin.test.ts b/test/unit/node/plugin.test.ts index 5459db2c287f..acd417316acf 100644 --- a/test/unit/node/plugin.test.ts +++ b/test/unit/node/plugin.test.ts @@ -58,7 +58,7 @@ describe("plugin", () => { }) afterAll(async () => { - await s.close() + await s.dispose() }) it("/api/applications", async () => { diff --git a/test/unit/node/proxy.test.ts b/test/unit/node/proxy.test.ts index 1a0b8c6f10bf..0861bfe840e6 100644 --- a/test/unit/node/proxy.test.ts +++ b/test/unit/node/proxy.test.ts @@ -24,7 +24,7 @@ describe("proxy", () => { }) afterAll(async () => { - await nhooyrDevServer.close() + await nhooyrDevServer.dispose() }) beforeEach(() => { @@ -33,7 +33,7 @@ describe("proxy", () => { afterEach(async () => { if (codeServer) { - await codeServer.close() + await codeServer.dispose() codeServer = undefined } }) diff --git a/test/unit/node/routes/health.test.ts b/test/unit/node/routes/health.test.ts index 4b950b4028d3..77dd6a942235 100644 --- a/test/unit/node/routes/health.test.ts +++ b/test/unit/node/routes/health.test.ts @@ -6,7 +6,7 @@ describe("health", () => { afterEach(async () => { if (codeServer) { - await codeServer.close() + await codeServer.dispose() codeServer = undefined } }) diff --git a/test/unit/node/routes/login.test.ts b/test/unit/node/routes/login.test.ts index e8547ef18126..3595f5a00752 100644 --- a/test/unit/node/routes/login.test.ts +++ b/test/unit/node/routes/login.test.ts @@ -58,17 +58,11 @@ describe("login", () => { afterEach(async () => { process.env.PASSWORD = previousEnvPassword if (_codeServer) { - await _codeServer.close() + await _codeServer.dispose() _codeServer = undefined } }) - afterAll(async () => { - if (_codeServer) { - _codeServer.dispose() - } - }) - it("should return HTML with 'Missing password' message", async () => { const resp = await codeServer().fetch("/login", { method: "POST" }) diff --git a/test/unit/node/routes/static.test.ts b/test/unit/node/routes/static.test.ts index c9f3187817ac..d3c03b718024 100644 --- a/test/unit/node/routes/static.test.ts +++ b/test/unit/node/routes/static.test.ts @@ -33,17 +33,11 @@ describe("/_static", () => { afterEach(async () => { if (_codeServer) { - await _codeServer.close() + await _codeServer.dispose() _codeServer = undefined } }) - afterAll(async () => { - if (_codeServer) { - _codeServer.dispose() - } - }) - function commonTests() { it("should return a 404 when a file is not provided", async () => { const resp = await codeServer().fetch(`/_static/`) diff --git a/test/utils/httpserver.ts b/test/utils/httpserver.ts index b7795c3cfdda..0c1ea7a939d9 100644 --- a/test/utils/httpserver.ts +++ b/test/utils/httpserver.ts @@ -60,9 +60,9 @@ export class HttpServer { } /** - * close cleans up the server. + * Clean up the server. */ - public close(): Promise { + public dispose(): Promise { return new Promise((resolve, reject) => { // Close will not actually close anything; it just waits until everything // is closed. @@ -74,6 +74,8 @@ export class HttpServer { resolve() }) + this._dispose?.() + // If there are sockets remaining we might need to force close them or // this promise might never resolve. if (this.sockets.size > 0) { @@ -90,11 +92,6 @@ export class HttpServer { }) } - public dispose() { - console.log("Disposing HTTP Server") - this._dispose?.() - } - /** * fetch fetches the request path. * The request path must be rooted! From fc81fc3453859d4191ce27a586af32d26bb3993f Mon Sep 17 00:00:00 2001 From: Asher Date: Tue, 26 Oct 2021 18:00:29 +0000 Subject: [PATCH 31/39] Dispose HTTP server Shares code with the test HTTP server. For now it is a function but maybe we should make it a class that is extended by tests. --- src/common/emitter.ts | 2 +- src/node/app.ts | 30 ++++++++++----- src/node/http.ts | 53 +++++++++++++++++++++++++++ src/node/main.ts | 13 ++++--- src/node/routes/index.ts | 75 ++++++++++++++++++-------------------- test/unit/node/app.test.ts | 33 ++++++----------- test/utils/httpserver.ts | 63 +++++++------------------------- test/utils/integration.ts | 4 +- 8 files changed, 144 insertions(+), 129 deletions(-) diff --git a/src/common/emitter.ts b/src/common/emitter.ts index ceb6dcfcd21b..78d0d7990ddb 100644 --- a/src/common/emitter.ts +++ b/src/common/emitter.ts @@ -7,7 +7,7 @@ import { logger } from "@coder/logger" export type Callback> = (t: T, p: Promise) => R export interface Disposable { - dispose(): void + dispose(): void | Promise } export interface Event { diff --git a/src/node/app.ts b/src/node/app.ts index d0e17a37ca9b..1387135583d5 100644 --- a/src/node/app.ts +++ b/src/node/app.ts @@ -4,13 +4,24 @@ import express, { Express } from "express" import { promises as fs } from "fs" import http from "http" import * as httpolyglot from "httpolyglot" +import { Disposable } from "../common/emitter" import * as util from "../common/util" import { DefaultedArgs } from "./cli" +import { disposer } from "./http" import { isNodeJSErrnoException } from "./util" import { handleUpgrade } from "./wsRouter" type ListenOptions = Pick +export interface App extends Disposable { + /** Handles regular HTTP requests. */ + router: Express + /** Handles websocket requests. */ + wsRouter: Express + /** The underlying HTTP server. */ + server: http.Server +} + const listen = (server: http.Server, { host, port, socket }: ListenOptions) => { return new Promise(async (resolve, reject) => { server.on("error", reject) @@ -41,10 +52,9 @@ const listen = (server: http.Server, { host, port, socket }: ListenOptions) => { /** * Create an Express app and an HTTP/S server to serve it. */ -export const createApp = async (args: DefaultedArgs): Promise<[Express, Express, http.Server]> => { - const app = express() - - app.use(compression()) +export const createApp = async (args: DefaultedArgs): Promise => { + const router = express() + router.use(compression()) const server = args.cert ? httpolyglot.createServer( @@ -52,16 +62,18 @@ export const createApp = async (args: DefaultedArgs): Promise<[Express, Express, cert: args.cert && (await fs.readFile(args.cert.value)), key: args["cert-key"] && (await fs.readFile(args["cert-key"])), }, - app, + router, ) - : http.createServer(app) + : http.createServer(router) + + const dispose = disposer(server) await listen(server, args) - const wsApp = express() - handleUpgrade(wsApp, server) + const wsRouter = express() + handleUpgrade(wsRouter, server) - return [app, wsApp, server] + return { router, wsRouter, server, dispose } } /** diff --git a/src/node/http.ts b/src/node/http.ts index d88d8610bdd4..d3c661c57fef 100644 --- a/src/node/http.ts +++ b/src/node/http.ts @@ -1,8 +1,11 @@ import { field, logger } from "@coder/logger" import * as express from "express" import * as expressCore from "express-serve-static-core" +import * as http from "http" +import * as net from "net" import path from "path" import qs from "qs" +import { Disposable } from "../common/emitter" import { HttpCode, HttpError } from "../common/http" import { normalize } from "../common/util" import { AuthType, DefaultedArgs } from "./cli" @@ -188,3 +191,53 @@ export const getCookieDomain = (host: string, proxyDomains: string[]): string | logger.debug("got cookie doman", field("host", host)) return host || undefined } + +/** + * Return a function capable of fully disposing an HTTP server. + */ +export function disposer(server: http.Server): Disposable["dispose"] { + const sockets = new Set() + let cleanupTimeout: undefined | NodeJS.Timeout + + server.on("connection", (socket) => { + sockets.add(socket) + + socket.on("close", () => { + sockets.delete(socket) + + if (cleanupTimeout && sockets.size === 0) { + clearTimeout(cleanupTimeout) + cleanupTimeout = undefined + } + }) + }) + + return () => { + return new Promise((resolve, reject) => { + // The whole reason we need this disposer is because close will not + // actually close anything; it only prevents future connections then waits + // until everything is closed. + server.close((err) => { + if (err) { + return reject(err) + } + + resolve() + }) + + // If there are sockets remaining we might need to force close them or + // this promise might never resolve. + if (sockets.size > 0) { + // Give sockets a chance to close up shop. + cleanupTimeout = setTimeout(() => { + cleanupTimeout = undefined + + for (const socket of sockets.values()) { + console.warn("a socket was left hanging") + socket.destroy() + } + }, 1000) + } + }) + } +} diff --git a/src/node/main.ts b/src/node/main.ts index 7e8874d7af78..ae99aa71ca12 100644 --- a/src/node/main.ts +++ b/src/node/main.ts @@ -121,9 +121,9 @@ export const runCodeServer = async ( ) } - const [app, wsApp, server] = await createApp(args) - const serverAddress = ensureAddress(server, args.cert ? "https" : "http") - const disposeApp = await register(app, wsApp, server, args) + const app = await createApp(args) + const serverAddress = ensureAddress(app.server, args.cert ? "https" : "http") + const disposeRoutes = await register(app, args) logger.info(`Using config file ${humanPath(args.config)}`) logger.info(`HTTP server listening on ${serverAddress.toString()} ${args.link ? "(randomized by --link)" : ""}`) @@ -194,10 +194,11 @@ export const runCodeServer = async ( } return { - server, - dispose: () => { - disposeApp() + server: app.server, + dispose: async () => { linkAgent?.kill() + disposeRoutes() + await app.dispose() }, } } diff --git a/src/node/routes/index.ts b/src/node/routes/index.ts index 267b3c2163bb..b02661841de4 100644 --- a/src/node/routes/index.ts +++ b/src/node/routes/index.ts @@ -2,13 +2,13 @@ import { logger } from "@coder/logger" import cookieParser from "cookie-parser" import * as express from "express" import { promises as fs } from "fs" -import http from "http" import * as path from "path" import * as tls from "tls" import * as pluginapi from "../../../typings/pluginapi" import { Disposable } from "../../common/emitter" import { HttpCode, HttpError } from "../../common/http" import { plural } from "../../common/util" +import { App } from "../app" import { AuthType, DefaultedArgs } from "../cli" import { commit, isDevMode, rootPath } from "../constants" import { Heart } from "../heart" @@ -28,15 +28,10 @@ import { createVSServerRouter, VSServerResult } from "./vscode" /** * Register all routes and middleware. */ -export const register = async ( - app: express.Express, - wsApp: express.Express, - server: http.Server, - args: DefaultedArgs, -): Promise => { +export const register = async (app: App, args: DefaultedArgs): Promise => { const heart = new Heart(path.join(paths.data, "heartbeat"), async () => { return new Promise((resolve, reject) => { - server.getConnections((error, count) => { + app.server.getConnections((error, count) => { if (error) { return reject(error) } @@ -46,11 +41,11 @@ export const register = async ( }) }) - app.disable("x-powered-by") - wsApp.disable("x-powered-by") + app.router.disable("x-powered-by") + app.wsRouter.disable("x-powered-by") - app.use(cookieParser()) - wsApp.use(cookieParser()) + app.router.use(cookieParser()) + app.wsRouter.use(cookieParser()) const common: express.RequestHandler = (req, _, next) => { // /healthz|/healthz/ needs to be excluded otherwise health checks will make @@ -66,10 +61,10 @@ export const register = async ( next() } - app.use(common) - wsApp.use(common) + app.router.use(common) + app.wsRouter.use(common) - app.use(async (req, res, next) => { + app.router.use(async (req, res, next) => { // If we're handling TLS ensure all requests are redirected to HTTPS. // TODO: This does *NOT* work if you have a base path since to specify the // protocol we need to specify the whole path. @@ -87,24 +82,24 @@ export const register = async ( next() }) - app.use("/", domainProxy.router) - wsApp.use("/", domainProxy.wsRouter.router) + app.router.use("/", domainProxy.router) + app.wsRouter.use("/", domainProxy.wsRouter.router) - app.all("/proxy/(:port)(/*)?", (req, res) => { + app.router.all("/proxy/(:port)(/*)?", (req, res) => { pathProxy.proxy(req, res) }) - wsApp.get("/proxy/(:port)(/*)?", async (req) => { + app.wsRouter.get("/proxy/(:port)(/*)?", async (req) => { await pathProxy.wsProxy(req as pluginapi.WebsocketRequest) }) // These two routes pass through the path directly. // So the proxied app must be aware it is running // under /absproxy// - app.all("/absproxy/(:port)(/*)?", (req, res) => { + app.router.all("/absproxy/(:port)(/*)?", (req, res) => { pathProxy.proxy(req, res, { passthroughPath: true, }) }) - wsApp.get("/absproxy/(:port)(/*)?", async (req) => { + app.wsRouter.get("/absproxy/(:port)(/*)?", async (req) => { await pathProxy.wsProxy(req as pluginapi.WebsocketRequest, { passthroughPath: true, }) @@ -115,40 +110,40 @@ export const register = async ( const workingDir = args._ && args._.length > 0 ? path.resolve(args._[args._.length - 1]) : undefined pluginApi = new PluginAPI(logger, process.env.CS_PLUGIN, process.env.CS_PLUGIN_PATH, workingDir) await pluginApi.loadPlugins() - pluginApi.mount(app, wsApp) - app.use("/api/applications", ensureAuthenticated, apps.router(pluginApi)) + pluginApi.mount(app.router, app.wsRouter) + app.router.use("/api/applications", ensureAuthenticated, apps.router(pluginApi)) } - app.use(express.json()) - app.use(express.urlencoded({ extended: true })) + app.router.use(express.json()) + app.router.use(express.urlencoded({ extended: true })) - app.use( + app.router.use( "/_static", express.static(rootPath, { cacheControl: commit !== "development", }), ) - app.use("/healthz", health.router) - wsApp.use("/healthz", health.wsRouter.router) + app.router.use("/healthz", health.router) + app.wsRouter.use("/healthz", health.wsRouter.router) if (args.auth === AuthType.Password) { - app.use("/login", login.router) - app.use("/logout", logout.router) + app.router.use("/login", login.router) + app.router.use("/logout", logout.router) } else { - app.all("/login", (req, res) => redirect(req, res, "/", {})) - app.all("/logout", (req, res) => redirect(req, res, "/", {})) + app.router.all("/login", (req, res) => redirect(req, res, "/", {})) + app.router.all("/logout", (req, res) => redirect(req, res, "/", {})) } - app.use("/update", update.router) + app.router.use("/update", update.router) let vscode: VSServerResult try { vscode = await createVSServerRouter(args) - app.use("/", vscode.router) - wsApp.use("/", vscode.wsRouter.router) - app.use("/vscode", vscode.router) - wsApp.use("/vscode", vscode.wsRouter.router) + app.router.use("/", vscode.router) + app.wsRouter.use("/", vscode.wsRouter.router) + app.router.use("/vscode", vscode.router) + app.wsRouter.use("/vscode", vscode.wsRouter.router) } catch (error: any) { if (isDevMode) { logger.warn(error) @@ -158,12 +153,12 @@ export const register = async ( } } - app.use(() => { + app.router.use(() => { throw new HttpError("Not Found", HttpCode.NotFound) }) - app.use(errorHandler) - wsApp.use(wsErrorHandler) + app.router.use(errorHandler) + app.wsRouter.use(wsErrorHandler) return () => { heart.dispose() diff --git a/test/unit/node/app.test.ts b/test/unit/node/app.test.ts index 2a3bf0210bca..5f8e04a5ae06 100644 --- a/test/unit/node/app.test.ts +++ b/test/unit/node/app.test.ts @@ -47,16 +47,16 @@ describe("createApp", () => { port, _: [], }) - const [app, wsApp, server] = await createApp(defaultArgs) + const app = await createApp(defaultArgs) // This doesn't check much, but it's a good sanity check // to ensure we actually get back values from createApp - expect(app).not.toBeNull() - expect(wsApp).not.toBeNull() - expect(server).toBeInstanceOf(http.Server) + expect(app.router).not.toBeNull() + expect(app.wsRouter).not.toBeNull() + expect(app.server).toBeInstanceOf(http.Server) // Cleanup - server.close() + app.dispose() }) it("should handle error events on the server", async () => { @@ -65,24 +65,18 @@ describe("createApp", () => { _: [], }) - // This looks funky, but that's because createApp - // returns an array like [app, wsApp, server] - // We only need server which is at index 2 - // we do it this way so ESLint is happy that we're - // have no declared variables not being used const app = await createApp(defaultArgs) - const server = app[2] const testError = new Error("Test error") // We can easily test how the server handles errors // By emitting an error event // Ref: https://stackoverflow.com/a/33872506/3015595 - server.emit("error", testError) + app.server.emit("error", testError) expect(spy).toHaveBeenCalledTimes(1) expect(spy).toHaveBeenCalledWith(`http server error: ${testError.message} ${testError.stack}`) // Cleanup - server.close() + app.dispose() }) it("should reject errors that happen before the server can listen", async () => { @@ -96,14 +90,13 @@ describe("createApp", () => { async function masterBall() { const app = await createApp(defaultArgs) - const server = app[2] const testError = new Error("Test error") - server.emit("error", testError) + app.server.emit("error", testError) // Cleanup - server.close() + app.dispose() } expect(() => masterBall()).rejects.toThrow(`listen EACCES: permission denied 127.0.0.1:${port}`) @@ -117,10 +110,9 @@ describe("createApp", () => { }) const app = await createApp(defaultArgs) - const server = app[2] expect(unlinkSpy).toHaveBeenCalledTimes(1) - server.close() + app.dispose() }) it("should create an https server if args.cert exists", async () => { @@ -133,14 +125,13 @@ describe("createApp", () => { ["cert-key"]: testCertificate.certKey, }) const app = await createApp(defaultArgs) - const server = app[2] // This doesn't check much, but it's a good sanity check // to ensure we actually get an https.Server - expect(server).toBeInstanceOf(https.Server) + expect(app.server).toBeInstanceOf(https.Server) // Cleanup - server.close() + app.dispose() }) }) diff --git a/test/utils/httpserver.ts b/test/utils/httpserver.ts index 0c1ea7a939d9..74c1c00e6e64 100644 --- a/test/utils/httpserver.ts +++ b/test/utils/httpserver.ts @@ -1,33 +1,29 @@ import { logger } from "@coder/logger" import * as express from "express" import * as http from "http" -import * as net from "net" import nodeFetch, { RequestInit, Response } from "node-fetch" import Websocket from "ws" import { Disposable } from "../../src/common/emitter" import * as util from "../../src/common/util" import { ensureAddress } from "../../src/node/app" +import { disposer } from "../../src/node/http" + import { handleUpgrade } from "../../src/node/wsRouter" // Perhaps an abstraction similar to this should be used in app.ts as well. export class HttpServer { - private readonly sockets = new Set() - private cleanupTimeout?: NodeJS.Timeout - - // See usage in test/integration.ts - public constructor(private readonly hs = http.createServer(), private _dispose?: Disposable["dispose"]) { - this.hs.on("connection", (socket) => { - this.sockets.add(socket) - - socket.on("close", () => { - this.sockets.delete(socket) + private hs: http.Server + public dispose: Disposable["dispose"] - if (this.cleanupTimeout && this.sockets.size === 0) { - clearTimeout(this.cleanupTimeout) - this.cleanupTimeout = undefined - } - }) - }) + /** + * Expects a server and a disposal that cleans up the server (and anything + * else that may need cleanup). + * + * Otherwise a new server is created. + */ + public constructor(server?: { server: http.Server; dispose: Disposable["dispose"] }) { + this.hs = server?.server || http.createServer() + this.dispose = server?.dispose || disposer(this.hs) } /** @@ -59,39 +55,6 @@ export class HttpServer { handleUpgrade(app, this.hs) } - /** - * Clean up the server. - */ - public dispose(): Promise { - return new Promise((resolve, reject) => { - // Close will not actually close anything; it just waits until everything - // is closed. - this.hs.close((err) => { - if (err) { - return reject(err) - } - - resolve() - }) - - this._dispose?.() - - // If there are sockets remaining we might need to force close them or - // this promise might never resolve. - if (this.sockets.size > 0) { - // Give sockets a chance to close up shop. - this.cleanupTimeout = setTimeout(() => { - this.cleanupTimeout = undefined - - for (const socket of this.sockets.values()) { - console.warn("a socket was left hanging") - socket.destroy() - } - }, 1000) - } - }) - } - /** * fetch fetches the request path. * The request path must be rooted! diff --git a/test/utils/integration.ts b/test/utils/integration.ts index bf00f89e4f18..5c4f0cc6aa7f 100644 --- a/test/utils/integration.ts +++ b/test/utils/integration.ts @@ -9,7 +9,7 @@ export async function setup(argv: string[], configFile?: string): Promise Date: Tue, 26 Oct 2021 19:17:47 +0000 Subject: [PATCH 32/39] Dispose app on exit --- src/node/entry.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/node/entry.ts b/src/node/entry.ts index 2bec20d250d3..06ce4cccfaa6 100644 --- a/src/node/entry.ts +++ b/src/node/entry.ts @@ -17,7 +17,8 @@ async function entry(): Promise { if (isChild(wrapper)) { const args = await wrapper.handshake() wrapper.preventExit() - await runCodeServer(args) + const server = await runCodeServer(args) + wrapper.onDispose(() => server.dispose()) return } From a343efe22708a2da4d510ccb1716091ff5dab7e4 Mon Sep 17 00:00:00 2001 From: Asher Date: Tue, 26 Oct 2021 21:51:56 +0000 Subject: [PATCH 33/39] Fix logging link errors Unfortunately the logger currently chokes when provided with error objects. Also for some reason the bracketed text was not displaying... --- src/common/util.ts | 2 +- src/node/main.ts | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/common/util.ts b/src/common/util.ts index f8c25dd102ea..30fb8387a549 100644 --- a/src/common/util.ts +++ b/src/common/util.ts @@ -65,7 +65,7 @@ export const arrayify = (value?: T | T[]): T[] => { } // TODO: Might make sense to add Error handling to the logger itself. -export function logError(logger: { error: (msg: string) => void }, prefix: string, err: Error | string): void { +export function logError(logger: { error: (msg: string) => void }, prefix: string, err: unknown): void { if (err instanceof Error) { logger.error(`${prefix}: ${err.message} ${err.stack}`) } else { diff --git a/src/node/main.ts b/src/node/main.ts index ae99aa71ca12..9235218f37d1 100644 --- a/src/node/main.ts +++ b/src/node/main.ts @@ -3,7 +3,7 @@ import { ChildProcessWithoutNullStreams } from "child_process" import http from "http" import path from "path" import { Disposable } from "../common/emitter" -import { plural } from "../common/util" +import { plural, logError } from "../common/util" import { createApp, ensureAddress } from "./app" import { AuthType, DefaultedArgs, Feature } from "./cli" import { coderCloudBind } from "./coder_cloud" @@ -160,13 +160,13 @@ export const runCodeServer = async ( try { linkAgent = startLink(serverAddress) linkAgent.on("error", (error) => { - logger.debug("[Link daemon]", field("error", error)) + logError(logger, "link daemon", error) }) linkAgent.on("close", (code) => { - logger.debug("[Link daemon]", field("code", `Closed with code ${code}`)) + logger.debug("link daemon closed", field("code", code)) }) } catch (error) { - logger.debug("Failed to start link daemon!", error as any) + logError(logger, "link daemon", error) } if (args.enable && args.enable.length > 0) { From 8857e67a3534da3da903e532b5d52823adb3344e Mon Sep 17 00:00:00 2001 From: Asher Date: Wed, 27 Oct 2021 21:05:33 +0000 Subject: [PATCH 34/39] Update regex used by e2e to extract address The address was recently changed to use URL which seems to add a trailing slash when using toString, causing the regex match to fail. --- test/e2e/models/CodeServer.ts | 20 +++++++++++++++----- test/utils/helpers.ts | 18 ++++++++++++++++++ 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/test/e2e/models/CodeServer.ts b/test/e2e/models/CodeServer.ts index 3acb0cd7b192..82a647861f47 100644 --- a/test/e2e/models/CodeServer.ts +++ b/test/e2e/models/CodeServer.ts @@ -1,11 +1,11 @@ -import { Logger, logger } from "@coder/logger" +import { field, Logger, logger } from "@coder/logger" import * as cp from "child_process" import { promises as fs } from "fs" import * as path from "path" import { Page } from "playwright" import { onLine } from "../../../src/node/util" import { PASSWORD, workspaceDir } from "../../utils/constants" -import { tmpdir } from "../../utils/helpers" +import { idleTimer, tmpdir } from "../../utils/helpers" interface CodeServerProcess { process: cp.ChildProcess @@ -99,34 +99,44 @@ export class CodeServer { }, ) + const timer = idleTimer("Failed to extract address; did the format change?", reject) + proc.on("error", (error) => { this.logger.error(error.message) + timer.dispose() reject(error) }) - proc.on("close", () => { + proc.on("close", (code) => { const error = new Error("closed unexpectedly") if (!this.closed) { - this.logger.error(error.message) + this.logger.error(error.message, field("code", code)) } + timer.dispose() reject(error) }) let resolved = false proc.stdout.setEncoding("utf8") onLine(proc, (line) => { + // As long as we are actively getting input reset the timer. If we stop + // getting input and still have not found the address the timer will + // reject. + timer.reset() + // Log the line without the timestamp. this.logger.trace(line.replace(/\[.+\]/, "")) if (resolved) { return } - const match = line.trim().match(/HTTP server listening on (https?:\/\/[.:\d]+)$/) + const match = line.trim().match(/HTTP server listening on (https?:\/\/[.:\d]+)\/?$/) if (match) { // Cookies don't seem to work on IP address so swap to localhost. // TODO: Investigate whether this is a bug with code-server. const address = match[1].replace("127.0.0.1", "localhost") this.logger.debug(`spawned on ${address}`) resolved = true + timer.dispose() resolve({ process: proc, address }) } }) diff --git a/test/utils/helpers.ts b/test/utils/helpers.ts index 2e55c322c080..10b4abee794e 100644 --- a/test/utils/helpers.ts +++ b/test/utils/helpers.ts @@ -82,3 +82,21 @@ export const getAvailablePort = (options?: net.ListenOptions): Promise = }) }) }) + +/** + * Return a timer that will not reject as long as it is disposed or continually + * reset before the delay elapses. + */ +export function idleTimer(message: string, reject: (error: Error) => void, delay = 5000) { + const start = () => setTimeout(() => reject(new Error(message)), delay) + let timeout = start() + return { + reset: () => { + clearTimeout(timeout) + timeout = start() + }, + dispose: () => { + clearTimeout(timeout) + }, + } +} From 7a52cb8a4ca58deec3c72905514c55d2942442c3 Mon Sep 17 00:00:00 2001 From: Asher Date: Wed, 27 Oct 2021 21:37:27 +0000 Subject: [PATCH 35/39] Log browser console in e2e tests --- test/e2e/models/CodeServer.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/test/e2e/models/CodeServer.ts b/test/e2e/models/CodeServer.ts index 82a647861f47..7f51e84bf0aa 100644 --- a/test/e2e/models/CodeServer.ts +++ b/test/e2e/models/CodeServer.ts @@ -166,7 +166,14 @@ export class CodeServer { export class CodeServerPage { private readonly editorSelector = "div.monaco-workbench" - constructor(private readonly codeServer: CodeServer, public readonly page: Page) {} + constructor(private readonly codeServer: CodeServer, public readonly page: Page) { + this.page.on("console", (message) => { + this.codeServer.logger.debug(message) + }) + this.page.on("pageerror", (error) => { + logError(this.codeServer.logger, "page", error) + }) + } address() { return this.codeServer.address() From 44602ccbdc97263586ba974412f53c5389252a81 Mon Sep 17 00:00:00 2001 From: Asher Date: Thu, 28 Oct 2021 18:43:46 +0000 Subject: [PATCH 36/39] Add base back to login page This is used to set cookies when using a base path. --- src/browser/pages/login.html | 9 +++++++++ src/node/routes/login.ts | 6 +++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/browser/pages/login.html b/src/browser/pages/login.html index f8837c8f30e3..75aa86dc2523 100644 --- a/src/browser/pages/login.html +++ b/src/browser/pages/login.html @@ -30,6 +30,7 @@

Welcome to code-server

+ diff --git a/src/node/routes/login.ts b/src/node/routes/login.ts index 8b8164f16b4e..9c1425c3659f 100644 --- a/src/node/routes/login.ts +++ b/src/node/routes/login.ts @@ -88,7 +88,11 @@ router.post("/", async (req, res) => { // obfuscation purposes (and as a side effect it handles escaping). res.cookie(Cookie.Key, hashedPassword, { domain: getCookieDomain(req.headers.host || "", req.args["proxy-domain"]), - path: req.body.base || "/", + // Browsers do not appear to allow cookies to be set relatively so we + // need to get the root path from the browser since the proxy rewrites + // it out of the path. Otherwise code-server instances hosted on + // separate sub-paths will clobber each other. + path: req.body.base ? path.posix.join(req.body.base, "..") : "/", sameSite: "lax", }) From 6fbbd8346d6dd002f499a8049e153ebe936e8655 Mon Sep 17 00:00:00 2001 From: Asher Date: Thu, 28 Oct 2021 18:44:14 +0000 Subject: [PATCH 37/39] Remove login page test The file this was testing no longer exists. --- test/unit/browser/pages/login.test.ts | 74 --------------------------- 1 file changed, 74 deletions(-) delete mode 100644 test/unit/browser/pages/login.test.ts diff --git a/test/unit/browser/pages/login.test.ts b/test/unit/browser/pages/login.test.ts deleted file mode 100644 index 7d804a37ac8b..000000000000 --- a/test/unit/browser/pages/login.test.ts +++ /dev/null @@ -1,74 +0,0 @@ -import { JSDOM } from "jsdom" -import { LocationLike } from "../../common/util.test" - -describe("login", () => { - describe("there is an element with id 'base'", () => { - beforeEach(() => { - const dom = new JSDOM() - global.document = dom.window.document - - const location: LocationLike = { - pathname: "/healthz", - origin: "http://localhost:8080", - } - - global.location = location as Location - }) - afterEach(() => { - // Reset the global.document - global.document = undefined as any as Document - global.location = undefined as any as Location - }) - it("should set the value to options.base", () => { - // Mock getElementById - const spy = jest.spyOn(document, "getElementById") - // Create a fake element and set the attribute - const mockElement = document.createElement("input") - const expected = { - base: "./hello-world", - logLevel: 2, - disableTelemetry: false, - disableUpdateCheck: false, - } - mockElement.setAttribute("data-settings", JSON.stringify(expected)) - document.body.appendChild(mockElement) - spy.mockImplementation(() => mockElement) - }) - }) - // TODO: Is this still used? - // describe("there is not an element with id 'base'", () => { - // let spy: jest.SpyInstance - - // beforeAll(() => { - // // This is important because we're manually requiring the file - // // If you don't call this before all tests - // // the module registry from other tests may cause side effects. - // jest.resetModules() - // }) - - // beforeEach(() => { - // const dom = new JSDOM() - // global.document = dom.window.document - // spy = jest.spyOn(document, "getElementById") - - // const location: LocationLike = { - // pathname: "/healthz", - // origin: "http://localhost:8080", - // } - - // global.location = location as Location - // }) - - // afterEach(() => { - // spy.mockClear() - // jest.resetModules() - // // Reset the global.document - // global.document = undefined as any as Document - // global.location = undefined as any as Location - // }) - - // afterAll(() => { - // jest.restoreAllMocks() - // }) - // }) -}) From f4a8c9d2e0a3692f1f8c708b213e655edfe36b3a Mon Sep 17 00:00:00 2001 From: Asher Date: Thu, 28 Oct 2021 19:22:37 +0000 Subject: [PATCH 38/39] Use path.posix for static base Since this is a web path and not platform-dependent. --- src/node/http.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/node/http.ts b/src/node/http.ts index d3c661c57fef..461aefc0d6b4 100644 --- a/src/node/http.ts +++ b/src/node/http.ts @@ -37,7 +37,7 @@ export const createClientConfiguration = (req: express.Request): ClientConfigura return { base, - csStaticBase: normalize(path.join(base, "_static/")), + csStaticBase: normalize(path.posix.join(base, "_static/")), codeServerVersion, } } From 02f4e00ff58a0db20c4dcd4f04962c824253f5fa Mon Sep 17 00:00:00 2001 From: Asher Date: Thu, 28 Oct 2021 19:50:21 +0000 Subject: [PATCH 39/39] Add test for invalid password --- test/unit/node/routes/login.test.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/unit/node/routes/login.test.ts b/test/unit/node/routes/login.test.ts index 3595f5a00752..94cc265a6c8c 100644 --- a/test/unit/node/routes/login.test.ts +++ b/test/unit/node/routes/login.test.ts @@ -72,5 +72,20 @@ describe("login", () => { expect(htmlContent).toContain("Missing password") }) + + it("should return HTML with 'Incorrect password' message", async () => { + const params = new URLSearchParams() + params.append("password", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") + const resp = await codeServer().fetch("/login", { + method: "POST", + body: params, + }) + + expect(resp.status).toBe(200) + + const htmlContent = await resp.text() + + expect(htmlContent).toContain("Incorrect password") + }) }) })