Skip to content

Commit

Permalink
fix: 🐞 fix Windows path for VSCode
Browse files Browse the repository at this point in the history
fix Windows path for VSCode
  • Loading branch information
tal-rofe committed Feb 17, 2023
1 parent e015f5a commit b6d0590
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/modules/run/utils/spawn-lib.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { spawn } from 'node:child_process';
import path from 'path';
import path from 'node:path';

import { EXLINT_FOLDER_PATH } from '@/models/exlint-folder';

Expand Down
25 changes: 20 additions & 5 deletions src/modules/use/helpers/vscode.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from 'node:path';
import util from 'node:util';
import { execFile } from 'node:child_process';
import { execFile, spawn } from 'node:child_process';

import fs from 'fs-extra';
import envinfo from 'envinfo';
Expand Down Expand Up @@ -72,6 +72,7 @@ export const installExtensions = async (libraries: string[]) => {
.flat();

let vsCodeCliCommandPath = 'code';
let cwd = process.cwd();

if (process.platform === 'darwin') {
const vsCodeFolderOutput = await asyncExecFile('/usr/bin/mdfind', [
Expand All @@ -82,21 +83,35 @@ export const installExtensions = async (libraries: string[]) => {
throw new Error('Failed to get VSCode path');
}

vsCodeCliCommandPath = path.join(
cwd = path.join(
path.resolve(vsCodeFolderOutput.stdout.trim()),
'Contents',
'Resources',
'app',
'bin',
'code',
);
} else {
const vsCodeData = await envinfo.helpers.getVSCodeInfo();

if (vsCodeData[2]) {
vsCodeCliCommandPath = vsCodeData[2];
cwd = path.dirname(vsCodeData[2]);
vsCodeCliCommandPath = path.basename(vsCodeData[2]);
}
}

await asyncExecFile(vsCodeCliCommandPath, [...extensionsCmdArgs, '--force'].flat());
await new Promise<void>((resolve, reject) => {
const spawner = spawn(vsCodeCliCommandPath, [...extensionsCmdArgs, '--force'].flat(), {
cwd,
windowsHide: true,
shell: true,
});

spawner.on('close', (exitCode: number) => {
if (exitCode === 0) {
return resolve();
}

reject();
});
});
};

0 comments on commit b6d0590

Please sign in to comment.