forked from facebook/react
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat[devtools]: support x_google_ignoreList source maps extension (fa…
…cebook#26951) ## Summary This was originally implemented by Mengdi @mondaychen in facebook#26506. Because we patch console methods (to append components stack and some other features), errors in console will include `react_devtools_backend-....js` in its stack traces. Example: <img width="763" alt="Screenshot 2023-06-15 at 13 31 49" src="https://github.com/facebook/react/assets/28902667/fa9c3d26-b6c5-4965-af71-62d100cd806d"> Using https://github.com/mondaychen/devtools-ignore-webpack-plugin to support [x_google_ignoreList source maps extension](https://developer.chrome.com/blog/devtools-better-angular-debugging/#the-x_google_ignorelist-source-map-extension). @mondaychen created a react app, which throws an error via `console.error`, when user click on the button - https://3owqsn.csb.app/. Stack trace with these changes: <img width="759" alt="Screenshot 2023-06-14 at 14 26 38" src="https://github.com/facebook/react/assets/28902667/b118b168-3200-4a47-9718-39fc455ea993">
- Loading branch information
1 parent
8fb9bb0
commit df9ab3a
Showing
6 changed files
with
235 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
packages/react-devtools-extensions/src/__tests__/xGoogleIgnoreList-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.