2019-08-13 21:59:07 -07:00
|
|
|
'use strict';
|
|
|
|
|
|
2024-06-17 11:58:19 +01:00
|
|
|
const {resolve, isAbsolute, relative} = require('path');
|
2023-06-14 13:15:52 +01:00
|
|
|
const Webpack = require('webpack');
|
2023-08-29 12:09:13 +01:00
|
|
|
const TerserPlugin = require('terser-webpack-plugin');
|
2024-06-17 16:31:36 +01:00
|
|
|
const {GITHUB_URL, getVersionString} = require('./utils');
|
2020-10-12 22:07:10 +05:00
|
|
|
const {resolveFeatureFlags} = require('react-devtools-shared/buildUtils');
|
2024-04-08 18:10:09 +01:00
|
|
|
const SourceMapIgnoreListPlugin = require('react-devtools-shared/SourceMapIgnoreListPlugin');
|
2025-09-17 15:03:12 +02:00
|
|
|
const {StatsWriterPlugin} = require('webpack-stats-plugin');
|
2019-01-22 11:04:37 -08:00
|
|
|
|
2019-03-26 13:22:55 -07:00
|
|
|
const NODE_ENV = process.env.NODE_ENV;
|
2019-04-18 18:13:34 -07:00
|
|
|
if (!NODE_ENV) {
|
|
|
|
|
console.error('NODE_ENV not set');
|
|
|
|
|
process.exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-21 11:51:51 -04:00
|
|
|
const builtModulesDir = resolve(
|
|
|
|
|
__dirname,
|
|
|
|
|
'..',
|
|
|
|
|
'..',
|
2021-09-21 15:12:52 -04:00
|
|
|
'build',
|
2021-09-21 11:51:51 -04:00
|
|
|
'oss-experimental',
|
|
|
|
|
);
|
2019-08-14 09:24:35 -07:00
|
|
|
|
2019-04-18 14:45:24 -07:00
|
|
|
const __DEV__ = NODE_ENV === 'development';
|
2019-01-22 11:04:37 -08:00
|
|
|
|
2021-10-27 17:18:48 -04:00
|
|
|
const DEVTOOLS_VERSION = getVersionString(process.env.DEVTOOLS_VERSION);
|
2019-02-12 20:41:39 -05:00
|
|
|
|
2021-11-03 08:27:30 -07:00
|
|
|
const EDITOR_URL = process.env.EDITOR_URL || null;
|
2021-09-30 13:47:14 -04:00
|
|
|
const LOGGING_URL = process.env.LOGGING_URL || null;
|
|
|
|
|
|
2023-08-29 10:40:02 +01:00
|
|
|
const IS_CHROME = process.env.IS_CHROME === 'true';
|
|
|
|
|
const IS_FIREFOX = process.env.IS_FIREFOX === 'true';
|
|
|
|
|
const IS_EDGE = process.env.IS_EDGE === 'true';
|
feat[devtools]: symbolicate source for inspected element (#28471)
Stacked on https://github.com/facebook/react/pull/28351, please review
only the last commit.
Top-level description of the approach:
1. Once user selects an element from the tree, frontend asks backend to
return the inspected element, this is where we simulate an error
happening in `render` function of the component and then we parse the
error stack. As an improvement, we should probably migrate from custom
implementation of error stack parser to `error-stack-parser` from npm.
2. When frontend receives the inspected element and this object is being
propagated, we create a Promise for symbolicated source, which is then
passed down to all components, which are using `source`.
3. These components use `use` hook for this promise and are wrapped in
Suspense.
Caching:
1. For browser extension, we cache Promises based on requested resource
+ key + column, also added use of
`chrome.devtools.inspectedWindow.getResource` API.
2. For standalone case (RN), we cache based on requested resource url,
we cache the content of it.
2024-03-05 12:32:11 +00:00
|
|
|
const IS_INTERNAL_VERSION = process.env.FEATURE_FLAG_TARGET === 'extension-fb';
|
2023-08-29 10:40:02 +01:00
|
|
|
|
2021-03-17 12:28:21 -04:00
|
|
|
const featureFlagTarget = process.env.FEATURE_FLAG_TARGET || 'extension-oss';
|
|
|
|
|
|
2025-09-17 15:03:12 +02:00
|
|
|
let statsFileName = `webpack-stats.${featureFlagTarget}.${__DEV__ ? 'development' : 'production'}`;
|
|
|
|
|
if (IS_CHROME) {
|
|
|
|
|
statsFileName += `.chrome`;
|
|
|
|
|
}
|
|
|
|
|
if (IS_FIREFOX) {
|
|
|
|
|
statsFileName += `.firefox`;
|
|
|
|
|
}
|
|
|
|
|
if (IS_EDGE) {
|
|
|
|
|
statsFileName += `.edge`;
|
|
|
|
|
}
|
|
|
|
|
statsFileName += '.json';
|
|
|
|
|
|
2021-07-22 13:58:57 -04:00
|
|
|
const babelOptions = {
|
|
|
|
|
configFile: resolve(
|
|
|
|
|
__dirname,
|
|
|
|
|
'..',
|
|
|
|
|
'react-devtools-shared',
|
|
|
|
|
'babel.config.js',
|
|
|
|
|
),
|
|
|
|
|
};
|
|
|
|
|
|
2019-01-22 11:04:37 -08:00
|
|
|
module.exports = {
|
|
|
|
|
mode: __DEV__ ? 'development' : 'production',
|
2024-04-08 18:10:09 +01:00
|
|
|
devtool: false,
|
2019-01-22 11:04:37 -08:00
|
|
|
entry: {
|
2025-09-17 15:45:25 +02:00
|
|
|
backend: './src/backend.js',
|
2023-08-29 12:09:26 +01:00
|
|
|
background: './src/background/index.js',
|
|
|
|
|
backendManager: './src/contentScripts/backendManager.js',
|
2026-01-14 01:49:44 +09:00
|
|
|
fallbackEvalContext: './src/contentScripts/fallbackEvalContext.js',
|
2023-09-25 12:02:13 -04:00
|
|
|
fileFetcher: './src/contentScripts/fileFetcher.js',
|
2023-08-29 12:09:26 +01:00
|
|
|
main: './src/main/index.js',
|
2019-03-17 13:52:37 -07:00
|
|
|
panel: './src/panel.js',
|
2022-10-21 22:52:18 -04:00
|
|
|
proxy: './src/contentScripts/proxy.js',
|
|
|
|
|
prepareInjection: './src/contentScripts/prepareInjection.js',
|
|
|
|
|
installHook: './src/contentScripts/installHook.js',
|
2024-09-18 18:26:39 +01:00
|
|
|
hookSettingsInjector: './src/contentScripts/hookSettingsInjector.js',
|
2019-01-22 11:04:37 -08:00
|
|
|
},
|
|
|
|
|
output: {
|
|
|
|
|
path: __dirname + '/build',
|
2021-08-16 13:46:46 -07:00
|
|
|
publicPath: '/build/',
|
2025-09-17 15:45:25 +02:00
|
|
|
filename: chunkData => {
|
|
|
|
|
switch (chunkData.chunk.name) {
|
|
|
|
|
case 'backend':
|
|
|
|
|
return 'react_devtools_backend_compact.js';
|
|
|
|
|
default:
|
|
|
|
|
return '[name].js';
|
|
|
|
|
}
|
|
|
|
|
},
|
2021-09-09 15:25:26 -04:00
|
|
|
chunkFilename: '[name].chunk.js',
|
2019-01-22 11:04:37 -08:00
|
|
|
},
|
2020-05-07 13:13:47 -07:00
|
|
|
node: {
|
2023-06-14 13:15:52 +01:00
|
|
|
global: false,
|
2020-05-07 13:13:47 -07:00
|
|
|
},
|
2019-08-14 09:24:35 -07:00
|
|
|
resolve: {
|
|
|
|
|
alias: {
|
|
|
|
|
react: resolve(builtModulesDir, 'react'),
|
2019-08-14 10:33:33 -07:00
|
|
|
'react-debug-tools': resolve(builtModulesDir, 'react-debug-tools'),
|
2021-03-17 12:28:21 -04:00
|
|
|
'react-devtools-feature-flags': resolveFeatureFlags(featureFlagTarget),
|
2022-03-01 00:13:28 -05:00
|
|
|
'react-dom/client': resolve(builtModulesDir, 'react-dom/client'),
|
2019-08-14 09:24:35 -07:00
|
|
|
'react-dom': resolve(builtModulesDir, 'react-dom'),
|
2019-08-14 10:33:33 -07:00
|
|
|
'react-is': resolve(builtModulesDir, 'react-is'),
|
2019-08-14 09:24:35 -07:00
|
|
|
scheduler: resolve(builtModulesDir, 'scheduler'),
|
|
|
|
|
},
|
|
|
|
|
},
|
2020-07-15 10:38:30 -04:00
|
|
|
optimization: {
|
2023-08-29 12:09:13 +01:00
|
|
|
minimize: !__DEV__,
|
|
|
|
|
minimizer: [
|
|
|
|
|
new TerserPlugin({
|
|
|
|
|
terserOptions: {
|
2023-10-16 14:54:25 +01:00
|
|
|
compress: {
|
|
|
|
|
unused: true,
|
|
|
|
|
dead_code: true,
|
|
|
|
|
},
|
2023-08-29 12:09:13 +01:00
|
|
|
mangle: {
|
|
|
|
|
keep_fnames: true,
|
|
|
|
|
},
|
|
|
|
|
format: {
|
|
|
|
|
comments: false,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
extractComments: false,
|
|
|
|
|
}),
|
|
|
|
|
],
|
2020-07-15 10:38:30 -04:00
|
|
|
},
|
2019-03-26 13:22:55 -07:00
|
|
|
plugins: [
|
2023-06-14 13:15:52 +01:00
|
|
|
new Webpack.ProvidePlugin({
|
|
|
|
|
process: 'process/browser',
|
|
|
|
|
}),
|
|
|
|
|
new Webpack.DefinePlugin({
|
2020-10-12 22:07:10 +05:00
|
|
|
__DEV__,
|
2020-04-21 11:46:11 -07:00
|
|
|
__EXPERIMENTAL__: true,
|
2020-10-12 22:07:10 +05:00
|
|
|
__EXTENSION__: true,
|
|
|
|
|
__PROFILE__: false,
|
|
|
|
|
__TEST__: NODE_ENV === 'test',
|
2023-10-16 14:54:25 +01:00
|
|
|
__IS_CHROME__: IS_CHROME,
|
|
|
|
|
__IS_FIREFOX__: IS_FIREFOX,
|
|
|
|
|
__IS_EDGE__: IS_EDGE,
|
2024-08-02 10:51:15 +01:00
|
|
|
__IS_NATIVE__: false,
|
feat[devtools]: symbolicate source for inspected element (#28471)
Stacked on https://github.com/facebook/react/pull/28351, please review
only the last commit.
Top-level description of the approach:
1. Once user selects an element from the tree, frontend asks backend to
return the inspected element, this is where we simulate an error
happening in `render` function of the component and then we parse the
error stack. As an improvement, we should probably migrate from custom
implementation of error stack parser to `error-stack-parser` from npm.
2. When frontend receives the inspected element and this object is being
propagated, we create a Promise for symbolicated source, which is then
passed down to all components, which are using `source`.
3. These components use `use` hook for this promise and are wrapped in
Suspense.
Caching:
1. For browser extension, we cache Promises based on requested resource
+ key + column, also added use of
`chrome.devtools.inspectedWindow.getResource` API.
2. For standalone case (RN), we cache based on requested resource url,
we cache the content of it.
2024-03-05 12:32:11 +00:00
|
|
|
__IS_INTERNAL_VERSION__: IS_INTERNAL_VERSION,
|
2021-05-07 08:46:58 -04:00
|
|
|
'process.env.DEVTOOLS_PACKAGE': `"react-devtools-extensions"`,
|
2019-03-26 13:22:55 -07:00
|
|
|
'process.env.DEVTOOLS_VERSION': `"${DEVTOOLS_VERSION}"`,
|
2021-11-03 08:27:30 -07:00
|
|
|
'process.env.EDITOR_URL': EDITOR_URL != null ? `"${EDITOR_URL}"` : null,
|
2019-04-11 17:19:03 -07:00
|
|
|
'process.env.GITHUB_URL': `"${GITHUB_URL}"`,
|
2021-09-30 13:47:14 -04:00
|
|
|
'process.env.LOGGING_URL': `"${LOGGING_URL}"`,
|
2019-03-26 13:22:55 -07:00
|
|
|
'process.env.NODE_ENV': `"${NODE_ENV}"`,
|
|
|
|
|
}),
|
2024-04-08 18:10:09 +01:00
|
|
|
new Webpack.SourceMapDevToolPlugin({
|
|
|
|
|
filename: '[file].map',
|
2025-09-17 15:45:25 +02:00
|
|
|
include: ['installHook.js', 'react_devtools_backend_compact.js'],
|
2024-04-08 18:10:09 +01:00
|
|
|
noSources: !__DEV__,
|
2024-06-17 11:58:19 +01:00
|
|
|
// https://github.com/webpack/webpack/issues/3603#issuecomment-1743147144
|
|
|
|
|
moduleFilenameTemplate(info) {
|
|
|
|
|
const {absoluteResourcePath, namespace, resourcePath} = info;
|
|
|
|
|
|
|
|
|
|
if (isAbsolute(absoluteResourcePath)) {
|
|
|
|
|
return relative(__dirname + '/build', absoluteResourcePath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Mimic Webpack's default behavior:
|
|
|
|
|
return `webpack://${namespace}/${resourcePath}`;
|
|
|
|
|
},
|
2024-04-08 18:10:09 +01:00
|
|
|
}),
|
|
|
|
|
new SourceMapIgnoreListPlugin({
|
|
|
|
|
shouldIgnoreSource: (assetName, _source) => {
|
|
|
|
|
if (__DEV__) {
|
|
|
|
|
// Don't ignore list anything in DEV build for debugging purposes
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const contentScriptNamesToIgnoreList = [
|
2025-09-17 15:45:25 +02:00
|
|
|
'react_devtools_backend_compact',
|
2024-04-08 18:10:09 +01:00
|
|
|
// This is where we override console
|
|
|
|
|
'installHook',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
return contentScriptNamesToIgnoreList.some(ignoreListName =>
|
|
|
|
|
assetName.startsWith(ignoreListName),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
}),
|
2024-09-19 15:44:34 +01:00
|
|
|
{
|
|
|
|
|
apply(compiler) {
|
|
|
|
|
if (__DEV__) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const {RawSource} = compiler.webpack.sources;
|
|
|
|
|
compiler.hooks.compilation.tap(
|
|
|
|
|
'CustomContentForHookScriptPlugin',
|
|
|
|
|
compilation => {
|
|
|
|
|
compilation.hooks.processAssets.tap(
|
|
|
|
|
{
|
|
|
|
|
name: 'CustomContentForHookScriptPlugin',
|
|
|
|
|
stage: Webpack.Compilation.PROCESS_ASSETS_STAGE_DEV_TOOLING,
|
|
|
|
|
additionalAssets: true,
|
|
|
|
|
},
|
|
|
|
|
assets => {
|
|
|
|
|
// eslint-disable-next-line no-for-of-loops/no-for-of-loops
|
|
|
|
|
for (const [name, asset] of Object.entries(assets)) {
|
|
|
|
|
if (name !== 'installHook.js.map') {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const mapContent = asset.source().toString();
|
|
|
|
|
if (!mapContent) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const map = JSON.parse(mapContent);
|
|
|
|
|
map.sourcesContent = map.sources.map(sourceName => {
|
|
|
|
|
if (!sourceName.endsWith('/hook.js')) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
'/*\n' +
|
|
|
|
|
' * This script is from React DevTools.\n' +
|
|
|
|
|
" * You're likely here because you thought it sent an error or warning to the console.\n" +
|
|
|
|
|
' * React DevTools patches the console to support features like appending component stacks, \n' +
|
|
|
|
|
' * so this file appears as a source. However, the console call actually came from another script.\n' +
|
|
|
|
|
" * To remove this script from stack traces, open your browser's DevTools (to enable source mapping) before these console calls happen.\n" +
|
|
|
|
|
' */'
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
compilation.updateAsset(
|
|
|
|
|
name,
|
|
|
|
|
new RawSource(JSON.stringify(map)),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
},
|
2025-09-17 15:03:12 +02:00
|
|
|
new StatsWriterPlugin({
|
|
|
|
|
stats: 'verbose',
|
|
|
|
|
filename: statsFileName,
|
|
|
|
|
}),
|
2019-03-26 13:22:55 -07:00
|
|
|
],
|
2019-01-22 11:04:37 -08:00
|
|
|
module: {
|
2021-07-01 14:39:18 -04:00
|
|
|
defaultRules: [
|
|
|
|
|
{
|
|
|
|
|
type: 'javascript/auto',
|
|
|
|
|
resolve: {},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
test: /\.json$/i,
|
|
|
|
|
type: 'json',
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
|
2019-01-22 11:04:37 -08:00
|
|
|
rules: [
|
2021-07-22 13:58:57 -04:00
|
|
|
{
|
|
|
|
|
test: /\.worker\.js$/,
|
|
|
|
|
use: [
|
|
|
|
|
{
|
|
|
|
|
loader: 'workerize-loader',
|
|
|
|
|
options: {
|
2025-09-17 17:59:55 +02:00
|
|
|
inline: false,
|
2021-09-15 23:21:33 +05:30
|
|
|
name: '[name]',
|
2021-07-22 13:58:57 -04:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
loader: 'babel-loader',
|
|
|
|
|
options: babelOptions,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
2019-01-22 11:04:37 -08:00
|
|
|
{
|
|
|
|
|
test: /\.js$/,
|
|
|
|
|
loader: 'babel-loader',
|
2021-07-22 13:58:57 -04:00
|
|
|
options: babelOptions,
|
2019-01-22 11:04:37 -08:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
test: /\.css$/,
|
|
|
|
|
use: [
|
|
|
|
|
{
|
|
|
|
|
loader: 'style-loader',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
loader: 'css-loader',
|
|
|
|
|
options: {
|
2025-10-20 13:39:42 +01:00
|
|
|
sourceMap: __DEV__,
|
2019-01-22 11:04:37 -08:00
|
|
|
modules: true,
|
|
|
|
|
localIdentName: '[local]___[hash:base64:5]',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
};
|