Skip to content

Commit

Permalink
[DevTools] Enable hook names in standalone app
Browse files Browse the repository at this point in the history
  • Loading branch information
Juan Tejada committed Sep 15, 2021
1 parent 67222f0 commit 420bc8d
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 28 deletions.
1 change: 1 addition & 0 deletions packages/react-devtools-core/hookNames.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./dist/hookNames');
3 changes: 2 additions & 1 deletion packages/react-devtools-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"dist",
"backend.js",
"build-info.json",
"standalone.js"
"standalone.js",
"hookNames.js"
],
"scripts": {
"build": "yarn build:backend && yarn build:standalone",
Expand Down
16 changes: 16 additions & 0 deletions packages/react-devtools-core/src/hookNames.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Copyright (c) Facebook, Inc. and its 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 {
parseHookNames,
parseSourceAndMetadata,
purgeCachedMetadata,
} from 'react-devtools-shared/src/hooks/parseHookNames';

export {parseHookNames, parseSourceAndMetadata, purgeCachedMetadata};
6 changes: 6 additions & 0 deletions packages/react-devtools-core/src/standalone.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ let nodeWaitingToConnectHTML: string = '';
let projectRoots: Array<string> = [];
let statusListener: StatusListener = (message: string) => {};

// TODO (Webpack 5) Hopefully we can remove this prop after the Webpack 5 migration.
function hookNamesModuleLoaderFunction() {
return import('./hookNames');
}

function setContentDOMNode(value: HTMLElement) {
node = value;

Expand Down Expand Up @@ -100,6 +105,7 @@ function reload() {
createElement(DevTools, {
bridge: ((bridge: any): FrontendBridge),
canViewElementSourceFunction,
hookNamesModuleLoaderFunction,
showTabBar: true,
store: ((store: any): Store),
warnIfLegacyBackendDetected: true,
Expand Down
4 changes: 3 additions & 1 deletion packages/react-devtools-core/webpack.standalone.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,16 @@ const babelOptions = {

module.exports = {
mode: __DEV__ ? 'development' : 'production',
devtool: __DEV__ ? 'cheap-module-eval-source-map' : 'source-map',
devtool: __DEV__ ? 'cheap-source-map' : 'source-map',
target: 'electron-main',
entry: {
standalone: './src/standalone.js',
hookNames: './src/hookNames.js',
},
output: {
path: __dirname + '/dist',
filename: '[name].js',
chunkFilename: '[name].chunk.js',
library: '[name]',
libraryTarget: 'commonjs2',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

export const enableProfilerChangedHookIndices = true;
export const isInternalFacebookBuild = true;
export const enableNamedHooksFeature = false;
export const enableNamedHooksFeature = true;
export const enableLogger = false;
export const consoleManagedByDevToolsDuringStrictMode = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

export const enableProfilerChangedHookIndices = false;
export const isInternalFacebookBuild = false;
export const enableNamedHooksFeature = false;
export const enableNamedHooksFeature = true;
export const enableLogger = false;
export const consoleManagedByDevToolsDuringStrictMode = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,33 +394,42 @@ function parseSourceAST(
hookParsedMetadata.originalSourceCode =
sourceMetadata.originalSourceCode;
} else {
// TypeScript is the most commonly used typed JS variant so let's default to it
// unless we detect explicit Flow usage via the "@flow" pragma.
const plugin =
originalSourceCode.indexOf('@flow') > 0 ? 'flow' : 'typescript';

// TODO (named hooks) This is probably where we should check max source length,
// rather than in loadSourceAndMetatada -> loadSourceFiles().
const originalSourceAST = withSyncPerfMeasurements(
'[@babel/parser] parse(originalSourceCode)',
() =>
parse(originalSourceCode, {
sourceType: 'unambiguous',
plugins: ['jsx', plugin],
}),
);
hookParsedMetadata.originalSourceAST = originalSourceAST;
try {
// TypeScript is the most commonly used typed JS variant so let's default to it
// unless we detect explicit Flow usage via the "@flow" pragma.
const plugin =
originalSourceCode.indexOf('@flow') > 0 ? 'flow' : 'typescript';

// TODO (named hooks) This is probably where we should check max source length,
// rather than in loadSourceAndMetatada -> loadSourceFiles().
// TODO(#22319): Support source files that are html files with inline script tags.
const originalSourceAST = withSyncPerfMeasurements(
'[@babel/parser] parse(originalSourceCode)',
() =>
parse(originalSourceCode, {
errorRecovery: true,
sourceType: 'unambiguous',
plugins: ['jsx', plugin],
}),
);
hookParsedMetadata.originalSourceAST = originalSourceAST;

if (__DEBUG__) {
console.log(
`parseSourceAST() Caching source metadata for "${originalSourceURL}"`,
if (__DEBUG__) {
console.log(
`parseSourceAST() Caching source metadata for "${originalSourceURL}"`,
);
}

originalURLToMetadataCache.set(originalSourceURL, {
originalSourceAST,
originalSourceCode,
});
} catch (error) {
throw new Error(
`Failed to parse source file: ${originalSourceURL}\n\n` +
`Original error: ${error}`,
);
}

originalURLToMetadataCache.set(originalSourceURL, {
originalSourceAST,
originalSourceCode,
});
}
},
);
Expand Down
1 change: 1 addition & 0 deletions packages/react-devtools/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ app.on('ready', function() {
//titleBarStyle: 'customButtonsOnHover',
webPreferences: {
nodeIntegration: true,
nodeIntegrationInWorker: true,
},
});

Expand Down

0 comments on commit 420bc8d

Please sign in to comment.