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
37e3ec8d
Unverified
Commit
37e3ec8d
authored
May 02, 2020
by
Joe Haddad
Committed by
GitHub
May 02, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Fast Refresh] Click to open in editor (#12397)
parent
eab41aba
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
581 additions
and
6 deletions
+581
-6
package.json
packages/react-dev-overlay/package.json
+2
-0
CodeFrame.tsx
...v-overlay/src/internal/components/CodeFrame/CodeFrame.tsx
+31
-2
styles.tsx
...-dev-overlay/src/internal/components/CodeFrame/styles.tsx
+15
-0
RuntimeError.tsx
...react-dev-overlay/src/internal/container/RuntimeError.tsx
+60
-2
launchEditor.ts
...es/react-dev-overlay/src/internal/helpers/launchEditor.ts
+427
-0
middleware.ts
packages/react-dev-overlay/src/middleware.ts
+38
-2
yarn.lock
yarn.lock
+8
-0
No files found.
packages/react-dev-overlay/package.json
View file @
37e3ec8d
...
...
@@ -18,7 +18,9 @@
"dependencies"
:
{
"@babel/code-frame"
:
"7.8.3"
,
"anser"
:
"1.4.9"
,
"chalk"
:
"4.0.0"
,
"classnames"
:
"2.2.6"
,
"shell-quote"
:
"1.7.2"
,
"source-map"
:
"0.8.0-beta.0"
,
"stacktrace-parser"
:
"0.1.9"
,
"strip-ansi"
:
"6.0.0"
...
...
packages/react-dev-overlay/src/internal/components/CodeFrame/CodeFrame.tsx
View file @
37e3ec8d
...
...
@@ -40,11 +40,40 @@ export const CodeFrame: React.FC<CodeFrameProps> = function CodeFrame({
})
},
[
formattedFrame
])
const
open
=
React
.
useCallback
(()
=>
{
const
params
=
new
URLSearchParams
()
for
(
const
key
in
stackFrame
)
{
params
.
append
(
key
,
(
stackFrame
[
key
]
??
''
).
toString
())
}
self
.
fetch
(
`/__nextjs_launch-editor?
${
params
.
toString
()}
`
).
then
(
()
=>
{},
()
=>
{
// TODO: report error
}
)
},
[
stackFrame
])
// TODO: make the caret absolute
return
(
<
div
data
-
nextjs
-
codeframe
>
<
p
>
<
p
role=
"link"
onClick=
{
open
}
tabIndex=
{
0
}
>
<
span
>
{
getFrameSource
(
stackFrame
)
}
@
{
stackFrame
.
methodName
}
</
span
>
<
svg
xmlns=
"http://www.w3.org/2000/svg"
viewBox=
"0 0 24 24"
fill=
"none"
stroke=
"currentColor"
strokeWidth=
"2"
strokeLinecap=
"round"
strokeLinejoin=
"round"
>
<
path
d=
"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"
></
path
>
<
polyline
points=
"15 3 21 3 21 9"
></
polyline
>
<
line
x1=
"10"
y1=
"14"
x2=
"21"
y2=
"3"
></
line
>
</
svg
>
</
p
>
<
hr
/>
<
pre
>
...
...
packages/react-dev-overlay/src/internal/components/CodeFrame/styles.tsx
View file @
37e3ec8d
...
...
@@ -33,6 +33,21 @@ const styles = css`
border-bottom-width: 1px;
border-color: var(--color-ansi-fg);
}
[data-nextjs-codeframe] > p {
display: flex;
align-items: center;
justify-content: space-between;
cursor: pointer;
}
[data-nextjs-codeframe] > p:hover {
text-decoration: underline dotted;
}
[data-nextjs-codeframe] > p > svg {
width: auto;
height: 1em;
margin-left: 0.5rem;
}
`
export
{
styles
}
packages/react-dev-overlay/src/internal/container/RuntimeError.tsx
View file @
37e3ec8d
...
...
@@ -14,10 +14,48 @@ const CallStackFrame: React.FC<{
// TODO: render error or external indicator
const
f
:
StackFrame
=
frame
.
originalStackFrame
??
frame
.
sourceStackFrame
const
hasSource
=
Boolean
(
frame
.
originalStackFrame
?.
file
)
const
open
=
React
.
useCallback
(()
=>
{
if
(
!
hasSource
)
return
const
params
=
new
URLSearchParams
()
for
(
const
key
in
f
)
{
params
.
append
(
key
,
(
f
[
key
]
??
''
).
toString
())
}
self
.
fetch
(
`/__nextjs_launch-editor?
${
params
.
toString
()}
`
).
then
(
()
=>
{},
()
=>
{
// TODO: report error
}
)
},
[
hasSource
,
f
])
return
(
<
div
data
-
nextjs
-
call
-
stack
-
frame
>
<
h6
>
{
f
.
methodName
}
</
h6
>
<
p
>
{
getFrameSource
(
f
)
}
</
p
>
<
div
data
-
has
-
source=
{
hasSource
?
'true'
:
undefined
}
tabIndex=
{
hasSource
?
0
:
undefined
}
role=
{
hasSource
?
'link'
:
undefined
}
onClick=
{
open
}
>
<
span
>
{
getFrameSource
(
f
)
}
</
span
>
<
svg
xmlns=
"http://www.w3.org/2000/svg"
viewBox=
"0 0 24 24"
fill=
"none"
stroke=
"currentColor"
strokeWidth=
"2"
strokeLinecap=
"round"
strokeLinejoin=
"round"
>
<
path
d=
"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"
></
path
>
<
polyline
points=
"15 3 21 3 21 9"
></
polyline
>
<
line
x1=
"10"
y1=
"14"
x2=
"21"
y2=
"3"
></
line
>
</
svg
>
</
div
>
</
div
>
)
}
...
...
@@ -98,11 +136,31 @@ export const styles = css`
font-family: var(--font-stack-monospace);
color: rgba(25, 25, 25, 1);
}
[data-nextjs-call-stack-frame] > p {
[data-nextjs-call-stack-frame] > div {
display: flex;
align-items: center;
margin-bottom: 1rem;
padding-left: 0.75rem;
font-size: 0.875rem;
color: rgba(25, 25, 25, 0.5);
}
[data-nextjs-call-stack-frame] > div > svg {
width: auto;
height: 0.875rem;
margin-left: 0.5rem;
display: none;
}
[data-nextjs-call-stack-frame] > div[data-has-source] {
cursor: pointer;
}
[data-nextjs-call-stack-frame] > div[data-has-source]:hover {
text-decoration: underline dotted;
}
[data-nextjs-call-stack-frame] > div[data-has-source] > svg {
display: unset;
}
`
export
{
RuntimeError
}
packages/react-dev-overlay/src/internal/helpers/launchEditor.ts
0 → 100644
View file @
37e3ec8d
/**
* MIT License
*
* Copyright (c) 2015-present, Facebook, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import
chalk
from
'chalk'
import
child_process
from
'child_process'
import
fs
from
'fs'
import
os
from
'os'
import
path
from
'path'
import
shellQuote
from
'shell-quote'
function
isTerminalEditor
(
editor
)
{
switch
(
editor
)
{
case
'vim'
:
case
'emacs'
:
case
'nano'
:
{
return
true
}
default
:
{
}
}
return
false
}
// Map from full process name to binary that starts the process
// We can't just re-use full process name, because it will spawn a new instance
// of the app every time
const
COMMON_EDITORS_MACOS
=
{
'/Applications/Atom.app/Contents/MacOS/Atom'
:
'atom'
,
'/Applications/Atom Beta.app/Contents/MacOS/Atom Beta'
:
'/Applications/Atom Beta.app/Contents/MacOS/Atom Beta'
,
'/Applications/Brackets.app/Contents/MacOS/Brackets'
:
'brackets'
,
'/Applications/Sublime Text.app/Contents/MacOS/Sublime Text'
:
'/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl'
,
'/Applications/Sublime Text Dev.app/Contents/MacOS/Sublime Text'
:
'/Applications/Sublime Text Dev.app/Contents/SharedSupport/bin/subl'
,
'/Applications/Sublime Text 2.app/Contents/MacOS/Sublime Text 2'
:
'/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl'
,
'/Applications/Visual Studio Code.app/Contents/MacOS/Electron'
:
'/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code'
,
'/Applications/Visual Studio Code - Insiders.app/Contents/MacOS/Electron'
:
'/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/bin/code'
,
'/Applications/VSCodium.app/Contents/MacOS/Electron'
:
'/Applications/VSCodium.app/Contents/Resources/app/bin/code'
,
'/Applications/AppCode.app/Contents/MacOS/appcode'
:
'/Applications/AppCode.app/Contents/MacOS/appcode'
,
'/Applications/CLion.app/Contents/MacOS/clion'
:
'/Applications/CLion.app/Contents/MacOS/clion'
,
'/Applications/IntelliJ IDEA.app/Contents/MacOS/idea'
:
'/Applications/IntelliJ IDEA.app/Contents/MacOS/idea'
,
'/Applications/PhpStorm.app/Contents/MacOS/phpstorm'
:
'/Applications/PhpStorm.app/Contents/MacOS/phpstorm'
,
'/Applications/PyCharm.app/Contents/MacOS/pycharm'
:
'/Applications/PyCharm.app/Contents/MacOS/pycharm'
,
'/Applications/PyCharm CE.app/Contents/MacOS/pycharm'
:
'/Applications/PyCharm CE.app/Contents/MacOS/pycharm'
,
'/Applications/RubyMine.app/Contents/MacOS/rubymine'
:
'/Applications/RubyMine.app/Contents/MacOS/rubymine'
,
'/Applications/WebStorm.app/Contents/MacOS/webstorm'
:
'/Applications/WebStorm.app/Contents/MacOS/webstorm'
,
'/Applications/MacVim.app/Contents/MacOS/MacVim'
:
'mvim'
,
'/Applications/GoLand.app/Contents/MacOS/goland'
:
'/Applications/GoLand.app/Contents/MacOS/goland'
,
'/Applications/Rider.app/Contents/MacOS/rider'
:
'/Applications/Rider.app/Contents/MacOS/rider'
,
}
const
COMMON_EDITORS_LINUX
=
{
atom
:
'atom'
,
Brackets
:
'brackets'
,
code
:
'code'
,
'code-insiders'
:
'code-insiders'
,
vscodium
:
'vscodium'
,
emacs
:
'emacs'
,
gvim
:
'gvim'
,
'idea.sh'
:
'idea'
,
'phpstorm.sh'
:
'phpstorm'
,
'pycharm.sh'
:
'pycharm'
,
'rubymine.sh'
:
'rubymine'
,
sublime_text
:
'sublime_text'
,
vim
:
'vim'
,
'webstorm.sh'
:
'webstorm'
,
'goland.sh'
:
'goland'
,
'rider.sh'
:
'rider'
,
}
const
COMMON_EDITORS_WIN
=
[
'Brackets.exe'
,
'Code.exe'
,
'Code - Insiders.exe'
,
'VSCodium.exe'
,
'atom.exe'
,
'sublime_text.exe'
,
'notepad++.exe'
,
'clion.exe'
,
'clion64.exe'
,
'idea.exe'
,
'idea64.exe'
,
'phpstorm.exe'
,
'phpstorm64.exe'
,
'pycharm.exe'
,
'pycharm64.exe'
,
'rubymine.exe'
,
'rubymine64.exe'
,
'webstorm.exe'
,
'webstorm64.exe'
,
'goland.exe'
,
'goland64.exe'
,
'rider.exe'
,
'rider64.exe'
,
]
// Transpiled version of: /^([A-Za-z]:[/\\])?[\p{L}0-9/.\-_\\]+$/u
// Non-transpiled version requires support for Unicode property regex. Allows
// alphanumeric characters, periods, dashes, slashes, and underscores.
const
WINDOWS_FILE_NAME_WHITELIST
=
/^
([
A-Za-z
]
:
[/\\])?(?:[\x
2D-9A-Z
\\
_a-z
\x
AA
\x
B5
\x
BA
\x
C0-
\x
D6
\x
D8-
\x
F6
\x
F8-
\u
02C1
\u
02C6-
\u
02D1
\u
02E0-
\u
02E4
\u
02EC
\u
02EE
\u
0370-
\u
0374
\u
0376
\u
0377
\u
037A-
\u
037D
\u
037F
\u
0386
\u
0388-
\u
038A
\u
038C
\u
038E-
\u
03A1
\u
03A3-
\u
03F5
\u
03F7-
\u
0481
\u
048A-
\u
052F
\u
0531-
\u
0556
\u
0559
\u
0560-
\u
0588
\u
05D0-
\u
05EA
\u
05EF-
\u
05F2
\u
0620-
\u
064A
\u
066E
\u
066F
\u
0671-
\u
06D3
\u
06D5
\u
06E5
\u
06E6
\u
06EE
\u
06EF
\u
06FA-
\u
06FC
\u
06FF
\u
0710
\u
0712-
\u
072F
\u
074D-
\u
07A5
\u
07B1
\u
07CA-
\u
07EA
\u
07F4
\u
07F5
\u
07FA
\u
0800-
\u
0815
\u
081A
\u
0824
\u
0828
\u
0840-
\u
0858
\u
0860-
\u
086A
\u
08A0-
\u
08B4
\u
08B6-
\u
08BD
\u
0904-
\u
0939
\u
093D
\u
0950
\u
0958-
\u
0961
\u
0971-
\u
0980
\u
0985-
\u
098C
\u
098F
\u
0990
\u
0993-
\u
09A8
\u
09AA-
\u
09B0
\u
09B2
\u
09B6-
\u
09B9
\u
09BD
\u
09CE
\u
09DC
\u
09DD
\u
09DF-
\u
09E1
\u
09F0
\u
09F1
\u
09FC
\u
0A05-
\u
0A0A
\u
0A0F
\u
0A10
\u
0A13-
\u
0A28
\u
0A2A-
\u
0A30
\u
0A32
\u
0A33
\u
0A35
\u
0A36
\u
0A38
\u
0A39
\u
0A59-
\u
0A5C
\u
0A5E
\u
0A72-
\u
0A74
\u
0A85-
\u
0A8D
\u
0A8F-
\u
0A91
\u
0A93-
\u
0AA8
\u
0AAA-
\u
0AB0
\u
0AB2
\u
0AB3
\u
0AB5-
\u
0AB9
\u
0ABD
\u
0AD0
\u
0AE0
\u
0AE1
\u
0AF9
\u
0B05-
\u
0B0C
\u
0B0F
\u
0B10
\u
0B13-
\u
0B28
\u
0B2A-
\u
0B30
\u
0B32
\u
0B33
\u
0B35-
\u
0B39
\u
0B3D
\u
0B5C
\u
0B5D
\u
0B5F-
\u
0B61
\u
0B71
\u
0B83
\u
0B85-
\u
0B8A
\u
0B8E-
\u
0B90
\u
0B92-
\u
0B95
\u
0B99
\u
0B9A
\u
0B9C
\u
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
\u
128D
\u
1290-
\u
12B0
\u
12B2-
\u
12B5
\u
12B8-
\u
12BE
\u
12C0
\u
12C2-
\u
12C5
\u
12C8-
\u
12D6
\u
12D8-
\u
1310
\u
1312-
\u
1315
\u
1318-
\u
135A
\u
1380-
\u
138F
\u
13A0-
\u
13F5
\u
13F8-
\u
13FD
\u
1401-
\u
166C
\u
166F-
\u
167F
\u
1681-
\u
169A
\u
16A0-
\u
16EA
\u
16F1-
\u
16F8
\u
1700-
\u
170C
\u
170E-
\u
1711
\u
1720-
\u
1731
\u
1740-
\u
1751
\u
1760-
\u
176C
\u
176E-
\u
1770
\u
1780-
\u
17B3
\u
17D7
\u
17DC
\u
1820-
\u
1878
\u
1880-
\u
1884
\u
1887-
\u
18A8
\u
18AA
\u
18B0-
\u
18F5
\u
1900-
\u
191E
\u
1950-
\u
196D
\u
1970-
\u
1974
\u
1980-
\u
19AB
\u
19B0-
\u
19C9
\u
1A00-
\u
1A16
\u
1A20-
\u
1A54
\u
1AA7
\u
1B05-
\u
1B33
\u
1B45-
\u
1B4B
\u
1B83-
\u
1BA0
\u
1BAE
\u
1BAF
\u
1BBA-
\u
1BE5
\u
1C00-
\u
1C23
\u
1C4D-
\u
1C4F
\u
1C5A-
\u
1C7D
\u
1C80-
\u
1C88
\u
1C90-
\u
1CBA
\u
1CBD-
\u
1CBF
\u
1CE9-
\u
1CEC
\u
1CEE-
\u
1CF1
\u
1CF5
\u
1CF6
\u
1D00-
\u
1DBF
\u
1E00-
\u
1F15
\u
1F18-
\u
1F1D
\u
1F20-
\u
1F45
\u
1F48-
\u
1F4D
\u
1F50-
\u
1F57
\u
1F59
\u
1F5B
\u
1F5D
\u
1F5F-
\u
1F7D
\u
1F80-
\u
1FB4
\u
1FB6-
\u
1FBC
\u
1FBE
\u
1FC2-
\u
1FC4
\u
1FC6-
\u
1FCC
\u
1FD0-
\u
1FD3
\u
1FD6-
\u
1FDB
\u
1FE0-
\u
1FEC
\u
1FF2-
\u
1FF4
\u
1FF6-
\u
1FFC
\u
2071
\u
207F
\u
2090-
\u
209C
\u
2102
\u
2107
\u
210A-
\u
2113
\u
2115
\u
2119-
\u
211D
\u
2124
\u
2126
\u
2128
\u
212A-
\u
212D
\u
212F-
\u
2139
\u
213C-
\u
213F
\u
2145-
\u
2149
\u
214E
\u
2183
\u
2184
\u
2C00-
\u
2C2E
\u
2C30-
\u
2C5E
\u
2C60-
\u
2CE4
\u
2CEB-
\u
2CEE
\u
2CF2
\u
2CF3
\u
2D00-
\u
2D25
\u
2D27
\u
2D2D
\u
2D30-
\u
2D67
\u
2D6F
\u
2D80-
\u
2D96
\u
2DA0-
\u
2DA6
\u
2DA8-
\u
2DAE
\u
2DB0-
\u
2DB6
\u
2DB8-
\u
2DBE
\u
2DC0-
\u
2DC6
\u
2DC8-
\u
2DCE
\u
2DD0-
\u
2DD6
\u
2DD8-
\u
2DDE
\u
2E2F
\u
3005
\u
3006
\u
3031-
\u
3035
\u
303B
\u
303C
\u
3041-
\u
3096
\u
309D-
\u
309F
\u
30A1-
\u
30FA
\u
30FC-
\u
30FF
\u
3105-
\u
312F
\u
3131-
\u
318E
\u
31A0-
\u
31BA
\u
31F0-
\u
31FF
\u
3400-
\u
4DB5
\u
4E00-
\u
9FEF
\u
A000-
\u
A48C
\u
A4D0-
\u
A4FD
\u
A500-
\u
A60C
\u
A610-
\u
A61F
\u
A62A
\u
A62B
\u
A640-
\u
A66E
\u
A67F-
\u
A69D
\u
A6A0-
\u
A6E5
\u
A717-
\u
A71F
\u
A722-
\u
A788
\u
A78B-
\u
A7B9
\u
A7F7-
\u
A801
\u
A803-
\u
A805
\u
A807-
\u
A80A
\u
A80C-
\u
A822
\u
A840-
\u
A873
\u
A882-
\u
A8B3
\u
A8F2-
\u
A8F7
\u
A8FB
\u
A8FD
\u
A8FE
\u
A90A-
\u
A925
\u
A930-
\u
A946
\u
A960-
\u
A97C
\u
A984-
\u
A9B2
\u
A9CF
\u
A9E0-
\u
A9E4
\u
A9E6-
\u
A9EF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u
DFFF
]
|
\u
D86D
[\u
DC00-
\u
DF34
\u
DF40-
\u
DFFF
]
|
\u
D86E
[\u
DC00-
\u
DC1D
\u
DC20-
\u
DFFF
]
|
\u
D873
[\u
DC00-
\u
DEA1
\u
DEB0-
\u
DFFF
]
|
\u
D87A
[\u
DC00-
\u
DFE0
]
|
\u
D87E
[\u
DC00-
\u
DE1D
])
+$/
function
addWorkspaceToArgumentsIfExists
(
args
,
workspace
)
{
if
(
workspace
)
{
args
.
unshift
(
workspace
)
}
return
args
}
function
getArgumentsForLineNumber
(
editor
,
fileName
,
lineNumber
,
colNumber
,
workspace
)
{
const
editorBasename
=
path
.
basename
(
editor
).
replace
(
/
\.(
exe|cmd|bat
)
$/i
,
''
)
switch
(
editorBasename
)
{
case
'atom'
:
case
'Atom'
:
case
'Atom Beta'
:
case
'subl'
:
case
'sublime'
:
case
'sublime_text'
:
{
return
[
fileName
+
':'
+
lineNumber
+
':'
+
colNumber
]
}
case
'wstorm'
:
case
'charm'
:
{
return
[
fileName
+
':'
+
lineNumber
]
}
case
'notepad++'
:
{
return
[
'-n'
+
lineNumber
,
'-c'
+
colNumber
,
fileName
]
}
case
'vim'
:
case
'mvim'
:
case
'joe'
:
case
'gvim'
:
{
return
[
'+'
+
lineNumber
,
fileName
]
}
case
'emacs'
:
case
'emacsclient'
:
{
return
[
'+'
+
lineNumber
+
':'
+
colNumber
,
fileName
]
}
case
'rmate'
:
case
'mate'
:
case
'mine'
:
{
return
[
'--line'
,
lineNumber
,
fileName
]
}
case
'code'
:
case
'Code'
:
case
'code-insiders'
:
case
'Code - Insiders'
:
case
'vscodium'
:
case
'VSCodium'
:
{
return
addWorkspaceToArgumentsIfExists
(
[
'-g'
,
fileName
+
':'
+
lineNumber
+
':'
+
colNumber
],
workspace
)
}
case
'appcode'
:
case
'clion'
:
case
'clion64'
:
case
'idea'
:
case
'idea64'
:
case
'phpstorm'
:
case
'phpstorm64'
:
case
'pycharm'
:
case
'pycharm64'
:
case
'rubymine'
:
case
'rubymine64'
:
case
'webstorm'
:
case
'webstorm64'
:
case
'goland'
:
case
'goland64'
:
case
'rider'
:
case
'rider64'
:
{
return
addWorkspaceToArgumentsIfExists
(
[
'--line'
,
lineNumber
,
fileName
],
workspace
)
}
default
:
{
// For all others, drop the lineNumber until we have
// a mapping above, since providing the lineNumber incorrectly
// can result in errors or confusing behavior.
return
[
fileName
]
}
}
}
function
guessEditor
()
{
// Explicit config always wins
if
(
process
.
env
.
REACT_EDITOR
)
{
return
shellQuote
.
parse
(
process
.
env
.
REACT_EDITOR
)
}
// We can find out which editor is currently running by:
// `ps x` on macOS and Linux
// `Get-Process` on Windows
try
{
if
(
process
.
platform
===
'darwin'
)
{
const
output
=
child_process
.
execSync
(
'ps x'
).
toString
()
const
processNames
=
Object
.
keys
(
COMMON_EDITORS_MACOS
)
for
(
let
i
=
0
;
i
<
processNames
.
length
;
i
++
)
{
const
processName
=
processNames
[
i
]
if
(
output
.
indexOf
(
processName
)
!==
-
1
)
{
return
[
COMMON_EDITORS_MACOS
[
processName
]]
}
}
}
else
if
(
process
.
platform
===
'win32'
)
{
// Some processes need elevated rights to get its executable path.
// Just filter them out upfront. This also saves 10-20ms on the command.
const
output
=
child_process
.
execSync
(
'wmic process where "executablepath is not null" get executablepath'
)
.
toString
()
const
runningProcesses
=
output
.
split
(
'
\
r
\
n'
)
for
(
let
i
=
0
;
i
<
runningProcesses
.
length
;
i
++
)
{
const
processPath
=
runningProcesses
[
i
].
trim
()
const
processName
=
path
.
basename
(
processPath
)
if
(
COMMON_EDITORS_WIN
.
indexOf
(
processName
)
!==
-
1
)
{
return
[
processPath
]
}
}
}
else
if
(
process
.
platform
===
'linux'
)
{
// --no-heading No header line
// x List all processes owned by you
// -o comm Need only names column
const
output
=
child_process
.
execSync
(
'ps x --no-heading -o comm --sort=comm'
)
.
toString
()
const
processNames
=
Object
.
keys
(
COMMON_EDITORS_LINUX
)
for
(
let
i
=
0
;
i
<
processNames
.
length
;
i
++
)
{
const
processName
=
processNames
[
i
]
if
(
output
.
indexOf
(
processName
)
!==
-
1
)
{
return
[
COMMON_EDITORS_LINUX
[
processName
]]
}
}
}
}
catch
(
error
)
{
// Ignore...
}
// Last resort, use old skool env vars
if
(
process
.
env
.
VISUAL
)
{
return
[
process
.
env
.
VISUAL
]
}
else
if
(
process
.
env
.
EDITOR
)
{
return
[
process
.
env
.
EDITOR
]
}
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
()
}
let
_childProcess
=
null
function
launchEditor
(
fileName
:
string
,
lineNumber
:
number
,
colNumber
:
number
)
{
if
(
!
fs
.
existsSync
(
fileName
))
{
return
}
// Sanitize lineNumber to prevent malicious use on win32
// via: https://github.com/nodejs/node/blob/c3bb4b1aa5e907d489619fb43d233c3336bfc03d/lib/child_process.js#L333
// and it should be a positive integer
if
(
!
(
Number
.
isInteger
(
lineNumber
)
&&
lineNumber
>
0
))
{
return
}
// colNumber is optional, but should be a positive integer too
// default is 1
if
(
!
(
Number
.
isInteger
(
colNumber
)
&&
colNumber
>
0
))
{
colNumber
=
1
}
let
[
editor
,
...
args
]
=
guessEditor
()
if
(
!
editor
)
{
printInstructions
(
fileName
,
null
)
return
}
if
(
editor
.
toLowerCase
()
===
'none'
)
{
return
}
if
(
process
.
platform
===
'linux'
&&
fileName
.
startsWith
(
'/mnt/'
)
&&
/Microsoft/i
.
test
(
os
.
release
())
)
{
// Assume WSL / "Bash on Ubuntu on Windows" is being used, and
// that the file exists on the Windows file system.
// `os.release()` is "4.4.0-43-Microsoft" in the current release
// build of WSL, see: https://github.com/Microsoft/BashOnWindows/issues/423#issuecomment-221627364
// When a Windows editor is specified, interop functionality can
// handle the path translation, but only if a relative path is used.
fileName
=
path
.
relative
(
''
,
fileName
)
}
// cmd.exe on Windows is vulnerable to RCE attacks given a file name of the
// form "C:\Users\myusername\Downloads\& curl 172.21.93.52". Use a whitelist
// to validate user-provided file names. This doesn't cover the entire range
// of valid file names but should cover almost all of them in practice.
if
(
process
.
platform
===
'win32'
&&
!
WINDOWS_FILE_NAME_WHITELIST
.
test
(
fileName
.
trim
())
)
{
console
.
log
()
console
.
log
(
chalk
.
red
(
'Could not open '
+
path
.
basename
(
fileName
)
+
' in the editor.'
)
)
console
.
log
()
console
.
log
(
'When running on Windows, file names are checked against a whitelist '
+
'to protect against remote code execution attacks. File names may '
+
'consist only of alphanumeric characters (all languages), periods, '
+
'dashes, slashes, and underscores.'
)
console
.
log
()
return
}
let
workspace
=
null
if
(
lineNumber
)
{
args
=
args
.
concat
(
getArgumentsForLineNumber
(
editor
,
fileName
,
lineNumber
,
colNumber
,
workspace
)
)
}
else
{
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'
)
}
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'
}
)
}
else
{
_childProcess
=
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
)
})
}
export
{
launchEditor
}
packages/react-dev-overlay/src/middleware.ts
View file @
37e3ec8d
import
{
codeFrameColumns
}
from
'@babel/code-frame'
import
{
promises
as
fs
}
from
'fs'
import
{
constants
as
FS
,
promises
as
fs
}
from
'fs'
import
{
IncomingMessage
,
ServerResponse
}
from
'http'
import
path
from
'path'
import
{
NullableMappedPosition
,
SourceMapConsumer
}
from
'source-map'
...
...
@@ -7,8 +7,9 @@ import { StackFrame } from 'stacktrace-parser'
import
url
from
'url'
import
webpack
from
'webpack'
import
{
OriginalSource
}
from
'webpack-sources'
import
{
launchEditor
}
from
'./internal/helpers/launchEditor'
type
OverlayMiddlewareOptions
=
{
export
type
OverlayMiddlewareOptions
=
{
rootDirectory
:
string
stats
():
webpack
.
Stats
}
...
...
@@ -122,6 +123,41 @@ function getOverlayMiddleware(options: OverlayMiddlewareOptions) {
res
.
statusCode
=
400
res
.
write
(
'Bad Request'
)
return
res
.
end
()
}
else
if
(
pathname
===
'/__nextjs_launch-editor'
)
{
const
frame
=
(
query
as
unknown
)
as
StackFrame
const
frameFile
=
frame
.
file
?.
toString
()
||
null
if
(
frameFile
==
null
)
{
res
.
statusCode
=
400
res
.
write
(
'Bad Request'
)
return
res
.
end
()
}
const
filePath
=
path
.
resolve
(
options
.
rootDirectory
,
frameFile
)
const
fileExists
=
await
fs
.
access
(
filePath
,
FS
.
F_OK
).
then
(
()
=>
true
,
()
=>
false
)
if
(
!
fileExists
)
{
res
.
statusCode
=
404
res
.
write
(
'Not Found'
)
return
res
.
end
()
}
const
frameLine
=
parseInt
(
frame
.
lineNumber
?.
toString
()
??
''
,
10
)
||
1
const
frameColumn
=
parseInt
(
frame
.
column
?.
toString
()
??
''
,
10
)
||
1
try
{
await
launchEditor
(
filePath
,
frameLine
,
frameColumn
)
}
catch
(
err
)
{
console
.
log
(
'Failed to launch editor:'
,
err
)
res
.
statusCode
=
500
res
.
write
(
'Internal Server Error'
)
return
res
.
end
()
}
res
.
statusCode
=
204
return
res
.
end
()
}
return
next
()
}
...
...
yarn.lock
View file @
37e3ec8d
...
...
@@ -4443,6 +4443,14 @@ chalk@2.4.2, chalk@^2.0.0, chalk@^2.0.1, chalk@^2.1.0, chalk@^2.3.0, chalk@^2.3.
escape-string-regexp "^1.0.5"
supports-color "^5.3.0"
chalk@4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.0.0.tgz#6e98081ed2d17faab615eb52ac66ec1fe6209e72"
integrity sha512-N9oWFcegS0sFr9oh1oz2d7Npos6vNoWW9HvtCg5N1KRFpUhaAhvTv5Y58g880fZaEYSNm3qDz8SU1UrGvp+n7A==
dependencies:
ansi-styles "^4.1.0"
supports-color "^7.1.0"
chalk@^1.0.0, chalk@^1.1.1, chalk@^1.1.3:
version "1.1.3"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-1.1.3.tgz#a8115c55e4a702fe4d150abd3872822a7e09fc98"
...
...
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