Skip to content
This repository was archived by the owner on Apr 4, 2025. It is now read-only.

Commit b1f9e24

Browse files
authored
Install bazel from npm, don't depend on user to do it manually (#231)
Update README to explain install This repo works with either Bazel or Yarn, you need only one of them
1 parent 4cae1a8 commit b1f9e24

5 files changed

Lines changed: 76 additions & 53 deletions

File tree

‎.circleci/config.yml‎

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,28 @@
11
# This file configures the build at https://circleci.com/gh/alexeagle/angular-bazel-example
22
# Complete documentation is at https://circleci.com/docs/2.0/
33

4-
# We use a docker image as the basis for our build, so that all the toolchains we use
5-
# are already installed and the build can start running right away. It also guarantees
6-
# the environment is portable and reproducible on your local machine.
7-
var_1: &docker_image angular/ngcontainer:0.8.0
8-
94
# CircleCI lets us pick the key for storing one or more caches, to speed up subsequent builds.
105
# We can use this to avoid re-fetching our dependencies from npm on every build.
116
# To ensure we don't load a stale cache, we invalidate it based on the entries in the key:
127
# - the checksum of Yarn's lock file
138
# - the branch we are on, which really shouldn't be needed since the yarn lock file should be hermetic
149
# - the docker image tag, working around an issue we saw where changing docker images causes permission
1510
# errors when restoring the cache, like when the user we run as changes
16-
var_2: &cache_key angular-{{ .Branch }}-{{ checksum "yarn.lock" }}-0.8.0
11+
var_1: &cache_key angular-{{ .Branch }}-{{ checksum "yarn.lock" }}-0.8.0
1712

1813
# Each job will inherit these defaults
19-
anchor_1: &job_defaults
14+
var_2: &job_defaults
2015
working_directory: ~/ng
2116
docker:
22-
- image: *docker_image
17+
# Use the -browsers version just to get the right .so files on the disk
18+
# We'll actually download a chromium version under the rules_webtesting
19+
- image: circleci/node:10.12-browsers
2320

2421
# After checkout, rebase on top of master, because we want to test the proposed merge of a
2522
# onto the target branch, not just test what's on the user's fork.
2623
# Similar to travis behavior, but not quite the same.
2724
# See https://discuss.circleci.com/t/1662
28-
anchor_2: &post_checkout
25+
var_3: &post_checkout
2926
post: git pull --ff-only origin "refs/pull/${CI_PULL_REQUEST//*pull\//}/merge"
3027

3128
# Opt-in to the new goodness
@@ -34,15 +31,19 @@ version: 2
3431
# These jobs will run in parallel, and report separate statuses to GitHub PRs
3532
jobs:
3633
lint:
37-
<<: *job_defaults
34+
docker:
35+
- image: circleci/node:10.12
3836
steps:
3937
- checkout:
4038
<<: *post_checkout
4139

42-
# Enforce that BUILD files are formatted. Note that this uses the version of buildifier
43-
# from the docker image above - take care that you use the same version when you run
44-
# buildifier locally on your change.
45-
- run: 'buildifier -mode=check $(find . -type f \( -name BUILD.bazel -or -name BUILD \)) ||
40+
- restore_cache:
41+
key: *cache_key
42+
43+
# Install Bazel
44+
- run: yarn
45+
# Enforce that BUILD files are formatted.
46+
- run: 'yarn buildifier -mode=check ||
4647
(echo "BUILD files not formatted. Please run ''yarn buildifier''" ; exit 1)'
4748

4849
build:
@@ -52,14 +53,17 @@ jobs:
5253
- checkout:
5354
<<: *post_checkout
5455

56+
- restore_cache:
57+
key: *cache_key
58+
5559
- run: sudo cp .circleci/bazel.rc /etc/bazel.bazelrc
5660

57-
# Helpful for debugging, so you can check you have the same bazel version when you need
58-
# to reproduce a failure.
59-
- run: bazel info release
61+
# Install Bazel from NPM
62+
- run: yarn
6063

6164
# Build and Test
62-
- run: bazel test //...
65+
- run: yarn test
66+
- run: yarn e2e
6367

6468
- store_artifacts:
6569
path: dist/bin/src/bundle.min.js
@@ -78,9 +82,10 @@ jobs:
7882
- restore_cache:
7983
key: *cache_key
8084

