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 #157.
  • Loading branch information
jamestalmage committed Nov 27, 2015
1 parent 306f28d commit 81db628
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
18 changes: 18 additions & 0 deletions cli.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
#!/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) {
var thisVersion = require('./package.json').version;
var localVersion = require(localCLI.replace(/cli\.js$/, 'package.json')).version;
var warningMessage = 'Using local install of AVA (v%s), which ';
warningMessage += thisVersion === localVersion ? 'matches' : 'differs from';
warningMessage += ' global (v%s)';
console.warn(require('chalk').yellow(warningMessage), localVersion, thisVersion);
require(localCLI);
return;
}

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

if (debug.enabled) {
Expand Down
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 81db628

Please sign in to comment.