fix: update usages of ExternalNpmPackageInfo.path
to be safe and default to empty string
#2881
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.
ExternalNpmPackageInfo
had apath
attribute introduced and used in2c2cc6e, but the provider was publicly exported beforehand. Even
though all internal usages were updated to include a path, this change was shipped in
3.2.0
andintroduced an unintentional breaking change for consumers. Most notably,
rules_postcss
manuallyimplements this provider and does not give a
path
failing in versions3.2.0
and up.https://github.com/bazelbuild/rules_postcss/blob/2bd16fda40cd4bf4fbf0b477b968366ec1602103/internal/plugin.bzl#L30-L41
Solution here is to safely retrieve the
path
attribute and default to empty string at all placesit is used. A test is also introduced to ensure that a
nodejs_binary()
can depend on a customExternalNpmPackageInfo
provider without apath
attribute, which should hopefully prevent againstregressions.
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Usage of custom rules which provide
ExternalNpmPackageInfo
without apath
attribute, break in versions3.2.0
and up.What is the new behavior?
All usages of an
ExternalNpmPackageInfo
provider with nopath
attribute, default to the empty string, meaning they will be linked at the root.Does this PR introduce a breaking change?
Other information
This bug appears to have been a regression in
3.2.0
which brokerules_postcss
, as its plugins return a customExternalNpmPackageInfo
provider that does not contain apath
, leading to the above error when usingpostcss_binary()
withrules_nodejs@>=3.2.0
.Considering that this shipped without note in
3.2.0
and in a minor version, I'm assuming this was a regression rather than a deliberate breaking change, so this PR simply provides a default value for a missingpath
field. Since then,4.0.0
was released, so we technically could argue this is just an undocumented breaking change in4.0.0
. I'm not sure if3.x.x
is still supported, but if not we could just call this a breaking change and thepath
field is now required. I'm inclined not to do that if possible and actually fix the bug inrules_nodejs
, which is the strategy this PR attempts to do.I'm not very familiar with the test infrastructure of
rules_nodejs
. I think I put this test in the right package, but most of the other packages use alinker()
rule that I don't fully understand. I found thatnodejs_binary()
was sufficient to reproduce the bug, so I just tested with that. Let me know if usinglinker()
would be more appropriate here.More context about how I came across this regression: dgp1130/rules_prerender#39.