diff --git a/bazel/extract_types.bzl b/bazel/extract_types.bzl index 62b667dba..fb927a792 100644 --- a/bazel/extract_types.bzl +++ b/bazel/extract_types.bzl @@ -1,14 +1,15 @@ -load("@build_bazel_rules_nodejs//:providers.bzl", "DeclarationInfo") +load("@aspect_rules_js//js:providers.bzl", "JsInfo") def _extract_types_impl(ctx): """Implementation of the `extract_types` rule.""" - depsets = [] + types_files = [] for dep in ctx.attr.deps: - if DeclarationInfo in dep: - depsets.append(dep[DeclarationInfo].transitive_declarations) + if JsInfo in dep: + types_files.extend(dep[JsInfo].transitive_types.to_list()) + types_files.extend(dep[JsInfo].types.to_list()) - types = depset(transitive = depsets) + types = depset([file for file in types_files if file.short_path.startswith(ctx.label.package)]) return [ DefaultInfo(files = types), diff --git a/bazel/extract_types_rjs.bzl b/bazel/extract_types_rjs.bzl deleted file mode 100644 index eff95345a..000000000 --- a/bazel/extract_types_rjs.bzl +++ /dev/null @@ -1,35 +0,0 @@ -load("@aspect_rules_js//js:providers.bzl", "JsInfo") - -def _extract_types_impl(ctx): - """Implementation of the `extract_types` rule.""" - depsets = [] - - for dep in ctx.attr.deps: - if JsInfo in dep: - depsets.append(dep[JsInfo].transitive_types) - depsets.append(dep[JsInfo].types) - - types = depset(transitive = depsets) - - return [ - DefaultInfo(files = types), - ] - -extract_types = rule( - implementation = _extract_types_impl, - doc = """ - Rule that collects all direct and transitive type definitions of specified targets. The - definitons are then exposed through the `DefaultInfo` provider, allowing for easy - consumption in other rules. - - This rule can be helpful if TypeScript typings are shipped along with bundled runtime code. - """, - attrs = { - "deps": attr.label_list( - doc = """List of targets for which all direct and transitive type definitions - should be collected.""", - allow_files = True, - mandatory = True, - ), - }, -) diff --git a/bazel/test/BUILD.bazel b/bazel/test/BUILD.bazel index cf062551c..cf93de239 100644 --- a/bazel/test/BUILD.bazel +++ b/bazel/test/BUILD.bazel @@ -1,18 +1,21 @@ +load("@aspect_rules_ts//ts:defs.bzl", "ts_project") load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_test") -load("//bazel:defaults.bzl", "ts_library") load("//bazel:extract_types.bzl", "extract_types") -load("//bazel:extract_js_module_output.bzl", "extract_js_module_output") -ts_library( +ts_project( name = "transitive_lib", testonly = True, srcs = ["transitive_file.ts"], + declaration = True, + tsconfig = "//bazel:tsconfig", ) -ts_library( +ts_project( name = "test_lib", testonly = True, srcs = ["fixture.ts"], + declaration = True, + tsconfig = "//bazel:tsconfig", deps = [":transitive_lib"], ) @@ -28,30 +31,9 @@ extract_types( deps = [":test_lib"], ) -extract_js_module_output( - name = "extract_js_module_output_target", - testonly = True, - forward_linker_mappings = True, - include_declarations = True, - include_default_files = True, - include_external_npm_packages = True, - provider = "JSModuleInfo", - deps = [ - ":test_lib", - ":text_fixture", - ], -) - nodejs_test( name = "extract_types_test", data = [":extract_types_target"], entry_point = "extract_types_test.js", templated_args = ["$(rootpaths :extract_types_target)"], ) - -nodejs_test( - name = "extract_js_module_test", - data = [":extract_js_module_output_target"], - entry_point = "extract_js_module_test.js", - templated_args = ["$(rootpaths :extract_js_module_output_target)"], -) diff --git a/bazel/test/extract_js_module_test.js b/bazel/test/extract_js_module_test.js deleted file mode 100644 index 5ef2ca278..000000000 --- a/bazel/test/extract_js_module_test.js +++ /dev/null @@ -1,20 +0,0 @@ -const assert = require('assert'); - -/** - * Files exposed through the `extract_js_module_output` target are passed - * as command line arguments. - */ -const extractedFileRootpaths = process.argv.slice(2); - -assert.deepStrictEqual(extractedFileRootpaths, [ - // TypeScript files transitively added to every `ts_library` target. This might be - // cleaned up in the future, but is captured in this test as it rarely should change. - '../npm/node_modules/typescript/lib/tsserverlibrary.d.ts', - '../npm/node_modules/typescript/lib/typescript.d.ts', - // Actual workspace-local extracted files. - 'bazel/test/fixture.d.ts', - 'bazel/test/fixture.js', - 'bazel/test/fixture.txt', - 'bazel/test/transitive_file.d.ts', - 'bazel/test/transitive_file.js', -]); diff --git a/bazel/test/extract_types_test.js b/bazel/test/extract_types_test.js index 856cb6529..6be107d6e 100644 --- a/bazel/test/extract_types_test.js +++ b/bazel/test/extract_types_test.js @@ -4,10 +4,6 @@ const assert = require('assert'); const typeRootpaths = process.argv.slice(2); assert.deepStrictEqual(typeRootpaths, [ - // TypeScript types transitively added to every `ts_library` target. This might be - // cleaned up in the future, but is captured in this test as it rarely should change. - '../npm/node_modules/typescript/lib/tsserverlibrary.d.ts', - '../npm/node_modules/typescript/lib/typescript.d.ts', // Actual workspace-local `d.ts` files. 'bazel/test/fixture.d.ts', 'bazel/test/transitive_file.d.ts',