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 28, 2015
1 parent 306f28d commit c62f136
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
13 changes: 13 additions & 0 deletions cli.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
#!/usr/bin/env node
'use strict';

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

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

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

if (debug.enabled) {
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,8 @@
"test[/\\\\]"
]
}
},
"xo": {
"ignore": ["cli.js"]
}
}
3 changes: 3 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ $ 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 c62f136

Please sign in to comment.