From e84df1db4a91a9ab1f2a328abe61a265ec0ab66c Mon Sep 17 00:00:00 2001 From: Doug Parker Date: Mon, 2 May 2022 21:24:40 -0700 Subject: [PATCH] Removes `css_group()` from public API. This actually isn't necessary because it's only use case was `prerender_resources(inline_styles = [...])`, but that has no valid external use case because `prerender_resources()` is intended for rendering non-HTML content (binary/text/JSON/... files). Users who want to render HTML, should be using `prerender_pages()` or `prerender_pages_unbundled()`, and not calling `prerender_resources()` directly. `prerender_resources_internal()` allows use of `inline_styles` but is only available internally in `rules_prerender`, and is *not* public API. --- index.bzl | 5 ---- .../prerender_pages_unbundled.bzl | 4 +-- .../rules_prerender/prerender_resources.bzl | 25 +++++++++++++++++-- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/index.bzl b/index.bzl index 46d40857..9b70ef66 100644 --- a/index.bzl +++ b/index.bzl @@ -36,16 +36,11 @@ load( "//packages/rules_prerender:web_resources_devserver.bzl", _web_resources_devserver = "web_resources_devserver", ) -load( - "//packages/rules_prerender/css:css_group.bzl", - _css_group = "css_group", -) load( "//packages/rules_prerender/css:css_library.bzl", _css_library = "css_library", ) -css_group = _css_group css_library = _css_library extract_single_resource = _extract_single_resource inject_resources = _inject_resources diff --git a/packages/rules_prerender/prerender_pages_unbundled.bzl b/packages/rules_prerender/prerender_pages_unbundled.bzl index 1cbec303..cc7e0761 100644 --- a/packages/rules_prerender/prerender_pages_unbundled.bzl +++ b/packages/rules_prerender/prerender_pages_unbundled.bzl @@ -5,7 +5,7 @@ load("@npm//@bazel/concatjs:index.bzl", "ts_library") load("//common:label.bzl", "absolute", "file_path_of") load(":entry_points.bzl", "script_entry_point", "style_entry_point") load(":prerender_component.bzl", "prerender_component") -load(":prerender_resources.bzl", "prerender_resources") +load(":prerender_resources.bzl", "prerender_resources_internal") load(":web_resources.bzl", "WebResourceInfo", "web_resources") def prerender_pages_unbundled( @@ -126,7 +126,7 @@ def prerender_pages_unbundled( if src.endswith(".ts") else src ) - prerender_resources( + prerender_resources_internal( name = annotated, entry_point = file_path_of(absolute(js_src)), inline_styles = ":%s" % component_inline_styles, diff --git a/packages/rules_prerender/prerender_resources.bzl b/packages/rules_prerender/prerender_resources.bzl index ace1397e..eac6c821 100644 --- a/packages/rules_prerender/prerender_resources.bzl +++ b/packages/rules_prerender/prerender_resources.bzl @@ -22,7 +22,7 @@ def prerender_resources( The file listed in `entry` must be included in the `data` attribute as a CommonJS module with a default export of the type: - + ``` () => Iterable | Promise> | AsyncIterable @@ -48,7 +48,7 @@ def prerender_resources( Outputs: %{name}: A `web_resources()`-compatible target containing all the files generated at their corresponding locations. - + Args: name: The name of this rule. entry_point: The JavaScript entry point to use to execute the given @@ -63,6 +63,27 @@ def prerender_resources( testonly: See https://docs.bazel.build/versions/master/be/common-definitions.html. visibility: See https://docs.bazel.build/versions/master/be/common-definitions.html. """ + prerender_resources_internal( + name = name, + entry_point = entry_point, + data = data, + testonly = testonly, + visibility = visibility, + # Not supported in public API because this would require exposing `css_group()` or + # `css_binaries()` and is only useful for prerendering HTML pages which should be + # done with `prerender_pages()`, not `prerender_resources()`. + inline_styles = None, + ) + +def prerender_resources_internal( + name, + entry_point, + data, + inline_styles = None, + testonly = None, + visibility = None, +): + """Internal version of `prerender_resources()` which allows `inline_styles` usage.""" # Validate `entry_point`. if "/" not in entry_point or not is_js_file(entry_point): fail(("`entry_point` (%s) *must* be a workspace-relative path of the"