From 780dfb4b0696cb8b14938e6184ee0137dc435ec2 Mon Sep 17 00:00:00 2001 From: Greg Magolan Date: Tue, 30 Jul 2019 14:36:10 -0700 Subject: [PATCH] fix: fencing for npm packages (#946) and other minor cleanups --- internal/rollup/BUILD.bazel | 1 - packages/jasmine/BUILD.bazel | 3 ++- packages/jasmine/src/BUILD.bazel | 18 ++++++++++++++++ packages/karma/src/BUILD.bazel | 6 ++++-- packages/labs/BUILD.bazel | 3 ++- packages/labs/src/BUILD.bazel | 4 ++++ packages/labs/src/webpack/BUILD.bazel | 2 ++ packages/protractor/BUILD.bazel | 3 ++- packages/stylus/BUILD.bazel | 3 ++- packages/stylus/src/BUILD.bazel | 4 ++++ packages/typescript/BUILD.bazel | 2 +- packages/typescript/replacements.bzl | 30 +++++++++++++++++++++++++++ packages/typescript/src/index.bzl | 13 ------------ 13 files changed, 71 insertions(+), 21 deletions(-) create mode 100644 packages/typescript/replacements.bzl diff --git a/internal/rollup/BUILD.bazel b/internal/rollup/BUILD.bazel index f930bc4064..866608a0fd 100644 --- a/internal/rollup/BUILD.bazel +++ b/internal/rollup/BUILD.bazel @@ -87,7 +87,6 @@ nodejs_binary( ) # BEGIN-INTERNAL -# TODO: switch to npm_bazel_jasmine # buildozer: disable=load-on-top # buildozer: disable=out-of-order-load load("@npm_bazel_jasmine//:index.from_src.bzl", "jasmine_node_test") diff --git a/packages/jasmine/BUILD.bazel b/packages/jasmine/BUILD.bazel index 975836ae29..df9ee14258 100644 --- a/packages/jasmine/BUILD.bazel +++ b/packages/jasmine/BUILD.bazel @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -load("@build_bazel_rules_nodejs//:defs.bzl", "npm_package") +load("@build_bazel_rules_nodejs//:defs.bzl", "COMMON_REPLACEMENTS", "npm_package") # Copy the license from our parent folder genrule( @@ -40,6 +40,7 @@ npm_package( srcs = [ "@npm_bazel_jasmine//:package_contents", ], + replacements = COMMON_REPLACEMENTS, vendor_external = [ "npm_bazel_jasmine", ], diff --git a/packages/jasmine/src/BUILD.bazel b/packages/jasmine/src/BUILD.bazel index 708fd1fec3..95acb245f7 100644 --- a/packages/jasmine/src/BUILD.bazel +++ b/packages/jasmine/src/BUILD.bazel @@ -1,3 +1,20 @@ +# Copyright 2019 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# BEGIN-INTERNAL +# Parts of this BUILD file only necessary when building from source. +# The generated `@bazel/jasmine` npm package contains a trimmed BUILD file using INTERNAL fences. load("@bazel_skylib//:bzl_library.bzl", "bzl_library") load("@build_bazel_rules_nodejs//internal/js_library:js_library.bzl", "js_library") @@ -31,3 +48,4 @@ js_library( ], module_name = "@bazel/jasmine", ) +# END-INTERNAL diff --git a/packages/karma/src/BUILD.bazel b/packages/karma/src/BUILD.bazel index 6740ff93c7..96cb5a5739 100644 --- a/packages/karma/src/BUILD.bazel +++ b/packages/karma/src/BUILD.bazel @@ -14,7 +14,7 @@ # BEGIN-INTERNAL # Parts of this BUILD file only necessary when building from source. -# The generated `@bazel/karma` npm package contains a trimmed BUILD file using # INTERNAL fences. +# The generated `@bazel/karma` npm package contains a trimmed BUILD file using INTERNAL fences. load("@bazel_skylib//:bzl_library.bzl", "bzl_library") load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary") load("@npm_bazel_typescript//:index.from_src.bzl", "ts_library") @@ -82,4 +82,6 @@ filegroup( ) # END-INTERNAL -exports_files(["karma.conf.js"]) +exports_files([ + "karma.conf.js", +]) diff --git a/packages/labs/BUILD.bazel b/packages/labs/BUILD.bazel index aea18aaf7f..553630437c 100644 --- a/packages/labs/BUILD.bazel +++ b/packages/labs/BUILD.bazel @@ -1,4 +1,4 @@ -load("@build_bazel_rules_nodejs//:defs.bzl", "npm_package") +load("@build_bazel_rules_nodejs//:defs.bzl", "COMMON_REPLACEMENTS", "npm_package") exports_files(["tsconfig.json"]) @@ -14,6 +14,7 @@ npm_package( srcs = [ "@npm_bazel_labs//:package_contents", ], + replacements = COMMON_REPLACEMENTS, vendor_external = [ "npm_bazel_labs", ], diff --git a/packages/labs/src/BUILD.bazel b/packages/labs/src/BUILD.bazel index ab8f9827d7..41bb5210ee 100644 --- a/packages/labs/src/BUILD.bazel +++ b/packages/labs/src/BUILD.bazel @@ -12,6 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. +# BEGIN-INTERNAL +# Parts of this BUILD file only necessary when building from source. +# The generated `@bazel/labs` npm package contains a trimmed BUILD file using INTERNAL fences. package(default_visibility = ["//visibility:public"]) exports_files(["tsconfig.json"]) @@ -25,3 +28,4 @@ filegroup( "//webpack:package_contents", ], ) +# END-INTERNAL diff --git a/packages/labs/src/webpack/BUILD.bazel b/packages/labs/src/webpack/BUILD.bazel index 042f210c18..9167e7cafb 100644 --- a/packages/labs/src/webpack/BUILD.bazel +++ b/packages/labs/src/webpack/BUILD.bazel @@ -13,6 +13,8 @@ # limitations under the License. # BEGIN-INTERNAL +# Parts of this BUILD file only necessary when building from source. +# The generated `@bazel/labs` npm package contains a trimmed BUILD file using INTERNAL fences. load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary") load("@npm_bazel_typescript//:index.from_src.bzl", "ts_library") diff --git a/packages/protractor/BUILD.bazel b/packages/protractor/BUILD.bazel index 2e8231462e..11fda80ac1 100644 --- a/packages/protractor/BUILD.bazel +++ b/packages/protractor/BUILD.bazel @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -load("@build_bazel_rules_nodejs//:defs.bzl", "npm_package") +load("@build_bazel_rules_nodejs//:defs.bzl", "COMMON_REPLACEMENTS", "npm_package") # Copy the license from our parent folder genrule( @@ -40,6 +40,7 @@ npm_package( srcs = [ "@npm_bazel_protractor//:package_contents", ], + replacements = COMMON_REPLACEMENTS, vendor_external = [ "npm_bazel_protractor", ], diff --git a/packages/stylus/BUILD.bazel b/packages/stylus/BUILD.bazel index 4d5d6041d6..0a8e7f77a9 100644 --- a/packages/stylus/BUILD.bazel +++ b/packages/stylus/BUILD.bazel @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -load("@build_bazel_rules_nodejs//:defs.bzl", "npm_package") +load("@build_bazel_rules_nodejs//:defs.bzl", "COMMON_REPLACEMENTS", "npm_package") # Copy the license from our parent folder genrule( @@ -40,6 +40,7 @@ npm_package( srcs = [ "@npm_bazel_stylus//:package_contents", ], + replacements = COMMON_REPLACEMENTS, vendor_external = [ "npm_bazel_stylus", ], diff --git a/packages/stylus/src/BUILD.bazel b/packages/stylus/src/BUILD.bazel index 17684b0589..e2d660423c 100644 --- a/packages/stylus/src/BUILD.bazel +++ b/packages/stylus/src/BUILD.bazel @@ -12,6 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. +# BEGIN-INTERNAL +# Parts of this BUILD file only necessary when building from source. +# The generated `@bazel/stylus` npm package contains a trimmed BUILD file using INTERNAL fences. load("@bazel_skylib//:bzl_library.bzl", "bzl_library") package(default_visibility = ["//visibility:public"]) @@ -33,3 +36,4 @@ filegroup( "package.json", ], ) +# END-INTERNAL diff --git a/packages/typescript/BUILD.bazel b/packages/typescript/BUILD.bazel index a0ccde5db9..6f574b74f6 100644 --- a/packages/typescript/BUILD.bazel +++ b/packages/typescript/BUILD.bazel @@ -13,7 +13,7 @@ # limitations under the License. load("@build_bazel_rules_nodejs//:defs.bzl", "npm_package") -load("@npm_bazel_typescript//:index.bzl", "TYPESCRIPT_REPLACEMENTS") +load(":replacements.bzl", "TYPESCRIPT_REPLACEMENTS") genrule( name = "copy_LICENSE", diff --git a/packages/typescript/replacements.bzl b/packages/typescript/replacements.bzl new file mode 100644 index 0000000000..c625860a03 --- /dev/null +++ b/packages/typescript/replacements.bzl @@ -0,0 +1,30 @@ +# Copyright 2019 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Replacements for @npm/typescript package +""" + +load("@build_bazel_rules_nodejs//:defs.bzl", "COMMON_REPLACEMENTS") + +TYPESCRIPT_REPLACEMENTS = dict( + COMMON_REPLACEMENTS, + **{ + # This BEGIN-DEV fencing is required as files pulled in from + # @build_bazel_rules_typescript//:npm_bazel_typescript_package + # use this alternate fencing + "(#|\/\/)\\s+BEGIN-DEV-ONLY[\\w\W]+?(#|\/\/)\\s+END-DEV-ONLY": "", + # This file gets vendored into our repo + "@build_bazel_rules_typescript//internal:common": "//internal:common", + } +) diff --git a/packages/typescript/src/index.bzl b/packages/typescript/src/index.bzl index 6951fd024d..f7d73f0ae5 100644 --- a/packages/typescript/src/index.bzl +++ b/packages/typescript/src/index.bzl @@ -17,7 +17,6 @@ Users should not load files under "/internal" """ -load("@build_bazel_rules_nodejs//:defs.bzl", "COMMON_REPLACEMENTS") load("//:version.bzl", _check_rules_typescript_version = "check_rules_typescript_version") load("//internal:build_defs.bzl", _ts_library = "ts_library_macro") load("//internal:ts_config.bzl", _ts_config = "ts_config") @@ -32,15 +31,3 @@ ts_config = _ts_config ts_devserver = _ts_devserver ts_proto_library = _ts_proto_library # If adding rules here also add to index.docs.bzl - -TYPESCRIPT_REPLACEMENTS = dict( - COMMON_REPLACEMENTS, - **{ - # This BEGIN-DEV fencing is required as files pulled in from - # @build_bazel_rules_typescript//:npm_bazel_typescript_package - # use this alternate fencing - "(#|\/\/)\\s+BEGIN-DEV-ONLY[\\w\W]+?(#|\/\/)\\s+END-DEV-ONLY": "", - # This file gets vendored into our repo - "@build_bazel_rules_typescript//internal:common": "//internal:common", - } -)