From cbb9183ed4da9f73acb298a1176d186eb4e65014 Mon Sep 17 00:00:00 2001 From: Paul Gschwendtner Date: Sat, 17 Dec 2022 10:32:29 +0000 Subject: [PATCH] refactor: update `packages/bazel` npm artifact to not rely on `defaults.bzl` (#48538) Fixes that we temporarily broke the Bazel npm package artifact as part of the ESM work. This commit adjusts it and also makes the artifact subsitutions more maintainable. PR Close #48538 --- packages/bazel/package.json | 8 ++-- packages/bazel/src/ng_package/BUILD.bazel | 38 +------------------ packages/bazel/src/ng_package/ng_package.bzl | 4 +- .../bazel/src/ng_package/rollup/BUILD.bazel | 26 +++++++++++++ tools/defaults.bzl | 2 +- 5 files changed, 35 insertions(+), 43 deletions(-) create mode 100644 packages/bazel/src/ng_package/rollup/BUILD.bazel diff --git a/packages/bazel/package.json b/packages/bazel/package.json index 88f472d1926..161ac89bfa4 100644 --- a/packages/bazel/package.json +++ b/packages/bazel/package.json @@ -8,10 +8,10 @@ "node": "^14.20.0 || ^16.13.0 || >=18.10.0" }, "bin": { - "ngc-wrapped": "./src/ngc-wrapped/index.js", - "packager": "./src/ng_package/packager.js", - "types_bundler": "./src/types_bundle/index.js", - "xi18n": "./src/ngc-wrapped/extract_i18n.js" + "ngc-wrapped": "./src/ngc-wrapped/index.mjs", + "packager": "./src/ng_package/packager.mjs", + "types_bundler": "./src/types_bundle/index.mjs", + "xi18n": "./src/ngc-wrapped/extract_i18n.mjs" }, "typings": "./src/ngc-wrapped/index.d.ts", "bazelBin": { diff --git a/packages/bazel/src/ng_package/BUILD.bazel b/packages/bazel/src/ng_package/BUILD.bazel index d0c562ccfbe..841dc674c2a 100644 --- a/packages/bazel/src/ng_package/BUILD.bazel +++ b/packages/bazel/src/ng_package/BUILD.bazel @@ -1,48 +1,13 @@ +# BEGIN-DEV-ONLY load("//tools:defaults.bzl", "nodejs_binary", "ts_library") package(default_visibility = ["//visibility:public"]) -nodejs_binary( - name = "rollup_for_ng_package", - data = [ - # BEGIN-DEV-ONLY - "@npm" + - # END-DEV-ONLY - "//rollup", - # BEGIN-DEV-ONLY - "@npm" + - # END-DEV-ONLY - "//@rollup/plugin-commonjs", - # BEGIN-DEV-ONLY - "@npm" + - # END-DEV-ONLY - "//@rollup/plugin-node-resolve", - # BEGIN-DEV-ONLY - "@npm" + - # END-DEV-ONLY - "//rollup-plugin-sourcemaps", - # BEGIN-DEV-ONLY - "@npm" + - # END-DEV-ONLY - "//typescript", - ], - entry_point = ( - # BEGIN-DEV-ONLY - "@npm" + - # END-DEV-ONLY - "//:node_modules/rollup/dist/bin/rollup" - ), - # Disable the linker and rely on patched resolution which works better on Windows - # and is less prone to race conditions when targets build concurrently. - templated_args = ["--nobazel_run_linker"], -) - exports_files([ "ng_package.bzl", "rollup.config.js", ]) -# BEGIN-DEV-ONLY ts_library( name = "lib", srcs = glob(["*.ts"]), @@ -55,6 +20,7 @@ ts_library( filegroup( name = "package_assets", srcs = glob(["*.bzl"]) + [ + "//packages/bazel/src/ng_package/rollup:package_assets", "BUILD.bazel", "rollup.config.js", ], diff --git a/packages/bazel/src/ng_package/ng_package.bzl b/packages/bazel/src/ng_package/ng_package.bzl index 7b65fd73249..7c4b4596146 100644 --- a/packages/bazel/src/ng_package/ng_package.bzl +++ b/packages/bazel/src/ng_package/ng_package.bzl @@ -32,7 +32,7 @@ def _debug(vars, *args): _DEFAULT_NG_PACKAGER = "//@angular/bazel/bin:packager" _DEFAULT_ROLLUP_CONFIG_TMPL = "//:node_modules/@angular/bazel/src/ng_package/rollup.config.js" -_DEFAULT_ROLLUP = "//@angular/bazel/src/ng_package:rollup_for_ng_package" +_DEFAULT_ROLLUP = "//@angular/bazel/src/ng_package/rollup" _NG_PACKAGE_MODULE_MAPPINGS_ATTR = "ng_package_module_mappings" @@ -112,7 +112,7 @@ def _compute_node_modules_root(ctx): """Computes the node_modules root from the node_modules and deps attributes. Args: - ctx: the skylark execution context + ctx: the starlark execution context Returns: The node_modules root as a string diff --git a/packages/bazel/src/ng_package/rollup/BUILD.bazel b/packages/bazel/src/ng_package/rollup/BUILD.bazel new file mode 100644 index 00000000000..c1f07c6cdba --- /dev/null +++ b/packages/bazel/src/ng_package/rollup/BUILD.bazel @@ -0,0 +1,26 @@ +# Note: This file is shipped to NPM. It cannot use the `defaults.bzl` macro. +load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_binary") + +package(default_visibility = ["//visibility:public"]) + +filegroup( + name = "package_assets", + srcs = ["BUILD.bazel"], +) + +nodejs_binary( + name = "rollup", + data = [ + "@npm//@rollup/plugin-commonjs", + "@npm//@rollup/plugin-node-resolve", + "@npm//rollup", + "@npm//rollup-plugin-sourcemaps", + "@npm//typescript", + ], + entry_point = ( + "@npm//:node_modules/rollup/dist/bin/rollup" + ), + # Disable the linker and rely on patched resolution which works better on Windows + # and is less prone to race conditions when targets build concurrently. + templated_args = ["--nobazel_run_linker"], +) diff --git a/tools/defaults.bzl b/tools/defaults.bzl index 19b75f50eb3..fae2fd2c6fd 100644 --- a/tools/defaults.bzl +++ b/tools/defaults.bzl @@ -26,7 +26,7 @@ _INTERNAL_NG_MODULE_COMPILER = "//packages/bazel/src/ngc-wrapped" _INTERNAL_NG_MODULE_XI18N = "//packages/bazel/src/ngc-wrapped:xi18n" _INTERNAL_NG_PACKAGE_PACKAGER = "//packages/bazel/src/ng_package:packager" _INTERNAL_NG_PACKAGE_DEFAULT_ROLLUP_CONFIG_TMPL = "//packages/bazel/src/ng_package:rollup.config.js" -_INTERNAL_NG_PACKAGE_DEFAULT_ROLLUP = "//packages/bazel/src/ng_package:rollup_for_ng_package" +_INTERNAL_NG_PACKAGE_DEFAULT_ROLLUP = "//packages/bazel/src/ng_package/rollup" esbuild_config = _esbuild_config http_server = _http_server