pub struct ResolverGeneric<Fs> { /* private fields */ }Expand description
Generic implementation of the resolver, can be configured by the Cache trait
Implementations§
Source§impl<Fs: FileSystem> ResolverGeneric<Fs>
impl<Fs: FileSystem> ResolverGeneric<Fs>
Sourcepub fn find_tsconfig<P: AsRef<Path>>(
&self,
path: P,
) -> Result<Option<Arc<TsConfig>>, ResolveError>
pub fn find_tsconfig<P: AsRef<Path>>( &self, path: P, ) -> Result<Option<Arc<TsConfig>>, ResolveError>
Finds the tsconfig to which this path belongs.
If the path is inside node_modules, this function always returns None.
Algorithm:
- Search for
tsconfig.jsonin ancestor directories. - If the path is not included in this
tsconfig.jsonthrough thefiles,include, orexcludefields: 2.1. Search through project references until a referencedtsconfigincludes this file. 2.2. If none of the references include this path, return thetsconfig.jsonfound in step 1.
§Errors
- Returns an error if the tsconfig is invalid, including any extended or referenced tsconfigs.
Sourcepub fn resolve_tsconfig<P: AsRef<Path>>(
&self,
path: P,
) -> Result<Arc<TsConfig>, ResolveError>
pub fn resolve_tsconfig<P: AsRef<Path>>( &self, path: P, ) -> Result<Arc<TsConfig>, ResolveError>
Resolve tsconfig.
The path can be:
- Path to a file with
.jsonextension. - Path to a file without
.jsonextension,.jsonwill be appended to filename. - Path to a directory, where the filename is defaulted to
tsconfig.json
§Errors
- See ResolveError
Source§impl<Fs: FileSystem> ResolverGeneric<Fs>
impl<Fs: FileSystem> ResolverGeneric<Fs>
pub fn new(options: ResolveOptions) -> Self
pub fn new_with_file_system(file_system: Fs, options: ResolveOptions) -> Self
Sourcepub fn clone_with_options(&self, options: ResolveOptions) -> Self
pub fn clone_with_options(&self, options: ResolveOptions) -> Self
Clone the resolver using the same underlying cache.
Sourcepub const fn options(&self) -> &ResolveOptions
pub const fn options(&self) -> &ResolveOptions
Returns the options.
Sourcepub fn clear_cache(&self)
pub fn clear_cache(&self)
Clear the underlying cache.
Warning: The caller must ensure that there’re no ongoing resolution operations when calling this method. Otherwise, it may cause those operations to return an incorrect result.
Sourcepub fn resolve<P: AsRef<Path>>(
&self,
directory: P,
specifier: &str,
) -> Result<Resolution, ResolveError>
pub fn resolve<P: AsRef<Path>>( &self, directory: P, specifier: &str, ) -> Result<Resolution, ResolveError>
Resolve specifier at an absolute path to a directory.
A specifier is the string passed to require or import, i.e. require("specifier") or import "specifier".
directory must be an absolute path to a directory where the specifier is resolved against.
For CommonJS modules, it is the __dirname variable that contains the absolute path to the folder containing current module.
For ECMAScript modules, it is the value of import.meta.url.
NOTE: TsconfigDiscovery::Auto does not work for this API, use ResolverGeneric::resolve_file instead.
§Errors
- See ResolveError
Sourcepub fn resolve_file<P: AsRef<Path>>(
&self,
file: P,
specifier: &str,
) -> Result<Resolution, ResolveError>
pub fn resolve_file<P: AsRef<Path>>( &self, file: P, specifier: &str, ) -> Result<Resolution, ResolveError>
Resolve specifier for an absolute path to a file.
NOTE: TsconfigDiscovery::Auto only work for this API.
§Errors
- See ResolveError
§Panics
- If the provided path is not a file.