Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix utils gotoVSCode gotoWebStorm was not export as documentation with its params #162

Merged
merged 3 commits into from
Jan 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/CHANGELOG.v2.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## [2.0.1](https://github.com/zthxxx/react-dev-inspector/compare/v1.9.0...v2.0.1)

### Bug Fixes

- fix: fix utils `gotoVSCode` `gotoWebStorm` was not export as [documentation](https://react-dev-inspector.zthxxx.me/docs/inspector-component#oninspectelement) with its params.


## [2.0.0](https://github.com/zthxxx/react-dev-inspector/compare/v1.9.0...v2.0.0) (2023-09-04)

### Features
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-plugin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@react-dev-inspector/babel-plugin",
"version": "2.0.0",
"version": "2.0.1",
"sideEffects": false,
"description": "babel plugin for react-dev-inspector to generate source code position info into jsx properties",
"main": "lib",
Expand Down
2 changes: 1 addition & 1 deletion packages/inspector/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-dev-inspector",
"version": "2.0.0",
"version": "2.0.1",
"sideEffects": false,
"description": "dev-tool for inspect react components and jump to local IDE for component code.",
"main": "lib",
Expand Down
4 changes: 4 additions & 0 deletions packages/inspector/src/Inspector/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
export {
gotoVSCode,
gotoVSCodeInsiders,
gotoWebStorm,

gotoServerEditor,
/** @deprecated Use `gotoServerEditor` instead. */
gotoServerEditor as gotoEditor,
Expand Down
25 changes: 20 additions & 5 deletions packages/inspector/src/Inspector/utils/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,22 @@
import launchEditorEndpoint from 'react-dev-utils/launchEditorEndpoint'
import type { CodeInfo } from './inspect'


type CodeInfoLike = CodeInfo | { codeInfo: CodeInfo }

const getCodeInfo = (_codeInfo: CodeInfoLike): CodeInfo => (
'codeInfo' in _codeInfo
? _codeInfo.codeInfo
: _codeInfo
)


/**
* fetch server api to open the code editor
*/
export const gotoServerEditor = (codeInfo?: CodeInfo) => {
if (!codeInfo) return
export const gotoServerEditor = (_codeInfo?: CodeInfoLike) => {
if (!_codeInfo) return
const codeInfo = getCodeInfo(_codeInfo)

const {
lineNumber,
Expand Down Expand Up @@ -48,7 +59,9 @@ export const gotoServerEditor = (codeInfo?: CodeInfo) => {
*
* https://code.visualstudio.com/docs/editor/command-line#_opening-vs-code-with-urls
*/
export const gotoVSCode = (codeInfo: CodeInfo, options?: { insiders?: boolean }) => {
export const gotoVSCode = (_codeInfo: CodeInfoLike, options?: { insiders?: boolean }) => {
const codeInfo = getCodeInfo(_codeInfo)

if (!codeInfo.absolutePath) {
console.error(`[react-dev-inspector] Cannot open editor without source fileName`, codeInfo)
return
Expand All @@ -61,15 +74,17 @@ export const gotoVSCode = (codeInfo: CodeInfo, options?: { insiders?: boolean })
/**
* open source file in VSCode via it's url schema
*/
export const gotoVSCodeInsiders = (codeInfo: CodeInfo) => {
export const gotoVSCodeInsiders = (codeInfo: CodeInfoLike) => {
return gotoVSCode(codeInfo, { insiders: true })
}


/**
* open source file in WebStorm via it's url schema
*/
export const gotoWebStorm = (codeInfo: CodeInfo) => {
export const gotoWebStorm = (_codeInfo: CodeInfoLike) => {
const codeInfo = getCodeInfo(_codeInfo)

if (!codeInfo.absolutePath) {
console.error(`[react-dev-inspector] Cannot open editor without source fileName`, codeInfo)
return
Expand Down
24 changes: 18 additions & 6 deletions packages/inspector/src/Inspector/utils/inspect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,20 @@ export interface CodeDataAttribute {
* https://github.com/facebook/react/blob/v18.0.0/packages/react-reconciler/src/ReactFiber.new.js#L648-L649
*/
export const getCodeInfoFromDebugSource = (fiber?: Fiber): CodeInfo | undefined => {
if (!fiber?._debugSource) return undefined
if (!fiber) return undefined

const debugSource = (
fiber._debugSource
?? fiber._debugOwner?._debugSource
) as Source & { columnNumber?: number }

if (!debugSource) return undefined

const {
fileName,
lineNumber,
columnNumber,
} = fiber._debugSource as Source & { columnNumber?: number }
} = debugSource

if (fileName && lineNumber) {
return {
Expand Down Expand Up @@ -101,10 +108,15 @@ export const getCodeInfoFromProps = (fiber?: Fiber): CodeInfo | undefined => {
return undefined
}

export const getCodeInfoFromFiber = (fiber?: Fiber): CodeInfo | undefined => (
getCodeInfoFromProps(fiber)
?? getCodeInfoFromDebugSource(fiber)
)
export const getCodeInfoFromFiber = (fiber?: Fiber): CodeInfo | undefined => {
const codeInfos = [
getCodeInfoFromDebugSource(fiber),
getCodeInfoFromProps(fiber),
].filter(Boolean) as CodeInfo[]

if (!codeInfos.length) return undefined
return Object.assign({}, ...codeInfos)
}

/**
* give a `base` dom fiber,
Expand Down
2 changes: 1 addition & 1 deletion packages/middleware/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@react-dev-inspector/middleware",
"version": "2.0.0",
"version": "2.0.1",
"sideEffects": false,
"description": "express middleware for react-dev-inspector to launch local IDE",
"main": "lib",
Expand Down
2 changes: 1 addition & 1 deletion packages/umi3-plugin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@react-dev-inspector/umi3-plugin",
"version": "2.0.0",
"version": "2.0.1",
"sideEffects": false,
"description": "umi3 plugin for react-dev-inspector to add babel plugin and server middleware",
"main": "lib",
Expand Down
2 changes: 1 addition & 1 deletion packages/umi4-plugin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@react-dev-inspector/umi4-plugin",
"version": "2.0.0",
"version": "2.0.1",
"sideEffects": false,
"description": "umi4 plugin for react-dev-inspector to add babel plugin and server middleware",
"main": "lib",
Expand Down
2 changes: 1 addition & 1 deletion packages/vite-plugin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@react-dev-inspector/vite-plugin",
"version": "2.0.0",
"version": "2.0.1",
"sideEffects": false,
"description": "vite plugin for react-dev-inspector to add server middleware. support vite2/vite3/vite4",
"main": "lib",
Expand Down
Loading