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
105 stars 59 forks source link

[Bug]: Source generated by conflicting actions when importing js into ts #707

Open aptenodytes-forsteri opened 5 days ago

aptenodytes-forsteri commented 5 days ago

What happened?

When importing js into ts while also transpiling with swc, rules_ts produces an error.

Repro case here: https://github.com/aptenodytes-forsteri/ts_js_interop

Version

Development (host) and target OS/architectures: Ubuntu 22.04

Output of bazel --version: bazel 7.3.2

Version of the Aspect rules, or other relevant rules from your WORKSPACE or MODULE.bazel file:

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_file")

http_archive(
        name = "aspect_rules_js",
        sha256 = "4cab6898f0ff8048e32640cce06a47aa4b92b2fb330d055940f95f24c8ebb868",
        strip_prefix = "rules_js-2.0.1",
        url = "https://github.com/aspect-build/rules_js/releases/download/v2.0.1/rules_js-v2.0.1.tar.gz",
    )

http_archive(
    name = "aspect_rules_ts",
    sha256 = "5aafa2422b6f2ed6d8db9edcd6368693055960bca7e149516b95c0d45a6a7ae5",
    strip_prefix = "rules_ts-3.1.0",
    url = "https://github.com/aspect-build/rules_ts/releases/download/v3.1.0/rules_ts-v3.1.0.tar.gz",
)

http_archive(
    name = "aspect_rules_swc",
    sha256 = "d63d7b283249fa942f78d2716ecff3edbdc10104ee1b9a6b9464ece471ef95ea",
    strip_prefix = "rules_swc-2.0.0",
    url = "https://github.com/aspect-build/rules_swc/releases/download/v2.0.0/rules_swc-v2.0.0.tar.gz",
)

Language(s) and/or frameworks involved: js / ts

How to reproduce

Clone https://github.com/aptenodytes-forsteri/ts_js_interop/tree/main

bazel build //...

More generally, attempt to import javascript into typescript. We have some code that has not been converted to typescript. We had successfully been importing this javascript into our typescript. Now, we get errors about conflicting source files.

Any other information?

No response

jbedard commented 3 days ago

Thanks for the good repro. I think this is fixed in the latest rules_ts release though, mainly just as a side-effect of adding declarations_transpiler and no_emit features. Can you try it out?

aptenodytes-forsteri commented 2 days ago

Yes, 3.2.0 seems to fix it. Worth adding a test case for this if there isn't one already? I'll also check to see if any other combinations of ts and js can break it.

jbedard commented 2 days ago

If you can contribute a test case that failed previously that would be great. I don't think any were added when fixed but maybe you can verify that?

aptenodytes-forsteri commented 2 days ago

My test case now passes with the new version, but a subsequent dependency fails

emit_transpiler_js = emit_js and transpiler and transpiler != "tsc" I think this is now getting set to false, so when I try to esbuild from my generated js, I get no js file exists.

aptenodytes-forsteri commented 2 days ago

I guess maybe I need to eliminate emit_declaration_only = True,

aptenodytes-forsteri commented 2 days ago

Err no, when I delete emit_declaration_only = True, I get the conflict again.

aptenodytes-forsteri commented 2 days ago

Updated repro case here: https://github.com/aptenodytes-forsteri/ts_js_interop/blob/main/src/BUILD.bazel

jbedard commented 2 days ago

Can you try adding test cases to rules_ts to reproduce it?

aptenodytes-forsteri commented 2 days ago

Can you try adding test cases to rules_ts to reproduce it?

https://github.com/aspect-build/rules_ts/pull/712

aptenodytes-forsteri commented 2 days ago

If I remove emit_declaration_only = True, I get the conflict error again.