aspect-build / rules_ts

Bazel rules for the `tsc` compiler from http://typescriptlang.org
https://docs.aspect.build/rules/aspect_rules_ts
Apache License 2.0
104 stars 58 forks source link

[Bug]: copy_files = True for ts_proto_library doesn't copy d.ts files to source tree #545

Open SinimaWath opened 8 months ago

SinimaWath commented 8 months ago

What happened?

Read that ts_proto_library copy generated files automaticly to source tree: https://github.com/aspect-build/rules_ts/blob/main/ts/proto.bzl#L59

   copy_files: whether to copy the resulting .d.ts files back to the source tree, for the editor to locate them.

But that behaviour doesn't work in rule_ts examples

Version

Development (host) and target OS/architectures: MacOS, darwin_arm64

Output of bazel --version: aspect 5.8.19

Version of the Aspect rules, or other relevant rules from your WORKSPACE or MODULE.bazel file: Reproducing in source code of https://github.com/aspect-build/rules_ts/

Language(s) and/or frameworks involved: Reproducing in source code of https://github.com/aspect-build/rules_ts/

How to reproduce

1 - git clone https://github.com/aspect-build/rules_ts.git
2 - cd rules_ts/examples/proto_grpc
3 - rm -rf logger_connect.d.ts logger_pb.d.ts
4 - bazel build proto_grpc

Expected:
logger_connect.d.ts logger_pb.d.ts was copied from `output`

Actual:
Nothing was copied

INFO: Analyzed target //examples/proto_grpc:proto_grpc (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
Target //examples/proto_grpc:proto_grpc up-to-date:
  bazel-bin/examples/proto_grpc/main.js
INFO: Elapsed time: 0.143s, Critical Path: 0.00s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action


### Any other information?

_No response_
SinimaWath commented 8 months ago

Read again code of ts_proto_library.

As I understand, generating and copy files on bazel build proto_grpc was not even planned (Am I right?)

And I need to run bazel run logger_ts_proto.copy before bazel build proto_grpc to always have updated typings:

bazel run logger_ts_proto.copy && bazel build proto_grpc

Maybe there is a way to make it easier in Bazel?

ordogfioka commented 7 months ago

When the copy_files is True in ts_proto_library it generates the *.copy_0 and *.copy_0_test bazel targets.

When running bazel build //..., the build fails because the *.copy_0_test will fail until the *.copy_0 target is called (or command with same effect)

Is there a way to prevent ts_proto_library to create the *.copy_0_test targets or not to build when bazel build //... is called? Based on this I think it is not, but would be very welcome.

sbussard commented 3 months ago

Using bzlmod, bazel 7 and aspect_rules_ts 3.0.0-rc1

According this document there should be an attribute for proto_srcs but I haven't found anything related to that in this file

image

sbussard commented 3 months ago

Downgrading to aspect_rules_ts 2.4.2 (also ubuntu 22.04)

I get this error

ERROR: /path/to/project/proto/BUILD:16:17: in ts_proto_library rule //project/proto:hello_world_ts_proto: 
Traceback (most recent call last):
        File "/home/username/.cache/bazel/username/965fb35944158111184471dacc5db77b/external/aspect_rules_ts~/ts/private/ts_proto_library.bzl", line 101, column 53, in _ts_proto_library_impl
                transitive_declarations = js_lib_helpers.gather_transitive_declarations(
Error: 'struct' value has no field or method 'gather_transitive_declarations'
Available attributes: envs_for_log_level, gather_files_from_js_infos, gather_npm_package_store_infos, gather_npm_sources, gather_runfiles, gather_transitive_sources, gather_transitive_types
ERROR: /path/to/project/proto/BUILD:16:17: Analysis of target '//project/proto:hello_world_ts_proto' failed
ERROR: Analysis of target '//project/proto:hello_world_ts_proto' failed; build aborted
INFO: Elapsed time: 11.196s, Critical Path: 0.10s
INFO: 1 process: 1 internal.
ERROR: Build did NOT complete successfully