Skip to content

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

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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")
Expand All @@ -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()
Expand Down
1 change: 1 addition & 0 deletions src/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ load("//tools:defaults.bzl", "ts_library")
exports_files([
"bazel-tsconfig-build.json",
"bazel-tsconfig-test.json",
"README.md",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not for this PR, but we should create separate npm README files for each of our packages

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Should these be pretty much similar to the current one but just have the "correct" package name title and refer to the proper URL for the sources?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created an issue and assigned it to myself for this.

])

ts_library(
Expand Down
6 changes: 2 additions & 4 deletions src/cdk-experimental/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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
Expand Down
6 changes: 2 additions & 4 deletions src/cdk/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -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
Expand Down
6 changes: 2 additions & 4 deletions src/lib/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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(
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/material-examples/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
6 changes: 2 additions & 4 deletions src/material-experimental/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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"],
Expand Down
6 changes: 2 additions & 4 deletions src/material-moment-adapter/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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"],
Expand Down
16 changes: 15 additions & 1 deletion tools/defaults.bzl
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions tools/npm-workspace/@angular/bazel/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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",
)
21 changes: 21 additions & 0 deletions tools/npm-workspace/@angular/bazel/bin/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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",
)
11 changes: 11 additions & 0 deletions tools/npm-workspace/@bazel/karma/bin/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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",
)
10 changes: 10 additions & 0 deletions tools/npm-workspace/@bazel/typescript/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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 change: 1 addition & 0 deletions tools/npm-workspace/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Empty build file that marks this directory as a Bazel package.
1 change: 1 addition & 0 deletions tools/npm-workspace/WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
workspace(name = "npm")
11 changes: 0 additions & 11 deletions tools/npm/package.json

This file was deleted.

Loading