CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-react-devtools

Standalone development tool for debugging React applications outside of browser environments

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

editor-integration.mddocs/

Editor Integration

Utilities for integrating with code editors to enable "click to open in editor" functionality from DevTools, supporting major editors and IDE configurations.

Capabilities

File Path Validation

Checks if a file path exists within the specified project roots.

/**
 * Checks if a file path exists within project roots
 * @param maybeRelativePath - Absolute or relative file path to check
 * @param absoluteProjectRoots - Array of absolute project root directory paths
 * @returns True if file exists within project roots, false otherwise
 */
function doesFilePathExist(maybeRelativePath: string, absoluteProjectRoots: string[]): boolean;

Usage Examples:

import { doesFilePathExist } from "react-devtools-core/src/editor";

const projectRoots = ['/path/to/project', '/path/to/shared'];

// Check absolute path
const exists1 = doesFilePathExist('/path/to/project/src/App.js', projectRoots);
// returns: true (if file exists)

// Check relative path
const exists2 = doesFilePathExist('src/components/Button.js', projectRoots);
// returns: true (if file exists in any project root)

// Non-existent file
const exists3 = doesFilePathExist('nonexistent.js', projectRoots);
// returns: false

Launch Editor

Opens a file in the user's preferred code editor at a specific line number.

/**
 * Opens a file in the user's preferred editor at a specific line
 * @param maybeRelativePath - Path to the file to open (absolute or relative)
 * @param lineNumber - Line number to navigate to (1-based)
 * @param absoluteProjectRoots - Array of absolute project root directories for path resolution
 */
function launchEditor(
  maybeRelativePath: string,
  lineNumber: number,
  absoluteProjectRoots: string[]
): void;

Usage Examples:

import { launchEditor } from "react-devtools-core/src/editor";

const projectRoots = ['/path/to/project'];

// Open file at specific line
launchEditor('src/App.js', 25, projectRoots);

// Open file at beginning (line 1)
launchEditor('src/components/Button.js', 1, projectRoots);

// Absolute path
launchEditor('/path/to/project/src/utils/helper.js', 42, projectRoots);

Supported Editors

Visual Studio Code

Automatically detected and launched with code command.

// Opens in VS Code with line navigation
launchEditor('src/App.js', 25, projectRoots);
// Executes: code --goto src/App.js:25

JetBrains IDEs

Supports WebStorm, IntelliJ IDEA, and other JetBrains products.

// Detected via process name and launched appropriately
launchEditor('src/App.js', 25, projectRoots);
// May execute: webstorm --line 25 src/App.js

Atom

Legacy support for Atom editor.

// Opens in Atom with line navigation
launchEditor('src/App.js', 25, projectRoots);
// Executes: atom src/App.js:25

Sublime Text

Supports both Sublime Text 2 and 3.

// Opens in Sublime Text
launchEditor('src/App.js', 25, projectRoots);
// Executes: subl src/App.js:25

Terminal Editors

Supports Vim, Emacs, and Nano with terminal detection.

// Opens in Vim (if configured as terminal editor)
launchEditor('src/App.js', 25, projectRoots);
// Executes: vim +25 src/App.js

// Opens in Emacs
launchEditor('src/App.js', 25, projectRoots);
// Executes: emacs +25 src/App.js

Editor Detection

Process-Based Detection

The editor integration automatically detects running editors by examining system processes and maps them to appropriate launch commands.

Common Editor Mappings:

const COMMON_EDITORS = {
  // macOS Applications
  '/Applications/Visual Studio Code.app/Contents/MacOS/Electron': 'code',
  '/Applications/Atom.app/Contents/MacOS/Atom': 'atom',
  '/Applications/Sublime Text.app/Contents/MacOS/Sublime Text': '/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl',
  
  // Command line editors
  'vim': 'vim',
  'nvim': 'nvim',
  'emacs': 'emacs',
  'nano': 'nano'
};

Environment Variable Configuration

Set preferred editor via environment variables:

# Set preferred editor
export EDITOR=code
export VISUAL=code

# Or set React DevTools specific editor
export REACT_EDITOR=code

Usage in different shells:

# Bash/Zsh
export REACT_EDITOR=code

# Fish
set -x REACT_EDITOR code

