Skip to content

Commit

Permalink
feat: display message if user ended up opening hook script
Browse files Browse the repository at this point in the history
  • Loading branch information
hoxyq committed Sep 19, 2024
1 parent 09d8283 commit d83cde3
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions packages/react-devtools-extensions/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,60 @@ module.exports = {
);
},
}),
{
apply(compiler) {
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 is the script 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. That's why this file appears as a source.\n" +
' * The console call actually came from another script.\n' +
" * Since your browser DevTools weren't open yet, ignore listing wasn't applied, and now you see this script.\n" +
' * To find the real source, make sure your browser DevTools are open before these console calls happen.\n' +
' */'
);
});

compilation.updateAsset(
name,
new RawSource(JSON.stringify(map)),
);
}
},
);
},
);
},
},
],
module: {
defaultRules: [
Expand Down

0 comments on commit d83cde3

Please sign in to comment.