81-
# Run the benchmark
85+
# Install Bazel/ibazel from NPM
8286
- run: yarn
83-
- run: node_modules/.bin/ibazel-benchmark-runner //src:devserver src/hello-world/hello-world.component.ts --url=http://localhost:5432
87+
# Run the benchmark
88+
- run: yarn benchmark
8489

8590
# If we get this far, save the node_modules directory for use next time.
8691
- save_cache:

‎README.md‎

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,66 +15,55 @@ Follow https://github.com/angular/angular/issues/19058 for updates.
1515

1616
## Installation
1717

18-
Install Bazel from the distribution, see [install] instructions.
19-
On Mac, if you have Homebrew installed you can
18+
You only need to install one build tool, and which one you choose typically depends on what kind of development you do most often.
2019

21-
```bash
22-
brew tap bazelbuild/tap
23-
brew tap-pin bazelbuild/tap
24-
brew install bazel
25-
```
26-
27-
Bazel will install a hermetic version of Node, npm, and Yarn when
28-
you run the first build.
20+
If you're a frontend developer, you should install NodeJS and yarn.
21+
The `package.json` file has an `engines` section which indicates the range of NodeJS and yarn versions that you could use.
22+
You simply run `yarn` commands shown below, and don't need to install Bazel or any other dependencies.
2923

30-
[install]: https://bazel.build/versions/master/docs/install.html
31-
32-
Also add `ibazel` to your `$PATH`:
33-
34-
```
35-
yarn global add @bazel/ibazel
36-
```
37-
38-
or
39-
40-
```
41-
npm install -g @bazel/ibazel
42-
```
24+
If you're a full-stack developer, you might be using Bazel for your backend already.
25+
In this case, you should install Bazel following instructions at http://bazel.build.
26+
Also install `ibazel`, which is a watch mode for Bazel not included in the standard distribution. See https://github.com/bazelbuild/bazel-watcher#installation.
27+
The `WORKSPACE` file has a `check_bazel_version` call which will print an error if your Bazel version is not in the supported range.
28+
You simply run `bazel` commands shown below, and don't need to install NodeJS, yarn, or any other dependencies.
4329

4430
## Development
4531

46-
Next we'll run the development server:
32+
First we'll run the development server:
4733

4834
```bash
4935
$ yarn serve
36+
# or
37+
$ ibazel run //src:devserver
5038
```
5139

52-
> This script runs `ibazel`, which is a "watch mode"
53-
> for Bazel. That means it will watch any files that are inputs to the devserver,
54-
> and when they change it will ask Bazel to re-build them. The server stays
55-
> running, and when the re-build is finished, it will trigger the LiveReload in
56-
> the browser.
40+
This runs in "watch mode", which means it will watch any files that are inputs to the devserver, and when they change it will ask Bazel to re-build them.
41+
When the re-build is finished, it will trigger a LiveReload in the browser.
5742

5843
This command prints a URL on the terminal. Open that page to see the demo app
5944
running. Now you can edit one of the source files (`src/lib/file.ts` is an easy
6045
one to understand and see the effect). As soon as you save a change, the app
6146
should refresh in the browser with the new content. Our intent is that this time
6247
is less than two seconds, even for a large application.
6348

64-
Control-C twice to kill the devserver and also stop `ibazel`.
49+
Control-C twice to kill the devserver.
6550

6651
## Testing
6752

6853
We can also run all the unit tests:
6954

7055
```bash
7156
$ yarn test
57+
# or
58+
$ bazel test //src/...
7259
```
7360

7461
Or run the end-to-end tests:
7562

7663
```bash
7764
$ yarn e2e
65+
# or
66+
$ bazel test //e2e/...
7867
```
7968

8069
In this example, there is a unit test for the `hello-world` component which uses
@@ -92,6 +81,8 @@ bundlers can be integrated with Bazel.
9281

9382
```bash
9483
$ yarn serve-prod
84+
# or
85+
$ bazel run //src:prodserver
9586
```
9687

9788
### Code splitting

‎WORKSPACE‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
workspace(name = "angular_bazel_example")
99

1010
# The Bazel buildtools repo contains tools like the BUILD file formatter, buildifier
11-
# This commit matches the version of buildifier in angular/ngcontainer
12-
# If you change this, also check if it matches the version in the angular/ngcontainer
13-
# version in /.circleci/config.yml
1411
BAZEL_BUILDTOOLS_VERSION = "49a6c199e3fbf5d94534b2771868677d3f9c6de9"
1512

