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
This commit is contained in:
Keen Yee Liau 2019-01-22 14:32:06 -08:00 committed by Jason Aden
parent fd8dbd5e40
commit 5dbc7d9a63
2 changed files with 8 additions and 4 deletions

View File

@ -8,6 +8,7 @@
/// <reference types='node'/> /// <reference types='node'/>
import {spawn, spawnSync} from 'child_process'; import {spawn, spawnSync} from 'child_process';
import {join} from 'path';
import {Observable, Subject} from 'rxjs'; import {Observable, Subject} from 'rxjs';
export type Executable = 'bazel' | 'ibazel'; export type Executable = 'bazel' | 'ibazel';
@ -17,7 +18,8 @@ export function runBazel(
projectDir: string, executable: Executable, command: Command, workspaceTarget: string, projectDir: string, executable: Executable, command: Command, workspaceTarget: string,
flags: string[]): Observable<void> { flags: string[]): Observable<void> {
const doneSubject = new Subject<void>(); const doneSubject = new Subject<void>();
const buildProcess = spawn(executable, [command, workspaceTarget, ...flags], { const bin = join(projectDir, 'node_modules', '.bin', executable);
const buildProcess = spawn(bin, [command, workspaceTarget, ...flags], {
cwd: projectDir, cwd: projectDir,
stdio: 'inherit', stdio: 'inherit',
shell: false, shell: false,
@ -35,7 +37,8 @@ export function runBazel(
} }
export function checkInstallation(executable: Executable, projectDir: string) { 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, cwd: projectDir,
shell: false, shell: false,
}); });

View File

@ -11,7 +11,7 @@
import {BuildEvent, Builder, BuilderConfiguration, BuilderContext} from '@angular-devkit/architect'; import {BuildEvent, Builder, BuilderConfiguration, BuilderContext} from '@angular-devkit/architect';
import {getSystemPath, resolve} from '@angular-devkit/core'; import {getSystemPath, resolve} from '@angular-devkit/core';
import {Observable, of } from 'rxjs'; import {Observable, of } from 'rxjs';
import {catchError, map, tap} from 'rxjs/operators'; import {catchError, map} from 'rxjs/operators';
import {checkInstallation, runBazel} from './bazel'; import {checkInstallation, runBazel} from './bazel';
import {Schema} from './schema'; import {Schema} from './schema';
@ -28,7 +28,8 @@ class BazelBuilder implements Builder<Schema> {
if (!checkInstallation(executable, projectRoot)) { if (!checkInstallation(executable, projectRoot)) {
throw new Error( throw new Error(
`Could not run ${executable}. Please make sure that the ` + `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. // TODO: Support passing flags.