diff --git a/plugins.test.ts b/plugins.test.ts index 8587077..0ac751f 100644 --- a/plugins.test.ts +++ b/plugins.test.ts @@ -22,11 +22,12 @@ Deno.test("tryResolveUserLatestJson", async () => { { const result = await getValidResultForUrl("https://plugins.dprint.dev/dprint/typescript/latest.json"); const releaseInfo = await getLatestReleaseInfo("dprint", "dprint-plugin-typescript"); + assertEquals(releaseInfo?.checksum?.length, 64); assertEquals(result, { schemaVersion: 1, url: `https://plugins.dprint.dev/typescript-${releaseInfo!.tagName}.wasm`, version: releaseInfo!.tagName, - checksum: undefined, + checksum: releaseInfo!.checksum, }); } // dprint repo full name @@ -35,11 +36,12 @@ Deno.test("tryResolveUserLatestJson", async () => { "https://plugins.dprint.dev/dprint/dprint-plugin-typescript/latest.json", ); const releaseInfo = await getLatestReleaseInfo("dprint", "dprint-plugin-typescript"); + assertEquals(releaseInfo?.checksum?.length, 64); assertEquals(result, { schemaVersion: 1, url: `https://plugins.dprint.dev/typescript-${releaseInfo!.tagName}.wasm`, version: releaseInfo!.tagName, - checksum: undefined, + checksum: releaseInfo!.checksum, }); } // non-dprint repo @@ -50,7 +52,7 @@ Deno.test("tryResolveUserLatestJson", async () => { schemaVersion: 1, url: `https://plugins.dprint.dev/malobre/vue-${releaseInfo!.tagName}.wasm`, version: releaseInfo!.tagName.replace(/^v/, ""), - checksum: undefined, + checksum: releaseInfo!.checksum, }); } // non-dprint repo full name @@ -61,7 +63,7 @@ Deno.test("tryResolveUserLatestJson", async () => { schemaVersion: 1, url: `https://plugins.dprint.dev/malobre/vue-${releaseInfo!.tagName}.wasm`, version: releaseInfo!.tagName.replace(/^v/, ""), - checksum: undefined, + checksum: releaseInfo!.checksum, }); } // process plugin repo diff --git a/utils/github.ts b/utils/github.ts index f0a69b1..752719b 100644 --- a/utils/github.ts +++ b/utils/github.ts @@ -61,12 +61,21 @@ function getReleaseInfo(data: GitHubRelease): ReleaseInfo { }; function getChecksum() { - if (typeof data.body !== "string") { - return undefined; + if (typeof data.body === "string") { + // search the body text for a dprint style checksum + const checksum = /\@([a-z0-9]{64})\b/i.exec(data.body); + if (checksum?.[1]) { + return checksum[1]; + } + } + // fall back to the digest from the release asset + const assetName = getPluginKind() === "wasm" ? "plugin.wasm" : "plugin.json"; + const asset = data.assets?.find((a) => a.name === assetName); + if (asset?.digest) { + const match = /^sha256:([a-f0-9]{64})$/i.exec(asset.digest); + return match?.[1]; } - // search the body text for a dprint style checksum - const checksum = /\@([a-z0-9]{64})\b/i.exec(data.body); - return checksum?.[1]; + return undefined; } function getPluginKind(): ReleaseInfo["kind"] { @@ -93,6 +102,7 @@ function getDownloadCount(assets: ReleaseAsset[]) { interface ReleaseAsset { name: string; download_count: number; + digest: string | null; } export async function getAllDownloadCount(username: string, repoName: string) {