feat: use pnpm & lock core-js shim

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

View File

@ -1,6 +1,6 @@
{ {
"version": "0.28.0-beta.3", "version": "0.28.0-beta.3",
"npmClient": "yarn", "npmClient": "pnpm",
"packages": [ "packages": [
"packages/*" "packages/*"
], ],

View File

@ -10,7 +10,7 @@
"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",
@ -23,6 +23,13 @@
"packages/*" "packages/*"
], ],
"devDependencies": { "devDependencies": {
"lerna": "^7.1.4" "lerna": "^7.2.0",
"reflect-metadata": "^0.1.13",
"rimraf": "^5.0.5",
"typescript": "^5.2.2",
"tslib": "^2.6.2",
"@types/node": "^20.8.8",
"@ccms/nashorn": "^0.28.0-beta.3",
"@javatypes/jdk": "^0.0.3"
} }
} }

View File

@ -18,10 +18,11 @@
"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/common": "^0.28.0-beta.3", "@ccms/common": "^0.28.0-beta.3",
"@ccms/container": "^0.28.0-beta.3", "@ccms/container": "^0.28.0-beta.3",
"@ccms/polyfill": "^0.28.0-beta.3", "@ccms/polyfill": "^0.28.0-beta.3",
@ -29,9 +30,6 @@
"source-map-builder": "^0.0.7" "source-map-builder": "^0.0.7"
}, },
"devDependencies": { "devDependencies": {
"@types/base64-js": "^1.3.0", "@types/base64-js": "^1.3.0"
"reflect-metadata": "^0.1.13",
"rimraf": "^4.4.1",
"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

@ -34,9 +34,7 @@ export namespace task {
protected pluginDisable(plugin: plugin.Plugin) { protected pluginDisable(plugin: plugin.Plugin) {
if (this.pluginCacheTasks.has(plugin.description.name)) { if (this.pluginCacheTasks.has(plugin.description.name)) {
this.pluginCacheTasks.get(plugin.description.name).forEach((task) => { this.pluginCacheTasks.get(plugin.description.name).forEach((task) => task.cancel())
task.cancel()
})
this.pluginCacheTasks.delete(plugin.description.name) this.pluginCacheTasks.delete(plugin.description.name)
} }
} }
@ -151,8 +149,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()
@ -181,7 +180,7 @@ export namespace task {
* *
* @param args * @param args
*/ */
protected abstract submit0(...args: any[]): any protected abstract submit0(...args: any[]): Cancelable
/** /**
* *
*/ */

View File

@ -18,14 +18,11 @@
"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.4.1",
"typescript": "^4.9.5"
}, },
"dependencies": { "dependencies": {
"@ccms/api": "^0.28.0-beta.3", "@ccms/api": "^0.28.0-beta.3",

View File

@ -18,14 +18,11 @@
"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.4.1",
"typescript": "^4.9.5"
}, },
"dependencies": { "dependencies": {
"@ccms/api": "^0.28.0-beta.3", "@ccms/api": "^0.28.0-beta.3",

View File

@ -18,15 +18,12 @@
"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": "^0.28.0-beta.3",
"@javatypes/jdk": "^0.0.3", "@javatypes/jdk": "^0.0.3"
"reflect-metadata": "^0.1.13",
"rimraf": "^4.4.1",
"typescript": "^4.9.5"
}, },
"gitHead": "562e2d00175c9d3a99c8b672aa07e6d92706a027" "gitHead": "562e2d00175c9d3a99c8b672aa07e6d92706a027"
} }

View File

@ -18,12 +18,27 @@
"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": {
"reflect-metadata": "^0.1.13", "@ccms/api": "^0.28.0-beta.3",
"rimraf": "^4.4.1", "@ccms/bukkit": "^0.28.0-beta.3",
"typescript": "^4.9.5" "@ccms/bungee": "^0.28.0-beta.3",
"@ccms/common": "^0.28.0-beta.3",
"@ccms/container": "^0.28.0-beta.3",
"@ccms/core": "^0.28.0-beta.3",
"@ccms/database": "^0.28.0-beta.3",
"@ccms/i18n": "^0.28.0-beta.3",
"@ccms/molang": "^0.28.0-beta.3",
"@ccms/nashorn": "^0.28.0-beta.3",
"@ccms/nodejs": "^0.28.0-beta.3",
"@ccms/nukkit": "^0.28.0-beta.3",
"@ccms/plugin": "^0.28.0-beta.3",
"@ccms/polyfill": "^0.28.0-beta.3",
"@ccms/protocol": "^0.28.0-beta.3",
"@ccms/qrcode": "^0.28.0-beta.3",
"@ccms/sponge": "^0.28.0-beta.3",
"@ccms/websocket": "^0.28.0-beta.3"
} }
} }

View File

