Skip to content

Commit 5480b57

Browse files
committed
fix: bundle flare version comparison
1 parent c462e03 commit 5480b57

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

scripts/lspArtifact.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ interface ManifestVersion {
2727
interface Manifest {
2828
versions: ManifestVersion[]
2929
}
30+
3031
async function verifyFileHash(filePath: string, expectedHash: string): Promise<boolean> {
3132
return new Promise((resolve, reject) => {
3233
const hash = crypto.createHash('sha384')
@@ -53,6 +54,21 @@ async function ensureDirectoryExists(dirPath: string): Promise<void> {
5354
}
5455
}
5556

57+
function compareVersions(v1: string, v2: string): number {
58+
const parts1 = v1.split('.').map(Number)
59+
const parts2 = v2.split('.').map(Number)
60+
61+
for (let i = 0; i < Math.max(parts1.length, parts2.length); i++) {
62+
const part1 = parts1[i] || 0
63+
const part2 = parts2[i] || 0
64+
65+
if (part1 > part2) return 1
66+
if (part1 < part2) return -1
67+
}
68+
69+
return 0
70+
}
71+
5672
export async function downloadLanguageServer(): Promise<void> {
5773
const tempDir = path.join(os.tmpdir(), 'amazonq-download-temp')
5874
const resourcesDir = path.join(__dirname, '../packages/amazonq/resources/language-server')
@@ -86,7 +102,7 @@ export async function downloadLanguageServer(): Promise<void> {
86102

87103
const latestVersion = manifest.versions
88104
.filter((v) => !v.isDelisted)
89-
.sort((a, b) => b.serverVersion.localeCompare(a.serverVersion))[0]
105+
.sort((a, b) => compareVersions(b.serverVersion, a.serverVersion))[0]
90106

91107
if (!latestVersion) {
92108
throw new Error('No valid version found in manifest')

0 commit comments

Comments
 (0)