swytchcode
Advanced tools
+50
-18
| #!/usr/bin/env node | ||
| 'use strict'; | ||
| process.on('SIGINT', () => { | ||
| try { process.stdin.setRawMode(false); } catch (_) {} // prevent stuck raw mode on Windows CMD | ||
| process.stdout.write('\x1b[?25h'); // restore cursor | ||
| process.exit(130); | ||
| }); | ||
| const { spawnSync, execSync } = require('child_process'); | ||
@@ -48,3 +54,16 @@ const fs = require('fs'); | ||
| const iface = rl.createInterface({ input: process.stdin, output: process.stdout }); | ||
| iface.question(prompt, answer => { iface.close(); resolve(answer.trim()); }); | ||
| function onClose() { | ||
| try { process.stdin.setRawMode(false); } catch (_) {} | ||
| process.stdout.write('\x1b[?25h'); | ||
| process.exit(130); | ||
| } | ||
| iface.on('close', onClose); | ||
| iface.question(prompt, answer => { | ||
| iface.removeListener('close', onClose); // only removes this specific listener | ||
| iface.close(); | ||
| resolve(answer.trim()); | ||
| }); | ||
| }); | ||
@@ -192,13 +211,23 @@ } | ||
| const env = { ...process.env, ...extraEnv }; | ||
| let result; | ||
| if (process.stdin.isTTY) { | ||
| return spawnSync(binPath, args, { stdio: 'inherit', env }); | ||
| result = spawnSync(binPath, args, { stdio: 'inherit', env }); | ||
| } else { | ||
| let stdinData; | ||
| try { stdinData = fs.readFileSync(0); } | ||
| catch (_) { stdinData = Buffer.alloc(0); } | ||
| result = spawnSync(binPath, args, { | ||
| stdio: ['pipe', 'inherit', 'inherit'], | ||
| input: stdinData, | ||
| env, | ||
| }); | ||
| } | ||
| let stdinData; | ||
| try { stdinData = fs.readFileSync(0); } | ||
| catch (_) { stdinData = Buffer.alloc(0); } | ||
| return spawnSync(binPath, args, { | ||
| stdio: ['pipe', 'inherit', 'inherit'], | ||
| input: stdinData, | ||
| env, | ||
| }); | ||
| if (result.signal === 'SIGINT') { | ||
| try { process.stdin.setRawMode(false); } catch (_) {} | ||
| process.stdout.write('\x1b[?25h'); | ||
| process.exit(130); | ||
| } | ||
| return result; | ||
| } | ||
@@ -376,6 +405,3 @@ | ||
| writeln(` ${c.gray}$ swytchcode demo stripe${c.reset}`); | ||
| spawnSync(binPath, ['demo', 'stripe'], { | ||
| stdio: 'inherit', | ||
| env: { ...process.env, SWYTCHCODE_ONBOARDING: '1' } | ||
| }); | ||
| spawnBin(binPath, ['demo', 'stripe'], { SWYTCHCODE_ONBOARDING: '1' }); | ||
| writeln(); | ||
@@ -451,2 +477,8 @@ writeln(` ${c.dim}That was a real API call. No credentials, no setup.${c.reset}`); | ||
| } catch (e) { | ||
| if (e.signal === 'SIGINT') { | ||
| installSpin.stop('Cancelled'); | ||
| try { process.stdin.setRawMode(false); } catch (_) {} | ||
| process.stdout.write('\x1b[?25h'); | ||
| process.exit(130); | ||
| } | ||
| installSpin.fail('Installation failed.'); | ||
@@ -479,3 +511,3 @@ } | ||
| writeln(); | ||
| const result = spawnSync(binPath, ['login'], { stdio: 'inherit' }); | ||
| const result = spawnBin(binPath, ['login']); | ||
| if (result.error || result.status !== 0) { | ||
@@ -491,3 +523,3 @@ writeln(` ${c.yellow}Login window closed or failed.${c.reset}`); | ||
| // login command handles both login and registration via the browser flow | ||
| const result = spawnSync(binPath, ['login'], { stdio: 'inherit' }); | ||
| const result = spawnBin(binPath, ['login']); | ||
| if (result.error || result.status !== 0) { | ||
@@ -522,3 +554,3 @@ writeln(` ${c.yellow}Browser window closed or failed.${c.reset}`); | ||
| writeln(); | ||
| const result = spawnSync(binPath, ['init'], { stdio: 'inherit' }); | ||
| const result = spawnBin(binPath, ['init']); | ||
| if (result.error) { | ||
@@ -530,3 +562,3 @@ writeln(` ${c.red}Could not launch swytchcode init: ${result.error.message}${c.reset}`); | ||
| writeln(); | ||
| const result = spawnSync(binPath, ['examples'], { stdio: 'inherit' }); | ||
| const result = spawnBin(binPath, ['examples']); | ||
| if (result.error) { | ||
@@ -533,0 +565,0 @@ writeln(` ${c.red}Could not launch swytchcode examples: ${result.error.message}${c.reset}`); |
+7
-7
| { | ||
| "name": "swytchcode", | ||
| "version": "2.6.0", | ||
| "version": "2.6.1", | ||
| "description": "Execution authority layer for API integrations", | ||
@@ -26,9 +26,9 @@ "keywords": [ | ||
| "optionalDependencies": { | ||
| "swytchcode-cli-darwin-arm64": "2.6.0", | ||
| "swytchcode-cli-darwin-x64": "2.6.0", | ||
| "swytchcode-cli-linux-arm64": "2.6.0", | ||
| "swytchcode-cli-linux-x64": "2.6.0", | ||
| "swytchcode-cli-win32-arm64": "2.6.0", | ||
| "swytchcode-cli-win32-x64": "2.6.0" | ||
| "swytchcode-cli-darwin-arm64": "2.6.1", | ||
| "swytchcode-cli-darwin-x64": "2.6.1", | ||
| "swytchcode-cli-linux-arm64": "2.6.1", | ||
| "swytchcode-cli-linux-x64": "2.6.1", | ||
| "swytchcode-cli-win32-arm64": "2.6.1", | ||
| "swytchcode-cli-win32-x64": "2.6.1" | ||
| } | ||
| } |
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
Found 1 instance in 1 package
24114
3.45%518
5.28%