Skip to content

Commit

Permalink
Merge pull request #2238 from cdr/code-asher/ch1385
Browse files Browse the repository at this point in the history
  • Loading branch information
code-asher authored Nov 12, 2020
2 parents da6000b + 9889f30 commit 5e60305
Show file tree
Hide file tree
Showing 49 changed files with 3,320 additions and 2,140 deletions.
2 changes: 2 additions & 0 deletions .eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ rules:
import/order:
[error, { alphabetize: { order: "asc" }, groups: [["builtin", "external", "internal"], "parent", "sibling"] }]
no-async-promise-executor: off
# This isn't a real module, just types, which apparently doesn't resolve.
import/no-unresolved: [error, { ignore: ["express-serve-static-core"] }]

settings:
# Does not work with CommonJS unfortunately.
Expand Down
5 changes: 4 additions & 1 deletion ci/dev/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ set -euo pipefail
main() {
cd "$(dirname "$0")/../.."

mocha -r ts-node/register ./test/*.test.ts
cd test/test-plugin
make -s out/index.js
cd "$OLDPWD"
mocha -r ts-node/register ./test/*.test.ts "$@"
}

main "$@"
16 changes: 14 additions & 2 deletions ci/dev/vscode.patch
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,18 @@ index da4fa3e9d0443d679dfbab1000b434af2ae01afd..50f3e1144f8057883dea8b91ec2f7073
}

function processLib() {
diff --git a/extensions/typescript-language-features/src/utils/platform.ts b/extensions/typescript-language-features/src/utils/platform.ts
index 2d754bf4054713f53beed030f9211b33532c1b4b..708b7e40a662e4ca93420992bf7a5af0c62ea5b2 100644
--- a/extensions/typescript-language-features/src/utils/platform.ts
+++ b/extensions/typescript-language-features/src/utils/platform.ts
@@ -6,6 +6,6 @@
import * as vscode from 'vscode';

export function isWeb(): boolean {
- // @ts-expect-error
+ // NOTE@coder: Remove unused ts-expect-error directive which causes tsc to error.
return typeof navigator !== 'undefined' && vscode.env.uiKind === vscode.UIKind.Web;
}
diff --git a/package.json b/package.json
index 770b44b0c1ff53d903b7680ede27715376df00f2..b27ab71647a3e7c4b6076ba4fdb8fde20fa73bb0 100644
--- a/package.json
Expand Down Expand Up @@ -1319,7 +1331,7 @@ index 0000000000000000000000000000000000000000..56331ff1fc32bbd82e769aaecb551e42
+require('../../bootstrap-amd').load('vs/server/entry');
diff --git a/src/vs/server/ipc.d.ts b/src/vs/server/ipc.d.ts
new file mode 100644
index 0000000000000000000000000000000000000000..33b28cf2d53746ee9c50c056ac2e087dcee0a4e2
index 0000000000000000000000000000000000000000..6ce56bec114a6d8daf5dd3ded945ea78fc72a5c6
--- /dev/null
+++ b/src/vs/server/ipc.d.ts
@@ -0,0 +1,131 @@
Expand All @@ -1337,7 +1349,7 @@ index 0000000000000000000000000000000000000000..33b28cf2d53746ee9c50c056ac2e087d
+ options: VscodeOptions;
+}
+
+export type Query = { [key: string]: string | string[] | undefined };
+export type Query = { [key: string]: string | string[] | undefined | Query | Query[] };
+
+export interface SocketMessage {
+ type: 'socket';
Expand Down
9 changes: 9 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
},
"main": "out/node/entry.js",
"devDependencies": {
"@types/body-parser": "^1.19.0",
"@types/cookie-parser": "^1.4.2",
"@types/express": "^4.17.8",
"@types/fs-extra": "^8.0.1",
"@types/http-proxy": "^1.17.4",
"@types/js-yaml": "^3.12.3",
Expand All @@ -40,6 +43,7 @@
"@types/safe-compare": "^1.1.0",
"@types/semver": "^7.1.0",
"@types/split2": "^2.1.6",
"@types/supertest": "^2.0.10",
"@types/tar-fs": "^2.0.0",
"@types/tar-stream": "^2.1.0",
"@types/ws": "^7.2.6",
Expand All @@ -56,6 +60,7 @@
"prettier": "^2.0.5",
"stylelint": "^13.0.0",
"stylelint-config-recommended": "^3.0.0",
"supertest": "^6.0.1",
"ts-node": "^9.0.0",
"typescript": "4.0.2"
},
Expand All @@ -66,13 +71,17 @@
},
"dependencies": {
"@coder/logger": "1.1.16",
"body-parser": "^1.19.0",
"cookie-parser": "^1.4.5",
"env-paths": "^2.2.0",
"express": "^5.0.0-alpha.8",
"fs-extra": "^9.0.1",
"http-proxy": "^1.18.0",
"httpolyglot": "^0.1.2",
"js-yaml": "^3.13.1",
"limiter": "^1.1.5",
"pem": "^1.14.2",
"qs": "6.7.0",
"rotating-file-stream": "^2.1.1",
"safe-buffer": "^5.1.1",
"safe-compare": "^1.1.4",
Expand Down
25 changes: 22 additions & 3 deletions src/common/emitter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { Callback } from "./types"
import { logger } from "@coder/logger"

/**
* Event emitter callback. Called with the emitted value and a promise that
* resolves when all emitters have finished.
*/
export type Callback<T, R = void | Promise<void>> = (t: T, p: Promise<void>) => R

export interface Disposable {
dispose(): void
Expand Down Expand Up @@ -32,8 +38,21 @@ export class Emitter<T> {
/**
* Emit an event with a value.
*/
public emit(value: T): void {
this.listeners.forEach((cb) => cb(value))
public async emit(value: T): Promise<void> {
let resolve: () => void
const promise = new Promise<void>((r) => (resolve = r))

await Promise.all(
this.listeners.map(async (cb) => {
try {
await cb(value, promise)
} catch (error) {
logger.error(error.message)
}
}),
)

resolve!()
}

public dispose(): void {
Expand Down
6 changes: 5 additions & 1 deletion src/common/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ export enum HttpCode {
ServerError = 500,
}

/**
* Represents an error with a message and an HTTP status code. This code will be
* used in the HTTP response.
*/
export class HttpError extends Error {
public constructor(message: string, public readonly code: number, public readonly details?: object) {
public constructor(message: string, public readonly status: HttpCode, public readonly details?: object) {
super(message)
this.name = this.constructor.name
}
Expand Down
1 change: 0 additions & 1 deletion src/common/types.ts

This file was deleted.

61 changes: 61 additions & 0 deletions src/node/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { logger } from "@coder/logger"
import express, { Express } from "express"
import { promises as fs } from "fs"
import http from "http"
import * as httpolyglot from "httpolyglot"
import { DefaultedArgs } from "./cli"
import { handleUpgrade } from "./wsRouter"

/**
* 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()

const server = args.cert
? httpolyglot.createServer(
{
cert: args.cert && (await fs.readFile(args.cert.value)),
key: args["cert-key"] && (await fs.readFile(args["cert-key"])),
},
app,
)
: http.createServer(app)

await new Promise<http.Server>(async (resolve, reject) => {
server.on("error", reject)
if (args.socket) {
try {
await fs.unlink(args.socket)
} catch (error) {
if (error.code !== "ENOENT") {
logger.error(error.message)
}
}
server.listen(args.socket, resolve)
} else {
// [] is the correct format when using :: but Node errors with them.
server.listen(args.port, args.host.replace(/^\[|\]$/g, ""), resolve)
}
})

const wsApp = express()
handleUpgrade(wsApp, server)

return [app, wsApp, server]
}

/**
* 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 => {
const addr = server.address()
if (!addr) {
throw new Error("server has no address")
}
if (typeof addr !== "string") {
return `http://${addr.address}:${addr.port}`
}
return addr
}
21 changes: 0 additions & 21 deletions src/node/app/health.ts

This file was deleted.

144 changes: 0 additions & 144 deletions src/node/app/login.ts

This file was deleted.

Loading

0 comments on commit 5e60305

Please sign in to comment.