-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Prefer the locally installed version of AVA. #277
Prefer the locally installed version of AVA. #277
Conversation
The second commit wraps the entire CLI in an IIFE, to avoid a |
a8b0c20
to
d6c3b6e
Compare
If xojs/xo#51 were to be implemented, the second commit would not be necessary. |
This needs a test suite, which is doable but will involve a number of fixtures. I would like agreement on my general approach before completing. Right now, it outputs the following:
|
Instead of wrapping it in an IIFE, just remove XO for now. We can add it back when we've sorted this out. |
I don't think it matters if they differ. All we're doing with the global CLI if local is available is to require the local one. As long as the user has AVA 0.7.0 containing this pull request installed globally they should be fine. |
// Prefer the local installation of AVA. | ||
var resolveFrom = require('resolve-from'); | ||
var localCLI; | ||
try { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Been thinking about changing resolve-from
to just return null
when not found instead of throwing. Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI try-resolve-from works as you expected. https://github.com/shinnn/try-resolve-from/blob/50cd2cb89934ec0172e43db86fe78263759908ee/index.js
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think resolve-from
should adopt that behavior. I can't think of very many scenarios where you would want resolve-from
, and not want to wrap the thrown exception.
Also, it looks like someone was already assuming that behavior here: babel.js#L41. This looks like the more common use-case.
Perhaps retain the old behavior somewhere:
require('resolve-from/throws');
or something like that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK I'll unpublish try-resolve-from. sindresorhus/resolve-from@4cb3cf0
This is what led me to the // cli-shim.js
require('fallback-cli')('ava/cli.js', function (opts) {
// returns are allowed inside the callback - linters stay happy.
if (opts.globalCli && opts.localCli) {
console.warn('Using the local install of AVA instead of global.');
}
require(opts.cli); // opts.cli === opts.localCli || opts.globalCli
}); |
335708a
to
db8d79f
Compare
} catch (e) {} | ||
|
||
if (localCLI && localCLI !== __filename) { | ||
console.warn('Using local install of AVA.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need that warning, it gives no helpful information to the test output. Plus, it will not look good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this is something we could have in a future --verbose
mode or just add it as a debug()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. Honestly, that line was there to appease you: xojs/xo#32 (comment).
I thought you brought up a good point, that silently changing standard behavior is a bad thing.
@sindresorhus, what do you think?
@jamestalmage Bump |
Generally looks good to me. |
db8d79f
to
cb58a1a
Compare
var localCLI = resolveFrom('.', 'ava/cli'); | ||
|
||
if (localCLI && localCLI !== __filename) { | ||
if (debug.enabled) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't have to check if debug is enabled. That's already done by debug
One minor comment. Otherwise it's good. Feel free to merge when that's resolved. |
This hunts for AVA in the locally installed project, and runs that CLI instead of the globally installed one. Fixes avajs#157.
cb58a1a
to
2f7ac92
Compare
Prefer the locally installed version of AVA.
This hunts for AVA in the locally installed project, and runs that
CLI instead of the globally installed one.
Fixes #157.