Skip to content

Commit 84a969c

Browse files
cleanup some duplicate code paths for getting latest editor release version
1 parent 4c4ee7b commit 84a969c

1 file changed

Lines changed: 8 additions & 25 deletions

File tree

src/unity-hub.ts

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ export class UnityHub {
247247
throw new Error(`Failed to execute Unity Hub: [${exitCode}] ${errorMessage}`);
248248
}
249249
}
250+
250251
output = output.split('\n')
251252
.filter(line => line.trim().length > 0)
252253
.filter(line => !ignoredLines.some(ignored => line.includes(ignored)))
@@ -518,7 +519,7 @@ chmod -R 777 "$hubPath"`]);
518519
if (!resolvedVersion.isLegacy()) {
519520
try {
520521
if (!resolvedVersion.isFullyQualified()) {
521-
const releases = await this.getLatestHubReleases();
522+
const releases = await this.ListAvailableReleases();
522523
resolvedVersion = resolvedVersion.findMatch(releases);
523524
}
524525

@@ -610,7 +611,7 @@ chmod -R 777 "$hubPath"`]);
610611
public async ListInstalledEditors(): Promise<string[]> {
611612
const output = await this.Exec(['editors', '-i']);
612613
return output.split('\n')
613-
.filter(line => line.trim().length > 0)
614+
.filter(line => /installed at/.test(line))
614615
.map(line => line.trim());
615616
}
616617

@@ -620,8 +621,9 @@ chmod -R 777 "$hubPath"`]);
620621
*/
621622
public async ListAvailableReleases(): Promise<string[]> {
622623
const output = await this.Exec(['editors', '--releases']);
624+
// filter out version lines only 2021.3.45f2 (may include installed path following version)
623625
return output.split('\n')
624-
.filter(line => line.trim().length > 0)
626+
.filter(line => /^\d{1,4}\.\d+\.\d+[abcfpx]?\d*/.test(line.trim()))
625627
.map(line => line.trim());
626628
}
627629

@@ -723,25 +725,6 @@ chmod -R 777 "$hubPath"`]);
723725
return editorPath;
724726
}
725727

726-
private async getLatestHubReleases(): Promise<string[]> {
727-
// Normalize output to bare version strings (e.g., 2022.3.62f1)
728-
// Unity Hub can return lines like:
729-
// - "6000.0.56f1 (Apple silicon)"
730-
// - "2022.3.62f1 installed at C:\\..."
731-
// - "2022.3.62f1, installed at ..." (older format)
732-
// We extract the first version token and discard the rest.
733-
const versionRegex = /(\d{1,4})\.(\d+)\.(\d+)([abcfpx])(\d+)/;
734-
return (await this.Exec([`editors`, `--releases`]))
735-
.split('\n')
736-
.map(line => line.trim())
737-
.filter(line => line.length > 0)
738-
.map(line => {
739-
const match = line.match(versionRegex);
740-
return match ? match[0] : '';
741-
})
742-
.filter(v => v.length > 0);
743-
}
744-
745728
/**
746729
* Patches the Bee Backend for Unity Linux Editor.
747730
* https://discussions.unity.com/t/linux-editor-stuck-on-loading-because-of-bee-backend-w-workaround/854480
@@ -783,9 +766,9 @@ done
783766
if (fullUnityVersionPattern.test(unityVersion.version)) {
784767
version = unityVersion.version;
785768
} else {
786-
const mm = unityVersion.version.match(/^(\d{1,4})(?:\.(\d+))?/);
787-
if (mm) {
788-
version = mm[2] ? `${mm[1]}.${mm[2]}` : mm[1]!;
769+
const match = unityVersion.version.match(/^(\d{1,4})(?:\.(\d+))?/);
770+
if (match) {
771+
version = match[2] ? `${match[1]}.${match[2]}` : match[1]!;
789772
} else {
790773
version = unityVersion.version.split('.')[0]!;
791774
}

0 commit comments

Comments
 (0)