Skip to content

Commit b69734e

Browse files
committed
fix: Connect commands not working on other shells
1 parent 4ff8152 commit b69734e

File tree

9 files changed

+32
-10
lines changed

9 files changed

+32
-10
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@
143143
"start:vm": "npm run build && npm run pack:macos && npm run start:vm",
144144
"deploy": "npm run pkg && npm run notarize && npm run upload"
145145
},
146-
"version": "1.0.0-beta4",
146+
"version": "1.0.0-beta5",
147147
"bugs": "https://github.com/codifycli/codify/issues",
148148
"keywords": [
149149
"oclif",

src/connect/http-routes/create-command.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Router } from 'express';
44
import WebSocket from 'ws';
55

66
import { Session, SocketServer } from '../socket-server.js';
7+
import { ShellUtils } from '../../utils/shell.js';
78

89
export enum ConnectCommand {
910
TERMINAL = 'start terminal',
@@ -59,7 +60,7 @@ export function createCommandHandler({ name, command, spawnCommand, onExit }: Pa
5960

6061
console.log(req.body);
6162

62-
const pty = spawnCommand ? await spawnCommand(req.body, ws, session) : spawn('zsh', command!, {
63+
const pty = spawnCommand ? await spawnCommand(req.body, ws, session) : spawn(ShellUtils.getDefaultShell(), command!, {
6364
name: 'xterm-color',
6465
cols: 80,
6566
rows: 30,

src/connect/http-routes/handlers/apply-handler.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { WebSocket } from 'ws';
77

88
import { ConnectOrchestrator } from '../../../orchestrators/connect.js';
99
import { ajv } from '../../../utils/ajv.js';
10+
import { ShellUtils } from '../../../utils/shell.js';
1011
import { Session } from '../../socket-server.js';
1112
import { ConnectCommand, createCommandHandler } from '../create-command.js';
1213

@@ -29,7 +30,7 @@ export function applyHandler() {
2930

3031
session.additionalData.filePath = filePath;
3132

32-
return spawn('zsh', ['-c', `${ConnectOrchestrator.nodeBinary} ${ConnectOrchestrator.rootCommand} apply -p ${filePath}`], {
33+
return spawn(ShellUtils.getDefaultShell(), ['-c', `${ConnectOrchestrator.nodeBinary} ${ConnectOrchestrator.rootCommand} apply -p ${filePath}`], {
3334
name: 'xterm-color',
3435
cols: 80,
3536
rows: 30,

src/connect/http-routes/handlers/import-handler.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { WebSocket } from 'ws';
88

99
import { ConnectOrchestrator } from '../../../orchestrators/connect.js';
1010
import { ajv } from '../../../utils/ajv.js';
11+
import { ShellUtils } from '../../../utils/shell.js';
1112
import { Session, SocketServer } from '../../socket-server.js';
1213
import { ConnectCommand, createCommandHandler } from '../create-command.js';
1314

@@ -55,7 +56,7 @@ export function importHandler() {
5556
}
5657
}
5758

58-
return spawn('zsh', ['-c', `${ConnectOrchestrator.nodeBinary} ${ConnectOrchestrator.rootCommand} import ${args} -p ${filePath} --updateExisting`], {
59+
return spawn(ShellUtils.getDefaultShell(), ['-c', `${ConnectOrchestrator.nodeBinary} ${ConnectOrchestrator.rootCommand} import ${args} -p ${filePath} --updateExisting`], {
5960
name: 'xterm-color',
6061
cols: 80,
6162
rows: 30,

src/connect/http-routes/handlers/init-handler.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import path from 'node:path';
66
import { WebSocket } from 'ws';
77

88
import { ConnectOrchestrator } from '../../../orchestrators/connect.js';
9+
import { ShellUtils } from '../../../utils/shell.js';
910
import { Session, SocketServer } from '../../socket-server.js';
1011
import { ConnectCommand, createCommandHandler } from '../create-command.js';
1112

@@ -17,7 +18,7 @@ export function initHandler() {
1718
session.additionalData.filePath = filePath;
1819
session.additionalData.existingFile = '[]';
1920

20-
return spawn('zsh', ['-c', `${ConnectOrchestrator.nodeBinary} ${ConnectOrchestrator.rootCommand} init -p ${filePath}`], {
21+
return spawn(ShellUtils.getDefaultShell(), ['-c', `${ConnectOrchestrator.nodeBinary} ${ConnectOrchestrator.rootCommand} init -p ${filePath}`], {
2122
name: 'xterm-color',
2223
cols: 80,
2324
rows: 30,

src/connect/http-routes/handlers/plan-handler.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { WebSocket } from 'ws';
77

88
import { ConnectOrchestrator } from '../../../orchestrators/connect.js';
99
import { ajv } from '../../../utils/ajv.js';
10+
import { ShellUtils } from '../../../utils/shell.js';
1011
import { Session } from '../../socket-server.js';
1112
import { ConnectCommand, createCommandHandler } from '../create-command.js';
1213

@@ -29,7 +30,7 @@ export function planHandler() {
2930

3031
session.additionalData.filePath = filePath;
3132

32-
return spawn('zsh', ['-c', `${ConnectOrchestrator.nodeBinary} ${ConnectOrchestrator.rootCommand} plan -p ${filePath}`], {
33+
return spawn(ShellUtils.getDefaultShell(), ['-c', `${ConnectOrchestrator.nodeBinary} ${ConnectOrchestrator.rootCommand} plan -p ${filePath}`], {
3334
name: 'xterm-color',
3435
cols: 80,
3536
rows: 30,

src/connect/http-routes/handlers/refresh-handler.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import { WebSocket } from 'ws';
88

99
import { ConnectOrchestrator } from '../../../orchestrators/connect.js';
1010
import { ajv } from '../../../utils/ajv.js';
11-
import { Session, SocketServer } from '../../socket-server.js';
11+
import { ShellUtils } from '../../../utils/shell.js';
12+
import { Session } from '../../socket-server.js';
1213
import { ConnectCommand, createCommandHandler } from '../create-command.js';
1314

1415
enum RefreshType {
@@ -55,7 +56,7 @@ export function refreshHandler() {
5556
}
5657
}
5758

58-
return spawn('zsh', ['-c', `${ConnectOrchestrator.nodeBinary} ${ConnectOrchestrator.rootCommand} refresh ${args} -p ${filePath}`], {
59+
return spawn(ShellUtils.getDefaultShell(), ['-c', `${ConnectOrchestrator.nodeBinary} ${ConnectOrchestrator.rootCommand} refresh ${args} -p ${filePath}`], {
5960
name: 'xterm-color',
6061
cols: 80,
6162
rows: 30,

src/utils/spawn.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import stripAnsi from 'strip-ansi';
44

55
import { SpawnError } from '../common/errors.js';
66
import { ctx } from '../events/context.js';
7+
import { OsUtils } from './os-utils.js';
78
import { Shell, ShellUtils } from './shell.js';
89

910
export interface SpawnResult {
@@ -64,7 +65,14 @@ export async function spawnSafe(cmd: string, options?: SpawnOptions, pluginName?
6465
const initialCols = process.stdout.columns ?? 80;
6566
const initialRows = process.stdout.rows ?? 24;
6667

67-
const command = options?.requiresRoot ? `sudo -k; sudo -SN <<< "${password}" ${cmd}` : cmd;
68+
// Mac OS uses -SN instead of -Sn
69+
let command;
70+
if (OsUtils.isMacOS()) {
71+
command = options?.requiresRoot ? `sudo -k; sudo -SN <<< "${password}" ${cmd}` : cmd;
72+
} else {
73+
command = options?.requiresRoot ? `sudo -k; sudo -Sk <<< "${password}" ${cmd}` : cmd;
74+
}
75+
6876
const args = options?.interactive ? ['-i', '-c', command] : ['-c', command]
6977

7078
// Run the command in a pty for interactivity

src/utils/sudo.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
import { execSync } from 'node:child_process';
22

3+
import { OsUtils } from './os-utils.js';
4+
35
export const SudoUtils = {
46
validate(password?: string): boolean {
57
try {
8+
if (OsUtils.isMacOS()) {
9+
// Sudo with -SNv will not prompt if within sudo cache timeout. Mac OS uses -SNv instead of -Snv
10+
execSync(`sudo -SNv ${password ? `<<< ${password}` : ''}`, { stdio: 'ignore' })
11+
return true;
12+
}
13+
614
// Sudo with -Snv will not prompt if within sudo cache timeout
7-
execSync(`sudo -Snv ${password ? `<<< ${password}` : ''}`, { stdio: 'ignore' })
15+
execSync(`sudo -Skv ${password ? `<<< ${password}` : ''} >/dev/null 2>&1`, { stdio: 'ignore' })
816
return true;
917
} catch {
1018
return false;

0 commit comments

Comments
 (0)