Hardcoded allowlist for publishing packages (#20485)
With separate lists for stable and experimental.
Andrew Clark committed
Dec 18, 2020 at 16:20 UTC
1bda600378f08861f40e2ce2f146e52354b8ef13
7 files changed
+62
-46
scripts/release/build-release-locally-commands/add-build-info-json.js
+2
-1
@@ -12,7 +12,8 @@ const {getPublicPackages, logPromise} = require('../utils');
12
const theme = require('../theme');
13
14
const run = async ({branch, checksum, commit, reactVersion, tempDirectory}) => {
15
- const packages = getPublicPackages(join(tempDirectory, 'packages'));
15
+ const isExperimental = reactVersion.includes('experimental');
16
+ const packages = getPublicPackages(isExperimental);
17
const packagesDir = join(tempDirectory, 'packages');
18
19
const buildInfoJSON = {
scripts/release/ci-add-build-info-json.js
+2
-1
@@ -27,7 +27,8 @@ const run = async () => {
27
reactVersion,
28
} = await getBuildInfo();
29
30
- const packages = getPublicPackages(join(cwd, 'packages'));
30
+ const isExperimental = process.env.RELEASE_CHANNEL === 'experimental';
31
+ const packages = getPublicPackages(isExperimental);
32
const packagesDir = join(cwd, 'packages');
33
34
const buildInfoJSON = {
scripts/release/download-experimental-build.js
+1
-1
@@ -15,7 +15,7 @@ const run = async () => {
15
try {
16
const params = parseParams();
17
params.cwd = join(__dirname, '..', '..');
18
- params.packages = await getPublicPackages();
18
+ params.packages = await getPublicPackages(true);
19
20
if (!params.build) {
21
params.build = await getLatestMasterBuildNumber(true);
scripts/release/prepare-release-from-ci.js
+6
-1
@@ -3,6 +3,7 @@
3
'use strict';
4
5
const {join} = require('path');
6
+const {readJsonSync} = require('fs-extra');
7
const {getPublicPackages, handleError} = require('./utils');
8
9
const checkEnvironmentVariables = require('./shared-commands/check-environment-variables');
@@ -17,7 +18,6 @@ const run = async () => {
18
try {
19
const params = parseParams();
20
params.cwd = join(__dirname, '..', '..');
20
- params.packages = await getPublicPackages();
21
22
if (!params.build) {
23
params.build = await getLatestMasterBuildNumber(false);
@@ -26,6 +26,11 @@ const run = async () => {
26
await checkEnvironmentVariables(params);
27
await downloadBuildArtifacts(params);
28
29
+ const version = readJsonSync('./build/node_modules/react/package.json')
30
+ .version;
31
+ const isExperimental = version.includes('experimental');
32
+ params.packages = await getPublicPackages(isExperimental);
33
+
34
if (!params.skipTests) {
35
await testPackagingFixture(params);
36
await testTracingFixture(params);
scripts/release/prepare-release-from-npm.js
+9
-6
@@ -20,18 +20,21 @@ const run = async () => {
20
try {
21
const params = parseParams();
22
params.cwd = join(__dirname, '..', '..');
23
- params.packages = await getPublicPackages();
23
25
- // Map of package name to upcoming stable version.
26
- // This Map is initially populated with guesses based on local versions.
27
- // The developer running the release later confirms or overrides each version.
28
- const versionsMap = new Map();
24
+ const isExperimental = params.version.includes('experimental');
25
26
if (!params.version) {
27
params.version = await getLatestNextVersion();
28
}
29
34
- if (params.version.includes('experimental')) {
30
+ params.packages = await getPublicPackages(isExperimental);
31
+
32
+ // Map of package name to upcoming stable version.
33
+ // This Map is initially populated with guesses based on local versions.
34
+ // The developer running the release later confirms or overrides each version.
35
+ const versionsMap = new Map();
36
+
37
+ if (isExperimental) {
38
console.error(
39
theme.error`Cannot promote an experimental build to stable.`
40
);
scripts/release/publish.js
+7
-1
@@ -3,6 +3,7 @@
3
'use strict';
4
5
const {join} = require('path');
6
+const {readJsonSync} = require('fs-extra');
7
const {getPublicPackages, handleError} = require('./utils');
8
const theme = require('./theme');
9
@@ -20,8 +21,13 @@ const validateSkipPackages = require('./publish-commands/validate-skip-packages'
21
const run = async () => {
22
try {
23
const params = parseParams();
24
+
25
+ const version = readJsonSync('./build/node_modules/react/package.json')
26
+ .version;
27
+ const isExperimental = version.includes('experimental');
28
+
29
params.cwd = join(__dirname, '..', '..');
24
- params.packages = await getPublicPackages();
30
+ params.packages = await getPublicPackages(isExperimental);
31
32
// Pre-filter any skipped packages to simplify the following commands.
33
// As part of doing this we can also validate that none of the skipped packages were misspelled.
scripts/release/utils.js
+35
-35
@@ -3,7 +3,7 @@
3
const {exec} = require('child-process-promise');
4
const {createPatch} = require('diff');
5
const {hashElement} = require('folder-hash');
6
-const {readdirSync, readFileSync, statSync, writeFileSync} = require('fs');
6
+const {readFileSync, writeFileSync} = require('fs');
7
const {readJson, writeJson} = require('fs-extra');
8
const http = require('request-promise-json');
9
const logUpdate = require('log-update');
@@ -12,14 +12,6 @@ const createLogger = require('progress-estimator');
12
const prompt = require('prompt-promise');
13
const theme = require('./theme');
14
15
-// The following packages are published to NPM but not by this script.
16
-// They are released through a separate process.
17
-const RELEASE_SCRIPT_PACKAGE_SKIPLIST = [
18
- 'react-devtools',
19
- 'react-devtools-core',
20
- 'react-devtools-inline',
21
-];
22
-
15
// https://www.npmjs.com/package/progress-estimator#configuration
16
const logger = createLogger({
17
storagePath: join(__dirname, '.progress-estimator'),
@@ -112,31 +104,38 @@ const getChecksumForCurrentRevision = async cwd => {
104
return hashedPackages.hash.slice(0, 7);
105
};
106
115
-const getPublicPackages = () => {
116
- const packagesRoot = join(__dirname, '..', '..', 'packages');
117
-
118
- return readdirSync(packagesRoot).filter(dir => {
119
- if (RELEASE_SCRIPT_PACKAGE_SKIPLIST.includes(dir)) {
120
- return false;
121
- }
122
-
123
- const packagePath = join(packagesRoot, dir, 'package.json');
124
-
125
- if (dir.charAt(0) !== '.') {
126
- let stat;
127
- try {
128
- stat = statSync(packagePath);
129
- } catch (err) {
130
- return false;
131
- }
132
- if (stat.isFile()) {
133
- const packageJSON = JSON.parse(readFileSync(packagePath));
134
- return packageJSON.private !== true;
135
- }
136
- }
137
-
138
- return false;
139
- });
107
+const getPublicPackages = isExperimental => {
108
+ if (isExperimental) {
109
+ return [
110
+ 'create-subscription',
111
+ 'eslint-plugin-react-hooks',
112
+ 'jest-react',
113
+ 'react',
114
+ 'react-art',
115
+ 'react-dom',
116
+ 'react-is',
117
+ 'react-reconciler',
118
+ 'react-refresh',
119
+ 'react-test-renderer',
120
+ 'use-subscription',
121
+ 'scheduler',
122
+ ];
123
+ } else {
124
+ return [
125
+ 'create-subscription',
126
+ 'eslint-plugin-react-hooks',
127
+ 'jest-react',
128
+ 'react',
129
+ 'react-art',
130
+ 'react-dom',
131
+ 'react-is',
132
+ 'react-reconciler',
133
+ 'react-refresh',
134
+ 'react-test-renderer',
135
+ 'use-subscription',
136
+ 'scheduler',
137
+ ];
138
+ }
139
};
140
141
const handleError = error => {
@@ -199,7 +198,8 @@ const splitCommaParams = array => {
198
// It is based on the version of React in the local package.json (e.g. 16.12.0-01974a867).
199
// Both numbers will be replaced if the "next" release is promoted to a stable release.
200
const updateVersionsForNext = async (cwd, reactVersion, version) => {
202
- const packages = getPublicPackages(join(cwd, 'packages'));
201
+ const isExperimental = reactVersion.includes('experimental');
202
+ const packages = getPublicPackages(isExperimental);
203
const packagesDir = join(cwd, 'packages');
204
205
// Update the shared React version source file.