From 93f44e5a00199e4b28cd4a6f010401813b1b1cc8 Mon Sep 17 00:00:00 2001 From: MiaoWoo Date: Fri, 26 Mar 2021 16:17:13 +0800 Subject: [PATCH] refactor: rename ployfill to polyfill Signed-off-by: MiaoWoo --- packages/api/package.json | 2 +- packages/i18n/languages/en.yml | 4 ++-- packages/i18n/languages/zh_cn.yml | 4 ++-- packages/{ployfill => polyfill}/.npmignore | 0 packages/{ployfill => polyfill}/package.json | 5 +++-- packages/{ployfill => polyfill}/src/es5-ext.ts | 0 packages/{ployfill => polyfill}/src/index.ts | 6 +++--- packages/{ployfill => polyfill}/src/node-shim.ts | 8 ++++++-- packages/{ployfill => polyfill}/src/proxy.ts | 2 +- packages/{ployfill => polyfill}/src/task.ts | 0 packages/{ployfill => polyfill}/src/xml-http-request.ts | 0 packages/{ployfill => polyfill}/tsconfig.json | 0 12 files changed, 18 insertions(+), 13 deletions(-) rename packages/{ployfill => polyfill}/.npmignore (100%) rename packages/{ployfill => polyfill}/package.json (85%) rename packages/{ployfill => polyfill}/src/es5-ext.ts (100%) rename packages/{ployfill => polyfill}/src/index.ts (69%) rename packages/{ployfill => polyfill}/src/node-shim.ts (97%) rename packages/{ployfill => polyfill}/src/proxy.ts (96%) rename packages/{ployfill => polyfill}/src/task.ts (100%) rename packages/{ployfill => polyfill}/src/xml-http-request.ts (100%) rename packages/{ployfill => polyfill}/tsconfig.json (100%) diff --git a/packages/api/package.json b/packages/api/package.json index b5956f86..c105bf31 100644 --- a/packages/api/package.json +++ b/packages/api/package.json @@ -21,7 +21,7 @@ "dependencies": { "@ccms/common": "^0.13.0", "@ccms/container": "^0.13.0", - "@ccms/ployfill": "^0.13.0", + "@ccms/polyfill": "^0.13.0", "base64-js": "^1.5.1", "source-map-builder": "^0.0.7" }, diff --git a/packages/i18n/languages/en.yml b/packages/i18n/languages/en.yml index 4275073e..4b046e28 100644 --- a/packages/i18n/languages/en.yml +++ b/packages/i18n/languages/en.yml @@ -1,6 +1,6 @@ ms.i18n.completed: "Internationalization component initialization completed. Current Language: English" -ms.ployfill.initialize: "Initialization Java Nashorn ployfill. Please wait..." -ms.ployfill.completed: "Java Nashorn ployfill loading completed... Cost ({time}s)!" +ms.polyfill.initialize: "Initialization Java Nashorn polyfill. Please wait..." +ms.polyfill.completed: "Java Nashorn polyfill loading completed... Cost ({time}s)!" ms.core.ioc.initialize: "Initialization MiaoScript IOC Container {scope}/container. Please wait..." ms.core.ioc.completed: "MiaoScript IOC Container {scope}/container loading completed({time}s)!" diff --git a/packages/i18n/languages/zh_cn.yml b/packages/i18n/languages/zh_cn.yml index 0ae0ed73..38c64ada 100644 --- a/packages/i18n/languages/zh_cn.yml +++ b/packages/i18n/languages/zh_cn.yml @@ -1,6 +1,6 @@ ms.i18n.completed: "国际化组件 初始化完成 当前语言: 简体中文" -ms.ployfill.initialize: "加载 Java Nashorn 补丁. 请稍候..." -ms.ployfill.completed: "Java Nashorn 补丁 加载完成... 耗时 ({time}s)!" +ms.polyfill.initialize: "加载 Java Nashorn 补丁. 请稍候..." +ms.polyfill.completed: "Java Nashorn 补丁 加载完成... 耗时 ({time}s)!" ms.core.ioc.initialize: "初始化 MiaoScript IOC 容器 {scope}/container. 请稍候..." ms.core.ioc.completed: "MiaoScript IOC 容器 {scope}/container 加载完成 耗时({time}s)" diff --git a/packages/ployfill/.npmignore b/packages/polyfill/.npmignore similarity index 100% rename from packages/ployfill/.npmignore rename to packages/polyfill/.npmignore diff --git a/packages/ployfill/package.json b/packages/polyfill/package.json similarity index 85% rename from packages/ployfill/package.json rename to packages/polyfill/package.json index 9eb8e99b..e869ec4b 100644 --- a/packages/ployfill/package.json +++ b/packages/polyfill/package.json @@ -1,7 +1,7 @@ { - "name": "@ccms/ployfill", + "name": "@ccms/polyfill", "version": "0.13.0", - "description": "MiaoScript ployfill package", + "description": "MiaoScript polyfill package", "author": "MiaoWoo ", "homepage": "https://github.com/circlecloud/ms.git", "license": "ISC", @@ -16,6 +16,7 @@ "dependencies": { "@ccms/i18n": "^0.13.0", "@ccms/nodejs": "^0.13.0", + "@ccms/nashorn": "^0.13.0", "core-js": "^3.7.0" }, "devDependencies": { diff --git a/packages/ployfill/src/es5-ext.ts b/packages/polyfill/src/es5-ext.ts similarity index 100% rename from packages/ployfill/src/es5-ext.ts rename to packages/polyfill/src/es5-ext.ts diff --git a/packages/ployfill/src/index.ts b/packages/polyfill/src/index.ts similarity index 69% rename from packages/ployfill/src/index.ts rename to packages/polyfill/src/index.ts index 2d1fec8d..b1504c32 100644 --- a/packages/ployfill/src/index.ts +++ b/packages/polyfill/src/index.ts @@ -1,9 +1,9 @@ /// import '@ccms/nodejs' import i18n from '@ccms/i18n' -let ployfillStartTime = new Date().getTime() +let polyfillStartTime = new Date().getTime() i18n.initialize() -console.i18n("ms.ployfill.initialize") +console.i18n("ms.polyfill.initialize") import './es5-ext' import './node-shim' import 'core-js' @@ -12,4 +12,4 @@ process.on('exit', () => require.disable()) global.setGlobal('Proxy', require('./proxy').Proxy) global.setGlobal('XMLHttpRequest', require('./xml-http-request').XMLHttpRequest) global.setGlobal('Blob', require('blob-polyfill').Blob) -console.i18n("ms.ployfill.completed", { time: (new Date().getTime() - ployfillStartTime) / 1000 }) +console.i18n("ms.polyfill.completed", { time: (new Date().getTime() - polyfillStartTime) / 1000 }) diff --git a/packages/ployfill/src/node-shim.ts b/packages/polyfill/src/node-shim.ts similarity index 97% rename from packages/ployfill/src/node-shim.ts rename to packages/polyfill/src/node-shim.ts index cb5212f9..b2b312ea 100644 --- a/packages/ployfill/src/node-shim.ts +++ b/packages/polyfill/src/node-shim.ts @@ -2,7 +2,6 @@ import { EventEmitter } from 'events' const System = Java.type('java.lang.System') const Thread = Java.type('java.lang.Thread') -const Runnable = Java.type('java.lang.Runnable') const InterruptedException = Java.type('java.lang.InterruptedException') const ThreadGroup = Java.type("java.lang.ThreadGroup") const AtomicInteger = Java.type("java.util.concurrent.atomic.AtomicInteger") @@ -56,6 +55,10 @@ class Process extends EventEmitter { console.log(`process exit by code ${code}!`) this.emit('exit', code) } + + toString() { + return "[object process]" + } } class EventLoop { @@ -191,8 +194,9 @@ class EventLoop { } } global.setGlobal('process', new Process(), {}) +Object.defineProperty(process, require('core-js/es/symbol/to-string-tag'), { value: '[object process]' }) const eventLoop = new EventLoop() -global.setGlobal('eventLoop', eventLoop, {}) +Object.defineProperty(process, 'eventLoop', { value: eventLoop }) eventLoop.startEventLoop() global.setGlobal('queueMicrotask', (func: any) => microTaskPool.execute(func), {}) global.setGlobal('setTimeout', eventLoop.setTimeout.bind(eventLoop), {}) diff --git a/packages/ployfill/src/proxy.ts b/packages/polyfill/src/proxy.ts similarity index 96% rename from packages/ployfill/src/proxy.ts rename to packages/polyfill/src/proxy.ts index 32b99f44..52b02890 100644 --- a/packages/ployfill/src/proxy.ts +++ b/packages/polyfill/src/proxy.ts @@ -1,4 +1,4 @@ -import { ProxyHandle } from '@ccms/nashorn' +import type { ProxyHandle } from '@ccms/nashorn' // Nashorn JSAdapter See https://wiki.openjdk.java.net/display/Nashorn/Nashorn+extensions#Nashornextensions-JSAdapterconstructor let createProxy = eval(` diff --git a/packages/ployfill/src/task.ts b/packages/polyfill/src/task.ts similarity index 100% rename from packages/ployfill/src/task.ts rename to packages/polyfill/src/task.ts diff --git a/packages/ployfill/src/xml-http-request.ts b/packages/polyfill/src/xml-http-request.ts similarity index 100% rename from packages/ployfill/src/xml-http-request.ts rename to packages/polyfill/src/xml-http-request.ts diff --git a/packages/ployfill/tsconfig.json b/packages/polyfill/tsconfig.json similarity index 100% rename from packages/ployfill/tsconfig.json rename to packages/polyfill/tsconfig.json