2015-02-20 04:10:52 +00:00
|
|
|
/**
|
2015-03-23 18:48:02 +00:00
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2015-02-20 04:10:52 +00:00
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
2015-04-24 17:31:28 +00:00
|
|
|
var chalk = require('chalk');
|
2015-02-20 04:10:52 +00:00
|
|
|
var fs = require('fs');
|
2015-11-11 21:43:11 +00:00
|
|
|
var path = require('path');
|
|
|
|
var child_process = require('child_process');
|
2016-06-21 17:45:44 +00:00
|
|
|
const isAbsolutePath = require('absolute-path');
|
2016-11-04 19:56:39 +00:00
|
|
|
const shellQuote = require('shell-quote');
|
Fix various issues with packager editor launcher
Summary: There are a few small bugs with the code that launches the editor from the packager:
* First of all, the filepath is not escaped which means tokens like `(` or spaces will mess up the process execution. Dropbox unfortunately decided to use spaces in its enterprise product, so I was getting this error:
![screen shot 2015-07-11 at 3 20 54 pm](https://cloud.githubusercontent.com/assets/1135007/8635748/186e7f2e-27ea-11e5-8058-1f4dabb79634.png)
* Next, the line number argument formatting was assumed to be in a specific format (`:%d`) which actually errors out vim and other editors.
* Lastly, the process was started synchronously but not attached to the stdin / stdout of the parent process. This means that only editors like mvim, sublime, and others would work since they spawn a new window. Editors like emacs, vi, nano, etc wouldn't work and instead just hang at the command line.
So I whipped up this diff to fix a number of these issues, demo here:
http://recordit.co/M6zwiUj7hp
The demo shows both
Closes https://github.com/facebook/react-native/pull/1957
Reviewed By: @vjeux, @pcottle
Differential Revision: D2420941
Pulled By: @frantic
2015-09-14 16:57:43 +00:00
|
|
|
|
|
|
|
function isTerminalEditor(editor) {
|
|
|
|
switch (editor) {
|
|
|
|
case 'vim':
|
|
|
|
case 'emacs':
|
|
|
|
case 'nano':
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-11-11 21:43:11 +00:00
|
|
|
// 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
|
|
|
|
var COMMON_EDITORS = {
|
|
|
|
'/Applications/Atom.app/Contents/MacOS/Atom': 'atom',
|
2017-04-03 16:06:27 +00:00
|
|
|
'/Applications/Atom Beta.app/Contents/MacOS/Atom Beta':
|
|
|
|
'/Applications/Atom Beta.app/Contents/MacOS/Atom Beta',
|
2017-09-26 21:54:24 +00:00
|
|
|
'/Applications/IntelliJ IDEA.app/Contents/MacOS/idea': 'idea',
|
2015-11-11 21:43:11 +00:00
|
|
|
'/Applications/Sublime Text.app/Contents/MacOS/Sublime Text':
|
|
|
|
'/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl',
|
|
|
|
'/Applications/Sublime Text 2.app/Contents/MacOS/Sublime Text 2':
|
|
|
|
'/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl',
|
2016-06-21 17:45:44 +00:00
|
|
|
'/Applications/Visual Studio Code.app/Contents/MacOS/Electron': 'code',
|
2017-09-26 21:54:24 +00:00
|
|
|
'/Applications/WebStorm.app/Contents/MacOS/webstorm': 'webstorm',
|
2015-11-11 21:43:11 +00:00
|
|
|
};
|
|
|
|
|
2016-06-21 17:45:44 +00:00
|
|
|
function addWorkspaceToArgumentsIfExists(args, workspace) {
|
|
|
|
if (workspace) {
|
|
|
|
args.unshift(workspace);
|
|
|
|
}
|
|
|
|
return args;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getArgumentsForLineNumber(editor, fileName, lineNumber, workspace) {
|
2015-11-11 21:43:11 +00:00
|
|
|
switch (path.basename(editor)) {
|
Fix various issues with packager editor launcher
Summary: There are a few small bugs with the code that launches the editor from the packager:
* First of all, the filepath is not escaped which means tokens like `(` or spaces will mess up the process execution. Dropbox unfortunately decided to use spaces in its enterprise product, so I was getting this error:
![screen shot 2015-07-11 at 3 20 54 pm](https://cloud.githubusercontent.com/assets/1135007/8635748/186e7f2e-27ea-11e5-8058-1f4dabb79634.png)
* Next, the line number argument formatting was assumed to be in a specific format (`:%d`) which actually errors out vim and other editors.
* Lastly, the process was started synchronously but not attached to the stdin / stdout of the parent process. This means that only editors like mvim, sublime, and others would work since they spawn a new window. Editors like emacs, vi, nano, etc wouldn't work and instead just hang at the command line.
So I whipped up this diff to fix a number of these issues, demo here:
http://recordit.co/M6zwiUj7hp
The demo shows both
Closes https://github.com/facebook/react-native/pull/1957
Reviewed By: @vjeux, @pcottle
Differential Revision: D2420941
Pulled By: @frantic
2015-09-14 16:57:43 +00:00
|
|
|
case 'vim':
|
|
|
|
case 'mvim':
|
|
|
|
return [fileName, '+' + lineNumber];
|
|
|
|
case 'atom':
|
2016-11-04 19:56:39 +00:00
|
|
|
case 'Atom':
|
|
|
|
case 'Atom Beta':
|
Fix various issues with packager editor launcher
Summary: There are a few small bugs with the code that launches the editor from the packager:
* First of all, the filepath is not escaped which means tokens like `(` or spaces will mess up the process execution. Dropbox unfortunately decided to use spaces in its enterprise product, so I was getting this error:
![screen shot 2015-07-11 at 3 20 54 pm](https://cloud.githubusercontent.com/assets/1135007/8635748/186e7f2e-27ea-11e5-8058-1f4dabb79634.png)
* Next, the line number argument formatting was assumed to be in a specific format (`:%d`) which actually errors out vim and other editors.
* Lastly, the process was started synchronously but not attached to the stdin / stdout of the parent process. This means that only editors like mvim, sublime, and others would work since they spawn a new window. Editors like emacs, vi, nano, etc wouldn't work and instead just hang at the command line.
So I whipped up this diff to fix a number of these issues, demo here:
http://recordit.co/M6zwiUj7hp
The demo shows both
Closes https://github.com/facebook/react-native/pull/1957
Reviewed By: @vjeux, @pcottle
Differential Revision: D2420941
Pulled By: @frantic
2015-09-14 16:57:43 +00:00
|
|
|
case 'subl':
|
|
|
|
case 'sublime':
|
2017-09-26 21:54:24 +00:00
|
|
|
case 'webstorm':
|
2016-07-27 11:40:41 +00:00
|
|
|
case 'wstorm':
|
|
|
|
case 'appcode':
|
2016-12-08 01:04:08 +00:00
|
|
|
case 'charm':
|
2017-04-03 16:06:27 +00:00
|
|
|
case 'idea':
|
Fix various issues with packager editor launcher
Summary: There are a few small bugs with the code that launches the editor from the packager:
* First of all, the filepath is not escaped which means tokens like `(` or spaces will mess up the process execution. Dropbox unfortunately decided to use spaces in its enterprise product, so I was getting this error:
![screen shot 2015-07-11 at 3 20 54 pm](https://cloud.githubusercontent.com/assets/1135007/8635748/186e7f2e-27ea-11e5-8058-1f4dabb79634.png)
* Next, the line number argument formatting was assumed to be in a specific format (`:%d`) which actually errors out vim and other editors.
* Lastly, the process was started synchronously but not attached to the stdin / stdout of the parent process. This means that only editors like mvim, sublime, and others would work since they spawn a new window. Editors like emacs, vi, nano, etc wouldn't work and instead just hang at the command line.
So I whipped up this diff to fix a number of these issues, demo here:
http://recordit.co/M6zwiUj7hp
The demo shows both
Closes https://github.com/facebook/react-native/pull/1957
Reviewed By: @vjeux, @pcottle
Differential Revision: D2420941
Pulled By: @frantic
2015-09-14 16:57:43 +00:00
|
|
|
return [fileName + ':' + lineNumber];
|
|
|
|
case 'joe':
|
|
|
|
case 'emacs':
|
2015-10-21 16:55:21 +00:00
|
|
|
case 'emacsclient':
|
Fix various issues with packager editor launcher
Summary: There are a few small bugs with the code that launches the editor from the packager:
* First of all, the filepath is not escaped which means tokens like `(` or spaces will mess up the process execution. Dropbox unfortunately decided to use spaces in its enterprise product, so I was getting this error:
![screen shot 2015-07-11 at 3 20 54 pm](https://cloud.githubusercontent.com/assets/1135007/8635748/186e7f2e-27ea-11e5-8058-1f4dabb79634.png)
* Next, the line number argument formatting was assumed to be in a specific format (`:%d`) which actually errors out vim and other editors.
* Lastly, the process was started synchronously but not attached to the stdin / stdout of the parent process. This means that only editors like mvim, sublime, and others would work since they spawn a new window. Editors like emacs, vi, nano, etc wouldn't work and instead just hang at the command line.
So I whipped up this diff to fix a number of these issues, demo here:
http://recordit.co/M6zwiUj7hp
The demo shows both
Closes https://github.com/facebook/react-native/pull/1957
Reviewed By: @vjeux, @pcottle
Differential Revision: D2420941
Pulled By: @frantic
2015-09-14 16:57:43 +00:00
|
|
|
return ['+' + lineNumber, fileName];
|
2015-09-23 23:59:44 +00:00
|
|
|
case 'rmate':
|
|
|
|
case 'mate':
|
2015-11-04 15:54:57 +00:00
|
|
|
case 'mine':
|
2015-09-23 23:59:44 +00:00
|
|
|
return ['--line', lineNumber, fileName];
|
2016-06-21 17:45:44 +00:00
|
|
|
case 'code':
|
|
|
|
return addWorkspaceToArgumentsIfExists(['-g', fileName + ':' + lineNumber], workspace);
|
Fix various issues with packager editor launcher
Summary: There are a few small bugs with the code that launches the editor from the packager:
* First of all, the filepath is not escaped which means tokens like `(` or spaces will mess up the process execution. Dropbox unfortunately decided to use spaces in its enterprise product, so I was getting this error:
![screen shot 2015-07-11 at 3 20 54 pm](https://cloud.githubusercontent.com/assets/1135007/8635748/186e7f2e-27ea-11e5-8058-1f4dabb79634.png)
* Next, the line number argument formatting was assumed to be in a specific format (`:%d`) which actually errors out vim and other editors.
* Lastly, the process was started synchronously but not attached to the stdin / stdout of the parent process. This means that only editors like mvim, sublime, and others would work since they spawn a new window. Editors like emacs, vi, nano, etc wouldn't work and instead just hang at the command line.
So I whipped up this diff to fix a number of these issues, demo here:
http://recordit.co/M6zwiUj7hp
The demo shows both
Closes https://github.com/facebook/react-native/pull/1957
Reviewed By: @vjeux, @pcottle
Differential Revision: D2420941
Pulled By: @frantic
2015-09-14 16:57:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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];
|
|
|
|
}
|
2015-04-24 17:31:28 +00:00
|
|
|
|
2015-11-11 21:43:11 +00:00
|
|
|
function guessEditor() {
|
|
|
|
// Explicit config always wins
|
|
|
|
if (process.env.REACT_EDITOR) {
|
2016-11-04 19:56:39 +00:00
|
|
|
return shellQuote.parse(process.env.REACT_EDITOR);
|
2015-11-11 21:43:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Using `ps x` on OSX we can find out which editor is currently running.
|
|
|
|
// Potentially we could use similar technique for Windows and Linux
|
|
|
|
if (process.platform === 'darwin') {
|
|
|
|
try {
|
|
|
|
var output = child_process.execSync('ps x').toString();
|
|
|
|
var processNames = Object.keys(COMMON_EDITORS);
|
|
|
|
for (var i = 0; i < processNames.length; i++) {
|
|
|
|
var processName = processNames[i];
|
|
|
|
if (output.indexOf(processName) !== -1) {
|
2016-11-04 19:56:39 +00:00
|
|
|
return [COMMON_EDITORS[processName]];
|
2015-11-11 21:43:11 +00:00
|
|
|
}
|
|
|
|
}
|
2017-10-10 00:37:08 +00:00
|
|
|
} catch (error) {
|
2015-11-11 21:43:11 +00:00
|
|
|
// Ignore...
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Last resort, use old skool env vars
|
2016-11-04 19:56:39 +00:00
|
|
|
if (process.env.VISUAL) {
|
|
|
|
return [process.env.VISUAL];
|
|
|
|
} else if (process.env.EDITOR) {
|
|
|
|
return [process.env.EDITOR];
|
|
|
|
}
|
|
|
|
|
2017-04-28 13:06:16 +00:00
|
|
|
return [null];
|
2015-11-11 21:43:11 +00:00
|
|
|
}
|
|
|
|
|
2015-04-24 17:31:28 +00:00
|
|
|
function printInstructions(title) {
|
|
|
|
console.log([
|
|
|
|
'',
|
|
|
|
chalk.bgBlue.white.bold(' ' + title + ' '),
|
|
|
|
' When you see Red Box with stack trace, you can click any ',
|
|
|
|
' stack frame to jump to the source file. The packager will launch your ',
|
|
|
|
' editor of choice. It will first look at REACT_EDITOR environment ',
|
|
|
|
' variable, then at EDITOR. To set it up, you can add something like ',
|
2015-11-11 21:43:11 +00:00
|
|
|
' export REACT_EDITOR=atom to your ~/.bashrc or ~/.zshrc depending on ',
|
|
|
|
' which shell you use.',
|
2015-04-24 17:31:28 +00:00
|
|
|
''
|
|
|
|
].join('\n'));
|
2015-02-20 04:10:52 +00:00
|
|
|
}
|
|
|
|
|
2016-06-21 17:45:44 +00:00
|
|
|
function transformToAbsolutePathIfNeeded(pathName) {
|
|
|
|
if (!isAbsolutePath(pathName)) {
|
|
|
|
pathName = path.resolve(process.cwd(), pathName);
|
|
|
|
}
|
|
|
|
return pathName;
|
|
|
|
}
|
|
|
|
|
|
|
|
function findRootForFile(projectRoots, fileName) {
|
|
|
|
fileName = transformToAbsolutePathIfNeeded(fileName);
|
|
|
|
return projectRoots.find((root) => {
|
|
|
|
root = transformToAbsolutePathIfNeeded(root);
|
|
|
|
return fileName.startsWith(root + path.sep);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
Fix various issues with packager editor launcher
Summary: There are a few small bugs with the code that launches the editor from the packager:
* First of all, the filepath is not escaped which means tokens like `(` or spaces will mess up the process execution. Dropbox unfortunately decided to use spaces in its enterprise product, so I was getting this error:
![screen shot 2015-07-11 at 3 20 54 pm](https://cloud.githubusercontent.com/assets/1135007/8635748/186e7f2e-27ea-11e5-8058-1f4dabb79634.png)
* Next, the line number argument formatting was assumed to be in a specific format (`:%d`) which actually errors out vim and other editors.
* Lastly, the process was started synchronously but not attached to the stdin / stdout of the parent process. This means that only editors like mvim, sublime, and others would work since they spawn a new window. Editors like emacs, vi, nano, etc wouldn't work and instead just hang at the command line.
So I whipped up this diff to fix a number of these issues, demo here:
http://recordit.co/M6zwiUj7hp
The demo shows both
Closes https://github.com/facebook/react-native/pull/1957
Reviewed By: @vjeux, @pcottle
Differential Revision: D2420941
Pulled By: @frantic
2015-09-14 16:57:43 +00:00
|
|
|
var _childProcess = null;
|
2016-06-21 17:45:44 +00:00
|
|
|
function launchEditor(fileName, lineNumber, projectRoots) {
|
2015-02-20 04:10:52 +00:00
|
|
|
if (!fs.existsSync(fileName)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
Sanitize lineNumber in launchEditor
Summary:Shelling out on win32 does not properly escape the command due to https://github.com/nodejs/node/blob/c3bb4b1aa5e907d489619fb43d233c3336bfc03d/lib/child_
This patch ensures a proper lineNumber before continuing, similar to how we check that the fileName passed exists.
**Test plan**
On platform `win32` or given appropriate testing changes to `launchEditor.js`...
With the following `request-bad` file:
```
GET /open-stack-frame HTTP/1.1
Host: 127.0.0.1:8081
Proxy-Connection: keep-alive
Cache-Control: max-age=0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-US,en;q=0.8
Content-Length: 64
{"file":"C:\\Windows\\system.ini","lineNumber":"123\" && calc"}
```
`$ nc localhost 8081 < request-bad`
Observe that before this patch `calc` would launch and afte
Closes https://github.com/facebook/react-native/pull/6299
Differential Revision: D3012074
Pulled By: davidaurelio
fb-gh-sync-id: cbc7b6e5c60529a289c0989a95593a322333ba5d
shipit-source-id: cbc7b6e5c60529a289c0989a95593a322333ba5d
2016-03-04 20:03:38 +00:00
|
|
|
// Sanitize lineNumber to prevent malicious use on win32
|
|
|
|
// via: https://github.com/nodejs/node/blob/c3bb4b1aa5e907d489619fb43d233c3336bfc03d/lib/child_process.js#L333
|
|
|
|
if (lineNumber && isNaN(lineNumber)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-12-16 18:16:51 +00:00
|
|
|
let [editor, ...args] = guessEditor();
|
Fix various issues with packager editor launcher
Summary: There are a few small bugs with the code that launches the editor from the packager:
* First of all, the filepath is not escaped which means tokens like `(` or spaces will mess up the process execution. Dropbox unfortunately decided to use spaces in its enterprise product, so I was getting this error:
![screen shot 2015-07-11 at 3 20 54 pm](https://cloud.githubusercontent.com/assets/1135007/8635748/186e7f2e-27ea-11e5-8058-1f4dabb79634.png)
* Next, the line number argument formatting was assumed to be in a specific format (`:%d`) which actually errors out vim and other editors.
* Lastly, the process was started synchronously but not attached to the stdin / stdout of the parent process. This means that only editors like mvim, sublime, and others would work since they spawn a new window. Editors like emacs, vi, nano, etc wouldn't work and instead just hang at the command line.
So I whipped up this diff to fix a number of these issues, demo here:
http://recordit.co/M6zwiUj7hp
The demo shows both
Closes https://github.com/facebook/react-native/pull/1957
Reviewed By: @vjeux, @pcottle
Differential Revision: D2420941
Pulled By: @frantic
2015-09-14 16:57:43 +00:00
|
|
|
if (!editor) {
|
|
|
|
printInstructions('PRO TIP');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-06-21 17:45:44 +00:00
|
|
|
var workspace = findRootForFile(projectRoots, fileName);
|
2015-02-20 04:10:52 +00:00
|
|
|
if (lineNumber) {
|
2016-12-16 18:16:51 +00:00
|
|
|
args = args.concat(getArgumentsForLineNumber(editor, fileName, lineNumber, workspace));
|
2016-11-04 19:56:39 +00:00
|
|
|
} else {
|
|
|
|
args.push(fileName);
|
2015-02-20 04:10:52 +00:00
|
|
|
}
|
Fix various issues with packager editor launcher
Summary: There are a few small bugs with the code that launches the editor from the packager:
* First of all, the filepath is not escaped which means tokens like `(` or spaces will mess up the process execution. Dropbox unfortunately decided to use spaces in its enterprise product, so I was getting this error:
![screen shot 2015-07-11 at 3 20 54 pm](https://cloud.githubusercontent.com/assets/1135007/8635748/186e7f2e-27ea-11e5-8058-1f4dabb79634.png)
* Next, the line number argument formatting was assumed to be in a specific format (`:%d`) which actually errors out vim and other editors.
* Lastly, the process was started synchronously but not attached to the stdin / stdout of the parent process. This means that only editors like mvim, sublime, and others would work since they spawn a new window. Editors like emacs, vi, nano, etc wouldn't work and instead just hang at the command line.
So I whipped up this diff to fix a number of these issues, demo here:
http://recordit.co/M6zwiUj7hp
The demo shows both
Closes https://github.com/facebook/react-native/pull/1957
Reviewed By: @vjeux, @pcottle
Differential Revision: D2420941
Pulled By: @frantic
2015-09-14 16:57:43 +00:00
|
|
|
console.log('Opening ' + chalk.underline(fileName) + ' with ' + chalk.bold(editor));
|
2015-02-20 04:10:52 +00:00
|
|
|
|
Fix various issues with packager editor launcher
Summary: There are a few small bugs with the code that launches the editor from the packager:
* First of all, the filepath is not escaped which means tokens like `(` or spaces will mess up the process execution. Dropbox unfortunately decided to use spaces in its enterprise product, so I was getting this error:
![screen shot 2015-07-11 at 3 20 54 pm](https://cloud.githubusercontent.com/assets/1135007/8635748/186e7f2e-27ea-11e5-8058-1f4dabb79634.png)
* Next, the line number argument formatting was assumed to be in a specific format (`:%d`) which actually errors out vim and other editors.
* Lastly, the process was started synchronously but not attached to the stdin / stdout of the parent process. This means that only editors like mvim, sublime, and others would work since they spawn a new window. Editors like emacs, vi, nano, etc wouldn't work and instead just hang at the command line.
So I whipped up this diff to fix a number of these issues, demo here:
http://recordit.co/M6zwiUj7hp
The demo shows both
Closes https://github.com/facebook/react-native/pull/1957
Reviewed By: @vjeux, @pcottle
Differential Revision: D2420941
Pulled By: @frantic
2015-09-14 16:57:43 +00:00
|
|
|
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');
|
2015-04-24 17:31:28 +00:00
|
|
|
}
|
Fix various issues with packager editor launcher
Summary: There are a few small bugs with the code that launches the editor from the packager:
* First of all, the filepath is not escaped which means tokens like `(` or spaces will mess up the process execution. Dropbox unfortunately decided to use spaces in its enterprise product, so I was getting this error:
![screen shot 2015-07-11 at 3 20 54 pm](https://cloud.githubusercontent.com/assets/1135007/8635748/186e7f2e-27ea-11e5-8058-1f4dabb79634.png)
* Next, the line number argument formatting was assumed to be in a specific format (`:%d`) which actually errors out vim and other editors.
* Lastly, the process was started synchronously but not attached to the stdin / stdout of the parent process. This means that only editors like mvim, sublime, and others would work since they spawn a new window. Editors like emacs, vi, nano, etc wouldn't work and instead just hang at the command line.
So I whipped up this diff to fix a number of these issues, demo here:
http://recordit.co/M6zwiUj7hp
The demo shows both
Closes https://github.com/facebook/react-native/pull/1957
Reviewed By: @vjeux, @pcottle
Differential Revision: D2420941
Pulled By: @frantic
2015-09-14 16:57:43 +00:00
|
|
|
|
2016-01-11 21:27:00 +00:00
|
|
|
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'});
|
|
|
|
}
|
Fix various issues with packager editor launcher
Summary: There are a few small bugs with the code that launches the editor from the packager:
* First of all, the filepath is not escaped which means tokens like `(` or spaces will mess up the process execution. Dropbox unfortunately decided to use spaces in its enterprise product, so I was getting this error:
![screen shot 2015-07-11 at 3 20 54 pm](https://cloud.githubusercontent.com/assets/1135007/8635748/186e7f2e-27ea-11e5-8058-1f4dabb79634.png)
* Next, the line number argument formatting was assumed to be in a specific format (`:%d`) which actually errors out vim and other editors.
* Lastly, the process was started synchronously but not attached to the stdin / stdout of the parent process. This means that only editors like mvim, sublime, and others would work since they spawn a new window. Editors like emacs, vi, nano, etc wouldn't work and instead just hang at the command line.
So I whipped up this diff to fix a number of these issues, demo here:
http://recordit.co/M6zwiUj7hp
The demo shows both
Closes https://github.com/facebook/react-native/pull/1957
Reviewed By: @vjeux, @pcottle
Differential Revision: D2420941
Pulled By: @frantic
2015-09-14 16:57:43 +00:00
|
|
|
_childProcess.on('exit', function(errorCode) {
|
|
|
|
_childProcess = null;
|
|
|
|
|
|
|
|
if (errorCode) {
|
|
|
|
console.log(chalk.red('Your editor exited with an error!'));
|
|
|
|
printInstructions('Keep these instructions in mind:');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
_childProcess.on('error', function(error) {
|
|
|
|
console.log(chalk.red(error.message));
|
|
|
|
printInstructions('How to fix:');
|
2015-11-11 21:43:11 +00:00
|
|
|
});
|
2015-02-20 04:10:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = launchEditor;
|