Skip to content

Commit

Permalink
Prefer the locally installed version of AVA.
Browse files Browse the repository at this point in the history
This hunts for AVA in the locally installed project, and runs that
CLI instead of the globally installed one.

Fixes avajs#157.
  • Loading branch information
jamestalmage committed Nov 29, 2015
1 parent 306f28d commit cb58a1a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
12 changes: 12 additions & 0 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@

var debug = require('debug')('ava');

// Prefer the local installation of AVA.
var resolveFrom = require('resolve-from');
var localCLI = resolveFrom('.', 'ava/cli');

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

if (debug.enabled) {
require('time-require');
}
Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
"power-assert-renderers": "^0.1.0",
"pretty-ms": "^2.0.0",
"require-from-string": "^1.1.0",
"resolve-from": "^1.0.0",
"resolve-from": "^2.0.0",
"serialize-error": "^1.1.0",
"set-immediate-shim": "^1.0.1",
"source-map-support": "^0.3.3",
Expand All @@ -128,5 +128,10 @@
"test[/\\\\]"
]
}
},
"xo": {
"ignore": [
"cli.js"
]
}
}
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ $ ava --help

Files starting with `_` are ignored. This can be useful for having helpers in the same directory as your test files.

*WARNING: NON-STANDARD BEHAVIOR:* The AVA CLI will always try to find and use your projects local install of AVA. This is true even when you run the global `ava` command. This non-standard behavior solves an important [issue](https://github.com/sindresorhus/ava/issues/157), and should have no impact on everyday use.

## Documentation

Expand Down

0 comments on commit cb58a1a

Please sign in to comment.