bazel-contrib / bazel-contrib/bazel-lib

[FR]: Support Expanding a filegroup via a rule

Open
#790 2 comments 0 reactions 0 assignees View on GitHub
can close? enhancement
Dominant language
Starlark
Stars
182
Forks
134
Avg merge
1d 46m
Merged PRs (30d)
1

Description

### What is the current behavior?

There is no rule for this.

### Describe the feature

I'm in the unique position where I need to expand an npm package and copy each individual file out of the package from `external` to another place in my WORKSPACE. If I were to use `copy_to_directory`, I can move the files around but I lose the granularity of each file and Bazel only sees a directory when I pass to `ts_project`. This means that I can't use that rule to bulk move files around.

I found this stackoverflow from a few years back that outlines a simple approach where in you can pass a `filegroup` to this rule and it makes an output for each file in the output group. https://stackoverflow.com/a/57983629

Having this be in bazel-lib would be fairly useful because then I can add a `filegroup` to the npm package which I then reference and expand anywhere. Going one step further, I expect `replace_prefix` or similar to exist on the rule such that I can strip out part of the source path and rewrite it for the destination path. e.g. if my source path is `external/my_package/package/src` I would want to rewrite it to `my_package/src`

Contributor guide

Open the contributing guide

Research direction

Start with the existing copy_to_directory behavior and the filegroup expansion approach described in the issue and linked Stack Overflow answer. Define how each file in the filegroup becomes an output and how replace_prefix should rewrite paths. Done means the rule preserves per-file granularity for use with ts_project and supports the requested source-to-destination path mapping.

Written by the indexing model from the issue text.

Assessment

Domain
build-system
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.