Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update to rules_js 1.1.0 #133

Merged
merged 1 commit into from
Aug 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ module(

bazel_dep(name = "bazel_skylib", version = "1.1.1")
bazel_dep(name = "rules_nodejs", version = "5.5.0")
bazel_dep(name = "aspect_rules_js", version = "1.0.0")
bazel_dep(name = "aspect_bazel_lib", version = "1.9.2")
bazel_dep(name = "aspect_rules_js", version = "1.1.0")
bazel_dep(name = "aspect_bazel_lib", version = "1.11.1")
2 changes: 1 addition & 1 deletion docs/rules.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion e2e/worker/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,17 @@ load("@aspect_rules_js//npm:npm_import.bzl", "npm_translate_lock")

npm_translate_lock(
name = "npm",
# Running lifecycle hooks on npm package @nestjs/[email protected]_9fad833c066e70b3b5e6d773402fdc0f fails in a dramatic way:
# ```
# SyntaxError: Unexpected strict mode reserved word
# at ESMLoader.moduleStrategy (node:internal/modules/esm/translators:117:18)
# at ESMLoader.moduleProvider (node:internal/modules/esm/loader:337:14)
# at async link (node:internal/modules/esm/module_job:70:21)
# ```
lifecycle_hooks_no_sandbox = False,
gregmagolan marked this conversation as resolved.
Show resolved Hide resolved
pnpm_lock = "//:pnpm-lock.yaml",
)

load("@npm//:repositories.bzl", "npm_repositories")

npm_repositories()
npm_repositories()
10 changes: 2 additions & 8 deletions examples/dts_lib/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
load("@aspect_rules_js//js:defs.bzl", "js_library")
load("@aspect_rules_ts//ts:defs.bzl", "ts_project")
load("@aspect_rules_js//npm:defs.bzl", "npm_package")
load("@bazel_skylib//rules:build_test.bzl", "build_test")

ts_project(
name = "lib_ts",
name = "lib",
srcs = [
"index.ts",
"lib_types.d.ts",
Expand All @@ -13,14 +12,9 @@ ts_project(
declaration = True,
)

js_library(
name = "lib",
deps = [":lib_ts"],
)

npm_package(
name = "dts_lib",
srcs = [":lib_ts"],
srcs = [":lib"],
package = "@myorg/dts_lib",
visibility = ["//examples:__subpackages__"],
)
Expand Down
47 changes: 28 additions & 19 deletions ts/private/ts_project.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ def _ts_project_impl(ctx):
Returns:
list of providers
"""
srcs = [_lib.relative_to_package(src.path, ctx) for src in ctx.files.srcs]
srcs_inputs = copy_files_to_bin_actions(ctx, ctx.files.srcs)

srcs = [_lib.relative_to_package(src.path, ctx) for src in srcs_inputs]

# Recalculate outputs inside the rule implementation.
# The outs are first calculated in the macro in order to try to predetermine outputs so they can be declared as
Expand Down Expand Up @@ -85,18 +87,11 @@ def _ts_project_impl(ctx):
"--extendedDiagnostics",
])

inputs = ctx.files.srcs[:]
inputs = srcs_inputs[:]
for dep in ctx.attr.deps:
if ValidOptionsInfo in dep:
inputs.append(dep[ValidOptionsInfo].marker)

inputs.extend(js_lib_helpers.gather_files_from_js_providers(
targets = ctx.attr.srcs + ctx.attr.deps,
include_transitive_sources = True,
include_declarations = True,
include_npm_linked_packages = True,
))

# Gather TsConfig info from both the direct (tsconfig) and indirect (extends) attribute
tsconfig_inputs = copy_files_to_bin_actions(ctx, _validate_lib.tsconfig_inputs(ctx))
inputs.extend(tsconfig_inputs)
Expand All @@ -111,7 +106,7 @@ def _ts_project_impl(ctx):
rootdir_replace_pattern = ctx.attr.root_dir + "/" if ctx.attr.root_dir else ""
json_outs = _lib.declare_outputs(ctx, [
_lib.join(ctx.attr.out_dir, src.short_path[pkg_len:].replace(rootdir_replace_pattern, ""))
for src in ctx.files.srcs
for src in srcs_inputs
if src.basename.endswith(".json") and src.is_source
])
else:
Expand All @@ -125,7 +120,7 @@ def _ts_project_impl(ctx):
])
outputs.append(ctx.outputs.buildinfo_out)
output_sources = json_outs + js_outs + map_outs
typings_srcs = [s for s in ctx.files.srcs if _lib.is_typings_src(s.path)]
typings_srcs = [s for s in srcs_inputs if _lib.is_typings_src(s.path)]

if len(js_outs) + len(typings_outs) < 1:
label = "//{}:{}".format(ctx.label.package, ctx.label.name)
Expand Down Expand Up @@ -178,9 +173,19 @@ This is an error because Bazel does not run actions unless their outputs are nee
default_outputs = []

if len(outputs) > 0:
inputs = depset(
copy_files_to_bin_actions(ctx, inputs),
transitive = [js_lib_helpers.gather_files_from_js_providers(
targets = ctx.attr.srcs + ctx.attr.deps,
include_transitive_sources = True,
include_declarations = True,
include_npm_linked_packages = True,
)],
)

ctx.actions.run(
executable = executable,
inputs = copy_files_to_bin_actions(ctx, inputs),
inputs = inputs,
arguments = [arguments],
outputs = outputs,
mnemonic = "TsProject",
Expand All @@ -203,13 +208,16 @@ This is an error because Bazel does not run actions unless their outputs are nee
deps = ctx.attr.deps,
)

npm_package_stores = js_lib_helpers.gather_npm_package_stores(
npm_package_store_deps = js_lib_helpers.gather_npm_package_store_deps(
targets = ctx.attr.data,
)

output_declarations_depset = depset(output_declarations)
output_sources_depset = depset(output_sources)

runfiles = js_lib_helpers.gather_runfiles(
ctx = ctx,
sources = output_sources,
sources = output_sources_depset,
data = ctx.attr.data,
deps = ctx.attr.srcs + ctx.attr.deps,
)
Expand All @@ -220,13 +228,14 @@ This is an error because Bazel does not run actions unless their outputs are nee
runfiles = runfiles,
),
js_info(
declarations = output_declarations,
declarations = output_declarations_depset,
npm_linked_package_files = npm_linked_packages.direct_files,
npm_linked_packages = npm_linked_packages.direct,
npm_package_stores = npm_package_stores.direct,
sources = output_sources,
npm_package_store_deps = npm_package_store_deps,
sources = output_sources_depset,
transitive_declarations = transitive_declarations,
transitive_npm_linked_package_files = npm_linked_packages.transitive_files,
transitive_npm_linked_packages = npm_linked_packages.transitive,
transitive_npm_package_stores = npm_package_stores.transitive,
transitive_sources = transitive_sources,
),
TsConfigInfo(deps = depset(tsconfig_inputs, transitive = [
Expand All @@ -235,7 +244,7 @@ This is an error because Bazel does not run actions unless their outputs are nee
if TsConfigInfo in dep
])),
OutputGroupInfo(
types = depset(output_declarations),
types = output_declarations_depset,
),
coverage_common.instrumented_files_info(
ctx,
Expand Down
12 changes: 6 additions & 6 deletions ts/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,17 @@ def rules_ts_dependencies(ts_version_from = None, ts_version = None, ts_integrit
maybe(
http_archive,
name = "aspect_rules_js",
sha256 = "538049993bec3ee1ae9b1c3cd669156bca04eb67027b222883e47b0a2aed2e67",
strip_prefix = "rules_js-1.0.0",
url = "https://github.com/aspect-build/rules_js/archive/refs/tags/v1.0.0.tar.gz",
sha256 = "25bcb082d49616ac2da538bf7bdd33a9730c8884edbec787fec83db07e4f7f16",
strip_prefix = "rules_js-1.1.0",
url = "https://github.com/aspect-build/rules_js/archive/refs/tags/v1.1.0.tar.gz",
)

maybe(
http_archive,
name = "aspect_bazel_lib",
sha256 = "e034e4aea098c91ac05ac7e08f01a302275378a0bc0814c4939e96552c912212",
strip_prefix = "bazel-lib-1.9.2",
url = "https://github.com/aspect-build/bazel-lib/archive/refs/tags/v1.9.2.tar.gz",
sha256 = "8ea64f13c6db68356355d6a97dced3d149e9cd7ba3ecb4112960586e914e466d",
strip_prefix = "bazel-lib-1.11.1",
url = "https://github.com/aspect-build/bazel-lib/archive/refs/tags/v1.11.1.tar.gz",
)

npm_dependencies(ts_version_from = ts_version_from, ts_version = ts_version, ts_integrity = ts_integrity)
2 changes: 1 addition & 1 deletion ts/test/transpiler_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def _impl0(ctx):
env = unittest.begin(ctx)

decls = []
for decl in ctx.attr.lib[JsInfo].declarations:
for decl in ctx.attr.lib[JsInfo].declarations.to_list():
decls.append(decl.basename)
asserts.equals(env, ctx.attr.expected_declarations, sorted(decls))

Expand Down