Enable strict mode on all TypeScript

This commit is contained in:
Radon Rosborough 2020-06-12 15:03:03 -06:00
parent 0dbb561063
commit 4ccb25a947
7 changed files with 35 additions and 27 deletions

View File

@ -1,5 +1,3 @@
"use strict";
import * as fs from "fs"; import * as fs from "fs";
import * as mkdirp from "mkdirp"; import * as mkdirp from "mkdirp";
import * as pty from "node-pty"; import * as pty from "node-pty";
@ -13,7 +11,7 @@ import { LangConfig, langs } from "./langs";
export class Session { export class Session {
code: string; code: string;
config: LangConfig; config: LangConfig;
term: { pty: IPty; live: boolean }; term: { pty: IPty | null; live: boolean };
ws: WebSocket; ws: WebSocket;
constructor(ws: WebSocket, lang: string) { constructor(ws: WebSocket, lang: string) {
@ -39,7 +37,7 @@ export class Session {
} else if (typeof msg.input !== "string") { } else if (typeof msg.input !== "string") {
console.error(`terminalInput: missing or malformed input field`); console.error(`terminalInput: missing or malformed input field`);
} else { } else {
this.term.pty.write(msg.input); this.term.pty!.write(msg.input);
} }
break; break;
case "runCode": case "runCode":
@ -132,7 +130,7 @@ export class Session {
pty: pty.spawn("bash", ["-c", cmdline], { pty: pty.spawn("bash", ["-c", cmdline], {
name: "xterm-color", name: "xterm-color",
cwd: tmpdir, cwd: tmpdir,
env: process.env, env: process.env as { [key: string]: string },
}), }),
live: true, live: true,
}; };

View File

@ -1,5 +1,3 @@
"use strict";
export interface LangConfig { export interface LangConfig {
aliases?: string[]; aliases?: string[];
name: string; name: string;

View File

@ -1,5 +1,3 @@
"use strict";
import * as http from "http"; import * as http from "http";
import * as https from "https"; import * as https from "https";
@ -13,8 +11,8 @@ import * as api from "./api";
import { langs } from "./langs"; import { langs } from "./langs";
const host = process.env.HOST || "localhost"; const host = process.env.HOST || "localhost";
const port = parseInt(process.env.PORT) || 6119; const port = parseInt(process.env.PORT || "") || 6119;
const tlsPort = parseInt(process.env.TLS_PORT) || 6120; const tlsPort = parseInt(process.env.TLS_PORT || "") || 6120;
const useTLS = process.env.TLS ? true : false; const useTLS = process.env.TLS ? true : false;
const app = express(); const app = express();
@ -56,7 +54,10 @@ app.get("/:lang", (req, res) => {
app.use("/css", express.static(appRoot.path + "/frontend/styles")); app.use("/css", express.static(appRoot.path + "/frontend/styles"));
app.use("/js", express.static(appRoot.path + "/frontend/out")); app.use("/js", express.static(appRoot.path + "/frontend/out"));
function addWebsocket(baseApp: express.Express, httpsServer: https.Server) { function addWebsocket(
baseApp: express.Express,
httpsServer: https.Server | undefined
) {
const app = ws(baseApp, httpsServer).app; const app = ws(baseApp, httpsServer).app;
app.ws("/api/v1/ws", (ws, req) => { app.ws("/api/v1/ws", (ws, req) => {
const lang = getQueryParams(req).get("lang"); const lang = getQueryParams(req).get("lang");
@ -77,7 +78,7 @@ function addWebsocket(baseApp: express.Express, httpsServer: https.Server) {
); );
ws.close(); ws.close();
} else { } else {
new api.Session(ws, getQueryParams(req).get("lang")); new api.Session(ws, lang);
} }
}); });
return app; return app;
@ -86,8 +87,10 @@ function addWebsocket(baseApp: express.Express, httpsServer: https.Server) {
if (useTLS) { if (useTLS) {
const httpsServer = https.createServer( const httpsServer = https.createServer(
{ {
key: Buffer.from(process.env.TLS_PRIVATE_KEY, "base64").toString("ascii"), key: Buffer.from(process.env.TLS_PRIVATE_KEY || "", "base64").toString(
cert: Buffer.from(process.env.TLS_CERTIFICATE, "base64").toString( "ascii"
),
cert: Buffer.from(process.env.TLS_CERTIFICATE || "", "base64").toString(
"ascii" "ascii"
), ),
}, },

View File

@ -1,5 +1,3 @@
"use strict";
import * as monaco from "monaco-editor"; import * as monaco from "monaco-editor";
import { Terminal } from "xterm"; import { Terminal } from "xterm";
import { FitAddon } from "xterm-addon-fit"; import { FitAddon } from "xterm-addon-fit";
@ -17,7 +15,7 @@ const config: RijuConfig = (window as any).rijuConfig;
const term = new Terminal(); const term = new Terminal();
const fitAddon = new FitAddon(); const fitAddon = new FitAddon();
term.loadAddon(fitAddon); term.loadAddon(fitAddon);
term.open(document.getElementById("terminal")); term.open(document.getElementById("terminal")!);
fitAddon.fit(); fitAddon.fit();
window.addEventListener("resize", () => fitAddon.fit()); window.addEventListener("resize", () => fitAddon.fit());
@ -81,21 +79,23 @@ function scheduleConnect() {
retryDelayMs *= 2; retryDelayMs *= 2;
} }
let socket = null; let socket: WebSocket | null = null;
tryConnect(); tryConnect();
term.onData((data) => term.onData(
socket.send(JSON.stringify({ event: "terminalInput", input: data })) (data) =>
socket &&
socket.send(JSON.stringify({ event: "terminalInput", input: data }))
); );
const editor = monaco.editor.create(document.getElementById("editor"), { const editor = monaco.editor.create(document.getElementById("editor")!, {
minimap: { enabled: false }, minimap: { enabled: false },
scrollbar: { verticalScrollbarSize: 0 }, scrollbar: { verticalScrollbarSize: 0 },
}); });
window.addEventListener("resize", () => editor.layout()); window.addEventListener("resize", () => editor.layout());
editor.getModel().setValue(config.template); editor.getModel()!.setValue(config.template);
monaco.editor.setModelLanguage(editor.getModel(), config.monacoLang); monaco.editor.setModelLanguage(editor.getModel()!, config.monacoLang);
document.getElementById("runButton").addEventListener("click", () => { document.getElementById("runButton")!.addEventListener("click", () => {
socket.send(JSON.stringify({ event: "runCode", code: editor.getValue() })); socket?.send(JSON.stringify({ event: "runCode", code: editor.getValue() }));
}); });

View File

@ -8,6 +8,7 @@
"@types/express": "^4.17.6", "@types/express": "^4.17.6",
"@types/express-ws": "^3.0.0", "@types/express-ws": "^3.0.0",
"@types/lodash": "^4.14.155", "@types/lodash": "^4.14.155",
"@types/mkdirp": "^1.0.1",
"@types/tmp": "^0.2.0", "@types/tmp": "^0.2.0",
"app-root-path": "^3.0.0", "app-root-path": "^3.0.0",
"css-loader": "^3.5.3", "css-loader": "^3.5.3",

View File

@ -3,7 +3,8 @@
"outDir": "./backend/out", "outDir": "./backend/out",
"resolveJsonModule": true, "resolveJsonModule": true,
"rootDir": "./backend/src", "rootDir": "./backend/src",
"sourceMap": true "sourceMap": true,
"strict": true
}, },
"include": ["backend/src"] "include": ["backend/src"]
} }

View File

@ -65,6 +65,13 @@
resolved "https://registry.yarnpkg.com/@types/mime/-/mime-2.0.2.tgz#857a118d8634c84bba7ae14088e4508490cd5da5" resolved "https://registry.yarnpkg.com/@types/mime/-/mime-2.0.2.tgz#857a118d8634c84bba7ae14088e4508490cd5da5"
integrity sha512-4kPlzbljFcsttWEq6aBW0OZe6BDajAmyvr2xknBG92tejQnvdGtT9+kXSZ580DqpxY9qG2xeQVF9Dq0ymUTo5Q== integrity sha512-4kPlzbljFcsttWEq6aBW0OZe6BDajAmyvr2xknBG92tejQnvdGtT9+kXSZ580DqpxY9qG2xeQVF9Dq0ymUTo5Q==
"@types/mkdirp@^1.0.1":
version "1.0.1"
resolved "https://registry.yarnpkg.com/@types/mkdirp/-/mkdirp-1.0.1.tgz#0930b948914a78587de35458b86c907b6e98bbf6"
integrity sha512-HkGSK7CGAXncr8Qn/0VqNtExEE+PHMWb+qlR1faHMao7ng6P3tAaoWWBMdva0gL5h4zprjIO89GJOLXsMcDm1Q==
dependencies:
"@types/node" "*"
"@types/node@*": "@types/node@*":
version "14.0.11" version "14.0.11"
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.0.11.tgz#61d4886e2424da73b7b25547f59fdcb534c165a3" resolved "https://registry.yarnpkg.com/@types/node/-/node-14.0.11.tgz#61d4886e2424da73b7b25547f59fdcb534c165a3"