fix: npmDependencies
returns dependencies from .nx/installation/node_modules
if node_modules
is a file
#2152
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When writing unit tests for
npmDependencies
, I decided to replaceawait stat(x)).isDirectory()
withdirectoryExists(x)
from@nx-console/shared/file-system
and added areadDirectory
function to make it easier to mock those file system operations.Since the
directoryExists
function already handles thrown exceptions inside, I could refactor the main code by getting rid of the nested try...catch blocks, but then I noticed a strange code path: Before, ifnode_modules
was not a directory but an existing file, an empty array was returned regardless whether.nx/installation/node_modules
directory existed. Now it goes on to check if.nx/installation/node_modules
exists too. I think this is the correct behavior now, albeit quite an unlikely scenario.You can check the new test cases to see if my understanding is correct.