Skip to content

Commit 2933d57

Browse files
committed
fix: expose post postProcess task
1 parent a034fba commit 2933d57

File tree

1 file changed

+48
-30
lines changed

1 file changed

+48
-30
lines changed

packages/installer/minecraft.ts

Lines changed: 48 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -500,25 +500,24 @@ export function resolveProcessors(side: "client" | "server", installProfile: Ins
500500
}
501501

502502
/**
503-
* Install by install profile. The install profile usually contains some preprocess should run before installing dependencies.
503+
* Post process the post processors from `InstallProfile`.
504504
*
505-
* @param installProfile The install profile
505+
* @param processors The processor info
506506
* @param minecraft The minecraft location
507-
* @param options The options to install
507+
* @param java The java executable path
508508
*/
509-
export function installByProfile(installProfile: InstallProfile, minecraft: MinecraftLocation, options: InstallProfileOption = {}) {
510-
return installByProfileTask(installProfile, minecraft, options).execute().wait();
509+
export function postProcess(processors: InstallProfile["processors"], minecraft: MinecraftFolder, java: string) {
510+
return postProcessTask(processors, minecraft, java).execute().wait();
511511
}
512512

513513
/**
514-
* Install by install profile. The install profile usually contains some preprocess should run before installing dependencies.
514+
* Post process the post processors from `InstallProfile`.
515515
*
516-
* @param installProfile The install profile
516+
* @param processors The processor info
517517
* @param minecraft The minecraft location
518-
* @param options The options to install
518+
* @param java The java executable path
519519
*/
520-
export function installByProfileTask(installProfile: InstallProfile, minecraft: MinecraftLocation, options: InstallProfileOption = {}) {
521-
normailzeDownloader(options);
520+
export function postProcessTask(processors: InstallProfile["processors"], minecraft: MinecraftFolder, java: string) {
522521
async function findMainClass(lib: string) {
523522
const zip = await open(lib, { lazyEntries: true });
524523
const [manifest] = await zip.filterEntries(["META-INF/MANIFEST.MF"]);
@@ -569,29 +568,48 @@ export function installByProfileTask(installProfile: InstallProfile, minecraft:
569568
throw new Error("Fail to process post processing since its validation failed.");
570569
}
571570
}
572-
function postProcessingTask(minecraft: MinecraftFolder, processors: InstallProfile["processors"], java: string, failImmediately: boolean) {
573-
return task("postProcessing", async function postProcessing(ctx) {
574-
if (!processors || processors.length === 0) {
575-
return;
576-
}
571+
return task("postProcessing", async function postProcessing(ctx) {
572+
if (!processors || processors.length === 0) {
573+
return;
574+
}
577575

578-
ctx.update(0, processors.length);
579-
let done = 0;
580-
for (let proc of processors) {
581-
try {
582-
await postProcess(minecraft, proc, java);
583-
} catch (e) {
584-
e = e || new Error(`Fail to post porcess ${proc.jar}: ${proc.args.join(" ")}, ${proc.classpath.join(" ")}`);
585-
throw e;
586-
}
587-
ctx.update(done += 1, processors.length);
576+
ctx.update(0, processors.length);
577+
let done = 0;
578+
for (let proc of processors) {
579+
try {
580+
await postProcess(minecraft, proc, java);
581+
} catch (e) {
582+
e = e || new Error(`Fail to post porcess ${proc.jar}: ${proc.args.join(" ")}, ${proc.classpath.join(" ")}`);
583+
throw e;
588584
}
585+
ctx.update(done += 1, processors.length);
586+
}
589587

590-
done += 1;
591-
ctx.update(done, processors.length);
592-
});
593-
}
588+
done += 1;
589+
ctx.update(done, processors.length);
590+
});
591+
}
594592

593+
/**
594+
* Install by install profile. The install profile usually contains some preprocess should run before installing dependencies.
595+
*
596+
* @param installProfile The install profile
597+
* @param minecraft The minecraft location
598+
* @param options The options to install
599+
*/
600+
export function installByProfile(installProfile: InstallProfile, minecraft: MinecraftLocation, options: InstallProfileOption = {}) {
601+
return installByProfileTask(installProfile, minecraft, options).execute().wait();
602+
}
603+
604+
/**
605+
* Install by install profile. The install profile usually contains some preprocess should run before installing dependencies.
606+
*
607+
* @param installProfile The install profile
608+
* @param minecraft The minecraft location
609+
* @param options The options to install
610+
*/
611+
export function installByProfileTask(installProfile: InstallProfile, minecraft: MinecraftLocation, options: InstallProfileOption = {}) {
612+
normailzeDownloader(options);
595613
return task("install", async function install(context: Task.Context) {
596614
const minecraftFolder = MinecraftFolder.from(minecraft);
597615
const java = options.java || "java";
@@ -602,7 +620,7 @@ export function installByProfileTask(installProfile: InstallProfile, minecraft:
602620
let libraries = VersionJson.resolveLibraries([...installProfile.libraries, ...versionJson.libraries]);
603621

604622
await context.execute(installResolvedLibrariesTask(libraries, minecraft, options), 50);
605-
await context.execute(postProcessingTask(minecraftFolder, processor, java, options.throwErrorImmediately || false), 50);
623+
await context.execute(postProcessTask(processor, minecraftFolder, java), 50);
606624
});
607625
}
608626

0 commit comments

Comments
 (0)