mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-24 04:16:00 +08:00
Validate that JS and Native code versions match for RN releases
Summary: Basic implementation of the proposal in #15271 Note that this should not affect facebook internally since they are not using OSS releases. Points to consider: - How strict should the version match be, right now I just match exact versions. - Wasn't able to use haste for ReactNativeVersion because I was getting duplicate module provider caused by the template file in scripts/versiontemplates. I tried adding the scripts folder to modulePathIgnorePatterns in package.json but that didn't help. - Redscreen vs. warning, I think warning is useless because if the app crashes you won't have time to see the warning. - Should the check and native modules be __DEV__ only? **Test plan** Tested that it works when version match and that it redscreens when versions don't before getting other errors on Android and iOS. Closes https://github.com/facebook/react-native/pull/15518 Differential Revision: D5813551 Pulled By: hramos fbshipit-source-id: 901757e25724b0f22bf39de172b56309d0dd5a95
This commit is contained in:
committed by
Facebook Github Bot
parent
9b3cc30357
commit
1af645b2fd
@@ -46,10 +46,39 @@ 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.
|
||||
let match = version.match(/^(\d+)\.(\d+)\.(\d+)(?:-(.+))?$/);
|
||||
if (!match) {
|
||||
echo(`You must pass a correctly formatted version; couldn't parse ${version}`);
|
||||
exit(1);
|
||||
}
|
||||
let [, major, minor, patch, prerelease] = match;
|
||||
|
||||
cat('scripts/versiontemplates/ReactNativeVersion.java.template')
|
||||
.replace('${major}', major)
|
||||
.replace('${minor}', minor)
|
||||
.replace('${patch}', patch)
|
||||
.replace('${prerelease}', prerelease !== undefined ? `"${prerelease}"` : 'null')
|
||||
.to('ReactAndroid/src/main/java/com/facebook/react/modules/systeminfo/ReactNativeVersion.java');
|
||||
|
||||
cat('scripts/versiontemplates/RCTVersion.h.template')
|
||||
.replace('${major}', `@(${major})`)
|
||||
.replace('${minor}', `@(${minor})`)
|
||||
.replace('${patch}', `@(${patch})`)
|
||||
.replace('${prerelease}', prerelease !== undefined ? `@"${prerelease}"` : '[NSNull null]')
|
||||
.to('React/Base/RCTVersion.h');
|
||||
|
||||
cat('scripts/versiontemplates/ReactNativeVersion.js.template')
|
||||
.replace('${major}', major)
|
||||
.replace('${minor}', minor)
|
||||
.replace('${patch}', patch)
|
||||
.replace('${prerelease}', prerelease !== undefined ? `'${prerelease}'` : 'null')
|
||||
.to('Libraries/Core/ReactNativeVersion.js');
|
||||
|
||||
let packageJson = JSON.parse(cat(`package.json`));
|
||||
packageJson.version = version;
|
||||
JSON.stringify(packageJson, null, 2).to(`package.json`);
|
||||
|
||||
Reference in New Issue
Block a user