Skip to content

Commit

Permalink
Removes @build_bazel_rules_nodejs provider usage.
Browse files Browse the repository at this point in the history
Refs #63.

We don't support `@build_bazel_rules_nodejs` targets, so these providers are never observed. Just supporting `JsInfo` should be all we need.
  • Loading branch information
dgp1130 committed Feb 18, 2023
1 parent 3898fbe commit 287b21c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 95 deletions.
108 changes: 18 additions & 90 deletions packages/rules_prerender/prerender_component.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@

load("@aspect_rules_js//js:defs.bzl", "js_library")
load("@aspect_rules_js//js:providers.bzl", "JsInfo", "js_info")
load(
"@build_bazel_rules_nodejs//:providers.bzl",
"DeclarationInfo",
"JSModuleInfo",
"JSEcmaScriptModuleInfo",
)
load("@aspect_rules_ts//ts:defs.bzl", "ts_project")
load("//common:label.bzl", "absolute")
load("//common:paths.bzl", "is_js_file")
Expand Down Expand Up @@ -150,127 +144,61 @@ which are always allowed).
)

def _js_reexport_impl(ctx):
for target in ctx.attr.srcs + ctx.attr.deps:
if DeclarationInfo in target: continue
if JsInfo in target: continue
if JSModuleInfo in target: continue
if JSEcmaScriptModuleInfo in target: continue

fail("Dependency (%s) does not include any of the required providers." % target.label)

merged_declaration_info = DeclarationInfo(
declarations = depset([],
transitive = [src[DeclarationInfo].declarations
for src in ctx.attr.srcs
if DeclarationInfo in src],
),
transitive_declarations = depset([],
transitive = [dep[DeclarationInfo].transitive_declarations
for dep in ctx.attr.srcs + ctx.attr.deps
if DeclarationInfo in dep],
),
type_blocklisted_declarations = depset([],
transitive = [dep[DeclarationInfo].type_blocklisted_declarations
for dep in ctx.attr.srcs + ctx.attr.deps
if DeclarationInfo in dep],
),
)

merged_js_info = js_info(
declarations = depset([],
transitive = [src[JsInfo].declarations
for src in ctx.attr.srcs
if JsInfo in src],
for src in ctx.attr.srcs],
),
npm_linked_package_files = depset([],
transitive = [src[JsInfo].npm_linked_package_files
for src in ctx.attr.srcs
if JsInfo in src],
for src in ctx.attr.srcs],
),
npm_linked_packages = depset([],
transitive = [src[JsInfo].npm_linked_packages
for src in ctx.attr.srcs
if JsInfo in src],
for src in ctx.attr.srcs],
),
npm_package_store_deps = depset([],
transitive = [src[JsInfo].npm_package_store_deps
for src in ctx.attr.srcs
if JsInfo in src],
for src in ctx.attr.srcs],
),
sources = depset([],
transitive = [src[JsInfo].sources
for src in ctx.attr.srcs
if JsInfo in src],
for src in ctx.attr.srcs],
),
transitive_declarations = depset([],
transitive = [dep[JsInfo].transitive_declarations
for dep in ctx.attr.srcs + ctx.attr.deps
if JsInfo in dep],
for dep in ctx.attr.srcs + ctx.attr.deps],
),
transitive_npm_linked_package_files = depset([],
transitive = [dep[JsInfo].transitive_npm_linked_package_files
for dep in ctx.attr.srcs + ctx.attr.deps
if JsInfo in dep],
for dep in ctx.attr.srcs + ctx.attr.deps],
),
transitive_npm_linked_packages = depset([],
transitive = [dep[JsInfo].transitive_npm_linked_packages
for dep in ctx.attr.srcs + ctx.attr.deps
if JsInfo in dep],
for dep in ctx.attr.srcs + ctx.attr.deps],
),
transitive_sources = depset([],
transitive = [dep[JsInfo].transitive_sources
for dep in ctx.attr.srcs + ctx.attr.deps
if JsInfo in dep],
),
)

merged_js_module_info = JSModuleInfo(
direct_sources = depset([],
transitive = [src[JSModuleInfo].direct_sources
for src in ctx.attr.srcs
if JSModuleInfo in src],
),
sources = depset([],
transitive = [dep[JSModuleInfo].sources
for dep in ctx.attr.srcs + ctx.attr.deps
if JSModuleInfo in dep],
),
)

merged_js_ecma_script_module_info = JSEcmaScriptModuleInfo(
direct_sources = depset([],
transitive = [src[JSEcmaScriptModuleInfo].direct_sources
for src in ctx.attr.srcs
if JSEcmaScriptModuleInfo in src],
for dep in ctx.attr.srcs + ctx.attr.deps],
),
sources = depset([],
transitive = [dep[JSEcmaScriptModuleInfo].sources
for dep in ctx.attr.srcs + ctx.attr.deps
if JSEcmaScriptModuleInfo in dep],
),
)

# Replicates output groups for TS/JS rules. Mostly for debugging purposes.
# https://bazelbuild.github.io/rules_nodejs/TypeScript.html#accessing-javascript-outputs
output_group_info = OutputGroupInfo(
es5_sources = merged_js_module_info.direct_sources,
es6_sources = merged_js_ecma_script_module_info.direct_sources,
)

return [
DefaultInfo(files = merged_declaration_info.declarations),
merged_declaration_info,
DefaultInfo(files = merged_js_info.sources),
merged_js_info,
merged_js_module_info,
merged_js_ecma_script_module_info,
output_group_info,
]

_js_reexport = rule(
implementation = _js_reexport_impl,
attrs = {
"srcs": attr.label_list(default = []),
"deps": attr.label_list(default = []),
"srcs": attr.label_list(
default = [],
providers = [JsInfo],
),
"deps": attr.label_list(
default = [],
providers = [JsInfo],
),
},
doc = """
Re-exports the given `ts_project()` and `js_library()` targets. Targets
Expand Down
5 changes: 0 additions & 5 deletions packages/rules_prerender/prerender_pages.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@

load("@aspect_bazel_lib//lib:copy_file.bzl", "copy_file")
load("@aspect_rules_rollup//rollup:defs.bzl", "rollup_bundle")
load(
"@build_bazel_rules_nodejs//:providers.bzl",
"JSEcmaScriptModuleInfo",
"JSModuleInfo",
)
load(":multi_inject_resources.bzl", "multi_inject_resources")
load(":prerender_pages_unbundled.bzl", "prerender_pages_unbundled")
load(":web_resources.bzl", "web_resources")
Expand Down

0 comments on commit 287b21c

Please sign in to comment.