diff --git a/dev-packages/e2e-tests/cli.mjs b/dev-packages/e2e-tests/cli.mjs index 9d8f958b80..383391a079 100755 --- a/dev-packages/e2e-tests/cli.mjs +++ b/dev-packages/e2e-tests/cli.mjs @@ -103,6 +103,18 @@ if (actions.includes('create')) { env: env, }); + // Only apply the package.json patch for newer RN versions + const versionNumber = parseFloat(RNVersion.replace(/[^\d.]/g, '')); + if (versionNumber >= 0.80) { + execSync(`${patchScriptsDir}/rn.patch.package.json.js --path package.json`, { + stdio: 'inherit', + cwd: appDir, + env: env, + }); + } else { + console.log(`Skipping rn.patch.package.json.js for RN ${RNVersion} (< 0.80)`); + } + // Install dependencies // yalc add doesn't fail if the package is not found - it skips silently. let yalcAddOutput = execSync(`yalc add @sentry/react-native`, { cwd: appDir, env: env, encoding: 'utf-8' }); diff --git a/dev-packages/e2e-tests/patch-scripts/rn.patch.package.json.js b/dev-packages/e2e-tests/patch-scripts/rn.patch.package.json.js new file mode 100755 index 0000000000..a36d7693c4 --- /dev/null +++ b/dev-packages/e2e-tests/patch-scripts/rn.patch.package.json.js @@ -0,0 +1,50 @@ +#!/usr/bin/env node + +const fs = require('fs'); +const path = require('path'); +const { argv, cwd } = require('process'); +const parseArgs = require('minimist'); +const { debug } = require('@sentry/core'); +debug.enable(); + +const args = parseArgs(argv.slice(2), { string: ['app','path','file'], alias: { path: ['file'] } }); + +function resolvePkgPath() { + if (args.path) { + const p = path.resolve(args.path); + if (!p.endsWith('package.json')) throw new Error(`--path must point to package.json, got: ${p}`); + return p; + } + if (args.app) return path.join(path.resolve(args.app), 'package.json'); + return path.join(cwd(), 'package.json'); +} + +const pkgPath = resolvePkgPath(); +if (!fs.existsSync(pkgPath)) throw new Error(`package.json not found at: ${pkgPath}`); + +const raw = fs.readFileSync(pkgPath, 'utf8'); +let pkg; +try { pkg = JSON.parse(raw); } catch (e) { throw new Error(`Invalid JSON: ${e.message}`); } + +const METRO_VERSION = '0.83.2'; + +// List of Metro packages that need to be pinned +const METRO_PACKAGES = [ + 'metro', + 'metro-config' +]; + +pkg.overrides = pkg.overrides || {}; +METRO_PACKAGES.forEach(pkgName => { + pkg.overrides[pkgName] = METRO_VERSION; +}); + +pkg.resolutions = pkg.resolutions || {}; +METRO_PACKAGES.forEach(pkgName => { + pkg.resolutions[pkgName] = METRO_VERSION; +}); + +fs.writeFileSync(pkgPath + '.bak', raw); +fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n'); + +debug.log('Patched package.json: Metro packages set to', METRO_VERSION);