Skip to content

Commit 2a0f497

Browse files
Keen Yee Liaualxhub
authored andcommitted
fix(bazel): Directly spawn native Bazel binary (#30306)
Instead of launching a Node.js process that in turn spawns Bazel binary, the Builder could now directly spawn the native binary. This makes the bootup process slightly more efficient, and allows the Builder to control spawn options. This works with both Bazel and iBazel. PR Close #30306
1 parent 392473e commit 2a0f497

3 files changed

Lines changed: 8 additions & 6 deletions

File tree

‎packages/bazel/src/builders/bazel.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
/// <reference types='node'/>
1010

11-
import {fork} from 'child_process';
11+
import {spawn} from 'child_process';
1212
import {copyFileSync, existsSync, readdirSync, statSync, unlinkSync} from 'fs';
1313
import {dirname, join, normalize} from 'path';
1414

@@ -24,7 +24,7 @@ export function runBazel(
2424
projectDir = normalize(projectDir);
2525
binary = normalize(binary);
2626
return new Promise((resolve, reject) => {
27-
const buildProcess = fork(binary, [command, workspaceTarget, ...flags], {
27+
const buildProcess = spawn(binary, [command, workspaceTarget, ...flags], {
2828
cwd: projectDir,
2929
stdio: 'inherit',
3030
});
@@ -51,12 +51,12 @@ export function runBazel(
5151
*/
5252
export function checkInstallation(name: Executable, projectDir: string): string {
5353
projectDir = normalize(projectDir);
54-
const packageName = `@bazel/${name}/package.json`;
54+
const packageName = `@bazel/${name}`;
5555
try {
5656
const bazelPath = require.resolve(packageName, {
5757
paths: [projectDir],
5858
});
59-
return dirname(bazelPath);
59+
return require(bazelPath).getNativeBinary();
6060
} catch (error) {
6161
if (error.code === 'MODULE_NOT_FOUND') {
6262
throw new Error(

‎packages/bazel/src/builders/files/__dot__bazelrc.template‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ build --incompatible_strict_action_env
2323
run --incompatible_strict_action_env
2424
test --incompatible_strict_action_env
2525

26+
build --incompatible_bzl_disallow_load_after_statement=false
27+
2628
test --test_output=errors
2729

2830
# Use the Angular 6 compiler

‎packages/bazel/src/schematics/ng-add/index.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ function addDevDependenciesToPackageJson(options: Schema) {
4848

4949
const devDependencies: {[k: string]: string} = {
5050
'@angular/bazel': angularCoreVersion,
51-
'@bazel/bazel': '^0.24.0',
52-
'@bazel/ibazel': '^0.10.1',
51+
'@bazel/bazel': '^0.25.1',
52+
'@bazel/ibazel': '^0.10.2',
5353
'@bazel/karma': '0.27.12',
5454
'@bazel/typescript': '0.27.12',
5555
};

0 commit comments

Comments
 (0)