1
1
mirror of https://github.com/Eugeny/tabby.git synced 2024-12-18 07:31:33 +03:00
tabby/web/polyfills.ts

169 lines
5.2 KiB
TypeScript
Raw Normal View History

2021-06-19 23:59:15 +03:00
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
2021-06-19 23:52:18 +03:00
/* eslint-disable @typescript-eslint/no-empty-function */
/* eslint-disable @typescript-eslint/no-extraneous-class */
2021-06-16 00:43:02 +03:00
import * as angularCoreModule from '@angular/core'
import * as angularCompilerModule from '@angular/compiler'
import * as angularCommonModule from '@angular/common'
import * as angularFormsModule from '@angular/forms'
import * as angularPlatformBrowserModule from '@angular/platform-browser'
import * as angularPlatformBrowserAnimationsModule from '@angular/platform-browser/animations'
import * as angularPlatformBrowserDynamicModule from '@angular/platform-browser-dynamic'
import * as angularAnimationsModule from '@angular/animations'
import * as ngBootstrapModule from '@ng-bootstrap/ng-bootstrap'
import * as ngxToastrModule from 'ngx-toastr'
2021-06-19 23:52:18 +03:00
import './polyfills.buffer'
import { Duplex } from 'stream-browserify'
2021-06-16 00:43:02 +03:00
2021-06-30 00:57:04 +03:00
const Tabby = window['Tabby']
2021-06-16 00:43:02 +03:00
2021-06-19 23:52:18 +03:00
export class SocketProxy extends Duplex {
socket: any
2021-06-16 00:43:02 +03:00
2021-06-19 23:59:15 +03:00
constructor (...args: any[]) {
2021-06-19 23:52:18 +03:00
super({
allowHalfOpen: false,
})
2021-06-22 12:51:52 +03:00
this.socket = window['__connector__'].createSocket(...args)
2021-06-19 23:52:18 +03:00
this.socket.connect$.subscribe(() => this['emit']('connect'))
this.socket.data$.subscribe(data => this['emit']('data', Buffer.from(data)))
2021-06-22 12:51:52 +03:00
this.socket.error$.subscribe(error => this['emit']('error', error))
2021-06-19 23:52:18 +03:00
}
2021-06-19 23:59:15 +03:00
connect (...args: any[]) {
2021-06-19 23:52:18 +03:00
this.socket.connect(...args)
}
setNoDelay () { }
setTimeout () { }
_read (_size: number): void { }
_write (chunk: Buffer, _encoding: string, callback: (error?: Error | null) => void): void {
this.socket.write(chunk)
callback()
}
_destroy (error: Error|null, callback: (error: Error|null) => void): void {
this.socket.close(error)
callback(error)
}
}
2021-06-16 00:43:02 +03:00
2021-06-30 00:57:04 +03:00
Tabby.registerMock('fs', {
2021-06-25 22:55:34 +03:00
realpathSync: () => null,
readdir: () => null,
stat: () => null,
appendFile: () => null,
constants: {},
})
2021-06-30 00:57:04 +03:00
Tabby.registerMock('any-promise', Promise)
Tabby.registerMock('tls', {})
Tabby.registerMock('module', {
2021-06-25 22:55:34 +03:00
globalPaths: [],
prototype: { require: window['require'] },
})
2021-06-30 00:57:04 +03:00
Tabby.registerMock('url', {
2021-06-25 22:55:34 +03:00
parse: () => null,
})
2021-06-30 00:57:04 +03:00
Tabby.registerMock('http', {
2021-06-25 22:55:34 +03:00
Agent: class {},
request: {},
})
2021-06-30 00:57:04 +03:00
Tabby.registerMock('https', {
2021-06-25 22:55:34 +03:00
Agent: class {},
request: {},
})
2021-06-30 00:57:04 +03:00
Tabby.registerMock('querystring', {})
Tabby.registerMock('tty', { isatty: () => false })
Tabby.registerMock('child_process', {})
Tabby.registerMock('readable-stream', {})
Tabby.registerMock('os', {
2021-06-25 22:55:34 +03:00
platform: () => 'web',
homedir: () => '/home',
})
2021-06-30 00:57:04 +03:00
Tabby.registerModule('buffer', {
2021-06-25 22:55:34 +03:00
Buffer: window['Buffer'],
})
2021-06-30 00:57:04 +03:00
Tabby.registerModule('crypto', {
2021-06-25 22:55:34 +03:00
...require('crypto-browserify'),
getHashes () {
return ['sha1', 'sha224', 'sha256', 'sha384', 'sha512', 'md5', 'rmd160']
2021-06-16 00:43:02 +03:00
},
2021-06-25 22:55:34 +03:00
timingSafeEqual (a, b) {
return a.equals(b)
2021-06-16 00:43:02 +03:00
},
2021-06-25 22:55:34 +03:00
})
2021-06-30 00:57:04 +03:00
Tabby.registerMock('hterm-umdjs', {
2021-06-25 22:55:34 +03:00
hterm: {
PreferenceManager: class { set () {} },
VT: {
ESC: {},
CSI: {},
OSC: {},
2021-06-16 00:43:02 +03:00
},
2021-06-25 22:55:34 +03:00
Terminal: class {},
Keyboard: class {},
2021-06-16 00:43:02 +03:00
},
2021-06-25 22:55:34 +03:00
lib: {
wc: {},
Storage: {
Memory: class {},
2021-06-16 00:43:02 +03:00
},
},
2021-06-25 22:55:34 +03:00
})
2021-06-30 00:57:04 +03:00
Tabby.registerMock('dns', {})
Tabby.registerMock('socksv5', {})
Tabby.registerMock('util', require('util/'))
Tabby.registerMock('keytar', {
2021-06-25 22:55:34 +03:00
getPassword: () => null,
})
2021-07-11 23:59:39 +03:00
Tabby.registerMock('@serialport/bindings', {})
2021-06-16 00:43:02 +03:00
2021-06-30 00:57:04 +03:00
Tabby.registerModule('net', {
2021-06-25 22:55:34 +03:00
Socket: SocketProxy,
})
2021-06-30 00:57:04 +03:00
Tabby.registerModule('events', require('events'))
Tabby.registerModule('path', require('path-browserify'))
Tabby.registerModule('zlib', {
2021-06-25 22:55:34 +03:00
...require('browserify-zlib'),
constants: require('browserify-zlib'),
})
2021-06-30 00:57:04 +03:00
Tabby.registerModule('assert', Object.assign(
2021-06-25 22:55:34 +03:00
require('assert'),
{
assertNotStrictEqual: () => true,
notStrictEqual: () => true,
},
))
2021-06-30 00:57:04 +03:00
Tabby.registerModule('constants', require('constants-browserify'))
Tabby.registerModule('stream', require('stream-browserify'))
2021-07-11 23:59:39 +03:00
Tabby.registerModule('readline', {
...require('readline-browserify'),
cursorTo: () => null,
clearLine: stream => stream.write('\r'),
})
2021-06-25 22:55:34 +03:00
2021-06-30 00:57:04 +03:00
Tabby.registerModule('@angular/core', angularCoreModule)
Tabby.registerModule('@angular/compiler', angularCompilerModule)
Tabby.registerModule('@angular/common', angularCommonModule)
Tabby.registerModule('@angular/forms', angularFormsModule)
Tabby.registerModule('@angular/platform-browser', angularPlatformBrowserModule)
Tabby.registerModule('@angular/platform-browser/animations', angularPlatformBrowserAnimationsModule)
Tabby.registerModule('@angular/platform-browser-dynamic', angularPlatformBrowserDynamicModule)
Tabby.registerModule('@angular/animations', angularAnimationsModule)
Tabby.registerModule('@ng-bootstrap/ng-bootstrap', ngBootstrapModule)
Tabby.registerModule('ngx-toastr', ngxToastrModule)
Tabby.registerModule('deepmerge', require('deepmerge'))
Tabby.registerModule('rxjs', require('rxjs'))
Tabby.registerModule('rxjs/operators', require('rxjs'))
2021-06-30 00:57:04 +03:00
Tabby.registerModule('js-yaml', require('js-yaml'))
Tabby.registerModule('zone.js/dist/zone.js', require('zone.js/dist/zone.js'))
2021-06-16 00:43:02 +03:00
Object.assign(window, {
2021-06-19 23:52:18 +03:00
__dirname: '__dirname',
setImmediate: setTimeout as any,
2021-06-16 00:43:02 +03:00
})