Skip to content

Commit

Permalink
fix(oclif): restore support for use local version
Browse files Browse the repository at this point in the history
  • Loading branch information
ianwremmel committed Apr 18, 2018
1 parent cacf86b commit 20c9412
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion bin/run
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,44 @@

'use strict';

const fs = require('fs');
const path = require('path');

const findRoot = require('find-root');

require('@oclif/command')
.run()
.run(undefined, findLocalClark())
.catch(require('@oclif/errors/handle'));

/**
* Attempts to determine if there's a non-globally-installed version of clark
* somewhere in the local folder hierarchy.
* @private
* @returns {string|undefined}
*/
function findLocalClark() {
try {
const root = findRoot(process.cwd(), (dir) => {
const clarkPath = path.resolve(dir, 'node_modules', '.bin', 'clark');
// eslint-disable-next-line no-sync
return fs.existsSync(clarkPath);
});

// This isn't perfect; it could break for certain layouts of node_modules, but
// I'm not sure those layouts can happen in a way that would also allow clark
// to work in a project.
const localPath = path.resolve(
root,
'node_modules',
'@ianwremmel',
'clark',
);
return localPath;
} catch (err) {
if (err.message.includes('package.json not found in path')) {
// eslint-disable-next-line import/no-unassigned-import
return undefined;
}
throw err;
}
}

0 comments on commit 20c9412

Please sign in to comment.