Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(bazel): Bazel workspace schematics #26971

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.
+553 −54
Diff settings

Always

Just for now

Copy path View file
@@ -1,7 +1,7 @@
.DS_STORE

/dist/
bazel-*
/bazel-*
e2e_test.*
node_modules
bower_components
Copy path View file
@@ -33,9 +33,10 @@
},
"// 1": "dependencies are used locally and by bazel",
"dependencies": {
"@angular-devkit/schematics": "^0.5.5",
"@angular-devkit/core": "^7.0.4",
"@angular-devkit/schematics": "^7.0.4",
"@bazel/typescript": "0.20.3",
"@schematics/angular": "^0.5.4",
"@schematics/angular": "^7.0.4",
"@types/chokidar": "1.7.3",
"@types/convert-source-map": "^1.5.1",
"@types/diff": "^3.2.2",
@@ -143,4 +144,4 @@
"vrsource-tslint-rules": "5.1.1",
"webpack": "1.12.9"
}
}
}
Copy path View file
@@ -7,6 +7,7 @@ npm_package(
"package.json",
"protractor-utils.js",
"//packages/bazel/src:package_assets",
"//packages/bazel/src/schematics:package_assets",
],
packages = [
"//packages/bazel/docs",
@@ -16,5 +17,6 @@ npm_package(
"//packages/bazel/src/ng_package:lib",
"//packages/bazel/src/ngc-wrapped:ngc_lib",
"//packages/bazel/src/protractor/utils",
"//packages/bazel/src/schematics/bazel-workspace",
],
)
Copy path View file
@@ -12,7 +12,10 @@
},
"typings": "./src/ngc-wrapped/index.d.ts",
"dependencies": {
"@angular-devkit/core": "^7.0.4",
"@angular-devkit/schematics": "^7.0.4",
"@bazel/typescript": "^0.20.3",
"@schematics/angular": "^7.0.4",
"@types/node": "6.0.84",
"shelljs": "0.8.2",
"tsickle": "0.32.1"
@@ -25,6 +28,7 @@
"type": "git",
"url": "https://github.com/angular/angular.git"
},
"schematics": "./src/schematics/collection.json",
"ng-update": {
"packageGroup": "NG_UPDATE_PACKAGE_GROUP"
},
@@ -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",
],
)
@@ -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
This conversation was marked as resolved by kyliau

This comment has been minimized.

Copy link
@alexeagle

alexeagle Nov 6, 2018

Contributor

should have a TODO to make the ts_json_schema rule re-usable and portable

This comment has been minimized.

Copy link
@kyliau

kyliau Nov 7, 2018

Author Member

done


```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).
@@ -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",
],
)
@@ -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",
])
@@ -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.
This conversation was marked as resolved by kyliau

This comment has been minimized.

Copy link
@alexeagle

alexeagle Nov 6, 2018

Contributor

Needs a comment about how this is generated code and not meant to be edited unless you've learned Bazel

# 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()
@@ -0,0 +1,2 @@
dist
node_modules
@@ -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
@@ -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",
)
@@ -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.
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.