pub struct ResolverImpl { /* private fields */ }Expand description
Non-generic core of the resolver holding the heavy resolution algorithm.
The filesystem is type-erased to Arc<dyn FileSystem> here so that the resolver
algorithm compiles exactly once, regardless of the concrete Fs type used by
ResolverGeneric. All public resolution methods live on this struct and are reachable
through ResolverGeneric’s Deref implementation.
Implementations§
Source§impl ResolverImpl
impl ResolverImpl
Sourcepub fn resolve_dts<P: AsRef<Path>>(
&self,
containing_file: P,
specifier: &str,
) -> Result<Resolution, ResolveError>
pub fn resolve_dts<P: AsRef<Path>>( &self, containing_file: P, specifier: &str, ) -> Result<Resolution, ResolveError>
Resolve a module specifier for TypeScript declaration files.
Matches ts.resolveModuleName with moduleResolution: "bundler".
containing_file is the absolute path of the file containing the import.
specifier is the module specifier string.
The resolver uses the existing ResolveOptions for:
condition_names(used forexportsresolution;"types"is always added)tsconfig(forpathsmapping)symlinks(for realpath resolution)
§Errors
- See
ResolveError
Source§impl ResolverImpl
impl ResolverImpl
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 ResolverImpl
impl ResolverImpl
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 ResolverImpl::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
- Returns an invalid input error if the provided path has no parent.