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

CLI not working on Windows #984

Closed
eugirdor opened this issue Aug 2, 2016 · 6 comments · Fixed by #993
Closed

CLI not working on Windows #984

eugirdor opened this issue Aug 2, 2016 · 6 comments · Fixed by #993
Labels
bug current functionality does not work as desired

Comments

@eugirdor
Copy link

eugirdor commented Aug 2, 2016

The CLI is not working for me on Windows, and the issue seems to be with this code:

ava/cli.js

Lines 11 to 15 in f9fe8f2

if (localCLI && localCLI !== __filename) {
debug('Using local install of AVA');
require(localCLI);
return;
}

if (localCLI && localCLI !== __filename) {
    debug('Using local install of AVA');
    require(localCLI);
    return;
}

The problem is with the use of !== to compare localCLI and __filename. In my case, the two variables hold the following values:

localCLI: c:\workspace\...\node_modules\ava\cli.js
__filename: C:\workspace\...\node_modules\ava\cli.js

As you can see, the drive letter c: is lowercase in localCLI and uppercase in __filename, thus failing the !== check.

Using !== to compare paths doesn't seem to be a particularly good idea since there are numerous different ways the exact same path can be encoded. Not sure what the best practice is for comparing paths in node.js is. Perhaps path.relative() could be used?

@eugirdor
Copy link
Author

eugirdor commented Aug 2, 2016

In the Windows command line, you can change your drive letter casing by switching to a different drive and changing directories on the C: drive. (Assuming you have a D: drive, the following commands will work):

C:\>D:

D:\>cd c:\

D:\>c:

c:\>

@vadimdemedes vadimdemedes added the bug current functionality does not work as desired label Aug 9, 2016
@vadimdemedes
Copy link
Contributor

The problem is with the use of !== to compare localCLI and __filename.

Swapping !== with != wouldn't solve the problem, as the case of strings affects the result anyway.

@sindresorhus @jamestalmage @sotojuan @jfmengels Would a simple .toLowerCase() be a good fix for this case?

@novemberborn
Copy link
Member

@vdemedes the suggestion is to use path methods to do the comparison. Lowercasing wouldn't work for case-sensitive file systems.

@vadimdemedes
Copy link
Contributor

@novemberborn I meant to lowercase both variables: localCLI and __filename.

@vadimdemedes
Copy link
Contributor

Although yes, path.relative would be better.

path.relative(localCLI, __filename) !== ''

@sindresorhus
Copy link
Member

Related Node.js issue: nodejs/node#6624

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug current functionality does not work as desired
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants