Permalink
Browse files

Use the `import-local` module (#1376)

  • Loading branch information...
sindresorhus committed Jun 14, 2017
1 parent dfca2d9 commit 7c62b3524d72a4b6953a4d874edf0e4138851317
View
14 cli.js
@@ -1,19 +1,11 @@
#!/usr/bin/env node
'use strict';
const path = require('path');
const debug = require('debug')('ava');
const importLocal = require('import-local');
// Prefer the local installation of AVA.
const resolveCwd = require('resolve-cwd');
const localCLI = resolveCwd('ava/cli');
// Use `path.relative()` to detect local AVA installation,
// because __filename's case is inconsistent on Windows
// see https://github.com/nodejs/node/issues/6624
if (localCLI && path.relative(localCLI, __filename) !== '') {
// Prefer the local installation of AVA
if (importLocal(__filename)) {
debug('Using local install of AVA');
require(localCLI);
} else {
if (debug.enabled) {
require('time-require'); // eslint-disable-line import/no-unassigned-import
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -133,6 +133,7 @@
"has-flag": "^2.0.0",
"hullabaloo-config-manager": "^1.1.0",
"ignore-by-default": "^1.0.0",
"import-local": "^0.1.1",
"indent-string": "^3.0.0",
"is-ci": "^1.0.7",
"is-generator-fn": "^1.0.0",
View
@@ -7,8 +7,6 @@ const getStream = require('get-stream');
const figures = require('figures');
const makeDir = require('make-dir');
const touch = require('touch');
const proxyquire = require('proxyquire');
const sinon = require('sinon');
const uniqueTempDir = require('unique-temp-dir');
const execa = require('execa');
const stripAnsi = require('strip-ansi');
@@ -33,7 +31,7 @@ function execCli(args, opts, cb) {
let stderr;
const processPromise = new Promise(resolve => {
child = childProcess.spawn(process.execPath, [path.relative(dirname, cliPath)].concat(args), {
child = childProcess.spawn(process.execPath, [cliPath].concat(args), {
cwd: dirname,
env,
stdio: [null, 'pipe', 'pipe']
@@ -421,33 +419,16 @@ test('should warn ava is required without the cli', t => {
});
test('prefers local version of ava', t => {
t.plan(1);
const stubModulePath = path.join(__dirname, '/fixture/empty');
const debugSpy = sinon.spy();
const resolveCwdStub = () => stubModulePath;
function debugStub() {
return message => {
let result = {
enabled: false
};
if (message) {
result = debugSpy(message);
}
return result;
};
}
proxyquire('../cli', {
debug: debugStub,
'resolve-cwd': resolveCwdStub
execCli('', {
dirname: 'fixture/local-bin',
env: {
DEBUG: 'ava'
}
}, (err, stdout, stderr) => {
t.ifError(err);
t.match(stderr, 'Using local install of AVA');
t.end();
});
t.ok(debugSpy.calledWith('Using local install of AVA'));
t.end();
});
test('use current working directory if `package.json` is not found', () => {

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

0 comments on commit 7c62b35

Please sign in to comment.