Skip to content

Commit 254422e

Browse files
feat: Validate platform version against production
1 parent 8922113 commit 254422e

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

packages/snaps-utils/src/manifest/validators/platform-version.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,35 @@
11
import { createRequire } from 'module';
2+
import { minVersion, gt } from 'semver';
23

34
import type { ValidatorMeta } from '../validator-types';
45

6+
/**
7+
* Determine the production version of the Snaps platform by inspecting
8+
* the latest GitHub release of the MetaMask extension.
9+
*
10+
* @returns The production version of the Snaps platform or null if any error occurred.
11+
*/
12+
async function determineProductionVersion() {
13+
try {
14+
// TODO: Cache this check.
15+
const latestRelease = await fetch(
16+
'https://api.github.com/repos/metamask/metamask-extension/releases/latest',
17+
).then(async (response) => response.json());
18+
19+
const latestReleaseCommit = latestRelease.target_commitish;
20+
21+
const packageJson = await fetch(
22+
`https://raw.githubusercontent.com/MetaMask/metamask-extension/${latestReleaseCommit}/package.json`,
23+
).then(async (response) => response.json());
24+
25+
const versionRange = packageJson.dependencies['@metamask/snaps-sdk'];
26+
27+
return minVersion(versionRange);
28+
} catch {
29+
return null;
30+
}
31+
}
32+
533
/**
634
* Check if the platform version in manifest matches the version of the Snaps
735
* SDK.
@@ -19,6 +47,14 @@ export const platformVersion: ValidatorMeta = {
1947
// eslint-disable-next-line import-x/no-dynamic-require
2048
const actualVersion = require(packageJson).version;
2149

50+
const maximumVersion = await determineProductionVersion();
51+
52+
if (maximumVersion && gt(actualVersion, maximumVersion)) {
53+
context.report(
54+
`The "platformVersion" in use is not supported in the production version of MetaMask yet. The current production version is "${maximumVersion.format()}".`,
55+
);
56+
}
57+
2258
if (!manifestPlatformVersion) {
2359
context.report(
2460
'The "platformVersion" field is missing from the manifest.',

0 commit comments

Comments
 (0)