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 to parse REACT_EDITOR in env #21331

Merged
merged 2 commits into from Jan 26, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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