-
Notifications
You must be signed in to change notification settings - Fork 522
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(angular): introduce an Angular CLI builder
This replaces the one being removed in angular/angular#37190
- Loading branch information
Showing
15 changed files
with
338 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ module.exports = { | |
'scope-enum': [ | ||
2, 'always', | ||
[ | ||
'angular', | ||
'builtin', | ||
'create', | ||
'examples', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
load("@build_bazel_rules_nodejs//:tools/defaults.bzl", "codeowners", "pkg_npm") | ||
load("//packages/typescript:index.bzl", "ts_project") | ||
|
||
codeowners( | ||
teams = ["@alan-agius4"], | ||
) | ||
|
||
ts_project( | ||
tsc = "@angular_deps//typescript/bin:tsc", | ||
deps = ["@angular_deps//:node_modules"], | ||
) | ||
|
||
pkg_npm( | ||
name = "npm_package", | ||
srcs = [ | ||
"README.md", | ||
"package.json", | ||
"src/builders/builders.json", | ||
"src/builders/schema.d.ts", | ||
"src/builders/schema.json", | ||
], | ||
deps = ["tsconfig"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Angular support for Bazel | ||
|
||
This package is a replacement for parts of the deprecated @angular/bazel package previously maintained by the Angular team. | ||
|
||
Currently, this only provides an Angular CLI Builder, which can execute Bazel when triggered by `ng build`, `ng test`, etc. | ||
See https://angular.io/guide/cli-builder for more info about Builders. | ||
|
||
This builder assumes you have already created Bazel configurations (WORKSPACE and BUILD files). | ||
There is presently no tooling to generate these automatically that's supported by either Angular team or rules_nodejs maintainers. | ||
See the `@bazel/create` package for a quickstart to creating a Bazel workspace, or look at examples in rules_nodejs. | ||
|
||
To use it, you would just install this package (it doesn't hook into `ng add` because it has no schematics): | ||
|
||
```sh | ||
$ npm install --save-dev @bazel/angular | ||
``` | ||
|
||
Then edit your `angular.json` to invoke Bazel. For example, to have `ng build` do `bazel build //:all` you would edit the `architect` block to have: | ||
|
||
```json | ||
"architect": { | ||
"build": { | ||
"builder": "@bazel/angular:build", | ||
"options": { | ||
"targetLabel": "//:all", | ||
"bazelCommand": "build" | ||
} | ||
} | ||
``` |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"name": "@bazel/angular", | ||
"description": "Run Bazel under the Angular CLI", | ||
"license": "Apache-2.0", | ||
"version": "0.0.0-PLACEHOLDER", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/bazelbuild/rules_nodejs.git", | ||
"directory": "packages/angular" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/bazelbuild/rules_nodejs/issues" | ||
}, | ||
"keywords": [ | ||
"angular", | ||
"bazel" | ||
], | ||
"builders": "./src/builders/builders.json", | ||
"dependencies": { | ||
"@bazel/bazelisk": "^1.4.0", | ||
"@bazel/ibazel": "^0.13.1", | ||
"@angular-devkit/architect": "^0.901.7" | ||
}, | ||
"devDependencies": { | ||
"@angular-devkit/core": "^9.1.7", | ||
"@types/node": "^14.0.5", | ||
"typescript": "^3.9.3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"builders": { | ||
"build": { | ||
"implementation": "./index", | ||
"schema": "./schema.json", | ||
"description": "Executes Bazel on a target." | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import {BuilderContext, BuilderOutput, createBuilder} from '@angular-devkit/architect'; | ||
import {JsonObject} from '@angular-devkit/core'; | ||
import {getNativeBinary as bazeliskBin} from '@bazel/bazelisk/bazelisk'; | ||
import {getNativeBinary as ibazelBin} from '@bazel/ibazel'; | ||
import {spawn} from 'child_process'; | ||
import {Schema} from './schema'; | ||
|
||
async function _bazelBuilder( | ||
options: JsonObject&Schema, | ||
context: BuilderContext, | ||
): Promise<BuilderOutput> { | ||
const {bazelCommand, targetLabel, watch} = options; | ||
const binary = watch ? ibazelBin() : bazeliskBin(); | ||
if (typeof binary !== 'string') { | ||
// this happens if no binary is located for the current platform | ||
return {success: false}; | ||
} else { | ||
try { | ||
const ps = spawn(binary, [bazelCommand, targetLabel], {stdio: 'inherit'}); | ||
|
||
function shutdown() { | ||
ps.kill('SIGTERM'); | ||
} | ||
|
||
process.on('SIGINT', shutdown); | ||
process.on('SIGTERM', shutdown); | ||
return new Promise(resolve => { | ||
ps.on('close', e => resolve({success: e === 0})); | ||
}); | ||
} catch (err) { | ||
context.logger.error(err.message); | ||
return {success: false}; | ||
} | ||
} | ||
} | ||
|
||
export default createBuilder(_bazelBuilder); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* @license | ||
* Copyright Google Inc. All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
/** | ||
* Options for Bazel Builder | ||
*/ | ||
export interface Schema { | ||
/** | ||
* Common commands supported by Bazel. | ||
*/ | ||
bazelCommand: BazelCommand; | ||
/** | ||
* Target to be executed under Bazel. | ||
*/ | ||
targetLabel: string; | ||
/** | ||
* If true, watch the filesystem using ibazel. | ||
*/ | ||
watch?: boolean; | ||
} | ||
|
||
/** | ||
* Common commands supported by Bazel. | ||
*/ | ||
export enum BazelCommand { | ||
Build = 'build', | ||
Run = 'run', | ||
Test = 'test', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"$schema": "http://json-schema.org/schema", | ||
"title": "Bazel builder schema", | ||
"description": "Options for Bazel Builder", | ||
"type": "object", | ||
"properties": { | ||
"targetLabel": { | ||
"type": "string", | ||
"description": "Target to be executed under Bazel." | ||
}, | ||
"bazelCommand": { | ||
"type": "string", | ||
"description": "Common commands supported by Bazel.", | ||
"enum": [ | ||
"run", | ||
"build", | ||
"test" | ||
] | ||
}, | ||
"watch": { | ||
"type": "boolean", | ||
"description": "If true, watch the filesystem using ibazel.", | ||
"default": false | ||
} | ||
}, | ||
"additionalProperties": false, | ||
"required": [ | ||
"targetLabel", | ||
"bazelCommand" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"compilerOptions": { | ||
"strict": true, | ||
"target": "ES2018", | ||
"module": "CommonJS", | ||
"types": ["node"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
declare module '@bazel/bazelisk/bazelisk' { | ||
function getNativeBinary(): Promise<number>|string; | ||
} | ||
|
||
declare module '@bazel/ibazel' { | ||
function getNativeBinary(): Promise<number>|string; | ||
} |