From 282736f8bed6be539826dfb7f89d63e660cc1eca Mon Sep 17 00:00:00 2001 From: Paul Gschwendtner Date: Thu, 11 Oct 2018 19:00:40 +0200 Subject: [PATCH] build: build cdk with angular from source (#13541) * build: build cdk with angular from source * Continues the long-term Bazel goal by fixing the CDK bazel build targets. Also builds the CDK targets with Angular from source. Follow up's will try to make serving, and testing possible. * Build package on CI * No longer compile with AOT compiler that generates factory files that cannot be packaged into "ng_package" --- .circleci/config.yml | 1 + BUILD.bazel | 9 ---- WORKSPACE | 49 +++++++++++++------ package.json | 1 - src/cdk/BUILD.bazel | 11 +++-- src/cdk/a11y/BUILD.bazel | 9 ++-- src/cdk/accordion/BUILD.bazel | 7 +-- src/cdk/bidi/BUILD.bazel | 14 +++--- src/cdk/coercion/BUILD.bazel | 8 ++- src/cdk/collections/BUILD.bazel | 9 ++-- src/cdk/drag-drop/BUILD.bazel | 7 ++- src/cdk/keycodes/BUILD.bazel | 7 ++- src/cdk/layout/BUILD.bazel | 8 +-- src/cdk/observers/BUILD.bazel | 6 ++- src/cdk/overlay/BUILD.bazel | 8 ++- src/cdk/platform/BUILD.bazel | 8 ++- src/cdk/portal/BUILD.bazel | 13 +++-- src/cdk/schematics/BUILD.bazel | 32 ++++++------ src/cdk/scrolling/BUILD.bazel | 8 +-- src/cdk/stepper/BUILD.bazel | 9 +++- src/cdk/table/BUILD.bazel | 9 ++-- src/cdk/testing/BUILD.bazel | 9 ++-- ...tsconfig-test.json => tsconfig-bazel.json} | 3 +- src/cdk/text-field/BUILD.bazel | 5 +- src/cdk/tree/BUILD.bazel | 9 ++-- src/cdk/tsconfig-build.json | 2 +- src/lib/schematics/BUILD.bazel | 24 ++++----- tools/BUILD.bazel | 9 +++- tools/bazel.rc | 4 ++ tools/defaults.bzl | 21 +++++++- yarn.lock | 42 +--------------- 31 files changed, 199 insertions(+), 162 deletions(-) rename src/cdk/testing/{tsconfig-test.json => tsconfig-bazel.json} (69%) diff --git a/.circleci/config.yml b/.circleci/config.yml index a839ad3826d..7f52e0ebad3 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -48,6 +48,7 @@ jobs: - run: sudo cp ./.circleci/bazel.rc /etc/bazel.bazelrc # TODO(jelbourn): Update this command to run all tests if the Bazel issues have been fixed. + - run: bazel build src/cdk:npm_package - run: bazel test src/{cdk,lib}/schematics:unit_tests - save_cache: diff --git a/BUILD.bazel b/BUILD.bazel index 7f3223bc971..c32432ab79f 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -1,14 +1,5 @@ package(default_visibility = ["//visibility:public"]) -# TODO(jelbourn): figure out if these workarounds are still needed - -# TODO: Replace with fine-grained node_modules using `npm_install` / `yarn_install`. -# TODO: See https://github.com/bazelbuild/rules_nodejs/wiki#migrating-to-rules_nodejs-013 -alias( - name = "node_modules", - actual = "@npm//:node_modules", -) - # Glob pattern that matches all Angular testing bundles. ANGULAR_TESTING = [ "node_modules/@angular/*/bundles/*-testing.umd.js", diff --git a/WORKSPACE b/WORKSPACE index 9a274007701..024147bd0ae 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -3,17 +3,17 @@ workspace(name = "angular_material") # Add NodeJS rules (explicitly used for sass bundle rules) http_archive( name = "build_bazel_rules_nodejs", - url = "https://github.com/bazelbuild/rules_nodejs/archive/0.14.2.zip", - strip_prefix = "rules_nodejs-0.14.2", - sha256 = "af481421c9e74f754a693a8bf5e9409484e38cf7be6f73f85879bdc7ed1b1d82", + url = "https://github.com/bazelbuild/rules_nodejs/archive/0.15.0.zip", + strip_prefix = "rules_nodejs-0.15.0", + sha256 = "5f5b6464ca20aa63d278caaf4736f0381eb838800d7375132057a48f09d0b837", ) # Add TypeScript rules http_archive( name = "build_bazel_rules_typescript", - url = "https://github.com/bazelbuild/rules_typescript/archive/0.19.1.zip", - strip_prefix = "rules_typescript-0.19.1", - sha256 = "91a03623a03a463ffd62cea3f7a384c2f298af6438d5d153fc4d69aa5665b53d", + url = "https://github.com/bazelbuild/rules_typescript/archive/0.20.2.zip", + strip_prefix = "rules_typescript-0.20.2", + sha256 = "2879fbd7168ba5d17db22bc2f585c0d1d3a82dd5e6f8af118e8b2f74d290024e", ) # Fetch transient dependencies of the TypeScript bazel rules. @@ -31,6 +31,27 @@ http_archive( load("@io_bazel_rules_sass//sass:sass_repositories.bzl", "sass_repositories") sass_repositories() +# Add Angular source and Bazel rules. +http_archive( + name = "angular", + # Temporarily locked down to the angular/angular:bazel branch. This branch includes necessary + # commits that make building from source possible. + # TODO(devversion): switch to release archive if workaround can be removed + url = "https://github.com/angular/angular/archive/08e4489cf5a93a352954f1639da5e92112993753.zip", + strip_prefix = "angular-08e4489cf5a93a352954f1639da5e92112993753", + sha256 = "a59c85426048cc95f51937d0c26f4d1143b7bef730152b68ac4b79d1438e746b", +) + +# Add RxJS as repository because those are needed in order to build Angular from source. +# Also we cannot refer to the RxJS version from the node modules because self-managed +# node modules are not guaranteed to be installed. +http_archive( + name = "rxjs", + url = "https://registry.yarnpkg.com/rxjs/-/rxjs-6.3.3.tgz", + strip_prefix = "package/src", + sha256 = "72b0b4e517f43358f554c125e40e39f67688cd2738a8998b4a266981ed32f403", +) + # NOTE: this rule installs nodejs, npm, and yarn, but does NOT install # your npm dependencies. You must still run the package manager. load("@build_bazel_rules_nodejs//:defs.bzl", "node_repositories", "yarn_install") @@ -54,14 +75,10 @@ yarn_install( load("@build_bazel_rules_typescript//:defs.bzl", "ts_setup_workspace") ts_setup_workspace() -# Add Angular rules -local_repository( - name = "angular", - path = "node_modules/@angular/bazel", -) +# Setup Angular bazel rules +load("@angular//packages/bazel:package.bzl", "rules_angular_dependencies") +rules_angular_dependencies() -# Add rxjs -local_repository( - name = "rxjs", - path = "node_modules/rxjs/src", -) +# Setup Angular workspace for building (Bazel managed node modules) +load("@angular//:index.bzl", "ng_setup_workspace") +ng_setup_workspace() diff --git a/package.json b/package.json index e1802f09aef..7d9caf6c28c 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,6 @@ "devDependencies": { "@angular-devkit/core": "7.0.0-rc.1", "@angular-devkit/schematics": "7.0.0-rc.1", - "@angular/bazel": "7.0.0-rc.0", "@angular/compiler-cli": "7.0.0-rc.0", "@angular/http": "7.0.0-rc.0", "@angular/platform-browser-dynamic": "7.0.0-rc.0", diff --git a/src/cdk/BUILD.bazel b/src/cdk/BUILD.bazel index 28a52976895..88a0304ea34 100644 --- a/src/cdk/BUILD.bazel +++ b/src/cdk/BUILD.bazel @@ -1,18 +1,21 @@ package(default_visibility=["//visibility:public"]) -load("@build_bazel_rules_typescript//:defs.bzl", "ts_library") + load("@angular//:index.bzl", "ng_package") load("//:packages.bzl", "CDK_TARGETS", "ROLLUP_GLOBALS", "VERSION_PLACEHOLDER_REPLACEMENTS") +load("//tools:defaults.bzl", "ng_module") # Export the CDK tsconfig so that subpackages can reference it directly. exports_files(["tsconfig-build.json"]) # Root "@angular/cdk" entry-point that does not re-export individual entry-points. -ts_library( +ng_module( name = "cdk", srcs = glob(["*.ts"], exclude=["**/*.spec.ts"]), module_name = "@angular/cdk", - deps = [], - tsconfig = "//src/lib:tsconfig-build.json", + deps = [ + "@angular//packages/core", + ], + tsconfig = ":tsconfig-build.json", ) # Creates the @angular/cdk package published to npm. diff --git a/src/cdk/a11y/BUILD.bazel b/src/cdk/a11y/BUILD.bazel index 3fbd6d99317..64318165bc4 100644 --- a/src/cdk/a11y/BUILD.bazel +++ b/src/cdk/a11y/BUILD.bazel @@ -1,19 +1,22 @@ package(default_visibility=["//visibility:public"]) -load("@angular//:index.bzl", "ng_module") + load("@io_bazel_rules_sass//sass:sass.bzl", "sass_library") load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test") - +load("//tools:defaults.bzl", "ng_module") ng_module( name = "a11y", srcs = glob(["**/*.ts"], exclude=["**/*.spec.ts"]), module_name = "@angular/cdk/a11y", deps = [ + "@angular//packages/common", + "@angular//packages/core", + "@rxjs", + "@rxjs//operators", "//src/cdk/coercion", "//src/cdk/keycodes", "//src/cdk/observers", "//src/cdk/platform", - "@rxjs", ], tsconfig = "//src/cdk:tsconfig-build.json", ) diff --git a/src/cdk/accordion/BUILD.bazel b/src/cdk/accordion/BUILD.bazel index a2878104d48..1c09cd88d7f 100644 --- a/src/cdk/accordion/BUILD.bazel +++ b/src/cdk/accordion/BUILD.bazel @@ -1,16 +1,17 @@ package(default_visibility=["//visibility:public"]) -load("@angular//:index.bzl", "ng_module") -load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test") +load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test") +load("//tools:defaults.bzl", "ng_module") ng_module( name = "accordion", srcs = glob(["**/*.ts"], exclude=["**/*.spec.ts"]), module_name = "@angular/cdk/accordion", deps = [ + "@angular//packages/core", + "@rxjs", "//src/cdk/coercion", "//src/cdk/collections", - "@rxjs", ], tsconfig = "//src/cdk:tsconfig-build.json", ) diff --git a/src/cdk/bidi/BUILD.bazel b/src/cdk/bidi/BUILD.bazel index 70f5572456f..7a109abc162 100644 --- a/src/cdk/bidi/BUILD.bazel +++ b/src/cdk/bidi/BUILD.bazel @@ -1,13 +1,16 @@ package(default_visibility=["//visibility:public"]) -load("@angular//:index.bzl", "ng_module") -load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test") +load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test") +load("//tools:defaults.bzl", "ng_module") ng_module( name = "bidi", srcs = glob(["**/*.ts"], exclude=["**/*.spec.ts"]), module_name = "@angular/cdk/bidi", - deps = ["@rxjs"], + deps = [ + "@angular//packages/common", + "@angular//packages/core", + ], tsconfig = "//src/cdk:tsconfig-build.json", ) @@ -15,10 +18,7 @@ ts_library( name = "bidi_test_sources", testonly = 1, srcs = glob(["**/*.spec.ts"]), - deps = [ - ":bidi", - "@rxjs", - ], + deps = [":bidi"], tsconfig = "//src/cdk:tsconfig-build.json", ) diff --git a/src/cdk/coercion/BUILD.bazel b/src/cdk/coercion/BUILD.bazel index a78f31f94ef..c3d848439b2 100644 --- a/src/cdk/coercion/BUILD.bazel +++ b/src/cdk/coercion/BUILD.bazel @@ -1,14 +1,12 @@ package(default_visibility=["//visibility:public"]) -load("@build_bazel_rules_typescript//:defs.bzl", "ts_library") + load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test") -load("@angular//:index.bzl", "ng_module") - -ng_module( +ts_library( name = "coercion", srcs = glob(["**/*.ts"], exclude=["**/*.spec.ts"]), module_name = "@angular/cdk/coercion", - deps = ["@rxjs"], + deps = ["@npm//tslib"], tsconfig = "//src/cdk:tsconfig-build.json", ) diff --git a/src/cdk/collections/BUILD.bazel b/src/cdk/collections/BUILD.bazel index c6339ee5842..23f87262424 100644 --- a/src/cdk/collections/BUILD.bazel +++ b/src/cdk/collections/BUILD.bazel @@ -1,13 +1,16 @@ package(default_visibility=["//visibility:public"]) -load("@angular//:index.bzl", "ng_module") -load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test") +load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test") +load("//tools:defaults.bzl", "ng_module") ng_module( name = "collections", srcs = glob(["**/*.ts"], exclude=["**/*.spec.ts"]), module_name = "@angular/cdk/collections", - deps = ["@rxjs"], + deps = [ + "@angular//packages/core", + "@rxjs" + ], tsconfig = "//src/cdk:tsconfig-build.json", ) diff --git a/src/cdk/drag-drop/BUILD.bazel b/src/cdk/drag-drop/BUILD.bazel index 1df5fffa8dd..30b5e49238f 100644 --- a/src/cdk/drag-drop/BUILD.bazel +++ b/src/cdk/drag-drop/BUILD.bazel @@ -1,15 +1,18 @@ package(default_visibility=["//visibility:public"]) -load("@angular//:index.bzl", "ng_module") + load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test") load("@io_bazel_rules_sass//sass:sass.bzl", "sass_binary") - +load("//tools:defaults.bzl", "ng_module") ng_module( name = "drag-drop", srcs = glob(["**/*.ts"], exclude=["**/*.spec.ts"]), module_name = "@angular/cdk/drag-drop", deps = [ + "@angular//packages/common", + "@angular//packages/core", "@rxjs", + "@rxjs//operators", "//src/cdk/platform", "//src/cdk/overlay", "//src/cdk/bidi", diff --git a/src/cdk/keycodes/BUILD.bazel b/src/cdk/keycodes/BUILD.bazel index dc89a13e67e..f62749f5f0c 100644 --- a/src/cdk/keycodes/BUILD.bazel +++ b/src/cdk/keycodes/BUILD.bazel @@ -1,12 +1,11 @@ package(default_visibility=["//visibility:public"]) + load("@build_bazel_rules_typescript//:defs.bzl", "ts_library") -load("@angular//:index.bzl", "ng_module") - -ng_module( +ts_library( name = "keycodes", srcs = glob(["**/*.ts"], exclude=["**/*.spec.ts"]), module_name = "@angular/cdk/keycodes", - deps = ["@rxjs"], + deps = ["@npm//tslib"], tsconfig = "//src/cdk:tsconfig-build.json", ) diff --git a/src/cdk/layout/BUILD.bazel b/src/cdk/layout/BUILD.bazel index 742dc9a049a..8ad0533177d 100644 --- a/src/cdk/layout/BUILD.bazel +++ b/src/cdk/layout/BUILD.bazel @@ -1,16 +1,18 @@ package(default_visibility=["//visibility:public"]) -load("@angular//:index.bzl", "ng_module") -load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test") +load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test") +load("//tools:defaults.bzl", "ng_module") ng_module( name = "layout", srcs = glob(["**/*.ts"], exclude=["**/*.spec.ts"]), module_name = "@angular/cdk/layout", deps = [ + "@angular//packages/core", + "@rxjs", + "@rxjs//operators", "//src/cdk/coercion", "//src/cdk/platform", - "@rxjs", ], tsconfig = "//src/cdk:tsconfig-build.json", ) diff --git a/src/cdk/observers/BUILD.bazel b/src/cdk/observers/BUILD.bazel index 58345024422..f98c4b1ddd5 100644 --- a/src/cdk/observers/BUILD.bazel +++ b/src/cdk/observers/BUILD.bazel @@ -1,14 +1,16 @@ package(default_visibility=["//visibility:public"]) -load("@angular//:index.bzl", "ng_module") -load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test") +load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test") +load("//tools:defaults.bzl", "ng_module") ng_module( name = "observers", srcs = glob(["**/*.ts"], exclude=["**/*.spec.ts"]), module_name = "@angular/cdk/observers", deps = [ + "@angular//packages/core", "@rxjs", + "@rxjs//operators", "//src/cdk/coercion", ], tsconfig = "//src/cdk:tsconfig-build.json", diff --git a/src/cdk/overlay/BUILD.bazel b/src/cdk/overlay/BUILD.bazel index 46a4ed714f3..6f4111a212b 100644 --- a/src/cdk/overlay/BUILD.bazel +++ b/src/cdk/overlay/BUILD.bazel @@ -1,20 +1,24 @@ package(default_visibility=["//visibility:public"]) -load("@angular//:index.bzl", "ng_module") + load("@io_bazel_rules_sass//sass:sass.bzl", "sass_library") load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test") +load("//tools:defaults.bzl", "ng_module") ng_module( name = "overlay", srcs = glob(["**/*.ts"], exclude=["**/*.spec.ts"]), module_name = "@angular/cdk/overlay", deps = [ + "@angular//packages/common", + "@angular//packages/core", + "@rxjs", + "@rxjs//operators", "//src/cdk/bidi", "//src/cdk/coercion", "//src/cdk/keycodes", "//src/cdk/platform", "//src/cdk/portal", "//src/cdk/scrolling", - "@rxjs", ], tsconfig = "//src/cdk:tsconfig-build.json", ) diff --git a/src/cdk/platform/BUILD.bazel b/src/cdk/platform/BUILD.bazel index 095c02204dc..fb1b8176ea4 100644 --- a/src/cdk/platform/BUILD.bazel +++ b/src/cdk/platform/BUILD.bazel @@ -1,10 +1,14 @@ package(default_visibility=["//visibility:public"]) -load("@angular//:index.bzl", "ng_module") + +load("//tools:defaults.bzl", "ng_module") ng_module( name = "platform", srcs = glob(["**/*.ts"], exclude=["**/*.spec.ts"]), module_name = "@angular/cdk/platform", - deps = ["@rxjs"], + deps = [ + "@angular//packages/common", + "@angular//packages/core", + ], tsconfig = "//src/cdk:tsconfig-build.json", ) diff --git a/src/cdk/portal/BUILD.bazel b/src/cdk/portal/BUILD.bazel index 1bb6f2bd7ea..ae2b09363b3 100644 --- a/src/cdk/portal/BUILD.bazel +++ b/src/cdk/portal/BUILD.bazel @@ -1,13 +1,15 @@ package(default_visibility=["//visibility:public"]) -load("@angular//:index.bzl", "ng_module") -load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test") +load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test") +load("//tools:defaults.bzl", "ng_module") ng_module( name = "portal", srcs = glob(["**/*.ts"], exclude=["**/*.spec.ts"]), module_name = "@angular/cdk/portal", - deps = ["@rxjs"], + deps = [ + "@angular//packages/core", + ], tsconfig = "//src/cdk:tsconfig-build.json", ) @@ -15,10 +17,7 @@ ts_library( name = "portal_test_sources", testonly = 1, srcs = glob(["**/*.spec.ts"]), - deps = [ - ":portal", - "@rxjs", - ], + deps = [":portal"], tsconfig = "//src/cdk:tsconfig-build.json", ) diff --git a/src/cdk/schematics/BUILD.bazel b/src/cdk/schematics/BUILD.bazel index 19f23f59478..8e5c8b90172 100644 --- a/src/cdk/schematics/BUILD.bazel +++ b/src/cdk/schematics/BUILD.bazel @@ -19,16 +19,16 @@ ts_library( srcs = glob(["**/*.ts"], exclude=["**/files/**/*.ts", "**/*.spec.ts"]), tsconfig = ":tsconfig.json", deps = [ - "@npm//:@schematics/angular", - "@npm//:@angular-devkit/schematics", + "@npm//@schematics/angular", + "@npm//@angular-devkit/schematics", # TODO(devversion): Only include jasmine for test sources (See: tsconfig types). - "@npm//:@types/jasmine", - "@npm//:@types/node", - "@npm//:glob", - "@npm//:parse5", - "@npm//:rxjs", - "@npm//:tslint", - "@npm//:typescript" + "@npm//@types/jasmine", + "@npm//@types/node", + "@npm//glob", + "@npm//parse5", + "@npm//rxjs", + "@npm//tslint", + "@npm//typescript" ], ) @@ -53,13 +53,13 @@ ts_library( srcs = glob(["**/*.spec.ts"], exclude = ["**/files/**/*.spec.ts"]), deps = [ ":schematics", - "@npm//:@schematics/angular", - "@npm//:@angular-devkit/schematics", - "@npm//:@types/jasmine", - "@npm//:@types/node", - "@npm//:mock-fs", - "@npm//:tslint", - "@npm//:typescript", + "@npm//@schematics/angular", + "@npm//@angular-devkit/schematics", + "@npm//@types/jasmine", + "@npm//@types/node", + "@npm//mock-fs", + "@npm//tslint", + "@npm//typescript", ], tsconfig = ":tsconfig.json", testonly = True, diff --git a/src/cdk/scrolling/BUILD.bazel b/src/cdk/scrolling/BUILD.bazel index 84a8315e447..cf14dcca06f 100644 --- a/src/cdk/scrolling/BUILD.bazel +++ b/src/cdk/scrolling/BUILD.bazel @@ -1,8 +1,8 @@ package(default_visibility=["//visibility:public"]) -load("@angular//:index.bzl", "ng_module") + load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test") load("@io_bazel_rules_sass//sass:sass.bzl", "sass_binary") - +load("//tools:defaults.bzl", "ng_module") ng_module( name = "scrolling", @@ -10,11 +10,13 @@ ng_module( module_name = "@angular/cdk/scrolling", assets = [":virtual-scroll-viewport.css"] + glob(["**/*.html"]), deps = [ + "@angular//packages/core", + "@rxjs", + "@rxjs//operators", "//src/cdk/bidi", "//src/cdk/coercion", "//src/cdk/collections", "//src/cdk/platform", - "@rxjs", ], tsconfig = "//src/cdk:tsconfig-build.json", ) diff --git a/src/cdk/stepper/BUILD.bazel b/src/cdk/stepper/BUILD.bazel index 1a0bfa530c4..1110403f3c2 100644 --- a/src/cdk/stepper/BUILD.bazel +++ b/src/cdk/stepper/BUILD.bazel @@ -1,16 +1,21 @@ package(default_visibility=["//visibility:public"]) -load("@angular//:index.bzl", "ng_module") + +load("//tools:defaults.bzl", "ng_module") ng_module( name = "stepper", srcs = glob(["**/*.ts"], exclude=["**/*.spec.ts"]), module_name = "@angular/cdk/stepper", deps = [ + "@angular//packages/common", + "@angular//packages/core", + "@angular//packages/forms", + "@rxjs", + "@rxjs//operators", "//src/cdk/a11y", "//src/cdk/bidi", "//src/cdk/coercion", "//src/cdk/keycodes", - "@rxjs", ], tsconfig = "//src/cdk:tsconfig-build.json", ) diff --git a/src/cdk/table/BUILD.bazel b/src/cdk/table/BUILD.bazel index cc610cb8173..cdf2ffe5d31 100644 --- a/src/cdk/table/BUILD.bazel +++ b/src/cdk/table/BUILD.bazel @@ -1,18 +1,21 @@ package(default_visibility=["//visibility:public"]) -load("@angular//:index.bzl", "ng_module") -load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test") +load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test") +load("//tools:defaults.bzl", "ng_module") ng_module( name = "table", srcs = glob(["**/*.ts"], exclude=["**/*.spec.ts"]), module_name = "@angular/cdk/table", deps = [ + "@angular//packages/common", + "@angular//packages/core", + "@rxjs", + "@rxjs//operators", "//src/cdk/bidi", "//src/cdk/collections", "//src/cdk/coercion", "//src/cdk/platform", - "@rxjs", ], tsconfig = "//src/cdk:tsconfig-build.json", ) diff --git a/src/cdk/testing/BUILD.bazel b/src/cdk/testing/BUILD.bazel index b83e4a5cc0e..251d440461d 100644 --- a/src/cdk/testing/BUILD.bazel +++ b/src/cdk/testing/BUILD.bazel @@ -1,10 +1,13 @@ package(default_visibility=["//visibility:public"]) -load("@angular//:index.bzl", "ng_module") + +load("//tools:defaults.bzl", "ng_module") ng_module( name = "testing", srcs = glob(["**/*.ts"], exclude=["**/*.spec.ts"]), module_name = "@angular/cdk/testing", - tsconfig = ":tsconfig-test.json", - deps = ["@rxjs"], + tsconfig = ":tsconfig-bazel.json", + deps = [ + "@angular//packages/core", + ], ) diff --git a/src/cdk/testing/tsconfig-test.json b/src/cdk/testing/tsconfig-bazel.json similarity index 69% rename from src/cdk/testing/tsconfig-test.json rename to src/cdk/testing/tsconfig-bazel.json index a3892825a7b..0bda591fb46 100644 --- a/src/cdk/testing/tsconfig-test.json +++ b/src/cdk/testing/tsconfig-bazel.json @@ -1,4 +1,5 @@ -// This file exists to be consumed by bazel +// This file exists to be consumed by Bazel +// Note that there is no build tsconfig because the cdk/testing entry-point is internal-only. { "extends": "../tsconfig-build", "files": [ diff --git a/src/cdk/text-field/BUILD.bazel b/src/cdk/text-field/BUILD.bazel index 77ac7736405..242e708d5aa 100644 --- a/src/cdk/text-field/BUILD.bazel +++ b/src/cdk/text-field/BUILD.bazel @@ -1,13 +1,16 @@ package(default_visibility=["//visibility:public"]) -load("@angular//:index.bzl", "ng_module") + load("@io_bazel_rules_sass//sass:sass.bzl", "sass_library", "sass_binary") +load("//tools:defaults.bzl", "ng_module") ng_module( name = "text-field", srcs = glob(["**/*.ts"], exclude=["**/*.spec.ts"]), module_name = "@angular/cdk/text-field", deps = [ + "@angular//packages/core", "@rxjs", + "@rxjs//operators", "//src/cdk/coercion", "//src/cdk/platform", ], diff --git a/src/cdk/tree/BUILD.bazel b/src/cdk/tree/BUILD.bazel index dfdd4420a6d..bf096f422aa 100644 --- a/src/cdk/tree/BUILD.bazel +++ b/src/cdk/tree/BUILD.bazel @@ -1,18 +1,21 @@ package(default_visibility=["//visibility:public"]) -load("@angular//:index.bzl", "ng_module") -load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test") +load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test") +load("//tools:defaults.bzl", "ng_module") ng_module( name = "tree", srcs = glob(["**/*.ts"], exclude=["**/*.spec.ts"]), module_name = "@angular/cdk/tree", deps = [ + "@angular//packages/common", + "@angular//packages/core", + "@rxjs", + "@rxjs//operators", "//src/cdk/a11y", "//src/cdk/bidi", "//src/cdk/coercion", "//src/cdk/collections", - "@rxjs", ], tsconfig = "//src/cdk:tsconfig-build.json", ) diff --git a/src/cdk/tsconfig-build.json b/src/cdk/tsconfig-build.json index 0a90a76732e..ba7d8f9fdac 100644 --- a/src/cdk/tsconfig-build.json +++ b/src/cdk/tsconfig-build.json @@ -24,7 +24,7 @@ "target": "es2015", "lib": ["es2015", "dom"], "skipLibCheck": true, - "types": ["jasmine", "tslib"], + "types": ["tslib"], "paths": { "@angular/cdk/*": ["../../dist/packages/cdk/*"] } diff --git a/src/lib/schematics/BUILD.bazel b/src/lib/schematics/BUILD.bazel index 57e1707089b..f9953c281e9 100644 --- a/src/lib/schematics/BUILD.bazel +++ b/src/lib/schematics/BUILD.bazel @@ -20,14 +20,14 @@ ts_library( ]), deps = [ "//src/cdk/schematics", - "@npm//:@angular-devkit/schematics", - "@npm//:@schematics/angular", + "@npm//@angular-devkit/schematics", + "@npm//@schematics/angular", # TODO(devversion): Only include jasmine for test sources (See: tsconfig types). - "@npm//:@types/jasmine", - "@npm//:@types/node", - "@npm//:parse5", - "@npm//:tslint", - "@npm//:typescript", + "@npm//@types/jasmine", + "@npm//@types/node", + "@npm//parse5", + "@npm//tslint", + "@npm//typescript", ], tsconfig = ":tsconfig.json", ) @@ -54,11 +54,11 @@ ts_library( deps = [ ":schematics", "//src/cdk/schematics", - "@npm//:@schematics/angular", - "@npm//:@angular-devkit/schematics", - "@npm//:@types/jasmine", - "@npm//:@types/node", - "@npm//:fs-extra", + "@npm//@schematics/angular", + "@npm//@angular-devkit/schematics", + "@npm//@types/jasmine", + "@npm//@types/node", + "@npm//fs-extra", ], tsconfig = ":tsconfig.json", testonly = True, diff --git a/tools/BUILD.bazel b/tools/BUILD.bazel index 418500d1511..65c88208003 100644 --- a/tools/BUILD.bazel +++ b/tools/BUILD.bazel @@ -6,12 +6,19 @@ load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary") ts_library( name = "sass_bundle_lib", srcs = ["sass_bundle.ts"], + deps = [ + "@npm//@types/node", + "@npm//scss-bundle", + ], tsconfig = "bazel-tools-tsconfig.json", ) # Executable for the custom sass_bundle rule (see sass_bundle.bzl). nodejs_binary( name = "sass_bundle", - data = [":sass_bundle_lib"], + data = [ + "@npm//scss-bundle", + ":sass_bundle_lib", + ], entry_point = "angular_material/tools/sass_bundle.js", ) diff --git a/tools/bazel.rc b/tools/bazel.rc index bbd341068d5..0ced420a281 100644 --- a/tools/bazel.rc +++ b/tools/bazel.rc @@ -46,3 +46,7 @@ build --workspace_status_command=./tools/bazel-stamp-vars.sh # 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 --strategy=AngularTemplateCompile=worker + +# Use the new "ngtsc" compiler strategy. We don't want to compile with Ivy nor with the +# legacy compiler that doesn't handle `providedIn` properly. +build --define=compile=local diff --git a/tools/defaults.bzl b/tools/defaults.bzl index 2735bb3086e..832eab5aa0c 100644 --- a/tools/defaults.bzl +++ b/tools/defaults.bzl @@ -1,12 +1,29 @@ # Re-export of Bazel rules with repository-wide defaults +load("@angular//:index.bzl", _ng_module = "ng_module") load("@build_bazel_rules_nodejs//:defs.bzl", _jasmine_node_test = "jasmine_node_test") +load("@build_bazel_rules_typescript//:defs.bzl", _ts_library = "ts_library") + +def ts_library(deps = [], **kwargs): + ts_library(**kwargs) + +def ng_module(deps = [], **kwargs): + local_deps = [ + # Since we use the TypeScript import helpers (tslib) for each TypeScript configuration, + # we declare TSLib as default dependency + "@npm//tslib", + ] + deps + + _ng_module( + deps = local_deps, + **kwargs + ) def jasmine_node_test(deps = [], **kwargs): local_deps = [ # Workaround for: https://github.com/bazelbuild/rules_nodejs/issues/344 - "@npm//:jasmine", - "@npm//:source-map-support", + "@npm//jasmine", + "@npm//source-map-support", ] + deps _jasmine_node_test( diff --git a/yarn.lock b/yarn.lock index 5199bb7ffd8..a14dfc48007 100644 --- a/yarn.lock +++ b/yarn.lock @@ -28,15 +28,6 @@ dependencies: tslib "^1.9.0" -"@angular/bazel@7.0.0-rc.0": - version "7.0.0-rc.0" - resolved "https://registry.yarnpkg.com/@angular/bazel/-/bazel-7.0.0-rc.0.tgz#3d624c7a2c9ec9a2a00a8cdbb6d1d1137f94fdf8" - integrity sha512-yO9y1Fvveenlp3MYQglfAwFJObA0RZTO1JQEYzh4OVDifw67pGMR0c9tED5U1Gh0HxTjzxn5zVlqLwQbCgTJAw== - dependencies: - "@bazel/typescript" "^0.15.0" - "@types/node" "6.0.84" - protobufjs "5.0.0" - "@angular/common@7.0.0-rc.0": version "7.0.0-rc.0" resolved "https://registry.yarnpkg.com/@angular/common/-/common-7.0.0-rc.0.tgz#4872a430838653cbddfba759ccf1f9332c065171" @@ -254,15 +245,6 @@ resolved "https://registry.yarnpkg.com/@bazel/ibazel/-/ibazel-0.3.1.tgz#5f02f208f138e581bbdb1534d5c013d7a0ac9799" integrity sha1-XwLyCPE45YG72xU01cAT16Csl5k= -"@bazel/typescript@^0.15.0": - version "0.15.3" - resolved "https://registry.yarnpkg.com/@bazel/typescript/-/typescript-0.15.3.tgz#5c32b3bf664b268f9ffb634b86f40004a50e7ef9" - integrity sha512-YWKX1cLGjWx2OdYBU0WeV7DlemlEaXuMcPKkeB3p2D7jiso5YYHaaOevWOQVJXKS4E/fbjd8nw7RGtRWsX8Myg== - dependencies: - protobufjs "5.0.0" - tsickle "0.25.x" - tsutils "2.20.0" - "@bazel/typescript@^0.19.1": version "0.19.1" resolved "https://registry.yarnpkg.com/@bazel/typescript/-/typescript-0.19.1.tgz#61dd57c0ab8a6c9930d2463d44e9522ec007fe3a" @@ -761,11 +743,6 @@ resolved "https://registry.yarnpkg.com/@types/node/-/node-10.11.4.tgz#e8bd933c3f78795d580ae41d86590bfc1f4f389d" integrity sha512-ojnbBiKkZFYRfQpmtnnWTMw+rzGp/JiystjluW9jgN3VzRwilXddJ6aGQ9V/7iuDG06SBgn7ozW9k3zcAnYjYQ== -"@types/node@6.0.84": - version "6.0.84" - resolved "https://registry.yarnpkg.com/@types/node/-/node-6.0.84.tgz#193ffe5a9f42864d425ffd9739d95b753c6a1eab" - integrity sha512-1SvEazClhUBRNroJM3oB3xf3u2r6xGmHDGbdigqNPHvNKLl8/BtATgO9eC04ZLuovpSh0B20BF1QJxdi+qmTlg== - "@types/node@^6.0.46": version "6.0.118" resolved "https://registry.yarnpkg.com/@types/node/-/node-6.0.118.tgz#8014a9b1dee0b72b4d7cd142563f1af21241c3a2" @@ -9728,7 +9705,7 @@ source-map-support@0.5.9, source-map-support@^0.5.0, source-map-support@^0.5.9: buffer-from "^1.0.0" source-map "^0.6.0" -source-map-support@^0.4.0, source-map-support@^0.4.15, source-map-support@^0.4.2, source-map-support@~0.4.0: +source-map-support@^0.4.0, source-map-support@^0.4.15, source-map-support@~0.4.0: version "0.4.18" resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.4.18.tgz#0286a6de8be42641338594e97ccea75f0a2c585f" integrity sha512-try0/JqxPLF9nOjvSta7tVondkP5dwgyLDjVoyMDlmjugT2lRZ1OfsrYTkCd2hkDnJTKRbO/Rl3orm8vlsUzbA== @@ -10600,16 +10577,6 @@ tsconfig@^6.0.0: strip-bom "^3.0.0" strip-json-comments "^2.0.0" -tsickle@0.25.x: - version "0.25.6" - resolved "https://registry.yarnpkg.com/tsickle/-/tsickle-0.25.6.tgz#b595db16b236721824eeeda8bb262365b47ef334" - integrity sha1-tZXbFrI2chgk7u2ouyYjZbR+8zQ= - dependencies: - minimist "^1.2.0" - mkdirp "^0.5.1" - source-map "^0.5.6" - source-map-support "^0.4.2" - tsickle@0.28.0: version "0.28.0" resolved "https://registry.yarnpkg.com/tsickle/-/tsickle-0.28.0.tgz#6cd6fa004766c6ad9261b599c83866ee97cc7875" @@ -10659,13 +10626,6 @@ tslint@^5.11.0: tslib "^1.8.0" tsutils "^2.27.2" -tsutils@2.20.0: - version "2.20.0" - resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-2.20.0.tgz#303394064bc80be8ee04e10b8609ae852e9312d3" - integrity sha512-qPOBy1/hwLdBxh/TNIpim5qL1WRMR0tgVGBB6shjnpw6/SuS5ZKYyXXxKDYsMsMtVdFOcL+XPGZVEuc+eCOo4A== - dependencies: - tslib "^1.8.1" - tsutils@2.27.2: version "2.27.2" resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-2.27.2.tgz#60ba88a23d6f785ec4b89c6e8179cac9b431f1c7"