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

fix(src): check if packages empty so we don't return null #756

Merged

Conversation

adamaucamp
Copy link
Contributor

Types of changes

  • Enhancement (project structure, spelling, grammar, formatting)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

A description of the changes proposed in the Pull Request

Essentially just do a check if the returned packages from the environment with the npm --list command during setup actually returns anything, and return an empty object instead of null.

see this issue for more (link)[https://github.com//issues/739]

Signed-off-by: Adam <AdamAucamp@users.noreply.github.com>
@jmcook1186
Copy link
Contributor

hi - thanks a lot for the PR!
pinging @narekhovhannisyan to review as he is closest to this aspect of the project.

@narekhovhannisyan
Copy link
Member

Hi @adamaucamp , thanks a lot for your contribution!
With the current solution, we will create an empty array by calling object entries on the empty object. And then we have an unnecessary call of the flattenDependencies function.

So what do you think about solving the problem with the following strategy?

const listDependencies = async () => {
  const {stdout} = await execPromise('npm list --json');
  const npmListResponse: NpmListResponse = JSON.parse(stdout);

  if (npmListResponse.dependencies) {
    const dependencies = Object.entries(npmListResponse.dependencies);

    return flattenDependencies(dependencies);
  }

  return [];
};

@adamaucamp
Copy link
Contributor Author

Hi @narekhovhannisyan, that is a much better solution yes. I'll update the PR. thanks.

Signed-off-by: Adam <AdamAucamp@users.noreply.github.com>
@jmcook1186 jmcook1186 self-assigned this Jun 10, 2024
@jmcook1186 jmcook1186 merged commit 1ad91dd into Green-Software-Foundation:main Jun 10, 2024
1 check passed
This was referenced Jun 11, 2024
@adamaucamp adamaucamp deleted the bugfix-issue-739 branch August 20, 2024 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants