Skip to content

build: drop usage of rules_nodejs 's pkg_npm in favor of using npm_package #30914

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
merged 1 commit into from
Apr 21, 2025
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
2 changes: 1 addition & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ setup_dependencies_2()

git_repository(
name = "rules_angular",
commit = "60d0dbdf18224f5167da1a43f4de9c4cb717b593",
commit = "514eda9ec00a6745dc11b2a62d7be2634199171e",
remote = "https://github.com/devversion/rules_angular.git",
)

Expand Down
7 changes: 3 additions & 4 deletions src/google-maps/schematics/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
load("@build_bazel_rules_nodejs//:index.bzl", "copy_to_bin")
load("//tools:defaults.bzl", "pkg_npm")
load("//tools:defaults2.bzl", "ts_project")
load("//tools:defaults2.bzl", "npm_package", "ts_project")
load("@aspect_rules_ts//ts:defs.bzl", rules_js_tsconfig = "ts_config")

package(default_visibility = ["//visibility:public"])
Expand Down Expand Up @@ -32,9 +31,9 @@ ts_project(
)

# This package is intended to be combined into the main @angular/google-maps package as a dep.
pkg_npm(
npm_package(
name = "npm_package",
deps = [
srcs = [
":schematics",
":schematics_assets",
"//src/google-maps/schematics/ng-update",
Expand Down
7 changes: 3 additions & 4 deletions src/material-date-fns-adapter/schematics/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
load("@build_bazel_rules_nodejs//:index.bzl", "copy_to_bin")
load("//tools:defaults.bzl", "pkg_npm")
load("//tools:defaults2.bzl", "ts_project")
load("//tools:defaults2.bzl", "npm_package", "ts_project")

package(default_visibility = ["//visibility:public"])

Expand All @@ -27,9 +26,9 @@ ts_project(
)

# This package is intended to be combined into the main @angular/material-date-fns-adapter package as a dep.
pkg_npm(
npm_package(
name = "npm_package",
deps = [
srcs = [
":schematics",
":schematics_assets",
],
Expand Down
7 changes: 3 additions & 4 deletions src/material-luxon-adapter/schematics/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
load("@build_bazel_rules_nodejs//:index.bzl", "copy_to_bin")
load("//tools:defaults.bzl", "pkg_npm")
load("//tools:defaults2.bzl", "ts_project")
load("//tools:defaults2.bzl", "npm_package", "ts_project")

package(default_visibility = ["//visibility:public"])

Expand All @@ -26,9 +25,9 @@ ts_project(
)

# This package is intended to be combined into the main @angular/material-luxon-adapter package as a dep.
pkg_npm(
npm_package(
name = "npm_package",
deps = [
srcs = [
":schematics",
":schematics_assets",
],
Expand Down
7 changes: 3 additions & 4 deletions src/material-moment-adapter/schematics/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
load("@build_bazel_rules_nodejs//:index.bzl", "copy_to_bin")
load("//tools:defaults.bzl", "pkg_npm")
load("//tools:defaults2.bzl", "ts_project")
load("//tools:defaults2.bzl", "npm_package", "ts_project")

package(default_visibility = ["//visibility:public"])

Expand All @@ -26,9 +25,9 @@ ts_project(
)

# This package is intended to be combined into the main @angular/material-moment-adapter package as a dep.
pkg_npm(
npm_package(
name = "npm_package",
deps = [
srcs = [
":schematics",
":schematics_assets",
],
Expand Down
7 changes: 3 additions & 4 deletions src/youtube-player/schematics/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
load("@build_bazel_rules_nodejs//:index.bzl", "copy_to_bin")
load("//tools:defaults.bzl", "pkg_npm")
load("//tools:defaults2.bzl", "ts_project")
load("//tools:defaults2.bzl", "npm_package", "ts_project")

package(default_visibility = ["//visibility:public"])

Expand All @@ -26,9 +25,9 @@ ts_project(
)

# This package is intended to be combined into the main @angular/youtube-player package as a dep.
pkg_npm(
npm_package(
name = "npm_package",
deps = [
srcs = [
":schematics",
":schematics_assets",
],
Expand Down
21 changes: 0 additions & 21 deletions tools/defaults.bzl
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Re-export of Bazel rules with repository-wide defaults

load("@rules_pkg//:pkg.bzl", "pkg_tar")
load("@build_bazel_rules_nodejs//:index.bzl", _pkg_npm = "pkg_npm")
load("@rules_sass//src:index.bzl", _sass_binary = "sass_binary", _sass_library = "sass_library")
load("@npm//@angular/bazel:index.bzl", _ng_package = "ng_package")
load("//:packages.bzl", "NO_STAMP_NPM_PACKAGE_SUBSTITUTIONS", "NPM_PACKAGE_SUBSTITUTIONS")
Expand Down Expand Up @@ -101,23 +100,3 @@ def ng_package(
interop_deps = [d.replace("_legacy", "") for d in deps] + package_deps,
package_name = package_name,
)

def pkg_npm(name, visibility = None, **kwargs):
_pkg_npm(
name = name,
# We never set a `package_name` for NPM packages, neither do we enable validation.
# This is necessary because the source targets of the NPM packages all have
# package names set and setting a similar `package_name` on the NPM package would
# result in duplicate linker mappings that will conflict. e.g. consider the following
# scenario: We have a `ts_library` for `@angular/cdk`. We will configure a package
# name for the target so that it can be resolved in NodeJS executions from `node_modules`.
# If we'd also set a `package_name` for the associated `pkg_npm` target, there would be
# two mappings for `@angular/cdk` and the linker will complain. For a better development
# experience, we want the mapping to resolve to the direct outputs of the `ts_library`
# instead of requiring tests and other targets to assemble the NPM package first.
package_name = None,
validate = False,
substitutions = npmPackageSubstitutions,
visibility = visibility,
**kwargs
)
24 changes: 22 additions & 2 deletions tools/defaults2.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,37 @@ load("@aspect_rules_js//npm:defs.bzl", _npm_package = "npm_package")
load("@devinfra//bazel/http-server:index.bzl", _http_server = "http_server")
load("@devinfra//bazel/spec-bundling:index_rjs.bzl", _spec_bundle = "spec_bundle")
load("@rules_angular//src/ng_project:index.bzl", _ng_project = "ng_project")
load("@rules_angular//src/ng_package/text_replace:index.bzl", _text_replace = "text_replace")
load("@rules_browsers//src/protractor_test:index.bzl", "protractor_test")
load("//tools/bazel:module_name.bzl", "compute_module_name")
load("//tools/bazel:ts_project_interop.bzl", _ts_project = "ts_project")
load("//tools/bazel:web_test_suite.bzl", _ng_web_test_suite = "ng_web_test_suite")
load("//:packages.bzl", "NO_STAMP_NPM_PACKAGE_SUBSTITUTIONS", "NPM_PACKAGE_SUBSTITUTIONS")

spec_bundle = _spec_bundle
http_server = _http_server
ng_web_test_suite = _ng_web_test_suite

def npm_package(**kwargs):
_npm_package(**kwargs)
def npm_package(name, srcs = [], **kwargs):
_text_replace(
name = "%s_substituted" % name,
srcs = srcs,
substitutions = select({
"//tools:stamp": NPM_PACKAGE_SUBSTITUTIONS,
"//conditions:default": NO_STAMP_NPM_PACKAGE_SUBSTITUTIONS,
}),
)
_npm_package(
name = name,
srcs = srcs + [
"%s_substituted" % name,
],
replace_prefixes = {
"%s_substituted" % name: "/",
},
allow_overwrites = True,
**kwargs
)

def ts_project(
name,
Expand Down
Loading