Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Meta
create-react-app
Commits
10c734b6
Commit
10c734b6
authored
7 years ago
by
Dan Abramov
Committed by
GitHub
7 years ago
Browse files
Options
Download
Email Patches
Plain Diff
Print error messages for editor integration (#2150)
parent
82687dd2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
packages/react-dev-utils/launchEditor.js
+37
-2
packages/react-dev-utils/launchEditor.js
with
37 additions
and
2 deletions
+37
-2
packages/react-dev-utils/launchEditor.js
+
37
-
2
View file @
10c734b6
...
@@ -11,7 +11,8 @@
...
@@ -11,7 +11,8 @@
var
fs
=
require
(
'
fs
'
);
var
fs
=
require
(
'
fs
'
);
var
path
=
require
(
'
path
'
);
var
path
=
require
(
'
path
'
);
var
child_process
=
require
(
'
child_process
'
);
var
child_process
=
require
(
'
child_process
'
);
const
shellQuote
=
require
(
'
shell-quote
'
);
var
chalk
=
require
(
'
chalk
'
);
var
shellQuote
=
require
(
'
shell-quote
'
);
function
isTerminalEditor
(
editor
)
{
function
isTerminalEditor
(
editor
)
{
switch
(
editor
)
{
switch
(
editor
)
{
...
@@ -110,6 +111,31 @@ function guessEditor() {
...
@@ -110,6 +111,31 @@ function guessEditor() {
return
[
null
];
return
[
null
];
}
}
function
printInstructions
(
fileName
,
errorMessage
)
{
console
.
log
();
console
.
log
(
chalk
.
red
(
'
Could not open
'
+
path
.
basename
(
fileName
)
+
'
in the editor.
'
)
);
if
(
errorMessage
)
{
if
(
errorMessage
[
errorMessage
.
length
-
1
]
!==
'
.
'
)
{
errorMessage
+=
'
.
'
;
}
console
.
log
(
chalk
.
red
(
'
The editor process exited with an error:
'
+
errorMessage
)
);
}
console
.
log
();
console
.
log
(
'
To set up the editor integration, add something like
'
+
chalk
.
cyan
(
'
REACT_EDITOR=atom
'
)
+
'
to the
'
+
chalk
.
green
(
'
.env.local
'
)
+
'
file in your project folder
'
+
'
and restart the development server.
'
);
console
.
log
();
}
var
_childProcess
=
null
;
var
_childProcess
=
null
;
function
launchEditor
(
fileName
,
lineNumber
)
{
function
launchEditor
(
fileName
,
lineNumber
)
{
if
(
!
fs
.
existsSync
(
fileName
))
{
if
(
!
fs
.
existsSync
(
fileName
))
{
...
@@ -124,6 +150,7 @@ function launchEditor(fileName, lineNumber) {
...
@@ -124,6 +150,7 @@ function launchEditor(fileName, lineNumber) {
let
[
editor
,
...
args
]
=
guessEditor
();
let
[
editor
,
...
args
]
=
guessEditor
();
if
(
!
editor
)
{
if
(
!
editor
)
{
printInstructions
(
fileName
,
null
);
return
;
return
;
}
}
...
@@ -154,8 +181,16 @@ function launchEditor(fileName, lineNumber) {
...
@@ -154,8 +181,16 @@ function launchEditor(fileName, lineNumber) {
}
else
{
}
else
{
_childProcess
=
child_process
.
spawn
(
editor
,
args
,
{
stdio
:
'
inherit
'
});
_childProcess
=
child_process
.
spawn
(
editor
,
args
,
{
stdio
:
'
inherit
'
});
}
}
_childProcess
.
on
(
'
exit
'
,
function
()
{
_childProcess
.
on
(
'
exit
'
,
function
(
errorCode
)
{
_childProcess
=
null
;
_childProcess
=
null
;
if
(
errorCode
)
{
printInstructions
(
fileName
,
'
(code
'
+
errorCode
+
'
)
'
);
}
});
_childProcess
.
on
(
'
error
'
,
function
(
error
)
{
printInstructions
(
fileName
,
error
.
message
);
});
});
}
}
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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