Compare commits

...

21 Commits

Author SHA1 Message Date
1ddcf02bbb v0.28.0-beta.11 2025-07-15 18:30:42 +08:00
af76fe723c feat(bukkit): 支持 Minecraft 1.20 版本 2025-07-14 17:01:25 +08:00
9250dbb2ad feat: use workspace version 2025-07-14 16:56:16 +08:00
8e807fc2e0 v0.28.0-beta.10 2023-12-15 16:46:50 +08:00
1aa042bef0 chore: private runtime package 2023-11-09 13:56:24 +08:00
d702d9e40d v0.28.0-beta.9 2023-11-09 13:44:38 +08:00
507431232b feat: 优化插件加载逻辑 2023-11-09 12:07:41 +08:00
3e8d1f7029 v0.28.0-beta.8 2023-10-25 17:47:25 +08:00
9fac585e5e chorn: change pack files 2023-10-25 17:44:27 +08:00
1d26a1e318 v0.28.0-beta.7 2023-10-25 16:27:57 +08:00
5f5df3452d fix: nodejs package publish error 2023-10-25 16:25:24 +08:00
fce3c1a284 v0.28.0-beta.6 2023-10-25 16:22:46 +08:00
21b35b0036 chorn: add @lerna-lite/run 2023-10-25 16:21:34 +08:00
2b7588cf04 chore: change lerna to lerna-lite 2023-10-25 14:39:09 +08:00
4435a239d4 v0.28.0-beta.5 2023-10-25 14:32:22 +08:00
4cc5e75f1d chorn: update build config 2023-10-25 12:07:15 +08:00
188641d57a chorn: remove npmignore use files limit 2023-10-25 12:04:43 +08:00
9a25362140 v0.28.0-beta.4 2023-10-25 11:48:18 +08:00
54eaae96bd feat: use pnpm & lock core-js shim 2023-10-25 11:29:01 +08:00
5bf4b1c09e feat: use files limit package file 2023-10-19 17:24:52 +08:00
54bea62735 bump: update deps version 2023-09-12 11:50:38 +08:00
69 changed files with 5664 additions and 510 deletions

5
.gitignore vendored
View File

@@ -1,9 +1,4 @@
.yarn* .yarn*
.vscode .vscode
.theia
node_modules node_modules
dist dist
package-lock.json
yarn.lock
packages/nashorn/docs
!packages/types/dist

View File

@@ -1,25 +0,0 @@
src
test
typings
bundled
build
coverage
docs
wiki
gulpfile.js
bower.json
karma.conf.js
tsconfig.json
typings.json
CONTRIBUTING.md
ISSUE_TEMPLATE.md
PULL_REQUEST_TEMPLATE.md
tslint.json
wallaby.js
.travis.yml
.gitignore
.vscode
.theia
type_definitions
tsconfig.tsbuildinfo
*.tsbuildinfo

1
.npmrc Normal file
View File

@@ -0,0 +1 @@
# shamefully-hoist = true

View File

