Skip to content

Commit

Permalink
Fix to parse REACT_EDITOR in env
Browse files Browse the repository at this point in the history
  • Loading branch information
youngvform committed Jan 19, 2021
1 parent 699a7ae commit 0a3c88f
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions packages/react-dev-overlay/src/internal/helpers/launchEditor.ts
Expand Up @@ -210,7 +210,7 @@ function getArgumentsForLineNumber(
}
}

function guessEditor(): string | null {
function guessEditor(): string[] {
// Explicit config always wins
if (process.env.REACT_EDITOR) {
return shellQuote.parse(process.env.REACT_EDITOR)
Expand All @@ -226,7 +226,7 @@ function guessEditor(): string | null {
for (let i = 0; i < processNames.length; i++) {
const processName = processNames[i]
if (output.indexOf(processName) !== -1) {
return (COMMON_EDITORS_MACOS as any)[processName]
return [(COMMON_EDITORS_MACOS as any)[processName]]
}
}
} else if (process.platform === 'win32') {
Expand All @@ -242,7 +242,7 @@ function guessEditor(): string | null {
const processPath = runningProcesses[i].trim()
const processName = path.basename(processPath)
if (COMMON_EDITORS_WIN.indexOf(processName) !== -1) {
return processPath
return [processPath]
}
}
} else if (process.platform === 'linux') {
Expand All @@ -256,7 +256,7 @@ function guessEditor(): string | null {
for (let i = 0; i < processNames.length; i++) {
const processName = processNames[i]
if (output.indexOf(processName) !== -1) {
return (COMMON_EDITORS_LINUX as any)[processName] as string
return [(COMMON_EDITORS_LINUX as any)[processName] as string]
}
}
}
Expand All @@ -266,12 +266,12 @@ function guessEditor(): string | null {

// Last resort, use old skool env vars
if (process.env.VISUAL) {
return process.env.VISUAL
return [process.env.VISUAL]
} else if (process.env.EDITOR) {
return process.env.EDITOR
return [process.env.EDITOR]
}

return null
return []
}

function printInstructions(fileName: string, errorMessage: string | null) {
Expand Down Expand Up @@ -317,8 +317,7 @@ function launchEditor(fileName: string, lineNumber: number, colNumber: number) {
colNumber = 1
}

const editor = guessEditor()
let args: string[] = []
let [editor, ...args] = guessEditor()

if (!editor) {
printInstructions(fileName, null)
Expand Down

0 comments on commit 0a3c88f

Please sign in to comment.