Skip to content

Commit

Permalink
Removes css_group() from public API.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dgp1130 committed May 3, 2022
1 parent 0b0adc6 commit e84df1d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
5 changes: 0 additions & 5 deletions index.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions packages/rules_prerender/prerender_pages_unbundled.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down
25 changes: 23 additions & 2 deletions packages/rules_prerender/prerender_resources.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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<PrerenderResource> | Promise<Iterable<PrerenderResource>>
| AsyncIterable<PrerenderResource>
Expand All @@ -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
Expand All @@ -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"
Expand Down

0 comments on commit e84df1d

Please sign in to comment.