Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add WSL support to launchEditor utility / error overlay functionality #2282

Merged
merged 1 commit into from
May 20, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion packages/react-dev-utils/launchEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
var fs = require('fs');
var path = require('path');
var child_process = require('child_process');
var os = require('os');
var chalk = require('chalk');
var shellQuote = require('shell-quote');

Expand Down Expand Up @@ -43,7 +44,8 @@ function addWorkspaceToArgumentsIfExists(args, workspace) {
}

function getArgumentsForLineNumber(editor, fileName, lineNumber, workspace) {
switch (path.basename(editor)) {
var editorBasename = path.basename(editor).replace(/\.(exe|cmd|bat)$/i, '');
switch (editorBasename) {
case 'vim':
case 'mvim':
return [fileName, '+' + lineNumber];
Expand Down Expand Up @@ -154,6 +156,20 @@ function launchEditor(fileName, lineNumber) {
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);
}

var workspace = null;
if (lineNumber) {
args = args.concat(
Expand Down