npm / cli

the package manager for JavaScript
https://docs.npmjs.com/cli/
Other
8.52k stars 3.19k forks source link

fix: don't mkdir directories that already exist #7899

Open TheCSDev opened 2 weeks ago

TheCSDev commented 2 weeks ago

This pull request aims to resolve #6412, by making checks for whether a project's working directory already exists, before attempting to mkdir it.
This effectively prevents reify.js from accidentally executing mkdir on root drive letters on Windows, like mkdir "D:/" for example, as the Windows operating system prohibits such operations.

The resolution of #6412 will inevitably introduce the npm error Tracker "idealTree" already exists issue, however I believe that is an issue separate from #6412, and that separate issue was already documented before, #7596 being a good example of one of those documentations (in my opinion).

As can be seen in #6412, this pull request makes changes to the following line of code in reify.js.

Of course, should one attempt to execute npm i in a drive letter that does not exist, then this error in my opinion should take place, informing the user that said drive letter and the path within cannot be created, and that error will take place. However this error in my opinion should not take place on existing drives, hence this pull request.

Additional info

wraithgar commented 4 days ago

npm run lintfix should fix linting errors.

TheCSDev commented 4 days ago

Ah, it appears I accidentally used double-quotes instead of single-quotes for the string.
Also for some reason npm run lintfix did not spot any errors or make any "fixing" changes for me, so it took a bit of figuring out. I eventually found the npm run lint -w @npmcli/arborist command from a GitHub Workflows task, and that one was able to spot the syntax error I made.
I will now make one more commit to correct that error, and hopefully that should be it. Thank you for helping me.

wraithgar commented 4 days ago

Oh shoot, sorry I forgot this was the cli repo. Yeah you gotta either be in the arborist directory or specify the workspace. I'll have to remember that when suggesting that in the future.