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

feat[devtools]: support x_google_ignoreList source maps extension #26951

Merged
merged 1 commit into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions packages/react-devtools-extensions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"chrome-launch": "^1.1.4",
"crx": "^5.0.0",
"css-loader": "^1.0.1",
"devtools-ignore-webpack-plugin": "^0.1.1",
"file-loader": "^6.1.0",
"filesize": "^6.0.1",
"find": "^0.3.0",
Expand All @@ -57,6 +58,7 @@
"parse-filepath": "^1.0.2",
"process": "0.11.10",
"raw-loader": "^3.1.0",
"rimraf": "^5.0.1",
"source-map-js": "^0.6.2",
"sourcemap-codec": "^1.4.8",
"style-loader": "^0.23.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

import {exec} from 'child-process-promise';
import {readFileSync} from 'fs';
import path from 'path';
import {rimrafSync} from 'rimraf';

describe('x_google_ignoreList source map extension', () => {
jest.setTimeout(30 * 1000);

const pathToExtensionsPackage = path.resolve(__dirname, '..', '..');
const pathToChromeExtensionBuild = path.join(
pathToExtensionsPackage,
'chrome/build',
);
const pathToSourceMap = path.resolve(
pathToChromeExtensionBuild,
'unpacked/build/react_devtools_backend_compact.js.map',
);

afterAll(() => {
rimrafSync(pathToChromeExtensionBuild);
});

describe('for dev builds', () => {
it('should include only sources with /node_modules/ and /webpack/ in path', async () => {
await exec('yarn build:chrome:local', {
cwd: pathToExtensionsPackage,
});

const sourceMapJSON = readFileSync(pathToSourceMap);
const sourceMap = JSON.parse(sourceMapJSON);

const {sources, x_google_ignoreList} = sourceMap;

const expectedIgnoreList = [];
for (let sourceIndex = 0; sourceIndex < sources.length; ++sourceIndex) {
const source = sources[sourceIndex];

if (source.includes('/node_modules/') || source.includes('/webpack/')) {
expectedIgnoreList.push(sourceIndex);
}
}

expect(x_google_ignoreList).toEqual(expectedIgnoreList);
});
});

describe('for production builds', function () {
it('should include every source', async () => {
await exec('yarn build:chrome', {cwd: pathToExtensionsPackage});

const sourceMapJSON = readFileSync(pathToSourceMap);
const sourceMap = JSON.parse(sourceMapJSON);

const {sources, x_google_ignoreList} = sourceMap;

expect(sources.length).toBe(x_google_ignoreList.length);
});
});
});
13 changes: 12 additions & 1 deletion packages/react-devtools-extensions/webpack.backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

const {resolve} = require('path');
const Webpack = require('webpack');
const DevToolsIgnorePlugin = require('devtools-ignore-webpack-plugin');

const {resolveFeatureFlags} = require('react-devtools-shared/buildUtils');
const {
DARK_MODE_DIMMED_WARNING_COLOR,
DARK_MODE_DIMMED_ERROR_COLOR,
Expand All @@ -12,7 +15,6 @@ const {
GITHUB_URL,
getVersionString,
} = require('./utils');
const {resolveFeatureFlags} = require('react-devtools-shared/buildUtils');

const NODE_ENV = process.env.NODE_ENV;
if (!NODE_ENV) {
Expand Down Expand Up @@ -78,6 +80,15 @@ module.exports = {
'process.env.LIGHT_MODE_DIMMED_ERROR_COLOR': `"${LIGHT_MODE_DIMMED_ERROR_COLOR}"`,
'process.env.LIGHT_MODE_DIMMED_LOG_COLOR': `"${LIGHT_MODE_DIMMED_LOG_COLOR}"`,
}),
new DevToolsIgnorePlugin({
shouldIgnorePath: function (path) {
if (!__DEV__) {
return true;
}

return path.includes('/node_modules/') || path.includes('/webpack/');
},
}),
],
module: {
rules: [
Expand Down
2 changes: 1 addition & 1 deletion packages/react-devtools-shared/src/__tests__/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export function getRendererID(): number {
return rendererInterface.renderer.rendererPackageName === 'react-dom';
});

if (ids == null) {
if (id == null) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is just a typo fix

throw Error('Could not find renderer.');
}

Expand Down
2 changes: 1 addition & 1 deletion scripts/jest/config.build-devtools.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ module.exports = Object.assign({}, baseConfig, {
'/__compiled__/',
'/__untransformed__/',
],
testRegex: 'packages/react-devtools-shared/.+/__tests__/[^]+.test.js$',
testRegex: 'packages/react-devtools(-(.+))?/.+/__tests__/[^]+.test.js$',
snapshotSerializers: [
require.resolve(
'../../packages/react-devtools-shared/src/__tests__/__serializers__/dehydratedValueSerializer.js'
Expand Down
Loading