|
| 1 | +use std::path::Path; |
1 | 2 | use std::{fmt, path::PathBuf};
|
2 | 3 |
|
3 | 4 | /// Module Resolution Options
|
@@ -130,6 +131,53 @@ pub struct ResolveOptions {
|
130 | 131 | pub builtin_modules: bool,
|
131 | 132 | }
|
132 | 133 |
|
| 134 | +impl ResolveOptions { |
| 135 | + /// ## Examples |
| 136 | + /// |
| 137 | + /// ``` |
| 138 | + /// use oxc_resolver::ResolveOptions; |
| 139 | + /// |
| 140 | + /// let options = ResolveOptions::default().with_condition_names(&["bar"]); |
| 141 | + /// assert_eq!(options.condition_names, vec!["bar".to_string()]) |
| 142 | + /// ``` |
| 143 | + #[must_use] |
| 144 | + pub fn with_condition_names(mut self, names: &[&str]) -> Self { |
| 145 | + self.condition_names = names.iter().map(ToString::to_string).collect::<Vec<String>>(); |
| 146 | + self |
| 147 | + } |
| 148 | + |
| 149 | + /// ## Examples |
| 150 | + /// |
| 151 | + /// ``` |
| 152 | + /// use oxc_resolver::ResolveOptions; |
| 153 | + /// |
| 154 | + /// let options = ResolveOptions::default().with_builtin_modules(false); |
| 155 | + /// assert_eq!(options.builtin_modules, false) |
| 156 | + /// ``` |
| 157 | + #[must_use] |
| 158 | + pub fn with_builtin_modules(mut self, flag: bool) -> Self { |
| 159 | + self.builtin_modules = flag; |
| 160 | + self |
| 161 | + } |
| 162 | + |
| 163 | + /// Adds a single root to the options |
| 164 | + /// |
| 165 | + /// ## Examples |
| 166 | + /// |
| 167 | + /// ``` |
| 168 | + /// use oxc_resolver::ResolveOptions; |
| 169 | + /// use std::path::{Path, PathBuf}; |
| 170 | + /// |
| 171 | + /// let options = ResolveOptions::default().with_root("foo"); |
| 172 | + /// assert_eq!(options.roots, vec![PathBuf::from("foo")]) |
| 173 | + /// ``` |
| 174 | + #[must_use] |
| 175 | + pub fn with_root<P: AsRef<Path>>(mut self, root: P) -> Self { |
| 176 | + self.roots.push(root.as_ref().to_path_buf()); |
| 177 | + self |
| 178 | + } |
| 179 | +} |
| 180 | + |
133 | 181 | /// Value for [ResolveOptions::enforce_extension]
|
134 | 182 | #[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
135 | 183 | pub enum EnforceExtension {
|
|
0 commit comments