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

feat: eliminate distinction between srcs and assets #750

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jfirebaugh
Copy link
Contributor

@jfirebaugh jfirebaugh commented Dec 13, 2024

I believe the distinction between srcs and assets is unnecessary and the two attributes should be combined. The desired behavior is that ts_project should produce at least one output file for every input file in srcs. Either the input should produce transpiled/declaration output(s), or it should be copied to the output directory, obeying the path rewriting rules implied by root_dir/out_dir/declaration_dir.

Empirically, users at Figma have found the current behavior of srcs confusing. A typical experience is that they put non-TS files in srcs, expecting them to get copied to out_dir, and then observed some sort of failure, often at runtime, because the file was silently ignored instead.

Some specific gotchas under the current behavior of srcs are:

  • With resolve_json_module = True, transpiler = "tsc", .json files in srcs that are imported by one of the other input files get copied to out_dir as expected. But .json files that are listed in srcs but unreferenced by any input file produce an "output was not created" Bazel error. With the change proposed here, all .json files get copied to out_dir, regardless of whether they are imported somewhere or not.
  • If you take a working resolve_json_module = True, transpiler = "tsc" target and change it to transpile with swc, any .json files in srcs will no longer get copied to out_dir. With the change proposed here, the behavior is consistent between tsc and swc.
  • The behavior of .d.ts files in srcs is unpredictable and changes between rules_ts releases. Prior to 3.3.2, .d.ts files did get copied to output, but without out_dir applied. In rules_ts 3.3.2, they stopped being output altogether. With the change proposed here, they have a consistent and predictable behavior: they are always outputs, in the types output group, with root_dir/out_dir/declaration_dir applied.

Changes are visible to end-users: yes

This would be a breaking change because it removes the assets attribute. Generally, the migration action is simply to merge the assets value into srcs.

Test plan

  • Covered by existing test cases
  • New test cases added

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant