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":["import { createRequire } from 'module';\n\nimport type { ValidatorMeta } from '../validator-types';\n\n/**\n * Check if the platform version in manifest matches the version of the Snaps\n * SDK.\n */\nexport const platformVersion: ValidatorMeta = {\n  severity: 'error',\n  async semanticCheck(files, context) {\n    const manifestPlatformVersion =\n      files.manifest.mergedManifest.platformVersion;\n\n    // Create a require function in the context of the location of the manifest\n    // file to avoid potentially loading the wrong version of the Snaps SDK.\n    const require = createRequire(files.manifest.mainManifest.path);\n\n    const packageJson = require.resolve('@metamask/snaps-sdk/package.json');\n    // eslint-disable-next-line import-x/no-dynamic-require\n    const actualVersion = require(packageJson).version;\n\n    if (!manifestPlatformVersion) {\n      context.report(\n        'platform-version-missing',\n        'The \"platformVersion\" field is missing from the manifest.',\n        ({ manifest }) => {\n          manifest.mainManifest.result.platformVersion = actualVersion;\n          return { manifest };\n        },\n      );\n\n      return;\n    }\n\n    if (manifestPlatformVersion !== actualVersion) {\n      context.report(\n        'platform-version-mismatch',\n        `The \"platformVersion\" field in the manifest must match the version of the Snaps SDK. Got \"${manifestPlatformVersion}\", expected \"${actualVersion}\".`,\n        async ({ manifest }) => {\n          manifest.mainManifest.result.platformVersion = actualVersion;\n          return { manifest };\n        },\n      );\n    }\n  },\n};\n"]}