Skip to content

Commit ad689cd

Browse files
gregmagolanmmalerba
authored andcommitted
build: update to rules_nodejs 1.0.0 (#18064)
Dependency sandwich exists between material & angular so we need to patch both @angular/bazel & ts-api-guardian npm packages to land this so that the material-unit-test CI job in angular/angular#34589 can be greened up.
1 parent 5511548 commit ad689cd

File tree

20 files changed

+148
-48
lines changed

20 files changed

+148
-48
lines changed

WORKSPACE

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,22 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
88
# Add NodeJS rules
99
http_archive(
1010
name = "build_bazel_rules_nodejs",
11-
sha256 = "a54b2511d6dae42c1f7cdaeb08144ee2808193a088004fc3b464a04583d5aa2e",
12-
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/0.42.3/rules_nodejs-0.42.3.tar.gz"],
11+
sha256 = "3887b948779431ac443e6a64f31b9e1e17b8d386a31eebc50ec1d9b0a6cabd2b",
12+
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/1.0.0/rules_nodejs-1.0.0.tar.gz"],
1313
)
1414

1515
# Add sass rules
1616
http_archive(
1717
name = "io_bazel_rules_sass",
18-
sha256 = "ad08e8c82aa1f48b72dc295cb83bba33f514cdf24cc7b0e21e9353f20f0dc147",
19-
strip_prefix = "rules_sass-5d1b26f8cd12c5d75dd359f9291090b341e8fd52",
20-
# We need to use a version that includes SHA 5d1b26f8cd12c5d75dd359f9291090b341e8fd52 of
21-
# the "rules_sass" repository as it adds support for workers.
22-
url = "https://github.com/bazelbuild/rules_sass/archive/5d1b26f8cd12c5d75dd359f9291090b341e8fd52.zip",
18+
sha256 = "77e241148f26d5dbb98f96fe0029d8f221c6cb75edbb83e781e08ac7f5322c5f",
19+
strip_prefix = "rules_sass-1.24.0",
20+
urls = [
21+
"https://github.com/bazelbuild/rules_sass/archive/1.24.0.zip",
22+
"https://mirror.bazel.build/github.com/bazelbuild/rules_sass/archive/1.24.0.zip",
23+
],
2324
)
2425

25-
load("@build_bazel_rules_nodejs//:defs.bzl", "check_bazel_version", "node_repositories", "yarn_install")
26+
load("@build_bazel_rules_nodejs//:index.bzl", "check_bazel_version", "node_repositories", "yarn_install")
2627

2728
# The minimum bazel version to use with this repo is v1.1.0.
2829
check_bazel_version("1.1.0")

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@
7171
"@bazel/bazel": "^1.1.0",
7272
"@bazel/buildifier": "^0.29.0",
7373
"@bazel/ibazel": "^0.10.3",
74-
"@bazel/jasmine": "^0.41.0",
75-
"@bazel/karma": "^0.41.0",
76-
"@bazel/protractor": "^0.41.0",
77-
"@bazel/typescript": "^0.41.0",
74+
"@bazel/jasmine": "1.0.0",
75+
"@bazel/karma": "1.0.0",
76+
"@bazel/protractor": "1.0.0",
77+
"@bazel/typescript": "1.0.0",
7878
"@firebase/app-types": "^0.3.2",
7979
"@octokit/rest": "^16.28.7",
8080
"@schematics/angular": "^9.0.0-rc.6",

src/cdk/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ ng_package(
5151
srcs = ["package.json"],
5252
data = rerootedStyleTargets + CDK_SCSS_LIBS,
5353
entry_point = ":public-api.ts",
54-
packages = [
54+
nested_packages = [
5555
"//src/cdk/schematics:npm_package",
5656
],
5757
tags = ["release-package"],

src/cdk/schematics/BUILD.bazel

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package(default_visibility = ["//visibility:public"])
22

3-
load("@build_bazel_rules_nodejs//:defs.bzl", "npm_package")
3+
load("@build_bazel_rules_nodejs//:index.bzl", "pkg_npm")
44
load("//:packages.bzl", "VERSION_PLACEHOLDER_REPLACEMENTS")
55
load("//tools:defaults.bzl", "jasmine_node_test", "ts_library")
66

@@ -40,10 +40,10 @@ ts_library(
4040
)
4141

4242
# This package is intended to be combined into the main @angular/cdk package as a dep.
43-
npm_package(
43+
pkg_npm(
4444
name = "npm_package",
4545
srcs = [":schematics_assets"],
46-
replacements = VERSION_PLACEHOLDER_REPLACEMENTS,
46+
substitutions = VERSION_PLACEHOLDER_REPLACEMENTS,
4747
deps = [":schematics"],
4848
)
4949

src/material/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ ng_package(
5353
] + MATERIAL_SCSS_LIBS,
5454
entry_point = ":index.ts",
5555
entry_point_name = "material",
56-
packages = ["//src/material/schematics:npm_package"],
56+
nested_packages = ["//src/material/schematics:npm_package"],
5757
tags = ["release-package"],
5858
deps = MATERIAL_TARGETS + MATERIAL_TESTING_TARGETS,
5959
)

src/material/schematics/BUILD.bazel

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package(default_visibility = ["//visibility:public"])
22

3-
load("@build_bazel_rules_nodejs//:defs.bzl", "npm_package")
3+
load("@build_bazel_rules_nodejs//:index.bzl", "pkg_npm")
44
load("//:packages.bzl", "VERSION_PLACEHOLDER_REPLACEMENTS")
55
load("//tools:defaults.bzl", "jasmine_node_test", "ts_library")
66

@@ -38,10 +38,10 @@ ts_library(
3838
)
3939

4040
# This package is intended to be combined into the main @angular/material package as a dep.
41-
npm_package(
41+
pkg_npm(
4242
name = "npm_package",
4343
srcs = [":schematics_assets"],
44-
replacements = VERSION_PLACEHOLDER_REPLACEMENTS,
44+
substitutions = VERSION_PLACEHOLDER_REPLACEMENTS,
4545
deps = [":schematics"],
4646
)
4747

src/universal-app/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package(default_visibility = ["//visibility:public"])
22

3-
load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_test")
3+
load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_test")
44
load("//src/cdk:config.bzl", "CDK_TARGETS")
55
load("//src/cdk-experimental:config.bzl", "CDK_EXPERIMENTAL_TARGETS")
66
load("//src/material:config.bzl", "MATERIAL_TARGETS")

tools/bazel/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package(default_visibility = ["//visibility:public"])
22

3-
load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary")
3+
load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_binary")
44

55
# Custom "tsc_wrapped" binary that has "tsickle" available as runtime dependency.
66
# This is needed as the default compiler for a "ts_library" does not have a dependency
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
diff --git node_modules/@angular/bazel/_BUILD.bazel node_modules/@angular/bazel/_BUILD.bazel
2+
index 1e4880f..5654615 100755
3+
--- node_modules/@angular/bazel/_BUILD.bazel
4+
+++ node_modules/@angular/bazel/_BUILD.bazel
5+
@@ -1,6 +1,6 @@
6+
-load("//tools:defaults.bzl", "npm_package")
7+
+load("//tools:defaults.bzl", "pkg_npm")
8+
9+
-npm_package(
10+
+pkg_npm(
11+
name = "npm_package",
12+
srcs = glob(
13+
["*"],
14+
@@ -14,10 +14,10 @@ npm_package(
15+
"//src/schematics:package_assets",
16+
"//third_party/github.com/bazelbuild/bazel/src/main/protobuf:package_assets",
17+
],
18+
- packages = [
19+
+ nested_packages = [
20+
"//docs",
21+
],
22+
- replacements = {
23+
+ substitutions = {
24+
"(#|\/\/)\\s+BEGIN-DEV-ONLY[\\w\W]+?(#|\/\/)\\s+END-DEV-ONLY": "",
25+
"//": "//",
26+
"npm_angular_bazel/": "npm_angular_bazel/",
27+
diff --git node_modules/@angular/bazel/src/ng_package/ng_package.bzl node_modules/@angular/bazel/src/ng_package/ng_package.bzl
28+
index 55bd685..8aaefdc 100755
29+
--- node_modules/@angular/bazel/src/ng_package/ng_package.bzl
30+
+++ node_modules/@angular/bazel/src/ng_package/ng_package.bzl
31+
@@ -15,9 +15,9 @@ specification of this format at https://goo.gl/jB3GVv
32+
33+
load("@build_bazel_rules_nodejs//:providers.bzl", "JSEcmaScriptModuleInfo", "JSNamedModuleInfo", "NpmPackageInfo", "node_modules_aspect")
34+
load(
35+
- "@build_bazel_rules_nodejs//internal/npm_package:npm_package.bzl",
36+
- "NPM_PACKAGE_ATTRS",
37+
- "NPM_PACKAGE_OUTPUTS",
38+
+ "@build_bazel_rules_nodejs//internal/pkg_npm:pkg_npm.bzl",
39+
+ "PKG_NPM_ATTRS",
40+
+ "PKG_NPM_OUTPUTS",
41+
"create_package",
42+
)
43+
load("//src:external.bzl", "FLAT_DTS_FILE_SUFFIX")
44+
@@ -623,7 +623,7 @@ def _ng_package_impl(ctx):
45+
package_dir = create_package(
46+
ctx,
47+
devfiles.to_list(),
48+
- [npm_package_directory] + ctx.files.packages,
49+
+ [npm_package_directory] + ctx.files.nested_packages,
50+
)
51+
return [DefaultInfo(
52+
files = depset([package_dir]),
53+
@@ -631,7 +631,7 @@ def _ng_package_impl(ctx):
54+
55+
_NG_PACKAGE_DEPS_ASPECTS = [esm5_outputs_aspect, ng_package_module_mappings_aspect, node_modules_aspect]
56+
57+
-_NG_PACKAGE_ATTRS = dict(NPM_PACKAGE_ATTRS, **{
58+
+_NG_PACKAGE_ATTRS = dict(PKG_NPM_ATTRS, **{
59+
"srcs": attr.label_list(
60+
doc = """JavaScript source files from the workspace.
61+
These can use ES2015 syntax and ES Modules (import/export)""",
62+
@@ -807,12 +807,12 @@ def _ng_package_outputs(name, entry_point, entry_point_name):
63+
"umd": "%s.umd.js" % basename,
64+
"umd_min": "%s.umd.min.js" % basename,
65+
}
66+
- for key in NPM_PACKAGE_OUTPUTS:
67+
- # NPM_PACKAGE_OUTPUTS is a "normal" dict-valued outputs so it looks like
68+
+ for key in PKG_NPM_OUTPUTS:
69+
+ # PKG_NPM_OUTPUTS is a "normal" dict-valued outputs so it looks like
70+
# "pack": "%{name}.pack",
71+
# But this is a function-valued outputs.
72+
# Bazel won't replace the %{name} token so we have to do it.
73+
- outputs[key] = NPM_PACKAGE_OUTPUTS[key].replace("%{name}", name)
74+
+ outputs[key] = PKG_NPM_OUTPUTS[key].replace("%{name}", name)
75+
return outputs
76+
77+
ng_package = rule(

tools/bazel/expand_template.bzl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
"""Implementation of the expand_template rule """
22

33
def expand_template_impl(ctx):
4-
replacements = dict(**ctx.attr.substitutions)
4+
substitutions = dict(**ctx.attr.substitutions)
55

66
for k in ctx.attr.configuration_env_vars:
77
if k in ctx.var.keys():
8-
replacements["$%s_TMPL" % k.upper()] = ctx.var[k]
8+
substitutions["$%s_TMPL" % k.upper()] = ctx.var[k]
99

1010
ctx.actions.expand_template(
1111
template = ctx.file.template,
1212
output = ctx.outputs.output_name,
13-
substitutions = replacements,
13+
substitutions = substitutions,
1414
)
1515

1616
"""

0 commit comments

Comments
 (0)