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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -65,6 +65,13 @@
resolved "https://registry.yarnpkg.com/@types/mime/-/mime-2.0.2.tgz#857a118d8634c84bba7ae14088e4508490cd5da5"
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@*":
version "14.0.11"
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.0.11.tgz#61d4886e2424da73b7b25547f59fdcb534c165a3"