Skip to content

Commit

Permalink
Release script updates private package dependencies also (facebook#13612
Browse files Browse the repository at this point in the history
)
  • Loading branch information
bvaughn authored and Simek committed Oct 25, 2018
1 parent 0af17a7 commit 07825b9
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
13 changes: 11 additions & 2 deletions scripts/release/build-commands/update-package-versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
11 changes: 9 additions & 2 deletions scripts/release/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -31,6 +31,7 @@ const run = async () => {
try {
const params = parseBuildParameters();
params.packages = getPublicPackages();

await checkEnvironmentVariables(params);
await validateVersion(params);
await checkUncommittedChanges(params);
Expand All @@ -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);
Expand Down
18 changes: 18 additions & 0 deletions scripts/release/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -99,6 +116,7 @@ const runYarnTask = async (cwd, task, errorMessage) => {
module.exports = {
execRead,
execUnlessDry,
getPackages,
getPublicPackages,
getUnexecutedCommands,
logPromise,
Expand Down

0 comments on commit 07825b9

Please sign in to comment.