1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-22 15:06:54 -05:00

fix(compat): ESM resolver for package subpath (#13599)

This commit is contained in:
Bartek Iwańczuk 2022-02-07 00:02:52 +01:00 committed by GitHub
parent a7850d7fe6
commit d0dd838521
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 23 additions and 1 deletions

View file

@ -903,7 +903,7 @@ fn parse_package_name(
} }
let package_name = if let Some(index) = separator_index { let package_name = if let Some(index) = separator_index {
specifier[0..=index].to_string() specifier[0..index].to_string()
} else { } else {
specifier.to_string() specifier.to_string()
}; };
@ -1195,6 +1195,22 @@ mod tests {
assert_eq!(actual.to_result().unwrap(), expected); assert_eq!(actual.to_result().unwrap(), expected);
} }
#[test]
fn package_subpath() {
let cwd = testdir("subpath");
let main = Url::from_file_path(cwd.join("main.js")).unwrap();
let actual = node_resolve("foo", main.as_str(), &cwd).unwrap();
let expected =
Url::from_file_path(cwd.join("node_modules/foo/index.js")).unwrap();
matches!(actual, ResolveResponse::CommonJs(_));
assert_eq!(actual.to_result().unwrap(), expected);
let actual = node_resolve("foo/server.js", main.as_str(), &cwd).unwrap();
let expected =
Url::from_file_path(cwd.join("node_modules/foo/server.js")).unwrap();
matches!(actual, ResolveResponse::CommonJs(_));
assert_eq!(actual.to_result().unwrap(), expected);
}
#[test] #[test]
fn basic_deps() { fn basic_deps() {
let cwd = testdir("basic_deps"); let cwd = testdir("basic_deps");

2
cli/compat/testdata/subpath/main.js vendored Normal file
View file

@ -0,0 +1,2 @@
import "foo";
import "foo/server.js";

View file

View file

@ -0,0 +1,4 @@
{
"name": "foo",
"main": "index.js"
}

View file