[ci] Cleanup forked build files
Unforks these scripts now that we are fully migrated to GH. ghstack-source-id: e1e15452f2d2e178a5b56203ebd0b42151e6a9ba Pull Request resolved: https://github.com/facebook/react/pull/30506
Lauren Tan committed
Jul 29, 2024 at 18:51 UTC
70885cfebec3adf4ff89f639f38302c57eda12ce
11 files changed
+148
-1130
.github/workflows/devtools_regression_tests.yml
+1
-1
@@ -37,7 +37,7 @@ jobs:
37
- name: Download react-devtools artifacts for base revision
38
run: |
39
git fetch origin main
40
- GH_TOKEN=${{ github.token }} scripts/release/download-experimental-build-ghaction.js --commit=$(git rev-parse origin/main)
40
+ GH_TOKEN=${{ github.token }} scripts/release/download-experimental-build.js --commit=$(git rev-parse origin/main)
41
- name: Display structure of build
42
run: ls -R build
43
- name: Archive build
.github/workflows/runtime_build_and_test.yml
+1
-1
@@ -549,7 +549,7 @@ jobs:
549
- name: Download artifacts for base revision
550
run: |
551
git fetch origin main
552
- GH_TOKEN=${{ github.token }} scripts/release/download-experimental-build-ghaction.js --commit=$(git rev-parse origin/main)
552
+ GH_TOKEN=${{ github.token }} scripts/release/download-experimental-build.js --commit=$(git rev-parse origin/main)
553
mv ./build ./base-build
554
# TODO: The `download-experimental-build` script copies the npm
555
# packages into the `node_modules` directory. This is a historical
.github/workflows/runtime_commit_artifacts.yml
+1
-1
@@ -72,7 +72,7 @@ jobs:
72
working-directory: scripts/release
73
- name: Download artifacts for base revision
74
run: |
75
- GH_TOKEN=${{ github.token }} scripts/release/download-experimental-build-ghaction.js --commit=${{ github.event.workflow_run.head_sha }}
75
+ GH_TOKEN=${{ github.token }} scripts/release/download-experimental-build.js --commit=${{ github.event.workflow_run.head_sha }}
76
- name: Display structure of build
77
run: ls -R build
78
- name: Strip @license from eslint plugin and react-refresh
scripts/release/download-experimental-build-ghaction.js
deleted
-59
@@ -1,59 +0,0 @@
1
-#!/usr/bin/env node
2
-
3
-'use strict';
4
-
5
-const {join, relative} = require('path');
6
-const {handleError} = require('./utils');
7
-const yargs = require('yargs');
8
-const clear = require('clear');
9
-const theme = require('./theme');
10
-const {
11
- downloadBuildArtifacts,
12
-} = require('./shared-commands/download-build-artifacts-ghaction');
13
-
14
-const argv = yargs.wrap(yargs.terminalWidth()).options({
15
- releaseChannel: {
16
- alias: 'r',
17
- describe: 'Download the given release channel.',
18
- requiresArg: true,
19
- type: 'string',
20
- choices: ['experimental', 'stable'],
21
- default: 'experimental',
22
- },
23
- commit: {
24
- alias: 'c',
25
- describe: 'Commit hash to download.',
26
- requiresArg: true,
27
- demandOption: true,
28
- type: 'string',
29
- },
30
-}).argv;
31
-
32
-function printSummary(commit) {
33
- const commandPath = relative(
34
- process.env.PWD,
35
- join(__dirname, '../download-experimental-build-ghaction.js')
36
- );
37
-
38
- clear();
39
-
40
- const message = theme`
41
- {caution An experimental build has been downloaded!}
42
-
43
- You can download this build again by running:
44
- {path ${commandPath}} --commit={commit ${commit}}
45
- `;
46
-
47
- console.log(message.replace(/\n +/g, '\n').trim());
48
-}
49
-
50
-const main = async () => {
51
- try {
52
- await downloadBuildArtifacts(argv.commit, argv.releaseChannel);
53
- printSummary(argv.commit);
54
- } catch (error) {
55
- handleError(error);
56
- }
57
-};
58
-
59
-main();
scripts/release/download-experimental-build.js
+48
-21
@@ -2,31 +2,58 @@
2
3
'use strict';
4
5
-const {join} = require('path');
5
+const {join, relative} = require('path');
6
+const {handleError} = require('./utils');
7
+const yargs = require('yargs');
8
+const clear = require('clear');
9
+const theme = require('./theme');
10
const {
7
- addDefaultParamValue,
8
- getPublicPackages,
9
- handleError,
10
-} = require('./utils');
11
-
12
-const downloadBuildArtifacts = require('./shared-commands/download-build-artifacts');
13
-const parseParams = require('./shared-commands/parse-params');
14
-const printSummary = require('./download-experimental-build-commands/print-summary');
15
-
16
-const run = async () => {
11
+ downloadBuildArtifacts,
12
+} = require('./shared-commands/download-build-artifacts');
13
+
14
+const argv = yargs.wrap(yargs.terminalWidth()).options({
15
+ releaseChannel: {
16
+ alias: 'r',
17
+ describe: 'Download the given release channel.',
18
+ requiresArg: true,
19
+ type: 'string',
20
+ choices: ['experimental', 'stable'],
21
+ default: 'experimental',
22
+ },
23
+ commit: {
24
+ alias: 'c',
25
+ describe: 'Commit hash to download.',
26
+ requiresArg: true,
27
+ demandOption: true,
28
+ type: 'string',
29
+ },
30
+}).argv;
31
+
32
+function printSummary(commit) {
33
+ const commandPath = relative(
34
+ process.env.PWD,
35
+ join(__dirname, '../download-experimental-build.js')
36
+ );
37
+
38
+ clear();
39
+
40
+ const message = theme`
41
+ {caution An experimental build has been downloaded!}
42
+
43
+ You can download this build again by running:
44
+ {path ${commandPath}} --commit={commit ${commit}}
45
+ `;
46
+
47
+ console.log(message.replace(/\n +/g, '\n').trim());
48
+}
49
+
50
+const main = async () => {
51
try {
18
- addDefaultParamValue('-r', '--releaseChannel', 'experimental');
19
-
20
- const params = await parseParams();
21
- params.cwd = join(__dirname, '..', '..');
22
- params.packages = await getPublicPackages(true);
23
-
24
- await downloadBuildArtifacts(params);
25
-
26
- printSummary(params);
52
+ await downloadBuildArtifacts(argv.commit, argv.releaseChannel);
53
+ printSummary(argv.commit);
54
} catch (error) {
55
handleError(error);
56
}
57
};
58
32
-run();
59
+main();
scripts/release/prepare-release-from-ci.js
+1
-1
@@ -7,7 +7,7 @@ const {addDefaultParamValue, handleError} = require('./utils');
7
8
const {
9
downloadBuildArtifacts,
10
-} = require('./shared-commands/download-build-artifacts-ghaction');
10
+} = require('./shared-commands/download-build-artifacts');
11
const parseParams = require('./shared-commands/parse-params');
12
const printPrereleaseSummary = require('./shared-commands/print-prerelease-summary');
13
const testPackagingFixture = require('./shared-commands/test-packaging-fixture');
scripts/release/shared-commands/download-build-artifacts-ghaction.js
deleted
-136
@@ -1,136 +0,0 @@
1
-'use strict';
2
-
3
-const {join} = require('path');
4
-const theme = require('../theme');
5
-const {exec} = require('child-process-promise');
6
-const {existsSync} = require('fs');
7
-const {logPromise} = require('../utils');
8
-
9
-if (process.env.GH_TOKEN == null) {
10
- console.log(
11
- theme`{error Expected GH_TOKEN to be provided as an env variable}`
12
- );
13
- process.exit(1);
14
-}
15
-
16
-const OWNER = 'facebook';
17
-const REPO = 'react';
18
-const WORKFLOW_ID = 'runtime_build_and_test.yml';
19
-const GITHUB_HEADERS = `
20
- -H "Accept: application/vnd.github+json" \
21
- -H "Authorization: Bearer ${process.env.GH_TOKEN}" \
22
- -H "X-GitHub-Api-Version: 2022-11-28"`.trim();
23
-
24
-function getWorkflowId() {
25
- if (
26
- existsSync(join(__dirname, `../../../.github/workflows/${WORKFLOW_ID}`))
27
- ) {
28
- return WORKFLOW_ID;
29
- } else {
30
- throw new Error(
31
- `Incorrect workflow ID: .github/workflows/${WORKFLOW_ID} does not exist. Please check the name of the workflow being downloaded from.`
32
- );
33
- }
34
-}
35
-
36
-async function getWorkflowRunId(commit) {
37
- const res = await exec(
38
- `curl -L ${GITHUB_HEADERS} https://api.github.com/repos/${OWNER}/${REPO}/actions/workflows/${getWorkflowId()}/runs?head_sha=${commit}&branch=main&exclude_pull_requests=true`
39
- );
40
-
41
- const json = JSON.parse(res.stdout);
42
- let workflowRun;
43
- if (json.total_count === 1) {
44
- workflowRun = json.workflow_runs[0];
45
- } else {
46
- workflowRun = json.workflow_runs.find(
47
- run => run.head_sha === commit && run.head_branch === 'main'
48
- );
49
- }
50
-
51
- if (workflowRun == null || workflowRun.id == null) {
52
- console.log(
53
- theme`{error The workflow run for the specified commit (${commit}) could not be found.}`
54
- );
55
- process.exit(1);
56
- }
57
-
58
- return workflowRun.id;
59
-}
60
-
61
-async function getArtifact(workflowRunId, artifactName) {
62
- const res = await exec(
63
- `curl -L ${GITHUB_HEADERS} https://api.github.com/repos/${OWNER}/${REPO}/actions/runs/${workflowRunId}/artifacts?per_page=100&name=${artifactName}`
64
- );
65
-
66
- const json = JSON.parse(res.stdout);
67
- let artifact;
68
- if (json.total_count === 1) {
69
- artifact = json.artifacts[0];
70
- } else {
71
- artifact = json.artifacts.find(
72
- _artifact => _artifact.name === artifactName
73
- );
74
- }
75
-
76
- if (artifact == null) {
77
- console.log(
78
- theme`{error The specified workflow run (${workflowRunId}) does not contain any build artifacts.}`
79
- );
80
- process.exit(1);
81
- }
82
-
83
- return artifact;
84
-}
85
-
86
-async function downloadArtifactsFromGitHub(commit, releaseChannel) {
87
- const workflowRunId = await getWorkflowRunId(commit);
88
- const artifact = await getArtifact(workflowRunId, 'artifacts_combined');
89
-
90
- // Download and extract artifact
91
- const cwd = join(__dirname, '..', '..', '..');
92
- await exec(`rm -rf ./build`, {cwd});
93
- await exec(
94
- `curl -L ${GITHUB_HEADERS} ${artifact.archive_download_url} \
95
- > a.zip && unzip a.zip -d . && rm a.zip build2.tgz && tar -xvzf build.tgz && rm build.tgz`,
96
- {
97
- cwd,
98
- }
99
- );
100
-
101
- // Copy to staging directory
102
- // TODO: Consider staging the release in a different directory from the CI
103
- // build artifacts: `./build/node_modules` -> `./staged-releases`
104
- if (!existsSync(join(cwd, 'build'))) {
105
- await exec(`mkdir ./build`, {cwd});
106
- } else {
107
- await exec(`rm -rf ./build/node_modules`, {cwd});
108
- }
109
- let sourceDir;
110
- // TODO: Rename release channel to `next`
111
- if (releaseChannel === 'stable') {
112
- sourceDir = 'oss-stable';
113
- } else if (releaseChannel === 'experimental') {
114
- sourceDir = 'oss-experimental';
115
- } else if (releaseChannel === 'rc') {
116
- sourceDir = 'oss-stable-rc';
117
- } else if (releaseChannel === 'latest') {
118
- sourceDir = 'oss-stable-semver';
119
- } else {
120
- console.error('Internal error: Invalid release channel: ' + releaseChannel);
121
- process.exit(releaseChannel);
122
- }
123
- await exec(`cp -r ./build/${sourceDir} ./build/node_modules`, {cwd});
124
-}
125
-
126
-async function downloadBuildArtifacts(commit, releaseChannel) {
127
- const label = theme`commit {commit ${commit}})`;
128
- return logPromise(
129
- downloadArtifactsFromGitHub(commit, releaseChannel),
130
- theme`Downloading artifacts from GitHub for ${label}`
131
- );
132
-}
133
-
134
-module.exports = {
135
- downloadBuildArtifacts,
136
-};
scripts/release/shared-commands/download-build-artifacts.js
+89
-28
@@ -1,36 +1,98 @@
1
-#!/usr/bin/env node
2
-
1
'use strict';
2
5
-const {exec} = require('child-process-promise');
6
-const {existsSync} = require('fs');
3
const {join} = require('path');
8
-const {getArtifactsList, logPromise} = require('../utils');
4
const theme = require('../theme');
5
+const {exec} = require('child-process-promise');
6
+const {existsSync} = require('fs');
7
+const {logPromise} = require('../utils');
8
+
9
+if (process.env.GH_TOKEN == null) {
10
+ console.log(
11
+ theme`{error Expected GH_TOKEN to be provided as an env variable}`
12
+ );
13
+ process.exit(1);
14
+}
15
+
16
+const OWNER = 'facebook';
17
+const REPO = 'react';
18
+const WORKFLOW_ID = 'runtime_build_and_test.yml';
19
+const GITHUB_HEADERS = `
20
+ -H "Accept: application/vnd.github+json" \
21
+ -H "Authorization: Bearer ${process.env.GH_TOKEN}" \
22
+ -H "X-GitHub-Api-Version: 2022-11-28"`.trim();
23
+
24
+function getWorkflowId() {
25
+ if (
26
+ existsSync(join(__dirname, `../../../.github/workflows/${WORKFLOW_ID}`))
27
+ ) {
28
+ return WORKFLOW_ID;
29
+ } else {
30
+ throw new Error(
31
+ `Incorrect workflow ID: .github/workflows/${WORKFLOW_ID} does not exist. Please check the name of the workflow being downloaded from.`
32
+ );
33
+ }
34
+}
35
11
-const run = async ({build, cwd, releaseChannel}) => {
12
- const artifacts = await getArtifactsList(build);
13
- const buildArtifacts = artifacts.find(entry =>
14
- entry.path.endsWith('build.tgz')
36
+async function getWorkflowRunId(commit) {
37
+ const res = await exec(
38
+ `curl -L ${GITHUB_HEADERS} https://api.github.com/repos/${OWNER}/${REPO}/actions/workflows/${getWorkflowId()}/runs?head_sha=${commit}&branch=main&exclude_pull_requests=true`
39
);
40
17
- if (!buildArtifacts) {
41
+ const json = JSON.parse(res.stdout);
42
+ let workflowRun;
43
+ if (json.total_count === 1) {
44
+ workflowRun = json.workflow_runs[0];
45
+ } else {
46
+ workflowRun = json.workflow_runs.find(
47
+ run => run.head_sha === commit && run.head_branch === 'main'
48
+ );
49
+ }
50
+
51
+ if (workflowRun == null || workflowRun.id == null) {
52
console.log(
19
- theme`{error The specified build (${build}) does not contain any build artifacts.}`
53
+ theme`{error The workflow run for the specified commit (${commit}) could not be found.}`
54
);
55
process.exit(1);
56
}
57
24
- // Download and extract artifact
25
- const {CIRCLE_CI_API_TOKEN} = process.env;
26
- let header = '';
27
- // Add Circle CI API token to request header if available.
28
- if (CIRCLE_CI_API_TOKEN != null) {
29
- header = '-H "Circle-Token: ${CIRCLE_CI_API_TOKEN}" ';
58
+ return workflowRun.id;
59
+}
60
+
61
+async function getArtifact(workflowRunId, artifactName) {
62
+ const res = await exec(
63
+ `curl -L ${GITHUB_HEADERS} https://api.github.com/repos/${OWNER}/${REPO}/actions/runs/${workflowRunId}/artifacts?per_page=100&name=${artifactName}`
64
+ );
65
+
66
+ const json = JSON.parse(res.stdout);
67
+ let artifact;
68
+ if (json.total_count === 1) {
69
+ artifact = json.artifacts[0];
70
+ } else {
71
+ artifact = json.artifacts.find(
72
+ _artifact => _artifact.name === artifactName
73
+ );
74
+ }
75
+
76
+ if (artifact == null) {
77
+ console.log(
78
+ theme`{error The specified workflow run (${workflowRunId}) does not contain any build artifacts.}`
79
+ );
80
+ process.exit(1);
81
}
82
+
83
+ return artifact;
84
+}
85
+
86
+async function downloadArtifactsFromGitHub(commit, releaseChannel) {
87
+ const workflowRunId = await getWorkflowRunId(commit);
88
+ const artifact = await getArtifact(workflowRunId, 'artifacts_combined');
89
+
90
+ // Download and extract artifact
91
+ const cwd = join(__dirname, '..', '..', '..');
92
await exec(`rm -rf ./build`, {cwd});
93
await exec(
33
- `curl -L $(fwdproxy-config curl) ${buildArtifacts.url} ${header}| tar -xvz`,
94
+ `curl -L ${GITHUB_HEADERS} ${artifact.archive_download_url} \
95
+ > a.zip && unzip a.zip -d . && rm a.zip build2.tgz && tar -xvzf build.tgz && rm build.tgz`,
96
{
97
cwd,
98
}
@@ -59,17 +121,16 @@ const run = async ({build, cwd, releaseChannel}) => {
121
process.exit(releaseChannel);
122
}
123
await exec(`cp -r ./build/${sourceDir} ./build/node_modules`, {cwd});
62
-};
124
+}
125
64
-module.exports = async ({build, commit, cwd, releaseChannel}) => {
65
- let buildLabel;
66
- if (commit !== null) {
67
- buildLabel = theme`commit {commit ${commit}} (build {build ${build}})`;
68
- } else {
69
- buildLabel = theme`build {build ${build}}`;
70
- }
126
+async function downloadBuildArtifacts(commit, releaseChannel) {
127
+ const label = theme`commit {commit ${commit}})`;
128
return logPromise(
72
- run({build, cwd, releaseChannel}),
73
- theme`Downloading artifacts from Circle CI for ${buildLabel}`
129
+ downloadArtifactsFromGitHub(commit, releaseChannel),
130
+ theme`Downloading artifacts from GitHub for ${label}`
131
);
132
+}
133
+
134
+module.exports = {
135
+ downloadBuildArtifacts,
136
};
scripts/rollup/build-all-release-channels.js
+4
-3
@@ -16,7 +16,6 @@ const {
16
rcNumber,
17
} = require('../../ReactVersions');
18
const yargs = require('yargs');
19
-const {buildEverything} = require('./build-ghaction');
19
const Bundles = require('./bundles');
20
21
// Runs the build script for both stable and experimental release channels,
@@ -111,7 +110,7 @@ const argv = yargs.wrap(yargs.terminalWidth()).options({
110
111
async function main() {
112
if (argv.ci === 'github') {
114
- await buildEverything(argv.index, argv.total);
113
+ buildForChannel(argv.releaseChannel, argv.total, argv.index);
114
switch (argv.releaseChannel) {
115
case 'stable': {
116
processStable('./build');
@@ -147,7 +146,7 @@ async function main() {
146
}
147
}
148
150
-function buildForChannel(channel) {
149
+function buildForChannel(channel, total, index) {
150
const {status} = spawnSync(
151
'node',
152
['./scripts/rollup/build.js', ...process.argv.slice(2)],
@@ -156,6 +155,8 @@ function buildForChannel(channel) {
155
env: {
156
...process.env,
157
RELEASE_CHANNEL: channel,
158
+ CI_TOTAL: total,
159
+ CI_INDEX: index,
160
},
161
}
162
);
scripts/rollup/build-ghaction.js
deleted
-875
@@ -1,875 +0,0 @@
1
-'use strict';
2
-
3
-const rollup = require('rollup');
4
-const babel = require('@rollup/plugin-babel').babel;
5
-const closure = require('./plugins/closure-plugin');
6
-const flowRemoveTypes = require('flow-remove-types');
7
-const prettier = require('rollup-plugin-prettier');
8
-const replace = require('@rollup/plugin-replace');
9
-const stripBanner = require('rollup-plugin-strip-banner');
10
-const chalk = require('chalk');
11
-const resolve = require('@rollup/plugin-node-resolve').nodeResolve;
12
-const fs = require('fs');
13
-const argv = require('minimist')(process.argv.slice(2));
14
-const Modules = require('./modules');
15
-const Bundles = require('./bundles');
16
-const Stats = require('./stats');
17
-const Sync = require('./sync');
18
-const sizes = require('./plugins/sizes-plugin');
19
-const useForks = require('./plugins/use-forks-plugin');
20
-const dynamicImports = require('./plugins/dynamic-imports');
21
-const Packaging = require('./packaging');
22
-const {asyncRimRaf} = require('./utils');
23
-const codeFrame = require('@babel/code-frame');
24
-const Wrappers = require('./wrappers');
25
-
26
-const RELEASE_CHANNEL = process.env.RELEASE_CHANNEL;
27
-
28
-// Default to building in experimental mode. If the release channel is set via
29
-// an environment variable, then check if it's "experimental".
30
-const __EXPERIMENTAL__ =
31
- typeof RELEASE_CHANNEL === 'string'
32
- ? RELEASE_CHANNEL === 'experimental'
33
- : true;
34
-
35
-// Errors in promises should be fatal.
36
-let loggedErrors = new Set();
37
-process.on('unhandledRejection', err => {
38
- if (loggedErrors.has(err)) {
39
- // No need to print it twice.
40
- process.exit(1);
41
- }
42
- throw err;
43
-});
44
-
45
-const {
46
- NODE_ES2015,
47
- ESM_DEV,
48
- ESM_PROD,
49
- NODE_DEV,
50
- NODE_PROD,
51
- NODE_PROFILING,
52
- BUN_DEV,
53
- BUN_PROD,
54
- FB_WWW_DEV,
55
- FB_WWW_PROD,
56
- FB_WWW_PROFILING,
57
- RN_OSS_DEV,
58
- RN_OSS_PROD,
59
- RN_OSS_PROFILING,
60
- RN_FB_DEV,
61
- RN_FB_PROD,
62
- RN_FB_PROFILING,
63
- BROWSER_SCRIPT,
64
-} = Bundles.bundleTypes;
65
-
66
-const {getFilename} = Bundles;
67
-
68
-function parseRequestedNames(names, toCase) {
69
- let result = [];
70
- for (let i = 0; i < names.length; i++) {
71
- let splitNames = names[i].split(',');
72
- for (let j = 0; j < splitNames.length; j++) {
73
- let name = splitNames[j].trim();
74
- if (!name) {
75
- continue;
76
- }
77
- if (toCase === 'uppercase') {
78
- name = name.toUpperCase();
79
- } else if (toCase === 'lowercase') {
80
- name = name.toLowerCase();
81
- }
82
- result.push(name);
83
- }
84
- }
85
- return result;
86
-}
87
-
88
-const argvType = Array.isArray(argv.type) ? argv.type : [argv.type];
89
-const requestedBundleTypes = argv.type
90
- ? parseRequestedNames(argvType, 'uppercase')
91
- : [];
92
-
93
-const requestedBundleNames = parseRequestedNames(argv._, 'lowercase');
94
-const forcePrettyOutput = argv.pretty;
95
-const isWatchMode = argv.watch;
96
-const syncFBSourcePath = argv['sync-fbsource'];
97
-const syncWWWPath = argv['sync-www'];
98
-
99
-// Non-ES2015 stuff applied before closure compiler.
100
-const babelPlugins = [
101
- // These plugins filter out non-ES2015.
102
- ['@babel/plugin-proposal-class-properties', {loose: true}],
103
- 'syntax-trailing-function-commas',
104
- // These use loose mode which avoids embedding a runtime.
105
- // TODO: Remove object spread from the source. Prefer Object.assign instead.
106
- [
107
- '@babel/plugin-proposal-object-rest-spread',
108
- {loose: true, useBuiltIns: true},
109
- ],
110
- ['@babel/plugin-transform-template-literals', {loose: true}],
111
- // TODO: Remove for...of from the source. It requires a runtime to be embedded.
112
- '@babel/plugin-transform-for-of',
113
- // TODO: Remove array spread from the source. Prefer .apply instead.
114
- ['@babel/plugin-transform-spread', {loose: true, useBuiltIns: true}],
115
- '@babel/plugin-transform-parameters',
116
- // TODO: Remove array destructuring from the source. Requires runtime.
117
- ['@babel/plugin-transform-destructuring', {loose: true, useBuiltIns: true}],
118
- // Transform Object spread to shared/assign
119
- require('../babel/transform-object-assign'),
120
-];
121
-
122
-const babelToES5Plugins = [
123
- // These plugins transform DEV mode. Closure compiler deals with these in PROD.
124
- '@babel/plugin-transform-literals',
125
- '@babel/plugin-transform-arrow-functions',
126
- '@babel/plugin-transform-block-scoped-functions',
127
- '@babel/plugin-transform-shorthand-properties',
128
- '@babel/plugin-transform-computed-properties',
129
- ['@babel/plugin-transform-block-scoping', {throwIfClosureRequired: true}],
130
-];
131
-
132
-function getBabelConfig(
133
- updateBabelOptions,
134
- bundleType,
135
- packageName,
136
- externals,
137
- isDevelopment,
138
- bundle
139
-) {
140
- const canAccessReactObject =
141
- packageName === 'react' || externals.indexOf('react') !== -1;
142
- let options = {
143
- exclude: '/**/node_modules/**',
144
- babelrc: false,
145
- configFile: false,
146
- presets: [],
147
- plugins: [...babelPlugins],
148
- babelHelpers: 'bundled',
149
- sourcemap: false,
150
- };
151
- if (isDevelopment) {
152
- options.plugins.push(...babelToES5Plugins);
153
- if (
154
- bundleType === FB_WWW_DEV ||
155
- bundleType === RN_OSS_DEV ||
156
- bundleType === RN_FB_DEV
157
- ) {
158
- options.plugins.push(
159
- // Turn console.error/warn() into a custom wrapper
160
- [
161
- require('../babel/transform-replace-console-calls'),
162
- {
163
- shouldError: !canAccessReactObject,
164
- },
165
- ]
166
- );
167
- }
168
- }
169
- if (updateBabelOptions) {
170
- options = updateBabelOptions(options);
171
- }
172
- // Controls whether to replace error messages with error codes in production.
173
- // By default, error messages are replaced in production.
174
- if (!isDevelopment && bundle.minifyWithProdErrorCodes !== false) {
175
- options.plugins.push(require('../error-codes/transform-error-messages'));
176
- }
177
-
178
- return options;
179
-}
180
-
181
-let getRollupInteropValue = id => {
182
- // We're setting Rollup to assume that imports are ES modules unless otherwise specified.
183
- // However, we also compile ES import syntax to `require()` using Babel.
184
- // This causes Rollup to turn uses of `import SomeDefaultImport from 'some-module' into
185
- // references to `SomeDefaultImport.default` due to CJS/ESM interop.
186
- // Some CJS modules don't have a `.default` export, and the rewritten import is incorrect.
187
- // Specifying `interop: 'default'` instead will have Rollup use the imported variable as-is,
188
- // without adding a `.default` to the reference.
189
- const modulesWithCommonJsExports = [
190
- 'art/core/transform',
191
- 'art/modes/current',
192
- 'art/modes/fast-noSideEffects',
193
- 'art/modes/svg',
194
- 'JSResourceReferenceImpl',
195
- 'error-stack-parser',
196
- 'neo-async',
197
- 'webpack/lib/dependencies/ModuleDependency',
198
- 'webpack/lib/dependencies/NullDependency',
199
- 'webpack/lib/Template',
200
- ];
201
-
202
- if (modulesWithCommonJsExports.includes(id)) {
203
- return 'default';
204
- }
205
-
206
- // For all other modules, handle imports without any import helper utils
207
- return 'esModule';
208
-};
209
-
210
-function getRollupOutputOptions(
211
- outputPath,
212
- format,
213
- globals,
214
- globalName,
215
- bundleType
216
-) {
217
- const isProduction = isProductionBundleType(bundleType);
218
-
219
- return {
220
- file: outputPath,
221
- format,
222
- globals,
223
- freeze: !isProduction,
224
- interop: getRollupInteropValue,
225
- name: globalName,
226
- sourcemap: false,
227
- esModule: false,
228
- exports: 'auto',
229
- };
230
-}
231
-
232
-function getFormat(bundleType) {
233
- switch (bundleType) {
234
- case NODE_ES2015:
235
- case NODE_DEV:
236
- case NODE_PROD:
237
- case NODE_PROFILING:
238
- case BUN_DEV:
239
- case BUN_PROD:
240
- case FB_WWW_DEV:
241
- case FB_WWW_PROD:
242
- case FB_WWW_PROFILING:
243
- case RN_OSS_DEV:
244
- case RN_OSS_PROD:
245
- case RN_OSS_PROFILING:
246
- case RN_FB_DEV:
247
- case RN_FB_PROD:
248
- case RN_FB_PROFILING:
249
- return `cjs`;
250
- case ESM_DEV:
251
- case ESM_PROD:
252
- return `es`;
253
- case BROWSER_SCRIPT:
254
- return `iife`;
255
- }
256
-}
257
-
258
-function isProductionBundleType(bundleType) {
259
- switch (bundleType) {
260
- case NODE_ES2015:
261
- return true;
262
- case ESM_DEV:
263
- case NODE_DEV:
264
- case BUN_DEV:
265
- case FB_WWW_DEV:
266
- case RN_OSS_DEV:
267
- case RN_FB_DEV:
268
- return false;
269
- case ESM_PROD:
270
- case NODE_PROD:
271
- case BUN_PROD:
272
- case NODE_PROFILING:
273
- case FB_WWW_PROD:
274
- case FB_WWW_PROFILING:
275
- case RN_OSS_PROD:
276
- case RN_OSS_PROFILING:
277
- case RN_FB_PROD:
278
- case RN_FB_PROFILING:
279
- case BROWSER_SCRIPT:
280
- return true;
281
- default:
282
- throw new Error(`Unknown type: ${bundleType}`);
283
- }
284
-}
285
-
286
-function isProfilingBundleType(bundleType) {
287
- switch (bundleType) {
288
- case NODE_ES2015:
289
- case FB_WWW_DEV:
290
- case FB_WWW_PROD:
291
- case NODE_DEV:
292
- case NODE_PROD:
293
- case BUN_DEV:
294
- case BUN_PROD:
295
- case RN_FB_DEV:
296
- case RN_FB_PROD:
297
- case RN_OSS_DEV:
298
- case RN_OSS_PROD:
299
- case ESM_DEV:
300
- case ESM_PROD:
301
- case BROWSER_SCRIPT:
302
- return false;
303
- case FB_WWW_PROFILING:
304
- case NODE_PROFILING:
305
- case RN_FB_PROFILING:
306
- case RN_OSS_PROFILING:
307
- return true;
308
- default:
309
- throw new Error(`Unknown type: ${bundleType}`);
310
- }
311
-}
312
-
313
-function getBundleTypeFlags(bundleType) {
314
- const isFBWWWBundle =
315
- bundleType === FB_WWW_DEV ||
316
- bundleType === FB_WWW_PROD ||
317
- bundleType === FB_WWW_PROFILING;
318
- const isRNBundle =
319
- bundleType === RN_OSS_DEV ||
320
- bundleType === RN_OSS_PROD ||
321
- bundleType === RN_OSS_PROFILING ||
322
- bundleType === RN_FB_DEV ||
323
- bundleType === RN_FB_PROD ||
324
- bundleType === RN_FB_PROFILING;
325
-
326
- const isFBRNBundle =
327
- bundleType === RN_FB_DEV ||
328
- bundleType === RN_FB_PROD ||
329
- bundleType === RN_FB_PROFILING;
330
-
331
- const shouldStayReadable = isFBWWWBundle || isRNBundle || forcePrettyOutput;
332
-
333
- return {
334
- isFBWWWBundle,
335
- isRNBundle,
336
- isFBRNBundle,
337
- shouldStayReadable,
338
- };
339
-}
340
-
341
-function forbidFBJSImports() {
342
- return {
343
- name: 'forbidFBJSImports',
344
- resolveId(importee, importer) {
345
- if (/^fbjs\//.test(importee)) {
346
- throw new Error(
347
- `Don't import ${importee} (found in ${importer}). ` +
348
- `Use the utilities in packages/shared/ instead.`
349
- );
350
- }
351
- },
352
- };
353
-}
354
-
355
-function getPlugins(
356
- entry,
357
- externals,
358
- updateBabelOptions,
359
- filename,
360
- packageName,
361
- bundleType,
362
- globalName,
363
- moduleType,
364
- pureExternalModules,
365
- bundle
366
-) {
367
- try {
368
- const forks = Modules.getForks(bundleType, entry, moduleType, bundle);
369
- const isProduction = isProductionBundleType(bundleType);
370
- const isProfiling = isProfilingBundleType(bundleType);
371
-
372
- const needsMinifiedByClosure =
373
- bundleType !== ESM_PROD && bundleType !== ESM_DEV;
374
-
375
- return [
376
- // Keep dynamic imports as externals
377
- dynamicImports(),
378
- {
379
- name: 'rollup-plugin-flow-remove-types',
380
- transform(code) {
381
- const transformed = flowRemoveTypes(code);
382
- return {
383
- code: transformed.toString(),
384
- map: null,
385
- };
386
- },
387
- },
388
- // Shim any modules that need forking in this environment.
389
- useForks(forks),
390
- // Ensure we don't try to bundle any fbjs modules.
391
- forbidFBJSImports(),
392
- // Use Node resolution mechanism.
393
- resolve({
394
- // skip: externals, // TODO: options.skip was removed in @rollup/plugin-node-resolve 3.0.0
395
- }),
396
- // Remove license headers from individual modules
397
- stripBanner({
398
- exclude: 'node_modules/**/*',
399
- }),
400
- // Compile to ES2015.
401
- babel(
402
- getBabelConfig(
403
- updateBabelOptions,
404
- bundleType,
405
- packageName,
406
- externals,
407
- !isProduction,
408
- bundle
409
- )
410
- ),
411
- // Remove 'use strict' from individual source files.
412
- {
413
- name: "remove 'use strict'",
414
- transform(source) {
415
- return source.replace(/['"]use strict["']/g, '');
416
- },
417
- },
418
- // Turn __DEV__ and process.env checks into constants.
419
- replace({
420
- preventAssignment: true,
421
- values: {
422
- __DEV__: isProduction ? 'false' : 'true',
423
- __PROFILE__: isProfiling || !isProduction ? 'true' : 'false',
424
- 'process.env.NODE_ENV': isProduction
425
- ? "'production'"
426
- : "'development'",
427
- __EXPERIMENTAL__,
428
- },
429
- }),
430
- {
431
- name: 'top-level-definitions',
432
- renderChunk(source) {
433
- return Wrappers.wrapWithTopLevelDefinitions(
434
- source,
435
- bundleType,
436
- globalName,
437
- filename,
438
- moduleType,
439
- bundle.wrapWithModuleBoundaries
440
- );
441
- },
442
- },
443
- // For production builds, compile with Closure. We do this even for the
444
- // "non-minified" production builds because Closure is much better at
445
- // minification than what most applications use. During this step, we do
446
- // preserve the original symbol names, though, so the resulting code is
447
- // relatively readable.
448
- //
449
- // For the minified builds, the names will be mangled later.
450
- //
451
- // We don't bother with sourcemaps at this step. The sourcemaps we publish
452
- // are only for whitespace and symbol renaming; they don't map back to
453
- // before Closure was applied.
454
- needsMinifiedByClosure &&
455
- closure({
456
- compilation_level: 'SIMPLE',
457
- language_in: 'ECMASCRIPT_2020',
458
- language_out:
459
- bundleType === NODE_ES2015
460
- ? 'ECMASCRIPT_2020'
461
- : bundleType === BROWSER_SCRIPT
462
- ? 'ECMASCRIPT5'
463
- : 'ECMASCRIPT5_STRICT',
464
- emit_use_strict:
465
- bundleType !== BROWSER_SCRIPT &&
466
- bundleType !== ESM_PROD &&
467
- bundleType !== ESM_DEV,
468
- env: 'CUSTOM',
469
- warning_level: 'QUIET',
470
- source_map_include_content: true,
471
- use_types_for_optimization: false,
472
- process_common_js_modules: false,
473
- rewrite_polyfills: false,
474
- inject_libraries: false,
475
- allow_dynamic_import: true,
476
-
477
- // Don't let it create global variables in the browser.
478
- // https://github.com/facebook/react/issues/10909
479
- assume_function_wrapper: true,
480
-
481
- // Don't rename symbols (variable names, functions, etc). We leave
482
- // this up to the application to handle, if they want. Otherwise gzip
483
- // takes care of it.
484
- renaming: false,
485
- }),
486
- needsMinifiedByClosure &&
487
- // Add the whitespace back
488
- prettier({
489
- parser: 'flow',
490
- singleQuote: false,
491
- trailingComma: 'none',
492
- bracketSpacing: true,
493
- }),
494
- {
495
- name: 'license-and-signature-header',
496
- renderChunk(source) {
497
- return Wrappers.wrapWithLicenseHeader(
498
- source,
499
- bundleType,
500
- globalName,
501
- filename,
502
- moduleType
503
- );
504
- },
505
- },
506
- // Record bundle size.
507
- sizes({
508
- getSize: (size, gzip) => {
509
- const currentSizes = Stats.currentBuildResults.bundleSizes;
510
- const recordIndex = currentSizes.findIndex(
511
- record =>
512
- record.filename === filename && record.bundleType === bundleType
513
- );
514
- const index = recordIndex !== -1 ? recordIndex : currentSizes.length;
515
- currentSizes[index] = {
516
- filename,
517
- bundleType,
518
- packageName,
519
- size,
520
- gzip,
521
- };
522
- },
523
- }),
524
- ].filter(Boolean);
525
- } catch (error) {
526
- console.error(
527
- chalk.red(`There was an error preparing plugins for entry "${entry}"`)
528
- );
529
- throw error;
530
- }
531
-}
532
-
533
-function shouldSkipBundle(bundle, bundleType) {
534
- const shouldSkipBundleType = bundle.bundleTypes.indexOf(bundleType) === -1;
535
- if (shouldSkipBundleType) {
536
- return true;
537
- }
538
- if (requestedBundleTypes.length > 0) {
539
- const isAskingForDifferentType = requestedBundleTypes.some(
540
- requestedType => !bundleType.includes(requestedType)
541
- );
542
- if (isAskingForDifferentType) {
543
- return true;
544
- }
545
- }
546
- if (requestedBundleNames.length > 0) {
547
- // If the name ends with `something/index` we only match if the
548
- // entry ends in something. Such as `react-dom/index` only matches
549
- // `react-dom` but not `react-dom/server`. Everything else is fuzzy
550
- // search.
551
- const entryLowerCase = bundle.entry.toLowerCase() + '/index.js';
552
- const isAskingForDifferentNames = requestedBundleNames.every(
553
- requestedName => {
554
- const matchEntry = entryLowerCase.indexOf(requestedName) !== -1;
555
- if (!bundle.name) {
556
- return !matchEntry;
557
- }
558
- const matchName =
559
- bundle.name.toLowerCase().indexOf(requestedName) !== -1;
560
- return !matchEntry && !matchName;
561
- }
562
- );
563
- if (isAskingForDifferentNames) {
564
- return true;
565
- }
566
- }
567
- return false;
568
-}
569
-
570
-function resolveEntryFork(resolvedEntry, isFBBundle) {
571
- // Pick which entry point fork to use:
572
- // .modern.fb.js
573
- // .classic.fb.js
574
- // .fb.js
575
- // .stable.js
576
- // .experimental.js
577
- // .js
578
- // or any of those plus .development.js
579
-
580
- if (isFBBundle) {
581
- const resolvedFBEntry = resolvedEntry.replace(
582
- '.js',
583
- __EXPERIMENTAL__ ? '.modern.fb.js' : '.classic.fb.js'
584
- );
585
- const developmentFBEntry = resolvedFBEntry.replace(
586
- '.js',
587
- '.development.js'
588
- );
589
- if (fs.existsSync(developmentFBEntry)) {
590
- return developmentFBEntry;
591
- }
592
- if (fs.existsSync(resolvedFBEntry)) {
593
- return resolvedFBEntry;
594
- }
595
- const resolvedGenericFBEntry = resolvedEntry.replace('.js', '.fb.js');
596
- const developmentGenericFBEntry = resolvedGenericFBEntry.replace(
597
- '.js',
598
- '.development.js'
599
- );
600
- if (fs.existsSync(developmentGenericFBEntry)) {
601
- return developmentGenericFBEntry;
602
- }
603
- if (fs.existsSync(resolvedGenericFBEntry)) {
604
- return resolvedGenericFBEntry;
605
- }
606
- // Even if it's a FB bundle we fallthrough to pick stable or experimental if we don't have an FB fork.
607
- }
608
- const resolvedForkedEntry = resolvedEntry.replace(
609
- '.js',
610
- __EXPERIMENTAL__ ? '.experimental.js' : '.stable.js'
611
- );
612
- const devForkedEntry = resolvedForkedEntry.replace('.js', '.development.js');
613
- if (fs.existsSync(devForkedEntry)) {
614
- return devForkedEntry;
615
- }
616
- if (fs.existsSync(resolvedForkedEntry)) {
617
- return resolvedForkedEntry;
618
- }
619
- // Just use the plain .js one.
620
- return resolvedEntry;
621
-}
622
-
623
-async function createBundle(bundle, bundleType) {
624
- const filename = getFilename(bundle, bundleType);
625
- const logKey =
626
- chalk.white.bold(filename) + chalk.dim(` (${bundleType.toLowerCase()})`);
627
- const format = getFormat(bundleType);
628
- const packageName = Packaging.getPackageName(bundle.entry);
629
-
630
- const {isFBWWWBundle, isFBRNBundle} = getBundleTypeFlags(bundleType);
631
-
632
- let resolvedEntry = resolveEntryFork(
633
- require.resolve(bundle.entry),
634
- isFBWWWBundle || isFBRNBundle,
635
- !isProductionBundleType(bundleType)
636
- );
637
-
638
- const peerGlobals = Modules.getPeerGlobals(bundle.externals, bundleType);
639
- let externals = Object.keys(peerGlobals);
640
-
641
- const deps = Modules.getDependencies(bundleType, bundle.entry);
642
- externals = externals.concat(deps);
643
-
644
- const importSideEffects = Modules.getImportSideEffects();
645
- const pureExternalModules = Object.keys(importSideEffects).filter(
646
- module => !importSideEffects[module]
647
- );
648
-
649
- const rollupConfig = {
650
- input: resolvedEntry,
651
- treeshake: {
652
- moduleSideEffects: (id, external) =>
653
- !(external && pureExternalModules.includes(id)),
654
- propertyReadSideEffects: false,
655
- },
656
- external(id) {
657
- const containsThisModule = pkg => id === pkg || id.startsWith(pkg + '/');
658
- const isProvidedByDependency = externals.some(containsThisModule);
659
- if (isProvidedByDependency) {
660
- if (id.indexOf('/src/') !== -1) {
661
- throw Error(
662
- 'You are trying to import ' +
663
- id +
664
- ' but ' +
665
- externals.find(containsThisModule) +
666
- ' is one of npm dependencies, ' +
667
- 'so it will not contain that source file. You probably want ' +
668
- 'to create a new bundle entry point for it instead.'
669
- );
670
- }
671
- return true;
672
- }
673
- return !!peerGlobals[id];
674
- },
675
- onwarn: handleRollupWarning,
676
- plugins: getPlugins(
677
- bundle.entry,
678
- externals,
679
- bundle.babel,
680
- filename,
681
- packageName,
682
- bundleType,
683
- bundle.global,
684
- bundle.moduleType,
685
- pureExternalModules,
686
- bundle
687
- ),
688
- output: {
689
- externalLiveBindings: false,
690
- freeze: false,
691
- interop: getRollupInteropValue,
692
- esModule: false,
693
- },
694
- };
695
- const mainOutputPath = Packaging.getBundleOutputPath(
696
- bundle,
697
- bundleType,
698
- filename,
699
- packageName
700
- );
701
-
702
- const rollupOutputOptions = getRollupOutputOptions(
703
- mainOutputPath,
704
- format,
705
- peerGlobals,
706
- bundle.global,
707
- bundleType
708
- );
709
-
710
- if (isWatchMode) {
711
- rollupConfig.output = [rollupOutputOptions];
712
- const watcher = rollup.watch(rollupConfig);
713
- watcher.on('event', async event => {
714
- switch (event.code) {
715
- case 'BUNDLE_START':
716
- console.log(`${chalk.bgYellow.black(' BUILDING ')} ${logKey}`);
717
- break;
718
- case 'BUNDLE_END':
719
- console.log(`${chalk.bgGreen.black(' COMPLETE ')} ${logKey}\n`);
720
- break;
721
- case 'ERROR':
722
- case 'FATAL':
723
- console.log(`${chalk.bgRed.black(' OH NOES! ')} ${logKey}\n`);
724
- handleRollupError(event.error);
725
- break;
726
- }
727
- });
728
- } else {
729
- console.log(`${chalk.bgYellow.black(' BUILDING ')} ${logKey}`);
730
- try {
731
- const result = await rollup.rollup(rollupConfig);
732
- await result.write(rollupOutputOptions);
733
- } catch (error) {
734
- console.log(`${chalk.bgRed.black(' OH NOES! ')} ${logKey}\n`);
735
- handleRollupError(error);
736
- throw error;
737
- }
738
- console.log(`${chalk.bgGreen.black(' COMPLETE ')} ${logKey}\n`);
739
- }
740
-}
741
-
742
-function handleRollupWarning(warning) {
743
- if (warning.code === 'UNUSED_EXTERNAL_IMPORT') {
744
- const match = warning.message.match(/external module "([^"]+)"/);
745
- if (!match || typeof match[1] !== 'string') {
746
- throw new Error(
747
- 'Could not parse a Rollup warning. ' + 'Fix this method.'
748
- );
749
- }
750
- const importSideEffects = Modules.getImportSideEffects();
751
- const externalModule = match[1];
752
- if (typeof importSideEffects[externalModule] !== 'boolean') {
753
- throw new Error(
754
- 'An external module "' +
755
- externalModule +
756
- '" is used in a DEV-only code path ' +
757
- 'but we do not know if it is safe to omit an unused require() to it in production. ' +
758
- 'Please add it to the `importSideEffects` list in `scripts/rollup/modules.js`.'
759
- );
760
- }
761
- // Don't warn. We will remove side effectless require() in a later pass.
762
- return;
763
- }
764
-
765
- if (warning.code === 'CIRCULAR_DEPENDENCY') {
766
- // Ignored
767
- } else if (typeof warning.code === 'string') {
768
- // This is a warning coming from Rollup itself.
769
- // These tend to be important (e.g. clashes in namespaced exports)
770
- // so we'll fail the build on any of them.
771
- console.error();
772
- console.error(warning.message || warning);
773
- console.error();
774
- process.exit(1);
775
- } else {
776
- // The warning is from one of the plugins.
777
- // Maybe it's not important, so just print it.
778
- console.warn(warning.message || warning);
779
- }
780
-}
781
-
782
-function handleRollupError(error) {
783
- loggedErrors.add(error);
784
- if (!error.code) {
785
- console.error(error);
786
- return;
787
- }
788
- console.error(
789
- `\x1b[31m-- ${error.code}${error.plugin ? ` (${error.plugin})` : ''} --`
790
- );
791
- console.error(error.stack);
792
- if (error.loc && error.loc.file) {
793
- const {file, line, column} = error.loc;
794
- // This looks like an error from Rollup, e.g. missing export.
795
- // We'll use the accurate line numbers provided by Rollup but
796
- // use Babel code frame because it looks nicer.
797
- const rawLines = fs.readFileSync(file, 'utf-8');
798
- // column + 1 is required due to rollup counting column start position from 0
799
- // whereas babel-code-frame counts from 1
800
- const frame = codeFrame(rawLines, line, column + 1, {
801
- highlightCode: true,
802
- });
803
- console.error(frame);
804
- } else if (error.codeFrame) {
805
- // This looks like an error from a plugin (e.g. Babel).
806
- // In this case we'll resort to displaying the provided code frame
807
- // because we can't be sure the reported location is accurate.
808
- console.error(error.codeFrame);
809
- }
810
-}
811
-
812
-async function buildEverything(index, total) {
813
- if (!argv['unsafe-partial']) {
814
- await asyncRimRaf('build');
815
- }
816
-
817
- // Run them serially for better console output
818
- // and to avoid any potential race conditions.
819
-
820
- let bundles = [];
821
- // eslint-disable-next-line no-for-of-loops/no-for-of-loops
822
- for (const bundle of Bundles.bundles) {
823
- bundles.push(
824
- [bundle, NODE_ES2015],
825
- [bundle, ESM_DEV],
826
- [bundle, ESM_PROD],
827
- [bundle, NODE_DEV],
828
- [bundle, NODE_PROD],
829
- [bundle, NODE_PROFILING],
830
- [bundle, BUN_DEV],
831
- [bundle, BUN_PROD],
832
- [bundle, FB_WWW_DEV],
833
- [bundle, FB_WWW_PROD],
834
- [bundle, FB_WWW_PROFILING],
835
- [bundle, RN_OSS_DEV],
836
- [bundle, RN_OSS_PROD],
837
- [bundle, RN_OSS_PROFILING],
838
- [bundle, RN_FB_DEV],
839
- [bundle, RN_FB_PROD],
840
- [bundle, RN_FB_PROFILING],
841
- [bundle, BROWSER_SCRIPT]
842
- );
843
- }
844
-
845
- bundles = bundles.filter(([bundle, bundleType]) => {
846
- return !shouldSkipBundle(bundle, bundleType);
847
- });
848
-
849
- const nodeTotal = parseInt(total, 10);
850
- const nodeIndex = parseInt(index, 10);
851
- bundles = bundles.filter((_, i) => i % nodeTotal === nodeIndex);
852
-
853
- // eslint-disable-next-line no-for-of-loops/no-for-of-loops
854
- for (const [bundle, bundleType] of bundles) {
855
- await createBundle(bundle, bundleType);
856
- }
857
-
858
- await Packaging.copyAllShims();
859
- await Packaging.prepareNpmPackages();
860
-
861
- if (syncFBSourcePath) {
862
- await Sync.syncReactNative(syncFBSourcePath);
863
- } else if (syncWWWPath) {
864
- await Sync.syncReactDom('build/facebook-www', syncWWWPath);
865
- }
866
-
867
- console.log(Stats.printResults());
868
- if (!forcePrettyOutput) {
869
- Stats.saveResults();
870
- }
871
-}
872
-
873
-module.exports = {
874
- buildEverything,
875
-};
scripts/rollup/build.js
+3
-4
@@ -850,10 +850,9 @@ async function buildEverything() {
850
return !shouldSkipBundle(bundle, bundleType);
851
});
852
853
- if (process.env.CIRCLE_NODE_TOTAL) {
854
- // In CI, parallelize bundles across multiple tasks.
855
- const nodeTotal = parseInt(process.env.CIRCLE_NODE_TOTAL, 10);
856
- const nodeIndex = parseInt(process.env.CIRCLE_NODE_INDEX, 10);
853
+ if (process.env.CI_TOTAL && process.env.CI_INDEX) {
854
+ const nodeTotal = parseInt(process.env.CI_TOTAL, 10);
855
+ const nodeIndex = parseInt(process.env.CI_INDEX, 10);
856
bundles = bundles.filter((_, i) => i % nodeTotal === nodeIndex);
857
}
858