Skip to content

Commit

Permalink
fix(bazel): export getNativeBinary()
Browse files Browse the repository at this point in the history
`@bazel/bazel` should export getNativeBinary() method so that downstream
consumers can locate the actual Bazel binary and spawn a process using
custom options. If loaded as script the package should work as before.
  • Loading branch information
Keen Yee Liau authored and alexeagle committed Apr 12, 2019
1 parent d6eb5a3 commit e1bd97c
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions packages/bazel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const spawnSync = require('child_process').spawnSync;
const warnGlobalInstall = `
*** WARNING
The Bazel binary is being run from a global install.
This means the version may not match the one used in your project.
We recommend installing the @bazel/bazel package locally in your project.
***
Expand Down Expand Up @@ -53,8 +53,14 @@ function getNativeBinary() {
return path.resolve(path.dirname(nativePackage), binary);
}

/** Starts a new synchronous child process that runs Bazel with the specified arguments. */
const bazelProcess = spawnSync(getNativeBinary(), process.argv.slice(2), {stdio: 'inherit'});
if (require.main === module) {
/** Starts a new synchronous child process that runs Bazel with the specified arguments. */
const bazelProcess = spawnSync(getNativeBinary(), process.argv.slice(2), {stdio: 'inherit'});

// Ensure that this wrapper script exits with the same exit code as the child process.
process.exit(bazelProcess.status);
}

// Ensure that this wrapper script exits with the same exit code as the child process.
process.exit(bazelProcess.status);
module.exports = {
getNativeBinary,
};

0 comments on commit e1bd97c

Please sign in to comment.