@@ -1,9 +1,6 @@
{ {
"version": "0.28.0-beta.3", "version": "0.28.0-beta.11",
"npmClient": "yarn", "npmClient": "pnpm",
"packages": [
"packages/*"
],
"command": { "command": {
"run": { "run": {
"stream": true "stream": true

View File

@@ -6,23 +6,30 @@
"author": "MiaoWoo <admin@yumc.pw>", "author": "MiaoWoo <admin@yumc.pw>",
"license": "MIT", "license": "MIT",
"scripts": { "scripts": {
"bs": "lerna bootstrap", "bs": "pnpm install",
"clean": "lerna run clean", "clean": "lerna run clean",
"watch": "lerna run watch --parallel", "watch": "lerna run watch --parallel",
"build": "lerna run build", "build": "lerna run build",
"ug": "yarn upgrade-interactive", "ug": "pnpm up -r -i",
"np": "./script/push.sh", "np": "./script/push.sh",
"lsp": "npm login -scope=@ccms", "lsp": "npm login -scope=@ccms",
"lp": "lerna publish --force-publish", "lp": "lerna publish --force-publish",
"lpb": "lerna publish --preid beta --dist-tag beta --force-publish", "lpb": "lerna publish prerelease --preid beta --dist-tag beta --force-publish",
"lpc": "lerna publish --canary --preid beta --pre-dist-tag beta --force-publish", "lpc": "lerna publish --canary --preid beta --pre-dist-tag beta --force-publish",
"lpf": "lerna publish from-package --yes", "lpf": "lerna publish from-package --dist-tag beta --yes",
"sync": "./script/sync.sh" "sync": "./script/sync.sh",
"postpublish": "pnpm sync"
}, },
"workspaces": [
"packages/*"
],
"devDependencies": { "devDependencies": {
"lerna": "^7.1.4" "@ccms/nashorn": "workspace:*",
"@javatypes/jdk": "^0.0.3",
"@lerna-lite/cli": "^2.6.0",
"@lerna-lite/publish": "^2.6.0",
"@lerna-lite/run": "^2.6.0",
"@types/node": "^20.8.8",
"reflect-metadata": "^0.1.13",
"rimraf": "^5.0.5",
"tslib": "^2.6.2",
"typescript": "^5.2.2"
} }
} }

View File

@@ -1 +0,0 @@
../../.npmignore

View File

@@ -1,6 +1,6 @@
{ {
"name": "@ccms/api", "name": "@ccms/api",
"version": "0.28.0-beta.3", "version": "0.28.0-beta.11",
"description": "MiaoScript api package", "description": "MiaoScript api package",
"keywords": [ "keywords": [
"miaoscript", "miaoscript",
@@ -12,23 +12,26 @@
"homepage": "https://github.com/circlecloud/ms.git", "homepage": "https://github.com/circlecloud/ms.git",
"license": "ISC", "license": "ISC",
"main": "dist/index.js", "main": "dist/index.js",
"files": [
"dist/**/*.js",
"dist/**/*.ts",
"dist/**/*.map"
],
"scripts": { "scripts": {
"clean": "rimraf dist", "clean": "rimraf dist",
"watch": "tsc --watch", "watch": "tsc --watch",
"build": "yarn clean && tsc", "build": "pnpm clean && tsc",
"test": "echo \"Error: run tests from root\" && exit 1" "test": "echo \"Error: run tests from root\" && exit 1"
}, },
"dependencies": { "dependencies": {
"@ccms/common": "^0.28.0-beta.3", "@ccms/common": "workspace:*",
"@ccms/container": "^0.28.0-beta.3", "@ccms/container": "workspace:*",
"@ccms/polyfill": "^0.28.0-beta.3", "@ccms/i18n": "workspace:*",
"@ccms/polyfill": "workspace:*",
"base64-js": "^1.5.1", "base64-js": "^1.5.1",
"source-map-builder": "^0.0.7" "source-map-builder": "^0.0.7"
}, },
"devDependencies": { "devDependencies": {
"@types/base64-js": "^1.3.0", "@types/base64-js": "^1.5.0"
"reflect-metadata": "^0.1.13",
"rimraf": "^4.1.2",
"typescript": "^4.9.5"
} }
} }

View File

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

@@ -26,6 +26,7 @@ global.setGlobal('MiaoScriptSourceFileMaps', sourceFileMaps)
export namespace jsconsole { export namespace jsconsole {
export function readSourceMap(fileName: string, lineNumber: any) { export function readSourceMap(fileName: string, lineNumber: any) {
if (lineNumber == 1) return { fileName, lineNumber }
try { try {
if (fileName.endsWith('js') || fileName.endsWith('ms')) { if (fileName.endsWith('js') || fileName.endsWith('ms')) {
if (sourceMaps[fileName] === undefined) { if (sourceMaps[fileName] === undefined) {
@@ -68,10 +69,7 @@ export namespace jsconsole {
console.ex(error) console.ex(error)
} }
} }
return { return { fileName, lineNumber }
fileName,
lineNumber
}
} }
export function getStackTrace(ex: Error, color: boolean = true): string[] { export function getStackTrace(ex: Error, color: boolean = true): string[] {

View File

@@ -19,14 +19,23 @@ export namespace plugin {
@injectable() @injectable()
export abstract class PluginManager { export abstract class PluginManager {
abstract scan(folder: string): void abstract scan(folder: string): void
abstract build(): void
abstract loadFromFile(file: string, ext?: any): Plugin abstract loadFromFile(file: string, ext?: any): Plugin
abstract load(...args: any[]): void abstract require(loadMetadata: PluginLoadMetadata): PluginMetadata
abstract enable(...args: any[]): void abstract build(metadata: PluginMetadata): Plugin
abstract disable(...args: any[]): void abstract rebuild(plugin: plugin.Plugin): void
abstract reload(...args: any[]): void abstract load(plugin: plugin.Plugin): void
abstract enable(plugin: plugin.Plugin): void
abstract disable(plugin: plugin.Plugin): void
abstract reload(plugin: plugin.Plugin): void
abstract has(name: string): boolean
abstract get(name: string): plugin.Plugin
abstract getPlugin(name: string): plugin.Plugin abstract getPlugin(name: string): plugin.Plugin
abstract getPlugins(): Map<string, plugin.Plugin> abstract getPlugins(): Map<string, plugin.Plugin>
abstract buildPlugins(): void
abstract rebuildPlugins(): void
abstract loadPlugins(): void
abstract enablePlugins(): void
abstract disablePlugins(): void
} }
export const PluginScanner = Symbol("PluginScanner") export const PluginScanner = Symbol("PluginScanner")
/** /**
@@ -38,9 +47,13 @@ export namespace plugin {
*/ */
type: string type: string
/** /**
* 插件文件 * 插件文件(java.io.File)
*/ */
file?: string file?: any
/**
* 插件规范路径 canonicalPath
*/
path?: string
/** /**
* 插件实例 * 插件实例
*/ */
@@ -122,11 +135,6 @@ export namespace plugin {
* @param plugin 插件 * @param plugin 插件
*/ */
disable?(plugin: Plugin): void disable?(plugin: Plugin): void
/**
* Reload 阶段
* @param plugin 插件
*/
reload?(plugin: Plugin): void
} }
export interface Plugin { export interface Plugin {
description: PluginMetadata description: PluginMetadata

View File

@@ -14,6 +14,7 @@ export namespace task {
constructor() { constructor() {
this.taskId = new AtomicInteger(0) this.taskId = new AtomicInteger(0)
process.on('core.disable', () => { this.disable() })
process.on('task.finish', (task: task.Task) => { process.on('task.finish', (task: task.Task) => {
let taskId = task.getTaskId() let taskId = task.getTaskId()
this.cacheTasks.delete(taskId) this.cacheTasks.delete(taskId)
@@ -24,30 +25,6 @@ export namespace task {
}) })
} }
protected pluginCreate(plugin: plugin.Plugin, task: task.Task) {
if (!this.pluginCacheTasks.has(plugin.description.name)) {
this.pluginCacheTasks.set(plugin.description.name, new Map())
}
this.pluginCacheTasks.get(plugin.description.name).set(task.getTaskId(), task)
return 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.delete(plugin.description.name)
}
}
/**
* 获得自增的任务ID
*/
protected nextId() {
return this.taskId.incrementAndGet()
}
/** /**
* 创建任务 * 创建任务
* @param func 任务内容 * @param func 任务内容
@@ -75,6 +52,28 @@ export namespace task {
if (plugin) { return this.pluginDisable(plugin) } if (plugin) { return this.pluginDisable(plugin) }
this.disable0() this.disable0()
} }
protected pluginCreate(plugin: plugin.Plugin, task: task.Task) {
if (!this.pluginCacheTasks.has(plugin.description.name)) {
this.pluginCacheTasks.set(plugin.description.name, new Map())
}
this.pluginCacheTasks.get(plugin.description.name).set(task.getTaskId(), task)
return 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.delete(plugin.description.name)
}
}
/**
* 获得自增的任务ID
*/
protected nextId() {
return this.taskId.incrementAndGet()
}
protected abstract create0(owner: plugin.Plugin, func: Function, id: number): task.Task protected abstract create0(owner: plugin.Plugin, func: Function, id: number): task.Task
protected abstract disable0() protected abstract disable0()
} }
@@ -97,6 +96,9 @@ export namespace task {
this.owner = owner this.owner = owner
this.func = func this.func = func
this.taskId = id this.taskId = id
this.on('finish', () => {
process.emit('task.finish', this)
})
} }
getOwner() { getOwner() {
@@ -151,8 +153,9 @@ export namespace task {
this.func(...args) this.func(...args)
this.emit('after', this) this.emit('after', this)
} catch (error: any) { } catch (error: any) {
this.emit('error', error) try {
if (!error.processed) { this.emit('error', error)
} catch (ignore) {
console.console('§4插件执行任务时发生错误', error) console.console('§4插件执行任务时发生错误', error)
console.ex(error) console.ex(error)
this.cancel() this.cancel()
@@ -164,7 +167,6 @@ export namespace task {
} }
protected finish() { protected finish() {
process.emit('task.finish', this)
this.emit('finish', this) this.emit('finish', this)
} }
@@ -181,7 +183,7 @@ export namespace task {
* 提交任务 * 提交任务
* @param args 任务参数 * @param args 任务参数
*/ */
protected abstract submit0(...args: any[]): any protected abstract submit0(...args: any[]): Cancelable
/** /**
* 取消任务 * 取消任务
*/ */

View File

@@ -1 +0,0 @@
../../.npmignore

View File

@@ -1,6 +1,6 @@
{ {
"name": "@ccms/bukkit", "name": "@ccms/bukkit",
"version": "0.28.0-beta.3", "version": "0.28.0-beta.11",
"description": "MiaoScript bukkit package", "description": "MiaoScript bukkit package",
"keywords": [ "keywords": [
"miaoscript", "miaoscript",
@@ -12,21 +12,23 @@
"homepage": "https://github.com/circlecloud/ms.git", "homepage": "https://github.com/circlecloud/ms.git",
"license": "ISC", "license": "ISC",
"main": "dist/index.js", "main": "dist/index.js",
"files": [
"dist/**/*.js",
"dist/**/*.ts",
"dist/**/*.map"
],
"scripts": { "scripts": {
"clean": "rimraf dist", "clean": "rimraf dist",
"watch": "tsc --watch", "watch": "tsc --watch",
"build": "yarn clean && tsc", "build": "pnpm clean && tsc",
"test": "echo \"Error: run tests from root\" && exit 1" "test": "echo \"Error: run tests from root\" && exit 1"
}, },
"devDependencies": { "devDependencies": {
"@javatypes/spigot-api": "^0.0.3", "@javatypes/spigot-api": "^0.0.3"
"reflect-metadata": "^0.1.13",
"rimraf": "^4.1.2",
"typescript": "^4.9.5"
}, },
"dependencies": { "dependencies": {
"@ccms/api": "^0.28.0-beta.3", "@ccms/api": "workspace:*",
"@ccms/common": "^0.28.0-beta.3", "@ccms/common": "workspace:*",
"@ccms/container": "^0.28.0-beta.3" "@ccms/container": "workspace:*"
} }
} }

View File

@@ -65,28 +65,32 @@ abstract class BukkitChatInvoke {
return base.getClass(['net.minecraft.server', this.nmsVersion, name].join('.')) return base.getClass(['net.minecraft.server', this.nmsVersion, name].join('.'))
} }
remapMethod(clazz: any, origin: string, test: string, params: any) { remapMethod(clazz: any, methods: string[], params: any) {
try { for (const method of methods) {
return clazz.getMethod(origin, params) try {
} catch (ex: any) { if (this.RemapUtils) {
if (this.RemapUtils) { return clazz.getMethod(this.RemapUtils.mapMethod(clazz, method, params), params)
return clazz.getMethod(this.RemapUtils.mapMethod(clazz, origin, params), params) } else {
} else { return clazz.getMethod(method, params)
return clazz.getMethod(test, params) }
} catch (error) {
} }
} }
throw new Error(`Class ${clazz} not found method ${methods}`)
} }
remapFieldName(clazz: any, origin: string, test: string) { remapFieldName(clazz: any, fields: string[]) {
try { for (const field of fields) {
return clazz.getField(origin) try {
} catch (ex: any) { if (this.RemapUtils) {
if (this.RemapUtils) { return clazz.getField(this.RemapUtils.mapFieldName(clazz, field))
return clazz.getField(this.RemapUtils.mapFieldName(clazz, origin)) } else {
} else { return clazz.getField(field)
return clazz.getField(test) }
} catch (ex: any) {
} }
} }
throw new Error(`Class ${clazz} not found field ${fields}`)
} }
json(sender: any, json: string) { json(sender: any, json: string) {
@@ -107,10 +111,10 @@ abstract class BukkitChatInvoke {
class BukkitChatInvokeBase extends BukkitChatInvoke { class BukkitChatInvokeBase extends BukkitChatInvoke {
getSendPacketMethodName(playerConnectionClass: any) { getSendPacketMethodName(playerConnectionClass: any) {
return this.remapMethod(playerConnectionClass, 'sendPacket', 'func_179290_a', this.getPacketClass()).getName() return this.remapMethod(playerConnectionClass, ['sendPacket', 'a', 'func_179290_a'], this.getPacketClass()).getName()
} }
getNmsChatSerializerMethodName(nmsChatSerializerClass: any) { getNmsChatSerializerMethodName(nmsChatSerializerClass: any) {
let nmsChatSerializerMethod = this.remapMethod(nmsChatSerializerClass, 'a', 'func_150699_a', base.getClass('java.lang.String')) let nmsChatSerializerMethod = this.remapMethod(nmsChatSerializerClass, ['serialize', 'a', 'func_150699_a'], base.getClass('java.lang.String'))
return nmsChatSerializerMethod.getName() return nmsChatSerializerMethod.getName()
} }
getPacketPlayOutChat(sender: any, json: any, type: number) { getPacketPlayOutChat(sender: any, json: any, type: number) {
@@ -123,7 +127,7 @@ class BukkitChatInvokeBase extends BukkitChatInvoke {
return this.nmsCls("PacketPlayOutChat") return this.nmsCls("PacketPlayOutChat")
} }
getPlayerConnectionField() { getPlayerConnectionField() {
return this.remapFieldName(this.nmsCls('EntityPlayer'), 'playerConnection', 'field_71135_a') return this.remapFieldName(this.nmsCls('EntityPlayer'), ['playerConnection', 'field_71135_a'])
} }
getPacketClass() { getPacketClass() {
return this.nmsCls('Packet') return this.nmsCls('Packet')
@@ -174,13 +178,27 @@ class BukkitChatInvoke_1_19 extends BukkitChatInvoke_1_18_2 {
return new this.PacketPlayOutChat(this.ChatSerializer[this.nmsChatSerializerMethodName](json), type) return new this.PacketPlayOutChat(this.ChatSerializer[this.nmsChatSerializerMethodName](json), type)
} }
} }
class BukkitChatInvoke_1_20 extends BukkitChatInvoke_1_19 {
getNmsChatSerializerClass() {
return base.getClass('net.minecraft.network.chat.IChatBaseComponent')
}
getNmsChatSerializerMethodName(nmsChatSerializerClass: any) {
let nmsChatSerializerMethod = this.remapMethod(nmsChatSerializerClass, ['literal', 'a'], base.getClass('java.lang.String'))
return nmsChatSerializerMethod.getName()
}
getPlayerConnectionField() {
return base.getClass('net.minecraft.server.level.EntityPlayer').getField('f')
}
}
try { try {
let Bukkit: typeof org.bukkit.Bukkit = Java.type('org.bukkit.Bukkit') let Bukkit: typeof org.bukkit.Bukkit = Java.type('org.bukkit.Bukkit')
// @ts-ignore // @ts-ignore
let nmsVersion = Bukkit.getServer().class.name.split('.')[3] let nmsVersion = Bukkit.getServer().class.name.split('.')[3]
let nmsSubVersion = nmsVersion.split("_")[1] let nmsSubVersion = nmsVersion.split("_")[1]
if (nmsSubVersion >= 19) { if (nmsSubVersion >= 20) {
bukkitChatInvoke = new BukkitChatInvoke_1_20(nmsVersion)
} else if (nmsSubVersion >= 19) {
bukkitChatInvoke = new BukkitChatInvoke_1_19(nmsVersion) bukkitChatInvoke = new BukkitChatInvoke_1_19(nmsVersion)
} else if (nmsSubVersion >= 18) { } else if (nmsSubVersion >= 18) {
bukkitChatInvoke = new BukkitChatInvoke_1_18_2(nmsVersion) bukkitChatInvoke = new BukkitChatInvoke_1_18_2(nmsVersion)

View File

@@ -1 +0,0 @@
../../.npmignore

View File

@@ -1,6 +1,6 @@
{ {
"name": "@ccms/bungee", "name": "@ccms/bungee",
"version": "0.28.0-beta.3", "version": "0.28.0-beta.11",
"description": "MiaoScript bungee package", "description": "MiaoScript bungee package",
"keywords": [ "keywords": [
"miaoscript", "miaoscript",
@@ -12,21 +12,23 @@
"homepage": "https://github.com/circlecloud/ms.git", "homepage": "https://github.com/circlecloud/ms.git",
"license": "ISC", "license": "ISC",
"main": "dist/index.js", "main": "dist/index.js",
"files": [
"dist/**/*.js",
"dist/**/*.ts",
"dist/**/*.map"
],
"scripts": { "scripts": {
"clean": "rimraf dist", "clean": "rimraf dist",
"watch": "tsc --watch", "watch": "tsc --watch",
"build": "yarn clean && tsc", "build": "pnpm clean && tsc",
"test": "echo \"Error: run tests from root\" && exit 1" "test": "echo \"Error: run tests from root\" && exit 1"
}, },
"devDependencies": { "devDependencies": {
"@javatypes/bungee-api": "^0.0.3", "@javatypes/bungee-api": "^0.0.3"
"reflect-metadata": "^0.1.13",
"rimraf": "^4.1.2",
"typescript": "^4.9.5"
}, },
"dependencies": { "dependencies": {
"@ccms/api": "^0.28.0-beta.3", "@ccms/api": "workspace:*",
"@ccms/common": "^0.28.0-beta.3", "@ccms/common": "workspace:*",
"@ccms/container": "^0.28.0-beta.3" "@ccms/container": "workspace:*"
} }
} }

View File

@@ -1 +0,0 @@
../../.npmignore

View File

@@ -1,6 +1,6 @@
{ {
"name": "@ccms/common", "name": "@ccms/common",
"version": "0.28.0-beta.3", "version": "0.28.0-beta.11",
"description": "MiaoScript common package", "description": "MiaoScript common package",
"keywords": [ "keywords": [
"miaoscript", "miaoscript",
@@ -12,18 +12,20 @@
"homepage": "https://github.com/circlecloud/ms.git", "homepage": "https://github.com/circlecloud/ms.git",
"license": "ISC", "license": "ISC",
"main": "dist/index.js", "main": "dist/index.js",
"files": [
"dist/**/*.js",
"dist/**/*.ts",
"dist/**/*.map"
],
"scripts": { "scripts": {
"clean": "rimraf dist", "clean": "rimraf dist",
"watch": "tsc --watch", "watch": "tsc --watch",
"build": "yarn clean && tsc", "build": "pnpm clean && tsc",
"test": "echo \"Error: run tests from root\" && exit 1" "test": "echo \"Error: run tests from root\" && exit 1"
}, },
"devDependencies": { "devDependencies": {
"@ccms/nashorn": "^0.28.0-beta.3", "@ccms/nashorn": "workspace:*",
"@javatypes/jdk": "^0.0.3", "@javatypes/jdk": "^0.0.3"
"reflect-metadata": "^0.1.13",
"rimraf": "^4.1.2",
"typescript": "^4.9.5"
}, },
"gitHead": "562e2d00175c9d3a99c8b672aa07e6d92706a027" "gitHead": "562e2d00175c9d3a99c8b672aa07e6d92706a027"
} }

View File

@@ -1 +0,0 @@
../../.npmignore

View File

@@ -1,6 +1,6 @@
{ {
"name": "@ccms/compile", "name": "@ccms/compile",
"version": "0.28.0-beta.3", "version": "0.28.0-beta.11",
"description": "MiaoScript compile package", "description": "MiaoScript compile package",
"keywords": [ "keywords": [
"miaoscript", "miaoscript",
@@ -12,15 +12,15 @@
"homepage": "https://github.com/circlecloud/ms.git", "homepage": "https://github.com/circlecloud/ms.git",
"license": "ISC", "license": "ISC",
"main": "dist/index.js", "main": "dist/index.js",
"files": [
"dist/**/*.js",
"dist/**/*.ts",
"dist/**/*.map"
],
"scripts": { "scripts": {
"clean": "rimraf dist", "clean": "rimraf dist",
"watch": "tsc --watch", "watch": "tsc --watch",
"build": "yarn clean && tsc", "build": "pnpm clean && tsc",
"test": "echo \"Error: run tests from root\" && exit 1" "test": "echo \"Error: run tests from root\" && exit 1"
},
"devDependencies": {
"reflect-metadata": "^0.1.13",
"rimraf": "^4.1.2",
"typescript": "^4.9.5"
} }
} }

View File

@@ -1 +0,0 @@
../../.npmignore

View File

@@ -1,6 +1,6 @@
{ {
"name": "@ccms/container", "name": "@ccms/container",
"version": "0.28.0-beta.3", "version": "0.28.0-beta.11",
"description": "MiaoScript container package", "description": "MiaoScript container package",
"keywords": [ "keywords": [
"miaoscript", "miaoscript",
@@ -12,20 +12,22 @@
"homepage": "https://github.com/circlecloud/ms.git", "homepage": "https://github.com/circlecloud/ms.git",
"license": "ISC", "license": "ISC",
"main": "dist/index.js", "main": "dist/index.js",
"files": [
"dist/**/*.js",
"dist/**/*.ts",
"dist/**/*.map"
],
"scripts": { "scripts": {
"clean": "rimraf dist", "clean": "rimraf dist",
"watch": "tsc --watch", "watch": "tsc --watch",
"build": "yarn clean && tsc", "build": "pnpm clean && tsc",
"test": "echo \"Error: run tests from root\" && exit 1" "test": "echo \"Error: run tests from root\" && exit 1"
}, },
"devDependencies": {
"@ccms/nashorn": "^0.28.0-beta.3",
"reflect-metadata": "^0.1.13",
"rimraf": "^4.1.2",
"typescript": "^4.9.5"
},
"dependencies": { "dependencies": {
"inversify": "^6.0.1", "inversify": "^6.0.1",
"inversify-binding-decorators": "^4.0.0" "inversify-binding-decorators": "^4.0.0"
},
"devDependencies": {
"@ccms/nashorn": "workspace:*"
} }
} }

View File

@@ -1 +0,0 @@
../../.npmignore

View File

@@ -1,6 +1,6 @@
{ {
"name": "@ccms/core", "name": "@ccms/core",
"version": "0.28.0-beta.3", "version": "0.28.0-beta.11",
"description": "MiaoScript core package", "description": "MiaoScript core package",
"keywords": [ "keywords": [
"miaoscript", "miaoscript",
@@ -12,20 +12,28 @@
"homepage": "https://github.com/circlecloud/ms.git", "homepage": "https://github.com/circlecloud/ms.git",
"license": "ISC", "license": "ISC",
"main": "dist/index.js", "main": "dist/index.js",
"files": [
"dist/**/*.js",
"dist/**/*.ts",
"dist/**/*.map"
],
"scripts": { "scripts": {
"clean": "rimraf dist", "clean": "rimraf dist",
"watch": "tsc --watch", "watch": "pnpm rollup -c rollup.config.js --watch",
"build": "yarn clean && tsc", "build": "pnpm clean && pnpm rollup -c rollup.config.js",
"test": "echo \"Error: run tests from root\" && exit 1" "test": "echo \"Error: run tests from root\" && exit 1"
}, },
"devDependencies": { "devDependencies": {
"reflect-metadata": "^0.1.13", "@rollup/plugin-typescript": "^11.1.6",
"rimraf": "^4.1.2", "rollup": "^2.79.2",
"typescript": "^4.9.5" "rollup-obfuscator": "^3.0.2",
"rollup-plugin-peer-deps-external": "^2.2.4"
}, },
"dependencies": { "dependencies": {
"@ccms/api": "^0.28.0-beta.3", "@ccms/api": "workspace:*",
"@ccms/container": "^0.28.0-beta.3" "@ccms/common": "workspace:*",
"@ccms/container": "workspace:*",
"js-yaml": "^4.1.0"
}, },
"gitHead": "781524f83e52cad26d7c480513e3c525df867121" "gitHead": "781524f83e52cad26d7c480513e3c525df867121"
} }

View File

@@ -0,0 +1,49 @@
import typescript from '@rollup/plugin-typescript'
import peerDepsExternal from 'rollup-plugin-peer-deps-external'
import { obfuscator } from 'rollup-obfuscator'
import pkg from './package.json'
const external = ['path', 'fs', 'typescript', 'tslib']
/**
* @type {import('rollup').RollupOptions}
*/
export default {
input: 'src/index.ts',
plugins: [
peerDepsExternal(),
typescript(),
obfuscator({
compact: true,
deadCodeInjection: true,
deadCodeInjectionThreshold: 1,
identifierNamesGenerator: 'mangled-shuffled',
numbersToExpressions: true,
simplify: true,
stringArray: true,
stringArrayThreshold: 1,
stringArrayEncoding: ['rc4'],
stringArrayCallsTransform: true,
stringArrayCallsTransformThreshold: 1,
stringArrayWrappersChainedCalls: true,
stringArrayWrappersParametersMaxCount: 3,
sourceMap: true,
sourceMapSourcesMode: 'sources',
inputFileName: `${pkg.name}.ts`,
transformObjectKeys: true,
unicodeEscapeSequence: true,
target: 'browser-no-eval'
}),
],
external,
treeshake: false,
output: [
{
format: 'cjs',
interop: "auto",
exports: "named",
sourcemap: true,
file: pkg.main || `dist/${pkg.name}.js`
}
]
}

View File

@@ -6,7 +6,6 @@ console.i18n("ms.core.ioc.completed", { scope: global.scope, time: (Date.now() -
import * as yaml from 'js-yaml' import * as yaml from 'js-yaml'
import http from '@ccms/common/dist/http' import http from '@ccms/common/dist/http'
import * as fs from '@ccms/common/dist/fs' import * as fs from '@ccms/common/dist/fs'
import { VersionUtils } from '@ccms/common/dist/version'
const UUID = Java.type('java.util.UUID') const UUID = Java.type('java.util.UUID')
const MiaoScriptAPI = Java.type('pw.yumc.MiaoScript.api.MiaoScriptAPI') const MiaoScriptAPI = Java.type('pw.yumc.MiaoScript.api.MiaoScriptAPI')
@@ -15,22 +14,18 @@ const MiaoScriptAPI = Java.type('pw.yumc.MiaoScript.api.MiaoScriptAPI')
class MiaoScriptCore { class MiaoScriptCore {
@Autowired(server.Console) @Autowired(server.Console)
private Console: Console private Console: Console
@Autowired(plugin.PluginFolder)
private pluginFolder: string
@Autowired()
private taskManager: task.TaskManager
@Autowired() @Autowired()
private pluginManager: plugin.PluginManager private pluginManager: plugin.PluginManager
enable() { enable() {
process.emit('core.before.enable') process.emit('core.before.enable', this)
this.loadServerConsole() this.loadServerConsole()
try { try {
MiaoScriptAPI.setPluginManager(this.pluginManager) MiaoScriptAPI.setPluginManager(this.pluginManager)
} catch (error) { } catch (error) {
} }
this.loadPlugins() process.emit('core.enable', this)
process.emit('core.after.enable') process.emit('core.after.enable', this)
console.i18n("ms.core.engine.completed", { console.i18n("ms.core.engine.completed", {
loader: base.version, loader: base.version,
version: 'v' + global.ScriptEngineVersion, version: 'v' + global.ScriptEngineVersion,
@@ -40,40 +35,28 @@ class MiaoScriptCore {
} }
loadServerConsole() { loadServerConsole() {
process.emit('core.before.load.console') process.emit('core.before.load.console', this)
//@ts-ignore //@ts-ignore
global.setGlobal('console', new this.Console(), { writable: false, configurable: false }) global.setGlobal('console', new this.Console(), { writable: false, configurable: false })
process.emit('core.after.load.console') process.emit('core.after.load.console', this)
}
loadPlugins() {
process.emit('core.before.load.plugins')
let loadPluginStartTime = new Date().getTime()
console.i18n("ms.core.plugin.initialize")
this.pluginManager.scan(this.pluginFolder)
this.pluginManager.build()
this.pluginManager.load(this.pluginManager.getPlugins())
this.pluginManager.enable(this.pluginManager.getPlugins())
console.i18n("ms.core.plugin.completed", { time: (new Date().getTime() - loadPluginStartTime) / 1000 })
process.emit('core.after.load.plugins')
} }
disable() { disable() {
process.emit('core.before.disable') process.emit('core.before.disable', this)
let disableStartTime = Date.now() let disableStartTime = Date.now()
console.i18n("ms.core.engine.disable") console.i18n("ms.core.engine.disable")
this.pluginManager.disable(this.pluginManager.getPlugins()) process.emit('core.disable', this)
this.taskManager.disable() process.emit('core.after.disable', this)
process.emit('core.after.disable')
loadCoreScript('exit') loadCoreScript('exit')
process.emit('core.before.exit') process.emit('core.before.exit', this)
process.exit(0) process.exit(0)
process.emit('core.exit', this)
console.i18n("ms.core.engine.disable.finish", { console.i18n("ms.core.engine.disable.finish", {
loader: base.version, loader: base.version,
version: 'v' + global.ScriptEngineVersion, version: 'v' + global.ScriptEngineVersion,
time: (new Date().getTime() - disableStartTime) / 1000 time: (new Date().getTime() - disableStartTime) / 1000
}) })
process.emit('core.after.exit') process.emit('core.after.exit', this)
} }
} }
@@ -166,14 +149,12 @@ function initialize() {
global.setGlobal('loadCoreScript', loadCoreScript) global.setGlobal('loadCoreScript', loadCoreScript)
loadCoreScript('initialize') loadCoreScript('initialize')
try { try {
let core = createCore() return createCore()
return VersionUtils.isGreaterOrEqual(base.version, '0.22.0') ? core : core.enable()
} catch (error: any) { } catch (error: any) {
let core = { enable: () => () => console.i18n('ms.core.engine.disable.abnormal') }
console.i18n("core.initialize.error", { error }) console.i18n("core.initialize.error", { error })
jsconsole.getStackTrace(error, false).forEach(line => console.log(line)) jsconsole.getStackTrace(error, false).forEach(line => console.log(line))
process.emit('core.initialize.error') process.emit('core.initialize.error')
return VersionUtils.isGreaterOrEqual(base.version, '0.22.0') ? core : core.enable() return { enable: () => () => console.i18n('ms.core.engine.disable.abnormal') }
} finally { } finally {
process.emit('core.after.initialize') process.emit('core.after.initialize')
} }

View File

@@ -1 +0,0 @@
../../.npmignore

View File

@@ -1,6 +1,6 @@
{ {
"name": "@ccms/database", "name": "@ccms/database",
"version": "0.28.0-beta.3", "version": "0.28.0-beta.11",
"description": "MiaoScript database package", "description": "MiaoScript database package",
"keywords": [ "keywords": [
"miaoscript", "miaoscript",
@@ -12,20 +12,22 @@
"homepage": "https://github.com/circlecloud/ms.git", "homepage": "https://github.com/circlecloud/ms.git",
"license": "ISC", "license": "ISC",
"main": "dist/index.js", "main": "dist/index.js",
"files": [
"dist/**/*.js",
"dist/**/*.ts",
"dist/**/*.map"
],
"scripts": { "scripts": {
"clean": "rimraf dist", "clean": "rimraf dist",
"watch": "tsc --watch", "watch": "tsc --watch",
"build": "yarn clean && tsc", "build": "pnpm clean && tsc",
"test": "echo \"Error: run tests from root\" && exit 1" "test": "echo \"Error: run tests from root\" && exit 1"
}, },
"devDependencies": { "devDependencies": {
"@javatypes/spring-jdbc": "^0.0.3", "@javatypes/spring-jdbc": "^0.0.3"
"reflect-metadata": "^0.1.13",
"rimraf": "^4.1.2",
"typescript": "^4.9.5"
}, },
"dependencies": { "dependencies": {
"@ccms/api": "^0.28.0-beta.3", "@ccms/api": "workspace:*",
"@ccms/container": "^0.28.0-beta.3" "@ccms/container": "workspace:*"
} }
} }

View File

@@ -1 +0,0 @@
../../.npmignore

View File

@@ -1,6 +1,6 @@
{ {
"name": "@ccms/i18n", "name": "@ccms/i18n",
"version": "0.28.0-beta.3", "version": "0.28.0-beta.11",
"description": "MiaoScript i18n package", "description": "MiaoScript i18n package",
"keywords": [ "keywords": [
"miaoscript", "miaoscript",
@@ -12,21 +12,24 @@
"homepage": "https://github.com/circlecloud/ms.git", "homepage": "https://github.com/circlecloud/ms.git",
"license": "ISC", "license": "ISC",
"main": "dist/index.js", "main": "dist/index.js",
"files": [
"dist/**/*.js",
"dist/**/*.ts",
"dist/**/*.map",
"languages"
],
"scripts": { "scripts": {
"clean": "rimraf dist", "clean": "rimraf dist",
"watch": "tsc --watch", "watch": "tsc --watch",
"build": "yarn clean && tsc", "build": "pnpm clean && tsc",
"test": "echo \"Error: run tests from root\" && exit 1" "test": "echo \"Error: run tests from root\" && exit 1"
}, },
"devDependencies": {
"@ccms/nashorn": "^0.28.0-beta.3",
"@types/js-yaml": "^4.0.5",
"reflect-metadata": "^0.1.13",
"rimraf": "^4.1.2",
"typescript": "^4.9.5"
},
"dependencies": { "dependencies": {
"js-yaml": "^4.1.0" "js-yaml": "^4.1.0"
}, },
"devDependencies": {
"@ccms/nashorn": "workspace:*",
"@types/js-yaml": "^4.0.9"
},
"gitHead": "781524f83e52cad26d7c480513e3c525df867121" "gitHead": "781524f83e52cad26d7c480513e3c525df867121"
} }

View File

@@ -1,13 +1,18 @@
{ {
"name": "@ccms/molang", "name": "@ccms/molang",
"version": "0.28.0-beta.3", "version": "0.28.0-beta.11",
"description": "A fast parser for Minecraft's MoLang", "description": "A fast parser for Minecraft's MoLang",
"main": "dist/index.js", "main": "dist/index.js",
"types": "dist/index.d.ts", "types": "dist/index.d.ts",
"files": [
"dist/**/*.js",
"dist/**/*.ts",
"dist/**/*.map"
],
"scripts": { "scripts": {
"clean": "rimraf dist", "clean": "rimraf dist",
"watch": "tsc --watch", "watch": "tsc --watch",
"build": "yarn clean && tsc", "build": "pnpm clean && tsc",
"test": "echo \"Error: run tests from root\" && exit 1" "test": "echo \"Error: run tests from root\" && exit 1"
}, },
"repository": { "repository": {
@@ -21,9 +26,6 @@
}, },
"homepage": "https://github.com/solvedDev/MoLang#readme", "homepage": "https://github.com/solvedDev/MoLang#readme",
"devDependencies": { "devDependencies": {
"@types/node": "^18.13.0", "@types/node": "^18.19.118"
"rimraf": "^4.1.2",
"tslib": "^2.5.0",
"typescript": "^4.9.5"
} }
} }

View File

@@ -1 +0,0 @@
../../.npmignore

View File

@@ -1,6 +1,6 @@
{ {
"name": "@ccms/nashorn", "name": "@ccms/nashorn",
"version": "0.28.0-beta.3", "version": "0.28.0-beta.11",
"description": "MiaoScript nashorn package", "description": "MiaoScript nashorn package",
"keywords": [ "keywords": [
"miaoscript", "miaoscript",
@@ -13,15 +13,15 @@
"license": "ISC", "license": "ISC",
"main": "dist/index.js", "main": "dist/index.js",
"types": "dist/index.d.ts", "types": "dist/index.d.ts",
"files": [
"dist/**/*.js",
"dist/**/*.ts",
"dist/**/*.map"
],
"scripts": { "scripts": {
"clean": "rimraf dist", "clean": "rimraf dist",
"watch": "tsc --watch", "watch": "tsc --watch",
"build": "yarn clean && tsc", "build": "pnpm clean && tsc",
"test": "echo \"Error: run tests from root\" && exit 1" "test": "echo \"Error: run tests from root\" && exit 1"
},
"devDependencies": {
"reflect-metadata": "^0.1.13",
"rimraf": "^4.1.2",
"typescript": "^4.9.5"
} }
} }

View File

@@ -1 +0,0 @@
../../.npmignore

View File

@@ -1,6 +1,6 @@
{ {
"name": "@ccms/nodejs", "name": "@ccms/nodejs",
"version": "0.28.0-beta.3", "version": "0.28.0-beta.11",
"description": "MiaoScript nodejs package", "description": "MiaoScript nodejs package",
"keywords": [ "keywords": [
"miaoscript", "miaoscript",
@@ -12,18 +12,19 @@
"homepage": "https://github.com/circlecloud/ms.git", "homepage": "https://github.com/circlecloud/ms.git",
"license": "ISC", "license": "ISC",
"main": "dist/index.js", "main": "dist/index.js",
"files": [
"dist/**/*.js",
"dist/**/*.ts",
"dist/**/*.map"
],
"scripts": { "scripts": {
"clean": "rimraf dist", "clean": "rimraf dist",
"watch": "tsc --watch", "watch": "tsc --watch",
"build": "yarn clean && tsc", "build": "pnpm clean && tsc",
"test": "echo \"Error: run tests from root\" && exit 1" "test": "echo \"Error: run tests from root\" && exit 1"
}, },
"devDependencies": { "devDependencies": {
"@ccms/nashorn": "^0.28.0-beta.3", "@ccms/nashorn": "workspace:*"
"reflect-metadata": "^0.1.13",
"rimraf": "^4.1.2",
"tslib": "^2.5.0",
"typescript": "^4.9.5"
}, },
"gitHead": "781524f83e52cad26d7c480513e3c525df867121" "gitHead": "781524f83e52cad26d7c480513e3c525df867121"
} }

View File

@@ -145,8 +145,8 @@ EventEmitter.prototype.emit = function emit(type) {
if (er.error instanceof Error || er.error instanceof Throwable) { if (er.error instanceof Error || er.error instanceof Throwable) {
throw er.error; // Unhandled 'error' event throw er.error; // Unhandled 'error' event
} }
if (er.cause instanceof Error || er.error instanceof Throwable) { if (er.cause instanceof Error || er.cause instanceof Throwable) {
throw er.error; // Unhandled 'error' event throw er.cause; // Unhandled 'error' event
} }
// At least give some kind of context to the user // At least give some kind of context to the user
var err = new Error('Unhandled error.' + (er ? ' (' + (er.message || er.error || er.cause || er) + ')' : '')); var err = new Error('Unhandled error.' + (er ? ' (' + (er.message || er.error || er.cause || er) + ')' : ''));

View File

@@ -715,6 +715,7 @@ function callbackify(original) {
// implications (stack, `uncaughtException`, `async_hooks`) // implications (stack, `uncaughtException`, `async_hooks`)
// @ts-ignore // @ts-ignore
original.apply(this, args) original.apply(this, args)
// @ts-ignore
.then(function (ret) { process.nextTick(cb.bind(null, null, ret)) }, .then(function (ret) { process.nextTick(cb.bind(null, null, ret)) },
function (rej) { process.nextTick(callbackifyOnRejected.bind(null, rej, cb)) }); function (rej) { process.nextTick(callbackifyOnRejected.bind(null, rej, cb)) });
} }

View File

@@ -1 +0,0 @@
../../.npmignore

View File

@@ -1,6 +1,6 @@
{ {
"name": "@ccms/nukkit", "name": "@ccms/nukkit",
"version": "0.28.0-beta.3", "version": "0.28.0-beta.11",
"description": "MiaoScript nukkit package", "description": "MiaoScript nukkit package",
"keywords": [ "keywords": [
"miaoscript", "miaoscript",
@@ -12,21 +12,23 @@
"homepage": "https://github.com/circlecloud/ms.git", "homepage": "https://github.com/circlecloud/ms.git",
"license": "ISC", "license": "ISC",
"main": "dist/index.js", "main": "dist/index.js",
"files": [
"dist/**/*.js",
"dist/**/*.ts",
"dist/**/*.map"
],
"scripts": { "scripts": {
"clean": "rimraf dist", "clean": "rimraf dist",
"watch": "tsc --watch", "watch": "tsc --watch",
"build": "yarn clean && tsc", "build": "pnpm clean && tsc",
"test": "echo \"Error: run tests from root\" && exit 1" "test": "echo \"Error: run tests from root\" && exit 1"
}, },
"devDependencies": { "devDependencies": {
"@javatypes/nukkit-api": "^0.0.3", "@javatypes/nukkit-api": "^0.0.3"
"reflect-metadata": "^0.1.13",
"rimraf": "^4.1.2",
"typescript": "^4.9.5"
}, },
"dependencies": { "dependencies": {
"@ccms/api": "^0.28.0-beta.3", "@ccms/api": "workspace:*",
"@ccms/common": "^0.28.0-beta.3", "@ccms/common": "workspace:*",
"@ccms/container": "^0.28.0-beta.3" "@ccms/container": "workspace:*"
} }
} }

View File

@@ -1 +0,0 @@
../../.npmignore

View File

@@ -1,6 +1,6 @@
{ {
"name": "@ccms/plugin", "name": "@ccms/plugin",
"version": "0.28.0-beta.3", "version": "0.28.0-beta.11",
"description": "MiaoScript plugin package", "description": "MiaoScript plugin package",
"keywords": [ "keywords": [
"miaoscript", "miaoscript",
@@ -12,26 +12,28 @@
"homepage": "https://github.com/circlecloud/ms.git", "homepage": "https://github.com/circlecloud/ms.git",
"license": "ISC", "license": "ISC",
"main": "dist/index.js", "main": "dist/index.js",
"files": [
"dist/**/*.js",
"dist/**/*.ts",
"dist/**/*.map"
],
"scripts": { "scripts": {
"clean": "rimraf dist", "clean": "rimraf dist",
"watch": "tsc --watch", "watch": "tsc --watch",
"build": "yarn clean && tsc", "build": "pnpm clean && tsc",
"test": "echo \"Error: run tests from root\" && exit 1" "test": "echo \"Error: run tests from root\" && exit 1"
}, },
"devDependencies": { "devDependencies": {
"@types/crypto-js": "^4.1.1", "@types/crypto-js": "^4.2.2",
"@types/js-yaml": "^4.0.5", "@types/js-yaml": "^4.0.9"
"reflect-metadata": "^0.1.13",
"rimraf": "^4.1.2",
"typescript": "^4.9.5"
}, },
"dependencies": { "dependencies": {
"@ccms/api": "^0.28.0-beta.3", "@ccms/api": "workspace:*",
"@ccms/common": "^0.28.0-beta.3", "@ccms/common": "workspace:*",
"@ccms/container": "^0.28.0-beta.3", "@ccms/container": "workspace:*",
"@ccms/i18n": "^0.28.0-beta.3", "@ccms/i18n": "workspace:*",
"@ccms/verify": "^0.26.1", "@ccms/verify": "^0.26.1",
"crypto-js": "^4.1.1", "crypto-js": "^4.2.0",
"js-yaml": "^4.1.0" "js-yaml": "^4.1.0"
} }
} }

View File

@@ -13,6 +13,8 @@ import './config/loader'
export class PluginConfigManager { export class PluginConfigManager {
@Autowired(ContainerInstance) @Autowired(ContainerInstance)
private container: Container private container: Container
@Autowired(plugin.PluginFolder)
private pluginFolder: string
private configLoaderMap = new Map<string, PluginConfigLoader>() private configLoaderMap = new Map<string, PluginConfigLoader>()
@@ -31,7 +33,7 @@ export class PluginConfigManager {
} }
getConfigLoader(format: string) { getConfigLoader(format: string) {
if (!this.configLoaderMap.has(format)) { throw new Error(`Unsupport config format ${format} !`) } if (!this.configLoaderMap.has(format)) { throw new Error(`unsupport config format ${format} !`) }
return this.configLoaderMap.get(format) return this.configLoaderMap.get(format)
} }
@@ -68,7 +70,8 @@ export class PluginConfigManager {
try { try {
let defaultValue = metadata.default ?? plugin[metadata.variable] let defaultValue = metadata.default ?? plugin[metadata.variable]
metadata.file = fs.concat( metadata.file = fs.concat(
fs.file(plugin.description.loadMetadata.file).parent, root,
this.pluginFolder,
plugin.description.name, plugin.description.name,
metadata.filename metadata.filename
) )
@@ -85,7 +88,7 @@ export class PluginConfigManager {
if (metadata.migrate && defaultValue && this.setDefaultValue(configValue, defaultValue, !!metadata.default)) { if (metadata.migrate && defaultValue && this.setDefaultValue(configValue, defaultValue, !!metadata.default)) {
base.save(metadata.file, configLoader.dump(configValue)) base.save(metadata.file, configLoader.dump(configValue))
} }
console.debug(`[${plugin.description.name}] Load Config ${metadata.variable} from file ${metadata.file}`) console.debug(`[${plugin.description.name}] load config ${metadata.variable} from file ${metadata.file}`)
this.defienConfigProp(plugin, metadata, configValue) this.defienConfigProp(plugin, metadata, configValue)
} catch (error: any) { } catch (error: any) {
console.i18n("ms.plugin.manager.config.load.error", { console.i18n("ms.plugin.manager.config.load.error", {
@@ -118,7 +121,7 @@ export class PluginConfigManager {
metadata.file = fs.concat(fs.file(plugin.description.loadMetadata.file).parent, plugin.description.name, metadata.filename) metadata.file = fs.concat(fs.file(plugin.description.loadMetadata.file).parent, plugin.description.name, metadata.filename)
let result = this.getConfigLoader(metadata.format).dump(plugin[metadata.variable]) let result = this.getConfigLoader(metadata.format).dump(plugin[metadata.variable])
base.save(metadata.file, result) base.save(metadata.file, result)
console.debug(`[${plugin.description.name}] Save Config ${metadata.variable} to file ${metadata.file} => console.debug(`[${plugin.description.name}] save config ${metadata.variable} to file ${metadata.file} =>
${result.substring(0, 500)}`) ${result.substring(0, 500)}`)
return true return true
} catch (error: any) { } catch (error: any) {

View File

@@ -17,11 +17,11 @@ export class BasicLoader implements plugin.PluginLoader {
if (metadata?.type == this.type) { if (metadata?.type == this.type) {
loadMetadata.metadata = metadata loadMetadata.metadata = metadata
loadMetadata.loaded = true loadMetadata.loaded = true
this.pluginRequireMap.set(metadata.source.toString(), loadMetadata.instance) this.pluginRequireMap.set(loadMetadata.path, loadMetadata.instance)
} }
return loadMetadata return loadMetadata
} }
build(metadata: plugin.PluginMetadata) { build(metadata: plugin.PluginMetadata) {
return this.pluginRequireMap.get(metadata.source.toString()) return this.pluginRequireMap.get(metadata.loadMetadata.path)
} }
} }

View File

@@ -21,8 +21,8 @@ export class IocLoader implements plugin.PluginLoader {
} }
require(loadMetadata: plugin.PluginLoadMetadata) { require(loadMetadata: plugin.PluginLoadMetadata) {
let metadata = this.pluginMetadataMap.get(loadMetadata.file.toString()) let metadata = this.pluginMetadataMap.get(loadMetadata.path)
if (metadata && metadata.type == this.type) { if (metadata?.type == this.type) {
loadMetadata.metadata = metadata loadMetadata.metadata = metadata
loadMetadata.loaded = true loadMetadata.loaded = true
} }
@@ -54,13 +54,6 @@ export class IocLoader implements plugin.PluginLoader {
disable(plugin: plugin.Plugin): void { disable(plugin: plugin.Plugin): void {
this.stage(plugin, 'disable') this.stage(plugin, 'disable')
} }
reload(plugin: plugin.Plugin): void {
this.disable(plugin)
//@ts-ignore
require(plugin.description.source, { cache: false })
this.load(plugin)
this.enable(plugin)
}
private bindPlugin(metadata: plugin.PluginMetadata) { private bindPlugin(metadata: plugin.PluginMetadata) {
if (this.container.isBoundNamed(plugin.Plugin, metadata.name)) { if (this.container.isBoundNamed(plugin.Plugin, metadata.name)) {

View File

@@ -18,6 +18,8 @@ export class PluginManagerImpl implements plugin.PluginManager {
private pluginInstance: any private pluginInstance: any
@Autowired(server.ServerType) @Autowired(server.ServerType)
private serverType: string private serverType: string
@Autowired(plugin.PluginFolder)
private pluginFolder: string
@Autowired() @Autowired()
private serverChecker: server.ServerChecker private serverChecker: server.ServerChecker
@@ -58,6 +60,21 @@ export class PluginManagerImpl implements plugin.PluginManager {
this.eventManager this.eventManager
this.configManager this.configManager
this.commandManager this.commandManager
process.on('core.enable', (core) => {
process.emit('core.before.load.plugins')
let loadPluginStartTime = new Date().getTime()
console.i18n("ms.core.plugin.initialize")
process.emit('core.load.plugins', this.pluginFolder)
console.i18n("ms.core.plugin.completed", { time: (new Date().getTime() - loadPluginStartTime) / 1000 })
process.emit('core.after.load.plugins')
})
process.on('core.load.plugins', (pluginFolder) => {
this.scan(pluginFolder)
this.buildPlugins()
this.loadPlugins()
this.enablePlugins()
})
process.on('core.disable', () => { this.disablePlugins() })
} }
initialize() { initialize() {
@@ -86,7 +103,7 @@ export class PluginManagerImpl implements plugin.PluginManager {
} }
scan(folder: string): void { scan(folder: string): void {
if (!folder) { throw new Error('plugin scan folder can\'t be empty!') } if (!folder) { throw new Error("plugin scan folder can't be undefiend.") }
this.initialize() this.initialize()
process.emit('plugin.manager.before.scan', folder, this) process.emit('plugin.manager.before.scan', folder, this)
for (const [, scanner] of this.sacnnerMap) { for (const [, scanner] of this.sacnnerMap) {
@@ -96,7 +113,7 @@ export class PluginManagerImpl implements plugin.PluginManager {
console.i18n('ms.plugin.manager.scan.finish', { scanner: scanner.type, folder, size: loadMetadatas.length }) console.i18n('ms.plugin.manager.scan.finish', { scanner: scanner.type, folder, size: loadMetadatas.length })
for (const loadMetadata of loadMetadatas) { for (const loadMetadata of loadMetadatas) {
try { try {
this.loadAndRequirePlugin(loadMetadata) this.require(loadMetadata)
} catch (error: any) { } catch (error: any) {
console.console(`§c扫描器 §4${scanner.type} §c文件 §4${loadMetadata.file.toString().replace(root, '')} §c编译失败 请提供下列错误给开发者`) console.console(`§c扫描器 §4${scanner.type} §c文件 §4${loadMetadata.file.toString().replace(root, '')} §c编译失败 请提供下列错误给开发者`)
console.ex(error) console.ex(error)
@@ -109,12 +126,6 @@ export class PluginManagerImpl implements plugin.PluginManager {
process.emit('plugin.manager.after.scan', folder, this) process.emit('plugin.manager.after.scan', folder, this)
} }
build(): void {
process.emit('plugin.manager.before.build', this)
this.buildPlugins()
process.emit('plugin.manager.after.build', this)
}
private logStage(plugin: plugin.Plugin, stage: string) { private logStage(plugin: plugin.Plugin, stage: string) {
console.i18n("ms.plugin.manager.stage", { stage, plugin: plugin.description.name, version: plugin.description.version, author: plugin.description.author }) console.i18n("ms.plugin.manager.stage", { stage, plugin: plugin.description.name, version: plugin.description.version, author: plugin.description.author })
} }
@@ -134,9 +145,9 @@ export class PluginManagerImpl implements plugin.PluginManager {
} }
} }
private loadPlugin(loadMetadata: plugin.PluginLoadMetadata) { private loadPlugin(loadMetadata: plugin.PluginLoadMetadata): plugin.PluginMetadata {
if (!loadMetadata) { throw new Error('loadMetadata can\'t be undefiend when loadPlugin!') } if (!loadMetadata) { throw new Error("loadMetadata can't be undefiend when loadPlugin.") }
if (loadMetadata.loaded) { throw new Error(`Plugin file ${loadMetadata.file} is already loaded by ${loadMetadata.loader?.type}!`) } if (loadMetadata.loaded) { throw new Error(`plugin file ${loadMetadata.file} is already loaded by ${loadMetadata.loader?.type}.`) }
process.emit(`plugin.before.require`, loadMetadata) process.emit(`plugin.before.require`, loadMetadata)
try { try {
for (const [, loader] of this.loaderMap) { for (const [, loader] of this.loaderMap) {
@@ -145,6 +156,8 @@ export class PluginManagerImpl implements plugin.PluginManager {
} catch (error: any) { } catch (error: any) {
console.i18n("ms.plugin.manager.initialize.error", { name: loadMetadata.file, ex: error }) console.i18n("ms.plugin.manager.initialize.error", { name: loadMetadata.file, ex: error })
console.ex(error) console.ex(error)
} finally {
process.emit(`plugin.after.require`, loadMetadata)
} }
} }
@@ -155,19 +168,18 @@ export class PluginManagerImpl implements plugin.PluginManager {
let metadata = loadMetadata.metadata let metadata = loadMetadata.metadata
if (this.metadataMap.has(metadata.name) && this.instanceMap.has(metadata.name)) { if (this.metadataMap.has(metadata.name) && this.instanceMap.has(metadata.name)) {
let oldMetadata = this.metadataMap.get(metadata.name) let oldMetadata = this.metadataMap.get(metadata.name)
throw new Error(`Plugin ${oldMetadata.name} is already load from ${oldMetadata.source}...`) throw new Error(`plugin ${oldMetadata.name} is already load from ${oldMetadata.source}.`)
} }
this.metadataMap.set(metadata.name, metadata) this.metadataMap.set(metadata.name, metadata)
metadata.loadMetadata = loadMetadata metadata.loadMetadata = loadMetadata
process.emit(`plugin.after.require`, loadMetadata)
} }
return loadMetadata return loadMetadata
} catch (error: any) { } catch (error: any) {
if (global.debug) { if (global.debug) {
console.console(`§6Loader §b${loader.type} §6load §a${loadMetadata.file} §cerror. §4Err: §c${error}`) console.console(`§6loader §b${loader.type} §6load §a${loadMetadata.file} §cerror. §4Err: §c${error}`)
console.ex(error) console.ex(error)
} else { } else {
console.warn(`Loader ${loader.type} load ${loadMetadata.file} error. Err: ${error}`) console.warn(`loader ${loader.type} load ${loadMetadata.file} error. Err: ${error}`)
} }
} }
} }
@@ -175,10 +187,10 @@ export class PluginManagerImpl implements plugin.PluginManager {
private loadAndRequirePlugin(loadMetadata: plugin.PluginLoadMetadata) { private loadAndRequirePlugin(loadMetadata: plugin.PluginLoadMetadata) {
let startTime = Date.now() let startTime = Date.now()
let metadata = this.loadPlugin(loadMetadata.scanner.load(loadMetadata)) let metadata = this.loadPlugin(loadMetadata.scanner.load(loadMetadata))
if (!metadata) { throw new Error('load plugin metadata failed.') } if (!metadata) { throw new Error(`can't load plugin from metadata: ${JSON.stringify(loadMetadata)}`) }
console.i18n('ms.plugin.manager.build', { console.i18n('ms.plugin.manager.build', {
name: loadMetadata.metadata.name, name: metadata.name,
version: loadMetadata.metadata.version, version: metadata.version,
file: loadMetadata.file.toString().replace(root, ''), file: loadMetadata.file.toString().replace(root, ''),
scanner: loadMetadata.scanner.type, scanner: loadMetadata.scanner.type,
loader: loadMetadata.loader.type, loader: loadMetadata.loader.type,
@@ -192,39 +204,54 @@ export class PluginManagerImpl implements plugin.PluginManager {
* @param file java.io.File * @param file java.io.File
*/ */
loadFromFile(file: string, ext: any = 'js'): plugin.Plugin { loadFromFile(file: string, ext: any = 'js'): plugin.Plugin {
if (!file) { throw new Error('plugin file can\'t be undefiend.') } if (!file) { throw new Error("plugin file can't be undefiend.") }
let scanner = this.sacnnerMap.get(ext) let scanner = this.sacnnerMap.get(ext)
if (!scanner) { throw new Error(`plugin scanner ${ext} can't found in sacnnerMap.`) } if (!scanner) { throw new Error(`scanner ${ext} can't found in sacnnerMap.`) }
let metadata = this.loadAndRequirePlugin(scanner.read(file)) let metadata = this.loadAndRequirePlugin(scanner.read(file))
this.buildPlugin(metadata) this.buildPlugin(metadata)
let plugin = metadata.target let plugin = metadata.target
if (!plugin) { throw new Error(`plugin scanner ${ext} can't found in sacnnerMap.`) } if (!plugin) { throw new Error(`loader ${metadata.loadMetadata.loader.type} build plugin ${metadata.name} failed.`) }
this.load(plugin) this.load(plugin)
this.enable(plugin) this.enable(plugin)
return plugin return plugin
} }
load(...args: any[]): void { load(plugin: plugin.Plugin): void {
this.checkAndGet(args[0]).forEach((plugin: plugin.Plugin) => this.runPluginStage(plugin, 'load')) this.runPluginStage(plugin, 'load')
} }
enable(...args: any[]): void { enable(plugin: plugin.Plugin): void {
this.checkAndGet(args[0]).forEach((plugin: plugin.Plugin) => this.runPluginStage(plugin, 'enable')) this.runPluginStage(plugin, 'enable')
} }
disable(...args: any[]): void { disable(plugin: plugin.Plugin): void {
this.checkAndGet(args[0]).forEach((plugin: plugin.Plugin) => { this.runPluginStage(plugin, 'disable')
this.runPluginStage(plugin, 'disable') this.metadataMap.delete(plugin.description.name)
this.metadataMap.delete(plugin.description.name) this.instanceMap.delete(plugin.description.name)
this.instanceMap.delete(plugin.description.name)
})
} }
reload(...args: any[]): void { reload(plugin: plugin.Plugin): void {
this.checkAndGet(args[0]).forEach((pl: plugin.Plugin) => { this.rebuild(plugin)
this.disable(pl) }
this.loadFromFile(pl.description.loadMetadata.file, pl.description.loadMetadata.scanner.type)
}) require(loadMetadata: plugin.PluginLoadMetadata): plugin.PluginMetadata {
return this.loadAndRequirePlugin(loadMetadata)
}
build(metadata: plugin.PluginMetadata): plugin.Plugin {
try {
return this.buildPlugin(metadata)
} catch (error: any) {
console.ex(error)
}
}
rebuild(plugin: plugin.Plugin): void {
if (!plugin) { throw new Error(`can't run reload plugin because plugin is ${plugin}`) }
this.disable(plugin)
let loadMetadata = plugin.description.loadMetadata
delete require.cache[loadMetadata.path]
this.loadFromFile(loadMetadata.file)
} }
has(name: string) { has(name: string) {
@@ -232,44 +259,63 @@ export class PluginManagerImpl implements plugin.PluginManager {
} }
get(name: string) { get(name: string) {
return this.instanceMap.get(name) || null return this.instanceMap.get(name)
} }
getPlugin(name: string) { getPlugin(name: string) {
return this.instanceMap.get(name) || null return this.instanceMap.get(name)
} }
getPlugins() { getPlugins() {
return this.instanceMap return this.instanceMap
} }
private runCatch(pl: any, func: string) { buildPlugins() {
try { process.emit('plugin.manager.before.build', this)
if (pl[func]) pl[func].call(pl) for (const [key, metadata] of this.metadataMap) {
} catch (ex: any) { if (metadata.depends?.length) {
console.i18n("ms.plugin.manager.stage.exec.error", { plugin: pl.description.name, executor: func, error: ex }) this.lazyMetadataMap.set(key, metadata)
console.ex(ex) } else {
this.build(metadata)
}
}
for (const metadata of this.lazyMetadataMap.values()) {
this.build(metadata)
}
process.emit('plugin.manager.after.build', this)
}
rebuildPlugins() {
for (const plugin of this.instanceMap.values()) {
this.rebuild(plugin)
} }
} }
private checkAndGet(name: string | plugin.Plugin | undefined | any): Map<string, plugin.Plugin> | plugin.Plugin[] { loadPlugins() {
if (name === undefined) throw new Error(`checkAndGet Plugin can't be undefiend.`) for (const plugin of this.instanceMap.values()) {
if (name == this.instanceMap) { return this.instanceMap } this.load(plugin)
if (typeof name == 'string' && this.instanceMap.has(name)) { return [this.instanceMap.get(name)] } }
if (name instanceof interfaces.Plugin) { return [name as plugin.Plugin] }
if (name.description?.name) { return [name as plugin.Plugin] }
throw new Error(`Plugin ${JSON.stringify(name)} not exist.`)
} }
private buildPlugins() { enablePlugins() {
this.metadataMap.forEach((metadata, key) => { for (const plugin of this.instanceMap.values()) {
if (metadata?.depends?.length) { this.enable(plugin)
this.lazyMetadataMap.set(key, metadata) }
} else { }
this.tryBuildPlugin(metadata)
} disablePlugins() {
}) for (const plugin of this.instanceMap.values()) {
this.lazyMetadataMap.forEach((metadata, key) => this.tryBuildPlugin(metadata)) this.disable(plugin)
}
}
private runCatch(plugin: any, fn: string) {
try {
if (plugin[fn]) plugin[fn].call(plugin)
} catch (ex: any) {
console.i18n("ms.plugin.manager.stage.exec.error", { plugin: plugin.description.name, executor: fn, error: ex })
console.ex(ex)
}
} }
private checkDepends(depends: string | string[]) { private checkDepends(depends: string | string[]) {
@@ -280,18 +326,11 @@ export class PluginManagerImpl implements plugin.PluginManager {
} }
private checkNativeDepends(depends: string | string[]) { private checkNativeDepends(depends: string | string[]) {
if (!depends) return [] if (!depends) return []
let loseDepends = [] let loseNativeDepends = []
for (const depend of depends) { if (!this.nativePluginManager.has(depend)) loseDepends.push(depend) } for (const depend of depends) { if (!this.nativePluginManager.has(depend)) loseNativeDepends.push(depend) }
return loseDepends return loseNativeDepends
} }
private tryBuildPlugin(metadata: plugin.PluginMetadata) {
try {
return this.buildPlugin(metadata)
} catch (error: any) {
console.ex(error)
}
}
private buildPlugin(metadata: plugin.PluginMetadata) { private buildPlugin(metadata: plugin.PluginMetadata) {
process.emit(`plugin.before.build`, metadata) process.emit(`plugin.before.build`, metadata)
@@ -304,6 +343,7 @@ export class PluginManagerImpl implements plugin.PluginManager {
if (loseNativeDepends.length) { throw new Error(`§4无法加载插件 §b${metadata.name} §4请检查插件依赖 §3[${loseNativeDepends.join(',')}] §4是否安装完整!`) } if (loseNativeDepends.length) { throw new Error(`§4无法加载插件 §b${metadata.name} §4请检查插件依赖 §3[${loseNativeDepends.join(',')}] §4是否安装完整!`) }
let pluginInstance = this.loaderMap.get(metadata.type).build(metadata) let pluginInstance = this.loaderMap.get(metadata.type).build(metadata)
if (!pluginInstance) { throw new Error(`§4加载器 §c${metadata.type} §4加载插件 §c${metadata.name} §4失败!`) } if (!pluginInstance) { throw new Error(`§4加载器 §c${metadata.type} §4加载插件 §c${metadata.name} §4失败!`) }
process.emit(`plugin.build`, pluginInstance)
metadata.target = pluginInstance metadata.target = pluginInstance
this.instanceMap.set(metadata.name, pluginInstance) this.instanceMap.set(metadata.name, pluginInstance)
process.emit(`plugin.after.build`, metadata, pluginInstance) process.emit(`plugin.after.build`, metadata, pluginInstance)

View File

@@ -13,15 +13,21 @@ export class JSFileScanner implements plugin.PluginScanner {
} }
read(file: any): plugin.PluginLoadMetadata { read(file: any): plugin.PluginLoadMetadata {
return { file, type: this.type, scanner: this, loaded: false } return {
file,
path: file.canonicalPath || file.toString(),
type: this.type,
scanner: this,
loaded: false
}
} }
load(metadata: plugin.PluginLoadMetadata): plugin.PluginLoadMetadata { load(loadMetadata: plugin.PluginLoadMetadata): plugin.PluginLoadMetadata {
if (metadata.type !== this.type) { return } if (loadMetadata.type !== this.type) { return }
this.updatePlugin(metadata.file) this.updatePlugin(loadMetadata.file)
//@ts-ignore load plugin not use cache delete require.cache[loadMetadata.path]
metadata.instance = require(metadata.file.toString(), { cache: false }) loadMetadata.instance = require(loadMetadata.path)
return metadata return loadMetadata
} }
private scanFolder(folder: any): string[] { private scanFolder(folder: any): string[] {
@@ -45,7 +51,7 @@ export class JSFileScanner implements plugin.PluginScanner {
} }
private updatePlugin(file: any) { private updatePlugin(file: any) {
var update = fs.file(fs.file(fs.file(file).parentFile, 'update'), file.name) var update = fs.file(fs.concat(file.parentFile, 'update', file.name))
if (update.exists()) { if (update.exists()) {
console.i18n("ms.plugin.manager.build.update", { name: file.name }) console.i18n("ms.plugin.manager.build.update", { name: file.name })
fs.move(update, file, true) fs.move(update, file, true)

View File

@@ -1 +0,0 @@
../../.npmignore

View File

@@ -1,27 +1,26 @@
{ {
"name": "@ccms/polyfill", "name": "@ccms/polyfill",
"version": "0.28.0-beta.3", "version": "0.28.0-beta.11",
"description": "MiaoScript polyfill package", "description": "MiaoScript polyfill package",
"author": "MiaoWoo <admin@yumc.pw>", "author": "MiaoWoo <admin@yumc.pw>",
"homepage": "https://github.com/circlecloud/ms.git", "homepage": "https://github.com/circlecloud/ms.git",
"license": "ISC", "license": "ISC",
"main": "dist/index.js", "main": "dist/index.js",
"types": "dist/index.d.ts", "types": "dist/index.d.ts",
"files": [
"dist/**/*.js",
"dist/**/*.ts",
"dist/**/*.map"
],
"scripts": { "scripts": {
"clean": "rimraf dist", "clean": "rimraf dist",
"watch": "tsc --watch", "watch": "tsc --watch",
"build": "yarn clean && tsc", "build": "pnpm clean && tsc",
"test": "echo \"Error: run tests from root\" && exit 1" "test": "echo \"Error: run tests from root\" && exit 1"
}, },
"dependencies": { "dependencies": {
"@ccms/i18n": "^0.28.0-beta.3", "@ccms/i18n": "workspace:*",
"@ccms/nodejs": "^0.28.0-beta.3", "@ccms/nodejs": "workspace:*",
"core-js": "^3.27.2" "core-js": "^3.44.0"
},
"devDependencies": {
"@ccms/nashorn": "^0.28.0-beta.3",
"reflect-metadata": "^0.1.13",
"rimraf": "^4.1.2",
"typescript": "^4.9.5"
} }
} }

View File

@@ -0,0 +1,241 @@
'use strict';
// @ts-ignore
require.internal.versionLockModules['core-js'] = '3.32.2'
import 'core-js/modules/es.symbol';
import 'core-js/modules/es.symbol.description';
import 'core-js/modules/es.symbol.async-iterator';
import 'core-js/modules/es.symbol.has-instance';
import 'core-js/modules/es.symbol.is-concat-spreadable';
import 'core-js/modules/es.symbol.iterator';
import 'core-js/modules/es.symbol.match';
import 'core-js/modules/es.symbol.match-all';
import 'core-js/modules/es.symbol.replace';
import 'core-js/modules/es.symbol.search';
import 'core-js/modules/es.symbol.species';
import 'core-js/modules/es.symbol.split';
import 'core-js/modules/es.symbol.to-primitive';
import 'core-js/modules/es.symbol.to-string-tag';
import 'core-js/modules/es.symbol.unscopables';
import 'core-js/modules/es.array.at';
import 'core-js/modules/es.array.concat';
import 'core-js/modules/es.array.copy-within';
import 'core-js/modules/es.array.every';
import 'core-js/modules/es.array.fill';
import 'core-js/modules/es.array.filter';
import 'core-js/modules/es.array.find';
import 'core-js/modules/es.array.find-index';
import 'core-js/modules/es.array.find-last';
import 'core-js/modules/es.array.find-last-index';
import 'core-js/modules/es.array.flat';
import 'core-js/modules/es.array.flat-map';
import 'core-js/modules/es.array.for-each';
import 'core-js/modules/es.array.from';
import 'core-js/modules/es.array.includes';
import 'core-js/modules/es.array.index-of';
import 'core-js/modules/es.array.is-array';
import 'core-js/modules/es.array.iterator';
import 'core-js/modules/es.array.join';
import 'core-js/modules/es.array.last-index-of';
import 'core-js/modules/es.array.map';
import 'core-js/modules/es.array.of';
import 'core-js/modules/es.array.push';
import 'core-js/modules/es.array.reduce';
import 'core-js/modules/es.array.reduce-right';
import 'core-js/modules/es.array.reverse';
import 'core-js/modules/es.array.slice';
import 'core-js/modules/es.array.some';
import 'core-js/modules/es.array.sort';
import 'core-js/modules/es.array.species';
import 'core-js/modules/es.array.splice';
import 'core-js/modules/es.array.to-reversed';
import 'core-js/modules/es.array.to-sorted';
import 'core-js/modules/es.array.to-spliced';
import 'core-js/modules/es.array.unscopables.flat';
import 'core-js/modules/es.array.unscopables.flat-map';
import 'core-js/modules/es.array.unshift';
import 'core-js/modules/es.array.with';
import 'core-js/modules/es.array-buffer.constructor';
import 'core-js/modules/es.array-buffer.is-view';
import 'core-js/modules/es.array-buffer.slice';
import 'core-js/modules/es.data-view';
import 'core-js/modules/es.date.get-year';
import 'core-js/modules/es.date.now';
import 'core-js/modules/es.date.set-year';
import 'core-js/modules/es.date.to-gmt-string';
import 'core-js/modules/es.date.to-iso-string';
import 'core-js/modules/es.date.to-json';
import 'core-js/modules/es.date.to-primitive';
import 'core-js/modules/es.date.to-string';
import 'core-js/modules/es.escape';
import 'core-js/modules/es.function.bind';
import 'core-js/modules/es.function.has-instance';
import 'core-js/modules/es.function.name';
import 'core-js/modules/es.global-this';
import 'core-js/modules/es.json.stringify';
import 'core-js/modules/es.json.to-string-tag';
import 'core-js/modules/es.map';
import 'core-js/modules/es.math.acosh';
import 'core-js/modules/es.math.asinh';
import 'core-js/modules/es.math.atanh';
import 'core-js/modules/es.math.cbrt';
import 'core-js/modules/es.math.clz32';
import 'core-js/modules/es.math.cosh';
import 'core-js/modules/es.math.expm1';
import 'core-js/modules/es.math.fround';
import 'core-js/modules/es.math.hypot';
import 'core-js/modules/es.math.imul';
import 'core-js/modules/es.math.log10';
import 'core-js/modules/es.math.log1p';
import 'core-js/modules/es.math.log2';
import 'core-js/modules/es.math.sign';
import 'core-js/modules/es.math.sinh';
import 'core-js/modules/es.math.tanh';
import 'core-js/modules/es.math.to-string-tag';
import 'core-js/modules/es.math.trunc';
import 'core-js/modules/es.number.constructor';
import 'core-js/modules/es.number.epsilon';
import 'core-js/modules/es.number.is-finite';
import 'core-js/modules/es.number.is-integer';
import 'core-js/modules/es.number.is-nan';
import 'core-js/modules/es.number.is-safe-integer';
import 'core-js/modules/es.number.max-safe-integer';
import 'core-js/modules/es.number.min-safe-integer';
import 'core-js/modules/es.number.parse-float';
import 'core-js/modules/es.number.parse-int';
import 'core-js/modules/es.number.to-exponential';
import 'core-js/modules/es.number.to-fixed';
import 'core-js/modules/es.number.to-precision';
import 'core-js/modules/es.object.assign';
import 'core-js/modules/es.object.create';
import 'core-js/modules/es.object.define-getter';
import 'core-js/modules/es.object.define-properties';
import 'core-js/modules/es.object.define-property';
import 'core-js/modules/es.object.define-setter';
import 'core-js/modules/es.object.entries';
import 'core-js/modules/es.object.freeze';
import 'core-js/modules/es.object.from-entries';
import 'core-js/modules/es.object.get-own-property-descriptor';
import 'core-js/modules/es.object.get-own-property-descriptors';
import 'core-js/modules/es.object.get-own-property-names';
import 'core-js/modules/es.object.get-prototype-of';
import 'core-js/modules/es.object.has-own';
import 'core-js/modules/es.object.is';
import 'core-js/modules/es.object.is-extensible';
import 'core-js/modules/es.object.is-frozen';
import 'core-js/modules/es.object.is-sealed';
import 'core-js/modules/es.object.keys';
import 'core-js/modules/es.object.lookup-getter';
import 'core-js/modules/es.object.lookup-setter';
import 'core-js/modules/es.object.prevent-extensions';
import 'core-js/modules/es.object.proto';
import 'core-js/modules/es.object.seal';
import 'core-js/modules/es.object.values';
import 'core-js/modules/es.parse-float';
import 'core-js/modules/es.parse-int';
import 'core-js/modules/es.promise';
import 'core-js/modules/es.promise.all-settled';
import 'core-js/modules/es.promise.any';
import 'core-js/modules/es.promise.finally';
import 'core-js/modules/es.reflect.apply';
import 'core-js/modules/es.reflect.construct';
import 'core-js/modules/es.reflect.define-property';
import 'core-js/modules/es.reflect.delete-property';
import 'core-js/modules/es.reflect.get';
import 'core-js/modules/es.reflect.get-own-property-descriptor';
import 'core-js/modules/es.reflect.get-prototype-of';
import 'core-js/modules/es.reflect.has';
import 'core-js/modules/es.reflect.is-extensible';
import 'core-js/modules/es.reflect.own-keys';
import 'core-js/modules/es.reflect.prevent-extensions';
import 'core-js/modules/es.reflect.set';
import 'core-js/modules/es.reflect.set-prototype-of';
import 'core-js/modules/es.reflect.to-string-tag';
import 'core-js/modules/es.regexp.constructor';
import 'core-js/modules/es.regexp.dot-all';
import 'core-js/modules/es.regexp.exec';
import 'core-js/modules/es.regexp.flags';
import 'core-js/modules/es.regexp.sticky';
import 'core-js/modules/es.regexp.test';
import 'core-js/modules/es.regexp.to-string';
import 'core-js/modules/es.set';
import 'core-js/modules/es.string.at-alternative';
import 'core-js/modules/es.string.code-point-at';
import 'core-js/modules/es.string.ends-with';
import 'core-js/modules/es.string.from-code-point';
import 'core-js/modules/es.string.includes';
import 'core-js/modules/es.string.is-well-formed';
import 'core-js/modules/es.string.iterator';
import 'core-js/modules/es.string.match';
import 'core-js/modules/es.string.match-all';
import 'core-js/modules/es.string.pad-end';
import 'core-js/modules/es.string.pad-start';
import 'core-js/modules/es.string.raw';
import 'core-js/modules/es.string.repeat';
import 'core-js/modules/es.string.replace';
import 'core-js/modules/es.string.replace-all';
import 'core-js/modules/es.string.search';
import 'core-js/modules/es.string.split';
import 'core-js/modules/es.string.starts-with';
import 'core-js/modules/es.string.substr';
import 'core-js/modules/es.string.to-well-formed';
import 'core-js/modules/es.string.trim';
import 'core-js/modules/es.string.trim-end';
import 'core-js/modules/es.string.trim-start';
import 'core-js/modules/es.string.anchor';
import 'core-js/modules/es.string.big';
import 'core-js/modules/es.string.blink';
import 'core-js/modules/es.string.bold';
import 'core-js/modules/es.string.fixed';
import 'core-js/modules/es.string.fontcolor';
import 'core-js/modules/es.string.fontsize';
import 'core-js/modules/es.string.italics';
import 'core-js/modules/es.string.link';
import 'core-js/modules/es.string.small';
import 'core-js/modules/es.string.strike';
import 'core-js/modules/es.string.sub';
import 'core-js/modules/es.string.sup';
import 'core-js/modules/es.typed-array.float32-array';
import 'core-js/modules/es.typed-array.float64-array';
import 'core-js/modules/es.typed-array.int8-array';
import 'core-js/modules/es.typed-array.int16-array';
import 'core-js/modules/es.typed-array.int32-array';
import 'core-js/modules/es.typed-array.uint8-array';
import 'core-js/modules/es.typed-array.uint8-clamped-array';
import 'core-js/modules/es.typed-array.uint16-array';
import 'core-js/modules/es.typed-array.uint32-array';
import 'core-js/modules/es.typed-array.at';
import 'core-js/modules/es.typed-array.copy-within';
import 'core-js/modules/es.typed-array.every';
import 'core-js/modules/es.typed-array.fill';
import 'core-js/modules/es.typed-array.filter';
import 'core-js/modules/es.typed-array.find';
import 'core-js/modules/es.typed-array.find-index';
import 'core-js/modules/es.typed-array.find-last';
import 'core-js/modules/es.typed-array.find-last-index';
import 'core-js/modules/es.typed-array.for-each';
import 'core-js/modules/es.typed-array.from';
import 'core-js/modules/es.typed-array.includes';
import 'core-js/modules/es.typed-array.index-of';
import 'core-js/modules/es.typed-array.iterator';
import 'core-js/modules/es.typed-array.join';
import 'core-js/modules/es.typed-array.last-index-of';
import 'core-js/modules/es.typed-array.map';
import 'core-js/modules/es.typed-array.of';
import 'core-js/modules/es.typed-array.reduce';
import 'core-js/modules/es.typed-array.reduce-right';
import 'core-js/modules/es.typed-array.reverse';
import 'core-js/modules/es.typed-array.set';
import 'core-js/modules/es.typed-array.slice';
import 'core-js/modules/es.typed-array.some';
import 'core-js/modules/es.typed-array.sort';
import 'core-js/modules/es.typed-array.subarray';
import 'core-js/modules/es.typed-array.to-locale-string';
import 'core-js/modules/es.typed-array.to-reversed';
import 'core-js/modules/es.typed-array.to-sorted';
import 'core-js/modules/es.typed-array.to-string';
import 'core-js/modules/es.typed-array.with';
import 'core-js/modules/es.unescape';
import 'core-js/modules/es.weak-map';
import 'core-js/modules/es.weak-set';
module.exports = require('core-js/internals/path');

View File

@@ -7,7 +7,7 @@ console.i18n("ms.polyfill.initialize")
import './openjdk-nashorn-shim' import './openjdk-nashorn-shim'
import './es5-ext' import './es5-ext'
import './node-shim' import './node-shim'
import 'core-js' import './core-js'
//@ts-ignore //@ts-ignore
process.on('exit', () => require.disable()) process.on('exit', () => require.disable())
global.setGlobal('Proxy', require('./proxy').Proxy) global.setGlobal('Proxy', require('./proxy').Proxy)

View File

@@ -18,10 +18,17 @@ const JavaScriptTask = Java.type(base.getJavaScriptTaskClass().name)
const threadCount = new AtomicInteger(0) const threadCount = new AtomicInteger(0)
const threadGroup = new ThreadGroup("@ccms/micro-task") const threadGroup = new ThreadGroup("@ccms/micro-task")
const microTaskPool = new ThreadPoolExecutor( const microTaskPool = new ThreadPoolExecutor(
100, 200, 60, TimeUnit.SECONDS, 16, 32, 64, TimeUnit.SECONDS,
new LinkedBlockingQueue(1024), new LinkedBlockingQueue(64),
new ThreadFactory((run: any) => new Thread(threadGroup, run, "@ccms/micro-task-" + threadCount.incrementAndGet())) new ThreadFactory((run: any) => new Thread(threadGroup, run, "@ccms/micro-task-" + threadCount.incrementAndGet()))
) )
declare global {
interface Function {
thread: any;
}
}
class Process extends EventEmitter { class Process extends EventEmitter {
readonly version = base.version readonly version = base.version
readonly versions = [] readonly versions = []
@@ -45,11 +52,13 @@ class Process extends EventEmitter {
execArgv = '' execArgv = ''
execPath = '' execPath = ''
private queueMicrotaskExecuteTimeout = 5000
constructor() { constructor() {
super() super()
this.on('exit', () => { this.on('exit', () => {
console.log(`await microTaskPool termination! queueTask: ${microTaskPool.shutdownNow().size()} remainTask: ${threadGroup.activeCount()}`) console.log(`await microTaskPool termination! queueTask: ${microTaskPool.shutdownNow().size()} remainTask: ${threadGroup.activeCount()}`)
microTaskPool.awaitTermination(3000, TimeUnit.MILLISECONDS) microTaskPool.awaitTermination(this.queueMicrotaskExecuteTimeout, TimeUnit.MILLISECONDS)
}) })
} }
on(event: string | symbol, listener: (...args: any[]) => void) { on(event: string | symbol, listener: (...args: any[]) => void) {
@@ -67,18 +76,34 @@ class Process extends EventEmitter {
}) })
} }
nextTick(callback: Function, ...args: any[]): void { nextTick(callback: Function, ...args: any[]): void {
microTaskPool.execute(() => { try {
try { microTaskPool.submit(new Callable({
callback(args) call: () => {
} catch (origin: any) { callback.thread = Thread.currentThread();
try { try {
super.emit('error', origin) callback(args)
} catch (error: any) { } catch (origin: any) {
console.ex(origin) try {
console.ex(error) super.emit('error', origin)
} catch (error: any) {
console.ex(origin)
console.ex(error)
}
}
} }
})).get(this.queueMicrotaskExecuteTimeout, TimeUnit.MILLISECONDS)
} catch (error: any) {
if (error instanceof InterruptedException) {
return console.warn(`FixedThreadPool isInterrupted exit! Task ${callback.name || '<anonymous>'} exec exit!`)
} }
}) if (error instanceof TimeoutException) {
if (callback.thread instanceof Thread) {
console.debug(console.stack(callback.thread as any))
}
return console.warn(`Task ${callback.name || '<anonymous>'} => ${callback} exec time greater than ${this.queueMicrotaskExecuteTimeout}ms!`)
}
throw error.getCause && error.getCause() || error
}
} }
exit(code: number) { exit(code: number) {
console.log(`process exit by code ${code}!`) console.log(`process exit by code ${code}!`)
@@ -120,9 +145,6 @@ class Process extends EventEmitter {
throw new Error('MiaoScript unsupport kill.') throw new Error('MiaoScript unsupport kill.')
return true return true
} }
toString() {
return "[object process]"
}
} }
class EventLoop { class EventLoop {
@@ -135,8 +157,8 @@ class EventLoop {
constructor() { constructor() {
this.taskExecuteTimeout = parseInt(process.env.MS_TASK_EXECUTE_TIMEOUT) || 3000 this.taskExecuteTimeout = parseInt(process.env.MS_TASK_EXECUTE_TIMEOUT) || 3000
this.fixedThreadPool = new ThreadPoolExecutor( this.fixedThreadPool = new ThreadPoolExecutor(
8, 16, 0, TimeUnit.SECONDS, 4, 16, 32, TimeUnit.SECONDS,
new LinkedBlockingQueue(1024), new LinkedBlockingQueue(32),
new ThreadFactory((run: any) => { new ThreadFactory((run: any) => {
let thread = new Thread(run, "@ccms/event-loop-" + this.threadCount.incrementAndGet()) let thread = new Thread(run, "@ccms/event-loop-" + this.threadCount.incrementAndGet())
thread.setDaemon(true) thread.setDaemon(true)
@@ -174,7 +196,7 @@ class EventLoop {
this.eventLoopMainThread.interrupt() this.eventLoopMainThread.interrupt()
this.fixedThreadPool.shutdownNow() this.fixedThreadPool.shutdownNow()
console.log(`await fixedThreadPool termination!`) console.log(`await fixedThreadPool termination!`)
this.fixedThreadPool.awaitTermination(3000, TimeUnit.MILLISECONDS) this.fixedThreadPool.awaitTermination(this.taskExecuteTimeout, TimeUnit.MILLISECONDS)
}) })
} }
@@ -196,6 +218,7 @@ class EventLoop {
try { try {
this.fixedThreadPool.submit(new Callable({ this.fixedThreadPool.submit(new Callable({
call: () => { call: () => {
callback.thread = Thread.currentThread();
try { try {
callback.apply(undefined, args) callback.apply(undefined, args)
} catch (cause: any) { } catch (cause: any) {
@@ -214,6 +237,9 @@ class EventLoop {
return console.warn(`FixedThreadPool isInterrupted exit! Task ${name} exec exit!`) return console.warn(`FixedThreadPool isInterrupted exit! Task ${name} exec exit!`)
} }
if (error instanceof TimeoutException) { if (error instanceof TimeoutException) {
if (callback.thread instanceof Thread) {
console.debug(console.stack(callback.thread as any).join('\n'))
}
return console.warn(`Task ${name} => ${callback} exec time greater than ${this.taskExecuteTimeout}ms!`) return console.warn(`Task ${name} => ${callback} exec time greater than ${this.taskExecuteTimeout}ms!`)
} }
throw error.getCause && error.getCause() || error throw error.getCause && error.getCause() || error
@@ -261,7 +287,7 @@ class EventLoop {
} }
} }
global.setGlobal('process', new Process(), {}) global.setGlobal('process', new Process(), {})
Object.defineProperty(process, require('core-js/es/symbol/to-string-tag'), { value: '[object process]' }) Object.defineProperty(process, require('core-js/es/symbol/to-string-tag'), { value: 'process' })
const eventLoop = new EventLoop() const eventLoop = new EventLoop()
Object.defineProperty(process, 'eventLoop', { value: eventLoop }) Object.defineProperty(process, 'eventLoop', { value: eventLoop })
eventLoop.startEventLoop() eventLoop.startEventLoop()

View File

@@ -1 +0,0 @@
../../.npmignore

View File

@@ -1,6 +1,6 @@
{ {
"name": "@ccms/protocol", "name": "@ccms/protocol",
"version": "0.28.0-beta.3", "version": "0.28.0-beta.11",
"description": "MiaoScript protocol package", "description": "MiaoScript protocol package",
"keywords": [ "keywords": [
"miaoscript", "miaoscript",
@@ -13,15 +13,15 @@
"license": "ISC", "license": "ISC",
"main": "dist/index.js", "main": "dist/index.js",
"types": "dist/index.d.ts", "types": "dist/index.d.ts",
"files": [
"dist/**/*.js",
"dist/**/*.ts",
"dist/**/*.map"
],
"scripts": { "scripts": {
"clean": "rimraf dist", "clean": "rimraf dist",
"watch": "tsc --watch", "watch": "tsc --watch",
"build": "yarn clean && tsc", "build": "pnpm clean && tsc",
"test": "echo \"Error: run tests from root\" && exit 1" "test": "echo \"Error: run tests from root\" && exit 1"
},
"devDependencies": {
"reflect-metadata": "^0.1.13",
"rimraf": "^4.1.2",
"typescript": "^4.9.5"
} }
} }

View File

@@ -1 +0,0 @@
../../.npmignore

View File

@@ -1,6 +1,6 @@
{ {
"name": "@ccms/qrcode", "name": "@ccms/qrcode",
"version": "0.28.0-beta.3", "version": "0.28.0-beta.11",
"description": "MiaoScript qrcode package", "description": "MiaoScript qrcode package",
"keywords": [ "keywords": [
"miaoscript", "miaoscript",
@@ -12,15 +12,15 @@
"homepage": "https://github.com/circlecloud/ms.git", "homepage": "https://github.com/circlecloud/ms.git",
"license": "ISC", "license": "ISC",
"main": "dist/index.js", "main": "dist/index.js",
"files": [
"dist/**/*.js",
"dist/**/*.ts",
"dist/**/*.map"
],
"scripts": { "scripts": {
"clean": "rimraf dist", "clean": "rimraf dist",
"watch": "tsc --watch", "watch": "tsc --watch",
"build": "yarn clean && tsc", "build": "pnpm clean && tsc",
"test": "echo \"Error: run tests from root\" && exit 1" "test": "echo \"Error: run tests from root\" && exit 1"
},
"devDependencies": {
"reflect-metadata": "^0.1.13",
"rimraf": "^4.1.2",
"typescript": "^4.9.5"
} }
} }

View File

@@ -0,0 +1,47 @@
{
"private": true,
"name": "@ccms/runtime",
"version": "0.28.0-beta.11",
"description": "development runtime",
"keywords": [
"miaoscript",
"minecraft",
"bukkit",
"sponge"
],
"author": "MiaoWoo <admin@yumc.pw>",
"homepage": "https://github.com/circlecloud/ms.git",
"license": "ISC",
"main": "dist/index.js",
"files": [
"dist/**/*.js",
"dist/**/*.ts",
"dist/**/*.map"
],
"scripts": {
"clean": "rimraf dist",
"watch": "tsc --watch",
"build": "pnpm clean && tsc",
"test": "echo \"Error: run tests from root\" && exit 1"
},
"devDependencies": {
"@ccms/api": "workspace:*",
"@ccms/bukkit": "workspace:*",
"@ccms/bungee": "workspace:*",
"@ccms/common": "workspace:*",
"@ccms/container": "workspace:*",
"@ccms/core": "workspace:*",
"@ccms/database": "workspace:*",
"@ccms/i18n": "workspace:*",
"@ccms/molang": "workspace:*",
"@ccms/nashorn": "workspace:*",
"@ccms/nodejs": "workspace:*",
"@ccms/nukkit": "workspace:*",
"@ccms/plugin": "workspace:*",
"@ccms/polyfill": "workspace:*",
"@ccms/protocol": "workspace:*",
"@ccms/qrcode": "workspace:*",
"@ccms/sponge": "workspace:*",
"@ccms/websocket": "workspace:*"
}
}

View File

View File

@@ -0,0 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"baseUrl": "src",
"outDir": "dist"
}
}

View File

@@ -1 +0,0 @@
../../.npmignore

View File

@@ -1,6 +1,6 @@
{ {
"name": "@ccms/sponge", "name": "@ccms/sponge",
"version": "0.28.0-beta.3", "version": "0.28.0-beta.11",
"description": "MiaoScript sponge package", "description": "MiaoScript sponge package",
"keywords": [ "keywords": [
"miaoscript", "miaoscript",
@@ -12,21 +12,23 @@
"homepage": "https://github.com/circlecloud/ms.git", "homepage": "https://github.com/circlecloud/ms.git",
"license": "ISC", "license": "ISC",
"main": "dist/index.js", "main": "dist/index.js",
"files": [
"dist/**/*.js",
"dist/**/*.ts",
"dist/**/*.map"
],
"scripts": { "scripts": {
"clean": "rimraf dist", "clean": "rimraf dist",
"watch": "tsc --watch", "watch": "tsc --watch",
"build": "yarn clean && tsc", "build": "pnpm clean && tsc",
"test": "echo \"Error: run tests from root\" && exit 1" "test": "echo \"Error: run tests from root\" && exit 1"
}, },
"devDependencies": { "devDependencies": {
"@javatypes/sponge-api": "^0.0.3", "@javatypes/sponge-api": "^0.0.3"
"reflect-metadata": "^0.1.13",
"rimraf": "^4.1.2",
"typescript": "^4.9.5"
}, },
"dependencies": { "dependencies": {
"@ccms/api": "^0.28.0-beta.3", "@ccms/api": "workspace:*",
"@ccms/common": "^0.28.0-beta.3", "@ccms/common": "workspace:*",
"@ccms/container": "^0.28.0-beta.3" "@ccms/container": "workspace:*"
} }
} }

View File

@@ -1 +0,0 @@
../../.npmignore

View File

@@ -1,33 +1,35 @@
{ {
"name": "@ccms/websocket", "name": "@ccms/websocket",
"version": "0.28.0-beta.3", "version": "0.28.0-beta.11",
"description": "MiaoScript websocket package", "description": "MiaoScript websocket package",
"keywords": [ "keywords": [
"miaoscript", "miaoscript",
"minecraft", "minecraft",
"bukkit", "bukkit",
"sponge" "sponge"
], ],
"author": "MiaoWoo <admin@yumc.pw>", "author": "MiaoWoo <admin@yumc.pw>",
"homepage": "https://github.com/circlecloud/ms.git", "homepage": "https://github.com/circlecloud/ms.git",
"license": "ISC", "license": "ISC",
"main": "dist/index.js", "main": "dist/index.js",
"scripts": { "files": [
"clean": "rimraf dist", "dist/**/*.js",
"watch": "tsc --watch", "dist/**/*.ts",
"build": "yarn clean && tsc", "dist/**/*.map"
"test": "echo \"Error: run tests from root\" && exit 1" ],
}, "scripts": {
"dependencies": { "clean": "rimraf dist",
"@socket.io/component-emitter": "3.1.0", "watch": "tsc --watch",
"backo2": "^1.0.2", "build": "pnpm clean && tsc",
"parseuri": "^0.0.6" "test": "echo \"Error: run tests from root\" && exit 1"
}, },
"devDependencies": { "dependencies": {
"@ccms/nashorn": "^0.28.0-beta.3", "@ccms/container": "workspace:*",
"@javatypes/tomcat-websocket-api": "^0.0.3", "@socket.io/component-emitter": "3.1.0",
"reflect-metadata": "^0.1.13", "backo2": "^1.0.2",
"rimraf": "^4.1.2", "parseuri": "^0.0.6"
"typescript": "^4.9.5" },
} "devDependencies": {
"@javatypes/tomcat-websocket-api": "^0.0.3"
}
} }

View File

@@ -9,7 +9,7 @@ export class WebSocketManager {
constructor() { constructor() {
process.on('exit', () => { process.on('exit', () => {
for (const client of this.clients.values()) { for (const client of this.clients.values()) {
client.close(0, `client ${client.id} close connect`) client.close(1000, `client ${client.id} close connect due process exit.`)
} }
this.clients.clear() this.clients.clear()
}) })

View File

@@ -147,7 +147,7 @@ export class NettyWebSocket extends Transport {
})) }))
} }
abortHandshake(reason: Error): void { abortHandshake(reason: Error): void {
this.handler.abortHandshake(reason) if (this.handler) this.handler.abortHandshake(reason)
} }
getChannel() { getChannel() {
return this.channel return this.channel

View File

@@ -56,7 +56,8 @@ export abstract class Transport extends EventEmitter {
this.abortHandshake(new Error(msg)); this.abortHandshake(new Error(msg));
return; return;
} }
if (code != 1000 && (code < 3000 || code > 4999)) { // if socket is clean ignore code check
if (code != 1000 && (code < 3000 || code > 4999) && !wasClean) {
throw new Error(`The code must be either 1000, or between 3000 and 4999. ${code} is neither.`) throw new Error(`The code must be either 1000, or between 3000 and 4999. ${code} is neither.`)
} }
this.readyState = WebSocket.CLOSING this.readyState = WebSocket.CLOSING

View File

@@ -711,6 +711,7 @@ export class Socket extends Emitter<{}, {}, SocketReservedEvents> {
* @api private * @api private
*/ */
private resetPingTimeout() { private resetPingTimeout() {
// @ts-ignore
this.clearTimeoutFn(this.pingTimeoutTimer) this.clearTimeoutFn(this.pingTimeoutTimer)
this.pingTimeoutTimer = this.setTimeoutFn(() => { this.pingTimeoutTimer = this.setTimeoutFn(() => {
this.onClose("ping timeout") this.onClose("ping timeout")
@@ -919,6 +920,7 @@ export class Socket extends Emitter<{}, {}, SocketReservedEvents> {
) { ) {
debug('socket close with reason: "%s"', reason) debug('socket close with reason: "%s"', reason)
// @ts-ignore
// clear timers // clear timers
this.clearTimeoutFn(this.pingTimeoutTimer) this.clearTimeoutFn(this.pingTimeoutTimer)

4746
pnpm-lock.yaml generated Normal file

File diff suppressed because it is too large Load Diff

2
pnpm-workspace.yaml Normal file
View File

@@ -0,0 +1,2 @@
packages:
- "packages/*"

View File

@@ -1,8 +1,8 @@
#!/bin/bash #!/bin/bash
DISTTAG=${1:latest} DISTTAG=${1:beta}
for package in `ls packages`; do for package in `ls packages`; do
echo $package echo $package
pushd packages/$package pushd packages/$package
npm publish --tag ${DISTTAG} --access=public --registry https://registry.npmjs.org pnpm publish --tag ${DISTTAG} --access=public --registry https://registry.npmjs.org
popd popd
done done