Avoid Bazel's unsound directory dependency checking #1482
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #1408.
This PR modifies
npm_import
(and by extensionnpm_translate_lock
) to mask thepackage
source directory with a generated target andTreeArtifact
(ctx.declare_directory
) output of the same name. This allows package files to be collected withglob(["package/**"])
, such that no source directory dependency exists (which Bazel reports as unsound).Any rule that depends on the
package
source directory directly (there should be none) will now be depending on the:package
target instead (this should extend to every file inside the directory as well, I think).Repo rules are the exception, they cannot consume the
:package
target and so will continue to see the source directory. There are no output differences, so this is fine.Type of change
Bug fix (Bazel 7+).
Currently mitigated with;
--noincompatible_disallow_unsound_directory_outputs
, if builds are failing (observed in other rules).startup --host_jvm_args=-DBAZEL_TRACK_SOURCE_DIRECTORIES=1
, to hide warnings.Test plan
rules_js
repo (checking outmain
/this PR as appropriate for before/after)startup --host_jvm_args=-DBAZEL_TRACK_SOURCE_DIRECTORIES=1
from.aspect/bazelrc/correctness.bazelrc
)cd e2e/pnpm_workspace
bazel build //app/a:main