forked from angular/angular
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(bazel): Bazel workspace schematics (angular#26971)
This commit creates a schematics for Bazel workspace. PR Close angular#26971
- Loading branch information
Showing
21 changed files
with
553 additions
and
54 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
.DS_STORE | ||
|
||
/dist/ | ||
bazel-* | ||
/bazel-* | ||
e2e_test.* | ||
node_modules | ||
bower_components | ||
|
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
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,20 @@ | ||
package(default_visibility = ["//visibility:public"]) | ||
|
||
filegroup( | ||
name = "package_assets", | ||
srcs = [ | ||
"collection.json", | ||
], | ||
visibility = ["//packages/bazel:__subpackages__"], | ||
) | ||
|
||
load("//tools:defaults.bzl", "jasmine_node_test", "ts_library") | ||
|
||
jasmine_node_test( | ||
name = "test", | ||
bootstrap = ["angular/tools/testing/init_node_spec.js"], | ||
deps = [ | ||
"//packages/bazel/src/schematics/bazel-workspace:test", | ||
"//tools/testing: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,32 @@ | ||
# Schematics for Bazel | ||
|
||
## Development notes | ||
|
||
To test any local changes, run | ||
|
||
```shell | ||
bazel build //packages/bazel:npm_package | ||
``` | ||
|
||
then `cd` to the npm package in the `dist` folder and run `yarn link`. | ||
Next run `yarn link` again in the directory where the `ng` command is invoked. | ||
Make sure the `ng` command is local, and not the global installation. | ||
|
||
## Generate .d.ts file from JSON schema | ||
|
||
The script to generate `.d.ts` file is located in the | ||
[Angular CLI](https://github.com/angular/angular-cli) repo. Make sure | ||
the CLI repository is checked out on your local machine. | ||
|
||
Then, in the CLI repository, run the following command | ||
|
||
```shell | ||
bazel run //tools:quicktype_runner -- \ | ||
~/Documents/GitHub/angular/packages/bazel/src/schematics/ng-new/schema.json \ | ||
~/Documents/GitHub/angular/packages/bazel/src/schematics/ng-new/schema.d.ts | ||
``` | ||
|
||
## TODOs | ||
|
||
1. Make the `ts_json_schema` rule re-usable and portable. | ||
2. Add comments in BUILD files. See discussion [here](https://github.com/angular/angular/pull/26971#discussion_r231325683). |
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 @@ | ||
package(default_visibility = ["//visibility:public"]) | ||
|
||
load("//tools:defaults.bzl", "ts_library") | ||
|
||
ts_library( | ||
name = "bazel-workspace", | ||
srcs = [ | ||
"index.ts", | ||
"schema.d.ts", | ||
], | ||
data = glob(["files/**/*"]) + [ | ||
"schema.json", | ||
], | ||
deps = [ | ||
"@ngdeps//@angular-devkit/core", | ||
"@ngdeps//@angular-devkit/schematics", | ||
"@ngdeps//@schematics/angular", | ||
], | ||
) | ||
|
||
ts_library( | ||
name = "test", | ||
testonly = True, | ||
srcs = [ | ||
"index_spec.ts", | ||
], | ||
data = [ | ||
"//packages/bazel/src/schematics:package_assets", | ||
], | ||
deps = [ | ||
":bazel-workspace", | ||
"@ngdeps//@angular-devkit/schematics", | ||
], | ||
) |
7 changes: 7 additions & 0 deletions
7
packages/bazel/src/schematics/bazel-workspace/files/BUILD.bazel.template
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 @@ | ||
package(default_visibility = ["//visibility:public"]) | ||
|
||
# This export allows targets in other packages to reference files that live | ||
# in this package. | ||
exports_files([ | ||
"tsconfig.json", | ||
]) |
76 changes: 76 additions & 0 deletions
76
packages/bazel/src/schematics/bazel-workspace/files/WORKSPACE.template
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,76 @@ | ||
# WARNING: This file is generated and it's not meant to be edited. | ||
# Before making any changes, please read Bazel documentation. | ||
# https://docs.bazel.build/versions/master/be/workspace.html | ||
# The WORKSPACE file tells Bazel that this directory is a "workspace", which is like a project root. | ||
# The content of this file specifies all the external dependencies Bazel needs to perform a build. | ||
|
||
#################################### | ||
# ESModule imports (and TypeScript imports) can be absolute starting with the workspace name. | ||
# The name of the workspace should match the npm package where we publish, so that these | ||
# imports also make sense when referencing the published package. | ||
workspace(name = "<%= utils.underscore(name) %>") | ||
|
||
# The @angular repo contains rule for building Angular applications | ||
# Provides "build_bazel_rules_typescript" | ||
ANGULAR_VERSION = "<%= ANGULAR_VERSION %>" | ||
http_archive( | ||
name = "angular", | ||
url = "https://github.com/angular/angular/archive/%s.zip" % ANGULAR_VERSION, | ||
strip_prefix = "angular-%s" % ANGULAR_VERSION, | ||
) | ||
|
||
# RxJS | ||
RXJS_VERSION = "<%= RXJS_VERSION %>" | ||
http_archive( | ||
name = "rxjs", | ||
url = "https://registry.yarnpkg.com/rxjs/-/rxjs-%s.tgz" % RXJS_VERSION, | ||
strip_prefix = "package/src", | ||
) | ||
|
||
# Rules for compiling sass | ||
RULES_SASS_VERSION = "<%= RULES_SASS_VERSION %>" | ||
http_archive( | ||
name = "io_bazel_rules_sass", | ||
url = "https://github.com/bazelbuild/rules_sass/archive/%s.zip" % RULES_SASS_VERSION, | ||
strip_prefix = "rules_sass-%s" % RULES_SASS_VERSION, | ||
) | ||
|
||
#################################### | ||
# Load and install our dependencies downloaded above. | ||
|
||
load("@angular//packages/bazel:package.bzl", "rules_angular_dependencies") | ||
rules_angular_dependencies() | ||
|
||
load("@build_bazel_rules_typescript//:package.bzl", "rules_typescript_dependencies") | ||
rules_typescript_dependencies() | ||
# build_bazel_rules_nodejs is loaded transitively through rules_typescript_dependencies. | ||
|
||
load("@build_bazel_rules_nodejs//:defs.bzl", "check_bazel_version", "node_repositories", "yarn_install") | ||
# 0.18.0 is needed for .bazelignore | ||
check_bazel_version("0.18.0") | ||
node_repositories() | ||
yarn_install( | ||
name = "npm", | ||
package_json = "//:package.json", | ||
yarn_lock = "//:yarn.lock", | ||
) | ||
|
||
load("@io_bazel_rules_go//go:def.bzl", "go_rules_dependencies", "go_register_toolchains") | ||
go_rules_dependencies() | ||
go_register_toolchains() | ||
|
||
load("@io_bazel_rules_webtesting//web:repositories.bzl", "browser_repositories", "web_test_repositories") | ||
web_test_repositories() | ||
browser_repositories( | ||
chromium = True, | ||
firefox = True, | ||
) | ||
|
||
load("@build_bazel_rules_typescript//:defs.bzl", "ts_setup_workspace", "check_rules_typescript_version") | ||
ts_setup_workspace() | ||
|
||
load("@io_bazel_rules_sass//sass:sass_repositories.bzl", "sass_repositories") | ||
sass_repositories() | ||
|
||
load("@angular//:index.bzl", "ng_setup_workspace") | ||
ng_setup_workspace() |
2 changes: 2 additions & 0 deletions
2
packages/bazel/src/schematics/bazel-workspace/files/__dot__bazelignore.template
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,2 @@ | ||
dist | ||
node_modules |
19 changes: 19 additions & 0 deletions
19
packages/bazel/src/schematics/bazel-workspace/files/__dot__bazelrc.template
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,19 @@ | ||
# Make TypeScript and Angular compilation fast, by keeping a few copies of the | ||
# compiler running as daemons, and cache SourceFile AST's to reduce parse time. | ||
build --strategy=TypeScriptCompile=worker | ||
build --strategy=AngularTemplateCompile=worker | ||
|
||
# Don't create bazel-* symlinks in the WORKSPACE directory, except `bazel-out`, | ||
# which is mandatory. | ||
# These require .gitignore and may scare users. | ||
# Also, it's a workaround for https://github.com/bazelbuild/rules_typescript/issues/12 | ||
# which affects the common case of having `tsconfig.json` in the WORKSPACE directory. | ||
# | ||
# Instead, the output will appear in `dist/bin`. You'll need to ignore the | ||
# `bazel-out` directory that is created in the workspace root. | ||
build --symlink_prefix=dist/ | ||
|
||
test --test_output=errors | ||
|
||
# Use the Angular 6 compiler | ||
build --define=compile=legacy |
46 changes: 46 additions & 0 deletions
46
packages/bazel/src/schematics/bazel-workspace/files/e2e/BUILD.bazel.template
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,46 @@ | ||
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library") | ||
load("@angular//:index.bzl", "protractor_web_test_suite") | ||
|
||
ts_library( | ||
name = "e2e_lib", | ||
testonly = 1, | ||
srcs = glob(["src/**/*.ts"]), | ||
tsconfig = ":tsconfig.e2e.json", | ||
deps = [ | ||
"@npm//@types/jasmine", | ||
"@npm//@types/jasminewd2", | ||
"@npm//@types/node", | ||
"@npm//jasmine", | ||
"@npm//protractor", | ||
] | ||
) | ||
|
||
protractor_web_test_suite( | ||
name = "prodserver_test", | ||
data = [ | ||
"@angular//packages/bazel/src/protractor/utils", | ||
"@npm//protractor", | ||
], | ||
on_prepare = ":protractor.on-prepare.js", | ||
server = "//src:prodserver", | ||
deps = [":e2e_lib"], | ||
) | ||
|
||
protractor_web_test_suite( | ||
name = "devserver_test", | ||
data = [ | ||
"@angular//packages/bazel/src/protractor/utils", | ||
"@npm//protractor", | ||
], | ||
on_prepare = ":protractor.on-prepare.js", | ||
server = "//src:devserver", | ||
deps = [":e2e_lib"], | ||
) | ||
|
||
# Default target in this package is to run the e2e tests on the devserver. | ||
# This is a faster round-trip but doesn't exercise production optimizations like | ||
# code-splitting and lazy loading. | ||
alias( | ||
name = "e2e", | ||
actual = "devserver_test", | ||
) |
23 changes: 23 additions & 0 deletions
23
packages/bazel/src/schematics/bazel-workspace/files/e2e/protractor.on-prepare.js.template
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 @@ | ||
// The function exported from this file is used by the protractor_web_test_suite. | ||
// It is passed to the `onPrepare` configuration setting in protractor and executed | ||
// before running tests. | ||
// | ||
// If the function returns a promise, as it does here, protractor will wait | ||
// for the promise to resolve before running tests. | ||
|
||
const protractorUtils = require('@angular/bazel/protractor-utils'); | ||
const protractor = require('protractor'); | ||
|
||
module.exports = function(config) { | ||
// In this example, `@angular/bazel/protractor-utils` is used to run | ||
// the server. protractorUtils.runServer() runs the server on a randomly | ||
// selected port (given a port flag to pass to the server as an argument). | ||
// The port used is returned in serverSpec and the protractor serverUrl | ||
// is the configured. | ||
const portFlag = config.server.endsWith('prodserver') ? '-p' : '-port'; | ||
return protractorUtils.runServer(config.workspace, config.server, portFlag, []) | ||
.then(serverSpec => { | ||
const serverUrl = `http://localhost:${serverSpec.port}`; | ||
protractor.browser.baseUrl = serverUrl; | ||
}); | ||
}; |
Oops, something went wrong.