# Windows Command Prompt
set REACT_EDITOR=code

# Windows PowerShell
$env:REACT_EDITOR = "code"

Advanced Configuration

Custom Editor Arguments

Different editors require different argument formats for line navigation:

/**
 * Editor-specific argument patterns for line navigation
 */
const editorLineArgs = {
  'vim': ['+{line}', '{file}'],
  'nvim': ['+{line}', '{file}'],
  'emacs': ['+{line}', '{file}'],
  'code': ['--goto', '{file}:{line}'],
  'atom': ['{file}:{line}'],
  'subl': ['{file}:{line}'],
  'webstorm': ['--line', '{line}', '{file}']
};

Project Root Resolution

The integration resolves file paths within project roots:

  1. Absolute Path Check: If file path is absolute and exists, use directly
  2. Relative Path Resolution: Try resolving relative to each project root
  3. Fallback: Use first project root as base if file not found

Example Resolution:

const projectRoots = ['/frontend', '/backend', '/shared'];
const filePath = 'src/components/Button.js';

// Resolution order:
// 1. /frontend/src/components/Button.js
// 2. /backend/src/components/Button.js  
// 3. /shared/src/components/Button.js
// 4. Use /frontend/src/components/Button.js (first root fallback)

Monorepo Support

For monorepo setups, configure multiple project roots:

import DevtoolsUI from "react-devtools-core/standalone";

// Configure for monorepo structure
DevtoolsUI.setProjectRoots([
  '/monorepo/packages/frontend',
  '/monorepo/packages/backend',
  '/monorepo/packages/shared',
  '/monorepo/apps/mobile'
]);

// DevTools will resolve files across all roots
// Click on component -> opens correct file in appropriate package

Integration with DevTools UI

Setup in CLI Tool

When using the CLI tool, pass project roots as arguments:

# Single project
react-devtools /path/to/project

# Multiple projects (monorepo)
react-devtools /path/to/frontend /path/to/backend /path/to/shared

Setup in Standalone Server

Configure project roots programmatically:

import DevtoolsUI from "react-devtools-core/standalone";

// Setup editor integration
DevtoolsUI.setProjectRoots([
  process.cwd(),
  path.join(process.cwd(), '..', 'shared')
]);

// Start server with editor support
const server = DevtoolsUI.startServer();

React Native Integration

React Native projects benefit from editor integration for navigating to component source:

import { connectToDevTools } from "react-devtools-core/backend";

// Connect with project root information
connectToDevTools({
  // Project roots passed from CLI or configuration
  // Enables click-to-open functionality in React Native
});

Troubleshooting

Editor Not Opening

Check Editor in PATH:

# Verify editor command is available
which code
which atom
which subl

# Add to PATH if needed (VS Code example)
export PATH="$PATH:/Applications/Visual Studio Code.app/Contents/Resources/app/bin"

Set Explicit Editor:

# Override automatic detection
export REACT_EDITOR=code
export REACT_EDITOR="/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code"

File Not Found

Verify Project Roots:

// Check project roots are correct
console.log('Project roots:', projectRoots);

// Verify file exists
import fs from 'fs';
const fullPath = path.join(projectRoot, filePath);
console.log('File exists:', fs.existsSync(fullPath));

Debug Path Resolution:

import { doesFilePathExist } from "react-devtools-core/src/editor";

const filePath = 'src/App.js';
const projectRoots = ['/path/to/project'];

console.log('File exists:', doesFilePathExist(filePath, projectRoots));

// Manual check
projectRoots.forEach(root => {
  const fullPath = path.join(root, filePath);
  console.log(`${root}: ${fs.existsSync(fullPath)}`);
});

Permission Issues

macOS Security:

# Grant permissions to editor if needed
xattr -d com.apple.quarantine /Applications/Visual\ Studio\ Code.app

Linux Permissions:

# Ensure editor executable has proper permissions
chmod +x /usr/local/bin/code

Windows PATH Issues:

# Add VS Code to PATH
setx PATH "%PATH%;%LOCALAPPDATA%\Programs\Microsoft VS Code\bin"

Install with Tessl CLI

npx tessl i tessl/npm-react-devtools

docs

backend-integration.md

cli-tool.md

editor-integration.md

index.md

standalone-server.md

tile.json