mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Update set-version to reuse set-rn-version (#43109)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/43109 Changelog: [Internal] Reviewed By: cipolleschi Differential Revision: D53940616 fbshipit-source-id: 8ce85437ab5164dae81a9956706c517880ee1f74
This commit is contained in:
committed by
Facebook GitHub Bot
parent
cffb69a12b
commit
a4d6be8908
@@ -78,7 +78,7 @@ async function main() {
|
||||
async function setReactNativeVersion(
|
||||
version /*: string */,
|
||||
dependencyVersions /*: ?Record<string, string> */,
|
||||
buildType /*: BuildType */,
|
||||
buildType /*: ?BuildType */,
|
||||
) {
|
||||
const versionInfo = parseVersion(version, buildType);
|
||||
|
||||
|
||||
@@ -176,8 +176,7 @@ exports[`setVersion updates monorepo for nightly: packages/react-native/package.
|
||||
\\"metro-config\\": \\"^0.80.3\\",
|
||||
\\"metro-runtime\\": \\"^0.80.3\\"
|
||||
}
|
||||
}
|
||||
"
|
||||
}"
|
||||
`;
|
||||
|
||||
exports[`setVersion updates monorepo for nightly: packages/react-native/template/package.json 1`] = `
|
||||
@@ -375,8 +374,7 @@ exports[`setVersion updates monorepo for release-candidate: packages/react-nativ
|
||||
\\"metro-config\\": \\"^0.80.3\\",
|
||||
\\"metro-runtime\\": \\"^0.80.3\\"
|
||||
}
|
||||
}
|
||||
"
|
||||
}"
|
||||
`;
|
||||
|
||||
exports[`setVersion updates monorepo for release-candidate: packages/react-native/template/package.json 1`] = `
|
||||
@@ -574,8 +572,7 @@ exports[`setVersion updates monorepo for stable version: packages/react-native/p
|
||||
\\"metro-config\\": \\"^0.80.3\\",
|
||||
\\"metro-runtime\\": \\"^0.80.3\\"
|
||||
}
|
||||
}
|
||||
"
|
||||
}"
|
||||
`;
|
||||
|
||||
exports[`setVersion updates monorepo for stable version: packages/react-native/template/package.json 1`] = `
|
||||
@@ -640,6 +637,127 @@ exports[`setVersion updates monorepo on main after release cut: packages/monorep
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`setVersion updates monorepo on main after release cut: packages/react-native/Libraries/Core/ReactNativeVersion.js 1`] = `
|
||||
"/**
|
||||
* 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.
|
||||
*
|
||||
* @flow strict
|
||||
* @generated by scripts/releases/set-rn-version.js
|
||||
*/
|
||||
|
||||
const version: $ReadOnly<{
|
||||
major: number,
|
||||
minor: number,
|
||||
patch: number,
|
||||
prerelease: string | null,
|
||||
}> = {
|
||||
major: 1000,
|
||||
minor: 0,
|
||||
patch: 0,
|
||||
prerelease: null,
|
||||
};
|
||||
|
||||
module.exports = {version};
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`setVersion updates monorepo on main after release cut: packages/react-native/React/Base/RCTVersion.m 1`] = `
|
||||
"/**
|
||||
* 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.
|
||||
*
|
||||
* @generated by scripts/releases/set-rn-version.js
|
||||
*/
|
||||
|
||||
#import \\"RCTVersion.h\\"
|
||||
|
||||
NSString* const RCTVersionMajor = @\\"major\\";
|
||||
NSString* const RCTVersionMinor = @\\"minor\\";
|
||||
NSString* const RCTVersionPatch = @\\"patch\\";
|
||||
NSString* const RCTVersionPrerelease = @\\"prerelease\\";
|
||||
|
||||
|
||||
NSDictionary* RCTGetReactNativeVersion(void)
|
||||
{
|
||||
static NSDictionary* __rnVersion;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^(void){
|
||||
__rnVersion = @{
|
||||
RCTVersionMajor: @(1000),
|
||||
RCTVersionMinor: @(0),
|
||||
RCTVersionPatch: @(0),
|
||||
RCTVersionPrerelease: [NSNull null],
|
||||
};
|
||||
});
|
||||
return __rnVersion;
|
||||
}
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`setVersion updates monorepo on main after release cut: packages/react-native/ReactAndroid/gradle.properties 1`] = `
|
||||
"VERSION_NAME=1000.0.0
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`setVersion updates monorepo on main after release cut: packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/systeminfo/ReactNativeVersion.java 1`] = `
|
||||
"/**
|
||||
* 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.
|
||||
*
|
||||
* @generated by scripts/releases/set-rn-version.js
|
||||
*/
|
||||
|
||||
package com.facebook.react.modules.systeminfo;
|
||||
|
||||
import com.facebook.react.common.MapBuilder;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class ReactNativeVersion {
|
||||
public static final Map<String, Object> VERSION = MapBuilder.<String, Object>of(
|
||||
\\"major\\", 1000,
|
||||
\\"minor\\", 0,
|
||||
\\"patch\\", 0,
|
||||
\\"prerelease\\", null);
|
||||
}
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`setVersion updates monorepo on main after release cut: packages/react-native/ReactCommon/cxxreact/ReactNativeVersion.h 1`] = `
|
||||
"/**
|
||||
* 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.
|
||||
*
|
||||
* @generated by scripts/releases/set-rn-version.js
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <string_view>
|
||||
|
||||
namespace facebook::react {
|
||||
|
||||
constexpr struct {
|
||||
int32_t Major = 1000;
|
||||
int32_t Minor = 0;
|
||||
int32_t Patch = 0;
|
||||
std::string_view Prerelease = \\"\\";
|
||||
} ReactNativeVersion;
|
||||
|
||||
} // namespace facebook::react
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`setVersion updates monorepo on main after release cut: packages/react-native/package.json 1`] = `
|
||||
"{
|
||||
\\"name\\": \\"react-native\\",
|
||||
@@ -652,8 +770,7 @@ exports[`setVersion updates monorepo on main after release cut: packages/react-n
|
||||
\\"metro-config\\": \\"^0.80.3\\",
|
||||
\\"metro-runtime\\": \\"^0.80.3\\"
|
||||
}
|
||||
}
|
||||
"
|
||||
}"
|
||||
`;
|
||||
|
||||
exports[`setVersion updates monorepo on main after release cut: packages/react-native/template/package.json 1`] = `
|
||||
|
||||
@@ -49,6 +49,7 @@ describe('setVersion', () => {
|
||||
|
||||
return {
|
||||
...originalFs,
|
||||
writeFileSync: writeFileMock,
|
||||
promises: {
|
||||
...originalFs.promises,
|
||||
writeFile: writeFileMock,
|
||||
@@ -88,19 +89,5 @@ describe('setVersion', () => {
|
||||
};
|
||||
|
||||
await setVersion('0.82.0-main', true);
|
||||
|
||||
// Make sure we don't update any react-native source or build files
|
||||
writeFileMock.mock.calls.forEach(([filePath, content]) => {
|
||||
if (!filePath.endsWith('package.json')) {
|
||||
throw new Error(
|
||||
`set-version should not update any react-native source or build files. Updated ${filePath}`,
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
jest.unmock('path');
|
||||
jest.unmock('fs');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -15,62 +15,20 @@
|
||||
import type {PackageJson} from '../utils/monorepo';
|
||||
*/
|
||||
|
||||
const {REACT_NATIVE_PACKAGE_DIR} = require('../../consts');
|
||||
const {updateGradleFile, updateSourceFiles} = require('../set-rn-version');
|
||||
const {setReactNativeVersion} = require('../set-rn-version');
|
||||
const {getPackages} = require('../utils/monorepo');
|
||||
const {parseVersion} = require('../utils/version-utils');
|
||||
const {promises: fs} = require('fs');
|
||||
const path = require('path');
|
||||
const yargs = require('yargs');
|
||||
|
||||
const TEMPLATE_DIR = path.join(REACT_NATIVE_PACKAGE_DIR, 'template');
|
||||
|
||||
async function updatePackages(
|
||||
version /*: string */,
|
||||
skipReactNativeVersion /*: boolean */,
|
||||
) {
|
||||
const packages = await getPackages({
|
||||
includePrivate: false,
|
||||
includeReactNative: true,
|
||||
});
|
||||
const newPackageVersions = Object.fromEntries(
|
||||
Object.keys(packages).map(packageName => [packageName, version]),
|
||||
);
|
||||
const templatePackageJson /*: PackageJson */ = JSON.parse(
|
||||
await fs.readFile(path.join(TEMPLATE_DIR, 'package.json'), 'utf-8'),
|
||||
);
|
||||
const packagesToUpdate = [
|
||||
...Object.values(packages),
|
||||
{
|
||||
path: TEMPLATE_DIR,
|
||||
packageJson: templatePackageJson,
|
||||
},
|
||||
];
|
||||
|
||||
await Promise.all(
|
||||
packagesToUpdate.map(({path: packagePath, packageJson}) =>
|
||||
updatePackageJson(
|
||||
packagePath,
|
||||
packageJson,
|
||||
newPackageVersions,
|
||||
skipReactNativeVersion,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
async function updatePackageJson(
|
||||
packagePath /*: string */,
|
||||
packageJson /*: PackageJson */,
|
||||
newPackageVersions /*: $ReadOnly<{[string]: string}> */,
|
||||
skipReactNativeVersion /*: boolean */,
|
||||
) /*: Promise<void> */ {
|
||||
const packageName = packageJson.name;
|
||||
|
||||
if (
|
||||
packageName in newPackageVersions &&
|
||||
(!skipReactNativeVersion || packageName !== 'react-native')
|
||||
) {
|
||||
if (packageName in newPackageVersions) {
|
||||
packageJson.version = newPackageVersions[packageName];
|
||||
}
|
||||
|
||||
@@ -81,12 +39,8 @@ async function updatePackageJson(
|
||||
continue;
|
||||
}
|
||||
|
||||
for (const dependency of Object.keys(deps)) {
|
||||
if (dependency === 'react-native' && skipReactNativeVersion) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (dependency in newPackageVersions) {
|
||||
for (const dependency in newPackageVersions) {
|
||||
if (dependency in deps) {
|
||||
deps[dependency] = newPackageVersions[dependency];
|
||||
}
|
||||
}
|
||||
@@ -115,15 +69,31 @@ async function updatePackageJson(
|
||||
async function setVersion(
|
||||
version /*: string */,
|
||||
skipReactNativeVersion /*: boolean */ = false,
|
||||
) {
|
||||
const parsedVersion = parseVersion(version);
|
||||
) /*: Promise<void> */ {
|
||||
const packages = await getPackages({
|
||||
includePrivate: false,
|
||||
includeReactNative: true,
|
||||
});
|
||||
const newPackageVersions = Object.fromEntries(
|
||||
Object.keys(packages).map(packageName => [packageName, version]),
|
||||
);
|
||||
|
||||
if (!skipReactNativeVersion) {
|
||||
await updateSourceFiles(parsedVersion);
|
||||
await updateGradleFile(parsedVersion.version);
|
||||
}
|
||||
await setReactNativeVersion(
|
||||
skipReactNativeVersion ? '1000.0.0' : version,
|
||||
newPackageVersions,
|
||||
);
|
||||
|
||||
await updatePackages(parsedVersion.version, skipReactNativeVersion);
|
||||
// Exclude the react-native package, since this (and the template) are
|
||||
// handled by `setReactNativeVersion`.
|
||||
const packagesToUpdate = Object.values(packages).filter(
|
||||
pkg => pkg.name !== 'react-native',
|
||||
);
|
||||
|
||||
await Promise.all(
|
||||
packagesToUpdate.map(({path: packagePath, packageJson}) =>
|
||||
updatePackageJson(packagePath, packageJson, newPackageVersions),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (require.main === module) {
|
||||
|
||||
@@ -9,10 +9,13 @@
|
||||
* @oncall react_native
|
||||
*/
|
||||
|
||||
const {REACT_NATIVE_PACKAGE_DIR} = require('../consts');
|
||||
const {applyPackageVersions} = require('../npm-utils');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const TEMPLATE_DIR = path.join(REACT_NATIVE_PACKAGE_DIR, 'template');
|
||||
|
||||
/**
|
||||
* Updates the react-native template package.json with
|
||||
* dependencies in `dependencyMap`.
|
||||
@@ -21,12 +24,8 @@ const path = require('path');
|
||||
* ex. {"react-native": "0.23.0", "other-dep": "nightly"}
|
||||
*/
|
||||
function updateTemplatePackage(dependencyMap /*: Record<string, string> */) {
|
||||
const jsonPath = path.join(
|
||||
__dirname,
|
||||
'../../packages/react-native/template/package.json',
|
||||
);
|
||||
// $FlowFixMe[unsupported-syntax]
|
||||
const templatePackageJson = require(jsonPath);
|
||||
const jsonPath = path.join(TEMPLATE_DIR, 'package.json');
|
||||
const templatePackageJson = JSON.parse(fs.readFileSync(jsonPath, 'utf-8'));
|
||||
|
||||
const updatedPackageJson = applyPackageVersions(
|
||||
templatePackageJson,
|
||||
|
||||
Reference in New Issue
Block a user