Skip to content

Commit

Permalink
Hardcoded allowlist for publishing packages
Browse files Browse the repository at this point in the history
With separate lists for stable and experimental.
  • Loading branch information
acdlite committed Dec 18, 2020
1 parent efc57e5 commit 27e7e9b
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
3 changes: 2 additions & 1 deletion scripts/release/ci-add-build-info-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion scripts/release/download-experimental-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 6 additions & 1 deletion scripts/release/prepare-release-from-ci.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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);
Expand All @@ -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);
Expand Down
15 changes: 9 additions & 6 deletions scripts/release/prepare-release-from-npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,21 @@ const run = async () => {
try {
const params = parseParams();
params.cwd = join(__dirname, '..', '..');
params.packages = await getPublicPackages();

// 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();
const isExperimental = params.version.includes('experimental');

if (!params.version) {
params.version = await getLatestNextVersion();
}

if (params.version.includes('experimental')) {
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 (isExperimental) {
console.error(
theme.error`Cannot promote an experimental build to stable.`
);
Expand Down
8 changes: 7 additions & 1 deletion scripts/release/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
'use strict';

const {join} = require('path');
const {readJsonSync} = require('fs-extra');
const {getPublicPackages, handleError} = require('./utils');
const theme = require('./theme');

Expand All @@ -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.
Expand Down
70 changes: 35 additions & 35 deletions scripts/release/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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'),
Expand Down Expand Up @@ -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 => {
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 27e7e9b

Please sign in to comment.