Add resolve()
method to SourceProvider
#177
Merged
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.
This adds a new
resolve()
method toSourceProvider
which is responsible for resolving an@import
specifier into a file path.FileProvider
still uses the default behavior of assuming the specifier is a relative path and joining it with the path of the originating file. This provides a hook for customSourceProviders
to implement their own application-specific resolution logic.This required a couple minor refactors in the
fs!
anderror_test()
utilities to make them more flexible and support testing a custom resolver.I've done a little Rust, but I'm not terribly familiar with it, so please let me know if I'm doing anything unidiomatic. Some of the areas I struggled with and am not convinced I found the ideal solution:
error_test()
accepts a callback which runs assertions. This was the only way I could reuse the function to assert different error kinds, since the only way to compare theBundleErrorKind
enum is withmatches!()
, and a match expression can't really work as a function input. I tried to return the error instead, but that ran into ownership issues since it outlived the bundler, and I couldn't find a good solution there.IOError
with aNotFound
kind, so it may not have an error message to wrap, and reaching into that felt a little too intrusive.Refs #174.