Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spinner not showing on using silent exec #172

Open
tiloio opened this issue Sep 30, 2023 · 2 comments
Open

Spinner not showing on using silent exec #172

tiloio opened this issue Sep 30, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@tiloio
Copy link

tiloio commented Sep 30, 2023

Environment

  • OS: Windows
  • Node Version: v18.18.0
  • Package: @clack/prompts
  • Package Version: v0.7.0

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:

  • Install shelljs `npm install shelljs
  • run the script above
  • no spinner is shown, the shell has just a empty line....

Expected behavior
A spinner is shown.

@tiloio tiloio added the bug Something isn't working label Sep 30, 2023
@tiloio
Copy link
Author

tiloio commented Sep 30, 2023

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
Copy link

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`);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants