Skip to content

Commit 902a53a

Browse files
alan-agius4IgorMinar
authored andcommittedApr 8, 2019
feat(bazel): update the build to use the new architect api (#29720)
With this change the builder has been updated to use the latest architect API and make it compatable with the latest CLI Fixes angular/angular-cli#14082 PR Close #29720
1 parent e381155 commit 902a53a

File tree

10 files changed

+124
-160
lines changed

10 files changed

+124
-160
lines changed
 

‎integration/cli-hello-world-ivy-compat/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"e2e": "ng e2e --webdriver-update=false",
88
"lint": "ng lint",
99
"ng": "ng",
10-
"postinstall": "webdriver-manager update --gecko=false --standalone=false $CI_CHROMEDRIVER_VERSION_ARG && yarn ivy-ngcc",
10+
"postinstall": "webdriver-manager update --gecko=false --standalone=false $CI_CHROMEDRIVER_VERSION_ARG",
1111
"start": "ng serve",
1212
"pretest": "ng version",
1313
"test": "ng test --progress=false --watch=false && yarn e2e --configuration=ci && yarn e2e --configuration=ci-production"
@@ -28,7 +28,7 @@
2828
"zone.js": "file:../../node_modules/zone.js"
2929
},
3030
"devDependencies": {
31-
"@angular-devkit/build-angular": "0.13.5",
31+
"@angular-devkit/build-angular": "^0.800.0-beta.11",
3232
"@angular/cli": "file:../../node_modules/@angular/cli",
3333
"@angular/compiler-cli": "file:../../dist/packages-dist/compiler-cli",
3434
"@angular/language-service": "file:../../dist/packages-dist/language-service",

‎integration/cli-hello-world-ivy-minimal/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"zone.js": "file:../../node_modules/zone.js"
2929
},
3030
"devDependencies": {
31-
"@angular-devkit/build-angular": "0.13.5",
31+
"@angular-devkit/build-angular": "^0.800.0-beta.11",
3232
"@angular/cli": "file:../../node_modules/@angular/cli",
3333
"@angular/compiler-cli": "file:../../dist/packages-dist/compiler-cli",
3434
"@angular/language-service": "file:../../dist/packages-dist/language-service",

‎integration/cli-hello-world/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"zone.js": "file:../../node_modules/zone.js"
2929
},
3030
"devDependencies": {
31-
"@angular-devkit/build-angular": "0.13.5",
31+
"@angular-devkit/build-angular": "^0.800.0-beta.11",
Code has comments. Press enter to view.
3232
"@angular/cli": "file:../../node_modules/@angular/cli",
3333
"@angular/compiler-cli": "file:../../dist/packages-dist/compiler-cli",
3434
"@angular/language-service": "file:../../dist/packages-dist/language-service",

‎package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@
110110
"// 2": "devDependencies are not used under Bazel. Many can be removed after test.sh is deleted.",
111111
"// 3": "when updating @bazel/bazel version you also need to update the RBE settings in .bazelrc (see https://github.com/angular/angular/pull/27935)",
112112
"devDependencies": {
113-
"@angular/cli": "^7.3.2",
113+
"@angular/cli": "^8.0.0-beta.11",
114114
"@bazel/bazel": "0.24.0",
115115
"@bazel/buildifier": "^0.19.2",
116116
"@bazel/ibazel": "~0.9.0",

‎packages/bazel/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@
2626
}
2727
},
2828
"dependencies": {
29-
"@angular-devkit/architect": "^0.13.4",
30-
"@angular-devkit/core": "^7.0.4",
31-
"@angular-devkit/schematics": "^7.3.0-rc.0",
29+
"@angular-devkit/architect": "^0.800.0-beta.11",
30+
"@angular-devkit/core": "^8.0.0-beta.11",
31+
"@angular-devkit/schematics": "^8.0.0-beta.11",
3232
"@microsoft/api-extractor": "^7.0.21",
33-
"@schematics/angular": "^7.3.5",
33+
"@schematics/angular": "^8.0.0-beta.11",
3434
"@types/node": "6.0.84",
3535
"semver": "^5.6.0",
3636
"shelljs": "0.8.2",

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

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88

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

11-
import {Path, basename, dirname, getSystemPath, join} from '@angular-devkit/core';
12-
import {resolve} from '@angular-devkit/core/node';
11+
import {Path, dirname, getSystemPath, join, normalize} from '@angular-devkit/core';
1312
import {Host} from '@angular-devkit/core/src/virtual-fs/host';
1413
import {spawn} from 'child_process';
14+
import * as path from 'path';
1515

1616
export type Executable = 'bazel' | 'ibazel';
1717
export type Command = 'build' | 'test' | 'run' | 'coverage' | 'query';
@@ -20,9 +20,9 @@ export type Command = 'build' | 'test' | 'run' | 'coverage' | 'query';
2020
* Spawn the Bazel process. Trap SINGINT to make sure Bazel process is killed.
2121
*/
2222
export function runBazel(
23-
projectDir: Path, binary: Path, command: Command, workspaceTarget: string, flags: string[]) {
23+
projectDir: Path, binary: string, command: Command, workspaceTarget: string, flags: string[]) {
2424
return new Promise((resolve, reject) => {
25-
const buildProcess = spawn(getSystemPath(binary), [command, workspaceTarget, ...flags], {
25+
const buildProcess = spawn(process.argv[0], [binary, command, workspaceTarget, ...flags], {
2626
cwd: getSystemPath(projectDir),
2727
stdio: 'inherit',
2828
shell: false,
@@ -39,7 +39,7 @@ export function runBazel(
3939
if (code === 0) {
4040
resolve();
4141
} else {
42-
reject(new Error(`${basename(binary)} failed with code ${code}.`));
42+
reject(new Error(`${binary} failed with code ${code}.`));
4343
}
4444
});
4545
});
@@ -49,11 +49,13 @@ export function runBazel(
4949
* Resolves the path to `@bazel/bazel` or `@bazel/ibazel`.
5050
*/
5151
export function checkInstallation(name: Executable, projectDir: Path): string {
52-
const packageName = `@bazel/${name}`;
52+
const packageName = `@bazel/${name}/package.json`;
5353
try {
54-
return resolve(packageName, {
55-
basedir: projectDir,
54+
const bazelPath = require.resolve(packageName, {
55+
paths: [getSystemPath(projectDir)],
5656
});
57+
58+
return path.dirname(bazelPath);
5759
} catch (error) {
5860
if (error.code === 'MODULE_NOT_FOUND') {
5961
throw new Error(
@@ -69,11 +71,11 @@ export function checkInstallation(name: Executable, projectDir: Path): string {
6971
* Returns the absolute path to the template directory in `@angular/bazel`.
7072
*/
7173
export async function getTemplateDir(host: Host, root: Path): Promise<Path> {
72-
const packageJson = resolve('@angular/bazel', {
73-
basedir: root,
74-
resolvePackageJson: true,
74+
const packageJson = require.resolve('@angular/bazel/package.json', {
75+
paths: [getSystemPath(root)],
7576
});
76-
const packageDir = dirname(packageJson as Path);
77+
78+
const packageDir = dirname(normalize(packageJson));
7779
const templateDir = join(packageDir, 'src', 'builders', 'files');
7880
if (!await host.isDirectory(templateDir).toPromise()) {
7981
throw new Error('Could not find Bazel template directory in "@angular/bazel".');

‎packages/bazel/src/builders/builders.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"builders": {
33
"build": {
4-
"class": "./index",
4+
"implementation": "./index",
55
"schema": "./schema.json",
66
"description": "Executes Bazel on a target."
77
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,5 +137,6 @@ ts_web_test_suite(
137137
deps = [
138138
":rxjs_umd_modules",
139139
":test_lib",
140+
"@npm//karma-jasmine",
140141
],
141142
)

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

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,24 @@
88
* @fileoverview Bazel builder
99
*/
1010

11-
import {BuildEvent, Builder, BuilderConfiguration, BuilderContext} from '@angular-devkit/architect';
12-
import {Path} from '@angular-devkit/core';
13-
import {Observable, from} from 'rxjs';
11+
import {BuilderContext, BuilderOutput, createBuilder,} from '@angular-devkit/architect/src/index2';
12+
import {JsonObject, normalize} from '@angular-devkit/core';
1413
import {checkInstallation, copyBazelFiles, deleteBazelFiles, getTemplateDir, runBazel} from './bazel';
1514
import {Schema} from './schema';
15+
import {NodeJsSyncHost} from '@angular-devkit/core/node';
1616

17-
class BazelBuilder implements Builder<Schema> {
18-
constructor(private context: BuilderContext) {}
17+
async function _bazelBuilder(options: JsonObject & Schema, context: BuilderContext, ):
18+
Promise<BuilderOutput> {
19+
const root = normalize(context.workspaceRoot);
20+
const {logger} = context;
21+
const {bazelCommand, leaveBazelFilesOnDisk, targetLabel, watch} = options;
22+
const executable = watch ? 'ibazel' : 'bazel';
23+
const binary = checkInstallation(executable, root);
1924

20-
run(config: BuilderConfiguration<Partial<Schema>>): Observable<BuildEvent> {
21-
const {host, logger, workspace} = this.context;
22-
const root: Path = workspace.root;
23-
const {bazelCommand, leaveBazelFilesOnDisk, targetLabel, watch} = config.options as Schema;
24-
const executable = watch ? 'ibazel' : 'bazel';
25-
const binary = checkInstallation(executable, root) as Path;
26-
27-
return from(Promise.resolve().then(async() => {
25+
const host = new NodeJsSyncHost();
2826
const templateDir = await getTemplateDir(host, root);
2927
const bazelFiles = await copyBazelFiles(host, root, templateDir);
28+
3029
try {
3130
const flags: string[] = [];
3231
await runBazel(root, binary, bazelCommand, targetLabel, flags);
@@ -39,8 +38,6 @@ class BazelBuilder implements Builder<Schema> {
3938
await deleteBazelFiles(host, bazelFiles); // this will never throw
4039
}
4140
}
42-
}));
43-
}
44-
}
41+
}
4542

46-
export default BazelBuilder;
43+
export default createBuilder(_bazelBuilder);

‎yarn.lock

Lines changed: 85 additions & 121 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.