Hardcoded allowlist for publishing packages (#20485)

With separate lists for stable and experimental.
This commit is contained in:
Andrew Clark
2020-12-18 16:20:37 -06:00
committed by GitHub
parent efc57e5cbb
commit 1bda600378
7 changed files with 62 additions and 46 deletions

View File

@@ -12,7 +12,8 @@ const {getPublicPackages, logPromise} = require('../utils');
const theme = require('../theme');
const run = async ({branch, checksum, commit, reactVersion, tempDirectory}) => {
const packages = getPublicPackages(join(tempDirectory, 'packages'));
const isExperimental = reactVersion.includes('experimental');
const packages = getPublicPackages(isExperimental);
const packagesDir = join(tempDirectory, 'packages');
const buildInfoJSON = {

View File

@@ -27,7 +27,8 @@ const run = async () => {
reactVersion,
} = await getBuildInfo();
const packages = getPublicPackages(join(cwd, 'packages'));
const isExperimental = process.env.RELEASE_CHANNEL === 'experimental';
const packages = getPublicPackages(isExperimental);
const packagesDir = join(cwd, 'packages');
const buildInfoJSON = {

View File

@@ -15,7 +15,7 @@ const run = async () => {
try {
const params = parseParams();
params.cwd = join(__dirname, '..', '..');
params.packages = await getPublicPackages();
params.packages = await getPublicPackages(true);
if (!params.build) {
params.build = await getLatestMasterBuildNumber(true);

View File

@@ -3,6 +3,7 @@
'use strict';
const {join} = require('path');
const {readJsonSync} = require('fs-extra');
const {getPublicPackages, handleError} = require('./utils');
const checkEnvironmentVariables = require('./shared-commands/check-environment-variables');
@@ -17,7 +18,6 @@ const run = async () => {
try {
const params = parseParams();
params.cwd = join(__dirname, '..', '..');
params.packages = await getPublicPackages();
if (!params.build) {
params.build = await getLatestMasterBuildNumber(false);
@@ -26,6 +26,11 @@ const run = async () => {
await checkEnvironmentVariables(params);
await downloadBuildArtifacts(params);
const version = readJsonSync('./build/node_modules/react/package.json')
.version;
const isExperimental = version.includes('experimental');
params.packages = await getPublicPackages(isExperimental);
if (!params.skipTests) {
await testPackagingFixture(params);
await testTracingFixture(params);

View File

@@ -20,18 +20,21 @@ const run = async () => {
try {
const params = parseParams();
params.cwd = join(__dirname, '..', '..');
params.packages = await getPublicPackages();
const isExperimental = params.version.includes('experimental');
if (!params.version) {
params.version = await getLatestNextVersion();
}
params.packages = await getPublicPackages(isExperimental);
// Map of package name to upcoming stable version.
// This Map is initially populated with guesses based on local versions.
// The developer running the release later confirms or overrides each version.
const versionsMap = new Map();
if (!params.version) {
params.version = await getLatestNextVersion();
}
if (params.version.includes('experimental')) {
if (isExperimental) {
console.error(
theme.error`Cannot promote an experimental build to stable.`
);

View File

@@ -3,6 +3,7 @@
'use strict';
const {join} = require('path');
const {readJsonSync} = require('fs-extra');
const {getPublicPackages, handleError} = require('./utils');
const theme = require('./theme');
@@ -20,8 +21,13 @@ const validateSkipPackages = require('./publish-commands/validate-skip-packages'
const run = async () => {
try {
const params = parseParams();
const version = readJsonSync('./build/node_modules/react/package.json')
.version;
const isExperimental = version.includes('experimental');
params.cwd = join(__dirname, '..', '..');
params.packages = await getPublicPackages();
params.packages = await getPublicPackages(isExperimental);
// Pre-filter any skipped packages to simplify the following commands.
// As part of doing this we can also validate that none of the skipped packages were misspelled.

View File

@@ -3,7 +3,7 @@
const {exec} = require('child-process-promise');
const {createPatch} = require('diff');
const {hashElement} = require('folder-hash');
const {readdirSync, readFileSync, statSync, writeFileSync} = require('fs');
const {readFileSync, writeFileSync} = require('fs');
const {readJson, writeJson} = require('fs-extra');
const http = require('request-promise-json');
const logUpdate = require('log-update');
@@ -12,14 +12,6 @@ const createLogger = require('progress-estimator');
const prompt = require('prompt-promise');
const theme = require('./theme');
// The following packages are published to NPM but not by this script.
// They are released through a separate process.
const RELEASE_SCRIPT_PACKAGE_SKIPLIST = [
'react-devtools',
'react-devtools-core',
'react-devtools-inline',
];
// https://www.npmjs.com/package/progress-estimator#configuration
const logger = createLogger({
storagePath: join(__dirname, '.progress-estimator'),
@@ -112,31 +104,38 @@ const getChecksumForCurrentRevision = async cwd => {
return hashedPackages.hash.slice(0, 7);
};
const getPublicPackages = () => {
const packagesRoot = join(__dirname, '..', '..', 'packages');
return readdirSync(packagesRoot).filter(dir => {
if (RELEASE_SCRIPT_PACKAGE_SKIPLIST.includes(dir)) {
return false;
}
const packagePath = join(packagesRoot, dir, 'package.json');
if (dir.charAt(0) !== '.') {
let stat;
try {
stat = statSync(packagePath);
} catch (err) {
return false;
}
if (stat.isFile()) {
const packageJSON = JSON.parse(readFileSync(packagePath));
return packageJSON.private !== true;
}
}
return false;
});
const getPublicPackages = isExperimental => {
if (isExperimental) {
return [
'create-subscription',
'eslint-plugin-react-hooks',
'jest-react',
'react',
'react-art',
'react-dom',
'react-is',
'react-reconciler',
'react-refresh',
'react-test-renderer',
'use-subscription',
'scheduler',
];
} else {
return [
'create-subscription',
'eslint-plugin-react-hooks',
'jest-react',
'react',
'react-art',
'react-dom',
'react-is',
'react-reconciler',
'react-refresh',
'react-test-renderer',
'use-subscription',
'scheduler',
];
}
};
const handleError = error => {
@@ -199,7 +198,8 @@ const splitCommaParams = array => {
// It is based on the version of React in the local package.json (e.g. 16.12.0-01974a867).
// Both numbers will be replaced if the "next" release is promoted to a stable release.
const updateVersionsForNext = async (cwd, reactVersion, version) => {
const packages = getPublicPackages(join(cwd, 'packages'));
const isExperimental = reactVersion.includes('experimental');
const packages = getPublicPackages(isExperimental);
const packagesDir = join(cwd, 'packages');
// Update the shared React version source file.