feat: use pnpm & lock core-js shim

This commit is contained in:
2023-10-25 11:29:01 +08:00
parent 5bf4b1c09e
commit 54eaae96bd
32 changed files with 444 additions and 178 deletions

View File

@@ -18,10 +18,11 @@
"scripts": {
"clean": "rimraf dist",
"watch": "tsc --watch",
"build": "yarn clean && tsc",
"build": "pnpm clean && tsc",
"test": "echo \"Error: run tests from root\" && exit 1"
},
"dependencies": {
"@ccms/i18n": "^0.28.0-beta.3",
"@ccms/common": "^0.28.0-beta.3",
"@ccms/container": "^0.28.0-beta.3",
"@ccms/polyfill": "^0.28.0-beta.3",
@@ -29,9 +30,6 @@
"source-map-builder": "^0.0.7"
},
"devDependencies": {
"@types/base64-js": "^1.3.0",
"reflect-metadata": "^0.1.13",
"rimraf": "^4.4.1",
"typescript": "^4.9.5"
"@types/base64-js": "^1.3.0"
}
}

View File

@@ -9,8 +9,7 @@ export namespace command {
* first time script engine need optimize jit code
* so ignore first slow exec notify
*/
private cacheSlowCommandKey = {};
private cacheSlowCompleteKey = {};
private cacheSlowKeys = {};
/**
* 注册插件命令
@@ -53,32 +52,13 @@ export namespace command {
try {
let time = Date.now()
let result = executor(sender, command, Java.from(args))
let cost = Date.now() - time
if (cost > global.ScriptSlowExecuteTime) {
let commandKey = `${plugin.description.name}-${command}-${sender.name}`
if (!this.cacheSlowCommandKey[commandKey]) { return this.cacheSlowCommandKey[commandKey] = cost }
console.i18n("ms.api.command.execute.slow", {
player: sender.name,
plugin: plugin.description.name,
command,
args: Java.from(args).join(' '),
cost
})
}
this.checkSlow(Date.now() - time,
"ms.api.command.execute.slow",
plugin, command, sender, args)
return result
} catch (ex: any) {
let message = i18n.translate("ms.api.command.execute.error", {
player: sender.name,
plugin: plugin.description.name,
command,
args: Java.from(args).join(' '),
ex
})
console.console(message)
console.ex(ex)
if (sender.name != 'CONSOLE') {
console.sender(sender, [message, ...console.stack(ex)])
}
this.printError(ex, "ms.api.command.execute.error",
plugin, command, sender, args)
return true
}
}
@@ -90,36 +70,18 @@ export namespace command {
var token = args[args.length - 1]
var complete = tabCompleter(sender, command, Java.from(args)) || []
let result = this.copyPartialMatches(complete, token)
let cost = Date.now() - time
if (cost > global.ScriptSlowExecuteTime) {
let completerKey = `${plugin.description.name}-${command}-${sender.name}`
if (!this.cacheSlowCompleteKey[completerKey]) { return this.cacheSlowCompleteKey[completerKey] = cost }
console.i18n("ms.api.command.tab.completer.slow", {
player: sender.name,
plugin: plugin.description.name,
command,
args: Java.from(args).join(' '),
cost
})
}
this.checkSlow(Date.now() - time,
"ms.api.command.tab.completer.slow",
plugin, command, sender, args)
return result
} catch (ex: any) {
let message = i18n.translate("ms.api.command.tab.completer.error", {
player: sender.name,
plugin: plugin.description.name,
command,
args: Java.from(args).join(' '),
ex
})
console.console(message)
console.ex(ex)
if (sender.name != 'CONSOLE') {
console.sender(sender, [message, ...console.stack(ex)])
}
this.printError(ex, "ms.api.command.tab.completer.error",
plugin, command, sender, args)
return []
}
}
}
protected copyPartialMatches(complete: string[], token: string, array: string[] = []): string[] {
if (!token) { return complete }
complete.forEach(function (e) {
@@ -129,5 +91,35 @@ export namespace command {
})
return array
}
private checkSlow(cost: number, key: string, plugin: plugin.Plugin, command: string, sender: any, args: any[]) {
if (cost > global.ScriptSlowExecuteTime) {
let completerKey = `${plugin.description.name}-${key}-${command}-${sender.name}`
if (!this.cacheSlowKeys[completerKey]) {
return this.cacheSlowKeys[completerKey] = cost
}
console.i18n(key, {
player: sender.name,
plugin: plugin.description.name,
command,
args: Java.from(args).join(' '),
cost
})
}
}
private printError(error: Error, key: string, plugin: plugin.Plugin, command: string, sender: any, args: any[]) {
let message = i18n.translate(key, {
player: sender.name,
plugin: plugin.description.name,
command,
args: Java.from(args).join(' '),
error
})
console.console(message)
console.ex(error)
if (sender.name != 'CONSOLE') {
console.sender(sender, [message, ...console.stack(error)])
}
}
}
}

View File

@@ -34,9 +34,7 @@ export namespace task {
protected pluginDisable(plugin: plugin.Plugin) {
if (this.pluginCacheTasks.has(plugin.description.name)) {
this.pluginCacheTasks.get(plugin.description.name).forEach((task) => {
task.cancel()
})
this.pluginCacheTasks.get(plugin.description.name).forEach((task) => task.cancel())
this.pluginCacheTasks.delete(plugin.description.name)
}
}
@@ -151,8 +149,9 @@ export namespace task {
this.func(...args)
this.emit('after', this)
} catch (error: any) {
this.emit('error', error)
if (!error.processed) {
try {
this.emit('error', error)
} catch (ignore) {
console.console('§4插件执行任务时发生错误', error)
console.ex(error)
this.cancel()
@@ -181,7 +180,7 @@ export namespace task {
* 提交任务
* @param args 任务参数
*/
protected abstract submit0(...args: any[]): any
protected abstract submit0(...args: any[]): Cancelable
/**
* 取消任务
*/