Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen committed Jan 19, 2024
1 parent 3fc870a commit 47d56a6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
10 changes: 9 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,15 @@ impl<Fs: FileSystem + Default> ResolverGeneric<Fs> {
if request != alias_value
&& !request.strip_prefix(alias_value).is_some_and(|prefix| prefix.starts_with('/'))
{
let new_specifier = format!("{alias_value}{}", &request[alias_key.len()..]);
let tail = &request[alias_key.len()..];
// Must not append anything to alias_value if it is a file.
if !tail.is_empty() {
let alias_value_cached_path = self.cache.value(Path::new(alias_value));
if alias_value_cached_path.is_file(&self.cache.fs, ctx) {
return Ok(None);
}
}
let new_specifier = format!("{alias_value}{tail}");
ctx.with_fully_specified(false);
return match self.require(cached_path, &new_specifier, ctx) {
Err(ResolveError::NotFound(_)) => Ok(None),
Expand Down
18 changes: 12 additions & 6 deletions src/tests/missing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,28 @@ fn alias_and_extensions() {
let f = super::fixture();

let resolver = Resolver::new(ResolveOptions {
alias: vec![(
"@scope-js/package-name/dir$".into(),
vec![AliasValue::Path(f.join("foo/index.js").to_string_lossy().to_string())],
)],
alias: vec![
(
"@scope-js/package-name/dir$".into(),
vec![AliasValue::Path(f.join("foo/index.js").to_string_lossy().to_string())],
),
(
"react-dom".into(),
vec![AliasValue::Path(f.join("foo/index.js").to_string_lossy().to_string())],
),
],
extensions: vec![".server.ts".into()],

..ResolveOptions::default()
});

let mut ctx = ResolveContext::default();
let _ = resolver.resolve_with_context(&f, "@scope-js/package-name/dir/router", &mut ctx);
let _ = resolver.resolve_with_context(&f, "react-dom/client", &mut ctx);

for dep in ctx.missing_dependencies {
if let Some(path) = dep.parent() {
// Parent must not be a file
assert!(!path.is_file(), "{path:?}");
assert!(!path.is_file(), "{path:?} must not be a file");
}
}
}

0 comments on commit 47d56a6

Please sign in to comment.