|
| 1 | +use std::path::PathBuf; |
| 2 | + |
| 3 | +use super::PluginContext; |
| 4 | +use crate::types::Dependency; |
| 5 | +use crate::types::JSONObject; |
| 6 | +use crate::types::Priority; |
| 7 | + |
| 8 | +// TODO Diagnostics and invalidations |
| 9 | + |
| 10 | +pub struct Resolution { |
| 11 | + /// Whether this dependency can be deferred by Parcel itself |
| 12 | + pub can_defer: bool, |
| 13 | + |
| 14 | + /// The code of the resolved asset |
| 15 | + /// |
| 16 | + /// If provided, this is used rather than reading the file from disk. |
| 17 | + /// |
| 18 | + pub code: Option<String>, |
| 19 | + |
| 20 | + /// An absolute path to the resolved file |
| 21 | + pub file_path: PathBuf, |
| 22 | + |
| 23 | + /// Whether the resolved file should be excluded from the build |
| 24 | + pub is_excluded: bool, |
| 25 | + |
| 26 | + /// Is spread (shallowly merged) onto the request's dependency.meta |
| 27 | + pub meta: JSONObject, |
| 28 | + |
| 29 | + /// An optional named pipeline to use to compile the resolved file |
| 30 | + pub pipeline: Option<String>, |
| 31 | + |
| 32 | + /// Overrides the priority set on the dependency |
| 33 | + pub priority: Option<Priority>, |
| 34 | + |
| 35 | + /// Corresponds to the asset side effects |
| 36 | + pub side_effects: bool, |
| 37 | + |
| 38 | + /// Query parameters to be used by transformers when compiling the resolved file |
| 39 | + pub query: Option<String>, |
| 40 | +} |
| 41 | + |
| 42 | +/// Converts a dependency specifier into a file path that will be processed by transformers |
| 43 | +/// |
| 44 | +/// Resolvers run in a pipeline until one of them return a result. |
| 45 | +/// |
| 46 | +pub trait ResolverPlugin: Send + Sync { |
| 47 | + /// Determines what the dependency specifier resolves to |
| 48 | + fn resolve( |
| 49 | + &self, |
| 50 | + specifier: &str, |
| 51 | + dependency: &Dependency, |
| 52 | + pipeline: Option<&str>, |
| 53 | + context: &PluginContext, |
| 54 | + ) -> Result<Resolution, anyhow::Error>; |
| 55 | +} |
0 commit comments