From 2f7ac92d8ccfd5763e83d5a4050ee0ed23e46a87 Mon Sep 17 00:00:00 2001 From: James Talmage Date: Fri, 27 Nov 2015 18:21:52 -0500 Subject: [PATCH] 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. --- cli.js | 10 ++++++++++ package.json | 7 ++++++- readme.md | 1 + 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/cli.js b/cli.js index 6ed48633a..f1218df28 100755 --- a/cli.js +++ b/cli.js @@ -3,6 +3,16 @@ 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) { + debug('Using local install of AVA.'); + require(localCLI); + return; +} + if (debug.enabled) { require('time-require'); } diff --git a/package.json b/package.json index b43e826ae..37a754347 100644 --- a/package.json +++ b/package.json @@ -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", @@ -128,5 +128,10 @@ "test[/\\\\]" ] } + }, + "xo": { + "ignore": [ + "cli.js" + ] } } diff --git a/readme.md b/readme.md index d35b35f7d..0c278c387 100644 --- a/readme.md +++ b/readme.md @@ -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