nx icon indicating copy to clipboard operation
nx copied to clipboard

run-commands cuts last line of inquirer output/console output

Open BlumDev92 opened this issue 1 year ago • 9 comments

Current Behavior

I'm running a custom node script for my executor nx run my-app:my-custom-script. My script contains an inquirer form. NX cuts the last line of this form.

I'm using:

"inquirer": "^9.1.4"

Sample code of inquirer form (index.mjs):

[...]
  const questions = [
    {
      type: 'list',
      name: 'SAMPLE',
      message: 'This is a samle question?',
      choices: ['Option1', 'Option2', 'Option3', 'Option4'],
    }
  ];

  const answers = await inquirer.prompt(questions);
[...]

project.json:

[...]
"my-custom-script": {
      "executor": "nx:run-commands",
      "options": {
        "commands": [
          {
            "command": "node build/index.mjs"
          }
        ],
        "cwd": "apps/my-app",
        "parallel": false
      }
    }
[...]

Sample output when I run nx run my-app:my-custom-script:

? This is a samle question? (Use arrow keys)
❯ Option1 
  Option2 
  Option3 

When I press CTRL+C the missing output gets printed:

? This is a samle question? (Use arrow keys)
❯ Option1 
  Option2 
  Option3 
  Option4  <--- PRINTED!
 >  NX   ERROR: Something went wrong in run-commands - Command failed: node build/index.mjs
   Pass --verbose to see the stacktrace.

Expected Behavior

Console output gets printed with last row.

Expected console output:

? This is a samle question? (Use arrow keys)
❯ Option1 
  Option2 
  Option3 
  Option4

Github Repo

No response

Steps to Reproduce

  1. Create a node script and put it somewhere in workspace.
  2. Create target like above in project.json of any app.
  3. Run new created target

Nx Report

Node : 16.13.0
   OS   : darwin x64
   npm  : 8.1.0
   
   nx : 15.2.1
   @nrwl/angular : Not Found
   @nrwl/cypress : 15.2.1
   @nrwl/detox : 15.2.1
   @nrwl/devkit : 15.2.1
   @nrwl/esbuild : Not Found
   @nrwl/eslint-plugin-nx : 15.2.1
   @nrwl/expo : 15.2.1
   @nrwl/express : Not Found
   @nrwl/jest : 15.2.1
   @nrwl/js : 15.2.1
   @nrwl/linter : 15.2.1
   @nrwl/nest : Not Found
   @nrwl/next : Not Found
   @nrwl/node : Not Found
   @nrwl/nx-cloud : Not Found
   @nrwl/nx-plugin : Not Found
   @nrwl/react : 15.2.1
   @nrwl/react-native : Not Found
   @nrwl/rollup : 15.2.1
   @nrwl/schematics : Not Found
   @nrwl/storybook : 15.2.1
   @nrwl/web : 15.2.1
   @nrwl/webpack : 15.2.1
   @nrwl/workspace : 15.2.1
   typescript : 4.8.4
   ---------------------------------------
   Local workspace plugins:
   ---------------------------------------
   Community plugins:

Failure Logs

No response

Additional Information

No response

BlumDev92 avatar Dec 01 '22 14:12 BlumDev92

this happens when using nx exec as well. it is particularly annoying when the underlying task prompts the user on that last line.

jeffhertzler avatar Jan 12 '23 17:01 jeffhertzler

Any updates on this issue? I am also facing it nx version 15.8.6.

MohammadKurjieh avatar Mar 25 '23 14:03 MohammadKurjieh

+1

enchorb avatar Mar 30 '23 01:03 enchorb

Very annoying problem to have ><

Lepozepo avatar May 16 '23 16:05 Lepozepo

+1

I can't even select an option.

abrahamsaanchez avatar May 18 '23 06:05 abrahamsaanchez

It seems this issue also affects other logged outputs as well, more importantly the last line of running tests interactively on something like jest

Lepozepo avatar May 18 '23 15:05 Lepozepo

+1

I am also experiencing this when using inquirer inside a local executor

Schmale97 avatar Jun 02 '23 11:06 Schmale97

I'm seeing the same behavior on most (if not all) other logs as well outside of inquirer

Lepozepo avatar Jun 02 '23 15:06 Lepozepo

any updates on this? The same thing happens to me.

abelpz avatar Jun 13 '23 16:06 abelpz

There's a workaround for this. Instead of the last option being cut off, the separator you will add at the end of the list will be cut off.

import inquirer from 'inquirer';

const questions = [
  {
    type: 'list',
    name: 'SAMPLE',
    message: 'This is a samle question?',
    choices: [
      'Option1',
      'Option2',
      'Option3',
      'Option4',
      new inquirer.Separator() // <- add a seperator.
    ],
  }
];

const answers = await inquirer.prompt(questions);

samrho avatar Sep 05 '23 04:09 samrho

@samrho yeah, that's an ok workaround for inquirer but it's gobbling up a bunch of stdout info that's not necessarily specific to inquirer also which is definitely annoying for observing other things like deployments.

Lepozepo avatar Sep 05 '23 16:09 Lepozepo

I'm seeing this as well - tried swapping to enquirer but it's behaving the same. I'm using [email protected]

pietschy avatar Sep 26 '23 04:09 pietschy

I confirm that with the version [email protected] I reproduce the error.

mcfdez avatar Sep 26 '23 09:09 mcfdez

this happens to me in custom executor. the same function works fine in custom generator 🤔

GreedyA1 avatar Nov 27 '23 11:11 GreedyA1

This should be fixed with the native comand runner in Nx 17.3. I'm going to go ahead with closing this out as the associated work has been merged.

AgentEnder avatar Jan 28 '24 22:01 AgentEnder

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

github-actions[bot] avatar Feb 28 '24 00:02 github-actions[bot]