@ -18,14 +18,11 @@
"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": "^0.28.0-beta.3"
"reflect-metadata": "^0.1.13",
"rimraf": "^4.4.1",
"typescript": "^4.9.5"
}, },
"dependencies": { "dependencies": {
"inversify": "^6.0.1", "inversify": "^6.0.1",

View File

@ -17,18 +17,21 @@
], ],
"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.5",
"rimraf": "^4.1.2", "rollup": "^2.79.1",
"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": "^0.28.0-beta.3",
"@ccms/container": "^0.28.0-beta.3" "@ccms/common": "^0.28.0-beta.3",
"@ccms/container": "^0.28.0-beta.3",
"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

@ -18,14 +18,11 @@
"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.4.1",
"typescript": "^4.9.5"
}, },
"dependencies": { "dependencies": {
"@ccms/api": "^0.28.0-beta.3", "@ccms/api": "^0.28.0-beta.3",

View File

@ -19,15 +19,12 @@
"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": "^0.28.0-beta.3",
"@types/js-yaml": "^4.0.5", "@types/js-yaml": "^4.0.5"
"reflect-metadata": "^0.1.13",
"rimraf": "^4.4.1",
"typescript": "^4.9.5"
}, },
"dependencies": { "dependencies": {
"js-yaml": "^4.1.0" "js-yaml": "^4.1.0"

View File

@ -10,7 +10,7 @@
"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": {
@ -24,9 +24,6 @@
}, },
"homepage": "https://github.com/solvedDev/MoLang#readme", "homepage": "https://github.com/solvedDev/MoLang#readme",
"devDependencies": { "devDependencies": {
"@types/node": "^18.17.15", "@types/node": "^18.17.15"
"rimraf": "^4.4.1",
"tslib": "^2.6.2",
"typescript": "^4.9.5"
} }
} }

View File

@ -19,12 +19,8 @@
"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": {}
"reflect-metadata": "^0.1.13",
"rimraf": "^4.4.1",
"typescript": "^4.9.5"
}
} }

View File

@ -18,15 +18,11 @@
"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": "^0.28.0-beta.3"
"reflect-metadata": "^0.1.13",
"rimraf": "^4.4.1",
"tslib": "^2.6.2",
"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

@ -18,14 +18,11 @@
"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.4.1",
"typescript": "^4.9.5"
}, },
"dependencies": { "dependencies": {
"@ccms/api": "^0.28.0-beta.3", "@ccms/api": "^0.28.0-beta.3",

View File

@ -18,15 +18,12 @@
"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.2", "@types/crypto-js": "^4.1.2",
"@types/js-yaml": "^4.0.5", "@types/js-yaml": "^4.0.5"
"reflect-metadata": "^0.1.13",
"rimraf": "^4.4.1",
"typescript": "^4.9.5"
}, },
"dependencies": { "dependencies": {
"@ccms/api": "^0.28.0-beta.3", "@ccms/api": "^0.28.0-beta.3",

View File

@ -13,7 +13,7 @@
"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": {
@ -22,9 +22,6 @@
"core-js": "^3.32.2" "core-js": "^3.32.2"
}, },
"devDependencies": { "devDependencies": {
"@ccms/nashorn": "^0.28.0-beta.3", "@ccms/nashorn": "^0.28.0-beta.3"
"reflect-metadata": "^0.1.13",
"rimraf": "^4.4.1",
"typescript": "^4.9.5"
} }
} }

View File

@ -0,0 +1,239 @@
'use strict';
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

@ -45,11 +45,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 +69,30 @@ 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) { try {
try { callback(args)
super.emit('error', origin) } catch (origin: any) {
} catch (error: any) { try {
console.ex(origin) super.emit('error', origin)
console.ex(error) } 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) {
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 +134,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 {
@ -174,7 +185,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)
}) })
} }
@ -261,7 +272,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

@ -19,12 +19,8 @@
"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": {}
"reflect-metadata": "^0.1.13",
"rimraf": "^4.4.1",
"typescript": "^4.9.5"
}
} }

View File

@ -18,12 +18,8 @@
"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": {}
"reflect-metadata": "^0.1.13",
"rimraf": "^4.4.1",
"typescript": "^4.9.5"
}
} }

View File

@ -18,14 +18,11 @@
"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.4.1",
"typescript": "^4.9.5"
}, },
"dependencies": { "dependencies": {
"@ccms/api": "^0.28.0-beta.3", "@ccms/api": "^0.28.0-beta.3",

View File

@ -18,7 +18,7 @@
"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": {
@ -28,9 +28,6 @@
}, },
"devDependencies": { "devDependencies": {
"@ccms/nashorn": "^0.28.0-beta.3", "@ccms/nashorn": "^0.28.0-beta.3",
"@javatypes/tomcat-websocket-api": "^0.0.3", "@javatypes/tomcat-websocket-api": "^0.0.3"
"reflect-metadata": "^0.1.13",
"rimraf": "^4.4.1",
"typescript": "^4.9.5"
} }
} }

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

@ -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)

2
pnpm-workspace.yaml Normal file
View File

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