Skip to content

[Bug]: copy_data_files_to_bin (for gather_runfiles) depends on whether transpiler is set #411

@gzm0

Description

@gzm0

What happened?

It seems that ts_project doesn't expose this config option yet and the defaults are different.

Without transpiler

  1. data is passed to the ts_project rule here:

    rules_ts/ts/defs.bzl

    Lines 406 to 412 in 42094e8

    ts_project_rule(
    name = tsc_target_name,
    srcs = srcs,
    args = args,
    assets = assets,
    data = data,
    deps = tsc_deps,

  2. The ts_project rule invokes gather_runfiles

    runfiles = js_lib_helpers.gather_runfiles(
    ctx = ctx,
    sources = output_sources_depset,
    data = ctx.attr.data,
    deps = ctx.attr.srcs + [ctx.attr.tsconfig] + ctx.attr.deps,
    )

  3. The default for copy_data_files_to_bin is False

With transpiler

  1. data is passed to js_library here:

    rules_ts/ts/defs.bzl

    Lines 392 to 400 in 42094e8

    js_library(
    name = name,
    # Include the tsc target in srcs to pick-up both the direct & transitive declaration outputs so
    # that this js_library can be a valid dep for downstream ts_project or other rules_js derivative rules.
    srcs = [transpile_target_name, tsc_target_name] + assets,
    deps = deps,
    data = data,
    **common_kwargs
    )

  2. The default for js_library is True

What I'd expect

  • The behavior with and without transpiler to be the same.
  • There be an equivalent option to js_library on ts_project (the macro).

Version

Development (host) and target OS/architectures:

Output of bazel --version:

bazelisk --version
bazel 6.3.2

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

rules_js: 1.31.0
rules_ts: 1.4.5

Language(s) and/or frameworks involved: None.

How to reproduce

Minimal steps, happy to provide more if necessary.

1. Add a filegroup with files in a different package to `data` of a `ts_project` (without `transpiler` set).
2. Build passes.
3. Set `transpiler` to `swc`.
4. Build fails (example failure below)
5. Switch `filegroup` to `js_library`
6. Build passes



Expected to find source file <the file> in '//package-of-ts-project', but instead it is in '//package-of-file'.

All source and data files that are not in the Bazel output tree must be in the same package as the
target so that they can be copied to the output tree in an action.

See https://docs.aspect.build/rules/aspect_rules_js/docs/#javascript for more context on why this is required.


### Any other information?

Happy to open a PR to align this, but I'd like to agree on the following first:
- Exact fix (add flag, align behavior, ???)
- Target branch (1.x, 2.x)?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingneed: investigationInvestigation required to proceed further

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions