mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-20 16:57:46 +00:00
Windows: Refactor Shell Scripts to Node.js for Cross-Platform Compatibility (#784)
This commit is contained in:
@@ -21,7 +21,11 @@ describe('checkHasEditor', () => {
|
||||
it('should return true for vscode if "code" command exists', () => {
|
||||
(execSync as Mock).mockReturnValue(Buffer.from('/usr/bin/code'));
|
||||
expect(checkHasEditor('vscode')).toBe(true);
|
||||
expect(execSync).toHaveBeenCalledWith('which code', { stdio: 'ignore' });
|
||||
const expectedCommand =
|
||||
process.platform === 'win32' ? 'where.exe code.cmd' : 'command -v code';
|
||||
expect(execSync).toHaveBeenCalledWith(expectedCommand, {
|
||||
stdio: 'ignore',
|
||||
});
|
||||
});
|
||||
|
||||
it('should return false for vscode if "code" command does not exist', () => {
|
||||
@@ -34,7 +38,11 @@ describe('checkHasEditor', () => {
|
||||
it('should return true for vim if "vim" command exists', () => {
|
||||
(execSync as Mock).mockReturnValue(Buffer.from('/usr/bin/vim'));
|
||||
expect(checkHasEditor('vim')).toBe(true);
|
||||
expect(execSync).toHaveBeenCalledWith('which vim', { stdio: 'ignore' });
|
||||
const expectedCommand =
|
||||
process.platform === 'win32' ? 'where.exe vim' : 'command -v vim';
|
||||
expect(execSync).toHaveBeenCalledWith(expectedCommand, {
|
||||
stdio: 'ignore',
|
||||
});
|
||||
});
|
||||
|
||||
it('should return false for vim if "vim" command does not exist', () => {
|
||||
|
||||
@@ -15,7 +15,10 @@ interface DiffCommand {
|
||||
|
||||
function commandExists(cmd: string): boolean {
|
||||
try {
|
||||
execSync(`which ${cmd}`, { stdio: 'ignore' });
|
||||
execSync(
|
||||
process.platform === 'win32' ? `where.exe ${cmd}` : `command -v ${cmd}`,
|
||||
{ stdio: 'ignore' },
|
||||
);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
@@ -24,7 +27,9 @@ function commandExists(cmd: string): boolean {
|
||||
|
||||
export function checkHasEditor(editor: EditorType): boolean {
|
||||
if (editor === 'vscode') {
|
||||
return commandExists('code');
|
||||
return process.platform === 'win32'
|
||||
? commandExists('code.cmd')
|
||||
: commandExists('code');
|
||||
} else if (editor === 'vim') {
|
||||
return commandExists('vim');
|
||||
}
|
||||
@@ -116,7 +121,10 @@ export async function openDiff(
|
||||
});
|
||||
} else {
|
||||
// Use execSync for terminal-based editors like vim
|
||||
const command = `${diffCommand.command} ${diffCommand.args.map((arg) => `"${arg}"`).join(' ')}`;
|
||||
const command =
|
||||
process.platform === 'win32'
|
||||
? `${diffCommand.command} ${diffCommand.args.join(' ')}`
|
||||
: `${diffCommand.command} ${diffCommand.args.map((arg) => `"${arg}"`).join(' ')}`;
|
||||
execSync(command, {
|
||||
stdio: 'inherit',
|
||||
encoding: 'utf8',
|
||||
|
||||
Reference in New Issue
Block a user