Minor fixes
This commit is contained in:
@@ -18,7 +18,8 @@ async function installJava(mcVersion, customExec = null) {
|
||||
const installationPath = await sysinfo.determineInstallationPath(component, majorVersion, customExec)
|
||||
const requiredComponentDetails = await web.getJREComponentDetails(component, sysinfo.getPlatformKey())
|
||||
const requiredComponentManifest = await web.getJREComponentManifest(requiredComponentDetails[0].manifest.url)
|
||||
return await installer.downloadJavaComponent(requiredComponentManifest, installationPath)
|
||||
|
||||
return installer.downloadJavaComponent(requiredComponentManifest, installationPath)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@azures04/minecraft-java-manager",
|
||||
"version": "0.0.2",
|
||||
"version": "0.0.3",
|
||||
"description": "Node module to check if java is installed and install it",
|
||||
"keywords": [
|
||||
"java",
|
||||
|
||||
+17
-14
@@ -140,26 +140,28 @@ async function downloadSingleFile(fileEntry, outputRoot, onProgress) {
|
||||
}
|
||||
}
|
||||
|
||||
async function downloadJavaComponent(manifest, outputRoot, options) {
|
||||
function downloadJavaComponent(manifest, outputRoot, options) {
|
||||
const emitter = new EventEmitter()
|
||||
const concurrency = (options && options.concurrency) || 5
|
||||
|
||||
// On lance le traitement de manière asynchrone SANS l'attendre ici
|
||||
// setImmediate garantit que l'appelant a le temps d'attacher ses listeners
|
||||
setImmediate(async () => {
|
||||
try {
|
||||
const files = extractDownloadableFiles(manifest)
|
||||
const totalFiles = files.length
|
||||
const totalBytesExpected = files.reduce((sum, f) => { return sum + (f.size || 0) }, 0)
|
||||
const totalBytesExpected = files.reduce((sum, f) => sum + (f.size || 0), 0)
|
||||
|
||||
emitter.emit("start", {
|
||||
totalFiles: totalFiles,
|
||||
totalFiles,
|
||||
totalBytes: totalBytesExpected,
|
||||
outputRoot: outputRoot
|
||||
outputRoot
|
||||
})
|
||||
|
||||
let completedFiles = 0
|
||||
let failedFiles = 0
|
||||
let totalBytesDownloaded = 0
|
||||
const errors = []
|
||||
|
||||
const perFileProgress = {}
|
||||
|
||||
function reportGlobalProgress() {
|
||||
@@ -168,13 +170,13 @@ async function downloadJavaComponent(manifest, outputRoot, options) {
|
||||
}, 0)
|
||||
|
||||
emitter.emit("progress", {
|
||||
completedFiles: completedFiles,
|
||||
totalFiles: totalFiles,
|
||||
completedFiles,
|
||||
totalFiles,
|
||||
bytesDownloaded: currentTotal,
|
||||
totalBytes: totalBytesExpected,
|
||||
percent: totalBytesExpected > 0 ?
|
||||
Math.round((currentTotal / totalBytesExpected) * 100) :
|
||||
null
|
||||
percent: totalBytesExpected > 0
|
||||
? Math.round((currentTotal / totalBytesExpected) * 100)
|
||||
: null
|
||||
})
|
||||
}
|
||||
|
||||
@@ -225,11 +227,11 @@ async function downloadJavaComponent(manifest, outputRoot, options) {
|
||||
await Promise.all(workers)
|
||||
|
||||
emitter.emit("complete", {
|
||||
totalFiles: totalFiles,
|
||||
completedFiles: completedFiles,
|
||||
failedFiles: failedFiles,
|
||||
totalFiles,
|
||||
completedFiles,
|
||||
failedFiles,
|
||||
totalBytes: totalBytesDownloaded,
|
||||
errors: errors
|
||||
errors
|
||||
})
|
||||
|
||||
} catch (err) {
|
||||
@@ -238,6 +240,7 @@ async function downloadJavaComponent(manifest, outputRoot, options) {
|
||||
error: err
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
return { events: emitter, path: outputRoot }
|
||||
}
|
||||
|
||||
+4
-4
@@ -34,7 +34,7 @@ function getPlatformKey() {
|
||||
return candidate
|
||||
}
|
||||
|
||||
return targets["linux"] ?? null
|
||||
return null
|
||||
}
|
||||
|
||||
async function determineInstallationPath(component, majorVersion, customInstallPath = null) {
|
||||
@@ -51,9 +51,9 @@ async function determineInstallationPath(component, majorVersion, customInstallP
|
||||
case "win32":
|
||||
return path.join("C:", "Program files", "Java", component, majorVersion.toString())
|
||||
case "linux":
|
||||
return path.join("opt", "java", component, majorVersion)
|
||||
case "macos":
|
||||
return path.join("Library", "Java", "JavaVirtualMachines", `${component}-${majorVersion}`)
|
||||
return path.join("/", "opt", "java", component, majorVersion)
|
||||
case "darwin":
|
||||
return path.join(process.env.HOME || "/", "Library", "Java", "JavaVirtualMachines", `${component}-${majorVersion}`)
|
||||
default:
|
||||
throw new Error("Unsupported OS")
|
||||
}
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@ async function getJREComponentDetails(componentRequested, os) {
|
||||
const mainifestRequest = await fetch(config.allRuntimes.get())
|
||||
const manifest = await mainifestRequest.json()
|
||||
const component = manifest[os][componentRequested]
|
||||
if (typeof component != "object") {
|
||||
if (!typeof component == "object") {
|
||||
throw new Error("No JRE Component found")
|
||||
}
|
||||
return component
|
||||
|
||||
Reference in New Issue
Block a user