From 5dbc7d9a63220b95c8a1c9f88e619f8de4eaad21 Mon Sep 17 00:00:00 2001 From: Keen Yee Liau Date: Tue, 22 Jan 2019 14:32:06 -0800 Subject: [PATCH] fix(bazel): Builder should invoke local bazel/iblaze (#28303) Builder for `@angular/bazel` schematics should not expect bazel/ibazel to be on the PATH. It should instead invoke the local executable installed by yarn/npm. PR Close #28303 --- packages/bazel/src/builders/bazel.ts | 7 +++++-- packages/bazel/src/builders/index.ts | 5 +++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/bazel/src/builders/bazel.ts b/packages/bazel/src/builders/bazel.ts index 24c5369a8d..e6e1a124d0 100644 --- a/packages/bazel/src/builders/bazel.ts +++ b/packages/bazel/src/builders/bazel.ts @@ -8,6 +8,7 @@ /// import {spawn, spawnSync} from 'child_process'; +import {join} from 'path'; import {Observable, Subject} from 'rxjs'; export type Executable = 'bazel' | 'ibazel'; @@ -17,7 +18,8 @@ export function runBazel( projectDir: string, executable: Executable, command: Command, workspaceTarget: string, flags: string[]): Observable { const doneSubject = new Subject(); - const buildProcess = spawn(executable, [command, workspaceTarget, ...flags], { + const bin = join(projectDir, 'node_modules', '.bin', executable); + const buildProcess = spawn(bin, [command, workspaceTarget, ...flags], { cwd: projectDir, stdio: 'inherit', shell: false, @@ -35,7 +37,8 @@ export function runBazel( } export function checkInstallation(executable: Executable, projectDir: string) { - const child = spawnSync(executable, ['version'], { + const bin = join(projectDir, 'node_modules', '.bin', executable); + const child = spawnSync(bin, ['version'], { cwd: projectDir, shell: false, }); diff --git a/packages/bazel/src/builders/index.ts b/packages/bazel/src/builders/index.ts index 42785c8c34..cf268067fc 100644 --- a/packages/bazel/src/builders/index.ts +++ b/packages/bazel/src/builders/index.ts @@ -11,7 +11,7 @@ import {BuildEvent, Builder, BuilderConfiguration, BuilderContext} from '@angular-devkit/architect'; import {getSystemPath, resolve} from '@angular-devkit/core'; import {Observable, of } from 'rxjs'; -import {catchError, map, tap} from 'rxjs/operators'; +import {catchError, map} from 'rxjs/operators'; import {checkInstallation, runBazel} from './bazel'; import {Schema} from './schema'; @@ -28,7 +28,8 @@ class BazelBuilder implements Builder { if (!checkInstallation(executable, projectRoot)) { throw new Error( `Could not run ${executable}. Please make sure that the ` + - `"${executable}" command is available in the $PATH.`); + `"${executable}" command is installed by running ` + + `"npm install" or "yarn install".`); } // TODO: Support passing flags.