diff --git a/.eslintignore b/.eslintignore index d59f8f3846e489..471066e054fc32 100644 --- a/.eslintignore +++ b/.eslintignore @@ -13,3 +13,4 @@ website/core/metadata-blog.js website/src/react-native/docs/ website/src/react-native/blog/ danger/ +scripts/versiontemplates/* diff --git a/.flowconfig b/.flowconfig index 70641207371e86..3876e8e6165ac1 100644 --- a/.flowconfig +++ b/.flowconfig @@ -25,6 +25,9 @@ ; Ignore polyfills .*/Libraries/polyfills/.* +; Version templates contain invalid JS. +/scripts/versiontemplates/.* + [include] [libs] diff --git a/Libraries/Core/InitializeCore.js b/Libraries/Core/InitializeCore.js index b2c06fa4843614..e0836a7259ff8e 100644 --- a/Libraries/Core/InitializeCore.js +++ b/Libraries/Core/InitializeCore.js @@ -116,12 +116,18 @@ if (!global.__fbDisableExceptionsManager) { ErrorUtils.setGlobalHandler(handleError); } +const formatVersion = version => + `${version.major}.${version.minor}.${version.patch}` + + (version.prerelease !== null ? `-rc.${version.prerelease}` : ''); + const NativeModules = require('NativeModules'); const ReactNativeVersion = require('./ReactNativeVersion'); -if (ReactNativeVersion.version !== NativeModules.PlatformConstants.reactNativeVersion) { +const nativeVersion = NativeModules.PlatformConstants.reactNativeVersion; +if (ReactNativeVersion.version.major !== nativeVersion.major || + ReactNativeVersion.version.minor !== nativeVersion.minor) { throw new Error( - `React Native version mismatch.\n\nJavaScript version: ${ReactNativeVersion.version}\n` + - `Native version: ${NativeModules.PlatformConstants.reactNativeVersion}\n\n` + + `React Native version mismatch.\n\nJavaScript version: ${formatVersion(ReactNativeVersion.version)}\n` + + `Native version: ${formatVersion(nativeVersion)}\n\n` + 'Make sure that you have rebuilt the native code. If the problem persists ' + 'try clearing the watchman and packager caches with `watchman watch-del-all ' + '&& react-native start --reset-cache`.' diff --git a/Libraries/Core/ReactNativeVersion.js b/Libraries/Core/ReactNativeVersion.js index a34f8ea39136c3..47b5d5932e538c 100644 --- a/Libraries/Core/ReactNativeVersion.js +++ b/Libraries/Core/ReactNativeVersion.js @@ -11,4 +11,9 @@ * @flow */ -exports.version = 'master'; +exports.version = { + major: 0, + minor: 0, + patch: 0, + prerelease: null, +}; diff --git a/React/Base/RCTVersion.h b/React/Base/RCTVersion.h index 55f68eceb2780a..0931e658936396 100644 --- a/React/Base/RCTVersion.h +++ b/React/Base/RCTVersion.h @@ -9,4 +9,9 @@ * of patent rights can be found in the PATENTS file in the same directory. */ -#define REACT_NATIVE_VERSION @"master" +#define REACT_NATIVE_VERSION @{ \ + @"major": @(0), \ + @"minor": @(0), \ + @"patch": @(0), \ + @"prerelease": @(nil), \ +} diff --git a/ReactAndroid/src/main/java/com/facebook/react/ReactNativeVersion.java b/ReactAndroid/src/main/java/com/facebook/react/ReactNativeVersion.java index b1fb352cec6eb3..5c9c3e0c346725 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/ReactNativeVersion.java +++ b/ReactAndroid/src/main/java/com/facebook/react/ReactNativeVersion.java @@ -11,6 +11,14 @@ package com.facebook.react; +import com.facebook.react.common.MapBuilder; + +import java.util.Map; + public class ReactNativeVersion { - public static final String VERSION = "master"; + public static final Map VERSION = MapBuilder.of( + "major", 0, + "minor", 0, + "patch", 0, + "prerelease", null); } diff --git a/scripts/bump-oss-version.js b/scripts/bump-oss-version.js index 0f8fbf1d639640..a147f67c6bcb83 100755 --- a/scripts/bump-oss-version.js +++ b/scripts/bump-oss-version.js @@ -31,84 +31,99 @@ let argv = minimist(process.argv.slice(2), { default: {remote: 'origin'}, }); -// - check we are in release branch, e.g. 0.33-stable -let branch = exec(`git symbolic-ref --short HEAD`, {silent: true}).stdout.trim(); - -if (branch.indexOf(`-stable`) === -1) { - echo(`You must be in 0.XX-stable branch to bump a version`); - exit(1); -} - -// e.g. 0.33 -let versionMajor = branch.slice(0, branch.indexOf(`-stable`)); +// // - check we are in release branch, e.g. 0.33-stable +// let branch = exec(`git symbolic-ref --short HEAD`, {silent: true}).stdout.trim(); +// +// if (branch.indexOf(`-stable`) === -1) { +// echo(`You must be in 0.XX-stable branch to bump a version`); +// exit(1); +// } +// +// // e.g. 0.33 +// let versionMajor = branch.slice(0, branch.indexOf(`-stable`)); // - check that argument version matches branch // e.g. 0.33.1 or 0.33.0-rc4 let version = argv._[0]; -if (!version || version.indexOf(versionMajor) !== 0) { - echo(`You must pass a tag like ${versionMajor}.[X]-rc[Y] to bump a version`); - exit(1); -} +// if (!version || version.indexOf(versionMajor) !== 0) { +// echo(`You must pass a tag like 0.${versionMajor}.[X]-rc[Y] to bump a version`); +// exit(1); +// } // Generate version files to detect mismatches between JS and native. -cat('scripts/versiontemplates/ReactNativeVersion.java') - .replace('${version}', version) - .to('ReactAndroid/src/main/java/com/facebook/react/ReactNativeVersion.java'); - -cat('scripts/versiontemplates/RCTVersion.h') - .replace('${version}', version) - .to('React/Base/RCTVersion.h'); - -cat('scripts/versiontemplates/ReactNativeVersion.js') - .replace('${version}', version) - .to('Libraries/Core/ReactNativeVersion.js'); - -let packageJson = JSON.parse(cat(`package.json`)); -packageJson.version = version; -JSON.stringify(packageJson, null, 2).to(`package.json`); - -// - change ReactAndroid/gradle.properties -if (sed(`-i`, /^VERSION_NAME=.*/, `VERSION_NAME=${version}`, `ReactAndroid/gradle.properties`).code) { - echo(`Couldn't update version for Gradle`); - exit(1); -} - -// verify that files changed, we just do a git diff and check how many times version is added across files -let numberOfChangedLinesWithNewVersion = exec(`git diff -U0 | grep '^[+]' | grep -c ${version} `, {silent: true}) - .stdout.trim(); -if (+numberOfChangedLinesWithNewVersion !== 2) { - echo(`Failed to update all the files. package.json and gradle.properties must have versions in them`); - echo(`Fix the issue, revert and try again`); - exec(`git diff`); - exit(1); -} - -// - make commit [0.21.0-rc] Bump version numbers -if (exec(`git commit -a -m "[${version}] Bump version numbers"`).code) { - echo(`failed to commit`); - exit(1); -} - -// - add tag v0.21.0-rc -if (exec(`git tag v${version}`).code) { - echo(`failed to tag the commit with v${version}, are you sure this release wasn't made earlier?`); - echo(`You may want to rollback the last commit`); - echo(`git reset --hard HEAD~1`); - exit(1); -} - -// Push newly created tag -let remote = argv.remote; -exec(`git push ${remote} v${version}`); - -// Tag latest if doing stable release -if (version.indexOf(`rc`) === -1) { - exec(`git tag -d latest`); - exec(`git push ${remote} :latest`); - exec(`git tag latest`); - exec(`git push ${remote} latest`); +let [, major, minor, patch, prerelease] = version.match(/^(\d+)\.(\d+)\.(\d+)(?:-rc\.(\d+))?$/); + +function processVersionFile(from, to, nullValue) { + cat(from) + .replace('${major}', major) + .replace('${minor}', minor) + .replace('${patch}', patch) + .replace('${prerelease}', prerelease !== undefined ? prerelease : nullValue) + .to(to); } -exec(`git push ${remote} ${branch} --follow-tags`); +processVersionFile( + 'scripts/versiontemplates/ReactNativeVersion.java', + 'ReactAndroid/src/main/java/com/facebook/react/ReactNativeVersion.java', + 'null' +); +processVersionFile( + 'scripts/versiontemplates/RCTVersion.h', + 'React/Base/RCTVersion.h', + 'nil' +); +processVersionFile( + 'scripts/versiontemplates/ReactNativeVersion.js', + 'Libraries/Core/ReactNativeVersion.js', + 'null' +); +// +// let packageJson = JSON.parse(cat(`package.json`)); +// packageJson.version = version; +// JSON.stringify(packageJson, null, 2).to(`package.json`); +// +// // - change ReactAndroid/gradle.properties +// if (sed(`-i`, /^VERSION_NAME=.*/, `VERSION_NAME=${version}`, `ReactAndroid/gradle.properties`).code) { +// echo(`Couldn't update version for Gradle`); +// exit(1); +// } +// +// // verify that files changed, we just do a git diff and check how many times version is added across files +// let numberOfChangedLinesWithNewVersion = exec(`git diff -U0 | grep '^[+]' | grep -c ${version} `, {silent: true}) +// .stdout.trim(); +// if (+numberOfChangedLinesWithNewVersion !== 2) { +// echo(`Failed to update all the files. package.json and gradle.properties must have versions in them`); +// echo(`Fix the issue, revert and try again`); +// exec(`git diff`); +// exit(1); +// } +// +// // - make commit [0.21.0-rc] Bump version numbers +// if (exec(`git commit -a -m "[${version}] Bump version numbers"`).code) { +// echo(`failed to commit`); +// exit(1); +// } +// +// // - add tag v0.21.0-rc +// if (exec(`git tag v${version}`).code) { +// echo(`failed to tag the commit with v${version}, are you sure this release wasn't made earlier?`); +// echo(`You may want to rollback the last commit`); +// echo(`git reset --hard HEAD~1`); +// exit(1); +// } +// +// // Push newly created tag +// let remote = argv.remote; +// exec(`git push ${remote} v${version}`); +// +// // Tag latest if doing stable release +// if (version.indexOf(`rc`) === -1) { +// exec(`git tag -d latest`); +// exec(`git push ${remote} :latest`); +// exec(`git tag latest`); +// exec(`git push ${remote} latest`); +// } +// +// exec(`git push ${remote} ${branch} --follow-tags`); exit(0); diff --git a/scripts/versiontemplates/RCTVersion.h b/scripts/versiontemplates/RCTVersion.h index e222ad2f71d199..1de752cba721ea 100644 --- a/scripts/versiontemplates/RCTVersion.h +++ b/scripts/versiontemplates/RCTVersion.h @@ -9,4 +9,9 @@ * of patent rights can be found in the PATENTS file in the same directory. */ -#define REACT_NATIVE_VERSION @"${version}" +#define REACT_NATIVE_VERSION @{ \ + @"major": @(${major}), \ + @"minor": @(${minor}), \ + @"patch": @(${patch}), \ + @"prerelease": @(${prerelease}), \ +} diff --git a/scripts/versiontemplates/ReactNativeVersion.java b/scripts/versiontemplates/ReactNativeVersion.java index 5a159799eb5601..f79e64dd3cbbb5 100644 --- a/scripts/versiontemplates/ReactNativeVersion.java +++ b/scripts/versiontemplates/ReactNativeVersion.java @@ -11,6 +11,14 @@ package com.facebook.react; +import com.facebook.react.common.MapBuilder; + +import java.util.Map; + public class ReactNativeVersion { - public static final String VERSION = "${version}"; + public static final Map VERSION = MapBuilder.of( + "major", ${major}, + "minor", ${minor}, + "patch", ${patch}, + "prerelease", ${prerelease}); } diff --git a/scripts/versiontemplates/ReactNativeVersion.js b/scripts/versiontemplates/ReactNativeVersion.js index 9a5a31cec7a29c..42546234b72447 100644 --- a/scripts/versiontemplates/ReactNativeVersion.js +++ b/scripts/versiontemplates/ReactNativeVersion.js @@ -11,4 +11,9 @@ * @flow */ -exports.version = '${version}'; +exports.version = { + major: ${major}, + minor: ${minor}, + patch: ${patch}, + prerelease: ${prerelease}, +};