Skip to content

Commit eba1938

Browse files
committed
feat[devtools]: support x_google_ignoreList source maps extension
1 parent 4ddc019 commit eba1938

File tree

6 files changed

+235
-22
lines changed

6 files changed

+235
-22
lines changed

packages/react-devtools-extensions/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"chrome-launch": "^1.1.4",
4040
"crx": "^5.0.0",
4141
"css-loader": "^1.0.1",
42+
"devtools-ignore-webpack-plugin": "^0.1.1",
4243
"file-loader": "^6.1.0",
4344
"filesize": "^6.0.1",
4445
"find": "^0.3.0",
@@ -57,6 +58,7 @@
5758
"parse-filepath": "^1.0.2",
5859
"process": "0.11.10",
5960
"raw-loader": "^3.1.0",
61+
"rimraf": "^5.0.1",
6062
"source-map-js": "^0.6.2",
6163
"sourcemap-codec": "^1.4.8",
6264
"style-loader": "^0.23.1",
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
*/
9+
10+
import {exec} from 'child-process-promise';
11+
import {readFileSync} from 'fs';
12+
import path from 'path';
13+
import {rimrafSync} from 'rimraf';
14+
15+
describe('x_google_ignoreList source map extension', () => {
16+
jest.setTimeout(30 * 1000);
17+
18+
const pathToExtensionsPackage = path.resolve(__dirname, '..', '..');
19+
const pathToChromeExtensionBuild = path.join(
20+
pathToExtensionsPackage,
21+
'chrome/build',
22+
);
23+
const pathToSourceMap = path.resolve(
24+
pathToChromeExtensionBuild,
25+
'unpacked/build/react_devtools_backend_compact.js.map',
26+
);
27+
28+
afterAll(() => {
29+
rimrafSync(pathToChromeExtensionBuild);
30+
});
31+
32+
describe('for dev builds', () => {
33+
it('should include only sources with /node_modules/ and /webpack/ in path', async () => {
34+
await exec('yarn build:chrome:local', {
35+
cwd: pathToExtensionsPackage,
36+
});
37+
38+
const sourceMapJSON = readFileSync(pathToSourceMap);
39+
const sourceMap = JSON.parse(sourceMapJSON);
40+
41+
const {sources, x_google_ignoreList} = sourceMap;
42+
43+
const expectedIgnoreList = [];
44+
for (let sourceIndex = 0; sourceIndex < sources.length; ++sourceIndex) {
45+
const source = sources[sourceIndex];
46+
47+
if (source.includes('/node_modules/') || source.includes('/webpack/')) {
48+
expectedIgnoreList.push(sourceIndex);
49+
}
50+
}
51+
52+
expect(x_google_ignoreList).toEqual(expectedIgnoreList);
53+
});
54+
});
55+
56+
describe('for production builds', function () {
57+
it('should include every source', async () => {
58+
await exec('yarn build:chrome', {cwd: pathToExtensionsPackage});
59+
60+
const sourceMapJSON = readFileSync(pathToSourceMap);
61+
const sourceMap = JSON.parse(sourceMapJSON);
62+
63+
const {sources, x_google_ignoreList} = sourceMap;
64+
65+
expect(sources.length).toBe(x_google_ignoreList.length);
66+
});
67+
});
68+
});

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
const {resolve} = require('path');
44
const Webpack = require('webpack');
5+
const DevToolsIgnorePlugin = require('devtools-ignore-webpack-plugin');
6+
7+
const {resolveFeatureFlags} = require('react-devtools-shared/buildUtils');
58
const {
69
DARK_MODE_DIMMED_WARNING_COLOR,
710
DARK_MODE_DIMMED_ERROR_COLOR,
@@ -12,7 +15,6 @@ const {
1215
GITHUB_URL,
1316
getVersionString,
1417
} = require('./utils');
15-
const {resolveFeatureFlags} = require('react-devtools-shared/buildUtils');
1618

1719
const NODE_ENV = process.env.NODE_ENV;
1820
if (!NODE_ENV) {
@@ -78,6 +80,15 @@ module.exports = {
7880
'process.env.LIGHT_MODE_DIMMED_ERROR_COLOR': `"${LIGHT_MODE_DIMMED_ERROR_COLOR}"`,
7981
'process.env.LIGHT_MODE_DIMMED_LOG_COLOR': `"${LIGHT_MODE_DIMMED_LOG_COLOR}"`,
8082
}),
83+
new DevToolsIgnorePlugin({
84+
shouldIgnorePath: function (path) {
85+
if (!__DEV__) {
86+
return true;
87+
}
88+
89+
return path.includes('/node_modules/') || path.includes('/webpack/');
90+
},
91+
}),
8192
],
8293
module: {
8394
rules: [

packages/react-devtools-shared/src/__tests__/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ export function getRendererID(): number {
152152
return rendererInterface.renderer.rendererPackageName === 'react-dom';
153153
});
154154

155-
if (ids == null) {
155+
if (id == null) {
156156
throw Error('Could not find renderer.');
157157
}
158158

scripts/jest/config.build-devtools.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ module.exports = Object.assign({}, baseConfig, {
6969
'/__compiled__/',
7070
'/__untransformed__/',
7171
],
72-
testRegex: 'packages/react-devtools-shared/.+/__tests__/[^]+.test.js$',
72+
testRegex: 'packages/react-devtools(-(.+))?/.+/__tests__/[^]+.test.js$',
7373
snapshotSerializers: [
7474
require.resolve(
7575
'../../packages/react-devtools-shared/src/__tests__/__serializers__/dehydratedValueSerializer.js'

0 commit comments

Comments
 (0)