Skip to content

os.cpus() returns empty array causing CLI generation to fail in some sandbox envs #10506

@harvitronix

Description

@harvitronix

Which packages are impacted by your issue?

@graphql-codegen/cli

Describe the bug

When running graphql-codegen in the CLI, the return value of os.cpus().length is passed into task.newListr. However, in some Sandbox environments, os.cpus() returns an empty array, resulting in passing the value 0 into the concurrent property of newListr. This in turn results in the generation hanging.

The Node JS documentation mentions:

os.cpus().length should not be used to calculate the amount of parallelism available to an application. Use os.availableParallelism() for this purpose.

Your Example Website or App

https://stackblitz.com/edit/github-ntbvauxb?file=package.json

Steps to Reproduce the Bug or Issue

  1. In the StackBlitz example, I've added a shim to mimic the sandbox response for os.cpus()
  2. Run yarn generate to see the error
  3. Change the assignment in force-no-cpus.js to os.cpus = () => ["x"]; and re-run yarn generate and you'll see that generation now works, given that ["x"].length is equal to 1

Expected behavior

I expect that the concurrency value is set to a minimum of 1, and/or uses the newer availableParallelism() function.

Screenshots or Videos

No response

Platform

  • OS: macOS in Codex CLI
  • NodeJS: v20.19.2
  • graphql version: 16.9.0
  • @graphql-codegen/cli version: 5.0.7

Codegen Config File

No response

Additional context

I'm happy to submit a PR to address this, if it's agreeable to do so.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions