From a7a58aa055202686f0983c8741dfb5a777c900a2 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Mon, 17 Sep 2018 13:41:44 -0700 Subject: [PATCH 1/5] Enable strict null checks and restrict DOM access in common Part of #1507 Part of #1319 --- package.json | 4 +++- src/common/EventEmitter.ts | 2 +- src/common/tsconfig.json | 18 ++++++++++++++++++ typings/xterm.d.ts | 2 ++ 4 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 src/common/tsconfig.json diff --git a/package.json b/package.json index 4bdac048..821872bd 100644 --- a/package.json +++ b/package.json @@ -51,6 +51,7 @@ "start": "node demo/start", "start-zmodem": "node demo/zmodem/app", "lint": "tslint 'src/**/*.ts' './demo/**/*.ts'", + "pretest": "npm run layering", "test": "npm-run-all mocha lint", "test-debug": "node --inspect-brk node_modules/.bin/gulp test", "test-suite": "gulp mocha-suite --test", @@ -64,6 +65,7 @@ "coveralls": "nyc report --reporter=text-lcov | coveralls", "webpack": "gulp webpack", "watch": "concurrently --kill-others-on-fail --names \"lib,css\" \"tsc -w\" \"gulp watch-css\"", - "watch-addons": "concurrently --kill-others-on-fail --names \"attach,fit,fullscreen,search,terminado,webLinks,winptyCompat,zmodem\" \"tsc -w -p ./src/addons/attach\" \"tsc -w -p ./src/addons/fit\" \"tsc -w -p ./src/addons/fullscreen\" \"tsc -w -p ./src/addons/search\" \"tsc -w -p ./src/addons/terminado\" \"tsc -w -p ./src/addons/webLinks\" \"tsc -w -p ./src/addons/winptyCompat\" \"tsc -w -p ./src/addons/zmodem\"" + "watch-addons": "concurrently --kill-others-on-fail --names \"attach,fit,fullscreen,search,terminado,webLinks,winptyCompat,zmodem\" \"tsc -w -p ./src/addons/attach\" \"tsc -w -p ./src/addons/fit\" \"tsc -w -p ./src/addons/fullscreen\" \"tsc -w -p ./src/addons/search\" \"tsc -w -p ./src/addons/terminado\" \"tsc -w -p ./src/addons/webLinks\" \"tsc -w -p ./src/addons/winptyCompat\" \"tsc -w -p ./src/addons/zmodem\"", + "layering": "tsc -p ./src/common" } } diff --git a/src/common/EventEmitter.ts b/src/common/EventEmitter.ts index ae8f0069..f9c0c001 100644 --- a/src/common/EventEmitter.ts +++ b/src/common/EventEmitter.ts @@ -14,7 +14,7 @@ export class EventEmitter extends Disposable implements IEventEmitter, IDisposab super(); // Restore the previous events if available, this will happen if the // constructor is called multiple times on the same object (terminal reset). - this._events = this._events || {}; + this._events = (this)._events || {}; } public on(type: string, listener: XtermListener): void { diff --git a/src/common/tsconfig.json b/src/common/tsconfig.json new file mode 100644 index 00000000..34198fdd --- /dev/null +++ b/src/common/tsconfig.json @@ -0,0 +1,18 @@ +{ + "compilerOptions": { + "target": "es5", + "lib": [ + "es5" + ], + "rootDir": ".", + "noEmit": true, + "strict": true, + "types": [ + "../../node_modules/@types/mocha", + "../../" + ] + }, + "include": [ + "./**/*" + ] +} diff --git a/typings/xterm.d.ts b/typings/xterm.d.ts index cc1ebcd9..c82e821e 100644 --- a/typings/xterm.d.ts +++ b/typings/xterm.d.ts @@ -7,6 +7,8 @@ * to be stable and consumed by external programs. */ +/// + declare module 'xterm' { /** * A string representing text font weight. From 33915f3ae0867419b744b49f2a1d7cdc3e5b7f7d Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Tue, 18 Sep 2018 09:49:07 -0700 Subject: [PATCH 2/5] Improve structure of addon tsconfigs --- src/addons/fit/tsconfig.json | 11 +++++++---- src/addons/fullscreen/tsconfig.json | 11 +++++++---- src/addons/search/search.test.ts | 3 ++- src/addons/search/tsconfig.json | 11 +++++++---- src/addons/terminado/tsconfig.json | 11 +++++++---- src/addons/webLinks/tsconfig.json | 9 ++++++--- src/addons/winptyCompat/tsconfig.json | 9 ++++++--- src/addons/zmodem/tsconfig.json | 9 ++++++--- 8 files changed, 48 insertions(+), 26 deletions(-) diff --git a/src/addons/fit/tsconfig.json b/src/addons/fit/tsconfig.json index bccb2ef1..f478e03f 100644 --- a/src/addons/fit/tsconfig.json +++ b/src/addons/fit/tsconfig.json @@ -4,17 +4,20 @@ "target": "es5", "lib": [ "dom", - "es6", + "es5" ], "rootDir": ".", "outDir": "../../../lib/addons/fit/", "sourceMap": true, "removeComments": true, "declaration": true, - "preserveWatchOutput": true + "preserveWatchOutput": true, + "types": [ + "../../node_modules/@types/mocha", + "../.." + ] }, "include": [ - "**/*.ts", - "../../../typings/xterm.d.ts" + "**/*.ts" ] } diff --git a/src/addons/fullscreen/tsconfig.json b/src/addons/fullscreen/tsconfig.json index cdebd36d..40d0ae71 100644 --- a/src/addons/fullscreen/tsconfig.json +++ b/src/addons/fullscreen/tsconfig.json @@ -4,17 +4,20 @@ "target": "es5", "lib": [ "dom", - "es6", + "es5" ], "rootDir": ".", "outDir": "../../../lib/addons/fullscreen/", "sourceMap": true, "removeComments": true, "declaration": true, - "preserveWatchOutput": true + "preserveWatchOutput": true, + "types": [ + "../../node_modules/@types/mocha", + "../.." + ] }, "include": [ - "**/*.ts", - "../../../typings/xterm.d.ts" + "**/*.ts" ] } diff --git a/src/addons/search/search.test.ts b/src/addons/search/search.test.ts index ccdebaf3..3d2a7d9c 100644 --- a/src/addons/search/search.test.ts +++ b/src/addons/search/search.test.ts @@ -7,6 +7,7 @@ import { assert, expect } from 'chai'; import * as search from './search'; import { SearchHelper } from './SearchHelper'; import { ISearchOptions, ISearchResult } from './Interfaces'; +import { Terminal } from '../../../lib/Terminal'; class MockTerminalPlain {} @@ -16,7 +17,7 @@ class MockTerminal { public searchHelper: TestSearchHelper; public cols: number; constructor(options: any) { - this._core = new (require('../../../lib/Terminal').Terminal)(options); + this._core = new Terminal(options); this.searchHelper = new TestSearchHelper(this as any); this.cols = options.cols; } diff --git a/src/addons/search/tsconfig.json b/src/addons/search/tsconfig.json index 5e9fa502..e7a1ff3d 100644 --- a/src/addons/search/tsconfig.json +++ b/src/addons/search/tsconfig.json @@ -4,17 +4,20 @@ "target": "es5", "lib": [ "dom", - "es6", + "es5" ], "rootDir": ".", "outDir": "../../../lib/addons/search/", "sourceMap": true, "removeComments": true, "declaration": true, - "preserveWatchOutput": true + "preserveWatchOutput": true, + "types": [ + "../../node_modules/@types/mocha", + "../.." + ] }, "include": [ - "**/*.ts", - "../../../typings/xterm.d.ts" + "**/*.ts" ] } diff --git a/src/addons/terminado/tsconfig.json b/src/addons/terminado/tsconfig.json index 66e90d90..52b14805 100644 --- a/src/addons/terminado/tsconfig.json +++ b/src/addons/terminado/tsconfig.json @@ -4,17 +4,20 @@ "target": "es5", "lib": [ "dom", - "es6", + "es5", ], "rootDir": ".", "outDir": "../../../lib/addons/terminado/", "sourceMap": true, "removeComments": true, "declaration": true, - "preserveWatchOutput": true + "preserveWatchOutput": true, + "types": [ + "../../node_modules/@types/mocha", + "../.." + ] }, "include": [ - "**/*.ts", - "../../../typings/xterm.d.ts" + "**/*.ts" ] } diff --git a/src/addons/webLinks/tsconfig.json b/src/addons/webLinks/tsconfig.json index a1cc8968..c577386e 100644 --- a/src/addons/webLinks/tsconfig.json +++ b/src/addons/webLinks/tsconfig.json @@ -11,10 +11,13 @@ "sourceMap": true, "removeComments": true, "declaration": true, - "preserveWatchOutput": true + "preserveWatchOutput": true, + "types": [ + "../../node_modules/@types/mocha", + "../.." + ] }, "include": [ - "**/*.ts", - "../../../typings/xterm.d.ts" + "**/*.ts" ] } diff --git a/src/addons/winptyCompat/tsconfig.json b/src/addons/winptyCompat/tsconfig.json index 8a4fe2dc..949fd9ea 100644 --- a/src/addons/winptyCompat/tsconfig.json +++ b/src/addons/winptyCompat/tsconfig.json @@ -11,10 +11,13 @@ "sourceMap": true, "removeComments": true, "declaration": true, - "preserveWatchOutput": true + "preserveWatchOutput": true, + "types": [ + "../../node_modules/@types/mocha", + "../.." + ] }, "include": [ - "**/*.ts", - "../../../typings/xterm.d.ts" + "**/*.ts" ] } diff --git a/src/addons/zmodem/tsconfig.json b/src/addons/zmodem/tsconfig.json index e2fdfeb0..115054ca 100644 --- a/src/addons/zmodem/tsconfig.json +++ b/src/addons/zmodem/tsconfig.json @@ -11,10 +11,13 @@ "sourceMap": true, "removeComments": true, "declaration": true, - "preserveWatchOutput": true + "preserveWatchOutput": true, + "types": [ + "../../node_modules/@types/mocha", + "../.." + ] }, "include": [ - "**/*.ts", - "../../../typings/xterm.d.ts" + "**/*.ts" ] } From fb0b73ab8330571bef48ba220e5c4ef003d6f2f2 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Tue, 18 Sep 2018 10:21:55 -0700 Subject: [PATCH 3/5] Enforce core layering and enable strict Part of #1507 Part of #1319 --- package.json | 2 +- src/common/tsconfig.json | 1 + src/core/data/Charsets.ts | 4 ++-- src/core/input/Keyboard.test.ts | 5 +++-- src/core/tsconfig.json | 20 ++++++++++++++++++++ 5 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 src/core/tsconfig.json diff --git a/package.json b/package.json index 2d4ff239..eaf3ad8c 100644 --- a/package.json +++ b/package.json @@ -66,6 +66,6 @@ "webpack": "gulp webpack", "watch": "concurrently --kill-others-on-fail --names \"lib,css\" \"tsc -w\" \"gulp watch-css\"", "watch-addons": "concurrently --kill-others-on-fail --names \"attach,fit,fullscreen,search,terminado,webLinks,winptyCompat,zmodem\" \"tsc -w -p ./src/addons/attach\" \"tsc -w -p ./src/addons/fit\" \"tsc -w -p ./src/addons/fullscreen\" \"tsc -w -p ./src/addons/search\" \"tsc -w -p ./src/addons/terminado\" \"tsc -w -p ./src/addons/webLinks\" \"tsc -w -p ./src/addons/winptyCompat\" \"tsc -w -p ./src/addons/zmodem\"", - "layering": "tsc -p ./src/common" + "layering": "concurrently --kill-others-on-fail --names \"common,core\" \"tsc -p ./src/common\" \"tsc -p ./src/core\"" } } diff --git a/src/common/tsconfig.json b/src/common/tsconfig.json index 34198fdd..19dd0273 100644 --- a/src/common/tsconfig.json +++ b/src/common/tsconfig.json @@ -7,6 +7,7 @@ "rootDir": ".", "noEmit": true, "strict": true, + "pretty": true, "types": [ "../../node_modules/@types/mocha", "../../" diff --git a/src/core/data/Charsets.ts b/src/core/data/Charsets.ts index b49ee77f..5fc36ac1 100644 --- a/src/core/data/Charsets.ts +++ b/src/core/data/Charsets.ts @@ -10,12 +10,12 @@ import { ICharset } from '../Types'; * to be represented within the terminal with only 8-bit encoding. See ISO 2022 * for a discussion on character sets. Only VT100 character sets are supported. */ -export const CHARSETS: { [key: string]: ICharset } = {}; +export const CHARSETS: { [key: string]: ICharset | null } = {}; /** * The default character set, US. */ -export const DEFAULT_CHARSET: ICharset = CHARSETS['B']; +export const DEFAULT_CHARSET: ICharset | null = CHARSETS['B']; /** * DEC Special Character and Line Drawing Set. diff --git a/src/core/input/Keyboard.test.ts b/src/core/input/Keyboard.test.ts index 1104fc61..e9846831 100644 --- a/src/core/input/Keyboard.test.ts +++ b/src/core/input/Keyboard.test.ts @@ -2,6 +2,7 @@ import { assert } from 'chai'; import { evaluateKeyboardEvent } from './Keyboard'; import { IKeyboardResult } from '../Types'; +import { IKeyboardEvent } from '../../common/Types'; /** * A helper function for testing which allows passing in a partial event and defaults will be filled @@ -20,12 +21,12 @@ function testEvaluateKeyboardEvent(partialEvent: { isMac?: boolean; macOptionIsMeta?: boolean; } = {}): IKeyboardResult { - const event = { + const event: IKeyboardEvent = { altKey: partialEvent.altKey || false, ctrlKey: partialEvent.ctrlKey || false, shiftKey: partialEvent.shiftKey || false, metaKey: partialEvent.metaKey || false, - keyCode: partialEvent.keyCode !== undefined ? partialEvent.keyCode : undefined, + keyCode: partialEvent.keyCode !== undefined ? partialEvent.keyCode : 0, key: partialEvent.key || '', type: partialEvent.type || '' }; diff --git a/src/core/tsconfig.json b/src/core/tsconfig.json new file mode 100644 index 00000000..4f024a28 --- /dev/null +++ b/src/core/tsconfig.json @@ -0,0 +1,20 @@ +{ + "compilerOptions": { + "target": "es5", + "lib": [ + "es5" + ], + "rootDir": ".", + "noEmit": true, + "strict": true, + "pretty": true, + "types": [ + "../../node_modules/@types/mocha", + "../../" + ] + }, + "include": [ + "./**/*", + "../common/**/*" + ] +} From 57bbc817bb8e21049f5f1787210a4f0b8bf67318 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Tue, 18 Sep 2018 10:25:49 -0700 Subject: [PATCH 4/5] Reduce addon lib usage --- src/addons/search/tsconfig.json | 1 - src/addons/terminado/tsconfig.json | 3 +-- src/addons/webLinks/tsconfig.json | 2 +- src/addons/winptyCompat/tsconfig.json | 3 +-- src/addons/zmodem/tsconfig.json | 3 +-- 5 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/addons/search/tsconfig.json b/src/addons/search/tsconfig.json index e7a1ff3d..c34a0bc5 100644 --- a/src/addons/search/tsconfig.json +++ b/src/addons/search/tsconfig.json @@ -3,7 +3,6 @@ "module": "commonjs", "target": "es5", "lib": [ - "dom", "es5" ], "rootDir": ".", diff --git a/src/addons/terminado/tsconfig.json b/src/addons/terminado/tsconfig.json index 52b14805..0e30963d 100644 --- a/src/addons/terminado/tsconfig.json +++ b/src/addons/terminado/tsconfig.json @@ -3,8 +3,7 @@ "module": "commonjs", "target": "es5", "lib": [ - "dom", - "es5", + "es5" ], "rootDir": ".", "outDir": "../../../lib/addons/terminado/", diff --git a/src/addons/webLinks/tsconfig.json b/src/addons/webLinks/tsconfig.json index c577386e..6f9db2cb 100644 --- a/src/addons/webLinks/tsconfig.json +++ b/src/addons/webLinks/tsconfig.json @@ -4,7 +4,7 @@ "target": "es5", "lib": [ "dom", - "es6", + "es5", ], "rootDir": ".", "outDir": "../../../lib/addons/webLinks/", diff --git a/src/addons/winptyCompat/tsconfig.json b/src/addons/winptyCompat/tsconfig.json index 949fd9ea..6056da08 100644 --- a/src/addons/winptyCompat/tsconfig.json +++ b/src/addons/winptyCompat/tsconfig.json @@ -3,8 +3,7 @@ "module": "commonjs", "target": "es5", "lib": [ - "dom", - "es6", + "es5" ], "rootDir": ".", "outDir": "../../../lib/addons/winptyCompat/", diff --git a/src/addons/zmodem/tsconfig.json b/src/addons/zmodem/tsconfig.json index 115054ca..5dd438a3 100644 --- a/src/addons/zmodem/tsconfig.json +++ b/src/addons/zmodem/tsconfig.json @@ -3,8 +3,7 @@ "module": "commonjs", "target": "es5", "lib": [ - "dom", - "es6", + "es5" ], "rootDir": ".", "outDir": "../../../lib/addons/zmodem/", From 995e384980ea2b022136abbdbb6699210e43f2f0 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Fri, 21 Sep 2018 07:31:06 -0700 Subject: [PATCH 5/5] Fix search addon build --- src/addons/search/search.test.ts | 4 +--- src/addons/search/tsconfig.json | 3 +++ 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/addons/search/search.test.ts b/src/addons/search/search.test.ts index 3d2a7d9c..1fe18b6a 100644 --- a/src/addons/search/search.test.ts +++ b/src/addons/search/search.test.ts @@ -7,8 +7,6 @@ import { assert, expect } from 'chai'; import * as search from './search'; import { SearchHelper } from './SearchHelper'; import { ISearchOptions, ISearchResult } from './Interfaces'; -import { Terminal } from '../../../lib/Terminal'; - class MockTerminalPlain {} @@ -17,7 +15,7 @@ class MockTerminal { public searchHelper: TestSearchHelper; public cols: number; constructor(options: any) { - this._core = new Terminal(options); + this._core = new (require('../../../lib/Terminal')).Terminal(options); this.searchHelper = new TestSearchHelper(this as any); this.cols = options.cols; } diff --git a/src/addons/search/tsconfig.json b/src/addons/search/tsconfig.json index c34a0bc5..9998dc1b 100644 --- a/src/addons/search/tsconfig.json +++ b/src/addons/search/tsconfig.json @@ -18,5 +18,8 @@ }, "include": [ "**/*.ts" + ], + "exclude": [ + "**/*.test.ts" ] }