Skip to content

Commit c06d245

Browse files
hecerincBrian Vaughn
and
Brian Vaughn
authored
Update devtools-extensions build script to reflect changes in local b… (#21004)
Co-authored-by: Brian Vaughn <bvaughn@fb.com>
1 parent f227e7f commit c06d245

File tree

4 files changed

+71
-10
lines changed

4 files changed

+71
-10
lines changed

Diff for: packages/react-devtools-extensions/build.js

+39-5
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,47 @@
55
const archiver = require('archiver');
66
const {execSync} = require('child_process');
77
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');
1010
const {getGitCommit} = require('./utils');
1111

1212
// These files are copied along with Webpack-bundled files
1313
// to produce the final web extension
1414
const STATIC_FILES = ['icons', 'popups', 'main.html', 'panel.html'];
1515

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+
1649
const preProcess = async (destinationPath, tempPath) => {
1750
await remove(destinationPath); // Clean up from previously completed builds
1851
await remove(tempPath); // Clean up from any previously failed builds
@@ -74,13 +107,13 @@ const build = async (tempPath, manifestPath) => {
74107
// Pack the extension
75108
const archive = archiver('zip', {zlib: {level: 9}});
76109
const zipStream = createWriteStream(join(tempPath, 'ReactDevTools.zip'));
77-
await new Promise((resolve, reject) => {
110+
await new Promise((resolvePromise, rejectPromise) => {
78111
archive
79112
.directory(zipPath, false)
80-
.on('error', err => reject(err))
113+
.on('error', err => rejectPromise(err))
81114
.pipe(zipStream);
82115
archive.finalize();
83-
zipStream.on('close', () => resolve());
116+
zipStream.on('close', () => resolvePromise());
84117
});
85118
};
86119

@@ -102,6 +135,7 @@ const main = async buildId => {
102135

103136
try {
104137
const tempPath = join(__dirname, 'build', buildId);
138+
await ensureLocalBuild();
105139
await preProcess(destinationPath, tempPath);
106140
await build(tempPath, manifestPath);
107141

Diff for: packages/react-devtools-extensions/firefox/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
The source code for this extension has moved to `shells/webextension`.
44

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.
66

77
## Testing in Firefox
88

Diff for: packages/react-devtools-extensions/firefox/test.js

+22-3
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,32 @@ const {argv} = require('yargs');
1010
const EXTENSION_PATH = resolve('./firefox/build/unpacked');
1111
const START_URL = argv.url || 'https://reactjs.org/';
1212

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+
1334
const main = async () => {
1435
const finder = new Finder();
1536

16-
// Use default Firefox profile for testing purposes.
17-
// This prevents users from having to re-login-to sites before testing.
1837
const findPathPromise = new Promise((resolvePromise, rejectPromise) => {
19-
finder.getPath('default', (error, profile) => {
38+
finder.getPath(getFirefoxProfileName(), (error, profile) => {
2039
if (error) {
2140
rejectPromise(error);
2241
} else {

Diff for: scripts/rollup/build-all-release-channels.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,13 @@ function crossDeviceRenameSync(source, destination) {
144144
return fse.moveSync(source, destination, {overwrite: true});
145145
}
146146

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+
*/
147154
function updatePackageVersions(modulesDir, version) {
148155
const allReactModuleNames = fs.readdirSync('packages');
149156
for (const moduleName of fs.readdirSync(modulesDir)) {
@@ -155,9 +162,10 @@ function updatePackageVersions(modulesDir, version) {
155162
// Update version
156163
packageInfo.version = version;
157164

158-
// Update dependency versions
159165
if (packageInfo.dependencies) {
160166
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.
161169
if (allReactModuleNames.includes(dep)) {
162170
packageInfo.dependencies[dep] = version;
163171
}

0 commit comments

Comments
 (0)