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

Regression: nx show does not flush output before exiting #27968

Open
1 of 4 tasks
akwodkiewicz opened this issue Sep 18, 2024 · 1 comment
Open
1 of 4 tasks

Regression: nx show does not flush output before exiting #27968

akwodkiewicz opened this issue Sep 18, 2024 · 1 comment

Comments

@akwodkiewicz
Copy link

akwodkiewicz commented Sep 18, 2024

Current Behavior

When running nx show project --json foobar with Node.js spawn, exec, spawnSync, etc., the output is truncated to 8192 characters.

Expected Behavior

The output is returned in full.

GitHub Repo

No response

Steps to Reproduce

  1. Get big enough project.json
  2. Run
const { exec } = require('node:child_process');

async function test() {
  const command = exec(`nx show project --json projectName`);

  let output = '';
  command.stdout?.on('data', (data) => (output += data.toString()));

  const promise = new Promise((resolve) => {
    command.on('close', (code) => {
      if (code !== 0) {
        console.error(`Error when running command, code: ${code}`);
      }
      // @ts-ignore
      resolve();
    });
  });
  await promise;
  console.log(`output: ${output}`);
  JSON.parse(output); // this will crash if the output is not full
}

test().catch(e => console.error(e));

or

const { spawnSync } = require('node:child_process');

const commandResult = spawnSync(`nx show project --json someProject`);
const projectInfo = commandResult.stdout.toString();
console.log(`output: ${projectInfo}`);
JSON.parse(projectInfo); // this will crash if the output is not full

Nx Report

Node           : 18.20.4
OS             : darwin-arm64
Native Target  : aarch64-macos
npm            : 10.7.0

nx (global)  : 19.7.3
nx           : 19.7.0
@nrwl/tao    : 19.7.0
typescript   : 5.4.5

Failure Logs

No response

Package Manager Version

No response

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

This has been already reported a year ago in #19059 and then fixed in #19793

But since then I see that the source code was refactored, and the await output.drain() line is nowhere to be found.

@akwodkiewicz
Copy link
Author

I just confirmed locally that the nx show project --json works fine with Node's exec in [email protected], which is the first version that received the fix (#19793).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant