Skip to content

Commit

Permalink
moved console log colors to process.env in webpack
Browse files Browse the repository at this point in the history
  • Loading branch information
lunaruan committed Aug 24, 2021
1 parent c137a15 commit d938848
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 27 deletions.
6 changes: 6 additions & 0 deletions packages/react-devtools-core/webpack.backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ module.exports = {
'process.env.DEVTOOLS_PACKAGE': `"react-devtools-core"`,
'process.env.DEVTOOLS_VERSION': `"${DEVTOOLS_VERSION}"`,
'process.env.GITHUB_URL': `"${GITHUB_URL}"`,
'process.env.DARK_MODE_DIMMED_WARNING_COLOR': `"rgba(250, 180, 50, 0.5)"`,
'process.env.DARK_MODE_DIMMED_ERROR_COLOR': `"rgba(250, 123, 130, 0.5)"`,
'process.env.DARK_MODE_DIMMED_LOG_COLOR': `"rgba(125, 125, 125, 0.5)"`,
'process.env.LIGHT_MODE_DIMMED_WARNING_COLOR': `"rgba(250, 180, 50, 0.75)"`,
'process.env.LIGHT_MODE_DIMMED_ERROR_COLOR': `"rgba(250, 123, 130, 0.75)"`,
'process.env.LIGHT_MODE_DIMMED_LOG_COLOR': `"rgba(125, 125, 125, 0.75)"`,
}),
],
optimization: {
Expand Down
6 changes: 6 additions & 0 deletions packages/react-devtools-core/webpack.standalone.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ module.exports = {
'process.env.DEVTOOLS_VERSION': `"${DEVTOOLS_VERSION}"`,
'process.env.GITHUB_URL': `"${GITHUB_URL}"`,
'process.env.NODE_ENV': `"${NODE_ENV}"`,
'process.env.DARK_MODE_DIMMED_WARNING_COLOR': `"rgba(250, 180, 50, 0.5)"`,
'process.env.DARK_MODE_DIMMED_ERROR_COLOR': `"rgba(250, 123, 130, 0.5)"`,
'process.env.DARK_MODE_DIMMED_LOG_COLOR': `"rgba(125, 125, 125, 0.5)"`,
'process.env.LIGHT_MODE_DIMMED_WARNING_COLOR': `"rgba(250, 180, 50, 0.75)"`,
'process.env.LIGHT_MODE_DIMMED_ERROR_COLOR': `"rgba(250, 123, 130, 0.75)"`,
'process.env.LIGHT_MODE_DIMMED_LOG_COLOR': `"rgba(125, 125, 125, 0.75)"`,
}),
],
module: {
Expand Down
6 changes: 6 additions & 0 deletions packages/react-devtools-extensions/webpack.backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ module.exports = {
'process.env.DEVTOOLS_PACKAGE': `"react-devtools-extensions"`,
'process.env.DEVTOOLS_VERSION': `"${DEVTOOLS_VERSION}"`,
'process.env.GITHUB_URL': `"${GITHUB_URL}"`,
'process.env.DARK_MODE_DIMMED_WARNING_COLOR': `"rgba(250, 180, 50, 0.5)"`,
'process.env.DARK_MODE_DIMMED_ERROR_COLOR': `"rgba(250, 123, 130, 0.5)"`,
'process.env.DARK_MODE_DIMMED_LOG_COLOR': `"rgba(125, 125, 125, 0.5)"`,
'process.env.LIGHT_MODE_DIMMED_WARNING_COLOR': `"rgba(250, 180, 50, 0.75)"`,
'process.env.LIGHT_MODE_DIMMED_ERROR_COLOR': `"rgba(250, 123, 130, 0.75)"`,
'process.env.LIGHT_MODE_DIMMED_LOG_COLOR': `"rgba(125, 125, 125, 0.75)"`,
}),
],
module: {
Expand Down
6 changes: 6 additions & 0 deletions packages/react-devtools-extensions/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ module.exports = {
'process.env.DEVTOOLS_VERSION': `"${DEVTOOLS_VERSION}"`,
'process.env.GITHUB_URL': `"${GITHUB_URL}"`,
'process.env.NODE_ENV': `"${NODE_ENV}"`,
'process.env.DARK_MODE_DIMMED_WARNING_COLOR': `"rgba(250, 180, 50, 0.5)"`,
'process.env.DARK_MODE_DIMMED_ERROR_COLOR': `"rgba(250, 123, 130, 0.5)"`,
'process.env.DARK_MODE_DIMMED_LOG_COLOR': `"rgba(125, 125, 125, 0.5)"`,
'process.env.LIGHT_MODE_DIMMED_WARNING_COLOR': `"rgba(250, 180, 50, 0.75)"`,
'process.env.LIGHT_MODE_DIMMED_ERROR_COLOR': `"rgba(250, 123, 130, 0.75)"`,
'process.env.LIGHT_MODE_DIMMED_LOG_COLOR': `"rgba(125, 125, 125, 0.75)"`,
}),
],
module: {
Expand Down
6 changes: 6 additions & 0 deletions packages/react-devtools-inline/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ module.exports = {
'process.env.DEVTOOLS_VERSION': `"${DEVTOOLS_VERSION}"`,
'process.env.GITHUB_URL': `"${GITHUB_URL}"`,
'process.env.NODE_ENV': `"${NODE_ENV}"`,
'process.env.DARK_MODE_DIMMED_WARNING_COLOR': `"rgba(250, 180, 50, 0.5)"`,
'process.env.DARK_MODE_DIMMED_ERROR_COLOR': `"rgba(250, 123, 130, 0.5)"`,
'process.env.DARK_MODE_DIMMED_LOG_COLOR': `"rgba(125, 125, 125, 0.5)"`,
'process.env.LIGHT_MODE_DIMMED_WARNING_COLOR': `"rgba(250, 180, 50, 0.75)"`,
'process.env.LIGHT_MODE_DIMMED_ERROR_COLOR': `"rgba(250, 123, 130, 0.75)"`,
'process.env.LIGHT_MODE_DIMMED_LOG_COLOR': `"rgba(125, 125, 125, 0.75)"`,
}),
],
module: {
Expand Down
19 changes: 6 additions & 13 deletions packages/react-devtools-shared/src/backend/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,8 @@ import {format} from './utils';
import {getInternalReactConstants} from './renderer';
import {getStackByFiberInDevAndProd} from './DevToolsFiberComponentStack';

// NOTE: KEEP IN SYNC with src/hook.js
const OVERRIDE_CONSOLE_METHODS = ['error', 'trace', 'warn', 'log'];
const DIMMED_NODE_CONSOLE_COLOR = '\x1b[2m%s\x1b[0m';
const DARK_MODE_DIMMED_WARNING_COLOR = 'rgba(250, 180, 50, 0.5)';
const DARK_MODE_DIMMED_ERROR_COLOR = 'rgba(250, 123, 130, 0.5)';
const DARK_MODE_DIMMED_LOG_COLOR = 'rgba(125, 125, 125, 0.5)';
const LIGHT_MODE_DIMMED_WARNING_COLOR = 'rgba(250, 180, 50, 0.75)';
const LIGHT_MODE_DIMMED_ERROR_COLOR = 'rgba(250, 123, 130, 0.75)';
const LIGHT_MODE_DIMMED_LOG_COLOR = 'rgba(125, 125, 125, 0.75)';

// React's custom built component stack strings match "\s{4}in"
// Chrome's prefix matches "\s{4}at"
Expand Down Expand Up @@ -256,21 +249,21 @@ export function patch({
case 'warn':
color =
browserTheme === 'light'
? LIGHT_MODE_DIMMED_WARNING_COLOR
: DARK_MODE_DIMMED_WARNING_COLOR;
? process.env.LIGHT_MODE_DIMMED_WARNING_COLOR
: process.env.DARK_MODE_DIMMED_WARNING_COLOR;
break;
case 'error':
color =
browserTheme === 'light'
? LIGHT_MODE_DIMMED_ERROR_COLOR
: DARK_MODE_DIMMED_ERROR_COLOR;
? process.env.LIGHT_MODE_DIMMED_ERROR_COLOR
: process.env.DARK_MODE_DIMMED_ERROR_COLOR;
break;
case 'log':
default:
color =
browserTheme === 'light'
? LIGHT_MODE_DIMMED_LOG_COLOR
: DARK_MODE_DIMMED_LOG_COLOR;
? process.env.LIGHT_MODE_DIMMED_LOG_COLOR
: process.env.DARK_MODE_DIMMED_LOG_COLOR;
break;
}

Expand Down
20 changes: 6 additions & 14 deletions packages/react-devtools-shared/src/hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,6 @@ export function installHook(target: any): DevToolsHook | null {
return null;
}

// Keep in sync with src/backend/console.js
const DARK_MODE_DIMMED_WARNING_COLOR = 'rgba(250, 180, 50, 0.5)';
const DARK_MODE_DIMMED_ERROR_COLOR = 'rgba(250, 123, 130, 0.5)';
const DARK_MODE_DIMMED_LOG_COLOR = 'rgba(125, 125, 125, 0.5)';
const LIGHT_MODE_DIMMED_WARNING_COLOR = 'rgba(250, 180, 50, 0.75)';
const LIGHT_MODE_DIMMED_ERROR_COLOR = 'rgba(250, 123, 130, 0.75)';
const LIGHT_MODE_DIMMED_LOG_COLOR = 'rgba(125, 125, 125, 0.75)';

function detectReactBuildType(renderer) {
try {
if (typeof renderer.version === 'string') {
Expand Down Expand Up @@ -278,21 +270,21 @@ export function installHook(target: any): DevToolsHook | null {
case 'warn':
color =
browserTheme === 'light'
? LIGHT_MODE_DIMMED_WARNING_COLOR
: DARK_MODE_DIMMED_WARNING_COLOR;
? process.env.LIGHT_MODE_DIMMED_WARNING_COLOR
: process.env.DARK_MODE_DIMMED_WARNING_COLOR;
break;
case 'error':
color =
browserTheme === 'light'
? LIGHT_MODE_DIMMED_ERROR_COLOR
: DARK_MODE_DIMMED_ERROR_COLOR;
? process.env.LIGHT_MODE_DIMMED_ERROR_COLOR
: process.env.DARK_MODE_DIMMED_ERROR_COLOR;
break;
case 'log':
default:
color =
browserTheme === 'light'
? LIGHT_MODE_DIMMED_LOG_COLOR
: DARK_MODE_DIMMED_LOG_COLOR;
? process.env.LIGHT_MODE_DIMMED_LOG_COLOR
: process.env.DARK_MODE_DIMMED_LOG_COLOR;
break;
}

Expand Down
6 changes: 6 additions & 0 deletions packages/react-devtools-shell/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ const config = {
'process.env.GITHUB_URL': `"${GITHUB_URL}"`,
'process.env.DEVTOOLS_PACKAGE': `"react-devtools-shell"`,
'process.env.DEVTOOLS_VERSION': `"${DEVTOOLS_VERSION}"`,
'process.env.DARK_MODE_DIMMED_WARNING_COLOR': `"rgba(250, 180, 50, 0.5)"`,
'process.env.DARK_MODE_DIMMED_ERROR_COLOR': `"rgba(250, 123, 130, 0.5)"`,
'process.env.DARK_MODE_DIMMED_LOG_COLOR': `"rgba(125, 125, 125, 0.5)"`,
'process.env.LIGHT_MODE_DIMMED_WARNING_COLOR': `"rgba(250, 180, 50, 0.75)"`,
'process.env.LIGHT_MODE_DIMMED_ERROR_COLOR': `"rgba(250, 123, 130, 0.75)"`,
'process.env.LIGHT_MODE_DIMMED_LOG_COLOR': `"rgba(125, 125, 125, 0.75)"`,
}),
],
module: {
Expand Down
7 changes: 7 additions & 0 deletions scripts/flow/react-devtools.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,10 @@

declare var __EXTENSION__: boolean;
declare var __TEST__: boolean;

declare var DARK_MODE_DIMMED_WARNING_COLOR: string;
declare var DARK_MODE_DIMMED_ERROR_COLOR: string;
declare var DARK_MODE_DIMMED_LOG_COLOR: string;
declare var LIGHT_MODE_DIMMED_WARNING_COLOR: string;
declare var LIGHT_MODE_DIMMED_ERROR_COLOR: string;
declare var LIGHT_MODE_DIMMED_LOG_COLOR: string;

0 comments on commit d938848

Please sign in to comment.