Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
45d8a7a5
Unverified
Commit
45d8a7a5
authored
May 03, 2020
by
Joe Haddad
Committed by
GitHub
May 03, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Fast Refresh] Fix terminal editors on macOS (#12430)
parent
5e80999c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
24 deletions
+32
-24
launchEditor.ts
...es/react-dev-overlay/src/internal/helpers/launchEditor.ts
+32
-24
No files found.
packages/react-dev-overlay/src/internal/helpers/launchEditor.ts
View file @
45d8a7a5
...
...
@@ -30,6 +30,7 @@ import shellQuote from 'shell-quote'
function
isTerminalEditor
(
editor
)
{
switch
(
editor
)
{
case
'vi'
:
case
'vim'
:
case
'emacs'
:
case
'nano'
:
{
...
...
@@ -311,7 +312,6 @@ function printInstructions(fileName, errorMessage) {
console
.
log
()
}
let
_childProcess
=
null
function
launchEditor
(
fileName
:
string
,
lineNumber
:
number
,
colNumber
:
number
)
{
if
(
!
fs
.
existsSync
(
fileName
))
{
return
...
...
@@ -393,35 +393,43 @@ function launchEditor(fileName: string, lineNumber: number, colNumber: number) {
args
.
push
(
fileName
)
}
if
(
_childProcess
&&
isTerminalEditor
(
editor
))
{
// There's an existing editor process already and it's attached
// to the terminal, so go kill it. Otherwise two separate editor
// instances attach to the stdin/stdout which gets confusing.
_childProcess
.
kill
(
'SIGKILL'
)
}
let
p
:
child_process
.
ChildProcess
if
(
process
.
platform
===
'win32'
)
{
// On Windows, launch the editor in a shell because spawn can only
// launch .exe files.
_childProcess
=
child_process
.
spawn
(
'cmd.exe'
,
[
'/C'
,
editor
].
concat
(
args
),
{
stdio
:
'inherit'
}
)
p
=
child_process
.
spawn
(
'cmd.exe'
,
[
'/C'
,
editor
].
concat
(
args
),
{
stdio
:
'inherit'
,
})
}
else
if
(
isTerminalEditor
(
editor
))
{
if
(
process
.
platform
===
'darwin'
)
{
p
=
child_process
.
spawn
(
'osascript'
,
[
'-e'
,
`tell application "Terminal" to do script "
${
shellQuote
.
quote
([
editor
,
...
args
,
])}
"`
,
],
{
stdio
:
'ignore'
}
)
}
else
{
printInstructions
(
fileName
,
'Terminal editors can only be used on macOS.'
)
}
}
else
{
_childProcess
=
child_process
.
spawn
(
editor
,
args
,
{
stdio
:
'inherit'
})
p
=
child_process
.
spawn
(
editor
,
args
,
{
stdio
:
'inherit'
})
}
_childProcess
.
on
(
'exit'
,
function
(
errorCode
)
{
_childProcess
=
null
if
(
errorCode
)
{
printInstructions
(
fileName
,
'(code '
+
errorCode
+
')'
)
}
})
_childProcess
.
on
(
'error'
,
function
(
error
)
{
printInstructions
(
fileName
,
error
.
message
)
})
if
(
p
)
{
p
.
on
(
'exit'
,
function
(
errorCode
)
{
if
(
errorCode
)
{
printInstructions
(
fileName
,
'(code '
+
errorCode
+
')'
)
}
})
p
.
on
(
'error'
,
function
(
error
)
{
printInstructions
(
fileName
,
error
.
message
)
})
}
}
export
{
launchEditor
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment