fix: windows load error

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
MiaoWoo 2021-03-26 18:40:57 +08:00
parent 1cb4c05efd
commit 48306b64c4
3 changed files with 29 additions and 17 deletions

View File

@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>pw.yumc</groupId> <groupId>pw.yumc</groupId>
<artifactId>MiaoScript</artifactId> <artifactId>MiaoScript</artifactId>
<version>0.11.0</version> <version>0.11.1</version>
<developers> <developers>
<developer> <developer>
<id>502647092</id> <id>502647092</id>

View File

@ -57,12 +57,12 @@ var global = this;
global.start = function (future) { global.start = function (future) {
if (!future.isDone()) { if (!future.isDone()) {
logger.info("Waiting MiaoScript booted...") log.info("Waiting MiaoScript booted...")
future.get() future.get()
} }
logger.info("MiaoScript booted starting...") log.info("MiaoScript booted starting...")
global.engineDisableImpl = require(java.lang.System.getenv("MS_NODE_CORE_MODULE") || (global.scope + '/core')).default || function () { global.engineDisableImpl = require(java.lang.System.getenv("MS_NODE_CORE_MODULE") || (global.scope + '/core')).default || function () {
logger.info('Error: abnormal Initialization MiaoScript Engine. Skip disable step...') log.info('Error: abnormal Initialization MiaoScript Engine. Skip disable step...')
} }
} }

View File

@ -52,6 +52,10 @@
// @ts-ignore // @ts-ignore
var URL = Java.type('java.net.URL') var URL = Java.type('java.net.URL')
// @ts-ignore // @ts-ignore
var Thread = Java.type('java.net.URL')
// @ts-ignore
var FutureTask = Java.type('java.util.concurrent.FutureTask')
// @ts-ignore
var JavaString = Java.type('java.lang.String') var JavaString = Java.type('java.lang.String')
var separatorChar = File.separatorChar var separatorChar = File.separatorChar
@ -301,15 +305,19 @@
var info = fetchPackageInfo(module_name) var info = fetchPackageInfo(module_name)
var url = info.versions[ModulesVersionLock[module_name] || info['dist-tags']['latest']].dist.tarball var url = info.versions[ModulesVersionLock[module_name] || info['dist-tags']['latest']].dist.tarball
console.log('fetch node_module ' + module_name + ' from ' + url + ' waiting...') console.log('fetch node_module ' + module_name + ' from ' + url + ' waiting...')
var tis = new TarInputStream(new BufferedInputStream(new GZIPInputStream(new URL(url).openStream()))) var future = new FutureTask(function () {
// @ts-ignore var tis = new TarInputStream(new BufferedInputStream(new GZIPInputStream(new URL(url).openStream())))
var entry // @ts-ignore
while ((entry = tis.getNextEntry()) != null) { var entry
var targetPath = Paths.get(target + separatorChar + entry.getName().substring(8)) while ((entry = tis.getNextEntry()) != null) {
targetPath.toFile().getParentFile().mkdirs() var targetPath = Paths.get(target + separatorChar + entry.getName().substring(8))
Files.copy(tis, targetPath, StandardCopyOption.REPLACE_EXISTING) targetPath.toFile().getParentFile().mkdirs()
} Files.copy(tis, targetPath, StandardCopyOption.REPLACE_EXISTING)
return name }
return name
})
new Thread(future, "MiaoScript download thread").start()
return future.get()
} }
/** /**
@ -327,10 +335,14 @@
} }
function fetchContent(url, name) { function fetchContent(url, name) {
var tempFile = Files.createTempFile(name.replace('/', '_'), '.json') var future = new FutureTask(function () {
Files.copy(new URL(url).openStream(), tempFile, StandardCopyOption.REPLACE_EXISTING) var tempFile = Files.createTempFile(name.replace('/', '_'), '.json')
tempFile.toFile().deleteOnExit() Files.copy(new URL(url).openStream(), tempFile, StandardCopyOption.REPLACE_EXISTING)
return new JavaString(Files.readAllBytes(tempFile), 'UTF-8') tempFile.toFile().deleteOnExit()
return new JavaString(Files.readAllBytes(tempFile), 'UTF-8')
})
new Thread(future, "MiaoScript require thread").start()
return future.get()
} }
var lastModule = '' var lastModule = ''