UNPKG

@rebilly/framepay-react

Version:

A React wrapper for Rebilly's FramePay offering out-of-the-box support for Redux and other common React features

68 lines (56 loc) 1.84 kB
/** * Tiny util to switch react version in test * * @type {string} */ const fs = require('fs'); const { execSync } = require('child_process'); const version = process.env.REACT_VERSION; const clean = !version || version === 'clean'; const packageJsonPath = './package.json'; const backupPath = './package.json.backup'; function runInstallCommand() { execSync('pnpm install', { stdio: 'inherit' }); } function backupPackageJson() { if (!fs.existsSync(backupPath)) { fs.copyFileSync(packageJsonPath, backupPath); console.log('>>> Backed up package.json <<<'); } } function restorePackageJson() { if (fs.existsSync(backupPath)) { fs.copyFileSync(backupPath, packageJsonPath); fs.unlinkSync(backupPath); console.log('>>> Restored package.json from backup <<<'); } else { console.log('>>> No backup found to restore <<<'); } } if (clean) { console.log(`>>> CLEAN REACT ALIAS <<<`); restorePackageJson(); runInstallCommand(); } else { backupPackageJson(); const pkg = require('../../package'); let template = { 'prop-types': './test/e2e/assets/prop-types.js', react: `./test/e2e/assets/react-${version}.js`, 'react-dom': `./test/e2e/assets/react-dom-${version}.js`, }; if (version === '0.14.0') { template = {}; pkg['dependencies']['prop-types'] = '0.2.0'; pkg['devDependencies']['react'] = '0.14.0'; pkg['devDependencies']['react-dom'] = '0.14.0'; pkg['@parcel/transformer-js'] = { "jsxRuntime": "classic" } } pkg.alias = pkg.alias || {}; Object.assign(pkg.alias, template); console.log(`>>> REACT_VERSION ${version} <<<`); fs.writeFileSync(packageJsonPath, JSON.stringify(pkg, null, 4), 'utf8'); runInstallCommand(); }