fix: new ts version build error

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
MiaoWoo 2021-03-27 11:35:54 +08:00
parent 4f41357953
commit bf34552321
8 changed files with 13 additions and 148 deletions

View File

@ -20,6 +20,7 @@ enum LogLevel {
export class MiaoScriptConsole implements Console {
Console: NodeJS.ConsoleConstructor
memory: any
private static sourceMaps: { [key: string]: SourceMapBuilder } = {}
private static sourceFileMaps: { [key: string]: string } = {}
@ -195,6 +196,9 @@ export class MiaoScriptConsole implements Console {
dirxml(...data: any[]): void {
throw new Error("Method not implemented.")
}
exception(message?: string, ...optionalParams: any[]): void {
throw new Error('Method not implemented.')
}
group(...label: any[]): void {
throw new Error("Method not implemented.")
}

View File

@ -25,6 +25,7 @@
"minecraft-protocol": "^1.24.1"
},
"devDependencies": {
"@types/node": "^14.14.37",
"rimraf": "^3.0.2",
"typescript": "^4.2.3"
}

View File

@ -23,7 +23,7 @@ interface RequestConfig {
}
function request(config: RequestConfig) {
// @ts-ignore
// @ts-ignore XMLHttpRequest class only exist nashorn polyfill
let xhr = new XMLHttpRequest()
xhr.open(config.method, config.url, false)
for (const header in config.headers) {
@ -44,6 +44,7 @@ function request(config: RequestConfig) {
if (xhr.getResponseHeader("Content-Type").indexOf('application/json') != -1) {
xhr.responseType = "json"
}
// @ts-ignore get only exist nashorn polyfill
return xhr.get()
}

View File

@ -50,7 +50,7 @@ export class Translate {
readYamlFile(dir: string, name: string) {
let langFile = this.concat(dir, 'languages', name + '.yml')
return this.exists(langFile) && yaml.safeLoad(base.read(langFile))
return this.exists(langFile) && yaml.load(base.read(langFile))
}
concat(...args: string[]) {

View File

@ -13,10 +13,10 @@ export interface PluginConfigLoader {
export class YamlPluginConfig implements PluginConfigLoader {
load(content: string) {
return yaml.safeLoad(content)
return yaml.load(content)
}
dump(variable: any): string {
return yaml.safeDump(variable, { skipInvalid: true, lineWidth: 120 })
return yaml.dump(variable, { skipInvalid: true, lineWidth: 120 })
}
}

View File

@ -15,12 +15,11 @@
},
"dependencies": {
"@ccms/i18n": "^0.14.0",
"@ccms/nashorn": "^0.14.0",
"@ccms/nodejs": "^0.14.0",
"core-js": "^3.9.1"
},
"devDependencies": {
"@ccms/nashorn": "^0.13.0",
"@ccms/nashorn": "^0.14.0",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"typescript": "^4.2.3"

View File

@ -1,141 +0,0 @@
(function nashornEventLoopMain(context) {
'use strict';
var Thread = Java.type('java.lang.Thread');
var Phaser = Java.type('java.util.concurrent.Phaser');
var ArrayDeque = Java.type('java.util.ArrayDeque');
var HashMap = Java.type('java.util.HashMap');
var TimeUnit = Java.type("java.util.concurrent.TimeUnit");
var Runnable = Java.type('java.lang.Runnable');
var globalTimerId;
var timerMap;
var eventLoop;
var phaser = new Phaser();
// __NASHORN_POLYFILL_TIMER__ type is ScheduledExecutorService
var scheduler = context.__NASHORN_POLYFILL_TIMER__;
resetEventLoop();
// console.log('main javasript thread ' + Thread.currentThread().getName());
function resetEventLoop() {
globalTimerId = 1;
if (timerMap) {
timerMap.forEach(function(key, value) {
value.cancel(true);
})
}
timerMap = new HashMap();
eventLoop = new ArrayDeque();
}
function waitForMessages() {
phaser.register();
var wait = !(eventLoop.size() === 0);
phaser.arriveAndDeregister();
return wait;
}
function processNextMessages() {
var remaining = 1;
while (remaining) {
phaser.register();
var message = eventLoop.removeFirst();
remaining = eventLoop.size();
phaser.arriveAndDeregister();
var fn = message.fn;
var args = message.args;
try {
fn.apply(context, args);
} catch (e) {
console.trace(e);
console.trace(fn);
console.trace(args);
}
}
}
context.nashornEventLoop = {
process: function() {
while (waitForMessages()) {
processNextMessages()
}
},
reset: resetEventLoop
};
function createRunnable(fn, timerId, args, repeated) {
return new Runnable({
run: function() {
try {
var phase = phaser.register();
eventLoop.addLast({
fn: fn,
args: args
});
} catch (e) {
console.trace(e);
} finally {
if (!repeated) timerMap.remove(timerId);
phaser.arriveAndDeregister();
}
}
})
}
var setTimeout = function(fn, millis /* [, args...] */) {
var args = [].slice.call(arguments, 2, arguments.length);
var timerId = globalTimerId++;
var runnable = createRunnable(fn, timerId, args, false);
var task = scheduler.schedule(runnable, millis, TimeUnit.MILLISECONDS);
timerMap.put(timerId, task);
return timerId;
};
var setImmediate = function(fn /* [, args...] */) {
var args = [].slice.call(arguments, 1, arguments.length);
// @ts-ignore
return setTimeout(fn, 0, args);
}
var clearImmediate = function(timerId) {
clearTimeout(timerId);
}
var clearTimeout = function(timerId) {
var task = timerMap.get(timerId);
if (task) {
task.cancel(true);
timerMap.remove(timerId);
}
};
var setInterval = function(fn, delay /* [, args...] */) {
var args = [].slice.call(arguments, 2, arguments.length);
var timerId = globalTimerId++;
var runnable = createRunnable(fn, timerId, args, true);
var task = scheduler.scheduleWithFixedDelay(runnable, delay, delay, TimeUnit.MILLISECONDS);
timerMap.put(timerId, task);
return timerId;
};
var clearInterval = function(timerId) {
clearTimeout(timerId);
};
context.setTimeout = setTimeout;
context.clearTimeout = clearTimeout;
context.setImmediate = setImmediate;
context.clearImmediate = clearImmediate;
context.setInterval = setInterval;
context.clearInterval = clearInterval;
// @ts-ignore
})(typeof global !== "undefined" && global || typeof self !== "undefined" && self || this);

View File

@ -5,6 +5,7 @@
"outDir": "dist",
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"strict": true,
"strictNullChecks": false,
"importHelpers": true,