Skip to content

Commit

Permalink
fix: RootsPlugin debug_assert on windows (#145)
Browse files Browse the repository at this point in the history
* fix: RootsPlugin on windows

* update

---------

Co-authored-by: Boshen <boshenc@gmail.com>
  • Loading branch information
ahabhgk and Boshen committed Apr 24, 2024
1 parent 3f082a5 commit 7866055
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,13 +333,8 @@ impl<Fs: FileSystem> ResolverGeneric<Fs> {
return Ok(path);
}
}
// enhanced-resolve: RootsPlugin
for root in &self.options.roots {
let cached_path = self.cache.value(root);
let specifier = specifier.trim_start_matches(SLASH_START);
if let Ok(path) = self.require_relative(&cached_path, specifier, ctx) {
return Ok(path);
}
if let Some(path) = self.load_roots(specifier, ctx) {
return Ok(path);
}
// 2. If X begins with '/'
// a. set Y to be the file system root
Expand Down Expand Up @@ -987,6 +982,26 @@ impl<Fs: FileSystem> ResolverGeneric<Fs> {
Err(ResolveError::ExtensionAlias)
}

/// enhanced-resolve: RootsPlugin
///
/// A list of directories where requests of server-relative URLs (starting with '/') are resolved,
/// defaults to context configuration option.
///
/// On non-Windows systems these requests are resolved as an absolute path first.
fn load_roots(&self, specifier: &str, ctx: &mut Ctx) -> Option<CachedPath> {
if !self.options.roots.is_empty() {
if let Some(specifier) = specifier.strip_prefix(SLASH_START) {
for root in &self.options.roots {
let cached_path = self.cache.value(root);
if let Ok(path) = self.require_relative(&cached_path, specifier, ctx) {
return Some(path);
}
}
}
}
None
}

fn load_tsconfig_paths(
&self,
cached_path: &CachedPath,
Expand Down

0 comments on commit 7866055

Please sign in to comment.