Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update devtools-extensions build script to reflect changes in local b… #21004

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 38 additions & 4 deletions packages/react-devtools-extensions/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,47 @@
const archiver = require('archiver');
const {execSync} = require('child_process');
const {readFileSync, writeFileSync, createWriteStream} = require('fs');
const {copy, ensureDir, move, remove} = require('fs-extra');
const {join} = require('path');
const {copy, ensureDir, move, remove, pathExistsSync} = require('fs-extra');
const {join, resolve} = require('path');
const {getGitCommit} = require('./utils');

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

/**
* Ensures that a local build of the dependencies exist either by downloading
* or running a local build via one of the `react-build-fordevtools*` scripts.
*/
const ensureLocalBuild = async () => {
const buildDir = resolve(__dirname, '..', '..', 'build');
const nodeModulesDir = join(buildDir, 'node_modules');

// TODO: remove this check whenever the CI pipeline is complete.
// See build-all-release-channels.js
const currentBuildDir = resolve(
__dirname,
'..',
'..',
'build2',
'oss-experimental',
);

if (pathExistsSync(buildDir)) {
return; // all good.
}

if (pathExistsSync(currentBuildDir)) {
await ensureDir(buildDir);
await copy(currentBuildDir, nodeModulesDir);
return; // all good.
}
Comment on lines +38 to +42
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice addition. Thanks!


throw Error(
'Could not find build artifacts in repo root. See README for prerequisites.',
);
};

const preProcess = async (destinationPath, tempPath) => {
await remove(destinationPath); // Clean up from previously completed builds
await remove(tempPath); // Clean up from any previously failed builds
Expand Down Expand Up @@ -74,13 +107,13 @@ const build = async (tempPath, manifestPath) => {
// Pack the extension
const archive = archiver('zip', {zlib: {level: 9}});
const zipStream = createWriteStream(join(tempPath, 'ReactDevTools.zip'));
await new Promise((resolve, reject) => {
await new Promise((resolvePromise, reject) => {
archive
.directory(zipPath, false)
.on('error', err => reject(err))
.pipe(zipStream);
archive.finalize();
zipStream.on('close', () => resolve());
zipStream.on('close', () => resolvePromise());
});
};

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

try {
const tempPath = join(__dirname, 'build', buildId);
await ensureLocalBuild();
await preProcess(destinationPath, tempPath);
await build(tempPath, manifestPath);

Expand Down
2 changes: 1 addition & 1 deletion packages/react-devtools-extensions/firefox/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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

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

## Testing in Firefox

Expand Down
21 changes: 20 additions & 1 deletion packages/react-devtools-extensions/firefox/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,32 @@ const {argv} = require('yargs');
const EXTENSION_PATH = resolve('./firefox/build/unpacked');
const START_URL = argv.url || 'https://reactjs.org/';

const ffVersion = process.env.WEB_EXT_FIREFOX;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit I generally like to avoid abbreviations in variable names like "ff". Totally not a big deal given the context of this change, but for consistency elsewhere I might rename this one before merging.


const getFFProfileName = () => {
// Keys are pulled from https://extensionworkshop.com/documentation/develop/web-ext-command-reference/#--firefox
// and profile names from https://searchfox.org/mozilla-central/source/toolkit/profile/xpcshell/head.js#96
switch (ffVersion) {
case 'firefox':
return 'default-release';
case 'beta':
return 'default-beta';
case 'nightly':
return 'default-nightly';
case 'firefoxdeveloperedition':
return 'dev-edition-default';
default:
return 'default';
}
};

const main = async () => {
const finder = new Finder();

// Use default Firefox profile for testing purposes.
// This prevents users from having to re-login-to sites before testing.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit This comment should be moved into the switch above. (I'll do this.)

const findPathPromise = new Promise((resolvePromise, rejectPromise) => {
finder.getPath('default', (error, profile) => {
finder.getPath(getFFProfileName(), (error, profile) => {
if (error) {
rejectPromise(error);
} else {
Expand Down
11 changes: 11 additions & 0 deletions scripts/rollup/build-all-release-channels.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@ function crossDeviceRenameSync(source, destination) {
return fse.moveSync(source, destination, {overwrite: true});
}

/*
* Grabs the built packages in ${tmp_build_dir}/node_modules and updates the
* `version` key in their package.json to 0.0.0-${commitHash} for the commit
* you're building. Also updates the dependencies and peerDependencies
* to match this version for all of the 'React' packages
* (packages available in this repo).
*/
function updatePackageVersions(modulesDir, version) {
const allReactModuleNames = fs.readdirSync('packages');
for (const moduleName of fs.readdirSync(modulesDir)) {
Expand All @@ -157,12 +164,16 @@ function updatePackageVersions(modulesDir, version) {

// Update dependency versions
if (packageInfo.dependencies) {
// Check everything under dependencies
for (const dep of Object.keys(packageInfo.dependencies)) {
// if it's a react package (available in the current repo), update the version
// TODO: is this too broad? Assumes all of the packages were built.
if (allReactModuleNames.includes(dep)) {
packageInfo.dependencies[dep] = version;
}
}
}
// Do the same for peerDeps
if (packageInfo.peerDependencies) {
for (const dep of Object.keys(packageInfo.peerDependencies)) {
if (allReactModuleNames.includes(dep)) {
Expand Down