|
| 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