mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
a469927c16
Summary: Changelog: [Internal] Okay, so before the monorepo migration we had to use two scripts separately: 1. Bumping every package with `npm run bump-all-updated-packages` 2. Aligning other packages versions with `npm run align-package-versions` The reason for it is that *before the monorepo* in a release branch cutoff process we had a step, which was removing `workspaces` keyword from `react-native` package. Without this keyword all new versions of packages will be resolved from npm (where they will be not available yet, because we have to publish them prior to it) This is not the case for our current setup, and we can actually bump packages versions and they will be resolved as a workspaces successfully Differential Revision: D44261057 fbshipit-source-id: 6095209c8183f6d84e2697fda2e9a21f8a57f73e
122 lines
3.3 KiB
JavaScript
122 lines
3.3 KiB
JavaScript
/**
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @format
|
|
*/
|
|
|
|
const {writeFileSync, readFileSync} = require('fs');
|
|
const path = require('path');
|
|
|
|
const forEachPackage = require('./for-each-package');
|
|
|
|
const ROOT_LOCATION = path.join(__dirname, '..', '..');
|
|
const TEMPLATE_LOCATION = path.join(
|
|
ROOT_LOCATION,
|
|
'packages',
|
|
'react-native',
|
|
'template',
|
|
);
|
|
|
|
const readJSONFile = pathToFile => JSON.parse(readFileSync(pathToFile));
|
|
|
|
const checkIfShouldUpdateDependencyPackageVersion = (
|
|
consumerPackageAbsolutePath,
|
|
updatedPackageName,
|
|
updatedPackageVersion,
|
|
) => {
|
|
const consumerPackageManifestPath = path.join(
|
|
consumerPackageAbsolutePath,
|
|
'package.json',
|
|
);
|
|
const consumerPackageManifest = readJSONFile(consumerPackageManifestPath);
|
|
|
|
const dependencyVersion =
|
|
consumerPackageManifest.dependencies?.[updatedPackageName];
|
|
|
|
if (dependencyVersion && dependencyVersion !== '*') {
|
|
const updatedDependencyVersion = dependencyVersion.startsWith('^')
|
|
? `^${updatedPackageVersion}`
|
|
: updatedPackageVersion;
|
|
|
|
if (updatedDependencyVersion !== dependencyVersion) {
|
|
console.log(
|
|
`\uD83D\uDCA1 ${consumerPackageManifest.name} was updated: now using version ${updatedPackageVersion} of ${updatedPackageName}`,
|
|
);
|
|
|
|
const updatedPackageManifest = {
|
|
...consumerPackageManifest,
|
|
dependencies: {
|
|
...consumerPackageManifest.dependencies,
|
|
[updatedPackageName]: updatedDependencyVersion,
|
|
},
|
|
};
|
|
|
|
writeFileSync(
|
|
consumerPackageManifestPath,
|
|
JSON.stringify(updatedPackageManifest, null, 2) + '\n',
|
|
'utf-8',
|
|
);
|
|
}
|
|
}
|
|
|
|
const devDependencyVersion =
|
|
consumerPackageManifest.devDependencies?.[updatedPackageName];
|
|
|
|
if (devDependencyVersion && devDependencyVersion !== '*') {
|
|
const updatedDependencyVersion = devDependencyVersion.startsWith('^')
|
|
? `^${updatedPackageVersion}`
|
|
: updatedPackageVersion;
|
|
|
|
if (updatedDependencyVersion !== devDependencyVersion) {
|
|
console.log(
|
|
`\uD83D\uDCA1 ${consumerPackageManifest.name} was updated: now using version ${updatedPackageVersion} of ${updatedPackageName}`,
|
|
);
|
|
|
|
const updatedPackageManifest = {
|
|
...consumerPackageManifest,
|
|
devDependencies: {
|
|
...consumerPackageManifest.devDependencies,
|
|
[updatedPackageName]: updatedDependencyVersion,
|
|
},
|
|
};
|
|
|
|
writeFileSync(
|
|
consumerPackageManifestPath,
|
|
JSON.stringify(updatedPackageManifest, null, 2) + '\n',
|
|
'utf-8',
|
|
);
|
|
}
|
|
}
|
|
};
|
|
|
|
const alignPackageVersions = () => {
|
|
forEachPackage((_, __, packageManifest) => {
|
|
checkIfShouldUpdateDependencyPackageVersion(
|
|
ROOT_LOCATION,
|
|
packageManifest.name,
|
|
packageManifest.version,
|
|
);
|
|
|
|
checkIfShouldUpdateDependencyPackageVersion(
|
|
TEMPLATE_LOCATION,
|
|
packageManifest.name,
|
|
packageManifest.version,
|
|
);
|
|
|
|
forEachPackage(
|
|
pathToPackage =>
|
|
checkIfShouldUpdateDependencyPackageVersion(
|
|
pathToPackage,
|
|
packageManifest.name,
|
|
packageManifest.version,
|
|
),
|
|
{includeReactNative: true},
|
|
);
|
|
});
|
|
};
|
|
|
|
module.exports = alignPackageVersions;
|