This document describes how to set up your development environment to build and test Angular.
It also explains the basic mechanics of using git
, node
, and npm
.
See the contribution guidelines if you'd like to contribute to Angular.
Before you can build and test Angular, you must install and configure the following products on your development machine:
-
Git and/or the GitHub app (for Mac or Windows); GitHub's Guide to Installing Git is a good source of information.
-
Node.js, (version specified in the engines field of
package.json
) which is used to run a development web server, run tests, and generate distributable files. -
Yarn (version specified in the engines field of
package.json
) which is used to install dependencies. -
Java Development Kit which is used to execute the selenium standalone server for e2e testing.
-
(Optional for now) Bazel, please follow instructions in BAZEL.md
Fork and clone the Angular repository:
- Login to your GitHub account or create one by following the instructions given here.
- Fork the main Angular repository.
- Clone your fork of the Angular repository and define an
upstream
remote pointing back to the Angular repository that you forked in the first place.
# Clone your GitHub repository:
git clone [email protected]:<github username>/angular.git
# Go to the Angular directory:
cd angular
# Add the main Angular repository as an upstream remote to your repository:
git remote add upstream https://github.com/angular/angular.git
Next, install the JavaScript modules needed to build and test Angular:
# Install Angular project dependencies (package.json)
yarn install
Optional: In this document, we make use of installed npm package scripts and binaries
(stored under ./node_modules/.bin
) by prefixing these command invocations with $(yarn bin)
; in
particular gulp
and protractor
commands.
In order to create the right symlinks, run as administrator:
./scripts/windows/create-symlinks.sh
Before submitting a PR, do not forget to remove them:
./scripts/windows/remove-symlinks.sh
To build Angular run:
./build.sh
- Results are put in the dist folder.
To run tests:
$ ./test.sh node # Run all angular tests on node
$ ./test.sh browser # Run all angular tests in browser
$ ./test.sh browserNoRouter # Optionally run all angular tests without router in browser
$ ./test.sh router # Optionally run only the router tests in browser
You should execute the 3 test suites before submitting a PR to github.
See DEBUG.md for information on debugging the code while running the unit tests.
All the tests are executed on our Continuous Integration infrastructure and a PR could only be merged once the tests pass.
- CircleCI fails if your code is not formatted properly,
- Travis CI fails if any of the test suites described above fails.
Angular uses clang-format to format the source code. If the source code is not properly formatted, the CI will fail and the PR can not be merged.
You can automatically format your code by running:
$ gulp format
There is a handy clang-format extension for Visual Studio Code. Use the following settings to format your code when you save a file:
{
"editor.formatOnSave": true,
"clang-format.executable": "${workspaceRoot}/node_modules/.bin/clang-format"
}
You can check that your code is properly formatted and adheres to coding style by running:
$ gulp lint
When a build of any branch on the upstream fork angular/angular is green on CircleCI,
it automatically publishes build artifacts
to repositories in the Angular org, eg. the @angular/core
package is published to
http://github.com/angular/core-builds.
You may find that your un-merged change needs some validation from external participants.
Rather than requiring them to pull your Pull Request and build Angular locally, you can
publish the *-builds
snapshots just like our Travis build does.
First time, you need to create the github repositories:
$ export TOKEN=[get one from https://github.com/settings/tokens]
$ CREATE_REPOS=1 TRAVIS= ./scripts/ci/publish-build-artifacts.sh [github username]
For subsequent snapshots, just run
$ ./scripts/publish/publish-build-artifacts.sh [github username]
The script will publish the build snapshot to a branch with the same name as your current branch, and create it if it doesn't exist.