Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search for a local npm installation #74

Merged
merged 2 commits into from
Dec 3, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion npm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

// This package inspired by
// https://github.com/angular/clang-format/blob/master/index.js
const fs = require('fs');
const os = require('os');
const path = require('path');
const spawn = require('child_process').spawn;
Expand All @@ -38,7 +39,23 @@ function main(args) {
return Promise.resolve(1);
}

const binary = path.join(__dirname, 'bin', `${platform}_${arch}`, 'ibazel');
// By default, use the ibazel binary underneath this script
var basePath = __dirname;

const dirs = process.cwd().split(path.sep);

// Walk up the cwd, looking for a local ibazel installation
for (var i = dirs.length; i > 0; i--) {
var attemptedBasePath = [...dirs.slice(0, i), 'node_modules', '@bazel', 'ibazel'].join(path.sep);

// If we find a local installation, use that one instead
if (fs.existsSync(path.join(attemptedBasePath, 'bin', `${platform}_${arch}`, 'ibazel'))) {
basePath = attemptedBasePath;
break;
}
}

const binary = path.join(basePath, 'bin', `${platform}_${arch}`, 'ibazel');
const ibazel = spawn(binary, args, {stdio: 'inherit'});
ibazel.on('close', e => process.exitCode = e);
}
Expand Down