diff --git a/.gitignore b/.gitignore index a9ee9f8e84365b..178b86bc5d49f8 100644 --- a/.gitignore +++ b/.gitignore @@ -157,3 +157,5 @@ package-lock.json # CircleCI .circleci/generated_config.yml + +react-native-*.tgz diff --git a/README.md b/README.md index a99a5c75c20e3f..9b84e12ab6f282 100644 --- a/README.md +++ b/README.md @@ -56,13 +56,18 @@ React Native is developed and supported by many companies and individual core co ## Contents -- [Requirements](#-requirements) -- [Building your first React Native app](#-building-your-first-react-native-app) -- [Documentation](#-documentation) -- [Upgrading](#-upgrading) -- [How to Contribute](#-how-to-contribute) -- [Code of Conduct](#code-of-conduct) -- [License](#-license) +- [Contents](#contents) +- [📋 Requirements](#-requirements) +- [🎉 Building your first React Native app](#-building-your-first-react-native-app) +- [📖 Documentation](#-documentation) +- [🚀 Upgrading](#-upgrading) +- [👏 How to Contribute](#-how-to-contribute) + - [Code of Conduct](#code-of-conduct) + - [Contributing Guide](#contributing-guide) + - [Open Source Roadmap](#open-source-roadmap) + - [Good First Issues](#good-first-issues) + - [Discussions](#discussions) +- [📄 License](#-license) ## 📋 Requirements diff --git a/packages/react-native/ReactAndroid/.npmignore b/packages/react-native/ReactAndroid/.npmignore index 914cb7646a1805..b0f2e281772119 100644 --- a/packages/react-native/ReactAndroid/.npmignore +++ b/packages/react-native/ReactAndroid/.npmignore @@ -8,3 +8,5 @@ src/main/third-party/ # Exclude Android & JVM tests src/test/ src/androidTest/ +# Exclude prebuilt +src/main/jni/prebuilt/lib/ diff --git a/scripts/generate-npm-tarball.js b/scripts/generate-npm-tarball.js new file mode 100644 index 00000000000000..13a270057cf20b --- /dev/null +++ b/scripts/generate-npm-tarball.js @@ -0,0 +1,101 @@ +/** + * @format + */ + +'use strict'; + +const {exec, echo, exit, sed, rm} = require('shelljs'); +const os = require('os'); +const path = require('path'); +const yargs = require('yargs'); + +const argv = yargs + .option('base-version', { + type: 'string', + }) + .option('fork-version', { + type: 'string', + }) + .option('hermes-version', { + type: 'string', + }) + .option('clean', { + type: 'boolean', + default: false, + }) + .strict().argv; +const baseVersion = argv.baseVersion; +const forkVersion = argv.forkVersion; +const hermesVersion = argv.hermesVersion; +const clean = argv.clean; + +const rnDir = path.join(__dirname, '../packages/react-native'); + +if (clean) { + rm('-rf', path.join(rnDir, 'android')); + rm('-rf', path.join(rnDir, 'sdks/download')); + rm('-rf', path.join(rnDir, 'sdks/hermes')); + rm('-rf', path.join(rnDir, 'sdks/hermesc')); +} + +// Update the version number. +if ( + exec( + `node scripts/set-rn-version.js --to-version ${forkVersion} --build-type release`, + ).code +) { + echo(`Failed to set version number to ${forkVersion}`); + exit(1); +} + +// Use the hermes prebuilt binaries from the base version. +sed( + '-i', + /^version = .*$/, + `version = '${baseVersion}'`, + path.join(rnDir, 'sdks/hermes-engine/hermes-engine.podspec'), +); + +// Download hermesc from the base version. +const rnTmpDir = path.join(os.tmpdir(), 'hermesc'); +const rnTgzOutput = path.join(rnTmpDir, `react-native-${baseVersion}.tgz`); +const hermescDest = path.join(rnDir, 'sdks'); +exec(`mkdir -p ${rnTmpDir}`); +if ( + exec( + `curl https://registry.npmjs.com/react-native/-/react-native-${baseVersion}.tgz --output ${rnTgzOutput}`, + ).code +) { + echo('Failed to download base react-native package'); + exit(1); +} +if (exec(`tar -xvf ${rnTgzOutput} -C ${rnTmpDir}`).code) { + echo('Failed to extract base react-native package'); + exit(1); +} +exec(`mkdir -p ${hermescDest}`); +if ( + exec(`cp -r ${path.join(rnTmpDir, 'package/sdks/hermesc')} ${hermescDest}`) + .code +) { + echo('Failed to copy hermesc from base react-native package'); + exit(1); +} + +if (hermesVersion) { + exec(`echo "${hermesVersion}" > ${hermescDest}/.hermesversion`); +} + +// Build the android artifacts in the npm package. +if (exec('./gradlew publishAllInsideNpmPackage').code) { + echo('Could not generate artifacts'); + exit(1); +} + +// Generate tarball. +if (exec(`cd ${rnDir} && npm pack`).code) { + echo('Failed to generate tarball'); + exit(1); +} else { + exit(0); +}