Skip to content

🎥 Make videos programmatically with React

`@remotion/studio-server`: Detect current VS Code macOS process (#9999)

Jonny Burgerdb7100e1df03
diff --git a/packages/studio-server/src/helpers/open-in-editor.ts b/packages/studio-server/src/helpers/open-in-editor.ts
index 684b488c92..07a2f2c4c8 100644
--- a/packages/studio-server/src/helpers/open-in-editor.ts
+++ b/packages/studio-server/src/helpers/open-in-editor.ts
@@ -163,6 +163,7 @@ const COMMON_EDITORS_OSX: Record<string, Editor> = {
'/Applications/Sublime Text Dev.app/Contents/SharedSupport/bin/subl',
'/Applications/Sublime Text 2.app/Contents/MacOS/Sublime Text 2':
'/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl',
+ '/Applications/Visual Studio Code.app/Contents/MacOS/Code': 'code',
'/Applications/Visual Studio Code.app/Contents/MacOS/Electron': 'code',
'/Applications/Visual Studio Code - Insiders.app/Contents/MacOS/Electron':
'code-insiders',
@@ -352,6 +353,24 @@ export type ProcessAndCommand = {
command: Editor;
};
+export const findMacOsEditorsFromProcessOutput = (
+ output: string,
+): ProcessAndCommand[] => {
+ const availableEditors: ProcessAndCommand[] = [];
+ const processNames = Object.keys(COMMON_EDITORS_OSX);
+ for (let i = 0; i < processNames.length; i++) {
+ const processName = processNames[i];
+ if (output.includes(processName)) {
+ availableEditors.push({
+ process: processName,
+ command: COMMON_EDITORS_OSX[processName],
+ });
+ }
+ }
+
+ return availableEditors;
+};
+
export async function guessEditor(): Promise<ProcessAndCommand[]> {
// We can find out which editor is currently running by:
// `ps x` on macOS and Linux
@@ -360,18 +379,7 @@ export async function guessEditor(): Promise<ProcessAndCommand[]> {
try {
if (process.platform === 'darwin') {
const output = (await execProm('ps x')).stdout.toString();
- const processNames = Object.keys(COMMON_EDITORS_OSX);
- for (let i = 0; i < processNames.length; i++) {
- const processName = processNames[i];
- if (output.indexOf(processName) !== -1) {
- availableEditors.push({
- process: processName,
- command: COMMON_EDITORS_OSX[processName],
- });
- }
- }
-
- return availableEditors;
+ return findMacOsEditorsFromProcessOutput(output);
}
if (process.platform === 'win32') {
diff --git a/packages/studio-server/src/test/open-in-editor.test.ts b/packages/studio-server/src/test/open-in-editor.test.ts
index 5e259e5fdf..ed7c295b0f 100644
--- a/packages/studio-server/src/test/open-in-editor.test.ts
+++ b/packages/studio-server/src/test/open-in-editor.test.ts
@@ -1,6 +1,17 @@
import {expect, test} from 'bun:test';
+import {findMacOsEditorsFromProcessOutput} from '../helpers/open-in-editor';
import {findSearchPosition} from '../preview-server/routes/find-in-file';
+test('detects current VS Code macOS processes', () => {
+ const process =
+ '/Applications/Visual Studio Code.app/Contents/MacOS/Code --open-url';
+
+ expect(findMacOsEditorsFromProcessOutput(process)).toContainEqual({
+ command: 'code',
+ process: '/Applications/Visual Studio Code.app/Contents/MacOS/Code',
+ });
+});
+
test('finds a property after the component location', () => {
const contents = [
'const MyComp = () => (',