build: no longer require updating multiple package.json files for bazel (#14391)

* Replaces second "package.json" file with a small workspace that just aliases to the actual dependencies provided in the "@matdeps" workspace. This speeds up the analysis phase and also makes debugging easier.
* Also proxies the "ng_package" so that it always includes the proper `README.md` file. Also this means that we can always replace the version placeholders. Similar to `angular/angular`.

Similar to https://github.com/angular/angular/commit/68074df0a23f12b11bd480a1911d7403d2b31530. Credits to @gregmagolan for this.

We just need a bit more work because we don't overwrite the default `compiler`, `xi18n` and `packager` targets to the actual source files (this is special to Angular because those contain the sources)
This commit is contained in:
Paul Gschwendtner
2018-12-06 21:41:31 +01:00
committed by mmalerba
parent 63be232283
commit 9067fd3eb7
17 changed files with 94 additions and 4303 deletions
+14 -12
View File
@@ -35,6 +35,19 @@ http_archive(
sha256 = "72b0b4e517f43358f554c125e40e39f67688cd2738a8998b4a266981ed32f403",
)
# We need to create a local repository called "npm" because currently Angular Material
# stores all of it's NPM dependencies in the "@matdeps" repository. This is necessary because
# we don't want to reserve the "npm" repository that is commonly used by downstream projects.
# Since we still need the "npm" repository in order to use the Angular or TypeScript Bazel
# rules, we create a local repository that is just defined in **this** workspace and is not
# being shipped to downstream projects. This can be removed once downstream projects can
# consume Angular Material completely from NPM.
# TODO(devversion): remove once Angular Material can be consumed from NPM with Bazel.
local_repository(
name = "npm",
path = "tools/npm-workspace"
)
# Add sass rules
http_archive(
name = "io_bazel_rules_sass",
@@ -60,8 +73,7 @@ rules_angular_dependencies()
load("@io_bazel_rules_sass//:package.bzl", "rules_sass_dependencies")
rules_sass_dependencies()
load("@build_bazel_rules_nodejs//:defs.bzl", "check_bazel_version", "node_repositories",
"yarn_install")
load("@build_bazel_rules_nodejs//:defs.bzl", "check_bazel_version", "node_repositories")
# The minimum bazel version to use with this repo is 0.18.0
check_bazel_version("0.18.0")
@@ -73,16 +85,6 @@ node_repositories(
yarn_version = "1.12.1",
)
# @npm is temporarily needed to build @rxjs from source since its ts_library
# targets will depend on an @npm workspace by default.
# TODO(gmagolan): remove this once rxjs ships with an named UMD bundle and we
# are no longer building it from source.
yarn_install(
name = "npm",
package_json = "//tools:npm/package.json",
yarn_lock = "//tools:npm/yarn.lock",
)
# Setup TypeScript Bazel workspace
load("@build_bazel_rules_typescript//:defs.bzl", "ts_setup_workspace")
ts_setup_workspace()
+1
View File
@@ -5,6 +5,7 @@ load("//tools:defaults.bzl", "ts_library")
exports_files([
"bazel-tsconfig-build.json",
"bazel-tsconfig-test.json",
"README.md",
])
ts_library(
+2 -4
View File
@@ -1,9 +1,8 @@
package(default_visibility=["//visibility:public"])
load("@angular//:index.bzl", "ng_package")
load("//tools:defaults.bzl", "ng_module")
load("//tools:defaults.bzl", "ng_module", "ng_package")
load("//:packages.bzl", "CDK_EXPERIMENTAL_PACKAGES", "CDK_EXPERIMENTAL_TARGETS",
"CDK_TARGETS", "ROLLUP_GLOBALS", "VERSION_PLACEHOLDER_REPLACEMENTS")
"CDK_TARGETS", "ROLLUP_GLOBALS")
ng_module(
name = "cdk-experimental",
@@ -17,7 +16,6 @@ ng_package(
srcs = ["package.json"],
entry_point = "src/cdk-experimental/public_api.js",
globals = ROLLUP_GLOBALS,
replacements = VERSION_PLACEHOLDER_REPLACEMENTS,
deps = CDK_EXPERIMENTAL_TARGETS,
# TODO(devversion): Use the npm package for publishing. Right now this is disabled because
# we build using AOT for serving & testing, but the `ng_package` rule should not include factory
+2 -4
View File
@@ -1,8 +1,7 @@
package(default_visibility=["//visibility:public"])
load("@angular//:index.bzl", "ng_package")
load("//:packages.bzl", "CDK_TARGETS", "ROLLUP_GLOBALS", "VERSION_PLACEHOLDER_REPLACEMENTS")
load("//tools:defaults.bzl", "ng_module")
load("//:packages.bzl", "CDK_TARGETS", "ROLLUP_GLOBALS")
load("//tools:defaults.bzl", "ng_module", "ng_package")
# Root "@angular/cdk" entry-point that does not re-export individual entry-points.
ng_module(
@@ -20,7 +19,6 @@ ng_package(
srcs = ["package.json"],
entry_point = "src/cdk/public_api.js",
globals = ROLLUP_GLOBALS,
replacements = VERSION_PLACEHOLDER_REPLACEMENTS,
deps = CDK_TARGETS,
# TODO(devversion): Use the npm package for publishing. Right now this is disabled because
# we build using AOT for serving & testing, but the `ng_package` rule should not include factory
+2 -4
View File
@@ -1,10 +1,9 @@
package(default_visibility=["//visibility:public"])
load("@angular//:index.bzl", "ng_package")
load("//tools:sass_bundle.bzl", "sass_bundle")
load("//tools:defaults.bzl", "ng_module")
load("//tools:defaults.bzl", "ng_module", "ng_package")
load("//:packages.bzl", "MATERIAL_PACKAGES", "MATERIAL_TARGETS", "MATERIAL_SCSS_LIBS",
"ROLLUP_GLOBALS", "VERSION_PLACEHOLDER_REPLACEMENTS")
"ROLLUP_GLOBALS")
# Root "@angular/material" entry-point.
ng_module(
@@ -40,7 +39,6 @@ ng_package(
"//src/lib/prebuilt-themes:purple-green",
],
packages = ["//src/lib/schematics:npm_package"],
replacements = VERSION_PLACEHOLDER_REPLACEMENTS,
deps = MATERIAL_TARGETS,
# TODO(devversion): Use the npm package for publishing. Right now this is disabled because
# we build using AOT for serving & testing, but the `ng_package` rule should not include factory
+1 -2
View File
@@ -1,8 +1,7 @@
package(default_visibility=["//visibility:public"])
load("@angular//:index.bzl", "ng_package")
load("//:packages.bzl", "CDK_TARGETS", "MATERIAL_TARGETS", "ROLLUP_GLOBALS")
load("//tools:defaults.bzl", "ng_module")
load("//tools:defaults.bzl", "ng_module", "ng_package")
load("//tools/highlight-files:index.bzl", "highlight_files")
ng_module(
+2 -4
View File
@@ -1,8 +1,7 @@
package(default_visibility=["//visibility:public"])
load("@angular//:index.bzl", "ng_package")
load("//tools:defaults.bzl", "ng_module")
load("//:packages.bzl", "CDK_TARGETS", "ROLLUP_GLOBALS", "VERSION_PLACEHOLDER_REPLACEMENTS")
load("//tools:defaults.bzl", "ng_module", "ng_package")
load("//:packages.bzl", "CDK_TARGETS", "ROLLUP_GLOBALS")
ng_module(
name = "material-experimental",
@@ -16,7 +15,6 @@ ng_package(
srcs = ["package.json"],
entry_point = "src/material-experimental/public_api.js",
globals = ROLLUP_GLOBALS,
replacements = VERSION_PLACEHOLDER_REPLACEMENTS,
deps = [":material-experimental"],
# TODO(devversion): re-enable once we have set up the proper compiler for the ng_package
tags = ["manual"],
+2 -4
View File
@@ -1,8 +1,7 @@
package(default_visibility=["//visibility:public"])
load("@angular//:index.bzl", "ng_package")
load("//tools:defaults.bzl", "ng_module")
load("//:packages.bzl", "ROLLUP_GLOBALS", "VERSION_PLACEHOLDER_REPLACEMENTS")
load("//tools:defaults.bzl", "ng_module", "ng_package")
load("//:packages.bzl", "ROLLUP_GLOBALS")
ng_module(
name = "material-moment-adapter",
@@ -25,7 +24,6 @@ ng_package(
srcs = ["package.json"],
entry_point = "src/material-moment-adapter/public_api.js",
globals = ROLLUP_GLOBALS,
replacements = VERSION_PLACEHOLDER_REPLACEMENTS,
deps = [":material-moment-adapter"],
# TODO(devversion): re-enable once we have set up the proper compiler for the ng_package
tags = ["manual"],
+15 -1
View File
@@ -1,10 +1,11 @@
# Re-export of Bazel rules with repository-wide defaults
load("@angular//:index.bzl", _ng_module = "ng_module")
load("@angular//:index.bzl", _ng_module = "ng_module", _ng_package = "ng_package")
load("@build_bazel_rules_nodejs//:defs.bzl", _jasmine_node_test = "jasmine_node_test")
load("@build_bazel_rules_typescript//:defs.bzl", _ts_library = "ts_library",
_ts_web_test_suite = "ts_web_test_suite")
load("//tools/markdown-to-html:index.bzl", _markdown_to_html = "markdown_to_html")
load("//:packages.bzl", "VERSION_PLACEHOLDER_REPLACEMENTS")
_DEFAULT_TSCONFIG_BUILD = "//src:bazel-tsconfig-build.json"
_DEFAULT_TSCONFIG_TEST = "//src:bazel-tsconfig-test.json"
@@ -55,6 +56,19 @@ def ng_module(deps = [], tsconfig = None, testonly = False, **kwargs):
**kwargs
)
def ng_package(name, readme_md = None, **kwargs):
# If no readme file has been specified explicitly, use the default readme for
# release packages from "src/README.md".
if not readme_md:
readme_md = "//src:README.md"
_ng_package(
name = name,
readme_md = readme_md,
replacements = VERSION_PLACEHOLDER_REPLACEMENTS,
**kwargs
)
def jasmine_node_test(deps = [], **kwargs):
local_deps = [
# Workaround for: https://github.com/bazelbuild/rules_nodejs/issues/344
@@ -0,0 +1,9 @@
package(default_visibility = ["//visibility:public"])
# Create an alias so that "@npm//@angular/bazel" is a valid Bazel target that refers to the
# actual Bazel rules code from NPM. This is required by the "@angular//:@angular/bazel/ngc-wrapped
# target. See: https://github.com/angular/angular/blob/master/BUILD.bazel#L45
alias(
name = "bazel",
actual = "@matdeps//@angular/bazel",
)
@@ -0,0 +1,21 @@
package(default_visibility = ["//visibility:public"])
# Workaround that ensures that our build targets using the Angular Bazel rules
# can find the required binaries. This is a temporary workaround and can be removed
# once we use the "npm" workspace for our own dependencies and consume Angular
# completely from NPM.
alias(
name = "xi18n",
actual = "@matdeps//@angular/bazel/bin:xi18n",
)
alias(
name = "packager",
actual = "@matdeps//@angular/bazel/bin:packager",
)
alias(
name = "ngc-wrapped",
actual = "@matdeps//@angular/bazel/bin:ngc-wrapped",
)
@@ -0,0 +1,11 @@
package(default_visibility = ["//visibility:public"])
# Workaround that ensures that our build targets using the Bazel TypeScript web test
# rules can find the required source files. This is a temporary workaround and can be
# removed once we use the "npm" workspace for our own dependencies and consume Angular
# completely from NPM.
alias(
name = "karma",
actual = "@matdeps//@bazel/karma/bin:karma",
)
@@ -0,0 +1,10 @@
package(default_visibility = ["//visibility:public"])
# Create an alias so that "@npm//@bazel/typescript" is a valid Bazel target that refers to the
# actual TypeScript rules output from NPM. This is required because by default the TypeScript
# rules expect the "tsc-wrapped" code to be available in the "npm" workspace.
# See: https://github.com/bazelbuild/rules_typescript/blob/master/BUILD.bazel#L66
alias(
name = "typescript",
actual = "@matdeps//@bazel/typescript",
)
+1
View File
@@ -0,0 +1 @@
# Empty build file that marks this directory as a Bazel package.
+1
View File
@@ -0,0 +1 @@
workspace(name = "npm")
-11
View File
@@ -1,11 +0,0 @@
{
"description": "minimal @npm repo required to build @rxjs from source and so that @npm//@angular/bazel is a valid target",
"dependencies": {
"@angular/bazel": "7.1.1",
"@angular/compiler": "7.1.1",
"@angular/compiler-cli": "7.1.1",
"@bazel/karma": "0.21.0",
"@bazel/typescript": "0.21.0",
"typescript": "^3.1.1"
}
}
-4257
View File
File diff suppressed because it is too large Load Diff