Skip to content

Commit

Permalink
chore(NA): add safe guard to remove bazelisk from yarn global at boot…
Browse files Browse the repository at this point in the history
…strap (#90538)
  • Loading branch information
mistic authored Feb 6, 2021
1 parent be725ca commit 6408a66
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
27 changes: 26 additions & 1 deletion packages/kbn-pm/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48119,6 +48119,29 @@ async function isBazeliskInstalled(bazeliskVersion) {
}
}

async function tryRemoveBazeliskFromYarnGlobal() {
try {
// Check if Bazelisk is installed on the yarn global scope
const {
stdout: bazeliskPkgInstallStdout
} = await Object(_child_process__WEBPACK_IMPORTED_MODULE_2__["spawn"])('yarn', ['global', 'list'], {
stdio: 'pipe'
}); // Bazelisk was found on yarn global scope so lets remove it

if (bazeliskPkgInstallStdout.includes(`@bazel/bazelisk@`)) {
await Object(_child_process__WEBPACK_IMPORTED_MODULE_2__["spawn"])('yarn', ['global', 'remove', `@bazel/bazelisk`], {
stdio: 'pipe'
});
_log__WEBPACK_IMPORTED_MODULE_4__["log"].info(`[bazel_tools] bazelisk was installed on Yarn global packages and is now removed`);
return true;
}

return false;
} catch {
return false;
}
}

async function installBazelTools(repoRootPath) {
_log__WEBPACK_IMPORTED_MODULE_4__["log"].debug(`[bazel_tools] reading bazel tools versions from version files`);
const bazeliskVersion = await readBazelToolsVersionFile(repoRootPath, '.bazeliskversion');
Expand All @@ -48128,7 +48151,9 @@ async function installBazelTools(repoRootPath) {

const isBazeliskPkgInstalled = await isBazeliskInstalled(bazeliskVersion); // Test if bazel bin is available

const isBazelBinAlreadyAvailable = await isBazelBinAvailable(); // Install bazelisk if not installed
const isBazelBinAlreadyAvailable = await isBazelBinAvailable(); // Check if we need to remove bazelisk from yarn

await tryRemoveBazeliskFromYarnGlobal(); // Install bazelisk if not installed

if (!isBazeliskPkgInstalled || !isBazelBinAlreadyAvailable) {
_log__WEBPACK_IMPORTED_MODULE_4__["log"].info(`[bazel_tools] installing Bazel tools`);
Expand Down
26 changes: 26 additions & 0 deletions packages/kbn-pm/src/utils/bazel/install_tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,29 @@ async function isBazeliskInstalled(bazeliskVersion: string) {
}
}

async function tryRemoveBazeliskFromYarnGlobal() {
try {
// Check if Bazelisk is installed on the yarn global scope
const { stdout: bazeliskPkgInstallStdout } = await spawn('yarn', ['global', 'list'], {
stdio: 'pipe',
});

// Bazelisk was found on yarn global scope so lets remove it
if (bazeliskPkgInstallStdout.includes(`@bazel/bazelisk@`)) {
await spawn('yarn', ['global', 'remove', `@bazel/bazelisk`], {
stdio: 'pipe',
});

log.info(`[bazel_tools] bazelisk was installed on Yarn global packages and is now removed`);
return true;
}

return false;
} catch {
return false;
}
}

export async function installBazelTools(repoRootPath: string) {
log.debug(`[bazel_tools] reading bazel tools versions from version files`);
const bazeliskVersion = await readBazelToolsVersionFile(repoRootPath, '.bazeliskversion');
Expand All @@ -66,6 +89,9 @@ export async function installBazelTools(repoRootPath: string) {
// Test if bazel bin is available
const isBazelBinAlreadyAvailable = await isBazelBinAvailable();

// Check if we need to remove bazelisk from yarn
await tryRemoveBazeliskFromYarnGlobal();

// Install bazelisk if not installed
if (!isBazeliskPkgInstalled || !isBazelBinAlreadyAvailable) {
log.info(`[bazel_tools] installing Bazel tools`);
Expand Down

0 comments on commit 6408a66

Please sign in to comment.