From e1ab6ef39e3e1a093da62b1a44ff1cc4422027f5 Mon Sep 17 00:00:00 2001 From: Greg Magolan Date: Fri, 26 Aug 2022 00:16:38 -0700 Subject: [PATCH] chore: update to rules_js 1.1.0 --- MODULE.bazel | 4 +-- docs/rules.md | 2 +- e2e/worker/WORKSPACE | 10 +++++++- examples/dts_lib/BUILD.bazel | 10 ++------ ts/private/ts_project.bzl | 47 +++++++++++++++++++++--------------- ts/repositories.bzl | 12 ++++----- ts/test/transpiler_tests.bzl | 2 +- 7 files changed, 49 insertions(+), 38 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index a83117cf..460ed9cd 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -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") diff --git a/docs/rules.md b/docs/rules.md index 8b0ba446..68d5c004 100644 --- a/docs/rules.md +++ b/docs/rules.md @@ -60,7 +60,7 @@ Implementation rule behind the ts_project macro. | args | https://www.typescriptlang.org/docs/handbook/compiler-options.html | List of strings | optional | [] | | buildinfo_out | Location in bazel-out where tsc will write a .tsbuildinfo file | Label | optional | | | composite | https://www.typescriptlang.org/tsconfig#composite | Boolean | optional | False | -| data | Runtime dependencies to include in binaries/tests that depend on this target.

The transitive npm dependencies, transitive sources, default outputs and runfiles of targets in the data attribute are added to the runfiles of this taregt. Thery should appear in the '*.runfiles' area of any executable which has a runtime dependency on this target.

If this list contains linked npm packages, npm package store targets or other targets that provide JsInfo, NpmPackageStoreInfo providers are gathered from JsInfo. This is done directly from npm_package_stores and transitive_npm_package_stores fields of these and for linked npm package targets, from the underlying npm_package_store target(s) that back the links via npm_linked_packages and transitive_npm_linked_packages.

Gathered NpmPackageStoreInfo providers are used downstream as direct dependencies when linking a downstream npm_package target with npm_link_package. | List of labels | optional | [] | +| data | Runtime dependencies to include in binaries/tests that depend on this target.

The transitive npm dependencies, transitive sources, default outputs and runfiles of targets in the data attribute are added to the runfiles of this taregt. Thery should appear in the '*.runfiles' area of any executable which has a runtime dependency on this target.

If this list contains linked npm packages, npm package store targets or other targets that provide JsInfo, NpmPackageStoreInfo providers are gathered from JsInfo. This is done directly from the npm_package_store_deps field of these. For linked npm package targets, the underlying npm_package_store target(s) that back the links is used.

Gathered NpmPackageStoreInfo providers are used downstream as direct dependencies when linking a downstream npm_package target with npm_link_package. | List of labels | optional | [] | | declaration | https://www.typescriptlang.org/tsconfig#declaration | Boolean | optional | False | | declaration_dir | https://www.typescriptlang.org/tsconfig#declarationDir | String | optional | "" | | declaration_map | https://www.typescriptlang.org/tsconfig#declarationMap | Boolean | optional | False | diff --git a/e2e/worker/WORKSPACE b/e2e/worker/WORKSPACE index db3eb590..551fb3c1 100644 --- a/e2e/worker/WORKSPACE +++ b/e2e/worker/WORKSPACE @@ -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/core@9.0.8_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, pnpm_lock = "//:pnpm-lock.yaml", ) load("@npm//:repositories.bzl", "npm_repositories") -npm_repositories() \ No newline at end of file +npm_repositories() diff --git a/examples/dts_lib/BUILD.bazel b/examples/dts_lib/BUILD.bazel index b0008fe1..fa2c13cc 100644 --- a/examples/dts_lib/BUILD.bazel +++ b/examples/dts_lib/BUILD.bazel @@ -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", @@ -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__"], ) diff --git a/ts/private/ts_project.bzl b/ts/private/ts_project.bzl index ba767a54..ae7f6c98 100644 --- a/ts/private/ts_project.bzl +++ b/ts/private/ts_project.bzl @@ -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 @@ -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) @@ -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: @@ -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) @@ -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", @@ -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, ) @@ -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 = [ @@ -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, diff --git a/ts/repositories.bzl b/ts/repositories.bzl index 4ecdf8ef..88fc6a8f 100644 --- a/ts/repositories.bzl +++ b/ts/repositories.bzl @@ -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) diff --git a/ts/test/transpiler_tests.bzl b/ts/test/transpiler_tests.bzl index c8a1816d..ab36c6f0 100644 --- a/ts/test/transpiler_tests.bzl +++ b/ts/test/transpiler_tests.bzl @@ -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))