diff --git a/scripts/bump-oss-version.js b/scripts/bump-oss-version.js index a9acfc52f..e6cf3751f 100755 --- a/scripts/bump-oss-version.js +++ b/scripts/bump-oss-version.js @@ -114,9 +114,7 @@ if ( } // Change react-native version in the template's package.json -let templatePackageJson = JSON.parse(cat('template/package.json')); -templatePackageJson.dependencies['react-native'] = version; -fs.writeFileSync('./template/package.json', JSON.stringify(templatePackageJson, null, 2) + '\n', 'utf-8'); +exec(`node scripts/set-rn-template-version.js ${version}`); // Verify that files changed, we just do a git diff and check how many times version is added across files let numberOfChangedLinesWithNewVersion = exec( diff --git a/scripts/set-rn-template-version.js b/scripts/set-rn-template-version.js new file mode 100755 index 000000000..228cdb620 --- /dev/null +++ b/scripts/set-rn-template-version.js @@ -0,0 +1,30 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @format + */ + +'use strict'; + +const fs = require('fs'); +const path = require('path'); + +const version = process.argv[2]; + +if (!version) { + console.error('Please provide a react-native version.'); + process.exit(1); +} + +const jsonPath = path.join(__dirname, '../template/package.json'); + +let templatePackageJson = require(jsonPath); +templatePackageJson.dependencies['react-native'] = version; +fs.writeFileSync( + jsonPath, + JSON.stringify(templatePackageJson, null, 2) + '\n', + 'utf-8', +); diff --git a/scripts/test-manual-e2e.sh b/scripts/test-manual-e2e.sh index 84affa42d..328f60f21 100755 --- a/scripts/test-manual-e2e.sh +++ b/scripts/test-manual-e2e.sh @@ -76,11 +76,14 @@ npm pack PACKAGE=$(pwd)/react-native-$PACKAGE_VERSION.tgz success "Package bundled ($PACKAGE)" +node scripts/set-rn-template-version.js "file:$PACKAGE" +success "React Native version changed in the template" + project_name="RNTestProject" cd /tmp/ rm -rf "$project_name" -react-native init "$project_name" --version $PACKAGE +node "$repo_root/cli.js" init "$project_name" --template "$repo_root" info "Double checking the versions in package.json are correct:" grep "\"react-native\": \".*react-native-$PACKAGE_VERSION.tgz\"" "/tmp/${project_name}/package.json" || error "Incorrect version number in /tmp/${project_name}/package.json"