From 54bfab5d6d9e0e313fbedbe76979c59470fbe140 Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Mon, 10 Sep 2018 13:14:34 -0700 Subject: [PATCH] Release script updates private package dependencies also (#13612) --- .../build-commands/update-package-versions.js | 13 +++++++++++-- scripts/release/build.js | 11 +++++++++-- scripts/release/utils.js | 18 ++++++++++++++++++ 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/scripts/release/build-commands/update-package-versions.js b/scripts/release/build-commands/update-package-versions.js index 60e98fbc2f282..467c20791b914 100644 --- a/scripts/release/build-commands/update-package-versions.js +++ b/scripts/release/build-commands/update-package-versions.js @@ -58,8 +58,11 @@ const update = async ({cwd, dry, packages, version}) => { const json = await readJson(path); const prerelease = semver.prerelease(version); - // Unstable package version. - json.version = getNextVersion(json.version, version); + // If this is a package we publish directly to NPM, update its version. + // Skip ones that we don't directly publish though (e.g. react-native-renderer). + if (json.private !== true) { + json.version = getNextVersion(json.version, version); + } if (project === 'react') { // Update inter-package dependencies as well. @@ -107,6 +110,12 @@ const update = async ({cwd, dry, packages, version}) => { Object.keys(json.dependencies).forEach(dependency => { if (packages.indexOf(dependency) >= 0) { const prevVersion = json.dependencies[dependency]; + + // Special case to handle e.g. react-noop-renderer + if (prevVersion === '*') { + return; + } + const nextVersion = getNextVersion( prevVersion.replace('^', ''), version diff --git a/scripts/release/build.js b/scripts/release/build.js index dedce1c267416..9288af14bf27d 100755 --- a/scripts/release/build.js +++ b/scripts/release/build.js @@ -8,7 +8,7 @@ const {exec} = require('child_process'); const run = async () => { const chalk = require('chalk'); const logUpdate = require('log-update'); - const {getPublicPackages} = require('./utils'); + const {getPublicPackages, getPackages} = require('./utils'); const addGitTag = require('./build-commands/add-git-tag'); const buildArtifacts = require('./build-commands/build-artifacts'); @@ -31,6 +31,7 @@ const run = async () => { try { const params = parseBuildParameters(); params.packages = getPublicPackages(); + await checkEnvironmentVariables(params); await validateVersion(params); await checkUncommittedChanges(params); @@ -41,7 +42,13 @@ const run = async () => { await checkPackageDependencies(params); await updateYarnDependencies(params); await runAutomatedTests(params); - await updatePackageVersions(params); + // Also update NPM dependencies for private packages (e.g. react-native-renderer) + // Even though we don't publish these to NPM, + // mismatching dependencies can cause `yarn install` to install duplicate packages. + await updatePackageVersions({ + ...params, + packages: getPackages(), + }); await updateNoopRendererDependencies(params); await buildArtifacts(params); await runAutomatedBundleTests(params); diff --git a/scripts/release/utils.js b/scripts/release/utils.js index d5be8b1a5a503..2a9ecff5e895c 100644 --- a/scripts/release/utils.js +++ b/scripts/release/utils.js @@ -23,6 +23,23 @@ const execUnlessDry = async (command, {cwd, dry}) => { } }; +const getPackages = () => { + const packagesRoot = join(__dirname, '..', '..', 'packages'); + + return readdirSync(packagesRoot).filter(dir => { + const packagePath = join(packagesRoot, dir, 'package.json'); + + if (dir.charAt(0) !== '.' && statSync(packagePath).isFile()) { + const packageJSON = JSON.parse(readFileSync(packagePath)); + + // Skip packages like "shared" and "events" that shouldn't be updated. + return packageJSON.version !== '0.0.0'; + } + + return false; + }); +}; + const getPublicPackages = () => { const packagesRoot = join(__dirname, '..', '..', 'packages'); @@ -99,6 +116,7 @@ const runYarnTask = async (cwd, task, errorMessage) => { module.exports = { execRead, execUnlessDry, + getPackages, getPublicPackages, getUnexecutedCommands, logPromise,