MCPcopy Index your code
hub / github.com/facebook/react / launchEditor

Function launchEditor

packages/react-devtools-core/src/editor.js:143–194  ·  view source on GitHub ↗
(
  maybeRelativePath: string,
  lineNumber: number,
  absoluteProjectRoots: Array<string>,
)

Source from the content-addressed store, hash-verified

141}
142
143export function launchEditor(
144 maybeRelativePath: string,
145 lineNumber: number,
146 absoluteProjectRoots: Array<string>,
147) {
148 const filePath = getValidFilePath(maybeRelativePath, absoluteProjectRoots);
149 if (filePath === null) {
150 return;
151 }
152
153 // Sanitize lineNumber to prevent malicious use on win32
154 // via: https://github.com/nodejs/node/blob/c3bb4b1aa5e907d489619fb43d233c3336bfc03d/lib/child_process.js#L333
155 if (lineNumber && isNaN(lineNumber)) {
156 return;
157 }
158
159 const [editor, ...destructuredArgs] = guessEditor();
160 if (!editor) {
161 return;
162 }
163
164 let args = destructuredArgs;
165
166 if (lineNumber) {
167 args = args.concat(getArgumentsForLineNumber(editor, filePath, lineNumber));
168 } else {
169 args.push(filePath);
170 }
171
172 if (childProcess && isTerminalEditor(editor)) {
173 // There's an existing editor process already and it's attached
174 // to the terminal, so go kill it. Otherwise two separate editor
175 // instances attach to the stdin/stdout which gets confusing.
176 // $FlowFixMe[incompatible-use] found when upgrading Flow
177 childProcess.kill('SIGKILL');
178 }
179
180 if (process.platform === 'win32') {
181 // On Windows, launch the editor in a shell because spawn can only
182 // launch .exe files.
183 childProcess = spawn('cmd.exe', ['/C', editor].concat(args), {
184 stdio: 'inherit',
185 });
186 } else {
187 childProcess = spawn(editor, args, {stdio: 'inherit'});
188 }
189 childProcess.on('error', function () {});
190 // $FlowFixMe[incompatible-use] found when upgrading Flow
191 childProcess.on('exit', function () {
192 childProcess = null;
193 });
194}

Callers 1

Calls 6

getValidFilePathFunction · 0.85
guessEditorFunction · 0.85
isTerminalEditorFunction · 0.85
onMethod · 0.80
pushMethod · 0.65

Tested by

no test coverage detected