Skip to content

Commit

Permalink
Updates prerender_component_publish_files to be compatible with `pr…
Browse files Browse the repository at this point in the history
…erender_component2`.

Refs #40.

Most notably, `prerender_component2` does not create targets for `_styles` and `_resources` if they aren't needed, so we need to optionally skip processing them.
  • Loading branch information
dgp1130 committed Jul 23, 2023
1 parent a5eed67 commit de6f413
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 18 deletions.
32 changes: 24 additions & 8 deletions packages/rules_prerender/prerender_component_publish_files.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ visibility(["//"])
def prerender_component_publish_files(
name,
dep,
collect_styles = True,
collect_resources = True,
testonly = None,
**kwargs,
):
Expand All @@ -23,6 +25,12 @@ def prerender_component_publish_files(
Params:
name: The name of this target.
dep: The `prerender_component()` to publish.
collect_scripts: Whether or not to collect and publish client-side
scripts. Should only be disabled if there are no scripts to collect.
collect_styles: Whether or not to collect and publish CSS styles. Should
only be disabled if there are no styles to collect.
collect_resources: Whether or not to collect and publish resources.
Should only be disabled if there are no resources to collect.
**kwargs: Remaining arguments to pass through to the underlying target.
Outputs:
Expand Down Expand Up @@ -63,17 +71,25 @@ def prerender_component_publish_files(
testonly = testonly,
)

files = [
":%s" % prerender_dts,
":%s" % prerender_js,
":%s" % scripts_dts,
":%s" % scripts_js,
]

# Collect CSS files.
if collect_styles:
files.append("%s_styles" % absolute_name)

# Collect static resources.
if collect_resources:
files.append("%s_resources" % absolute_name)

# Collect all the files to be published for the component.
native.filegroup(
name = name,
srcs = [
":%s" % prerender_dts,
":%s" % prerender_js,
":%s" % scripts_dts,
":%s" % scripts_js,
"%s_styles" % absolute_name, # inlined `*.css` files.
"%s_resources" % absolute_name, # resource files.
],
srcs = files,
testonly = testonly,
**kwargs
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ describe('prerender_component_publish_files()', () => {
'script_dep.d.mts',
// Temporary bad assertion. Need to update component publishing to copy
// styles into the correct position in the NPM package.
'component_styles_bin_binary_0',
'component_resources', // from `resources` attribute.
'component_styles_reexport_binary_0',
'resources', // from `resources` attribute.
]);

const actualFiles = new Set(await fs.readdir(root));
Expand All @@ -30,7 +30,7 @@ describe('prerender_component_publish_files()', () => {

// Separately test for the resources directory.
const expectedResources = new Set([ 'resource.txt' ]);
const actualResources = new Set(await fs.readdir(`${root}/component_resources`));
const actualResources = new Set(await fs.readdir(`${root}/resources`));
expect(actualResources).toEqual(expectedResources);
});
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
load(
"//:index.bzl",
"prerender_component",
prerender_component = "prerender_component2",
"prerender_component_publish_files",
)
load("//packages/rules_prerender:web_resources.bzl", "web_resources")
Expand All @@ -10,13 +10,16 @@ load("//tools/typescript:defs.bzl", "ts_project")

prerender_component(
name = "component",
prerender = ":prerender",
scripts = ":scripts",
styles = ":styles",
resources = ":resources",
)

ts_project(
name = "prerender",
srcs = ["component.mts"],
tsconfig = "//:tsconfig",
source_map = True,
lib_deps = [":prerender_dep"],
scripts = [":scripts"],
styles = [":styles"],
resources = [":resources"],
deps = [":prerender_dep"],
)

ts_project(
Expand Down

0 comments on commit de6f413

Please sign in to comment.