Skip to content

Commit

Permalink
Version map, check only major and minor
Browse files Browse the repository at this point in the history
  • Loading branch information
janicduplessis committed Sep 9, 2017
1 parent 04a9905 commit 2e69a0e
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 20 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ website/core/metadata-blog.js
website/src/react-native/docs/
website/src/react-native/blog/
danger/
scripts/versiontemplates/*
3 changes: 3 additions & 0 deletions .flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
; Ignore polyfills
.*/Libraries/polyfills/.*

; Version templates contain invalid JS.
<PROJECT_ROOT>/scripts/versiontemplates/.*

[include]

[libs]
Expand Down
12 changes: 9 additions & 3 deletions Libraries/Core/InitializeCore.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`.'
Expand Down
7 changes: 6 additions & 1 deletion Libraries/Core/ReactNativeVersion.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,9 @@
* @flow
*/

exports.version = 'master';
exports.version = {
major: 0,
minor: 0,
patch: 0,
prerelease: null,
};
7 changes: 6 additions & 1 deletion React/Base/RCTVersion.h
Original file line number Diff line number Diff line change
Expand Up @@ -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), \
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Integer> VERSION = MapBuilder.of(
"major", 0,
"minor", 0,
"patch", 0,
"prerelease", null);
}
37 changes: 26 additions & 11 deletions scripts/bump-oss-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,37 @@ let versionMajor = branch.slice(0, branch.indexOf(`-stable`));
// 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`);
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');
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);
}

cat('scripts/versiontemplates/ReactNativeVersion.js')
.replace('${version}', version)
.to('Libraries/Core/ReactNativeVersion.js');
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;
Expand Down
7 changes: 6 additions & 1 deletion scripts/versiontemplates/RCTVersion.h
Original file line number Diff line number Diff line change
Expand Up @@ -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}), \
}
10 changes: 9 additions & 1 deletion scripts/versiontemplates/ReactNativeVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Integer> VERSION = MapBuilder.of(
"major", ${major},
"minor", ${minor},
"patch", ${patch},
"prerelease", ${prerelease});
}
7 changes: 6 additions & 1 deletion scripts/versiontemplates/ReactNativeVersion.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,9 @@
* @flow
*/

exports.version = '${version}';
exports.version = {
major: ${major},
minor: ${minor},
patch: ${patch},
prerelease: ${prerelease},
};

0 comments on commit 2e69a0e

Please sign in to comment.