Skip to content

Commit ac3f8c4

Browse files
devversionjelbourn
authored andcommitted
feat(schematics): support for ng add (#13319)
* Introduces support for `ng add @angular/cdk`. Note that this currently just sets up the `package.json` but is necessary because otherwise the CLI will complain about the `ng-add` schematic not being available. * Upgrades Bazel workspace rules in favor of removing Bazel manual-copying workarounds for the schematics. This also allows us to switch over to fine-grained dependencies in a follow-up (making it consistent with angular/angular). * Use fine grained dependencies in schematics bazel rules
1 parent 4e475f9 commit ac3f8c4

27 files changed

+778
-440
lines changed

.circleci/config.yml

+4-8
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,8 @@
77
# To validate changes, use an online parser, eg.
88
# http://yaml-online-parser.appspot.com/
99

10-
## IMPORTANT
11-
# If you change the `docker_image` version, also change the `cache_key` suffix and the version of
12-
# `com_github_bazelbuild_buildtools` in the `/WORKSPACE` file.
13-
var_1: &docker_image angular/ngcontainer:0.3.3
14-
var_2: &cache_key v2-ng-mat-{{ .Branch }}-{{ checksum "package-lock.json" }}-0.3.3
10+
var_1: &docker_image angular/ngcontainer:0.6.0
11+
var_2: &cache_key v2-ng-mat-{{ .Branch }}-{{ checksum "package-lock.json" }}-0.6.0
1512

1613
# Define common ENV vars
1714
var_3: &define_env_vars
@@ -48,9 +45,8 @@ jobs:
4845
- restore_cache:
4946
key: *cache_key
5047

51-
- run: bazel run @nodejs//:npm install
52-
# TODO(jelbourn): Update this command to run all tests if the Bazel issues have been fixed.
53-
- run: bazel test src/lib/schematics:unit_tests
48+
# TODO(jelbourn): Update this command to run all tests if the Bazel issues have been fixed.
49+
- run: bazel test src/{cdk,lib}/schematics:unit_tests
5450

5551
- save_cache:
5652
key: *cache_key

BUILD.bazel

+4-40
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,13 @@ package(default_visibility = ["//visibility:public"])
22

33
# TODO(jelbourn): figure out if these workarounds are still needed
44

5-
# This rule belongs in node_modules/BUILD
6-
# It's here as a workaround for
7-
# https://github.com/bazelbuild/bazel/issues/374#issuecomment-296217940
8-
filegroup(
5+
# TODO: Replace with fine-grained node_modules using `npm_install` / `yarn_install`.
6+
# TODO: See https://github.com/bazelbuild/rules_nodejs/wiki#migrating-to-rules_nodejs-013
7+
alias(
98
name = "node_modules",
10-
# Performance workaround: list individual files
11-
# Reduces the number of files as inputs to nodejs_binary:
12-
# bazel query "deps(:node_modules)" | wc -l
13-
# This won't scale in the general case.
14-
# TODO(alexeagle): figure out what to do
15-
srcs = glob(["/".join(["node_modules", pkg, "**", ext]) for pkg in [
16-
"@angular",
17-
"@angular-devkit",
18-
"@schematics",
19-
"@types",
20-
"bytebuffer",
21-
"hammerjs",
22-
"jasmine",
23-
"minimist",
24-
"moment",
25-
"parse5",
26-
"protobufjs",
27-
"protractor",
28-
"reflect-metadata",
29-
"rxjs",
30-
"tsickle",
31-
"tslib",
32-
"tslint",
33-
"typescript",
34-
"zone.js",
35-
] for ext in [
36-
"*.js",
37-
"*.json",
38-
"*.d.ts",
39-
]] + [
40-
"node_modules/http-server/**",
41-
# Reference all files of the "@schematics/angular" package because the schematic
42-
# tests depend on the template files of the angular schematics.
43-
"node_modules/@schematics/angular/**",
44-
]),
9+
actual = "@npm//:node_modules",
4510
)
4611

47-
4812
# Glob pattern that matches all Angular testing bundles.
4913
ANGULAR_TESTING = [
5014
"node_modules/@angular/*/bundles/*-testing.umd.js",

WORKSPACE

+32-30
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,52 @@
11
workspace(name = "angular_material")
22

3-
# Add nodejs rules
3+
# Load NodeJS rules. Note that this is technically not needed because
4+
# `rules_typescript_dependencies()` would also load the NodeJS rules, but we specifically need
5+
# at least v0.14.1 which includes: https://github.com/bazelbuild/rules_nodejs/pull/341
46
http_archive(
57
name = "build_bazel_rules_nodejs",
6-
url = "https://github.com/bazelbuild/rules_nodejs/archive/0.10.1.zip",
7-
strip_prefix = "rules_nodejs-0.10.1",
8-
sha256 = "634206524d90dc03c52392fa3f19a16637d2bcf154910436fe1d669a0d9d7b9c",
8+
url = "https://github.com/bazelbuild/rules_nodejs/archive/0.14.1.zip",
9+
strip_prefix = "rules_nodejs-0.14.1",
10+
sha256 = "813eb51733d3632f456f3bb581d940ed64e80dab417595c93bf5ad19079898e2"
911
)
1012

11-
# NOTE: this rule installs nodejs, npm, and yarn, but does NOT install
12-
# your npm dependencies. You must still run the package manager.
13-
load("@build_bazel_rules_nodejs//:defs.bzl", "check_bazel_version", "node_repositories")
13+
# Add TypeScript rules
14+
http_archive(
15+
name = "build_bazel_rules_typescript",
16+
url = "https://github.com/bazelbuild/rules_typescript/archive/0.18.0.zip",
17+
strip_prefix = "rules_typescript-0.18.0",
18+
sha256 = "4726e07a2f8d23b5e3af166f3b2a6e8aa75adad94b35ab4d959e8fe875f90272",
19+
)
1420

15-
check_bazel_version("0.15.0")
16-
node_repositories(package_json = ["//:package.json"])
21+
# Fetch transient dependencies of the TypeScript bazel rules.
22+
load("@build_bazel_rules_typescript//:package.bzl", "rules_typescript_dependencies")
23+
rules_typescript_dependencies()
1724

1825
# Add sass rules
1926
http_archive(
2027
name = "io_bazel_rules_sass",
21-
url = "https://github.com/bazelbuild/rules_sass/archive/0.1.0.zip",
22-
strip_prefix = "rules_sass-0.1.0",
23-
sha256 = "b243c4d64f054c174051785862ab079050d90b37a1cef7da93821c6981cb9ad4",
28+
url = "https://github.com/bazelbuild/rules_sass/archive/1.13.4.zip",
29+
strip_prefix = "rules_sass-1.13.4",
30+
sha256 = "5ddde0d3df96978fa537f76e766538c031dee4d29f91a895f4b1345b5e3f9b16",
2431
)
2532

2633
load("@io_bazel_rules_sass//sass:sass_repositories.bzl", "sass_repositories")
2734
sass_repositories()
2835

29-
# Add TypeScript rules
30-
http_archive(
31-
name = "build_bazel_rules_typescript",
32-
url = "https://github.com/bazelbuild/rules_typescript/archive/0.15.1.zip",
33-
strip_prefix = "rules_typescript-0.15.1",
34-
sha256 = "3792cc20ef13bb1d1d8b1760894c3320f02a87843e3a04fed7e8e454a75328b6",
35-
)
36+
# NOTE: this rule installs nodejs, npm, and yarn, but does NOT install
37+
# your npm dependencies. You must still run the package manager.
38+
load("@build_bazel_rules_nodejs//:defs.bzl", "check_bazel_version", "node_repositories",
39+
"npm_install")
3640

37-
http_archive(
38-
name = "io_bazel_rules_webtesting",
39-
url = "https://github.com/bazelbuild/rules_webtesting/archive/7ffe970bbf380891754487f66c3d680c087d67f2.zip",
40-
strip_prefix = "rules_webtesting-7ffe970bbf380891754487f66c3d680c087d67f2",
41-
sha256 = "4fb0dca8c9a90547891b7ef486592775a523330fc4555c88cd8f09270055c2ce",
41+
check_bazel_version("0.15.0")
42+
node_repositories()
43+
44+
# Use Bazel managed node modules. See more below:
45+
# https://github.com/bazelbuild/rules_nodejs#bazel-managed-vs-self-managed-dependencies
46+
npm_install(
47+
name = "npm",
48+
package_json = "//:package.json",
49+
package_lock_json = "//:package-lock.json",
4250
)
4351

4452
# Setup TypeScript Bazel workspace
@@ -56,9 +64,3 @@ local_repository(
5664
name = "rxjs",
5765
path = "node_modules/rxjs/src",
5866
)
59-
60-
61-
# This commit matches the version of buildifier in angular/ngcontainer
62-
# If you change this, also check if it matches the version in the angular/ngcontainer
63-
# version in /.circleci/config.yml
64-
BAZEL_BUILDTOOLS_VERSION = "82b21607e00913b16fe1c51bec80232d9d6de31c"

0 commit comments

Comments
 (0)