Skip to content

Commit bfe454a

Browse files
authored
fix(e2e): Temporarily pin Metro 0.83.2 for E2E tests (#5234)
1 parent e74e877 commit bfe454a

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

dev-packages/e2e-tests/cli.mjs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,18 @@ if (actions.includes('create')) {
103103
env: env,
104104
});
105105

106+
// Only apply the package.json patch for newer RN versions
107+
const versionNumber = parseFloat(RNVersion.replace(/[^\d.]/g, ''));
108+
if (versionNumber >= 0.80) {
109+
execSync(`${patchScriptsDir}/rn.patch.package.json.js --path package.json`, {
110+
stdio: 'inherit',
111+
cwd: appDir,
112+
env: env,
113+
});
114+
} else {
115+
console.log(`Skipping rn.patch.package.json.js for RN ${RNVersion} (< 0.80)`);
116+
}
117+
106118
// Install dependencies
107119
// yalc add doesn't fail if the package is not found - it skips silently.
108120
let yalcAddOutput = execSync(`yalc add @sentry/react-native`, { cwd: appDir, env: env, encoding: 'utf-8' });
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env node
2+
3+
const fs = require('fs');
4+
const path = require('path');
5+
const { argv, cwd } = require('process');
6+
const parseArgs = require('minimist');
7+
const { debug } = require('@sentry/core');
8+
debug.enable();
9+
10+
const args = parseArgs(argv.slice(2), { string: ['app','path','file'], alias: { path: ['file'] } });
11+
12+
function resolvePkgPath() {
13+
if (args.path) {
14+
const p = path.resolve(args.path);
15+
if (!p.endsWith('package.json')) throw new Error(`--path must point to package.json, got: ${p}`);
16+
return p;
17+
}
18+
if (args.app) return path.join(path.resolve(args.app), 'package.json');
19+
return path.join(cwd(), 'package.json');
20+
}
21+
22+
const pkgPath = resolvePkgPath();
23+
if (!fs.existsSync(pkgPath)) throw new Error(`package.json not found at: ${pkgPath}`);
24+
25+
const raw = fs.readFileSync(pkgPath, 'utf8');
26+
let pkg;
27+
try { pkg = JSON.parse(raw); } catch (e) { throw new Error(`Invalid JSON: ${e.message}`); }
28+
29+
const METRO_VERSION = '0.83.2';
30+
31+
// List of Metro packages that need to be pinned
32+
const METRO_PACKAGES = [
33+
'metro',
34+
'metro-config'
35+
];
36+
37+
pkg.overrides = pkg.overrides || {};
38+
METRO_PACKAGES.forEach(pkgName => {
39+
pkg.overrides[pkgName] = METRO_VERSION;
40+
});
41+
42+
pkg.resolutions = pkg.resolutions || {};
43+
METRO_PACKAGES.forEach(pkgName => {
44+
pkg.resolutions[pkgName] = METRO_VERSION;
45+
});
46+
47+
fs.writeFileSync(pkgPath + '.bak', raw);
48+
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n');
49+
50+
debug.log('Patched package.json: Metro packages set to', METRO_VERSION);

0 commit comments

Comments
 (0)