Unverified Commit 3368fdde authored by youngvform's avatar youngvform Committed by GitHub

Fix to parse REACT_EDITOR in env (#21331)

I made an issue #[21330](https://github.com/vercel/next.js/issues/21330).

I think this line https://github.com/vercel/next.js/blob/0bd175264b000895cccd75f4499bdf55daad4882/packages/react-dev-overlay/src/internal/helpers/launchEditor.ts#L216 return string array and toLowerCase is undefined in string array so throw error.

I fixed it by referring to [launchEditor](https://github.com/facebook/create-react-app/blob/7e4949a20fc828577fb7626a3262832422f3ae3b/packages/react-dev-utils/launchEditor.js) of create react app.
parent c619f41f
......@@ -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)
......@@ -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') {
......@@ -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') {
......@@ -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]
}
}
}
......@@ -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) {
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment