Update devtools-extensions build script to reflect changes in local b… (#21004)
Co-authored-by: Brian Vaughn <bvaughn@fb.com>
Hector Rincon committed
Mar 15, 2021 at 06:46 UTC
c06d245fc7325612347ed19232d92385cae2e0a7
4 files changed
+71
-10
packages/react-devtools-extensions/build.js
+39
-5
@@ -5,14 +5,47 @@
5
const archiver = require('archiver');
6
const {execSync} = require('child_process');
7
const {readFileSync, writeFileSync, createWriteStream} = require('fs');
8
-const {copy, ensureDir, move, remove} = require('fs-extra');
9
-const {join} = require('path');
8
+const {copy, ensureDir, move, remove, pathExistsSync} = require('fs-extra');
9
+const {join, resolve} = require('path');
10
const {getGitCommit} = require('./utils');
11
12
// These files are copied along with Webpack-bundled files
13
// to produce the final web extension
14
const STATIC_FILES = ['icons', 'popups', 'main.html', 'panel.html'];
15
16
+/**
17
+ * Ensures that a local build of the dependencies exist either by downloading
18
+ * or running a local build via one of the `react-build-fordevtools*` scripts.
19
+ */
20
+const ensureLocalBuild = async () => {
21
+ const buildDir = resolve(__dirname, '..', '..', 'build');
22
+ const nodeModulesDir = join(buildDir, 'node_modules');
23
+
24
+ // TODO: remove this check whenever the CI pipeline is complete.
25
+ // See build-all-release-channels.js
26
+ const currentBuildDir = resolve(
27
+ __dirname,
28
+ '..',
29
+ '..',
30
+ 'build2',
31
+ 'oss-experimental',
32
+ );
33
+
34
+ if (pathExistsSync(buildDir)) {
35
+ return; // all good.
36
+ }
37
+
38
+ if (pathExistsSync(currentBuildDir)) {
39
+ await ensureDir(buildDir);
40
+ await copy(currentBuildDir, nodeModulesDir);
41
+ return; // all good.
42
+ }
43
+
44
+ throw Error(
45
+ 'Could not find build artifacts in repo root. See README for prerequisites.',
46
+ );
47
+};
48
+
49
const preProcess = async (destinationPath, tempPath) => {
50
await remove(destinationPath); // Clean up from previously completed builds
51
await remove(tempPath); // Clean up from any previously failed builds
@@ -74,13 +107,13 @@ const build = async (tempPath, manifestPath) => {
107
// Pack the extension
108
const archive = archiver('zip', {zlib: {level: 9}});
109
const zipStream = createWriteStream(join(tempPath, 'ReactDevTools.zip'));
77
- await new Promise((resolve, reject) => {
110
+ await new Promise((resolvePromise, rejectPromise) => {
111
archive
112
.directory(zipPath, false)
80
- .on('error', err => reject(err))
113
+ .on('error', err => rejectPromise(err))
114
.pipe(zipStream);
115
archive.finalize();
83
- zipStream.on('close', () => resolve());
116
+ zipStream.on('close', () => resolvePromise());
117
});
118
};
119
@@ -102,6 +135,7 @@ const main = async buildId => {
135
136
try {
137
const tempPath = join(__dirname, 'build', buildId);
138
+ await ensureLocalBuild();
139
await preProcess(destinationPath, tempPath);
140
await build(tempPath, manifestPath);
141
packages/react-devtools-extensions/firefox/README.md
+1
-1
@@ -2,7 +2,7 @@
2
3
The source code for this extension has moved to `shells/webextension`.
4
5
-Modify the source code there and then rebuild this extension by running `node build` from this directory or `yarn run build:extension:firefox` from the root directory.
5
+Modify the source code there and then rebuild this extension by running `node build` from this directory or `yarn run build:firefox` from the root directory.
6
7
## Testing in Firefox
8
packages/react-devtools-extensions/firefox/test.js
+22
-3
@@ -10,13 +10,32 @@ const {argv} = require('yargs');
10
const EXTENSION_PATH = resolve('./firefox/build/unpacked');
11
const START_URL = argv.url || 'https://reactjs.org/';
12
13
+const firefoxVersion = process.env.WEB_EXT_FIREFOX;
14
+
15
+const getFirefoxProfileName = () => {
16
+ // Keys are pulled from https://extensionworkshop.com/documentation/develop/web-ext-command-reference/#--firefox
17
+ // and profile names from https://searchfox.org/mozilla-central/source/toolkit/profile/xpcshell/head.js#96
18
+ switch (firefoxVersion) {
19
+ case 'firefox':
20
+ return 'default-release';
21
+ case 'beta':
22
+ return 'default-beta';
23
+ case 'nightly':
24
+ return 'default-nightly';
25
+ case 'firefoxdeveloperedition':
26
+ return 'dev-edition-default';
27
+ default:
28
+ // Fall back to using the default Firefox profile for testing purposes.
29
+ // This prevents users from having to re-login-to sites before testing.
30
+ return 'default';
31
+ }
32
+};
33
+
34
const main = async () => {
35
const finder = new Finder();
36
16
- // Use default Firefox profile for testing purposes.
17
- // This prevents users from having to re-login-to sites before testing.
37
const findPathPromise = new Promise((resolvePromise, rejectPromise) => {
19
- finder.getPath('default', (error, profile) => {
38
+ finder.getPath(getFirefoxProfileName(), (error, profile) => {
39
if (error) {
40
rejectPromise(error);
41
} else {
scripts/rollup/build-all-release-channels.js
+9
-1
@@ -144,6 +144,13 @@ function crossDeviceRenameSync(source, destination) {
144
return fse.moveSync(source, destination, {overwrite: true});
145
}
146
147
+/*
148
+ * Grabs the built packages in ${tmp_build_dir}/node_modules and updates the
149
+ * `version` key in their package.json to 0.0.0-${commitHash} for the commit
150
+ * you're building. Also updates the dependencies and peerDependencies
151
+ * to match this version for all of the 'React' packages
152
+ * (packages available in this repo).
153
+ */
154
function updatePackageVersions(modulesDir, version) {
155
const allReactModuleNames = fs.readdirSync('packages');
156
for (const moduleName of fs.readdirSync(modulesDir)) {
@@ -155,9 +162,10 @@ function updatePackageVersions(modulesDir, version) {
162
// Update version
163
packageInfo.version = version;
164
158
- // Update dependency versions
165
if (packageInfo.dependencies) {
166
for (const dep of Object.keys(packageInfo.dependencies)) {
167
+ // if it's a react package (available in the current repo), update the version
168
+ // TODO: is this too broad? Assumes all of the packages were built.
169
if (allReactModuleNames.includes(dep)) {
170
packageInfo.dependencies[dep] = version;
171
}