bombshell-dev / clack

Effortlessly build beautiful command-line apps
https://clack.cc
5.23k stars 88 forks source link

Spinner not showing on using silent exec #172

Open tiloio opened 9 months ago

tiloio commented 9 months ago

Environment

Describe the bug No spinner is shown.

To Reproduce Run code on a real environment, shell is not working in stackblitz.

import { intro, outro, spinner } from '@clack/prompts';
import shell from "shelljs";

intro(`No spinner on shell.exec`);

const s = spinner();
s.start('Running install');
const command = await shell.exec('npm install', { silent: true });
const message = command.code === 0 ? "Installtion successful" : "Installation failed";
s.stop(message, command.code);

outro(`done`);

Steps to reproduce the behavior:

Expected behavior A spinner is shown.

tiloio commented 9 months ago

Nodes normal exec is also not workin...

import { intro, outro, spinner } from '@clack/prompts';
import { execSync } from "node:child_process";

intro(`No spinner on execSync`);

const s = spinner();
s.start('Running install');
const command = execSync('npm install', { stdio: null });
const message = command.code === 0 ? "Installtion successful" : "Installation failed";
s.stop(message, command.code);

outro(`done`);
Slowlife01 commented 9 months ago

In both cases, you are using sync functions, which wouldn’t work. It will work if you turn them into async using util.promisify

import { intro, outro, spinner } from '@clack/prompts';

import { promisify } from "node:util";
import shell from "shelljs";

const exec = promisify(shell.exec);
intro(`No spinner on shell.exec`);

const s = spinner();
s.start('Running install');
const command = await exec('pnpm install', { silent: true }).catch(() => ({code: 1}));
const message = command.code === 0 ? "Installtion successful" : "Installation failed";
s.stop(message, command.code);

outro(`done`);