Skip to content
This repository has been archived by the owner on Jul 6, 2019. It is now read-only.

Fix #100 (Improved escaping of spaced paths on Windows) #141

Closed
wants to merge 3 commits into from
Closed

Fix #100 (Improved escaping of spaced paths on Windows) #141

wants to merge 3 commits into from

Conversation

noelleleigh
Copy link
Contributor

Fixes: #100

I went through the npx operations on a Windows 10 user account named "name with spaces" in it to figure out where the issue arises. Since npm proper does work with accounts with spaces, I figured it was an npx issue.

The script crashes during the running of the child npm process to install the packages. Inspecting the arguments provided to the installPackages() function, I decided to try escaping the path in the prefix argument using the child.escapeArg() function. I left the asPath as false because setting it to true led to the script hanging for some reason.

With these changes, I can run npx where before I couldn't:

(Running in my npx local repository)
Before

C:\Users\name with spaces\dev\npx> node .\test\util\npx-bin.js cowsay hey
Error: EPERM: operation not permitted, mkdir 'C:\Users\name'
TypeError: Cannot read property 'get' of undefined
    at errorHandler (C:\Users\name with spaces\dev\npx\node_modules\npm\lib\utils\error-handler.js:213:18)
    at C:\Users\name with spaces\dev\npx\node_modules\npm\bin\npm-cli.js:83:20
    at cb (C:\Users\name with spaces\dev\npx\node_modules\npm\lib\npm.js:215:22)
    at C:\Users\name with spaces\dev\npx\node_modules\npm\lib\npm.js:253:24
    at C:\Users\name with spaces\dev\npx\node_modules\npm\lib\config\core.js:81:7
    at Array.forEach (<anonymous>)
    at C:\Users\name with spaces\dev\npx\node_modules\npm\lib\config\core.js:80:13
    at f (C:\Users\name with spaces\dev\npx\node_modules\npm\node_modules\once\once.js:25:25)
    at afterExtras (C:\Users\name with spaces\dev\npx\node_modules\npm\lib\config\core.js:178:20)
    at C:\Users\name with spaces\dev\npx\node_modules\npm\node_modules\mkdirp\index.js:47:53
C:\Users\name with spaces\dev\npx\node_modules\npm\lib\utils\error-handler.js:213
  if (npm.config.get('json')) {
                 ^

TypeError: Cannot read property 'get' of undefined
    at process.errorHandler (C:\Users\name with spaces\dev\npx\node_modules\npm\lib\utils\error-handler.js:213:18)
    at process.emit (events.js:159:13)
    at process._fatalException (bootstrap_node.js:387:26)
Install for cowsay@latest failed with code 7

After

C:\Users\name with spaces\dev\npx> node .\test\util\npx-bin.js cowsay hey
npx: installed 9 in 3.593s
 _____
< hey >
 -----
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

I included a unit test for installPackages() for this new behavior, modeled after the other previously-implemented tests.

@noelleleigh
Copy link
Contributor Author

Whoops, didn't see #138 before submitting this. Brian's changes seem more elegant, so I'll close this.

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

Successfully merging this pull request may close these issues.

Error: EPERM: operation not permitted, mkdir 'C:\Users\Foo'
1 participant