MCPcopy
hub / github.com/facebook/react / guessEditor

Function guessEditor

packages/react-devtools-core/src/editor.js:77–108  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

75}
76
77function guessEditor(): Array<string> {
78 // Explicit config always wins
79 if (process.env.REACT_EDITOR) {
80 return parse(process.env.REACT_EDITOR);
81 }
82
83 // Using `ps x` on OSX we can find out which editor is currently running.
84 // Potentially we could use similar technique for Windows and Linux
85 if (process.platform === 'darwin') {
86 try {
87 const output = execSync('ps x').toString();
88 const processNames = Object.keys(COMMON_EDITORS);
89 for (let i = 0; i < processNames.length; i++) {
90 const processName = processNames[i];
91 if (output.indexOf(processName) !== -1) {
92 return [COMMON_EDITORS[processName]];
93 }
94 }
95 } catch (error) {
96 // Ignore...
97 }
98 }
99
100 // Last resort, use old-school env vars
101 if (process.env.VISUAL) {
102 return [process.env.VISUAL];
103 } else if (process.env.EDITOR) {
104 return [process.env.EDITOR];
105 }
106
107 return [];
108}
109
110let childProcess = null;
111

Callers 1

launchEditorFunction · 0.85

Calls 3

keysMethod · 0.80
toStringMethod · 0.65
parseFunction · 0.50

Tested by

no test coverage detected