Skip to content

Commit 6a4c8f5

Browse files
authored
[DevTools] Store Webpack stats when building extensions (#34514)
1 parent 16df13b commit 6a4c8f5

File tree

7 files changed

+71
-11
lines changed

7 files changed

+71
-11
lines changed

.github/workflows/devtools_regression_tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ jobs:
9292
uses: actions/upload-artifact@v4
9393
with:
9494
name: react-devtools
95-
path: build/devtools.tgz
95+
path: build/devtools
9696
if-no-files-found: error
9797
# Simplifies getting the extension for local testing
9898
- name: Archive chrome extension

.github/workflows/runtime_build_and_test.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,11 @@ jobs:
766766
name: react-devtools-${{ matrix.browser }}-extension
767767
path: build/devtools/${{ matrix.browser }}-extension.zip
768768
if-no-files-found: error
769+
- name: Archive ${{ matrix.browser }} metadata
770+
uses: actions/upload-artifact@v4
771+
with:
772+
name: react-devtools-${{ matrix.browser }}-metadata
773+
path: build/devtools/webpack-stats.*.json
769774

770775
merge_devtools_artifacts:
771776
name: Merge DevTools artifacts
@@ -776,7 +781,7 @@ jobs:
776781
uses: actions/upload-artifact/merge@v4
777782
with:
778783
name: react-devtools
779-
pattern: react-devtools-*-extension
784+
pattern: react-devtools-*
780785

781786
run_devtools_e2e_tests:
782787
name: Run DevTools e2e tests

packages/react-devtools-extensions/build.js

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const archiver = require('archiver');
66
const {execSync} = require('child_process');
77
const {readFileSync, writeFileSync, createWriteStream} = require('fs');
88
const {copy, ensureDir, move, remove, pathExistsSync} = require('fs-extra');
9-
const {join, resolve} = require('path');
9+
const {join, resolve, basename} = require('path');
1010
const {getGitCommit} = require('./utils');
1111

1212
// These files are copied along with Webpack-bundled files
@@ -80,8 +80,25 @@ const build = async (tempPath, manifestPath, envExtension = {}) => {
8080

8181
const copiedManifestPath = join(zipPath, 'manifest.json');
8282

83+
let webpackStatsFilePath = null;
8384
// Copy unbuilt source files to zip dir to be packaged:
84-
await copy(binPath, join(zipPath, 'build'));
85+
await copy(binPath, join(zipPath, 'build'), {
86+
filter: filePath => {
87+
if (basename(filePath).startsWith('webpack-stats.')) {
88+
webpackStatsFilePath = filePath;
89+
// The ZIP is the actual extension and doesn't need this metadata.
90+
return false;
91+
}
92+
return true;
93+
},
94+
});
95+
if (webpackStatsFilePath !== null) {
96+
await copy(
97+
webpackStatsFilePath,
98+
join(tempPath, basename(webpackStatsFilePath)),
99+
);
100+
webpackStatsFilePath = join(tempPath, basename(webpackStatsFilePath));
101+
}
85102
await copy(manifestPath, copiedManifestPath);
86103
await Promise.all(
87104
STATIC_FILES.map(file => copy(join(__dirname, file), join(zipPath, file))),
@@ -120,16 +137,26 @@ const build = async (tempPath, manifestPath, envExtension = {}) => {
120137
archive.finalize();
121138
zipStream.on('close', () => resolvePromise());
122139
});
140+
141+
return webpackStatsFilePath;
123142
};
124143

125-
const postProcess = async (tempPath, destinationPath) => {
144+
const postProcess = async (tempPath, destinationPath, webpackStatsFilePath) => {
126145
const unpackedSourcePath = join(tempPath, 'zip');
127146
const packedSourcePath = join(tempPath, 'ReactDevTools.zip');
128147
const packedDestPath = join(destinationPath, 'ReactDevTools.zip');
129148
const unpackedDestPath = join(destinationPath, 'unpacked');
130149

131150
await move(unpackedSourcePath, unpackedDestPath); // Copy built files to destination
132151
await move(packedSourcePath, packedDestPath); // Copy built files to destination
152+
if (webpackStatsFilePath !== null) {
153+
await move(
154+
webpackStatsFilePath,
155+
join(destinationPath, basename(webpackStatsFilePath)),
156+
);
157+
} else {
158+
console.log('No webpack-stats.json file was generated.');
159+
}
133160
await remove(tempPath); // Clean up temp directory and files
134161
};
135162

@@ -158,10 +185,14 @@ const main = async buildId => {
158185
const tempPath = join(__dirname, 'build', buildId);
159186
await ensureLocalBuild();
160187
await preProcess(destinationPath, tempPath);
161-
await build(tempPath, manifestPath, envExtension);
188+
const webpackStatsFilePath = await build(
189+
tempPath,
190+
manifestPath,
191+
envExtension,
192+
);
162193

163194
const builtUnpackedPath = join(destinationPath, 'unpacked');
164-
await postProcess(tempPath, destinationPath);
195+
await postProcess(tempPath, destinationPath, webpackStatsFilePath);
165196

166197
return builtUnpackedPath;
167198
} catch (error) {

packages/react-devtools-extensions/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
"webpack": "^5.82.1",
6666
"webpack-cli": "^5.1.1",
6767
"webpack-dev-server": "^4.15.0",
68+
"webpack-stats-plugin": "^1.1.3",
6869
"workerize-loader": "^2.0.2"
6970
},
7071
"dependencies": {

packages/react-devtools-extensions/webpack.config.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const TerserPlugin = require('terser-webpack-plugin');
66
const {GITHUB_URL, getVersionString} = require('./utils');
77
const {resolveFeatureFlags} = require('react-devtools-shared/buildUtils');
88
const SourceMapIgnoreListPlugin = require('react-devtools-shared/SourceMapIgnoreListPlugin');
9+
const {StatsWriterPlugin} = require('webpack-stats-plugin');
910

1011
const NODE_ENV = process.env.NODE_ENV;
1112
if (!NODE_ENV) {
@@ -37,6 +38,21 @@ const IS_INTERNAL_MCP_BUILD = process.env.IS_INTERNAL_MCP_BUILD === 'true';
3738

3839
const featureFlagTarget = process.env.FEATURE_FLAG_TARGET || 'extension-oss';
3940

41+
let statsFileName = `webpack-stats.${featureFlagTarget}.${__DEV__ ? 'development' : 'production'}`;
42+
if (IS_CHROME) {
43+
statsFileName += `.chrome`;
44+
}
45+
if (IS_FIREFOX) {
46+
statsFileName += `.firefox`;
47+
}
48+
if (IS_EDGE) {
49+
statsFileName += `.edge`;
50+
}
51+
if (IS_INTERNAL_MCP_BUILD) {
52+
statsFileName += `.mcp`;
53+
}
54+
statsFileName += '.json';
55+
4056
const babelOptions = {
4157
configFile: resolve(
4258
__dirname,
@@ -213,6 +229,10 @@ module.exports = {
213229
);
214230
},
215231
},
232+
new StatsWriterPlugin({
233+
stats: 'verbose',
234+
filename: statsFileName,
235+
}),
216236
],
217237
module: {
218238
defaultRules: [

scripts/ci/pack_and_store_devtools_artifacts.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,11 @@ cd ../react-devtools-extensions
2020
if [[ -n "$1" ]]; then
2121
yarn build:$1
2222
mv ./$1/build/ReactDevTools.zip ../../build/devtools/$1-extension.zip
23+
mv ./$1/build/webpack-stats.*.json ../../build/devtools/
2324
else
2425
yarn build
2526
for browser in chrome firefox edge; do
2627
mv ./$browser/build/ReactDevTools.zip ../../build/devtools/$browser-extension.zip
28+
mv ./$browser/build/webpack-stats.*.json ../../build/devtools/
2729
done
2830
fi
29-
30-
# Compress all DevTools artifacts into a single tarball for easy download
31-
cd ../../build/devtools
32-
tar -zcvf ../devtools.tgz .

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17792,6 +17792,11 @@ webpack-sources@^3.2.0, webpack-sources@^3.2.3:
1779217792
resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-3.2.3.tgz#2d4daab8451fd4b240cc27055ff6a0c2ccea0cde"
1779317793
integrity sha512-/DyMEOrDgLKKIG0fmvtz+4dUX/3Ghozwgm6iPp8KRhvn+eQf9+Q7GWxVNMk3+uCPWfdXYC4ExGBckIXdFEfH1w==
1779417794

17795+
webpack-stats-plugin@^1.1.3:
17796+
version "1.1.3"
17797+
resolved "https://registry.yarnpkg.com/webpack-stats-plugin/-/webpack-stats-plugin-1.1.3.tgz#ebcc36c8b468074ad737882e2043c1ce4b55d928"
17798+
integrity sha512-yUKYyy+e0iF/w31QdfioRKY+h3jDBRpthexBOWGKda99iu2l/wxYsI/XqdlP5IU58/0KB9CsJZgWNAl+/MPkRw==
17799+
1779517800
webpack@^5.82.1:
1779617801
version "5.82.1"
1779717802
resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.82.1.tgz#8f38c78e53467556e8a89054ebd3ef6e9f67dbab"

0 commit comments

Comments
 (0)