1613
http_archive(

‎package.json‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
"version": "0.0.1",
44
"description": "Demo of bazel rules for angular",
55
"license": "Apache 2.0",
6+
"engines": {
7+
"node": ">=10.9.0 <11.0.0",
8+
"yarn": ">=1.9.2 <2.0.0"
9+
},
610
"dependencies": {
711
"@ngrx/store": "6.1.0",
812
"rxjs": "6.3.3",
@@ -19,6 +23,7 @@
1923
"@angular/common": "7.0.4",
2024
"@angular/core": "7.0.4",
2125
"@angular/material": "7.0.4",
26+
"@bazel/bazel": "^0.19.1",
2227
"@bazel/benchmark-runner": "0.1.0",
2328
"@bazel/ibazel": "0.5.0",
2429
"@bazel/karma": "0.20.3",
@@ -36,6 +41,7 @@
3641
"serve-prod": "bazel run //src:prodserver",
3742
"e2e": "bazel test //e2e:all",
3843
"test": "bazel test //src/...",
44+
"benchmark": "ibazel-benchmark-runner //src:devserver src/hello-world/hello-world.component.ts --url=http://localhost:5432",
3945
"postinstall": "ngc -p postinstall.tsconfig.json",
4046
"prebuildifier": "bazel build @com_github_bazelbuild_buildtools//buildifier",
4147
"//": "note: working around https://github.com/alexeagle/angular-bazel-example/issues/60",

‎yarn.lock‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,30 @@
7373
dependencies:
7474
tslib "^1.7.1"
7575

76+
"@bazel/bazel-darwin_x64@0.19.1":
77+
version "0.19.1"
78+
resolved "https://registry.yarnpkg.com/@bazel/bazel-darwin_x64/-/bazel-darwin_x64-0.19.1.tgz#58d779c8938bd1c136cab55e2f6473121f83741b"
79+
integrity sha512-Rnk8zw5S9SZfuMQsGRodm7ZXme1FS2rpmYbIJVF0M+k7jaWLZJwV2w5T2vMyuluEjOxTbptXenbigTF80jETIA==
80+
81+
"@bazel/bazel-linux_x64@0.19.1":
82+
version "0.19.1"
83+
resolved "https://registry.yarnpkg.com/@bazel/bazel-linux_x64/-/bazel-linux_x64-0.19.1.tgz#aef363e0932d29d1bb48980da139d74bfb4b1ffb"
84+
integrity sha512-dWKKYa0cwDEjVRRwUMVSy1WvQjTHQPiwrA6mDzNzoRX0D0KBX25QqdkQW6HS6fzyEOsFjT+yVtfqtxL0qO+FCA==
85+
86+
"@bazel/bazel-win32_x64@0.19.1":
87+
version "0.19.1"
88+
resolved "https://registry.yarnpkg.com/@bazel/bazel-win32_x64/-/bazel-win32_x64-0.19.1.tgz#273c43b0febc11675614c402ec82ae44b519f9ee"
89+
integrity sha512-t6vOh2IOzUAk19ccS0q3Kho364Yxjtjv1v4utAjOSNw8GVwutfekdiojGBrR8ihvJi1Xp885mOkQnZA38B9tvQ==
90+
91+
"@bazel/bazel@^0.19.1":
92+
version "0.19.1"
93+
resolved "https://registry.yarnpkg.com/@bazel/bazel/-/bazel-0.19.1.tgz#22ce225b5172a4ad2a94496be66b14b7c7facca2"
94+
integrity sha512-RGxp/Ny36ESzBG7l3yYG24yWfvjFyGE2VqNtXZdJfCfO5312zTNz0qRmZS8pNrCEN+F89jQDRvPhpdAyXKKwOg==
95+
optionalDependencies:
96+
"@bazel/bazel-darwin_x64" "0.19.1"
97+
"@bazel/bazel-linux_x64" "0.19.1"
98+
"@bazel/bazel-win32_x64" "0.19.1"
99+
76100
"@bazel/benchmark-runner@0.1.0":
77101
version "0.1.0"
78102
resolved "https://registry.yarnpkg.com/@bazel/benchmark-runner/-/benchmark-runner-0.1.0.tgz#a586394fcf7f2402b381319fbc2750627b5a06f1"

0 commit comments

Comments
 (0)