Skip to content

Commit d3e8536

Browse files
noinklinggaearon
authored andcommitted
Add WSL support to launchEditor utility (#2282)
1 parent 4e886f7 commit d3e8536

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

packages/react-dev-utils/launchEditor.js

+17-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
var fs = require('fs');
1212
var path = require('path');
1313
var child_process = require('child_process');
14+
var os = require('os');
1415
var chalk = require('chalk');
1516
var shellQuote = require('shell-quote');
1617

@@ -43,7 +44,8 @@ function addWorkspaceToArgumentsIfExists(args, workspace) {
4344
}
4445

4546
function getArgumentsForLineNumber(editor, fileName, lineNumber, workspace) {
46-
switch (path.basename(editor)) {
47+
var editorBasename = path.basename(editor).replace(/\.(exe|cmd|bat)$/i, '');
48+
switch (editorBasename) {
4749
case 'vim':
4850
case 'mvim':
4951
return [fileName, '+' + lineNumber];
@@ -154,6 +156,20 @@ function launchEditor(fileName, lineNumber) {
154156
return;
155157
}
156158

159+
if (
160+
process.platform === 'linux' &&
161+
fileName.startsWith('/mnt/') &&
162+
/Microsoft/i.test(os.release())
163+
) {
164+
// Assume WSL / "Bash on Ubuntu on Windows" is being used, and
165+
// that the file exists on the Windows file system.
166+
// `os.release()` is "4.4.0-43-Microsoft" in the current release
167+
// build of WSL, see: https://github.com/Microsoft/BashOnWindows/issues/423#issuecomment-221627364
168+
// When a Windows editor is specified, interop functionality can
169+
// handle the path translation, but only if a relative path is used.
170+
fileName = path.relative('', fileName);
171+
}
172+
157173
var workspace = null;
158174
if (lineNumber) {
159175
args = args.concat(

0 commit comments

Comments
 (0)