diff --git a/package.json b/package.json index 580c5681ef..95c25db87e 100644 --- a/package.json +++ b/package.json @@ -59,7 +59,7 @@ "test-watch": "NODE_ENV=test jest --watchAll", "test-ci": "NODE_ENV=test jest --ci --forceExit --reporters=default --reporters=jest-junit", "test-coverage": "NODE_ENV=test jest --coverage", - "lint": "oxlint --quiet src modules", + "lint": "oxlint --quiet src modules && node scripts/check-sentry-browser-version.mjs", "lint-native": "swiftlint ./modules && ktlint ./modules", "lint-native:fix": "swiftlint --fix ./modules && ktlint --format ./modules", "lexicons:generate": "lex build --clear --index-file --import-ext ''", diff --git a/scripts/check-sentry-browser-version.mjs b/scripts/check-sentry-browser-version.mjs new file mode 100644 index 0000000000..7b3ed3ed5f --- /dev/null +++ b/scripts/check-sentry-browser-version.mjs @@ -0,0 +1,48 @@ +#!/usr/bin/env node +/** + * Verifies that our direct @sentry/browser dependency is pinned to the exact + * version @sentry/react-native depends on. + * + * The web build initializes @sentry/browser directly (src/logger/sentry/ + * {lib,setup}/index.web.ts) to keep the RN SDK layer out of the web bundle, + * while native still goes through @sentry/react-native, which pins an exact + * @sentry/browser version internally. If the two versions drift apart, pnpm + * silently installs two copies of the browser SDK - bloating the bundle and + * splitting SDK state between them - so when bumping @sentry/react-native, + * bump @sentry/browser to the version it pins. This check makes drift loud. + * + * Usage: node scripts/check-sentry-browser-version.mjs + * Exits 1 on mismatch. + */ + +import {readFileSync} from 'node:fs' +import {dirname, join, resolve} from 'node:path' +import {fileURLToPath} from 'node:url' + +const root = resolve(dirname(fileURLToPath(import.meta.url)), '..') +const readPkg = p => JSON.parse(readFileSync(join(root, p), 'utf8')) + +const ours = readPkg('package.json').dependencies['@sentry/browser'] +const theirs = readPkg('node_modules/@sentry/react-native/package.json') + .dependencies['@sentry/browser'] + +if (!ours) { + console.error( + 'check-sentry-browser-version: @sentry/browser is missing from ' + + 'dependencies in package.json. The web Sentry setup imports it directly.', + ) + process.exit(1) +} + +if (ours !== theirs) { + console.error( + `check-sentry-browser-version: @sentry/browser version mismatch.\n` + + ` package.json pins: ${ours}\n` + + ` @sentry/react-native expects: ${theirs}\n` + + `Set "@sentry/browser": "${theirs}" in package.json so pnpm resolves a ` + + `single copy of the browser SDK.`, + ) + process.exit(1) +} + +console.log(`check-sentry-browser-version: OK (${ours})`)