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]: ship source maps for content scripts and ignore list …
…installHook script (facebook#28730) ## Summary 1. RDT browser extension's content scripts will now ship source maps (without source in prod, to save some bundle size). 2. `installHook` content script will be ignore listed via `ignoreList` field in the corresponding source map. 3. Previously, source map for backend file used `x_google_ignoreList` naming, now `ignoreList`. ## How did you test this change? 1. `ignoreList-test.js` 2. Tested manually that I don't see `installHook` in stack traces when `console.error` is called.
- Loading branch information
1 parent
15d179b
commit a10e36a
Showing
6 changed files
with
111 additions
and
33 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
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
73 changes: 73 additions & 0 deletions
73
packages/react-devtools-shared/SourceMapIgnoreListPlugin.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,73 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
/** | ||
* The implementation of this plugin is based on similar webpack plugin in Angular CLI | ||
* https://github.com/angular/angular-cli/blob/16d8c552e99bfe65ded9e843e917dbb95eb8ec01/packages/angular_devkit/build_angular/src/tools/webpack/plugins/devtools-ignore-plugin.ts | ||
* and devtools-ignore-webpack-plugin | ||
* https://github.com/mondaychen/devtools-ignore-webpack-plugin/blob/d15274e4d2fdb74f73aa644f14773a5523823999/src/index.ts | ||
* which both are licensed under MIT | ||
*/ | ||
|
||
const {Compilation} = require('webpack'); | ||
|
||
const IGNORE_LIST = 'ignoreList'; | ||
const PLUGIN_NAME = 'source-map-ignore-list-plugin'; | ||
|
||
class SourceMapIgnoreListPlugin { | ||
constructor({shouldIgnoreSource}) { | ||
this.shouldIgnoreSource = shouldIgnoreSource; | ||
} | ||
|
||
apply(compiler) { | ||
const {RawSource} = compiler.webpack.sources; | ||
|
||
compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => { | ||
compilation.hooks.processAssets.tap( | ||
{ | ||
name: PLUGIN_NAME, | ||
stage: 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.endsWith('.map')) { | ||
continue; | ||
} | ||
|
||
const mapContent = asset.source().toString(); | ||
if (!mapContent) { | ||
continue; | ||
} | ||
|
||
const map = JSON.parse(mapContent); | ||
const ignoreList = []; | ||
|
||
const sourcesCount = map.sources.length; | ||
for ( | ||
let potentialSourceIndex = 0; | ||
potentialSourceIndex < sourcesCount; | ||
++potentialSourceIndex | ||
) { | ||
const source = map.sources[potentialSourceIndex]; | ||
|
||
if (this.shouldIgnoreSource(name, source)) { | ||
ignoreList.push(potentialSourceIndex); | ||
} | ||
} | ||
|
||
map[IGNORE_LIST] = ignoreList; | ||
compilation.updateAsset(name, new RawSource(JSON.stringify(map))); | ||
} | ||
}, | ||
); | ||
}); | ||
} | ||
} | ||
|
||
module.exports = SourceMapIgnoreListPlugin; |
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