Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for React Devtools (#287)
This change adds support for debugging Ink apps using React Devtools. All you need to do is run your CLI with `DEV=true` environment variable set. ``` $ DEV=true my-cli ``` Then, start up React Devtools itself to debug: ``` $ npx react-devtools ``` After it starts up, you should see the component tree of your CLI. You can even inspect and change the props of components, and see the results immediatelly in the CLI, without restarting it.
- Loading branch information
Vadim Demedes
committed
May 7, 2020
1 parent
2913ecf
commit 1a44aac
Showing
17 changed files
with
165 additions
and
39 deletions.
There are no files selected for viewing
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
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
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,66 @@ | ||
// Ignoring missing types error to avoid adding another dependency for this hack to work | ||
// @ts-ignore | ||
import ws from 'ws'; | ||
|
||
const customGlobal = global as any; | ||
|
||
// These things must exist before importing `react-devtools-core` | ||
customGlobal.WebSocket = ws; | ||
customGlobal.window = global; | ||
|
||
// Filter out Ink's internal components from devtools for a cleaner view. | ||
// Also, ince `react-devtools-shared` package isn't published on npm, we can't | ||
// use its types, that's why there are hard-coded values in `type` fields below. | ||
// See https://github.com/facebook/react/blob/edf6eac8a181860fd8a2d076a43806f1237495a1/packages/react-devtools-shared/src/types.js#L24 | ||
customGlobal.window.__REACT_DEVTOOLS_COMPONENT_FILTERS__ = [ | ||
{ | ||
// ComponentFilterElementType | ||
type: 1, | ||
// ElementTypeHostComponent | ||
value: 7, | ||
isEnabled: true | ||
}, | ||
{ | ||
// ComponentFilterDisplayName | ||
type: 2, | ||
value: 'InternalApp', | ||
isEnabled: true, | ||
isValid: true | ||
}, | ||
{ | ||
// ComponentFilterDisplayName | ||
type: 2, | ||
value: 'InternalAppContext', | ||
isEnabled: true, | ||
isValid: true | ||
}, | ||
{ | ||
// ComponentFilterDisplayName | ||
type: 2, | ||
value: 'InternalStdoutContext', | ||
isEnabled: true, | ||
isValid: true | ||
}, | ||
{ | ||
// ComponentFilterDisplayName | ||
type: 2, | ||
value: 'InternalStderrContext', | ||
isEnabled: true, | ||
isValid: true | ||
}, | ||
{ | ||
// ComponentFilterDisplayName | ||
type: 2, | ||
value: 'InternalStdinContext', | ||
isEnabled: true, | ||
isValid: true | ||
} | ||
]; | ||
|
||
// Ignoring missing types error to avoid adding another dependency for this hack to work | ||
// @ts-ignore | ||
import {connectToDevTools} from 'react-devtools-core'; | ||
|
||
if (process.env.DEV === 'true') { | ||
connectToDevTools(); | ||
} |
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