Skip to content

Commit 5e60305

Browse files
authored
Merge pull request #2238 from cdr/code-asher/ch1385
2 parents da6000b + 9889f30 commit 5e60305

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+3320
-2140
lines changed

.eslintrc.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ rules:
3131
import/order:
3232
[error, { alphabetize: { order: "asc" }, groups: [["builtin", "external", "internal"], "parent", "sibling"] }]
3333
no-async-promise-executor: off
34+
# This isn't a real module, just types, which apparently doesn't resolve.
35+
import/no-unresolved: [error, { ignore: ["express-serve-static-core"] }]
3436

3537
settings:
3638
# Does not work with CommonJS unfortunately.

ci/dev/test.sh

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ set -euo pipefail
44
main() {
55
cd "$(dirname "$0")/../.."
66

7-
mocha -r ts-node/register ./test/*.test.ts
7+
cd test/test-plugin
8+
make -s out/index.js
9+
cd "$OLDPWD"
10+
mocha -r ts-node/register ./test/*.test.ts "$@"
811
}
912

1013
main "$@"

ci/dev/vscode.patch

+14-2
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,18 @@ index da4fa3e9d0443d679dfbab1000b434af2ae01afd..50f3e1144f8057883dea8b91ec2f7073
210210
}
211211

212212
function processLib() {
213+
diff --git a/extensions/typescript-language-features/src/utils/platform.ts b/extensions/typescript-language-features/src/utils/platform.ts
214+
index 2d754bf4054713f53beed030f9211b33532c1b4b..708b7e40a662e4ca93420992bf7a5af0c62ea5b2 100644
215+
--- a/extensions/typescript-language-features/src/utils/platform.ts
216+
+++ b/extensions/typescript-language-features/src/utils/platform.ts
217+
@@ -6,6 +6,6 @@
218+
import * as vscode from 'vscode';
219+
220+
export function isWeb(): boolean {
221+
- // @ts-expect-error
222+
+ // NOTE@coder: Remove unused ts-expect-error directive which causes tsc to error.
223+
return typeof navigator !== 'undefined' && vscode.env.uiKind === vscode.UIKind.Web;
224+
}
213225
diff --git a/package.json b/package.json
214226
index 770b44b0c1ff53d903b7680ede27715376df00f2..b27ab71647a3e7c4b6076ba4fdb8fde20fa73bb0 100644
215227
--- a/package.json
@@ -1319,7 +1331,7 @@ index 0000000000000000000000000000000000000000..56331ff1fc32bbd82e769aaecb551e42
13191331
+require('../../bootstrap-amd').load('vs/server/entry');
13201332
diff --git a/src/vs/server/ipc.d.ts b/src/vs/server/ipc.d.ts
13211333
new file mode 100644
1322-
index 0000000000000000000000000000000000000000..33b28cf2d53746ee9c50c056ac2e087dcee0a4e2
1334+
index 0000000000000000000000000000000000000000..6ce56bec114a6d8daf5dd3ded945ea78fc72a5c6
13231335
--- /dev/null
13241336
+++ b/src/vs/server/ipc.d.ts
13251337
@@ -0,0 +1,131 @@
@@ -1337,7 +1349,7 @@ index 0000000000000000000000000000000000000000..33b28cf2d53746ee9c50c056ac2e087d
13371349
+ options: VscodeOptions;
13381350
+}
13391351
+
1340-
+export type Query = { [key: string]: string | string[] | undefined };
1352+
+export type Query = { [key: string]: string | string[] | undefined | Query | Query[] };
13411353
+
13421354
+export interface SocketMessage {
13431355
+ type: 'socket';

package.json

+9
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
},
3131
"main": "out/node/entry.js",
3232
"devDependencies": {
33+
"@types/body-parser": "^1.19.0",
34+
"@types/cookie-parser": "^1.4.2",
35+
"@types/express": "^4.17.8",
3336
"@types/fs-extra": "^8.0.1",
3437
"@types/http-proxy": "^1.17.4",
3538
"@types/js-yaml": "^3.12.3",
@@ -40,6 +43,7 @@
4043
"@types/safe-compare": "^1.1.0",
4144
"@types/semver": "^7.1.0",
4245
"@types/split2": "^2.1.6",
46+
"@types/supertest": "^2.0.10",
4347
"@types/tar-fs": "^2.0.0",
4448
"@types/tar-stream": "^2.1.0",
4549
"@types/ws": "^7.2.6",
@@ -56,6 +60,7 @@
5660
"prettier": "^2.0.5",
5761
"stylelint": "^13.0.0",
5862
"stylelint-config-recommended": "^3.0.0",
63+
"supertest": "^6.0.1",
5964
"ts-node": "^9.0.0",
6065
"typescript": "4.0.2"
6166
},
@@ -66,13 +71,17 @@
6671
},
6772
"dependencies": {
6873
"@coder/logger": "1.1.16",
74+
"body-parser": "^1.19.0",
75+
"cookie-parser": "^1.4.5",
6976
"env-paths": "^2.2.0",
77+
"express": "^5.0.0-alpha.8",
7078
"fs-extra": "^9.0.1",
7179
"http-proxy": "^1.18.0",
7280
"httpolyglot": "^0.1.2",
7381
"js-yaml": "^3.13.1",
7482
"limiter": "^1.1.5",
7583
"pem": "^1.14.2",
84+
"qs": "6.7.0",
7685
"rotating-file-stream": "^2.1.1",
7786
"safe-buffer": "^5.1.1",
7887
"safe-compare": "^1.1.4",

src/common/emitter.ts

+22-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { Callback } from "./types"
1+
import { logger } from "@coder/logger"
2+
3+
/**
4+
* Event emitter callback. Called with the emitted value and a promise that
5+
* resolves when all emitters have finished.
6+
*/
7+
export type Callback<T, R = void | Promise<void>> = (t: T, p: Promise<void>) => R
28

39
export interface Disposable {
410
dispose(): void
@@ -32,8 +38,21 @@ export class Emitter<T> {
3238
/**
3339
* Emit an event with a value.
3440
*/
35-
public emit(value: T): void {
36-
this.listeners.forEach((cb) => cb(value))
41+
public async emit(value: T): Promise<void> {
42+
let resolve: () => void
43+
const promise = new Promise<void>((r) => (resolve = r))
44+
45+
await Promise.all(
46+
this.listeners.map(async (cb) => {
47+
try {
48+
await cb(value, promise)
49+
} catch (error) {
50+
logger.error(error.message)
51+
}
52+
}),
53+
)
54+
55+
resolve!()
3756
}
3857

3958
public dispose(): void {

src/common/http.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@ export enum HttpCode {
88
ServerError = 500,
99
}
1010

11+
/**
12+
* Represents an error with a message and an HTTP status code. This code will be
13+
* used in the HTTP response.
14+
*/
1115
export class HttpError extends Error {
12-
public constructor(message: string, public readonly code: number, public readonly details?: object) {
16+
public constructor(message: string, public readonly status: HttpCode, public readonly details?: object) {
1317
super(message)
1418
this.name = this.constructor.name
1519
}

src/common/types.ts

-1
This file was deleted.

src/node/app.ts

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { logger } from "@coder/logger"
2+
import express, { Express } from "express"
3+
import { promises as fs } from "fs"
4+
import http from "http"
5+
import * as httpolyglot from "httpolyglot"
6+
import { DefaultedArgs } from "./cli"
7+
import { handleUpgrade } from "./wsRouter"
8+
9+
/**
10+
* Create an Express app and an HTTP/S server to serve it.
11+
*/
12+
export const createApp = async (args: DefaultedArgs): Promise<[Express, Express, http.Server]> => {
13+
const app = express()
14+
15+
const server = args.cert
16+
? httpolyglot.createServer(
17+
{
18+
cert: args.cert && (await fs.readFile(args.cert.value)),
19+
key: args["cert-key"] && (await fs.readFile(args["cert-key"])),
20+
},
21+
app,
22+
)
23+
: http.createServer(app)
24+
25+
await new Promise<http.Server>(async (resolve, reject) => {
26+
server.on("error", reject)
27+
if (args.socket) {
28+
try {
29+
await fs.unlink(args.socket)
30+
} catch (error) {
31+
if (error.code !== "ENOENT") {
32+
logger.error(error.message)
33+
}
34+
}
35+
server.listen(args.socket, resolve)
36+
} else {
37+
// [] is the correct format when using :: but Node errors with them.
38+
server.listen(args.port, args.host.replace(/^\[|\]$/g, ""), resolve)
39+
}
40+
})
41+
42+
const wsApp = express()
43+
handleUpgrade(wsApp, server)
44+
45+
return [app, wsApp, server]
46+
}
47+
48+
/**
49+
* Get the address of a server as a string (protocol *is* included) while
50+
* ensuring there is one (will throw if there isn't).
51+
*/
52+
export const ensureAddress = (server: http.Server): string => {
53+
const addr = server.address()
54+
if (!addr) {
55+
throw new Error("server has no address")
56+
}
57+
if (typeof addr !== "string") {
58+
return `http://${addr.address}:${addr.port}`
59+
}
60+
return addr
61+
}

src/node/app/health.ts

-21
This file was deleted.

src/node/app/login.ts

-144
This file was deleted.

0 commit comments

Comments
 (0)