Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade typescript #399

Merged
merged 4 commits into from
Apr 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 135 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
module.exports = {
"env": {
"browser": true,
"es6": true,
"node": true
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "src/tsconfig.json",
"sourceType": "module"
},
"ignorePatterns": "**/typings/*.d.ts",
"plugins": [
"@typescript-eslint"
],
"rules": {
"@typescript-eslint/array-type": [
"error",
{
"default": "array-simple",
"readonly": "generic"
}
],
"@typescript-eslint/class-name-casing": "error",
"@typescript-eslint/consistent-type-definitions": "error",
"@typescript-eslint/explicit-function-return-type": [
"error",
{
"allowExpressions": true
}
],
"@typescript-eslint/indent": [
"error",
2
],
"@typescript-eslint/interface-name-prefix": [
"error",
"always"
],
"@typescript-eslint/member-delimiter-style": [
"error",
{
"multiline": {
"delimiter": "semi",
"requireLast": true
},
"singleline": {
"delimiter": "comma",
"requireLast": false
}
}
],
"@typescript-eslint/naming-convention": [
"error",
{ "selector": "default", "format": ["camelCase"] },
// variableLike
{ "selector": "variable", "format": ["camelCase", "UPPER_CASE"] },
{ "selector": "variable", "filter": "^I.+Service$", "format": ["PascalCase"], "prefix": ["I"] },
// memberLike
{ "selector": "memberLike", "modifiers": ["private"], "format": ["camelCase"], "leadingUnderscore": "require" },
{ "selector": "memberLike", "modifiers": ["protected"], "format": ["camelCase"], "leadingUnderscore": "require" },
{ "selector": "enumMember", "format": ["UPPER_CASE"] },
// memberLike - Allow enum-like objects to use UPPER_CASE
{ "selector": "property", "modifiers": ["public"], "format": ["camelCase", "UPPER_CASE"] },
{ "selector": "method", "modifiers": ["public"], "format": ["camelCase", "UPPER_CASE"] },
// typeLike
{ "selector": "typeLike", "format": ["PascalCase"] },
{ "selector": "interface", "format": ["PascalCase"], "prefix": ["I"] },
],
"@typescript-eslint/prefer-namespace-keyword": "error",
"@typescript-eslint/type-annotation-spacing": "error",
"@typescript-eslint/quotes": [
"error",
"single",
{ "allowTemplateLiterals": true }
],
"@typescript-eslint/semi": [
"error",
"always"
],
"@typescript-eslint/type-annotation-spacing": "error",
"comma-dangle": [
"error",
{
"objects": "never",
"arrays": "never",
"functions": "never"
}
],
"curly": [
"error",
"multi-line"
],
"eol-last": "error",
"eqeqeq": [
"error",
"always"
],
"keyword-spacing": "error",
"new-parens": "error",
"no-duplicate-imports": "error",
"no-else-return": [
"error",
{
allowElseIf: false
}
],
"no-eval": "error",
"no-irregular-whitespace": "error",
"no-restricted-imports": [
"error",
{
"patterns": [
".*\\/out\\/.*"
]
}
],
"no-trailing-spaces": "error",
"no-unsafe-finally": "error",
"no-var": "error",
"one-var": [
"error",
"never"
],
"prefer-const": "error",
"spaced-comment": [
"error",
"always",
{
"markers": ["/"],
"exceptions": ["-"]
}
]
}
};
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ ptyProcess.write('ls\r');
# Install dependencies and build C++
npm install
# Compile TypeScript -> JavaScript
npm run tsc
npm run build
```

## Dependencies
Expand Down
18 changes: 10 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,28 @@
"openpty"
],
"scripts": {
"tsc": "tsc",
"watch": "tsc -w",
"lint": "tslint 'src/**/*.ts'",
"build": "tsc -b ./src/tsconfig.json",
"watch": "tsc -b -w ./src/tsconfig.json",
"lint": "eslint -c .eslintrc.js --ext .ts src/",
"install": "node scripts/install.js",
"postinstall": "node scripts/post-install.js",
"test": "cross-env NODE_ENV=test mocha -R spec --exit lib/*.test.js",
"prepare": "npm run tsc",
"prepublishOnly": "npm run tsc"
"posttest": "npm run lint",
"prepare": "npm run build",
"prepublishOnly": "npm run build"
},
"dependencies": {
"nan": "^2.14.0"
},
"devDependencies": {
"@types/mocha": "^7.0.2",
"@types/node": "8",
"@typescript-eslint/eslint-plugin": "^2.27.0",
"@typescript-eslint/parser": "^2.27.0",
"cross-env": "^5.1.4",
"eslint": "^6.8.0",
"mocha": "^7.1.1",
"ps-list": "^6.0.0",
"tslint": "5.12.1",
"tslint-consistent-codestyle": "^1.15.0",
"typescript": "3.4"
"typescript": "^3.8.3"
}
}
4 changes: 2 additions & 2 deletions src/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ export abstract class Terminal implements ITerminal {

/** See net.Socket.setEncoding */
public setEncoding(encoding: string | null): void {
if ((<any>this._socket)._decoder) {
delete (<any>this._socket)._decoder;
if ((this._socket as any)._decoder) {
delete (this._socket as any)._decoder;
}
if (encoding) {
this._socket.setEncoding(encoding);
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json → src/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"rootDir": "src",
"outDir": "lib",
"rootDir": ".",
"outDir": "../lib",
"sourceMap": true,
"lib": [
"es2015"
Expand Down
7 changes: 3 additions & 4 deletions src/unixTerminal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ if (process.platform !== 'win32') {
describe('Constructor', () => {
it('should set a valid pts name', () => {
const term = new UnixTerminal('/bin/bash', [], {});
let regExp;
let regExp: RegExp;
if (process.platform === 'linux') {
// https://linux.die.net/man/4/pts
regExp = /^\/dev\/pts\/\d+$/;
Expand Down Expand Up @@ -80,7 +80,6 @@ if (process.platform !== 'win32') {
});

it('should open a pty with access to a master and slave socket', (done) => {
let doneCalled = false;
term = UnixTerminal.open({});

let slavebuf = '';
Expand Down Expand Up @@ -125,7 +124,7 @@ if (process.platform !== 'win32') {
setTimeout(() => null, 500);
console.log('ready', ptyProcess.pid);
`;
let buffer: string[] = [];
const buffer: string[] = [];
const p = cp.spawn('node', ['-e', data]);
let sub = '';
p.stdout.on('data', (data) => {
Expand Down Expand Up @@ -166,7 +165,7 @@ if (process.platform !== 'win32') {
setTimeout(() => null, 500);
console.log('ready', ptyProcess.pid);
`;
let buffer: string[] = [];
const buffer: string[] = [];
const p = cp.spawn('node', ['-e', data]);
let sub = '';
p.stdout.on('data', (data) => {
Expand Down
38 changes: 19 additions & 19 deletions src/unixTerminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class UnixTerminal extends Terminal {

const encoding = (opt.encoding === undefined ? 'utf8' : opt.encoding);

const onexit = (code: number, signal: number) => {
const onexit = (code: number, signal: number): void => {
// XXX Sometimes a data event is emitted after exit. Wait til socket is
// destroyed.
if (!this._emittedClose) {
Expand Down Expand Up @@ -193,13 +193,13 @@ export class UnixTerminal extends Terminal {

self._master = new PipeSocket(<number>term.master);
if (encoding !== null) {
self._master.setEncoding(encoding);
self._master.setEncoding(encoding);
}
self._master.resume();

self._slave = new PipeSocket(term.slave);
if (encoding !== null) {
self._slave.setEncoding(encoding);
self._slave.setEncoding(encoding);
}
self._slave.resume();

Expand Down Expand Up @@ -267,20 +267,20 @@ export class UnixTerminal extends Terminal {
}

private _sanitizeEnv(env: IProcessEnv): void {
// Make sure we didn't start our server from inside tmux.
delete env['TMUX'];
delete env['TMUX_PANE'];

// Make sure we didn't start our server from inside screen.
// http://web.mit.edu/gnu/doc/html/screen_20.html
delete env['STY'];
delete env['WINDOW'];

// Delete some variables that might confuse our terminal.
delete env['WINDOWID'];
delete env['TERMCAP'];
delete env['COLUMNS'];
delete env['LINES'];
// Make sure we didn't start our server from inside tmux.
delete env['TMUX'];
delete env['TMUX_PANE'];

// Make sure we didn't start our server from inside screen.
// http://web.mit.edu/gnu/doc/html/screen_20.html
delete env['STY'];
delete env['WINDOW'];

// Delete some variables that might confuse our terminal.
delete env['WINDOWID'];
delete env['TERMCAP'];
delete env['COLUMNS'];
delete env['LINES'];
}
}

Expand All @@ -291,9 +291,9 @@ export class UnixTerminal extends Terminal {
*/
class PipeSocket extends net.Socket {
constructor(fd: number) {
const { Pipe, constants } = (<any>process).binding('pipe_wrap'); // tslint:disable-line
const pipeWrap = (<any>process).binding('pipe_wrap'); // tslint:disable-line
// @types/node has fd as string? https://github.com/DefinitelyTyped/DefinitelyTyped/pull/18275
const handle = new Pipe(constants.SOCKET);
const handle = new pipeWrap.Pipe(pipeWrap.constants.SOCKET);
handle.open(fd);
super(<any>{ handle });
}
Expand Down
3 changes: 1 addition & 2 deletions src/windowsPtyAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,7 @@ export class WindowsPtyAgent {
// TODO: Wait for ready event?

if (this._useConpty) {
const connect = (this._ptyNative as IConptyNative).connect(this._pty, commandLine, cwd, env, c => this._$onProcessExit(c)
);
const connect = (this._ptyNative as IConptyNative).connect(this._pty, commandLine, cwd, env, c => this._$onProcessExit(c));
this._innerPid = connect.pid;
}
}
Expand Down
Loading